pdf.mjs 630 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814
  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. /***/ 976:
  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__(292);
  34. // EXTERNAL MODULE: ./src/display/display_utils.js
  35. var display_utils = __webpack_require__(419);
  36. // EXTERNAL MODULE: ./src/display/annotation_storage.js
  37. var annotation_storage = __webpack_require__(792);
  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__(284);
  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. #updates = null;
  171. #hasBorder = false;
  172. constructor(parameters, {
  173. isRenderable = false,
  174. ignoreBorder = false,
  175. createQuadrilaterals = false
  176. } = {}) {
  177. this.isRenderable = isRenderable;
  178. this.data = parameters.data;
  179. this.layer = parameters.layer;
  180. this.linkService = parameters.linkService;
  181. this.downloadManager = parameters.downloadManager;
  182. this.imageResourcesPath = parameters.imageResourcesPath;
  183. this.renderForms = parameters.renderForms;
  184. this.svgFactory = parameters.svgFactory;
  185. this.annotationStorage = parameters.annotationStorage;
  186. this.enableScripting = parameters.enableScripting;
  187. this.hasJSActions = parameters.hasJSActions;
  188. this._fieldObjects = parameters.fieldObjects;
  189. this.parent = parameters.parent;
  190. if (isRenderable) {
  191. this.container = this._createContainer(ignoreBorder);
  192. }
  193. if (createQuadrilaterals) {
  194. this._createQuadrilaterals();
  195. }
  196. }
  197. static _hasPopupData({
  198. titleObj,
  199. contentsObj,
  200. richText
  201. }) {
  202. return !!(titleObj?.str || contentsObj?.str || richText?.str);
  203. }
  204. get hasPopupData() {
  205. return AnnotationElement._hasPopupData(this.data);
  206. }
  207. updateEdited(params) {
  208. if (!this.container) {
  209. return;
  210. }
  211. this.#updates ||= {
  212. rect: this.data.rect.slice(0)
  213. };
  214. const {
  215. rect
  216. } = params;
  217. if (rect) {
  218. this.#setRectEdited(rect);
  219. }
  220. }
  221. resetEdited() {
  222. if (!this.#updates) {
  223. return;
  224. }
  225. this.#setRectEdited(this.#updates.rect);
  226. this.#updates = null;
  227. }
  228. #setRectEdited(rect) {
  229. const {
  230. container: {
  231. style
  232. },
  233. data: {
  234. rect: currentRect,
  235. rotation
  236. },
  237. parent: {
  238. viewport: {
  239. rawDims: {
  240. pageWidth,
  241. pageHeight,
  242. pageX,
  243. pageY
  244. }
  245. }
  246. }
  247. } = this;
  248. currentRect?.splice(0, 4, ...rect);
  249. const {
  250. width,
  251. height
  252. } = getRectDims(rect);
  253. style.left = `${100 * (rect[0] - pageX) / pageWidth}%`;
  254. style.top = `${100 * (pageHeight - rect[3] + pageY) / pageHeight}%`;
  255. if (rotation === 0) {
  256. style.width = `${100 * width / pageWidth}%`;
  257. style.height = `${100 * height / pageHeight}%`;
  258. } else {
  259. this.setRotation(rotation);
  260. }
  261. }
  262. _createContainer(ignoreBorder) {
  263. const {
  264. data,
  265. parent: {
  266. page,
  267. viewport
  268. }
  269. } = this;
  270. const container = document.createElement("section");
  271. container.setAttribute("data-annotation-id", data.id);
  272. if (!(this instanceof WidgetAnnotationElement)) {
  273. container.tabIndex = DEFAULT_TAB_INDEX;
  274. }
  275. const {
  276. style
  277. } = container;
  278. style.zIndex = this.parent.zIndex++;
  279. if (data.popupRef) {
  280. container.setAttribute("aria-haspopup", "dialog");
  281. }
  282. if (data.alternativeText) {
  283. container.title = data.alternativeText;
  284. }
  285. if (data.noRotate) {
  286. container.classList.add("norotate");
  287. }
  288. if (!data.rect || this instanceof PopupAnnotationElement) {
  289. const {
  290. rotation
  291. } = data;
  292. if (!data.hasOwnCanvas && rotation !== 0) {
  293. this.setRotation(rotation, container);
  294. }
  295. return container;
  296. }
  297. const {
  298. width,
  299. height
  300. } = getRectDims(data.rect);
  301. if (!ignoreBorder && data.borderStyle.width > 0) {
  302. style.borderWidth = `${data.borderStyle.width}px`;
  303. const horizontalRadius = data.borderStyle.horizontalCornerRadius;
  304. const verticalRadius = data.borderStyle.verticalCornerRadius;
  305. if (horizontalRadius > 0 || verticalRadius > 0) {
  306. const radius = `calc(${horizontalRadius}px * var(--scale-factor)) / calc(${verticalRadius}px * var(--scale-factor))`;
  307. style.borderRadius = radius;
  308. } else if (this instanceof RadioButtonWidgetAnnotationElement) {
  309. const radius = `calc(${width}px * var(--scale-factor)) / calc(${height}px * var(--scale-factor))`;
  310. style.borderRadius = radius;
  311. }
  312. switch (data.borderStyle.style) {
  313. case util.AnnotationBorderStyleType.SOLID:
  314. style.borderStyle = "solid";
  315. break;
  316. case util.AnnotationBorderStyleType.DASHED:
  317. style.borderStyle = "dashed";
  318. break;
  319. case util.AnnotationBorderStyleType.BEVELED:
  320. (0,util.warn)("Unimplemented border style: beveled");
  321. break;
  322. case util.AnnotationBorderStyleType.INSET:
  323. (0,util.warn)("Unimplemented border style: inset");
  324. break;
  325. case util.AnnotationBorderStyleType.UNDERLINE:
  326. style.borderBottomStyle = "solid";
  327. break;
  328. default:
  329. break;
  330. }
  331. const borderColor = data.borderColor || null;
  332. if (borderColor) {
  333. this.#hasBorder = true;
  334. style.borderColor = util.Util.makeHexColor(borderColor[0] | 0, borderColor[1] | 0, borderColor[2] | 0);
  335. } else {
  336. style.borderWidth = 0;
  337. }
  338. }
  339. 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]]);
  340. const {
  341. pageWidth,
  342. pageHeight,
  343. pageX,
  344. pageY
  345. } = viewport.rawDims;
  346. style.left = `${100 * (rect[0] - pageX) / pageWidth}%`;
  347. style.top = `${100 * (rect[1] - pageY) / pageHeight}%`;
  348. const {
  349. rotation
  350. } = data;
  351. if (data.hasOwnCanvas || rotation === 0) {
  352. style.width = `${100 * width / pageWidth}%`;
  353. style.height = `${100 * height / pageHeight}%`;
  354. } else {
  355. this.setRotation(rotation, container);
  356. }
  357. return container;
  358. }
  359. setRotation(angle, container = this.container) {
  360. if (!this.data.rect) {
  361. return;
  362. }
  363. const {
  364. pageWidth,
  365. pageHeight
  366. } = this.parent.viewport.rawDims;
  367. const {
  368. width,
  369. height
  370. } = getRectDims(this.data.rect);
  371. let elementWidth, elementHeight;
  372. if (angle % 180 === 0) {
  373. elementWidth = 100 * width / pageWidth;
  374. elementHeight = 100 * height / pageHeight;
  375. } else {
  376. elementWidth = 100 * height / pageWidth;
  377. elementHeight = 100 * width / pageHeight;
  378. }
  379. container.style.width = `${elementWidth}%`;
  380. container.style.height = `${elementHeight}%`;
  381. container.setAttribute("data-main-rotation", (360 - angle) % 360);
  382. }
  383. get _commonActions() {
  384. const setColor = (jsName, styleName, event) => {
  385. const color = event.detail[jsName];
  386. const colorType = color[0];
  387. const colorArray = color.slice(1);
  388. event.target.style[styleName] = ColorConverters[`${colorType}_HTML`](colorArray);
  389. this.annotationStorage.setValue(this.data.id, {
  390. [styleName]: ColorConverters[`${colorType}_rgb`](colorArray)
  391. });
  392. };
  393. return (0,util.shadow)(this, "_commonActions", {
  394. display: event => {
  395. const {
  396. display
  397. } = event.detail;
  398. const hidden = display % 2 === 1;
  399. this.container.style.visibility = hidden ? "hidden" : "visible";
  400. this.annotationStorage.setValue(this.data.id, {
  401. noView: hidden,
  402. noPrint: display === 1 || display === 2
  403. });
  404. },
  405. print: event => {
  406. this.annotationStorage.setValue(this.data.id, {
  407. noPrint: !event.detail.print
  408. });
  409. },
  410. hidden: event => {
  411. const {
  412. hidden
  413. } = event.detail;
  414. this.container.style.visibility = hidden ? "hidden" : "visible";
  415. this.annotationStorage.setValue(this.data.id, {
  416. noPrint: hidden,
  417. noView: hidden
  418. });
  419. },
  420. focus: event => {
  421. setTimeout(() => event.target.focus({
  422. preventScroll: false
  423. }), 0);
  424. },
  425. userName: event => {
  426. event.target.title = event.detail.userName;
  427. },
  428. readonly: event => {
  429. event.target.disabled = event.detail.readonly;
  430. },
  431. required: event => {
  432. this._setRequired(event.target, event.detail.required);
  433. },
  434. bgColor: event => {
  435. setColor("bgColor", "backgroundColor", event);
  436. },
  437. fillColor: event => {
  438. setColor("fillColor", "backgroundColor", event);
  439. },
  440. fgColor: event => {
  441. setColor("fgColor", "color", event);
  442. },
  443. textColor: event => {
  444. setColor("textColor", "color", event);
  445. },
  446. borderColor: event => {
  447. setColor("borderColor", "borderColor", event);
  448. },
  449. strokeColor: event => {
  450. setColor("strokeColor", "borderColor", event);
  451. },
  452. rotation: event => {
  453. const angle = event.detail.rotation;
  454. this.setRotation(angle);
  455. this.annotationStorage.setValue(this.data.id, {
  456. rotation: angle
  457. });
  458. }
  459. });
  460. }
  461. _dispatchEventFromSandbox(actions, jsEvent) {
  462. const commonActions = this._commonActions;
  463. for (const name of Object.keys(jsEvent.detail)) {
  464. const action = actions[name] || commonActions[name];
  465. action?.(jsEvent);
  466. }
  467. }
  468. _setDefaultPropertiesFromJS(element) {
  469. if (!this.enableScripting) {
  470. return;
  471. }
  472. const storedData = this.annotationStorage.getRawValue(this.data.id);
  473. if (!storedData) {
  474. return;
  475. }
  476. const commonActions = this._commonActions;
  477. for (const [actionName, detail] of Object.entries(storedData)) {
  478. const action = commonActions[actionName];
  479. if (action) {
  480. const eventProxy = {
  481. detail: {
  482. [actionName]: detail
  483. },
  484. target: element
  485. };
  486. action(eventProxy);
  487. delete storedData[actionName];
  488. }
  489. }
  490. }
  491. _createQuadrilaterals() {
  492. if (!this.container) {
  493. return;
  494. }
  495. const {
  496. quadPoints
  497. } = this.data;
  498. if (!quadPoints) {
  499. return;
  500. }
  501. const [rectBlX, rectBlY, rectTrX, rectTrY] = this.data.rect;
  502. if (quadPoints.length === 1) {
  503. const [, {
  504. x: trX,
  505. y: trY
  506. }, {
  507. x: blX,
  508. y: blY
  509. }] = quadPoints[0];
  510. if (rectTrX === trX && rectTrY === trY && rectBlX === blX && rectBlY === blY) {
  511. return;
  512. }
  513. }
  514. const {
  515. style
  516. } = this.container;
  517. let svgBuffer;
  518. if (this.#hasBorder) {
  519. const {
  520. borderColor,
  521. borderWidth
  522. } = style;
  523. style.borderWidth = 0;
  524. 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}">`];
  525. this.container.classList.add("hasBorder");
  526. }
  527. const width = rectTrX - rectBlX;
  528. const height = rectTrY - rectBlY;
  529. const {
  530. svgFactory
  531. } = this;
  532. const svg = svgFactory.createElement("svg");
  533. svg.classList.add("quadrilateralsContainer");
  534. svg.setAttribute("width", 0);
  535. svg.setAttribute("height", 0);
  536. const defs = svgFactory.createElement("defs");
  537. svg.append(defs);
  538. const clipPath = svgFactory.createElement("clipPath");
  539. const id = `clippath_${this.data.id}`;
  540. clipPath.setAttribute("id", id);
  541. clipPath.setAttribute("clipPathUnits", "objectBoundingBox");
  542. defs.append(clipPath);
  543. for (const [, {
  544. x: trX,
  545. y: trY
  546. }, {
  547. x: blX,
  548. y: blY
  549. }] of quadPoints) {
  550. const rect = svgFactory.createElement("rect");
  551. const x = (blX - rectBlX) / width;
  552. const y = (rectTrY - trY) / height;
  553. const rectWidth = (trX - blX) / width;
  554. const rectHeight = (trY - blY) / height;
  555. rect.setAttribute("x", x);
  556. rect.setAttribute("y", y);
  557. rect.setAttribute("width", rectWidth);
  558. rect.setAttribute("height", rectHeight);
  559. clipPath.append(rect);
  560. svgBuffer?.push(`<rect vector-effect="non-scaling-stroke" x="${x}" y="${y}" width="${rectWidth}" height="${rectHeight}"/>`);
  561. }
  562. if (this.#hasBorder) {
  563. svgBuffer.push(`</g></svg>')`);
  564. style.backgroundImage = svgBuffer.join("");
  565. }
  566. this.container.append(svg);
  567. this.container.style.clipPath = `url(#${id})`;
  568. }
  569. _createPopup() {
  570. const {
  571. container,
  572. data
  573. } = this;
  574. container.setAttribute("aria-haspopup", "dialog");
  575. const popup = new PopupAnnotationElement({
  576. data: {
  577. color: data.color,
  578. titleObj: data.titleObj,
  579. modificationDate: data.modificationDate,
  580. contentsObj: data.contentsObj,
  581. richText: data.richText,
  582. parentRect: data.rect,
  583. borderStyle: 0,
  584. id: `popup_${data.id}`,
  585. rotation: data.rotation
  586. },
  587. parent: this.parent,
  588. elements: [this]
  589. });
  590. this.parent.div.append(popup.render());
  591. }
  592. render() {
  593. (0,util.unreachable)("Abstract method `AnnotationElement.render` called");
  594. }
  595. _getElementsByName(name, skipId = null) {
  596. const fields = [];
  597. if (this._fieldObjects) {
  598. const fieldObj = this._fieldObjects[name];
  599. if (fieldObj) {
  600. for (const {
  601. page,
  602. id,
  603. exportValues
  604. } of fieldObj) {
  605. if (page === -1) {
  606. continue;
  607. }
  608. if (id === skipId) {
  609. continue;
  610. }
  611. const exportValue = typeof exportValues === "string" ? exportValues : null;
  612. const domElement = document.querySelector(`[data-element-id="${id}"]`);
  613. if (domElement && !GetElementsByNameSet.has(domElement)) {
  614. (0,util.warn)(`_getElementsByName - element not allowed: ${id}`);
  615. continue;
  616. }
  617. fields.push({
  618. id,
  619. exportValue,
  620. domElement
  621. });
  622. }
  623. }
  624. return fields;
  625. }
  626. for (const domElement of document.getElementsByName(name)) {
  627. const {
  628. exportValue
  629. } = domElement;
  630. const id = domElement.getAttribute("data-element-id");
  631. if (id === skipId) {
  632. continue;
  633. }
  634. if (!GetElementsByNameSet.has(domElement)) {
  635. continue;
  636. }
  637. fields.push({
  638. id,
  639. exportValue,
  640. domElement
  641. });
  642. }
  643. return fields;
  644. }
  645. show() {
  646. if (this.container) {
  647. this.container.hidden = false;
  648. }
  649. this.popup?.maybeShow();
  650. }
  651. hide() {
  652. if (this.container) {
  653. this.container.hidden = true;
  654. }
  655. this.popup?.forceHide();
  656. }
  657. getElementsToTriggerPopup() {
  658. return this.container;
  659. }
  660. addHighlightArea() {
  661. const triggers = this.getElementsToTriggerPopup();
  662. if (Array.isArray(triggers)) {
  663. for (const element of triggers) {
  664. element.classList.add("highlightArea");
  665. }
  666. } else {
  667. triggers.classList.add("highlightArea");
  668. }
  669. }
  670. get _isEditable() {
  671. return false;
  672. }
  673. _editOnDoubleClick() {
  674. if (!this._isEditable) {
  675. return;
  676. }
  677. const {
  678. annotationEditorType: mode,
  679. data: {
  680. id: editId
  681. }
  682. } = this;
  683. this.container.addEventListener("dblclick", () => {
  684. this.linkService.eventBus?.dispatch("switchannotationeditormode", {
  685. source: this,
  686. mode,
  687. editId
  688. });
  689. });
  690. }
  691. }
  692. class LinkAnnotationElement extends AnnotationElement {
  693. constructor(parameters, options = null) {
  694. super(parameters, {
  695. isRenderable: true,
  696. ignoreBorder: !!options?.ignoreBorder,
  697. createQuadrilaterals: true
  698. });
  699. this.isTooltipOnly = parameters.data.isTooltipOnly;
  700. }
  701. render() {
  702. const {
  703. data,
  704. linkService
  705. } = this;
  706. const link = document.createElement("a");
  707. link.setAttribute("data-element-id", data.id);
  708. let isBound = false;
  709. if (data.url) {
  710. linkService.addLinkAttributes(link, data.url, data.newWindow);
  711. isBound = true;
  712. } else if (data.action) {
  713. this._bindNamedAction(link, data.action);
  714. isBound = true;
  715. } else if (data.attachment) {
  716. this.#bindAttachment(link, data.attachment, data.attachmentDest);
  717. isBound = true;
  718. } else if (data.setOCGState) {
  719. this.#bindSetOCGState(link, data.setOCGState);
  720. isBound = true;
  721. } else if (data.dest) {
  722. this._bindLink(link, data.dest);
  723. isBound = true;
  724. } else {
  725. if (data.actions && (data.actions.Action || data.actions["Mouse Up"] || data.actions["Mouse Down"]) && this.enableScripting && this.hasJSActions) {
  726. this._bindJSAction(link, data);
  727. isBound = true;
  728. }
  729. if (data.resetForm) {
  730. this._bindResetFormAction(link, data.resetForm);
  731. isBound = true;
  732. } else if (this.isTooltipOnly && !isBound) {
  733. this._bindLink(link, "");
  734. isBound = true;
  735. }
  736. }
  737. this.container.classList.add("linkAnnotation");
  738. if (isBound) {
  739. this.container.append(link);
  740. }
  741. return this.container;
  742. }
  743. #setInternalLink() {
  744. this.container.setAttribute("data-internal-link", "");
  745. }
  746. _bindLink(link, destination) {
  747. link.href = this.linkService.getDestinationHash(destination);
  748. link.onclick = () => {
  749. if (destination) {
  750. this.linkService.goToDestination(destination);
  751. }
  752. return false;
  753. };
  754. if (destination || destination === "") {
  755. this.#setInternalLink();
  756. }
  757. }
  758. _bindNamedAction(link, action) {
  759. link.href = this.linkService.getAnchorUrl("");
  760. link.onclick = () => {
  761. this.linkService.executeNamedAction(action);
  762. return false;
  763. };
  764. this.#setInternalLink();
  765. }
  766. #bindAttachment(link, attachment, dest = null) {
  767. link.href = this.linkService.getAnchorUrl("");
  768. link.onclick = () => {
  769. this.downloadManager?.openOrDownloadData(attachment.content, attachment.filename, dest);
  770. return false;
  771. };
  772. this.#setInternalLink();
  773. }
  774. #bindSetOCGState(link, action) {
  775. link.href = this.linkService.getAnchorUrl("");
  776. link.onclick = () => {
  777. this.linkService.executeSetOCGState(action);
  778. return false;
  779. };
  780. this.#setInternalLink();
  781. }
  782. _bindJSAction(link, data) {
  783. link.href = this.linkService.getAnchorUrl("");
  784. const map = new Map([["Action", "onclick"], ["Mouse Up", "onmouseup"], ["Mouse Down", "onmousedown"]]);
  785. for (const name of Object.keys(data.actions)) {
  786. const jsName = map.get(name);
  787. if (!jsName) {
  788. continue;
  789. }
  790. link[jsName] = () => {
  791. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  792. source: this,
  793. detail: {
  794. id: data.id,
  795. name
  796. }
  797. });
  798. return false;
  799. };
  800. }
  801. if (!link.onclick) {
  802. link.onclick = () => false;
  803. }
  804. this.#setInternalLink();
  805. }
  806. _bindResetFormAction(link, resetForm) {
  807. const otherClickAction = link.onclick;
  808. if (!otherClickAction) {
  809. link.href = this.linkService.getAnchorUrl("");
  810. }
  811. this.#setInternalLink();
  812. if (!this._fieldObjects) {
  813. (0,util.warn)(`_bindResetFormAction - "resetForm" action not supported, ` + "ensure that the `fieldObjects` parameter is provided.");
  814. if (!otherClickAction) {
  815. link.onclick = () => false;
  816. }
  817. return;
  818. }
  819. link.onclick = () => {
  820. otherClickAction?.();
  821. const {
  822. fields: resetFormFields,
  823. refs: resetFormRefs,
  824. include
  825. } = resetForm;
  826. const allFields = [];
  827. if (resetFormFields.length !== 0 || resetFormRefs.length !== 0) {
  828. const fieldIds = new Set(resetFormRefs);
  829. for (const fieldName of resetFormFields) {
  830. const fields = this._fieldObjects[fieldName] || [];
  831. for (const {
  832. id
  833. } of fields) {
  834. fieldIds.add(id);
  835. }
  836. }
  837. for (const fields of Object.values(this._fieldObjects)) {
  838. for (const field of fields) {
  839. if (fieldIds.has(field.id) === include) {
  840. allFields.push(field);
  841. }
  842. }
  843. }
  844. } else {
  845. for (const fields of Object.values(this._fieldObjects)) {
  846. allFields.push(...fields);
  847. }
  848. }
  849. const storage = this.annotationStorage;
  850. const allIds = [];
  851. for (const field of allFields) {
  852. const {
  853. id
  854. } = field;
  855. allIds.push(id);
  856. switch (field.type) {
  857. case "text":
  858. {
  859. const value = field.defaultValue || "";
  860. storage.setValue(id, {
  861. value
  862. });
  863. break;
  864. }
  865. case "checkbox":
  866. case "radiobutton":
  867. {
  868. const value = field.defaultValue === field.exportValues;
  869. storage.setValue(id, {
  870. value
  871. });
  872. break;
  873. }
  874. case "combobox":
  875. case "listbox":
  876. {
  877. const value = field.defaultValue || "";
  878. storage.setValue(id, {
  879. value
  880. });
  881. break;
  882. }
  883. default:
  884. continue;
  885. }
  886. const domElement = document.querySelector(`[data-element-id="${id}"]`);
  887. if (!domElement) {
  888. continue;
  889. } else if (!GetElementsByNameSet.has(domElement)) {
  890. (0,util.warn)(`_bindResetFormAction - element not allowed: ${id}`);
  891. continue;
  892. }
  893. domElement.dispatchEvent(new Event("resetform"));
  894. }
  895. if (this.enableScripting) {
  896. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  897. source: this,
  898. detail: {
  899. id: "app",
  900. ids: allIds,
  901. name: "ResetForm"
  902. }
  903. });
  904. }
  905. return false;
  906. };
  907. }
  908. }
  909. class TextAnnotationElement extends AnnotationElement {
  910. constructor(parameters) {
  911. super(parameters, {
  912. isRenderable: true
  913. });
  914. }
  915. render() {
  916. this.container.classList.add("textAnnotation");
  917. const image = document.createElement("img");
  918. image.src = this.imageResourcesPath + "annotation-" + this.data.name.toLowerCase() + ".svg";
  919. image.setAttribute("data-l10n-id", "pdfjs-text-annotation-type");
  920. image.setAttribute("data-l10n-args", JSON.stringify({
  921. type: this.data.name
  922. }));
  923. if (!this.data.popupRef && this.hasPopupData) {
  924. this._createPopup();
  925. }
  926. this.container.append(image);
  927. return this.container;
  928. }
  929. }
  930. class WidgetAnnotationElement extends AnnotationElement {
  931. render() {
  932. return this.container;
  933. }
  934. showElementAndHideCanvas(element) {
  935. if (this.data.hasOwnCanvas) {
  936. if (element.previousSibling?.nodeName === "CANVAS") {
  937. element.previousSibling.hidden = true;
  938. }
  939. element.hidden = false;
  940. }
  941. }
  942. _getKeyModifier(event) {
  943. return util.FeatureTest.platform.isMac ? event.metaKey : event.ctrlKey;
  944. }
  945. _setEventListener(element, elementData, baseName, eventName, valueGetter) {
  946. if (baseName.includes("mouse")) {
  947. element.addEventListener(baseName, event => {
  948. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  949. source: this,
  950. detail: {
  951. id: this.data.id,
  952. name: eventName,
  953. value: valueGetter(event),
  954. shift: event.shiftKey,
  955. modifier: this._getKeyModifier(event)
  956. }
  957. });
  958. });
  959. } else {
  960. element.addEventListener(baseName, event => {
  961. if (baseName === "blur") {
  962. if (!elementData.focused || !event.relatedTarget) {
  963. return;
  964. }
  965. elementData.focused = false;
  966. } else if (baseName === "focus") {
  967. if (elementData.focused) {
  968. return;
  969. }
  970. elementData.focused = true;
  971. }
  972. if (!valueGetter) {
  973. return;
  974. }
  975. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  976. source: this,
  977. detail: {
  978. id: this.data.id,
  979. name: eventName,
  980. value: valueGetter(event)
  981. }
  982. });
  983. });
  984. }
  985. }
  986. _setEventListeners(element, elementData, names, getter) {
  987. for (const [baseName, eventName] of names) {
  988. if (eventName === "Action" || this.data.actions?.[eventName]) {
  989. if (eventName === "Focus" || eventName === "Blur") {
  990. elementData ||= {
  991. focused: false
  992. };
  993. }
  994. this._setEventListener(element, elementData, baseName, eventName, getter);
  995. if (eventName === "Focus" && !this.data.actions?.Blur) {
  996. this._setEventListener(element, elementData, "blur", "Blur", null);
  997. } else if (eventName === "Blur" && !this.data.actions?.Focus) {
  998. this._setEventListener(element, elementData, "focus", "Focus", null);
  999. }
  1000. }
  1001. }
  1002. }
  1003. _setBackgroundColor(element) {
  1004. const color = this.data.backgroundColor || null;
  1005. element.style.backgroundColor = color === null ? "transparent" : util.Util.makeHexColor(color[0], color[1], color[2]);
  1006. }
  1007. _setTextStyle(element) {
  1008. const TEXT_ALIGNMENT = ["left", "center", "right"];
  1009. const {
  1010. fontColor
  1011. } = this.data.defaultAppearanceData;
  1012. const fontSize = this.data.defaultAppearanceData.fontSize || DEFAULT_FONT_SIZE;
  1013. const style = element.style;
  1014. let computedFontSize;
  1015. const BORDER_SIZE = 2;
  1016. const roundToOneDecimal = x => Math.round(10 * x) / 10;
  1017. if (this.data.multiLine) {
  1018. const height = Math.abs(this.data.rect[3] - this.data.rect[1] - BORDER_SIZE);
  1019. const numberOfLines = Math.round(height / (util.LINE_FACTOR * fontSize)) || 1;
  1020. const lineHeight = height / numberOfLines;
  1021. computedFontSize = Math.min(fontSize, roundToOneDecimal(lineHeight / util.LINE_FACTOR));
  1022. } else {
  1023. const height = Math.abs(this.data.rect[3] - this.data.rect[1] - BORDER_SIZE);
  1024. computedFontSize = Math.min(fontSize, roundToOneDecimal(height / util.LINE_FACTOR));
  1025. }
  1026. style.fontSize = `calc(${computedFontSize}px * var(--scale-factor))`;
  1027. style.color = util.Util.makeHexColor(fontColor[0], fontColor[1], fontColor[2]);
  1028. if (this.data.textAlignment !== null) {
  1029. style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
  1030. }
  1031. }
  1032. _setRequired(element, isRequired) {
  1033. if (isRequired) {
  1034. element.setAttribute("required", true);
  1035. } else {
  1036. element.removeAttribute("required");
  1037. }
  1038. element.setAttribute("aria-required", isRequired);
  1039. }
  1040. }
  1041. class TextWidgetAnnotationElement extends WidgetAnnotationElement {
  1042. constructor(parameters) {
  1043. const isRenderable = parameters.renderForms || parameters.data.hasOwnCanvas || !parameters.data.hasAppearance && !!parameters.data.fieldValue;
  1044. super(parameters, {
  1045. isRenderable
  1046. });
  1047. }
  1048. setPropertyOnSiblings(base, key, value, keyInStorage) {
  1049. const storage = this.annotationStorage;
  1050. for (const element of this._getElementsByName(base.name, base.id)) {
  1051. if (element.domElement) {
  1052. element.domElement[key] = value;
  1053. }
  1054. storage.setValue(element.id, {
  1055. [keyInStorage]: value
  1056. });
  1057. }
  1058. }
  1059. render() {
  1060. const storage = this.annotationStorage;
  1061. const id = this.data.id;
  1062. this.container.classList.add("textWidgetAnnotation");
  1063. let element = null;
  1064. if (this.renderForms) {
  1065. const storedData = storage.getValue(id, {
  1066. value: this.data.fieldValue
  1067. });
  1068. let textContent = storedData.value || "";
  1069. const maxLen = storage.getValue(id, {
  1070. charLimit: this.data.maxLen
  1071. }).charLimit;
  1072. if (maxLen && textContent.length > maxLen) {
  1073. textContent = textContent.slice(0, maxLen);
  1074. }
  1075. let fieldFormattedValues = storedData.formattedValue || this.data.textContent?.join("\n") || null;
  1076. if (fieldFormattedValues && this.data.comb) {
  1077. fieldFormattedValues = fieldFormattedValues.replaceAll(/\s+/g, "");
  1078. }
  1079. const elementData = {
  1080. userValue: textContent,
  1081. formattedValue: fieldFormattedValues,
  1082. lastCommittedValue: null,
  1083. commitKey: 1,
  1084. focused: false
  1085. };
  1086. if (this.data.multiLine) {
  1087. element = document.createElement("textarea");
  1088. element.textContent = fieldFormattedValues ?? textContent;
  1089. if (this.data.doNotScroll) {
  1090. element.style.overflowY = "hidden";
  1091. }
  1092. } else {
  1093. element = document.createElement("input");
  1094. element.type = "text";
  1095. element.setAttribute("value", fieldFormattedValues ?? textContent);
  1096. if (this.data.doNotScroll) {
  1097. element.style.overflowX = "hidden";
  1098. }
  1099. }
  1100. if (this.data.hasOwnCanvas) {
  1101. element.hidden = true;
  1102. }
  1103. GetElementsByNameSet.add(element);
  1104. element.setAttribute("data-element-id", id);
  1105. element.disabled = this.data.readOnly;
  1106. element.name = this.data.fieldName;
  1107. element.tabIndex = DEFAULT_TAB_INDEX;
  1108. this._setRequired(element, this.data.required);
  1109. if (maxLen) {
  1110. element.maxLength = maxLen;
  1111. }
  1112. element.addEventListener("input", event => {
  1113. storage.setValue(id, {
  1114. value: event.target.value
  1115. });
  1116. this.setPropertyOnSiblings(element, "value", event.target.value, "value");
  1117. elementData.formattedValue = null;
  1118. });
  1119. element.addEventListener("resetform", event => {
  1120. const defaultValue = this.data.defaultFieldValue ?? "";
  1121. element.value = elementData.userValue = defaultValue;
  1122. elementData.formattedValue = null;
  1123. });
  1124. let blurListener = event => {
  1125. const {
  1126. formattedValue
  1127. } = elementData;
  1128. if (formattedValue !== null && formattedValue !== undefined) {
  1129. event.target.value = formattedValue;
  1130. }
  1131. event.target.scrollLeft = 0;
  1132. };
  1133. if (this.enableScripting && this.hasJSActions) {
  1134. element.addEventListener("focus", event => {
  1135. if (elementData.focused) {
  1136. return;
  1137. }
  1138. const {
  1139. target
  1140. } = event;
  1141. if (elementData.userValue) {
  1142. target.value = elementData.userValue;
  1143. }
  1144. elementData.lastCommittedValue = target.value;
  1145. elementData.commitKey = 1;
  1146. if (!this.data.actions?.Focus) {
  1147. elementData.focused = true;
  1148. }
  1149. });
  1150. element.addEventListener("updatefromsandbox", jsEvent => {
  1151. this.showElementAndHideCanvas(jsEvent.target);
  1152. const actions = {
  1153. value(event) {
  1154. elementData.userValue = event.detail.value ?? "";
  1155. storage.setValue(id, {
  1156. value: elementData.userValue.toString()
  1157. });
  1158. event.target.value = elementData.userValue;
  1159. },
  1160. formattedValue(event) {
  1161. const {
  1162. formattedValue
  1163. } = event.detail;
  1164. elementData.formattedValue = formattedValue;
  1165. if (formattedValue !== null && formattedValue !== undefined && event.target !== document.activeElement) {
  1166. event.target.value = formattedValue;
  1167. }
  1168. storage.setValue(id, {
  1169. formattedValue
  1170. });
  1171. },
  1172. selRange(event) {
  1173. event.target.setSelectionRange(...event.detail.selRange);
  1174. },
  1175. charLimit: event => {
  1176. const {
  1177. charLimit
  1178. } = event.detail;
  1179. const {
  1180. target
  1181. } = event;
  1182. if (charLimit === 0) {
  1183. target.removeAttribute("maxLength");
  1184. return;
  1185. }
  1186. target.setAttribute("maxLength", charLimit);
  1187. let value = elementData.userValue;
  1188. if (!value || value.length <= charLimit) {
  1189. return;
  1190. }
  1191. value = value.slice(0, charLimit);
  1192. target.value = elementData.userValue = value;
  1193. storage.setValue(id, {
  1194. value
  1195. });
  1196. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  1197. source: this,
  1198. detail: {
  1199. id,
  1200. name: "Keystroke",
  1201. value,
  1202. willCommit: true,
  1203. commitKey: 1,
  1204. selStart: target.selectionStart,
  1205. selEnd: target.selectionEnd
  1206. }
  1207. });
  1208. }
  1209. };
  1210. this._dispatchEventFromSandbox(actions, jsEvent);
  1211. });
  1212. element.addEventListener("keydown", event => {
  1213. elementData.commitKey = 1;
  1214. let commitKey = -1;
  1215. if (event.key === "Escape") {
  1216. commitKey = 0;
  1217. } else if (event.key === "Enter" && !this.data.multiLine) {
  1218. commitKey = 2;
  1219. } else if (event.key === "Tab") {
  1220. elementData.commitKey = 3;
  1221. }
  1222. if (commitKey === -1) {
  1223. return;
  1224. }
  1225. const {
  1226. value
  1227. } = event.target;
  1228. if (elementData.lastCommittedValue === value) {
  1229. return;
  1230. }
  1231. elementData.lastCommittedValue = value;
  1232. elementData.userValue = value;
  1233. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  1234. source: this,
  1235. detail: {
  1236. id,
  1237. name: "Keystroke",
  1238. value,
  1239. willCommit: true,
  1240. commitKey,
  1241. selStart: event.target.selectionStart,
  1242. selEnd: event.target.selectionEnd
  1243. }
  1244. });
  1245. });
  1246. const _blurListener = blurListener;
  1247. blurListener = null;
  1248. element.addEventListener("blur", event => {
  1249. if (!elementData.focused || !event.relatedTarget) {
  1250. return;
  1251. }
  1252. if (!this.data.actions?.Blur) {
  1253. elementData.focused = false;
  1254. }
  1255. const {
  1256. value
  1257. } = event.target;
  1258. elementData.userValue = value;
  1259. if (elementData.lastCommittedValue !== value) {
  1260. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  1261. source: this,
  1262. detail: {
  1263. id,
  1264. name: "Keystroke",
  1265. value,
  1266. willCommit: true,
  1267. commitKey: elementData.commitKey,
  1268. selStart: event.target.selectionStart,
  1269. selEnd: event.target.selectionEnd
  1270. }
  1271. });
  1272. }
  1273. _blurListener(event);
  1274. });
  1275. if (this.data.actions?.Keystroke) {
  1276. element.addEventListener("beforeinput", event => {
  1277. elementData.lastCommittedValue = null;
  1278. const {
  1279. data,
  1280. target
  1281. } = event;
  1282. const {
  1283. value,
  1284. selectionStart,
  1285. selectionEnd
  1286. } = target;
  1287. let selStart = selectionStart,
  1288. selEnd = selectionEnd;
  1289. switch (event.inputType) {
  1290. case "deleteWordBackward":
  1291. {
  1292. const match = value.substring(0, selectionStart).match(/\w*[^\w]*$/);
  1293. if (match) {
  1294. selStart -= match[0].length;
  1295. }
  1296. break;
  1297. }
  1298. case "deleteWordForward":
  1299. {
  1300. const match = value.substring(selectionStart).match(/^[^\w]*\w*/);
  1301. if (match) {
  1302. selEnd += match[0].length;
  1303. }
  1304. break;
  1305. }
  1306. case "deleteContentBackward":
  1307. if (selectionStart === selectionEnd) {
  1308. selStart -= 1;
  1309. }
  1310. break;
  1311. case "deleteContentForward":
  1312. if (selectionStart === selectionEnd) {
  1313. selEnd += 1;
  1314. }
  1315. break;
  1316. }
  1317. event.preventDefault();
  1318. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  1319. source: this,
  1320. detail: {
  1321. id,
  1322. name: "Keystroke",
  1323. value,
  1324. change: data || "",
  1325. willCommit: false,
  1326. selStart,
  1327. selEnd
  1328. }
  1329. });
  1330. });
  1331. }
  1332. this._setEventListeners(element, elementData, [["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"]], event => event.target.value);
  1333. }
  1334. if (blurListener) {
  1335. element.addEventListener("blur", blurListener);
  1336. }
  1337. if (this.data.comb) {
  1338. const fieldWidth = this.data.rect[2] - this.data.rect[0];
  1339. const combWidth = fieldWidth / maxLen;
  1340. element.classList.add("comb");
  1341. element.style.letterSpacing = `calc(${combWidth}px * var(--scale-factor) - 1ch)`;
  1342. }
  1343. } else {
  1344. element = document.createElement("div");
  1345. element.textContent = this.data.fieldValue;
  1346. element.style.verticalAlign = "middle";
  1347. element.style.display = "table-cell";
  1348. if (this.data.hasOwnCanvas) {
  1349. element.hidden = true;
  1350. }
  1351. }
  1352. this._setTextStyle(element);
  1353. this._setBackgroundColor(element);
  1354. this._setDefaultPropertiesFromJS(element);
  1355. this.container.append(element);
  1356. return this.container;
  1357. }
  1358. }
  1359. class SignatureWidgetAnnotationElement extends WidgetAnnotationElement {
  1360. constructor(parameters) {
  1361. super(parameters, {
  1362. isRenderable: !!parameters.data.hasOwnCanvas
  1363. });
  1364. }
  1365. }
  1366. class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement {
  1367. constructor(parameters) {
  1368. super(parameters, {
  1369. isRenderable: parameters.renderForms
  1370. });
  1371. }
  1372. render() {
  1373. const storage = this.annotationStorage;
  1374. const data = this.data;
  1375. const id = data.id;
  1376. let value = storage.getValue(id, {
  1377. value: data.exportValue === data.fieldValue
  1378. }).value;
  1379. if (typeof value === "string") {
  1380. value = value !== "Off";
  1381. storage.setValue(id, {
  1382. value
  1383. });
  1384. }
  1385. this.container.classList.add("buttonWidgetAnnotation", "checkBox");
  1386. const element = document.createElement("input");
  1387. GetElementsByNameSet.add(element);
  1388. element.setAttribute("data-element-id", id);
  1389. element.disabled = data.readOnly;
  1390. this._setRequired(element, this.data.required);
  1391. element.type = "checkbox";
  1392. element.name = data.fieldName;
  1393. if (value) {
  1394. element.setAttribute("checked", true);
  1395. }
  1396. element.setAttribute("exportValue", data.exportValue);
  1397. element.tabIndex = DEFAULT_TAB_INDEX;
  1398. element.addEventListener("change", event => {
  1399. const {
  1400. name,
  1401. checked
  1402. } = event.target;
  1403. for (const checkbox of this._getElementsByName(name, id)) {
  1404. const curChecked = checked && checkbox.exportValue === data.exportValue;
  1405. if (checkbox.domElement) {
  1406. checkbox.domElement.checked = curChecked;
  1407. }
  1408. storage.setValue(checkbox.id, {
  1409. value: curChecked
  1410. });
  1411. }
  1412. storage.setValue(id, {
  1413. value: checked
  1414. });
  1415. });
  1416. element.addEventListener("resetform", event => {
  1417. const defaultValue = data.defaultFieldValue || "Off";
  1418. event.target.checked = defaultValue === data.exportValue;
  1419. });
  1420. if (this.enableScripting && this.hasJSActions) {
  1421. element.addEventListener("updatefromsandbox", jsEvent => {
  1422. const actions = {
  1423. value(event) {
  1424. event.target.checked = event.detail.value !== "Off";
  1425. storage.setValue(id, {
  1426. value: event.target.checked
  1427. });
  1428. }
  1429. };
  1430. this._dispatchEventFromSandbox(actions, jsEvent);
  1431. });
  1432. 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);
  1433. }
  1434. this._setBackgroundColor(element);
  1435. this._setDefaultPropertiesFromJS(element);
  1436. this.container.append(element);
  1437. return this.container;
  1438. }
  1439. }
  1440. class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
  1441. constructor(parameters) {
  1442. super(parameters, {
  1443. isRenderable: parameters.renderForms
  1444. });
  1445. }
  1446. render() {
  1447. this.container.classList.add("buttonWidgetAnnotation", "radioButton");
  1448. const storage = this.annotationStorage;
  1449. const data = this.data;
  1450. const id = data.id;
  1451. let value = storage.getValue(id, {
  1452. value: data.fieldValue === data.buttonValue
  1453. }).value;
  1454. if (typeof value === "string") {
  1455. value = value !== data.buttonValue;
  1456. storage.setValue(id, {
  1457. value
  1458. });
  1459. }
  1460. if (value) {
  1461. for (const radio of this._getElementsByName(data.fieldName, id)) {
  1462. storage.setValue(radio.id, {
  1463. value: false
  1464. });
  1465. }
  1466. }
  1467. const element = document.createElement("input");
  1468. GetElementsByNameSet.add(element);
  1469. element.setAttribute("data-element-id", id);
  1470. element.disabled = data.readOnly;
  1471. this._setRequired(element, this.data.required);
  1472. element.type = "radio";
  1473. element.name = data.fieldName;
  1474. if (value) {
  1475. element.setAttribute("checked", true);
  1476. }
  1477. element.tabIndex = DEFAULT_TAB_INDEX;
  1478. element.addEventListener("change", event => {
  1479. const {
  1480. name,
  1481. checked
  1482. } = event.target;
  1483. for (const radio of this._getElementsByName(name, id)) {
  1484. storage.setValue(radio.id, {
  1485. value: false
  1486. });
  1487. }
  1488. storage.setValue(id, {
  1489. value: checked
  1490. });
  1491. });
  1492. element.addEventListener("resetform", event => {
  1493. const defaultValue = data.defaultFieldValue;
  1494. event.target.checked = defaultValue !== null && defaultValue !== undefined && defaultValue === data.buttonValue;
  1495. });
  1496. if (this.enableScripting && this.hasJSActions) {
  1497. const pdfButtonValue = data.buttonValue;
  1498. element.addEventListener("updatefromsandbox", jsEvent => {
  1499. const actions = {
  1500. value: event => {
  1501. const checked = pdfButtonValue === event.detail.value;
  1502. for (const radio of this._getElementsByName(event.target.name)) {
  1503. const curChecked = checked && radio.id === id;
  1504. if (radio.domElement) {
  1505. radio.domElement.checked = curChecked;
  1506. }
  1507. storage.setValue(radio.id, {
  1508. value: curChecked
  1509. });
  1510. }
  1511. }
  1512. };
  1513. this._dispatchEventFromSandbox(actions, jsEvent);
  1514. });
  1515. 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);
  1516. }
  1517. this._setBackgroundColor(element);
  1518. this._setDefaultPropertiesFromJS(element);
  1519. this.container.append(element);
  1520. return this.container;
  1521. }
  1522. }
  1523. class PushButtonWidgetAnnotationElement extends LinkAnnotationElement {
  1524. constructor(parameters) {
  1525. super(parameters, {
  1526. ignoreBorder: parameters.data.hasAppearance
  1527. });
  1528. }
  1529. render() {
  1530. const container = super.render();
  1531. container.classList.add("buttonWidgetAnnotation", "pushButton");
  1532. const linkElement = container.lastChild;
  1533. if (this.enableScripting && this.hasJSActions && linkElement) {
  1534. this._setDefaultPropertiesFromJS(linkElement);
  1535. linkElement.addEventListener("updatefromsandbox", jsEvent => {
  1536. this._dispatchEventFromSandbox({}, jsEvent);
  1537. });
  1538. }
  1539. return container;
  1540. }
  1541. }
  1542. class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
  1543. constructor(parameters) {
  1544. super(parameters, {
  1545. isRenderable: parameters.renderForms
  1546. });
  1547. }
  1548. render() {
  1549. this.container.classList.add("choiceWidgetAnnotation");
  1550. const storage = this.annotationStorage;
  1551. const id = this.data.id;
  1552. const storedData = storage.getValue(id, {
  1553. value: this.data.fieldValue
  1554. });
  1555. const selectElement = document.createElement("select");
  1556. GetElementsByNameSet.add(selectElement);
  1557. selectElement.setAttribute("data-element-id", id);
  1558. selectElement.disabled = this.data.readOnly;
  1559. this._setRequired(selectElement, this.data.required);
  1560. selectElement.name = this.data.fieldName;
  1561. selectElement.tabIndex = DEFAULT_TAB_INDEX;
  1562. let addAnEmptyEntry = this.data.combo && this.data.options.length > 0;
  1563. if (!this.data.combo) {
  1564. selectElement.size = this.data.options.length;
  1565. if (this.data.multiSelect) {
  1566. selectElement.multiple = true;
  1567. }
  1568. }
  1569. selectElement.addEventListener("resetform", event => {
  1570. const defaultValue = this.data.defaultFieldValue;
  1571. for (const option of selectElement.options) {
  1572. option.selected = option.value === defaultValue;
  1573. }
  1574. });
  1575. for (const option of this.data.options) {
  1576. const optionElement = document.createElement("option");
  1577. optionElement.textContent = option.displayValue;
  1578. optionElement.value = option.exportValue;
  1579. if (storedData.value.includes(option.exportValue)) {
  1580. optionElement.setAttribute("selected", true);
  1581. addAnEmptyEntry = false;
  1582. }
  1583. selectElement.append(optionElement);
  1584. }
  1585. let removeEmptyEntry = null;
  1586. if (addAnEmptyEntry) {
  1587. const noneOptionElement = document.createElement("option");
  1588. noneOptionElement.value = " ";
  1589. noneOptionElement.setAttribute("hidden", true);
  1590. noneOptionElement.setAttribute("selected", true);
  1591. selectElement.prepend(noneOptionElement);
  1592. removeEmptyEntry = () => {
  1593. noneOptionElement.remove();
  1594. selectElement.removeEventListener("input", removeEmptyEntry);
  1595. removeEmptyEntry = null;
  1596. };
  1597. selectElement.addEventListener("input", removeEmptyEntry);
  1598. }
  1599. const getValue = isExport => {
  1600. const name = isExport ? "value" : "textContent";
  1601. const {
  1602. options,
  1603. multiple
  1604. } = selectElement;
  1605. if (!multiple) {
  1606. return options.selectedIndex === -1 ? null : options[options.selectedIndex][name];
  1607. }
  1608. return Array.prototype.filter.call(options, option => option.selected).map(option => option[name]);
  1609. };
  1610. let selectedValues = getValue(false);
  1611. const getItems = event => {
  1612. const options = event.target.options;
  1613. return Array.prototype.map.call(options, option => ({
  1614. displayValue: option.textContent,
  1615. exportValue: option.value
  1616. }));
  1617. };
  1618. if (this.enableScripting && this.hasJSActions) {
  1619. selectElement.addEventListener("updatefromsandbox", jsEvent => {
  1620. const actions = {
  1621. value(event) {
  1622. removeEmptyEntry?.();
  1623. const value = event.detail.value;
  1624. const values = new Set(Array.isArray(value) ? value : [value]);
  1625. for (const option of selectElement.options) {
  1626. option.selected = values.has(option.value);
  1627. }
  1628. storage.setValue(id, {
  1629. value: getValue(true)
  1630. });
  1631. selectedValues = getValue(false);
  1632. },
  1633. multipleSelection(event) {
  1634. selectElement.multiple = true;
  1635. },
  1636. remove(event) {
  1637. const options = selectElement.options;
  1638. const index = event.detail.remove;
  1639. options[index].selected = false;
  1640. selectElement.remove(index);
  1641. if (options.length > 0) {
  1642. const i = Array.prototype.findIndex.call(options, option => option.selected);
  1643. if (i === -1) {
  1644. options[0].selected = true;
  1645. }
  1646. }
  1647. storage.setValue(id, {
  1648. value: getValue(true),
  1649. items: getItems(event)
  1650. });
  1651. selectedValues = getValue(false);
  1652. },
  1653. clear(event) {
  1654. while (selectElement.length !== 0) {
  1655. selectElement.remove(0);
  1656. }
  1657. storage.setValue(id, {
  1658. value: null,
  1659. items: []
  1660. });
  1661. selectedValues = getValue(false);
  1662. },
  1663. insert(event) {
  1664. const {
  1665. index,
  1666. displayValue,
  1667. exportValue
  1668. } = event.detail.insert;
  1669. const selectChild = selectElement.children[index];
  1670. const optionElement = document.createElement("option");
  1671. optionElement.textContent = displayValue;
  1672. optionElement.value = exportValue;
  1673. if (selectChild) {
  1674. selectChild.before(optionElement);
  1675. } else {
  1676. selectElement.append(optionElement);
  1677. }
  1678. storage.setValue(id, {
  1679. value: getValue(true),
  1680. items: getItems(event)
  1681. });
  1682. selectedValues = getValue(false);
  1683. },
  1684. items(event) {
  1685. const {
  1686. items
  1687. } = event.detail;
  1688. while (selectElement.length !== 0) {
  1689. selectElement.remove(0);
  1690. }
  1691. for (const item of items) {
  1692. const {
  1693. displayValue,
  1694. exportValue
  1695. } = item;
  1696. const optionElement = document.createElement("option");
  1697. optionElement.textContent = displayValue;
  1698. optionElement.value = exportValue;
  1699. selectElement.append(optionElement);
  1700. }
  1701. if (selectElement.options.length > 0) {
  1702. selectElement.options[0].selected = true;
  1703. }
  1704. storage.setValue(id, {
  1705. value: getValue(true),
  1706. items: getItems(event)
  1707. });
  1708. selectedValues = getValue(false);
  1709. },
  1710. indices(event) {
  1711. const indices = new Set(event.detail.indices);
  1712. for (const option of event.target.options) {
  1713. option.selected = indices.has(option.index);
  1714. }
  1715. storage.setValue(id, {
  1716. value: getValue(true)
  1717. });
  1718. selectedValues = getValue(false);
  1719. },
  1720. editable(event) {
  1721. event.target.disabled = !event.detail.editable;
  1722. }
  1723. };
  1724. this._dispatchEventFromSandbox(actions, jsEvent);
  1725. });
  1726. selectElement.addEventListener("input", event => {
  1727. const exportValue = getValue(true);
  1728. const change = getValue(false);
  1729. storage.setValue(id, {
  1730. value: exportValue
  1731. });
  1732. event.preventDefault();
  1733. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  1734. source: this,
  1735. detail: {
  1736. id,
  1737. name: "Keystroke",
  1738. value: selectedValues,
  1739. change,
  1740. changeEx: exportValue,
  1741. willCommit: false,
  1742. commitKey: 1,
  1743. keyDown: false
  1744. }
  1745. });
  1746. });
  1747. 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);
  1748. } else {
  1749. selectElement.addEventListener("input", function (event) {
  1750. storage.setValue(id, {
  1751. value: getValue(true)
  1752. });
  1753. });
  1754. }
  1755. if (this.data.combo) {
  1756. this._setTextStyle(selectElement);
  1757. } else {}
  1758. this._setBackgroundColor(selectElement);
  1759. this._setDefaultPropertiesFromJS(selectElement);
  1760. this.container.append(selectElement);
  1761. return this.container;
  1762. }
  1763. }
  1764. class PopupAnnotationElement extends AnnotationElement {
  1765. constructor(parameters) {
  1766. const {
  1767. data,
  1768. elements
  1769. } = parameters;
  1770. super(parameters, {
  1771. isRenderable: AnnotationElement._hasPopupData(data)
  1772. });
  1773. this.elements = elements;
  1774. }
  1775. render() {
  1776. this.container.classList.add("popupAnnotation");
  1777. const popup = new PopupElement({
  1778. container: this.container,
  1779. color: this.data.color,
  1780. titleObj: this.data.titleObj,
  1781. modificationDate: this.data.modificationDate,
  1782. contentsObj: this.data.contentsObj,
  1783. richText: this.data.richText,
  1784. rect: this.data.rect,
  1785. parentRect: this.data.parentRect || null,
  1786. parent: this.parent,
  1787. elements: this.elements,
  1788. open: this.data.open
  1789. });
  1790. const elementIds = [];
  1791. for (const element of this.elements) {
  1792. element.popup = popup;
  1793. elementIds.push(element.data.id);
  1794. element.addHighlightArea();
  1795. }
  1796. this.container.setAttribute("aria-controls", elementIds.map(id => `${util.AnnotationPrefix}${id}`).join(","));
  1797. return this.container;
  1798. }
  1799. }
  1800. class PopupElement {
  1801. #boundKeyDown = this.#keyDown.bind(this);
  1802. #boundHide = this.#hide.bind(this);
  1803. #boundShow = this.#show.bind(this);
  1804. #boundToggle = this.#toggle.bind(this);
  1805. #color = null;
  1806. #container = null;
  1807. #contentsObj = null;
  1808. #dateObj = null;
  1809. #elements = null;
  1810. #parent = null;
  1811. #parentRect = null;
  1812. #pinned = false;
  1813. #popup = null;
  1814. #rect = null;
  1815. #richText = null;
  1816. #titleObj = null;
  1817. #wasVisible = false;
  1818. constructor({
  1819. container,
  1820. color,
  1821. elements,
  1822. titleObj,
  1823. modificationDate,
  1824. contentsObj,
  1825. richText,
  1826. parent,
  1827. rect,
  1828. parentRect,
  1829. open
  1830. }) {
  1831. this.#container = container;
  1832. this.#titleObj = titleObj;
  1833. this.#contentsObj = contentsObj;
  1834. this.#richText = richText;
  1835. this.#parent = parent;
  1836. this.#color = color;
  1837. this.#rect = rect;
  1838. this.#parentRect = parentRect;
  1839. this.#elements = elements;
  1840. this.#dateObj = display_utils.PDFDateString.toDateObject(modificationDate);
  1841. this.trigger = elements.flatMap(e => e.getElementsToTriggerPopup());
  1842. for (const element of this.trigger) {
  1843. element.addEventListener("click", this.#boundToggle);
  1844. element.addEventListener("mouseenter", this.#boundShow);
  1845. element.addEventListener("mouseleave", this.#boundHide);
  1846. element.classList.add("popupTriggerArea");
  1847. }
  1848. for (const element of elements) {
  1849. element.container?.addEventListener("keydown", this.#boundKeyDown);
  1850. }
  1851. this.#container.hidden = true;
  1852. if (open) {
  1853. this.#toggle();
  1854. }
  1855. }
  1856. render() {
  1857. if (this.#popup) {
  1858. return;
  1859. }
  1860. const {
  1861. page: {
  1862. view
  1863. },
  1864. viewport: {
  1865. rawDims: {
  1866. pageWidth,
  1867. pageHeight,
  1868. pageX,
  1869. pageY
  1870. }
  1871. }
  1872. } = this.#parent;
  1873. const popup = this.#popup = document.createElement("div");
  1874. popup.className = "popup";
  1875. if (this.#color) {
  1876. const baseColor = popup.style.outlineColor = util.Util.makeHexColor(...this.#color);
  1877. if (CSS.supports("background-color", "color-mix(in srgb, red 30%, white)")) {
  1878. popup.style.backgroundColor = `color-mix(in srgb, ${baseColor} 30%, white)`;
  1879. } else {
  1880. const BACKGROUND_ENLIGHT = 0.7;
  1881. popup.style.backgroundColor = util.Util.makeHexColor(...this.#color.map(c => Math.floor(BACKGROUND_ENLIGHT * (255 - c) + c)));
  1882. }
  1883. }
  1884. const header = document.createElement("span");
  1885. header.className = "header";
  1886. const title = document.createElement("h1");
  1887. header.append(title);
  1888. ({
  1889. dir: title.dir,
  1890. str: title.textContent
  1891. } = this.#titleObj);
  1892. popup.append(header);
  1893. if (this.#dateObj) {
  1894. const modificationDate = document.createElement("span");
  1895. modificationDate.classList.add("popupDate");
  1896. modificationDate.setAttribute("data-l10n-id", "pdfjs-annotation-date-string");
  1897. modificationDate.setAttribute("data-l10n-args", JSON.stringify({
  1898. date: this.#dateObj.toLocaleDateString(),
  1899. time: this.#dateObj.toLocaleTimeString()
  1900. }));
  1901. header.append(modificationDate);
  1902. }
  1903. const contentsObj = this.#contentsObj;
  1904. const richText = this.#richText;
  1905. if (richText?.str && (!contentsObj?.str || contentsObj.str === richText.str)) {
  1906. xfa_layer.XfaLayer.render({
  1907. xfaHtml: richText.html,
  1908. intent: "richText",
  1909. div: popup
  1910. });
  1911. popup.lastChild.classList.add("richText", "popupContent");
  1912. } else {
  1913. const contents = this._formatContents(contentsObj);
  1914. popup.append(contents);
  1915. }
  1916. let useParentRect = !!this.#parentRect;
  1917. let rect = useParentRect ? this.#parentRect : this.#rect;
  1918. for (const element of this.#elements) {
  1919. if (!rect || util.Util.intersect(element.data.rect, rect) !== null) {
  1920. rect = element.data.rect;
  1921. useParentRect = true;
  1922. break;
  1923. }
  1924. }
  1925. const normalizedRect = util.Util.normalizeRect([rect[0], view[3] - rect[1] + view[1], rect[2], view[3] - rect[3] + view[1]]);
  1926. const HORIZONTAL_SPACE_AFTER_ANNOTATION = 5;
  1927. const parentWidth = useParentRect ? rect[2] - rect[0] + HORIZONTAL_SPACE_AFTER_ANNOTATION : 0;
  1928. const popupLeft = normalizedRect[0] + parentWidth;
  1929. const popupTop = normalizedRect[1];
  1930. const {
  1931. style
  1932. } = this.#container;
  1933. style.left = `${100 * (popupLeft - pageX) / pageWidth}%`;
  1934. style.top = `${100 * (popupTop - pageY) / pageHeight}%`;
  1935. this.#container.append(popup);
  1936. }
  1937. _formatContents({
  1938. str,
  1939. dir
  1940. }) {
  1941. const p = document.createElement("p");
  1942. p.classList.add("popupContent");
  1943. p.dir = dir;
  1944. const lines = str.split(/(?:\r\n?|\n)/);
  1945. for (let i = 0, ii = lines.length; i < ii; ++i) {
  1946. const line = lines[i];
  1947. p.append(document.createTextNode(line));
  1948. if (i < ii - 1) {
  1949. p.append(document.createElement("br"));
  1950. }
  1951. }
  1952. return p;
  1953. }
  1954. #keyDown(event) {
  1955. if (event.altKey || event.shiftKey || event.ctrlKey || event.metaKey) {
  1956. return;
  1957. }
  1958. if (event.key === "Enter" || event.key === "Escape" && this.#pinned) {
  1959. this.#toggle();
  1960. }
  1961. }
  1962. #toggle() {
  1963. this.#pinned = !this.#pinned;
  1964. if (this.#pinned) {
  1965. this.#show();
  1966. this.#container.addEventListener("click", this.#boundToggle);
  1967. this.#container.addEventListener("keydown", this.#boundKeyDown);
  1968. } else {
  1969. this.#hide();
  1970. this.#container.removeEventListener("click", this.#boundToggle);
  1971. this.#container.removeEventListener("keydown", this.#boundKeyDown);
  1972. }
  1973. }
  1974. #show() {
  1975. if (!this.#popup) {
  1976. this.render();
  1977. }
  1978. if (!this.isVisible) {
  1979. this.#container.hidden = false;
  1980. this.#container.style.zIndex = parseInt(this.#container.style.zIndex) + 1000;
  1981. } else if (this.#pinned) {
  1982. this.#container.classList.add("focused");
  1983. }
  1984. }
  1985. #hide() {
  1986. this.#container.classList.remove("focused");
  1987. if (this.#pinned || !this.isVisible) {
  1988. return;
  1989. }
  1990. this.#container.hidden = true;
  1991. this.#container.style.zIndex = parseInt(this.#container.style.zIndex) - 1000;
  1992. }
  1993. forceHide() {
  1994. this.#wasVisible = this.isVisible;
  1995. if (!this.#wasVisible) {
  1996. return;
  1997. }
  1998. this.#container.hidden = true;
  1999. }
  2000. maybeShow() {
  2001. if (!this.#wasVisible) {
  2002. return;
  2003. }
  2004. this.#wasVisible = false;
  2005. this.#container.hidden = false;
  2006. }
  2007. get isVisible() {
  2008. return this.#container.hidden === false;
  2009. }
  2010. }
  2011. class FreeTextAnnotationElement extends AnnotationElement {
  2012. constructor(parameters) {
  2013. super(parameters, {
  2014. isRenderable: true,
  2015. ignoreBorder: true
  2016. });
  2017. this.textContent = parameters.data.textContent;
  2018. this.textPosition = parameters.data.textPosition;
  2019. this.annotationEditorType = util.AnnotationEditorType.FREETEXT;
  2020. }
  2021. render() {
  2022. this.container.classList.add("freeTextAnnotation");
  2023. if (this.textContent) {
  2024. const content = document.createElement("div");
  2025. content.classList.add("annotationTextContent");
  2026. content.setAttribute("role", "comment");
  2027. for (const line of this.textContent) {
  2028. const lineSpan = document.createElement("span");
  2029. lineSpan.textContent = line;
  2030. content.append(lineSpan);
  2031. }
  2032. this.container.append(content);
  2033. }
  2034. if (!this.data.popupRef && this.hasPopupData) {
  2035. this._createPopup();
  2036. }
  2037. this._editOnDoubleClick();
  2038. return this.container;
  2039. }
  2040. get _isEditable() {
  2041. return this.data.hasOwnCanvas;
  2042. }
  2043. }
  2044. class LineAnnotationElement extends AnnotationElement {
  2045. #line = null;
  2046. constructor(parameters) {
  2047. super(parameters, {
  2048. isRenderable: true,
  2049. ignoreBorder: true
  2050. });
  2051. }
  2052. render() {
  2053. this.container.classList.add("lineAnnotation");
  2054. const data = this.data;
  2055. const {
  2056. width,
  2057. height
  2058. } = getRectDims(data.rect);
  2059. const svg = this.svgFactory.create(width, height, true);
  2060. const line = this.#line = this.svgFactory.createElement("svg:line");
  2061. line.setAttribute("x1", data.rect[2] - data.lineCoordinates[0]);
  2062. line.setAttribute("y1", data.rect[3] - data.lineCoordinates[1]);
  2063. line.setAttribute("x2", data.rect[2] - data.lineCoordinates[2]);
  2064. line.setAttribute("y2", data.rect[3] - data.lineCoordinates[3]);
  2065. line.setAttribute("stroke-width", data.borderStyle.width || 1);
  2066. line.setAttribute("stroke", "transparent");
  2067. line.setAttribute("fill", "transparent");
  2068. svg.append(line);
  2069. this.container.append(svg);
  2070. if (!data.popupRef && this.hasPopupData) {
  2071. this._createPopup();
  2072. }
  2073. return this.container;
  2074. }
  2075. getElementsToTriggerPopup() {
  2076. return this.#line;
  2077. }
  2078. addHighlightArea() {
  2079. this.container.classList.add("highlightArea");
  2080. }
  2081. }
  2082. class SquareAnnotationElement extends AnnotationElement {
  2083. #square = null;
  2084. constructor(parameters) {
  2085. super(parameters, {
  2086. isRenderable: true,
  2087. ignoreBorder: true
  2088. });
  2089. }
  2090. render() {
  2091. this.container.classList.add("squareAnnotation");
  2092. const data = this.data;
  2093. const {
  2094. width,
  2095. height
  2096. } = getRectDims(data.rect);
  2097. const svg = this.svgFactory.create(width, height, true);
  2098. const borderWidth = data.borderStyle.width;
  2099. const square = this.#square = this.svgFactory.createElement("svg:rect");
  2100. square.setAttribute("x", borderWidth / 2);
  2101. square.setAttribute("y", borderWidth / 2);
  2102. square.setAttribute("width", width - borderWidth);
  2103. square.setAttribute("height", height - borderWidth);
  2104. square.setAttribute("stroke-width", borderWidth || 1);
  2105. square.setAttribute("stroke", "transparent");
  2106. square.setAttribute("fill", "transparent");
  2107. svg.append(square);
  2108. this.container.append(svg);
  2109. if (!data.popupRef && this.hasPopupData) {
  2110. this._createPopup();
  2111. }
  2112. return this.container;
  2113. }
  2114. getElementsToTriggerPopup() {
  2115. return this.#square;
  2116. }
  2117. addHighlightArea() {
  2118. this.container.classList.add("highlightArea");
  2119. }
  2120. }
  2121. class CircleAnnotationElement extends AnnotationElement {
  2122. #circle = null;
  2123. constructor(parameters) {
  2124. super(parameters, {
  2125. isRenderable: true,
  2126. ignoreBorder: true
  2127. });
  2128. }
  2129. render() {
  2130. this.container.classList.add("circleAnnotation");
  2131. const data = this.data;
  2132. const {
  2133. width,
  2134. height
  2135. } = getRectDims(data.rect);
  2136. const svg = this.svgFactory.create(width, height, true);
  2137. const borderWidth = data.borderStyle.width;
  2138. const circle = this.#circle = this.svgFactory.createElement("svg:ellipse");
  2139. circle.setAttribute("cx", width / 2);
  2140. circle.setAttribute("cy", height / 2);
  2141. circle.setAttribute("rx", width / 2 - borderWidth / 2);
  2142. circle.setAttribute("ry", height / 2 - borderWidth / 2);
  2143. circle.setAttribute("stroke-width", borderWidth || 1);
  2144. circle.setAttribute("stroke", "transparent");
  2145. circle.setAttribute("fill", "transparent");
  2146. svg.append(circle);
  2147. this.container.append(svg);
  2148. if (!data.popupRef && this.hasPopupData) {
  2149. this._createPopup();
  2150. }
  2151. return this.container;
  2152. }
  2153. getElementsToTriggerPopup() {
  2154. return this.#circle;
  2155. }
  2156. addHighlightArea() {
  2157. this.container.classList.add("highlightArea");
  2158. }
  2159. }
  2160. class PolylineAnnotationElement extends AnnotationElement {
  2161. #polyline = null;
  2162. constructor(parameters) {
  2163. super(parameters, {
  2164. isRenderable: true,
  2165. ignoreBorder: true
  2166. });
  2167. this.containerClassName = "polylineAnnotation";
  2168. this.svgElementName = "svg:polyline";
  2169. }
  2170. render() {
  2171. this.container.classList.add(this.containerClassName);
  2172. const data = this.data;
  2173. const {
  2174. width,
  2175. height
  2176. } = getRectDims(data.rect);
  2177. const svg = this.svgFactory.create(width, height, true);
  2178. let points = [];
  2179. for (const coordinate of data.vertices) {
  2180. const x = coordinate.x - data.rect[0];
  2181. const y = data.rect[3] - coordinate.y;
  2182. points.push(x + "," + y);
  2183. }
  2184. points = points.join(" ");
  2185. const polyline = this.#polyline = this.svgFactory.createElement(this.svgElementName);
  2186. polyline.setAttribute("points", points);
  2187. polyline.setAttribute("stroke-width", data.borderStyle.width || 1);
  2188. polyline.setAttribute("stroke", "transparent");
  2189. polyline.setAttribute("fill", "transparent");
  2190. svg.append(polyline);
  2191. this.container.append(svg);
  2192. if (!data.popupRef && this.hasPopupData) {
  2193. this._createPopup();
  2194. }
  2195. return this.container;
  2196. }
  2197. getElementsToTriggerPopup() {
  2198. return this.#polyline;
  2199. }
  2200. addHighlightArea() {
  2201. this.container.classList.add("highlightArea");
  2202. }
  2203. }
  2204. class PolygonAnnotationElement extends PolylineAnnotationElement {
  2205. constructor(parameters) {
  2206. super(parameters);
  2207. this.containerClassName = "polygonAnnotation";
  2208. this.svgElementName = "svg:polygon";
  2209. }
  2210. }
  2211. class CaretAnnotationElement extends AnnotationElement {
  2212. constructor(parameters) {
  2213. super(parameters, {
  2214. isRenderable: true,
  2215. ignoreBorder: true
  2216. });
  2217. }
  2218. render() {
  2219. this.container.classList.add("caretAnnotation");
  2220. if (!this.data.popupRef && this.hasPopupData) {
  2221. this._createPopup();
  2222. }
  2223. return this.container;
  2224. }
  2225. }
  2226. class InkAnnotationElement extends AnnotationElement {
  2227. #polylines = [];
  2228. constructor(parameters) {
  2229. super(parameters, {
  2230. isRenderable: true,
  2231. ignoreBorder: true
  2232. });
  2233. this.containerClassName = "inkAnnotation";
  2234. this.svgElementName = "svg:polyline";
  2235. this.annotationEditorType = util.AnnotationEditorType.INK;
  2236. }
  2237. render() {
  2238. this.container.classList.add(this.containerClassName);
  2239. const data = this.data;
  2240. const {
  2241. width,
  2242. height
  2243. } = getRectDims(data.rect);
  2244. const svg = this.svgFactory.create(width, height, true);
  2245. for (const inkList of data.inkLists) {
  2246. let points = [];
  2247. for (const coordinate of inkList) {
  2248. const x = coordinate.x - data.rect[0];
  2249. const y = data.rect[3] - coordinate.y;
  2250. points.push(`${x},${y}`);
  2251. }
  2252. points = points.join(" ");
  2253. const polyline = this.svgFactory.createElement(this.svgElementName);
  2254. this.#polylines.push(polyline);
  2255. polyline.setAttribute("points", points);
  2256. polyline.setAttribute("stroke-width", data.borderStyle.width || 1);
  2257. polyline.setAttribute("stroke", "transparent");
  2258. polyline.setAttribute("fill", "transparent");
  2259. if (!data.popupRef && this.hasPopupData) {
  2260. this._createPopup();
  2261. }
  2262. svg.append(polyline);
  2263. }
  2264. this.container.append(svg);
  2265. return this.container;
  2266. }
  2267. getElementsToTriggerPopup() {
  2268. return this.#polylines;
  2269. }
  2270. addHighlightArea() {
  2271. this.container.classList.add("highlightArea");
  2272. }
  2273. }
  2274. class HighlightAnnotationElement extends AnnotationElement {
  2275. constructor(parameters) {
  2276. super(parameters, {
  2277. isRenderable: true,
  2278. ignoreBorder: true,
  2279. createQuadrilaterals: true
  2280. });
  2281. }
  2282. render() {
  2283. if (!this.data.popupRef && this.hasPopupData) {
  2284. this._createPopup();
  2285. }
  2286. this.container.classList.add("highlightAnnotation");
  2287. return this.container;
  2288. }
  2289. }
  2290. class UnderlineAnnotationElement extends AnnotationElement {
  2291. constructor(parameters) {
  2292. super(parameters, {
  2293. isRenderable: true,
  2294. ignoreBorder: true,
  2295. createQuadrilaterals: true
  2296. });
  2297. }
  2298. render() {
  2299. if (!this.data.popupRef && this.hasPopupData) {
  2300. this._createPopup();
  2301. }
  2302. this.container.classList.add("underlineAnnotation");
  2303. return this.container;
  2304. }
  2305. }
  2306. class SquigglyAnnotationElement extends AnnotationElement {
  2307. constructor(parameters) {
  2308. super(parameters, {
  2309. isRenderable: true,
  2310. ignoreBorder: true,
  2311. createQuadrilaterals: true
  2312. });
  2313. }
  2314. render() {
  2315. if (!this.data.popupRef && this.hasPopupData) {
  2316. this._createPopup();
  2317. }
  2318. this.container.classList.add("squigglyAnnotation");
  2319. return this.container;
  2320. }
  2321. }
  2322. class StrikeOutAnnotationElement extends AnnotationElement {
  2323. constructor(parameters) {
  2324. super(parameters, {
  2325. isRenderable: true,
  2326. ignoreBorder: true,
  2327. createQuadrilaterals: true
  2328. });
  2329. }
  2330. render() {
  2331. if (!this.data.popupRef && this.hasPopupData) {
  2332. this._createPopup();
  2333. }
  2334. this.container.classList.add("strikeoutAnnotation");
  2335. return this.container;
  2336. }
  2337. }
  2338. class StampAnnotationElement extends AnnotationElement {
  2339. constructor(parameters) {
  2340. super(parameters, {
  2341. isRenderable: true,
  2342. ignoreBorder: true
  2343. });
  2344. }
  2345. render() {
  2346. this.container.classList.add("stampAnnotation");
  2347. if (!this.data.popupRef && this.hasPopupData) {
  2348. this._createPopup();
  2349. }
  2350. return this.container;
  2351. }
  2352. }
  2353. class FileAttachmentAnnotationElement extends AnnotationElement {
  2354. #trigger = null;
  2355. constructor(parameters) {
  2356. super(parameters, {
  2357. isRenderable: true
  2358. });
  2359. const {
  2360. filename,
  2361. content
  2362. } = this.data.file;
  2363. this.filename = (0,display_utils.getFilenameFromUrl)(filename, true);
  2364. this.content = content;
  2365. this.linkService.eventBus?.dispatch("fileattachmentannotation", {
  2366. source: this,
  2367. filename,
  2368. content
  2369. });
  2370. }
  2371. render() {
  2372. this.container.classList.add("fileAttachmentAnnotation");
  2373. const {
  2374. container,
  2375. data
  2376. } = this;
  2377. let trigger;
  2378. if (data.hasAppearance || data.fillAlpha === 0) {
  2379. trigger = document.createElement("div");
  2380. } else {
  2381. trigger = document.createElement("img");
  2382. trigger.src = `${this.imageResourcesPath}annotation-${/paperclip/i.test(data.name) ? "paperclip" : "pushpin"}.svg`;
  2383. if (data.fillAlpha && data.fillAlpha < 1) {
  2384. trigger.style = `filter: opacity(${Math.round(data.fillAlpha * 100)}%);`;
  2385. }
  2386. }
  2387. trigger.addEventListener("dblclick", this.#download.bind(this));
  2388. this.#trigger = trigger;
  2389. const {
  2390. isMac
  2391. } = util.FeatureTest.platform;
  2392. container.addEventListener("keydown", evt => {
  2393. if (evt.key === "Enter" && (isMac ? evt.metaKey : evt.ctrlKey)) {
  2394. this.#download();
  2395. }
  2396. });
  2397. if (!data.popupRef && this.hasPopupData) {
  2398. this._createPopup();
  2399. } else {
  2400. trigger.classList.add("popupTriggerArea");
  2401. }
  2402. container.append(trigger);
  2403. return container;
  2404. }
  2405. getElementsToTriggerPopup() {
  2406. return this.#trigger;
  2407. }
  2408. addHighlightArea() {
  2409. this.container.classList.add("highlightArea");
  2410. }
  2411. #download() {
  2412. this.downloadManager?.openOrDownloadData(this.content, this.filename);
  2413. }
  2414. }
  2415. class AnnotationLayer {
  2416. #accessibilityManager = null;
  2417. #annotationCanvasMap = null;
  2418. #editableAnnotations = new Map();
  2419. constructor({
  2420. div,
  2421. accessibilityManager,
  2422. annotationCanvasMap,
  2423. annotationEditorUIManager,
  2424. page,
  2425. viewport
  2426. }) {
  2427. this.div = div;
  2428. this.#accessibilityManager = accessibilityManager;
  2429. this.#annotationCanvasMap = annotationCanvasMap;
  2430. this.page = page;
  2431. this.viewport = viewport;
  2432. this.zIndex = 0;
  2433. this._annotationEditorUIManager = annotationEditorUIManager;
  2434. }
  2435. #appendElement(element, id) {
  2436. const contentElement = element.firstChild || element;
  2437. contentElement.id = `${util.AnnotationPrefix}${id}`;
  2438. this.div.append(element);
  2439. this.#accessibilityManager?.moveElementInDOM(this.div, element, contentElement, false);
  2440. }
  2441. async render(params) {
  2442. const {
  2443. annotations
  2444. } = params;
  2445. const layer = this.div;
  2446. (0,display_utils.setLayerDimensions)(layer, this.viewport);
  2447. const popupToElements = new Map();
  2448. const elementParams = {
  2449. data: null,
  2450. layer,
  2451. linkService: params.linkService,
  2452. downloadManager: params.downloadManager,
  2453. imageResourcesPath: params.imageResourcesPath || "",
  2454. renderForms: params.renderForms !== false,
  2455. svgFactory: new display_utils.DOMSVGFactory(),
  2456. annotationStorage: params.annotationStorage || new annotation_storage.AnnotationStorage(),
  2457. enableScripting: params.enableScripting === true,
  2458. hasJSActions: params.hasJSActions,
  2459. fieldObjects: params.fieldObjects,
  2460. parent: this,
  2461. elements: null
  2462. };
  2463. for (const data of annotations) {
  2464. if (data.noHTML) {
  2465. continue;
  2466. }
  2467. const isPopupAnnotation = data.annotationType === util.AnnotationType.POPUP;
  2468. if (!isPopupAnnotation) {
  2469. const {
  2470. width,
  2471. height
  2472. } = getRectDims(data.rect);
  2473. if (width <= 0 || height <= 0) {
  2474. continue;
  2475. }
  2476. } else {
  2477. const elements = popupToElements.get(data.id);
  2478. if (!elements) {
  2479. continue;
  2480. }
  2481. elementParams.elements = elements;
  2482. }
  2483. elementParams.data = data;
  2484. const element = AnnotationElementFactory.create(elementParams);
  2485. if (!element.isRenderable) {
  2486. continue;
  2487. }
  2488. if (!isPopupAnnotation && data.popupRef) {
  2489. const elements = popupToElements.get(data.popupRef);
  2490. if (!elements) {
  2491. popupToElements.set(data.popupRef, [element]);
  2492. } else {
  2493. elements.push(element);
  2494. }
  2495. }
  2496. const rendered = element.render();
  2497. if (data.hidden) {
  2498. rendered.style.visibility = "hidden";
  2499. }
  2500. this.#appendElement(rendered, data.id);
  2501. if (element.annotationEditorType > 0) {
  2502. this.#editableAnnotations.set(element.data.id, element);
  2503. this._annotationEditorUIManager?.renderAnnotationElement(element);
  2504. }
  2505. }
  2506. this.#setAnnotationCanvasMap();
  2507. }
  2508. update({
  2509. viewport
  2510. }) {
  2511. const layer = this.div;
  2512. this.viewport = viewport;
  2513. (0,display_utils.setLayerDimensions)(layer, {
  2514. rotation: viewport.rotation
  2515. });
  2516. this.#setAnnotationCanvasMap();
  2517. layer.hidden = false;
  2518. }
  2519. #setAnnotationCanvasMap() {
  2520. if (!this.#annotationCanvasMap) {
  2521. return;
  2522. }
  2523. const layer = this.div;
  2524. for (const [id, canvas] of this.#annotationCanvasMap) {
  2525. const element = layer.querySelector(`[data-annotation-id="${id}"]`);
  2526. if (!element) {
  2527. continue;
  2528. }
  2529. canvas.className = "annotationContent";
  2530. const {
  2531. firstChild
  2532. } = element;
  2533. if (!firstChild) {
  2534. element.append(canvas);
  2535. } else if (firstChild.nodeName === "CANVAS") {
  2536. firstChild.replaceWith(canvas);
  2537. } else if (!firstChild.classList.contains("annotationContent")) {
  2538. firstChild.before(canvas);
  2539. } else {
  2540. firstChild.after(canvas);
  2541. }
  2542. }
  2543. this.#annotationCanvasMap.clear();
  2544. }
  2545. getEditableAnnotations() {
  2546. return Array.from(this.#editableAnnotations.values());
  2547. }
  2548. getEditableAnnotation(id) {
  2549. return this.#editableAnnotations.get(id);
  2550. }
  2551. }
  2552. /***/ }),
  2553. /***/ 792:
  2554. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  2555. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  2556. /* harmony export */ AnnotationStorage: () => (/* binding */ AnnotationStorage),
  2557. /* harmony export */ PrintAnnotationStorage: () => (/* binding */ PrintAnnotationStorage),
  2558. /* harmony export */ SerializableEmpty: () => (/* binding */ SerializableEmpty)
  2559. /* harmony export */ });
  2560. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(292);
  2561. /* harmony import */ var _editor_editor_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(310);
  2562. /* harmony import */ var _shared_murmurhash3_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(651);
  2563. const SerializableEmpty = Object.freeze({
  2564. map: null,
  2565. hash: "",
  2566. transfer: undefined
  2567. });
  2568. class AnnotationStorage {
  2569. #modified = false;
  2570. #storage = new Map();
  2571. constructor() {
  2572. this.onSetModified = null;
  2573. this.onResetModified = null;
  2574. this.onAnnotationEditor = null;
  2575. }
  2576. getValue(key, defaultValue) {
  2577. const value = this.#storage.get(key);
  2578. if (value === undefined) {
  2579. return defaultValue;
  2580. }
  2581. return Object.assign(defaultValue, value);
  2582. }
  2583. getRawValue(key) {
  2584. return this.#storage.get(key);
  2585. }
  2586. remove(key) {
  2587. this.#storage.delete(key);
  2588. if (this.#storage.size === 0) {
  2589. this.resetModified();
  2590. }
  2591. if (typeof this.onAnnotationEditor === "function") {
  2592. for (const value of this.#storage.values()) {
  2593. if (value instanceof _editor_editor_js__WEBPACK_IMPORTED_MODULE_1__.AnnotationEditor) {
  2594. return;
  2595. }
  2596. }
  2597. this.onAnnotationEditor(null);
  2598. }
  2599. }
  2600. setValue(key, value) {
  2601. const obj = this.#storage.get(key);
  2602. let modified = false;
  2603. if (obj !== undefined) {
  2604. for (const [entry, val] of Object.entries(value)) {
  2605. if (obj[entry] !== val) {
  2606. modified = true;
  2607. obj[entry] = val;
  2608. }
  2609. }
  2610. } else {
  2611. modified = true;
  2612. this.#storage.set(key, value);
  2613. }
  2614. if (modified) {
  2615. this.#setModified();
  2616. }
  2617. if (value instanceof _editor_editor_js__WEBPACK_IMPORTED_MODULE_1__.AnnotationEditor && typeof this.onAnnotationEditor === "function") {
  2618. this.onAnnotationEditor(value.constructor._type);
  2619. }
  2620. }
  2621. has(key) {
  2622. return this.#storage.has(key);
  2623. }
  2624. getAll() {
  2625. return this.#storage.size > 0 ? (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.objectFromMap)(this.#storage) : null;
  2626. }
  2627. setAll(obj) {
  2628. for (const [key, val] of Object.entries(obj)) {
  2629. this.setValue(key, val);
  2630. }
  2631. }
  2632. get size() {
  2633. return this.#storage.size;
  2634. }
  2635. #setModified() {
  2636. if (!this.#modified) {
  2637. this.#modified = true;
  2638. if (typeof this.onSetModified === "function") {
  2639. this.onSetModified();
  2640. }
  2641. }
  2642. }
  2643. resetModified() {
  2644. if (this.#modified) {
  2645. this.#modified = false;
  2646. if (typeof this.onResetModified === "function") {
  2647. this.onResetModified();
  2648. }
  2649. }
  2650. }
  2651. get print() {
  2652. return new PrintAnnotationStorage(this);
  2653. }
  2654. get serializable() {
  2655. if (this.#storage.size === 0) {
  2656. return SerializableEmpty;
  2657. }
  2658. const map = new Map(),
  2659. hash = new _shared_murmurhash3_js__WEBPACK_IMPORTED_MODULE_2__.MurmurHash3_64(),
  2660. transfer = [];
  2661. const context = Object.create(null);
  2662. let hasBitmap = false;
  2663. for (const [key, val] of this.#storage) {
  2664. const serialized = val instanceof _editor_editor_js__WEBPACK_IMPORTED_MODULE_1__.AnnotationEditor ? val.serialize(false, context) : val;
  2665. if (serialized) {
  2666. map.set(key, serialized);
  2667. hash.update(`${key}:${JSON.stringify(serialized)}`);
  2668. hasBitmap ||= !!serialized.bitmap;
  2669. }
  2670. }
  2671. if (hasBitmap) {
  2672. for (const value of map.values()) {
  2673. if (value.bitmap) {
  2674. transfer.push(value.bitmap);
  2675. }
  2676. }
  2677. }
  2678. return map.size > 0 ? {
  2679. map,
  2680. hash: hash.hexdigest(),
  2681. transfer
  2682. } : SerializableEmpty;
  2683. }
  2684. get editorStats() {
  2685. let stats = null;
  2686. const typeToEditor = new Map();
  2687. for (const value of this.#storage.values()) {
  2688. if (!(value instanceof _editor_editor_js__WEBPACK_IMPORTED_MODULE_1__.AnnotationEditor)) {
  2689. continue;
  2690. }
  2691. const editorStats = value.telemetryFinalData;
  2692. if (!editorStats) {
  2693. continue;
  2694. }
  2695. const {
  2696. type
  2697. } = editorStats;
  2698. if (!typeToEditor.has(type)) {
  2699. typeToEditor.set(type, Object.getPrototypeOf(value).constructor);
  2700. }
  2701. stats ||= Object.create(null);
  2702. const map = stats[type] ||= new Map();
  2703. for (const [key, val] of Object.entries(editorStats)) {
  2704. if (key === "type") {
  2705. continue;
  2706. }
  2707. let counters = map.get(key);
  2708. if (!counters) {
  2709. counters = new Map();
  2710. map.set(key, counters);
  2711. }
  2712. const count = counters.get(val) ?? 0;
  2713. counters.set(val, count + 1);
  2714. }
  2715. }
  2716. for (const [type, editor] of typeToEditor) {
  2717. stats[type] = editor.computeTelemetryFinalData(stats[type]);
  2718. }
  2719. return stats;
  2720. }
  2721. }
  2722. class PrintAnnotationStorage extends AnnotationStorage {
  2723. #serializable;
  2724. constructor(parent) {
  2725. super();
  2726. const {
  2727. map,
  2728. hash,
  2729. transfer
  2730. } = parent.serializable;
  2731. const clone = structuredClone(map, transfer ? {
  2732. transfer
  2733. } : null);
  2734. this.#serializable = {
  2735. map: clone,
  2736. hash,
  2737. transfer
  2738. };
  2739. }
  2740. get print() {
  2741. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.unreachable)("Should not call PrintAnnotationStorage.print");
  2742. }
  2743. get serializable() {
  2744. return this.#serializable;
  2745. }
  2746. }
  2747. /***/ }),
  2748. /***/ 831:
  2749. /***/ ((__webpack_module__, __webpack_exports__, __webpack_require__) => {
  2750. __webpack_require__.a(__webpack_module__, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
  2751. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  2752. /* harmony export */ PDFDataRangeTransport: () => (/* binding */ PDFDataRangeTransport),
  2753. /* harmony export */ PDFWorker: () => (/* binding */ PDFWorker),
  2754. /* harmony export */ build: () => (/* binding */ build),
  2755. /* harmony export */ getDocument: () => (/* binding */ getDocument),
  2756. /* harmony export */ version: () => (/* binding */ version)
  2757. /* harmony export */ });
  2758. /* unused harmony exports DefaultCanvasFactory, DefaultCMapReaderFactory, DefaultFilterFactory, DefaultStandardFontDataFactory, LoopbackPort, PDFDocumentLoadingTask, PDFDocumentProxy, PDFPageProxy, PDFWorkerUtil, RenderTask */
  2759. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(292);
  2760. /* harmony import */ var _annotation_storage_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(792);
  2761. /* harmony import */ var _display_utils_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(419);
  2762. /* harmony import */ var _font_loader_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(10);
  2763. /* harmony import */ var display_node_utils__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(573);
  2764. /* harmony import */ var _canvas_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(923);
  2765. /* harmony import */ var _text_layer_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(814);
  2766. /* harmony import */ var _worker_options_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(164);
  2767. /* harmony import */ var _shared_message_handler_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(178);
  2768. /* harmony import */ var _metadata_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(62);
  2769. /* harmony import */ var _optional_content_config_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(626);
  2770. /* harmony import */ var _transport_stream_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(585);
  2771. /* harmony import */ var display_fetch_stream__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(94);
  2772. /* harmony import */ var display_network__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(457);
  2773. /* harmony import */ var display_node_stream__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(786);
  2774. /* harmony import */ var _xfa_text_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(50);
  2775. var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([display_node_utils__WEBPACK_IMPORTED_MODULE_4__, display_node_stream__WEBPACK_IMPORTED_MODULE_13__]);
  2776. ([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__);
  2777. const DEFAULT_RANGE_CHUNK_SIZE = 65536;
  2778. const RENDERING_CANCELLED_TIMEOUT = 100;
  2779. const DELAYED_CLEANUP_TIMEOUT = 5000;
  2780. 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;
  2781. 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;
  2782. 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;
  2783. 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;
  2784. function getDocument(src) {
  2785. if (typeof src === "string" || src instanceof URL) {
  2786. src = {
  2787. url: src
  2788. };
  2789. } else if (src instanceof ArrayBuffer || ArrayBuffer.isView(src)) {
  2790. src = {
  2791. data: src
  2792. };
  2793. }
  2794. if (typeof src !== "object") {
  2795. throw new Error("Invalid parameter in getDocument, need parameter object.");
  2796. }
  2797. if (!src.url && !src.data && !src.range) {
  2798. throw new Error("Invalid parameter object: need either .data, .range or .url");
  2799. }
  2800. const task = new PDFDocumentLoadingTask();
  2801. const {
  2802. docId
  2803. } = task;
  2804. const url = src.url ? getUrlProp(src.url) : null;
  2805. const data = src.data ? getDataProp(src.data) : null;
  2806. const httpHeaders = src.httpHeaders || null;
  2807. const withCredentials = src.withCredentials === true;
  2808. const password = src.password ?? null;
  2809. const rangeTransport = src.range instanceof PDFDataRangeTransport ? src.range : null;
  2810. const rangeChunkSize = Number.isInteger(src.rangeChunkSize) && src.rangeChunkSize > 0 ? src.rangeChunkSize : DEFAULT_RANGE_CHUNK_SIZE;
  2811. let worker = src.worker instanceof PDFWorker ? src.worker : null;
  2812. const verbosity = src.verbosity;
  2813. const docBaseUrl = typeof src.docBaseUrl === "string" && !(0,_display_utils_js__WEBPACK_IMPORTED_MODULE_2__.isDataScheme)(src.docBaseUrl) ? src.docBaseUrl : null;
  2814. const cMapUrl = typeof src.cMapUrl === "string" ? src.cMapUrl : null;
  2815. const cMapPacked = src.cMapPacked !== false;
  2816. const CMapReaderFactory = src.CMapReaderFactory || DefaultCMapReaderFactory;
  2817. const standardFontDataUrl = typeof src.standardFontDataUrl === "string" ? src.standardFontDataUrl : null;
  2818. const StandardFontDataFactory = src.StandardFontDataFactory || DefaultStandardFontDataFactory;
  2819. const ignoreErrors = src.stopAtErrors !== true;
  2820. const maxImageSize = Number.isInteger(src.maxImageSize) && src.maxImageSize > -1 ? src.maxImageSize : -1;
  2821. const isEvalSupported = src.isEvalSupported !== false;
  2822. const isOffscreenCanvasSupported = typeof src.isOffscreenCanvasSupported === "boolean" ? src.isOffscreenCanvasSupported : !_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.isNodeJS;
  2823. const canvasMaxAreaInBytes = Number.isInteger(src.canvasMaxAreaInBytes) ? src.canvasMaxAreaInBytes : -1;
  2824. const disableFontFace = typeof src.disableFontFace === "boolean" ? src.disableFontFace : _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.isNodeJS;
  2825. const fontExtraProperties = src.fontExtraProperties === true;
  2826. const enableXfa = src.enableXfa === true;
  2827. const ownerDocument = src.ownerDocument || globalThis.document;
  2828. const disableRange = src.disableRange === true;
  2829. const disableStream = src.disableStream === true;
  2830. const disableAutoFetch = src.disableAutoFetch === true;
  2831. const pdfBug = src.pdfBug === true;
  2832. const length = rangeTransport ? rangeTransport.length : src.length ?? NaN;
  2833. const useSystemFonts = typeof src.useSystemFonts === "boolean" ? src.useSystemFonts : !_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.isNodeJS && !disableFontFace;
  2834. 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);
  2835. const canvasFactory = src.canvasFactory || new DefaultCanvasFactory({
  2836. ownerDocument
  2837. });
  2838. const filterFactory = src.filterFactory || new DefaultFilterFactory({
  2839. docId,
  2840. ownerDocument
  2841. });
  2842. const styleElement = null;
  2843. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.setVerbosityLevel)(verbosity);
  2844. const transportFactory = {
  2845. canvasFactory,
  2846. filterFactory
  2847. };
  2848. if (!useWorkerFetch) {
  2849. transportFactory.cMapReaderFactory = new CMapReaderFactory({
  2850. baseUrl: cMapUrl,
  2851. isCompressed: cMapPacked
  2852. });
  2853. transportFactory.standardFontDataFactory = new StandardFontDataFactory({
  2854. baseUrl: standardFontDataUrl
  2855. });
  2856. }
  2857. if (!worker) {
  2858. const workerParams = {
  2859. verbosity,
  2860. port: _worker_options_js__WEBPACK_IMPORTED_MODULE_14__.GlobalWorkerOptions.workerPort
  2861. };
  2862. worker = workerParams.port ? PDFWorker.fromPort(workerParams) : new PDFWorker(workerParams);
  2863. task._worker = worker;
  2864. }
  2865. const fetchDocParams = {
  2866. docId,
  2867. apiVersion: "4.2.67",
  2868. data,
  2869. password,
  2870. disableAutoFetch,
  2871. rangeChunkSize,
  2872. length,
  2873. docBaseUrl,
  2874. enableXfa,
  2875. evaluatorOptions: {
  2876. maxImageSize,
  2877. disableFontFace,
  2878. ignoreErrors,
  2879. isEvalSupported,
  2880. isOffscreenCanvasSupported,
  2881. canvasMaxAreaInBytes,
  2882. fontExtraProperties,
  2883. useSystemFonts,
  2884. cMapUrl: useWorkerFetch ? cMapUrl : null,
  2885. standardFontDataUrl: useWorkerFetch ? standardFontDataUrl : null
  2886. }
  2887. };
  2888. const transportParams = {
  2889. ignoreErrors,
  2890. disableFontFace,
  2891. fontExtraProperties,
  2892. enableXfa,
  2893. ownerDocument,
  2894. disableAutoFetch,
  2895. pdfBug,
  2896. styleElement
  2897. };
  2898. worker.promise.then(function () {
  2899. if (task.destroyed) {
  2900. throw new Error("Loading aborted");
  2901. }
  2902. const workerIdPromise = _fetchDocument(worker, fetchDocParams);
  2903. const networkStreamPromise = new Promise(function (resolve) {
  2904. let networkStream;
  2905. if (rangeTransport) {
  2906. networkStream = new _transport_stream_js__WEBPACK_IMPORTED_MODULE_10__.PDFDataTransportStream(rangeTransport, {
  2907. disableRange,
  2908. disableStream
  2909. });
  2910. } else if (!data) {
  2911. const createPDFNetworkStream = params => {
  2912. if (_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.isNodeJS) {
  2913. const isFetchSupported = function () {
  2914. return typeof fetch !== "undefined" && typeof Response !== "undefined" && "body" in Response.prototype;
  2915. };
  2916. return isFetchSupported() && (0,_display_utils_js__WEBPACK_IMPORTED_MODULE_2__.isValidFetchUrl)(params.url) ? new display_fetch_stream__WEBPACK_IMPORTED_MODULE_11__.PDFFetchStream(params) : new display_node_stream__WEBPACK_IMPORTED_MODULE_13__.PDFNodeStream(params);
  2917. }
  2918. 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);
  2919. };
  2920. networkStream = createPDFNetworkStream({
  2921. url,
  2922. length,
  2923. httpHeaders,
  2924. withCredentials,
  2925. rangeChunkSize,
  2926. disableRange,
  2927. disableStream
  2928. });
  2929. }
  2930. resolve(networkStream);
  2931. });
  2932. return Promise.all([workerIdPromise, networkStreamPromise]).then(function ([workerId, networkStream]) {
  2933. if (task.destroyed) {
  2934. throw new Error("Loading aborted");
  2935. }
  2936. const messageHandler = new _shared_message_handler_js__WEBPACK_IMPORTED_MODULE_7__.MessageHandler(docId, workerId, worker.port);
  2937. const transport = new WorkerTransport(messageHandler, task, networkStream, transportParams, transportFactory);
  2938. task._transport = transport;
  2939. messageHandler.send("Ready", null);
  2940. });
  2941. }).catch(task._capability.reject);
  2942. return task;
  2943. }
  2944. async function _fetchDocument(worker, source) {
  2945. if (worker.destroyed) {
  2946. throw new Error("Worker was destroyed");
  2947. }
  2948. const workerId = await worker.messageHandler.sendWithPromise("GetDocRequest", source, source.data ? [source.data.buffer] : null);
  2949. if (worker.destroyed) {
  2950. throw new Error("Worker was destroyed");
  2951. }
  2952. return workerId;
  2953. }
  2954. function getUrlProp(val) {
  2955. if (val instanceof URL) {
  2956. return val.href;
  2957. }
  2958. try {
  2959. return new URL(val, window.location).href;
  2960. } catch {
  2961. if (_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.isNodeJS && typeof val === "string") {
  2962. return val;
  2963. }
  2964. }
  2965. throw new Error("Invalid PDF url data: " + "either string or URL-object is expected in the url property.");
  2966. }
  2967. function getDataProp(val) {
  2968. if (_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.isNodeJS && typeof Buffer !== "undefined" && val instanceof Buffer) {
  2969. throw new Error("Please provide binary data as `Uint8Array`, rather than `Buffer`.");
  2970. }
  2971. if (val instanceof Uint8Array && val.byteLength === val.buffer.byteLength) {
  2972. return val;
  2973. }
  2974. if (typeof val === "string") {
  2975. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.stringToBytes)(val);
  2976. }
  2977. if (val instanceof ArrayBuffer || ArrayBuffer.isView(val) || typeof val === "object" && !isNaN(val?.length)) {
  2978. return new Uint8Array(val);
  2979. }
  2980. throw new Error("Invalid PDF binary data: either TypedArray, " + "string, or array-like object is expected in the data property.");
  2981. }
  2982. function isRefProxy(ref) {
  2983. return typeof ref === "object" && Number.isInteger(ref?.num) && ref.num >= 0 && Number.isInteger(ref?.gen) && ref.gen >= 0;
  2984. }
  2985. class PDFDocumentLoadingTask {
  2986. static #docId = 0;
  2987. constructor() {
  2988. this._capability = Promise.withResolvers();
  2989. this._transport = null;
  2990. this._worker = null;
  2991. this.docId = `d${PDFDocumentLoadingTask.#docId++}`;
  2992. this.destroyed = false;
  2993. this.onPassword = null;
  2994. this.onProgress = null;
  2995. }
  2996. get promise() {
  2997. return this._capability.promise;
  2998. }
  2999. async destroy() {
  3000. this.destroyed = true;
  3001. try {
  3002. if (this._worker?.port) {
  3003. this._worker._pendingDestroy = true;
  3004. }
  3005. await this._transport?.destroy();
  3006. } catch (ex) {
  3007. if (this._worker?.port) {
  3008. delete this._worker._pendingDestroy;
  3009. }
  3010. throw ex;
  3011. }
  3012. this._transport = null;
  3013. if (this._worker) {
  3014. this._worker.destroy();
  3015. this._worker = null;
  3016. }
  3017. }
  3018. }
  3019. class PDFDataRangeTransport {
  3020. constructor(length, initialData, progressiveDone = false, contentDispositionFilename = null) {
  3021. this.length = length;
  3022. this.initialData = initialData;
  3023. this.progressiveDone = progressiveDone;
  3024. this.contentDispositionFilename = contentDispositionFilename;
  3025. this._rangeListeners = [];
  3026. this._progressListeners = [];
  3027. this._progressiveReadListeners = [];
  3028. this._progressiveDoneListeners = [];
  3029. this._readyCapability = Promise.withResolvers();
  3030. }
  3031. addRangeListener(listener) {
  3032. this._rangeListeners.push(listener);
  3033. }
  3034. addProgressListener(listener) {
  3035. this._progressListeners.push(listener);
  3036. }
  3037. addProgressiveReadListener(listener) {
  3038. this._progressiveReadListeners.push(listener);
  3039. }
  3040. addProgressiveDoneListener(listener) {
  3041. this._progressiveDoneListeners.push(listener);
  3042. }
  3043. onDataRange(begin, chunk) {
  3044. for (const listener of this._rangeListeners) {
  3045. listener(begin, chunk);
  3046. }
  3047. }
  3048. onDataProgress(loaded, total) {
  3049. this._readyCapability.promise.then(() => {
  3050. for (const listener of this._progressListeners) {
  3051. listener(loaded, total);
  3052. }
  3053. });
  3054. }
  3055. onDataProgressiveRead(chunk) {
  3056. this._readyCapability.promise.then(() => {
  3057. for (const listener of this._progressiveReadListeners) {
  3058. listener(chunk);
  3059. }
  3060. });
  3061. }
  3062. onDataProgressiveDone() {
  3063. this._readyCapability.promise.then(() => {
  3064. for (const listener of this._progressiveDoneListeners) {
  3065. listener();
  3066. }
  3067. });
  3068. }
  3069. transportReady() {
  3070. this._readyCapability.resolve();
  3071. }
  3072. requestDataRange(begin, end) {
  3073. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.unreachable)("Abstract method PDFDataRangeTransport.requestDataRange");
  3074. }
  3075. abort() {}
  3076. }
  3077. class PDFDocumentProxy {
  3078. constructor(pdfInfo, transport) {
  3079. this._pdfInfo = pdfInfo;
  3080. this._transport = transport;
  3081. }
  3082. get annotationStorage() {
  3083. return this._transport.annotationStorage;
  3084. }
  3085. get filterFactory() {
  3086. return this._transport.filterFactory;
  3087. }
  3088. get numPages() {
  3089. return this._pdfInfo.numPages;
  3090. }
  3091. get fingerprints() {
  3092. return this._pdfInfo.fingerprints;
  3093. }
  3094. get isPureXfa() {
  3095. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow)(this, "isPureXfa", !!this._transport._htmlForXfa);
  3096. }
  3097. get allXfaHtml() {
  3098. return this._transport._htmlForXfa;
  3099. }
  3100. getPage(pageNumber) {
  3101. return this._transport.getPage(pageNumber);
  3102. }
  3103. getPageIndex(ref) {
  3104. return this._transport.getPageIndex(ref);
  3105. }
  3106. getDestinations() {
  3107. return this._transport.getDestinations();
  3108. }
  3109. getDestination(id) {
  3110. return this._transport.getDestination(id);
  3111. }
  3112. getPageLabels() {
  3113. return this._transport.getPageLabels();
  3114. }
  3115. getPageLayout() {
  3116. return this._transport.getPageLayout();
  3117. }
  3118. getPageMode() {
  3119. return this._transport.getPageMode();
  3120. }
  3121. getViewerPreferences() {
  3122. return this._transport.getViewerPreferences();
  3123. }
  3124. getOpenAction() {
  3125. return this._transport.getOpenAction();
  3126. }
  3127. getAttachments() {
  3128. return this._transport.getAttachments();
  3129. }
  3130. getJSActions() {
  3131. return this._transport.getDocJSActions();
  3132. }
  3133. getOutline() {
  3134. return this._transport.getOutline();
  3135. }
  3136. getOptionalContentConfig({
  3137. intent = "display"
  3138. } = {}) {
  3139. const {
  3140. renderingIntent
  3141. } = this._transport.getRenderingIntent(intent);
  3142. return this._transport.getOptionalContentConfig(renderingIntent);
  3143. }
  3144. getPermissions() {
  3145. return this._transport.getPermissions();
  3146. }
  3147. getMetadata() {
  3148. return this._transport.getMetadata();
  3149. }
  3150. getMarkInfo() {
  3151. return this._transport.getMarkInfo();
  3152. }
  3153. getData() {
  3154. return this._transport.getData();
  3155. }
  3156. saveDocument() {
  3157. return this._transport.saveDocument();
  3158. }
  3159. getDownloadInfo() {
  3160. return this._transport.downloadInfoCapability.promise;
  3161. }
  3162. cleanup(keepLoadedFonts = false) {
  3163. return this._transport.startCleanup(keepLoadedFonts || this.isPureXfa);
  3164. }
  3165. destroy() {
  3166. return this.loadingTask.destroy();
  3167. }
  3168. cachedPageNumber(ref) {
  3169. return this._transport.cachedPageNumber(ref);
  3170. }
  3171. get loadingParams() {
  3172. return this._transport.loadingParams;
  3173. }
  3174. get loadingTask() {
  3175. return this._transport.loadingTask;
  3176. }
  3177. getFieldObjects() {
  3178. return this._transport.getFieldObjects();
  3179. }
  3180. hasJSActions() {
  3181. return this._transport.hasJSActions();
  3182. }
  3183. getCalculationOrderIds() {
  3184. return this._transport.getCalculationOrderIds();
  3185. }
  3186. }
  3187. class PDFPageProxy {
  3188. #delayedCleanupTimeout = null;
  3189. #pendingCleanup = false;
  3190. constructor(pageIndex, pageInfo, transport, pdfBug = false) {
  3191. this._pageIndex = pageIndex;
  3192. this._pageInfo = pageInfo;
  3193. this._transport = transport;
  3194. this._stats = pdfBug ? new _display_utils_js__WEBPACK_IMPORTED_MODULE_2__.StatTimer() : null;
  3195. this._pdfBug = pdfBug;
  3196. this.commonObjs = transport.commonObjs;
  3197. this.objs = new PDFObjects();
  3198. this._maybeCleanupAfterRender = false;
  3199. this._intentStates = new Map();
  3200. this.destroyed = false;
  3201. }
  3202. get pageNumber() {
  3203. return this._pageIndex + 1;
  3204. }
  3205. get rotate() {
  3206. return this._pageInfo.rotate;
  3207. }
  3208. get ref() {
  3209. return this._pageInfo.ref;
  3210. }
  3211. get userUnit() {
  3212. return this._pageInfo.userUnit;
  3213. }
  3214. get view() {
  3215. return this._pageInfo.view;
  3216. }
  3217. getViewport({
  3218. scale,
  3219. rotation = this.rotate,
  3220. offsetX = 0,
  3221. offsetY = 0,
  3222. dontFlip = false
  3223. } = {}) {
  3224. return new _display_utils_js__WEBPACK_IMPORTED_MODULE_2__.PageViewport({
  3225. viewBox: this.view,
  3226. scale,
  3227. rotation,
  3228. offsetX,
  3229. offsetY,
  3230. dontFlip
  3231. });
  3232. }
  3233. getAnnotations({
  3234. intent = "display"
  3235. } = {}) {
  3236. const {
  3237. renderingIntent
  3238. } = this._transport.getRenderingIntent(intent);
  3239. return this._transport.getAnnotations(this._pageIndex, renderingIntent);
  3240. }
  3241. getJSActions() {
  3242. return this._transport.getPageJSActions(this._pageIndex);
  3243. }
  3244. get filterFactory() {
  3245. return this._transport.filterFactory;
  3246. }
  3247. get isPureXfa() {
  3248. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow)(this, "isPureXfa", !!this._transport._htmlForXfa);
  3249. }
  3250. async getXfa() {
  3251. return this._transport._htmlForXfa?.children[this._pageIndex] || null;
  3252. }
  3253. render({
  3254. canvasContext,
  3255. viewport,
  3256. intent = "display",
  3257. annotationMode = _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationMode.ENABLE,
  3258. transform = null,
  3259. background = null,
  3260. optionalContentConfigPromise = null,
  3261. annotationCanvasMap = null,
  3262. pageColors = null,
  3263. printAnnotationStorage = null
  3264. }) {
  3265. this._stats?.time("Overall");
  3266. const intentArgs = this._transport.getRenderingIntent(intent, annotationMode, printAnnotationStorage);
  3267. const {
  3268. renderingIntent,
  3269. cacheKey
  3270. } = intentArgs;
  3271. this.#pendingCleanup = false;
  3272. this.#abortDelayedCleanup();
  3273. optionalContentConfigPromise ||= this._transport.getOptionalContentConfig(renderingIntent);
  3274. let intentState = this._intentStates.get(cacheKey);
  3275. if (!intentState) {
  3276. intentState = Object.create(null);
  3277. this._intentStates.set(cacheKey, intentState);
  3278. }
  3279. if (intentState.streamReaderCancelTimeout) {
  3280. clearTimeout(intentState.streamReaderCancelTimeout);
  3281. intentState.streamReaderCancelTimeout = null;
  3282. }
  3283. const intentPrint = !!(renderingIntent & _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.RenderingIntentFlag.PRINT);
  3284. if (!intentState.displayReadyCapability) {
  3285. intentState.displayReadyCapability = Promise.withResolvers();
  3286. intentState.operatorList = {
  3287. fnArray: [],
  3288. argsArray: [],
  3289. lastChunk: false,
  3290. separateAnnots: null
  3291. };
  3292. this._stats?.time("Page Request");
  3293. this._pumpOperatorList(intentArgs);
  3294. }
  3295. const complete = error => {
  3296. intentState.renderTasks.delete(internalRenderTask);
  3297. if (this._maybeCleanupAfterRender || intentPrint) {
  3298. this.#pendingCleanup = true;
  3299. }
  3300. this.#tryCleanup(!intentPrint);
  3301. if (error) {
  3302. internalRenderTask.capability.reject(error);
  3303. this._abortOperatorList({
  3304. intentState,
  3305. reason: error instanceof Error ? error : new Error(error)
  3306. });
  3307. } else {
  3308. internalRenderTask.capability.resolve();
  3309. }
  3310. this._stats?.timeEnd("Rendering");
  3311. this._stats?.timeEnd("Overall");
  3312. };
  3313. const internalRenderTask = new InternalRenderTask({
  3314. callback: complete,
  3315. params: {
  3316. canvasContext,
  3317. viewport,
  3318. transform,
  3319. background
  3320. },
  3321. objs: this.objs,
  3322. commonObjs: this.commonObjs,
  3323. annotationCanvasMap,
  3324. operatorList: intentState.operatorList,
  3325. pageIndex: this._pageIndex,
  3326. canvasFactory: this._transport.canvasFactory,
  3327. filterFactory: this._transport.filterFactory,
  3328. useRequestAnimationFrame: !intentPrint,
  3329. pdfBug: this._pdfBug,
  3330. pageColors
  3331. });
  3332. (intentState.renderTasks ||= new Set()).add(internalRenderTask);
  3333. const renderTask = internalRenderTask.task;
  3334. Promise.all([intentState.displayReadyCapability.promise, optionalContentConfigPromise]).then(([transparency, optionalContentConfig]) => {
  3335. if (this.destroyed) {
  3336. complete();
  3337. return;
  3338. }
  3339. this._stats?.time("Rendering");
  3340. if (!(optionalContentConfig.renderingIntent & renderingIntent)) {
  3341. throw new Error("Must use the same `intent`-argument when calling the `PDFPageProxy.render` " + "and `PDFDocumentProxy.getOptionalContentConfig` methods.");
  3342. }
  3343. internalRenderTask.initializeGraphics({
  3344. transparency,
  3345. optionalContentConfig
  3346. });
  3347. internalRenderTask.operatorListChanged();
  3348. }).catch(complete);
  3349. return renderTask;
  3350. }
  3351. getOperatorList({
  3352. intent = "display",
  3353. annotationMode = _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationMode.ENABLE,
  3354. printAnnotationStorage = null
  3355. } = {}) {
  3356. function operatorListChanged() {
  3357. if (intentState.operatorList.lastChunk) {
  3358. intentState.opListReadCapability.resolve(intentState.operatorList);
  3359. intentState.renderTasks.delete(opListTask);
  3360. }
  3361. }
  3362. const intentArgs = this._transport.getRenderingIntent(intent, annotationMode, printAnnotationStorage, true);
  3363. let intentState = this._intentStates.get(intentArgs.cacheKey);
  3364. if (!intentState) {
  3365. intentState = Object.create(null);
  3366. this._intentStates.set(intentArgs.cacheKey, intentState);
  3367. }
  3368. let opListTask;
  3369. if (!intentState.opListReadCapability) {
  3370. opListTask = Object.create(null);
  3371. opListTask.operatorListChanged = operatorListChanged;
  3372. intentState.opListReadCapability = Promise.withResolvers();
  3373. (intentState.renderTasks ||= new Set()).add(opListTask);
  3374. intentState.operatorList = {
  3375. fnArray: [],
  3376. argsArray: [],
  3377. lastChunk: false,
  3378. separateAnnots: null
  3379. };
  3380. this._stats?.time("Page Request");
  3381. this._pumpOperatorList(intentArgs);
  3382. }
  3383. return intentState.opListReadCapability.promise;
  3384. }
  3385. streamTextContent({
  3386. includeMarkedContent = false,
  3387. disableNormalization = false
  3388. } = {}) {
  3389. const TEXT_CONTENT_CHUNK_SIZE = 100;
  3390. return this._transport.messageHandler.sendWithStream("GetTextContent", {
  3391. pageIndex: this._pageIndex,
  3392. includeMarkedContent: includeMarkedContent === true,
  3393. disableNormalization: disableNormalization === true
  3394. }, {
  3395. highWaterMark: TEXT_CONTENT_CHUNK_SIZE,
  3396. size(textContent) {
  3397. return textContent.items.length;
  3398. }
  3399. });
  3400. }
  3401. getTextContent(params = {}) {
  3402. if (this._transport._htmlForXfa) {
  3403. return this.getXfa().then(xfa => _xfa_text_js__WEBPACK_IMPORTED_MODULE_15__.XfaText.textContent(xfa));
  3404. }
  3405. const readableStream = this.streamTextContent(params);
  3406. return new Promise(function (resolve, reject) {
  3407. function pump() {
  3408. reader.read().then(function ({
  3409. value,
  3410. done
  3411. }) {
  3412. if (done) {
  3413. resolve(textContent);
  3414. return;
  3415. }
  3416. Object.assign(textContent.styles, value.styles);
  3417. textContent.items.push(...value.items);
  3418. pump();
  3419. }, reject);
  3420. }
  3421. const reader = readableStream.getReader();
  3422. const textContent = {
  3423. items: [],
  3424. styles: Object.create(null)
  3425. };
  3426. pump();
  3427. });
  3428. }
  3429. getStructTree() {
  3430. return this._transport.getStructTree(this._pageIndex);
  3431. }
  3432. _destroy() {
  3433. this.destroyed = true;
  3434. const waitOn = [];
  3435. for (const intentState of this._intentStates.values()) {
  3436. this._abortOperatorList({
  3437. intentState,
  3438. reason: new Error("Page was destroyed."),
  3439. force: true
  3440. });
  3441. if (intentState.opListReadCapability) {
  3442. continue;
  3443. }
  3444. for (const internalRenderTask of intentState.renderTasks) {
  3445. waitOn.push(internalRenderTask.completed);
  3446. internalRenderTask.cancel();
  3447. }
  3448. }
  3449. this.objs.clear();
  3450. this.#pendingCleanup = false;
  3451. this.#abortDelayedCleanup();
  3452. return Promise.all(waitOn);
  3453. }
  3454. cleanup(resetStats = false) {
  3455. this.#pendingCleanup = true;
  3456. const success = this.#tryCleanup(false);
  3457. if (resetStats && success) {
  3458. this._stats &&= new _display_utils_js__WEBPACK_IMPORTED_MODULE_2__.StatTimer();
  3459. }
  3460. return success;
  3461. }
  3462. #tryCleanup(delayed = false) {
  3463. this.#abortDelayedCleanup();
  3464. if (!this.#pendingCleanup || this.destroyed) {
  3465. return false;
  3466. }
  3467. if (delayed) {
  3468. this.#delayedCleanupTimeout = setTimeout(() => {
  3469. this.#delayedCleanupTimeout = null;
  3470. this.#tryCleanup(false);
  3471. }, DELAYED_CLEANUP_TIMEOUT);
  3472. return false;
  3473. }
  3474. for (const {
  3475. renderTasks,
  3476. operatorList
  3477. } of this._intentStates.values()) {
  3478. if (renderTasks.size > 0 || !operatorList.lastChunk) {
  3479. return false;
  3480. }
  3481. }
  3482. this._intentStates.clear();
  3483. this.objs.clear();
  3484. this.#pendingCleanup = false;
  3485. return true;
  3486. }
  3487. #abortDelayedCleanup() {
  3488. if (this.#delayedCleanupTimeout) {
  3489. clearTimeout(this.#delayedCleanupTimeout);
  3490. this.#delayedCleanupTimeout = null;
  3491. }
  3492. }
  3493. _startRenderPage(transparency, cacheKey) {
  3494. const intentState = this._intentStates.get(cacheKey);
  3495. if (!intentState) {
  3496. return;
  3497. }
  3498. this._stats?.timeEnd("Page Request");
  3499. intentState.displayReadyCapability?.resolve(transparency);
  3500. }
  3501. _renderPageChunk(operatorListChunk, intentState) {
  3502. for (let i = 0, ii = operatorListChunk.length; i < ii; i++) {
  3503. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  3504. intentState.operatorList.argsArray.push(operatorListChunk.argsArray[i]);
  3505. }
  3506. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  3507. intentState.operatorList.separateAnnots = operatorListChunk.separateAnnots;
  3508. for (const internalRenderTask of intentState.renderTasks) {
  3509. internalRenderTask.operatorListChanged();
  3510. }
  3511. if (operatorListChunk.lastChunk) {
  3512. this.#tryCleanup(true);
  3513. }
  3514. }
  3515. _pumpOperatorList({
  3516. renderingIntent,
  3517. cacheKey,
  3518. annotationStorageSerializable
  3519. }) {
  3520. const {
  3521. map,
  3522. transfer
  3523. } = annotationStorageSerializable;
  3524. const readableStream = this._transport.messageHandler.sendWithStream("GetOperatorList", {
  3525. pageIndex: this._pageIndex,
  3526. intent: renderingIntent,
  3527. cacheKey,
  3528. annotationStorage: map
  3529. }, transfer);
  3530. const reader = readableStream.getReader();
  3531. const intentState = this._intentStates.get(cacheKey);
  3532. intentState.streamReader = reader;
  3533. const pump = () => {
  3534. reader.read().then(({
  3535. value,
  3536. done
  3537. }) => {
  3538. if (done) {
  3539. intentState.streamReader = null;
  3540. return;
  3541. }
  3542. if (this._transport.destroyed) {
  3543. return;
  3544. }
  3545. this._renderPageChunk(value, intentState);
  3546. pump();
  3547. }, reason => {
  3548. intentState.streamReader = null;
  3549. if (this._transport.destroyed) {
  3550. return;
  3551. }
  3552. if (intentState.operatorList) {
  3553. intentState.operatorList.lastChunk = true;
  3554. for (const internalRenderTask of intentState.renderTasks) {
  3555. internalRenderTask.operatorListChanged();
  3556. }
  3557. this.#tryCleanup(true);
  3558. }
  3559. if (intentState.displayReadyCapability) {
  3560. intentState.displayReadyCapability.reject(reason);
  3561. } else if (intentState.opListReadCapability) {
  3562. intentState.opListReadCapability.reject(reason);
  3563. } else {
  3564. throw reason;
  3565. }
  3566. });
  3567. };
  3568. pump();
  3569. }
  3570. _abortOperatorList({
  3571. intentState,
  3572. reason,
  3573. force = false
  3574. }) {
  3575. if (!intentState.streamReader) {
  3576. return;
  3577. }
  3578. if (intentState.streamReaderCancelTimeout) {
  3579. clearTimeout(intentState.streamReaderCancelTimeout);
  3580. intentState.streamReaderCancelTimeout = null;
  3581. }
  3582. if (!force) {
  3583. if (intentState.renderTasks.size > 0) {
  3584. return;
  3585. }
  3586. if (reason instanceof _display_utils_js__WEBPACK_IMPORTED_MODULE_2__.RenderingCancelledException) {
  3587. let delay = RENDERING_CANCELLED_TIMEOUT;
  3588. if (reason.extraDelay > 0 && reason.extraDelay < 1000) {
  3589. delay += reason.extraDelay;
  3590. }
  3591. intentState.streamReaderCancelTimeout = setTimeout(() => {
  3592. intentState.streamReaderCancelTimeout = null;
  3593. this._abortOperatorList({
  3594. intentState,
  3595. reason,
  3596. force: true
  3597. });
  3598. }, delay);
  3599. return;
  3600. }
  3601. }
  3602. intentState.streamReader.cancel(new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AbortException(reason.message)).catch(() => {});
  3603. intentState.streamReader = null;
  3604. if (this._transport.destroyed) {
  3605. return;
  3606. }
  3607. for (const [curCacheKey, curIntentState] of this._intentStates) {
  3608. if (curIntentState === intentState) {
  3609. this._intentStates.delete(curCacheKey);
  3610. break;
  3611. }
  3612. }
  3613. this.cleanup();
  3614. }
  3615. get stats() {
  3616. return this._stats;
  3617. }
  3618. }
  3619. class LoopbackPort {
  3620. #listeners = new Set();
  3621. #deferred = Promise.resolve();
  3622. postMessage(obj, transfer) {
  3623. const event = {
  3624. data: structuredClone(obj, transfer ? {
  3625. transfer
  3626. } : null)
  3627. };
  3628. this.#deferred.then(() => {
  3629. for (const listener of this.#listeners) {
  3630. listener.call(this, event);
  3631. }
  3632. });
  3633. }
  3634. addEventListener(name, listener) {
  3635. this.#listeners.add(listener);
  3636. }
  3637. removeEventListener(name, listener) {
  3638. this.#listeners.delete(listener);
  3639. }
  3640. terminate() {
  3641. this.#listeners.clear();
  3642. }
  3643. }
  3644. const PDFWorkerUtil = {
  3645. isWorkerDisabled: false,
  3646. fakeWorkerId: 0
  3647. };
  3648. {
  3649. if (_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.isNodeJS) {
  3650. PDFWorkerUtil.isWorkerDisabled = true;
  3651. _worker_options_js__WEBPACK_IMPORTED_MODULE_14__.GlobalWorkerOptions.workerSrc ||= "./pdf.worker.mjs";
  3652. }
  3653. PDFWorkerUtil.isSameOrigin = function (baseUrl, otherUrl) {
  3654. let base;
  3655. try {
  3656. base = new URL(baseUrl);
  3657. if (!base.origin || base.origin === "null") {
  3658. return false;
  3659. }
  3660. } catch {
  3661. return false;
  3662. }
  3663. const other = new URL(otherUrl, base);
  3664. return base.origin === other.origin;
  3665. };
  3666. PDFWorkerUtil.createCDNWrapper = function (url) {
  3667. const wrapper = `await import("${url}");`;
  3668. return URL.createObjectURL(new Blob([wrapper], {
  3669. type: "text/javascript"
  3670. }));
  3671. };
  3672. }
  3673. class PDFWorker {
  3674. static #workerPorts;
  3675. constructor({
  3676. name = null,
  3677. port = null,
  3678. verbosity = (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.getVerbosityLevel)()
  3679. } = {}) {
  3680. this.name = name;
  3681. this.destroyed = false;
  3682. this.verbosity = verbosity;
  3683. this._readyCapability = Promise.withResolvers();
  3684. this._port = null;
  3685. this._webWorker = null;
  3686. this._messageHandler = null;
  3687. if (port) {
  3688. if (PDFWorker.#workerPorts?.has(port)) {
  3689. throw new Error("Cannot use more than one PDFWorker per port.");
  3690. }
  3691. (PDFWorker.#workerPorts ||= new WeakMap()).set(port, this);
  3692. this._initializeFromPort(port);
  3693. return;
  3694. }
  3695. this._initialize();
  3696. }
  3697. get promise() {
  3698. return this._readyCapability.promise;
  3699. }
  3700. get port() {
  3701. return this._port;
  3702. }
  3703. get messageHandler() {
  3704. return this._messageHandler;
  3705. }
  3706. _initializeFromPort(port) {
  3707. this._port = port;
  3708. this._messageHandler = new _shared_message_handler_js__WEBPACK_IMPORTED_MODULE_7__.MessageHandler("main", "worker", port);
  3709. this._messageHandler.on("ready", function () {});
  3710. this._readyCapability.resolve();
  3711. this._messageHandler.send("configure", {
  3712. verbosity: this.verbosity
  3713. });
  3714. }
  3715. _initialize() {
  3716. if (!PDFWorkerUtil.isWorkerDisabled && !PDFWorker.#mainThreadWorkerMessageHandler) {
  3717. let {
  3718. workerSrc
  3719. } = PDFWorker;
  3720. try {
  3721. if (!PDFWorkerUtil.isSameOrigin(window.location.href, workerSrc)) {
  3722. workerSrc = PDFWorkerUtil.createCDNWrapper(new URL(workerSrc, window.location).href);
  3723. }
  3724. const worker = new Worker(workerSrc, {
  3725. type: "module"
  3726. });
  3727. const messageHandler = new _shared_message_handler_js__WEBPACK_IMPORTED_MODULE_7__.MessageHandler("main", "worker", worker);
  3728. const terminateEarly = () => {
  3729. worker.removeEventListener("error", onWorkerError);
  3730. messageHandler.destroy();
  3731. worker.terminate();
  3732. if (this.destroyed) {
  3733. this._readyCapability.reject(new Error("Worker was destroyed"));
  3734. } else {
  3735. this._setupFakeWorker();
  3736. }
  3737. };
  3738. const onWorkerError = () => {
  3739. if (!this._webWorker) {
  3740. terminateEarly();
  3741. }
  3742. };
  3743. worker.addEventListener("error", onWorkerError);
  3744. messageHandler.on("test", data => {
  3745. worker.removeEventListener("error", onWorkerError);
  3746. if (this.destroyed) {
  3747. terminateEarly();
  3748. return;
  3749. }
  3750. if (data) {
  3751. this._messageHandler = messageHandler;
  3752. this._port = worker;
  3753. this._webWorker = worker;
  3754. this._readyCapability.resolve();
  3755. messageHandler.send("configure", {
  3756. verbosity: this.verbosity
  3757. });
  3758. } else {
  3759. this._setupFakeWorker();
  3760. messageHandler.destroy();
  3761. worker.terminate();
  3762. }
  3763. });
  3764. messageHandler.on("ready", data => {
  3765. worker.removeEventListener("error", onWorkerError);
  3766. if (this.destroyed) {
  3767. terminateEarly();
  3768. return;
  3769. }
  3770. try {
  3771. sendTest();
  3772. } catch {
  3773. this._setupFakeWorker();
  3774. }
  3775. });
  3776. const sendTest = () => {
  3777. const testObj = new Uint8Array();
  3778. messageHandler.send("test", testObj, [testObj.buffer]);
  3779. };
  3780. sendTest();
  3781. return;
  3782. } catch {
  3783. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.info)("The worker has been disabled.");
  3784. }
  3785. }
  3786. this._setupFakeWorker();
  3787. }
  3788. _setupFakeWorker() {
  3789. if (!PDFWorkerUtil.isWorkerDisabled) {
  3790. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)("Setting up fake worker.");
  3791. PDFWorkerUtil.isWorkerDisabled = true;
  3792. }
  3793. PDFWorker._setupFakeWorkerGlobal.then(WorkerMessageHandler => {
  3794. if (this.destroyed) {
  3795. this._readyCapability.reject(new Error("Worker was destroyed"));
  3796. return;
  3797. }
  3798. const port = new LoopbackPort();
  3799. this._port = port;
  3800. const id = `fake${PDFWorkerUtil.fakeWorkerId++}`;
  3801. const workerHandler = new _shared_message_handler_js__WEBPACK_IMPORTED_MODULE_7__.MessageHandler(id + "_worker", id, port);
  3802. WorkerMessageHandler.setup(workerHandler, port);
  3803. const messageHandler = new _shared_message_handler_js__WEBPACK_IMPORTED_MODULE_7__.MessageHandler(id, id + "_worker", port);
  3804. this._messageHandler = messageHandler;
  3805. this._readyCapability.resolve();
  3806. messageHandler.send("configure", {
  3807. verbosity: this.verbosity
  3808. });
  3809. }).catch(reason => {
  3810. this._readyCapability.reject(new Error(`Setting up fake worker failed: "${reason.message}".`));
  3811. });
  3812. }
  3813. destroy() {
  3814. this.destroyed = true;
  3815. if (this._webWorker) {
  3816. this._webWorker.terminate();
  3817. this._webWorker = null;
  3818. }
  3819. PDFWorker.#workerPorts?.delete(this._port);
  3820. this._port = null;
  3821. if (this._messageHandler) {
  3822. this._messageHandler.destroy();
  3823. this._messageHandler = null;
  3824. }
  3825. }
  3826. static fromPort(params) {
  3827. if (!params?.port) {
  3828. throw new Error("PDFWorker.fromPort - invalid method signature.");
  3829. }
  3830. const cachedPort = this.#workerPorts?.get(params.port);
  3831. if (cachedPort) {
  3832. if (cachedPort._pendingDestroy) {
  3833. throw new Error("PDFWorker.fromPort - the worker is being destroyed.\n" + "Please remember to await `PDFDocumentLoadingTask.destroy()`-calls.");
  3834. }
  3835. return cachedPort;
  3836. }
  3837. return new PDFWorker(params);
  3838. }
  3839. static get workerSrc() {
  3840. if (_worker_options_js__WEBPACK_IMPORTED_MODULE_14__.GlobalWorkerOptions.workerSrc) {
  3841. return _worker_options_js__WEBPACK_IMPORTED_MODULE_14__.GlobalWorkerOptions.workerSrc;
  3842. }
  3843. throw new Error('No "GlobalWorkerOptions.workerSrc" specified.');
  3844. }
  3845. static get #mainThreadWorkerMessageHandler() {
  3846. try {
  3847. return globalThis.pdfjsWorker?.WorkerMessageHandler || null;
  3848. } catch {
  3849. return null;
  3850. }
  3851. }
  3852. static get _setupFakeWorkerGlobal() {
  3853. const loader = async () => {
  3854. if (this.#mainThreadWorkerMessageHandler) {
  3855. return this.#mainThreadWorkerMessageHandler;
  3856. }
  3857. const worker = await import( /*webpackIgnore: true*/this.workerSrc);
  3858. return worker.WorkerMessageHandler;
  3859. };
  3860. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow)(this, "_setupFakeWorkerGlobal", loader());
  3861. }
  3862. }
  3863. class WorkerTransport {
  3864. #methodPromises = new Map();
  3865. #pageCache = new Map();
  3866. #pagePromises = new Map();
  3867. #pageRefCache = new Map();
  3868. #passwordCapability = null;
  3869. constructor(messageHandler, loadingTask, networkStream, params, factory) {
  3870. this.messageHandler = messageHandler;
  3871. this.loadingTask = loadingTask;
  3872. this.commonObjs = new PDFObjects();
  3873. this.fontLoader = new _font_loader_js__WEBPACK_IMPORTED_MODULE_3__.FontLoader({
  3874. ownerDocument: params.ownerDocument,
  3875. styleElement: params.styleElement
  3876. });
  3877. this._params = params;
  3878. this.canvasFactory = factory.canvasFactory;
  3879. this.filterFactory = factory.filterFactory;
  3880. this.cMapReaderFactory = factory.cMapReaderFactory;
  3881. this.standardFontDataFactory = factory.standardFontDataFactory;
  3882. this.destroyed = false;
  3883. this.destroyCapability = null;
  3884. this._networkStream = networkStream;
  3885. this._fullReader = null;
  3886. this._lastProgress = null;
  3887. this.downloadInfoCapability = Promise.withResolvers();
  3888. this.setupMessageHandler();
  3889. }
  3890. #cacheSimpleMethod(name, data = null) {
  3891. const cachedPromise = this.#methodPromises.get(name);
  3892. if (cachedPromise) {
  3893. return cachedPromise;
  3894. }
  3895. const promise = this.messageHandler.sendWithPromise(name, data);
  3896. this.#methodPromises.set(name, promise);
  3897. return promise;
  3898. }
  3899. get annotationStorage() {
  3900. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow)(this, "annotationStorage", new _annotation_storage_js__WEBPACK_IMPORTED_MODULE_1__.AnnotationStorage());
  3901. }
  3902. getRenderingIntent(intent, annotationMode = _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationMode.ENABLE, printAnnotationStorage = null, isOpList = false) {
  3903. let renderingIntent = _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.RenderingIntentFlag.DISPLAY;
  3904. let annotationStorageSerializable = _annotation_storage_js__WEBPACK_IMPORTED_MODULE_1__.SerializableEmpty;
  3905. switch (intent) {
  3906. case "any":
  3907. renderingIntent = _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.RenderingIntentFlag.ANY;
  3908. break;
  3909. case "display":
  3910. break;
  3911. case "print":
  3912. renderingIntent = _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.RenderingIntentFlag.PRINT;
  3913. break;
  3914. default:
  3915. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`getRenderingIntent - invalid intent: ${intent}`);
  3916. }
  3917. switch (annotationMode) {
  3918. case _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationMode.DISABLE:
  3919. renderingIntent += _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.RenderingIntentFlag.ANNOTATIONS_DISABLE;
  3920. break;
  3921. case _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationMode.ENABLE:
  3922. break;
  3923. case _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationMode.ENABLE_FORMS:
  3924. renderingIntent += _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.RenderingIntentFlag.ANNOTATIONS_FORMS;
  3925. break;
  3926. case _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationMode.ENABLE_STORAGE:
  3927. renderingIntent += _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.RenderingIntentFlag.ANNOTATIONS_STORAGE;
  3928. 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;
  3929. annotationStorageSerializable = annotationStorage.serializable;
  3930. break;
  3931. default:
  3932. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`getRenderingIntent - invalid annotationMode: ${annotationMode}`);
  3933. }
  3934. if (isOpList) {
  3935. renderingIntent += _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.RenderingIntentFlag.OPLIST;
  3936. }
  3937. return {
  3938. renderingIntent,
  3939. cacheKey: `${renderingIntent}_${annotationStorageSerializable.hash}`,
  3940. annotationStorageSerializable
  3941. };
  3942. }
  3943. destroy() {
  3944. if (this.destroyCapability) {
  3945. return this.destroyCapability.promise;
  3946. }
  3947. this.destroyed = true;
  3948. this.destroyCapability = Promise.withResolvers();
  3949. this.#passwordCapability?.reject(new Error("Worker was destroyed during onPassword callback"));
  3950. const waitOn = [];
  3951. for (const page of this.#pageCache.values()) {
  3952. waitOn.push(page._destroy());
  3953. }
  3954. this.#pageCache.clear();
  3955. this.#pagePromises.clear();
  3956. this.#pageRefCache.clear();
  3957. if (this.hasOwnProperty("annotationStorage")) {
  3958. this.annotationStorage.resetModified();
  3959. }
  3960. const terminated = this.messageHandler.sendWithPromise("Terminate", null);
  3961. waitOn.push(terminated);
  3962. Promise.all(waitOn).then(() => {
  3963. this.commonObjs.clear();
  3964. this.fontLoader.clear();
  3965. this.#methodPromises.clear();
  3966. this.filterFactory.destroy();
  3967. (0,_text_layer_js__WEBPACK_IMPORTED_MODULE_6__.cleanupTextLayer)();
  3968. this._networkStream?.cancelAllRequests(new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AbortException("Worker was terminated."));
  3969. if (this.messageHandler) {
  3970. this.messageHandler.destroy();
  3971. this.messageHandler = null;
  3972. }
  3973. this.destroyCapability.resolve();
  3974. }, this.destroyCapability.reject);
  3975. return this.destroyCapability.promise;
  3976. }
  3977. setupMessageHandler() {
  3978. const {
  3979. messageHandler,
  3980. loadingTask
  3981. } = this;
  3982. messageHandler.on("GetReader", (data, sink) => {
  3983. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(this._networkStream, "GetReader - no `IPDFStream` instance available.");
  3984. this._fullReader = this._networkStream.getFullReader();
  3985. this._fullReader.onProgress = evt => {
  3986. this._lastProgress = {
  3987. loaded: evt.loaded,
  3988. total: evt.total
  3989. };
  3990. };
  3991. sink.onPull = () => {
  3992. this._fullReader.read().then(function ({
  3993. value,
  3994. done
  3995. }) {
  3996. if (done) {
  3997. sink.close();
  3998. return;
  3999. }
  4000. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(value instanceof ArrayBuffer, "GetReader - expected an ArrayBuffer.");
  4001. sink.enqueue(new Uint8Array(value), 1, [value]);
  4002. }).catch(reason => {
  4003. sink.error(reason);
  4004. });
  4005. };
  4006. sink.onCancel = reason => {
  4007. this._fullReader.cancel(reason);
  4008. sink.ready.catch(readyReason => {
  4009. if (this.destroyed) {
  4010. return;
  4011. }
  4012. throw readyReason;
  4013. });
  4014. };
  4015. });
  4016. messageHandler.on("ReaderHeadersReady", data => {
  4017. const headersCapability = Promise.withResolvers();
  4018. const fullReader = this._fullReader;
  4019. fullReader.headersReady.then(() => {
  4020. if (!fullReader.isStreamingSupported || !fullReader.isRangeSupported) {
  4021. if (this._lastProgress) {
  4022. loadingTask.onProgress?.(this._lastProgress);
  4023. }
  4024. fullReader.onProgress = evt => {
  4025. loadingTask.onProgress?.({
  4026. loaded: evt.loaded,
  4027. total: evt.total
  4028. });
  4029. };
  4030. }
  4031. headersCapability.resolve({
  4032. isStreamingSupported: fullReader.isStreamingSupported,
  4033. isRangeSupported: fullReader.isRangeSupported,
  4034. contentLength: fullReader.contentLength
  4035. });
  4036. }, headersCapability.reject);
  4037. return headersCapability.promise;
  4038. });
  4039. messageHandler.on("GetRangeReader", (data, sink) => {
  4040. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(this._networkStream, "GetRangeReader - no `IPDFStream` instance available.");
  4041. const rangeReader = this._networkStream.getRangeReader(data.begin, data.end);
  4042. if (!rangeReader) {
  4043. sink.close();
  4044. return;
  4045. }
  4046. sink.onPull = () => {
  4047. rangeReader.read().then(function ({
  4048. value,
  4049. done
  4050. }) {
  4051. if (done) {
  4052. sink.close();
  4053. return;
  4054. }
  4055. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(value instanceof ArrayBuffer, "GetRangeReader - expected an ArrayBuffer.");
  4056. sink.enqueue(new Uint8Array(value), 1, [value]);
  4057. }).catch(reason => {
  4058. sink.error(reason);
  4059. });
  4060. };
  4061. sink.onCancel = reason => {
  4062. rangeReader.cancel(reason);
  4063. sink.ready.catch(readyReason => {
  4064. if (this.destroyed) {
  4065. return;
  4066. }
  4067. throw readyReason;
  4068. });
  4069. };
  4070. });
  4071. messageHandler.on("GetDoc", ({
  4072. pdfInfo
  4073. }) => {
  4074. this._numPages = pdfInfo.numPages;
  4075. this._htmlForXfa = pdfInfo.htmlForXfa;
  4076. delete pdfInfo.htmlForXfa;
  4077. loadingTask._capability.resolve(new PDFDocumentProxy(pdfInfo, this));
  4078. });
  4079. messageHandler.on("DocException", function (ex) {
  4080. let reason;
  4081. switch (ex.name) {
  4082. case "PasswordException":
  4083. reason = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PasswordException(ex.message, ex.code);
  4084. break;
  4085. case "InvalidPDFException":
  4086. reason = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.InvalidPDFException(ex.message);
  4087. break;
  4088. case "MissingPDFException":
  4089. reason = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.MissingPDFException(ex.message);
  4090. break;
  4091. case "UnexpectedResponseException":
  4092. reason = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.UnexpectedResponseException(ex.message, ex.status);
  4093. break;
  4094. case "UnknownErrorException":
  4095. reason = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.UnknownErrorException(ex.message, ex.details);
  4096. break;
  4097. default:
  4098. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.unreachable)("DocException - expected a valid Error.");
  4099. }
  4100. loadingTask._capability.reject(reason);
  4101. });
  4102. messageHandler.on("PasswordRequest", exception => {
  4103. this.#passwordCapability = Promise.withResolvers();
  4104. if (loadingTask.onPassword) {
  4105. const updatePassword = password => {
  4106. if (password instanceof Error) {
  4107. this.#passwordCapability.reject(password);
  4108. } else {
  4109. this.#passwordCapability.resolve({
  4110. password
  4111. });
  4112. }
  4113. };
  4114. try {
  4115. loadingTask.onPassword(updatePassword, exception.code);
  4116. } catch (ex) {
  4117. this.#passwordCapability.reject(ex);
  4118. }
  4119. } else {
  4120. this.#passwordCapability.reject(new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PasswordException(exception.message, exception.code));
  4121. }
  4122. return this.#passwordCapability.promise;
  4123. });
  4124. messageHandler.on("DataLoaded", data => {
  4125. loadingTask.onProgress?.({
  4126. loaded: data.length,
  4127. total: data.length
  4128. });
  4129. this.downloadInfoCapability.resolve(data);
  4130. });
  4131. messageHandler.on("StartRenderPage", data => {
  4132. if (this.destroyed) {
  4133. return;
  4134. }
  4135. const page = this.#pageCache.get(data.pageIndex);
  4136. page._startRenderPage(data.transparency, data.cacheKey);
  4137. });
  4138. messageHandler.on("commonobj", ([id, type, exportedData]) => {
  4139. if (this.destroyed) {
  4140. return null;
  4141. }
  4142. if (this.commonObjs.has(id)) {
  4143. return null;
  4144. }
  4145. switch (type) {
  4146. case "Font":
  4147. const params = this._params;
  4148. if ("error" in exportedData) {
  4149. const exportedError = exportedData.error;
  4150. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`Error during font loading: ${exportedError}`);
  4151. this.commonObjs.resolve(id, exportedError);
  4152. break;
  4153. }
  4154. const inspectFont = params.pdfBug && globalThis.FontInspector?.enabled ? (font, url) => globalThis.FontInspector.fontAdded(font, url) : null;
  4155. const font = new _font_loader_js__WEBPACK_IMPORTED_MODULE_3__.FontFaceObject(exportedData, {
  4156. disableFontFace: params.disableFontFace,
  4157. ignoreErrors: params.ignoreErrors,
  4158. inspectFont
  4159. });
  4160. this.fontLoader.bind(font).catch(() => messageHandler.sendWithPromise("FontFallback", {
  4161. id
  4162. })).finally(() => {
  4163. if (!params.fontExtraProperties && font.data) {
  4164. font.data = null;
  4165. }
  4166. this.commonObjs.resolve(id, font);
  4167. });
  4168. break;
  4169. case "CopyLocalImage":
  4170. const {
  4171. imageRef
  4172. } = exportedData;
  4173. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(imageRef, "The imageRef must be defined.");
  4174. for (const pageProxy of this.#pageCache.values()) {
  4175. for (const [, data] of pageProxy.objs) {
  4176. if (data.ref !== imageRef) {
  4177. continue;
  4178. }
  4179. if (!data.dataLen) {
  4180. return null;
  4181. }
  4182. this.commonObjs.resolve(id, structuredClone(data));
  4183. return data.dataLen;
  4184. }
  4185. }
  4186. break;
  4187. case "FontPath":
  4188. case "Image":
  4189. case "Pattern":
  4190. this.commonObjs.resolve(id, exportedData);
  4191. break;
  4192. default:
  4193. throw new Error(`Got unknown common object type ${type}`);
  4194. }
  4195. return null;
  4196. });
  4197. messageHandler.on("obj", ([id, pageIndex, type, imageData]) => {
  4198. if (this.destroyed) {
  4199. return;
  4200. }
  4201. const pageProxy = this.#pageCache.get(pageIndex);
  4202. if (pageProxy.objs.has(id)) {
  4203. return;
  4204. }
  4205. if (pageProxy._intentStates.size === 0) {
  4206. imageData?.bitmap?.close();
  4207. return;
  4208. }
  4209. switch (type) {
  4210. case "Image":
  4211. pageProxy.objs.resolve(id, imageData);
  4212. if (imageData?.dataLen > _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.MAX_IMAGE_SIZE_TO_CACHE) {
  4213. pageProxy._maybeCleanupAfterRender = true;
  4214. }
  4215. break;
  4216. case "Pattern":
  4217. pageProxy.objs.resolve(id, imageData);
  4218. break;
  4219. default:
  4220. throw new Error(`Got unknown object type ${type}`);
  4221. }
  4222. });
  4223. messageHandler.on("DocProgress", data => {
  4224. if (this.destroyed) {
  4225. return;
  4226. }
  4227. loadingTask.onProgress?.({
  4228. loaded: data.loaded,
  4229. total: data.total
  4230. });
  4231. });
  4232. messageHandler.on("FetchBuiltInCMap", data => {
  4233. if (this.destroyed) {
  4234. return Promise.reject(new Error("Worker was destroyed."));
  4235. }
  4236. if (!this.cMapReaderFactory) {
  4237. return Promise.reject(new Error("CMapReaderFactory not initialized, see the `useWorkerFetch` parameter."));
  4238. }
  4239. return this.cMapReaderFactory.fetch(data);
  4240. });
  4241. messageHandler.on("FetchStandardFontData", data => {
  4242. if (this.destroyed) {
  4243. return Promise.reject(new Error("Worker was destroyed."));
  4244. }
  4245. if (!this.standardFontDataFactory) {
  4246. return Promise.reject(new Error("StandardFontDataFactory not initialized, see the `useWorkerFetch` parameter."));
  4247. }
  4248. return this.standardFontDataFactory.fetch(data);
  4249. });
  4250. }
  4251. getData() {
  4252. return this.messageHandler.sendWithPromise("GetData", null);
  4253. }
  4254. saveDocument() {
  4255. if (this.annotationStorage.size <= 0) {
  4256. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)("saveDocument called while `annotationStorage` is empty, " + "please use the getData-method instead.");
  4257. }
  4258. const {
  4259. map,
  4260. transfer
  4261. } = this.annotationStorage.serializable;
  4262. return this.messageHandler.sendWithPromise("SaveDocument", {
  4263. isPureXfa: !!this._htmlForXfa,
  4264. numPages: this._numPages,
  4265. annotationStorage: map,
  4266. filename: this._fullReader?.filename ?? null
  4267. }, transfer).finally(() => {
  4268. this.annotationStorage.resetModified();
  4269. });
  4270. }
  4271. getPage(pageNumber) {
  4272. if (!Number.isInteger(pageNumber) || pageNumber <= 0 || pageNumber > this._numPages) {
  4273. return Promise.reject(new Error("Invalid page request."));
  4274. }
  4275. const pageIndex = pageNumber - 1,
  4276. cachedPromise = this.#pagePromises.get(pageIndex);
  4277. if (cachedPromise) {
  4278. return cachedPromise;
  4279. }
  4280. const promise = this.messageHandler.sendWithPromise("GetPage", {
  4281. pageIndex
  4282. }).then(pageInfo => {
  4283. if (this.destroyed) {
  4284. throw new Error("Transport destroyed");
  4285. }
  4286. if (pageInfo.refStr) {
  4287. this.#pageRefCache.set(pageInfo.refStr, pageNumber);
  4288. }
  4289. const page = new PDFPageProxy(pageIndex, pageInfo, this, this._params.pdfBug);
  4290. this.#pageCache.set(pageIndex, page);
  4291. return page;
  4292. });
  4293. this.#pagePromises.set(pageIndex, promise);
  4294. return promise;
  4295. }
  4296. getPageIndex(ref) {
  4297. if (!isRefProxy(ref)) {
  4298. return Promise.reject(new Error("Invalid pageIndex request."));
  4299. }
  4300. return this.messageHandler.sendWithPromise("GetPageIndex", {
  4301. num: ref.num,
  4302. gen: ref.gen
  4303. });
  4304. }
  4305. getAnnotations(pageIndex, intent) {
  4306. return this.messageHandler.sendWithPromise("GetAnnotations", {
  4307. pageIndex,
  4308. intent
  4309. });
  4310. }
  4311. getFieldObjects() {
  4312. return this.#cacheSimpleMethod("GetFieldObjects");
  4313. }
  4314. hasJSActions() {
  4315. return this.#cacheSimpleMethod("HasJSActions");
  4316. }
  4317. getCalculationOrderIds() {
  4318. return this.messageHandler.sendWithPromise("GetCalculationOrderIds", null);
  4319. }
  4320. getDestinations() {
  4321. return this.messageHandler.sendWithPromise("GetDestinations", null);
  4322. }
  4323. getDestination(id) {
  4324. if (typeof id !== "string") {
  4325. return Promise.reject(new Error("Invalid destination request."));
  4326. }
  4327. return this.messageHandler.sendWithPromise("GetDestination", {
  4328. id
  4329. });
  4330. }
  4331. getPageLabels() {
  4332. return this.messageHandler.sendWithPromise("GetPageLabels", null);
  4333. }
  4334. getPageLayout() {
  4335. return this.messageHandler.sendWithPromise("GetPageLayout", null);
  4336. }
  4337. getPageMode() {
  4338. return this.messageHandler.sendWithPromise("GetPageMode", null);
  4339. }
  4340. getViewerPreferences() {
  4341. return this.messageHandler.sendWithPromise("GetViewerPreferences", null);
  4342. }
  4343. getOpenAction() {
  4344. return this.messageHandler.sendWithPromise("GetOpenAction", null);
  4345. }
  4346. getAttachments() {
  4347. return this.messageHandler.sendWithPromise("GetAttachments", null);
  4348. }
  4349. getDocJSActions() {
  4350. return this.#cacheSimpleMethod("GetDocJSActions");
  4351. }
  4352. getPageJSActions(pageIndex) {
  4353. return this.messageHandler.sendWithPromise("GetPageJSActions", {
  4354. pageIndex
  4355. });
  4356. }
  4357. getStructTree(pageIndex) {
  4358. return this.messageHandler.sendWithPromise("GetStructTree", {
  4359. pageIndex
  4360. });
  4361. }
  4362. getOutline() {
  4363. return this.messageHandler.sendWithPromise("GetOutline", null);
  4364. }
  4365. getOptionalContentConfig(renderingIntent) {
  4366. return this.#cacheSimpleMethod("GetOptionalContentConfig").then(data => new _optional_content_config_js__WEBPACK_IMPORTED_MODULE_9__.OptionalContentConfig(data, renderingIntent));
  4367. }
  4368. getPermissions() {
  4369. return this.messageHandler.sendWithPromise("GetPermissions", null);
  4370. }
  4371. getMetadata() {
  4372. const name = "GetMetadata",
  4373. cachedPromise = this.#methodPromises.get(name);
  4374. if (cachedPromise) {
  4375. return cachedPromise;
  4376. }
  4377. const promise = this.messageHandler.sendWithPromise(name, null).then(results => ({
  4378. info: results[0],
  4379. metadata: results[1] ? new _metadata_js__WEBPACK_IMPORTED_MODULE_8__.Metadata(results[1]) : null,
  4380. contentDispositionFilename: this._fullReader?.filename ?? null,
  4381. contentLength: this._fullReader?.contentLength ?? null
  4382. }));
  4383. this.#methodPromises.set(name, promise);
  4384. return promise;
  4385. }
  4386. getMarkInfo() {
  4387. return this.messageHandler.sendWithPromise("GetMarkInfo", null);
  4388. }
  4389. async startCleanup(keepLoadedFonts = false) {
  4390. if (this.destroyed) {
  4391. return;
  4392. }
  4393. await this.messageHandler.sendWithPromise("Cleanup", null);
  4394. for (const page of this.#pageCache.values()) {
  4395. const cleanupSuccessful = page.cleanup();
  4396. if (!cleanupSuccessful) {
  4397. throw new Error(`startCleanup: Page ${page.pageNumber} is currently rendering.`);
  4398. }
  4399. }
  4400. this.commonObjs.clear();
  4401. if (!keepLoadedFonts) {
  4402. this.fontLoader.clear();
  4403. }
  4404. this.#methodPromises.clear();
  4405. this.filterFactory.destroy(true);
  4406. (0,_text_layer_js__WEBPACK_IMPORTED_MODULE_6__.cleanupTextLayer)();
  4407. }
  4408. cachedPageNumber(ref) {
  4409. if (!isRefProxy(ref)) {
  4410. return null;
  4411. }
  4412. const refStr = ref.gen === 0 ? `${ref.num}R` : `${ref.num}R${ref.gen}`;
  4413. return this.#pageRefCache.get(refStr) ?? null;
  4414. }
  4415. get loadingParams() {
  4416. const {
  4417. disableAutoFetch,
  4418. enableXfa
  4419. } = this._params;
  4420. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow)(this, "loadingParams", {
  4421. disableAutoFetch,
  4422. enableXfa
  4423. });
  4424. }
  4425. }
  4426. const INITIAL_DATA = Symbol("INITIAL_DATA");
  4427. class PDFObjects {
  4428. #objs = Object.create(null);
  4429. #ensureObj(objId) {
  4430. return this.#objs[objId] ||= {
  4431. ...Promise.withResolvers(),
  4432. data: INITIAL_DATA
  4433. };
  4434. }
  4435. get(objId, callback = null) {
  4436. if (callback) {
  4437. const obj = this.#ensureObj(objId);
  4438. obj.promise.then(() => callback(obj.data));
  4439. return null;
  4440. }
  4441. const obj = this.#objs[objId];
  4442. if (!obj || obj.data === INITIAL_DATA) {
  4443. throw new Error(`Requesting object that isn't resolved yet ${objId}.`);
  4444. }
  4445. return obj.data;
  4446. }
  4447. has(objId) {
  4448. const obj = this.#objs[objId];
  4449. return !!obj && obj.data !== INITIAL_DATA;
  4450. }
  4451. resolve(objId, data = null) {
  4452. const obj = this.#ensureObj(objId);
  4453. obj.data = data;
  4454. obj.resolve();
  4455. }
  4456. clear() {
  4457. for (const objId in this.#objs) {
  4458. const {
  4459. data
  4460. } = this.#objs[objId];
  4461. data?.bitmap?.close();
  4462. }
  4463. this.#objs = Object.create(null);
  4464. }
  4465. *[Symbol.iterator]() {
  4466. for (const objId in this.#objs) {
  4467. const {
  4468. data
  4469. } = this.#objs[objId];
  4470. if (data === INITIAL_DATA) {
  4471. continue;
  4472. }
  4473. yield [objId, data];
  4474. }
  4475. }
  4476. }
  4477. class RenderTask {
  4478. #internalRenderTask = null;
  4479. constructor(internalRenderTask) {
  4480. this.#internalRenderTask = internalRenderTask;
  4481. this.onContinue = null;
  4482. }
  4483. get promise() {
  4484. return this.#internalRenderTask.capability.promise;
  4485. }
  4486. cancel(extraDelay = 0) {
  4487. this.#internalRenderTask.cancel(null, extraDelay);
  4488. }
  4489. get separateAnnots() {
  4490. const {
  4491. separateAnnots
  4492. } = this.#internalRenderTask.operatorList;
  4493. if (!separateAnnots) {
  4494. return false;
  4495. }
  4496. const {
  4497. annotationCanvasMap
  4498. } = this.#internalRenderTask;
  4499. return separateAnnots.form || separateAnnots.canvas && annotationCanvasMap?.size > 0;
  4500. }
  4501. }
  4502. class InternalRenderTask {
  4503. static #canvasInUse = new WeakSet();
  4504. constructor({
  4505. callback,
  4506. params,
  4507. objs,
  4508. commonObjs,
  4509. annotationCanvasMap,
  4510. operatorList,
  4511. pageIndex,
  4512. canvasFactory,
  4513. filterFactory,
  4514. useRequestAnimationFrame = false,
  4515. pdfBug = false,
  4516. pageColors = null
  4517. }) {
  4518. this.callback = callback;
  4519. this.params = params;
  4520. this.objs = objs;
  4521. this.commonObjs = commonObjs;
  4522. this.annotationCanvasMap = annotationCanvasMap;
  4523. this.operatorListIdx = null;
  4524. this.operatorList = operatorList;
  4525. this._pageIndex = pageIndex;
  4526. this.canvasFactory = canvasFactory;
  4527. this.filterFactory = filterFactory;
  4528. this._pdfBug = pdfBug;
  4529. this.pageColors = pageColors;
  4530. this.running = false;
  4531. this.graphicsReadyCallback = null;
  4532. this.graphicsReady = false;
  4533. this._useRequestAnimationFrame = useRequestAnimationFrame === true && typeof window !== "undefined";
  4534. this.cancelled = false;
  4535. this.capability = Promise.withResolvers();
  4536. this.task = new RenderTask(this);
  4537. this._cancelBound = this.cancel.bind(this);
  4538. this._continueBound = this._continue.bind(this);
  4539. this._scheduleNextBound = this._scheduleNext.bind(this);
  4540. this._nextBound = this._next.bind(this);
  4541. this._canvas = params.canvasContext.canvas;
  4542. }
  4543. get completed() {
  4544. return this.capability.promise.catch(function () {});
  4545. }
  4546. initializeGraphics({
  4547. transparency = false,
  4548. optionalContentConfig
  4549. }) {
  4550. if (this.cancelled) {
  4551. return;
  4552. }
  4553. if (this._canvas) {
  4554. if (InternalRenderTask.#canvasInUse.has(this._canvas)) {
  4555. throw new Error("Cannot use the same canvas during multiple render() operations. " + "Use different canvas or ensure previous operations were " + "cancelled or completed.");
  4556. }
  4557. InternalRenderTask.#canvasInUse.add(this._canvas);
  4558. }
  4559. if (this._pdfBug && globalThis.StepperManager?.enabled) {
  4560. this.stepper = globalThis.StepperManager.create(this._pageIndex);
  4561. this.stepper.init(this.operatorList);
  4562. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  4563. }
  4564. const {
  4565. canvasContext,
  4566. viewport,
  4567. transform,
  4568. background
  4569. } = this.params;
  4570. this.gfx = new _canvas_js__WEBPACK_IMPORTED_MODULE_5__.CanvasGraphics(canvasContext, this.commonObjs, this.objs, this.canvasFactory, this.filterFactory, {
  4571. optionalContentConfig
  4572. }, this.annotationCanvasMap, this.pageColors);
  4573. this.gfx.beginDrawing({
  4574. transform,
  4575. viewport,
  4576. transparency,
  4577. background
  4578. });
  4579. this.operatorListIdx = 0;
  4580. this.graphicsReady = true;
  4581. this.graphicsReadyCallback?.();
  4582. }
  4583. cancel(error = null, extraDelay = 0) {
  4584. this.running = false;
  4585. this.cancelled = true;
  4586. this.gfx?.endDrawing();
  4587. InternalRenderTask.#canvasInUse.delete(this._canvas);
  4588. this.callback(error || new _display_utils_js__WEBPACK_IMPORTED_MODULE_2__.RenderingCancelledException(`Rendering cancelled, page ${this._pageIndex + 1}`, extraDelay));
  4589. }
  4590. operatorListChanged() {
  4591. if (!this.graphicsReady) {
  4592. this.graphicsReadyCallback ||= this._continueBound;
  4593. return;
  4594. }
  4595. this.stepper?.updateOperatorList(this.operatorList);
  4596. if (this.running) {
  4597. return;
  4598. }
  4599. this._continue();
  4600. }
  4601. _continue() {
  4602. this.running = true;
  4603. if (this.cancelled) {
  4604. return;
  4605. }
  4606. if (this.task.onContinue) {
  4607. this.task.onContinue(this._scheduleNextBound);
  4608. } else {
  4609. this._scheduleNext();
  4610. }
  4611. }
  4612. _scheduleNext() {
  4613. if (this._useRequestAnimationFrame) {
  4614. window.requestAnimationFrame(() => {
  4615. this._nextBound().catch(this._cancelBound);
  4616. });
  4617. } else {
  4618. Promise.resolve().then(this._nextBound).catch(this._cancelBound);
  4619. }
  4620. }
  4621. async _next() {
  4622. if (this.cancelled) {
  4623. return;
  4624. }
  4625. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList, this.operatorListIdx, this._continueBound, this.stepper);
  4626. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  4627. this.running = false;
  4628. if (this.operatorList.lastChunk) {
  4629. this.gfx.endDrawing();
  4630. InternalRenderTask.#canvasInUse.delete(this._canvas);
  4631. this.callback();
  4632. }
  4633. }
  4634. }
  4635. }
  4636. const version = "4.2.67";
  4637. const build = "49b388101";
  4638. __webpack_async_result__();
  4639. } catch(e) { __webpack_async_result__(e); } });
  4640. /***/ }),
  4641. /***/ 583:
  4642. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  4643. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  4644. /* harmony export */ BaseCMapReaderFactory: () => (/* binding */ BaseCMapReaderFactory),
  4645. /* harmony export */ BaseCanvasFactory: () => (/* binding */ BaseCanvasFactory),
  4646. /* harmony export */ BaseFilterFactory: () => (/* binding */ BaseFilterFactory),
  4647. /* harmony export */ BaseSVGFactory: () => (/* binding */ BaseSVGFactory),
  4648. /* harmony export */ BaseStandardFontDataFactory: () => (/* binding */ BaseStandardFontDataFactory)
  4649. /* harmony export */ });
  4650. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(292);
  4651. class BaseFilterFactory {
  4652. constructor() {
  4653. if (this.constructor === BaseFilterFactory) {
  4654. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.unreachable)("Cannot initialize BaseFilterFactory.");
  4655. }
  4656. }
  4657. addFilter(maps) {
  4658. return "none";
  4659. }
  4660. addHCMFilter(fgColor, bgColor) {
  4661. return "none";
  4662. }
  4663. addHighlightHCMFilter(filterName, fgColor, bgColor, newFgColor, newBgColor) {
  4664. return "none";
  4665. }
  4666. destroy(keepHCM = false) {}
  4667. }
  4668. class BaseCanvasFactory {
  4669. constructor() {
  4670. if (this.constructor === BaseCanvasFactory) {
  4671. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.unreachable)("Cannot initialize BaseCanvasFactory.");
  4672. }
  4673. }
  4674. create(width, height) {
  4675. if (width <= 0 || height <= 0) {
  4676. throw new Error("Invalid canvas size");
  4677. }
  4678. const canvas = this._createCanvas(width, height);
  4679. return {
  4680. canvas,
  4681. context: canvas.getContext("2d")
  4682. };
  4683. }
  4684. reset(canvasAndContext, width, height) {
  4685. if (!canvasAndContext.canvas) {
  4686. throw new Error("Canvas is not specified");
  4687. }
  4688. if (width <= 0 || height <= 0) {
  4689. throw new Error("Invalid canvas size");
  4690. }
  4691. canvasAndContext.canvas.width = width;
  4692. canvasAndContext.canvas.height = height;
  4693. }
  4694. destroy(canvasAndContext) {
  4695. if (!canvasAndContext.canvas) {
  4696. throw new Error("Canvas is not specified");
  4697. }
  4698. canvasAndContext.canvas.width = 0;
  4699. canvasAndContext.canvas.height = 0;
  4700. canvasAndContext.canvas = null;
  4701. canvasAndContext.context = null;
  4702. }
  4703. _createCanvas(width, height) {
  4704. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.unreachable)("Abstract method `_createCanvas` called.");
  4705. }
  4706. }
  4707. class BaseCMapReaderFactory {
  4708. constructor({
  4709. baseUrl = null,
  4710. isCompressed = true
  4711. }) {
  4712. if (this.constructor === BaseCMapReaderFactory) {
  4713. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.unreachable)("Cannot initialize BaseCMapReaderFactory.");
  4714. }
  4715. this.baseUrl = baseUrl;
  4716. this.isCompressed = isCompressed;
  4717. }
  4718. async fetch({
  4719. name
  4720. }) {
  4721. if (!this.baseUrl) {
  4722. throw new Error('The CMap "baseUrl" parameter must be specified, ensure that ' + 'the "cMapUrl" and "cMapPacked" API parameters are provided.');
  4723. }
  4724. if (!name) {
  4725. throw new Error("CMap name must be specified.");
  4726. }
  4727. const url = this.baseUrl + name + (this.isCompressed ? ".bcmap" : "");
  4728. const compressionType = this.isCompressed ? _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.CMapCompressionType.BINARY : _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.CMapCompressionType.NONE;
  4729. return this._fetchData(url, compressionType).catch(reason => {
  4730. throw new Error(`Unable to load ${this.isCompressed ? "binary " : ""}CMap at: ${url}`);
  4731. });
  4732. }
  4733. _fetchData(url, compressionType) {
  4734. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.unreachable)("Abstract method `_fetchData` called.");
  4735. }
  4736. }
  4737. class BaseStandardFontDataFactory {
  4738. constructor({
  4739. baseUrl = null
  4740. }) {
  4741. if (this.constructor === BaseStandardFontDataFactory) {
  4742. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.unreachable)("Cannot initialize BaseStandardFontDataFactory.");
  4743. }
  4744. this.baseUrl = baseUrl;
  4745. }
  4746. async fetch({
  4747. filename
  4748. }) {
  4749. if (!this.baseUrl) {
  4750. throw new Error('The standard font "baseUrl" parameter must be specified, ensure that ' + 'the "standardFontDataUrl" API parameter is provided.');
  4751. }
  4752. if (!filename) {
  4753. throw new Error("Font filename must be specified.");
  4754. }
  4755. const url = `${this.baseUrl}${filename}`;
  4756. return this._fetchData(url).catch(reason => {
  4757. throw new Error(`Unable to load font data at: ${url}`);
  4758. });
  4759. }
  4760. _fetchData(url) {
  4761. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.unreachable)("Abstract method `_fetchData` called.");
  4762. }
  4763. }
  4764. class BaseSVGFactory {
  4765. constructor() {
  4766. if (this.constructor === BaseSVGFactory) {
  4767. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.unreachable)("Cannot initialize BaseSVGFactory.");
  4768. }
  4769. }
  4770. create(width, height, skipDimensions = false) {
  4771. if (width <= 0 || height <= 0) {
  4772. throw new Error("Invalid SVG dimensions");
  4773. }
  4774. const svg = this._createSVG("svg:svg");
  4775. svg.setAttribute("version", "1.1");
  4776. if (!skipDimensions) {
  4777. svg.setAttribute("width", `${width}px`);
  4778. svg.setAttribute("height", `${height}px`);
  4779. }
  4780. svg.setAttribute("preserveAspectRatio", "none");
  4781. svg.setAttribute("viewBox", `0 0 ${width} ${height}`);
  4782. return svg;
  4783. }
  4784. createElement(type) {
  4785. if (typeof type !== "string") {
  4786. throw new Error("Invalid SVG element type");
  4787. }
  4788. return this._createSVG(type);
  4789. }
  4790. _createSVG(type) {
  4791. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.unreachable)("Abstract method `_createSVG` called.");
  4792. }
  4793. }
  4794. /***/ }),
  4795. /***/ 923:
  4796. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  4797. // EXPORTS
  4798. __webpack_require__.d(__webpack_exports__, {
  4799. CanvasGraphics: () => (/* binding */ CanvasGraphics)
  4800. });
  4801. // EXTERNAL MODULE: ./src/shared/util.js
  4802. var util = __webpack_require__(292);
  4803. // EXTERNAL MODULE: ./src/display/display_utils.js
  4804. var display_utils = __webpack_require__(419);
  4805. ;// CONCATENATED MODULE: ./src/display/pattern_helper.js
  4806. const PathType = {
  4807. FILL: "Fill",
  4808. STROKE: "Stroke",
  4809. SHADING: "Shading"
  4810. };
  4811. function applyBoundingBox(ctx, bbox) {
  4812. if (!bbox) {
  4813. return;
  4814. }
  4815. const width = bbox[2] - bbox[0];
  4816. const height = bbox[3] - bbox[1];
  4817. const region = new Path2D();
  4818. region.rect(bbox[0], bbox[1], width, height);
  4819. ctx.clip(region);
  4820. }
  4821. class BaseShadingPattern {
  4822. constructor() {
  4823. if (this.constructor === BaseShadingPattern) {
  4824. (0,util.unreachable)("Cannot initialize BaseShadingPattern.");
  4825. }
  4826. }
  4827. getPattern() {
  4828. (0,util.unreachable)("Abstract method `getPattern` called.");
  4829. }
  4830. }
  4831. class RadialAxialShadingPattern extends BaseShadingPattern {
  4832. constructor(IR) {
  4833. super();
  4834. this._type = IR[1];
  4835. this._bbox = IR[2];
  4836. this._colorStops = IR[3];
  4837. this._p0 = IR[4];
  4838. this._p1 = IR[5];
  4839. this._r0 = IR[6];
  4840. this._r1 = IR[7];
  4841. this.matrix = null;
  4842. }
  4843. _createGradient(ctx) {
  4844. let grad;
  4845. if (this._type === "axial") {
  4846. grad = ctx.createLinearGradient(this._p0[0], this._p0[1], this._p1[0], this._p1[1]);
  4847. } else if (this._type === "radial") {
  4848. grad = ctx.createRadialGradient(this._p0[0], this._p0[1], this._r0, this._p1[0], this._p1[1], this._r1);
  4849. }
  4850. for (const colorStop of this._colorStops) {
  4851. grad.addColorStop(colorStop[0], colorStop[1]);
  4852. }
  4853. return grad;
  4854. }
  4855. getPattern(ctx, owner, inverse, pathType) {
  4856. let pattern;
  4857. if (pathType === PathType.STROKE || pathType === PathType.FILL) {
  4858. const ownerBBox = owner.current.getClippedPathBoundingBox(pathType, (0,display_utils.getCurrentTransform)(ctx)) || [0, 0, 0, 0];
  4859. const width = Math.ceil(ownerBBox[2] - ownerBBox[0]) || 1;
  4860. const height = Math.ceil(ownerBBox[3] - ownerBBox[1]) || 1;
  4861. const tmpCanvas = owner.cachedCanvases.getCanvas("pattern", width, height, true);
  4862. const tmpCtx = tmpCanvas.context;
  4863. tmpCtx.clearRect(0, 0, tmpCtx.canvas.width, tmpCtx.canvas.height);
  4864. tmpCtx.beginPath();
  4865. tmpCtx.rect(0, 0, tmpCtx.canvas.width, tmpCtx.canvas.height);
  4866. tmpCtx.translate(-ownerBBox[0], -ownerBBox[1]);
  4867. inverse = util.Util.transform(inverse, [1, 0, 0, 1, ownerBBox[0], ownerBBox[1]]);
  4868. tmpCtx.transform(...owner.baseTransform);
  4869. if (this.matrix) {
  4870. tmpCtx.transform(...this.matrix);
  4871. }
  4872. applyBoundingBox(tmpCtx, this._bbox);
  4873. tmpCtx.fillStyle = this._createGradient(tmpCtx);
  4874. tmpCtx.fill();
  4875. pattern = ctx.createPattern(tmpCanvas.canvas, "no-repeat");
  4876. const domMatrix = new DOMMatrix(inverse);
  4877. pattern.setTransform(domMatrix);
  4878. } else {
  4879. applyBoundingBox(ctx, this._bbox);
  4880. pattern = this._createGradient(ctx);
  4881. }
  4882. return pattern;
  4883. }
  4884. }
  4885. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  4886. const coords = context.coords,
  4887. colors = context.colors;
  4888. const bytes = data.data,
  4889. rowSize = data.width * 4;
  4890. let tmp;
  4891. if (coords[p1 + 1] > coords[p2 + 1]) {
  4892. tmp = p1;
  4893. p1 = p2;
  4894. p2 = tmp;
  4895. tmp = c1;
  4896. c1 = c2;
  4897. c2 = tmp;
  4898. }
  4899. if (coords[p2 + 1] > coords[p3 + 1]) {
  4900. tmp = p2;
  4901. p2 = p3;
  4902. p3 = tmp;
  4903. tmp = c2;
  4904. c2 = c3;
  4905. c3 = tmp;
  4906. }
  4907. if (coords[p1 + 1] > coords[p2 + 1]) {
  4908. tmp = p1;
  4909. p1 = p2;
  4910. p2 = tmp;
  4911. tmp = c1;
  4912. c1 = c2;
  4913. c2 = tmp;
  4914. }
  4915. const x1 = (coords[p1] + context.offsetX) * context.scaleX;
  4916. const y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  4917. const x2 = (coords[p2] + context.offsetX) * context.scaleX;
  4918. const y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  4919. const x3 = (coords[p3] + context.offsetX) * context.scaleX;
  4920. const y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  4921. if (y1 >= y3) {
  4922. return;
  4923. }
  4924. const c1r = colors[c1],
  4925. c1g = colors[c1 + 1],
  4926. c1b = colors[c1 + 2];
  4927. const c2r = colors[c2],
  4928. c2g = colors[c2 + 1],
  4929. c2b = colors[c2 + 2];
  4930. const c3r = colors[c3],
  4931. c3g = colors[c3 + 1],
  4932. c3b = colors[c3 + 2];
  4933. const minY = Math.round(y1),
  4934. maxY = Math.round(y3);
  4935. let xa, car, cag, cab;
  4936. let xb, cbr, cbg, cbb;
  4937. for (let y = minY; y <= maxY; y++) {
  4938. if (y < y2) {
  4939. const k = y < y1 ? 0 : (y1 - y) / (y1 - y2);
  4940. xa = x1 - (x1 - x2) * k;
  4941. car = c1r - (c1r - c2r) * k;
  4942. cag = c1g - (c1g - c2g) * k;
  4943. cab = c1b - (c1b - c2b) * k;
  4944. } else {
  4945. let k;
  4946. if (y > y3) {
  4947. k = 1;
  4948. } else if (y2 === y3) {
  4949. k = 0;
  4950. } else {
  4951. k = (y2 - y) / (y2 - y3);
  4952. }
  4953. xa = x2 - (x2 - x3) * k;
  4954. car = c2r - (c2r - c3r) * k;
  4955. cag = c2g - (c2g - c3g) * k;
  4956. cab = c2b - (c2b - c3b) * k;
  4957. }
  4958. let k;
  4959. if (y < y1) {
  4960. k = 0;
  4961. } else if (y > y3) {
  4962. k = 1;
  4963. } else {
  4964. k = (y1 - y) / (y1 - y3);
  4965. }
  4966. xb = x1 - (x1 - x3) * k;
  4967. cbr = c1r - (c1r - c3r) * k;
  4968. cbg = c1g - (c1g - c3g) * k;
  4969. cbb = c1b - (c1b - c3b) * k;
  4970. const x1_ = Math.round(Math.min(xa, xb));
  4971. const x2_ = Math.round(Math.max(xa, xb));
  4972. let j = rowSize * y + x1_ * 4;
  4973. for (let x = x1_; x <= x2_; x++) {
  4974. k = (xa - x) / (xa - xb);
  4975. if (k < 0) {
  4976. k = 0;
  4977. } else if (k > 1) {
  4978. k = 1;
  4979. }
  4980. bytes[j++] = car - (car - cbr) * k | 0;
  4981. bytes[j++] = cag - (cag - cbg) * k | 0;
  4982. bytes[j++] = cab - (cab - cbb) * k | 0;
  4983. bytes[j++] = 255;
  4984. }
  4985. }
  4986. }
  4987. function drawFigure(data, figure, context) {
  4988. const ps = figure.coords;
  4989. const cs = figure.colors;
  4990. let i, ii;
  4991. switch (figure.type) {
  4992. case "lattice":
  4993. const verticesPerRow = figure.verticesPerRow;
  4994. const rows = Math.floor(ps.length / verticesPerRow) - 1;
  4995. const cols = verticesPerRow - 1;
  4996. for (i = 0; i < rows; i++) {
  4997. let q = i * verticesPerRow;
  4998. for (let j = 0; j < cols; j++, q++) {
  4999. drawTriangle(data, context, ps[q], ps[q + 1], ps[q + verticesPerRow], cs[q], cs[q + 1], cs[q + verticesPerRow]);
  5000. drawTriangle(data, context, ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow], cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  5001. }
  5002. }
  5003. break;
  5004. case "triangles":
  5005. for (i = 0, ii = ps.length; i < ii; i += 3) {
  5006. drawTriangle(data, context, ps[i], ps[i + 1], ps[i + 2], cs[i], cs[i + 1], cs[i + 2]);
  5007. }
  5008. break;
  5009. default:
  5010. throw new Error("illegal figure");
  5011. }
  5012. }
  5013. class MeshShadingPattern extends BaseShadingPattern {
  5014. constructor(IR) {
  5015. super();
  5016. this._coords = IR[2];
  5017. this._colors = IR[3];
  5018. this._figures = IR[4];
  5019. this._bounds = IR[5];
  5020. this._bbox = IR[7];
  5021. this._background = IR[8];
  5022. this.matrix = null;
  5023. }
  5024. _createMeshCanvas(combinedScale, backgroundColor, cachedCanvases) {
  5025. const EXPECTED_SCALE = 1.1;
  5026. const MAX_PATTERN_SIZE = 3000;
  5027. const BORDER_SIZE = 2;
  5028. const offsetX = Math.floor(this._bounds[0]);
  5029. const offsetY = Math.floor(this._bounds[1]);
  5030. const boundsWidth = Math.ceil(this._bounds[2]) - offsetX;
  5031. const boundsHeight = Math.ceil(this._bounds[3]) - offsetY;
  5032. const width = Math.min(Math.ceil(Math.abs(boundsWidth * combinedScale[0] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5033. const height = Math.min(Math.ceil(Math.abs(boundsHeight * combinedScale[1] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5034. const scaleX = boundsWidth / width;
  5035. const scaleY = boundsHeight / height;
  5036. const context = {
  5037. coords: this._coords,
  5038. colors: this._colors,
  5039. offsetX: -offsetX,
  5040. offsetY: -offsetY,
  5041. scaleX: 1 / scaleX,
  5042. scaleY: 1 / scaleY
  5043. };
  5044. const paddedWidth = width + BORDER_SIZE * 2;
  5045. const paddedHeight = height + BORDER_SIZE * 2;
  5046. const tmpCanvas = cachedCanvases.getCanvas("mesh", paddedWidth, paddedHeight, false);
  5047. const tmpCtx = tmpCanvas.context;
  5048. const data = tmpCtx.createImageData(width, height);
  5049. if (backgroundColor) {
  5050. const bytes = data.data;
  5051. for (let i = 0, ii = bytes.length; i < ii; i += 4) {
  5052. bytes[i] = backgroundColor[0];
  5053. bytes[i + 1] = backgroundColor[1];
  5054. bytes[i + 2] = backgroundColor[2];
  5055. bytes[i + 3] = 255;
  5056. }
  5057. }
  5058. for (const figure of this._figures) {
  5059. drawFigure(data, figure, context);
  5060. }
  5061. tmpCtx.putImageData(data, BORDER_SIZE, BORDER_SIZE);
  5062. const canvas = tmpCanvas.canvas;
  5063. return {
  5064. canvas,
  5065. offsetX: offsetX - BORDER_SIZE * scaleX,
  5066. offsetY: offsetY - BORDER_SIZE * scaleY,
  5067. scaleX,
  5068. scaleY
  5069. };
  5070. }
  5071. getPattern(ctx, owner, inverse, pathType) {
  5072. applyBoundingBox(ctx, this._bbox);
  5073. let scale;
  5074. if (pathType === PathType.SHADING) {
  5075. scale = util.Util.singularValueDecompose2dScale((0,display_utils.getCurrentTransform)(ctx));
  5076. } else {
  5077. scale = util.Util.singularValueDecompose2dScale(owner.baseTransform);
  5078. if (this.matrix) {
  5079. const matrixScale = util.Util.singularValueDecompose2dScale(this.matrix);
  5080. scale = [scale[0] * matrixScale[0], scale[1] * matrixScale[1]];
  5081. }
  5082. }
  5083. const temporaryPatternCanvas = this._createMeshCanvas(scale, pathType === PathType.SHADING ? null : this._background, owner.cachedCanvases);
  5084. if (pathType !== PathType.SHADING) {
  5085. ctx.setTransform(...owner.baseTransform);
  5086. if (this.matrix) {
  5087. ctx.transform(...this.matrix);
  5088. }
  5089. }
  5090. ctx.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY);
  5091. ctx.scale(temporaryPatternCanvas.scaleX, temporaryPatternCanvas.scaleY);
  5092. return ctx.createPattern(temporaryPatternCanvas.canvas, "no-repeat");
  5093. }
  5094. }
  5095. class DummyShadingPattern extends BaseShadingPattern {
  5096. getPattern() {
  5097. return "hotpink";
  5098. }
  5099. }
  5100. function getShadingPattern(IR) {
  5101. switch (IR[0]) {
  5102. case "RadialAxial":
  5103. return new RadialAxialShadingPattern(IR);
  5104. case "Mesh":
  5105. return new MeshShadingPattern(IR);
  5106. case "Dummy":
  5107. return new DummyShadingPattern();
  5108. }
  5109. throw new Error(`Unknown IR type: ${IR[0]}`);
  5110. }
  5111. const PaintType = {
  5112. COLORED: 1,
  5113. UNCOLORED: 2
  5114. };
  5115. class TilingPattern {
  5116. static MAX_PATTERN_SIZE = 3000;
  5117. constructor(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
  5118. this.operatorList = IR[2];
  5119. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  5120. this.bbox = IR[4];
  5121. this.xstep = IR[5];
  5122. this.ystep = IR[6];
  5123. this.paintType = IR[7];
  5124. this.tilingType = IR[8];
  5125. this.color = color;
  5126. this.ctx = ctx;
  5127. this.canvasGraphicsFactory = canvasGraphicsFactory;
  5128. this.baseTransform = baseTransform;
  5129. }
  5130. createPatternCanvas(owner) {
  5131. const operatorList = this.operatorList;
  5132. const bbox = this.bbox;
  5133. const xstep = this.xstep;
  5134. const ystep = this.ystep;
  5135. const paintType = this.paintType;
  5136. const tilingType = this.tilingType;
  5137. const color = this.color;
  5138. const canvasGraphicsFactory = this.canvasGraphicsFactory;
  5139. (0,util.info)("TilingType: " + tilingType);
  5140. const x0 = bbox[0],
  5141. y0 = bbox[1],
  5142. x1 = bbox[2],
  5143. y1 = bbox[3];
  5144. const matrixScale = util.Util.singularValueDecompose2dScale(this.matrix);
  5145. const curMatrixScale = util.Util.singularValueDecompose2dScale(this.baseTransform);
  5146. const combinedScale = [matrixScale[0] * curMatrixScale[0], matrixScale[1] * curMatrixScale[1]];
  5147. const dimx = this.getSizeAndScale(xstep, this.ctx.canvas.width, combinedScale[0]);
  5148. const dimy = this.getSizeAndScale(ystep, this.ctx.canvas.height, combinedScale[1]);
  5149. const tmpCanvas = owner.cachedCanvases.getCanvas("pattern", dimx.size, dimy.size, true);
  5150. const tmpCtx = tmpCanvas.context;
  5151. const graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
  5152. graphics.groupLevel = owner.groupLevel;
  5153. this.setFillAndStrokeStyleToContext(graphics, paintType, color);
  5154. let adjustedX0 = x0;
  5155. let adjustedY0 = y0;
  5156. let adjustedX1 = x1;
  5157. let adjustedY1 = y1;
  5158. if (x0 < 0) {
  5159. adjustedX0 = 0;
  5160. adjustedX1 += Math.abs(x0);
  5161. }
  5162. if (y0 < 0) {
  5163. adjustedY0 = 0;
  5164. adjustedY1 += Math.abs(y0);
  5165. }
  5166. tmpCtx.translate(-(dimx.scale * adjustedX0), -(dimy.scale * adjustedY0));
  5167. graphics.transform(dimx.scale, 0, 0, dimy.scale, 0, 0);
  5168. tmpCtx.save();
  5169. this.clipBbox(graphics, adjustedX0, adjustedY0, adjustedX1, adjustedY1);
  5170. graphics.baseTransform = (0,display_utils.getCurrentTransform)(graphics.ctx);
  5171. graphics.executeOperatorList(operatorList);
  5172. graphics.endDrawing();
  5173. return {
  5174. canvas: tmpCanvas.canvas,
  5175. scaleX: dimx.scale,
  5176. scaleY: dimy.scale,
  5177. offsetX: adjustedX0,
  5178. offsetY: adjustedY0
  5179. };
  5180. }
  5181. getSizeAndScale(step, realOutputSize, scale) {
  5182. step = Math.abs(step);
  5183. const maxSize = Math.max(TilingPattern.MAX_PATTERN_SIZE, realOutputSize);
  5184. let size = Math.ceil(step * scale);
  5185. if (size >= maxSize) {
  5186. size = maxSize;
  5187. } else {
  5188. scale = size / step;
  5189. }
  5190. return {
  5191. scale,
  5192. size
  5193. };
  5194. }
  5195. clipBbox(graphics, x0, y0, x1, y1) {
  5196. const bboxWidth = x1 - x0;
  5197. const bboxHeight = y1 - y0;
  5198. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  5199. graphics.current.updateRectMinMax((0,display_utils.getCurrentTransform)(graphics.ctx), [x0, y0, x1, y1]);
  5200. graphics.clip();
  5201. graphics.endPath();
  5202. }
  5203. setFillAndStrokeStyleToContext(graphics, paintType, color) {
  5204. const context = graphics.ctx,
  5205. current = graphics.current;
  5206. switch (paintType) {
  5207. case PaintType.COLORED:
  5208. const ctx = this.ctx;
  5209. context.fillStyle = ctx.fillStyle;
  5210. context.strokeStyle = ctx.strokeStyle;
  5211. current.fillColor = ctx.fillStyle;
  5212. current.strokeColor = ctx.strokeStyle;
  5213. break;
  5214. case PaintType.UNCOLORED:
  5215. const cssColor = util.Util.makeHexColor(color[0], color[1], color[2]);
  5216. context.fillStyle = cssColor;
  5217. context.strokeStyle = cssColor;
  5218. current.fillColor = cssColor;
  5219. current.strokeColor = cssColor;
  5220. break;
  5221. default:
  5222. throw new util.FormatError(`Unsupported paint type: ${paintType}`);
  5223. }
  5224. }
  5225. getPattern(ctx, owner, inverse, pathType) {
  5226. let matrix = inverse;
  5227. if (pathType !== PathType.SHADING) {
  5228. matrix = util.Util.transform(matrix, owner.baseTransform);
  5229. if (this.matrix) {
  5230. matrix = util.Util.transform(matrix, this.matrix);
  5231. }
  5232. }
  5233. const temporaryPatternCanvas = this.createPatternCanvas(owner);
  5234. let domMatrix = new DOMMatrix(matrix);
  5235. domMatrix = domMatrix.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY);
  5236. domMatrix = domMatrix.scale(1 / temporaryPatternCanvas.scaleX, 1 / temporaryPatternCanvas.scaleY);
  5237. const pattern = ctx.createPattern(temporaryPatternCanvas.canvas, "repeat");
  5238. pattern.setTransform(domMatrix);
  5239. return pattern;
  5240. }
  5241. }
  5242. ;// CONCATENATED MODULE: ./src/shared/image_utils.js
  5243. function convertToRGBA(params) {
  5244. switch (params.kind) {
  5245. case ImageKind.GRAYSCALE_1BPP:
  5246. return convertBlackAndWhiteToRGBA(params);
  5247. case ImageKind.RGB_24BPP:
  5248. return convertRGBToRGBA(params);
  5249. }
  5250. return null;
  5251. }
  5252. function convertBlackAndWhiteToRGBA({
  5253. src,
  5254. srcPos = 0,
  5255. dest,
  5256. width,
  5257. height,
  5258. nonBlackColor = 0xffffffff,
  5259. inverseDecode = false
  5260. }) {
  5261. const black = util.FeatureTest.isLittleEndian ? 0xff000000 : 0x000000ff;
  5262. const [zeroMapping, oneMapping] = inverseDecode ? [nonBlackColor, black] : [black, nonBlackColor];
  5263. const widthInSource = width >> 3;
  5264. const widthRemainder = width & 7;
  5265. const srcLength = src.length;
  5266. dest = new Uint32Array(dest.buffer);
  5267. let destPos = 0;
  5268. for (let i = 0; i < height; i++) {
  5269. for (const max = srcPos + widthInSource; srcPos < max; srcPos++) {
  5270. const elem = srcPos < srcLength ? src[srcPos] : 255;
  5271. dest[destPos++] = elem & 0b10000000 ? oneMapping : zeroMapping;
  5272. dest[destPos++] = elem & 0b1000000 ? oneMapping : zeroMapping;
  5273. dest[destPos++] = elem & 0b100000 ? oneMapping : zeroMapping;
  5274. dest[destPos++] = elem & 0b10000 ? oneMapping : zeroMapping;
  5275. dest[destPos++] = elem & 0b1000 ? oneMapping : zeroMapping;
  5276. dest[destPos++] = elem & 0b100 ? oneMapping : zeroMapping;
  5277. dest[destPos++] = elem & 0b10 ? oneMapping : zeroMapping;
  5278. dest[destPos++] = elem & 0b1 ? oneMapping : zeroMapping;
  5279. }
  5280. if (widthRemainder === 0) {
  5281. continue;
  5282. }
  5283. const elem = srcPos < srcLength ? src[srcPos++] : 255;
  5284. for (let j = 0; j < widthRemainder; j++) {
  5285. dest[destPos++] = elem & 1 << 7 - j ? oneMapping : zeroMapping;
  5286. }
  5287. }
  5288. return {
  5289. srcPos,
  5290. destPos
  5291. };
  5292. }
  5293. function convertRGBToRGBA({
  5294. src,
  5295. srcPos = 0,
  5296. dest,
  5297. destPos = 0,
  5298. width,
  5299. height
  5300. }) {
  5301. let i = 0;
  5302. const len32 = src.length >> 2;
  5303. const src32 = new Uint32Array(src.buffer, srcPos, len32);
  5304. if (FeatureTest.isLittleEndian) {
  5305. for (; i < len32 - 2; i += 3, destPos += 4) {
  5306. const s1 = src32[i];
  5307. const s2 = src32[i + 1];
  5308. const s3 = src32[i + 2];
  5309. dest[destPos] = s1 | 0xff000000;
  5310. dest[destPos + 1] = s1 >>> 24 | s2 << 8 | 0xff000000;
  5311. dest[destPos + 2] = s2 >>> 16 | s3 << 16 | 0xff000000;
  5312. dest[destPos + 3] = s3 >>> 8 | 0xff000000;
  5313. }
  5314. for (let j = i * 4, jj = src.length; j < jj; j += 3) {
  5315. dest[destPos++] = src[j] | src[j + 1] << 8 | src[j + 2] << 16 | 0xff000000;
  5316. }
  5317. } else {
  5318. for (; i < len32 - 2; i += 3, destPos += 4) {
  5319. const s1 = src32[i];
  5320. const s2 = src32[i + 1];
  5321. const s3 = src32[i + 2];
  5322. dest[destPos] = s1 | 0xff;
  5323. dest[destPos + 1] = s1 << 24 | s2 >>> 8 | 0xff;
  5324. dest[destPos + 2] = s2 << 16 | s3 >>> 16 | 0xff;
  5325. dest[destPos + 3] = s3 << 8 | 0xff;
  5326. }
  5327. for (let j = i * 4, jj = src.length; j < jj; j += 3) {
  5328. dest[destPos++] = src[j] << 24 | src[j + 1] << 16 | src[j + 2] << 8 | 0xff;
  5329. }
  5330. }
  5331. return {
  5332. srcPos,
  5333. destPos
  5334. };
  5335. }
  5336. function grayToRGBA(src, dest) {
  5337. if (FeatureTest.isLittleEndian) {
  5338. for (let i = 0, ii = src.length; i < ii; i++) {
  5339. dest[i] = src[i] * 0x10101 | 0xff000000;
  5340. }
  5341. } else {
  5342. for (let i = 0, ii = src.length; i < ii; i++) {
  5343. dest[i] = src[i] * 0x1010100 | 0x000000ff;
  5344. }
  5345. }
  5346. }
  5347. ;// CONCATENATED MODULE: ./src/display/canvas.js
  5348. const MIN_FONT_SIZE = 16;
  5349. const MAX_FONT_SIZE = 100;
  5350. const MAX_GROUP_SIZE = 4096;
  5351. const EXECUTION_TIME = 15;
  5352. const EXECUTION_STEPS = 10;
  5353. const MAX_SIZE_TO_COMPILE = 1000;
  5354. const FULL_CHUNK_HEIGHT = 16;
  5355. function mirrorContextOperations(ctx, destCtx) {
  5356. if (ctx._removeMirroring) {
  5357. throw new Error("Context is already forwarding operations.");
  5358. }
  5359. ctx.__originalSave = ctx.save;
  5360. ctx.__originalRestore = ctx.restore;
  5361. ctx.__originalRotate = ctx.rotate;
  5362. ctx.__originalScale = ctx.scale;
  5363. ctx.__originalTranslate = ctx.translate;
  5364. ctx.__originalTransform = ctx.transform;
  5365. ctx.__originalSetTransform = ctx.setTransform;
  5366. ctx.__originalResetTransform = ctx.resetTransform;
  5367. ctx.__originalClip = ctx.clip;
  5368. ctx.__originalMoveTo = ctx.moveTo;
  5369. ctx.__originalLineTo = ctx.lineTo;
  5370. ctx.__originalBezierCurveTo = ctx.bezierCurveTo;
  5371. ctx.__originalRect = ctx.rect;
  5372. ctx.__originalClosePath = ctx.closePath;
  5373. ctx.__originalBeginPath = ctx.beginPath;
  5374. ctx._removeMirroring = () => {
  5375. ctx.save = ctx.__originalSave;
  5376. ctx.restore = ctx.__originalRestore;
  5377. ctx.rotate = ctx.__originalRotate;
  5378. ctx.scale = ctx.__originalScale;
  5379. ctx.translate = ctx.__originalTranslate;
  5380. ctx.transform = ctx.__originalTransform;
  5381. ctx.setTransform = ctx.__originalSetTransform;
  5382. ctx.resetTransform = ctx.__originalResetTransform;
  5383. ctx.clip = ctx.__originalClip;
  5384. ctx.moveTo = ctx.__originalMoveTo;
  5385. ctx.lineTo = ctx.__originalLineTo;
  5386. ctx.bezierCurveTo = ctx.__originalBezierCurveTo;
  5387. ctx.rect = ctx.__originalRect;
  5388. ctx.closePath = ctx.__originalClosePath;
  5389. ctx.beginPath = ctx.__originalBeginPath;
  5390. delete ctx._removeMirroring;
  5391. };
  5392. ctx.save = function ctxSave() {
  5393. destCtx.save();
  5394. this.__originalSave();
  5395. };
  5396. ctx.restore = function ctxRestore() {
  5397. destCtx.restore();
  5398. this.__originalRestore();
  5399. };
  5400. ctx.translate = function ctxTranslate(x, y) {
  5401. destCtx.translate(x, y);
  5402. this.__originalTranslate(x, y);
  5403. };
  5404. ctx.scale = function ctxScale(x, y) {
  5405. destCtx.scale(x, y);
  5406. this.__originalScale(x, y);
  5407. };
  5408. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  5409. destCtx.transform(a, b, c, d, e, f);
  5410. this.__originalTransform(a, b, c, d, e, f);
  5411. };
  5412. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  5413. destCtx.setTransform(a, b, c, d, e, f);
  5414. this.__originalSetTransform(a, b, c, d, e, f);
  5415. };
  5416. ctx.resetTransform = function ctxResetTransform() {
  5417. destCtx.resetTransform();
  5418. this.__originalResetTransform();
  5419. };
  5420. ctx.rotate = function ctxRotate(angle) {
  5421. destCtx.rotate(angle);
  5422. this.__originalRotate(angle);
  5423. };
  5424. ctx.clip = function ctxRotate(rule) {
  5425. destCtx.clip(rule);
  5426. this.__originalClip(rule);
  5427. };
  5428. ctx.moveTo = function (x, y) {
  5429. destCtx.moveTo(x, y);
  5430. this.__originalMoveTo(x, y);
  5431. };
  5432. ctx.lineTo = function (x, y) {
  5433. destCtx.lineTo(x, y);
  5434. this.__originalLineTo(x, y);
  5435. };
  5436. ctx.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
  5437. destCtx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
  5438. this.__originalBezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
  5439. };
  5440. ctx.rect = function (x, y, width, height) {
  5441. destCtx.rect(x, y, width, height);
  5442. this.__originalRect(x, y, width, height);
  5443. };
  5444. ctx.closePath = function () {
  5445. destCtx.closePath();
  5446. this.__originalClosePath();
  5447. };
  5448. ctx.beginPath = function () {
  5449. destCtx.beginPath();
  5450. this.__originalBeginPath();
  5451. };
  5452. }
  5453. class CachedCanvases {
  5454. constructor(canvasFactory) {
  5455. this.canvasFactory = canvasFactory;
  5456. this.cache = Object.create(null);
  5457. }
  5458. getCanvas(id, width, height) {
  5459. let canvasEntry;
  5460. if (this.cache[id] !== undefined) {
  5461. canvasEntry = this.cache[id];
  5462. this.canvasFactory.reset(canvasEntry, width, height);
  5463. } else {
  5464. canvasEntry = this.canvasFactory.create(width, height);
  5465. this.cache[id] = canvasEntry;
  5466. }
  5467. return canvasEntry;
  5468. }
  5469. delete(id) {
  5470. delete this.cache[id];
  5471. }
  5472. clear() {
  5473. for (const id in this.cache) {
  5474. const canvasEntry = this.cache[id];
  5475. this.canvasFactory.destroy(canvasEntry);
  5476. delete this.cache[id];
  5477. }
  5478. }
  5479. }
  5480. function drawImageAtIntegerCoords(ctx, srcImg, srcX, srcY, srcW, srcH, destX, destY, destW, destH) {
  5481. const [a, b, c, d, tx, ty] = (0,display_utils.getCurrentTransform)(ctx);
  5482. if (b === 0 && c === 0) {
  5483. const tlX = destX * a + tx;
  5484. const rTlX = Math.round(tlX);
  5485. const tlY = destY * d + ty;
  5486. const rTlY = Math.round(tlY);
  5487. const brX = (destX + destW) * a + tx;
  5488. const rWidth = Math.abs(Math.round(brX) - rTlX) || 1;
  5489. const brY = (destY + destH) * d + ty;
  5490. const rHeight = Math.abs(Math.round(brY) - rTlY) || 1;
  5491. ctx.setTransform(Math.sign(a), 0, 0, Math.sign(d), rTlX, rTlY);
  5492. ctx.drawImage(srcImg, srcX, srcY, srcW, srcH, 0, 0, rWidth, rHeight);
  5493. ctx.setTransform(a, b, c, d, tx, ty);
  5494. return [rWidth, rHeight];
  5495. }
  5496. if (a === 0 && d === 0) {
  5497. const tlX = destY * c + tx;
  5498. const rTlX = Math.round(tlX);
  5499. const tlY = destX * b + ty;
  5500. const rTlY = Math.round(tlY);
  5501. const brX = (destY + destH) * c + tx;
  5502. const rWidth = Math.abs(Math.round(brX) - rTlX) || 1;
  5503. const brY = (destX + destW) * b + ty;
  5504. const rHeight = Math.abs(Math.round(brY) - rTlY) || 1;
  5505. ctx.setTransform(0, Math.sign(b), Math.sign(c), 0, rTlX, rTlY);
  5506. ctx.drawImage(srcImg, srcX, srcY, srcW, srcH, 0, 0, rHeight, rWidth);
  5507. ctx.setTransform(a, b, c, d, tx, ty);
  5508. return [rHeight, rWidth];
  5509. }
  5510. ctx.drawImage(srcImg, srcX, srcY, srcW, srcH, destX, destY, destW, destH);
  5511. const scaleX = Math.hypot(a, b);
  5512. const scaleY = Math.hypot(c, d);
  5513. return [scaleX * destW, scaleY * destH];
  5514. }
  5515. function compileType3Glyph(imgData) {
  5516. const {
  5517. width,
  5518. height
  5519. } = imgData;
  5520. if (width > MAX_SIZE_TO_COMPILE || height > MAX_SIZE_TO_COMPILE) {
  5521. return null;
  5522. }
  5523. const POINT_TO_PROCESS_LIMIT = 1000;
  5524. const POINT_TYPES = new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  5525. const width1 = width + 1;
  5526. let points = new Uint8Array(width1 * (height + 1));
  5527. let i, j, j0;
  5528. const lineSize = width + 7 & ~7;
  5529. let data = new Uint8Array(lineSize * height),
  5530. pos = 0;
  5531. for (const elem of imgData.data) {
  5532. let mask = 128;
  5533. while (mask > 0) {
  5534. data[pos++] = elem & mask ? 0 : 255;
  5535. mask >>= 1;
  5536. }
  5537. }
  5538. let count = 0;
  5539. pos = 0;
  5540. if (data[pos] !== 0) {
  5541. points[0] = 1;
  5542. ++count;
  5543. }
  5544. for (j = 1; j < width; j++) {
  5545. if (data[pos] !== data[pos + 1]) {
  5546. points[j] = data[pos] ? 2 : 1;
  5547. ++count;
  5548. }
  5549. pos++;
  5550. }
  5551. if (data[pos] !== 0) {
  5552. points[j] = 2;
  5553. ++count;
  5554. }
  5555. for (i = 1; i < height; i++) {
  5556. pos = i * lineSize;
  5557. j0 = i * width1;
  5558. if (data[pos - lineSize] !== data[pos]) {
  5559. points[j0] = data[pos] ? 1 : 8;
  5560. ++count;
  5561. }
  5562. let sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  5563. for (j = 1; j < width; j++) {
  5564. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) + (data[pos - lineSize + 1] ? 8 : 0);
  5565. if (POINT_TYPES[sum]) {
  5566. points[j0 + j] = POINT_TYPES[sum];
  5567. ++count;
  5568. }
  5569. pos++;
  5570. }
  5571. if (data[pos - lineSize] !== data[pos]) {
  5572. points[j0 + j] = data[pos] ? 2 : 4;
  5573. ++count;
  5574. }
  5575. if (count > POINT_TO_PROCESS_LIMIT) {
  5576. return null;
  5577. }
  5578. }
  5579. pos = lineSize * (height - 1);
  5580. j0 = i * width1;
  5581. if (data[pos] !== 0) {
  5582. points[j0] = 8;
  5583. ++count;
  5584. }
  5585. for (j = 1; j < width; j++) {
  5586. if (data[pos] !== data[pos + 1]) {
  5587. points[j0 + j] = data[pos] ? 4 : 8;
  5588. ++count;
  5589. }
  5590. pos++;
  5591. }
  5592. if (data[pos] !== 0) {
  5593. points[j0 + j] = 4;
  5594. ++count;
  5595. }
  5596. if (count > POINT_TO_PROCESS_LIMIT) {
  5597. return null;
  5598. }
  5599. const steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  5600. const path = new Path2D();
  5601. for (i = 0; count && i <= height; i++) {
  5602. let p = i * width1;
  5603. const end = p + width;
  5604. while (p < end && !points[p]) {
  5605. p++;
  5606. }
  5607. if (p === end) {
  5608. continue;
  5609. }
  5610. path.moveTo(p % width1, i);
  5611. const p0 = p;
  5612. let type = points[p];
  5613. do {
  5614. const step = steps[type];
  5615. do {
  5616. p += step;
  5617. } while (!points[p]);
  5618. const pp = points[p];
  5619. if (pp !== 5 && pp !== 10) {
  5620. type = pp;
  5621. points[p] = 0;
  5622. } else {
  5623. type = pp & 0x33 * type >> 4;
  5624. points[p] &= type >> 2 | type << 2;
  5625. }
  5626. path.lineTo(p % width1, p / width1 | 0);
  5627. if (!points[p]) {
  5628. --count;
  5629. }
  5630. } while (p0 !== p);
  5631. --i;
  5632. }
  5633. data = null;
  5634. points = null;
  5635. const drawOutline = function (c) {
  5636. c.save();
  5637. c.scale(1 / width, -1 / height);
  5638. c.translate(0, -height);
  5639. c.fill(path);
  5640. c.beginPath();
  5641. c.restore();
  5642. };
  5643. return drawOutline;
  5644. }
  5645. class CanvasExtraState {
  5646. constructor(width, height) {
  5647. this.alphaIsShape = false;
  5648. this.fontSize = 0;
  5649. this.fontSizeScale = 1;
  5650. this.textMatrix = util.IDENTITY_MATRIX;
  5651. this.textMatrixScale = 1;
  5652. this.fontMatrix = util.FONT_IDENTITY_MATRIX;
  5653. this.leading = 0;
  5654. this.x = 0;
  5655. this.y = 0;
  5656. this.lineX = 0;
  5657. this.lineY = 0;
  5658. this.charSpacing = 0;
  5659. this.wordSpacing = 0;
  5660. this.textHScale = 1;
  5661. this.textRenderingMode = util.TextRenderingMode.FILL;
  5662. this.textRise = 0;
  5663. this.fillColor = "#000000";
  5664. this.strokeColor = "#000000";
  5665. this.patternFill = false;
  5666. this.fillAlpha = 1;
  5667. this.strokeAlpha = 1;
  5668. this.lineWidth = 1;
  5669. this.activeSMask = null;
  5670. this.transferMaps = "none";
  5671. this.startNewPathAndClipBox([0, 0, width, height]);
  5672. }
  5673. clone() {
  5674. const clone = Object.create(this);
  5675. clone.clipBox = this.clipBox.slice();
  5676. return clone;
  5677. }
  5678. setCurrentPoint(x, y) {
  5679. this.x = x;
  5680. this.y = y;
  5681. }
  5682. updatePathMinMax(transform, x, y) {
  5683. [x, y] = util.Util.applyTransform([x, y], transform);
  5684. this.minX = Math.min(this.minX, x);
  5685. this.minY = Math.min(this.minY, y);
  5686. this.maxX = Math.max(this.maxX, x);
  5687. this.maxY = Math.max(this.maxY, y);
  5688. }
  5689. updateRectMinMax(transform, rect) {
  5690. const p1 = util.Util.applyTransform(rect, transform);
  5691. const p2 = util.Util.applyTransform(rect.slice(2), transform);
  5692. const p3 = util.Util.applyTransform([rect[0], rect[3]], transform);
  5693. const p4 = util.Util.applyTransform([rect[2], rect[1]], transform);
  5694. this.minX = Math.min(this.minX, p1[0], p2[0], p3[0], p4[0]);
  5695. this.minY = Math.min(this.minY, p1[1], p2[1], p3[1], p4[1]);
  5696. this.maxX = Math.max(this.maxX, p1[0], p2[0], p3[0], p4[0]);
  5697. this.maxY = Math.max(this.maxY, p1[1], p2[1], p3[1], p4[1]);
  5698. }
  5699. updateScalingPathMinMax(transform, minMax) {
  5700. util.Util.scaleMinMax(transform, minMax);
  5701. this.minX = Math.min(this.minX, minMax[0]);
  5702. this.minY = Math.min(this.minY, minMax[1]);
  5703. this.maxX = Math.max(this.maxX, minMax[2]);
  5704. this.maxY = Math.max(this.maxY, minMax[3]);
  5705. }
  5706. updateCurvePathMinMax(transform, x0, y0, x1, y1, x2, y2, x3, y3, minMax) {
  5707. const box = util.Util.bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3, minMax);
  5708. if (minMax) {
  5709. return;
  5710. }
  5711. this.updateRectMinMax(transform, box);
  5712. }
  5713. getPathBoundingBox(pathType = PathType.FILL, transform = null) {
  5714. const box = [this.minX, this.minY, this.maxX, this.maxY];
  5715. if (pathType === PathType.STROKE) {
  5716. if (!transform) {
  5717. (0,util.unreachable)("Stroke bounding box must include transform.");
  5718. }
  5719. const scale = util.Util.singularValueDecompose2dScale(transform);
  5720. const xStrokePad = scale[0] * this.lineWidth / 2;
  5721. const yStrokePad = scale[1] * this.lineWidth / 2;
  5722. box[0] -= xStrokePad;
  5723. box[1] -= yStrokePad;
  5724. box[2] += xStrokePad;
  5725. box[3] += yStrokePad;
  5726. }
  5727. return box;
  5728. }
  5729. updateClipFromPath() {
  5730. const intersect = util.Util.intersect(this.clipBox, this.getPathBoundingBox());
  5731. this.startNewPathAndClipBox(intersect || [0, 0, 0, 0]);
  5732. }
  5733. isEmptyClip() {
  5734. return this.minX === Infinity;
  5735. }
  5736. startNewPathAndClipBox(box) {
  5737. this.clipBox = box;
  5738. this.minX = Infinity;
  5739. this.minY = Infinity;
  5740. this.maxX = 0;
  5741. this.maxY = 0;
  5742. }
  5743. getClippedPathBoundingBox(pathType = PathType.FILL, transform = null) {
  5744. return util.Util.intersect(this.clipBox, this.getPathBoundingBox(pathType, transform));
  5745. }
  5746. }
  5747. function putBinaryImageData(ctx, imgData) {
  5748. if (typeof ImageData !== "undefined" && imgData instanceof ImageData) {
  5749. ctx.putImageData(imgData, 0, 0);
  5750. return;
  5751. }
  5752. const height = imgData.height,
  5753. width = imgData.width;
  5754. const partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  5755. const fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  5756. const totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  5757. const chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  5758. let srcPos = 0,
  5759. destPos;
  5760. const src = imgData.data;
  5761. const dest = chunkImgData.data;
  5762. let i, j, thisChunkHeight, elemsInThisChunk;
  5763. if (imgData.kind === util.ImageKind.GRAYSCALE_1BPP) {
  5764. const srcLength = src.byteLength;
  5765. const dest32 = new Uint32Array(dest.buffer, 0, dest.byteLength >> 2);
  5766. const dest32DataLength = dest32.length;
  5767. const fullSrcDiff = width + 7 >> 3;
  5768. const white = 0xffffffff;
  5769. const black = util.FeatureTest.isLittleEndian ? 0xff000000 : 0x000000ff;
  5770. for (i = 0; i < totalChunks; i++) {
  5771. thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  5772. destPos = 0;
  5773. for (j = 0; j < thisChunkHeight; j++) {
  5774. const srcDiff = srcLength - srcPos;
  5775. let k = 0;
  5776. const kEnd = srcDiff > fullSrcDiff ? width : srcDiff * 8 - 7;
  5777. const kEndUnrolled = kEnd & ~7;
  5778. let mask = 0;
  5779. let srcByte = 0;
  5780. for (; k < kEndUnrolled; k += 8) {
  5781. srcByte = src[srcPos++];
  5782. dest32[destPos++] = srcByte & 128 ? white : black;
  5783. dest32[destPos++] = srcByte & 64 ? white : black;
  5784. dest32[destPos++] = srcByte & 32 ? white : black;
  5785. dest32[destPos++] = srcByte & 16 ? white : black;
  5786. dest32[destPos++] = srcByte & 8 ? white : black;
  5787. dest32[destPos++] = srcByte & 4 ? white : black;
  5788. dest32[destPos++] = srcByte & 2 ? white : black;
  5789. dest32[destPos++] = srcByte & 1 ? white : black;
  5790. }
  5791. for (; k < kEnd; k++) {
  5792. if (mask === 0) {
  5793. srcByte = src[srcPos++];
  5794. mask = 128;
  5795. }
  5796. dest32[destPos++] = srcByte & mask ? white : black;
  5797. mask >>= 1;
  5798. }
  5799. }
  5800. while (destPos < dest32DataLength) {
  5801. dest32[destPos++] = 0;
  5802. }
  5803. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  5804. }
  5805. } else if (imgData.kind === util.ImageKind.RGBA_32BPP) {
  5806. j = 0;
  5807. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  5808. for (i = 0; i < fullChunks; i++) {
  5809. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  5810. srcPos += elemsInThisChunk;
  5811. ctx.putImageData(chunkImgData, 0, j);
  5812. j += FULL_CHUNK_HEIGHT;
  5813. }
  5814. if (i < totalChunks) {
  5815. elemsInThisChunk = width * partialChunkHeight * 4;
  5816. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  5817. ctx.putImageData(chunkImgData, 0, j);
  5818. }
  5819. } else if (imgData.kind === util.ImageKind.RGB_24BPP) {
  5820. thisChunkHeight = FULL_CHUNK_HEIGHT;
  5821. elemsInThisChunk = width * thisChunkHeight;
  5822. for (i = 0; i < totalChunks; i++) {
  5823. if (i >= fullChunks) {
  5824. thisChunkHeight = partialChunkHeight;
  5825. elemsInThisChunk = width * thisChunkHeight;
  5826. }
  5827. destPos = 0;
  5828. for (j = elemsInThisChunk; j--;) {
  5829. dest[destPos++] = src[srcPos++];
  5830. dest[destPos++] = src[srcPos++];
  5831. dest[destPos++] = src[srcPos++];
  5832. dest[destPos++] = 255;
  5833. }
  5834. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  5835. }
  5836. } else {
  5837. throw new Error(`bad image kind: ${imgData.kind}`);
  5838. }
  5839. }
  5840. function putBinaryImageMask(ctx, imgData) {
  5841. if (imgData.bitmap) {
  5842. ctx.drawImage(imgData.bitmap, 0, 0);
  5843. return;
  5844. }
  5845. const height = imgData.height,
  5846. width = imgData.width;
  5847. const partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  5848. const fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  5849. const totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  5850. const chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  5851. let srcPos = 0;
  5852. const src = imgData.data;
  5853. const dest = chunkImgData.data;
  5854. for (let i = 0; i < totalChunks; i++) {
  5855. const thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  5856. ({
  5857. srcPos
  5858. } = convertBlackAndWhiteToRGBA({
  5859. src,
  5860. srcPos,
  5861. dest,
  5862. width,
  5863. height: thisChunkHeight,
  5864. nonBlackColor: 0
  5865. }));
  5866. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  5867. }
  5868. }
  5869. function copyCtxState(sourceCtx, destCtx) {
  5870. const properties = ["strokeStyle", "fillStyle", "fillRule", "globalAlpha", "lineWidth", "lineCap", "lineJoin", "miterLimit", "globalCompositeOperation", "font", "filter"];
  5871. for (const property of properties) {
  5872. if (sourceCtx[property] !== undefined) {
  5873. destCtx[property] = sourceCtx[property];
  5874. }
  5875. }
  5876. if (sourceCtx.setLineDash !== undefined) {
  5877. destCtx.setLineDash(sourceCtx.getLineDash());
  5878. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  5879. }
  5880. }
  5881. function resetCtxToDefault(ctx) {
  5882. ctx.strokeStyle = ctx.fillStyle = "#000000";
  5883. ctx.fillRule = "nonzero";
  5884. ctx.globalAlpha = 1;
  5885. ctx.lineWidth = 1;
  5886. ctx.lineCap = "butt";
  5887. ctx.lineJoin = "miter";
  5888. ctx.miterLimit = 10;
  5889. ctx.globalCompositeOperation = "source-over";
  5890. ctx.font = "10px sans-serif";
  5891. if (ctx.setLineDash !== undefined) {
  5892. ctx.setLineDash([]);
  5893. ctx.lineDashOffset = 0;
  5894. }
  5895. if (!util.isNodeJS) {
  5896. const {
  5897. filter
  5898. } = ctx;
  5899. if (filter !== "none" && filter !== "") {
  5900. ctx.filter = "none";
  5901. }
  5902. }
  5903. }
  5904. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  5905. const length = bytes.length;
  5906. for (let i = 3; i < length; i += 4) {
  5907. const alpha = bytes[i];
  5908. if (alpha === 0) {
  5909. bytes[i - 3] = r0;
  5910. bytes[i - 2] = g0;
  5911. bytes[i - 1] = b0;
  5912. } else if (alpha < 255) {
  5913. const alpha_ = 255 - alpha;
  5914. bytes[i - 3] = bytes[i - 3] * alpha + r0 * alpha_ >> 8;
  5915. bytes[i - 2] = bytes[i - 2] * alpha + g0 * alpha_ >> 8;
  5916. bytes[i - 1] = bytes[i - 1] * alpha + b0 * alpha_ >> 8;
  5917. }
  5918. }
  5919. }
  5920. function composeSMaskAlpha(maskData, layerData, transferMap) {
  5921. const length = maskData.length;
  5922. const scale = 1 / 255;
  5923. for (let i = 3; i < length; i += 4) {
  5924. const alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
  5925. layerData[i] = layerData[i] * alpha * scale | 0;
  5926. }
  5927. }
  5928. function composeSMaskLuminosity(maskData, layerData, transferMap) {
  5929. const length = maskData.length;
  5930. for (let i = 3; i < length; i += 4) {
  5931. const y = maskData[i - 3] * 77 + maskData[i - 2] * 152 + maskData[i - 1] * 28;
  5932. layerData[i] = transferMap ? layerData[i] * transferMap[y >> 8] >> 8 : layerData[i] * y >> 16;
  5933. }
  5934. }
  5935. function genericComposeSMask(maskCtx, layerCtx, width, height, subtype, backdrop, transferMap, layerOffsetX, layerOffsetY, maskOffsetX, maskOffsetY) {
  5936. const hasBackdrop = !!backdrop;
  5937. const r0 = hasBackdrop ? backdrop[0] : 0;
  5938. const g0 = hasBackdrop ? backdrop[1] : 0;
  5939. const b0 = hasBackdrop ? backdrop[2] : 0;
  5940. const composeFn = subtype === "Luminosity" ? composeSMaskLuminosity : composeSMaskAlpha;
  5941. const PIXELS_TO_PROCESS = 1048576;
  5942. const chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  5943. for (let row = 0; row < height; row += chunkSize) {
  5944. const chunkHeight = Math.min(chunkSize, height - row);
  5945. const maskData = maskCtx.getImageData(layerOffsetX - maskOffsetX, row + (layerOffsetY - maskOffsetY), width, chunkHeight);
  5946. const layerData = layerCtx.getImageData(layerOffsetX, row + layerOffsetY, width, chunkHeight);
  5947. if (hasBackdrop) {
  5948. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  5949. }
  5950. composeFn(maskData.data, layerData.data, transferMap);
  5951. layerCtx.putImageData(layerData, layerOffsetX, row + layerOffsetY);
  5952. }
  5953. }
  5954. function composeSMask(ctx, smask, layerCtx, layerBox) {
  5955. const layerOffsetX = layerBox[0];
  5956. const layerOffsetY = layerBox[1];
  5957. const layerWidth = layerBox[2] - layerOffsetX;
  5958. const layerHeight = layerBox[3] - layerOffsetY;
  5959. if (layerWidth === 0 || layerHeight === 0) {
  5960. return;
  5961. }
  5962. genericComposeSMask(smask.context, layerCtx, layerWidth, layerHeight, smask.subtype, smask.backdrop, smask.transferMap, layerOffsetX, layerOffsetY, smask.offsetX, smask.offsetY);
  5963. ctx.save();
  5964. ctx.globalAlpha = 1;
  5965. ctx.globalCompositeOperation = "source-over";
  5966. ctx.setTransform(1, 0, 0, 1, 0, 0);
  5967. ctx.drawImage(layerCtx.canvas, 0, 0);
  5968. ctx.restore();
  5969. }
  5970. function getImageSmoothingEnabled(transform, interpolate) {
  5971. if (interpolate) {
  5972. return true;
  5973. }
  5974. const scale = util.Util.singularValueDecompose2dScale(transform);
  5975. scale[0] = Math.fround(scale[0]);
  5976. scale[1] = Math.fround(scale[1]);
  5977. const actualScale = Math.fround((globalThis.devicePixelRatio || 1) * display_utils.PixelsPerInch.PDF_TO_CSS_UNITS);
  5978. return scale[0] <= actualScale && scale[1] <= actualScale;
  5979. }
  5980. const LINE_CAP_STYLES = ["butt", "round", "square"];
  5981. const LINE_JOIN_STYLES = ["miter", "round", "bevel"];
  5982. const NORMAL_CLIP = {};
  5983. const EO_CLIP = {};
  5984. class CanvasGraphics {
  5985. constructor(canvasCtx, commonObjs, objs, canvasFactory, filterFactory, {
  5986. optionalContentConfig,
  5987. markedContentStack = null
  5988. }, annotationCanvasMap, pageColors) {
  5989. this.ctx = canvasCtx;
  5990. this.current = new CanvasExtraState(this.ctx.canvas.width, this.ctx.canvas.height);
  5991. this.stateStack = [];
  5992. this.pendingClip = null;
  5993. this.pendingEOFill = false;
  5994. this.res = null;
  5995. this.xobjs = null;
  5996. this.commonObjs = commonObjs;
  5997. this.objs = objs;
  5998. this.canvasFactory = canvasFactory;
  5999. this.filterFactory = filterFactory;
  6000. this.groupStack = [];
  6001. this.processingType3 = null;
  6002. this.baseTransform = null;
  6003. this.baseTransformStack = [];
  6004. this.groupLevel = 0;
  6005. this.smaskStack = [];
  6006. this.smaskCounter = 0;
  6007. this.tempSMask = null;
  6008. this.suspendedCtx = null;
  6009. this.contentVisible = true;
  6010. this.markedContentStack = markedContentStack || [];
  6011. this.optionalContentConfig = optionalContentConfig;
  6012. this.cachedCanvases = new CachedCanvases(this.canvasFactory);
  6013. this.cachedPatterns = new Map();
  6014. this.annotationCanvasMap = annotationCanvasMap;
  6015. this.viewportScale = 1;
  6016. this.outputScaleX = 1;
  6017. this.outputScaleY = 1;
  6018. this.pageColors = pageColors;
  6019. this._cachedScaleForStroking = [-1, 0];
  6020. this._cachedGetSinglePixelWidth = null;
  6021. this._cachedBitmapsMap = new Map();
  6022. }
  6023. getObject(data, fallback = null) {
  6024. if (typeof data === "string") {
  6025. return data.startsWith("g_") ? this.commonObjs.get(data) : this.objs.get(data);
  6026. }
  6027. return fallback;
  6028. }
  6029. beginDrawing({
  6030. transform,
  6031. viewport,
  6032. transparency = false,
  6033. background = null
  6034. }) {
  6035. const width = this.ctx.canvas.width;
  6036. const height = this.ctx.canvas.height;
  6037. const savedFillStyle = this.ctx.fillStyle;
  6038. this.ctx.fillStyle = background || "#ffffff";
  6039. this.ctx.fillRect(0, 0, width, height);
  6040. this.ctx.fillStyle = savedFillStyle;
  6041. if (transparency) {
  6042. const transparentCanvas = this.cachedCanvases.getCanvas("transparent", width, height);
  6043. this.compositeCtx = this.ctx;
  6044. this.transparentCanvas = transparentCanvas.canvas;
  6045. this.ctx = transparentCanvas.context;
  6046. this.ctx.save();
  6047. this.ctx.transform(...(0,display_utils.getCurrentTransform)(this.compositeCtx));
  6048. }
  6049. this.ctx.save();
  6050. resetCtxToDefault(this.ctx);
  6051. if (transform) {
  6052. this.ctx.transform(...transform);
  6053. this.outputScaleX = transform[0];
  6054. this.outputScaleY = transform[0];
  6055. }
  6056. this.ctx.transform(...viewport.transform);
  6057. this.viewportScale = viewport.scale;
  6058. this.baseTransform = (0,display_utils.getCurrentTransform)(this.ctx);
  6059. }
  6060. executeOperatorList(operatorList, executionStartIdx, continueCallback, stepper) {
  6061. const argsArray = operatorList.argsArray;
  6062. const fnArray = operatorList.fnArray;
  6063. let i = executionStartIdx || 0;
  6064. const argsArrayLen = argsArray.length;
  6065. if (argsArrayLen === i) {
  6066. return i;
  6067. }
  6068. const chunkOperations = argsArrayLen - i > EXECUTION_STEPS && typeof continueCallback === "function";
  6069. const endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  6070. let steps = 0;
  6071. const commonObjs = this.commonObjs;
  6072. const objs = this.objs;
  6073. let fnId;
  6074. while (true) {
  6075. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  6076. stepper.breakIt(i, continueCallback);
  6077. return i;
  6078. }
  6079. fnId = fnArray[i];
  6080. if (fnId !== util.OPS.dependency) {
  6081. this[fnId].apply(this, argsArray[i]);
  6082. } else {
  6083. for (const depObjId of argsArray[i]) {
  6084. const objsPool = depObjId.startsWith("g_") ? commonObjs : objs;
  6085. if (!objsPool.has(depObjId)) {
  6086. objsPool.get(depObjId, continueCallback);
  6087. return i;
  6088. }
  6089. }
  6090. }
  6091. i++;
  6092. if (i === argsArrayLen) {
  6093. return i;
  6094. }
  6095. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  6096. if (Date.now() > endTime) {
  6097. continueCallback();
  6098. return i;
  6099. }
  6100. steps = 0;
  6101. }
  6102. }
  6103. }
  6104. #restoreInitialState() {
  6105. while (this.stateStack.length || this.inSMaskMode) {
  6106. this.restore();
  6107. }
  6108. this.ctx.restore();
  6109. if (this.transparentCanvas) {
  6110. this.ctx = this.compositeCtx;
  6111. this.ctx.save();
  6112. this.ctx.setTransform(1, 0, 0, 1, 0, 0);
  6113. this.ctx.drawImage(this.transparentCanvas, 0, 0);
  6114. this.ctx.restore();
  6115. this.transparentCanvas = null;
  6116. }
  6117. }
  6118. endDrawing() {
  6119. this.#restoreInitialState();
  6120. this.cachedCanvases.clear();
  6121. this.cachedPatterns.clear();
  6122. for (const cache of this._cachedBitmapsMap.values()) {
  6123. for (const canvas of cache.values()) {
  6124. if (typeof HTMLCanvasElement !== "undefined" && canvas instanceof HTMLCanvasElement) {
  6125. canvas.width = canvas.height = 0;
  6126. }
  6127. }
  6128. cache.clear();
  6129. }
  6130. this._cachedBitmapsMap.clear();
  6131. this.#drawFilter();
  6132. }
  6133. #drawFilter() {
  6134. if (this.pageColors) {
  6135. const hcmFilterId = this.filterFactory.addHCMFilter(this.pageColors.foreground, this.pageColors.background);
  6136. if (hcmFilterId !== "none") {
  6137. const savedFilter = this.ctx.filter;
  6138. this.ctx.filter = hcmFilterId;
  6139. this.ctx.drawImage(this.ctx.canvas, 0, 0);
  6140. this.ctx.filter = savedFilter;
  6141. }
  6142. }
  6143. }
  6144. _scaleImage(img, inverseTransform) {
  6145. const width = img.width;
  6146. const height = img.height;
  6147. let widthScale = Math.max(Math.hypot(inverseTransform[0], inverseTransform[1]), 1);
  6148. let heightScale = Math.max(Math.hypot(inverseTransform[2], inverseTransform[3]), 1);
  6149. let paintWidth = width,
  6150. paintHeight = height;
  6151. let tmpCanvasId = "prescale1";
  6152. let tmpCanvas, tmpCtx;
  6153. while (widthScale > 2 && paintWidth > 1 || heightScale > 2 && paintHeight > 1) {
  6154. let newWidth = paintWidth,
  6155. newHeight = paintHeight;
  6156. if (widthScale > 2 && paintWidth > 1) {
  6157. newWidth = paintWidth >= 16384 ? Math.floor(paintWidth / 2) - 1 || 1 : Math.ceil(paintWidth / 2);
  6158. widthScale /= paintWidth / newWidth;
  6159. }
  6160. if (heightScale > 2 && paintHeight > 1) {
  6161. newHeight = paintHeight >= 16384 ? Math.floor(paintHeight / 2) - 1 || 1 : Math.ceil(paintHeight) / 2;
  6162. heightScale /= paintHeight / newHeight;
  6163. }
  6164. tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
  6165. tmpCtx = tmpCanvas.context;
  6166. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  6167. tmpCtx.drawImage(img, 0, 0, paintWidth, paintHeight, 0, 0, newWidth, newHeight);
  6168. img = tmpCanvas.canvas;
  6169. paintWidth = newWidth;
  6170. paintHeight = newHeight;
  6171. tmpCanvasId = tmpCanvasId === "prescale1" ? "prescale2" : "prescale1";
  6172. }
  6173. return {
  6174. img,
  6175. paintWidth,
  6176. paintHeight
  6177. };
  6178. }
  6179. _createMaskCanvas(img) {
  6180. const ctx = this.ctx;
  6181. const {
  6182. width,
  6183. height
  6184. } = img;
  6185. const fillColor = this.current.fillColor;
  6186. const isPatternFill = this.current.patternFill;
  6187. const currentTransform = (0,display_utils.getCurrentTransform)(ctx);
  6188. let cache, cacheKey, scaled, maskCanvas;
  6189. if ((img.bitmap || img.data) && img.count > 1) {
  6190. const mainKey = img.bitmap || img.data.buffer;
  6191. cacheKey = JSON.stringify(isPatternFill ? currentTransform : [currentTransform.slice(0, 4), fillColor]);
  6192. cache = this._cachedBitmapsMap.get(mainKey);
  6193. if (!cache) {
  6194. cache = new Map();
  6195. this._cachedBitmapsMap.set(mainKey, cache);
  6196. }
  6197. const cachedImage = cache.get(cacheKey);
  6198. if (cachedImage && !isPatternFill) {
  6199. const offsetX = Math.round(Math.min(currentTransform[0], currentTransform[2]) + currentTransform[4]);
  6200. const offsetY = Math.round(Math.min(currentTransform[1], currentTransform[3]) + currentTransform[5]);
  6201. return {
  6202. canvas: cachedImage,
  6203. offsetX,
  6204. offsetY
  6205. };
  6206. }
  6207. scaled = cachedImage;
  6208. }
  6209. if (!scaled) {
  6210. maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
  6211. putBinaryImageMask(maskCanvas.context, img);
  6212. }
  6213. let maskToCanvas = util.Util.transform(currentTransform, [1 / width, 0, 0, -1 / height, 0, 0]);
  6214. maskToCanvas = util.Util.transform(maskToCanvas, [1, 0, 0, 1, 0, -height]);
  6215. const [minX, minY, maxX, maxY] = util.Util.getAxialAlignedBoundingBox([0, 0, width, height], maskToCanvas);
  6216. const drawnWidth = Math.round(maxX - minX) || 1;
  6217. const drawnHeight = Math.round(maxY - minY) || 1;
  6218. const fillCanvas = this.cachedCanvases.getCanvas("fillCanvas", drawnWidth, drawnHeight);
  6219. const fillCtx = fillCanvas.context;
  6220. const offsetX = minX;
  6221. const offsetY = minY;
  6222. fillCtx.translate(-offsetX, -offsetY);
  6223. fillCtx.transform(...maskToCanvas);
  6224. if (!scaled) {
  6225. scaled = this._scaleImage(maskCanvas.canvas, (0,display_utils.getCurrentTransformInverse)(fillCtx));
  6226. scaled = scaled.img;
  6227. if (cache && isPatternFill) {
  6228. cache.set(cacheKey, scaled);
  6229. }
  6230. }
  6231. fillCtx.imageSmoothingEnabled = getImageSmoothingEnabled((0,display_utils.getCurrentTransform)(fillCtx), img.interpolate);
  6232. drawImageAtIntegerCoords(fillCtx, scaled, 0, 0, scaled.width, scaled.height, 0, 0, width, height);
  6233. fillCtx.globalCompositeOperation = "source-in";
  6234. const inverse = util.Util.transform((0,display_utils.getCurrentTransformInverse)(fillCtx), [1, 0, 0, 1, -offsetX, -offsetY]);
  6235. fillCtx.fillStyle = isPatternFill ? fillColor.getPattern(ctx, this, inverse, PathType.FILL) : fillColor;
  6236. fillCtx.fillRect(0, 0, width, height);
  6237. if (cache && !isPatternFill) {
  6238. this.cachedCanvases.delete("fillCanvas");
  6239. cache.set(cacheKey, fillCanvas.canvas);
  6240. }
  6241. return {
  6242. canvas: fillCanvas.canvas,
  6243. offsetX: Math.round(offsetX),
  6244. offsetY: Math.round(offsetY)
  6245. };
  6246. }
  6247. setLineWidth(width) {
  6248. if (width !== this.current.lineWidth) {
  6249. this._cachedScaleForStroking[0] = -1;
  6250. }
  6251. this.current.lineWidth = width;
  6252. this.ctx.lineWidth = width;
  6253. }
  6254. setLineCap(style) {
  6255. this.ctx.lineCap = LINE_CAP_STYLES[style];
  6256. }
  6257. setLineJoin(style) {
  6258. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  6259. }
  6260. setMiterLimit(limit) {
  6261. this.ctx.miterLimit = limit;
  6262. }
  6263. setDash(dashArray, dashPhase) {
  6264. const ctx = this.ctx;
  6265. if (ctx.setLineDash !== undefined) {
  6266. ctx.setLineDash(dashArray);
  6267. ctx.lineDashOffset = dashPhase;
  6268. }
  6269. }
  6270. setRenderingIntent(intent) {}
  6271. setFlatness(flatness) {}
  6272. setGState(states) {
  6273. for (const [key, value] of states) {
  6274. switch (key) {
  6275. case "LW":
  6276. this.setLineWidth(value);
  6277. break;
  6278. case "LC":
  6279. this.setLineCap(value);
  6280. break;
  6281. case "LJ":
  6282. this.setLineJoin(value);
  6283. break;
  6284. case "ML":
  6285. this.setMiterLimit(value);
  6286. break;
  6287. case "D":
  6288. this.setDash(value[0], value[1]);
  6289. break;
  6290. case "RI":
  6291. this.setRenderingIntent(value);
  6292. break;
  6293. case "FL":
  6294. this.setFlatness(value);
  6295. break;
  6296. case "Font":
  6297. this.setFont(value[0], value[1]);
  6298. break;
  6299. case "CA":
  6300. this.current.strokeAlpha = value;
  6301. break;
  6302. case "ca":
  6303. this.current.fillAlpha = value;
  6304. this.ctx.globalAlpha = value;
  6305. break;
  6306. case "BM":
  6307. this.ctx.globalCompositeOperation = value;
  6308. break;
  6309. case "SMask":
  6310. this.current.activeSMask = value ? this.tempSMask : null;
  6311. this.tempSMask = null;
  6312. this.checkSMaskState();
  6313. break;
  6314. case "TR":
  6315. this.ctx.filter = this.current.transferMaps = this.filterFactory.addFilter(value);
  6316. break;
  6317. }
  6318. }
  6319. }
  6320. get inSMaskMode() {
  6321. return !!this.suspendedCtx;
  6322. }
  6323. checkSMaskState() {
  6324. const inSMaskMode = this.inSMaskMode;
  6325. if (this.current.activeSMask && !inSMaskMode) {
  6326. this.beginSMaskMode();
  6327. } else if (!this.current.activeSMask && inSMaskMode) {
  6328. this.endSMaskMode();
  6329. }
  6330. }
  6331. beginSMaskMode() {
  6332. if (this.inSMaskMode) {
  6333. throw new Error("beginSMaskMode called while already in smask mode");
  6334. }
  6335. const drawnWidth = this.ctx.canvas.width;
  6336. const drawnHeight = this.ctx.canvas.height;
  6337. const cacheId = "smaskGroupAt" + this.groupLevel;
  6338. const scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight);
  6339. this.suspendedCtx = this.ctx;
  6340. this.ctx = scratchCanvas.context;
  6341. const ctx = this.ctx;
  6342. ctx.setTransform(...(0,display_utils.getCurrentTransform)(this.suspendedCtx));
  6343. copyCtxState(this.suspendedCtx, ctx);
  6344. mirrorContextOperations(ctx, this.suspendedCtx);
  6345. this.setGState([["BM", "source-over"], ["ca", 1], ["CA", 1]]);
  6346. }
  6347. endSMaskMode() {
  6348. if (!this.inSMaskMode) {
  6349. throw new Error("endSMaskMode called while not in smask mode");
  6350. }
  6351. this.ctx._removeMirroring();
  6352. copyCtxState(this.ctx, this.suspendedCtx);
  6353. this.ctx = this.suspendedCtx;
  6354. this.suspendedCtx = null;
  6355. }
  6356. compose(dirtyBox) {
  6357. if (!this.current.activeSMask) {
  6358. return;
  6359. }
  6360. if (!dirtyBox) {
  6361. dirtyBox = [0, 0, this.ctx.canvas.width, this.ctx.canvas.height];
  6362. } else {
  6363. dirtyBox[0] = Math.floor(dirtyBox[0]);
  6364. dirtyBox[1] = Math.floor(dirtyBox[1]);
  6365. dirtyBox[2] = Math.ceil(dirtyBox[2]);
  6366. dirtyBox[3] = Math.ceil(dirtyBox[3]);
  6367. }
  6368. const smask = this.current.activeSMask;
  6369. const suspendedCtx = this.suspendedCtx;
  6370. composeSMask(suspendedCtx, smask, this.ctx, dirtyBox);
  6371. this.ctx.save();
  6372. this.ctx.setTransform(1, 0, 0, 1, 0, 0);
  6373. this.ctx.clearRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height);
  6374. this.ctx.restore();
  6375. }
  6376. save() {
  6377. if (this.inSMaskMode) {
  6378. copyCtxState(this.ctx, this.suspendedCtx);
  6379. this.suspendedCtx.save();
  6380. } else {
  6381. this.ctx.save();
  6382. }
  6383. const old = this.current;
  6384. this.stateStack.push(old);
  6385. this.current = old.clone();
  6386. }
  6387. restore() {
  6388. if (this.stateStack.length === 0 && this.inSMaskMode) {
  6389. this.endSMaskMode();
  6390. }
  6391. if (this.stateStack.length !== 0) {
  6392. this.current = this.stateStack.pop();
  6393. if (this.inSMaskMode) {
  6394. this.suspendedCtx.restore();
  6395. copyCtxState(this.suspendedCtx, this.ctx);
  6396. } else {
  6397. this.ctx.restore();
  6398. }
  6399. this.checkSMaskState();
  6400. this.pendingClip = null;
  6401. this._cachedScaleForStroking[0] = -1;
  6402. this._cachedGetSinglePixelWidth = null;
  6403. }
  6404. }
  6405. transform(a, b, c, d, e, f) {
  6406. this.ctx.transform(a, b, c, d, e, f);
  6407. this._cachedScaleForStroking[0] = -1;
  6408. this._cachedGetSinglePixelWidth = null;
  6409. }
  6410. constructPath(ops, args, minMax) {
  6411. const ctx = this.ctx;
  6412. const current = this.current;
  6413. let x = current.x,
  6414. y = current.y;
  6415. let startX, startY;
  6416. const currentTransform = (0,display_utils.getCurrentTransform)(ctx);
  6417. const isScalingMatrix = currentTransform[0] === 0 && currentTransform[3] === 0 || currentTransform[1] === 0 && currentTransform[2] === 0;
  6418. const minMaxForBezier = isScalingMatrix ? minMax.slice(0) : null;
  6419. for (let i = 0, j = 0, ii = ops.length; i < ii; i++) {
  6420. switch (ops[i] | 0) {
  6421. case util.OPS.rectangle:
  6422. x = args[j++];
  6423. y = args[j++];
  6424. const width = args[j++];
  6425. const height = args[j++];
  6426. const xw = x + width;
  6427. const yh = y + height;
  6428. ctx.moveTo(x, y);
  6429. if (width === 0 || height === 0) {
  6430. ctx.lineTo(xw, yh);
  6431. } else {
  6432. ctx.lineTo(xw, y);
  6433. ctx.lineTo(xw, yh);
  6434. ctx.lineTo(x, yh);
  6435. }
  6436. if (!isScalingMatrix) {
  6437. current.updateRectMinMax(currentTransform, [x, y, xw, yh]);
  6438. }
  6439. ctx.closePath();
  6440. break;
  6441. case util.OPS.moveTo:
  6442. x = args[j++];
  6443. y = args[j++];
  6444. ctx.moveTo(x, y);
  6445. if (!isScalingMatrix) {
  6446. current.updatePathMinMax(currentTransform, x, y);
  6447. }
  6448. break;
  6449. case util.OPS.lineTo:
  6450. x = args[j++];
  6451. y = args[j++];
  6452. ctx.lineTo(x, y);
  6453. if (!isScalingMatrix) {
  6454. current.updatePathMinMax(currentTransform, x, y);
  6455. }
  6456. break;
  6457. case util.OPS.curveTo:
  6458. startX = x;
  6459. startY = y;
  6460. x = args[j + 4];
  6461. y = args[j + 5];
  6462. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3], x, y);
  6463. current.updateCurvePathMinMax(currentTransform, startX, startY, args[j], args[j + 1], args[j + 2], args[j + 3], x, y, minMaxForBezier);
  6464. j += 6;
  6465. break;
  6466. case util.OPS.curveTo2:
  6467. startX = x;
  6468. startY = y;
  6469. ctx.bezierCurveTo(x, y, args[j], args[j + 1], args[j + 2], args[j + 3]);
  6470. current.updateCurvePathMinMax(currentTransform, startX, startY, x, y, args[j], args[j + 1], args[j + 2], args[j + 3], minMaxForBezier);
  6471. x = args[j + 2];
  6472. y = args[j + 3];
  6473. j += 4;
  6474. break;
  6475. case util.OPS.curveTo3:
  6476. startX = x;
  6477. startY = y;
  6478. x = args[j + 2];
  6479. y = args[j + 3];
  6480. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  6481. current.updateCurvePathMinMax(currentTransform, startX, startY, args[j], args[j + 1], x, y, x, y, minMaxForBezier);
  6482. j += 4;
  6483. break;
  6484. case util.OPS.closePath:
  6485. ctx.closePath();
  6486. break;
  6487. }
  6488. }
  6489. if (isScalingMatrix) {
  6490. current.updateScalingPathMinMax(currentTransform, minMaxForBezier);
  6491. }
  6492. current.setCurrentPoint(x, y);
  6493. }
  6494. closePath() {
  6495. this.ctx.closePath();
  6496. }
  6497. stroke(consumePath = true) {
  6498. const ctx = this.ctx;
  6499. const strokeColor = this.current.strokeColor;
  6500. ctx.globalAlpha = this.current.strokeAlpha;
  6501. if (this.contentVisible) {
  6502. if (typeof strokeColor === "object" && strokeColor?.getPattern) {
  6503. ctx.save();
  6504. ctx.strokeStyle = strokeColor.getPattern(ctx, this, (0,display_utils.getCurrentTransformInverse)(ctx), PathType.STROKE);
  6505. this.rescaleAndStroke(false);
  6506. ctx.restore();
  6507. } else {
  6508. this.rescaleAndStroke(true);
  6509. }
  6510. }
  6511. if (consumePath) {
  6512. this.consumePath(this.current.getClippedPathBoundingBox());
  6513. }
  6514. ctx.globalAlpha = this.current.fillAlpha;
  6515. }
  6516. closeStroke() {
  6517. this.closePath();
  6518. this.stroke();
  6519. }
  6520. fill(consumePath = true) {
  6521. const ctx = this.ctx;
  6522. const fillColor = this.current.fillColor;
  6523. const isPatternFill = this.current.patternFill;
  6524. let needRestore = false;
  6525. if (isPatternFill) {
  6526. ctx.save();
  6527. ctx.fillStyle = fillColor.getPattern(ctx, this, (0,display_utils.getCurrentTransformInverse)(ctx), PathType.FILL);
  6528. needRestore = true;
  6529. }
  6530. const intersect = this.current.getClippedPathBoundingBox();
  6531. if (this.contentVisible && intersect !== null) {
  6532. if (this.pendingEOFill) {
  6533. ctx.fill("evenodd");
  6534. this.pendingEOFill = false;
  6535. } else {
  6536. ctx.fill();
  6537. }
  6538. }
  6539. if (needRestore) {
  6540. ctx.restore();
  6541. }
  6542. if (consumePath) {
  6543. this.consumePath(intersect);
  6544. }
  6545. }
  6546. eoFill() {
  6547. this.pendingEOFill = true;
  6548. this.fill();
  6549. }
  6550. fillStroke() {
  6551. this.fill(false);
  6552. this.stroke(false);
  6553. this.consumePath();
  6554. }
  6555. eoFillStroke() {
  6556. this.pendingEOFill = true;
  6557. this.fillStroke();
  6558. }
  6559. closeFillStroke() {
  6560. this.closePath();
  6561. this.fillStroke();
  6562. }
  6563. closeEOFillStroke() {
  6564. this.pendingEOFill = true;
  6565. this.closePath();
  6566. this.fillStroke();
  6567. }
  6568. endPath() {
  6569. this.consumePath();
  6570. }
  6571. clip() {
  6572. this.pendingClip = NORMAL_CLIP;
  6573. }
  6574. eoClip() {
  6575. this.pendingClip = EO_CLIP;
  6576. }
  6577. beginText() {
  6578. this.current.textMatrix = util.IDENTITY_MATRIX;
  6579. this.current.textMatrixScale = 1;
  6580. this.current.x = this.current.lineX = 0;
  6581. this.current.y = this.current.lineY = 0;
  6582. }
  6583. endText() {
  6584. const paths = this.pendingTextPaths;
  6585. const ctx = this.ctx;
  6586. if (paths === undefined) {
  6587. ctx.beginPath();
  6588. return;
  6589. }
  6590. ctx.save();
  6591. ctx.beginPath();
  6592. for (const path of paths) {
  6593. ctx.setTransform(...path.transform);
  6594. ctx.translate(path.x, path.y);
  6595. path.addToPath(ctx, path.fontSize);
  6596. }
  6597. ctx.restore();
  6598. ctx.clip();
  6599. ctx.beginPath();
  6600. delete this.pendingTextPaths;
  6601. }
  6602. setCharSpacing(spacing) {
  6603. this.current.charSpacing = spacing;
  6604. }
  6605. setWordSpacing(spacing) {
  6606. this.current.wordSpacing = spacing;
  6607. }
  6608. setHScale(scale) {
  6609. this.current.textHScale = scale / 100;
  6610. }
  6611. setLeading(leading) {
  6612. this.current.leading = -leading;
  6613. }
  6614. setFont(fontRefName, size) {
  6615. const fontObj = this.commonObjs.get(fontRefName);
  6616. const current = this.current;
  6617. if (!fontObj) {
  6618. throw new Error(`Can't find font for ${fontRefName}`);
  6619. }
  6620. current.fontMatrix = fontObj.fontMatrix || util.FONT_IDENTITY_MATRIX;
  6621. if (current.fontMatrix[0] === 0 || current.fontMatrix[3] === 0) {
  6622. (0,util.warn)("Invalid font matrix for font " + fontRefName);
  6623. }
  6624. if (size < 0) {
  6625. size = -size;
  6626. current.fontDirection = -1;
  6627. } else {
  6628. current.fontDirection = 1;
  6629. }
  6630. this.current.font = fontObj;
  6631. this.current.fontSize = size;
  6632. if (fontObj.isType3Font) {
  6633. return;
  6634. }
  6635. const name = fontObj.loadedName || "sans-serif";
  6636. const typeface = fontObj.systemFontInfo?.css || `"${name}", ${fontObj.fallbackName}`;
  6637. let bold = "normal";
  6638. if (fontObj.black) {
  6639. bold = "900";
  6640. } else if (fontObj.bold) {
  6641. bold = "bold";
  6642. }
  6643. const italic = fontObj.italic ? "italic" : "normal";
  6644. let browserFontSize = size;
  6645. if (size < MIN_FONT_SIZE) {
  6646. browserFontSize = MIN_FONT_SIZE;
  6647. } else if (size > MAX_FONT_SIZE) {
  6648. browserFontSize = MAX_FONT_SIZE;
  6649. }
  6650. this.current.fontSizeScale = size / browserFontSize;
  6651. this.ctx.font = `${italic} ${bold} ${browserFontSize}px ${typeface}`;
  6652. }
  6653. setTextRenderingMode(mode) {
  6654. this.current.textRenderingMode = mode;
  6655. }
  6656. setTextRise(rise) {
  6657. this.current.textRise = rise;
  6658. }
  6659. moveText(x, y) {
  6660. this.current.x = this.current.lineX += x;
  6661. this.current.y = this.current.lineY += y;
  6662. }
  6663. setLeadingMoveText(x, y) {
  6664. this.setLeading(-y);
  6665. this.moveText(x, y);
  6666. }
  6667. setTextMatrix(a, b, c, d, e, f) {
  6668. this.current.textMatrix = [a, b, c, d, e, f];
  6669. this.current.textMatrixScale = Math.hypot(a, b);
  6670. this.current.x = this.current.lineX = 0;
  6671. this.current.y = this.current.lineY = 0;
  6672. }
  6673. nextLine() {
  6674. this.moveText(0, this.current.leading);
  6675. }
  6676. paintChar(character, x, y, patternTransform) {
  6677. const ctx = this.ctx;
  6678. const current = this.current;
  6679. const font = current.font;
  6680. const textRenderingMode = current.textRenderingMode;
  6681. const fontSize = current.fontSize / current.fontSizeScale;
  6682. const fillStrokeMode = textRenderingMode & util.TextRenderingMode.FILL_STROKE_MASK;
  6683. const isAddToPathSet = !!(textRenderingMode & util.TextRenderingMode.ADD_TO_PATH_FLAG);
  6684. const patternFill = current.patternFill && !font.missingFile;
  6685. let addToPath;
  6686. if (font.disableFontFace || isAddToPathSet || patternFill) {
  6687. addToPath = font.getPathGenerator(this.commonObjs, character);
  6688. }
  6689. if (font.disableFontFace || patternFill) {
  6690. ctx.save();
  6691. ctx.translate(x, y);
  6692. ctx.beginPath();
  6693. addToPath(ctx, fontSize);
  6694. if (patternTransform) {
  6695. ctx.setTransform(...patternTransform);
  6696. }
  6697. if (fillStrokeMode === util.TextRenderingMode.FILL || fillStrokeMode === util.TextRenderingMode.FILL_STROKE) {
  6698. ctx.fill();
  6699. }
  6700. if (fillStrokeMode === util.TextRenderingMode.STROKE || fillStrokeMode === util.TextRenderingMode.FILL_STROKE) {
  6701. ctx.stroke();
  6702. }
  6703. ctx.restore();
  6704. } else {
  6705. if (fillStrokeMode === util.TextRenderingMode.FILL || fillStrokeMode === util.TextRenderingMode.FILL_STROKE) {
  6706. ctx.fillText(character, x, y);
  6707. }
  6708. if (fillStrokeMode === util.TextRenderingMode.STROKE || fillStrokeMode === util.TextRenderingMode.FILL_STROKE) {
  6709. ctx.strokeText(character, x, y);
  6710. }
  6711. }
  6712. if (isAddToPathSet) {
  6713. const paths = this.pendingTextPaths ||= [];
  6714. paths.push({
  6715. transform: (0,display_utils.getCurrentTransform)(ctx),
  6716. x,
  6717. y,
  6718. fontSize,
  6719. addToPath
  6720. });
  6721. }
  6722. }
  6723. get isFontSubpixelAAEnabled() {
  6724. const {
  6725. context: ctx
  6726. } = this.cachedCanvases.getCanvas("isFontSubpixelAAEnabled", 10, 10);
  6727. ctx.scale(1.5, 1);
  6728. ctx.fillText("I", 0, 10);
  6729. const data = ctx.getImageData(0, 0, 10, 10).data;
  6730. let enabled = false;
  6731. for (let i = 3; i < data.length; i += 4) {
  6732. if (data[i] > 0 && data[i] < 255) {
  6733. enabled = true;
  6734. break;
  6735. }
  6736. }
  6737. return (0,util.shadow)(this, "isFontSubpixelAAEnabled", enabled);
  6738. }
  6739. showText(glyphs) {
  6740. const current = this.current;
  6741. const font = current.font;
  6742. if (font.isType3Font) {
  6743. return this.showType3Text(glyphs);
  6744. }
  6745. const fontSize = current.fontSize;
  6746. if (fontSize === 0) {
  6747. return undefined;
  6748. }
  6749. const ctx = this.ctx;
  6750. const fontSizeScale = current.fontSizeScale;
  6751. const charSpacing = current.charSpacing;
  6752. const wordSpacing = current.wordSpacing;
  6753. const fontDirection = current.fontDirection;
  6754. const textHScale = current.textHScale * fontDirection;
  6755. const glyphsLength = glyphs.length;
  6756. const vertical = font.vertical;
  6757. const spacingDir = vertical ? 1 : -1;
  6758. const defaultVMetrics = font.defaultVMetrics;
  6759. const widthAdvanceScale = fontSize * current.fontMatrix[0];
  6760. const simpleFillText = current.textRenderingMode === util.TextRenderingMode.FILL && !font.disableFontFace && !current.patternFill;
  6761. ctx.save();
  6762. ctx.transform(...current.textMatrix);
  6763. ctx.translate(current.x, current.y + current.textRise);
  6764. if (fontDirection > 0) {
  6765. ctx.scale(textHScale, -1);
  6766. } else {
  6767. ctx.scale(textHScale, 1);
  6768. }
  6769. let patternTransform;
  6770. if (current.patternFill) {
  6771. ctx.save();
  6772. const pattern = current.fillColor.getPattern(ctx, this, (0,display_utils.getCurrentTransformInverse)(ctx), PathType.FILL);
  6773. patternTransform = (0,display_utils.getCurrentTransform)(ctx);
  6774. ctx.restore();
  6775. ctx.fillStyle = pattern;
  6776. }
  6777. let lineWidth = current.lineWidth;
  6778. const scale = current.textMatrixScale;
  6779. if (scale === 0 || lineWidth === 0) {
  6780. const fillStrokeMode = current.textRenderingMode & util.TextRenderingMode.FILL_STROKE_MASK;
  6781. if (fillStrokeMode === util.TextRenderingMode.STROKE || fillStrokeMode === util.TextRenderingMode.FILL_STROKE) {
  6782. lineWidth = this.getSinglePixelWidth();
  6783. }
  6784. } else {
  6785. lineWidth /= scale;
  6786. }
  6787. if (fontSizeScale !== 1.0) {
  6788. ctx.scale(fontSizeScale, fontSizeScale);
  6789. lineWidth /= fontSizeScale;
  6790. }
  6791. ctx.lineWidth = lineWidth;
  6792. if (font.isInvalidPDFjsFont) {
  6793. const chars = [];
  6794. let width = 0;
  6795. for (const glyph of glyphs) {
  6796. chars.push(glyph.unicode);
  6797. width += glyph.width;
  6798. }
  6799. ctx.fillText(chars.join(""), 0, 0);
  6800. current.x += width * widthAdvanceScale * textHScale;
  6801. ctx.restore();
  6802. this.compose();
  6803. return undefined;
  6804. }
  6805. let x = 0,
  6806. i;
  6807. for (i = 0; i < glyphsLength; ++i) {
  6808. const glyph = glyphs[i];
  6809. if (typeof glyph === "number") {
  6810. x += spacingDir * glyph * fontSize / 1000;
  6811. continue;
  6812. }
  6813. let restoreNeeded = false;
  6814. const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  6815. const character = glyph.fontChar;
  6816. const accent = glyph.accent;
  6817. let scaledX, scaledY;
  6818. let width = glyph.width;
  6819. if (vertical) {
  6820. const vmetric = glyph.vmetric || defaultVMetrics;
  6821. const vx = -(glyph.vmetric ? vmetric[1] : width * 0.5) * widthAdvanceScale;
  6822. const vy = vmetric[2] * widthAdvanceScale;
  6823. width = vmetric ? -vmetric[0] : width;
  6824. scaledX = vx / fontSizeScale;
  6825. scaledY = (x + vy) / fontSizeScale;
  6826. } else {
  6827. scaledX = x / fontSizeScale;
  6828. scaledY = 0;
  6829. }
  6830. if (font.remeasure && width > 0) {
  6831. const measuredWidth = ctx.measureText(character).width * 1000 / fontSize * fontSizeScale;
  6832. if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
  6833. const characterScaleX = width / measuredWidth;
  6834. restoreNeeded = true;
  6835. ctx.save();
  6836. ctx.scale(characterScaleX, 1);
  6837. scaledX /= characterScaleX;
  6838. } else if (width !== measuredWidth) {
  6839. scaledX += (width - measuredWidth) / 2000 * fontSize / fontSizeScale;
  6840. }
  6841. }
  6842. if (this.contentVisible && (glyph.isInFont || font.missingFile)) {
  6843. if (simpleFillText && !accent) {
  6844. ctx.fillText(character, scaledX, scaledY);
  6845. } else {
  6846. this.paintChar(character, scaledX, scaledY, patternTransform);
  6847. if (accent) {
  6848. const scaledAccentX = scaledX + fontSize * accent.offset.x / fontSizeScale;
  6849. const scaledAccentY = scaledY - fontSize * accent.offset.y / fontSizeScale;
  6850. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY, patternTransform);
  6851. }
  6852. }
  6853. }
  6854. const charWidth = vertical ? width * widthAdvanceScale - spacing * fontDirection : width * widthAdvanceScale + spacing * fontDirection;
  6855. x += charWidth;
  6856. if (restoreNeeded) {
  6857. ctx.restore();
  6858. }
  6859. }
  6860. if (vertical) {
  6861. current.y -= x;
  6862. } else {
  6863. current.x += x * textHScale;
  6864. }
  6865. ctx.restore();
  6866. this.compose();
  6867. return undefined;
  6868. }
  6869. showType3Text(glyphs) {
  6870. const ctx = this.ctx;
  6871. const current = this.current;
  6872. const font = current.font;
  6873. const fontSize = current.fontSize;
  6874. const fontDirection = current.fontDirection;
  6875. const spacingDir = font.vertical ? 1 : -1;
  6876. const charSpacing = current.charSpacing;
  6877. const wordSpacing = current.wordSpacing;
  6878. const textHScale = current.textHScale * fontDirection;
  6879. const fontMatrix = current.fontMatrix || util.FONT_IDENTITY_MATRIX;
  6880. const glyphsLength = glyphs.length;
  6881. const isTextInvisible = current.textRenderingMode === util.TextRenderingMode.INVISIBLE;
  6882. let i, glyph, width, spacingLength;
  6883. if (isTextInvisible || fontSize === 0) {
  6884. return;
  6885. }
  6886. this._cachedScaleForStroking[0] = -1;
  6887. this._cachedGetSinglePixelWidth = null;
  6888. ctx.save();
  6889. ctx.transform(...current.textMatrix);
  6890. ctx.translate(current.x, current.y);
  6891. ctx.scale(textHScale, fontDirection);
  6892. for (i = 0; i < glyphsLength; ++i) {
  6893. glyph = glyphs[i];
  6894. if (typeof glyph === "number") {
  6895. spacingLength = spacingDir * glyph * fontSize / 1000;
  6896. this.ctx.translate(spacingLength, 0);
  6897. current.x += spacingLength * textHScale;
  6898. continue;
  6899. }
  6900. const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  6901. const operatorList = font.charProcOperatorList[glyph.operatorListId];
  6902. if (!operatorList) {
  6903. (0,util.warn)(`Type3 character "${glyph.operatorListId}" is not available.`);
  6904. continue;
  6905. }
  6906. if (this.contentVisible) {
  6907. this.processingType3 = glyph;
  6908. this.save();
  6909. ctx.scale(fontSize, fontSize);
  6910. ctx.transform(...fontMatrix);
  6911. this.executeOperatorList(operatorList);
  6912. this.restore();
  6913. }
  6914. const transformed = util.Util.applyTransform([glyph.width, 0], fontMatrix);
  6915. width = transformed[0] * fontSize + spacing;
  6916. ctx.translate(width, 0);
  6917. current.x += width * textHScale;
  6918. }
  6919. ctx.restore();
  6920. this.processingType3 = null;
  6921. }
  6922. setCharWidth(xWidth, yWidth) {}
  6923. setCharWidthAndBounds(xWidth, yWidth, llx, lly, urx, ury) {
  6924. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  6925. this.ctx.clip();
  6926. this.endPath();
  6927. }
  6928. getColorN_Pattern(IR) {
  6929. let pattern;
  6930. if (IR[0] === "TilingPattern") {
  6931. const color = IR[1];
  6932. const baseTransform = this.baseTransform || (0,display_utils.getCurrentTransform)(this.ctx);
  6933. const canvasGraphicsFactory = {
  6934. createCanvasGraphics: ctx => new CanvasGraphics(ctx, this.commonObjs, this.objs, this.canvasFactory, this.filterFactory, {
  6935. optionalContentConfig: this.optionalContentConfig,
  6936. markedContentStack: this.markedContentStack
  6937. })
  6938. };
  6939. pattern = new TilingPattern(IR, color, this.ctx, canvasGraphicsFactory, baseTransform);
  6940. } else {
  6941. pattern = this._getPattern(IR[1], IR[2]);
  6942. }
  6943. return pattern;
  6944. }
  6945. setStrokeColorN() {
  6946. this.current.strokeColor = this.getColorN_Pattern(arguments);
  6947. }
  6948. setFillColorN() {
  6949. this.current.fillColor = this.getColorN_Pattern(arguments);
  6950. this.current.patternFill = true;
  6951. }
  6952. setStrokeRGBColor(r, g, b) {
  6953. const color = util.Util.makeHexColor(r, g, b);
  6954. this.ctx.strokeStyle = color;
  6955. this.current.strokeColor = color;
  6956. }
  6957. setFillRGBColor(r, g, b) {
  6958. const color = util.Util.makeHexColor(r, g, b);
  6959. this.ctx.fillStyle = color;
  6960. this.current.fillColor = color;
  6961. this.current.patternFill = false;
  6962. }
  6963. _getPattern(objId, matrix = null) {
  6964. let pattern;
  6965. if (this.cachedPatterns.has(objId)) {
  6966. pattern = this.cachedPatterns.get(objId);
  6967. } else {
  6968. pattern = getShadingPattern(this.getObject(objId));
  6969. this.cachedPatterns.set(objId, pattern);
  6970. }
  6971. if (matrix) {
  6972. pattern.matrix = matrix;
  6973. }
  6974. return pattern;
  6975. }
  6976. shadingFill(objId) {
  6977. if (!this.contentVisible) {
  6978. return;
  6979. }
  6980. const ctx = this.ctx;
  6981. this.save();
  6982. const pattern = this._getPattern(objId);
  6983. ctx.fillStyle = pattern.getPattern(ctx, this, (0,display_utils.getCurrentTransformInverse)(ctx), PathType.SHADING);
  6984. const inv = (0,display_utils.getCurrentTransformInverse)(ctx);
  6985. if (inv) {
  6986. const {
  6987. width,
  6988. height
  6989. } = ctx.canvas;
  6990. const [x0, y0, x1, y1] = util.Util.getAxialAlignedBoundingBox([0, 0, width, height], inv);
  6991. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  6992. } else {
  6993. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  6994. }
  6995. this.compose(this.current.getClippedPathBoundingBox());
  6996. this.restore();
  6997. }
  6998. beginInlineImage() {
  6999. (0,util.unreachable)("Should not call beginInlineImage");
  7000. }
  7001. beginImageData() {
  7002. (0,util.unreachable)("Should not call beginImageData");
  7003. }
  7004. paintFormXObjectBegin(matrix, bbox) {
  7005. if (!this.contentVisible) {
  7006. return;
  7007. }
  7008. this.save();
  7009. this.baseTransformStack.push(this.baseTransform);
  7010. if (Array.isArray(matrix) && matrix.length === 6) {
  7011. this.transform(...matrix);
  7012. }
  7013. this.baseTransform = (0,display_utils.getCurrentTransform)(this.ctx);
  7014. if (bbox) {
  7015. const width = bbox[2] - bbox[0];
  7016. const height = bbox[3] - bbox[1];
  7017. this.ctx.rect(bbox[0], bbox[1], width, height);
  7018. this.current.updateRectMinMax((0,display_utils.getCurrentTransform)(this.ctx), bbox);
  7019. this.clip();
  7020. this.endPath();
  7021. }
  7022. }
  7023. paintFormXObjectEnd() {
  7024. if (!this.contentVisible) {
  7025. return;
  7026. }
  7027. this.restore();
  7028. this.baseTransform = this.baseTransformStack.pop();
  7029. }
  7030. beginGroup(group) {
  7031. if (!this.contentVisible) {
  7032. return;
  7033. }
  7034. this.save();
  7035. if (this.inSMaskMode) {
  7036. this.endSMaskMode();
  7037. this.current.activeSMask = null;
  7038. }
  7039. const currentCtx = this.ctx;
  7040. if (!group.isolated) {
  7041. (0,util.info)("TODO: Support non-isolated groups.");
  7042. }
  7043. if (group.knockout) {
  7044. (0,util.warn)("Knockout groups not supported.");
  7045. }
  7046. const currentTransform = (0,display_utils.getCurrentTransform)(currentCtx);
  7047. if (group.matrix) {
  7048. currentCtx.transform(...group.matrix);
  7049. }
  7050. if (!group.bbox) {
  7051. throw new Error("Bounding box is required.");
  7052. }
  7053. let bounds = util.Util.getAxialAlignedBoundingBox(group.bbox, (0,display_utils.getCurrentTransform)(currentCtx));
  7054. const canvasBounds = [0, 0, currentCtx.canvas.width, currentCtx.canvas.height];
  7055. bounds = util.Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  7056. const offsetX = Math.floor(bounds[0]);
  7057. const offsetY = Math.floor(bounds[1]);
  7058. let drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  7059. let drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  7060. let scaleX = 1,
  7061. scaleY = 1;
  7062. if (drawnWidth > MAX_GROUP_SIZE) {
  7063. scaleX = drawnWidth / MAX_GROUP_SIZE;
  7064. drawnWidth = MAX_GROUP_SIZE;
  7065. }
  7066. if (drawnHeight > MAX_GROUP_SIZE) {
  7067. scaleY = drawnHeight / MAX_GROUP_SIZE;
  7068. drawnHeight = MAX_GROUP_SIZE;
  7069. }
  7070. this.current.startNewPathAndClipBox([0, 0, drawnWidth, drawnHeight]);
  7071. let cacheId = "groupAt" + this.groupLevel;
  7072. if (group.smask) {
  7073. cacheId += "_smask_" + this.smaskCounter++ % 2;
  7074. }
  7075. const scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight);
  7076. const groupCtx = scratchCanvas.context;
  7077. groupCtx.scale(1 / scaleX, 1 / scaleY);
  7078. groupCtx.translate(-offsetX, -offsetY);
  7079. groupCtx.transform(...currentTransform);
  7080. if (group.smask) {
  7081. this.smaskStack.push({
  7082. canvas: scratchCanvas.canvas,
  7083. context: groupCtx,
  7084. offsetX,
  7085. offsetY,
  7086. scaleX,
  7087. scaleY,
  7088. subtype: group.smask.subtype,
  7089. backdrop: group.smask.backdrop,
  7090. transferMap: group.smask.transferMap || null,
  7091. startTransformInverse: null
  7092. });
  7093. } else {
  7094. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  7095. currentCtx.translate(offsetX, offsetY);
  7096. currentCtx.scale(scaleX, scaleY);
  7097. currentCtx.save();
  7098. }
  7099. copyCtxState(currentCtx, groupCtx);
  7100. this.ctx = groupCtx;
  7101. this.setGState([["BM", "source-over"], ["ca", 1], ["CA", 1]]);
  7102. this.groupStack.push(currentCtx);
  7103. this.groupLevel++;
  7104. }
  7105. endGroup(group) {
  7106. if (!this.contentVisible) {
  7107. return;
  7108. }
  7109. this.groupLevel--;
  7110. const groupCtx = this.ctx;
  7111. const ctx = this.groupStack.pop();
  7112. this.ctx = ctx;
  7113. this.ctx.imageSmoothingEnabled = false;
  7114. if (group.smask) {
  7115. this.tempSMask = this.smaskStack.pop();
  7116. this.restore();
  7117. } else {
  7118. this.ctx.restore();
  7119. const currentMtx = (0,display_utils.getCurrentTransform)(this.ctx);
  7120. this.restore();
  7121. this.ctx.save();
  7122. this.ctx.setTransform(...currentMtx);
  7123. const dirtyBox = util.Util.getAxialAlignedBoundingBox([0, 0, groupCtx.canvas.width, groupCtx.canvas.height], currentMtx);
  7124. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  7125. this.ctx.restore();
  7126. this.compose(dirtyBox);
  7127. }
  7128. }
  7129. beginAnnotation(id, rect, transform, matrix, hasOwnCanvas) {
  7130. this.#restoreInitialState();
  7131. resetCtxToDefault(this.ctx);
  7132. this.ctx.save();
  7133. this.save();
  7134. if (this.baseTransform) {
  7135. this.ctx.setTransform(...this.baseTransform);
  7136. }
  7137. if (Array.isArray(rect) && rect.length === 4) {
  7138. const width = rect[2] - rect[0];
  7139. const height = rect[3] - rect[1];
  7140. if (hasOwnCanvas && this.annotationCanvasMap) {
  7141. transform = transform.slice();
  7142. transform[4] -= rect[0];
  7143. transform[5] -= rect[1];
  7144. rect = rect.slice();
  7145. rect[0] = rect[1] = 0;
  7146. rect[2] = width;
  7147. rect[3] = height;
  7148. const [scaleX, scaleY] = util.Util.singularValueDecompose2dScale((0,display_utils.getCurrentTransform)(this.ctx));
  7149. const {
  7150. viewportScale
  7151. } = this;
  7152. const canvasWidth = Math.ceil(width * this.outputScaleX * viewportScale);
  7153. const canvasHeight = Math.ceil(height * this.outputScaleY * viewportScale);
  7154. this.annotationCanvas = this.canvasFactory.create(canvasWidth, canvasHeight);
  7155. const {
  7156. canvas,
  7157. context
  7158. } = this.annotationCanvas;
  7159. this.annotationCanvasMap.set(id, canvas);
  7160. this.annotationCanvas.savedCtx = this.ctx;
  7161. this.ctx = context;
  7162. this.ctx.save();
  7163. this.ctx.setTransform(scaleX, 0, 0, -scaleY, 0, height * scaleY);
  7164. resetCtxToDefault(this.ctx);
  7165. } else {
  7166. resetCtxToDefault(this.ctx);
  7167. this.ctx.rect(rect[0], rect[1], width, height);
  7168. this.ctx.clip();
  7169. this.endPath();
  7170. }
  7171. }
  7172. this.current = new CanvasExtraState(this.ctx.canvas.width, this.ctx.canvas.height);
  7173. this.transform(...transform);
  7174. this.transform(...matrix);
  7175. }
  7176. endAnnotation() {
  7177. if (this.annotationCanvas) {
  7178. this.ctx.restore();
  7179. this.#drawFilter();
  7180. this.ctx = this.annotationCanvas.savedCtx;
  7181. delete this.annotationCanvas.savedCtx;
  7182. delete this.annotationCanvas;
  7183. }
  7184. }
  7185. paintImageMaskXObject(img) {
  7186. if (!this.contentVisible) {
  7187. return;
  7188. }
  7189. const count = img.count;
  7190. img = this.getObject(img.data, img);
  7191. img.count = count;
  7192. const ctx = this.ctx;
  7193. const glyph = this.processingType3;
  7194. if (glyph) {
  7195. if (glyph.compiled === undefined) {
  7196. glyph.compiled = compileType3Glyph(img);
  7197. }
  7198. if (glyph.compiled) {
  7199. glyph.compiled(ctx);
  7200. return;
  7201. }
  7202. }
  7203. const mask = this._createMaskCanvas(img);
  7204. const maskCanvas = mask.canvas;
  7205. ctx.save();
  7206. ctx.setTransform(1, 0, 0, 1, 0, 0);
  7207. ctx.drawImage(maskCanvas, mask.offsetX, mask.offsetY);
  7208. ctx.restore();
  7209. this.compose();
  7210. }
  7211. paintImageMaskXObjectRepeat(img, scaleX, skewX = 0, skewY = 0, scaleY, positions) {
  7212. if (!this.contentVisible) {
  7213. return;
  7214. }
  7215. img = this.getObject(img.data, img);
  7216. const ctx = this.ctx;
  7217. ctx.save();
  7218. const currentTransform = (0,display_utils.getCurrentTransform)(ctx);
  7219. ctx.transform(scaleX, skewX, skewY, scaleY, 0, 0);
  7220. const mask = this._createMaskCanvas(img);
  7221. ctx.setTransform(1, 0, 0, 1, mask.offsetX - currentTransform[4], mask.offsetY - currentTransform[5]);
  7222. for (let i = 0, ii = positions.length; i < ii; i += 2) {
  7223. const trans = util.Util.transform(currentTransform, [scaleX, skewX, skewY, scaleY, positions[i], positions[i + 1]]);
  7224. const [x, y] = util.Util.applyTransform([0, 0], trans);
  7225. ctx.drawImage(mask.canvas, x, y);
  7226. }
  7227. ctx.restore();
  7228. this.compose();
  7229. }
  7230. paintImageMaskXObjectGroup(images) {
  7231. if (!this.contentVisible) {
  7232. return;
  7233. }
  7234. const ctx = this.ctx;
  7235. const fillColor = this.current.fillColor;
  7236. const isPatternFill = this.current.patternFill;
  7237. for (const image of images) {
  7238. const {
  7239. data,
  7240. width,
  7241. height,
  7242. transform
  7243. } = image;
  7244. const maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
  7245. const maskCtx = maskCanvas.context;
  7246. maskCtx.save();
  7247. const img = this.getObject(data, image);
  7248. putBinaryImageMask(maskCtx, img);
  7249. maskCtx.globalCompositeOperation = "source-in";
  7250. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this, (0,display_utils.getCurrentTransformInverse)(ctx), PathType.FILL) : fillColor;
  7251. maskCtx.fillRect(0, 0, width, height);
  7252. maskCtx.restore();
  7253. ctx.save();
  7254. ctx.transform(...transform);
  7255. ctx.scale(1, -1);
  7256. drawImageAtIntegerCoords(ctx, maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1);
  7257. ctx.restore();
  7258. }
  7259. this.compose();
  7260. }
  7261. paintImageXObject(objId) {
  7262. if (!this.contentVisible) {
  7263. return;
  7264. }
  7265. const imgData = this.getObject(objId);
  7266. if (!imgData) {
  7267. (0,util.warn)("Dependent image isn't ready yet");
  7268. return;
  7269. }
  7270. this.paintInlineImageXObject(imgData);
  7271. }
  7272. paintImageXObjectRepeat(objId, scaleX, scaleY, positions) {
  7273. if (!this.contentVisible) {
  7274. return;
  7275. }
  7276. const imgData = this.getObject(objId);
  7277. if (!imgData) {
  7278. (0,util.warn)("Dependent image isn't ready yet");
  7279. return;
  7280. }
  7281. const width = imgData.width;
  7282. const height = imgData.height;
  7283. const map = [];
  7284. for (let i = 0, ii = positions.length; i < ii; i += 2) {
  7285. map.push({
  7286. transform: [scaleX, 0, 0, scaleY, positions[i], positions[i + 1]],
  7287. x: 0,
  7288. y: 0,
  7289. w: width,
  7290. h: height
  7291. });
  7292. }
  7293. this.paintInlineImageXObjectGroup(imgData, map);
  7294. }
  7295. applyTransferMapsToCanvas(ctx) {
  7296. if (this.current.transferMaps !== "none") {
  7297. ctx.filter = this.current.transferMaps;
  7298. ctx.drawImage(ctx.canvas, 0, 0);
  7299. ctx.filter = "none";
  7300. }
  7301. return ctx.canvas;
  7302. }
  7303. applyTransferMapsToBitmap(imgData) {
  7304. if (this.current.transferMaps === "none") {
  7305. return imgData.bitmap;
  7306. }
  7307. const {
  7308. bitmap,
  7309. width,
  7310. height
  7311. } = imgData;
  7312. const tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", width, height);
  7313. const tmpCtx = tmpCanvas.context;
  7314. tmpCtx.filter = this.current.transferMaps;
  7315. tmpCtx.drawImage(bitmap, 0, 0);
  7316. tmpCtx.filter = "none";
  7317. return tmpCanvas.canvas;
  7318. }
  7319. paintInlineImageXObject(imgData) {
  7320. if (!this.contentVisible) {
  7321. return;
  7322. }
  7323. const width = imgData.width;
  7324. const height = imgData.height;
  7325. const ctx = this.ctx;
  7326. this.save();
  7327. if (!util.isNodeJS) {
  7328. const {
  7329. filter
  7330. } = ctx;
  7331. if (filter !== "none" && filter !== "") {
  7332. ctx.filter = "none";
  7333. }
  7334. }
  7335. ctx.scale(1 / width, -1 / height);
  7336. let imgToPaint;
  7337. if (imgData.bitmap) {
  7338. imgToPaint = this.applyTransferMapsToBitmap(imgData);
  7339. } else if (typeof HTMLElement === "function" && imgData instanceof HTMLElement || !imgData.data) {
  7340. imgToPaint = imgData;
  7341. } else {
  7342. const tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", width, height);
  7343. const tmpCtx = tmpCanvas.context;
  7344. putBinaryImageData(tmpCtx, imgData);
  7345. imgToPaint = this.applyTransferMapsToCanvas(tmpCtx);
  7346. }
  7347. const scaled = this._scaleImage(imgToPaint, (0,display_utils.getCurrentTransformInverse)(ctx));
  7348. ctx.imageSmoothingEnabled = getImageSmoothingEnabled((0,display_utils.getCurrentTransform)(ctx), imgData.interpolate);
  7349. drawImageAtIntegerCoords(ctx, scaled.img, 0, 0, scaled.paintWidth, scaled.paintHeight, 0, -height, width, height);
  7350. this.compose();
  7351. this.restore();
  7352. }
  7353. paintInlineImageXObjectGroup(imgData, map) {
  7354. if (!this.contentVisible) {
  7355. return;
  7356. }
  7357. const ctx = this.ctx;
  7358. let imgToPaint;
  7359. if (imgData.bitmap) {
  7360. imgToPaint = imgData.bitmap;
  7361. } else {
  7362. const w = imgData.width;
  7363. const h = imgData.height;
  7364. const tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", w, h);
  7365. const tmpCtx = tmpCanvas.context;
  7366. putBinaryImageData(tmpCtx, imgData);
  7367. imgToPaint = this.applyTransferMapsToCanvas(tmpCtx);
  7368. }
  7369. for (const entry of map) {
  7370. ctx.save();
  7371. ctx.transform(...entry.transform);
  7372. ctx.scale(1, -1);
  7373. drawImageAtIntegerCoords(ctx, imgToPaint, entry.x, entry.y, entry.w, entry.h, 0, -1, 1, 1);
  7374. ctx.restore();
  7375. }
  7376. this.compose();
  7377. }
  7378. paintSolidColorImageMask() {
  7379. if (!this.contentVisible) {
  7380. return;
  7381. }
  7382. this.ctx.fillRect(0, 0, 1, 1);
  7383. this.compose();
  7384. }
  7385. markPoint(tag) {}
  7386. markPointProps(tag, properties) {}
  7387. beginMarkedContent(tag) {
  7388. this.markedContentStack.push({
  7389. visible: true
  7390. });
  7391. }
  7392. beginMarkedContentProps(tag, properties) {
  7393. if (tag === "OC") {
  7394. this.markedContentStack.push({
  7395. visible: this.optionalContentConfig.isVisible(properties)
  7396. });
  7397. } else {
  7398. this.markedContentStack.push({
  7399. visible: true
  7400. });
  7401. }
  7402. this.contentVisible = this.isContentVisible();
  7403. }
  7404. endMarkedContent() {
  7405. this.markedContentStack.pop();
  7406. this.contentVisible = this.isContentVisible();
  7407. }
  7408. beginCompat() {}
  7409. endCompat() {}
  7410. consumePath(clipBox) {
  7411. const isEmpty = this.current.isEmptyClip();
  7412. if (this.pendingClip) {
  7413. this.current.updateClipFromPath();
  7414. }
  7415. if (!this.pendingClip) {
  7416. this.compose(clipBox);
  7417. }
  7418. const ctx = this.ctx;
  7419. if (this.pendingClip) {
  7420. if (!isEmpty) {
  7421. if (this.pendingClip === EO_CLIP) {
  7422. ctx.clip("evenodd");
  7423. } else {
  7424. ctx.clip();
  7425. }
  7426. }
  7427. this.pendingClip = null;
  7428. }
  7429. this.current.startNewPathAndClipBox(this.current.clipBox);
  7430. ctx.beginPath();
  7431. }
  7432. getSinglePixelWidth() {
  7433. if (!this._cachedGetSinglePixelWidth) {
  7434. const m = (0,display_utils.getCurrentTransform)(this.ctx);
  7435. if (m[1] === 0 && m[2] === 0) {
  7436. this._cachedGetSinglePixelWidth = 1 / Math.min(Math.abs(m[0]), Math.abs(m[3]));
  7437. } else {
  7438. const absDet = Math.abs(m[0] * m[3] - m[2] * m[1]);
  7439. const normX = Math.hypot(m[0], m[2]);
  7440. const normY = Math.hypot(m[1], m[3]);
  7441. this._cachedGetSinglePixelWidth = Math.max(normX, normY) / absDet;
  7442. }
  7443. }
  7444. return this._cachedGetSinglePixelWidth;
  7445. }
  7446. getScaleForStroking() {
  7447. if (this._cachedScaleForStroking[0] === -1) {
  7448. const {
  7449. lineWidth
  7450. } = this.current;
  7451. const {
  7452. a,
  7453. b,
  7454. c,
  7455. d
  7456. } = this.ctx.getTransform();
  7457. let scaleX, scaleY;
  7458. if (b === 0 && c === 0) {
  7459. const normX = Math.abs(a);
  7460. const normY = Math.abs(d);
  7461. if (normX === normY) {
  7462. if (lineWidth === 0) {
  7463. scaleX = scaleY = 1 / normX;
  7464. } else {
  7465. const scaledLineWidth = normX * lineWidth;
  7466. scaleX = scaleY = scaledLineWidth < 1 ? 1 / scaledLineWidth : 1;
  7467. }
  7468. } else if (lineWidth === 0) {
  7469. scaleX = 1 / normX;
  7470. scaleY = 1 / normY;
  7471. } else {
  7472. const scaledXLineWidth = normX * lineWidth;
  7473. const scaledYLineWidth = normY * lineWidth;
  7474. scaleX = scaledXLineWidth < 1 ? 1 / scaledXLineWidth : 1;
  7475. scaleY = scaledYLineWidth < 1 ? 1 / scaledYLineWidth : 1;
  7476. }
  7477. } else {
  7478. const absDet = Math.abs(a * d - b * c);
  7479. const normX = Math.hypot(a, b);
  7480. const normY = Math.hypot(c, d);
  7481. if (lineWidth === 0) {
  7482. scaleX = normY / absDet;
  7483. scaleY = normX / absDet;
  7484. } else {
  7485. const baseArea = lineWidth * absDet;
  7486. scaleX = normY > baseArea ? normY / baseArea : 1;
  7487. scaleY = normX > baseArea ? normX / baseArea : 1;
  7488. }
  7489. }
  7490. this._cachedScaleForStroking[0] = scaleX;
  7491. this._cachedScaleForStroking[1] = scaleY;
  7492. }
  7493. return this._cachedScaleForStroking;
  7494. }
  7495. rescaleAndStroke(saveRestore) {
  7496. const {
  7497. ctx
  7498. } = this;
  7499. const {
  7500. lineWidth
  7501. } = this.current;
  7502. const [scaleX, scaleY] = this.getScaleForStroking();
  7503. ctx.lineWidth = lineWidth || 1;
  7504. if (scaleX === 1 && scaleY === 1) {
  7505. ctx.stroke();
  7506. return;
  7507. }
  7508. const dashes = ctx.getLineDash();
  7509. if (saveRestore) {
  7510. ctx.save();
  7511. }
  7512. ctx.scale(scaleX, scaleY);
  7513. if (dashes.length > 0) {
  7514. const scale = Math.max(scaleX, scaleY);
  7515. ctx.setLineDash(dashes.map(x => x / scale));
  7516. ctx.lineDashOffset /= scale;
  7517. }
  7518. ctx.stroke();
  7519. if (saveRestore) {
  7520. ctx.restore();
  7521. }
  7522. }
  7523. isContentVisible() {
  7524. for (let i = this.markedContentStack.length - 1; i >= 0; i--) {
  7525. if (!this.markedContentStack[i].visible) {
  7526. return false;
  7527. }
  7528. }
  7529. return true;
  7530. }
  7531. }
  7532. for (const op in util.OPS) {
  7533. if (CanvasGraphics.prototype[op] !== undefined) {
  7534. CanvasGraphics.prototype[util.OPS[op]] = CanvasGraphics.prototype[op];
  7535. }
  7536. }
  7537. /***/ }),
  7538. /***/ 419:
  7539. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  7540. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  7541. /* harmony export */ DOMCMapReaderFactory: () => (/* binding */ DOMCMapReaderFactory),
  7542. /* harmony export */ DOMCanvasFactory: () => (/* binding */ DOMCanvasFactory),
  7543. /* harmony export */ DOMFilterFactory: () => (/* binding */ DOMFilterFactory),
  7544. /* harmony export */ DOMSVGFactory: () => (/* binding */ DOMSVGFactory),
  7545. /* harmony export */ DOMStandardFontDataFactory: () => (/* binding */ DOMStandardFontDataFactory),
  7546. /* harmony export */ PDFDateString: () => (/* binding */ PDFDateString),
  7547. /* harmony export */ PageViewport: () => (/* binding */ PageViewport),
  7548. /* harmony export */ PixelsPerInch: () => (/* binding */ PixelsPerInch),
  7549. /* harmony export */ RenderingCancelledException: () => (/* binding */ RenderingCancelledException),
  7550. /* harmony export */ StatTimer: () => (/* binding */ StatTimer),
  7551. /* harmony export */ fetchData: () => (/* binding */ fetchData),
  7552. /* harmony export */ getColorValues: () => (/* binding */ getColorValues),
  7553. /* harmony export */ getCurrentTransform: () => (/* binding */ getCurrentTransform),
  7554. /* harmony export */ getCurrentTransformInverse: () => (/* binding */ getCurrentTransformInverse),
  7555. /* harmony export */ getFilenameFromUrl: () => (/* binding */ getFilenameFromUrl),
  7556. /* harmony export */ getPdfFilenameFromUrl: () => (/* binding */ getPdfFilenameFromUrl),
  7557. /* harmony export */ getRGB: () => (/* binding */ getRGB),
  7558. /* harmony export */ getXfaPageViewport: () => (/* binding */ getXfaPageViewport),
  7559. /* harmony export */ isDataScheme: () => (/* binding */ isDataScheme),
  7560. /* harmony export */ isPdfFile: () => (/* binding */ isPdfFile),
  7561. /* harmony export */ isValidFetchUrl: () => (/* binding */ isValidFetchUrl),
  7562. /* harmony export */ noContextMenu: () => (/* binding */ noContextMenu),
  7563. /* harmony export */ setLayerDimensions: () => (/* binding */ setLayerDimensions)
  7564. /* harmony export */ });
  7565. /* unused harmony export deprecated */
  7566. /* harmony import */ var _base_factory_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(583);
  7567. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(292);
  7568. const SVG_NS = "http://www.w3.org/2000/svg";
  7569. class PixelsPerInch {
  7570. static CSS = 96.0;
  7571. static PDF = 72.0;
  7572. static PDF_TO_CSS_UNITS = this.CSS / this.PDF;
  7573. }
  7574. class DOMFilterFactory extends _base_factory_js__WEBPACK_IMPORTED_MODULE_0__.BaseFilterFactory {
  7575. #_cache;
  7576. #_defs;
  7577. #docId;
  7578. #document;
  7579. #_hcmCache;
  7580. #id = 0;
  7581. constructor({
  7582. docId,
  7583. ownerDocument = globalThis.document
  7584. } = {}) {
  7585. super();
  7586. this.#docId = docId;
  7587. this.#document = ownerDocument;
  7588. }
  7589. get #cache() {
  7590. return this.#_cache ||= new Map();
  7591. }
  7592. get #hcmCache() {
  7593. return this.#_hcmCache ||= new Map();
  7594. }
  7595. get #defs() {
  7596. if (!this.#_defs) {
  7597. const div = this.#document.createElement("div");
  7598. const {
  7599. style
  7600. } = div;
  7601. style.visibility = "hidden";
  7602. style.contain = "strict";
  7603. style.width = style.height = 0;
  7604. style.position = "absolute";
  7605. style.top = style.left = 0;
  7606. style.zIndex = -1;
  7607. const svg = this.#document.createElementNS(SVG_NS, "svg");
  7608. svg.setAttribute("width", 0);
  7609. svg.setAttribute("height", 0);
  7610. this.#_defs = this.#document.createElementNS(SVG_NS, "defs");
  7611. div.append(svg);
  7612. svg.append(this.#_defs);
  7613. this.#document.body.append(div);
  7614. }
  7615. return this.#_defs;
  7616. }
  7617. addFilter(maps) {
  7618. if (!maps) {
  7619. return "none";
  7620. }
  7621. let value = this.#cache.get(maps);
  7622. if (value) {
  7623. return value;
  7624. }
  7625. let tableR, tableG, tableB, key;
  7626. if (maps.length === 1) {
  7627. const mapR = maps[0];
  7628. const buffer = new Array(256);
  7629. for (let i = 0; i < 256; i++) {
  7630. buffer[i] = mapR[i] / 255;
  7631. }
  7632. key = tableR = tableG = tableB = buffer.join(",");
  7633. } else {
  7634. const [mapR, mapG, mapB] = maps;
  7635. const bufferR = new Array(256);
  7636. const bufferG = new Array(256);
  7637. const bufferB = new Array(256);
  7638. for (let i = 0; i < 256; i++) {
  7639. bufferR[i] = mapR[i] / 255;
  7640. bufferG[i] = mapG[i] / 255;
  7641. bufferB[i] = mapB[i] / 255;
  7642. }
  7643. tableR = bufferR.join(",");
  7644. tableG = bufferG.join(",");
  7645. tableB = bufferB.join(",");
  7646. key = `${tableR}${tableG}${tableB}`;
  7647. }
  7648. value = this.#cache.get(key);
  7649. if (value) {
  7650. this.#cache.set(maps, value);
  7651. return value;
  7652. }
  7653. const id = `g_${this.#docId}_transfer_map_${this.#id++}`;
  7654. const url = `url(#${id})`;
  7655. this.#cache.set(maps, url);
  7656. this.#cache.set(key, url);
  7657. const filter = this.#createFilter(id);
  7658. this.#addTransferMapConversion(tableR, tableG, tableB, filter);
  7659. return url;
  7660. }
  7661. addHCMFilter(fgColor, bgColor) {
  7662. const key = `${fgColor}-${bgColor}`;
  7663. const filterName = "base";
  7664. let info = this.#hcmCache.get(filterName);
  7665. if (info?.key === key) {
  7666. return info.url;
  7667. }
  7668. if (info) {
  7669. info.filter?.remove();
  7670. info.key = key;
  7671. info.url = "none";
  7672. info.filter = null;
  7673. } else {
  7674. info = {
  7675. key,
  7676. url: "none",
  7677. filter: null
  7678. };
  7679. this.#hcmCache.set(filterName, info);
  7680. }
  7681. if (!fgColor || !bgColor) {
  7682. return info.url;
  7683. }
  7684. const fgRGB = this.#getRGB(fgColor);
  7685. fgColor = _shared_util_js__WEBPACK_IMPORTED_MODULE_1__.Util.makeHexColor(...fgRGB);
  7686. const bgRGB = this.#getRGB(bgColor);
  7687. bgColor = _shared_util_js__WEBPACK_IMPORTED_MODULE_1__.Util.makeHexColor(...bgRGB);
  7688. this.#defs.style.color = "";
  7689. if (fgColor === "#000000" && bgColor === "#ffffff" || fgColor === bgColor) {
  7690. return info.url;
  7691. }
  7692. const map = new Array(256);
  7693. for (let i = 0; i <= 255; i++) {
  7694. const x = i / 255;
  7695. map[i] = x <= 0.03928 ? x / 12.92 : ((x + 0.055) / 1.055) ** 2.4;
  7696. }
  7697. const table = map.join(",");
  7698. const id = `g_${this.#docId}_hcm_filter`;
  7699. const filter = info.filter = this.#createFilter(id);
  7700. this.#addTransferMapConversion(table, table, table, filter);
  7701. this.#addGrayConversion(filter);
  7702. const getSteps = (c, n) => {
  7703. const start = fgRGB[c] / 255;
  7704. const end = bgRGB[c] / 255;
  7705. const arr = new Array(n + 1);
  7706. for (let i = 0; i <= n; i++) {
  7707. arr[i] = start + i / n * (end - start);
  7708. }
  7709. return arr.join(",");
  7710. };
  7711. this.#addTransferMapConversion(getSteps(0, 5), getSteps(1, 5), getSteps(2, 5), filter);
  7712. info.url = `url(#${id})`;
  7713. return info.url;
  7714. }
  7715. addHighlightHCMFilter(filterName, fgColor, bgColor, newFgColor, newBgColor) {
  7716. const key = `${fgColor}-${bgColor}-${newFgColor}-${newBgColor}`;
  7717. let info = this.#hcmCache.get(filterName);
  7718. if (info?.key === key) {
  7719. return info.url;
  7720. }
  7721. if (info) {
  7722. info.filter?.remove();
  7723. info.key = key;
  7724. info.url = "none";
  7725. info.filter = null;
  7726. } else {
  7727. info = {
  7728. key,
  7729. url: "none",
  7730. filter: null
  7731. };
  7732. this.#hcmCache.set(filterName, info);
  7733. }
  7734. if (!fgColor || !bgColor) {
  7735. return info.url;
  7736. }
  7737. const [fgRGB, bgRGB] = [fgColor, bgColor].map(this.#getRGB.bind(this));
  7738. let fgGray = Math.round(0.2126 * fgRGB[0] + 0.7152 * fgRGB[1] + 0.0722 * fgRGB[2]);
  7739. let bgGray = Math.round(0.2126 * bgRGB[0] + 0.7152 * bgRGB[1] + 0.0722 * bgRGB[2]);
  7740. let [newFgRGB, newBgRGB] = [newFgColor, newBgColor].map(this.#getRGB.bind(this));
  7741. if (bgGray < fgGray) {
  7742. [fgGray, bgGray, newFgRGB, newBgRGB] = [bgGray, fgGray, newBgRGB, newFgRGB];
  7743. }
  7744. this.#defs.style.color = "";
  7745. const getSteps = (fg, bg, n) => {
  7746. const arr = new Array(256);
  7747. const step = (bgGray - fgGray) / n;
  7748. const newStart = fg / 255;
  7749. const newStep = (bg - fg) / (255 * n);
  7750. let prev = 0;
  7751. for (let i = 0; i <= n; i++) {
  7752. const k = Math.round(fgGray + i * step);
  7753. const value = newStart + i * newStep;
  7754. for (let j = prev; j <= k; j++) {
  7755. arr[j] = value;
  7756. }
  7757. prev = k + 1;
  7758. }
  7759. for (let i = prev; i < 256; i++) {
  7760. arr[i] = arr[prev - 1];
  7761. }
  7762. return arr.join(",");
  7763. };
  7764. const id = `g_${this.#docId}_hcm_${filterName}_filter`;
  7765. const filter = info.filter = this.#createFilter(id);
  7766. this.#addGrayConversion(filter);
  7767. this.#addTransferMapConversion(getSteps(newFgRGB[0], newBgRGB[0], 5), getSteps(newFgRGB[1], newBgRGB[1], 5), getSteps(newFgRGB[2], newBgRGB[2], 5), filter);
  7768. info.url = `url(#${id})`;
  7769. return info.url;
  7770. }
  7771. destroy(keepHCM = false) {
  7772. if (keepHCM && this.#hcmCache.size !== 0) {
  7773. return;
  7774. }
  7775. if (this.#_defs) {
  7776. this.#_defs.parentNode.parentNode.remove();
  7777. this.#_defs = null;
  7778. }
  7779. if (this.#_cache) {
  7780. this.#_cache.clear();
  7781. this.#_cache = null;
  7782. }
  7783. this.#id = 0;
  7784. }
  7785. #addGrayConversion(filter) {
  7786. const feColorMatrix = this.#document.createElementNS(SVG_NS, "feColorMatrix");
  7787. feColorMatrix.setAttribute("type", "matrix");
  7788. 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");
  7789. filter.append(feColorMatrix);
  7790. }
  7791. #createFilter(id) {
  7792. const filter = this.#document.createElementNS(SVG_NS, "filter");
  7793. filter.setAttribute("color-interpolation-filters", "sRGB");
  7794. filter.setAttribute("id", id);
  7795. this.#defs.append(filter);
  7796. return filter;
  7797. }
  7798. #appendFeFunc(feComponentTransfer, func, table) {
  7799. const feFunc = this.#document.createElementNS(SVG_NS, func);
  7800. feFunc.setAttribute("type", "discrete");
  7801. feFunc.setAttribute("tableValues", table);
  7802. feComponentTransfer.append(feFunc);
  7803. }
  7804. #addTransferMapConversion(rTable, gTable, bTable, filter) {
  7805. const feComponentTransfer = this.#document.createElementNS(SVG_NS, "feComponentTransfer");
  7806. filter.append(feComponentTransfer);
  7807. this.#appendFeFunc(feComponentTransfer, "feFuncR", rTable);
  7808. this.#appendFeFunc(feComponentTransfer, "feFuncG", gTable);
  7809. this.#appendFeFunc(feComponentTransfer, "feFuncB", bTable);
  7810. }
  7811. #getRGB(color) {
  7812. this.#defs.style.color = color;
  7813. return getRGB(getComputedStyle(this.#defs).getPropertyValue("color"));
  7814. }
  7815. }
  7816. class DOMCanvasFactory extends _base_factory_js__WEBPACK_IMPORTED_MODULE_0__.BaseCanvasFactory {
  7817. constructor({
  7818. ownerDocument = globalThis.document
  7819. } = {}) {
  7820. super();
  7821. this._document = ownerDocument;
  7822. }
  7823. _createCanvas(width, height) {
  7824. const canvas = this._document.createElement("canvas");
  7825. canvas.width = width;
  7826. canvas.height = height;
  7827. return canvas;
  7828. }
  7829. }
  7830. async function fetchData(url, type = "text") {
  7831. if (isValidFetchUrl(url, document.baseURI)) {
  7832. const response = await fetch(url);
  7833. if (!response.ok) {
  7834. throw new Error(response.statusText);
  7835. }
  7836. switch (type) {
  7837. case "arraybuffer":
  7838. return response.arrayBuffer();
  7839. case "blob":
  7840. return response.blob();
  7841. case "json":
  7842. return response.json();
  7843. }
  7844. return response.text();
  7845. }
  7846. return new Promise((resolve, reject) => {
  7847. const request = new XMLHttpRequest();
  7848. request.open("GET", url, true);
  7849. request.responseType = type;
  7850. request.onreadystatechange = () => {
  7851. if (request.readyState !== XMLHttpRequest.DONE) {
  7852. return;
  7853. }
  7854. if (request.status === 200 || request.status === 0) {
  7855. switch (type) {
  7856. case "arraybuffer":
  7857. case "blob":
  7858. case "json":
  7859. resolve(request.response);
  7860. return;
  7861. }
  7862. resolve(request.responseText);
  7863. return;
  7864. }
  7865. reject(new Error(request.statusText));
  7866. };
  7867. request.send(null);
  7868. });
  7869. }
  7870. class DOMCMapReaderFactory extends _base_factory_js__WEBPACK_IMPORTED_MODULE_0__.BaseCMapReaderFactory {
  7871. _fetchData(url, compressionType) {
  7872. return fetchData(url, this.isCompressed ? "arraybuffer" : "text").then(data => ({
  7873. cMapData: data instanceof ArrayBuffer ? new Uint8Array(data) : (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_1__.stringToBytes)(data),
  7874. compressionType
  7875. }));
  7876. }
  7877. }
  7878. class DOMStandardFontDataFactory extends _base_factory_js__WEBPACK_IMPORTED_MODULE_0__.BaseStandardFontDataFactory {
  7879. _fetchData(url) {
  7880. return fetchData(url, "arraybuffer").then(data => new Uint8Array(data));
  7881. }
  7882. }
  7883. class DOMSVGFactory extends _base_factory_js__WEBPACK_IMPORTED_MODULE_0__.BaseSVGFactory {
  7884. _createSVG(type) {
  7885. return document.createElementNS(SVG_NS, type);
  7886. }
  7887. }
  7888. class PageViewport {
  7889. constructor({
  7890. viewBox,
  7891. scale,
  7892. rotation,
  7893. offsetX = 0,
  7894. offsetY = 0,
  7895. dontFlip = false
  7896. }) {
  7897. this.viewBox = viewBox;
  7898. this.scale = scale;
  7899. this.rotation = rotation;
  7900. this.offsetX = offsetX;
  7901. this.offsetY = offsetY;
  7902. const centerX = (viewBox[2] + viewBox[0]) / 2;
  7903. const centerY = (viewBox[3] + viewBox[1]) / 2;
  7904. let rotateA, rotateB, rotateC, rotateD;
  7905. rotation %= 360;
  7906. if (rotation < 0) {
  7907. rotation += 360;
  7908. }
  7909. switch (rotation) {
  7910. case 180:
  7911. rotateA = -1;
  7912. rotateB = 0;
  7913. rotateC = 0;
  7914. rotateD = 1;
  7915. break;
  7916. case 90:
  7917. rotateA = 0;
  7918. rotateB = 1;
  7919. rotateC = 1;
  7920. rotateD = 0;
  7921. break;
  7922. case 270:
  7923. rotateA = 0;
  7924. rotateB = -1;
  7925. rotateC = -1;
  7926. rotateD = 0;
  7927. break;
  7928. case 0:
  7929. rotateA = 1;
  7930. rotateB = 0;
  7931. rotateC = 0;
  7932. rotateD = -1;
  7933. break;
  7934. default:
  7935. throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.");
  7936. }
  7937. if (dontFlip) {
  7938. rotateC = -rotateC;
  7939. rotateD = -rotateD;
  7940. }
  7941. let offsetCanvasX, offsetCanvasY;
  7942. let width, height;
  7943. if (rotateA === 0) {
  7944. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  7945. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  7946. width = (viewBox[3] - viewBox[1]) * scale;
  7947. height = (viewBox[2] - viewBox[0]) * scale;
  7948. } else {
  7949. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  7950. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  7951. width = (viewBox[2] - viewBox[0]) * scale;
  7952. height = (viewBox[3] - viewBox[1]) * scale;
  7953. }
  7954. this.transform = [rotateA * scale, rotateB * scale, rotateC * scale, rotateD * scale, offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY, offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY];
  7955. this.width = width;
  7956. this.height = height;
  7957. }
  7958. get rawDims() {
  7959. const {
  7960. viewBox
  7961. } = this;
  7962. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_1__.shadow)(this, "rawDims", {
  7963. pageWidth: viewBox[2] - viewBox[0],
  7964. pageHeight: viewBox[3] - viewBox[1],
  7965. pageX: viewBox[0],
  7966. pageY: viewBox[1]
  7967. });
  7968. }
  7969. clone({
  7970. scale = this.scale,
  7971. rotation = this.rotation,
  7972. offsetX = this.offsetX,
  7973. offsetY = this.offsetY,
  7974. dontFlip = false
  7975. } = {}) {
  7976. return new PageViewport({
  7977. viewBox: this.viewBox.slice(),
  7978. scale,
  7979. rotation,
  7980. offsetX,
  7981. offsetY,
  7982. dontFlip
  7983. });
  7984. }
  7985. convertToViewportPoint(x, y) {
  7986. return _shared_util_js__WEBPACK_IMPORTED_MODULE_1__.Util.applyTransform([x, y], this.transform);
  7987. }
  7988. convertToViewportRectangle(rect) {
  7989. const topLeft = _shared_util_js__WEBPACK_IMPORTED_MODULE_1__.Util.applyTransform([rect[0], rect[1]], this.transform);
  7990. const bottomRight = _shared_util_js__WEBPACK_IMPORTED_MODULE_1__.Util.applyTransform([rect[2], rect[3]], this.transform);
  7991. return [topLeft[0], topLeft[1], bottomRight[0], bottomRight[1]];
  7992. }
  7993. convertToPdfPoint(x, y) {
  7994. return _shared_util_js__WEBPACK_IMPORTED_MODULE_1__.Util.applyInverseTransform([x, y], this.transform);
  7995. }
  7996. }
  7997. class RenderingCancelledException extends _shared_util_js__WEBPACK_IMPORTED_MODULE_1__.BaseException {
  7998. constructor(msg, extraDelay = 0) {
  7999. super(msg, "RenderingCancelledException");
  8000. this.extraDelay = extraDelay;
  8001. }
  8002. }
  8003. function isDataScheme(url) {
  8004. const ii = url.length;
  8005. let i = 0;
  8006. while (i < ii && url[i].trim() === "") {
  8007. i++;
  8008. }
  8009. return url.substring(i, i + 5).toLowerCase() === "data:";
  8010. }
  8011. function isPdfFile(filename) {
  8012. return typeof filename === "string" && /\.pdf$/i.test(filename);
  8013. }
  8014. function getFilenameFromUrl(url, onlyStripPath = false) {
  8015. if (!onlyStripPath) {
  8016. [url] = url.split(/[#?]/, 1);
  8017. }
  8018. return url.substring(url.lastIndexOf("/") + 1);
  8019. }
  8020. function getPdfFilenameFromUrl(url, defaultFilename = "document.pdf") {
  8021. if (typeof url !== "string") {
  8022. return defaultFilename;
  8023. }
  8024. if (isDataScheme(url)) {
  8025. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_1__.warn)('getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.');
  8026. return defaultFilename;
  8027. }
  8028. const reURI = /^(?:(?:[^:]+:)?\/\/[^/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
  8029. const reFilename = /[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
  8030. const splitURI = reURI.exec(url);
  8031. let suggestedFilename = reFilename.exec(splitURI[1]) || reFilename.exec(splitURI[2]) || reFilename.exec(splitURI[3]);
  8032. if (suggestedFilename) {
  8033. suggestedFilename = suggestedFilename[0];
  8034. if (suggestedFilename.includes("%")) {
  8035. try {
  8036. suggestedFilename = reFilename.exec(decodeURIComponent(suggestedFilename))[0];
  8037. } catch {}
  8038. }
  8039. }
  8040. return suggestedFilename || defaultFilename;
  8041. }
  8042. class StatTimer {
  8043. started = Object.create(null);
  8044. times = [];
  8045. time(name) {
  8046. if (name in this.started) {
  8047. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_1__.warn)(`Timer is already running for ${name}`);
  8048. }
  8049. this.started[name] = Date.now();
  8050. }
  8051. timeEnd(name) {
  8052. if (!(name in this.started)) {
  8053. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_1__.warn)(`Timer has not been started for ${name}`);
  8054. }
  8055. this.times.push({
  8056. name,
  8057. start: this.started[name],
  8058. end: Date.now()
  8059. });
  8060. delete this.started[name];
  8061. }
  8062. toString() {
  8063. const outBuf = [];
  8064. let longest = 0;
  8065. for (const {
  8066. name
  8067. } of this.times) {
  8068. longest = Math.max(name.length, longest);
  8069. }
  8070. for (const {
  8071. name,
  8072. start,
  8073. end
  8074. } of this.times) {
  8075. outBuf.push(`${name.padEnd(longest)} ${end - start}ms\n`);
  8076. }
  8077. return outBuf.join("");
  8078. }
  8079. }
  8080. function isValidFetchUrl(url, baseUrl) {
  8081. try {
  8082. const {
  8083. protocol
  8084. } = baseUrl ? new URL(url, baseUrl) : new URL(url);
  8085. return protocol === "http:" || protocol === "https:";
  8086. } catch {
  8087. return false;
  8088. }
  8089. }
  8090. function noContextMenu(e) {
  8091. e.preventDefault();
  8092. }
  8093. function deprecated(details) {
  8094. console.log("Deprecated API usage: " + details);
  8095. }
  8096. let pdfDateStringRegex;
  8097. class PDFDateString {
  8098. static toDateObject(input) {
  8099. if (!input || typeof input !== "string") {
  8100. return null;
  8101. }
  8102. pdfDateStringRegex ||= new RegExp("^D:" + "(\\d{4})" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "([Z|+|-])?" + "(\\d{2})?" + "'?" + "(\\d{2})?" + "'?");
  8103. const matches = pdfDateStringRegex.exec(input);
  8104. if (!matches) {
  8105. return null;
  8106. }
  8107. const year = parseInt(matches[1], 10);
  8108. let month = parseInt(matches[2], 10);
  8109. month = month >= 1 && month <= 12 ? month - 1 : 0;
  8110. let day = parseInt(matches[3], 10);
  8111. day = day >= 1 && day <= 31 ? day : 1;
  8112. let hour = parseInt(matches[4], 10);
  8113. hour = hour >= 0 && hour <= 23 ? hour : 0;
  8114. let minute = parseInt(matches[5], 10);
  8115. minute = minute >= 0 && minute <= 59 ? minute : 0;
  8116. let second = parseInt(matches[6], 10);
  8117. second = second >= 0 && second <= 59 ? second : 0;
  8118. const universalTimeRelation = matches[7] || "Z";
  8119. let offsetHour = parseInt(matches[8], 10);
  8120. offsetHour = offsetHour >= 0 && offsetHour <= 23 ? offsetHour : 0;
  8121. let offsetMinute = parseInt(matches[9], 10) || 0;
  8122. offsetMinute = offsetMinute >= 0 && offsetMinute <= 59 ? offsetMinute : 0;
  8123. if (universalTimeRelation === "-") {
  8124. hour += offsetHour;
  8125. minute += offsetMinute;
  8126. } else if (universalTimeRelation === "+") {
  8127. hour -= offsetHour;
  8128. minute -= offsetMinute;
  8129. }
  8130. return new Date(Date.UTC(year, month, day, hour, minute, second));
  8131. }
  8132. }
  8133. function getXfaPageViewport(xfaPage, {
  8134. scale = 1,
  8135. rotation = 0
  8136. }) {
  8137. const {
  8138. width,
  8139. height
  8140. } = xfaPage.attributes.style;
  8141. const viewBox = [0, 0, parseInt(width), parseInt(height)];
  8142. return new PageViewport({
  8143. viewBox,
  8144. scale,
  8145. rotation
  8146. });
  8147. }
  8148. function getRGB(color) {
  8149. if (color.startsWith("#")) {
  8150. const colorRGB = parseInt(color.slice(1), 16);
  8151. return [(colorRGB & 0xff0000) >> 16, (colorRGB & 0x00ff00) >> 8, colorRGB & 0x0000ff];
  8152. }
  8153. if (color.startsWith("rgb(")) {
  8154. return color.slice(4, -1).split(",").map(x => parseInt(x));
  8155. }
  8156. if (color.startsWith("rgba(")) {
  8157. return color.slice(5, -1).split(",").map(x => parseInt(x)).slice(0, 3);
  8158. }
  8159. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_1__.warn)(`Not a valid color format: "${color}"`);
  8160. return [0, 0, 0];
  8161. }
  8162. function getColorValues(colors) {
  8163. const span = document.createElement("span");
  8164. span.style.visibility = "hidden";
  8165. document.body.append(span);
  8166. for (const name of colors.keys()) {
  8167. span.style.color = name;
  8168. const computedColor = window.getComputedStyle(span).color;
  8169. colors.set(name, getRGB(computedColor));
  8170. }
  8171. span.remove();
  8172. }
  8173. function getCurrentTransform(ctx) {
  8174. const {
  8175. a,
  8176. b,
  8177. c,
  8178. d,
  8179. e,
  8180. f
  8181. } = ctx.getTransform();
  8182. return [a, b, c, d, e, f];
  8183. }
  8184. function getCurrentTransformInverse(ctx) {
  8185. const {
  8186. a,
  8187. b,
  8188. c,
  8189. d,
  8190. e,
  8191. f
  8192. } = ctx.getTransform().invertSelf();
  8193. return [a, b, c, d, e, f];
  8194. }
  8195. function setLayerDimensions(div, viewport, mustFlip = false, mustRotate = true) {
  8196. if (viewport instanceof PageViewport) {
  8197. const {
  8198. pageWidth,
  8199. pageHeight
  8200. } = viewport.rawDims;
  8201. const {
  8202. style
  8203. } = div;
  8204. const useRound = _shared_util_js__WEBPACK_IMPORTED_MODULE_1__.FeatureTest.isCSSRoundSupported;
  8205. const w = `var(--scale-factor) * ${pageWidth}px`,
  8206. h = `var(--scale-factor) * ${pageHeight}px`;
  8207. const widthStr = useRound ? `round(${w}, 1px)` : `calc(${w})`,
  8208. heightStr = useRound ? `round(${h}, 1px)` : `calc(${h})`;
  8209. if (!mustFlip || viewport.rotation % 180 === 0) {
  8210. style.width = widthStr;
  8211. style.height = heightStr;
  8212. } else {
  8213. style.width = heightStr;
  8214. style.height = widthStr;
  8215. }
  8216. }
  8217. if (mustRotate) {
  8218. div.setAttribute("data-main-rotation", viewport.rotation);
  8219. }
  8220. }
  8221. /***/ }),
  8222. /***/ 47:
  8223. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  8224. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  8225. /* harmony export */ DrawLayer: () => (/* binding */ DrawLayer)
  8226. /* harmony export */ });
  8227. /* harmony import */ var _display_utils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(419);
  8228. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(292);
  8229. class DrawLayer {
  8230. #parent = null;
  8231. #id = 0;
  8232. #mapping = new Map();
  8233. #toUpdate = new Map();
  8234. constructor({
  8235. pageIndex
  8236. }) {
  8237. this.pageIndex = pageIndex;
  8238. }
  8239. setParent(parent) {
  8240. if (!this.#parent) {
  8241. this.#parent = parent;
  8242. return;
  8243. }
  8244. if (this.#parent !== parent) {
  8245. if (this.#mapping.size > 0) {
  8246. for (const root of this.#mapping.values()) {
  8247. root.remove();
  8248. parent.append(root);
  8249. }
  8250. }
  8251. this.#parent = parent;
  8252. }
  8253. }
  8254. static get _svgFactory() {
  8255. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_1__.shadow)(this, "_svgFactory", new _display_utils_js__WEBPACK_IMPORTED_MODULE_0__.DOMSVGFactory());
  8256. }
  8257. static #setBox(element, {
  8258. x = 0,
  8259. y = 0,
  8260. width = 1,
  8261. height = 1
  8262. } = {}) {
  8263. const {
  8264. style
  8265. } = element;
  8266. style.top = `${100 * y}%`;
  8267. style.left = `${100 * x}%`;
  8268. style.width = `${100 * width}%`;
  8269. style.height = `${100 * height}%`;
  8270. }
  8271. #createSVG(box) {
  8272. const svg = DrawLayer._svgFactory.create(1, 1, true);
  8273. this.#parent.append(svg);
  8274. svg.setAttribute("aria-hidden", true);
  8275. DrawLayer.#setBox(svg, box);
  8276. return svg;
  8277. }
  8278. #createClipPath(defs, pathId) {
  8279. const clipPath = DrawLayer._svgFactory.createElement("clipPath");
  8280. defs.append(clipPath);
  8281. const clipPathId = `clip_${pathId}`;
  8282. clipPath.setAttribute("id", clipPathId);
  8283. clipPath.setAttribute("clipPathUnits", "objectBoundingBox");
  8284. const clipPathUse = DrawLayer._svgFactory.createElement("use");
  8285. clipPath.append(clipPathUse);
  8286. clipPathUse.setAttribute("href", `#${pathId}`);
  8287. clipPathUse.classList.add("clip");
  8288. return clipPathId;
  8289. }
  8290. highlight(outlines, color, opacity, isPathUpdatable = false) {
  8291. const id = this.#id++;
  8292. const root = this.#createSVG(outlines.box);
  8293. root.classList.add("highlight");
  8294. if (outlines.free) {
  8295. root.classList.add("free");
  8296. }
  8297. const defs = DrawLayer._svgFactory.createElement("defs");
  8298. root.append(defs);
  8299. const path = DrawLayer._svgFactory.createElement("path");
  8300. defs.append(path);
  8301. const pathId = `path_p${this.pageIndex}_${id}`;
  8302. path.setAttribute("id", pathId);
  8303. path.setAttribute("d", outlines.toSVGPath());
  8304. if (isPathUpdatable) {
  8305. this.#toUpdate.set(id, path);
  8306. }
  8307. const clipPathId = this.#createClipPath(defs, pathId);
  8308. const use = DrawLayer._svgFactory.createElement("use");
  8309. root.append(use);
  8310. root.setAttribute("fill", color);
  8311. root.setAttribute("fill-opacity", opacity);
  8312. use.setAttribute("href", `#${pathId}`);
  8313. this.#mapping.set(id, root);
  8314. return {
  8315. id,
  8316. clipPathId: `url(#${clipPathId})`
  8317. };
  8318. }
  8319. highlightOutline(outlines) {
  8320. const id = this.#id++;
  8321. const root = this.#createSVG(outlines.box);
  8322. root.classList.add("highlightOutline");
  8323. const defs = DrawLayer._svgFactory.createElement("defs");
  8324. root.append(defs);
  8325. const path = DrawLayer._svgFactory.createElement("path");
  8326. defs.append(path);
  8327. const pathId = `path_p${this.pageIndex}_${id}`;
  8328. path.setAttribute("id", pathId);
  8329. path.setAttribute("d", outlines.toSVGPath());
  8330. path.setAttribute("vector-effect", "non-scaling-stroke");
  8331. let maskId;
  8332. if (outlines.free) {
  8333. root.classList.add("free");
  8334. const mask = DrawLayer._svgFactory.createElement("mask");
  8335. defs.append(mask);
  8336. maskId = `mask_p${this.pageIndex}_${id}`;
  8337. mask.setAttribute("id", maskId);
  8338. mask.setAttribute("maskUnits", "objectBoundingBox");
  8339. const rect = DrawLayer._svgFactory.createElement("rect");
  8340. mask.append(rect);
  8341. rect.setAttribute("width", "1");
  8342. rect.setAttribute("height", "1");
  8343. rect.setAttribute("fill", "white");
  8344. const use = DrawLayer._svgFactory.createElement("use");
  8345. mask.append(use);
  8346. use.setAttribute("href", `#${pathId}`);
  8347. use.setAttribute("stroke", "none");
  8348. use.setAttribute("fill", "black");
  8349. use.setAttribute("fill-rule", "nonzero");
  8350. use.classList.add("mask");
  8351. }
  8352. const use1 = DrawLayer._svgFactory.createElement("use");
  8353. root.append(use1);
  8354. use1.setAttribute("href", `#${pathId}`);
  8355. if (maskId) {
  8356. use1.setAttribute("mask", `url(#${maskId})`);
  8357. }
  8358. const use2 = use1.cloneNode();
  8359. root.append(use2);
  8360. use1.classList.add("mainOutline");
  8361. use2.classList.add("secondaryOutline");
  8362. this.#mapping.set(id, root);
  8363. return id;
  8364. }
  8365. finalizeLine(id, line) {
  8366. const path = this.#toUpdate.get(id);
  8367. this.#toUpdate.delete(id);
  8368. this.updateBox(id, line.box);
  8369. path.setAttribute("d", line.toSVGPath());
  8370. }
  8371. updateLine(id, line) {
  8372. const root = this.#mapping.get(id);
  8373. const defs = root.firstChild;
  8374. const path = defs.firstChild;
  8375. path.setAttribute("d", line.toSVGPath());
  8376. }
  8377. removeFreeHighlight(id) {
  8378. this.remove(id);
  8379. this.#toUpdate.delete(id);
  8380. }
  8381. updatePath(id, line) {
  8382. this.#toUpdate.get(id).setAttribute("d", line.toSVGPath());
  8383. }
  8384. updateBox(id, box) {
  8385. DrawLayer.#setBox(this.#mapping.get(id), box);
  8386. }
  8387. show(id, visible) {
  8388. this.#mapping.get(id).classList.toggle("hidden", !visible);
  8389. }
  8390. rotate(id, angle) {
  8391. this.#mapping.get(id).setAttribute("data-main-rotation", angle);
  8392. }
  8393. changeColor(id, color) {
  8394. this.#mapping.get(id).setAttribute("fill", color);
  8395. }
  8396. changeOpacity(id, opacity) {
  8397. this.#mapping.get(id).setAttribute("fill-opacity", opacity);
  8398. }
  8399. addClass(id, className) {
  8400. this.#mapping.get(id).classList.add(className);
  8401. }
  8402. removeClass(id, className) {
  8403. this.#mapping.get(id).classList.remove(className);
  8404. }
  8405. remove(id) {
  8406. if (this.#parent === null) {
  8407. return;
  8408. }
  8409. this.#mapping.get(id).remove();
  8410. this.#mapping.delete(id);
  8411. }
  8412. destroy() {
  8413. this.#parent = null;
  8414. for (const root of this.#mapping.values()) {
  8415. root.remove();
  8416. }
  8417. this.#mapping.clear();
  8418. }
  8419. }
  8420. /***/ }),
  8421. /***/ 731:
  8422. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  8423. // EXPORTS
  8424. __webpack_require__.d(__webpack_exports__, {
  8425. AnnotationEditorLayer: () => (/* binding */ AnnotationEditorLayer)
  8426. });
  8427. // EXTERNAL MODULE: ./src/shared/util.js
  8428. var util = __webpack_require__(292);
  8429. // EXTERNAL MODULE: ./src/display/editor/editor.js + 1 modules
  8430. var editor_editor = __webpack_require__(310);
  8431. // EXTERNAL MODULE: ./src/display/editor/tools.js
  8432. var tools = __webpack_require__(830);
  8433. // EXTERNAL MODULE: ./src/display/annotation_layer.js + 1 modules
  8434. var annotation_layer = __webpack_require__(976);
  8435. ;// CONCATENATED MODULE: ./src/display/editor/freetext.js
  8436. const EOL_PATTERN = /\r\n?|\n/g;
  8437. class FreeTextEditor extends editor_editor.AnnotationEditor {
  8438. #boundEditorDivBlur = this.editorDivBlur.bind(this);
  8439. #boundEditorDivFocus = this.editorDivFocus.bind(this);
  8440. #boundEditorDivInput = this.editorDivInput.bind(this);
  8441. #boundEditorDivKeydown = this.editorDivKeydown.bind(this);
  8442. #boundEditorDivPaste = this.editorDivPaste.bind(this);
  8443. #color;
  8444. #content = "";
  8445. #editorDivId = `${this.id}-editor`;
  8446. #fontSize;
  8447. #initialData = null;
  8448. static _freeTextDefaultContent = "";
  8449. static _internalPadding = 0;
  8450. static _defaultColor = null;
  8451. static _defaultFontSize = 10;
  8452. static get _keyboardManager() {
  8453. const proto = FreeTextEditor.prototype;
  8454. const arrowChecker = self => self.isEmpty();
  8455. const small = tools.AnnotationEditorUIManager.TRANSLATE_SMALL;
  8456. const big = tools.AnnotationEditorUIManager.TRANSLATE_BIG;
  8457. return (0,util.shadow)(this, "_keyboardManager", new tools.KeyboardManager([[["ctrl+s", "mac+meta+s", "ctrl+p", "mac+meta+p"], proto.commitOrRemove, {
  8458. bubbles: true
  8459. }], [["ctrl+Enter", "mac+meta+Enter", "Escape", "mac+Escape"], proto.commitOrRemove], [["ArrowLeft", "mac+ArrowLeft"], proto._translateEmpty, {
  8460. args: [-small, 0],
  8461. checker: arrowChecker
  8462. }], [["ctrl+ArrowLeft", "mac+shift+ArrowLeft"], proto._translateEmpty, {
  8463. args: [-big, 0],
  8464. checker: arrowChecker
  8465. }], [["ArrowRight", "mac+ArrowRight"], proto._translateEmpty, {
  8466. args: [small, 0],
  8467. checker: arrowChecker
  8468. }], [["ctrl+ArrowRight", "mac+shift+ArrowRight"], proto._translateEmpty, {
  8469. args: [big, 0],
  8470. checker: arrowChecker
  8471. }], [["ArrowUp", "mac+ArrowUp"], proto._translateEmpty, {
  8472. args: [0, -small],
  8473. checker: arrowChecker
  8474. }], [["ctrl+ArrowUp", "mac+shift+ArrowUp"], proto._translateEmpty, {
  8475. args: [0, -big],
  8476. checker: arrowChecker
  8477. }], [["ArrowDown", "mac+ArrowDown"], proto._translateEmpty, {
  8478. args: [0, small],
  8479. checker: arrowChecker
  8480. }], [["ctrl+ArrowDown", "mac+shift+ArrowDown"], proto._translateEmpty, {
  8481. args: [0, big],
  8482. checker: arrowChecker
  8483. }]]));
  8484. }
  8485. static _type = "freetext";
  8486. static _editorType = util.AnnotationEditorType.FREETEXT;
  8487. constructor(params) {
  8488. super({
  8489. ...params,
  8490. name: "freeTextEditor"
  8491. });
  8492. this.#color = params.color || FreeTextEditor._defaultColor || editor_editor.AnnotationEditor._defaultLineColor;
  8493. this.#fontSize = params.fontSize || FreeTextEditor._defaultFontSize;
  8494. }
  8495. static initialize(l10n, uiManager) {
  8496. editor_editor.AnnotationEditor.initialize(l10n, uiManager, {
  8497. strings: ["pdfjs-free-text-default-content"]
  8498. });
  8499. const style = getComputedStyle(document.documentElement);
  8500. this._internalPadding = parseFloat(style.getPropertyValue("--freetext-padding"));
  8501. }
  8502. static updateDefaultParams(type, value) {
  8503. switch (type) {
  8504. case util.AnnotationEditorParamsType.FREETEXT_SIZE:
  8505. FreeTextEditor._defaultFontSize = value;
  8506. break;
  8507. case util.AnnotationEditorParamsType.FREETEXT_COLOR:
  8508. FreeTextEditor._defaultColor = value;
  8509. break;
  8510. }
  8511. }
  8512. updateParams(type, value) {
  8513. switch (type) {
  8514. case util.AnnotationEditorParamsType.FREETEXT_SIZE:
  8515. this.#updateFontSize(value);
  8516. break;
  8517. case util.AnnotationEditorParamsType.FREETEXT_COLOR:
  8518. this.#updateColor(value);
  8519. break;
  8520. }
  8521. }
  8522. static get defaultPropertiesToUpdate() {
  8523. return [[util.AnnotationEditorParamsType.FREETEXT_SIZE, FreeTextEditor._defaultFontSize], [util.AnnotationEditorParamsType.FREETEXT_COLOR, FreeTextEditor._defaultColor || editor_editor.AnnotationEditor._defaultLineColor]];
  8524. }
  8525. get propertiesToUpdate() {
  8526. return [[util.AnnotationEditorParamsType.FREETEXT_SIZE, this.#fontSize], [util.AnnotationEditorParamsType.FREETEXT_COLOR, this.#color]];
  8527. }
  8528. #updateFontSize(fontSize) {
  8529. const setFontsize = size => {
  8530. this.editorDiv.style.fontSize = `calc(${size}px * var(--scale-factor))`;
  8531. this.translate(0, -(size - this.#fontSize) * this.parentScale);
  8532. this.#fontSize = size;
  8533. this.#setEditorDimensions();
  8534. };
  8535. const savedFontsize = this.#fontSize;
  8536. this.addCommands({
  8537. cmd: setFontsize.bind(this, fontSize),
  8538. undo: setFontsize.bind(this, savedFontsize),
  8539. post: this._uiManager.updateUI.bind(this._uiManager, this),
  8540. mustExec: true,
  8541. type: util.AnnotationEditorParamsType.FREETEXT_SIZE,
  8542. overwriteIfSameType: true,
  8543. keepUndo: true
  8544. });
  8545. }
  8546. #updateColor(color) {
  8547. const setColor = col => {
  8548. this.#color = this.editorDiv.style.color = col;
  8549. };
  8550. const savedColor = this.#color;
  8551. this.addCommands({
  8552. cmd: setColor.bind(this, color),
  8553. undo: setColor.bind(this, savedColor),
  8554. post: this._uiManager.updateUI.bind(this._uiManager, this),
  8555. mustExec: true,
  8556. type: util.AnnotationEditorParamsType.FREETEXT_COLOR,
  8557. overwriteIfSameType: true,
  8558. keepUndo: true
  8559. });
  8560. }
  8561. _translateEmpty(x, y) {
  8562. this._uiManager.translateSelectedEditors(x, y, true);
  8563. }
  8564. getInitialTranslation() {
  8565. const scale = this.parentScale;
  8566. return [-FreeTextEditor._internalPadding * scale, -(FreeTextEditor._internalPadding + this.#fontSize) * scale];
  8567. }
  8568. rebuild() {
  8569. if (!this.parent) {
  8570. return;
  8571. }
  8572. super.rebuild();
  8573. if (this.div === null) {
  8574. return;
  8575. }
  8576. if (!this.isAttachedToDOM) {
  8577. this.parent.add(this);
  8578. }
  8579. }
  8580. enableEditMode() {
  8581. if (this.isInEditMode()) {
  8582. return;
  8583. }
  8584. this.parent.setEditingState(false);
  8585. this.parent.updateToolbar(util.AnnotationEditorType.FREETEXT);
  8586. super.enableEditMode();
  8587. this.overlayDiv.classList.remove("enabled");
  8588. this.editorDiv.contentEditable = true;
  8589. this._isDraggable = false;
  8590. this.div.removeAttribute("aria-activedescendant");
  8591. this.editorDiv.addEventListener("keydown", this.#boundEditorDivKeydown);
  8592. this.editorDiv.addEventListener("focus", this.#boundEditorDivFocus);
  8593. this.editorDiv.addEventListener("blur", this.#boundEditorDivBlur);
  8594. this.editorDiv.addEventListener("input", this.#boundEditorDivInput);
  8595. this.editorDiv.addEventListener("paste", this.#boundEditorDivPaste);
  8596. }
  8597. disableEditMode() {
  8598. if (!this.isInEditMode()) {
  8599. return;
  8600. }
  8601. this.parent.setEditingState(true);
  8602. super.disableEditMode();
  8603. this.overlayDiv.classList.add("enabled");
  8604. this.editorDiv.contentEditable = false;
  8605. this.div.setAttribute("aria-activedescendant", this.#editorDivId);
  8606. this._isDraggable = true;
  8607. this.editorDiv.removeEventListener("keydown", this.#boundEditorDivKeydown);
  8608. this.editorDiv.removeEventListener("focus", this.#boundEditorDivFocus);
  8609. this.editorDiv.removeEventListener("blur", this.#boundEditorDivBlur);
  8610. this.editorDiv.removeEventListener("input", this.#boundEditorDivInput);
  8611. this.editorDiv.removeEventListener("paste", this.#boundEditorDivPaste);
  8612. this.div.focus({
  8613. preventScroll: true
  8614. });
  8615. this.isEditing = false;
  8616. this.parent.div.classList.add("freetextEditing");
  8617. }
  8618. focusin(event) {
  8619. if (!this._focusEventsAllowed) {
  8620. return;
  8621. }
  8622. super.focusin(event);
  8623. if (event.target !== this.editorDiv) {
  8624. this.editorDiv.focus();
  8625. }
  8626. }
  8627. onceAdded() {
  8628. if (this.width) {
  8629. return;
  8630. }
  8631. this.enableEditMode();
  8632. this.editorDiv.focus();
  8633. if (this._initialOptions?.isCentered) {
  8634. this.center();
  8635. }
  8636. this._initialOptions = null;
  8637. }
  8638. isEmpty() {
  8639. return !this.editorDiv || this.editorDiv.innerText.trim() === "";
  8640. }
  8641. remove() {
  8642. this.isEditing = false;
  8643. if (this.parent) {
  8644. this.parent.setEditingState(true);
  8645. this.parent.div.classList.add("freetextEditing");
  8646. }
  8647. super.remove();
  8648. }
  8649. #extractText() {
  8650. const buffer = [];
  8651. this.editorDiv.normalize();
  8652. for (const child of this.editorDiv.childNodes) {
  8653. buffer.push(FreeTextEditor.#getNodeContent(child));
  8654. }
  8655. return buffer.join("\n");
  8656. }
  8657. #setEditorDimensions() {
  8658. const [parentWidth, parentHeight] = this.parentDimensions;
  8659. let rect;
  8660. if (this.isAttachedToDOM) {
  8661. rect = this.div.getBoundingClientRect();
  8662. } else {
  8663. const {
  8664. currentLayer,
  8665. div
  8666. } = this;
  8667. const savedDisplay = div.style.display;
  8668. const savedVisibility = div.classList.contains("hidden");
  8669. div.classList.remove("hidden");
  8670. div.style.display = "hidden";
  8671. currentLayer.div.append(this.div);
  8672. rect = div.getBoundingClientRect();
  8673. div.remove();
  8674. div.style.display = savedDisplay;
  8675. div.classList.toggle("hidden", savedVisibility);
  8676. }
  8677. if (this.rotation % 180 === this.parentRotation % 180) {
  8678. this.width = rect.width / parentWidth;
  8679. this.height = rect.height / parentHeight;
  8680. } else {
  8681. this.width = rect.height / parentWidth;
  8682. this.height = rect.width / parentHeight;
  8683. }
  8684. this.fixAndSetPosition();
  8685. }
  8686. commit() {
  8687. if (!this.isInEditMode()) {
  8688. return;
  8689. }
  8690. super.commit();
  8691. this.disableEditMode();
  8692. const savedText = this.#content;
  8693. const newText = this.#content = this.#extractText().trimEnd();
  8694. if (savedText === newText) {
  8695. return;
  8696. }
  8697. const setText = text => {
  8698. this.#content = text;
  8699. if (!text) {
  8700. this.remove();
  8701. return;
  8702. }
  8703. this.#setContent();
  8704. this._uiManager.rebuild(this);
  8705. this.#setEditorDimensions();
  8706. };
  8707. this.addCommands({
  8708. cmd: () => {
  8709. setText(newText);
  8710. },
  8711. undo: () => {
  8712. setText(savedText);
  8713. },
  8714. mustExec: false
  8715. });
  8716. this.#setEditorDimensions();
  8717. }
  8718. shouldGetKeyboardEvents() {
  8719. return this.isInEditMode();
  8720. }
  8721. enterInEditMode() {
  8722. this.enableEditMode();
  8723. this.editorDiv.focus();
  8724. }
  8725. dblclick(event) {
  8726. this.enterInEditMode();
  8727. }
  8728. keydown(event) {
  8729. if (event.target === this.div && event.key === "Enter") {
  8730. this.enterInEditMode();
  8731. event.preventDefault();
  8732. }
  8733. }
  8734. editorDivKeydown(event) {
  8735. FreeTextEditor._keyboardManager.exec(this, event);
  8736. }
  8737. editorDivFocus(event) {
  8738. this.isEditing = true;
  8739. }
  8740. editorDivBlur(event) {
  8741. this.isEditing = false;
  8742. }
  8743. editorDivInput(event) {
  8744. this.parent.div.classList.toggle("freetextEditing", this.isEmpty());
  8745. }
  8746. disableEditing() {
  8747. this.editorDiv.setAttribute("role", "comment");
  8748. this.editorDiv.removeAttribute("aria-multiline");
  8749. }
  8750. enableEditing() {
  8751. this.editorDiv.setAttribute("role", "textbox");
  8752. this.editorDiv.setAttribute("aria-multiline", true);
  8753. }
  8754. render() {
  8755. if (this.div) {
  8756. return this.div;
  8757. }
  8758. let baseX, baseY;
  8759. if (this.width) {
  8760. baseX = this.x;
  8761. baseY = this.y;
  8762. }
  8763. super.render();
  8764. this.editorDiv = document.createElement("div");
  8765. this.editorDiv.className = "internal";
  8766. this.editorDiv.setAttribute("id", this.#editorDivId);
  8767. this.editorDiv.setAttribute("data-l10n-id", "pdfjs-free-text");
  8768. this.enableEditing();
  8769. editor_editor.AnnotationEditor._l10nPromise.get("pdfjs-free-text-default-content").then(msg => this.editorDiv?.setAttribute("default-content", msg));
  8770. this.editorDiv.contentEditable = true;
  8771. const {
  8772. style
  8773. } = this.editorDiv;
  8774. style.fontSize = `calc(${this.#fontSize}px * var(--scale-factor))`;
  8775. style.color = this.#color;
  8776. this.div.append(this.editorDiv);
  8777. this.overlayDiv = document.createElement("div");
  8778. this.overlayDiv.classList.add("overlay", "enabled");
  8779. this.div.append(this.overlayDiv);
  8780. (0,tools.bindEvents)(this, this.div, ["dblclick", "keydown"]);
  8781. if (this.width) {
  8782. const [parentWidth, parentHeight] = this.parentDimensions;
  8783. if (this.annotationElementId) {
  8784. const {
  8785. position
  8786. } = this.#initialData;
  8787. let [tx, ty] = this.getInitialTranslation();
  8788. [tx, ty] = this.pageTranslationToScreen(tx, ty);
  8789. const [pageWidth, pageHeight] = this.pageDimensions;
  8790. const [pageX, pageY] = this.pageTranslation;
  8791. let posX, posY;
  8792. switch (this.rotation) {
  8793. case 0:
  8794. posX = baseX + (position[0] - pageX) / pageWidth;
  8795. posY = baseY + this.height - (position[1] - pageY) / pageHeight;
  8796. break;
  8797. case 90:
  8798. posX = baseX + (position[0] - pageX) / pageWidth;
  8799. posY = baseY - (position[1] - pageY) / pageHeight;
  8800. [tx, ty] = [ty, -tx];
  8801. break;
  8802. case 180:
  8803. posX = baseX - this.width + (position[0] - pageX) / pageWidth;
  8804. posY = baseY - (position[1] - pageY) / pageHeight;
  8805. [tx, ty] = [-tx, -ty];
  8806. break;
  8807. case 270:
  8808. posX = baseX + (position[0] - pageX - this.height * pageHeight) / pageWidth;
  8809. posY = baseY + (position[1] - pageY - this.width * pageWidth) / pageHeight;
  8810. [tx, ty] = [-ty, tx];
  8811. break;
  8812. }
  8813. this.setAt(posX * parentWidth, posY * parentHeight, tx, ty);
  8814. } else {
  8815. this.setAt(baseX * parentWidth, baseY * parentHeight, this.width * parentWidth, this.height * parentHeight);
  8816. }
  8817. this.#setContent();
  8818. this._isDraggable = true;
  8819. this.editorDiv.contentEditable = false;
  8820. } else {
  8821. this._isDraggable = false;
  8822. this.editorDiv.contentEditable = true;
  8823. }
  8824. return this.div;
  8825. }
  8826. static #getNodeContent(node) {
  8827. return (node.nodeType === Node.TEXT_NODE ? node.nodeValue : node.innerText).replaceAll(EOL_PATTERN, "");
  8828. }
  8829. editorDivPaste(event) {
  8830. const clipboardData = event.clipboardData || window.clipboardData;
  8831. const {
  8832. types
  8833. } = clipboardData;
  8834. if (types.length === 1 && types[0] === "text/plain") {
  8835. return;
  8836. }
  8837. event.preventDefault();
  8838. const paste = FreeTextEditor.#deserializeContent(clipboardData.getData("text") || "").replaceAll(EOL_PATTERN, "\n");
  8839. if (!paste) {
  8840. return;
  8841. }
  8842. const selection = window.getSelection();
  8843. if (!selection.rangeCount) {
  8844. return;
  8845. }
  8846. this.editorDiv.normalize();
  8847. selection.deleteFromDocument();
  8848. const range = selection.getRangeAt(0);
  8849. if (!paste.includes("\n")) {
  8850. range.insertNode(document.createTextNode(paste));
  8851. this.editorDiv.normalize();
  8852. selection.collapseToStart();
  8853. return;
  8854. }
  8855. const {
  8856. startContainer,
  8857. startOffset
  8858. } = range;
  8859. const bufferBefore = [];
  8860. const bufferAfter = [];
  8861. if (startContainer.nodeType === Node.TEXT_NODE) {
  8862. const parent = startContainer.parentElement;
  8863. bufferAfter.push(startContainer.nodeValue.slice(startOffset).replaceAll(EOL_PATTERN, ""));
  8864. if (parent !== this.editorDiv) {
  8865. let buffer = bufferBefore;
  8866. for (const child of this.editorDiv.childNodes) {
  8867. if (child === parent) {
  8868. buffer = bufferAfter;
  8869. continue;
  8870. }
  8871. buffer.push(FreeTextEditor.#getNodeContent(child));
  8872. }
  8873. }
  8874. bufferBefore.push(startContainer.nodeValue.slice(0, startOffset).replaceAll(EOL_PATTERN, ""));
  8875. } else if (startContainer === this.editorDiv) {
  8876. let buffer = bufferBefore;
  8877. let i = 0;
  8878. for (const child of this.editorDiv.childNodes) {
  8879. if (i++ === startOffset) {
  8880. buffer = bufferAfter;
  8881. }
  8882. buffer.push(FreeTextEditor.#getNodeContent(child));
  8883. }
  8884. }
  8885. this.#content = `${bufferBefore.join("\n")}${paste}${bufferAfter.join("\n")}`;
  8886. this.#setContent();
  8887. const newRange = new Range();
  8888. let beforeLength = bufferBefore.reduce((acc, line) => acc + line.length, 0);
  8889. for (const {
  8890. firstChild
  8891. } of this.editorDiv.childNodes) {
  8892. if (firstChild.nodeType === Node.TEXT_NODE) {
  8893. const length = firstChild.nodeValue.length;
  8894. if (beforeLength <= length) {
  8895. newRange.setStart(firstChild, beforeLength);
  8896. newRange.setEnd(firstChild, beforeLength);
  8897. break;
  8898. }
  8899. beforeLength -= length;
  8900. }
  8901. }
  8902. selection.removeAllRanges();
  8903. selection.addRange(newRange);
  8904. }
  8905. #setContent() {
  8906. this.editorDiv.replaceChildren();
  8907. if (!this.#content) {
  8908. return;
  8909. }
  8910. for (const line of this.#content.split("\n")) {
  8911. const div = document.createElement("div");
  8912. div.append(line ? document.createTextNode(line) : document.createElement("br"));
  8913. this.editorDiv.append(div);
  8914. }
  8915. }
  8916. #serializeContent() {
  8917. return this.#content.replaceAll("\xa0", " ");
  8918. }
  8919. static #deserializeContent(content) {
  8920. return content.replaceAll(" ", "\xa0");
  8921. }
  8922. get contentDiv() {
  8923. return this.editorDiv;
  8924. }
  8925. static deserialize(data, parent, uiManager) {
  8926. let initialData = null;
  8927. if (data instanceof annotation_layer.FreeTextAnnotationElement) {
  8928. const {
  8929. data: {
  8930. defaultAppearanceData: {
  8931. fontSize,
  8932. fontColor
  8933. },
  8934. rect,
  8935. rotation,
  8936. id
  8937. },
  8938. textContent,
  8939. textPosition,
  8940. parent: {
  8941. page: {
  8942. pageNumber
  8943. }
  8944. }
  8945. } = data;
  8946. if (!textContent || textContent.length === 0) {
  8947. return null;
  8948. }
  8949. initialData = data = {
  8950. annotationType: util.AnnotationEditorType.FREETEXT,
  8951. color: Array.from(fontColor),
  8952. fontSize,
  8953. value: textContent.join("\n"),
  8954. position: textPosition,
  8955. pageIndex: pageNumber - 1,
  8956. rect: rect.slice(0),
  8957. rotation,
  8958. id,
  8959. deleted: false
  8960. };
  8961. }
  8962. const editor = super.deserialize(data, parent, uiManager);
  8963. editor.#fontSize = data.fontSize;
  8964. editor.#color = util.Util.makeHexColor(...data.color);
  8965. editor.#content = FreeTextEditor.#deserializeContent(data.value);
  8966. editor.annotationElementId = data.id || null;
  8967. editor.#initialData = initialData;
  8968. return editor;
  8969. }
  8970. serialize(isForCopying = false) {
  8971. if (this.isEmpty()) {
  8972. return null;
  8973. }
  8974. if (this.deleted) {
  8975. return {
  8976. pageIndex: this.pageIndex,
  8977. id: this.annotationElementId,
  8978. deleted: true
  8979. };
  8980. }
  8981. const padding = FreeTextEditor._internalPadding * this.parentScale;
  8982. const rect = this.getRect(padding, padding);
  8983. const color = editor_editor.AnnotationEditor._colorManager.convert(this.isAttachedToDOM ? getComputedStyle(this.editorDiv).color : this.#color);
  8984. const serialized = {
  8985. annotationType: util.AnnotationEditorType.FREETEXT,
  8986. color,
  8987. fontSize: this.#fontSize,
  8988. value: this.#serializeContent(),
  8989. pageIndex: this.pageIndex,
  8990. rect,
  8991. rotation: this.rotation,
  8992. structTreeParentId: this._structTreeParentId
  8993. };
  8994. if (isForCopying) {
  8995. return serialized;
  8996. }
  8997. if (this.annotationElementId && !this.#hasElementChanged(serialized)) {
  8998. return null;
  8999. }
  9000. serialized.id = this.annotationElementId;
  9001. return serialized;
  9002. }
  9003. #hasElementChanged(serialized) {
  9004. const {
  9005. value,
  9006. fontSize,
  9007. color,
  9008. pageIndex
  9009. } = this.#initialData;
  9010. return this._hasBeenMoved || serialized.value !== value || serialized.fontSize !== fontSize || serialized.color.some((c, i) => c !== color[i]) || serialized.pageIndex !== pageIndex;
  9011. }
  9012. renderAnnotationElement(annotation) {
  9013. const content = super.renderAnnotationElement(annotation);
  9014. if (this.deleted) {
  9015. return content;
  9016. }
  9017. const {
  9018. style
  9019. } = content;
  9020. style.fontSize = `calc(${this.#fontSize}px * var(--scale-factor))`;
  9021. style.color = this.#color;
  9022. content.replaceChildren();
  9023. for (const line of this.#content.split("\n")) {
  9024. const div = document.createElement("div");
  9025. div.append(line ? document.createTextNode(line) : document.createElement("br"));
  9026. content.append(div);
  9027. }
  9028. const padding = FreeTextEditor._internalPadding * this.parentScale;
  9029. annotation.updateEdited({
  9030. rect: this.getRect(padding, padding)
  9031. });
  9032. return content;
  9033. }
  9034. resetAnnotationElement(annotation) {
  9035. super.resetAnnotationElement(annotation);
  9036. annotation.resetEdited();
  9037. }
  9038. }
  9039. // EXTERNAL MODULE: ./src/display/editor/outliner.js
  9040. var editor_outliner = __webpack_require__(61);
  9041. // EXTERNAL MODULE: ./src/display/editor/color_picker.js
  9042. var color_picker = __webpack_require__(259);
  9043. // EXTERNAL MODULE: ./src/display/display_utils.js
  9044. var display_utils = __webpack_require__(419);
  9045. ;// CONCATENATED MODULE: ./src/display/editor/highlight.js
  9046. class HighlightEditor extends editor_editor.AnnotationEditor {
  9047. #anchorNode = null;
  9048. #anchorOffset = 0;
  9049. #boxes;
  9050. #clipPathId = null;
  9051. #colorPicker = null;
  9052. #focusOutlines = null;
  9053. #focusNode = null;
  9054. #focusOffset = 0;
  9055. #highlightDiv = null;
  9056. #highlightOutlines = null;
  9057. #id = null;
  9058. #isFreeHighlight = false;
  9059. #boundKeydown = this.#keydown.bind(this);
  9060. #lastPoint = null;
  9061. #opacity;
  9062. #outlineId = null;
  9063. #text = "";
  9064. #thickness;
  9065. #methodOfCreation = "";
  9066. static _defaultColor = null;
  9067. static _defaultOpacity = 1;
  9068. static _defaultThickness = 12;
  9069. static _l10nPromise;
  9070. static _type = "highlight";
  9071. static _editorType = util.AnnotationEditorType.HIGHLIGHT;
  9072. static _freeHighlightId = -1;
  9073. static _freeHighlight = null;
  9074. static _freeHighlightClipId = "";
  9075. static get _keyboardManager() {
  9076. const proto = HighlightEditor.prototype;
  9077. return (0,util.shadow)(this, "_keyboardManager", new tools.KeyboardManager([[["ArrowLeft", "mac+ArrowLeft"], proto._moveCaret, {
  9078. args: [0]
  9079. }], [["ArrowRight", "mac+ArrowRight"], proto._moveCaret, {
  9080. args: [1]
  9081. }], [["ArrowUp", "mac+ArrowUp"], proto._moveCaret, {
  9082. args: [2]
  9083. }], [["ArrowDown", "mac+ArrowDown"], proto._moveCaret, {
  9084. args: [3]
  9085. }]]));
  9086. }
  9087. constructor(params) {
  9088. super({
  9089. ...params,
  9090. name: "highlightEditor"
  9091. });
  9092. this.color = params.color || HighlightEditor._defaultColor;
  9093. this.#thickness = params.thickness || HighlightEditor._defaultThickness;
  9094. this.#opacity = params.opacity || HighlightEditor._defaultOpacity;
  9095. this.#boxes = params.boxes || null;
  9096. this.#methodOfCreation = params.methodOfCreation || "";
  9097. this.#text = params.text || "";
  9098. this._isDraggable = false;
  9099. if (params.highlightId > -1) {
  9100. this.#isFreeHighlight = true;
  9101. this.#createFreeOutlines(params);
  9102. this.#addToDrawLayer();
  9103. } else {
  9104. this.#anchorNode = params.anchorNode;
  9105. this.#anchorOffset = params.anchorOffset;
  9106. this.#focusNode = params.focusNode;
  9107. this.#focusOffset = params.focusOffset;
  9108. this.#createOutlines();
  9109. this.#addToDrawLayer();
  9110. this.rotate(this.rotation);
  9111. }
  9112. }
  9113. get telemetryInitialData() {
  9114. return {
  9115. action: "added",
  9116. type: this.#isFreeHighlight ? "free_highlight" : "highlight",
  9117. color: this._uiManager.highlightColorNames.get(this.color),
  9118. thickness: this.#thickness,
  9119. methodOfCreation: this.#methodOfCreation
  9120. };
  9121. }
  9122. get telemetryFinalData() {
  9123. return {
  9124. type: "highlight",
  9125. color: this._uiManager.highlightColorNames.get(this.color)
  9126. };
  9127. }
  9128. static computeTelemetryFinalData(data) {
  9129. return {
  9130. numberOfColors: data.get("color").size
  9131. };
  9132. }
  9133. #createOutlines() {
  9134. const outliner = new editor_outliner.Outliner(this.#boxes, 0.001);
  9135. this.#highlightOutlines = outliner.getOutlines();
  9136. ({
  9137. x: this.x,
  9138. y: this.y,
  9139. width: this.width,
  9140. height: this.height
  9141. } = this.#highlightOutlines.box);
  9142. const outlinerForOutline = new editor_outliner.Outliner(this.#boxes, 0.0025, 0.001, this._uiManager.direction === "ltr");
  9143. this.#focusOutlines = outlinerForOutline.getOutlines();
  9144. const {
  9145. lastPoint
  9146. } = this.#focusOutlines.box;
  9147. this.#lastPoint = [(lastPoint[0] - this.x) / this.width, (lastPoint[1] - this.y) / this.height];
  9148. }
  9149. #createFreeOutlines({
  9150. highlightOutlines,
  9151. highlightId,
  9152. clipPathId
  9153. }) {
  9154. this.#highlightOutlines = highlightOutlines;
  9155. const extraThickness = 1.5;
  9156. this.#focusOutlines = highlightOutlines.getNewOutline(this.#thickness / 2 + extraThickness, 0.0025);
  9157. if (highlightId >= 0) {
  9158. this.#id = highlightId;
  9159. this.#clipPathId = clipPathId;
  9160. this.parent.drawLayer.finalizeLine(highlightId, highlightOutlines);
  9161. this.#outlineId = this.parent.drawLayer.highlightOutline(this.#focusOutlines);
  9162. } else if (this.parent) {
  9163. const angle = this.parent.viewport.rotation;
  9164. this.parent.drawLayer.updateLine(this.#id, highlightOutlines);
  9165. this.parent.drawLayer.updateBox(this.#id, HighlightEditor.#rotateBbox(this.#highlightOutlines.box, (angle - this.rotation + 360) % 360));
  9166. this.parent.drawLayer.updateLine(this.#outlineId, this.#focusOutlines);
  9167. this.parent.drawLayer.updateBox(this.#outlineId, HighlightEditor.#rotateBbox(this.#focusOutlines.box, angle));
  9168. }
  9169. const {
  9170. x,
  9171. y,
  9172. width,
  9173. height
  9174. } = highlightOutlines.box;
  9175. switch (this.rotation) {
  9176. case 0:
  9177. this.x = x;
  9178. this.y = y;
  9179. this.width = width;
  9180. this.height = height;
  9181. break;
  9182. case 90:
  9183. {
  9184. const [pageWidth, pageHeight] = this.parentDimensions;
  9185. this.x = y;
  9186. this.y = 1 - x;
  9187. this.width = width * pageHeight / pageWidth;
  9188. this.height = height * pageWidth / pageHeight;
  9189. break;
  9190. }
  9191. case 180:
  9192. this.x = 1 - x;
  9193. this.y = 1 - y;
  9194. this.width = width;
  9195. this.height = height;
  9196. break;
  9197. case 270:
  9198. {
  9199. const [pageWidth, pageHeight] = this.parentDimensions;
  9200. this.x = 1 - y;
  9201. this.y = x;
  9202. this.width = width * pageHeight / pageWidth;
  9203. this.height = height * pageWidth / pageHeight;
  9204. break;
  9205. }
  9206. }
  9207. const {
  9208. lastPoint
  9209. } = this.#focusOutlines.box;
  9210. this.#lastPoint = [(lastPoint[0] - x) / width, (lastPoint[1] - y) / height];
  9211. }
  9212. static initialize(l10n, uiManager) {
  9213. editor_editor.AnnotationEditor.initialize(l10n, uiManager);
  9214. HighlightEditor._defaultColor ||= uiManager.highlightColors?.values().next().value || "#fff066";
  9215. }
  9216. static updateDefaultParams(type, value) {
  9217. switch (type) {
  9218. case util.AnnotationEditorParamsType.HIGHLIGHT_DEFAULT_COLOR:
  9219. HighlightEditor._defaultColor = value;
  9220. break;
  9221. case util.AnnotationEditorParamsType.HIGHLIGHT_THICKNESS:
  9222. HighlightEditor._defaultThickness = value;
  9223. break;
  9224. }
  9225. }
  9226. translateInPage(x, y) {}
  9227. get toolbarPosition() {
  9228. return this.#lastPoint;
  9229. }
  9230. updateParams(type, value) {
  9231. switch (type) {
  9232. case util.AnnotationEditorParamsType.HIGHLIGHT_COLOR:
  9233. this.#updateColor(value);
  9234. break;
  9235. case util.AnnotationEditorParamsType.HIGHLIGHT_THICKNESS:
  9236. this.#updateThickness(value);
  9237. break;
  9238. }
  9239. }
  9240. static get defaultPropertiesToUpdate() {
  9241. return [[util.AnnotationEditorParamsType.HIGHLIGHT_DEFAULT_COLOR, HighlightEditor._defaultColor], [util.AnnotationEditorParamsType.HIGHLIGHT_THICKNESS, HighlightEditor._defaultThickness]];
  9242. }
  9243. get propertiesToUpdate() {
  9244. return [[util.AnnotationEditorParamsType.HIGHLIGHT_COLOR, this.color || HighlightEditor._defaultColor], [util.AnnotationEditorParamsType.HIGHLIGHT_THICKNESS, this.#thickness || HighlightEditor._defaultThickness], [util.AnnotationEditorParamsType.HIGHLIGHT_FREE, this.#isFreeHighlight]];
  9245. }
  9246. #updateColor(color) {
  9247. const setColor = col => {
  9248. this.color = col;
  9249. this.parent?.drawLayer.changeColor(this.#id, col);
  9250. this.#colorPicker?.updateColor(col);
  9251. };
  9252. const savedColor = this.color;
  9253. this.addCommands({
  9254. cmd: setColor.bind(this, color),
  9255. undo: setColor.bind(this, savedColor),
  9256. post: this._uiManager.updateUI.bind(this._uiManager, this),
  9257. mustExec: true,
  9258. type: util.AnnotationEditorParamsType.HIGHLIGHT_COLOR,
  9259. overwriteIfSameType: true,
  9260. keepUndo: true
  9261. });
  9262. this._reportTelemetry({
  9263. action: "color_changed",
  9264. color: this._uiManager.highlightColorNames.get(color)
  9265. }, true);
  9266. }
  9267. #updateThickness(thickness) {
  9268. const savedThickness = this.#thickness;
  9269. const setThickness = th => {
  9270. this.#thickness = th;
  9271. this.#changeThickness(th);
  9272. };
  9273. this.addCommands({
  9274. cmd: setThickness.bind(this, thickness),
  9275. undo: setThickness.bind(this, savedThickness),
  9276. post: this._uiManager.updateUI.bind(this._uiManager, this),
  9277. mustExec: true,
  9278. type: util.AnnotationEditorParamsType.INK_THICKNESS,
  9279. overwriteIfSameType: true,
  9280. keepUndo: true
  9281. });
  9282. this._reportTelemetry({
  9283. action: "thickness_changed",
  9284. thickness
  9285. }, true);
  9286. }
  9287. async addEditToolbar() {
  9288. const toolbar = await super.addEditToolbar();
  9289. if (!toolbar) {
  9290. return null;
  9291. }
  9292. if (this._uiManager.highlightColors) {
  9293. this.#colorPicker = new color_picker.ColorPicker({
  9294. editor: this
  9295. });
  9296. toolbar.addColorPicker(this.#colorPicker);
  9297. }
  9298. return toolbar;
  9299. }
  9300. disableEditing() {
  9301. super.disableEditing();
  9302. this.div.classList.toggle("disabled", true);
  9303. }
  9304. enableEditing() {
  9305. super.enableEditing();
  9306. this.div.classList.toggle("disabled", false);
  9307. }
  9308. fixAndSetPosition() {
  9309. return super.fixAndSetPosition(this.#getRotation());
  9310. }
  9311. getBaseTranslation() {
  9312. return [0, 0];
  9313. }
  9314. getRect(tx, ty) {
  9315. return super.getRect(tx, ty, this.#getRotation());
  9316. }
  9317. onceAdded() {
  9318. this.parent.addUndoableEditor(this);
  9319. this.div.focus();
  9320. }
  9321. remove() {
  9322. this.#cleanDrawLayer();
  9323. this._reportTelemetry({
  9324. action: "deleted"
  9325. });
  9326. super.remove();
  9327. }
  9328. rebuild() {
  9329. if (!this.parent) {
  9330. return;
  9331. }
  9332. super.rebuild();
  9333. if (this.div === null) {
  9334. return;
  9335. }
  9336. this.#addToDrawLayer();
  9337. if (!this.isAttachedToDOM) {
  9338. this.parent.add(this);
  9339. }
  9340. }
  9341. setParent(parent) {
  9342. let mustBeSelected = false;
  9343. if (this.parent && !parent) {
  9344. this.#cleanDrawLayer();
  9345. } else if (parent) {
  9346. this.#addToDrawLayer(parent);
  9347. mustBeSelected = !this.parent && this.div?.classList.contains("selectedEditor");
  9348. }
  9349. super.setParent(parent);
  9350. this.show(this._isVisible);
  9351. if (mustBeSelected) {
  9352. this.select();
  9353. }
  9354. }
  9355. #changeThickness(thickness) {
  9356. if (!this.#isFreeHighlight) {
  9357. return;
  9358. }
  9359. this.#createFreeOutlines({
  9360. highlightOutlines: this.#highlightOutlines.getNewOutline(thickness / 2)
  9361. });
  9362. this.fixAndSetPosition();
  9363. const [parentWidth, parentHeight] = this.parentDimensions;
  9364. this.setDims(this.width * parentWidth, this.height * parentHeight);
  9365. }
  9366. #cleanDrawLayer() {
  9367. if (this.#id === null || !this.parent) {
  9368. return;
  9369. }
  9370. this.parent.drawLayer.remove(this.#id);
  9371. this.#id = null;
  9372. this.parent.drawLayer.remove(this.#outlineId);
  9373. this.#outlineId = null;
  9374. }
  9375. #addToDrawLayer(parent = this.parent) {
  9376. if (this.#id !== null) {
  9377. return;
  9378. }
  9379. ({
  9380. id: this.#id,
  9381. clipPathId: this.#clipPathId
  9382. } = parent.drawLayer.highlight(this.#highlightOutlines, this.color, this.#opacity));
  9383. this.#outlineId = parent.drawLayer.highlightOutline(this.#focusOutlines);
  9384. if (this.#highlightDiv) {
  9385. this.#highlightDiv.style.clipPath = this.#clipPathId;
  9386. }
  9387. }
  9388. static #rotateBbox({
  9389. x,
  9390. y,
  9391. width,
  9392. height
  9393. }, angle) {
  9394. switch (angle) {
  9395. case 90:
  9396. return {
  9397. x: 1 - y - height,
  9398. y: x,
  9399. width: height,
  9400. height: width
  9401. };
  9402. case 180:
  9403. return {
  9404. x: 1 - x - width,
  9405. y: 1 - y - height,
  9406. width,
  9407. height
  9408. };
  9409. case 270:
  9410. return {
  9411. x: y,
  9412. y: 1 - x - width,
  9413. width: height,
  9414. height: width
  9415. };
  9416. }
  9417. return {
  9418. x,
  9419. y,
  9420. width,
  9421. height
  9422. };
  9423. }
  9424. rotate(angle) {
  9425. const {
  9426. drawLayer
  9427. } = this.parent;
  9428. let box;
  9429. if (this.#isFreeHighlight) {
  9430. angle = (angle - this.rotation + 360) % 360;
  9431. box = HighlightEditor.#rotateBbox(this.#highlightOutlines.box, angle);
  9432. } else {
  9433. box = HighlightEditor.#rotateBbox(this, angle);
  9434. }
  9435. drawLayer.rotate(this.#id, angle);
  9436. drawLayer.rotate(this.#outlineId, angle);
  9437. drawLayer.updateBox(this.#id, box);
  9438. drawLayer.updateBox(this.#outlineId, HighlightEditor.#rotateBbox(this.#focusOutlines.box, angle));
  9439. }
  9440. render() {
  9441. if (this.div) {
  9442. return this.div;
  9443. }
  9444. const div = super.render();
  9445. if (this.#text) {
  9446. div.setAttribute("aria-label", this.#text);
  9447. div.setAttribute("role", "mark");
  9448. }
  9449. if (this.#isFreeHighlight) {
  9450. div.classList.add("free");
  9451. } else {
  9452. this.div.addEventListener("keydown", this.#boundKeydown);
  9453. }
  9454. const highlightDiv = this.#highlightDiv = document.createElement("div");
  9455. div.append(highlightDiv);
  9456. highlightDiv.setAttribute("aria-hidden", "true");
  9457. highlightDiv.className = "internal";
  9458. highlightDiv.style.clipPath = this.#clipPathId;
  9459. const [parentWidth, parentHeight] = this.parentDimensions;
  9460. this.setDims(this.width * parentWidth, this.height * parentHeight);
  9461. (0,tools.bindEvents)(this, this.#highlightDiv, ["pointerover", "pointerleave"]);
  9462. this.enableEditing();
  9463. return div;
  9464. }
  9465. pointerover() {
  9466. this.parent.drawLayer.addClass(this.#outlineId, "hovered");
  9467. }
  9468. pointerleave() {
  9469. this.parent.drawLayer.removeClass(this.#outlineId, "hovered");
  9470. }
  9471. #keydown(event) {
  9472. HighlightEditor._keyboardManager.exec(this, event);
  9473. }
  9474. _moveCaret(direction) {
  9475. this.parent.unselect(this);
  9476. switch (direction) {
  9477. case 0:
  9478. case 2:
  9479. this.#setCaret(true);
  9480. break;
  9481. case 1:
  9482. case 3:
  9483. this.#setCaret(false);
  9484. break;
  9485. }
  9486. }
  9487. #setCaret(start) {
  9488. if (!this.#anchorNode) {
  9489. return;
  9490. }
  9491. const selection = window.getSelection();
  9492. if (start) {
  9493. selection.setPosition(this.#anchorNode, this.#anchorOffset);
  9494. } else {
  9495. selection.setPosition(this.#focusNode, this.#focusOffset);
  9496. }
  9497. }
  9498. select() {
  9499. super.select();
  9500. if (!this.#outlineId) {
  9501. return;
  9502. }
  9503. this.parent?.drawLayer.removeClass(this.#outlineId, "hovered");
  9504. this.parent?.drawLayer.addClass(this.#outlineId, "selected");
  9505. }
  9506. unselect() {
  9507. super.unselect();
  9508. if (!this.#outlineId) {
  9509. return;
  9510. }
  9511. this.parent?.drawLayer.removeClass(this.#outlineId, "selected");
  9512. if (!this.#isFreeHighlight) {
  9513. this.#setCaret(false);
  9514. }
  9515. }
  9516. get _mustFixPosition() {
  9517. return !this.#isFreeHighlight;
  9518. }
  9519. show(visible = this._isVisible) {
  9520. super.show(visible);
  9521. if (this.parent) {
  9522. this.parent.drawLayer.show(this.#id, visible);
  9523. this.parent.drawLayer.show(this.#outlineId, visible);
  9524. }
  9525. }
  9526. #getRotation() {
  9527. return this.#isFreeHighlight ? this.rotation : 0;
  9528. }
  9529. #serializeBoxes() {
  9530. if (this.#isFreeHighlight) {
  9531. return null;
  9532. }
  9533. const [pageWidth, pageHeight] = this.pageDimensions;
  9534. const boxes = this.#boxes;
  9535. const quadPoints = new Array(boxes.length * 8);
  9536. let i = 0;
  9537. for (const {
  9538. x,
  9539. y,
  9540. width,
  9541. height
  9542. } of boxes) {
  9543. const sx = x * pageWidth;
  9544. const sy = (1 - y - height) * pageHeight;
  9545. quadPoints[i] = quadPoints[i + 4] = sx;
  9546. quadPoints[i + 1] = quadPoints[i + 3] = sy;
  9547. quadPoints[i + 2] = quadPoints[i + 6] = sx + width * pageWidth;
  9548. quadPoints[i + 5] = quadPoints[i + 7] = sy + height * pageHeight;
  9549. i += 8;
  9550. }
  9551. return quadPoints;
  9552. }
  9553. #serializeOutlines(rect) {
  9554. return this.#highlightOutlines.serialize(rect, this.#getRotation());
  9555. }
  9556. static startHighlighting(parent, isLTR, {
  9557. target: textLayer,
  9558. x,
  9559. y
  9560. }) {
  9561. const {
  9562. x: layerX,
  9563. y: layerY,
  9564. width: parentWidth,
  9565. height: parentHeight
  9566. } = textLayer.getBoundingClientRect();
  9567. const pointerMove = e => {
  9568. this.#highlightMove(parent, e);
  9569. };
  9570. const pointerDownOptions = {
  9571. capture: true,
  9572. passive: false
  9573. };
  9574. const pointerDown = e => {
  9575. e.preventDefault();
  9576. e.stopPropagation();
  9577. };
  9578. const pointerUpCallback = e => {
  9579. textLayer.removeEventListener("pointermove", pointerMove);
  9580. window.removeEventListener("blur", pointerUpCallback);
  9581. window.removeEventListener("pointerup", pointerUpCallback);
  9582. window.removeEventListener("pointerdown", pointerDown, pointerDownOptions);
  9583. window.removeEventListener("contextmenu", display_utils.noContextMenu);
  9584. this.#endHighlight(parent, e);
  9585. };
  9586. window.addEventListener("blur", pointerUpCallback);
  9587. window.addEventListener("pointerup", pointerUpCallback);
  9588. window.addEventListener("pointerdown", pointerDown, pointerDownOptions);
  9589. window.addEventListener("contextmenu", display_utils.noContextMenu);
  9590. textLayer.addEventListener("pointermove", pointerMove);
  9591. this._freeHighlight = new editor_outliner.FreeOutliner({
  9592. x,
  9593. y
  9594. }, [layerX, layerY, parentWidth, parentHeight], parent.scale, this._defaultThickness / 2, isLTR, 0.001);
  9595. ({
  9596. id: this._freeHighlightId,
  9597. clipPathId: this._freeHighlightClipId
  9598. } = parent.drawLayer.highlight(this._freeHighlight, this._defaultColor, this._defaultOpacity, true));
  9599. }
  9600. static #highlightMove(parent, event) {
  9601. if (this._freeHighlight.add(event)) {
  9602. parent.drawLayer.updatePath(this._freeHighlightId, this._freeHighlight);
  9603. }
  9604. }
  9605. static #endHighlight(parent, event) {
  9606. if (!this._freeHighlight.isEmpty()) {
  9607. parent.createAndAddNewEditor(event, false, {
  9608. highlightId: this._freeHighlightId,
  9609. highlightOutlines: this._freeHighlight.getOutlines(),
  9610. clipPathId: this._freeHighlightClipId,
  9611. methodOfCreation: "main_toolbar"
  9612. });
  9613. } else {
  9614. parent.drawLayer.removeFreeHighlight(this._freeHighlightId);
  9615. }
  9616. this._freeHighlightId = -1;
  9617. this._freeHighlight = null;
  9618. this._freeHighlightClipId = "";
  9619. }
  9620. static deserialize(data, parent, uiManager) {
  9621. const editor = super.deserialize(data, parent, uiManager);
  9622. const {
  9623. rect: [blX, blY, trX, trY],
  9624. color,
  9625. quadPoints
  9626. } = data;
  9627. editor.color = util.Util.makeHexColor(...color);
  9628. editor.#opacity = data.opacity;
  9629. const [pageWidth, pageHeight] = editor.pageDimensions;
  9630. editor.width = (trX - blX) / pageWidth;
  9631. editor.height = (trY - blY) / pageHeight;
  9632. const boxes = editor.#boxes = [];
  9633. for (let i = 0; i < quadPoints.length; i += 8) {
  9634. boxes.push({
  9635. x: (quadPoints[4] - trX) / pageWidth,
  9636. y: (trY - (1 - quadPoints[i + 5])) / pageHeight,
  9637. width: (quadPoints[i + 2] - quadPoints[i]) / pageWidth,
  9638. height: (quadPoints[i + 5] - quadPoints[i + 1]) / pageHeight
  9639. });
  9640. }
  9641. editor.#createOutlines();
  9642. return editor;
  9643. }
  9644. serialize(isForCopying = false) {
  9645. if (this.isEmpty() || isForCopying) {
  9646. return null;
  9647. }
  9648. const rect = this.getRect(0, 0);
  9649. const color = editor_editor.AnnotationEditor._colorManager.convert(this.color);
  9650. return {
  9651. annotationType: util.AnnotationEditorType.HIGHLIGHT,
  9652. color,
  9653. opacity: this.#opacity,
  9654. thickness: this.#thickness,
  9655. quadPoints: this.#serializeBoxes(),
  9656. outlines: this.#serializeOutlines(rect),
  9657. pageIndex: this.pageIndex,
  9658. rect,
  9659. rotation: this.#getRotation(),
  9660. structTreeParentId: this._structTreeParentId
  9661. };
  9662. }
  9663. static canCreateNewEmptyEditor() {
  9664. return false;
  9665. }
  9666. }
  9667. ;// CONCATENATED MODULE: ./src/display/editor/ink.js
  9668. class InkEditor extends editor_editor.AnnotationEditor {
  9669. #baseHeight = 0;
  9670. #baseWidth = 0;
  9671. #boundCanvasPointermove = this.canvasPointermove.bind(this);
  9672. #boundCanvasPointerleave = this.canvasPointerleave.bind(this);
  9673. #boundCanvasPointerup = this.canvasPointerup.bind(this);
  9674. #boundCanvasPointerdown = this.canvasPointerdown.bind(this);
  9675. #canvasContextMenuTimeoutId = null;
  9676. #currentPath2D = new Path2D();
  9677. #disableEditing = false;
  9678. #hasSomethingToDraw = false;
  9679. #isCanvasInitialized = false;
  9680. #observer = null;
  9681. #realWidth = 0;
  9682. #realHeight = 0;
  9683. #requestFrameCallback = null;
  9684. static _defaultColor = null;
  9685. static _defaultOpacity = 1;
  9686. static _defaultThickness = 1;
  9687. static _type = "ink";
  9688. static _editorType = util.AnnotationEditorType.INK;
  9689. constructor(params) {
  9690. super({
  9691. ...params,
  9692. name: "inkEditor"
  9693. });
  9694. this.color = params.color || null;
  9695. this.thickness = params.thickness || null;
  9696. this.opacity = params.opacity || null;
  9697. this.paths = [];
  9698. this.bezierPath2D = [];
  9699. this.allRawPaths = [];
  9700. this.currentPath = [];
  9701. this.scaleFactor = 1;
  9702. this.translationX = this.translationY = 0;
  9703. this.x = 0;
  9704. this.y = 0;
  9705. this._willKeepAspectRatio = true;
  9706. }
  9707. static initialize(l10n, uiManager) {
  9708. editor_editor.AnnotationEditor.initialize(l10n, uiManager);
  9709. }
  9710. static updateDefaultParams(type, value) {
  9711. switch (type) {
  9712. case util.AnnotationEditorParamsType.INK_THICKNESS:
  9713. InkEditor._defaultThickness = value;
  9714. break;
  9715. case util.AnnotationEditorParamsType.INK_COLOR:
  9716. InkEditor._defaultColor = value;
  9717. break;
  9718. case util.AnnotationEditorParamsType.INK_OPACITY:
  9719. InkEditor._defaultOpacity = value / 100;
  9720. break;
  9721. }
  9722. }
  9723. updateParams(type, value) {
  9724. switch (type) {
  9725. case util.AnnotationEditorParamsType.INK_THICKNESS:
  9726. this.#updateThickness(value);
  9727. break;
  9728. case util.AnnotationEditorParamsType.INK_COLOR:
  9729. this.#updateColor(value);
  9730. break;
  9731. case util.AnnotationEditorParamsType.INK_OPACITY:
  9732. this.#updateOpacity(value);
  9733. break;
  9734. }
  9735. }
  9736. static get defaultPropertiesToUpdate() {
  9737. 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)]];
  9738. }
  9739. get propertiesToUpdate() {
  9740. 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))]];
  9741. }
  9742. #updateThickness(thickness) {
  9743. const setThickness = th => {
  9744. this.thickness = th;
  9745. this.#fitToContent();
  9746. };
  9747. const savedThickness = this.thickness;
  9748. this.addCommands({
  9749. cmd: setThickness.bind(this, thickness),
  9750. undo: setThickness.bind(this, savedThickness),
  9751. post: this._uiManager.updateUI.bind(this._uiManager, this),
  9752. mustExec: true,
  9753. type: util.AnnotationEditorParamsType.INK_THICKNESS,
  9754. overwriteIfSameType: true,
  9755. keepUndo: true
  9756. });
  9757. }
  9758. #updateColor(color) {
  9759. const setColor = col => {
  9760. this.color = col;
  9761. this.#redraw();
  9762. };
  9763. const savedColor = this.color;
  9764. this.addCommands({
  9765. cmd: setColor.bind(this, color),
  9766. undo: setColor.bind(this, savedColor),
  9767. post: this._uiManager.updateUI.bind(this._uiManager, this),
  9768. mustExec: true,
  9769. type: util.AnnotationEditorParamsType.INK_COLOR,
  9770. overwriteIfSameType: true,
  9771. keepUndo: true
  9772. });
  9773. }
  9774. #updateOpacity(opacity) {
  9775. const setOpacity = op => {
  9776. this.opacity = op;
  9777. this.#redraw();
  9778. };
  9779. opacity /= 100;
  9780. const savedOpacity = this.opacity;
  9781. this.addCommands({
  9782. cmd: setOpacity.bind(this, opacity),
  9783. undo: setOpacity.bind(this, savedOpacity),
  9784. post: this._uiManager.updateUI.bind(this._uiManager, this),
  9785. mustExec: true,
  9786. type: util.AnnotationEditorParamsType.INK_OPACITY,
  9787. overwriteIfSameType: true,
  9788. keepUndo: true
  9789. });
  9790. }
  9791. rebuild() {
  9792. if (!this.parent) {
  9793. return;
  9794. }
  9795. super.rebuild();
  9796. if (this.div === null) {
  9797. return;
  9798. }
  9799. if (!this.canvas) {
  9800. this.#createCanvas();
  9801. this.#createObserver();
  9802. }
  9803. if (!this.isAttachedToDOM) {
  9804. this.parent.add(this);
  9805. this.#setCanvasDims();
  9806. }
  9807. this.#fitToContent();
  9808. }
  9809. remove() {
  9810. if (this.canvas === null) {
  9811. return;
  9812. }
  9813. if (!this.isEmpty()) {
  9814. this.commit();
  9815. }
  9816. this.canvas.width = this.canvas.height = 0;
  9817. this.canvas.remove();
  9818. this.canvas = null;
  9819. if (this.#canvasContextMenuTimeoutId) {
  9820. clearTimeout(this.#canvasContextMenuTimeoutId);
  9821. this.#canvasContextMenuTimeoutId = null;
  9822. }
  9823. this.#observer.disconnect();
  9824. this.#observer = null;
  9825. super.remove();
  9826. }
  9827. setParent(parent) {
  9828. if (!this.parent && parent) {
  9829. this._uiManager.removeShouldRescale(this);
  9830. } else if (this.parent && parent === null) {
  9831. this._uiManager.addShouldRescale(this);
  9832. }
  9833. super.setParent(parent);
  9834. }
  9835. onScaleChanging() {
  9836. const [parentWidth, parentHeight] = this.parentDimensions;
  9837. const width = this.width * parentWidth;
  9838. const height = this.height * parentHeight;
  9839. this.setDimensions(width, height);
  9840. }
  9841. enableEditMode() {
  9842. if (this.#disableEditing || this.canvas === null) {
  9843. return;
  9844. }
  9845. super.enableEditMode();
  9846. this._isDraggable = false;
  9847. this.canvas.addEventListener("pointerdown", this.#boundCanvasPointerdown);
  9848. }
  9849. disableEditMode() {
  9850. if (!this.isInEditMode() || this.canvas === null) {
  9851. return;
  9852. }
  9853. super.disableEditMode();
  9854. this._isDraggable = !this.isEmpty();
  9855. this.div.classList.remove("editing");
  9856. this.canvas.removeEventListener("pointerdown", this.#boundCanvasPointerdown);
  9857. }
  9858. onceAdded() {
  9859. this._isDraggable = !this.isEmpty();
  9860. }
  9861. isEmpty() {
  9862. return this.paths.length === 0 || this.paths.length === 1 && this.paths[0].length === 0;
  9863. }
  9864. #getInitialBBox() {
  9865. const {
  9866. parentRotation,
  9867. parentDimensions: [width, height]
  9868. } = this;
  9869. switch (parentRotation) {
  9870. case 90:
  9871. return [0, height, height, width];
  9872. case 180:
  9873. return [width, height, width, height];
  9874. case 270:
  9875. return [width, 0, height, width];
  9876. default:
  9877. return [0, 0, width, height];
  9878. }
  9879. }
  9880. #setStroke() {
  9881. const {
  9882. ctx,
  9883. color,
  9884. opacity,
  9885. thickness,
  9886. parentScale,
  9887. scaleFactor
  9888. } = this;
  9889. ctx.lineWidth = thickness * parentScale / scaleFactor;
  9890. ctx.lineCap = "round";
  9891. ctx.lineJoin = "round";
  9892. ctx.miterLimit = 10;
  9893. ctx.strokeStyle = `${color}${(0,tools.opacityToHex)(opacity)}`;
  9894. }
  9895. #startDrawing(x, y) {
  9896. this.canvas.addEventListener("contextmenu", display_utils.noContextMenu);
  9897. this.canvas.addEventListener("pointerleave", this.#boundCanvasPointerleave);
  9898. this.canvas.addEventListener("pointermove", this.#boundCanvasPointermove);
  9899. this.canvas.addEventListener("pointerup", this.#boundCanvasPointerup);
  9900. this.canvas.removeEventListener("pointerdown", this.#boundCanvasPointerdown);
  9901. this.isEditing = true;
  9902. if (!this.#isCanvasInitialized) {
  9903. this.#isCanvasInitialized = true;
  9904. this.#setCanvasDims();
  9905. this.thickness ||= InkEditor._defaultThickness;
  9906. this.color ||= InkEditor._defaultColor || editor_editor.AnnotationEditor._defaultLineColor;
  9907. this.opacity ??= InkEditor._defaultOpacity;
  9908. }
  9909. this.currentPath.push([x, y]);
  9910. this.#hasSomethingToDraw = false;
  9911. this.#setStroke();
  9912. this.#requestFrameCallback = () => {
  9913. this.#drawPoints();
  9914. if (this.#requestFrameCallback) {
  9915. window.requestAnimationFrame(this.#requestFrameCallback);
  9916. }
  9917. };
  9918. window.requestAnimationFrame(this.#requestFrameCallback);
  9919. }
  9920. #draw(x, y) {
  9921. const [lastX, lastY] = this.currentPath.at(-1);
  9922. if (this.currentPath.length > 1 && x === lastX && y === lastY) {
  9923. return;
  9924. }
  9925. const currentPath = this.currentPath;
  9926. let path2D = this.#currentPath2D;
  9927. currentPath.push([x, y]);
  9928. this.#hasSomethingToDraw = true;
  9929. if (currentPath.length <= 2) {
  9930. path2D.moveTo(...currentPath[0]);
  9931. path2D.lineTo(x, y);
  9932. return;
  9933. }
  9934. if (currentPath.length === 3) {
  9935. this.#currentPath2D = path2D = new Path2D();
  9936. path2D.moveTo(...currentPath[0]);
  9937. }
  9938. this.#makeBezierCurve(path2D, ...currentPath.at(-3), ...currentPath.at(-2), x, y);
  9939. }
  9940. #endPath() {
  9941. if (this.currentPath.length === 0) {
  9942. return;
  9943. }
  9944. const lastPoint = this.currentPath.at(-1);
  9945. this.#currentPath2D.lineTo(...lastPoint);
  9946. }
  9947. #stopDrawing(x, y) {
  9948. this.#requestFrameCallback = null;
  9949. x = Math.min(Math.max(x, 0), this.canvas.width);
  9950. y = Math.min(Math.max(y, 0), this.canvas.height);
  9951. this.#draw(x, y);
  9952. this.#endPath();
  9953. let bezier;
  9954. if (this.currentPath.length !== 1) {
  9955. bezier = this.#generateBezierPoints();
  9956. } else {
  9957. const xy = [x, y];
  9958. bezier = [[xy, xy.slice(), xy.slice(), xy]];
  9959. }
  9960. const path2D = this.#currentPath2D;
  9961. const currentPath = this.currentPath;
  9962. this.currentPath = [];
  9963. this.#currentPath2D = new Path2D();
  9964. const cmd = () => {
  9965. this.allRawPaths.push(currentPath);
  9966. this.paths.push(bezier);
  9967. this.bezierPath2D.push(path2D);
  9968. this._uiManager.rebuild(this);
  9969. };
  9970. const undo = () => {
  9971. this.allRawPaths.pop();
  9972. this.paths.pop();
  9973. this.bezierPath2D.pop();
  9974. if (this.paths.length === 0) {
  9975. this.remove();
  9976. } else {
  9977. if (!this.canvas) {
  9978. this.#createCanvas();
  9979. this.#createObserver();
  9980. }
  9981. this.#fitToContent();
  9982. }
  9983. };
  9984. this.addCommands({
  9985. cmd,
  9986. undo,
  9987. mustExec: true
  9988. });
  9989. }
  9990. #drawPoints() {
  9991. if (!this.#hasSomethingToDraw) {
  9992. return;
  9993. }
  9994. this.#hasSomethingToDraw = false;
  9995. const thickness = Math.ceil(this.thickness * this.parentScale);
  9996. const lastPoints = this.currentPath.slice(-3);
  9997. const x = lastPoints.map(xy => xy[0]);
  9998. const y = lastPoints.map(xy => xy[1]);
  9999. const xMin = Math.min(...x) - thickness;
  10000. const xMax = Math.max(...x) + thickness;
  10001. const yMin = Math.min(...y) - thickness;
  10002. const yMax = Math.max(...y) + thickness;
  10003. const {
  10004. ctx
  10005. } = this;
  10006. ctx.save();
  10007. ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
  10008. for (const path of this.bezierPath2D) {
  10009. ctx.stroke(path);
  10010. }
  10011. ctx.stroke(this.#currentPath2D);
  10012. ctx.restore();
  10013. }
  10014. #makeBezierCurve(path2D, x0, y0, x1, y1, x2, y2) {
  10015. const prevX = (x0 + x1) / 2;
  10016. const prevY = (y0 + y1) / 2;
  10017. const x3 = (x1 + x2) / 2;
  10018. const y3 = (y1 + y2) / 2;
  10019. path2D.bezierCurveTo(prevX + 2 * (x1 - prevX) / 3, prevY + 2 * (y1 - prevY) / 3, x3 + 2 * (x1 - x3) / 3, y3 + 2 * (y1 - y3) / 3, x3, y3);
  10020. }
  10021. #generateBezierPoints() {
  10022. const path = this.currentPath;
  10023. if (path.length <= 2) {
  10024. return [[path[0], path[0], path.at(-1), path.at(-1)]];
  10025. }
  10026. const bezierPoints = [];
  10027. let i;
  10028. let [x0, y0] = path[0];
  10029. for (i = 1; i < path.length - 2; i++) {
  10030. const [x1, y1] = path[i];
  10031. const [x2, y2] = path[i + 1];
  10032. const x3 = (x1 + x2) / 2;
  10033. const y3 = (y1 + y2) / 2;
  10034. const control1 = [x0 + 2 * (x1 - x0) / 3, y0 + 2 * (y1 - y0) / 3];
  10035. const control2 = [x3 + 2 * (x1 - x3) / 3, y3 + 2 * (y1 - y3) / 3];
  10036. bezierPoints.push([[x0, y0], control1, control2, [x3, y3]]);
  10037. [x0, y0] = [x3, y3];
  10038. }
  10039. const [x1, y1] = path[i];
  10040. const [x2, y2] = path[i + 1];
  10041. const control1 = [x0 + 2 * (x1 - x0) / 3, y0 + 2 * (y1 - y0) / 3];
  10042. const control2 = [x2 + 2 * (x1 - x2) / 3, y2 + 2 * (y1 - y2) / 3];
  10043. bezierPoints.push([[x0, y0], control1, control2, [x2, y2]]);
  10044. return bezierPoints;
  10045. }
  10046. #redraw() {
  10047. if (this.isEmpty()) {
  10048. this.#updateTransform();
  10049. return;
  10050. }
  10051. this.#setStroke();
  10052. const {
  10053. canvas,
  10054. ctx
  10055. } = this;
  10056. ctx.setTransform(1, 0, 0, 1, 0, 0);
  10057. ctx.clearRect(0, 0, canvas.width, canvas.height);
  10058. this.#updateTransform();
  10059. for (const path of this.bezierPath2D) {
  10060. ctx.stroke(path);
  10061. }
  10062. }
  10063. commit() {
  10064. if (this.#disableEditing) {
  10065. return;
  10066. }
  10067. super.commit();
  10068. this.isEditing = false;
  10069. this.disableEditMode();
  10070. this.setInForeground();
  10071. this.#disableEditing = true;
  10072. this.div.classList.add("disabled");
  10073. this.#fitToContent(true);
  10074. this.select();
  10075. this.parent.addInkEditorIfNeeded(true);
  10076. this.moveInDOM();
  10077. this.div.focus({
  10078. preventScroll: true
  10079. });
  10080. }
  10081. focusin(event) {
  10082. if (!this._focusEventsAllowed) {
  10083. return;
  10084. }
  10085. super.focusin(event);
  10086. this.enableEditMode();
  10087. }
  10088. canvasPointerdown(event) {
  10089. if (event.button !== 0 || !this.isInEditMode() || this.#disableEditing) {
  10090. return;
  10091. }
  10092. this.setInForeground();
  10093. event.preventDefault();
  10094. if (!this.div.contains(document.activeElement)) {
  10095. this.div.focus({
  10096. preventScroll: true
  10097. });
  10098. }
  10099. this.#startDrawing(event.offsetX, event.offsetY);
  10100. }
  10101. canvasPointermove(event) {
  10102. event.preventDefault();
  10103. this.#draw(event.offsetX, event.offsetY);
  10104. }
  10105. canvasPointerup(event) {
  10106. event.preventDefault();
  10107. this.#endDrawing(event);
  10108. }
  10109. canvasPointerleave(event) {
  10110. this.#endDrawing(event);
  10111. }
  10112. #endDrawing(event) {
  10113. this.canvas.removeEventListener("pointerleave", this.#boundCanvasPointerleave);
  10114. this.canvas.removeEventListener("pointermove", this.#boundCanvasPointermove);
  10115. this.canvas.removeEventListener("pointerup", this.#boundCanvasPointerup);
  10116. this.canvas.addEventListener("pointerdown", this.#boundCanvasPointerdown);
  10117. if (this.#canvasContextMenuTimeoutId) {
  10118. clearTimeout(this.#canvasContextMenuTimeoutId);
  10119. }
  10120. this.#canvasContextMenuTimeoutId = setTimeout(() => {
  10121. this.#canvasContextMenuTimeoutId = null;
  10122. this.canvas.removeEventListener("contextmenu", display_utils.noContextMenu);
  10123. }, 10);
  10124. this.#stopDrawing(event.offsetX, event.offsetY);
  10125. this.addToAnnotationStorage();
  10126. this.setInBackground();
  10127. }
  10128. #createCanvas() {
  10129. this.canvas = document.createElement("canvas");
  10130. this.canvas.width = this.canvas.height = 0;
  10131. this.canvas.className = "inkEditorCanvas";
  10132. this.canvas.setAttribute("data-l10n-id", "pdfjs-ink-canvas");
  10133. this.div.append(this.canvas);
  10134. this.ctx = this.canvas.getContext("2d");
  10135. }
  10136. #createObserver() {
  10137. this.#observer = new ResizeObserver(entries => {
  10138. const rect = entries[0].contentRect;
  10139. if (rect.width && rect.height) {
  10140. this.setDimensions(rect.width, rect.height);
  10141. }
  10142. });
  10143. this.#observer.observe(this.div);
  10144. }
  10145. get isResizable() {
  10146. return !this.isEmpty() && this.#disableEditing;
  10147. }
  10148. render() {
  10149. if (this.div) {
  10150. return this.div;
  10151. }
  10152. let baseX, baseY;
  10153. if (this.width) {
  10154. baseX = this.x;
  10155. baseY = this.y;
  10156. }
  10157. super.render();
  10158. this.div.setAttribute("data-l10n-id", "pdfjs-ink");
  10159. const [x, y, w, h] = this.#getInitialBBox();
  10160. this.setAt(x, y, 0, 0);
  10161. this.setDims(w, h);
  10162. this.#createCanvas();
  10163. if (this.width) {
  10164. const [parentWidth, parentHeight] = this.parentDimensions;
  10165. this.setAspectRatio(this.width * parentWidth, this.height * parentHeight);
  10166. this.setAt(baseX * parentWidth, baseY * parentHeight, this.width * parentWidth, this.height * parentHeight);
  10167. this.#isCanvasInitialized = true;
  10168. this.#setCanvasDims();
  10169. this.setDims(this.width * parentWidth, this.height * parentHeight);
  10170. this.#redraw();
  10171. this.div.classList.add("disabled");
  10172. } else {
  10173. this.div.classList.add("editing");
  10174. this.enableEditMode();
  10175. }
  10176. this.#createObserver();
  10177. return this.div;
  10178. }
  10179. #setCanvasDims() {
  10180. if (!this.#isCanvasInitialized) {
  10181. return;
  10182. }
  10183. const [parentWidth, parentHeight] = this.parentDimensions;
  10184. this.canvas.width = Math.ceil(this.width * parentWidth);
  10185. this.canvas.height = Math.ceil(this.height * parentHeight);
  10186. this.#updateTransform();
  10187. }
  10188. setDimensions(width, height) {
  10189. const roundedWidth = Math.round(width);
  10190. const roundedHeight = Math.round(height);
  10191. if (this.#realWidth === roundedWidth && this.#realHeight === roundedHeight) {
  10192. return;
  10193. }
  10194. this.#realWidth = roundedWidth;
  10195. this.#realHeight = roundedHeight;
  10196. this.canvas.style.visibility = "hidden";
  10197. const [parentWidth, parentHeight] = this.parentDimensions;
  10198. this.width = width / parentWidth;
  10199. this.height = height / parentHeight;
  10200. this.fixAndSetPosition();
  10201. if (this.#disableEditing) {
  10202. this.#setScaleFactor(width, height);
  10203. }
  10204. this.#setCanvasDims();
  10205. this.#redraw();
  10206. this.canvas.style.visibility = "visible";
  10207. this.fixDims();
  10208. }
  10209. #setScaleFactor(width, height) {
  10210. const padding = this.#getPadding();
  10211. const scaleFactorW = (width - padding) / this.#baseWidth;
  10212. const scaleFactorH = (height - padding) / this.#baseHeight;
  10213. this.scaleFactor = Math.min(scaleFactorW, scaleFactorH);
  10214. }
  10215. #updateTransform() {
  10216. const padding = this.#getPadding() / 2;
  10217. this.ctx.setTransform(this.scaleFactor, 0, 0, this.scaleFactor, this.translationX * this.scaleFactor + padding, this.translationY * this.scaleFactor + padding);
  10218. }
  10219. static #buildPath2D(bezier) {
  10220. const path2D = new Path2D();
  10221. for (let i = 0, ii = bezier.length; i < ii; i++) {
  10222. const [first, control1, control2, second] = bezier[i];
  10223. if (i === 0) {
  10224. path2D.moveTo(...first);
  10225. }
  10226. path2D.bezierCurveTo(control1[0], control1[1], control2[0], control2[1], second[0], second[1]);
  10227. }
  10228. return path2D;
  10229. }
  10230. static #toPDFCoordinates(points, rect, rotation) {
  10231. const [blX, blY, trX, trY] = rect;
  10232. switch (rotation) {
  10233. case 0:
  10234. for (let i = 0, ii = points.length; i < ii; i += 2) {
  10235. points[i] += blX;
  10236. points[i + 1] = trY - points[i + 1];
  10237. }
  10238. break;
  10239. case 90:
  10240. for (let i = 0, ii = points.length; i < ii; i += 2) {
  10241. const x = points[i];
  10242. points[i] = points[i + 1] + blX;
  10243. points[i + 1] = x + blY;
  10244. }
  10245. break;
  10246. case 180:
  10247. for (let i = 0, ii = points.length; i < ii; i += 2) {
  10248. points[i] = trX - points[i];
  10249. points[i + 1] += blY;
  10250. }
  10251. break;
  10252. case 270:
  10253. for (let i = 0, ii = points.length; i < ii; i += 2) {
  10254. const x = points[i];
  10255. points[i] = trX - points[i + 1];
  10256. points[i + 1] = trY - x;
  10257. }
  10258. break;
  10259. default:
  10260. throw new Error("Invalid rotation");
  10261. }
  10262. return points;
  10263. }
  10264. static #fromPDFCoordinates(points, rect, rotation) {
  10265. const [blX, blY, trX, trY] = rect;
  10266. switch (rotation) {
  10267. case 0:
  10268. for (let i = 0, ii = points.length; i < ii; i += 2) {
  10269. points[i] -= blX;
  10270. points[i + 1] = trY - points[i + 1];
  10271. }
  10272. break;
  10273. case 90:
  10274. for (let i = 0, ii = points.length; i < ii; i += 2) {
  10275. const x = points[i];
  10276. points[i] = points[i + 1] - blY;
  10277. points[i + 1] = x - blX;
  10278. }
  10279. break;
  10280. case 180:
  10281. for (let i = 0, ii = points.length; i < ii; i += 2) {
  10282. points[i] = trX - points[i];
  10283. points[i + 1] -= blY;
  10284. }
  10285. break;
  10286. case 270:
  10287. for (let i = 0, ii = points.length; i < ii; i += 2) {
  10288. const x = points[i];
  10289. points[i] = trY - points[i + 1];
  10290. points[i + 1] = trX - x;
  10291. }
  10292. break;
  10293. default:
  10294. throw new Error("Invalid rotation");
  10295. }
  10296. return points;
  10297. }
  10298. #serializePaths(s, tx, ty, rect) {
  10299. const paths = [];
  10300. const padding = this.thickness / 2;
  10301. const shiftX = s * tx + padding;
  10302. const shiftY = s * ty + padding;
  10303. for (const bezier of this.paths) {
  10304. const buffer = [];
  10305. const points = [];
  10306. for (let j = 0, jj = bezier.length; j < jj; j++) {
  10307. const [first, control1, control2, second] = bezier[j];
  10308. if (first[0] === second[0] && first[1] === second[1] && jj === 1) {
  10309. const p0 = s * first[0] + shiftX;
  10310. const p1 = s * first[1] + shiftY;
  10311. buffer.push(p0, p1);
  10312. points.push(p0, p1);
  10313. break;
  10314. }
  10315. const p10 = s * first[0] + shiftX;
  10316. const p11 = s * first[1] + shiftY;
  10317. const p20 = s * control1[0] + shiftX;
  10318. const p21 = s * control1[1] + shiftY;
  10319. const p30 = s * control2[0] + shiftX;
  10320. const p31 = s * control2[1] + shiftY;
  10321. const p40 = s * second[0] + shiftX;
  10322. const p41 = s * second[1] + shiftY;
  10323. if (j === 0) {
  10324. buffer.push(p10, p11);
  10325. points.push(p10, p11);
  10326. }
  10327. buffer.push(p20, p21, p30, p31, p40, p41);
  10328. points.push(p20, p21);
  10329. if (j === jj - 1) {
  10330. points.push(p40, p41);
  10331. }
  10332. }
  10333. paths.push({
  10334. bezier: InkEditor.#toPDFCoordinates(buffer, rect, this.rotation),
  10335. points: InkEditor.#toPDFCoordinates(points, rect, this.rotation)
  10336. });
  10337. }
  10338. return paths;
  10339. }
  10340. #getBbox() {
  10341. let xMin = Infinity;
  10342. let xMax = -Infinity;
  10343. let yMin = Infinity;
  10344. let yMax = -Infinity;
  10345. for (const path of this.paths) {
  10346. for (const [first, control1, control2, second] of path) {
  10347. const bbox = util.Util.bezierBoundingBox(...first, ...control1, ...control2, ...second);
  10348. xMin = Math.min(xMin, bbox[0]);
  10349. yMin = Math.min(yMin, bbox[1]);
  10350. xMax = Math.max(xMax, bbox[2]);
  10351. yMax = Math.max(yMax, bbox[3]);
  10352. }
  10353. }
  10354. return [xMin, yMin, xMax, yMax];
  10355. }
  10356. #getPadding() {
  10357. return this.#disableEditing ? Math.ceil(this.thickness * this.parentScale) : 0;
  10358. }
  10359. #fitToContent(firstTime = false) {
  10360. if (this.isEmpty()) {
  10361. return;
  10362. }
  10363. if (!this.#disableEditing) {
  10364. this.#redraw();
  10365. return;
  10366. }
  10367. const bbox = this.#getBbox();
  10368. const padding = this.#getPadding();
  10369. this.#baseWidth = Math.max(editor_editor.AnnotationEditor.MIN_SIZE, bbox[2] - bbox[0]);
  10370. this.#baseHeight = Math.max(editor_editor.AnnotationEditor.MIN_SIZE, bbox[3] - bbox[1]);
  10371. const width = Math.ceil(padding + this.#baseWidth * this.scaleFactor);
  10372. const height = Math.ceil(padding + this.#baseHeight * this.scaleFactor);
  10373. const [parentWidth, parentHeight] = this.parentDimensions;
  10374. this.width = width / parentWidth;
  10375. this.height = height / parentHeight;
  10376. this.setAspectRatio(width, height);
  10377. const prevTranslationX = this.translationX;
  10378. const prevTranslationY = this.translationY;
  10379. this.translationX = -bbox[0];
  10380. this.translationY = -bbox[1];
  10381. this.#setCanvasDims();
  10382. this.#redraw();
  10383. this.#realWidth = width;
  10384. this.#realHeight = height;
  10385. this.setDims(width, height);
  10386. const unscaledPadding = firstTime ? padding / this.scaleFactor / 2 : 0;
  10387. this.translate(prevTranslationX - this.translationX - unscaledPadding, prevTranslationY - this.translationY - unscaledPadding);
  10388. }
  10389. static deserialize(data, parent, uiManager) {
  10390. if (data instanceof annotation_layer.InkAnnotationElement) {
  10391. return null;
  10392. }
  10393. const editor = super.deserialize(data, parent, uiManager);
  10394. editor.thickness = data.thickness;
  10395. editor.color = util.Util.makeHexColor(...data.color);
  10396. editor.opacity = data.opacity;
  10397. const [pageWidth, pageHeight] = editor.pageDimensions;
  10398. const width = editor.width * pageWidth;
  10399. const height = editor.height * pageHeight;
  10400. const scaleFactor = editor.parentScale;
  10401. const padding = data.thickness / 2;
  10402. editor.#disableEditing = true;
  10403. editor.#realWidth = Math.round(width);
  10404. editor.#realHeight = Math.round(height);
  10405. const {
  10406. paths,
  10407. rect,
  10408. rotation
  10409. } = data;
  10410. for (let {
  10411. bezier
  10412. } of paths) {
  10413. bezier = InkEditor.#fromPDFCoordinates(bezier, rect, rotation);
  10414. const path = [];
  10415. editor.paths.push(path);
  10416. let p0 = scaleFactor * (bezier[0] - padding);
  10417. let p1 = scaleFactor * (bezier[1] - padding);
  10418. for (let i = 2, ii = bezier.length; i < ii; i += 6) {
  10419. const p10 = scaleFactor * (bezier[i] - padding);
  10420. const p11 = scaleFactor * (bezier[i + 1] - padding);
  10421. const p20 = scaleFactor * (bezier[i + 2] - padding);
  10422. const p21 = scaleFactor * (bezier[i + 3] - padding);
  10423. const p30 = scaleFactor * (bezier[i + 4] - padding);
  10424. const p31 = scaleFactor * (bezier[i + 5] - padding);
  10425. path.push([[p0, p1], [p10, p11], [p20, p21], [p30, p31]]);
  10426. p0 = p30;
  10427. p1 = p31;
  10428. }
  10429. const path2D = this.#buildPath2D(path);
  10430. editor.bezierPath2D.push(path2D);
  10431. }
  10432. const bbox = editor.#getBbox();
  10433. editor.#baseWidth = Math.max(editor_editor.AnnotationEditor.MIN_SIZE, bbox[2] - bbox[0]);
  10434. editor.#baseHeight = Math.max(editor_editor.AnnotationEditor.MIN_SIZE, bbox[3] - bbox[1]);
  10435. editor.#setScaleFactor(width, height);
  10436. return editor;
  10437. }
  10438. serialize() {
  10439. if (this.isEmpty()) {
  10440. return null;
  10441. }
  10442. const rect = this.getRect(0, 0);
  10443. const color = editor_editor.AnnotationEditor._colorManager.convert(this.ctx.strokeStyle);
  10444. return {
  10445. annotationType: util.AnnotationEditorType.INK,
  10446. color,
  10447. thickness: this.thickness,
  10448. opacity: this.opacity,
  10449. paths: this.#serializePaths(this.scaleFactor / this.parentScale, this.translationX, this.translationY, rect),
  10450. pageIndex: this.pageIndex,
  10451. rect,
  10452. rotation: this.rotation,
  10453. structTreeParentId: this._structTreeParentId
  10454. };
  10455. }
  10456. }
  10457. ;// CONCATENATED MODULE: ./src/display/editor/stamp.js
  10458. class StampEditor extends editor_editor.AnnotationEditor {
  10459. #bitmap = null;
  10460. #bitmapId = null;
  10461. #bitmapPromise = null;
  10462. #bitmapUrl = null;
  10463. #bitmapFile = null;
  10464. #bitmapFileName = "";
  10465. #canvas = null;
  10466. #observer = null;
  10467. #resizeTimeoutId = null;
  10468. #isSvg = false;
  10469. #hasBeenAddedInUndoStack = false;
  10470. static _type = "stamp";
  10471. static _editorType = util.AnnotationEditorType.STAMP;
  10472. constructor(params) {
  10473. super({
  10474. ...params,
  10475. name: "stampEditor"
  10476. });
  10477. this.#bitmapUrl = params.bitmapUrl;
  10478. this.#bitmapFile = params.bitmapFile;
  10479. }
  10480. static initialize(l10n, uiManager) {
  10481. editor_editor.AnnotationEditor.initialize(l10n, uiManager);
  10482. }
  10483. static get supportedTypes() {
  10484. const types = ["apng", "avif", "bmp", "gif", "jpeg", "png", "svg+xml", "webp", "x-icon"];
  10485. return (0,util.shadow)(this, "supportedTypes", types.map(type => `image/${type}`));
  10486. }
  10487. static get supportedTypesStr() {
  10488. return (0,util.shadow)(this, "supportedTypesStr", this.supportedTypes.join(","));
  10489. }
  10490. static isHandlingMimeForPasting(mime) {
  10491. return this.supportedTypes.includes(mime);
  10492. }
  10493. static paste(item, parent) {
  10494. parent.pasteEditor(util.AnnotationEditorType.STAMP, {
  10495. bitmapFile: item.getAsFile()
  10496. });
  10497. }
  10498. #getBitmapFetched(data, fromId = false) {
  10499. if (!data) {
  10500. this.remove();
  10501. return;
  10502. }
  10503. this.#bitmap = data.bitmap;
  10504. if (!fromId) {
  10505. this.#bitmapId = data.id;
  10506. this.#isSvg = data.isSvg;
  10507. }
  10508. if (data.file) {
  10509. this.#bitmapFileName = data.file.name;
  10510. }
  10511. this.#createCanvas();
  10512. }
  10513. #getBitmapDone() {
  10514. this.#bitmapPromise = null;
  10515. this._uiManager.enableWaiting(false);
  10516. if (this.#canvas) {
  10517. this.div.focus();
  10518. }
  10519. }
  10520. #getBitmap() {
  10521. if (this.#bitmapId) {
  10522. this._uiManager.enableWaiting(true);
  10523. this._uiManager.imageManager.getFromId(this.#bitmapId).then(data => this.#getBitmapFetched(data, true)).finally(() => this.#getBitmapDone());
  10524. return;
  10525. }
  10526. if (this.#bitmapUrl) {
  10527. const url = this.#bitmapUrl;
  10528. this.#bitmapUrl = null;
  10529. this._uiManager.enableWaiting(true);
  10530. this.#bitmapPromise = this._uiManager.imageManager.getFromUrl(url).then(data => this.#getBitmapFetched(data)).finally(() => this.#getBitmapDone());
  10531. return;
  10532. }
  10533. if (this.#bitmapFile) {
  10534. const file = this.#bitmapFile;
  10535. this.#bitmapFile = null;
  10536. this._uiManager.enableWaiting(true);
  10537. this.#bitmapPromise = this._uiManager.imageManager.getFromFile(file).then(data => this.#getBitmapFetched(data)).finally(() => this.#getBitmapDone());
  10538. return;
  10539. }
  10540. const input = document.createElement("input");
  10541. input.type = "file";
  10542. input.accept = StampEditor.supportedTypesStr;
  10543. this.#bitmapPromise = new Promise(resolve => {
  10544. input.addEventListener("change", async () => {
  10545. if (!input.files || input.files.length === 0) {
  10546. this.remove();
  10547. } else {
  10548. this._uiManager.enableWaiting(true);
  10549. const data = await this._uiManager.imageManager.getFromFile(input.files[0]);
  10550. this.#getBitmapFetched(data);
  10551. }
  10552. resolve();
  10553. });
  10554. input.addEventListener("cancel", () => {
  10555. this.remove();
  10556. resolve();
  10557. });
  10558. }).finally(() => this.#getBitmapDone());
  10559. input.click();
  10560. }
  10561. remove() {
  10562. if (this.#bitmapId) {
  10563. this.#bitmap = null;
  10564. this._uiManager.imageManager.deleteId(this.#bitmapId);
  10565. this.#canvas?.remove();
  10566. this.#canvas = null;
  10567. this.#observer?.disconnect();
  10568. this.#observer = null;
  10569. if (this.#resizeTimeoutId) {
  10570. clearTimeout(this.#resizeTimeoutId);
  10571. this.#resizeTimeoutId = null;
  10572. }
  10573. }
  10574. super.remove();
  10575. }
  10576. rebuild() {
  10577. if (!this.parent) {
  10578. if (this.#bitmapId) {
  10579. this.#getBitmap();
  10580. }
  10581. return;
  10582. }
  10583. super.rebuild();
  10584. if (this.div === null) {
  10585. return;
  10586. }
  10587. if (this.#bitmapId && this.#canvas === null) {
  10588. this.#getBitmap();
  10589. }
  10590. if (!this.isAttachedToDOM) {
  10591. this.parent.add(this);
  10592. }
  10593. }
  10594. onceAdded() {
  10595. this._isDraggable = true;
  10596. this.div.focus();
  10597. }
  10598. isEmpty() {
  10599. return !(this.#bitmapPromise || this.#bitmap || this.#bitmapUrl || this.#bitmapFile || this.#bitmapId);
  10600. }
  10601. get isResizable() {
  10602. return true;
  10603. }
  10604. render() {
  10605. if (this.div) {
  10606. return this.div;
  10607. }
  10608. let baseX, baseY;
  10609. if (this.width) {
  10610. baseX = this.x;
  10611. baseY = this.y;
  10612. }
  10613. super.render();
  10614. this.div.hidden = true;
  10615. this.addAltTextButton();
  10616. if (this.#bitmap) {
  10617. this.#createCanvas();
  10618. } else {
  10619. this.#getBitmap();
  10620. }
  10621. if (this.width) {
  10622. const [parentWidth, parentHeight] = this.parentDimensions;
  10623. this.setAt(baseX * parentWidth, baseY * parentHeight, this.width * parentWidth, this.height * parentHeight);
  10624. }
  10625. return this.div;
  10626. }
  10627. #createCanvas() {
  10628. const {
  10629. div
  10630. } = this;
  10631. let {
  10632. width,
  10633. height
  10634. } = this.#bitmap;
  10635. const [pageWidth, pageHeight] = this.pageDimensions;
  10636. const MAX_RATIO = 0.75;
  10637. if (this.width) {
  10638. width = this.width * pageWidth;
  10639. height = this.height * pageHeight;
  10640. } else if (width > MAX_RATIO * pageWidth || height > MAX_RATIO * pageHeight) {
  10641. const factor = Math.min(MAX_RATIO * pageWidth / width, MAX_RATIO * pageHeight / height);
  10642. width *= factor;
  10643. height *= factor;
  10644. }
  10645. const [parentWidth, parentHeight] = this.parentDimensions;
  10646. this.setDims(width * parentWidth / pageWidth, height * parentHeight / pageHeight);
  10647. this._uiManager.enableWaiting(false);
  10648. const canvas = this.#canvas = document.createElement("canvas");
  10649. div.append(canvas);
  10650. div.hidden = false;
  10651. this.#drawBitmap(width, height);
  10652. this.#createObserver();
  10653. if (!this.#hasBeenAddedInUndoStack) {
  10654. this.parent.addUndoableEditor(this);
  10655. this.#hasBeenAddedInUndoStack = true;
  10656. }
  10657. this._reportTelemetry({
  10658. action: "inserted_image"
  10659. });
  10660. if (this.#bitmapFileName) {
  10661. canvas.setAttribute("aria-label", this.#bitmapFileName);
  10662. }
  10663. }
  10664. #setDimensions(width, height) {
  10665. const [parentWidth, parentHeight] = this.parentDimensions;
  10666. this.width = width / parentWidth;
  10667. this.height = height / parentHeight;
  10668. this.setDims(width, height);
  10669. if (this._initialOptions?.isCentered) {
  10670. this.center();
  10671. } else {
  10672. this.fixAndSetPosition();
  10673. }
  10674. this._initialOptions = null;
  10675. if (this.#resizeTimeoutId !== null) {
  10676. clearTimeout(this.#resizeTimeoutId);
  10677. }
  10678. const TIME_TO_WAIT = 200;
  10679. this.#resizeTimeoutId = setTimeout(() => {
  10680. this.#resizeTimeoutId = null;
  10681. this.#drawBitmap(width, height);
  10682. }, TIME_TO_WAIT);
  10683. }
  10684. #scaleBitmap(width, height) {
  10685. const {
  10686. width: bitmapWidth,
  10687. height: bitmapHeight
  10688. } = this.#bitmap;
  10689. let newWidth = bitmapWidth;
  10690. let newHeight = bitmapHeight;
  10691. let bitmap = this.#bitmap;
  10692. while (newWidth > 2 * width || newHeight > 2 * height) {
  10693. const prevWidth = newWidth;
  10694. const prevHeight = newHeight;
  10695. if (newWidth > 2 * width) {
  10696. newWidth = newWidth >= 16384 ? Math.floor(newWidth / 2) - 1 : Math.ceil(newWidth / 2);
  10697. }
  10698. if (newHeight > 2 * height) {
  10699. newHeight = newHeight >= 16384 ? Math.floor(newHeight / 2) - 1 : Math.ceil(newHeight / 2);
  10700. }
  10701. const offscreen = new OffscreenCanvas(newWidth, newHeight);
  10702. const ctx = offscreen.getContext("2d");
  10703. ctx.drawImage(bitmap, 0, 0, prevWidth, prevHeight, 0, 0, newWidth, newHeight);
  10704. bitmap = offscreen.transferToImageBitmap();
  10705. }
  10706. return bitmap;
  10707. }
  10708. #drawBitmap(width, height) {
  10709. width = Math.ceil(width);
  10710. height = Math.ceil(height);
  10711. const canvas = this.#canvas;
  10712. if (!canvas || canvas.width === width && canvas.height === height) {
  10713. return;
  10714. }
  10715. canvas.width = width;
  10716. canvas.height = height;
  10717. const bitmap = this.#isSvg ? this.#bitmap : this.#scaleBitmap(width, height);
  10718. if (this._uiManager.hasMLManager && !this.hasAltText()) {
  10719. const offscreen = new OffscreenCanvas(width, height);
  10720. const ctx = offscreen.getContext("2d");
  10721. ctx.drawImage(bitmap, 0, 0, bitmap.width, bitmap.height, 0, 0, width, height);
  10722. offscreen.convertToBlob().then(blob => {
  10723. const fileReader = new FileReader();
  10724. fileReader.onload = () => {
  10725. const url = fileReader.result;
  10726. this._uiManager.mlGuess({
  10727. service: "image-to-text",
  10728. request: {
  10729. imageData: url
  10730. }
  10731. }).then(response => {
  10732. const altText = response?.output || "";
  10733. if (this.parent && altText && !this.hasAltText()) {
  10734. this.altTextData = {
  10735. altText,
  10736. decorative: false
  10737. };
  10738. }
  10739. });
  10740. };
  10741. fileReader.readAsDataURL(blob);
  10742. });
  10743. }
  10744. const ctx = canvas.getContext("2d");
  10745. ctx.filter = this._uiManager.hcmFilter;
  10746. ctx.drawImage(bitmap, 0, 0, bitmap.width, bitmap.height, 0, 0, width, height);
  10747. }
  10748. getImageForAltText() {
  10749. return this.#canvas;
  10750. }
  10751. #serializeBitmap(toUrl) {
  10752. if (toUrl) {
  10753. if (this.#isSvg) {
  10754. const url = this._uiManager.imageManager.getSvgUrl(this.#bitmapId);
  10755. if (url) {
  10756. return url;
  10757. }
  10758. }
  10759. const canvas = document.createElement("canvas");
  10760. ({
  10761. width: canvas.width,
  10762. height: canvas.height
  10763. } = this.#bitmap);
  10764. const ctx = canvas.getContext("2d");
  10765. ctx.drawImage(this.#bitmap, 0, 0);
  10766. return canvas.toDataURL();
  10767. }
  10768. if (this.#isSvg) {
  10769. const [pageWidth, pageHeight] = this.pageDimensions;
  10770. const width = Math.round(this.width * pageWidth * display_utils.PixelsPerInch.PDF_TO_CSS_UNITS);
  10771. const height = Math.round(this.height * pageHeight * display_utils.PixelsPerInch.PDF_TO_CSS_UNITS);
  10772. const offscreen = new OffscreenCanvas(width, height);
  10773. const ctx = offscreen.getContext("2d");
  10774. ctx.drawImage(this.#bitmap, 0, 0, this.#bitmap.width, this.#bitmap.height, 0, 0, width, height);
  10775. return offscreen.transferToImageBitmap();
  10776. }
  10777. return structuredClone(this.#bitmap);
  10778. }
  10779. #createObserver() {
  10780. this.#observer = new ResizeObserver(entries => {
  10781. const rect = entries[0].contentRect;
  10782. if (rect.width && rect.height) {
  10783. this.#setDimensions(rect.width, rect.height);
  10784. }
  10785. });
  10786. this.#observer.observe(this.div);
  10787. }
  10788. static deserialize(data, parent, uiManager) {
  10789. if (data instanceof annotation_layer.StampAnnotationElement) {
  10790. return null;
  10791. }
  10792. const editor = super.deserialize(data, parent, uiManager);
  10793. const {
  10794. rect,
  10795. bitmapUrl,
  10796. bitmapId,
  10797. isSvg,
  10798. accessibilityData
  10799. } = data;
  10800. if (bitmapId && uiManager.imageManager.isValidId(bitmapId)) {
  10801. editor.#bitmapId = bitmapId;
  10802. } else {
  10803. editor.#bitmapUrl = bitmapUrl;
  10804. }
  10805. editor.#isSvg = isSvg;
  10806. const [parentWidth, parentHeight] = editor.pageDimensions;
  10807. editor.width = (rect[2] - rect[0]) / parentWidth;
  10808. editor.height = (rect[3] - rect[1]) / parentHeight;
  10809. if (accessibilityData) {
  10810. editor.altTextData = accessibilityData;
  10811. }
  10812. return editor;
  10813. }
  10814. serialize(isForCopying = false, context = null) {
  10815. if (this.isEmpty()) {
  10816. return null;
  10817. }
  10818. const serialized = {
  10819. annotationType: util.AnnotationEditorType.STAMP,
  10820. bitmapId: this.#bitmapId,
  10821. pageIndex: this.pageIndex,
  10822. rect: this.getRect(0, 0),
  10823. rotation: this.rotation,
  10824. isSvg: this.#isSvg,
  10825. structTreeParentId: this._structTreeParentId
  10826. };
  10827. if (isForCopying) {
  10828. serialized.bitmapUrl = this.#serializeBitmap(true);
  10829. serialized.accessibilityData = this.altTextData;
  10830. return serialized;
  10831. }
  10832. const {
  10833. decorative,
  10834. altText
  10835. } = this.altTextData;
  10836. if (!decorative && altText) {
  10837. serialized.accessibilityData = {
  10838. type: "Figure",
  10839. alt: altText
  10840. };
  10841. }
  10842. if (context === null) {
  10843. return serialized;
  10844. }
  10845. context.stamps ||= new Map();
  10846. const area = this.#isSvg ? (serialized.rect[2] - serialized.rect[0]) * (serialized.rect[3] - serialized.rect[1]) : null;
  10847. if (!context.stamps.has(this.#bitmapId)) {
  10848. context.stamps.set(this.#bitmapId, {
  10849. area,
  10850. serialized
  10851. });
  10852. serialized.bitmap = this.#serializeBitmap(false);
  10853. } else if (this.#isSvg) {
  10854. const prevData = context.stamps.get(this.#bitmapId);
  10855. if (area > prevData.area) {
  10856. prevData.area = area;
  10857. prevData.serialized.bitmap.close();
  10858. prevData.serialized.bitmap = this.#serializeBitmap(false);
  10859. }
  10860. }
  10861. return serialized;
  10862. }
  10863. }
  10864. ;// CONCATENATED MODULE: ./src/display/editor/annotation_editor_layer.js
  10865. class AnnotationEditorLayer {
  10866. #accessibilityManager;
  10867. #allowClick = false;
  10868. #annotationLayer = null;
  10869. #boundPointerup = null;
  10870. #boundPointerdown = null;
  10871. #boundTextLayerPointerDown = null;
  10872. #editorFocusTimeoutId = null;
  10873. #editors = new Map();
  10874. #hadPointerDown = false;
  10875. #isCleaningUp = false;
  10876. #isDisabling = false;
  10877. #textLayer = null;
  10878. #uiManager;
  10879. static _initialized = false;
  10880. static #editorTypes = new Map([FreeTextEditor, InkEditor, StampEditor, HighlightEditor].map(type => [type._editorType, type]));
  10881. constructor({
  10882. uiManager,
  10883. pageIndex,
  10884. div,
  10885. accessibilityManager,
  10886. annotationLayer,
  10887. drawLayer,
  10888. textLayer,
  10889. viewport,
  10890. l10n
  10891. }) {
  10892. const editorTypes = [...AnnotationEditorLayer.#editorTypes.values()];
  10893. if (!AnnotationEditorLayer._initialized) {
  10894. AnnotationEditorLayer._initialized = true;
  10895. for (const editorType of editorTypes) {
  10896. editorType.initialize(l10n, uiManager);
  10897. }
  10898. }
  10899. uiManager.registerEditorTypes(editorTypes);
  10900. this.#uiManager = uiManager;
  10901. this.pageIndex = pageIndex;
  10902. this.div = div;
  10903. this.#accessibilityManager = accessibilityManager;
  10904. this.#annotationLayer = annotationLayer;
  10905. this.viewport = viewport;
  10906. this.#textLayer = textLayer;
  10907. this.drawLayer = drawLayer;
  10908. this.#uiManager.addLayer(this);
  10909. }
  10910. get isEmpty() {
  10911. return this.#editors.size === 0;
  10912. }
  10913. get isInvisible() {
  10914. return this.isEmpty && this.#uiManager.getMode() === util.AnnotationEditorType.NONE;
  10915. }
  10916. updateToolbar(mode) {
  10917. this.#uiManager.updateToolbar(mode);
  10918. }
  10919. updateMode(mode = this.#uiManager.getMode()) {
  10920. this.#cleanup();
  10921. switch (mode) {
  10922. case util.AnnotationEditorType.NONE:
  10923. this.disableTextSelection();
  10924. this.togglePointerEvents(false);
  10925. this.toggleAnnotationLayerPointerEvents(true);
  10926. this.disableClick();
  10927. return;
  10928. case util.AnnotationEditorType.INK:
  10929. this.addInkEditorIfNeeded(false);
  10930. this.disableTextSelection();
  10931. this.togglePointerEvents(true);
  10932. this.disableClick();
  10933. break;
  10934. case util.AnnotationEditorType.HIGHLIGHT:
  10935. this.enableTextSelection();
  10936. this.togglePointerEvents(false);
  10937. this.disableClick();
  10938. break;
  10939. default:
  10940. this.disableTextSelection();
  10941. this.togglePointerEvents(true);
  10942. this.enableClick();
  10943. }
  10944. this.toggleAnnotationLayerPointerEvents(false);
  10945. const {
  10946. classList
  10947. } = this.div;
  10948. for (const editorType of AnnotationEditorLayer.#editorTypes.values()) {
  10949. classList.toggle(`${editorType._type}Editing`, mode === editorType._editorType);
  10950. }
  10951. this.div.hidden = false;
  10952. }
  10953. hasTextLayer(textLayer) {
  10954. return textLayer === this.#textLayer?.div;
  10955. }
  10956. addInkEditorIfNeeded(isCommitting) {
  10957. if (this.#uiManager.getMode() !== util.AnnotationEditorType.INK) {
  10958. return;
  10959. }
  10960. if (!isCommitting) {
  10961. for (const editor of this.#editors.values()) {
  10962. if (editor.isEmpty()) {
  10963. editor.setInBackground();
  10964. return;
  10965. }
  10966. }
  10967. }
  10968. const editor = this.createAndAddNewEditor({
  10969. offsetX: 0,
  10970. offsetY: 0
  10971. }, false);
  10972. editor.setInBackground();
  10973. }
  10974. setEditingState(isEditing) {
  10975. this.#uiManager.setEditingState(isEditing);
  10976. }
  10977. addCommands(params) {
  10978. this.#uiManager.addCommands(params);
  10979. }
  10980. togglePointerEvents(enabled = false) {
  10981. this.div.classList.toggle("disabled", !enabled);
  10982. }
  10983. toggleAnnotationLayerPointerEvents(enabled = false) {
  10984. this.#annotationLayer?.div.classList.toggle("disabled", !enabled);
  10985. }
  10986. enable() {
  10987. this.div.tabIndex = 0;
  10988. this.togglePointerEvents(true);
  10989. const annotationElementIds = new Set();
  10990. for (const editor of this.#editors.values()) {
  10991. editor.enableEditing();
  10992. editor.show(true);
  10993. if (editor.annotationElementId) {
  10994. this.#uiManager.removeChangedExistingAnnotation(editor);
  10995. annotationElementIds.add(editor.annotationElementId);
  10996. }
  10997. }
  10998. if (!this.#annotationLayer) {
  10999. return;
  11000. }
  11001. const editables = this.#annotationLayer.getEditableAnnotations();
  11002. for (const editable of editables) {
  11003. editable.hide();
  11004. if (this.#uiManager.isDeletedAnnotationElement(editable.data.id)) {
  11005. continue;
  11006. }
  11007. if (annotationElementIds.has(editable.data.id)) {
  11008. continue;
  11009. }
  11010. const editor = this.deserialize(editable);
  11011. if (!editor) {
  11012. continue;
  11013. }
  11014. this.addOrRebuild(editor);
  11015. editor.enableEditing();
  11016. }
  11017. }
  11018. disable() {
  11019. this.#isDisabling = true;
  11020. this.div.tabIndex = -1;
  11021. this.togglePointerEvents(false);
  11022. const changedAnnotations = new Map();
  11023. const resetAnnotations = new Map();
  11024. for (const editor of this.#editors.values()) {
  11025. editor.disableEditing();
  11026. if (!editor.annotationElementId) {
  11027. continue;
  11028. }
  11029. if (editor.serialize() !== null) {
  11030. changedAnnotations.set(editor.annotationElementId, editor);
  11031. continue;
  11032. } else {
  11033. resetAnnotations.set(editor.annotationElementId, editor);
  11034. }
  11035. this.getEditableAnnotation(editor.annotationElementId)?.show();
  11036. editor.remove();
  11037. }
  11038. if (this.#annotationLayer) {
  11039. const editables = this.#annotationLayer.getEditableAnnotations();
  11040. for (const editable of editables) {
  11041. const {
  11042. id
  11043. } = editable.data;
  11044. if (this.#uiManager.isDeletedAnnotationElement(id)) {
  11045. continue;
  11046. }
  11047. let editor = resetAnnotations.get(id);
  11048. if (editor) {
  11049. editor.resetAnnotationElement(editable);
  11050. editor.show(false);
  11051. editable.show();
  11052. continue;
  11053. }
  11054. editor = changedAnnotations.get(id);
  11055. if (editor) {
  11056. this.#uiManager.addChangedExistingAnnotation(editor);
  11057. editor.renderAnnotationElement(editable);
  11058. editor.show(false);
  11059. }
  11060. editable.show();
  11061. }
  11062. }
  11063. this.#cleanup();
  11064. if (this.isEmpty) {
  11065. this.div.hidden = true;
  11066. }
  11067. const {
  11068. classList
  11069. } = this.div;
  11070. for (const editorType of AnnotationEditorLayer.#editorTypes.values()) {
  11071. classList.remove(`${editorType._type}Editing`);
  11072. }
  11073. this.disableTextSelection();
  11074. this.toggleAnnotationLayerPointerEvents(true);
  11075. this.#isDisabling = false;
  11076. }
  11077. getEditableAnnotation(id) {
  11078. return this.#annotationLayer?.getEditableAnnotation(id) || null;
  11079. }
  11080. setActiveEditor(editor) {
  11081. const currentActive = this.#uiManager.getActive();
  11082. if (currentActive === editor) {
  11083. return;
  11084. }
  11085. this.#uiManager.setActiveEditor(editor);
  11086. }
  11087. enableTextSelection() {
  11088. this.div.tabIndex = -1;
  11089. if (this.#textLayer?.div && !this.#boundTextLayerPointerDown) {
  11090. this.#boundTextLayerPointerDown = this.#textLayerPointerDown.bind(this);
  11091. this.#textLayer.div.addEventListener("pointerdown", this.#boundTextLayerPointerDown);
  11092. this.#textLayer.div.classList.add("highlighting");
  11093. }
  11094. }
  11095. disableTextSelection() {
  11096. this.div.tabIndex = 0;
  11097. if (this.#textLayer?.div && this.#boundTextLayerPointerDown) {
  11098. this.#textLayer.div.removeEventListener("pointerdown", this.#boundTextLayerPointerDown);
  11099. this.#boundTextLayerPointerDown = null;
  11100. this.#textLayer.div.classList.remove("highlighting");
  11101. }
  11102. }
  11103. #textLayerPointerDown(event) {
  11104. this.#uiManager.unselectAll();
  11105. if (event.target === this.#textLayer.div) {
  11106. const {
  11107. isMac
  11108. } = util.FeatureTest.platform;
  11109. if (event.button !== 0 || event.ctrlKey && isMac) {
  11110. return;
  11111. }
  11112. this.#uiManager.showAllEditors("highlight", true, true);
  11113. this.#textLayer.div.classList.add("free");
  11114. HighlightEditor.startHighlighting(this, this.#uiManager.direction === "ltr", event);
  11115. this.#textLayer.div.addEventListener("pointerup", () => {
  11116. this.#textLayer.div.classList.remove("free");
  11117. }, {
  11118. once: true
  11119. });
  11120. event.preventDefault();
  11121. }
  11122. }
  11123. enableClick() {
  11124. if (this.#boundPointerdown) {
  11125. return;
  11126. }
  11127. this.#boundPointerdown = this.pointerdown.bind(this);
  11128. this.#boundPointerup = this.pointerup.bind(this);
  11129. this.div.addEventListener("pointerdown", this.#boundPointerdown);
  11130. this.div.addEventListener("pointerup", this.#boundPointerup);
  11131. }
  11132. disableClick() {
  11133. if (!this.#boundPointerdown) {
  11134. return;
  11135. }
  11136. this.div.removeEventListener("pointerdown", this.#boundPointerdown);
  11137. this.div.removeEventListener("pointerup", this.#boundPointerup);
  11138. this.#boundPointerdown = null;
  11139. this.#boundPointerup = null;
  11140. }
  11141. attach(editor) {
  11142. this.#editors.set(editor.id, editor);
  11143. const {
  11144. annotationElementId
  11145. } = editor;
  11146. if (annotationElementId && this.#uiManager.isDeletedAnnotationElement(annotationElementId)) {
  11147. this.#uiManager.removeDeletedAnnotationElement(editor);
  11148. }
  11149. }
  11150. detach(editor) {
  11151. this.#editors.delete(editor.id);
  11152. this.#accessibilityManager?.removePointerInTextLayer(editor.contentDiv);
  11153. if (!this.#isDisabling && editor.annotationElementId) {
  11154. this.#uiManager.addDeletedAnnotationElement(editor);
  11155. }
  11156. }
  11157. remove(editor) {
  11158. this.detach(editor);
  11159. this.#uiManager.removeEditor(editor);
  11160. editor.div.remove();
  11161. editor.isAttachedToDOM = false;
  11162. if (!this.#isCleaningUp) {
  11163. this.addInkEditorIfNeeded(false);
  11164. }
  11165. }
  11166. changeParent(editor) {
  11167. if (editor.parent === this) {
  11168. return;
  11169. }
  11170. if (editor.parent && editor.annotationElementId) {
  11171. this.#uiManager.addDeletedAnnotationElement(editor.annotationElementId);
  11172. editor_editor.AnnotationEditor.deleteAnnotationElement(editor);
  11173. editor.annotationElementId = null;
  11174. }
  11175. this.attach(editor);
  11176. editor.parent?.detach(editor);
  11177. editor.setParent(this);
  11178. if (editor.div && editor.isAttachedToDOM) {
  11179. editor.div.remove();
  11180. this.div.append(editor.div);
  11181. }
  11182. }
  11183. add(editor) {
  11184. if (editor.parent === this && editor.isAttachedToDOM) {
  11185. return;
  11186. }
  11187. this.changeParent(editor);
  11188. this.#uiManager.addEditor(editor);
  11189. this.attach(editor);
  11190. if (!editor.isAttachedToDOM) {
  11191. const div = editor.render();
  11192. this.div.append(div);
  11193. editor.isAttachedToDOM = true;
  11194. }
  11195. editor.fixAndSetPosition();
  11196. editor.onceAdded();
  11197. this.#uiManager.addToAnnotationStorage(editor);
  11198. editor._reportTelemetry(editor.telemetryInitialData);
  11199. }
  11200. moveEditorInDOM(editor) {
  11201. if (!editor.isAttachedToDOM) {
  11202. return;
  11203. }
  11204. const {
  11205. activeElement
  11206. } = document;
  11207. if (editor.div.contains(activeElement) && !this.#editorFocusTimeoutId) {
  11208. editor._focusEventsAllowed = false;
  11209. this.#editorFocusTimeoutId = setTimeout(() => {
  11210. this.#editorFocusTimeoutId = null;
  11211. if (!editor.div.contains(document.activeElement)) {
  11212. editor.div.addEventListener("focusin", () => {
  11213. editor._focusEventsAllowed = true;
  11214. }, {
  11215. once: true
  11216. });
  11217. activeElement.focus();
  11218. } else {
  11219. editor._focusEventsAllowed = true;
  11220. }
  11221. }, 0);
  11222. }
  11223. editor._structTreeParentId = this.#accessibilityManager?.moveElementInDOM(this.div, editor.div, editor.contentDiv, true);
  11224. }
  11225. addOrRebuild(editor) {
  11226. if (editor.needsToBeRebuilt()) {
  11227. editor.parent ||= this;
  11228. editor.rebuild();
  11229. editor.show();
  11230. } else {
  11231. this.add(editor);
  11232. }
  11233. }
  11234. addUndoableEditor(editor) {
  11235. const cmd = () => editor._uiManager.rebuild(editor);
  11236. const undo = () => {
  11237. editor.remove();
  11238. };
  11239. this.addCommands({
  11240. cmd,
  11241. undo,
  11242. mustExec: false
  11243. });
  11244. }
  11245. getNextId() {
  11246. return this.#uiManager.getId();
  11247. }
  11248. get #currentEditorType() {
  11249. return AnnotationEditorLayer.#editorTypes.get(this.#uiManager.getMode());
  11250. }
  11251. #createNewEditor(params) {
  11252. const editorType = this.#currentEditorType;
  11253. return editorType ? new editorType.prototype.constructor(params) : null;
  11254. }
  11255. canCreateNewEmptyEditor() {
  11256. return this.#currentEditorType?.canCreateNewEmptyEditor();
  11257. }
  11258. pasteEditor(mode, params) {
  11259. this.#uiManager.updateToolbar(mode);
  11260. this.#uiManager.updateMode(mode);
  11261. const {
  11262. offsetX,
  11263. offsetY
  11264. } = this.#getCenterPoint();
  11265. const id = this.getNextId();
  11266. const editor = this.#createNewEditor({
  11267. parent: this,
  11268. id,
  11269. x: offsetX,
  11270. y: offsetY,
  11271. uiManager: this.#uiManager,
  11272. isCentered: true,
  11273. ...params
  11274. });
  11275. if (editor) {
  11276. this.add(editor);
  11277. }
  11278. }
  11279. deserialize(data) {
  11280. return AnnotationEditorLayer.#editorTypes.get(data.annotationType ?? data.annotationEditorType)?.deserialize(data, this, this.#uiManager) || null;
  11281. }
  11282. createAndAddNewEditor(event, isCentered, data = {}) {
  11283. const id = this.getNextId();
  11284. const editor = this.#createNewEditor({
  11285. parent: this,
  11286. id,
  11287. x: event.offsetX,
  11288. y: event.offsetY,
  11289. uiManager: this.#uiManager,
  11290. isCentered,
  11291. ...data
  11292. });
  11293. if (editor) {
  11294. this.add(editor);
  11295. }
  11296. return editor;
  11297. }
  11298. #getCenterPoint() {
  11299. const {
  11300. x,
  11301. y,
  11302. width,
  11303. height
  11304. } = this.div.getBoundingClientRect();
  11305. const tlX = Math.max(0, x);
  11306. const tlY = Math.max(0, y);
  11307. const brX = Math.min(window.innerWidth, x + width);
  11308. const brY = Math.min(window.innerHeight, y + height);
  11309. const centerX = (tlX + brX) / 2 - x;
  11310. const centerY = (tlY + brY) / 2 - y;
  11311. const [offsetX, offsetY] = this.viewport.rotation % 180 === 0 ? [centerX, centerY] : [centerY, centerX];
  11312. return {
  11313. offsetX,
  11314. offsetY
  11315. };
  11316. }
  11317. addNewEditor() {
  11318. this.createAndAddNewEditor(this.#getCenterPoint(), true);
  11319. }
  11320. setSelected(editor) {
  11321. this.#uiManager.setSelected(editor);
  11322. }
  11323. toggleSelected(editor) {
  11324. this.#uiManager.toggleSelected(editor);
  11325. }
  11326. isSelected(editor) {
  11327. return this.#uiManager.isSelected(editor);
  11328. }
  11329. unselect(editor) {
  11330. this.#uiManager.unselect(editor);
  11331. }
  11332. pointerup(event) {
  11333. const {
  11334. isMac
  11335. } = util.FeatureTest.platform;
  11336. if (event.button !== 0 || event.ctrlKey && isMac) {
  11337. return;
  11338. }
  11339. if (event.target !== this.div) {
  11340. return;
  11341. }
  11342. if (!this.#hadPointerDown) {
  11343. return;
  11344. }
  11345. this.#hadPointerDown = false;
  11346. if (!this.#allowClick) {
  11347. this.#allowClick = true;
  11348. return;
  11349. }
  11350. if (this.#uiManager.getMode() === util.AnnotationEditorType.STAMP) {
  11351. this.#uiManager.unselectAll();
  11352. return;
  11353. }
  11354. this.createAndAddNewEditor(event, false);
  11355. }
  11356. pointerdown(event) {
  11357. if (this.#uiManager.getMode() === util.AnnotationEditorType.HIGHLIGHT) {
  11358. this.enableTextSelection();
  11359. }
  11360. if (this.#hadPointerDown) {
  11361. this.#hadPointerDown = false;
  11362. return;
  11363. }
  11364. const {
  11365. isMac
  11366. } = util.FeatureTest.platform;
  11367. if (event.button !== 0 || event.ctrlKey && isMac) {
  11368. return;
  11369. }
  11370. if (event.target !== this.div) {
  11371. return;
  11372. }
  11373. this.#hadPointerDown = true;
  11374. const editor = this.#uiManager.getActive();
  11375. this.#allowClick = !editor || editor.isEmpty();
  11376. }
  11377. findNewParent(editor, x, y) {
  11378. const layer = this.#uiManager.findParent(x, y);
  11379. if (layer === null || layer === this) {
  11380. return false;
  11381. }
  11382. layer.changeParent(editor);
  11383. return true;
  11384. }
  11385. destroy() {
  11386. if (this.#uiManager.getActive()?.parent === this) {
  11387. this.#uiManager.commitOrRemove();
  11388. this.#uiManager.setActiveEditor(null);
  11389. }
  11390. if (this.#editorFocusTimeoutId) {
  11391. clearTimeout(this.#editorFocusTimeoutId);
  11392. this.#editorFocusTimeoutId = null;
  11393. }
  11394. for (const editor of this.#editors.values()) {
  11395. this.#accessibilityManager?.removePointerInTextLayer(editor.contentDiv);
  11396. editor.setParent(null);
  11397. editor.isAttachedToDOM = false;
  11398. editor.div.remove();
  11399. }
  11400. this.div = null;
  11401. this.#editors.clear();
  11402. this.#uiManager.removeLayer(this);
  11403. }
  11404. #cleanup() {
  11405. this.#isCleaningUp = true;
  11406. for (const editor of this.#editors.values()) {
  11407. if (editor.isEmpty()) {
  11408. editor.remove();
  11409. }
  11410. }
  11411. this.#isCleaningUp = false;
  11412. }
  11413. render({
  11414. viewport
  11415. }) {
  11416. this.viewport = viewport;
  11417. (0,display_utils.setLayerDimensions)(this.div, viewport);
  11418. for (const editor of this.#uiManager.getEditors(this.pageIndex)) {
  11419. this.add(editor);
  11420. editor.rebuild();
  11421. }
  11422. this.updateMode();
  11423. }
  11424. update({
  11425. viewport
  11426. }) {
  11427. this.#uiManager.commitOrRemove();
  11428. this.#cleanup();
  11429. const oldRotation = this.viewport.rotation;
  11430. const rotation = viewport.rotation;
  11431. this.viewport = viewport;
  11432. (0,display_utils.setLayerDimensions)(this.div, {
  11433. rotation
  11434. });
  11435. if (oldRotation !== rotation) {
  11436. for (const editor of this.#editors.values()) {
  11437. editor.rotate(rotation);
  11438. }
  11439. }
  11440. this.addInkEditorIfNeeded(false);
  11441. }
  11442. get pageDimensions() {
  11443. const {
  11444. pageWidth,
  11445. pageHeight
  11446. } = this.viewport.rawDims;
  11447. return [pageWidth, pageHeight];
  11448. }
  11449. get scale() {
  11450. return this.#uiManager.viewParameters.realScale;
  11451. }
  11452. }
  11453. /***/ }),
  11454. /***/ 259:
  11455. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  11456. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  11457. /* harmony export */ ColorPicker: () => (/* binding */ ColorPicker)
  11458. /* harmony export */ });
  11459. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(292);
  11460. /* harmony import */ var _tools_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(830);
  11461. /* harmony import */ var _display_utils_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(419);
  11462. class ColorPicker {
  11463. #boundKeyDown = this.#keyDown.bind(this);
  11464. #boundPointerDown = this.#pointerDown.bind(this);
  11465. #button = null;
  11466. #buttonSwatch = null;
  11467. #defaultColor;
  11468. #dropdown = null;
  11469. #dropdownWasFromKeyboard = false;
  11470. #isMainColorPicker = false;
  11471. #editor = null;
  11472. #eventBus;
  11473. #uiManager = null;
  11474. #type;
  11475. static get _keyboardManager() {
  11476. 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]]));
  11477. }
  11478. constructor({
  11479. editor = null,
  11480. uiManager = null
  11481. }) {
  11482. if (editor) {
  11483. this.#isMainColorPicker = false;
  11484. this.#type = _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorParamsType.HIGHLIGHT_COLOR;
  11485. this.#editor = editor;
  11486. } else {
  11487. this.#isMainColorPicker = true;
  11488. this.#type = _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorParamsType.HIGHLIGHT_DEFAULT_COLOR;
  11489. }
  11490. this.#uiManager = editor?._uiManager || uiManager;
  11491. this.#eventBus = this.#uiManager._eventBus;
  11492. this.#defaultColor = editor?.color || this.#uiManager?.highlightColors.values().next().value || "#FFFF98";
  11493. }
  11494. renderButton() {
  11495. const button = this.#button = document.createElement("button");
  11496. button.className = "colorPicker";
  11497. button.tabIndex = "0";
  11498. button.setAttribute("data-l10n-id", "pdfjs-editor-colorpicker-button");
  11499. button.setAttribute("aria-haspopup", true);
  11500. button.addEventListener("click", this.#openDropdown.bind(this));
  11501. button.addEventListener("keydown", this.#boundKeyDown);
  11502. const swatch = this.#buttonSwatch = document.createElement("span");
  11503. swatch.className = "swatch";
  11504. swatch.setAttribute("aria-hidden", true);
  11505. swatch.style.backgroundColor = this.#defaultColor;
  11506. button.append(swatch);
  11507. return button;
  11508. }
  11509. renderMainDropdown() {
  11510. const dropdown = this.#dropdown = this.#getDropdownRoot();
  11511. dropdown.setAttribute("aria-orientation", "horizontal");
  11512. dropdown.setAttribute("aria-labelledby", "highlightColorPickerLabel");
  11513. return dropdown;
  11514. }
  11515. #getDropdownRoot() {
  11516. const div = document.createElement("div");
  11517. div.addEventListener("contextmenu", _display_utils_js__WEBPACK_IMPORTED_MODULE_2__.noContextMenu);
  11518. div.className = "dropdown";
  11519. div.role = "listbox";
  11520. div.setAttribute("aria-multiselectable", false);
  11521. div.setAttribute("aria-orientation", "vertical");
  11522. div.setAttribute("data-l10n-id", "pdfjs-editor-colorpicker-dropdown");
  11523. for (const [name, color] of this.#uiManager.highlightColors) {
  11524. const button = document.createElement("button");
  11525. button.tabIndex = "0";
  11526. button.role = "option";
  11527. button.setAttribute("data-color", color);
  11528. button.title = name;
  11529. button.setAttribute("data-l10n-id", `pdfjs-editor-colorpicker-${name}`);
  11530. const swatch = document.createElement("span");
  11531. button.append(swatch);
  11532. swatch.className = "swatch";
  11533. swatch.style.backgroundColor = color;
  11534. button.setAttribute("aria-selected", color === this.#defaultColor);
  11535. button.addEventListener("click", this.#colorSelect.bind(this, color));
  11536. div.append(button);
  11537. }
  11538. div.addEventListener("keydown", this.#boundKeyDown);
  11539. return div;
  11540. }
  11541. #colorSelect(color, event) {
  11542. event.stopPropagation();
  11543. this.#eventBus.dispatch("switchannotationeditorparams", {
  11544. source: this,
  11545. type: this.#type,
  11546. value: color
  11547. });
  11548. }
  11549. _colorSelectFromKeyboard(event) {
  11550. if (event.target === this.#button) {
  11551. this.#openDropdown(event);
  11552. return;
  11553. }
  11554. const color = event.target.getAttribute("data-color");
  11555. if (!color) {
  11556. return;
  11557. }
  11558. this.#colorSelect(color, event);
  11559. }
  11560. _moveToNext(event) {
  11561. if (!this.#isDropdownVisible) {
  11562. this.#openDropdown(event);
  11563. return;
  11564. }
  11565. if (event.target === this.#button) {
  11566. this.#dropdown.firstChild?.focus();
  11567. return;
  11568. }
  11569. event.target.nextSibling?.focus();
  11570. }
  11571. _moveToPrevious(event) {
  11572. if (event.target === this.#dropdown?.firstChild || event.target === this.#button) {
  11573. if (this.#isDropdownVisible) {
  11574. this._hideDropdownFromKeyboard();
  11575. }
  11576. return;
  11577. }
  11578. if (!this.#isDropdownVisible) {
  11579. this.#openDropdown(event);
  11580. }
  11581. event.target.previousSibling?.focus();
  11582. }
  11583. _moveToBeginning(event) {
  11584. if (!this.#isDropdownVisible) {
  11585. this.#openDropdown(event);
  11586. return;
  11587. }
  11588. this.#dropdown.firstChild?.focus();
  11589. }
  11590. _moveToEnd(event) {
  11591. if (!this.#isDropdownVisible) {
  11592. this.#openDropdown(event);
  11593. return;
  11594. }
  11595. this.#dropdown.lastChild?.focus();
  11596. }
  11597. #keyDown(event) {
  11598. ColorPicker._keyboardManager.exec(this, event);
  11599. }
  11600. #openDropdown(event) {
  11601. if (this.#isDropdownVisible) {
  11602. this.hideDropdown();
  11603. return;
  11604. }
  11605. this.#dropdownWasFromKeyboard = event.detail === 0;
  11606. window.addEventListener("pointerdown", this.#boundPointerDown);
  11607. if (this.#dropdown) {
  11608. this.#dropdown.classList.remove("hidden");
  11609. return;
  11610. }
  11611. const root = this.#dropdown = this.#getDropdownRoot();
  11612. this.#button.append(root);
  11613. }
  11614. #pointerDown(event) {
  11615. if (this.#dropdown?.contains(event.target)) {
  11616. return;
  11617. }
  11618. this.hideDropdown();
  11619. }
  11620. hideDropdown() {
  11621. this.#dropdown?.classList.add("hidden");
  11622. window.removeEventListener("pointerdown", this.#boundPointerDown);
  11623. }
  11624. get #isDropdownVisible() {
  11625. return this.#dropdown && !this.#dropdown.classList.contains("hidden");
  11626. }
  11627. _hideDropdownFromKeyboard() {
  11628. if (this.#isMainColorPicker) {
  11629. return;
  11630. }
  11631. if (!this.#isDropdownVisible) {
  11632. this.#editor?.unselect();
  11633. return;
  11634. }
  11635. this.hideDropdown();
  11636. this.#button.focus({
  11637. preventScroll: true,
  11638. focusVisible: this.#dropdownWasFromKeyboard
  11639. });
  11640. }
  11641. updateColor(color) {
  11642. if (this.#buttonSwatch) {
  11643. this.#buttonSwatch.style.backgroundColor = color;
  11644. }
  11645. if (!this.#dropdown) {
  11646. return;
  11647. }
  11648. const i = this.#uiManager.highlightColors.values();
  11649. for (const child of this.#dropdown.children) {
  11650. child.setAttribute("aria-selected", i.next().value === color);
  11651. }
  11652. }
  11653. destroy() {
  11654. this.#button?.remove();
  11655. this.#button = null;
  11656. this.#buttonSwatch = null;
  11657. this.#dropdown?.remove();
  11658. this.#dropdown = null;
  11659. }
  11660. }
  11661. /***/ }),
  11662. /***/ 310:
  11663. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  11664. // EXPORTS
  11665. __webpack_require__.d(__webpack_exports__, {
  11666. AnnotationEditor: () => (/* binding */ AnnotationEditor)
  11667. });
  11668. // EXTERNAL MODULE: ./src/display/editor/tools.js
  11669. var tools = __webpack_require__(830);
  11670. // EXTERNAL MODULE: ./src/shared/util.js
  11671. var util = __webpack_require__(292);
  11672. // EXTERNAL MODULE: ./src/display/display_utils.js
  11673. var display_utils = __webpack_require__(419);
  11674. ;// CONCATENATED MODULE: ./src/display/editor/alt_text.js
  11675. class AltText {
  11676. #altText = "";
  11677. #altTextDecorative = false;
  11678. #altTextButton = null;
  11679. #altTextTooltip = null;
  11680. #altTextTooltipTimeout = null;
  11681. #altTextWasFromKeyBoard = false;
  11682. #editor = null;
  11683. static _l10nPromise = null;
  11684. constructor(editor) {
  11685. this.#editor = editor;
  11686. }
  11687. static initialize(l10nPromise) {
  11688. AltText._l10nPromise ||= l10nPromise;
  11689. }
  11690. async render() {
  11691. const altText = this.#altTextButton = document.createElement("button");
  11692. altText.className = "altText";
  11693. const msg = await AltText._l10nPromise.get("pdfjs-editor-alt-text-button-label");
  11694. altText.textContent = msg;
  11695. altText.setAttribute("aria-label", msg);
  11696. altText.tabIndex = "0";
  11697. altText.addEventListener("contextmenu", display_utils.noContextMenu);
  11698. altText.addEventListener("pointerdown", event => event.stopPropagation());
  11699. const onClick = event => {
  11700. event.preventDefault();
  11701. this.#editor._uiManager.editAltText(this.#editor);
  11702. };
  11703. altText.addEventListener("click", onClick, {
  11704. capture: true
  11705. });
  11706. altText.addEventListener("keydown", event => {
  11707. if (event.target === altText && event.key === "Enter") {
  11708. this.#altTextWasFromKeyBoard = true;
  11709. onClick(event);
  11710. }
  11711. });
  11712. await this.#setState();
  11713. return altText;
  11714. }
  11715. finish() {
  11716. if (!this.#altTextButton) {
  11717. return;
  11718. }
  11719. this.#altTextButton.focus({
  11720. focusVisible: this.#altTextWasFromKeyBoard
  11721. });
  11722. this.#altTextWasFromKeyBoard = false;
  11723. }
  11724. isEmpty() {
  11725. return !this.#altText && !this.#altTextDecorative;
  11726. }
  11727. get data() {
  11728. return {
  11729. altText: this.#altText,
  11730. decorative: this.#altTextDecorative
  11731. };
  11732. }
  11733. set data({
  11734. altText,
  11735. decorative
  11736. }) {
  11737. if (this.#altText === altText && this.#altTextDecorative === decorative) {
  11738. return;
  11739. }
  11740. this.#altText = altText;
  11741. this.#altTextDecorative = decorative;
  11742. this.#setState();
  11743. }
  11744. toggle(enabled = false) {
  11745. if (!this.#altTextButton) {
  11746. return;
  11747. }
  11748. if (!enabled && this.#altTextTooltipTimeout) {
  11749. clearTimeout(this.#altTextTooltipTimeout);
  11750. this.#altTextTooltipTimeout = null;
  11751. }
  11752. this.#altTextButton.disabled = !enabled;
  11753. }
  11754. destroy() {
  11755. this.#altTextButton?.remove();
  11756. this.#altTextButton = null;
  11757. this.#altTextTooltip = null;
  11758. }
  11759. async #setState() {
  11760. const button = this.#altTextButton;
  11761. if (!button) {
  11762. return;
  11763. }
  11764. if (!this.#altText && !this.#altTextDecorative) {
  11765. button.classList.remove("done");
  11766. this.#altTextTooltip?.remove();
  11767. return;
  11768. }
  11769. button.classList.add("done");
  11770. AltText._l10nPromise.get("pdfjs-editor-alt-text-edit-button-label").then(msg => {
  11771. button.setAttribute("aria-label", msg);
  11772. });
  11773. let tooltip = this.#altTextTooltip;
  11774. if (!tooltip) {
  11775. this.#altTextTooltip = tooltip = document.createElement("span");
  11776. tooltip.className = "tooltip";
  11777. tooltip.setAttribute("role", "tooltip");
  11778. const id = tooltip.id = `alt-text-tooltip-${this.#editor.id}`;
  11779. button.setAttribute("aria-describedby", id);
  11780. const DELAY_TO_SHOW_TOOLTIP = 100;
  11781. button.addEventListener("mouseenter", () => {
  11782. this.#altTextTooltipTimeout = setTimeout(() => {
  11783. this.#altTextTooltipTimeout = null;
  11784. this.#altTextTooltip.classList.add("show");
  11785. this.#editor._reportTelemetry({
  11786. action: "alt_text_tooltip"
  11787. });
  11788. }, DELAY_TO_SHOW_TOOLTIP);
  11789. });
  11790. button.addEventListener("mouseleave", () => {
  11791. if (this.#altTextTooltipTimeout) {
  11792. clearTimeout(this.#altTextTooltipTimeout);
  11793. this.#altTextTooltipTimeout = null;
  11794. }
  11795. this.#altTextTooltip?.classList.remove("show");
  11796. });
  11797. }
  11798. tooltip.innerText = this.#altTextDecorative ? await AltText._l10nPromise.get("pdfjs-editor-alt-text-decorative-tooltip") : this.#altText;
  11799. if (!tooltip.parentNode) {
  11800. button.append(tooltip);
  11801. }
  11802. const element = this.#editor.getImageForAltText();
  11803. element?.setAttribute("aria-describedby", tooltip.id);
  11804. }
  11805. }
  11806. // EXTERNAL MODULE: ./src/display/editor/toolbar.js
  11807. var toolbar = __webpack_require__(362);
  11808. ;// CONCATENATED MODULE: ./src/display/editor/editor.js
  11809. class AnnotationEditor {
  11810. #allResizerDivs = null;
  11811. #altText = null;
  11812. #disabled = false;
  11813. #keepAspectRatio = false;
  11814. #resizersDiv = null;
  11815. #savedDimensions = null;
  11816. #boundFocusin = this.focusin.bind(this);
  11817. #boundFocusout = this.focusout.bind(this);
  11818. #editToolbar = null;
  11819. #focusedResizerName = "";
  11820. #hasBeenClicked = false;
  11821. #initialPosition = null;
  11822. #isEditing = false;
  11823. #isInEditMode = false;
  11824. #isResizerEnabledForKeyboard = false;
  11825. #moveInDOMTimeout = null;
  11826. #prevDragX = 0;
  11827. #prevDragY = 0;
  11828. #telemetryTimeouts = null;
  11829. _initialOptions = Object.create(null);
  11830. _isVisible = true;
  11831. _uiManager = null;
  11832. _focusEventsAllowed = true;
  11833. _l10nPromise = null;
  11834. #isDraggable = false;
  11835. #zIndex = AnnotationEditor._zIndex++;
  11836. static _borderLineWidth = -1;
  11837. static _colorManager = new tools.ColorManager();
  11838. static _zIndex = 1;
  11839. static _telemetryTimeout = 1000;
  11840. static get _resizerKeyboardManager() {
  11841. const resize = AnnotationEditor.prototype._resizeWithKeyboard;
  11842. const small = tools.AnnotationEditorUIManager.TRANSLATE_SMALL;
  11843. const big = tools.AnnotationEditorUIManager.TRANSLATE_BIG;
  11844. return (0,util.shadow)(this, "_resizerKeyboardManager", new tools.KeyboardManager([[["ArrowLeft", "mac+ArrowLeft"], resize, {
  11845. args: [-small, 0]
  11846. }], [["ctrl+ArrowLeft", "mac+shift+ArrowLeft"], resize, {
  11847. args: [-big, 0]
  11848. }], [["ArrowRight", "mac+ArrowRight"], resize, {
  11849. args: [small, 0]
  11850. }], [["ctrl+ArrowRight", "mac+shift+ArrowRight"], resize, {
  11851. args: [big, 0]
  11852. }], [["ArrowUp", "mac+ArrowUp"], resize, {
  11853. args: [0, -small]
  11854. }], [["ctrl+ArrowUp", "mac+shift+ArrowUp"], resize, {
  11855. args: [0, -big]
  11856. }], [["ArrowDown", "mac+ArrowDown"], resize, {
  11857. args: [0, small]
  11858. }], [["ctrl+ArrowDown", "mac+shift+ArrowDown"], resize, {
  11859. args: [0, big]
  11860. }], [["Escape", "mac+Escape"], AnnotationEditor.prototype._stopResizingWithKeyboard]]));
  11861. }
  11862. constructor(parameters) {
  11863. if (this.constructor === AnnotationEditor) {
  11864. (0,util.unreachable)("Cannot initialize AnnotationEditor.");
  11865. }
  11866. this.parent = parameters.parent;
  11867. this.id = parameters.id;
  11868. this.width = this.height = null;
  11869. this.pageIndex = parameters.parent.pageIndex;
  11870. this.name = parameters.name;
  11871. this.div = null;
  11872. this._uiManager = parameters.uiManager;
  11873. this.annotationElementId = null;
  11874. this._willKeepAspectRatio = false;
  11875. this._initialOptions.isCentered = parameters.isCentered;
  11876. this._structTreeParentId = null;
  11877. const {
  11878. rotation,
  11879. rawDims: {
  11880. pageWidth,
  11881. pageHeight,
  11882. pageX,
  11883. pageY
  11884. }
  11885. } = this.parent.viewport;
  11886. this.rotation = rotation;
  11887. this.pageRotation = (360 + rotation - this._uiManager.viewParameters.rotation) % 360;
  11888. this.pageDimensions = [pageWidth, pageHeight];
  11889. this.pageTranslation = [pageX, pageY];
  11890. const [width, height] = this.parentDimensions;
  11891. this.x = parameters.x / width;
  11892. this.y = parameters.y / height;
  11893. this.isAttachedToDOM = false;
  11894. this.deleted = false;
  11895. }
  11896. get editorType() {
  11897. return Object.getPrototypeOf(this).constructor._type;
  11898. }
  11899. static get _defaultLineColor() {
  11900. return (0,util.shadow)(this, "_defaultLineColor", this._colorManager.getHexCode("CanvasText"));
  11901. }
  11902. static deleteAnnotationElement(editor) {
  11903. const fakeEditor = new FakeEditor({
  11904. id: editor.parent.getNextId(),
  11905. parent: editor.parent,
  11906. uiManager: editor._uiManager
  11907. });
  11908. fakeEditor.annotationElementId = editor.annotationElementId;
  11909. fakeEditor.deleted = true;
  11910. fakeEditor._uiManager.addToAnnotationStorage(fakeEditor);
  11911. }
  11912. static initialize(l10n, _uiManager, options) {
  11913. 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()}`))]));
  11914. if (options?.strings) {
  11915. for (const str of options.strings) {
  11916. AnnotationEditor._l10nPromise.set(str, l10n.get(str));
  11917. }
  11918. }
  11919. if (AnnotationEditor._borderLineWidth !== -1) {
  11920. return;
  11921. }
  11922. const style = getComputedStyle(document.documentElement);
  11923. AnnotationEditor._borderLineWidth = parseFloat(style.getPropertyValue("--outline-width")) || 0;
  11924. }
  11925. static updateDefaultParams(_type, _value) {}
  11926. static get defaultPropertiesToUpdate() {
  11927. return [];
  11928. }
  11929. static isHandlingMimeForPasting(mime) {
  11930. return false;
  11931. }
  11932. static paste(item, parent) {
  11933. (0,util.unreachable)("Not implemented");
  11934. }
  11935. get propertiesToUpdate() {
  11936. return [];
  11937. }
  11938. get _isDraggable() {
  11939. return this.#isDraggable;
  11940. }
  11941. set _isDraggable(value) {
  11942. this.#isDraggable = value;
  11943. this.div?.classList.toggle("draggable", value);
  11944. }
  11945. get isEnterHandled() {
  11946. return true;
  11947. }
  11948. center() {
  11949. const [pageWidth, pageHeight] = this.pageDimensions;
  11950. switch (this.parentRotation) {
  11951. case 90:
  11952. this.x -= this.height * pageHeight / (pageWidth * 2);
  11953. this.y += this.width * pageWidth / (pageHeight * 2);
  11954. break;
  11955. case 180:
  11956. this.x += this.width / 2;
  11957. this.y += this.height / 2;
  11958. break;
  11959. case 270:
  11960. this.x += this.height * pageHeight / (pageWidth * 2);
  11961. this.y -= this.width * pageWidth / (pageHeight * 2);
  11962. break;
  11963. default:
  11964. this.x -= this.width / 2;
  11965. this.y -= this.height / 2;
  11966. break;
  11967. }
  11968. this.fixAndSetPosition();
  11969. }
  11970. addCommands(params) {
  11971. this._uiManager.addCommands(params);
  11972. }
  11973. get currentLayer() {
  11974. return this._uiManager.currentLayer;
  11975. }
  11976. setInBackground() {
  11977. this.div.style.zIndex = 0;
  11978. }
  11979. setInForeground() {
  11980. this.div.style.zIndex = this.#zIndex;
  11981. }
  11982. setParent(parent) {
  11983. if (parent !== null) {
  11984. this.pageIndex = parent.pageIndex;
  11985. this.pageDimensions = parent.pageDimensions;
  11986. } else {
  11987. this.#stopResizing();
  11988. }
  11989. this.parent = parent;
  11990. }
  11991. focusin(event) {
  11992. if (!this._focusEventsAllowed) {
  11993. return;
  11994. }
  11995. if (!this.#hasBeenClicked) {
  11996. this.parent.setSelected(this);
  11997. } else {
  11998. this.#hasBeenClicked = false;
  11999. }
  12000. }
  12001. focusout(event) {
  12002. if (!this._focusEventsAllowed) {
  12003. return;
  12004. }
  12005. if (!this.isAttachedToDOM) {
  12006. return;
  12007. }
  12008. const target = event.relatedTarget;
  12009. if (target?.closest(`#${this.id}`)) {
  12010. return;
  12011. }
  12012. event.preventDefault();
  12013. if (!this.parent?.isMultipleSelection) {
  12014. this.commitOrRemove();
  12015. }
  12016. }
  12017. commitOrRemove() {
  12018. if (this.isEmpty()) {
  12019. this.remove();
  12020. } else {
  12021. this.commit();
  12022. }
  12023. }
  12024. commit() {
  12025. this.addToAnnotationStorage();
  12026. }
  12027. addToAnnotationStorage() {
  12028. this._uiManager.addToAnnotationStorage(this);
  12029. }
  12030. setAt(x, y, tx, ty) {
  12031. const [width, height] = this.parentDimensions;
  12032. [tx, ty] = this.screenToPageTranslation(tx, ty);
  12033. this.x = (x + tx) / width;
  12034. this.y = (y + ty) / height;
  12035. this.fixAndSetPosition();
  12036. }
  12037. #translate([width, height], x, y) {
  12038. [x, y] = this.screenToPageTranslation(x, y);
  12039. this.x += x / width;
  12040. this.y += y / height;
  12041. this.fixAndSetPosition();
  12042. }
  12043. translate(x, y) {
  12044. this.#translate(this.parentDimensions, x, y);
  12045. }
  12046. translateInPage(x, y) {
  12047. this.#initialPosition ||= [this.x, this.y];
  12048. this.#translate(this.pageDimensions, x, y);
  12049. this.div.scrollIntoView({
  12050. block: "nearest"
  12051. });
  12052. }
  12053. drag(tx, ty) {
  12054. this.#initialPosition ||= [this.x, this.y];
  12055. const [parentWidth, parentHeight] = this.parentDimensions;
  12056. this.x += tx / parentWidth;
  12057. this.y += ty / parentHeight;
  12058. if (this.parent && (this.x < 0 || this.x > 1 || this.y < 0 || this.y > 1)) {
  12059. const {
  12060. x,
  12061. y
  12062. } = this.div.getBoundingClientRect();
  12063. if (this.parent.findNewParent(this, x, y)) {
  12064. this.x -= Math.floor(this.x);
  12065. this.y -= Math.floor(this.y);
  12066. }
  12067. }
  12068. let {
  12069. x,
  12070. y
  12071. } = this;
  12072. const [bx, by] = this.getBaseTranslation();
  12073. x += bx;
  12074. y += by;
  12075. this.div.style.left = `${(100 * x).toFixed(2)}%`;
  12076. this.div.style.top = `${(100 * y).toFixed(2)}%`;
  12077. this.div.scrollIntoView({
  12078. block: "nearest"
  12079. });
  12080. }
  12081. get _hasBeenMoved() {
  12082. return !!this.#initialPosition && (this.#initialPosition[0] !== this.x || this.#initialPosition[1] !== this.y);
  12083. }
  12084. getBaseTranslation() {
  12085. const [parentWidth, parentHeight] = this.parentDimensions;
  12086. const {
  12087. _borderLineWidth
  12088. } = AnnotationEditor;
  12089. const x = _borderLineWidth / parentWidth;
  12090. const y = _borderLineWidth / parentHeight;
  12091. switch (this.rotation) {
  12092. case 90:
  12093. return [-x, y];
  12094. case 180:
  12095. return [x, y];
  12096. case 270:
  12097. return [x, -y];
  12098. default:
  12099. return [-x, -y];
  12100. }
  12101. }
  12102. get _mustFixPosition() {
  12103. return true;
  12104. }
  12105. fixAndSetPosition(rotation = this.rotation) {
  12106. const [pageWidth, pageHeight] = this.pageDimensions;
  12107. let {
  12108. x,
  12109. y,
  12110. width,
  12111. height
  12112. } = this;
  12113. width *= pageWidth;
  12114. height *= pageHeight;
  12115. x *= pageWidth;
  12116. y *= pageHeight;
  12117. if (this._mustFixPosition) {
  12118. switch (rotation) {
  12119. case 0:
  12120. x = Math.max(0, Math.min(pageWidth - width, x));
  12121. y = Math.max(0, Math.min(pageHeight - height, y));
  12122. break;
  12123. case 90:
  12124. x = Math.max(0, Math.min(pageWidth - height, x));
  12125. y = Math.min(pageHeight, Math.max(width, y));
  12126. break;
  12127. case 180:
  12128. x = Math.min(pageWidth, Math.max(width, x));
  12129. y = Math.min(pageHeight, Math.max(height, y));
  12130. break;
  12131. case 270:
  12132. x = Math.min(pageWidth, Math.max(height, x));
  12133. y = Math.max(0, Math.min(pageHeight - width, y));
  12134. break;
  12135. }
  12136. }
  12137. this.x = x /= pageWidth;
  12138. this.y = y /= pageHeight;
  12139. const [bx, by] = this.getBaseTranslation();
  12140. x += bx;
  12141. y += by;
  12142. const {
  12143. style
  12144. } = this.div;
  12145. style.left = `${(100 * x).toFixed(2)}%`;
  12146. style.top = `${(100 * y).toFixed(2)}%`;
  12147. this.moveInDOM();
  12148. }
  12149. static #rotatePoint(x, y, angle) {
  12150. switch (angle) {
  12151. case 90:
  12152. return [y, -x];
  12153. case 180:
  12154. return [-x, -y];
  12155. case 270:
  12156. return [-y, x];
  12157. default:
  12158. return [x, y];
  12159. }
  12160. }
  12161. screenToPageTranslation(x, y) {
  12162. return AnnotationEditor.#rotatePoint(x, y, this.parentRotation);
  12163. }
  12164. pageTranslationToScreen(x, y) {
  12165. return AnnotationEditor.#rotatePoint(x, y, 360 - this.parentRotation);
  12166. }
  12167. #getRotationMatrix(rotation) {
  12168. switch (rotation) {
  12169. case 90:
  12170. {
  12171. const [pageWidth, pageHeight] = this.pageDimensions;
  12172. return [0, -pageWidth / pageHeight, pageHeight / pageWidth, 0];
  12173. }
  12174. case 180:
  12175. return [-1, 0, 0, -1];
  12176. case 270:
  12177. {
  12178. const [pageWidth, pageHeight] = this.pageDimensions;
  12179. return [0, pageWidth / pageHeight, -pageHeight / pageWidth, 0];
  12180. }
  12181. default:
  12182. return [1, 0, 0, 1];
  12183. }
  12184. }
  12185. get parentScale() {
  12186. return this._uiManager.viewParameters.realScale;
  12187. }
  12188. get parentRotation() {
  12189. return (this._uiManager.viewParameters.rotation + this.pageRotation) % 360;
  12190. }
  12191. get parentDimensions() {
  12192. const {
  12193. parentScale,
  12194. pageDimensions: [pageWidth, pageHeight]
  12195. } = this;
  12196. const scaledWidth = pageWidth * parentScale;
  12197. const scaledHeight = pageHeight * parentScale;
  12198. return util.FeatureTest.isCSSRoundSupported ? [Math.round(scaledWidth), Math.round(scaledHeight)] : [scaledWidth, scaledHeight];
  12199. }
  12200. setDims(width, height) {
  12201. const [parentWidth, parentHeight] = this.parentDimensions;
  12202. this.div.style.width = `${(100 * width / parentWidth).toFixed(2)}%`;
  12203. if (!this.#keepAspectRatio) {
  12204. this.div.style.height = `${(100 * height / parentHeight).toFixed(2)}%`;
  12205. }
  12206. }
  12207. fixDims() {
  12208. const {
  12209. style
  12210. } = this.div;
  12211. const {
  12212. height,
  12213. width
  12214. } = style;
  12215. const widthPercent = width.endsWith("%");
  12216. const heightPercent = !this.#keepAspectRatio && height.endsWith("%");
  12217. if (widthPercent && heightPercent) {
  12218. return;
  12219. }
  12220. const [parentWidth, parentHeight] = this.parentDimensions;
  12221. if (!widthPercent) {
  12222. style.width = `${(100 * parseFloat(width) / parentWidth).toFixed(2)}%`;
  12223. }
  12224. if (!this.#keepAspectRatio && !heightPercent) {
  12225. style.height = `${(100 * parseFloat(height) / parentHeight).toFixed(2)}%`;
  12226. }
  12227. }
  12228. getInitialTranslation() {
  12229. return [0, 0];
  12230. }
  12231. #createResizers() {
  12232. if (this.#resizersDiv) {
  12233. return;
  12234. }
  12235. this.#resizersDiv = document.createElement("div");
  12236. this.#resizersDiv.classList.add("resizers");
  12237. const classes = this._willKeepAspectRatio ? ["topLeft", "topRight", "bottomRight", "bottomLeft"] : ["topLeft", "topMiddle", "topRight", "middleRight", "bottomRight", "bottomMiddle", "bottomLeft", "middleLeft"];
  12238. for (const name of classes) {
  12239. const div = document.createElement("div");
  12240. this.#resizersDiv.append(div);
  12241. div.classList.add("resizer", name);
  12242. div.setAttribute("data-resizer-name", name);
  12243. div.addEventListener("pointerdown", this.#resizerPointerdown.bind(this, name));
  12244. div.addEventListener("contextmenu", display_utils.noContextMenu);
  12245. div.tabIndex = -1;
  12246. }
  12247. this.div.prepend(this.#resizersDiv);
  12248. }
  12249. #resizerPointerdown(name, event) {
  12250. event.preventDefault();
  12251. const {
  12252. isMac
  12253. } = util.FeatureTest.platform;
  12254. if (event.button !== 0 || event.ctrlKey && isMac) {
  12255. return;
  12256. }
  12257. this.#altText?.toggle(false);
  12258. const boundResizerPointermove = this.#resizerPointermove.bind(this, name);
  12259. const savedDraggable = this._isDraggable;
  12260. this._isDraggable = false;
  12261. const pointerMoveOptions = {
  12262. passive: true,
  12263. capture: true
  12264. };
  12265. this.parent.togglePointerEvents(false);
  12266. window.addEventListener("pointermove", boundResizerPointermove, pointerMoveOptions);
  12267. window.addEventListener("contextmenu", display_utils.noContextMenu);
  12268. const savedX = this.x;
  12269. const savedY = this.y;
  12270. const savedWidth = this.width;
  12271. const savedHeight = this.height;
  12272. const savedParentCursor = this.parent.div.style.cursor;
  12273. const savedCursor = this.div.style.cursor;
  12274. this.div.style.cursor = this.parent.div.style.cursor = window.getComputedStyle(event.target).cursor;
  12275. const pointerUpCallback = () => {
  12276. this.parent.togglePointerEvents(true);
  12277. this.#altText?.toggle(true);
  12278. this._isDraggable = savedDraggable;
  12279. window.removeEventListener("pointerup", pointerUpCallback);
  12280. window.removeEventListener("blur", pointerUpCallback);
  12281. window.removeEventListener("pointermove", boundResizerPointermove, pointerMoveOptions);
  12282. window.removeEventListener("contextmenu", display_utils.noContextMenu);
  12283. this.parent.div.style.cursor = savedParentCursor;
  12284. this.div.style.cursor = savedCursor;
  12285. this.#addResizeToUndoStack(savedX, savedY, savedWidth, savedHeight);
  12286. };
  12287. window.addEventListener("pointerup", pointerUpCallback);
  12288. window.addEventListener("blur", pointerUpCallback);
  12289. }
  12290. #addResizeToUndoStack(savedX, savedY, savedWidth, savedHeight) {
  12291. const newX = this.x;
  12292. const newY = this.y;
  12293. const newWidth = this.width;
  12294. const newHeight = this.height;
  12295. if (newX === savedX && newY === savedY && newWidth === savedWidth && newHeight === savedHeight) {
  12296. return;
  12297. }
  12298. this.addCommands({
  12299. cmd: () => {
  12300. this.width = newWidth;
  12301. this.height = newHeight;
  12302. this.x = newX;
  12303. this.y = newY;
  12304. const [parentWidth, parentHeight] = this.parentDimensions;
  12305. this.setDims(parentWidth * newWidth, parentHeight * newHeight);
  12306. this.fixAndSetPosition();
  12307. },
  12308. undo: () => {
  12309. this.width = savedWidth;
  12310. this.height = savedHeight;
  12311. this.x = savedX;
  12312. this.y = savedY;
  12313. const [parentWidth, parentHeight] = this.parentDimensions;
  12314. this.setDims(parentWidth * savedWidth, parentHeight * savedHeight);
  12315. this.fixAndSetPosition();
  12316. },
  12317. mustExec: true
  12318. });
  12319. }
  12320. #resizerPointermove(name, event) {
  12321. const [parentWidth, parentHeight] = this.parentDimensions;
  12322. const savedX = this.x;
  12323. const savedY = this.y;
  12324. const savedWidth = this.width;
  12325. const savedHeight = this.height;
  12326. const minWidth = AnnotationEditor.MIN_SIZE / parentWidth;
  12327. const minHeight = AnnotationEditor.MIN_SIZE / parentHeight;
  12328. const round = x => Math.round(x * 10000) / 10000;
  12329. const rotationMatrix = this.#getRotationMatrix(this.rotation);
  12330. const transf = (x, y) => [rotationMatrix[0] * x + rotationMatrix[2] * y, rotationMatrix[1] * x + rotationMatrix[3] * y];
  12331. const invRotationMatrix = this.#getRotationMatrix(360 - this.rotation);
  12332. const invTransf = (x, y) => [invRotationMatrix[0] * x + invRotationMatrix[2] * y, invRotationMatrix[1] * x + invRotationMatrix[3] * y];
  12333. let getPoint;
  12334. let getOpposite;
  12335. let isDiagonal = false;
  12336. let isHorizontal = false;
  12337. switch (name) {
  12338. case "topLeft":
  12339. isDiagonal = true;
  12340. getPoint = (w, h) => [0, 0];
  12341. getOpposite = (w, h) => [w, h];
  12342. break;
  12343. case "topMiddle":
  12344. getPoint = (w, h) => [w / 2, 0];
  12345. getOpposite = (w, h) => [w / 2, h];
  12346. break;
  12347. case "topRight":
  12348. isDiagonal = true;
  12349. getPoint = (w, h) => [w, 0];
  12350. getOpposite = (w, h) => [0, h];
  12351. break;
  12352. case "middleRight":
  12353. isHorizontal = true;
  12354. getPoint = (w, h) => [w, h / 2];
  12355. getOpposite = (w, h) => [0, h / 2];
  12356. break;
  12357. case "bottomRight":
  12358. isDiagonal = true;
  12359. getPoint = (w, h) => [w, h];
  12360. getOpposite = (w, h) => [0, 0];
  12361. break;
  12362. case "bottomMiddle":
  12363. getPoint = (w, h) => [w / 2, h];
  12364. getOpposite = (w, h) => [w / 2, 0];
  12365. break;
  12366. case "bottomLeft":
  12367. isDiagonal = true;
  12368. getPoint = (w, h) => [0, h];
  12369. getOpposite = (w, h) => [w, 0];
  12370. break;
  12371. case "middleLeft":
  12372. isHorizontal = true;
  12373. getPoint = (w, h) => [0, h / 2];
  12374. getOpposite = (w, h) => [w, h / 2];
  12375. break;
  12376. }
  12377. const point = getPoint(savedWidth, savedHeight);
  12378. const oppositePoint = getOpposite(savedWidth, savedHeight);
  12379. let transfOppositePoint = transf(...oppositePoint);
  12380. const oppositeX = round(savedX + transfOppositePoint[0]);
  12381. const oppositeY = round(savedY + transfOppositePoint[1]);
  12382. let ratioX = 1;
  12383. let ratioY = 1;
  12384. let [deltaX, deltaY] = this.screenToPageTranslation(event.movementX, event.movementY);
  12385. [deltaX, deltaY] = invTransf(deltaX / parentWidth, deltaY / parentHeight);
  12386. if (isDiagonal) {
  12387. const oldDiag = Math.hypot(savedWidth, savedHeight);
  12388. 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);
  12389. } else if (isHorizontal) {
  12390. ratioX = Math.max(minWidth, Math.min(1, Math.abs(oppositePoint[0] - point[0] - deltaX))) / savedWidth;
  12391. } else {
  12392. ratioY = Math.max(minHeight, Math.min(1, Math.abs(oppositePoint[1] - point[1] - deltaY))) / savedHeight;
  12393. }
  12394. const newWidth = round(savedWidth * ratioX);
  12395. const newHeight = round(savedHeight * ratioY);
  12396. transfOppositePoint = transf(...getOpposite(newWidth, newHeight));
  12397. const newX = oppositeX - transfOppositePoint[0];
  12398. const newY = oppositeY - transfOppositePoint[1];
  12399. this.width = newWidth;
  12400. this.height = newHeight;
  12401. this.x = newX;
  12402. this.y = newY;
  12403. this.setDims(parentWidth * newWidth, parentHeight * newHeight);
  12404. this.fixAndSetPosition();
  12405. }
  12406. altTextFinish() {
  12407. this.#altText?.finish();
  12408. }
  12409. async addEditToolbar() {
  12410. if (this.#editToolbar || this.#isInEditMode) {
  12411. return this.#editToolbar;
  12412. }
  12413. this.#editToolbar = new toolbar.EditorToolbar(this);
  12414. this.div.append(this.#editToolbar.render());
  12415. if (this.#altText) {
  12416. this.#editToolbar.addAltTextButton(await this.#altText.render());
  12417. }
  12418. return this.#editToolbar;
  12419. }
  12420. removeEditToolbar() {
  12421. if (!this.#editToolbar) {
  12422. return;
  12423. }
  12424. this.#editToolbar.remove();
  12425. this.#editToolbar = null;
  12426. this.#altText?.destroy();
  12427. }
  12428. getClientDimensions() {
  12429. return this.div.getBoundingClientRect();
  12430. }
  12431. async addAltTextButton() {
  12432. if (this.#altText) {
  12433. return;
  12434. }
  12435. AltText.initialize(AnnotationEditor._l10nPromise);
  12436. this.#altText = new AltText(this);
  12437. await this.addEditToolbar();
  12438. }
  12439. get altTextData() {
  12440. return this.#altText?.data;
  12441. }
  12442. set altTextData(data) {
  12443. if (!this.#altText) {
  12444. return;
  12445. }
  12446. this.#altText.data = data;
  12447. }
  12448. hasAltText() {
  12449. return !this.#altText?.isEmpty();
  12450. }
  12451. render() {
  12452. this.div = document.createElement("div");
  12453. this.div.setAttribute("data-editor-rotation", (360 - this.rotation) % 360);
  12454. this.div.className = this.name;
  12455. this.div.setAttribute("id", this.id);
  12456. this.div.tabIndex = this.#disabled ? -1 : 0;
  12457. if (!this._isVisible) {
  12458. this.div.classList.add("hidden");
  12459. }
  12460. this.setInForeground();
  12461. this.div.addEventListener("focusin", this.#boundFocusin);
  12462. this.div.addEventListener("focusout", this.#boundFocusout);
  12463. const [parentWidth, parentHeight] = this.parentDimensions;
  12464. if (this.parentRotation % 180 !== 0) {
  12465. this.div.style.maxWidth = `${(100 * parentHeight / parentWidth).toFixed(2)}%`;
  12466. this.div.style.maxHeight = `${(100 * parentWidth / parentHeight).toFixed(2)}%`;
  12467. }
  12468. const [tx, ty] = this.getInitialTranslation();
  12469. this.translate(tx, ty);
  12470. (0,tools.bindEvents)(this, this.div, ["pointerdown"]);
  12471. return this.div;
  12472. }
  12473. pointerdown(event) {
  12474. const {
  12475. isMac
  12476. } = util.FeatureTest.platform;
  12477. if (event.button !== 0 || event.ctrlKey && isMac) {
  12478. event.preventDefault();
  12479. return;
  12480. }
  12481. this.#hasBeenClicked = true;
  12482. if (this._isDraggable) {
  12483. this.#setUpDragSession(event);
  12484. return;
  12485. }
  12486. this.#selectOnPointerEvent(event);
  12487. }
  12488. #selectOnPointerEvent(event) {
  12489. const {
  12490. isMac
  12491. } = util.FeatureTest.platform;
  12492. if (event.ctrlKey && !isMac || event.shiftKey || event.metaKey && isMac) {
  12493. this.parent.toggleSelected(this);
  12494. } else {
  12495. this.parent.setSelected(this);
  12496. }
  12497. }
  12498. #setUpDragSession(event) {
  12499. const isSelected = this._uiManager.isSelected(this);
  12500. this._uiManager.setUpDragSession();
  12501. let pointerMoveOptions, pointerMoveCallback;
  12502. if (isSelected) {
  12503. this.div.classList.add("moving");
  12504. pointerMoveOptions = {
  12505. passive: true,
  12506. capture: true
  12507. };
  12508. this.#prevDragX = event.clientX;
  12509. this.#prevDragY = event.clientY;
  12510. pointerMoveCallback = e => {
  12511. const {
  12512. clientX: x,
  12513. clientY: y
  12514. } = e;
  12515. const [tx, ty] = this.screenToPageTranslation(x - this.#prevDragX, y - this.#prevDragY);
  12516. this.#prevDragX = x;
  12517. this.#prevDragY = y;
  12518. this._uiManager.dragSelectedEditors(tx, ty);
  12519. };
  12520. window.addEventListener("pointermove", pointerMoveCallback, pointerMoveOptions);
  12521. }
  12522. const pointerUpCallback = () => {
  12523. window.removeEventListener("pointerup", pointerUpCallback);
  12524. window.removeEventListener("blur", pointerUpCallback);
  12525. if (isSelected) {
  12526. this.div.classList.remove("moving");
  12527. window.removeEventListener("pointermove", pointerMoveCallback, pointerMoveOptions);
  12528. }
  12529. this.#hasBeenClicked = false;
  12530. if (!this._uiManager.endDragSession()) {
  12531. this.#selectOnPointerEvent(event);
  12532. }
  12533. };
  12534. window.addEventListener("pointerup", pointerUpCallback);
  12535. window.addEventListener("blur", pointerUpCallback);
  12536. }
  12537. moveInDOM() {
  12538. if (this.#moveInDOMTimeout) {
  12539. clearTimeout(this.#moveInDOMTimeout);
  12540. }
  12541. this.#moveInDOMTimeout = setTimeout(() => {
  12542. this.#moveInDOMTimeout = null;
  12543. this.parent?.moveEditorInDOM(this);
  12544. }, 0);
  12545. }
  12546. _setParentAndPosition(parent, x, y) {
  12547. parent.changeParent(this);
  12548. this.x = x;
  12549. this.y = y;
  12550. this.fixAndSetPosition();
  12551. }
  12552. getRect(tx, ty, rotation = this.rotation) {
  12553. const scale = this.parentScale;
  12554. const [pageWidth, pageHeight] = this.pageDimensions;
  12555. const [pageX, pageY] = this.pageTranslation;
  12556. const shiftX = tx / scale;
  12557. const shiftY = ty / scale;
  12558. const x = this.x * pageWidth;
  12559. const y = this.y * pageHeight;
  12560. const width = this.width * pageWidth;
  12561. const height = this.height * pageHeight;
  12562. switch (rotation) {
  12563. case 0:
  12564. return [x + shiftX + pageX, pageHeight - y - shiftY - height + pageY, x + shiftX + width + pageX, pageHeight - y - shiftY + pageY];
  12565. case 90:
  12566. return [x + shiftY + pageX, pageHeight - y + shiftX + pageY, x + shiftY + height + pageX, pageHeight - y + shiftX + width + pageY];
  12567. case 180:
  12568. return [x - shiftX - width + pageX, pageHeight - y + shiftY + pageY, x - shiftX + pageX, pageHeight - y + shiftY + height + pageY];
  12569. case 270:
  12570. return [x - shiftY - height + pageX, pageHeight - y - shiftX - width + pageY, x - shiftY + pageX, pageHeight - y - shiftX + pageY];
  12571. default:
  12572. throw new Error("Invalid rotation");
  12573. }
  12574. }
  12575. getRectInCurrentCoords(rect, pageHeight) {
  12576. const [x1, y1, x2, y2] = rect;
  12577. const width = x2 - x1;
  12578. const height = y2 - y1;
  12579. switch (this.rotation) {
  12580. case 0:
  12581. return [x1, pageHeight - y2, width, height];
  12582. case 90:
  12583. return [x1, pageHeight - y1, height, width];
  12584. case 180:
  12585. return [x2, pageHeight - y1, width, height];
  12586. case 270:
  12587. return [x2, pageHeight - y2, height, width];
  12588. default:
  12589. throw new Error("Invalid rotation");
  12590. }
  12591. }
  12592. onceAdded() {}
  12593. isEmpty() {
  12594. return false;
  12595. }
  12596. enableEditMode() {
  12597. this.#isInEditMode = true;
  12598. }
  12599. disableEditMode() {
  12600. this.#isInEditMode = false;
  12601. }
  12602. isInEditMode() {
  12603. return this.#isInEditMode;
  12604. }
  12605. shouldGetKeyboardEvents() {
  12606. return this.#isResizerEnabledForKeyboard;
  12607. }
  12608. needsToBeRebuilt() {
  12609. return this.div && !this.isAttachedToDOM;
  12610. }
  12611. rebuild() {
  12612. this.div?.addEventListener("focusin", this.#boundFocusin);
  12613. this.div?.addEventListener("focusout", this.#boundFocusout);
  12614. }
  12615. rotate(_angle) {}
  12616. serialize(isForCopying = false, context = null) {
  12617. (0,util.unreachable)("An editor must be serializable");
  12618. }
  12619. static deserialize(data, parent, uiManager) {
  12620. const editor = new this.prototype.constructor({
  12621. parent,
  12622. id: parent.getNextId(),
  12623. uiManager
  12624. });
  12625. editor.rotation = data.rotation;
  12626. const [pageWidth, pageHeight] = editor.pageDimensions;
  12627. const [x, y, width, height] = editor.getRectInCurrentCoords(data.rect, pageHeight);
  12628. editor.x = x / pageWidth;
  12629. editor.y = y / pageHeight;
  12630. editor.width = width / pageWidth;
  12631. editor.height = height / pageHeight;
  12632. return editor;
  12633. }
  12634. get hasBeenModified() {
  12635. return !!this.annotationElementId && (this.deleted || this.serialize() !== null);
  12636. }
  12637. remove() {
  12638. this.div.removeEventListener("focusin", this.#boundFocusin);
  12639. this.div.removeEventListener("focusout", this.#boundFocusout);
  12640. if (!this.isEmpty()) {
  12641. this.commit();
  12642. }
  12643. if (this.parent) {
  12644. this.parent.remove(this);
  12645. } else {
  12646. this._uiManager.removeEditor(this);
  12647. }
  12648. if (this.#moveInDOMTimeout) {
  12649. clearTimeout(this.#moveInDOMTimeout);
  12650. this.#moveInDOMTimeout = null;
  12651. }
  12652. this.#stopResizing();
  12653. this.removeEditToolbar();
  12654. if (this.#telemetryTimeouts) {
  12655. for (const timeout of this.#telemetryTimeouts.values()) {
  12656. clearTimeout(timeout);
  12657. }
  12658. this.#telemetryTimeouts = null;
  12659. }
  12660. this.parent = null;
  12661. }
  12662. get isResizable() {
  12663. return false;
  12664. }
  12665. makeResizable() {
  12666. if (this.isResizable) {
  12667. this.#createResizers();
  12668. this.#resizersDiv.classList.remove("hidden");
  12669. (0,tools.bindEvents)(this, this.div, ["keydown"]);
  12670. }
  12671. }
  12672. get toolbarPosition() {
  12673. return null;
  12674. }
  12675. keydown(event) {
  12676. if (!this.isResizable || event.target !== this.div || event.key !== "Enter") {
  12677. return;
  12678. }
  12679. this._uiManager.setSelected(this);
  12680. this.#savedDimensions = {
  12681. savedX: this.x,
  12682. savedY: this.y,
  12683. savedWidth: this.width,
  12684. savedHeight: this.height
  12685. };
  12686. const children = this.#resizersDiv.children;
  12687. if (!this.#allResizerDivs) {
  12688. this.#allResizerDivs = Array.from(children);
  12689. const boundResizerKeydown = this.#resizerKeydown.bind(this);
  12690. const boundResizerBlur = this.#resizerBlur.bind(this);
  12691. for (const div of this.#allResizerDivs) {
  12692. const name = div.getAttribute("data-resizer-name");
  12693. div.setAttribute("role", "spinbutton");
  12694. div.addEventListener("keydown", boundResizerKeydown);
  12695. div.addEventListener("blur", boundResizerBlur);
  12696. div.addEventListener("focus", this.#resizerFocus.bind(this, name));
  12697. AnnotationEditor._l10nPromise.get(`pdfjs-editor-resizer-label-${name}`).then(msg => div.setAttribute("aria-label", msg));
  12698. }
  12699. }
  12700. const first = this.#allResizerDivs[0];
  12701. let firstPosition = 0;
  12702. for (const div of children) {
  12703. if (div === first) {
  12704. break;
  12705. }
  12706. firstPosition++;
  12707. }
  12708. const nextFirstPosition = (360 - this.rotation + this.parentRotation) % 360 / 90 * (this.#allResizerDivs.length / 4);
  12709. if (nextFirstPosition !== firstPosition) {
  12710. if (nextFirstPosition < firstPosition) {
  12711. for (let i = 0; i < firstPosition - nextFirstPosition; i++) {
  12712. this.#resizersDiv.append(this.#resizersDiv.firstChild);
  12713. }
  12714. } else if (nextFirstPosition > firstPosition) {
  12715. for (let i = 0; i < nextFirstPosition - firstPosition; i++) {
  12716. this.#resizersDiv.firstChild.before(this.#resizersDiv.lastChild);
  12717. }
  12718. }
  12719. let i = 0;
  12720. for (const child of children) {
  12721. const div = this.#allResizerDivs[i++];
  12722. const name = div.getAttribute("data-resizer-name");
  12723. AnnotationEditor._l10nPromise.get(`pdfjs-editor-resizer-label-${name}`).then(msg => child.setAttribute("aria-label", msg));
  12724. }
  12725. }
  12726. this.#setResizerTabIndex(0);
  12727. this.#isResizerEnabledForKeyboard = true;
  12728. this.#resizersDiv.firstChild.focus({
  12729. focusVisible: true
  12730. });
  12731. event.preventDefault();
  12732. event.stopImmediatePropagation();
  12733. }
  12734. #resizerKeydown(event) {
  12735. AnnotationEditor._resizerKeyboardManager.exec(this, event);
  12736. }
  12737. #resizerBlur(event) {
  12738. if (this.#isResizerEnabledForKeyboard && event.relatedTarget?.parentNode !== this.#resizersDiv) {
  12739. this.#stopResizing();
  12740. }
  12741. }
  12742. #resizerFocus(name) {
  12743. this.#focusedResizerName = this.#isResizerEnabledForKeyboard ? name : "";
  12744. }
  12745. #setResizerTabIndex(value) {
  12746. if (!this.#allResizerDivs) {
  12747. return;
  12748. }
  12749. for (const div of this.#allResizerDivs) {
  12750. div.tabIndex = value;
  12751. }
  12752. }
  12753. _resizeWithKeyboard(x, y) {
  12754. if (!this.#isResizerEnabledForKeyboard) {
  12755. return;
  12756. }
  12757. this.#resizerPointermove(this.#focusedResizerName, {
  12758. movementX: x,
  12759. movementY: y
  12760. });
  12761. }
  12762. #stopResizing() {
  12763. this.#isResizerEnabledForKeyboard = false;
  12764. this.#setResizerTabIndex(-1);
  12765. if (this.#savedDimensions) {
  12766. const {
  12767. savedX,
  12768. savedY,
  12769. savedWidth,
  12770. savedHeight
  12771. } = this.#savedDimensions;
  12772. this.#addResizeToUndoStack(savedX, savedY, savedWidth, savedHeight);
  12773. this.#savedDimensions = null;
  12774. }
  12775. }
  12776. _stopResizingWithKeyboard() {
  12777. this.#stopResizing();
  12778. this.div.focus();
  12779. }
  12780. select() {
  12781. this.makeResizable();
  12782. this.div?.classList.add("selectedEditor");
  12783. if (!this.#editToolbar) {
  12784. this.addEditToolbar().then(() => {
  12785. if (this.div?.classList.contains("selectedEditor")) {
  12786. this.#editToolbar?.show();
  12787. }
  12788. });
  12789. return;
  12790. }
  12791. this.#editToolbar?.show();
  12792. }
  12793. unselect() {
  12794. this.#resizersDiv?.classList.add("hidden");
  12795. this.div?.classList.remove("selectedEditor");
  12796. if (this.div?.contains(document.activeElement)) {
  12797. this._uiManager.currentLayer.div.focus({
  12798. preventScroll: true
  12799. });
  12800. }
  12801. this.#editToolbar?.hide();
  12802. }
  12803. updateParams(type, value) {}
  12804. disableEditing() {}
  12805. enableEditing() {}
  12806. enterInEditMode() {}
  12807. getImageForAltText() {
  12808. return null;
  12809. }
  12810. get contentDiv() {
  12811. return this.div;
  12812. }
  12813. get isEditing() {
  12814. return this.#isEditing;
  12815. }
  12816. set isEditing(value) {
  12817. this.#isEditing = value;
  12818. if (!this.parent) {
  12819. return;
  12820. }
  12821. if (value) {
  12822. this.parent.setSelected(this);
  12823. this.parent.setActiveEditor(this);
  12824. } else {
  12825. this.parent.setActiveEditor(null);
  12826. }
  12827. }
  12828. setAspectRatio(width, height) {
  12829. this.#keepAspectRatio = true;
  12830. const aspectRatio = width / height;
  12831. const {
  12832. style
  12833. } = this.div;
  12834. style.aspectRatio = aspectRatio;
  12835. style.height = "auto";
  12836. }
  12837. static get MIN_SIZE() {
  12838. return 16;
  12839. }
  12840. static canCreateNewEmptyEditor() {
  12841. return true;
  12842. }
  12843. get telemetryInitialData() {
  12844. return {
  12845. action: "added"
  12846. };
  12847. }
  12848. get telemetryFinalData() {
  12849. return null;
  12850. }
  12851. _reportTelemetry(data, mustWait = false) {
  12852. if (mustWait) {
  12853. this.#telemetryTimeouts ||= new Map();
  12854. const {
  12855. action
  12856. } = data;
  12857. let timeout = this.#telemetryTimeouts.get(action);
  12858. if (timeout) {
  12859. clearTimeout(timeout);
  12860. }
  12861. timeout = setTimeout(() => {
  12862. this._reportTelemetry(data);
  12863. this.#telemetryTimeouts.delete(action);
  12864. if (this.#telemetryTimeouts.size === 0) {
  12865. this.#telemetryTimeouts = null;
  12866. }
  12867. }, AnnotationEditor._telemetryTimeout);
  12868. this.#telemetryTimeouts.set(action, timeout);
  12869. return;
  12870. }
  12871. data.type ||= this.editorType;
  12872. this._uiManager._eventBus.dispatch("reporttelemetry", {
  12873. source: this,
  12874. details: {
  12875. type: "editing",
  12876. data
  12877. }
  12878. });
  12879. }
  12880. show(visible = this._isVisible) {
  12881. this.div.classList.toggle("hidden", !visible);
  12882. this._isVisible = visible;
  12883. }
  12884. enable() {
  12885. if (this.div) {
  12886. this.div.tabIndex = 0;
  12887. }
  12888. this.#disabled = false;
  12889. }
  12890. disable() {
  12891. if (this.div) {
  12892. this.div.tabIndex = -1;
  12893. }
  12894. this.#disabled = true;
  12895. }
  12896. renderAnnotationElement(annotation) {
  12897. let content = annotation.container.querySelector(".annotationContent");
  12898. if (!content) {
  12899. content = document.createElement("div");
  12900. content.classList.add("annotationContent", this.editorType);
  12901. annotation.container.prepend(content);
  12902. } else if (content.nodeName === "CANVAS") {
  12903. const canvas = content;
  12904. content = document.createElement("div");
  12905. content.classList.add("annotationContent", this.editorType);
  12906. canvas.before(content);
  12907. }
  12908. return content;
  12909. }
  12910. resetAnnotationElement(annotation) {
  12911. const {
  12912. firstChild
  12913. } = annotation.container;
  12914. if (firstChild.nodeName === "DIV" && firstChild.classList.contains("annotationContent")) {
  12915. firstChild.remove();
  12916. }
  12917. }
  12918. }
  12919. class FakeEditor extends AnnotationEditor {
  12920. constructor(params) {
  12921. super(params);
  12922. this.annotationElementId = params.annotationElementId;
  12923. this.deleted = true;
  12924. }
  12925. serialize() {
  12926. return {
  12927. id: this.annotationElementId,
  12928. deleted: true,
  12929. pageIndex: this.pageIndex
  12930. };
  12931. }
  12932. }
  12933. /***/ }),
  12934. /***/ 61:
  12935. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  12936. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  12937. /* harmony export */ FreeOutliner: () => (/* binding */ FreeOutliner),
  12938. /* harmony export */ Outliner: () => (/* binding */ Outliner)
  12939. /* harmony export */ });
  12940. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(292);
  12941. class Outliner {
  12942. #box;
  12943. #verticalEdges = [];
  12944. #intervals = [];
  12945. constructor(boxes, borderWidth = 0, innerMargin = 0, isLTR = true) {
  12946. let minX = Infinity;
  12947. let maxX = -Infinity;
  12948. let minY = Infinity;
  12949. let maxY = -Infinity;
  12950. const NUMBER_OF_DIGITS = 4;
  12951. const EPSILON = 10 ** -NUMBER_OF_DIGITS;
  12952. for (const {
  12953. x,
  12954. y,
  12955. width,
  12956. height
  12957. } of boxes) {
  12958. const x1 = Math.floor((x - borderWidth) / EPSILON) * EPSILON;
  12959. const x2 = Math.ceil((x + width + borderWidth) / EPSILON) * EPSILON;
  12960. const y1 = Math.floor((y - borderWidth) / EPSILON) * EPSILON;
  12961. const y2 = Math.ceil((y + height + borderWidth) / EPSILON) * EPSILON;
  12962. const left = [x1, y1, y2, true];
  12963. const right = [x2, y1, y2, false];
  12964. this.#verticalEdges.push(left, right);
  12965. minX = Math.min(minX, x1);
  12966. maxX = Math.max(maxX, x2);
  12967. minY = Math.min(minY, y1);
  12968. maxY = Math.max(maxY, y2);
  12969. }
  12970. const bboxWidth = maxX - minX + 2 * innerMargin;
  12971. const bboxHeight = maxY - minY + 2 * innerMargin;
  12972. const shiftedMinX = minX - innerMargin;
  12973. const shiftedMinY = minY - innerMargin;
  12974. const lastEdge = this.#verticalEdges.at(isLTR ? -1 : -2);
  12975. const lastPoint = [lastEdge[0], lastEdge[2]];
  12976. for (const edge of this.#verticalEdges) {
  12977. const [x, y1, y2] = edge;
  12978. edge[0] = (x - shiftedMinX) / bboxWidth;
  12979. edge[1] = (y1 - shiftedMinY) / bboxHeight;
  12980. edge[2] = (y2 - shiftedMinY) / bboxHeight;
  12981. }
  12982. this.#box = {
  12983. x: shiftedMinX,
  12984. y: shiftedMinY,
  12985. width: bboxWidth,
  12986. height: bboxHeight,
  12987. lastPoint
  12988. };
  12989. }
  12990. getOutlines() {
  12991. this.#verticalEdges.sort((a, b) => a[0] - b[0] || a[1] - b[1] || a[2] - b[2]);
  12992. const outlineVerticalEdges = [];
  12993. for (const edge of this.#verticalEdges) {
  12994. if (edge[3]) {
  12995. outlineVerticalEdges.push(...this.#breakEdge(edge));
  12996. this.#insert(edge);
  12997. } else {
  12998. this.#remove(edge);
  12999. outlineVerticalEdges.push(...this.#breakEdge(edge));
  13000. }
  13001. }
  13002. return this.#getOutlines(outlineVerticalEdges);
  13003. }
  13004. #getOutlines(outlineVerticalEdges) {
  13005. const edges = [];
  13006. const allEdges = new Set();
  13007. for (const edge of outlineVerticalEdges) {
  13008. const [x, y1, y2] = edge;
  13009. edges.push([x, y1, edge], [x, y2, edge]);
  13010. }
  13011. edges.sort((a, b) => a[1] - b[1] || a[0] - b[0]);
  13012. for (let i = 0, ii = edges.length; i < ii; i += 2) {
  13013. const edge1 = edges[i][2];
  13014. const edge2 = edges[i + 1][2];
  13015. edge1.push(edge2);
  13016. edge2.push(edge1);
  13017. allEdges.add(edge1);
  13018. allEdges.add(edge2);
  13019. }
  13020. const outlines = [];
  13021. let outline;
  13022. while (allEdges.size > 0) {
  13023. const edge = allEdges.values().next().value;
  13024. let [x, y1, y2, edge1, edge2] = edge;
  13025. allEdges.delete(edge);
  13026. let lastPointX = x;
  13027. let lastPointY = y1;
  13028. outline = [x, y2];
  13029. outlines.push(outline);
  13030. while (true) {
  13031. let e;
  13032. if (allEdges.has(edge1)) {
  13033. e = edge1;
  13034. } else if (allEdges.has(edge2)) {
  13035. e = edge2;
  13036. } else {
  13037. break;
  13038. }
  13039. allEdges.delete(e);
  13040. [x, y1, y2, edge1, edge2] = e;
  13041. if (lastPointX !== x) {
  13042. outline.push(lastPointX, lastPointY, x, lastPointY === y1 ? y1 : y2);
  13043. lastPointX = x;
  13044. }
  13045. lastPointY = lastPointY === y1 ? y2 : y1;
  13046. }
  13047. outline.push(lastPointX, lastPointY);
  13048. }
  13049. return new HighlightOutline(outlines, this.#box);
  13050. }
  13051. #binarySearch(y) {
  13052. const array = this.#intervals;
  13053. let start = 0;
  13054. let end = array.length - 1;
  13055. while (start <= end) {
  13056. const middle = start + end >> 1;
  13057. const y1 = array[middle][0];
  13058. if (y1 === y) {
  13059. return middle;
  13060. }
  13061. if (y1 < y) {
  13062. start = middle + 1;
  13063. } else {
  13064. end = middle - 1;
  13065. }
  13066. }
  13067. return end + 1;
  13068. }
  13069. #insert([, y1, y2]) {
  13070. const index = this.#binarySearch(y1);
  13071. this.#intervals.splice(index, 0, [y1, y2]);
  13072. }
  13073. #remove([, y1, y2]) {
  13074. const index = this.#binarySearch(y1);
  13075. for (let i = index; i < this.#intervals.length; i++) {
  13076. const [start, end] = this.#intervals[i];
  13077. if (start !== y1) {
  13078. break;
  13079. }
  13080. if (start === y1 && end === y2) {
  13081. this.#intervals.splice(i, 1);
  13082. return;
  13083. }
  13084. }
  13085. for (let i = index - 1; i >= 0; i--) {
  13086. const [start, end] = this.#intervals[i];
  13087. if (start !== y1) {
  13088. break;
  13089. }
  13090. if (start === y1 && end === y2) {
  13091. this.#intervals.splice(i, 1);
  13092. return;
  13093. }
  13094. }
  13095. }
  13096. #breakEdge(edge) {
  13097. const [x, y1, y2] = edge;
  13098. const results = [[x, y1, y2]];
  13099. const index = this.#binarySearch(y2);
  13100. for (let i = 0; i < index; i++) {
  13101. const [start, end] = this.#intervals[i];
  13102. for (let j = 0, jj = results.length; j < jj; j++) {
  13103. const [, y3, y4] = results[j];
  13104. if (end <= y3 || y4 <= start) {
  13105. continue;
  13106. }
  13107. if (y3 >= start) {
  13108. if (y4 > end) {
  13109. results[j][1] = end;
  13110. } else {
  13111. if (jj === 1) {
  13112. return [];
  13113. }
  13114. results.splice(j, 1);
  13115. j--;
  13116. jj--;
  13117. }
  13118. continue;
  13119. }
  13120. results[j][2] = start;
  13121. if (y4 > end) {
  13122. results.push([x, end, y4]);
  13123. }
  13124. }
  13125. }
  13126. return results;
  13127. }
  13128. }
  13129. class Outline {
  13130. toSVGPath() {
  13131. throw new Error("Abstract method `toSVGPath` must be implemented.");
  13132. }
  13133. get box() {
  13134. throw new Error("Abstract getter `box` must be implemented.");
  13135. }
  13136. serialize(_bbox, _rotation) {
  13137. throw new Error("Abstract method `serialize` must be implemented.");
  13138. }
  13139. get free() {
  13140. return this instanceof FreeHighlightOutline;
  13141. }
  13142. }
  13143. class HighlightOutline extends Outline {
  13144. #box;
  13145. #outlines;
  13146. constructor(outlines, box) {
  13147. super();
  13148. this.#outlines = outlines;
  13149. this.#box = box;
  13150. }
  13151. toSVGPath() {
  13152. const buffer = [];
  13153. for (const polygon of this.#outlines) {
  13154. let [prevX, prevY] = polygon;
  13155. buffer.push(`M${prevX} ${prevY}`);
  13156. for (let i = 2; i < polygon.length; i += 2) {
  13157. const x = polygon[i];
  13158. const y = polygon[i + 1];
  13159. if (x === prevX) {
  13160. buffer.push(`V${y}`);
  13161. prevY = y;
  13162. } else if (y === prevY) {
  13163. buffer.push(`H${x}`);
  13164. prevX = x;
  13165. }
  13166. }
  13167. buffer.push("Z");
  13168. }
  13169. return buffer.join(" ");
  13170. }
  13171. serialize([blX, blY, trX, trY], _rotation) {
  13172. const outlines = [];
  13173. const width = trX - blX;
  13174. const height = trY - blY;
  13175. for (const outline of this.#outlines) {
  13176. const points = new Array(outline.length);
  13177. for (let i = 0; i < outline.length; i += 2) {
  13178. points[i] = blX + outline[i] * width;
  13179. points[i + 1] = trY - outline[i + 1] * height;
  13180. }
  13181. outlines.push(points);
  13182. }
  13183. return outlines;
  13184. }
  13185. get box() {
  13186. return this.#box;
  13187. }
  13188. }
  13189. class FreeOutliner {
  13190. #box;
  13191. #bottom = [];
  13192. #innerMargin;
  13193. #isLTR;
  13194. #top = [];
  13195. #last = new Float64Array(18);
  13196. #lastX;
  13197. #lastY;
  13198. #min;
  13199. #min_dist;
  13200. #scaleFactor;
  13201. #thickness;
  13202. #points = [];
  13203. static #MIN_DIST = 8;
  13204. static #MIN_DIFF = 2;
  13205. static #MIN = FreeOutliner.#MIN_DIST + FreeOutliner.#MIN_DIFF;
  13206. constructor({
  13207. x,
  13208. y
  13209. }, box, scaleFactor, thickness, isLTR, innerMargin = 0) {
  13210. this.#box = box;
  13211. this.#thickness = thickness * scaleFactor;
  13212. this.#isLTR = isLTR;
  13213. this.#last.set([NaN, NaN, NaN, NaN, x, y], 6);
  13214. this.#innerMargin = innerMargin;
  13215. this.#min_dist = FreeOutliner.#MIN_DIST * scaleFactor;
  13216. this.#min = FreeOutliner.#MIN * scaleFactor;
  13217. this.#scaleFactor = scaleFactor;
  13218. this.#points.push(x, y);
  13219. }
  13220. get free() {
  13221. return true;
  13222. }
  13223. isEmpty() {
  13224. return isNaN(this.#last[8]);
  13225. }
  13226. #getLastCoords() {
  13227. const lastTop = this.#last.subarray(4, 6);
  13228. const lastBottom = this.#last.subarray(16, 18);
  13229. const [x, y, width, height] = this.#box;
  13230. return [(this.#lastX + (lastTop[0] - lastBottom[0]) / 2 - x) / width, (this.#lastY + (lastTop[1] - lastBottom[1]) / 2 - y) / height, (this.#lastX + (lastBottom[0] - lastTop[0]) / 2 - x) / width, (this.#lastY + (lastBottom[1] - lastTop[1]) / 2 - y) / height];
  13231. }
  13232. add({
  13233. x,
  13234. y
  13235. }) {
  13236. this.#lastX = x;
  13237. this.#lastY = y;
  13238. const [layerX, layerY, layerWidth, layerHeight] = this.#box;
  13239. let [x1, y1, x2, y2] = this.#last.subarray(8, 12);
  13240. const diffX = x - x2;
  13241. const diffY = y - y2;
  13242. const d = Math.hypot(diffX, diffY);
  13243. if (d < this.#min) {
  13244. return false;
  13245. }
  13246. const diffD = d - this.#min_dist;
  13247. const K = diffD / d;
  13248. const shiftX = K * diffX;
  13249. const shiftY = K * diffY;
  13250. let x0 = x1;
  13251. let y0 = y1;
  13252. x1 = x2;
  13253. y1 = y2;
  13254. x2 += shiftX;
  13255. y2 += shiftY;
  13256. this.#points?.push(x, y);
  13257. const nX = -shiftY / diffD;
  13258. const nY = shiftX / diffD;
  13259. const thX = nX * this.#thickness;
  13260. const thY = nY * this.#thickness;
  13261. this.#last.set(this.#last.subarray(2, 8), 0);
  13262. this.#last.set([x2 + thX, y2 + thY], 4);
  13263. this.#last.set(this.#last.subarray(14, 18), 12);
  13264. this.#last.set([x2 - thX, y2 - thY], 16);
  13265. if (isNaN(this.#last[6])) {
  13266. if (this.#top.length === 0) {
  13267. this.#last.set([x1 + thX, y1 + thY], 2);
  13268. this.#top.push(NaN, NaN, NaN, NaN, (x1 + thX - layerX) / layerWidth, (y1 + thY - layerY) / layerHeight);
  13269. this.#last.set([x1 - thX, y1 - thY], 14);
  13270. this.#bottom.push(NaN, NaN, NaN, NaN, (x1 - thX - layerX) / layerWidth, (y1 - thY - layerY) / layerHeight);
  13271. }
  13272. this.#last.set([x0, y0, x1, y1, x2, y2], 6);
  13273. return !this.isEmpty();
  13274. }
  13275. this.#last.set([x0, y0, x1, y1, x2, y2], 6);
  13276. const angle = Math.abs(Math.atan2(y0 - y1, x0 - x1) - Math.atan2(shiftY, shiftX));
  13277. if (angle < Math.PI / 2) {
  13278. [x1, y1, x2, y2] = this.#last.subarray(2, 6);
  13279. this.#top.push(NaN, NaN, NaN, NaN, ((x1 + x2) / 2 - layerX) / layerWidth, ((y1 + y2) / 2 - layerY) / layerHeight);
  13280. [x1, y1, x0, y0] = this.#last.subarray(14, 18);
  13281. this.#bottom.push(NaN, NaN, NaN, NaN, ((x0 + x1) / 2 - layerX) / layerWidth, ((y0 + y1) / 2 - layerY) / layerHeight);
  13282. return true;
  13283. }
  13284. [x0, y0, x1, y1, x2, y2] = this.#last.subarray(0, 6);
  13285. this.#top.push(((x0 + 5 * x1) / 6 - layerX) / layerWidth, ((y0 + 5 * y1) / 6 - layerY) / layerHeight, ((5 * x1 + x2) / 6 - layerX) / layerWidth, ((5 * y1 + y2) / 6 - layerY) / layerHeight, ((x1 + x2) / 2 - layerX) / layerWidth, ((y1 + y2) / 2 - layerY) / layerHeight);
  13286. [x2, y2, x1, y1, x0, y0] = this.#last.subarray(12, 18);
  13287. this.#bottom.push(((x0 + 5 * x1) / 6 - layerX) / layerWidth, ((y0 + 5 * y1) / 6 - layerY) / layerHeight, ((5 * x1 + x2) / 6 - layerX) / layerWidth, ((5 * y1 + y2) / 6 - layerY) / layerHeight, ((x1 + x2) / 2 - layerX) / layerWidth, ((y1 + y2) / 2 - layerY) / layerHeight);
  13288. return true;
  13289. }
  13290. toSVGPath() {
  13291. if (this.isEmpty()) {
  13292. return "";
  13293. }
  13294. const top = this.#top;
  13295. const bottom = this.#bottom;
  13296. const lastTop = this.#last.subarray(4, 6);
  13297. const lastBottom = this.#last.subarray(16, 18);
  13298. const [x, y, width, height] = this.#box;
  13299. const [lastTopX, lastTopY, lastBottomX, lastBottomY] = this.#getLastCoords();
  13300. if (isNaN(this.#last[6]) && !this.isEmpty()) {
  13301. return `M${(this.#last[2] - x) / width} ${(this.#last[3] - y) / height} L${(this.#last[4] - x) / width} ${(this.#last[5] - y) / height} L${lastTopX} ${lastTopY} L${lastBottomX} ${lastBottomY} L${(this.#last[16] - x) / width} ${(this.#last[17] - y) / height} L${(this.#last[14] - x) / width} ${(this.#last[15] - y) / height} Z`;
  13302. }
  13303. const buffer = [];
  13304. buffer.push(`M${top[4]} ${top[5]}`);
  13305. for (let i = 6; i < top.length; i += 6) {
  13306. if (isNaN(top[i])) {
  13307. buffer.push(`L${top[i + 4]} ${top[i + 5]}`);
  13308. } else {
  13309. buffer.push(`C${top[i]} ${top[i + 1]} ${top[i + 2]} ${top[i + 3]} ${top[i + 4]} ${top[i + 5]}`);
  13310. }
  13311. }
  13312. buffer.push(`L${(lastTop[0] - x) / width} ${(lastTop[1] - y) / height} L${lastTopX} ${lastTopY} L${lastBottomX} ${lastBottomY} L${(lastBottom[0] - x) / width} ${(lastBottom[1] - y) / height}`);
  13313. for (let i = bottom.length - 6; i >= 6; i -= 6) {
  13314. if (isNaN(bottom[i])) {
  13315. buffer.push(`L${bottom[i + 4]} ${bottom[i + 5]}`);
  13316. } else {
  13317. buffer.push(`C${bottom[i]} ${bottom[i + 1]} ${bottom[i + 2]} ${bottom[i + 3]} ${bottom[i + 4]} ${bottom[i + 5]}`);
  13318. }
  13319. }
  13320. buffer.push(`L${bottom[4]} ${bottom[5]} Z`);
  13321. return buffer.join(" ");
  13322. }
  13323. getOutlines() {
  13324. const top = this.#top;
  13325. const bottom = this.#bottom;
  13326. const last = this.#last;
  13327. const lastTop = last.subarray(4, 6);
  13328. const lastBottom = last.subarray(16, 18);
  13329. const [layerX, layerY, layerWidth, layerHeight] = this.#box;
  13330. const points = new Float64Array((this.#points?.length ?? 0) + 2);
  13331. for (let i = 0, ii = points.length - 2; i < ii; i += 2) {
  13332. points[i] = (this.#points[i] - layerX) / layerWidth;
  13333. points[i + 1] = (this.#points[i + 1] - layerY) / layerHeight;
  13334. }
  13335. points[points.length - 2] = (this.#lastX - layerX) / layerWidth;
  13336. points[points.length - 1] = (this.#lastY - layerY) / layerHeight;
  13337. const [lastTopX, lastTopY, lastBottomX, lastBottomY] = this.#getLastCoords();
  13338. if (isNaN(last[6]) && !this.isEmpty()) {
  13339. const outline = new Float64Array(36);
  13340. outline.set([NaN, NaN, NaN, NaN, (last[2] - layerX) / layerWidth, (last[3] - layerY) / layerHeight, NaN, NaN, NaN, NaN, (last[4] - layerX) / layerWidth, (last[5] - layerY) / layerHeight, NaN, NaN, NaN, NaN, lastTopX, lastTopY, NaN, NaN, NaN, NaN, lastBottomX, lastBottomY, NaN, NaN, NaN, NaN, (last[16] - layerX) / layerWidth, (last[17] - layerY) / layerHeight, NaN, NaN, NaN, NaN, (last[14] - layerX) / layerWidth, (last[15] - layerY) / layerHeight], 0);
  13341. return new FreeHighlightOutline(outline, points, this.#box, this.#scaleFactor, this.#innerMargin, this.#isLTR);
  13342. }
  13343. const outline = new Float64Array(this.#top.length + 24 + this.#bottom.length);
  13344. let N = top.length;
  13345. for (let i = 0; i < N; i += 2) {
  13346. if (isNaN(top[i])) {
  13347. outline[i] = outline[i + 1] = NaN;
  13348. continue;
  13349. }
  13350. outline[i] = top[i];
  13351. outline[i + 1] = top[i + 1];
  13352. }
  13353. outline.set([NaN, NaN, NaN, NaN, (lastTop[0] - layerX) / layerWidth, (lastTop[1] - layerY) / layerHeight, NaN, NaN, NaN, NaN, lastTopX, lastTopY, NaN, NaN, NaN, NaN, lastBottomX, lastBottomY, NaN, NaN, NaN, NaN, (lastBottom[0] - layerX) / layerWidth, (lastBottom[1] - layerY) / layerHeight], N);
  13354. N += 24;
  13355. for (let i = bottom.length - 6; i >= 6; i -= 6) {
  13356. for (let j = 0; j < 6; j += 2) {
  13357. if (isNaN(bottom[i + j])) {
  13358. outline[N] = outline[N + 1] = NaN;
  13359. N += 2;
  13360. continue;
  13361. }
  13362. outline[N] = bottom[i + j];
  13363. outline[N + 1] = bottom[i + j + 1];
  13364. N += 2;
  13365. }
  13366. }
  13367. outline.set([NaN, NaN, NaN, NaN, bottom[4], bottom[5]], N);
  13368. return new FreeHighlightOutline(outline, points, this.#box, this.#scaleFactor, this.#innerMargin, this.#isLTR);
  13369. }
  13370. }
  13371. class FreeHighlightOutline extends Outline {
  13372. #box;
  13373. #bbox = null;
  13374. #innerMargin;
  13375. #isLTR;
  13376. #points;
  13377. #scaleFactor;
  13378. #outline;
  13379. constructor(outline, points, box, scaleFactor, innerMargin, isLTR) {
  13380. super();
  13381. this.#outline = outline;
  13382. this.#points = points;
  13383. this.#box = box;
  13384. this.#scaleFactor = scaleFactor;
  13385. this.#innerMargin = innerMargin;
  13386. this.#isLTR = isLTR;
  13387. this.#computeMinMax(isLTR);
  13388. const {
  13389. x,
  13390. y,
  13391. width,
  13392. height
  13393. } = this.#bbox;
  13394. for (let i = 0, ii = outline.length; i < ii; i += 2) {
  13395. outline[i] = (outline[i] - x) / width;
  13396. outline[i + 1] = (outline[i + 1] - y) / height;
  13397. }
  13398. for (let i = 0, ii = points.length; i < ii; i += 2) {
  13399. points[i] = (points[i] - x) / width;
  13400. points[i + 1] = (points[i + 1] - y) / height;
  13401. }
  13402. }
  13403. toSVGPath() {
  13404. const buffer = [`M${this.#outline[4]} ${this.#outline[5]}`];
  13405. for (let i = 6, ii = this.#outline.length; i < ii; i += 6) {
  13406. if (isNaN(this.#outline[i])) {
  13407. buffer.push(`L${this.#outline[i + 4]} ${this.#outline[i + 5]}`);
  13408. continue;
  13409. }
  13410. buffer.push(`C${this.#outline[i]} ${this.#outline[i + 1]} ${this.#outline[i + 2]} ${this.#outline[i + 3]} ${this.#outline[i + 4]} ${this.#outline[i + 5]}`);
  13411. }
  13412. buffer.push("Z");
  13413. return buffer.join(" ");
  13414. }
  13415. serialize([blX, blY, trX, trY], rotation) {
  13416. const width = trX - blX;
  13417. const height = trY - blY;
  13418. let outline;
  13419. let points;
  13420. switch (rotation) {
  13421. case 0:
  13422. outline = this.#rescale(this.#outline, blX, trY, width, -height);
  13423. points = this.#rescale(this.#points, blX, trY, width, -height);
  13424. break;
  13425. case 90:
  13426. outline = this.#rescaleAndSwap(this.#outline, blX, blY, width, height);
  13427. points = this.#rescaleAndSwap(this.#points, blX, blY, width, height);
  13428. break;
  13429. case 180:
  13430. outline = this.#rescale(this.#outline, trX, blY, -width, height);
  13431. points = this.#rescale(this.#points, trX, blY, -width, height);
  13432. break;
  13433. case 270:
  13434. outline = this.#rescaleAndSwap(this.#outline, trX, trY, -width, -height);
  13435. points = this.#rescaleAndSwap(this.#points, trX, trY, -width, -height);
  13436. break;
  13437. }
  13438. return {
  13439. outline: Array.from(outline),
  13440. points: [Array.from(points)]
  13441. };
  13442. }
  13443. #rescale(src, tx, ty, sx, sy) {
  13444. const dest = new Float64Array(src.length);
  13445. for (let i = 0, ii = src.length; i < ii; i += 2) {
  13446. dest[i] = tx + src[i] * sx;
  13447. dest[i + 1] = ty + src[i + 1] * sy;
  13448. }
  13449. return dest;
  13450. }
  13451. #rescaleAndSwap(src, tx, ty, sx, sy) {
  13452. const dest = new Float64Array(src.length);
  13453. for (let i = 0, ii = src.length; i < ii; i += 2) {
  13454. dest[i] = tx + src[i + 1] * sx;
  13455. dest[i + 1] = ty + src[i] * sy;
  13456. }
  13457. return dest;
  13458. }
  13459. #computeMinMax(isLTR) {
  13460. const outline = this.#outline;
  13461. let lastX = outline[4];
  13462. let lastY = outline[5];
  13463. let minX = lastX;
  13464. let minY = lastY;
  13465. let maxX = lastX;
  13466. let maxY = lastY;
  13467. let lastPointX = lastX;
  13468. let lastPointY = lastY;
  13469. const ltrCallback = isLTR ? Math.max : Math.min;
  13470. for (let i = 6, ii = outline.length; i < ii; i += 6) {
  13471. if (isNaN(outline[i])) {
  13472. minX = Math.min(minX, outline[i + 4]);
  13473. minY = Math.min(minY, outline[i + 5]);
  13474. maxX = Math.max(maxX, outline[i + 4]);
  13475. maxY = Math.max(maxY, outline[i + 5]);
  13476. if (lastPointY < outline[i + 5]) {
  13477. lastPointX = outline[i + 4];
  13478. lastPointY = outline[i + 5];
  13479. } else if (lastPointY === outline[i + 5]) {
  13480. lastPointX = ltrCallback(lastPointX, outline[i + 4]);
  13481. }
  13482. } else {
  13483. const bbox = _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.Util.bezierBoundingBox(lastX, lastY, ...outline.slice(i, i + 6));
  13484. minX = Math.min(minX, bbox[0]);
  13485. minY = Math.min(minY, bbox[1]);
  13486. maxX = Math.max(maxX, bbox[2]);
  13487. maxY = Math.max(maxY, bbox[3]);
  13488. if (lastPointY < bbox[3]) {
  13489. lastPointX = bbox[2];
  13490. lastPointY = bbox[3];
  13491. } else if (lastPointY === bbox[3]) {
  13492. lastPointX = ltrCallback(lastPointX, bbox[2]);
  13493. }
  13494. }
  13495. lastX = outline[i + 4];
  13496. lastY = outline[i + 5];
  13497. }
  13498. const x = minX - this.#innerMargin,
  13499. y = minY - this.#innerMargin,
  13500. width = maxX - minX + 2 * this.#innerMargin,
  13501. height = maxY - minY + 2 * this.#innerMargin;
  13502. this.#bbox = {
  13503. x,
  13504. y,
  13505. width,
  13506. height,
  13507. lastPoint: [lastPointX, lastPointY]
  13508. };
  13509. }
  13510. get box() {
  13511. return this.#bbox;
  13512. }
  13513. getNewOutline(thickness, innerMargin) {
  13514. const {
  13515. x,
  13516. y,
  13517. width,
  13518. height
  13519. } = this.#bbox;
  13520. const [layerX, layerY, layerWidth, layerHeight] = this.#box;
  13521. const sx = width * layerWidth;
  13522. const sy = height * layerHeight;
  13523. const tx = x * layerWidth + layerX;
  13524. const ty = y * layerHeight + layerY;
  13525. const outliner = new FreeOutliner({
  13526. x: this.#points[0] * sx + tx,
  13527. y: this.#points[1] * sy + ty
  13528. }, this.#box, this.#scaleFactor, thickness, this.#isLTR, innerMargin ?? this.#innerMargin);
  13529. for (let i = 2; i < this.#points.length; i += 2) {
  13530. outliner.add({
  13531. x: this.#points[i] * sx + tx,
  13532. y: this.#points[i + 1] * sy + ty
  13533. });
  13534. }
  13535. return outliner.getOutlines();
  13536. }
  13537. }
  13538. /***/ }),
  13539. /***/ 362:
  13540. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  13541. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  13542. /* harmony export */ EditorToolbar: () => (/* binding */ EditorToolbar),
  13543. /* harmony export */ HighlightToolbar: () => (/* binding */ HighlightToolbar)
  13544. /* harmony export */ });
  13545. /* harmony import */ var _display_utils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(419);
  13546. class EditorToolbar {
  13547. #toolbar = null;
  13548. #colorPicker = null;
  13549. #editor;
  13550. #buttons = null;
  13551. constructor(editor) {
  13552. this.#editor = editor;
  13553. }
  13554. render() {
  13555. const editToolbar = this.#toolbar = document.createElement("div");
  13556. editToolbar.className = "editToolbar";
  13557. editToolbar.setAttribute("role", "toolbar");
  13558. editToolbar.addEventListener("contextmenu", _display_utils_js__WEBPACK_IMPORTED_MODULE_0__.noContextMenu);
  13559. editToolbar.addEventListener("pointerdown", EditorToolbar.#pointerDown);
  13560. const buttons = this.#buttons = document.createElement("div");
  13561. buttons.className = "buttons";
  13562. editToolbar.append(buttons);
  13563. const position = this.#editor.toolbarPosition;
  13564. if (position) {
  13565. const {
  13566. style
  13567. } = editToolbar;
  13568. const x = this.#editor._uiManager.direction === "ltr" ? 1 - position[0] : position[0];
  13569. style.insetInlineEnd = `${100 * x}%`;
  13570. style.top = `calc(${100 * position[1]}% + var(--editor-toolbar-vert-offset))`;
  13571. }
  13572. this.#addDeleteButton();
  13573. return editToolbar;
  13574. }
  13575. static #pointerDown(e) {
  13576. e.stopPropagation();
  13577. }
  13578. #focusIn(e) {
  13579. this.#editor._focusEventsAllowed = false;
  13580. e.preventDefault();
  13581. e.stopPropagation();
  13582. }
  13583. #focusOut(e) {
  13584. this.#editor._focusEventsAllowed = true;
  13585. e.preventDefault();
  13586. e.stopPropagation();
  13587. }
  13588. #addListenersToElement(element) {
  13589. element.addEventListener("focusin", this.#focusIn.bind(this), {
  13590. capture: true
  13591. });
  13592. element.addEventListener("focusout", this.#focusOut.bind(this), {
  13593. capture: true
  13594. });
  13595. element.addEventListener("contextmenu", _display_utils_js__WEBPACK_IMPORTED_MODULE_0__.noContextMenu);
  13596. }
  13597. hide() {
  13598. this.#toolbar.classList.add("hidden");
  13599. this.#colorPicker?.hideDropdown();
  13600. }
  13601. show() {
  13602. this.#toolbar.classList.remove("hidden");
  13603. }
  13604. #addDeleteButton() {
  13605. const button = document.createElement("button");
  13606. button.className = "delete";
  13607. button.tabIndex = 0;
  13608. button.setAttribute("data-l10n-id", `pdfjs-editor-remove-${this.#editor.editorType}-button`);
  13609. this.#addListenersToElement(button);
  13610. button.addEventListener("click", e => {
  13611. this.#editor._uiManager.delete();
  13612. });
  13613. this.#buttons.append(button);
  13614. }
  13615. get #divider() {
  13616. const divider = document.createElement("div");
  13617. divider.className = "divider";
  13618. return divider;
  13619. }
  13620. addAltTextButton(button) {
  13621. this.#addListenersToElement(button);
  13622. this.#buttons.prepend(button, this.#divider);
  13623. }
  13624. addColorPicker(colorPicker) {
  13625. this.#colorPicker = colorPicker;
  13626. const button = colorPicker.renderButton();
  13627. this.#addListenersToElement(button);
  13628. this.#buttons.prepend(button, this.#divider);
  13629. }
  13630. remove() {
  13631. this.#toolbar.remove();
  13632. this.#colorPicker?.destroy();
  13633. this.#colorPicker = null;
  13634. }
  13635. }
  13636. class HighlightToolbar {
  13637. #buttons = null;
  13638. #toolbar = null;
  13639. #uiManager;
  13640. constructor(uiManager) {
  13641. this.#uiManager = uiManager;
  13642. }
  13643. #render() {
  13644. const editToolbar = this.#toolbar = document.createElement("div");
  13645. editToolbar.className = "editToolbar";
  13646. editToolbar.setAttribute("role", "toolbar");
  13647. editToolbar.addEventListener("contextmenu", _display_utils_js__WEBPACK_IMPORTED_MODULE_0__.noContextMenu);
  13648. const buttons = this.#buttons = document.createElement("div");
  13649. buttons.className = "buttons";
  13650. editToolbar.append(buttons);
  13651. this.#addHighlightButton();
  13652. return editToolbar;
  13653. }
  13654. #getLastPoint(boxes, isLTR) {
  13655. let lastY = 0;
  13656. let lastX = 0;
  13657. for (const box of boxes) {
  13658. const y = box.y + box.height;
  13659. if (y < lastY) {
  13660. continue;
  13661. }
  13662. const x = box.x + (isLTR ? box.width : 0);
  13663. if (y > lastY) {
  13664. lastX = x;
  13665. lastY = y;
  13666. continue;
  13667. }
  13668. if (isLTR) {
  13669. if (x > lastX) {
  13670. lastX = x;
  13671. }
  13672. } else if (x < lastX) {
  13673. lastX = x;
  13674. }
  13675. }
  13676. return [isLTR ? 1 - lastX : lastX, lastY];
  13677. }
  13678. show(parent, boxes, isLTR) {
  13679. const [x, y] = this.#getLastPoint(boxes, isLTR);
  13680. const {
  13681. style
  13682. } = this.#toolbar ||= this.#render();
  13683. parent.append(this.#toolbar);
  13684. style.insetInlineEnd = `${100 * x}%`;
  13685. style.top = `calc(${100 * y}% + var(--editor-toolbar-vert-offset))`;
  13686. }
  13687. hide() {
  13688. this.#toolbar.remove();
  13689. }
  13690. #addHighlightButton() {
  13691. const button = document.createElement("button");
  13692. button.className = "highlightButton";
  13693. button.tabIndex = 0;
  13694. button.setAttribute("data-l10n-id", `pdfjs-highlight-floating-button1`);
  13695. const span = document.createElement("span");
  13696. button.append(span);
  13697. span.className = "visuallyHidden";
  13698. span.setAttribute("data-l10n-id", "pdfjs-highlight-floating-button-label");
  13699. button.addEventListener("contextmenu", _display_utils_js__WEBPACK_IMPORTED_MODULE_0__.noContextMenu);
  13700. button.addEventListener("click", () => {
  13701. this.#uiManager.highlightSelection("floating_button");
  13702. });
  13703. this.#buttons.append(button);
  13704. }
  13705. }
  13706. /***/ }),
  13707. /***/ 830:
  13708. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  13709. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  13710. /* harmony export */ AnnotationEditorUIManager: () => (/* binding */ AnnotationEditorUIManager),
  13711. /* harmony export */ ColorManager: () => (/* binding */ ColorManager),
  13712. /* harmony export */ KeyboardManager: () => (/* binding */ KeyboardManager),
  13713. /* harmony export */ bindEvents: () => (/* binding */ bindEvents),
  13714. /* harmony export */ opacityToHex: () => (/* binding */ opacityToHex)
  13715. /* harmony export */ });
  13716. /* unused harmony export CommandManager */
  13717. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(292);
  13718. /* harmony import */ var _display_utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(419);
  13719. /* harmony import */ var _toolbar_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(362);
  13720. function bindEvents(obj, element, names) {
  13721. for (const name of names) {
  13722. element.addEventListener(name, obj[name].bind(obj));
  13723. }
  13724. }
  13725. function opacityToHex(opacity) {
  13726. return Math.round(Math.min(255, Math.max(1, 255 * opacity))).toString(16).padStart(2, "0");
  13727. }
  13728. class IdManager {
  13729. #id = 0;
  13730. constructor() {}
  13731. get id() {
  13732. return `${_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorPrefix}${this.#id++}`;
  13733. }
  13734. }
  13735. class ImageManager {
  13736. #baseId = (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.getUuid)();
  13737. #id = 0;
  13738. #cache = null;
  13739. static get _isSVGFittingCanvas() {
  13740. 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>`;
  13741. const canvas = new OffscreenCanvas(1, 3);
  13742. const ctx = canvas.getContext("2d");
  13743. const image = new Image();
  13744. image.src = svg;
  13745. const promise = image.decode().then(() => {
  13746. ctx.drawImage(image, 0, 0, 1, 1, 0, 0, 1, 3);
  13747. return new Uint32Array(ctx.getImageData(0, 0, 1, 1).data.buffer)[0] === 0;
  13748. });
  13749. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow)(this, "_isSVGFittingCanvas", promise);
  13750. }
  13751. async #get(key, rawData) {
  13752. this.#cache ||= new Map();
  13753. let data = this.#cache.get(key);
  13754. if (data === null) {
  13755. return null;
  13756. }
  13757. if (data?.bitmap) {
  13758. data.refCounter += 1;
  13759. return data;
  13760. }
  13761. try {
  13762. data ||= {
  13763. bitmap: null,
  13764. id: `image_${this.#baseId}_${this.#id++}`,
  13765. refCounter: 0,
  13766. isSvg: false
  13767. };
  13768. let image;
  13769. if (typeof rawData === "string") {
  13770. data.url = rawData;
  13771. image = await (0,_display_utils_js__WEBPACK_IMPORTED_MODULE_1__.fetchData)(rawData, "blob");
  13772. } else {
  13773. image = data.file = rawData;
  13774. }
  13775. if (image.type === "image/svg+xml") {
  13776. const mustRemoveAspectRatioPromise = ImageManager._isSVGFittingCanvas;
  13777. const fileReader = new FileReader();
  13778. const imageElement = new Image();
  13779. const imagePromise = new Promise((resolve, reject) => {
  13780. imageElement.onload = () => {
  13781. data.bitmap = imageElement;
  13782. data.isSvg = true;
  13783. resolve();
  13784. };
  13785. fileReader.onload = async () => {
  13786. const url = data.svgUrl = fileReader.result;
  13787. imageElement.src = (await mustRemoveAspectRatioPromise) ? `${url}#svgView(preserveAspectRatio(none))` : url;
  13788. };
  13789. imageElement.onerror = fileReader.onerror = reject;
  13790. });
  13791. fileReader.readAsDataURL(image);
  13792. await imagePromise;
  13793. } else {
  13794. data.bitmap = await createImageBitmap(image);
  13795. }
  13796. data.refCounter = 1;
  13797. } catch (e) {
  13798. console.error(e);
  13799. data = null;
  13800. }
  13801. this.#cache.set(key, data);
  13802. if (data) {
  13803. this.#cache.set(data.id, data);
  13804. }
  13805. return data;
  13806. }
  13807. async getFromFile(file) {
  13808. const {
  13809. lastModified,
  13810. name,
  13811. size,
  13812. type
  13813. } = file;
  13814. return this.#get(`${lastModified}_${name}_${size}_${type}`, file);
  13815. }
  13816. async getFromUrl(url) {
  13817. return this.#get(url, url);
  13818. }
  13819. async getFromId(id) {
  13820. this.#cache ||= new Map();
  13821. const data = this.#cache.get(id);
  13822. if (!data) {
  13823. return null;
  13824. }
  13825. if (data.bitmap) {
  13826. data.refCounter += 1;
  13827. return data;
  13828. }
  13829. if (data.file) {
  13830. return this.getFromFile(data.file);
  13831. }
  13832. return this.getFromUrl(data.url);
  13833. }
  13834. getSvgUrl(id) {
  13835. const data = this.#cache.get(id);
  13836. if (!data?.isSvg) {
  13837. return null;
  13838. }
  13839. return data.svgUrl;
  13840. }
  13841. deleteId(id) {
  13842. this.#cache ||= new Map();
  13843. const data = this.#cache.get(id);
  13844. if (!data) {
  13845. return;
  13846. }
  13847. data.refCounter -= 1;
  13848. if (data.refCounter !== 0) {
  13849. return;
  13850. }
  13851. data.bitmap = null;
  13852. }
  13853. isValidId(id) {
  13854. return id.startsWith(`image_${this.#baseId}_`);
  13855. }
  13856. }
  13857. class CommandManager {
  13858. #commands = [];
  13859. #locked = false;
  13860. #maxSize;
  13861. #position = -1;
  13862. constructor(maxSize = 128) {
  13863. this.#maxSize = maxSize;
  13864. }
  13865. add({
  13866. cmd,
  13867. undo,
  13868. post,
  13869. mustExec,
  13870. type = NaN,
  13871. overwriteIfSameType = false,
  13872. keepUndo = false
  13873. }) {
  13874. if (mustExec) {
  13875. cmd();
  13876. }
  13877. if (this.#locked) {
  13878. return;
  13879. }
  13880. const save = {
  13881. cmd,
  13882. undo,
  13883. post,
  13884. type
  13885. };
  13886. if (this.#position === -1) {
  13887. if (this.#commands.length > 0) {
  13888. this.#commands.length = 0;
  13889. }
  13890. this.#position = 0;
  13891. this.#commands.push(save);
  13892. return;
  13893. }
  13894. if (overwriteIfSameType && this.#commands[this.#position].type === type) {
  13895. if (keepUndo) {
  13896. save.undo = this.#commands[this.#position].undo;
  13897. }
  13898. this.#commands[this.#position] = save;
  13899. return;
  13900. }
  13901. const next = this.#position + 1;
  13902. if (next === this.#maxSize) {
  13903. this.#commands.splice(0, 1);
  13904. } else {
  13905. this.#position = next;
  13906. if (next < this.#commands.length) {
  13907. this.#commands.splice(next);
  13908. }
  13909. }
  13910. this.#commands.push(save);
  13911. }
  13912. undo() {
  13913. if (this.#position === -1) {
  13914. return;
  13915. }
  13916. this.#locked = true;
  13917. const {
  13918. undo,
  13919. post
  13920. } = this.#commands[this.#position];
  13921. undo();
  13922. post?.();
  13923. this.#locked = false;
  13924. this.#position -= 1;
  13925. }
  13926. redo() {
  13927. if (this.#position < this.#commands.length - 1) {
  13928. this.#position += 1;
  13929. this.#locked = true;
  13930. const {
  13931. cmd,
  13932. post
  13933. } = this.#commands[this.#position];
  13934. cmd();
  13935. post?.();
  13936. this.#locked = false;
  13937. }
  13938. }
  13939. hasSomethingToUndo() {
  13940. return this.#position !== -1;
  13941. }
  13942. hasSomethingToRedo() {
  13943. return this.#position < this.#commands.length - 1;
  13944. }
  13945. destroy() {
  13946. this.#commands = null;
  13947. }
  13948. }
  13949. class KeyboardManager {
  13950. constructor(callbacks) {
  13951. this.buffer = [];
  13952. this.callbacks = new Map();
  13953. this.allKeys = new Set();
  13954. const {
  13955. isMac
  13956. } = _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.FeatureTest.platform;
  13957. for (const [keys, callback, options = {}] of callbacks) {
  13958. for (const key of keys) {
  13959. const isMacKey = key.startsWith("mac+");
  13960. if (isMac && isMacKey) {
  13961. this.callbacks.set(key.slice(4), {
  13962. callback,
  13963. options
  13964. });
  13965. this.allKeys.add(key.split("+").at(-1));
  13966. } else if (!isMac && !isMacKey) {
  13967. this.callbacks.set(key, {
  13968. callback,
  13969. options
  13970. });
  13971. this.allKeys.add(key.split("+").at(-1));
  13972. }
  13973. }
  13974. }
  13975. }
  13976. #serialize(event) {
  13977. if (event.altKey) {
  13978. this.buffer.push("alt");
  13979. }
  13980. if (event.ctrlKey) {
  13981. this.buffer.push("ctrl");
  13982. }
  13983. if (event.metaKey) {
  13984. this.buffer.push("meta");
  13985. }
  13986. if (event.shiftKey) {
  13987. this.buffer.push("shift");
  13988. }
  13989. this.buffer.push(event.key);
  13990. const str = this.buffer.join("+");
  13991. this.buffer.length = 0;
  13992. return str;
  13993. }
  13994. exec(self, event) {
  13995. if (!this.allKeys.has(event.key)) {
  13996. return;
  13997. }
  13998. const info = this.callbacks.get(this.#serialize(event));
  13999. if (!info) {
  14000. return;
  14001. }
  14002. const {
  14003. callback,
  14004. options: {
  14005. bubbles = false,
  14006. args = [],
  14007. checker = null
  14008. }
  14009. } = info;
  14010. if (checker && !checker(self, event)) {
  14011. return;
  14012. }
  14013. callback.bind(self, ...args, event)();
  14014. if (!bubbles) {
  14015. event.stopPropagation();
  14016. event.preventDefault();
  14017. }
  14018. }
  14019. }
  14020. class ColorManager {
  14021. static _colorsMapping = new Map([["CanvasText", [0, 0, 0]], ["Canvas", [255, 255, 255]]]);
  14022. get _colors() {
  14023. const colors = new Map([["CanvasText", null], ["Canvas", null]]);
  14024. (0,_display_utils_js__WEBPACK_IMPORTED_MODULE_1__.getColorValues)(colors);
  14025. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow)(this, "_colors", colors);
  14026. }
  14027. convert(color) {
  14028. const rgb = (0,_display_utils_js__WEBPACK_IMPORTED_MODULE_1__.getRGB)(color);
  14029. if (!window.matchMedia("(forced-colors: active)").matches) {
  14030. return rgb;
  14031. }
  14032. for (const [name, RGB] of this._colors) {
  14033. if (RGB.every((x, i) => x === rgb[i])) {
  14034. return ColorManager._colorsMapping.get(name);
  14035. }
  14036. }
  14037. return rgb;
  14038. }
  14039. getHexCode(name) {
  14040. const rgb = this._colors.get(name);
  14041. if (!rgb) {
  14042. return name;
  14043. }
  14044. return _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.Util.makeHexColor(...rgb);
  14045. }
  14046. }
  14047. class AnnotationEditorUIManager {
  14048. #activeEditor = null;
  14049. #allEditors = new Map();
  14050. #allLayers = new Map();
  14051. #altTextManager = null;
  14052. #annotationStorage = null;
  14053. #changedExistingAnnotations = null;
  14054. #commandManager = new CommandManager();
  14055. #currentPageIndex = 0;
  14056. #deletedAnnotationsElementIds = new Set();
  14057. #draggingEditors = null;
  14058. #editorTypes = null;
  14059. #editorsToRescale = new Set();
  14060. #enableHighlightFloatingButton = false;
  14061. #filterFactory = null;
  14062. #focusMainContainerTimeoutId = null;
  14063. #highlightColors = null;
  14064. #highlightWhenShiftUp = false;
  14065. #highlightToolbar = null;
  14066. #idManager = new IdManager();
  14067. #isEnabled = false;
  14068. #isWaiting = false;
  14069. #lastActiveElement = null;
  14070. #mainHighlightColorPicker = null;
  14071. #mlManager = null;
  14072. #mode = _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorType.NONE;
  14073. #selectedEditors = new Set();
  14074. #selectedTextNode = null;
  14075. #pageColors = null;
  14076. #showAllStates = null;
  14077. #boundBlur = this.blur.bind(this);
  14078. #boundFocus = this.focus.bind(this);
  14079. #boundCopy = this.copy.bind(this);
  14080. #boundCut = this.cut.bind(this);
  14081. #boundPaste = this.paste.bind(this);
  14082. #boundKeydown = this.keydown.bind(this);
  14083. #boundKeyup = this.keyup.bind(this);
  14084. #boundOnEditingAction = this.onEditingAction.bind(this);
  14085. #boundOnPageChanging = this.onPageChanging.bind(this);
  14086. #boundOnScaleChanging = this.onScaleChanging.bind(this);
  14087. #boundSelectionChange = this.#selectionChange.bind(this);
  14088. #boundOnRotationChanging = this.onRotationChanging.bind(this);
  14089. #previousStates = {
  14090. isEditing: false,
  14091. isEmpty: true,
  14092. hasSomethingToUndo: false,
  14093. hasSomethingToRedo: false,
  14094. hasSelectedEditor: false,
  14095. hasSelectedText: false
  14096. };
  14097. #translation = [0, 0];
  14098. #translationTimeoutId = null;
  14099. #container = null;
  14100. #viewer = null;
  14101. static TRANSLATE_SMALL = 1;
  14102. static TRANSLATE_BIG = 10;
  14103. static get _keyboardManager() {
  14104. const proto = AnnotationEditorUIManager.prototype;
  14105. const arrowChecker = self => self.#container.contains(document.activeElement) && document.activeElement.tagName !== "BUTTON" && self.hasSomethingToControl();
  14106. const textInputChecker = (_self, {
  14107. target: el
  14108. }) => {
  14109. if (el instanceof HTMLInputElement) {
  14110. const {
  14111. type
  14112. } = el;
  14113. return type !== "text" && type !== "number";
  14114. }
  14115. return true;
  14116. };
  14117. const small = this.TRANSLATE_SMALL;
  14118. const big = this.TRANSLATE_BIG;
  14119. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow)(this, "_keyboardManager", new KeyboardManager([[["ctrl+a", "mac+meta+a"], proto.selectAll, {
  14120. checker: textInputChecker
  14121. }], [["ctrl+z", "mac+meta+z"], proto.undo, {
  14122. checker: textInputChecker
  14123. }], [["ctrl+y", "ctrl+shift+z", "mac+meta+shift+z", "ctrl+shift+Z", "mac+meta+shift+Z"], proto.redo, {
  14124. checker: textInputChecker
  14125. }], [["Backspace", "alt+Backspace", "ctrl+Backspace", "shift+Backspace", "mac+Backspace", "mac+alt+Backspace", "mac+ctrl+Backspace", "Delete", "ctrl+Delete", "shift+Delete", "mac+Delete"], proto.delete, {
  14126. checker: textInputChecker
  14127. }], [["Enter", "mac+Enter"], proto.addNewEditorFromKeyboard, {
  14128. checker: (self, {
  14129. target: el
  14130. }) => !(el instanceof HTMLButtonElement) && self.#container.contains(el) && !self.isEnterHandled
  14131. }], [[" ", "mac+ "], proto.addNewEditorFromKeyboard, {
  14132. checker: (self, {
  14133. target: el
  14134. }) => !(el instanceof HTMLButtonElement) && self.#container.contains(document.activeElement)
  14135. }], [["Escape", "mac+Escape"], proto.unselectAll], [["ArrowLeft", "mac+ArrowLeft"], proto.translateSelectedEditors, {
  14136. args: [-small, 0],
  14137. checker: arrowChecker
  14138. }], [["ctrl+ArrowLeft", "mac+shift+ArrowLeft"], proto.translateSelectedEditors, {
  14139. args: [-big, 0],
  14140. checker: arrowChecker
  14141. }], [["ArrowRight", "mac+ArrowRight"], proto.translateSelectedEditors, {
  14142. args: [small, 0],
  14143. checker: arrowChecker
  14144. }], [["ctrl+ArrowRight", "mac+shift+ArrowRight"], proto.translateSelectedEditors, {
  14145. args: [big, 0],
  14146. checker: arrowChecker
  14147. }], [["ArrowUp", "mac+ArrowUp"], proto.translateSelectedEditors, {
  14148. args: [0, -small],
  14149. checker: arrowChecker
  14150. }], [["ctrl+ArrowUp", "mac+shift+ArrowUp"], proto.translateSelectedEditors, {
  14151. args: [0, -big],
  14152. checker: arrowChecker
  14153. }], [["ArrowDown", "mac+ArrowDown"], proto.translateSelectedEditors, {
  14154. args: [0, small],
  14155. checker: arrowChecker
  14156. }], [["ctrl+ArrowDown", "mac+shift+ArrowDown"], proto.translateSelectedEditors, {
  14157. args: [0, big],
  14158. checker: arrowChecker
  14159. }]]));
  14160. }
  14161. constructor(container, viewer, altTextManager, eventBus, pdfDocument, pageColors, highlightColors, enableHighlightFloatingButton, mlManager) {
  14162. this.#container = container;
  14163. this.#viewer = viewer;
  14164. this.#altTextManager = altTextManager;
  14165. this._eventBus = eventBus;
  14166. this._eventBus._on("editingaction", this.#boundOnEditingAction);
  14167. this._eventBus._on("pagechanging", this.#boundOnPageChanging);
  14168. this._eventBus._on("scalechanging", this.#boundOnScaleChanging);
  14169. this._eventBus._on("rotationchanging", this.#boundOnRotationChanging);
  14170. this.#addSelectionListener();
  14171. this.#addKeyboardManager();
  14172. this.#annotationStorage = pdfDocument.annotationStorage;
  14173. this.#filterFactory = pdfDocument.filterFactory;
  14174. this.#pageColors = pageColors;
  14175. this.#highlightColors = highlightColors || null;
  14176. this.#enableHighlightFloatingButton = enableHighlightFloatingButton;
  14177. this.#mlManager = mlManager || null;
  14178. this.viewParameters = {
  14179. realScale: _display_utils_js__WEBPACK_IMPORTED_MODULE_1__.PixelsPerInch.PDF_TO_CSS_UNITS,
  14180. rotation: 0
  14181. };
  14182. this.isShiftKeyDown = false;
  14183. }
  14184. destroy() {
  14185. this.#removeKeyboardManager();
  14186. this.#removeFocusManager();
  14187. this._eventBus._off("editingaction", this.#boundOnEditingAction);
  14188. this._eventBus._off("pagechanging", this.#boundOnPageChanging);
  14189. this._eventBus._off("scalechanging", this.#boundOnScaleChanging);
  14190. this._eventBus._off("rotationchanging", this.#boundOnRotationChanging);
  14191. for (const layer of this.#allLayers.values()) {
  14192. layer.destroy();
  14193. }
  14194. this.#allLayers.clear();
  14195. this.#allEditors.clear();
  14196. this.#editorsToRescale.clear();
  14197. this.#activeEditor = null;
  14198. this.#selectedEditors.clear();
  14199. this.#commandManager.destroy();
  14200. this.#altTextManager?.destroy();
  14201. this.#highlightToolbar?.hide();
  14202. this.#highlightToolbar = null;
  14203. if (this.#focusMainContainerTimeoutId) {
  14204. clearTimeout(this.#focusMainContainerTimeoutId);
  14205. this.#focusMainContainerTimeoutId = null;
  14206. }
  14207. if (this.#translationTimeoutId) {
  14208. clearTimeout(this.#translationTimeoutId);
  14209. this.#translationTimeoutId = null;
  14210. }
  14211. this.#removeSelectionListener();
  14212. }
  14213. async mlGuess(data) {
  14214. return this.#mlManager?.guess(data) || null;
  14215. }
  14216. get hasMLManager() {
  14217. return !!this.#mlManager;
  14218. }
  14219. get hcmFilter() {
  14220. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow)(this, "hcmFilter", this.#pageColors ? this.#filterFactory.addHCMFilter(this.#pageColors.foreground, this.#pageColors.background) : "none");
  14221. }
  14222. get direction() {
  14223. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow)(this, "direction", getComputedStyle(this.#container).direction);
  14224. }
  14225. get highlightColors() {
  14226. 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);
  14227. }
  14228. get highlightColorNames() {
  14229. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow)(this, "highlightColorNames", this.highlightColors ? new Map(Array.from(this.highlightColors, e => e.reverse())) : null);
  14230. }
  14231. setMainHighlightColorPicker(colorPicker) {
  14232. this.#mainHighlightColorPicker = colorPicker;
  14233. }
  14234. editAltText(editor) {
  14235. this.#altTextManager?.editAltText(this, editor);
  14236. }
  14237. onPageChanging({
  14238. pageNumber
  14239. }) {
  14240. this.#currentPageIndex = pageNumber - 1;
  14241. }
  14242. focusMainContainer() {
  14243. this.#container.focus();
  14244. }
  14245. findParent(x, y) {
  14246. for (const layer of this.#allLayers.values()) {
  14247. const {
  14248. x: layerX,
  14249. y: layerY,
  14250. width,
  14251. height
  14252. } = layer.div.getBoundingClientRect();
  14253. if (x >= layerX && x <= layerX + width && y >= layerY && y <= layerY + height) {
  14254. return layer;
  14255. }
  14256. }
  14257. return null;
  14258. }
  14259. disableUserSelect(value = false) {
  14260. this.#viewer.classList.toggle("noUserSelect", value);
  14261. }
  14262. addShouldRescale(editor) {
  14263. this.#editorsToRescale.add(editor);
  14264. }
  14265. removeShouldRescale(editor) {
  14266. this.#editorsToRescale.delete(editor);
  14267. }
  14268. onScaleChanging({
  14269. scale
  14270. }) {
  14271. this.commitOrRemove();
  14272. this.viewParameters.realScale = scale * _display_utils_js__WEBPACK_IMPORTED_MODULE_1__.PixelsPerInch.PDF_TO_CSS_UNITS;
  14273. for (const editor of this.#editorsToRescale) {
  14274. editor.onScaleChanging();
  14275. }
  14276. }
  14277. onRotationChanging({
  14278. pagesRotation
  14279. }) {
  14280. this.commitOrRemove();
  14281. this.viewParameters.rotation = pagesRotation;
  14282. }
  14283. #getAnchorElementForSelection({
  14284. anchorNode
  14285. }) {
  14286. return anchorNode.nodeType === Node.TEXT_NODE ? anchorNode.parentElement : anchorNode;
  14287. }
  14288. highlightSelection(methodOfCreation = "") {
  14289. const selection = document.getSelection();
  14290. if (!selection || selection.isCollapsed) {
  14291. return;
  14292. }
  14293. const {
  14294. anchorNode,
  14295. anchorOffset,
  14296. focusNode,
  14297. focusOffset
  14298. } = selection;
  14299. const text = selection.toString();
  14300. const anchorElement = this.#getAnchorElementForSelection(selection);
  14301. const textLayer = anchorElement.closest(".textLayer");
  14302. const boxes = this.getSelectionBoxes(textLayer);
  14303. if (!boxes) {
  14304. return;
  14305. }
  14306. selection.empty();
  14307. if (this.#mode === _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorType.NONE) {
  14308. this._eventBus.dispatch("showannotationeditorui", {
  14309. source: this,
  14310. mode: _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorType.HIGHLIGHT
  14311. });
  14312. this.showAllEditors("highlight", true, true);
  14313. }
  14314. for (const layer of this.#allLayers.values()) {
  14315. if (layer.hasTextLayer(textLayer)) {
  14316. layer.createAndAddNewEditor({
  14317. x: 0,
  14318. y: 0
  14319. }, false, {
  14320. methodOfCreation,
  14321. boxes,
  14322. anchorNode,
  14323. anchorOffset,
  14324. focusNode,
  14325. focusOffset,
  14326. text
  14327. });
  14328. break;
  14329. }
  14330. }
  14331. }
  14332. #displayHighlightToolbar() {
  14333. const selection = document.getSelection();
  14334. if (!selection || selection.isCollapsed) {
  14335. return;
  14336. }
  14337. const anchorElement = this.#getAnchorElementForSelection(selection);
  14338. const textLayer = anchorElement.closest(".textLayer");
  14339. const boxes = this.getSelectionBoxes(textLayer);
  14340. if (!boxes) {
  14341. return;
  14342. }
  14343. this.#highlightToolbar ||= new _toolbar_js__WEBPACK_IMPORTED_MODULE_2__.HighlightToolbar(this);
  14344. this.#highlightToolbar.show(textLayer, boxes, this.direction === "ltr");
  14345. }
  14346. addToAnnotationStorage(editor) {
  14347. if (!editor.isEmpty() && this.#annotationStorage && !this.#annotationStorage.has(editor.id)) {
  14348. this.#annotationStorage.setValue(editor.id, editor);
  14349. }
  14350. }
  14351. #selectionChange() {
  14352. const selection = document.getSelection();
  14353. if (!selection || selection.isCollapsed) {
  14354. if (this.#selectedTextNode) {
  14355. this.#highlightToolbar?.hide();
  14356. this.#selectedTextNode = null;
  14357. this.#dispatchUpdateStates({
  14358. hasSelectedText: false
  14359. });
  14360. }
  14361. return;
  14362. }
  14363. const {
  14364. anchorNode
  14365. } = selection;
  14366. if (anchorNode === this.#selectedTextNode) {
  14367. return;
  14368. }
  14369. const anchorElement = this.#getAnchorElementForSelection(selection);
  14370. const textLayer = anchorElement.closest(".textLayer");
  14371. if (!textLayer) {
  14372. if (this.#selectedTextNode) {
  14373. this.#highlightToolbar?.hide();
  14374. this.#selectedTextNode = null;
  14375. this.#dispatchUpdateStates({
  14376. hasSelectedText: false
  14377. });
  14378. }
  14379. return;
  14380. }
  14381. this.#highlightToolbar?.hide();
  14382. this.#selectedTextNode = anchorNode;
  14383. this.#dispatchUpdateStates({
  14384. hasSelectedText: true
  14385. });
  14386. if (this.#mode !== _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorType.HIGHLIGHT && this.#mode !== _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorType.NONE) {
  14387. return;
  14388. }
  14389. if (this.#mode === _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorType.HIGHLIGHT) {
  14390. this.showAllEditors("highlight", true, true);
  14391. }
  14392. this.#highlightWhenShiftUp = this.isShiftKeyDown;
  14393. if (!this.isShiftKeyDown) {
  14394. const pointerup = e => {
  14395. if (e.type === "pointerup" && e.button !== 0) {
  14396. return;
  14397. }
  14398. window.removeEventListener("pointerup", pointerup);
  14399. window.removeEventListener("blur", pointerup);
  14400. if (e.type === "pointerup") {
  14401. this.#onSelectEnd("main_toolbar");
  14402. }
  14403. };
  14404. window.addEventListener("pointerup", pointerup);
  14405. window.addEventListener("blur", pointerup);
  14406. }
  14407. }
  14408. #onSelectEnd(methodOfCreation = "") {
  14409. if (this.#mode === _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorType.HIGHLIGHT) {
  14410. this.highlightSelection(methodOfCreation);
  14411. } else if (this.#enableHighlightFloatingButton) {
  14412. this.#displayHighlightToolbar();
  14413. }
  14414. }
  14415. #addSelectionListener() {
  14416. document.addEventListener("selectionchange", this.#boundSelectionChange);
  14417. }
  14418. #removeSelectionListener() {
  14419. document.removeEventListener("selectionchange", this.#boundSelectionChange);
  14420. }
  14421. #addFocusManager() {
  14422. window.addEventListener("focus", this.#boundFocus);
  14423. window.addEventListener("blur", this.#boundBlur);
  14424. }
  14425. #removeFocusManager() {
  14426. window.removeEventListener("focus", this.#boundFocus);
  14427. window.removeEventListener("blur", this.#boundBlur);
  14428. }
  14429. blur() {
  14430. this.isShiftKeyDown = false;
  14431. if (this.#highlightWhenShiftUp) {
  14432. this.#highlightWhenShiftUp = false;
  14433. this.#onSelectEnd("main_toolbar");
  14434. }
  14435. if (!this.hasSelection) {
  14436. return;
  14437. }
  14438. const {
  14439. activeElement
  14440. } = document;
  14441. for (const editor of this.#selectedEditors) {
  14442. if (editor.div.contains(activeElement)) {
  14443. this.#lastActiveElement = [editor, activeElement];
  14444. editor._focusEventsAllowed = false;
  14445. break;
  14446. }
  14447. }
  14448. }
  14449. focus() {
  14450. if (!this.#lastActiveElement) {
  14451. return;
  14452. }
  14453. const [lastEditor, lastActiveElement] = this.#lastActiveElement;
  14454. this.#lastActiveElement = null;
  14455. lastActiveElement.addEventListener("focusin", () => {
  14456. lastEditor._focusEventsAllowed = true;
  14457. }, {
  14458. once: true
  14459. });
  14460. lastActiveElement.focus();
  14461. }
  14462. #addKeyboardManager() {
  14463. window.addEventListener("keydown", this.#boundKeydown);
  14464. window.addEventListener("keyup", this.#boundKeyup);
  14465. }
  14466. #removeKeyboardManager() {
  14467. window.removeEventListener("keydown", this.#boundKeydown);
  14468. window.removeEventListener("keyup", this.#boundKeyup);
  14469. }
  14470. #addCopyPasteListeners() {
  14471. document.addEventListener("copy", this.#boundCopy);
  14472. document.addEventListener("cut", this.#boundCut);
  14473. document.addEventListener("paste", this.#boundPaste);
  14474. }
  14475. #removeCopyPasteListeners() {
  14476. document.removeEventListener("copy", this.#boundCopy);
  14477. document.removeEventListener("cut", this.#boundCut);
  14478. document.removeEventListener("paste", this.#boundPaste);
  14479. }
  14480. addEditListeners() {
  14481. this.#addKeyboardManager();
  14482. this.#addCopyPasteListeners();
  14483. }
  14484. removeEditListeners() {
  14485. this.#removeKeyboardManager();
  14486. this.#removeCopyPasteListeners();
  14487. }
  14488. copy(event) {
  14489. event.preventDefault();
  14490. this.#activeEditor?.commitOrRemove();
  14491. if (!this.hasSelection) {
  14492. return;
  14493. }
  14494. const editors = [];
  14495. for (const editor of this.#selectedEditors) {
  14496. const serialized = editor.serialize(true);
  14497. if (serialized) {
  14498. editors.push(serialized);
  14499. }
  14500. }
  14501. if (editors.length === 0) {
  14502. return;
  14503. }
  14504. event.clipboardData.setData("application/pdfjs", JSON.stringify(editors));
  14505. }
  14506. cut(event) {
  14507. this.copy(event);
  14508. this.delete();
  14509. }
  14510. paste(event) {
  14511. event.preventDefault();
  14512. const {
  14513. clipboardData
  14514. } = event;
  14515. for (const item of clipboardData.items) {
  14516. for (const editorType of this.#editorTypes) {
  14517. if (editorType.isHandlingMimeForPasting(item.type)) {
  14518. editorType.paste(item, this.currentLayer);
  14519. return;
  14520. }
  14521. }
  14522. }
  14523. let data = clipboardData.getData("application/pdfjs");
  14524. if (!data) {
  14525. return;
  14526. }
  14527. try {
  14528. data = JSON.parse(data);
  14529. } catch (ex) {
  14530. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`paste: "${ex.message}".`);
  14531. return;
  14532. }
  14533. if (!Array.isArray(data)) {
  14534. return;
  14535. }
  14536. this.unselectAll();
  14537. const layer = this.currentLayer;
  14538. try {
  14539. const newEditors = [];
  14540. for (const editor of data) {
  14541. const deserializedEditor = layer.deserialize(editor);
  14542. if (!deserializedEditor) {
  14543. return;
  14544. }
  14545. newEditors.push(deserializedEditor);
  14546. }
  14547. const cmd = () => {
  14548. for (const editor of newEditors) {
  14549. this.#addEditorToLayer(editor);
  14550. }
  14551. this.#selectEditors(newEditors);
  14552. };
  14553. const undo = () => {
  14554. for (const editor of newEditors) {
  14555. editor.remove();
  14556. }
  14557. };
  14558. this.addCommands({
  14559. cmd,
  14560. undo,
  14561. mustExec: true
  14562. });
  14563. } catch (ex) {
  14564. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`paste: "${ex.message}".`);
  14565. }
  14566. }
  14567. keydown(event) {
  14568. if (!this.isShiftKeyDown && event.key === "Shift") {
  14569. this.isShiftKeyDown = true;
  14570. }
  14571. if (this.#mode !== _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorType.NONE && !this.isEditorHandlingKeyboard) {
  14572. AnnotationEditorUIManager._keyboardManager.exec(this, event);
  14573. }
  14574. }
  14575. keyup(event) {
  14576. if (this.isShiftKeyDown && event.key === "Shift") {
  14577. this.isShiftKeyDown = false;
  14578. if (this.#highlightWhenShiftUp) {
  14579. this.#highlightWhenShiftUp = false;
  14580. this.#onSelectEnd("main_toolbar");
  14581. }
  14582. }
  14583. }
  14584. onEditingAction({
  14585. name
  14586. }) {
  14587. switch (name) {
  14588. case "undo":
  14589. case "redo":
  14590. case "delete":
  14591. case "selectAll":
  14592. this[name]();
  14593. break;
  14594. case "highlightSelection":
  14595. this.highlightSelection("context_menu");
  14596. break;
  14597. }
  14598. }
  14599. #dispatchUpdateStates(details) {
  14600. const hasChanged = Object.entries(details).some(([key, value]) => this.#previousStates[key] !== value);
  14601. if (hasChanged) {
  14602. this._eventBus.dispatch("annotationeditorstateschanged", {
  14603. source: this,
  14604. details: Object.assign(this.#previousStates, details)
  14605. });
  14606. if (this.#mode === _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorType.HIGHLIGHT && details.hasSelectedEditor === false) {
  14607. this.#dispatchUpdateUI([[_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorParamsType.HIGHLIGHT_FREE, true]]);
  14608. }
  14609. }
  14610. }
  14611. #dispatchUpdateUI(details) {
  14612. this._eventBus.dispatch("annotationeditorparamschanged", {
  14613. source: this,
  14614. details
  14615. });
  14616. }
  14617. setEditingState(isEditing) {
  14618. if (isEditing) {
  14619. this.#addFocusManager();
  14620. this.#addCopyPasteListeners();
  14621. this.#dispatchUpdateStates({
  14622. isEditing: this.#mode !== _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorType.NONE,
  14623. isEmpty: this.#isEmpty(),
  14624. hasSomethingToUndo: this.#commandManager.hasSomethingToUndo(),
  14625. hasSomethingToRedo: this.#commandManager.hasSomethingToRedo(),
  14626. hasSelectedEditor: false
  14627. });
  14628. } else {
  14629. this.#removeFocusManager();
  14630. this.#removeCopyPasteListeners();
  14631. this.#dispatchUpdateStates({
  14632. isEditing: false
  14633. });
  14634. this.disableUserSelect(false);
  14635. }
  14636. }
  14637. registerEditorTypes(types) {
  14638. if (this.#editorTypes) {
  14639. return;
  14640. }
  14641. this.#editorTypes = types;
  14642. for (const editorType of this.#editorTypes) {
  14643. this.#dispatchUpdateUI(editorType.defaultPropertiesToUpdate);
  14644. }
  14645. }
  14646. getId() {
  14647. return this.#idManager.id;
  14648. }
  14649. get currentLayer() {
  14650. return this.#allLayers.get(this.#currentPageIndex);
  14651. }
  14652. getLayer(pageIndex) {
  14653. return this.#allLayers.get(pageIndex);
  14654. }
  14655. get currentPageIndex() {
  14656. return this.#currentPageIndex;
  14657. }
  14658. addLayer(layer) {
  14659. this.#allLayers.set(layer.pageIndex, layer);
  14660. if (this.#isEnabled) {
  14661. layer.enable();
  14662. } else {
  14663. layer.disable();
  14664. }
  14665. }
  14666. removeLayer(layer) {
  14667. this.#allLayers.delete(layer.pageIndex);
  14668. }
  14669. updateMode(mode, editId = null, isFromKeyboard = false) {
  14670. if (this.#mode === mode) {
  14671. return;
  14672. }
  14673. this.#mode = mode;
  14674. if (mode === _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorType.NONE) {
  14675. this.setEditingState(false);
  14676. this.#disableAll();
  14677. return;
  14678. }
  14679. this.setEditingState(true);
  14680. this.#enableAll();
  14681. this.unselectAll();
  14682. for (const layer of this.#allLayers.values()) {
  14683. layer.updateMode(mode);
  14684. }
  14685. if (!editId && isFromKeyboard) {
  14686. this.addNewEditorFromKeyboard();
  14687. return;
  14688. }
  14689. if (!editId) {
  14690. return;
  14691. }
  14692. for (const editor of this.#allEditors.values()) {
  14693. if (editor.annotationElementId === editId) {
  14694. this.setSelected(editor);
  14695. editor.enterInEditMode();
  14696. break;
  14697. }
  14698. }
  14699. }
  14700. addNewEditorFromKeyboard() {
  14701. if (this.currentLayer.canCreateNewEmptyEditor()) {
  14702. this.currentLayer.addNewEditor();
  14703. }
  14704. }
  14705. updateToolbar(mode) {
  14706. if (mode === this.#mode) {
  14707. return;
  14708. }
  14709. this._eventBus.dispatch("switchannotationeditormode", {
  14710. source: this,
  14711. mode
  14712. });
  14713. }
  14714. updateParams(type, value) {
  14715. if (!this.#editorTypes) {
  14716. return;
  14717. }
  14718. switch (type) {
  14719. case _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorParamsType.CREATE:
  14720. this.currentLayer.addNewEditor();
  14721. return;
  14722. case _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorParamsType.HIGHLIGHT_DEFAULT_COLOR:
  14723. this.#mainHighlightColorPicker?.updateColor(value);
  14724. break;
  14725. case _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorParamsType.HIGHLIGHT_SHOW_ALL:
  14726. this._eventBus.dispatch("reporttelemetry", {
  14727. source: this,
  14728. details: {
  14729. type: "editing",
  14730. data: {
  14731. type: "highlight",
  14732. action: "toggle_visibility"
  14733. }
  14734. }
  14735. });
  14736. (this.#showAllStates ||= new Map()).set(type, value);
  14737. this.showAllEditors("highlight", value);
  14738. break;
  14739. }
  14740. for (const editor of this.#selectedEditors) {
  14741. editor.updateParams(type, value);
  14742. }
  14743. for (const editorType of this.#editorTypes) {
  14744. editorType.updateDefaultParams(type, value);
  14745. }
  14746. }
  14747. showAllEditors(type, visible, updateButton = false) {
  14748. for (const editor of this.#allEditors.values()) {
  14749. if (editor.editorType === type) {
  14750. editor.show(visible);
  14751. }
  14752. }
  14753. const state = this.#showAllStates?.get(_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorParamsType.HIGHLIGHT_SHOW_ALL) ?? true;
  14754. if (state !== visible) {
  14755. this.#dispatchUpdateUI([[_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorParamsType.HIGHLIGHT_SHOW_ALL, visible]]);
  14756. }
  14757. }
  14758. enableWaiting(mustWait = false) {
  14759. if (this.#isWaiting === mustWait) {
  14760. return;
  14761. }
  14762. this.#isWaiting = mustWait;
  14763. for (const layer of this.#allLayers.values()) {
  14764. if (mustWait) {
  14765. layer.disableClick();
  14766. } else {
  14767. layer.enableClick();
  14768. }
  14769. layer.div.classList.toggle("waiting", mustWait);
  14770. }
  14771. }
  14772. #enableAll() {
  14773. if (!this.#isEnabled) {
  14774. this.#isEnabled = true;
  14775. for (const layer of this.#allLayers.values()) {
  14776. layer.enable();
  14777. }
  14778. for (const editor of this.#allEditors.values()) {
  14779. editor.enable();
  14780. }
  14781. }
  14782. }
  14783. #disableAll() {
  14784. this.unselectAll();
  14785. if (this.#isEnabled) {
  14786. this.#isEnabled = false;
  14787. for (const layer of this.#allLayers.values()) {
  14788. layer.disable();
  14789. }
  14790. for (const editor of this.#allEditors.values()) {
  14791. editor.disable();
  14792. }
  14793. }
  14794. }
  14795. getEditors(pageIndex) {
  14796. const editors = [];
  14797. for (const editor of this.#allEditors.values()) {
  14798. if (editor.pageIndex === pageIndex) {
  14799. editors.push(editor);
  14800. }
  14801. }
  14802. return editors;
  14803. }
  14804. getEditor(id) {
  14805. return this.#allEditors.get(id);
  14806. }
  14807. addEditor(editor) {
  14808. this.#allEditors.set(editor.id, editor);
  14809. }
  14810. removeEditor(editor) {
  14811. if (editor.div.contains(document.activeElement)) {
  14812. if (this.#focusMainContainerTimeoutId) {
  14813. clearTimeout(this.#focusMainContainerTimeoutId);
  14814. }
  14815. this.#focusMainContainerTimeoutId = setTimeout(() => {
  14816. this.focusMainContainer();
  14817. this.#focusMainContainerTimeoutId = null;
  14818. }, 0);
  14819. }
  14820. this.#allEditors.delete(editor.id);
  14821. this.unselect(editor);
  14822. if (!editor.annotationElementId || !this.#deletedAnnotationsElementIds.has(editor.annotationElementId)) {
  14823. this.#annotationStorage?.remove(editor.id);
  14824. }
  14825. }
  14826. addDeletedAnnotationElement(editor) {
  14827. this.#deletedAnnotationsElementIds.add(editor.annotationElementId);
  14828. this.addChangedExistingAnnotation(editor);
  14829. editor.deleted = true;
  14830. }
  14831. isDeletedAnnotationElement(annotationElementId) {
  14832. return this.#deletedAnnotationsElementIds.has(annotationElementId);
  14833. }
  14834. removeDeletedAnnotationElement(editor) {
  14835. this.#deletedAnnotationsElementIds.delete(editor.annotationElementId);
  14836. this.removeChangedExistingAnnotation(editor);
  14837. editor.deleted = false;
  14838. }
  14839. #addEditorToLayer(editor) {
  14840. const layer = this.#allLayers.get(editor.pageIndex);
  14841. if (layer) {
  14842. layer.addOrRebuild(editor);
  14843. } else {
  14844. this.addEditor(editor);
  14845. this.addToAnnotationStorage(editor);
  14846. }
  14847. }
  14848. setActiveEditor(editor) {
  14849. if (this.#activeEditor === editor) {
  14850. return;
  14851. }
  14852. this.#activeEditor = editor;
  14853. if (editor) {
  14854. this.#dispatchUpdateUI(editor.propertiesToUpdate);
  14855. }
  14856. }
  14857. get #lastSelectedEditor() {
  14858. let ed = null;
  14859. for (ed of this.#selectedEditors) {}
  14860. return ed;
  14861. }
  14862. updateUI(editor) {
  14863. if (this.#lastSelectedEditor === editor) {
  14864. this.#dispatchUpdateUI(editor.propertiesToUpdate);
  14865. }
  14866. }
  14867. toggleSelected(editor) {
  14868. if (this.#selectedEditors.has(editor)) {
  14869. this.#selectedEditors.delete(editor);
  14870. editor.unselect();
  14871. this.#dispatchUpdateStates({
  14872. hasSelectedEditor: this.hasSelection
  14873. });
  14874. return;
  14875. }
  14876. this.#selectedEditors.add(editor);
  14877. editor.select();
  14878. this.#dispatchUpdateUI(editor.propertiesToUpdate);
  14879. this.#dispatchUpdateStates({
  14880. hasSelectedEditor: true
  14881. });
  14882. }
  14883. setSelected(editor) {
  14884. for (const ed of this.#selectedEditors) {
  14885. if (ed !== editor) {
  14886. ed.unselect();
  14887. }
  14888. }
  14889. this.#selectedEditors.clear();
  14890. this.#selectedEditors.add(editor);
  14891. editor.select();
  14892. this.#dispatchUpdateUI(editor.propertiesToUpdate);
  14893. this.#dispatchUpdateStates({
  14894. hasSelectedEditor: true
  14895. });
  14896. }
  14897. isSelected(editor) {
  14898. return this.#selectedEditors.has(editor);
  14899. }
  14900. get firstSelectedEditor() {
  14901. return this.#selectedEditors.values().next().value;
  14902. }
  14903. unselect(editor) {
  14904. editor.unselect();
  14905. this.#selectedEditors.delete(editor);
  14906. this.#dispatchUpdateStates({
  14907. hasSelectedEditor: this.hasSelection
  14908. });
  14909. }
  14910. get hasSelection() {
  14911. return this.#selectedEditors.size !== 0;
  14912. }
  14913. get isEnterHandled() {
  14914. return this.#selectedEditors.size === 1 && this.firstSelectedEditor.isEnterHandled;
  14915. }
  14916. undo() {
  14917. this.#commandManager.undo();
  14918. this.#dispatchUpdateStates({
  14919. hasSomethingToUndo: this.#commandManager.hasSomethingToUndo(),
  14920. hasSomethingToRedo: true,
  14921. isEmpty: this.#isEmpty()
  14922. });
  14923. }
  14924. redo() {
  14925. this.#commandManager.redo();
  14926. this.#dispatchUpdateStates({
  14927. hasSomethingToUndo: true,
  14928. hasSomethingToRedo: this.#commandManager.hasSomethingToRedo(),
  14929. isEmpty: this.#isEmpty()
  14930. });
  14931. }
  14932. addCommands(params) {
  14933. this.#commandManager.add(params);
  14934. this.#dispatchUpdateStates({
  14935. hasSomethingToUndo: true,
  14936. hasSomethingToRedo: false,
  14937. isEmpty: this.#isEmpty()
  14938. });
  14939. }
  14940. #isEmpty() {
  14941. if (this.#allEditors.size === 0) {
  14942. return true;
  14943. }
  14944. if (this.#allEditors.size === 1) {
  14945. for (const editor of this.#allEditors.values()) {
  14946. return editor.isEmpty();
  14947. }
  14948. }
  14949. return false;
  14950. }
  14951. delete() {
  14952. this.commitOrRemove();
  14953. if (!this.hasSelection) {
  14954. return;
  14955. }
  14956. const editors = [...this.#selectedEditors];
  14957. const cmd = () => {
  14958. for (const editor of editors) {
  14959. editor.remove();
  14960. }
  14961. };
  14962. const undo = () => {
  14963. for (const editor of editors) {
  14964. this.#addEditorToLayer(editor);
  14965. }
  14966. };
  14967. this.addCommands({
  14968. cmd,
  14969. undo,
  14970. mustExec: true
  14971. });
  14972. }
  14973. commitOrRemove() {
  14974. this.#activeEditor?.commitOrRemove();
  14975. }
  14976. hasSomethingToControl() {
  14977. return this.#activeEditor || this.hasSelection;
  14978. }
  14979. #selectEditors(editors) {
  14980. for (const editor of this.#selectedEditors) {
  14981. editor.unselect();
  14982. }
  14983. this.#selectedEditors.clear();
  14984. for (const editor of editors) {
  14985. if (editor.isEmpty()) {
  14986. continue;
  14987. }
  14988. this.#selectedEditors.add(editor);
  14989. editor.select();
  14990. }
  14991. this.#dispatchUpdateStates({
  14992. hasSelectedEditor: this.hasSelection
  14993. });
  14994. }
  14995. selectAll() {
  14996. for (const editor of this.#selectedEditors) {
  14997. editor.commit();
  14998. }
  14999. this.#selectEditors(this.#allEditors.values());
  15000. }
  15001. unselectAll() {
  15002. if (this.#activeEditor) {
  15003. this.#activeEditor.commitOrRemove();
  15004. if (this.#mode !== _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorType.NONE) {
  15005. return;
  15006. }
  15007. }
  15008. if (!this.hasSelection) {
  15009. return;
  15010. }
  15011. for (const editor of this.#selectedEditors) {
  15012. editor.unselect();
  15013. }
  15014. this.#selectedEditors.clear();
  15015. this.#dispatchUpdateStates({
  15016. hasSelectedEditor: false
  15017. });
  15018. }
  15019. translateSelectedEditors(x, y, noCommit = false) {
  15020. if (!noCommit) {
  15021. this.commitOrRemove();
  15022. }
  15023. if (!this.hasSelection) {
  15024. return;
  15025. }
  15026. this.#translation[0] += x;
  15027. this.#translation[1] += y;
  15028. const [totalX, totalY] = this.#translation;
  15029. const editors = [...this.#selectedEditors];
  15030. const TIME_TO_WAIT = 1000;
  15031. if (this.#translationTimeoutId) {
  15032. clearTimeout(this.#translationTimeoutId);
  15033. }
  15034. this.#translationTimeoutId = setTimeout(() => {
  15035. this.#translationTimeoutId = null;
  15036. this.#translation[0] = this.#translation[1] = 0;
  15037. this.addCommands({
  15038. cmd: () => {
  15039. for (const editor of editors) {
  15040. if (this.#allEditors.has(editor.id)) {
  15041. editor.translateInPage(totalX, totalY);
  15042. }
  15043. }
  15044. },
  15045. undo: () => {
  15046. for (const editor of editors) {
  15047. if (this.#allEditors.has(editor.id)) {
  15048. editor.translateInPage(-totalX, -totalY);
  15049. }
  15050. }
  15051. },
  15052. mustExec: false
  15053. });
  15054. }, TIME_TO_WAIT);
  15055. for (const editor of editors) {
  15056. editor.translateInPage(x, y);
  15057. }
  15058. }
  15059. setUpDragSession() {
  15060. if (!this.hasSelection) {
  15061. return;
  15062. }
  15063. this.disableUserSelect(true);
  15064. this.#draggingEditors = new Map();
  15065. for (const editor of this.#selectedEditors) {
  15066. this.#draggingEditors.set(editor, {
  15067. savedX: editor.x,
  15068. savedY: editor.y,
  15069. savedPageIndex: editor.pageIndex,
  15070. newX: 0,
  15071. newY: 0,
  15072. newPageIndex: -1
  15073. });
  15074. }
  15075. }
  15076. endDragSession() {
  15077. if (!this.#draggingEditors) {
  15078. return false;
  15079. }
  15080. this.disableUserSelect(false);
  15081. const map = this.#draggingEditors;
  15082. this.#draggingEditors = null;
  15083. let mustBeAddedInUndoStack = false;
  15084. for (const [{
  15085. x,
  15086. y,
  15087. pageIndex
  15088. }, value] of map) {
  15089. value.newX = x;
  15090. value.newY = y;
  15091. value.newPageIndex = pageIndex;
  15092. mustBeAddedInUndoStack ||= x !== value.savedX || y !== value.savedY || pageIndex !== value.savedPageIndex;
  15093. }
  15094. if (!mustBeAddedInUndoStack) {
  15095. return false;
  15096. }
  15097. const move = (editor, x, y, pageIndex) => {
  15098. if (this.#allEditors.has(editor.id)) {
  15099. const parent = this.#allLayers.get(pageIndex);
  15100. if (parent) {
  15101. editor._setParentAndPosition(parent, x, y);
  15102. } else {
  15103. editor.pageIndex = pageIndex;
  15104. editor.x = x;
  15105. editor.y = y;
  15106. }
  15107. }
  15108. };
  15109. this.addCommands({
  15110. cmd: () => {
  15111. for (const [editor, {
  15112. newX,
  15113. newY,
  15114. newPageIndex
  15115. }] of map) {
  15116. move(editor, newX, newY, newPageIndex);
  15117. }
  15118. },
  15119. undo: () => {
  15120. for (const [editor, {
  15121. savedX,
  15122. savedY,
  15123. savedPageIndex
  15124. }] of map) {
  15125. move(editor, savedX, savedY, savedPageIndex);
  15126. }
  15127. },
  15128. mustExec: true
  15129. });
  15130. return true;
  15131. }
  15132. dragSelectedEditors(tx, ty) {
  15133. if (!this.#draggingEditors) {
  15134. return;
  15135. }
  15136. for (const editor of this.#draggingEditors.keys()) {
  15137. editor.drag(tx, ty);
  15138. }
  15139. }
  15140. rebuild(editor) {
  15141. if (editor.parent === null) {
  15142. const parent = this.getLayer(editor.pageIndex);
  15143. if (parent) {
  15144. parent.changeParent(editor);
  15145. parent.addOrRebuild(editor);
  15146. } else {
  15147. this.addEditor(editor);
  15148. this.addToAnnotationStorage(editor);
  15149. editor.rebuild();
  15150. }
  15151. } else {
  15152. editor.parent.addOrRebuild(editor);
  15153. }
  15154. }
  15155. get isEditorHandlingKeyboard() {
  15156. return this.getActive()?.shouldGetKeyboardEvents() || this.#selectedEditors.size === 1 && this.firstSelectedEditor.shouldGetKeyboardEvents();
  15157. }
  15158. isActive(editor) {
  15159. return this.#activeEditor === editor;
  15160. }
  15161. getActive() {
  15162. return this.#activeEditor;
  15163. }
  15164. getMode() {
  15165. return this.#mode;
  15166. }
  15167. get imageManager() {
  15168. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow)(this, "imageManager", new ImageManager());
  15169. }
  15170. getSelectionBoxes(textLayer) {
  15171. if (!textLayer) {
  15172. return null;
  15173. }
  15174. const selection = document.getSelection();
  15175. for (let i = 0, ii = selection.rangeCount; i < ii; i++) {
  15176. if (!textLayer.contains(selection.getRangeAt(i).commonAncestorContainer)) {
  15177. return null;
  15178. }
  15179. }
  15180. const {
  15181. x: layerX,
  15182. y: layerY,
  15183. width: parentWidth,
  15184. height: parentHeight
  15185. } = textLayer.getBoundingClientRect();
  15186. let rotator;
  15187. switch (textLayer.getAttribute("data-main-rotation")) {
  15188. case "90":
  15189. rotator = (x, y, w, h) => ({
  15190. x: (y - layerY) / parentHeight,
  15191. y: 1 - (x + w - layerX) / parentWidth,
  15192. width: h / parentHeight,
  15193. height: w / parentWidth
  15194. });
  15195. break;
  15196. case "180":
  15197. rotator = (x, y, w, h) => ({
  15198. x: 1 - (x + w - layerX) / parentWidth,
  15199. y: 1 - (y + h - layerY) / parentHeight,
  15200. width: w / parentWidth,
  15201. height: h / parentHeight
  15202. });
  15203. break;
  15204. case "270":
  15205. rotator = (x, y, w, h) => ({
  15206. x: 1 - (y + h - layerY) / parentHeight,
  15207. y: (x - layerX) / parentWidth,
  15208. width: h / parentHeight,
  15209. height: w / parentWidth
  15210. });
  15211. break;
  15212. default:
  15213. rotator = (x, y, w, h) => ({
  15214. x: (x - layerX) / parentWidth,
  15215. y: (y - layerY) / parentHeight,
  15216. width: w / parentWidth,
  15217. height: h / parentHeight
  15218. });
  15219. break;
  15220. }
  15221. const boxes = [];
  15222. for (let i = 0, ii = selection.rangeCount; i < ii; i++) {
  15223. const range = selection.getRangeAt(i);
  15224. if (range.collapsed) {
  15225. continue;
  15226. }
  15227. for (const {
  15228. x,
  15229. y,
  15230. width,
  15231. height
  15232. } of range.getClientRects()) {
  15233. if (width === 0 || height === 0) {
  15234. continue;
  15235. }
  15236. boxes.push(rotator(x, y, width, height));
  15237. }
  15238. }
  15239. return boxes.length === 0 ? null : boxes;
  15240. }
  15241. addChangedExistingAnnotation({
  15242. annotationElementId,
  15243. id
  15244. }) {
  15245. (this.#changedExistingAnnotations ||= new Map()).set(annotationElementId, id);
  15246. }
  15247. removeChangedExistingAnnotation({
  15248. annotationElementId
  15249. }) {
  15250. this.#changedExistingAnnotations?.delete(annotationElementId);
  15251. }
  15252. renderAnnotationElement(annotation) {
  15253. const editorId = this.#changedExistingAnnotations?.get(annotation.data.id);
  15254. if (!editorId) {
  15255. return;
  15256. }
  15257. const editor = this.#annotationStorage.getRawValue(editorId);
  15258. if (!editor) {
  15259. return;
  15260. }
  15261. if (this.#mode === _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorType.NONE && !editor.hasBeenModified) {
  15262. return;
  15263. }
  15264. editor.renderAnnotationElement(annotation);
  15265. }
  15266. }
  15267. /***/ }),
  15268. /***/ 94:
  15269. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  15270. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  15271. /* harmony export */ PDFFetchStream: () => (/* binding */ PDFFetchStream)
  15272. /* harmony export */ });
  15273. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(292);
  15274. /* harmony import */ var _network_utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(490);
  15275. function createFetchOptions(headers, withCredentials, abortController) {
  15276. return {
  15277. method: "GET",
  15278. headers,
  15279. signal: abortController.signal,
  15280. mode: "cors",
  15281. credentials: withCredentials ? "include" : "same-origin",
  15282. redirect: "follow"
  15283. };
  15284. }
  15285. function createHeaders(httpHeaders) {
  15286. const headers = new Headers();
  15287. for (const property in httpHeaders) {
  15288. const value = httpHeaders[property];
  15289. if (value === undefined) {
  15290. continue;
  15291. }
  15292. headers.append(property, value);
  15293. }
  15294. return headers;
  15295. }
  15296. function getArrayBuffer(val) {
  15297. if (val instanceof Uint8Array) {
  15298. return val.buffer;
  15299. }
  15300. if (val instanceof ArrayBuffer) {
  15301. return val;
  15302. }
  15303. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`getArrayBuffer - unexpected data format: ${val}`);
  15304. return new Uint8Array(val).buffer;
  15305. }
  15306. class PDFFetchStream {
  15307. constructor(source) {
  15308. this.source = source;
  15309. this.isHttp = /^https?:/i.test(source.url);
  15310. this.httpHeaders = this.isHttp && source.httpHeaders || {};
  15311. this._fullRequestReader = null;
  15312. this._rangeRequestReaders = [];
  15313. }
  15314. get _progressiveDataLength() {
  15315. return this._fullRequestReader?._loaded ?? 0;
  15316. }
  15317. getFullReader() {
  15318. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(!this._fullRequestReader, "PDFFetchStream.getFullReader can only be called once.");
  15319. this._fullRequestReader = new PDFFetchStreamReader(this);
  15320. return this._fullRequestReader;
  15321. }
  15322. getRangeReader(begin, end) {
  15323. if (end <= this._progressiveDataLength) {
  15324. return null;
  15325. }
  15326. const reader = new PDFFetchStreamRangeReader(this, begin, end);
  15327. this._rangeRequestReaders.push(reader);
  15328. return reader;
  15329. }
  15330. cancelAllRequests(reason) {
  15331. this._fullRequestReader?.cancel(reason);
  15332. for (const reader of this._rangeRequestReaders.slice(0)) {
  15333. reader.cancel(reason);
  15334. }
  15335. }
  15336. }
  15337. class PDFFetchStreamReader {
  15338. constructor(stream) {
  15339. this._stream = stream;
  15340. this._reader = null;
  15341. this._loaded = 0;
  15342. this._filename = null;
  15343. const source = stream.source;
  15344. this._withCredentials = source.withCredentials || false;
  15345. this._contentLength = source.length;
  15346. this._headersCapability = Promise.withResolvers();
  15347. this._disableRange = source.disableRange || false;
  15348. this._rangeChunkSize = source.rangeChunkSize;
  15349. if (!this._rangeChunkSize && !this._disableRange) {
  15350. this._disableRange = true;
  15351. }
  15352. this._abortController = new AbortController();
  15353. this._isStreamingSupported = !source.disableStream;
  15354. this._isRangeSupported = !source.disableRange;
  15355. this._headers = createHeaders(this._stream.httpHeaders);
  15356. const url = source.url;
  15357. fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(response => {
  15358. if (!(0,_network_utils_js__WEBPACK_IMPORTED_MODULE_1__.validateResponseStatus)(response.status)) {
  15359. throw (0,_network_utils_js__WEBPACK_IMPORTED_MODULE_1__.createResponseStatusError)(response.status, url);
  15360. }
  15361. this._reader = response.body.getReader();
  15362. this._headersCapability.resolve();
  15363. const getResponseHeader = name => response.headers.get(name);
  15364. const {
  15365. allowRangeRequests,
  15366. suggestedLength
  15367. } = (0,_network_utils_js__WEBPACK_IMPORTED_MODULE_1__.validateRangeRequestCapabilities)({
  15368. getResponseHeader,
  15369. isHttp: this._stream.isHttp,
  15370. rangeChunkSize: this._rangeChunkSize,
  15371. disableRange: this._disableRange
  15372. });
  15373. this._isRangeSupported = allowRangeRequests;
  15374. this._contentLength = suggestedLength || this._contentLength;
  15375. this._filename = (0,_network_utils_js__WEBPACK_IMPORTED_MODULE_1__.extractFilenameFromHeader)(getResponseHeader);
  15376. if (!this._isStreamingSupported && this._isRangeSupported) {
  15377. this.cancel(new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AbortException("Streaming is disabled."));
  15378. }
  15379. }).catch(this._headersCapability.reject);
  15380. this.onProgress = null;
  15381. }
  15382. get headersReady() {
  15383. return this._headersCapability.promise;
  15384. }
  15385. get filename() {
  15386. return this._filename;
  15387. }
  15388. get contentLength() {
  15389. return this._contentLength;
  15390. }
  15391. get isRangeSupported() {
  15392. return this._isRangeSupported;
  15393. }
  15394. get isStreamingSupported() {
  15395. return this._isStreamingSupported;
  15396. }
  15397. async read() {
  15398. await this._headersCapability.promise;
  15399. const {
  15400. value,
  15401. done
  15402. } = await this._reader.read();
  15403. if (done) {
  15404. return {
  15405. value,
  15406. done
  15407. };
  15408. }
  15409. this._loaded += value.byteLength;
  15410. this.onProgress?.({
  15411. loaded: this._loaded,
  15412. total: this._contentLength
  15413. });
  15414. return {
  15415. value: getArrayBuffer(value),
  15416. done: false
  15417. };
  15418. }
  15419. cancel(reason) {
  15420. this._reader?.cancel(reason);
  15421. this._abortController.abort();
  15422. }
  15423. }
  15424. class PDFFetchStreamRangeReader {
  15425. constructor(stream, begin, end) {
  15426. this._stream = stream;
  15427. this._reader = null;
  15428. this._loaded = 0;
  15429. const source = stream.source;
  15430. this._withCredentials = source.withCredentials || false;
  15431. this._readCapability = Promise.withResolvers();
  15432. this._isStreamingSupported = !source.disableStream;
  15433. this._abortController = new AbortController();
  15434. this._headers = createHeaders(this._stream.httpHeaders);
  15435. this._headers.append("Range", `bytes=${begin}-${end - 1}`);
  15436. const url = source.url;
  15437. fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(response => {
  15438. if (!(0,_network_utils_js__WEBPACK_IMPORTED_MODULE_1__.validateResponseStatus)(response.status)) {
  15439. throw (0,_network_utils_js__WEBPACK_IMPORTED_MODULE_1__.createResponseStatusError)(response.status, url);
  15440. }
  15441. this._readCapability.resolve();
  15442. this._reader = response.body.getReader();
  15443. }).catch(this._readCapability.reject);
  15444. this.onProgress = null;
  15445. }
  15446. get isStreamingSupported() {
  15447. return this._isStreamingSupported;
  15448. }
  15449. async read() {
  15450. await this._readCapability.promise;
  15451. const {
  15452. value,
  15453. done
  15454. } = await this._reader.read();
  15455. if (done) {
  15456. return {
  15457. value,
  15458. done
  15459. };
  15460. }
  15461. this._loaded += value.byteLength;
  15462. this.onProgress?.({
  15463. loaded: this._loaded
  15464. });
  15465. return {
  15466. value: getArrayBuffer(value),
  15467. done: false
  15468. };
  15469. }
  15470. cancel(reason) {
  15471. this._reader?.cancel(reason);
  15472. this._abortController.abort();
  15473. }
  15474. }
  15475. /***/ }),
  15476. /***/ 10:
  15477. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  15478. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  15479. /* harmony export */ FontFaceObject: () => (/* binding */ FontFaceObject),
  15480. /* harmony export */ FontLoader: () => (/* binding */ FontLoader)
  15481. /* harmony export */ });
  15482. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(292);
  15483. class FontLoader {
  15484. #systemFonts = new Set();
  15485. constructor({
  15486. ownerDocument = globalThis.document,
  15487. styleElement = null
  15488. }) {
  15489. this._document = ownerDocument;
  15490. this.nativeFontFaces = new Set();
  15491. this.styleElement = null;
  15492. this.loadingRequests = [];
  15493. this.loadTestFontId = 0;
  15494. }
  15495. addNativeFontFace(nativeFontFace) {
  15496. this.nativeFontFaces.add(nativeFontFace);
  15497. this._document.fonts.add(nativeFontFace);
  15498. }
  15499. removeNativeFontFace(nativeFontFace) {
  15500. this.nativeFontFaces.delete(nativeFontFace);
  15501. this._document.fonts.delete(nativeFontFace);
  15502. }
  15503. insertRule(rule) {
  15504. if (!this.styleElement) {
  15505. this.styleElement = this._document.createElement("style");
  15506. this._document.documentElement.getElementsByTagName("head")[0].append(this.styleElement);
  15507. }
  15508. const styleSheet = this.styleElement.sheet;
  15509. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  15510. }
  15511. clear() {
  15512. for (const nativeFontFace of this.nativeFontFaces) {
  15513. this._document.fonts.delete(nativeFontFace);
  15514. }
  15515. this.nativeFontFaces.clear();
  15516. this.#systemFonts.clear();
  15517. if (this.styleElement) {
  15518. this.styleElement.remove();
  15519. this.styleElement = null;
  15520. }
  15521. }
  15522. async loadSystemFont({
  15523. systemFontInfo: info,
  15524. _inspectFont
  15525. }) {
  15526. if (!info || this.#systemFonts.has(info.loadedName)) {
  15527. return;
  15528. }
  15529. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(!this.disableFontFace, "loadSystemFont shouldn't be called when `disableFontFace` is set.");
  15530. if (this.isFontLoadingAPISupported) {
  15531. const {
  15532. loadedName,
  15533. src,
  15534. style
  15535. } = info;
  15536. const fontFace = new FontFace(loadedName, src, style);
  15537. this.addNativeFontFace(fontFace);
  15538. try {
  15539. await fontFace.load();
  15540. this.#systemFonts.add(loadedName);
  15541. _inspectFont?.(info);
  15542. } catch {
  15543. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`Cannot load system font: ${info.baseFontName}, installing it could help to improve PDF rendering.`);
  15544. this.removeNativeFontFace(fontFace);
  15545. }
  15546. return;
  15547. }
  15548. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.unreachable)("Not implemented: loadSystemFont without the Font Loading API.");
  15549. }
  15550. async bind(font) {
  15551. if (font.attached || font.missingFile && !font.systemFontInfo) {
  15552. return;
  15553. }
  15554. font.attached = true;
  15555. if (font.systemFontInfo) {
  15556. await this.loadSystemFont(font);
  15557. return;
  15558. }
  15559. if (this.isFontLoadingAPISupported) {
  15560. const nativeFontFace = font.createNativeFontFace();
  15561. if (nativeFontFace) {
  15562. this.addNativeFontFace(nativeFontFace);
  15563. try {
  15564. await nativeFontFace.loaded;
  15565. } catch (ex) {
  15566. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`Failed to load font '${nativeFontFace.family}': '${ex}'.`);
  15567. font.disableFontFace = true;
  15568. throw ex;
  15569. }
  15570. }
  15571. return;
  15572. }
  15573. const rule = font.createFontFaceRule();
  15574. if (rule) {
  15575. this.insertRule(rule);
  15576. if (this.isSyncFontLoadingSupported) {
  15577. return;
  15578. }
  15579. await new Promise(resolve => {
  15580. const request = this._queueLoadingCallback(resolve);
  15581. this._prepareFontLoadEvent(font, request);
  15582. });
  15583. }
  15584. }
  15585. get isFontLoadingAPISupported() {
  15586. const hasFonts = !!this._document?.fonts;
  15587. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow)(this, "isFontLoadingAPISupported", hasFonts);
  15588. }
  15589. get isSyncFontLoadingSupported() {
  15590. let supported = false;
  15591. if (_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.isNodeJS) {
  15592. supported = true;
  15593. } else if (typeof navigator !== "undefined" && typeof navigator?.userAgent === "string" && /Mozilla\/5.0.*?rv:\d+.*? Gecko/.test(navigator.userAgent)) {
  15594. supported = true;
  15595. }
  15596. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow)(this, "isSyncFontLoadingSupported", supported);
  15597. }
  15598. _queueLoadingCallback(callback) {
  15599. function completeRequest() {
  15600. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(!request.done, "completeRequest() cannot be called twice.");
  15601. request.done = true;
  15602. while (loadingRequests.length > 0 && loadingRequests[0].done) {
  15603. const otherRequest = loadingRequests.shift();
  15604. setTimeout(otherRequest.callback, 0);
  15605. }
  15606. }
  15607. const {
  15608. loadingRequests
  15609. } = this;
  15610. const request = {
  15611. done: false,
  15612. complete: completeRequest,
  15613. callback
  15614. };
  15615. loadingRequests.push(request);
  15616. return request;
  15617. }
  15618. get _loadTestFont() {
  15619. 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==");
  15620. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow)(this, "_loadTestFont", testFont);
  15621. }
  15622. _prepareFontLoadEvent(font, request) {
  15623. function int32(data, offset) {
  15624. return data.charCodeAt(offset) << 24 | data.charCodeAt(offset + 1) << 16 | data.charCodeAt(offset + 2) << 8 | data.charCodeAt(offset + 3) & 0xff;
  15625. }
  15626. function spliceString(s, offset, remove, insert) {
  15627. const chunk1 = s.substring(0, offset);
  15628. const chunk2 = s.substring(offset + remove);
  15629. return chunk1 + insert + chunk2;
  15630. }
  15631. let i, ii;
  15632. const canvas = this._document.createElement("canvas");
  15633. canvas.width = 1;
  15634. canvas.height = 1;
  15635. const ctx = canvas.getContext("2d");
  15636. let called = 0;
  15637. function isFontReady(name, callback) {
  15638. if (++called > 30) {
  15639. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)("Load test font never loaded.");
  15640. callback();
  15641. return;
  15642. }
  15643. ctx.font = "30px " + name;
  15644. ctx.fillText(".", 0, 20);
  15645. const imageData = ctx.getImageData(0, 0, 1, 1);
  15646. if (imageData.data[3] > 0) {
  15647. callback();
  15648. return;
  15649. }
  15650. setTimeout(isFontReady.bind(null, name, callback));
  15651. }
  15652. const loadTestFontId = `lt${Date.now()}${this.loadTestFontId++}`;
  15653. let data = this._loadTestFont;
  15654. const COMMENT_OFFSET = 976;
  15655. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length, loadTestFontId);
  15656. const CFF_CHECKSUM_OFFSET = 16;
  15657. const XXXX_VALUE = 0x58585858;
  15658. let checksum = int32(data, CFF_CHECKSUM_OFFSET);
  15659. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  15660. checksum = checksum - XXXX_VALUE + int32(loadTestFontId, i) | 0;
  15661. }
  15662. if (i < loadTestFontId.length) {
  15663. checksum = checksum - XXXX_VALUE + int32(loadTestFontId + "XXX", i) | 0;
  15664. }
  15665. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.string32)(checksum));
  15666. const url = `url(data:font/opentype;base64,${btoa(data)});`;
  15667. const rule = `@font-face {font-family:"${loadTestFontId}";src:${url}}`;
  15668. this.insertRule(rule);
  15669. const div = this._document.createElement("div");
  15670. div.style.visibility = "hidden";
  15671. div.style.width = div.style.height = "10px";
  15672. div.style.position = "absolute";
  15673. div.style.top = div.style.left = "0px";
  15674. for (const name of [font.loadedName, loadTestFontId]) {
  15675. const span = this._document.createElement("span");
  15676. span.textContent = "Hi";
  15677. span.style.fontFamily = name;
  15678. div.append(span);
  15679. }
  15680. this._document.body.append(div);
  15681. isFontReady(loadTestFontId, () => {
  15682. div.remove();
  15683. request.complete();
  15684. });
  15685. }
  15686. }
  15687. class FontFaceObject {
  15688. constructor(translatedData, {
  15689. disableFontFace = false,
  15690. ignoreErrors = false,
  15691. inspectFont = null
  15692. }) {
  15693. this.compiledGlyphs = Object.create(null);
  15694. for (const i in translatedData) {
  15695. this[i] = translatedData[i];
  15696. }
  15697. this.disableFontFace = disableFontFace === true;
  15698. this.ignoreErrors = ignoreErrors === true;
  15699. this._inspectFont = inspectFont;
  15700. }
  15701. createNativeFontFace() {
  15702. if (!this.data || this.disableFontFace) {
  15703. return null;
  15704. }
  15705. let nativeFontFace;
  15706. if (!this.cssFontInfo) {
  15707. nativeFontFace = new FontFace(this.loadedName, this.data, {});
  15708. } else {
  15709. const css = {
  15710. weight: this.cssFontInfo.fontWeight
  15711. };
  15712. if (this.cssFontInfo.italicAngle) {
  15713. css.style = `oblique ${this.cssFontInfo.italicAngle}deg`;
  15714. }
  15715. nativeFontFace = new FontFace(this.cssFontInfo.fontFamily, this.data, css);
  15716. }
  15717. this._inspectFont?.(this);
  15718. return nativeFontFace;
  15719. }
  15720. createFontFaceRule() {
  15721. if (!this.data || this.disableFontFace) {
  15722. return null;
  15723. }
  15724. const data = (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.bytesToString)(this.data);
  15725. const url = `url(data:${this.mimetype};base64,${btoa(data)});`;
  15726. let rule;
  15727. if (!this.cssFontInfo) {
  15728. rule = `@font-face {font-family:"${this.loadedName}";src:${url}}`;
  15729. } else {
  15730. let css = `font-weight: ${this.cssFontInfo.fontWeight};`;
  15731. if (this.cssFontInfo.italicAngle) {
  15732. css += `font-style: oblique ${this.cssFontInfo.italicAngle}deg;`;
  15733. }
  15734. rule = `@font-face {font-family:"${this.cssFontInfo.fontFamily}";${css}src:${url}}`;
  15735. }
  15736. this._inspectFont?.(this, url);
  15737. return rule;
  15738. }
  15739. getPathGenerator(objs, character) {
  15740. if (this.compiledGlyphs[character] !== undefined) {
  15741. return this.compiledGlyphs[character];
  15742. }
  15743. let cmds;
  15744. try {
  15745. cmds = objs.get(this.loadedName + "_path_" + character);
  15746. } catch (ex) {
  15747. if (!this.ignoreErrors) {
  15748. throw ex;
  15749. }
  15750. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`getPathGenerator - ignoring character: "${ex}".`);
  15751. }
  15752. if (!Array.isArray(cmds) || cmds.length === 0) {
  15753. return this.compiledGlyphs[character] = function (c, size) {};
  15754. }
  15755. const commands = [];
  15756. for (let i = 0, ii = cmds.length; i < ii;) {
  15757. switch (cmds[i++]) {
  15758. case _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.FontRenderOps.BEZIER_CURVE_TO:
  15759. {
  15760. const [a, b, c, d, e, f] = cmds.slice(i, i + 6);
  15761. commands.push(ctx => ctx.bezierCurveTo(a, b, c, d, e, f));
  15762. i += 6;
  15763. }
  15764. break;
  15765. case _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.FontRenderOps.MOVE_TO:
  15766. {
  15767. const [a, b] = cmds.slice(i, i + 2);
  15768. commands.push(ctx => ctx.moveTo(a, b));
  15769. i += 2;
  15770. }
  15771. break;
  15772. case _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.FontRenderOps.LINE_TO:
  15773. {
  15774. const [a, b] = cmds.slice(i, i + 2);
  15775. commands.push(ctx => ctx.lineTo(a, b));
  15776. i += 2;
  15777. }
  15778. break;
  15779. case _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.FontRenderOps.QUADRATIC_CURVE_TO:
  15780. {
  15781. const [a, b, c, d] = cmds.slice(i, i + 4);
  15782. commands.push(ctx => ctx.quadraticCurveTo(a, b, c, d));
  15783. i += 4;
  15784. }
  15785. break;
  15786. case _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.FontRenderOps.RESTORE:
  15787. commands.push(ctx => ctx.restore());
  15788. break;
  15789. case _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.FontRenderOps.SAVE:
  15790. commands.push(ctx => ctx.save());
  15791. break;
  15792. case _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.FontRenderOps.SCALE:
  15793. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(commands.length === 2, "Scale command is only valid at the third position.");
  15794. break;
  15795. case _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.FontRenderOps.TRANSFORM:
  15796. {
  15797. const [a, b, c, d, e, f] = cmds.slice(i, i + 6);
  15798. commands.push(ctx => ctx.transform(a, b, c, d, e, f));
  15799. i += 6;
  15800. }
  15801. break;
  15802. case _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.FontRenderOps.TRANSLATE:
  15803. {
  15804. const [a, b] = cmds.slice(i, i + 2);
  15805. commands.push(ctx => ctx.translate(a, b));
  15806. i += 2;
  15807. }
  15808. break;
  15809. }
  15810. }
  15811. return this.compiledGlyphs[character] = function glyphDrawer(ctx, size) {
  15812. commands[0](ctx);
  15813. commands[1](ctx);
  15814. ctx.scale(size, -size);
  15815. for (let i = 2, ii = commands.length; i < ii; i++) {
  15816. commands[i](ctx);
  15817. }
  15818. };
  15819. }
  15820. }
  15821. /***/ }),
  15822. /***/ 62:
  15823. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  15824. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  15825. /* harmony export */ Metadata: () => (/* binding */ Metadata)
  15826. /* harmony export */ });
  15827. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(292);
  15828. class Metadata {
  15829. #metadataMap;
  15830. #data;
  15831. constructor({
  15832. parsedData,
  15833. rawData
  15834. }) {
  15835. this.#metadataMap = parsedData;
  15836. this.#data = rawData;
  15837. }
  15838. getRaw() {
  15839. return this.#data;
  15840. }
  15841. get(name) {
  15842. return this.#metadataMap.get(name) ?? null;
  15843. }
  15844. getAll() {
  15845. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.objectFromMap)(this.#metadataMap);
  15846. }
  15847. has(name) {
  15848. return this.#metadataMap.has(name);
  15849. }
  15850. }
  15851. /***/ }),
  15852. /***/ 457:
  15853. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  15854. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  15855. /* harmony export */ PDFNetworkStream: () => (/* binding */ PDFNetworkStream)
  15856. /* harmony export */ });
  15857. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(292);
  15858. /* harmony import */ var _network_utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(490);
  15859. const OK_RESPONSE = 200;
  15860. const PARTIAL_CONTENT_RESPONSE = 206;
  15861. function getArrayBuffer(xhr) {
  15862. const data = xhr.response;
  15863. if (typeof data !== "string") {
  15864. return data;
  15865. }
  15866. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.stringToBytes)(data).buffer;
  15867. }
  15868. class NetworkManager {
  15869. constructor(url, args = {}) {
  15870. this.url = url;
  15871. this.isHttp = /^https?:/i.test(url);
  15872. this.httpHeaders = this.isHttp && args.httpHeaders || Object.create(null);
  15873. this.withCredentials = args.withCredentials || false;
  15874. this.currXhrId = 0;
  15875. this.pendingRequests = Object.create(null);
  15876. }
  15877. requestRange(begin, end, listeners) {
  15878. const args = {
  15879. begin,
  15880. end
  15881. };
  15882. for (const prop in listeners) {
  15883. args[prop] = listeners[prop];
  15884. }
  15885. return this.request(args);
  15886. }
  15887. requestFull(listeners) {
  15888. return this.request(listeners);
  15889. }
  15890. request(args) {
  15891. const xhr = new XMLHttpRequest();
  15892. const xhrId = this.currXhrId++;
  15893. const pendingRequest = this.pendingRequests[xhrId] = {
  15894. xhr
  15895. };
  15896. xhr.open("GET", this.url);
  15897. xhr.withCredentials = this.withCredentials;
  15898. for (const property in this.httpHeaders) {
  15899. const value = this.httpHeaders[property];
  15900. if (value === undefined) {
  15901. continue;
  15902. }
  15903. xhr.setRequestHeader(property, value);
  15904. }
  15905. if (this.isHttp && "begin" in args && "end" in args) {
  15906. xhr.setRequestHeader("Range", `bytes=${args.begin}-${args.end - 1}`);
  15907. pendingRequest.expectedStatus = PARTIAL_CONTENT_RESPONSE;
  15908. } else {
  15909. pendingRequest.expectedStatus = OK_RESPONSE;
  15910. }
  15911. xhr.responseType = "arraybuffer";
  15912. if (args.onError) {
  15913. xhr.onerror = function (evt) {
  15914. args.onError(xhr.status);
  15915. };
  15916. }
  15917. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  15918. xhr.onprogress = this.onProgress.bind(this, xhrId);
  15919. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  15920. pendingRequest.onDone = args.onDone;
  15921. pendingRequest.onError = args.onError;
  15922. pendingRequest.onProgress = args.onProgress;
  15923. xhr.send(null);
  15924. return xhrId;
  15925. }
  15926. onProgress(xhrId, evt) {
  15927. const pendingRequest = this.pendingRequests[xhrId];
  15928. if (!pendingRequest) {
  15929. return;
  15930. }
  15931. pendingRequest.onProgress?.(evt);
  15932. }
  15933. onStateChange(xhrId, evt) {
  15934. const pendingRequest = this.pendingRequests[xhrId];
  15935. if (!pendingRequest) {
  15936. return;
  15937. }
  15938. const xhr = pendingRequest.xhr;
  15939. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  15940. pendingRequest.onHeadersReceived();
  15941. delete pendingRequest.onHeadersReceived;
  15942. }
  15943. if (xhr.readyState !== 4) {
  15944. return;
  15945. }
  15946. if (!(xhrId in this.pendingRequests)) {
  15947. return;
  15948. }
  15949. delete this.pendingRequests[xhrId];
  15950. if (xhr.status === 0 && this.isHttp) {
  15951. pendingRequest.onError?.(xhr.status);
  15952. return;
  15953. }
  15954. const xhrStatus = xhr.status || OK_RESPONSE;
  15955. const ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  15956. if (!ok_response_on_range_request && xhrStatus !== pendingRequest.expectedStatus) {
  15957. pendingRequest.onError?.(xhr.status);
  15958. return;
  15959. }
  15960. const chunk = getArrayBuffer(xhr);
  15961. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  15962. const rangeHeader = xhr.getResponseHeader("Content-Range");
  15963. const matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  15964. pendingRequest.onDone({
  15965. begin: parseInt(matches[1], 10),
  15966. chunk
  15967. });
  15968. } else if (chunk) {
  15969. pendingRequest.onDone({
  15970. begin: 0,
  15971. chunk
  15972. });
  15973. } else {
  15974. pendingRequest.onError?.(xhr.status);
  15975. }
  15976. }
  15977. getRequestXhr(xhrId) {
  15978. return this.pendingRequests[xhrId].xhr;
  15979. }
  15980. isPendingRequest(xhrId) {
  15981. return xhrId in this.pendingRequests;
  15982. }
  15983. abortRequest(xhrId) {
  15984. const xhr = this.pendingRequests[xhrId].xhr;
  15985. delete this.pendingRequests[xhrId];
  15986. xhr.abort();
  15987. }
  15988. }
  15989. class PDFNetworkStream {
  15990. constructor(source) {
  15991. this._source = source;
  15992. this._manager = new NetworkManager(source.url, {
  15993. httpHeaders: source.httpHeaders,
  15994. withCredentials: source.withCredentials
  15995. });
  15996. this._rangeChunkSize = source.rangeChunkSize;
  15997. this._fullRequestReader = null;
  15998. this._rangeRequestReaders = [];
  15999. }
  16000. _onRangeRequestReaderClosed(reader) {
  16001. const i = this._rangeRequestReaders.indexOf(reader);
  16002. if (i >= 0) {
  16003. this._rangeRequestReaders.splice(i, 1);
  16004. }
  16005. }
  16006. getFullReader() {
  16007. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(!this._fullRequestReader, "PDFNetworkStream.getFullReader can only be called once.");
  16008. this._fullRequestReader = new PDFNetworkStreamFullRequestReader(this._manager, this._source);
  16009. return this._fullRequestReader;
  16010. }
  16011. getRangeReader(begin, end) {
  16012. const reader = new PDFNetworkStreamRangeRequestReader(this._manager, begin, end);
  16013. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  16014. this._rangeRequestReaders.push(reader);
  16015. return reader;
  16016. }
  16017. cancelAllRequests(reason) {
  16018. this._fullRequestReader?.cancel(reason);
  16019. for (const reader of this._rangeRequestReaders.slice(0)) {
  16020. reader.cancel(reason);
  16021. }
  16022. }
  16023. }
  16024. class PDFNetworkStreamFullRequestReader {
  16025. constructor(manager, source) {
  16026. this._manager = manager;
  16027. const args = {
  16028. onHeadersReceived: this._onHeadersReceived.bind(this),
  16029. onDone: this._onDone.bind(this),
  16030. onError: this._onError.bind(this),
  16031. onProgress: this._onProgress.bind(this)
  16032. };
  16033. this._url = source.url;
  16034. this._fullRequestId = manager.requestFull(args);
  16035. this._headersReceivedCapability = Promise.withResolvers();
  16036. this._disableRange = source.disableRange || false;
  16037. this._contentLength = source.length;
  16038. this._rangeChunkSize = source.rangeChunkSize;
  16039. if (!this._rangeChunkSize && !this._disableRange) {
  16040. this._disableRange = true;
  16041. }
  16042. this._isStreamingSupported = false;
  16043. this._isRangeSupported = false;
  16044. this._cachedChunks = [];
  16045. this._requests = [];
  16046. this._done = false;
  16047. this._storedError = undefined;
  16048. this._filename = null;
  16049. this.onProgress = null;
  16050. }
  16051. _onHeadersReceived() {
  16052. const fullRequestXhrId = this._fullRequestId;
  16053. const fullRequestXhr = this._manager.getRequestXhr(fullRequestXhrId);
  16054. const getResponseHeader = name => fullRequestXhr.getResponseHeader(name);
  16055. const {
  16056. allowRangeRequests,
  16057. suggestedLength
  16058. } = (0,_network_utils_js__WEBPACK_IMPORTED_MODULE_1__.validateRangeRequestCapabilities)({
  16059. getResponseHeader,
  16060. isHttp: this._manager.isHttp,
  16061. rangeChunkSize: this._rangeChunkSize,
  16062. disableRange: this._disableRange
  16063. });
  16064. if (allowRangeRequests) {
  16065. this._isRangeSupported = true;
  16066. }
  16067. this._contentLength = suggestedLength || this._contentLength;
  16068. this._filename = (0,_network_utils_js__WEBPACK_IMPORTED_MODULE_1__.extractFilenameFromHeader)(getResponseHeader);
  16069. if (this._isRangeSupported) {
  16070. this._manager.abortRequest(fullRequestXhrId);
  16071. }
  16072. this._headersReceivedCapability.resolve();
  16073. }
  16074. _onDone(data) {
  16075. if (data) {
  16076. if (this._requests.length > 0) {
  16077. const requestCapability = this._requests.shift();
  16078. requestCapability.resolve({
  16079. value: data.chunk,
  16080. done: false
  16081. });
  16082. } else {
  16083. this._cachedChunks.push(data.chunk);
  16084. }
  16085. }
  16086. this._done = true;
  16087. if (this._cachedChunks.length > 0) {
  16088. return;
  16089. }
  16090. for (const requestCapability of this._requests) {
  16091. requestCapability.resolve({
  16092. value: undefined,
  16093. done: true
  16094. });
  16095. }
  16096. this._requests.length = 0;
  16097. }
  16098. _onError(status) {
  16099. this._storedError = (0,_network_utils_js__WEBPACK_IMPORTED_MODULE_1__.createResponseStatusError)(status, this._url);
  16100. this._headersReceivedCapability.reject(this._storedError);
  16101. for (const requestCapability of this._requests) {
  16102. requestCapability.reject(this._storedError);
  16103. }
  16104. this._requests.length = 0;
  16105. this._cachedChunks.length = 0;
  16106. }
  16107. _onProgress(evt) {
  16108. this.onProgress?.({
  16109. loaded: evt.loaded,
  16110. total: evt.lengthComputable ? evt.total : this._contentLength
  16111. });
  16112. }
  16113. get filename() {
  16114. return this._filename;
  16115. }
  16116. get isRangeSupported() {
  16117. return this._isRangeSupported;
  16118. }
  16119. get isStreamingSupported() {
  16120. return this._isStreamingSupported;
  16121. }
  16122. get contentLength() {
  16123. return this._contentLength;
  16124. }
  16125. get headersReady() {
  16126. return this._headersReceivedCapability.promise;
  16127. }
  16128. async read() {
  16129. if (this._storedError) {
  16130. throw this._storedError;
  16131. }
  16132. if (this._cachedChunks.length > 0) {
  16133. const chunk = this._cachedChunks.shift();
  16134. return {
  16135. value: chunk,
  16136. done: false
  16137. };
  16138. }
  16139. if (this._done) {
  16140. return {
  16141. value: undefined,
  16142. done: true
  16143. };
  16144. }
  16145. const requestCapability = Promise.withResolvers();
  16146. this._requests.push(requestCapability);
  16147. return requestCapability.promise;
  16148. }
  16149. cancel(reason) {
  16150. this._done = true;
  16151. this._headersReceivedCapability.reject(reason);
  16152. for (const requestCapability of this._requests) {
  16153. requestCapability.resolve({
  16154. value: undefined,
  16155. done: true
  16156. });
  16157. }
  16158. this._requests.length = 0;
  16159. if (this._manager.isPendingRequest(this._fullRequestId)) {
  16160. this._manager.abortRequest(this._fullRequestId);
  16161. }
  16162. this._fullRequestReader = null;
  16163. }
  16164. }
  16165. class PDFNetworkStreamRangeRequestReader {
  16166. constructor(manager, begin, end) {
  16167. this._manager = manager;
  16168. const args = {
  16169. onDone: this._onDone.bind(this),
  16170. onError: this._onError.bind(this),
  16171. onProgress: this._onProgress.bind(this)
  16172. };
  16173. this._url = manager.url;
  16174. this._requestId = manager.requestRange(begin, end, args);
  16175. this._requests = [];
  16176. this._queuedChunk = null;
  16177. this._done = false;
  16178. this._storedError = undefined;
  16179. this.onProgress = null;
  16180. this.onClosed = null;
  16181. }
  16182. _close() {
  16183. this.onClosed?.(this);
  16184. }
  16185. _onDone(data) {
  16186. const chunk = data.chunk;
  16187. if (this._requests.length > 0) {
  16188. const requestCapability = this._requests.shift();
  16189. requestCapability.resolve({
  16190. value: chunk,
  16191. done: false
  16192. });
  16193. } else {
  16194. this._queuedChunk = chunk;
  16195. }
  16196. this._done = true;
  16197. for (const requestCapability of this._requests) {
  16198. requestCapability.resolve({
  16199. value: undefined,
  16200. done: true
  16201. });
  16202. }
  16203. this._requests.length = 0;
  16204. this._close();
  16205. }
  16206. _onError(status) {
  16207. this._storedError = (0,_network_utils_js__WEBPACK_IMPORTED_MODULE_1__.createResponseStatusError)(status, this._url);
  16208. for (const requestCapability of this._requests) {
  16209. requestCapability.reject(this._storedError);
  16210. }
  16211. this._requests.length = 0;
  16212. this._queuedChunk = null;
  16213. }
  16214. _onProgress(evt) {
  16215. if (!this.isStreamingSupported) {
  16216. this.onProgress?.({
  16217. loaded: evt.loaded
  16218. });
  16219. }
  16220. }
  16221. get isStreamingSupported() {
  16222. return false;
  16223. }
  16224. async read() {
  16225. if (this._storedError) {
  16226. throw this._storedError;
  16227. }
  16228. if (this._queuedChunk !== null) {
  16229. const chunk = this._queuedChunk;
  16230. this._queuedChunk = null;
  16231. return {
  16232. value: chunk,
  16233. done: false
  16234. };
  16235. }
  16236. if (this._done) {
  16237. return {
  16238. value: undefined,
  16239. done: true
  16240. };
  16241. }
  16242. const requestCapability = Promise.withResolvers();
  16243. this._requests.push(requestCapability);
  16244. return requestCapability.promise;
  16245. }
  16246. cancel(reason) {
  16247. this._done = true;
  16248. for (const requestCapability of this._requests) {
  16249. requestCapability.resolve({
  16250. value: undefined,
  16251. done: true
  16252. });
  16253. }
  16254. this._requests.length = 0;
  16255. if (this._manager.isPendingRequest(this._requestId)) {
  16256. this._manager.abortRequest(this._requestId);
  16257. }
  16258. this._close();
  16259. }
  16260. }
  16261. /***/ }),
  16262. /***/ 490:
  16263. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  16264. // EXPORTS
  16265. __webpack_require__.d(__webpack_exports__, {
  16266. createResponseStatusError: () => (/* binding */ createResponseStatusError),
  16267. extractFilenameFromHeader: () => (/* binding */ extractFilenameFromHeader),
  16268. validateRangeRequestCapabilities: () => (/* binding */ validateRangeRequestCapabilities),
  16269. validateResponseStatus: () => (/* binding */ validateResponseStatus)
  16270. });
  16271. // EXTERNAL MODULE: ./src/shared/util.js
  16272. var util = __webpack_require__(292);
  16273. ;// CONCATENATED MODULE: ./src/display/content_disposition.js
  16274. function getFilenameFromContentDispositionHeader(contentDisposition) {
  16275. let needsEncodingFixup = true;
  16276. let tmp = toParamRegExp("filename\\*", "i").exec(contentDisposition);
  16277. if (tmp) {
  16278. tmp = tmp[1];
  16279. let filename = rfc2616unquote(tmp);
  16280. filename = unescape(filename);
  16281. filename = rfc5987decode(filename);
  16282. filename = rfc2047decode(filename);
  16283. return fixupEncoding(filename);
  16284. }
  16285. tmp = rfc2231getparam(contentDisposition);
  16286. if (tmp) {
  16287. const filename = rfc2047decode(tmp);
  16288. return fixupEncoding(filename);
  16289. }
  16290. tmp = toParamRegExp("filename", "i").exec(contentDisposition);
  16291. if (tmp) {
  16292. tmp = tmp[1];
  16293. let filename = rfc2616unquote(tmp);
  16294. filename = rfc2047decode(filename);
  16295. return fixupEncoding(filename);
  16296. }
  16297. function toParamRegExp(attributePattern, flags) {
  16298. return new RegExp("(?:^|;)\\s*" + attributePattern + "\\s*=\\s*" + "(" + '[^";\\s][^;\\s]*' + "|" + '"(?:[^"\\\\]|\\\\"?)+"?' + ")", flags);
  16299. }
  16300. function textdecode(encoding, value) {
  16301. if (encoding) {
  16302. if (!/^[\x00-\xFF]+$/.test(value)) {
  16303. return value;
  16304. }
  16305. try {
  16306. const decoder = new TextDecoder(encoding, {
  16307. fatal: true
  16308. });
  16309. const buffer = (0,util.stringToBytes)(value);
  16310. value = decoder.decode(buffer);
  16311. needsEncodingFixup = false;
  16312. } catch {}
  16313. }
  16314. return value;
  16315. }
  16316. function fixupEncoding(value) {
  16317. if (needsEncodingFixup && /[\x80-\xff]/.test(value)) {
  16318. value = textdecode("utf-8", value);
  16319. if (needsEncodingFixup) {
  16320. value = textdecode("iso-8859-1", value);
  16321. }
  16322. }
  16323. return value;
  16324. }
  16325. function rfc2231getparam(contentDispositionStr) {
  16326. const matches = [];
  16327. let match;
  16328. const iter = toParamRegExp("filename\\*((?!0\\d)\\d+)(\\*?)", "ig");
  16329. while ((match = iter.exec(contentDispositionStr)) !== null) {
  16330. let [, n, quot, part] = match;
  16331. n = parseInt(n, 10);
  16332. if (n in matches) {
  16333. if (n === 0) {
  16334. break;
  16335. }
  16336. continue;
  16337. }
  16338. matches[n] = [quot, part];
  16339. }
  16340. const parts = [];
  16341. for (let n = 0; n < matches.length; ++n) {
  16342. if (!(n in matches)) {
  16343. break;
  16344. }
  16345. let [quot, part] = matches[n];
  16346. part = rfc2616unquote(part);
  16347. if (quot) {
  16348. part = unescape(part);
  16349. if (n === 0) {
  16350. part = rfc5987decode(part);
  16351. }
  16352. }
  16353. parts.push(part);
  16354. }
  16355. return parts.join("");
  16356. }
  16357. function rfc2616unquote(value) {
  16358. if (value.startsWith('"')) {
  16359. const parts = value.slice(1).split('\\"');
  16360. for (let i = 0; i < parts.length; ++i) {
  16361. const quotindex = parts[i].indexOf('"');
  16362. if (quotindex !== -1) {
  16363. parts[i] = parts[i].slice(0, quotindex);
  16364. parts.length = i + 1;
  16365. }
  16366. parts[i] = parts[i].replaceAll(/\\(.)/g, "$1");
  16367. }
  16368. value = parts.join('"');
  16369. }
  16370. return value;
  16371. }
  16372. function rfc5987decode(extvalue) {
  16373. const encodingend = extvalue.indexOf("'");
  16374. if (encodingend === -1) {
  16375. return extvalue;
  16376. }
  16377. const encoding = extvalue.slice(0, encodingend);
  16378. const langvalue = extvalue.slice(encodingend + 1);
  16379. const value = langvalue.replace(/^[^']*'/, "");
  16380. return textdecode(encoding, value);
  16381. }
  16382. function rfc2047decode(value) {
  16383. if (!value.startsWith("=?") || /[\x00-\x19\x80-\xff]/.test(value)) {
  16384. return value;
  16385. }
  16386. return value.replaceAll(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g, function (matches, charset, encoding, text) {
  16387. if (encoding === "q" || encoding === "Q") {
  16388. text = text.replaceAll("_", " ");
  16389. text = text.replaceAll(/=([0-9a-fA-F]{2})/g, function (match, hex) {
  16390. return String.fromCharCode(parseInt(hex, 16));
  16391. });
  16392. return textdecode(charset, text);
  16393. }
  16394. try {
  16395. text = atob(text);
  16396. } catch {}
  16397. return textdecode(charset, text);
  16398. });
  16399. }
  16400. return "";
  16401. }
  16402. // EXTERNAL MODULE: ./src/display/display_utils.js
  16403. var display_utils = __webpack_require__(419);
  16404. ;// CONCATENATED MODULE: ./src/display/network_utils.js
  16405. function validateRangeRequestCapabilities({
  16406. getResponseHeader,
  16407. isHttp,
  16408. rangeChunkSize,
  16409. disableRange
  16410. }) {
  16411. const returnValues = {
  16412. allowRangeRequests: false,
  16413. suggestedLength: undefined
  16414. };
  16415. const length = parseInt(getResponseHeader("Content-Length"), 10);
  16416. if (!Number.isInteger(length)) {
  16417. return returnValues;
  16418. }
  16419. returnValues.suggestedLength = length;
  16420. if (length <= 2 * rangeChunkSize) {
  16421. return returnValues;
  16422. }
  16423. if (disableRange || !isHttp) {
  16424. return returnValues;
  16425. }
  16426. if (getResponseHeader("Accept-Ranges") !== "bytes") {
  16427. return returnValues;
  16428. }
  16429. const contentEncoding = getResponseHeader("Content-Encoding") || "identity";
  16430. if (contentEncoding !== "identity") {
  16431. return returnValues;
  16432. }
  16433. returnValues.allowRangeRequests = true;
  16434. return returnValues;
  16435. }
  16436. function extractFilenameFromHeader(getResponseHeader) {
  16437. const contentDisposition = getResponseHeader("Content-Disposition");
  16438. if (contentDisposition) {
  16439. let filename = getFilenameFromContentDispositionHeader(contentDisposition);
  16440. if (filename.includes("%")) {
  16441. try {
  16442. filename = decodeURIComponent(filename);
  16443. } catch {}
  16444. }
  16445. if ((0,display_utils.isPdfFile)(filename)) {
  16446. return filename;
  16447. }
  16448. }
  16449. return null;
  16450. }
  16451. function createResponseStatusError(status, url) {
  16452. if (status === 404 || status === 0 && url.startsWith("file:")) {
  16453. return new util.MissingPDFException('Missing PDF "' + url + '".');
  16454. }
  16455. return new util.UnexpectedResponseException(`Unexpected server response (${status}) while retrieving PDF "${url}".`, status);
  16456. }
  16457. function validateResponseStatus(status) {
  16458. return status === 200 || status === 206;
  16459. }
  16460. /***/ }),
  16461. /***/ 786:
  16462. /***/ ((__webpack_module__, __webpack_exports__, __webpack_require__) => {
  16463. __webpack_require__.a(__webpack_module__, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
  16464. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  16465. /* harmony export */ PDFNodeStream: () => (/* binding */ PDFNodeStream)
  16466. /* harmony export */ });
  16467. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(292);
  16468. /* harmony import */ var _network_utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(490);
  16469. let fs, http, https, url;
  16470. if (_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.isNodeJS) {
  16471. fs = await import( /*webpackIgnore: true*/"fs");
  16472. http = await import( /*webpackIgnore: true*/"http");
  16473. https = await import( /*webpackIgnore: true*/"https");
  16474. url = await import( /*webpackIgnore: true*/"url");
  16475. }
  16476. const fileUriRegex = /^file:\/\/\/[a-zA-Z]:\//;
  16477. function parseUrl(sourceUrl) {
  16478. const parsedUrl = url.parse(sourceUrl);
  16479. if (parsedUrl.protocol === "file:" || parsedUrl.host) {
  16480. return parsedUrl;
  16481. }
  16482. if (/^[a-z]:[/\\]/i.test(sourceUrl)) {
  16483. return url.parse(`file:///${sourceUrl}`);
  16484. }
  16485. if (!parsedUrl.host) {
  16486. parsedUrl.protocol = "file:";
  16487. }
  16488. return parsedUrl;
  16489. }
  16490. class PDFNodeStream {
  16491. constructor(source) {
  16492. this.source = source;
  16493. this.url = parseUrl(source.url);
  16494. this.isHttp = this.url.protocol === "http:" || this.url.protocol === "https:";
  16495. this.isFsUrl = this.url.protocol === "file:";
  16496. this.httpHeaders = this.isHttp && source.httpHeaders || {};
  16497. this._fullRequestReader = null;
  16498. this._rangeRequestReaders = [];
  16499. }
  16500. get _progressiveDataLength() {
  16501. return this._fullRequestReader?._loaded ?? 0;
  16502. }
  16503. getFullReader() {
  16504. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(!this._fullRequestReader, "PDFNodeStream.getFullReader can only be called once.");
  16505. this._fullRequestReader = this.isFsUrl ? new PDFNodeStreamFsFullReader(this) : new PDFNodeStreamFullReader(this);
  16506. return this._fullRequestReader;
  16507. }
  16508. getRangeReader(start, end) {
  16509. if (end <= this._progressiveDataLength) {
  16510. return null;
  16511. }
  16512. const rangeReader = this.isFsUrl ? new PDFNodeStreamFsRangeReader(this, start, end) : new PDFNodeStreamRangeReader(this, start, end);
  16513. this._rangeRequestReaders.push(rangeReader);
  16514. return rangeReader;
  16515. }
  16516. cancelAllRequests(reason) {
  16517. this._fullRequestReader?.cancel(reason);
  16518. for (const reader of this._rangeRequestReaders.slice(0)) {
  16519. reader.cancel(reason);
  16520. }
  16521. }
  16522. }
  16523. class BaseFullReader {
  16524. constructor(stream) {
  16525. this._url = stream.url;
  16526. this._done = false;
  16527. this._storedError = null;
  16528. this.onProgress = null;
  16529. const source = stream.source;
  16530. this._contentLength = source.length;
  16531. this._loaded = 0;
  16532. this._filename = null;
  16533. this._disableRange = source.disableRange || false;
  16534. this._rangeChunkSize = source.rangeChunkSize;
  16535. if (!this._rangeChunkSize && !this._disableRange) {
  16536. this._disableRange = true;
  16537. }
  16538. this._isStreamingSupported = !source.disableStream;
  16539. this._isRangeSupported = !source.disableRange;
  16540. this._readableStream = null;
  16541. this._readCapability = Promise.withResolvers();
  16542. this._headersCapability = Promise.withResolvers();
  16543. }
  16544. get headersReady() {
  16545. return this._headersCapability.promise;
  16546. }
  16547. get filename() {
  16548. return this._filename;
  16549. }
  16550. get contentLength() {
  16551. return this._contentLength;
  16552. }
  16553. get isRangeSupported() {
  16554. return this._isRangeSupported;
  16555. }
  16556. get isStreamingSupported() {
  16557. return this._isStreamingSupported;
  16558. }
  16559. async read() {
  16560. await this._readCapability.promise;
  16561. if (this._done) {
  16562. return {
  16563. value: undefined,
  16564. done: true
  16565. };
  16566. }
  16567. if (this._storedError) {
  16568. throw this._storedError;
  16569. }
  16570. const chunk = this._readableStream.read();
  16571. if (chunk === null) {
  16572. this._readCapability = Promise.withResolvers();
  16573. return this.read();
  16574. }
  16575. this._loaded += chunk.length;
  16576. this.onProgress?.({
  16577. loaded: this._loaded,
  16578. total: this._contentLength
  16579. });
  16580. const buffer = new Uint8Array(chunk).buffer;
  16581. return {
  16582. value: buffer,
  16583. done: false
  16584. };
  16585. }
  16586. cancel(reason) {
  16587. if (!this._readableStream) {
  16588. this._error(reason);
  16589. return;
  16590. }
  16591. this._readableStream.destroy(reason);
  16592. }
  16593. _error(reason) {
  16594. this._storedError = reason;
  16595. this._readCapability.resolve();
  16596. }
  16597. _setReadableStream(readableStream) {
  16598. this._readableStream = readableStream;
  16599. readableStream.on("readable", () => {
  16600. this._readCapability.resolve();
  16601. });
  16602. readableStream.on("end", () => {
  16603. readableStream.destroy();
  16604. this._done = true;
  16605. this._readCapability.resolve();
  16606. });
  16607. readableStream.on("error", reason => {
  16608. this._error(reason);
  16609. });
  16610. if (!this._isStreamingSupported && this._isRangeSupported) {
  16611. this._error(new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AbortException("streaming is disabled"));
  16612. }
  16613. if (this._storedError) {
  16614. this._readableStream.destroy(this._storedError);
  16615. }
  16616. }
  16617. }
  16618. class BaseRangeReader {
  16619. constructor(stream) {
  16620. this._url = stream.url;
  16621. this._done = false;
  16622. this._storedError = null;
  16623. this.onProgress = null;
  16624. this._loaded = 0;
  16625. this._readableStream = null;
  16626. this._readCapability = Promise.withResolvers();
  16627. const source = stream.source;
  16628. this._isStreamingSupported = !source.disableStream;
  16629. }
  16630. get isStreamingSupported() {
  16631. return this._isStreamingSupported;
  16632. }
  16633. async read() {
  16634. await this._readCapability.promise;
  16635. if (this._done) {
  16636. return {
  16637. value: undefined,
  16638. done: true
  16639. };
  16640. }
  16641. if (this._storedError) {
  16642. throw this._storedError;
  16643. }
  16644. const chunk = this._readableStream.read();
  16645. if (chunk === null) {
  16646. this._readCapability = Promise.withResolvers();
  16647. return this.read();
  16648. }
  16649. this._loaded += chunk.length;
  16650. this.onProgress?.({
  16651. loaded: this._loaded
  16652. });
  16653. const buffer = new Uint8Array(chunk).buffer;
  16654. return {
  16655. value: buffer,
  16656. done: false
  16657. };
  16658. }
  16659. cancel(reason) {
  16660. if (!this._readableStream) {
  16661. this._error(reason);
  16662. return;
  16663. }
  16664. this._readableStream.destroy(reason);
  16665. }
  16666. _error(reason) {
  16667. this._storedError = reason;
  16668. this._readCapability.resolve();
  16669. }
  16670. _setReadableStream(readableStream) {
  16671. this._readableStream = readableStream;
  16672. readableStream.on("readable", () => {
  16673. this._readCapability.resolve();
  16674. });
  16675. readableStream.on("end", () => {
  16676. readableStream.destroy();
  16677. this._done = true;
  16678. this._readCapability.resolve();
  16679. });
  16680. readableStream.on("error", reason => {
  16681. this._error(reason);
  16682. });
  16683. if (this._storedError) {
  16684. this._readableStream.destroy(this._storedError);
  16685. }
  16686. }
  16687. }
  16688. function createRequestOptions(parsedUrl, headers) {
  16689. return {
  16690. protocol: parsedUrl.protocol,
  16691. auth: parsedUrl.auth,
  16692. host: parsedUrl.hostname,
  16693. port: parsedUrl.port,
  16694. path: parsedUrl.path,
  16695. method: "GET",
  16696. headers
  16697. };
  16698. }
  16699. class PDFNodeStreamFullReader extends BaseFullReader {
  16700. constructor(stream) {
  16701. super(stream);
  16702. const handleResponse = response => {
  16703. if (response.statusCode === 404) {
  16704. const error = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.MissingPDFException(`Missing PDF "${this._url}".`);
  16705. this._storedError = error;
  16706. this._headersCapability.reject(error);
  16707. return;
  16708. }
  16709. this._headersCapability.resolve();
  16710. this._setReadableStream(response);
  16711. const getResponseHeader = name => this._readableStream.headers[name.toLowerCase()];
  16712. const {
  16713. allowRangeRequests,
  16714. suggestedLength
  16715. } = (0,_network_utils_js__WEBPACK_IMPORTED_MODULE_1__.validateRangeRequestCapabilities)({
  16716. getResponseHeader,
  16717. isHttp: stream.isHttp,
  16718. rangeChunkSize: this._rangeChunkSize,
  16719. disableRange: this._disableRange
  16720. });
  16721. this._isRangeSupported = allowRangeRequests;
  16722. this._contentLength = suggestedLength || this._contentLength;
  16723. this._filename = (0,_network_utils_js__WEBPACK_IMPORTED_MODULE_1__.extractFilenameFromHeader)(getResponseHeader);
  16724. };
  16725. this._request = null;
  16726. if (this._url.protocol === "http:") {
  16727. this._request = http.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
  16728. } else {
  16729. this._request = https.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
  16730. }
  16731. this._request.on("error", reason => {
  16732. this._storedError = reason;
  16733. this._headersCapability.reject(reason);
  16734. });
  16735. this._request.end();
  16736. }
  16737. }
  16738. class PDFNodeStreamRangeReader extends BaseRangeReader {
  16739. constructor(stream, start, end) {
  16740. super(stream);
  16741. this._httpHeaders = {};
  16742. for (const property in stream.httpHeaders) {
  16743. const value = stream.httpHeaders[property];
  16744. if (value === undefined) {
  16745. continue;
  16746. }
  16747. this._httpHeaders[property] = value;
  16748. }
  16749. this._httpHeaders.Range = `bytes=${start}-${end - 1}`;
  16750. const handleResponse = response => {
  16751. if (response.statusCode === 404) {
  16752. const error = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.MissingPDFException(`Missing PDF "${this._url}".`);
  16753. this._storedError = error;
  16754. return;
  16755. }
  16756. this._setReadableStream(response);
  16757. };
  16758. this._request = null;
  16759. if (this._url.protocol === "http:") {
  16760. this._request = http.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
  16761. } else {
  16762. this._request = https.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
  16763. }
  16764. this._request.on("error", reason => {
  16765. this._storedError = reason;
  16766. });
  16767. this._request.end();
  16768. }
  16769. }
  16770. class PDFNodeStreamFsFullReader extends BaseFullReader {
  16771. constructor(stream) {
  16772. super(stream);
  16773. let path = decodeURIComponent(this._url.path);
  16774. if (fileUriRegex.test(this._url.href)) {
  16775. path = path.replace(/^\//, "");
  16776. }
  16777. fs.promises.lstat(path).then(stat => {
  16778. this._contentLength = stat.size;
  16779. this._setReadableStream(fs.createReadStream(path));
  16780. this._headersCapability.resolve();
  16781. }, error => {
  16782. if (error.code === "ENOENT") {
  16783. error = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.MissingPDFException(`Missing PDF "${path}".`);
  16784. }
  16785. this._storedError = error;
  16786. this._headersCapability.reject(error);
  16787. });
  16788. }
  16789. }
  16790. class PDFNodeStreamFsRangeReader extends BaseRangeReader {
  16791. constructor(stream, start, end) {
  16792. super(stream);
  16793. let path = decodeURIComponent(this._url.path);
  16794. if (fileUriRegex.test(this._url.href)) {
  16795. path = path.replace(/^\//, "");
  16796. }
  16797. this._setReadableStream(fs.createReadStream(path, {
  16798. start,
  16799. end: end - 1
  16800. }));
  16801. }
  16802. }
  16803. __webpack_async_result__();
  16804. } catch(e) { __webpack_async_result__(e); } }, 1);
  16805. /***/ }),
  16806. /***/ 573:
  16807. /***/ ((__webpack_module__, __webpack_exports__, __webpack_require__) => {
  16808. __webpack_require__.a(__webpack_module__, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
  16809. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  16810. /* harmony export */ NodeCMapReaderFactory: () => (/* binding */ NodeCMapReaderFactory),
  16811. /* harmony export */ NodeCanvasFactory: () => (/* binding */ NodeCanvasFactory),
  16812. /* harmony export */ NodeFilterFactory: () => (/* binding */ NodeFilterFactory),
  16813. /* harmony export */ NodeStandardFontDataFactory: () => (/* binding */ NodeStandardFontDataFactory)
  16814. /* harmony export */ });
  16815. /* harmony import */ var _base_factory_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(583);
  16816. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(292);
  16817. let fs, canvas, path2d;
  16818. if (_shared_util_js__WEBPACK_IMPORTED_MODULE_1__.isNodeJS) {
  16819. fs = await import( /*webpackIgnore: true*/"fs");
  16820. try {
  16821. canvas = await import( /*webpackIgnore: true*/"canvas");
  16822. } catch {}
  16823. try {
  16824. path2d = await import( /*webpackIgnore: true*/"path2d");
  16825. } catch {}
  16826. }
  16827. const fetchData = function (url) {
  16828. return fs.promises.readFile(url).then(data => new Uint8Array(data));
  16829. };
  16830. class NodeFilterFactory extends _base_factory_js__WEBPACK_IMPORTED_MODULE_0__.BaseFilterFactory {}
  16831. class NodeCanvasFactory extends _base_factory_js__WEBPACK_IMPORTED_MODULE_0__.BaseCanvasFactory {
  16832. _createCanvas(width, height) {
  16833. return canvas.createCanvas(width, height);
  16834. }
  16835. }
  16836. class NodeCMapReaderFactory extends _base_factory_js__WEBPACK_IMPORTED_MODULE_0__.BaseCMapReaderFactory {
  16837. _fetchData(url, compressionType) {
  16838. return fetchData(url).then(data => ({
  16839. cMapData: data,
  16840. compressionType
  16841. }));
  16842. }
  16843. }
  16844. class NodeStandardFontDataFactory extends _base_factory_js__WEBPACK_IMPORTED_MODULE_0__.BaseStandardFontDataFactory {
  16845. _fetchData(url) {
  16846. return fetchData(url);
  16847. }
  16848. }
  16849. __webpack_async_result__();
  16850. } catch(e) { __webpack_async_result__(e); } }, 1);
  16851. /***/ }),
  16852. /***/ 626:
  16853. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  16854. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  16855. /* harmony export */ OptionalContentConfig: () => (/* binding */ OptionalContentConfig)
  16856. /* harmony export */ });
  16857. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(292);
  16858. /* harmony import */ var _shared_murmurhash3_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(651);
  16859. const INTERNAL = Symbol("INTERNAL");
  16860. class OptionalContentGroup {
  16861. #isDisplay = false;
  16862. #isPrint = false;
  16863. #userSet = false;
  16864. #visible = true;
  16865. constructor(renderingIntent, {
  16866. name,
  16867. intent,
  16868. usage
  16869. }) {
  16870. this.#isDisplay = !!(renderingIntent & _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.RenderingIntentFlag.DISPLAY);
  16871. this.#isPrint = !!(renderingIntent & _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.RenderingIntentFlag.PRINT);
  16872. this.name = name;
  16873. this.intent = intent;
  16874. this.usage = usage;
  16875. }
  16876. get visible() {
  16877. if (this.#userSet) {
  16878. return this.#visible;
  16879. }
  16880. if (!this.#visible) {
  16881. return false;
  16882. }
  16883. const {
  16884. print,
  16885. view
  16886. } = this.usage;
  16887. if (this.#isDisplay) {
  16888. return view?.viewState !== "OFF";
  16889. } else if (this.#isPrint) {
  16890. return print?.printState !== "OFF";
  16891. }
  16892. return true;
  16893. }
  16894. _setVisible(internal, visible, userSet = false) {
  16895. if (internal !== INTERNAL) {
  16896. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.unreachable)("Internal method `_setVisible` called.");
  16897. }
  16898. this.#userSet = userSet;
  16899. this.#visible = visible;
  16900. }
  16901. }
  16902. class OptionalContentConfig {
  16903. #cachedGetHash = null;
  16904. #groups = new Map();
  16905. #initialHash = null;
  16906. #order = null;
  16907. constructor(data, renderingIntent = _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.RenderingIntentFlag.DISPLAY) {
  16908. this.renderingIntent = renderingIntent;
  16909. this.name = null;
  16910. this.creator = null;
  16911. if (data === null) {
  16912. return;
  16913. }
  16914. this.name = data.name;
  16915. this.creator = data.creator;
  16916. this.#order = data.order;
  16917. for (const group of data.groups) {
  16918. this.#groups.set(group.id, new OptionalContentGroup(renderingIntent, group));
  16919. }
  16920. if (data.baseState === "OFF") {
  16921. for (const group of this.#groups.values()) {
  16922. group._setVisible(INTERNAL, false);
  16923. }
  16924. }
  16925. for (const on of data.on) {
  16926. this.#groups.get(on)._setVisible(INTERNAL, true);
  16927. }
  16928. for (const off of data.off) {
  16929. this.#groups.get(off)._setVisible(INTERNAL, false);
  16930. }
  16931. this.#initialHash = this.getHash();
  16932. }
  16933. #evaluateVisibilityExpression(array) {
  16934. const length = array.length;
  16935. if (length < 2) {
  16936. return true;
  16937. }
  16938. const operator = array[0];
  16939. for (let i = 1; i < length; i++) {
  16940. const element = array[i];
  16941. let state;
  16942. if (Array.isArray(element)) {
  16943. state = this.#evaluateVisibilityExpression(element);
  16944. } else if (this.#groups.has(element)) {
  16945. state = this.#groups.get(element).visible;
  16946. } else {
  16947. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`Optional content group not found: ${element}`);
  16948. return true;
  16949. }
  16950. switch (operator) {
  16951. case "And":
  16952. if (!state) {
  16953. return false;
  16954. }
  16955. break;
  16956. case "Or":
  16957. if (state) {
  16958. return true;
  16959. }
  16960. break;
  16961. case "Not":
  16962. return !state;
  16963. default:
  16964. return true;
  16965. }
  16966. }
  16967. return operator === "And";
  16968. }
  16969. isVisible(group) {
  16970. if (this.#groups.size === 0) {
  16971. return true;
  16972. }
  16973. if (!group) {
  16974. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.info)("Optional content group not defined.");
  16975. return true;
  16976. }
  16977. if (group.type === "OCG") {
  16978. if (!this.#groups.has(group.id)) {
  16979. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`Optional content group not found: ${group.id}`);
  16980. return true;
  16981. }
  16982. return this.#groups.get(group.id).visible;
  16983. } else if (group.type === "OCMD") {
  16984. if (group.expression) {
  16985. return this.#evaluateVisibilityExpression(group.expression);
  16986. }
  16987. if (!group.policy || group.policy === "AnyOn") {
  16988. for (const id of group.ids) {
  16989. if (!this.#groups.has(id)) {
  16990. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`Optional content group not found: ${id}`);
  16991. return true;
  16992. }
  16993. if (this.#groups.get(id).visible) {
  16994. return true;
  16995. }
  16996. }
  16997. return false;
  16998. } else if (group.policy === "AllOn") {
  16999. for (const id of group.ids) {
  17000. if (!this.#groups.has(id)) {
  17001. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`Optional content group not found: ${id}`);
  17002. return true;
  17003. }
  17004. if (!this.#groups.get(id).visible) {
  17005. return false;
  17006. }
  17007. }
  17008. return true;
  17009. } else if (group.policy === "AnyOff") {
  17010. for (const id of group.ids) {
  17011. if (!this.#groups.has(id)) {
  17012. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`Optional content group not found: ${id}`);
  17013. return true;
  17014. }
  17015. if (!this.#groups.get(id).visible) {
  17016. return true;
  17017. }
  17018. }
  17019. return false;
  17020. } else if (group.policy === "AllOff") {
  17021. for (const id of group.ids) {
  17022. if (!this.#groups.has(id)) {
  17023. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`Optional content group not found: ${id}`);
  17024. return true;
  17025. }
  17026. if (this.#groups.get(id).visible) {
  17027. return false;
  17028. }
  17029. }
  17030. return true;
  17031. }
  17032. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`Unknown optional content policy ${group.policy}.`);
  17033. return true;
  17034. }
  17035. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`Unknown group type ${group.type}.`);
  17036. return true;
  17037. }
  17038. setVisibility(id, visible = true) {
  17039. const group = this.#groups.get(id);
  17040. if (!group) {
  17041. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`Optional content group not found: ${id}`);
  17042. return;
  17043. }
  17044. group._setVisible(INTERNAL, !!visible, true);
  17045. this.#cachedGetHash = null;
  17046. }
  17047. setOCGState({
  17048. state,
  17049. preserveRB
  17050. }) {
  17051. let operator;
  17052. for (const elem of state) {
  17053. switch (elem) {
  17054. case "ON":
  17055. case "OFF":
  17056. case "Toggle":
  17057. operator = elem;
  17058. continue;
  17059. }
  17060. const group = this.#groups.get(elem);
  17061. if (!group) {
  17062. continue;
  17063. }
  17064. switch (operator) {
  17065. case "ON":
  17066. group._setVisible(INTERNAL, true);
  17067. break;
  17068. case "OFF":
  17069. group._setVisible(INTERNAL, false);
  17070. break;
  17071. case "Toggle":
  17072. group._setVisible(INTERNAL, !group.visible);
  17073. break;
  17074. }
  17075. }
  17076. this.#cachedGetHash = null;
  17077. }
  17078. get hasInitialVisibility() {
  17079. return this.#initialHash === null || this.getHash() === this.#initialHash;
  17080. }
  17081. getOrder() {
  17082. if (!this.#groups.size) {
  17083. return null;
  17084. }
  17085. if (this.#order) {
  17086. return this.#order.slice();
  17087. }
  17088. return [...this.#groups.keys()];
  17089. }
  17090. getGroups() {
  17091. return this.#groups.size > 0 ? (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.objectFromMap)(this.#groups) : null;
  17092. }
  17093. getGroup(id) {
  17094. return this.#groups.get(id) || null;
  17095. }
  17096. getHash() {
  17097. if (this.#cachedGetHash !== null) {
  17098. return this.#cachedGetHash;
  17099. }
  17100. const hash = new _shared_murmurhash3_js__WEBPACK_IMPORTED_MODULE_1__.MurmurHash3_64();
  17101. for (const [id, group] of this.#groups) {
  17102. hash.update(`${id}:${group.visible}`);
  17103. }
  17104. return this.#cachedGetHash = hash.hexdigest();
  17105. }
  17106. }
  17107. /***/ }),
  17108. /***/ 814:
  17109. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  17110. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  17111. /* harmony export */ cleanupTextLayer: () => (/* binding */ cleanupTextLayer),
  17112. /* harmony export */ renderTextLayer: () => (/* binding */ renderTextLayer),
  17113. /* harmony export */ updateTextLayer: () => (/* binding */ updateTextLayer)
  17114. /* harmony export */ });
  17115. /* unused harmony export TextLayerRenderTask */
  17116. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(292);
  17117. /* harmony import */ var _display_utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(419);
  17118. const MAX_TEXT_DIVS_TO_RENDER = 100000;
  17119. const DEFAULT_FONT_SIZE = 30;
  17120. const DEFAULT_FONT_ASCENT = 0.8;
  17121. const ascentCache = new Map();
  17122. let _canvasContext = null;
  17123. function getCtx() {
  17124. if (!_canvasContext) {
  17125. const canvas = document.createElement("canvas");
  17126. canvas.className = "hiddenCanvasElement";
  17127. document.body.append(canvas);
  17128. _canvasContext = canvas.getContext("2d", {
  17129. alpha: false
  17130. });
  17131. }
  17132. return _canvasContext;
  17133. }
  17134. function cleanupTextLayer() {
  17135. _canvasContext?.canvas.remove();
  17136. _canvasContext = null;
  17137. }
  17138. function getAscent(fontFamily) {
  17139. const cachedAscent = ascentCache.get(fontFamily);
  17140. if (cachedAscent) {
  17141. return cachedAscent;
  17142. }
  17143. const ctx = getCtx();
  17144. const savedFont = ctx.font;
  17145. ctx.canvas.width = ctx.canvas.height = DEFAULT_FONT_SIZE;
  17146. ctx.font = `${DEFAULT_FONT_SIZE}px ${fontFamily}`;
  17147. const metrics = ctx.measureText("");
  17148. let ascent = metrics.fontBoundingBoxAscent;
  17149. let descent = Math.abs(metrics.fontBoundingBoxDescent);
  17150. if (ascent) {
  17151. const ratio = ascent / (ascent + descent);
  17152. ascentCache.set(fontFamily, ratio);
  17153. ctx.canvas.width = ctx.canvas.height = 0;
  17154. ctx.font = savedFont;
  17155. return ratio;
  17156. }
  17157. ctx.strokeStyle = "red";
  17158. ctx.clearRect(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE);
  17159. ctx.strokeText("g", 0, 0);
  17160. let pixels = ctx.getImageData(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE).data;
  17161. descent = 0;
  17162. for (let i = pixels.length - 1 - 3; i >= 0; i -= 4) {
  17163. if (pixels[i] > 0) {
  17164. descent = Math.ceil(i / 4 / DEFAULT_FONT_SIZE);
  17165. break;
  17166. }
  17167. }
  17168. ctx.clearRect(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE);
  17169. ctx.strokeText("A", 0, DEFAULT_FONT_SIZE);
  17170. pixels = ctx.getImageData(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE).data;
  17171. ascent = 0;
  17172. for (let i = 0, ii = pixels.length; i < ii; i += 4) {
  17173. if (pixels[i] > 0) {
  17174. ascent = DEFAULT_FONT_SIZE - Math.floor(i / 4 / DEFAULT_FONT_SIZE);
  17175. break;
  17176. }
  17177. }
  17178. ctx.canvas.width = ctx.canvas.height = 0;
  17179. ctx.font = savedFont;
  17180. if (ascent) {
  17181. const ratio = ascent / (ascent + descent);
  17182. ascentCache.set(fontFamily, ratio);
  17183. return ratio;
  17184. }
  17185. ascentCache.set(fontFamily, DEFAULT_FONT_ASCENT);
  17186. return DEFAULT_FONT_ASCENT;
  17187. }
  17188. function appendText(task, geom, styles) {
  17189. const textDiv = document.createElement("span");
  17190. const textDivProperties = {
  17191. angle: 0,
  17192. canvasWidth: 0,
  17193. hasText: geom.str !== "",
  17194. hasEOL: geom.hasEOL,
  17195. fontSize: 0
  17196. };
  17197. task._textDivs.push(textDiv);
  17198. const tx = _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.Util.transform(task._transform, geom.transform);
  17199. let angle = Math.atan2(tx[1], tx[0]);
  17200. const style = styles[geom.fontName];
  17201. if (style.vertical) {
  17202. angle += Math.PI / 2;
  17203. }
  17204. const fontFamily = task._fontInspectorEnabled && style.fontSubstitution || style.fontFamily;
  17205. const fontHeight = Math.hypot(tx[2], tx[3]);
  17206. const fontAscent = fontHeight * getAscent(fontFamily);
  17207. let left, top;
  17208. if (angle === 0) {
  17209. left = tx[4];
  17210. top = tx[5] - fontAscent;
  17211. } else {
  17212. left = tx[4] + fontAscent * Math.sin(angle);
  17213. top = tx[5] - fontAscent * Math.cos(angle);
  17214. }
  17215. const scaleFactorStr = "calc(var(--scale-factor)*";
  17216. const divStyle = textDiv.style;
  17217. if (task._container === task._rootContainer) {
  17218. divStyle.left = `${(100 * left / task._pageWidth).toFixed(2)}%`;
  17219. divStyle.top = `${(100 * top / task._pageHeight).toFixed(2)}%`;
  17220. } else {
  17221. divStyle.left = `${scaleFactorStr}${left.toFixed(2)}px)`;
  17222. divStyle.top = `${scaleFactorStr}${top.toFixed(2)}px)`;
  17223. }
  17224. divStyle.fontSize = `${scaleFactorStr}${fontHeight.toFixed(2)}px)`;
  17225. divStyle.fontFamily = fontFamily;
  17226. textDivProperties.fontSize = fontHeight;
  17227. textDiv.setAttribute("role", "presentation");
  17228. textDiv.textContent = geom.str;
  17229. textDiv.dir = geom.dir;
  17230. if (task._fontInspectorEnabled) {
  17231. textDiv.dataset.fontName = style.fontSubstitutionLoadedName || geom.fontName;
  17232. }
  17233. if (angle !== 0) {
  17234. textDivProperties.angle = angle * (180 / Math.PI);
  17235. }
  17236. let shouldScaleText = false;
  17237. if (geom.str.length > 1) {
  17238. shouldScaleText = true;
  17239. } else if (geom.str !== " " && geom.transform[0] !== geom.transform[3]) {
  17240. const absScaleX = Math.abs(geom.transform[0]),
  17241. absScaleY = Math.abs(geom.transform[3]);
  17242. if (absScaleX !== absScaleY && Math.max(absScaleX, absScaleY) / Math.min(absScaleX, absScaleY) > 1.5) {
  17243. shouldScaleText = true;
  17244. }
  17245. }
  17246. if (shouldScaleText) {
  17247. textDivProperties.canvasWidth = style.vertical ? geom.height : geom.width;
  17248. }
  17249. task._textDivProperties.set(textDiv, textDivProperties);
  17250. if (task._isReadableStream) {
  17251. task._layoutText(textDiv);
  17252. }
  17253. }
  17254. function layout(params) {
  17255. const {
  17256. div,
  17257. scale,
  17258. properties,
  17259. ctx,
  17260. prevFontSize,
  17261. prevFontFamily
  17262. } = params;
  17263. const {
  17264. style
  17265. } = div;
  17266. let transform = "";
  17267. if (properties.canvasWidth !== 0 && properties.hasText) {
  17268. const {
  17269. fontFamily
  17270. } = style;
  17271. const {
  17272. canvasWidth,
  17273. fontSize
  17274. } = properties;
  17275. if (prevFontSize !== fontSize || prevFontFamily !== fontFamily) {
  17276. ctx.font = `${fontSize * scale}px ${fontFamily}`;
  17277. params.prevFontSize = fontSize;
  17278. params.prevFontFamily = fontFamily;
  17279. }
  17280. const {
  17281. width
  17282. } = ctx.measureText(div.textContent);
  17283. if (width > 0) {
  17284. transform = `scaleX(${canvasWidth * scale / width})`;
  17285. }
  17286. }
  17287. if (properties.angle !== 0) {
  17288. transform = `rotate(${properties.angle}deg) ${transform}`;
  17289. }
  17290. if (transform.length > 0) {
  17291. style.transform = transform;
  17292. }
  17293. }
  17294. function render(task) {
  17295. if (task._canceled) {
  17296. return;
  17297. }
  17298. const textDivs = task._textDivs;
  17299. const capability = task._capability;
  17300. const textDivsLength = textDivs.length;
  17301. if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
  17302. capability.resolve();
  17303. return;
  17304. }
  17305. if (!task._isReadableStream) {
  17306. for (const textDiv of textDivs) {
  17307. task._layoutText(textDiv);
  17308. }
  17309. }
  17310. capability.resolve();
  17311. }
  17312. class TextLayerRenderTask {
  17313. constructor({
  17314. textContentSource,
  17315. container,
  17316. viewport,
  17317. textDivs,
  17318. textDivProperties,
  17319. textContentItemsStr
  17320. }) {
  17321. this._textContentSource = textContentSource;
  17322. this._isReadableStream = textContentSource instanceof ReadableStream;
  17323. this._container = this._rootContainer = container;
  17324. this._textDivs = textDivs || [];
  17325. this._textContentItemsStr = textContentItemsStr || [];
  17326. this._fontInspectorEnabled = !!globalThis.FontInspector?.enabled;
  17327. this._reader = null;
  17328. this._textDivProperties = textDivProperties || new WeakMap();
  17329. this._canceled = false;
  17330. this._capability = Promise.withResolvers();
  17331. this._layoutTextParams = {
  17332. prevFontSize: null,
  17333. prevFontFamily: null,
  17334. div: null,
  17335. scale: viewport.scale * (globalThis.devicePixelRatio || 1),
  17336. properties: null,
  17337. ctx: getCtx()
  17338. };
  17339. const {
  17340. pageWidth,
  17341. pageHeight,
  17342. pageX,
  17343. pageY
  17344. } = viewport.rawDims;
  17345. this._transform = [1, 0, 0, -1, -pageX, pageY + pageHeight];
  17346. this._pageWidth = pageWidth;
  17347. this._pageHeight = pageHeight;
  17348. (0,_display_utils_js__WEBPACK_IMPORTED_MODULE_1__.setLayerDimensions)(container, viewport);
  17349. this._capability.promise.finally(() => {
  17350. this._layoutTextParams = null;
  17351. }).catch(() => {});
  17352. }
  17353. get promise() {
  17354. return this._capability.promise;
  17355. }
  17356. cancel() {
  17357. this._canceled = true;
  17358. if (this._reader) {
  17359. this._reader.cancel(new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AbortException("TextLayer task cancelled.")).catch(() => {});
  17360. this._reader = null;
  17361. }
  17362. this._capability.reject(new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AbortException("TextLayer task cancelled."));
  17363. }
  17364. _processItems(items, styleCache) {
  17365. for (const item of items) {
  17366. if (item.str === undefined) {
  17367. if (item.type === "beginMarkedContentProps" || item.type === "beginMarkedContent") {
  17368. const parent = this._container;
  17369. this._container = document.createElement("span");
  17370. this._container.classList.add("markedContent");
  17371. if (item.id !== null) {
  17372. this._container.setAttribute("id", `${item.id}`);
  17373. }
  17374. parent.append(this._container);
  17375. } else if (item.type === "endMarkedContent") {
  17376. this._container = this._container.parentNode;
  17377. }
  17378. continue;
  17379. }
  17380. this._textContentItemsStr.push(item.str);
  17381. appendText(this, item, styleCache);
  17382. }
  17383. }
  17384. _layoutText(textDiv) {
  17385. const textDivProperties = this._layoutTextParams.properties = this._textDivProperties.get(textDiv);
  17386. this._layoutTextParams.div = textDiv;
  17387. layout(this._layoutTextParams);
  17388. if (textDivProperties.hasText) {
  17389. this._container.append(textDiv);
  17390. }
  17391. if (textDivProperties.hasEOL) {
  17392. const br = document.createElement("br");
  17393. br.setAttribute("role", "presentation");
  17394. this._container.append(br);
  17395. }
  17396. }
  17397. _render() {
  17398. const {
  17399. promise,
  17400. resolve,
  17401. reject
  17402. } = Promise.withResolvers();
  17403. let styleCache = Object.create(null);
  17404. if (this._isReadableStream) {
  17405. const pump = () => {
  17406. this._reader.read().then(({
  17407. value,
  17408. done
  17409. }) => {
  17410. if (done) {
  17411. resolve();
  17412. return;
  17413. }
  17414. Object.assign(styleCache, value.styles);
  17415. this._processItems(value.items, styleCache);
  17416. pump();
  17417. }, reject);
  17418. };
  17419. this._reader = this._textContentSource.getReader();
  17420. pump();
  17421. } else if (this._textContentSource) {
  17422. const {
  17423. items,
  17424. styles
  17425. } = this._textContentSource;
  17426. this._processItems(items, styles);
  17427. resolve();
  17428. } else {
  17429. throw new Error('No "textContentSource" parameter specified.');
  17430. }
  17431. promise.then(() => {
  17432. styleCache = null;
  17433. render(this);
  17434. }, this._capability.reject);
  17435. }
  17436. }
  17437. function renderTextLayer(params) {
  17438. const task = new TextLayerRenderTask(params);
  17439. task._render();
  17440. return task;
  17441. }
  17442. function updateTextLayer({
  17443. container,
  17444. viewport,
  17445. textDivs,
  17446. textDivProperties,
  17447. mustRotate = true,
  17448. mustRescale = true
  17449. }) {
  17450. if (mustRotate) {
  17451. (0,_display_utils_js__WEBPACK_IMPORTED_MODULE_1__.setLayerDimensions)(container, {
  17452. rotation: viewport.rotation
  17453. });
  17454. }
  17455. if (mustRescale) {
  17456. const ctx = getCtx();
  17457. const scale = viewport.scale * (globalThis.devicePixelRatio || 1);
  17458. const params = {
  17459. prevFontSize: null,
  17460. prevFontFamily: null,
  17461. div: null,
  17462. scale,
  17463. properties: null,
  17464. ctx
  17465. };
  17466. for (const div of textDivs) {
  17467. params.properties = textDivProperties.get(div);
  17468. params.div = div;
  17469. layout(params);
  17470. }
  17471. }
  17472. }
  17473. /***/ }),
  17474. /***/ 585:
  17475. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  17476. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  17477. /* harmony export */ PDFDataTransportStream: () => (/* binding */ PDFDataTransportStream)
  17478. /* harmony export */ });
  17479. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(292);
  17480. /* harmony import */ var _display_utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(419);
  17481. class PDFDataTransportStream {
  17482. constructor(pdfDataRangeTransport, {
  17483. disableRange = false,
  17484. disableStream = false
  17485. }) {
  17486. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(pdfDataRangeTransport, 'PDFDataTransportStream - missing required "pdfDataRangeTransport" argument.');
  17487. const {
  17488. length,
  17489. initialData,
  17490. progressiveDone,
  17491. contentDispositionFilename
  17492. } = pdfDataRangeTransport;
  17493. this._queuedChunks = [];
  17494. this._progressiveDone = progressiveDone;
  17495. this._contentDispositionFilename = contentDispositionFilename;
  17496. if (initialData?.length > 0) {
  17497. const buffer = initialData instanceof Uint8Array && initialData.byteLength === initialData.buffer.byteLength ? initialData.buffer : new Uint8Array(initialData).buffer;
  17498. this._queuedChunks.push(buffer);
  17499. }
  17500. this._pdfDataRangeTransport = pdfDataRangeTransport;
  17501. this._isStreamingSupported = !disableStream;
  17502. this._isRangeSupported = !disableRange;
  17503. this._contentLength = length;
  17504. this._fullRequestReader = null;
  17505. this._rangeReaders = [];
  17506. pdfDataRangeTransport.addRangeListener((begin, chunk) => {
  17507. this._onReceiveData({
  17508. begin,
  17509. chunk
  17510. });
  17511. });
  17512. pdfDataRangeTransport.addProgressListener((loaded, total) => {
  17513. this._onProgress({
  17514. loaded,
  17515. total
  17516. });
  17517. });
  17518. pdfDataRangeTransport.addProgressiveReadListener(chunk => {
  17519. this._onReceiveData({
  17520. chunk
  17521. });
  17522. });
  17523. pdfDataRangeTransport.addProgressiveDoneListener(() => {
  17524. this._onProgressiveDone();
  17525. });
  17526. pdfDataRangeTransport.transportReady();
  17527. }
  17528. _onReceiveData({
  17529. begin,
  17530. chunk
  17531. }) {
  17532. const buffer = chunk instanceof Uint8Array && chunk.byteLength === chunk.buffer.byteLength ? chunk.buffer : new Uint8Array(chunk).buffer;
  17533. if (begin === undefined) {
  17534. if (this._fullRequestReader) {
  17535. this._fullRequestReader._enqueue(buffer);
  17536. } else {
  17537. this._queuedChunks.push(buffer);
  17538. }
  17539. } else {
  17540. const found = this._rangeReaders.some(function (rangeReader) {
  17541. if (rangeReader._begin !== begin) {
  17542. return false;
  17543. }
  17544. rangeReader._enqueue(buffer);
  17545. return true;
  17546. });
  17547. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(found, "_onReceiveData - no `PDFDataTransportStreamRangeReader` instance found.");
  17548. }
  17549. }
  17550. get _progressiveDataLength() {
  17551. return this._fullRequestReader?._loaded ?? 0;
  17552. }
  17553. _onProgress(evt) {
  17554. if (evt.total === undefined) {
  17555. this._rangeReaders[0]?.onProgress?.({
  17556. loaded: evt.loaded
  17557. });
  17558. } else {
  17559. this._fullRequestReader?.onProgress?.({
  17560. loaded: evt.loaded,
  17561. total: evt.total
  17562. });
  17563. }
  17564. }
  17565. _onProgressiveDone() {
  17566. this._fullRequestReader?.progressiveDone();
  17567. this._progressiveDone = true;
  17568. }
  17569. _removeRangeReader(reader) {
  17570. const i = this._rangeReaders.indexOf(reader);
  17571. if (i >= 0) {
  17572. this._rangeReaders.splice(i, 1);
  17573. }
  17574. }
  17575. getFullReader() {
  17576. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(!this._fullRequestReader, "PDFDataTransportStream.getFullReader can only be called once.");
  17577. const queuedChunks = this._queuedChunks;
  17578. this._queuedChunks = null;
  17579. return new PDFDataTransportStreamReader(this, queuedChunks, this._progressiveDone, this._contentDispositionFilename);
  17580. }
  17581. getRangeReader(begin, end) {
  17582. if (end <= this._progressiveDataLength) {
  17583. return null;
  17584. }
  17585. const reader = new PDFDataTransportStreamRangeReader(this, begin, end);
  17586. this._pdfDataRangeTransport.requestDataRange(begin, end);
  17587. this._rangeReaders.push(reader);
  17588. return reader;
  17589. }
  17590. cancelAllRequests(reason) {
  17591. this._fullRequestReader?.cancel(reason);
  17592. for (const reader of this._rangeReaders.slice(0)) {
  17593. reader.cancel(reason);
  17594. }
  17595. this._pdfDataRangeTransport.abort();
  17596. }
  17597. }
  17598. class PDFDataTransportStreamReader {
  17599. constructor(stream, queuedChunks, progressiveDone = false, contentDispositionFilename = null) {
  17600. this._stream = stream;
  17601. this._done = progressiveDone || false;
  17602. this._filename = (0,_display_utils_js__WEBPACK_IMPORTED_MODULE_1__.isPdfFile)(contentDispositionFilename) ? contentDispositionFilename : null;
  17603. this._queuedChunks = queuedChunks || [];
  17604. this._loaded = 0;
  17605. for (const chunk of this._queuedChunks) {
  17606. this._loaded += chunk.byteLength;
  17607. }
  17608. this._requests = [];
  17609. this._headersReady = Promise.resolve();
  17610. stream._fullRequestReader = this;
  17611. this.onProgress = null;
  17612. }
  17613. _enqueue(chunk) {
  17614. if (this._done) {
  17615. return;
  17616. }
  17617. if (this._requests.length > 0) {
  17618. const requestCapability = this._requests.shift();
  17619. requestCapability.resolve({
  17620. value: chunk,
  17621. done: false
  17622. });
  17623. } else {
  17624. this._queuedChunks.push(chunk);
  17625. }
  17626. this._loaded += chunk.byteLength;
  17627. }
  17628. get headersReady() {
  17629. return this._headersReady;
  17630. }
  17631. get filename() {
  17632. return this._filename;
  17633. }
  17634. get isRangeSupported() {
  17635. return this._stream._isRangeSupported;
  17636. }
  17637. get isStreamingSupported() {
  17638. return this._stream._isStreamingSupported;
  17639. }
  17640. get contentLength() {
  17641. return this._stream._contentLength;
  17642. }
  17643. async read() {
  17644. if (this._queuedChunks.length > 0) {
  17645. const chunk = this._queuedChunks.shift();
  17646. return {
  17647. value: chunk,
  17648. done: false
  17649. };
  17650. }
  17651. if (this._done) {
  17652. return {
  17653. value: undefined,
  17654. done: true
  17655. };
  17656. }
  17657. const requestCapability = Promise.withResolvers();
  17658. this._requests.push(requestCapability);
  17659. return requestCapability.promise;
  17660. }
  17661. cancel(reason) {
  17662. this._done = true;
  17663. for (const requestCapability of this._requests) {
  17664. requestCapability.resolve({
  17665. value: undefined,
  17666. done: true
  17667. });
  17668. }
  17669. this._requests.length = 0;
  17670. }
  17671. progressiveDone() {
  17672. if (this._done) {
  17673. return;
  17674. }
  17675. this._done = true;
  17676. }
  17677. }
  17678. class PDFDataTransportStreamRangeReader {
  17679. constructor(stream, begin, end) {
  17680. this._stream = stream;
  17681. this._begin = begin;
  17682. this._end = end;
  17683. this._queuedChunk = null;
  17684. this._requests = [];
  17685. this._done = false;
  17686. this.onProgress = null;
  17687. }
  17688. _enqueue(chunk) {
  17689. if (this._done) {
  17690. return;
  17691. }
  17692. if (this._requests.length === 0) {
  17693. this._queuedChunk = chunk;
  17694. } else {
  17695. const requestsCapability = this._requests.shift();
  17696. requestsCapability.resolve({
  17697. value: chunk,
  17698. done: false
  17699. });
  17700. for (const requestCapability of this._requests) {
  17701. requestCapability.resolve({
  17702. value: undefined,
  17703. done: true
  17704. });
  17705. }
  17706. this._requests.length = 0;
  17707. }
  17708. this._done = true;
  17709. this._stream._removeRangeReader(this);
  17710. }
  17711. get isStreamingSupported() {
  17712. return false;
  17713. }
  17714. async read() {
  17715. if (this._queuedChunk) {
  17716. const chunk = this._queuedChunk;
  17717. this._queuedChunk = null;
  17718. return {
  17719. value: chunk,
  17720. done: false
  17721. };
  17722. }
  17723. if (this._done) {
  17724. return {
  17725. value: undefined,
  17726. done: true
  17727. };
  17728. }
  17729. const requestCapability = Promise.withResolvers();
  17730. this._requests.push(requestCapability);
  17731. return requestCapability.promise;
  17732. }
  17733. cancel(reason) {
  17734. this._done = true;
  17735. for (const requestCapability of this._requests) {
  17736. requestCapability.resolve({
  17737. value: undefined,
  17738. done: true
  17739. });
  17740. }
  17741. this._requests.length = 0;
  17742. this._stream._removeRangeReader(this);
  17743. }
  17744. }
  17745. /***/ }),
  17746. /***/ 164:
  17747. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  17748. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  17749. /* harmony export */ GlobalWorkerOptions: () => (/* binding */ GlobalWorkerOptions)
  17750. /* harmony export */ });
  17751. class GlobalWorkerOptions {
  17752. static #port = null;
  17753. static #src = "";
  17754. static get workerPort() {
  17755. return this.#port;
  17756. }
  17757. static set workerPort(val) {
  17758. if (!(typeof Worker !== "undefined" && val instanceof Worker) && val !== null) {
  17759. throw new Error("Invalid `workerPort` type.");
  17760. }
  17761. this.#port = val;
  17762. }
  17763. static get workerSrc() {
  17764. return this.#src;
  17765. }
  17766. static set workerSrc(val) {
  17767. if (typeof val !== "string") {
  17768. throw new Error("Invalid `workerSrc` type.");
  17769. }
  17770. this.#src = val;
  17771. }
  17772. }
  17773. /***/ }),
  17774. /***/ 284:
  17775. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  17776. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  17777. /* harmony export */ XfaLayer: () => (/* binding */ XfaLayer)
  17778. /* harmony export */ });
  17779. /* harmony import */ var _xfa_text_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(50);
  17780. class XfaLayer {
  17781. static setupStorage(html, id, element, storage, intent) {
  17782. const storedData = storage.getValue(id, {
  17783. value: null
  17784. });
  17785. switch (element.name) {
  17786. case "textarea":
  17787. if (storedData.value !== null) {
  17788. html.textContent = storedData.value;
  17789. }
  17790. if (intent === "print") {
  17791. break;
  17792. }
  17793. html.addEventListener("input", event => {
  17794. storage.setValue(id, {
  17795. value: event.target.value
  17796. });
  17797. });
  17798. break;
  17799. case "input":
  17800. if (element.attributes.type === "radio" || element.attributes.type === "checkbox") {
  17801. if (storedData.value === element.attributes.xfaOn) {
  17802. html.setAttribute("checked", true);
  17803. } else if (storedData.value === element.attributes.xfaOff) {
  17804. html.removeAttribute("checked");
  17805. }
  17806. if (intent === "print") {
  17807. break;
  17808. }
  17809. html.addEventListener("change", event => {
  17810. storage.setValue(id, {
  17811. value: event.target.checked ? event.target.getAttribute("xfaOn") : event.target.getAttribute("xfaOff")
  17812. });
  17813. });
  17814. } else {
  17815. if (storedData.value !== null) {
  17816. html.setAttribute("value", storedData.value);
  17817. }
  17818. if (intent === "print") {
  17819. break;
  17820. }
  17821. html.addEventListener("input", event => {
  17822. storage.setValue(id, {
  17823. value: event.target.value
  17824. });
  17825. });
  17826. }
  17827. break;
  17828. case "select":
  17829. if (storedData.value !== null) {
  17830. html.setAttribute("value", storedData.value);
  17831. for (const option of element.children) {
  17832. if (option.attributes.value === storedData.value) {
  17833. option.attributes.selected = true;
  17834. } else if (option.attributes.hasOwnProperty("selected")) {
  17835. delete option.attributes.selected;
  17836. }
  17837. }
  17838. }
  17839. html.addEventListener("input", event => {
  17840. const options = event.target.options;
  17841. const value = options.selectedIndex === -1 ? "" : options[options.selectedIndex].value;
  17842. storage.setValue(id, {
  17843. value
  17844. });
  17845. });
  17846. break;
  17847. }
  17848. }
  17849. static setAttributes({
  17850. html,
  17851. element,
  17852. storage = null,
  17853. intent,
  17854. linkService
  17855. }) {
  17856. const {
  17857. attributes
  17858. } = element;
  17859. const isHTMLAnchorElement = html instanceof HTMLAnchorElement;
  17860. if (attributes.type === "radio") {
  17861. attributes.name = `${attributes.name}-${intent}`;
  17862. }
  17863. for (const [key, value] of Object.entries(attributes)) {
  17864. if (value === null || value === undefined) {
  17865. continue;
  17866. }
  17867. switch (key) {
  17868. case "class":
  17869. if (value.length) {
  17870. html.setAttribute(key, value.join(" "));
  17871. }
  17872. break;
  17873. case "dataId":
  17874. break;
  17875. case "id":
  17876. html.setAttribute("data-element-id", value);
  17877. break;
  17878. case "style":
  17879. Object.assign(html.style, value);
  17880. break;
  17881. case "textContent":
  17882. html.textContent = value;
  17883. break;
  17884. default:
  17885. if (!isHTMLAnchorElement || key !== "href" && key !== "newWindow") {
  17886. html.setAttribute(key, value);
  17887. }
  17888. }
  17889. }
  17890. if (isHTMLAnchorElement) {
  17891. linkService.addLinkAttributes(html, attributes.href, attributes.newWindow);
  17892. }
  17893. if (storage && attributes.dataId) {
  17894. this.setupStorage(html, attributes.dataId, element, storage);
  17895. }
  17896. }
  17897. static render(parameters) {
  17898. const storage = parameters.annotationStorage;
  17899. const linkService = parameters.linkService;
  17900. const root = parameters.xfaHtml;
  17901. const intent = parameters.intent || "display";
  17902. const rootHtml = document.createElement(root.name);
  17903. if (root.attributes) {
  17904. this.setAttributes({
  17905. html: rootHtml,
  17906. element: root,
  17907. intent,
  17908. linkService
  17909. });
  17910. }
  17911. const isNotForRichText = intent !== "richText";
  17912. const rootDiv = parameters.div;
  17913. rootDiv.append(rootHtml);
  17914. if (parameters.viewport) {
  17915. const transform = `matrix(${parameters.viewport.transform.join(",")})`;
  17916. rootDiv.style.transform = transform;
  17917. }
  17918. if (isNotForRichText) {
  17919. rootDiv.setAttribute("class", "xfaLayer xfaFont");
  17920. }
  17921. const textDivs = [];
  17922. if (root.children.length === 0) {
  17923. if (root.value) {
  17924. const node = document.createTextNode(root.value);
  17925. rootHtml.append(node);
  17926. if (isNotForRichText && _xfa_text_js__WEBPACK_IMPORTED_MODULE_0__.XfaText.shouldBuildText(root.name)) {
  17927. textDivs.push(node);
  17928. }
  17929. }
  17930. return {
  17931. textDivs
  17932. };
  17933. }
  17934. const stack = [[root, -1, rootHtml]];
  17935. while (stack.length > 0) {
  17936. const [parent, i, html] = stack.at(-1);
  17937. if (i + 1 === parent.children.length) {
  17938. stack.pop();
  17939. continue;
  17940. }
  17941. const child = parent.children[++stack.at(-1)[1]];
  17942. if (child === null) {
  17943. continue;
  17944. }
  17945. const {
  17946. name
  17947. } = child;
  17948. if (name === "#text") {
  17949. const node = document.createTextNode(child.value);
  17950. textDivs.push(node);
  17951. html.append(node);
  17952. continue;
  17953. }
  17954. const childHtml = child?.attributes?.xmlns ? document.createElementNS(child.attributes.xmlns, name) : document.createElement(name);
  17955. html.append(childHtml);
  17956. if (child.attributes) {
  17957. this.setAttributes({
  17958. html: childHtml,
  17959. element: child,
  17960. storage,
  17961. intent,
  17962. linkService
  17963. });
  17964. }
  17965. if (child.children?.length > 0) {
  17966. stack.push([child, -1, childHtml]);
  17967. } else if (child.value) {
  17968. const node = document.createTextNode(child.value);
  17969. if (isNotForRichText && _xfa_text_js__WEBPACK_IMPORTED_MODULE_0__.XfaText.shouldBuildText(name)) {
  17970. textDivs.push(node);
  17971. }
  17972. childHtml.append(node);
  17973. }
  17974. }
  17975. for (const el of rootDiv.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea")) {
  17976. el.setAttribute("readOnly", true);
  17977. }
  17978. return {
  17979. textDivs
  17980. };
  17981. }
  17982. static update(parameters) {
  17983. const transform = `matrix(${parameters.viewport.transform.join(",")})`;
  17984. parameters.div.style.transform = transform;
  17985. parameters.div.hidden = false;
  17986. }
  17987. }
  17988. /***/ }),
  17989. /***/ 50:
  17990. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  17991. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  17992. /* harmony export */ XfaText: () => (/* binding */ XfaText)
  17993. /* harmony export */ });
  17994. class XfaText {
  17995. static textContent(xfa) {
  17996. const items = [];
  17997. const output = {
  17998. items,
  17999. styles: Object.create(null)
  18000. };
  18001. function walk(node) {
  18002. if (!node) {
  18003. return;
  18004. }
  18005. let str = null;
  18006. const name = node.name;
  18007. if (name === "#text") {
  18008. str = node.value;
  18009. } else if (!XfaText.shouldBuildText(name)) {
  18010. return;
  18011. } else if (node?.attributes?.textContent) {
  18012. str = node.attributes.textContent;
  18013. } else if (node.value) {
  18014. str = node.value;
  18015. }
  18016. if (str !== null) {
  18017. items.push({
  18018. str
  18019. });
  18020. }
  18021. if (!node.children) {
  18022. return;
  18023. }
  18024. for (const child of node.children) {
  18025. walk(child);
  18026. }
  18027. }
  18028. walk(xfa);
  18029. return output;
  18030. }
  18031. static shouldBuildText(name) {
  18032. return !(name === "textarea" || name === "input" || name === "option" || name === "select");
  18033. }
  18034. }
  18035. /***/ }),
  18036. /***/ 228:
  18037. /***/ ((__webpack_module__, __webpack_exports__, __webpack_require__) => {
  18038. __webpack_require__.a(__webpack_module__, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
  18039. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  18040. /* harmony export */ AbortException: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AbortException),
  18041. /* harmony export */ AnnotationEditorLayer: () => (/* reexport safe */ _display_editor_annotation_editor_layer_js__WEBPACK_IMPORTED_MODULE_4__.AnnotationEditorLayer),
  18042. /* harmony export */ AnnotationEditorParamsType: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorParamsType),
  18043. /* harmony export */ AnnotationEditorType: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorType),
  18044. /* harmony export */ AnnotationEditorUIManager: () => (/* reexport safe */ _display_editor_tools_js__WEBPACK_IMPORTED_MODULE_5__.AnnotationEditorUIManager),
  18045. /* harmony export */ AnnotationLayer: () => (/* reexport safe */ _display_annotation_layer_js__WEBPACK_IMPORTED_MODULE_6__.AnnotationLayer),
  18046. /* harmony export */ AnnotationMode: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationMode),
  18047. /* harmony export */ CMapCompressionType: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.CMapCompressionType),
  18048. /* harmony export */ ColorPicker: () => (/* reexport safe */ _display_editor_color_picker_js__WEBPACK_IMPORTED_MODULE_7__.ColorPicker),
  18049. /* harmony export */ DOMSVGFactory: () => (/* reexport safe */ _display_display_utils_js__WEBPACK_IMPORTED_MODULE_2__.DOMSVGFactory),
  18050. /* harmony export */ DrawLayer: () => (/* reexport safe */ _display_draw_layer_js__WEBPACK_IMPORTED_MODULE_8__.DrawLayer),
  18051. /* harmony export */ FeatureTest: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.FeatureTest),
  18052. /* harmony export */ GlobalWorkerOptions: () => (/* reexport safe */ _display_worker_options_js__WEBPACK_IMPORTED_MODULE_10__.GlobalWorkerOptions),
  18053. /* harmony export */ ImageKind: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.ImageKind),
  18054. /* harmony export */ InvalidPDFException: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.InvalidPDFException),
  18055. /* harmony export */ MissingPDFException: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.MissingPDFException),
  18056. /* harmony export */ OPS: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.OPS),
  18057. /* harmony export */ Outliner: () => (/* reexport safe */ _display_editor_outliner_js__WEBPACK_IMPORTED_MODULE_9__.Outliner),
  18058. /* harmony export */ PDFDataRangeTransport: () => (/* reexport safe */ _display_api_js__WEBPACK_IMPORTED_MODULE_1__.PDFDataRangeTransport),
  18059. /* harmony export */ PDFDateString: () => (/* reexport safe */ _display_display_utils_js__WEBPACK_IMPORTED_MODULE_2__.PDFDateString),
  18060. /* harmony export */ PDFWorker: () => (/* reexport safe */ _display_api_js__WEBPACK_IMPORTED_MODULE_1__.PDFWorker),
  18061. /* harmony export */ PasswordResponses: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PasswordResponses),
  18062. /* harmony export */ PermissionFlag: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PermissionFlag),
  18063. /* harmony export */ PixelsPerInch: () => (/* reexport safe */ _display_display_utils_js__WEBPACK_IMPORTED_MODULE_2__.PixelsPerInch),
  18064. /* harmony export */ RenderingCancelledException: () => (/* reexport safe */ _display_display_utils_js__WEBPACK_IMPORTED_MODULE_2__.RenderingCancelledException),
  18065. /* harmony export */ UnexpectedResponseException: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.UnexpectedResponseException),
  18066. /* harmony export */ Util: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.Util),
  18067. /* harmony export */ VerbosityLevel: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.VerbosityLevel),
  18068. /* harmony export */ XfaLayer: () => (/* reexport safe */ _display_xfa_layer_js__WEBPACK_IMPORTED_MODULE_11__.XfaLayer),
  18069. /* harmony export */ build: () => (/* reexport safe */ _display_api_js__WEBPACK_IMPORTED_MODULE_1__.build),
  18070. /* harmony export */ createValidAbsoluteUrl: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.createValidAbsoluteUrl),
  18071. /* harmony export */ fetchData: () => (/* reexport safe */ _display_display_utils_js__WEBPACK_IMPORTED_MODULE_2__.fetchData),
  18072. /* harmony export */ getDocument: () => (/* reexport safe */ _display_api_js__WEBPACK_IMPORTED_MODULE_1__.getDocument),
  18073. /* harmony export */ getFilenameFromUrl: () => (/* reexport safe */ _display_display_utils_js__WEBPACK_IMPORTED_MODULE_2__.getFilenameFromUrl),
  18074. /* harmony export */ getPdfFilenameFromUrl: () => (/* reexport safe */ _display_display_utils_js__WEBPACK_IMPORTED_MODULE_2__.getPdfFilenameFromUrl),
  18075. /* harmony export */ getXfaPageViewport: () => (/* reexport safe */ _display_display_utils_js__WEBPACK_IMPORTED_MODULE_2__.getXfaPageViewport),
  18076. /* harmony export */ isDataScheme: () => (/* reexport safe */ _display_display_utils_js__WEBPACK_IMPORTED_MODULE_2__.isDataScheme),
  18077. /* harmony export */ isPdfFile: () => (/* reexport safe */ _display_display_utils_js__WEBPACK_IMPORTED_MODULE_2__.isPdfFile),
  18078. /* harmony export */ noContextMenu: () => (/* reexport safe */ _display_display_utils_js__WEBPACK_IMPORTED_MODULE_2__.noContextMenu),
  18079. /* harmony export */ normalizeUnicode: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.normalizeUnicode),
  18080. /* harmony export */ renderTextLayer: () => (/* reexport safe */ _display_text_layer_js__WEBPACK_IMPORTED_MODULE_3__.renderTextLayer),
  18081. /* harmony export */ setLayerDimensions: () => (/* reexport safe */ _display_display_utils_js__WEBPACK_IMPORTED_MODULE_2__.setLayerDimensions),
  18082. /* harmony export */ shadow: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow),
  18083. /* harmony export */ updateTextLayer: () => (/* reexport safe */ _display_text_layer_js__WEBPACK_IMPORTED_MODULE_3__.updateTextLayer),
  18084. /* harmony export */ version: () => (/* reexport safe */ _display_api_js__WEBPACK_IMPORTED_MODULE_1__.version)
  18085. /* harmony export */ });
  18086. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(292);
  18087. /* harmony import */ var _display_api_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(831);
  18088. /* harmony import */ var _display_display_utils_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(419);
  18089. /* harmony import */ var _display_text_layer_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(814);
  18090. /* harmony import */ var _display_editor_annotation_editor_layer_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(731);
  18091. /* harmony import */ var _display_editor_tools_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(830);
  18092. /* harmony import */ var _display_annotation_layer_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(976);
  18093. /* harmony import */ var _display_editor_color_picker_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(259);
  18094. /* harmony import */ var _display_draw_layer_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(47);
  18095. /* harmony import */ var _display_worker_options_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(164);
  18096. /* harmony import */ var _display_editor_outliner_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(61);
  18097. /* harmony import */ var _display_xfa_layer_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(284);
  18098. var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_display_api_js__WEBPACK_IMPORTED_MODULE_1__]);
  18099. _display_api_js__WEBPACK_IMPORTED_MODULE_1__ = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[0];
  18100. const pdfjsVersion = "4.2.67";
  18101. const pdfjsBuild = "49b388101";
  18102. __webpack_async_result__();
  18103. } catch(e) { __webpack_async_result__(e); } });
  18104. /***/ }),
  18105. /***/ 178:
  18106. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  18107. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  18108. /* harmony export */ MessageHandler: () => (/* binding */ MessageHandler)
  18109. /* harmony export */ });
  18110. /* harmony import */ var _util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(292);
  18111. const CallbackKind = {
  18112. UNKNOWN: 0,
  18113. DATA: 1,
  18114. ERROR: 2
  18115. };
  18116. const StreamKind = {
  18117. UNKNOWN: 0,
  18118. CANCEL: 1,
  18119. CANCEL_COMPLETE: 2,
  18120. CLOSE: 3,
  18121. ENQUEUE: 4,
  18122. ERROR: 5,
  18123. PULL: 6,
  18124. PULL_COMPLETE: 7,
  18125. START_COMPLETE: 8
  18126. };
  18127. function wrapReason(reason) {
  18128. if (!(reason instanceof Error || typeof reason === "object" && reason !== null)) {
  18129. (0,_util_js__WEBPACK_IMPORTED_MODULE_0__.unreachable)('wrapReason: Expected "reason" to be a (possibly cloned) Error.');
  18130. }
  18131. switch (reason.name) {
  18132. case "AbortException":
  18133. return new _util_js__WEBPACK_IMPORTED_MODULE_0__.AbortException(reason.message);
  18134. case "MissingPDFException":
  18135. return new _util_js__WEBPACK_IMPORTED_MODULE_0__.MissingPDFException(reason.message);
  18136. case "PasswordException":
  18137. return new _util_js__WEBPACK_IMPORTED_MODULE_0__.PasswordException(reason.message, reason.code);
  18138. case "UnexpectedResponseException":
  18139. return new _util_js__WEBPACK_IMPORTED_MODULE_0__.UnexpectedResponseException(reason.message, reason.status);
  18140. case "UnknownErrorException":
  18141. return new _util_js__WEBPACK_IMPORTED_MODULE_0__.UnknownErrorException(reason.message, reason.details);
  18142. default:
  18143. return new _util_js__WEBPACK_IMPORTED_MODULE_0__.UnknownErrorException(reason.message, reason.toString());
  18144. }
  18145. }
  18146. class MessageHandler {
  18147. constructor(sourceName, targetName, comObj) {
  18148. this.sourceName = sourceName;
  18149. this.targetName = targetName;
  18150. this.comObj = comObj;
  18151. this.callbackId = 1;
  18152. this.streamId = 1;
  18153. this.streamSinks = Object.create(null);
  18154. this.streamControllers = Object.create(null);
  18155. this.callbackCapabilities = Object.create(null);
  18156. this.actionHandler = Object.create(null);
  18157. this._onComObjOnMessage = event => {
  18158. const data = event.data;
  18159. if (data.targetName !== this.sourceName) {
  18160. return;
  18161. }
  18162. if (data.stream) {
  18163. this.#processStreamMessage(data);
  18164. return;
  18165. }
  18166. if (data.callback) {
  18167. const callbackId = data.callbackId;
  18168. const capability = this.callbackCapabilities[callbackId];
  18169. if (!capability) {
  18170. throw new Error(`Cannot resolve callback ${callbackId}`);
  18171. }
  18172. delete this.callbackCapabilities[callbackId];
  18173. if (data.callback === CallbackKind.DATA) {
  18174. capability.resolve(data.data);
  18175. } else if (data.callback === CallbackKind.ERROR) {
  18176. capability.reject(wrapReason(data.reason));
  18177. } else {
  18178. throw new Error("Unexpected callback case");
  18179. }
  18180. return;
  18181. }
  18182. const action = this.actionHandler[data.action];
  18183. if (!action) {
  18184. throw new Error(`Unknown action from worker: ${data.action}`);
  18185. }
  18186. if (data.callbackId) {
  18187. const cbSourceName = this.sourceName;
  18188. const cbTargetName = data.sourceName;
  18189. new Promise(function (resolve) {
  18190. resolve(action(data.data));
  18191. }).then(function (result) {
  18192. comObj.postMessage({
  18193. sourceName: cbSourceName,
  18194. targetName: cbTargetName,
  18195. callback: CallbackKind.DATA,
  18196. callbackId: data.callbackId,
  18197. data: result
  18198. });
  18199. }, function (reason) {
  18200. comObj.postMessage({
  18201. sourceName: cbSourceName,
  18202. targetName: cbTargetName,
  18203. callback: CallbackKind.ERROR,
  18204. callbackId: data.callbackId,
  18205. reason: wrapReason(reason)
  18206. });
  18207. });
  18208. return;
  18209. }
  18210. if (data.streamId) {
  18211. this.#createStreamSink(data);
  18212. return;
  18213. }
  18214. action(data.data);
  18215. };
  18216. comObj.addEventListener("message", this._onComObjOnMessage);
  18217. }
  18218. on(actionName, handler) {
  18219. const ah = this.actionHandler;
  18220. if (ah[actionName]) {
  18221. throw new Error(`There is already an actionName called "${actionName}"`);
  18222. }
  18223. ah[actionName] = handler;
  18224. }
  18225. send(actionName, data, transfers) {
  18226. this.comObj.postMessage({
  18227. sourceName: this.sourceName,
  18228. targetName: this.targetName,
  18229. action: actionName,
  18230. data
  18231. }, transfers);
  18232. }
  18233. sendWithPromise(actionName, data, transfers) {
  18234. const callbackId = this.callbackId++;
  18235. const capability = Promise.withResolvers();
  18236. this.callbackCapabilities[callbackId] = capability;
  18237. try {
  18238. this.comObj.postMessage({
  18239. sourceName: this.sourceName,
  18240. targetName: this.targetName,
  18241. action: actionName,
  18242. callbackId,
  18243. data
  18244. }, transfers);
  18245. } catch (ex) {
  18246. capability.reject(ex);
  18247. }
  18248. return capability.promise;
  18249. }
  18250. sendWithStream(actionName, data, queueingStrategy, transfers) {
  18251. const streamId = this.streamId++,
  18252. sourceName = this.sourceName,
  18253. targetName = this.targetName,
  18254. comObj = this.comObj;
  18255. return new ReadableStream({
  18256. start: controller => {
  18257. const startCapability = Promise.withResolvers();
  18258. this.streamControllers[streamId] = {
  18259. controller,
  18260. startCall: startCapability,
  18261. pullCall: null,
  18262. cancelCall: null,
  18263. isClosed: false
  18264. };
  18265. comObj.postMessage({
  18266. sourceName,
  18267. targetName,
  18268. action: actionName,
  18269. streamId,
  18270. data,
  18271. desiredSize: controller.desiredSize
  18272. }, transfers);
  18273. return startCapability.promise;
  18274. },
  18275. pull: controller => {
  18276. const pullCapability = Promise.withResolvers();
  18277. this.streamControllers[streamId].pullCall = pullCapability;
  18278. comObj.postMessage({
  18279. sourceName,
  18280. targetName,
  18281. stream: StreamKind.PULL,
  18282. streamId,
  18283. desiredSize: controller.desiredSize
  18284. });
  18285. return pullCapability.promise;
  18286. },
  18287. cancel: reason => {
  18288. (0,_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(reason instanceof Error, "cancel must have a valid reason");
  18289. const cancelCapability = Promise.withResolvers();
  18290. this.streamControllers[streamId].cancelCall = cancelCapability;
  18291. this.streamControllers[streamId].isClosed = true;
  18292. comObj.postMessage({
  18293. sourceName,
  18294. targetName,
  18295. stream: StreamKind.CANCEL,
  18296. streamId,
  18297. reason: wrapReason(reason)
  18298. });
  18299. return cancelCapability.promise;
  18300. }
  18301. }, queueingStrategy);
  18302. }
  18303. #createStreamSink(data) {
  18304. const streamId = data.streamId,
  18305. sourceName = this.sourceName,
  18306. targetName = data.sourceName,
  18307. comObj = this.comObj;
  18308. const self = this,
  18309. action = this.actionHandler[data.action];
  18310. const streamSink = {
  18311. enqueue(chunk, size = 1, transfers) {
  18312. if (this.isCancelled) {
  18313. return;
  18314. }
  18315. const lastDesiredSize = this.desiredSize;
  18316. this.desiredSize -= size;
  18317. if (lastDesiredSize > 0 && this.desiredSize <= 0) {
  18318. this.sinkCapability = Promise.withResolvers();
  18319. this.ready = this.sinkCapability.promise;
  18320. }
  18321. comObj.postMessage({
  18322. sourceName,
  18323. targetName,
  18324. stream: StreamKind.ENQUEUE,
  18325. streamId,
  18326. chunk
  18327. }, transfers);
  18328. },
  18329. close() {
  18330. if (this.isCancelled) {
  18331. return;
  18332. }
  18333. this.isCancelled = true;
  18334. comObj.postMessage({
  18335. sourceName,
  18336. targetName,
  18337. stream: StreamKind.CLOSE,
  18338. streamId
  18339. });
  18340. delete self.streamSinks[streamId];
  18341. },
  18342. error(reason) {
  18343. (0,_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(reason instanceof Error, "error must have a valid reason");
  18344. if (this.isCancelled) {
  18345. return;
  18346. }
  18347. this.isCancelled = true;
  18348. comObj.postMessage({
  18349. sourceName,
  18350. targetName,
  18351. stream: StreamKind.ERROR,
  18352. streamId,
  18353. reason: wrapReason(reason)
  18354. });
  18355. },
  18356. sinkCapability: Promise.withResolvers(),
  18357. onPull: null,
  18358. onCancel: null,
  18359. isCancelled: false,
  18360. desiredSize: data.desiredSize,
  18361. ready: null
  18362. };
  18363. streamSink.sinkCapability.resolve();
  18364. streamSink.ready = streamSink.sinkCapability.promise;
  18365. this.streamSinks[streamId] = streamSink;
  18366. new Promise(function (resolve) {
  18367. resolve(action(data.data, streamSink));
  18368. }).then(function () {
  18369. comObj.postMessage({
  18370. sourceName,
  18371. targetName,
  18372. stream: StreamKind.START_COMPLETE,
  18373. streamId,
  18374. success: true
  18375. });
  18376. }, function (reason) {
  18377. comObj.postMessage({
  18378. sourceName,
  18379. targetName,
  18380. stream: StreamKind.START_COMPLETE,
  18381. streamId,
  18382. reason: wrapReason(reason)
  18383. });
  18384. });
  18385. }
  18386. #processStreamMessage(data) {
  18387. const streamId = data.streamId,
  18388. sourceName = this.sourceName,
  18389. targetName = data.sourceName,
  18390. comObj = this.comObj;
  18391. const streamController = this.streamControllers[streamId],
  18392. streamSink = this.streamSinks[streamId];
  18393. switch (data.stream) {
  18394. case StreamKind.START_COMPLETE:
  18395. if (data.success) {
  18396. streamController.startCall.resolve();
  18397. } else {
  18398. streamController.startCall.reject(wrapReason(data.reason));
  18399. }
  18400. break;
  18401. case StreamKind.PULL_COMPLETE:
  18402. if (data.success) {
  18403. streamController.pullCall.resolve();
  18404. } else {
  18405. streamController.pullCall.reject(wrapReason(data.reason));
  18406. }
  18407. break;
  18408. case StreamKind.PULL:
  18409. if (!streamSink) {
  18410. comObj.postMessage({
  18411. sourceName,
  18412. targetName,
  18413. stream: StreamKind.PULL_COMPLETE,
  18414. streamId,
  18415. success: true
  18416. });
  18417. break;
  18418. }
  18419. if (streamSink.desiredSize <= 0 && data.desiredSize > 0) {
  18420. streamSink.sinkCapability.resolve();
  18421. }
  18422. streamSink.desiredSize = data.desiredSize;
  18423. new Promise(function (resolve) {
  18424. resolve(streamSink.onPull?.());
  18425. }).then(function () {
  18426. comObj.postMessage({
  18427. sourceName,
  18428. targetName,
  18429. stream: StreamKind.PULL_COMPLETE,
  18430. streamId,
  18431. success: true
  18432. });
  18433. }, function (reason) {
  18434. comObj.postMessage({
  18435. sourceName,
  18436. targetName,
  18437. stream: StreamKind.PULL_COMPLETE,
  18438. streamId,
  18439. reason: wrapReason(reason)
  18440. });
  18441. });
  18442. break;
  18443. case StreamKind.ENQUEUE:
  18444. (0,_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(streamController, "enqueue should have stream controller");
  18445. if (streamController.isClosed) {
  18446. break;
  18447. }
  18448. streamController.controller.enqueue(data.chunk);
  18449. break;
  18450. case StreamKind.CLOSE:
  18451. (0,_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(streamController, "close should have stream controller");
  18452. if (streamController.isClosed) {
  18453. break;
  18454. }
  18455. streamController.isClosed = true;
  18456. streamController.controller.close();
  18457. this.#deleteStreamController(streamController, streamId);
  18458. break;
  18459. case StreamKind.ERROR:
  18460. (0,_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(streamController, "error should have stream controller");
  18461. streamController.controller.error(wrapReason(data.reason));
  18462. this.#deleteStreamController(streamController, streamId);
  18463. break;
  18464. case StreamKind.CANCEL_COMPLETE:
  18465. if (data.success) {
  18466. streamController.cancelCall.resolve();
  18467. } else {
  18468. streamController.cancelCall.reject(wrapReason(data.reason));
  18469. }
  18470. this.#deleteStreamController(streamController, streamId);
  18471. break;
  18472. case StreamKind.CANCEL:
  18473. if (!streamSink) {
  18474. break;
  18475. }
  18476. new Promise(function (resolve) {
  18477. resolve(streamSink.onCancel?.(wrapReason(data.reason)));
  18478. }).then(function () {
  18479. comObj.postMessage({
  18480. sourceName,
  18481. targetName,
  18482. stream: StreamKind.CANCEL_COMPLETE,
  18483. streamId,
  18484. success: true
  18485. });
  18486. }, function (reason) {
  18487. comObj.postMessage({
  18488. sourceName,
  18489. targetName,
  18490. stream: StreamKind.CANCEL_COMPLETE,
  18491. streamId,
  18492. reason: wrapReason(reason)
  18493. });
  18494. });
  18495. streamSink.sinkCapability.reject(wrapReason(data.reason));
  18496. streamSink.isCancelled = true;
  18497. delete this.streamSinks[streamId];
  18498. break;
  18499. default:
  18500. throw new Error("Unexpected stream case");
  18501. }
  18502. }
  18503. async #deleteStreamController(streamController, streamId) {
  18504. await Promise.allSettled([streamController.startCall?.promise, streamController.pullCall?.promise, streamController.cancelCall?.promise]);
  18505. delete this.streamControllers[streamId];
  18506. }
  18507. destroy() {
  18508. this.comObj.removeEventListener("message", this._onComObjOnMessage);
  18509. }
  18510. }
  18511. /***/ }),
  18512. /***/ 651:
  18513. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  18514. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  18515. /* harmony export */ MurmurHash3_64: () => (/* binding */ MurmurHash3_64)
  18516. /* harmony export */ });
  18517. const SEED = 0xc3d2e1f0;
  18518. const MASK_HIGH = 0xffff0000;
  18519. const MASK_LOW = 0xffff;
  18520. class MurmurHash3_64 {
  18521. constructor(seed) {
  18522. this.h1 = seed ? seed & 0xffffffff : SEED;
  18523. this.h2 = seed ? seed & 0xffffffff : SEED;
  18524. }
  18525. update(input) {
  18526. let data, length;
  18527. if (typeof input === "string") {
  18528. data = new Uint8Array(input.length * 2);
  18529. length = 0;
  18530. for (let i = 0, ii = input.length; i < ii; i++) {
  18531. const code = input.charCodeAt(i);
  18532. if (code <= 0xff) {
  18533. data[length++] = code;
  18534. } else {
  18535. data[length++] = code >>> 8;
  18536. data[length++] = code & 0xff;
  18537. }
  18538. }
  18539. } else if (ArrayBuffer.isView(input)) {
  18540. data = input.slice();
  18541. length = data.byteLength;
  18542. } else {
  18543. throw new Error("Invalid data format, must be a string or TypedArray.");
  18544. }
  18545. const blockCounts = length >> 2;
  18546. const tailLength = length - blockCounts * 4;
  18547. const dataUint32 = new Uint32Array(data.buffer, 0, blockCounts);
  18548. let k1 = 0,
  18549. k2 = 0;
  18550. let h1 = this.h1,
  18551. h2 = this.h2;
  18552. const C1 = 0xcc9e2d51,
  18553. C2 = 0x1b873593;
  18554. const C1_LOW = C1 & MASK_LOW,
  18555. C2_LOW = C2 & MASK_LOW;
  18556. for (let i = 0; i < blockCounts; i++) {
  18557. if (i & 1) {
  18558. k1 = dataUint32[i];
  18559. k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
  18560. k1 = k1 << 15 | k1 >>> 17;
  18561. k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
  18562. h1 ^= k1;
  18563. h1 = h1 << 13 | h1 >>> 19;
  18564. h1 = h1 * 5 + 0xe6546b64;
  18565. } else {
  18566. k2 = dataUint32[i];
  18567. k2 = k2 * C1 & MASK_HIGH | k2 * C1_LOW & MASK_LOW;
  18568. k2 = k2 << 15 | k2 >>> 17;
  18569. k2 = k2 * C2 & MASK_HIGH | k2 * C2_LOW & MASK_LOW;
  18570. h2 ^= k2;
  18571. h2 = h2 << 13 | h2 >>> 19;
  18572. h2 = h2 * 5 + 0xe6546b64;
  18573. }
  18574. }
  18575. k1 = 0;
  18576. switch (tailLength) {
  18577. case 3:
  18578. k1 ^= data[blockCounts * 4 + 2] << 16;
  18579. case 2:
  18580. k1 ^= data[blockCounts * 4 + 1] << 8;
  18581. case 1:
  18582. k1 ^= data[blockCounts * 4];
  18583. k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
  18584. k1 = k1 << 15 | k1 >>> 17;
  18585. k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
  18586. if (blockCounts & 1) {
  18587. h1 ^= k1;
  18588. } else {
  18589. h2 ^= k1;
  18590. }
  18591. }
  18592. this.h1 = h1;
  18593. this.h2 = h2;
  18594. }
  18595. hexdigest() {
  18596. let h1 = this.h1,
  18597. h2 = this.h2;
  18598. h1 ^= h2 >>> 1;
  18599. h1 = h1 * 0xed558ccd & MASK_HIGH | h1 * 0x8ccd & MASK_LOW;
  18600. h2 = h2 * 0xff51afd7 & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16;
  18601. h1 ^= h2 >>> 1;
  18602. h1 = h1 * 0x1a85ec53 & MASK_HIGH | h1 * 0xec53 & MASK_LOW;
  18603. h2 = h2 * 0xc4ceb9fe & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16;
  18604. h1 ^= h2 >>> 1;
  18605. return (h1 >>> 0).toString(16).padStart(8, "0") + (h2 >>> 0).toString(16).padStart(8, "0");
  18606. }
  18607. }
  18608. /***/ }),
  18609. /***/ 292:
  18610. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  18611. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  18612. /* harmony export */ AbortException: () => (/* binding */ AbortException),
  18613. /* harmony export */ AnnotationBorderStyleType: () => (/* binding */ AnnotationBorderStyleType),
  18614. /* harmony export */ AnnotationEditorParamsType: () => (/* binding */ AnnotationEditorParamsType),
  18615. /* harmony export */ AnnotationEditorPrefix: () => (/* binding */ AnnotationEditorPrefix),
  18616. /* harmony export */ AnnotationEditorType: () => (/* binding */ AnnotationEditorType),
  18617. /* harmony export */ AnnotationMode: () => (/* binding */ AnnotationMode),
  18618. /* harmony export */ AnnotationPrefix: () => (/* binding */ AnnotationPrefix),
  18619. /* harmony export */ AnnotationType: () => (/* binding */ AnnotationType),
  18620. /* harmony export */ BaseException: () => (/* binding */ BaseException),
  18621. /* harmony export */ CMapCompressionType: () => (/* binding */ CMapCompressionType),
  18622. /* harmony export */ FONT_IDENTITY_MATRIX: () => (/* binding */ FONT_IDENTITY_MATRIX),
  18623. /* harmony export */ FeatureTest: () => (/* binding */ FeatureTest),
  18624. /* harmony export */ FontRenderOps: () => (/* binding */ FontRenderOps),
  18625. /* harmony export */ FormatError: () => (/* binding */ FormatError),
  18626. /* harmony export */ IDENTITY_MATRIX: () => (/* binding */ IDENTITY_MATRIX),
  18627. /* harmony export */ ImageKind: () => (/* binding */ ImageKind),
  18628. /* harmony export */ InvalidPDFException: () => (/* binding */ InvalidPDFException),
  18629. /* harmony export */ LINE_FACTOR: () => (/* binding */ LINE_FACTOR),
  18630. /* harmony export */ MAX_IMAGE_SIZE_TO_CACHE: () => (/* binding */ MAX_IMAGE_SIZE_TO_CACHE),
  18631. /* harmony export */ MissingPDFException: () => (/* binding */ MissingPDFException),
  18632. /* harmony export */ OPS: () => (/* binding */ OPS),
  18633. /* harmony export */ PasswordException: () => (/* binding */ PasswordException),
  18634. /* harmony export */ PasswordResponses: () => (/* binding */ PasswordResponses),
  18635. /* harmony export */ PermissionFlag: () => (/* binding */ PermissionFlag),
  18636. /* harmony export */ RenderingIntentFlag: () => (/* binding */ RenderingIntentFlag),
  18637. /* harmony export */ TextRenderingMode: () => (/* binding */ TextRenderingMode),
  18638. /* harmony export */ UnexpectedResponseException: () => (/* binding */ UnexpectedResponseException),
  18639. /* harmony export */ UnknownErrorException: () => (/* binding */ UnknownErrorException),
  18640. /* harmony export */ Util: () => (/* binding */ Util),
  18641. /* harmony export */ VerbosityLevel: () => (/* binding */ VerbosityLevel),
  18642. /* harmony export */ assert: () => (/* binding */ assert),
  18643. /* harmony export */ bytesToString: () => (/* binding */ bytesToString),
  18644. /* harmony export */ createValidAbsoluteUrl: () => (/* binding */ createValidAbsoluteUrl),
  18645. /* harmony export */ getUuid: () => (/* binding */ getUuid),
  18646. /* harmony export */ getVerbosityLevel: () => (/* binding */ getVerbosityLevel),
  18647. /* harmony export */ info: () => (/* binding */ info),
  18648. /* harmony export */ isNodeJS: () => (/* binding */ isNodeJS),
  18649. /* harmony export */ normalizeUnicode: () => (/* binding */ normalizeUnicode),
  18650. /* harmony export */ objectFromMap: () => (/* binding */ objectFromMap),
  18651. /* harmony export */ setVerbosityLevel: () => (/* binding */ setVerbosityLevel),
  18652. /* harmony export */ shadow: () => (/* binding */ shadow),
  18653. /* harmony export */ string32: () => (/* binding */ string32),
  18654. /* harmony export */ stringToBytes: () => (/* binding */ stringToBytes),
  18655. /* harmony export */ unreachable: () => (/* binding */ unreachable),
  18656. /* harmony export */ warn: () => (/* binding */ warn)
  18657. /* harmony export */ });
  18658. /* unused harmony exports AnnotationActionEventType, AnnotationFieldFlag, AnnotationFlag, AnnotationReplyType, BASELINE_FACTOR, DocumentActionEventType, getModificationDate, isArrayEqual, LINE_DESCENT_FACTOR, objectSize, PageActionEventType, stringToPDFString, stringToUTF8String, utf8StringToString */
  18659. const isNodeJS = typeof process === "object" && process + "" === "[object process]" && !process.versions.nw && !(process.versions.electron && process.type && process.type !== "browser");
  18660. const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  18661. const FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  18662. const MAX_IMAGE_SIZE_TO_CACHE = 10e6;
  18663. const LINE_FACTOR = 1.35;
  18664. const LINE_DESCENT_FACTOR = 0.35;
  18665. const BASELINE_FACTOR = LINE_DESCENT_FACTOR / LINE_FACTOR;
  18666. const RenderingIntentFlag = {
  18667. ANY: 0x01,
  18668. DISPLAY: 0x02,
  18669. PRINT: 0x04,
  18670. SAVE: 0x08,
  18671. ANNOTATIONS_FORMS: 0x10,
  18672. ANNOTATIONS_STORAGE: 0x20,
  18673. ANNOTATIONS_DISABLE: 0x40,
  18674. OPLIST: 0x100
  18675. };
  18676. const AnnotationMode = {
  18677. DISABLE: 0,
  18678. ENABLE: 1,
  18679. ENABLE_FORMS: 2,
  18680. ENABLE_STORAGE: 3
  18681. };
  18682. const AnnotationEditorPrefix = "pdfjs_internal_editor_";
  18683. const AnnotationEditorType = {
  18684. DISABLE: -1,
  18685. NONE: 0,
  18686. FREETEXT: 3,
  18687. HIGHLIGHT: 9,
  18688. STAMP: 13,
  18689. INK: 15
  18690. };
  18691. const AnnotationEditorParamsType = {
  18692. RESIZE: 1,
  18693. CREATE: 2,
  18694. FREETEXT_SIZE: 11,
  18695. FREETEXT_COLOR: 12,
  18696. FREETEXT_OPACITY: 13,
  18697. INK_COLOR: 21,
  18698. INK_THICKNESS: 22,
  18699. INK_OPACITY: 23,
  18700. HIGHLIGHT_COLOR: 31,
  18701. HIGHLIGHT_DEFAULT_COLOR: 32,
  18702. HIGHLIGHT_THICKNESS: 33,
  18703. HIGHLIGHT_FREE: 34,
  18704. HIGHLIGHT_SHOW_ALL: 35
  18705. };
  18706. const PermissionFlag = {
  18707. PRINT: 0x04,
  18708. MODIFY_CONTENTS: 0x08,
  18709. COPY: 0x10,
  18710. MODIFY_ANNOTATIONS: 0x20,
  18711. FILL_INTERACTIVE_FORMS: 0x100,
  18712. COPY_FOR_ACCESSIBILITY: 0x200,
  18713. ASSEMBLE: 0x400,
  18714. PRINT_HIGH_QUALITY: 0x800
  18715. };
  18716. const TextRenderingMode = {
  18717. FILL: 0,
  18718. STROKE: 1,
  18719. FILL_STROKE: 2,
  18720. INVISIBLE: 3,
  18721. FILL_ADD_TO_PATH: 4,
  18722. STROKE_ADD_TO_PATH: 5,
  18723. FILL_STROKE_ADD_TO_PATH: 6,
  18724. ADD_TO_PATH: 7,
  18725. FILL_STROKE_MASK: 3,
  18726. ADD_TO_PATH_FLAG: 4
  18727. };
  18728. const ImageKind = {
  18729. GRAYSCALE_1BPP: 1,
  18730. RGB_24BPP: 2,
  18731. RGBA_32BPP: 3
  18732. };
  18733. const AnnotationType = {
  18734. TEXT: 1,
  18735. LINK: 2,
  18736. FREETEXT: 3,
  18737. LINE: 4,
  18738. SQUARE: 5,
  18739. CIRCLE: 6,
  18740. POLYGON: 7,
  18741. POLYLINE: 8,
  18742. HIGHLIGHT: 9,
  18743. UNDERLINE: 10,
  18744. SQUIGGLY: 11,
  18745. STRIKEOUT: 12,
  18746. STAMP: 13,
  18747. CARET: 14,
  18748. INK: 15,
  18749. POPUP: 16,
  18750. FILEATTACHMENT: 17,
  18751. SOUND: 18,
  18752. MOVIE: 19,
  18753. WIDGET: 20,
  18754. SCREEN: 21,
  18755. PRINTERMARK: 22,
  18756. TRAPNET: 23,
  18757. WATERMARK: 24,
  18758. THREED: 25,
  18759. REDACT: 26
  18760. };
  18761. const AnnotationReplyType = {
  18762. GROUP: "Group",
  18763. REPLY: "R"
  18764. };
  18765. const AnnotationFlag = {
  18766. INVISIBLE: 0x01,
  18767. HIDDEN: 0x02,
  18768. PRINT: 0x04,
  18769. NOZOOM: 0x08,
  18770. NOROTATE: 0x10,
  18771. NOVIEW: 0x20,
  18772. READONLY: 0x40,
  18773. LOCKED: 0x80,
  18774. TOGGLENOVIEW: 0x100,
  18775. LOCKEDCONTENTS: 0x200
  18776. };
  18777. const AnnotationFieldFlag = {
  18778. READONLY: 0x0000001,
  18779. REQUIRED: 0x0000002,
  18780. NOEXPORT: 0x0000004,
  18781. MULTILINE: 0x0001000,
  18782. PASSWORD: 0x0002000,
  18783. NOTOGGLETOOFF: 0x0004000,
  18784. RADIO: 0x0008000,
  18785. PUSHBUTTON: 0x0010000,
  18786. COMBO: 0x0020000,
  18787. EDIT: 0x0040000,
  18788. SORT: 0x0080000,
  18789. FILESELECT: 0x0100000,
  18790. MULTISELECT: 0x0200000,
  18791. DONOTSPELLCHECK: 0x0400000,
  18792. DONOTSCROLL: 0x0800000,
  18793. COMB: 0x1000000,
  18794. RICHTEXT: 0x2000000,
  18795. RADIOSINUNISON: 0x2000000,
  18796. COMMITONSELCHANGE: 0x4000000
  18797. };
  18798. const AnnotationBorderStyleType = {
  18799. SOLID: 1,
  18800. DASHED: 2,
  18801. BEVELED: 3,
  18802. INSET: 4,
  18803. UNDERLINE: 5
  18804. };
  18805. const AnnotationActionEventType = {
  18806. E: "Mouse Enter",
  18807. X: "Mouse Exit",
  18808. D: "Mouse Down",
  18809. U: "Mouse Up",
  18810. Fo: "Focus",
  18811. Bl: "Blur",
  18812. PO: "PageOpen",
  18813. PC: "PageClose",
  18814. PV: "PageVisible",
  18815. PI: "PageInvisible",
  18816. K: "Keystroke",
  18817. F: "Format",
  18818. V: "Validate",
  18819. C: "Calculate"
  18820. };
  18821. const DocumentActionEventType = {
  18822. WC: "WillClose",
  18823. WS: "WillSave",
  18824. DS: "DidSave",
  18825. WP: "WillPrint",
  18826. DP: "DidPrint"
  18827. };
  18828. const PageActionEventType = {
  18829. O: "PageOpen",
  18830. C: "PageClose"
  18831. };
  18832. const VerbosityLevel = {
  18833. ERRORS: 0,
  18834. WARNINGS: 1,
  18835. INFOS: 5
  18836. };
  18837. const CMapCompressionType = {
  18838. NONE: 0,
  18839. BINARY: 1
  18840. };
  18841. const OPS = {
  18842. dependency: 1,
  18843. setLineWidth: 2,
  18844. setLineCap: 3,
  18845. setLineJoin: 4,
  18846. setMiterLimit: 5,
  18847. setDash: 6,
  18848. setRenderingIntent: 7,
  18849. setFlatness: 8,
  18850. setGState: 9,
  18851. save: 10,
  18852. restore: 11,
  18853. transform: 12,
  18854. moveTo: 13,
  18855. lineTo: 14,
  18856. curveTo: 15,
  18857. curveTo2: 16,
  18858. curveTo3: 17,
  18859. closePath: 18,
  18860. rectangle: 19,
  18861. stroke: 20,
  18862. closeStroke: 21,
  18863. fill: 22,
  18864. eoFill: 23,
  18865. fillStroke: 24,
  18866. eoFillStroke: 25,
  18867. closeFillStroke: 26,
  18868. closeEOFillStroke: 27,
  18869. endPath: 28,
  18870. clip: 29,
  18871. eoClip: 30,
  18872. beginText: 31,
  18873. endText: 32,
  18874. setCharSpacing: 33,
  18875. setWordSpacing: 34,
  18876. setHScale: 35,
  18877. setLeading: 36,
  18878. setFont: 37,
  18879. setTextRenderingMode: 38,
  18880. setTextRise: 39,
  18881. moveText: 40,
  18882. setLeadingMoveText: 41,
  18883. setTextMatrix: 42,
  18884. nextLine: 43,
  18885. showText: 44,
  18886. showSpacedText: 45,
  18887. nextLineShowText: 46,
  18888. nextLineSetSpacingShowText: 47,
  18889. setCharWidth: 48,
  18890. setCharWidthAndBounds: 49,
  18891. setStrokeColorSpace: 50,
  18892. setFillColorSpace: 51,
  18893. setStrokeColor: 52,
  18894. setStrokeColorN: 53,
  18895. setFillColor: 54,
  18896. setFillColorN: 55,
  18897. setStrokeGray: 56,
  18898. setFillGray: 57,
  18899. setStrokeRGBColor: 58,
  18900. setFillRGBColor: 59,
  18901. setStrokeCMYKColor: 60,
  18902. setFillCMYKColor: 61,
  18903. shadingFill: 62,
  18904. beginInlineImage: 63,
  18905. beginImageData: 64,
  18906. endInlineImage: 65,
  18907. paintXObject: 66,
  18908. markPoint: 67,
  18909. markPointProps: 68,
  18910. beginMarkedContent: 69,
  18911. beginMarkedContentProps: 70,
  18912. endMarkedContent: 71,
  18913. beginCompat: 72,
  18914. endCompat: 73,
  18915. paintFormXObjectBegin: 74,
  18916. paintFormXObjectEnd: 75,
  18917. beginGroup: 76,
  18918. endGroup: 77,
  18919. beginAnnotation: 80,
  18920. endAnnotation: 81,
  18921. paintImageMaskXObject: 83,
  18922. paintImageMaskXObjectGroup: 84,
  18923. paintImageXObject: 85,
  18924. paintInlineImageXObject: 86,
  18925. paintInlineImageXObjectGroup: 87,
  18926. paintImageXObjectRepeat: 88,
  18927. paintImageMaskXObjectRepeat: 89,
  18928. paintSolidColorImageMask: 90,
  18929. constructPath: 91
  18930. };
  18931. const PasswordResponses = {
  18932. NEED_PASSWORD: 1,
  18933. INCORRECT_PASSWORD: 2
  18934. };
  18935. let verbosity = VerbosityLevel.WARNINGS;
  18936. function setVerbosityLevel(level) {
  18937. if (Number.isInteger(level)) {
  18938. verbosity = level;
  18939. }
  18940. }
  18941. function getVerbosityLevel() {
  18942. return verbosity;
  18943. }
  18944. function info(msg) {
  18945. if (verbosity >= VerbosityLevel.INFOS) {
  18946. console.log(`Info: ${msg}`);
  18947. }
  18948. }
  18949. function warn(msg) {
  18950. if (verbosity >= VerbosityLevel.WARNINGS) {
  18951. console.log(`Warning: ${msg}`);
  18952. }
  18953. }
  18954. function unreachable(msg) {
  18955. throw new Error(msg);
  18956. }
  18957. function assert(cond, msg) {
  18958. if (!cond) {
  18959. unreachable(msg);
  18960. }
  18961. }
  18962. function _isValidProtocol(url) {
  18963. switch (url?.protocol) {
  18964. case "http:":
  18965. case "https:":
  18966. case "ftp:":
  18967. case "mailto:":
  18968. case "tel:":
  18969. return true;
  18970. default:
  18971. return false;
  18972. }
  18973. }
  18974. function createValidAbsoluteUrl(url, baseUrl = null, options = null) {
  18975. if (!url) {
  18976. return null;
  18977. }
  18978. try {
  18979. if (options && typeof url === "string") {
  18980. if (options.addDefaultProtocol && url.startsWith("www.")) {
  18981. const dots = url.match(/\./g);
  18982. if (dots?.length >= 2) {
  18983. url = `http://${url}`;
  18984. }
  18985. }
  18986. if (options.tryConvertEncoding) {
  18987. try {
  18988. url = stringToUTF8String(url);
  18989. } catch {}
  18990. }
  18991. }
  18992. const absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url);
  18993. if (_isValidProtocol(absoluteUrl)) {
  18994. return absoluteUrl;
  18995. }
  18996. } catch {}
  18997. return null;
  18998. }
  18999. function shadow(obj, prop, value, nonSerializable = false) {
  19000. Object.defineProperty(obj, prop, {
  19001. value,
  19002. enumerable: !nonSerializable,
  19003. configurable: true,
  19004. writable: false
  19005. });
  19006. return value;
  19007. }
  19008. const BaseException = function BaseExceptionClosure() {
  19009. function BaseException(message, name) {
  19010. if (this.constructor === BaseException) {
  19011. unreachable("Cannot initialize BaseException.");
  19012. }
  19013. this.message = message;
  19014. this.name = name;
  19015. }
  19016. BaseException.prototype = new Error();
  19017. BaseException.constructor = BaseException;
  19018. return BaseException;
  19019. }();
  19020. class PasswordException extends BaseException {
  19021. constructor(msg, code) {
  19022. super(msg, "PasswordException");
  19023. this.code = code;
  19024. }
  19025. }
  19026. class UnknownErrorException extends BaseException {
  19027. constructor(msg, details) {
  19028. super(msg, "UnknownErrorException");
  19029. this.details = details;
  19030. }
  19031. }
  19032. class InvalidPDFException extends BaseException {
  19033. constructor(msg) {
  19034. super(msg, "InvalidPDFException");
  19035. }
  19036. }
  19037. class MissingPDFException extends BaseException {
  19038. constructor(msg) {
  19039. super(msg, "MissingPDFException");
  19040. }
  19041. }
  19042. class UnexpectedResponseException extends BaseException {
  19043. constructor(msg, status) {
  19044. super(msg, "UnexpectedResponseException");
  19045. this.status = status;
  19046. }
  19047. }
  19048. class FormatError extends BaseException {
  19049. constructor(msg) {
  19050. super(msg, "FormatError");
  19051. }
  19052. }
  19053. class AbortException extends BaseException {
  19054. constructor(msg) {
  19055. super(msg, "AbortException");
  19056. }
  19057. }
  19058. function bytesToString(bytes) {
  19059. if (typeof bytes !== "object" || bytes?.length === undefined) {
  19060. unreachable("Invalid argument for bytesToString");
  19061. }
  19062. const length = bytes.length;
  19063. const MAX_ARGUMENT_COUNT = 8192;
  19064. if (length < MAX_ARGUMENT_COUNT) {
  19065. return String.fromCharCode.apply(null, bytes);
  19066. }
  19067. const strBuf = [];
  19068. for (let i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  19069. const chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  19070. const chunk = bytes.subarray(i, chunkEnd);
  19071. strBuf.push(String.fromCharCode.apply(null, chunk));
  19072. }
  19073. return strBuf.join("");
  19074. }
  19075. function stringToBytes(str) {
  19076. if (typeof str !== "string") {
  19077. unreachable("Invalid argument for stringToBytes");
  19078. }
  19079. const length = str.length;
  19080. const bytes = new Uint8Array(length);
  19081. for (let i = 0; i < length; ++i) {
  19082. bytes[i] = str.charCodeAt(i) & 0xff;
  19083. }
  19084. return bytes;
  19085. }
  19086. function string32(value) {
  19087. return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
  19088. }
  19089. function objectSize(obj) {
  19090. return Object.keys(obj).length;
  19091. }
  19092. function objectFromMap(map) {
  19093. const obj = Object.create(null);
  19094. for (const [key, value] of map) {
  19095. obj[key] = value;
  19096. }
  19097. return obj;
  19098. }
  19099. function isLittleEndian() {
  19100. const buffer8 = new Uint8Array(4);
  19101. buffer8[0] = 1;
  19102. const view32 = new Uint32Array(buffer8.buffer, 0, 1);
  19103. return view32[0] === 1;
  19104. }
  19105. function isEvalSupported() {
  19106. try {
  19107. new Function("");
  19108. return true;
  19109. } catch {
  19110. return false;
  19111. }
  19112. }
  19113. class FeatureTest {
  19114. static get isLittleEndian() {
  19115. return shadow(this, "isLittleEndian", isLittleEndian());
  19116. }
  19117. static get isEvalSupported() {
  19118. return shadow(this, "isEvalSupported", isEvalSupported());
  19119. }
  19120. static get isOffscreenCanvasSupported() {
  19121. return shadow(this, "isOffscreenCanvasSupported", typeof OffscreenCanvas !== "undefined");
  19122. }
  19123. static get platform() {
  19124. if (typeof navigator !== "undefined" && typeof navigator?.platform === "string") {
  19125. return shadow(this, "platform", {
  19126. isMac: navigator.platform.includes("Mac")
  19127. });
  19128. }
  19129. return shadow(this, "platform", {
  19130. isMac: false
  19131. });
  19132. }
  19133. static get isCSSRoundSupported() {
  19134. return shadow(this, "isCSSRoundSupported", globalThis.CSS?.supports?.("width: round(1.5px, 1px)"));
  19135. }
  19136. }
  19137. const hexNumbers = Array.from(Array(256).keys(), n => n.toString(16).padStart(2, "0"));
  19138. class Util {
  19139. static makeHexColor(r, g, b) {
  19140. return `#${hexNumbers[r]}${hexNumbers[g]}${hexNumbers[b]}`;
  19141. }
  19142. static scaleMinMax(transform, minMax) {
  19143. let temp;
  19144. if (transform[0]) {
  19145. if (transform[0] < 0) {
  19146. temp = minMax[0];
  19147. minMax[0] = minMax[2];
  19148. minMax[2] = temp;
  19149. }
  19150. minMax[0] *= transform[0];
  19151. minMax[2] *= transform[0];
  19152. if (transform[3] < 0) {
  19153. temp = minMax[1];
  19154. minMax[1] = minMax[3];
  19155. minMax[3] = temp;
  19156. }
  19157. minMax[1] *= transform[3];
  19158. minMax[3] *= transform[3];
  19159. } else {
  19160. temp = minMax[0];
  19161. minMax[0] = minMax[1];
  19162. minMax[1] = temp;
  19163. temp = minMax[2];
  19164. minMax[2] = minMax[3];
  19165. minMax[3] = temp;
  19166. if (transform[1] < 0) {
  19167. temp = minMax[1];
  19168. minMax[1] = minMax[3];
  19169. minMax[3] = temp;
  19170. }
  19171. minMax[1] *= transform[1];
  19172. minMax[3] *= transform[1];
  19173. if (transform[2] < 0) {
  19174. temp = minMax[0];
  19175. minMax[0] = minMax[2];
  19176. minMax[2] = temp;
  19177. }
  19178. minMax[0] *= transform[2];
  19179. minMax[2] *= transform[2];
  19180. }
  19181. minMax[0] += transform[4];
  19182. minMax[1] += transform[5];
  19183. minMax[2] += transform[4];
  19184. minMax[3] += transform[5];
  19185. }
  19186. static transform(m1, m2) {
  19187. 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]];
  19188. }
  19189. static applyTransform(p, m) {
  19190. const xt = p[0] * m[0] + p[1] * m[2] + m[4];
  19191. const yt = p[0] * m[1] + p[1] * m[3] + m[5];
  19192. return [xt, yt];
  19193. }
  19194. static applyInverseTransform(p, m) {
  19195. const d = m[0] * m[3] - m[1] * m[2];
  19196. const xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  19197. const yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  19198. return [xt, yt];
  19199. }
  19200. static getAxialAlignedBoundingBox(r, m) {
  19201. const p1 = this.applyTransform(r, m);
  19202. const p2 = this.applyTransform(r.slice(2, 4), m);
  19203. const p3 = this.applyTransform([r[0], r[3]], m);
  19204. const p4 = this.applyTransform([r[2], r[1]], m);
  19205. 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])];
  19206. }
  19207. static inverseTransform(m) {
  19208. const d = m[0] * m[3] - m[1] * m[2];
  19209. 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];
  19210. }
  19211. static singularValueDecompose2dScale(m) {
  19212. const transpose = [m[0], m[2], m[1], m[3]];
  19213. const a = m[0] * transpose[0] + m[1] * transpose[2];
  19214. const b = m[0] * transpose[1] + m[1] * transpose[3];
  19215. const c = m[2] * transpose[0] + m[3] * transpose[2];
  19216. const d = m[2] * transpose[1] + m[3] * transpose[3];
  19217. const first = (a + d) / 2;
  19218. const second = Math.sqrt((a + d) ** 2 - 4 * (a * d - c * b)) / 2;
  19219. const sx = first + second || 1;
  19220. const sy = first - second || 1;
  19221. return [Math.sqrt(sx), Math.sqrt(sy)];
  19222. }
  19223. static normalizeRect(rect) {
  19224. const r = rect.slice(0);
  19225. if (rect[0] > rect[2]) {
  19226. r[0] = rect[2];
  19227. r[2] = rect[0];
  19228. }
  19229. if (rect[1] > rect[3]) {
  19230. r[1] = rect[3];
  19231. r[3] = rect[1];
  19232. }
  19233. return r;
  19234. }
  19235. static intersect(rect1, rect2) {
  19236. const xLow = Math.max(Math.min(rect1[0], rect1[2]), Math.min(rect2[0], rect2[2]));
  19237. const xHigh = Math.min(Math.max(rect1[0], rect1[2]), Math.max(rect2[0], rect2[2]));
  19238. if (xLow > xHigh) {
  19239. return null;
  19240. }
  19241. const yLow = Math.max(Math.min(rect1[1], rect1[3]), Math.min(rect2[1], rect2[3]));
  19242. const yHigh = Math.min(Math.max(rect1[1], rect1[3]), Math.max(rect2[1], rect2[3]));
  19243. if (yLow > yHigh) {
  19244. return null;
  19245. }
  19246. return [xLow, yLow, xHigh, yHigh];
  19247. }
  19248. static #getExtremumOnCurve(x0, x1, x2, x3, y0, y1, y2, y3, t, minMax) {
  19249. if (t <= 0 || t >= 1) {
  19250. return;
  19251. }
  19252. const mt = 1 - t;
  19253. const tt = t * t;
  19254. const ttt = tt * t;
  19255. const x = mt * (mt * (mt * x0 + 3 * t * x1) + 3 * tt * x2) + ttt * x3;
  19256. const y = mt * (mt * (mt * y0 + 3 * t * y1) + 3 * tt * y2) + ttt * y3;
  19257. minMax[0] = Math.min(minMax[0], x);
  19258. minMax[1] = Math.min(minMax[1], y);
  19259. minMax[2] = Math.max(minMax[2], x);
  19260. minMax[3] = Math.max(minMax[3], y);
  19261. }
  19262. static #getExtremum(x0, x1, x2, x3, y0, y1, y2, y3, a, b, c, minMax) {
  19263. if (Math.abs(a) < 1e-12) {
  19264. if (Math.abs(b) >= 1e-12) {
  19265. this.#getExtremumOnCurve(x0, x1, x2, x3, y0, y1, y2, y3, -c / b, minMax);
  19266. }
  19267. return;
  19268. }
  19269. const delta = b ** 2 - 4 * c * a;
  19270. if (delta < 0) {
  19271. return;
  19272. }
  19273. const sqrtDelta = Math.sqrt(delta);
  19274. const a2 = 2 * a;
  19275. this.#getExtremumOnCurve(x0, x1, x2, x3, y0, y1, y2, y3, (-b + sqrtDelta) / a2, minMax);
  19276. this.#getExtremumOnCurve(x0, x1, x2, x3, y0, y1, y2, y3, (-b - sqrtDelta) / a2, minMax);
  19277. }
  19278. static bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3, minMax) {
  19279. if (minMax) {
  19280. minMax[0] = Math.min(minMax[0], x0, x3);
  19281. minMax[1] = Math.min(minMax[1], y0, y3);
  19282. minMax[2] = Math.max(minMax[2], x0, x3);
  19283. minMax[3] = Math.max(minMax[3], y0, y3);
  19284. } else {
  19285. minMax = [Math.min(x0, x3), Math.min(y0, y3), Math.max(x0, x3), Math.max(y0, y3)];
  19286. }
  19287. this.#getExtremum(x0, x1, x2, x3, y0, y1, y2, y3, 3 * (-x0 + 3 * (x1 - x2) + x3), 6 * (x0 - 2 * x1 + x2), 3 * (x1 - x0), minMax);
  19288. this.#getExtremum(x0, x1, x2, x3, y0, y1, y2, y3, 3 * (-y0 + 3 * (y1 - y2) + y3), 6 * (y0 - 2 * y1 + y2), 3 * (y1 - y0), minMax);
  19289. return minMax;
  19290. }
  19291. }
  19292. 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]));
  19293. function stringToPDFString(str) {
  19294. if (str[0] >= "\xEF") {
  19295. let encoding;
  19296. if (str[0] === "\xFE" && str[1] === "\xFF") {
  19297. encoding = "utf-16be";
  19298. if (str.length % 2 === 1) {
  19299. str = str.slice(0, -1);
  19300. }
  19301. } else if (str[0] === "\xFF" && str[1] === "\xFE") {
  19302. encoding = "utf-16le";
  19303. if (str.length % 2 === 1) {
  19304. str = str.slice(0, -1);
  19305. }
  19306. } else if (str[0] === "\xEF" && str[1] === "\xBB" && str[2] === "\xBF") {
  19307. encoding = "utf-8";
  19308. }
  19309. if (encoding) {
  19310. try {
  19311. const decoder = new TextDecoder(encoding, {
  19312. fatal: true
  19313. });
  19314. const buffer = stringToBytes(str);
  19315. const decoded = decoder.decode(buffer);
  19316. if (!decoded.includes("\x1b")) {
  19317. return decoded;
  19318. }
  19319. return decoded.replaceAll(/\x1b[^\x1b]*(?:\x1b|$)/g, "");
  19320. } catch (ex) {
  19321. warn(`stringToPDFString: "${ex}".`);
  19322. }
  19323. }
  19324. }
  19325. const strBuf = [];
  19326. for (let i = 0, ii = str.length; i < ii; i++) {
  19327. const charCode = str.charCodeAt(i);
  19328. if (charCode === 0x1b) {
  19329. while (++i < ii && str.charCodeAt(i) !== 0x1b) {}
  19330. continue;
  19331. }
  19332. const code = PDFStringTranslateTable[charCode];
  19333. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  19334. }
  19335. return strBuf.join("");
  19336. }
  19337. function stringToUTF8String(str) {
  19338. return decodeURIComponent(escape(str));
  19339. }
  19340. function utf8StringToString(str) {
  19341. return unescape(encodeURIComponent(str));
  19342. }
  19343. function isArrayEqual(arr1, arr2) {
  19344. if (arr1.length !== arr2.length) {
  19345. return false;
  19346. }
  19347. for (let i = 0, ii = arr1.length; i < ii; i++) {
  19348. if (arr1[i] !== arr2[i]) {
  19349. return false;
  19350. }
  19351. }
  19352. return true;
  19353. }
  19354. function getModificationDate(date = new Date()) {
  19355. 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")];
  19356. return buffer.join("");
  19357. }
  19358. let NormalizeRegex = null;
  19359. let NormalizationMap = null;
  19360. function normalizeUnicode(str) {
  19361. if (!NormalizeRegex) {
  19362. 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;
  19363. NormalizationMap = new Map([["ſt", "ſt"]]);
  19364. }
  19365. return str.replaceAll(NormalizeRegex, (_, p1, p2) => p1 ? p1.normalize("NFKC") : NormalizationMap.get(p2));
  19366. }
  19367. function getUuid() {
  19368. if (typeof crypto !== "undefined" && typeof crypto?.randomUUID === "function") {
  19369. return crypto.randomUUID();
  19370. }
  19371. const buf = new Uint8Array(32);
  19372. if (typeof crypto !== "undefined" && typeof crypto?.getRandomValues === "function") {
  19373. crypto.getRandomValues(buf);
  19374. } else {
  19375. for (let i = 0; i < 32; i++) {
  19376. buf[i] = Math.floor(Math.random() * 255);
  19377. }
  19378. }
  19379. return bytesToString(buf);
  19380. }
  19381. const AnnotationPrefix = "pdfjs_internal_id_";
  19382. const FontRenderOps = {
  19383. BEZIER_CURVE_TO: 0,
  19384. MOVE_TO: 1,
  19385. LINE_TO: 2,
  19386. QUADRATIC_CURVE_TO: 3,
  19387. RESTORE: 4,
  19388. SAVE: 5,
  19389. SCALE: 6,
  19390. TRANSFORM: 7,
  19391. TRANSLATE: 8
  19392. };
  19393. /***/ })
  19394. /******/ });
  19395. /************************************************************************/
  19396. /******/ // The module cache
  19397. /******/ var __webpack_module_cache__ = {};
  19398. /******/
  19399. /******/ // The require function
  19400. /******/ function __webpack_require__(moduleId) {
  19401. /******/ // Check if module is in cache
  19402. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  19403. /******/ if (cachedModule !== undefined) {
  19404. /******/ return cachedModule.exports;
  19405. /******/ }
  19406. /******/ // Create a new module (and put it into the cache)
  19407. /******/ var module = __webpack_module_cache__[moduleId] = {
  19408. /******/ // no module.id needed
  19409. /******/ // no module.loaded needed
  19410. /******/ exports: {}
  19411. /******/ };
  19412. /******/
  19413. /******/ // Execute the module function
  19414. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  19415. /******/
  19416. /******/ // Return the exports of the module
  19417. /******/ return module.exports;
  19418. /******/ }
  19419. /******/
  19420. /************************************************************************/
  19421. /******/ /* webpack/runtime/async module */
  19422. /******/ (() => {
  19423. /******/ var webpackQueues = typeof Symbol === "function" ? Symbol("webpack queues") : "__webpack_queues__";
  19424. /******/ var webpackExports = typeof Symbol === "function" ? Symbol("webpack exports") : "__webpack_exports__";
  19425. /******/ var webpackError = typeof Symbol === "function" ? Symbol("webpack error") : "__webpack_error__";
  19426. /******/ var resolveQueue = (queue) => {
  19427. /******/ if(queue && queue.d < 1) {
  19428. /******/ queue.d = 1;
  19429. /******/ queue.forEach((fn) => (fn.r--));
  19430. /******/ queue.forEach((fn) => (fn.r-- ? fn.r++ : fn()));
  19431. /******/ }
  19432. /******/ }
  19433. /******/ var wrapDeps = (deps) => (deps.map((dep) => {
  19434. /******/ if(dep !== null && typeof dep === "object") {
  19435. /******/ if(dep[webpackQueues]) return dep;
  19436. /******/ if(dep.then) {
  19437. /******/ var queue = [];
  19438. /******/ queue.d = 0;
  19439. /******/ dep.then((r) => {
  19440. /******/ obj[webpackExports] = r;
  19441. /******/ resolveQueue(queue);
  19442. /******/ }, (e) => {
  19443. /******/ obj[webpackError] = e;
  19444. /******/ resolveQueue(queue);
  19445. /******/ });
  19446. /******/ var obj = {};
  19447. /******/ obj[webpackQueues] = (fn) => (fn(queue));
  19448. /******/ return obj;
  19449. /******/ }
  19450. /******/ }
  19451. /******/ var ret = {};
  19452. /******/ ret[webpackQueues] = x => {};
  19453. /******/ ret[webpackExports] = dep;
  19454. /******/ return ret;
  19455. /******/ }));
  19456. /******/ __webpack_require__.a = (module, body, hasAwait) => {
  19457. /******/ var queue;
  19458. /******/ hasAwait && ((queue = []).d = -1);
  19459. /******/ var depQueues = new Set();
  19460. /******/ var exports = module.exports;
  19461. /******/ var currentDeps;
  19462. /******/ var outerResolve;
  19463. /******/ var reject;
  19464. /******/ var promise = new Promise((resolve, rej) => {
  19465. /******/ reject = rej;
  19466. /******/ outerResolve = resolve;
  19467. /******/ });
  19468. /******/ promise[webpackExports] = exports;
  19469. /******/ promise[webpackQueues] = (fn) => (queue && fn(queue), depQueues.forEach(fn), promise["catch"](x => {}));
  19470. /******/ module.exports = promise;
  19471. /******/ body((deps) => {
  19472. /******/ currentDeps = wrapDeps(deps);
  19473. /******/ var fn;
  19474. /******/ var getResult = () => (currentDeps.map((d) => {
  19475. /******/ if(d[webpackError]) throw d[webpackError];
  19476. /******/ return d[webpackExports];
  19477. /******/ }))
  19478. /******/ var promise = new Promise((resolve) => {
  19479. /******/ fn = () => (resolve(getResult));
  19480. /******/ fn.r = 0;
  19481. /******/ var fnQueue = (q) => (q !== queue && !depQueues.has(q) && (depQueues.add(q), q && !q.d && (fn.r++, q.push(fn))));
  19482. /******/ currentDeps.map((dep) => (dep[webpackQueues](fnQueue)));
  19483. /******/ });
  19484. /******/ return fn.r ? promise : getResult();
  19485. /******/ }, (err) => ((err ? reject(promise[webpackError] = err) : outerResolve(exports)), resolveQueue(queue)));
  19486. /******/ queue && queue.d < 0 && (queue.d = 0);
  19487. /******/ };
  19488. /******/ })();
  19489. /******/
  19490. /******/ /* webpack/runtime/define property getters */
  19491. /******/ (() => {
  19492. /******/ // define getter functions for harmony exports
  19493. /******/ __webpack_require__.d = (exports, definition) => {
  19494. /******/ for(var key in definition) {
  19495. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  19496. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  19497. /******/ }
  19498. /******/ }
  19499. /******/ };
  19500. /******/ })();
  19501. /******/
  19502. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  19503. /******/ (() => {
  19504. /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
  19505. /******/ })();
  19506. /******/
  19507. /************************************************************************/
  19508. /******/
  19509. /******/ // startup
  19510. /******/ // Load entry module and return exports
  19511. /******/ // This entry module used 'module' so it can't be inlined
  19512. /******/ var __webpack_exports__ = __webpack_require__(228);
  19513. /******/ __webpack_exports__ = globalThis.pdfjsLib = await (globalThis.pdfjsLibPromise = __webpack_exports__);
  19514. /******/ var __webpack_exports__AbortException = __webpack_exports__.AbortException;
  19515. /******/ var __webpack_exports__AnnotationEditorLayer = __webpack_exports__.AnnotationEditorLayer;
  19516. /******/ var __webpack_exports__AnnotationEditorParamsType = __webpack_exports__.AnnotationEditorParamsType;
  19517. /******/ var __webpack_exports__AnnotationEditorType = __webpack_exports__.AnnotationEditorType;
  19518. /******/ var __webpack_exports__AnnotationEditorUIManager = __webpack_exports__.AnnotationEditorUIManager;
  19519. /******/ var __webpack_exports__AnnotationLayer = __webpack_exports__.AnnotationLayer;
  19520. /******/ var __webpack_exports__AnnotationMode = __webpack_exports__.AnnotationMode;
  19521. /******/ var __webpack_exports__CMapCompressionType = __webpack_exports__.CMapCompressionType;
  19522. /******/ var __webpack_exports__ColorPicker = __webpack_exports__.ColorPicker;
  19523. /******/ var __webpack_exports__DOMSVGFactory = __webpack_exports__.DOMSVGFactory;
  19524. /******/ var __webpack_exports__DrawLayer = __webpack_exports__.DrawLayer;
  19525. /******/ var __webpack_exports__FeatureTest = __webpack_exports__.FeatureTest;
  19526. /******/ var __webpack_exports__GlobalWorkerOptions = __webpack_exports__.GlobalWorkerOptions;
  19527. /******/ var __webpack_exports__ImageKind = __webpack_exports__.ImageKind;
  19528. /******/ var __webpack_exports__InvalidPDFException = __webpack_exports__.InvalidPDFException;
  19529. /******/ var __webpack_exports__MissingPDFException = __webpack_exports__.MissingPDFException;
  19530. /******/ var __webpack_exports__OPS = __webpack_exports__.OPS;
  19531. /******/ var __webpack_exports__Outliner = __webpack_exports__.Outliner;
  19532. /******/ var __webpack_exports__PDFDataRangeTransport = __webpack_exports__.PDFDataRangeTransport;
  19533. /******/ var __webpack_exports__PDFDateString = __webpack_exports__.PDFDateString;
  19534. /******/ var __webpack_exports__PDFWorker = __webpack_exports__.PDFWorker;
  19535. /******/ var __webpack_exports__PasswordResponses = __webpack_exports__.PasswordResponses;
  19536. /******/ var __webpack_exports__PermissionFlag = __webpack_exports__.PermissionFlag;
  19537. /******/ var __webpack_exports__PixelsPerInch = __webpack_exports__.PixelsPerInch;
  19538. /******/ var __webpack_exports__RenderingCancelledException = __webpack_exports__.RenderingCancelledException;
  19539. /******/ var __webpack_exports__UnexpectedResponseException = __webpack_exports__.UnexpectedResponseException;
  19540. /******/ var __webpack_exports__Util = __webpack_exports__.Util;
  19541. /******/ var __webpack_exports__VerbosityLevel = __webpack_exports__.VerbosityLevel;
  19542. /******/ var __webpack_exports__XfaLayer = __webpack_exports__.XfaLayer;
  19543. /******/ var __webpack_exports__build = __webpack_exports__.build;
  19544. /******/ var __webpack_exports__createValidAbsoluteUrl = __webpack_exports__.createValidAbsoluteUrl;
  19545. /******/ var __webpack_exports__fetchData = __webpack_exports__.fetchData;
  19546. /******/ var __webpack_exports__getDocument = __webpack_exports__.getDocument;
  19547. /******/ var __webpack_exports__getFilenameFromUrl = __webpack_exports__.getFilenameFromUrl;
  19548. /******/ var __webpack_exports__getPdfFilenameFromUrl = __webpack_exports__.getPdfFilenameFromUrl;
  19549. /******/ var __webpack_exports__getXfaPageViewport = __webpack_exports__.getXfaPageViewport;
  19550. /******/ var __webpack_exports__isDataScheme = __webpack_exports__.isDataScheme;
  19551. /******/ var __webpack_exports__isPdfFile = __webpack_exports__.isPdfFile;
  19552. /******/ var __webpack_exports__noContextMenu = __webpack_exports__.noContextMenu;
  19553. /******/ var __webpack_exports__normalizeUnicode = __webpack_exports__.normalizeUnicode;
  19554. /******/ var __webpack_exports__renderTextLayer = __webpack_exports__.renderTextLayer;
  19555. /******/ var __webpack_exports__setLayerDimensions = __webpack_exports__.setLayerDimensions;
  19556. /******/ var __webpack_exports__shadow = __webpack_exports__.shadow;
  19557. /******/ var __webpack_exports__updateTextLayer = __webpack_exports__.updateTextLayer;
  19558. /******/ var __webpack_exports__version = __webpack_exports__.version;
  19559. /******/ 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__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 };
  19560. /******/
  19561. //# sourceMappingURL=pdf.mjs.map