pdf.js 1020 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343
  1. amis.define('node_modules/pdfjs-dist/build/pdf.mjs', function(require, exports, module, define) {
  2. "use strict";
  3. /**
  4. * @licstart The following is the entire license notice for the
  5. * JavaScript code in this page
  6. *
  7. * Copyright 2023 Mozilla Foundation
  8. *
  9. * Licensed under the Apache License, Version 2.0 (the "License");
  10. * you may not use this file except in compliance with the License.
  11. * You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing, software
  16. * distributed under the License is distributed on an "AS IS" BASIS,
  17. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. * See the License for the specific language governing permissions and
  19. * limitations under the License.
  20. *
  21. * @licend The above is the entire license notice for the
  22. * JavaScript code in this page
  23. */
  24. var _a, _Util_getExtremumOnCurve, _Util_getExtremum, _DOMFilterFactory_instances, _DOMFilterFactory__cache, _DOMFilterFactory__defs, _DOMFilterFactory_docId, _DOMFilterFactory_document, _DOMFilterFactory__hcmCache, _DOMFilterFactory_id, _DOMFilterFactory_cache_get, _DOMFilterFactory_hcmCache_get, _DOMFilterFactory_defs_get, _DOMFilterFactory_createTables, _DOMFilterFactory_addLuminosityConversion, _DOMFilterFactory_addGrayConversion, _DOMFilterFactory_createFilter, _DOMFilterFactory_appendFeFunc, _DOMFilterFactory_addTransferMapConversion, _DOMFilterFactory_addTransferMapAlphaConversion, _DOMFilterFactory_getRGB, _EditorToolbar_instances, _b, _EditorToolbar_toolbar, _EditorToolbar_colorPicker, _EditorToolbar_editor, _EditorToolbar_buttons, _EditorToolbar_pointerDown, _EditorToolbar_focusIn, _EditorToolbar_focusOut, _EditorToolbar_addListenersToElement, _EditorToolbar_addDeleteButton, _EditorToolbar_divider_get, _HighlightToolbar_instances, _HighlightToolbar_buttons, _HighlightToolbar_toolbar, _HighlightToolbar_uiManager, _HighlightToolbar_render, _HighlightToolbar_getLastPoint, _HighlightToolbar_addHighlightButton, _IdManager_id, _ImageManager_instances, _ImageManager_baseId, _ImageManager_id, _ImageManager_cache, _ImageManager_get, _CommandManager_commands, _CommandManager_locked, _CommandManager_maxSize, _CommandManager_position, _KeyboardManager_instances, _KeyboardManager_serialize, _AnnotationStorage_instances, _AnnotationStorage_modified, _AnnotationStorage_storage, _AnnotationStorage_setModified, _PrintAnnotationStorage_serializable, _FontLoader_systemFonts, _CanvasGraphics_instances, _CanvasGraphics_restoreInitialState, _CanvasGraphics_drawFilter, _MessageHandler_instances, _MessageHandler_createStreamSink, _MessageHandler_processStreamMessage, _MessageHandler_deleteStreamController, _Metadata_metadataMap, _Metadata_data, _OptionalContentGroup_isDisplay, _OptionalContentGroup_isPrint, _OptionalContentGroup_userSet, _OptionalContentGroup_visible, _OptionalContentConfig_instances, _OptionalContentConfig_cachedGetHash, _OptionalContentConfig_groups, _OptionalContentConfig_initialHash, _OptionalContentConfig_order, _OptionalContentConfig_evaluateVisibilityExpression, _PDFPageProxy_instances, _PDFPageProxy_delayedCleanupTimeout, _PDFPageProxy_pendingCleanup, _PDFPageProxy_tryCleanup, _PDFPageProxy_abortDelayedCleanup, _LoopbackPort_listeners, _LoopbackPort_deferred, _c, _PDFWorker_workerPorts, _PDFWorker_mainThreadWorkerMessageHandler_get, _WorkerTransport_instances, _WorkerTransport_methodPromises, _WorkerTransport_pageCache, _WorkerTransport_pagePromises, _WorkerTransport_pageRefCache, _WorkerTransport_passwordCapability, _WorkerTransport_cacheSimpleMethod, _PDFObjects_instances, _PDFObjects_objs, _PDFObjects_ensureObj, _RenderTask_internalRenderTask, _AnnotationElement_instances, _AnnotationElement_updates, _AnnotationElement_hasBorder, _AnnotationElement_popupElement, _AnnotationElement_setRectEdited, _LinkAnnotationElement_instances, _LinkAnnotationElement_setInternalLink, _LinkAnnotationElement_bindAttachment, _LinkAnnotationElement_bindSetOCGState, _PopupElement_instances, _PopupElement_boundKeyDown, _PopupElement_boundHide, _PopupElement_boundShow, _PopupElement_boundToggle, _PopupElement_color, _PopupElement_container, _PopupElement_contentsObj, _PopupElement_dateObj, _PopupElement_elements, _PopupElement_parent, _PopupElement_parentRect, _PopupElement_pinned, _PopupElement_popup, _PopupElement_position, _PopupElement_rect, _PopupElement_richText, _PopupElement_titleObj, _PopupElement_updates, _PopupElement_wasVisible, _PopupElement_html_get, _PopupElement_fontSize_get, _PopupElement_fontColor_get, _PopupElement_makePopupContent, _PopupElement_keyDown, _PopupElement_setPosition, _PopupElement_toggle, _PopupElement_show, _PopupElement_hide, _LineAnnotationElement_line, _SquareAnnotationElement_square, _CircleAnnotationElement_circle, _PolylineAnnotationElement_polyline, _InkAnnotationElement_polylines, _FileAttachmentAnnotationElement_instances, _FileAttachmentAnnotationElement_trigger, _FileAttachmentAnnotationElement_download, _AnnotationLayer_instances, _AnnotationLayer_accessibilityManager, _AnnotationLayer_annotationCanvasMap, _AnnotationLayer_editableAnnotations, _AnnotationLayer_appendElement, _AnnotationLayer_setAnnotationCanvasMap, _Outliner_instances, _Outliner_box, _Outliner_verticalEdges, _Outliner_intervals, _Outliner_getOutlines, _Outliner_binarySearch, _Outliner_insert, _Outliner_remove, _Outliner_breakEdge, _HighlightOutline_box, _HighlightOutline_outlines, _FreeHighlightOutline_instances, _FreeHighlightOutline_box, _FreeHighlightOutline_bbox, _FreeHighlightOutline_innerMargin, _FreeHighlightOutline_isLTR, _FreeHighlightOutline_points, _FreeHighlightOutline_scaleFactor, _FreeHighlightOutline_outline, _FreeHighlightOutline_rescale, _FreeHighlightOutline_rescaleAndSwap, _FreeHighlightOutline_computeMinMax, _ColorPicker_instances, _ColorPicker_boundKeyDown, _ColorPicker_boundPointerDown, _ColorPicker_button, _ColorPicker_buttonSwatch, _ColorPicker_defaultColor, _ColorPicker_dropdown, _ColorPicker_dropdownWasFromKeyboard, _ColorPicker_isMainColorPicker, _ColorPicker_editor, _ColorPicker_eventBus, _ColorPicker_uiManager, _ColorPicker_type, _ColorPicker_getDropdownRoot, _ColorPicker_colorSelect, _ColorPicker_keyDown, _ColorPicker_openDropdown, _ColorPicker_pointerDown, _ColorPicker_isDropdownVisible_get, _DrawLayer_instances, _d, _DrawLayer_parent, _DrawLayer_id, _DrawLayer_mapping, _DrawLayer_toUpdate, _DrawLayer_setBox, _DrawLayer_createSVG, _DrawLayer_createClipPath;
  25. Object.defineProperty(exports, "__esModule", { value: true });
  26. exports.version = exports.updateTextLayer = exports.shadow = exports.setLayerDimensions = exports.renderTextLayer = exports.normalizeUnicode = exports.noContextMenu = exports.isPdfFile = exports.isDataScheme = exports.getXfaPageViewport = exports.getPdfFilenameFromUrl = exports.getFilenameFromUrl = exports.getDocument = exports.fetchData = exports.createValidAbsoluteUrl = exports.build = exports.XfaLayer = exports.VerbosityLevel = exports.Util = exports.UnexpectedResponseException = exports.TextLayer = exports.RenderingCancelledException = exports.PixelsPerInch = exports.PermissionFlag = exports.PasswordResponses = exports.PDFWorker = exports.PDFDateString = exports.PDFDataRangeTransport = exports.Outliner = exports.OPS = exports.MissingPDFException = exports.InvalidPDFException = exports.ImageKind = exports.GlobalWorkerOptions = exports.FeatureTest = exports.DrawLayer = exports.DOMSVGFactory = exports.ColorPicker = exports.CMapCompressionType = exports.AnnotationMode = exports.AnnotationLayer = exports.AnnotationEditorUIManager = exports.AnnotationEditorType = exports.AnnotationEditorParamsType = exports.AnnotationEditorLayer = exports.AbortException = void 0;
  27. var tslib_1 = require("d8ecf1d");
  28. /******/ // The require scope
  29. /******/ var __webpack_require__ = {};
  30. /******/
  31. /************************************************************************/
  32. /******/ /* webpack/runtime/define property getters */
  33. /******/ (function () {
  34. /******/ // define getter functions for harmony exports
  35. /******/ __webpack_require__.d = function (exports, definition) {
  36. /******/ for (var key in definition) {
  37. /******/ if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  38. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  39. /******/ }
  40. /******/ }
  41. /******/
  42. };
  43. /******/
  44. })();
  45. /******/
  46. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  47. /******/ (function () {
  48. /******/ __webpack_require__.o = function (obj, prop) { return (Object.prototype.hasOwnProperty.call(obj, prop)); };
  49. /******/
  50. })();
  51. /******/
  52. /************************************************************************/
  53. var __webpack_exports__ = globalThis.pdfjsLib = {};
  54. // EXPORTS
  55. __webpack_require__.d(__webpack_exports__, {
  56. AbortException: function () { return ( /* reexport */AbortException); },
  57. AnnotationEditorLayer: function () { return ( /* reexport */AnnotationEditorLayer); },
  58. AnnotationEditorParamsType: function () { return ( /* reexport */AnnotationEditorParamsType); },
  59. AnnotationEditorType: function () { return ( /* reexport */AnnotationEditorType); },
  60. AnnotationEditorUIManager: function () { return ( /* reexport */AnnotationEditorUIManager); },
  61. AnnotationLayer: function () { return ( /* reexport */AnnotationLayer); },
  62. AnnotationMode: function () { return ( /* reexport */AnnotationMode); },
  63. CMapCompressionType: function () { return ( /* reexport */CMapCompressionType); },
  64. ColorPicker: function () { return ( /* reexport */ColorPicker); },
  65. DOMSVGFactory: function () { return ( /* reexport */DOMSVGFactory); },
  66. DrawLayer: function () { return ( /* reexport */DrawLayer); },
  67. FeatureTest: function () { return ( /* reexport */util_FeatureTest); },
  68. GlobalWorkerOptions: function () { return ( /* reexport */GlobalWorkerOptions); },
  69. ImageKind: function () { return ( /* reexport */util_ImageKind); },
  70. InvalidPDFException: function () { return ( /* reexport */InvalidPDFException); },
  71. MissingPDFException: function () { return ( /* reexport */MissingPDFException); },
  72. OPS: function () { return ( /* reexport */OPS); },
  73. Outliner: function () { return ( /* reexport */Outliner); },
  74. PDFDataRangeTransport: function () { return ( /* reexport */PDFDataRangeTransport); },
  75. PDFDateString: function () { return ( /* reexport */PDFDateString); },
  76. PDFWorker: function () { return ( /* reexport */PDFWorker); },
  77. PasswordResponses: function () { return ( /* reexport */PasswordResponses); },
  78. PermissionFlag: function () { return ( /* reexport */PermissionFlag); },
  79. PixelsPerInch: function () { return ( /* reexport */PixelsPerInch); },
  80. RenderingCancelledException: function () { return ( /* reexport */RenderingCancelledException); },
  81. TextLayer: function () { return ( /* reexport */TextLayer); },
  82. UnexpectedResponseException: function () { return ( /* reexport */UnexpectedResponseException); },
  83. Util: function () { return ( /* reexport */Util); },
  84. VerbosityLevel: function () { return ( /* reexport */VerbosityLevel); },
  85. XfaLayer: function () { return ( /* reexport */XfaLayer); },
  86. build: function () { return ( /* reexport */build); },
  87. createValidAbsoluteUrl: function () { return ( /* reexport */createValidAbsoluteUrl); },
  88. fetchData: function () { return ( /* reexport */fetchData); },
  89. getDocument: function () { return ( /* reexport */getDocument); },
  90. getFilenameFromUrl: function () { return ( /* reexport */getFilenameFromUrl); },
  91. getPdfFilenameFromUrl: function () { return ( /* reexport */getPdfFilenameFromUrl); },
  92. getXfaPageViewport: function () { return ( /* reexport */getXfaPageViewport); },
  93. isDataScheme: function () { return ( /* reexport */isDataScheme); },
  94. isPdfFile: function () { return ( /* reexport */isPdfFile); },
  95. noContextMenu: function () { return ( /* reexport */noContextMenu); },
  96. normalizeUnicode: function () { return ( /* reexport */normalizeUnicode); },
  97. renderTextLayer: function () { return ( /* reexport */renderTextLayer); },
  98. setLayerDimensions: function () { return ( /* reexport */setLayerDimensions); },
  99. shadow: function () { return ( /* reexport */shadow); },
  100. updateTextLayer: function () { return ( /* reexport */updateTextLayer); },
  101. version: function () { return ( /* reexport */version); }
  102. });
  103. ; // CONCATENATED MODULE: ./src/shared/util.js
  104. var isNodeJS = "undefined" === "object" && process + "" === "[object process]" && !process.versions.nw && !(process.versions.electron && process.type && process.type !== "browser");
  105. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  106. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  107. var MAX_IMAGE_SIZE_TO_CACHE = 10e6;
  108. var LINE_FACTOR = 1.35;
  109. var LINE_DESCENT_FACTOR = 0.35;
  110. var BASELINE_FACTOR = LINE_DESCENT_FACTOR / LINE_FACTOR;
  111. var RenderingIntentFlag = {
  112. ANY: 0x01,
  113. DISPLAY: 0x02,
  114. PRINT: 0x04,
  115. SAVE: 0x08,
  116. ANNOTATIONS_FORMS: 0x10,
  117. ANNOTATIONS_STORAGE: 0x20,
  118. ANNOTATIONS_DISABLE: 0x40,
  119. OPLIST: 0x100
  120. };
  121. var AnnotationMode = {
  122. DISABLE: 0,
  123. ENABLE: 1,
  124. ENABLE_FORMS: 2,
  125. ENABLE_STORAGE: 3
  126. };
  127. var AnnotationEditorPrefix = "pdfjs_internal_editor_";
  128. var AnnotationEditorType = {
  129. DISABLE: -1,
  130. NONE: 0,
  131. FREETEXT: 3,
  132. HIGHLIGHT: 9,
  133. STAMP: 13,
  134. INK: 15
  135. };
  136. var AnnotationEditorParamsType = {
  137. RESIZE: 1,
  138. CREATE: 2,
  139. FREETEXT_SIZE: 11,
  140. FREETEXT_COLOR: 12,
  141. FREETEXT_OPACITY: 13,
  142. INK_COLOR: 21,
  143. INK_THICKNESS: 22,
  144. INK_OPACITY: 23,
  145. HIGHLIGHT_COLOR: 31,
  146. HIGHLIGHT_DEFAULT_COLOR: 32,
  147. HIGHLIGHT_THICKNESS: 33,
  148. HIGHLIGHT_FREE: 34,
  149. HIGHLIGHT_SHOW_ALL: 35
  150. };
  151. var PermissionFlag = {
  152. PRINT: 0x04,
  153. MODIFY_CONTENTS: 0x08,
  154. COPY: 0x10,
  155. MODIFY_ANNOTATIONS: 0x20,
  156. FILL_INTERACTIVE_FORMS: 0x100,
  157. COPY_FOR_ACCESSIBILITY: 0x200,
  158. ASSEMBLE: 0x400,
  159. PRINT_HIGH_QUALITY: 0x800
  160. };
  161. var TextRenderingMode = {
  162. FILL: 0,
  163. STROKE: 1,
  164. FILL_STROKE: 2,
  165. INVISIBLE: 3,
  166. FILL_ADD_TO_PATH: 4,
  167. STROKE_ADD_TO_PATH: 5,
  168. FILL_STROKE_ADD_TO_PATH: 6,
  169. ADD_TO_PATH: 7,
  170. FILL_STROKE_MASK: 3,
  171. ADD_TO_PATH_FLAG: 4
  172. };
  173. var util_ImageKind = {
  174. GRAYSCALE_1BPP: 1,
  175. RGB_24BPP: 2,
  176. RGBA_32BPP: 3
  177. };
  178. var AnnotationType = {
  179. TEXT: 1,
  180. LINK: 2,
  181. FREETEXT: 3,
  182. LINE: 4,
  183. SQUARE: 5,
  184. CIRCLE: 6,
  185. POLYGON: 7,
  186. POLYLINE: 8,
  187. HIGHLIGHT: 9,
  188. UNDERLINE: 10,
  189. SQUIGGLY: 11,
  190. STRIKEOUT: 12,
  191. STAMP: 13,
  192. CARET: 14,
  193. INK: 15,
  194. POPUP: 16,
  195. FILEATTACHMENT: 17,
  196. SOUND: 18,
  197. MOVIE: 19,
  198. WIDGET: 20,
  199. SCREEN: 21,
  200. PRINTERMARK: 22,
  201. TRAPNET: 23,
  202. WATERMARK: 24,
  203. THREED: 25,
  204. REDACT: 26
  205. };
  206. var AnnotationReplyType = {
  207. GROUP: "Group",
  208. REPLY: "R"
  209. };
  210. var AnnotationFlag = {
  211. INVISIBLE: 0x01,
  212. HIDDEN: 0x02,
  213. PRINT: 0x04,
  214. NOZOOM: 0x08,
  215. NOROTATE: 0x10,
  216. NOVIEW: 0x20,
  217. READONLY: 0x40,
  218. LOCKED: 0x80,
  219. TOGGLENOVIEW: 0x100,
  220. LOCKEDCONTENTS: 0x200
  221. };
  222. var AnnotationFieldFlag = {
  223. READONLY: 0x0000001,
  224. REQUIRED: 0x0000002,
  225. NOEXPORT: 0x0000004,
  226. MULTILINE: 0x0001000,
  227. PASSWORD: 0x0002000,
  228. NOTOGGLETOOFF: 0x0004000,
  229. RADIO: 0x0008000,
  230. PUSHBUTTON: 0x0010000,
  231. COMBO: 0x0020000,
  232. EDIT: 0x0040000,
  233. SORT: 0x0080000,
  234. FILESELECT: 0x0100000,
  235. MULTISELECT: 0x0200000,
  236. DONOTSPELLCHECK: 0x0400000,
  237. DONOTSCROLL: 0x0800000,
  238. COMB: 0x1000000,
  239. RICHTEXT: 0x2000000,
  240. RADIOSINUNISON: 0x2000000,
  241. COMMITONSELCHANGE: 0x4000000
  242. };
  243. var AnnotationBorderStyleType = {
  244. SOLID: 1,
  245. DASHED: 2,
  246. BEVELED: 3,
  247. INSET: 4,
  248. UNDERLINE: 5
  249. };
  250. var AnnotationActionEventType = {
  251. E: "Mouse Enter",
  252. X: "Mouse Exit",
  253. D: "Mouse Down",
  254. U: "Mouse Up",
  255. Fo: "Focus",
  256. Bl: "Blur",
  257. PO: "PageOpen",
  258. PC: "PageClose",
  259. PV: "PageVisible",
  260. PI: "PageInvisible",
  261. K: "Keystroke",
  262. F: "Format",
  263. V: "Validate",
  264. C: "Calculate"
  265. };
  266. var DocumentActionEventType = {
  267. WC: "WillClose",
  268. WS: "WillSave",
  269. DS: "DidSave",
  270. WP: "WillPrint",
  271. DP: "DidPrint"
  272. };
  273. var PageActionEventType = {
  274. O: "PageOpen",
  275. C: "PageClose"
  276. };
  277. var VerbosityLevel = {
  278. ERRORS: 0,
  279. WARNINGS: 1,
  280. INFOS: 5
  281. };
  282. var CMapCompressionType = {
  283. NONE: 0,
  284. BINARY: 1
  285. };
  286. var OPS = {
  287. dependency: 1,
  288. setLineWidth: 2,
  289. setLineCap: 3,
  290. setLineJoin: 4,
  291. setMiterLimit: 5,
  292. setDash: 6,
  293. setRenderingIntent: 7,
  294. setFlatness: 8,
  295. setGState: 9,
  296. save: 10,
  297. restore: 11,
  298. transform: 12,
  299. moveTo: 13,
  300. lineTo: 14,
  301. curveTo: 15,
  302. curveTo2: 16,
  303. curveTo3: 17,
  304. closePath: 18,
  305. rectangle: 19,
  306. stroke: 20,
  307. closeStroke: 21,
  308. fill: 22,
  309. eoFill: 23,
  310. fillStroke: 24,
  311. eoFillStroke: 25,
  312. closeFillStroke: 26,
  313. closeEOFillStroke: 27,
  314. endPath: 28,
  315. clip: 29,
  316. eoClip: 30,
  317. beginText: 31,
  318. endText: 32,
  319. setCharSpacing: 33,
  320. setWordSpacing: 34,
  321. setHScale: 35,
  322. setLeading: 36,
  323. setFont: 37,
  324. setTextRenderingMode: 38,
  325. setTextRise: 39,
  326. moveText: 40,
  327. setLeadingMoveText: 41,
  328. setTextMatrix: 42,
  329. nextLine: 43,
  330. showText: 44,
  331. showSpacedText: 45,
  332. nextLineShowText: 46,
  333. nextLineSetSpacingShowText: 47,
  334. setCharWidth: 48,
  335. setCharWidthAndBounds: 49,
  336. setStrokeColorSpace: 50,
  337. setFillColorSpace: 51,
  338. setStrokeColor: 52,
  339. setStrokeColorN: 53,
  340. setFillColor: 54,
  341. setFillColorN: 55,
  342. setStrokeGray: 56,
  343. setFillGray: 57,
  344. setStrokeRGBColor: 58,
  345. setFillRGBColor: 59,
  346. setStrokeCMYKColor: 60,
  347. setFillCMYKColor: 61,
  348. shadingFill: 62,
  349. beginInlineImage: 63,
  350. beginImageData: 64,
  351. endInlineImage: 65,
  352. paintXObject: 66,
  353. markPoint: 67,
  354. markPointProps: 68,
  355. beginMarkedContent: 69,
  356. beginMarkedContentProps: 70,
  357. endMarkedContent: 71,
  358. beginCompat: 72,
  359. endCompat: 73,
  360. paintFormXObjectBegin: 74,
  361. paintFormXObjectEnd: 75,
  362. beginGroup: 76,
  363. endGroup: 77,
  364. beginAnnotation: 80,
  365. endAnnotation: 81,
  366. paintImageMaskXObject: 83,
  367. paintImageMaskXObjectGroup: 84,
  368. paintImageXObject: 85,
  369. paintInlineImageXObject: 86,
  370. paintInlineImageXObjectGroup: 87,
  371. paintImageXObjectRepeat: 88,
  372. paintImageMaskXObjectRepeat: 89,
  373. paintSolidColorImageMask: 90,
  374. constructPath: 91
  375. };
  376. var PasswordResponses = {
  377. NEED_PASSWORD: 1,
  378. INCORRECT_PASSWORD: 2
  379. };
  380. var verbosity = VerbosityLevel.WARNINGS;
  381. function setVerbosityLevel(level) {
  382. if (Number.isInteger(level)) {
  383. verbosity = level;
  384. }
  385. }
  386. function getVerbosityLevel() {
  387. return verbosity;
  388. }
  389. function info(msg) {
  390. if (verbosity >= VerbosityLevel.INFOS) {
  391. console.log("Info: ".concat(msg));
  392. }
  393. }
  394. function warn(msg) {
  395. if (verbosity >= VerbosityLevel.WARNINGS) {
  396. console.log("Warning: ".concat(msg));
  397. }
  398. }
  399. function unreachable(msg) {
  400. throw new Error(msg);
  401. }
  402. function assert(cond, msg) {
  403. if (!cond) {
  404. unreachable(msg);
  405. }
  406. }
  407. function _isValidProtocol(url) {
  408. switch (url === null || url === void 0 ? void 0 : url.protocol) {
  409. case "http:":
  410. case "https:":
  411. case "ftp:":
  412. case "mailto:":
  413. case "tel:":
  414. return true;
  415. default:
  416. return false;
  417. }
  418. }
  419. function createValidAbsoluteUrl(url, baseUrl, options) {
  420. if (baseUrl === void 0) { baseUrl = null; }
  421. if (options === void 0) { options = null; }
  422. if (!url) {
  423. return null;
  424. }
  425. try {
  426. if (options && typeof url === "string") {
  427. if (options.addDefaultProtocol && url.startsWith("www.")) {
  428. var dots = url.match(/\./g);
  429. if ((dots === null || dots === void 0 ? void 0 : dots.length) >= 2) {
  430. url = "http://".concat(url);
  431. }
  432. }
  433. if (options.tryConvertEncoding) {
  434. try {
  435. url = stringToUTF8String(url);
  436. }
  437. catch (_e) { }
  438. }
  439. }
  440. var absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url);
  441. if (_isValidProtocol(absoluteUrl)) {
  442. return absoluteUrl;
  443. }
  444. }
  445. catch (_f) { }
  446. return null;
  447. }
  448. function shadow(obj, prop, value, nonSerializable) {
  449. if (nonSerializable === void 0) { nonSerializable = false; }
  450. Object.defineProperty(obj, prop, {
  451. value: value,
  452. enumerable: !nonSerializable,
  453. configurable: true,
  454. writable: false
  455. });
  456. return value;
  457. }
  458. var BaseException = function BaseExceptionClosure() {
  459. function BaseException(message, name) {
  460. if (this.constructor === BaseException) {
  461. unreachable("Cannot initialize BaseException.");
  462. }
  463. this.message = message;
  464. this.name = name;
  465. }
  466. BaseException.prototype = new Error();
  467. BaseException.constructor = BaseException;
  468. return BaseException;
  469. }();
  470. var PasswordException = /** @class */ (function (_super) {
  471. tslib_1.__extends(PasswordException, _super);
  472. function PasswordException(msg, code) {
  473. var _this = _super.call(this, msg, "PasswordException") || this;
  474. _this.code = code;
  475. return _this;
  476. }
  477. return PasswordException;
  478. }(BaseException));
  479. var UnknownErrorException = /** @class */ (function (_super) {
  480. tslib_1.__extends(UnknownErrorException, _super);
  481. function UnknownErrorException(msg, details) {
  482. var _this = _super.call(this, msg, "UnknownErrorException") || this;
  483. _this.details = details;
  484. return _this;
  485. }
  486. return UnknownErrorException;
  487. }(BaseException));
  488. var InvalidPDFException = /** @class */ (function (_super) {
  489. tslib_1.__extends(InvalidPDFException, _super);
  490. function InvalidPDFException(msg) {
  491. return _super.call(this, msg, "InvalidPDFException") || this;
  492. }
  493. return InvalidPDFException;
  494. }(BaseException));
  495. var MissingPDFException = /** @class */ (function (_super) {
  496. tslib_1.__extends(MissingPDFException, _super);
  497. function MissingPDFException(msg) {
  498. return _super.call(this, msg, "MissingPDFException") || this;
  499. }
  500. return MissingPDFException;
  501. }(BaseException));
  502. var UnexpectedResponseException = /** @class */ (function (_super) {
  503. tslib_1.__extends(UnexpectedResponseException, _super);
  504. function UnexpectedResponseException(msg, status) {
  505. var _this = _super.call(this, msg, "UnexpectedResponseException") || this;
  506. _this.status = status;
  507. return _this;
  508. }
  509. return UnexpectedResponseException;
  510. }(BaseException));
  511. var FormatError = /** @class */ (function (_super) {
  512. tslib_1.__extends(FormatError, _super);
  513. function FormatError(msg) {
  514. return _super.call(this, msg, "FormatError") || this;
  515. }
  516. return FormatError;
  517. }(BaseException));
  518. var AbortException = /** @class */ (function (_super) {
  519. tslib_1.__extends(AbortException, _super);
  520. function AbortException(msg) {
  521. return _super.call(this, msg, "AbortException") || this;
  522. }
  523. return AbortException;
  524. }(BaseException));
  525. function bytesToString(bytes) {
  526. if (typeof bytes !== "object" || (bytes === null || bytes === void 0 ? void 0 : bytes.length) === undefined) {
  527. unreachable("Invalid argument for bytesToString");
  528. }
  529. var length = bytes.length;
  530. var MAX_ARGUMENT_COUNT = 8192;
  531. if (length < MAX_ARGUMENT_COUNT) {
  532. return String.fromCharCode.apply(null, bytes);
  533. }
  534. var strBuf = [];
  535. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  536. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  537. var chunk = bytes.subarray(i, chunkEnd);
  538. strBuf.push(String.fromCharCode.apply(null, chunk));
  539. }
  540. return strBuf.join("");
  541. }
  542. function stringToBytes(str) {
  543. if (typeof str !== "string") {
  544. unreachable("Invalid argument for stringToBytes");
  545. }
  546. var length = str.length;
  547. var bytes = new Uint8Array(length);
  548. for (var i = 0; i < length; ++i) {
  549. bytes[i] = str.charCodeAt(i) & 0xff;
  550. }
  551. return bytes;
  552. }
  553. function string32(value) {
  554. return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
  555. }
  556. function objectSize(obj) {
  557. return Object.keys(obj).length;
  558. }
  559. function objectFromMap(map) {
  560. var obj = Object.create(null);
  561. for (var _i = 0, map_1 = map; _i < map_1.length; _i++) {
  562. var _e = map_1[_i], key = _e[0], value = _e[1];
  563. obj[key] = value;
  564. }
  565. return obj;
  566. }
  567. function isLittleEndian() {
  568. var buffer8 = new Uint8Array(4);
  569. buffer8[0] = 1;
  570. var view32 = new Uint32Array(buffer8.buffer, 0, 1);
  571. return view32[0] === 1;
  572. }
  573. function isEvalSupported() {
  574. try {
  575. new Function("");
  576. return true;
  577. }
  578. catch (_e) {
  579. return false;
  580. }
  581. }
  582. var util_FeatureTest = /** @class */ (function () {
  583. function util_FeatureTest() {
  584. }
  585. Object.defineProperty(util_FeatureTest, "isLittleEndian", {
  586. get: function () {
  587. return shadow(this, "isLittleEndian", isLittleEndian());
  588. },
  589. enumerable: false,
  590. configurable: true
  591. });
  592. Object.defineProperty(util_FeatureTest, "isEvalSupported", {
  593. get: function () {
  594. return shadow(this, "isEvalSupported", isEvalSupported());
  595. },
  596. enumerable: false,
  597. configurable: true
  598. });
  599. Object.defineProperty(util_FeatureTest, "isOffscreenCanvasSupported", {
  600. get: function () {
  601. return shadow(this, "isOffscreenCanvasSupported", typeof OffscreenCanvas !== "undefined");
  602. },
  603. enumerable: false,
  604. configurable: true
  605. });
  606. Object.defineProperty(util_FeatureTest, "platform", {
  607. get: function () {
  608. if (typeof navigator !== "undefined" && typeof (navigator === null || navigator === void 0 ? void 0 : navigator.platform) === "string") {
  609. return shadow(this, "platform", {
  610. isMac: navigator.platform.includes("Mac")
  611. });
  612. }
  613. return shadow(this, "platform", {
  614. isMac: false
  615. });
  616. },
  617. enumerable: false,
  618. configurable: true
  619. });
  620. Object.defineProperty(util_FeatureTest, "isCSSRoundSupported", {
  621. get: function () {
  622. var _e, _f;
  623. return shadow(this, "isCSSRoundSupported", (_f = (_e = globalThis.CSS) === null || _e === void 0 ? void 0 : _e.supports) === null || _f === void 0 ? void 0 : _f.call(_e, "width: round(1.5px, 1px)"));
  624. },
  625. enumerable: false,
  626. configurable: true
  627. });
  628. return util_FeatureTest;
  629. }());
  630. var hexNumbers = Array.from(Array(256).keys(), function (n) { return n.toString(16).padStart(2, "0"); });
  631. var Util = /** @class */ (function () {
  632. function Util() {
  633. }
  634. Util.makeHexColor = function (r, g, b) {
  635. return "#".concat(hexNumbers[r]).concat(hexNumbers[g]).concat(hexNumbers[b]);
  636. };
  637. Util.scaleMinMax = function (transform, minMax) {
  638. var temp;
  639. if (transform[0]) {
  640. if (transform[0] < 0) {
  641. temp = minMax[0];
  642. minMax[0] = minMax[2];
  643. minMax[2] = temp;
  644. }
  645. minMax[0] *= transform[0];
  646. minMax[2] *= transform[0];
  647. if (transform[3] < 0) {
  648. temp = minMax[1];
  649. minMax[1] = minMax[3];
  650. minMax[3] = temp;
  651. }
  652. minMax[1] *= transform[3];
  653. minMax[3] *= transform[3];
  654. }
  655. else {
  656. temp = minMax[0];
  657. minMax[0] = minMax[1];
  658. minMax[1] = temp;
  659. temp = minMax[2];
  660. minMax[2] = minMax[3];
  661. minMax[3] = temp;
  662. if (transform[1] < 0) {
  663. temp = minMax[1];
  664. minMax[1] = minMax[3];
  665. minMax[3] = temp;
  666. }
  667. minMax[1] *= transform[1];
  668. minMax[3] *= transform[1];
  669. if (transform[2] < 0) {
  670. temp = minMax[0];
  671. minMax[0] = minMax[2];
  672. minMax[2] = temp;
  673. }
  674. minMax[0] *= transform[2];
  675. minMax[2] *= transform[2];
  676. }
  677. minMax[0] += transform[4];
  678. minMax[1] += transform[5];
  679. minMax[2] += transform[4];
  680. minMax[3] += transform[5];
  681. };
  682. Util.transform = function (m1, m2) {
  683. 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]];
  684. };
  685. Util.applyTransform = function (p, m) {
  686. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  687. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  688. return [xt, yt];
  689. };
  690. Util.applyInverseTransform = function (p, m) {
  691. var d = m[0] * m[3] - m[1] * m[2];
  692. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  693. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  694. return [xt, yt];
  695. };
  696. Util.getAxialAlignedBoundingBox = function (r, m) {
  697. var p1 = this.applyTransform(r, m);
  698. var p2 = this.applyTransform(r.slice(2, 4), m);
  699. var p3 = this.applyTransform([r[0], r[3]], m);
  700. var p4 = this.applyTransform([r[2], r[1]], m);
  701. 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])];
  702. };
  703. Util.inverseTransform = function (m) {
  704. var d = m[0] * m[3] - m[1] * m[2];
  705. 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];
  706. };
  707. Util.singularValueDecompose2dScale = function (m) {
  708. var transpose = [m[0], m[2], m[1], m[3]];
  709. var a = m[0] * transpose[0] + m[1] * transpose[2];
  710. var b = m[0] * transpose[1] + m[1] * transpose[3];
  711. var c = m[2] * transpose[0] + m[3] * transpose[2];
  712. var d = m[2] * transpose[1] + m[3] * transpose[3];
  713. var first = (a + d) / 2;
  714. var second = Math.sqrt(Math.pow((a + d), 2) - 4 * (a * d - c * b)) / 2;
  715. var sx = first + second || 1;
  716. var sy = first - second || 1;
  717. return [Math.sqrt(sx), Math.sqrt(sy)];
  718. };
  719. Util.normalizeRect = function (rect) {
  720. var r = rect.slice(0);
  721. if (rect[0] > rect[2]) {
  722. r[0] = rect[2];
  723. r[2] = rect[0];
  724. }
  725. if (rect[1] > rect[3]) {
  726. r[1] = rect[3];
  727. r[3] = rect[1];
  728. }
  729. return r;
  730. };
  731. Util.intersect = function (rect1, rect2) {
  732. var xLow = Math.max(Math.min(rect1[0], rect1[2]), Math.min(rect2[0], rect2[2]));
  733. var xHigh = Math.min(Math.max(rect1[0], rect1[2]), Math.max(rect2[0], rect2[2]));
  734. if (xLow > xHigh) {
  735. return null;
  736. }
  737. var yLow = Math.max(Math.min(rect1[1], rect1[3]), Math.min(rect2[1], rect2[3]));
  738. var yHigh = Math.min(Math.max(rect1[1], rect1[3]), Math.max(rect2[1], rect2[3]));
  739. if (yLow > yHigh) {
  740. return null;
  741. }
  742. return [xLow, yLow, xHigh, yHigh];
  743. };
  744. Util.bezierBoundingBox = function (x0, y0, x1, y1, x2, y2, x3, y3, minMax) {
  745. if (minMax) {
  746. minMax[0] = Math.min(minMax[0], x0, x3);
  747. minMax[1] = Math.min(minMax[1], y0, y3);
  748. minMax[2] = Math.max(minMax[2], x0, x3);
  749. minMax[3] = Math.max(minMax[3], y0, y3);
  750. }
  751. else {
  752. minMax = [Math.min(x0, x3), Math.min(y0, y3), Math.max(x0, x3), Math.max(y0, y3)];
  753. }
  754. tslib_1.__classPrivateFieldGet(this, _a, "m", _Util_getExtremum).call(this, x0, x1, x2, x3, y0, y1, y2, y3, 3 * (-x0 + 3 * (x1 - x2) + x3), 6 * (x0 - 2 * x1 + x2), 3 * (x1 - x0), minMax);
  755. tslib_1.__classPrivateFieldGet(this, _a, "m", _Util_getExtremum).call(this, x0, x1, x2, x3, y0, y1, y2, y3, 3 * (-y0 + 3 * (y1 - y2) + y3), 6 * (y0 - 2 * y1 + y2), 3 * (y1 - y0), minMax);
  756. return minMax;
  757. };
  758. return Util;
  759. }());
  760. _a = Util, _Util_getExtremumOnCurve = function _Util_getExtremumOnCurve(x0, x1, x2, x3, y0, y1, y2, y3, t, minMax) {
  761. if (t <= 0 || t >= 1) {
  762. return;
  763. }
  764. var mt = 1 - t;
  765. var tt = t * t;
  766. var ttt = tt * t;
  767. var x = mt * (mt * (mt * x0 + 3 * t * x1) + 3 * tt * x2) + ttt * x3;
  768. var y = mt * (mt * (mt * y0 + 3 * t * y1) + 3 * tt * y2) + ttt * y3;
  769. minMax[0] = Math.min(minMax[0], x);
  770. minMax[1] = Math.min(minMax[1], y);
  771. minMax[2] = Math.max(minMax[2], x);
  772. minMax[3] = Math.max(minMax[3], y);
  773. }, _Util_getExtremum = function _Util_getExtremum(x0, x1, x2, x3, y0, y1, y2, y3, a, b, c, minMax) {
  774. if (Math.abs(a) < 1e-12) {
  775. if (Math.abs(b) >= 1e-12) {
  776. tslib_1.__classPrivateFieldGet(this, _a, "m", _Util_getExtremumOnCurve).call(this, x0, x1, x2, x3, y0, y1, y2, y3, -c / b, minMax);
  777. }
  778. return;
  779. }
  780. var delta = Math.pow(b, 2) - 4 * c * a;
  781. if (delta < 0) {
  782. return;
  783. }
  784. var sqrtDelta = Math.sqrt(delta);
  785. var a2 = 2 * a;
  786. tslib_1.__classPrivateFieldGet(this, _a, "m", _Util_getExtremumOnCurve).call(this, x0, x1, x2, x3, y0, y1, y2, y3, (-b + sqrtDelta) / a2, minMax);
  787. tslib_1.__classPrivateFieldGet(this, _a, "m", _Util_getExtremumOnCurve).call(this, x0, x1, x2, x3, y0, y1, y2, y3, (-b - sqrtDelta) / a2, minMax);
  788. };
  789. var 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]));
  790. function stringToPDFString(str) {
  791. if (str[0] >= "\xEF") {
  792. var encoding = void 0;
  793. if (str[0] === "\xFE" && str[1] === "\xFF") {
  794. encoding = "utf-16be";
  795. if (str.length % 2 === 1) {
  796. str = str.slice(0, -1);
  797. }
  798. }
  799. else if (str[0] === "\xFF" && str[1] === "\xFE") {
  800. encoding = "utf-16le";
  801. if (str.length % 2 === 1) {
  802. str = str.slice(0, -1);
  803. }
  804. }
  805. else if (str[0] === "\xEF" && str[1] === "\xBB" && str[2] === "\xBF") {
  806. encoding = "utf-8";
  807. }
  808. if (encoding) {
  809. try {
  810. var decoder = new TextDecoder(encoding, {
  811. fatal: true
  812. });
  813. var buffer = stringToBytes(str);
  814. var decoded = decoder.decode(buffer);
  815. if (!decoded.includes("\x1b")) {
  816. return decoded;
  817. }
  818. return decoded.replaceAll(/\x1b[^\x1b]*(?:\x1b|$)/g, "");
  819. }
  820. catch (ex) {
  821. warn("stringToPDFString: \"".concat(ex, "\"."));
  822. }
  823. }
  824. }
  825. var strBuf = [];
  826. for (var i = 0, ii = str.length; i < ii; i++) {
  827. var charCode = str.charCodeAt(i);
  828. if (charCode === 0x1b) {
  829. while (++i < ii && str.charCodeAt(i) !== 0x1b) { }
  830. continue;
  831. }
  832. var code = PDFStringTranslateTable[charCode];
  833. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  834. }
  835. return strBuf.join("");
  836. }
  837. function stringToUTF8String(str) {
  838. return decodeURIComponent(escape(str));
  839. }
  840. function utf8StringToString(str) {
  841. return unescape(encodeURIComponent(str));
  842. }
  843. function isArrayEqual(arr1, arr2) {
  844. if (arr1.length !== arr2.length) {
  845. return false;
  846. }
  847. for (var i = 0, ii = arr1.length; i < ii; i++) {
  848. if (arr1[i] !== arr2[i]) {
  849. return false;
  850. }
  851. }
  852. return true;
  853. }
  854. function getModificationDate(date) {
  855. if (date === void 0) { date = new Date(); }
  856. var 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")];
  857. return buffer.join("");
  858. }
  859. var NormalizeRegex = null;
  860. var NormalizationMap = null;
  861. function normalizeUnicode(str) {
  862. if (!NormalizeRegex) {
  863. 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;
  864. NormalizationMap = new Map([["ſt", "ſt"]]);
  865. }
  866. return str.replaceAll(NormalizeRegex, function (_, p1, p2) { return p1 ? p1.normalize("NFKC") : NormalizationMap.get(p2); });
  867. }
  868. function getUuid() {
  869. if (typeof crypto !== "undefined" && typeof (crypto === null || crypto === void 0 ? void 0 : crypto.randomUUID) === "function") {
  870. return crypto.randomUUID();
  871. }
  872. var buf = new Uint8Array(32);
  873. if (typeof crypto !== "undefined" && typeof (crypto === null || crypto === void 0 ? void 0 : crypto.getRandomValues) === "function") {
  874. crypto.getRandomValues(buf);
  875. }
  876. else {
  877. for (var i = 0; i < 32; i++) {
  878. buf[i] = Math.floor(Math.random() * 255);
  879. }
  880. }
  881. return bytesToString(buf);
  882. }
  883. var AnnotationPrefix = "pdfjs_internal_id_";
  884. var FontRenderOps = {
  885. BEZIER_CURVE_TO: 0,
  886. MOVE_TO: 1,
  887. LINE_TO: 2,
  888. QUADRATIC_CURVE_TO: 3,
  889. RESTORE: 4,
  890. SAVE: 5,
  891. SCALE: 6,
  892. TRANSFORM: 7,
  893. TRANSLATE: 8
  894. };
  895. ; // CONCATENATED MODULE: ./src/display/base_factory.js
  896. var BaseFilterFactory = /** @class */ (function () {
  897. function BaseFilterFactory() {
  898. if (this.constructor === BaseFilterFactory) {
  899. unreachable("Cannot initialize BaseFilterFactory.");
  900. }
  901. }
  902. BaseFilterFactory.prototype.addFilter = function (maps) {
  903. return "none";
  904. };
  905. BaseFilterFactory.prototype.addHCMFilter = function (fgColor, bgColor) {
  906. return "none";
  907. };
  908. BaseFilterFactory.prototype.addAlphaFilter = function (map) {
  909. return "none";
  910. };
  911. BaseFilterFactory.prototype.addLuminosityFilter = function (map) {
  912. return "none";
  913. };
  914. BaseFilterFactory.prototype.addHighlightHCMFilter = function (filterName, fgColor, bgColor, newFgColor, newBgColor) {
  915. return "none";
  916. };
  917. BaseFilterFactory.prototype.destroy = function (keepHCM) {
  918. if (keepHCM === void 0) { keepHCM = false; }
  919. };
  920. return BaseFilterFactory;
  921. }());
  922. var BaseCanvasFactory = /** @class */ (function () {
  923. function BaseCanvasFactory() {
  924. if (this.constructor === BaseCanvasFactory) {
  925. unreachable("Cannot initialize BaseCanvasFactory.");
  926. }
  927. }
  928. BaseCanvasFactory.prototype.create = function (width, height) {
  929. if (width <= 0 || height <= 0) {
  930. throw new Error("Invalid canvas size");
  931. }
  932. var canvas = this._createCanvas(width, height);
  933. return {
  934. canvas: canvas,
  935. context: canvas.getContext("2d")
  936. };
  937. };
  938. BaseCanvasFactory.prototype.reset = function (canvasAndContext, width, height) {
  939. if (!canvasAndContext.canvas) {
  940. throw new Error("Canvas is not specified");
  941. }
  942. if (width <= 0 || height <= 0) {
  943. throw new Error("Invalid canvas size");
  944. }
  945. canvasAndContext.canvas.width = width;
  946. canvasAndContext.canvas.height = height;
  947. };
  948. BaseCanvasFactory.prototype.destroy = function (canvasAndContext) {
  949. if (!canvasAndContext.canvas) {
  950. throw new Error("Canvas is not specified");
  951. }
  952. canvasAndContext.canvas.width = 0;
  953. canvasAndContext.canvas.height = 0;
  954. canvasAndContext.canvas = null;
  955. canvasAndContext.context = null;
  956. };
  957. BaseCanvasFactory.prototype._createCanvas = function (width, height) {
  958. unreachable("Abstract method `_createCanvas` called.");
  959. };
  960. return BaseCanvasFactory;
  961. }());
  962. var BaseCMapReaderFactory = /** @class */ (function () {
  963. function BaseCMapReaderFactory(_e) {
  964. var _f = _e.baseUrl, baseUrl = _f === void 0 ? null : _f, _g = _e.isCompressed, isCompressed = _g === void 0 ? true : _g;
  965. if (this.constructor === BaseCMapReaderFactory) {
  966. unreachable("Cannot initialize BaseCMapReaderFactory.");
  967. }
  968. this.baseUrl = baseUrl;
  969. this.isCompressed = isCompressed;
  970. }
  971. BaseCMapReaderFactory.prototype.fetch = function (_e) {
  972. var name = _e.name;
  973. return tslib_1.__awaiter(this, void 0, void 0, function () {
  974. var url, compressionType;
  975. var _this = this;
  976. return tslib_1.__generator(this, function (_f) {
  977. if (!this.baseUrl) {
  978. throw new Error('The CMap "baseUrl" parameter must be specified, ensure that ' + 'the "cMapUrl" and "cMapPacked" API parameters are provided.');
  979. }
  980. if (!name) {
  981. throw new Error("CMap name must be specified.");
  982. }
  983. url = this.baseUrl + name + (this.isCompressed ? ".bcmap" : "");
  984. compressionType = this.isCompressed ? CMapCompressionType.BINARY : CMapCompressionType.NONE;
  985. return [2 /*return*/, this._fetchData(url, compressionType).catch(function (reason) {
  986. throw new Error("Unable to load ".concat(_this.isCompressed ? "binary " : "", "CMap at: ").concat(url));
  987. })];
  988. });
  989. });
  990. };
  991. BaseCMapReaderFactory.prototype._fetchData = function (url, compressionType) {
  992. unreachable("Abstract method `_fetchData` called.");
  993. };
  994. return BaseCMapReaderFactory;
  995. }());
  996. var BaseStandardFontDataFactory = /** @class */ (function () {
  997. function BaseStandardFontDataFactory(_e) {
  998. var _f = _e.baseUrl, baseUrl = _f === void 0 ? null : _f;
  999. if (this.constructor === BaseStandardFontDataFactory) {
  1000. unreachable("Cannot initialize BaseStandardFontDataFactory.");
  1001. }
  1002. this.baseUrl = baseUrl;
  1003. }
  1004. BaseStandardFontDataFactory.prototype.fetch = function (_e) {
  1005. var filename = _e.filename;
  1006. return tslib_1.__awaiter(this, void 0, void 0, function () {
  1007. var url;
  1008. return tslib_1.__generator(this, function (_f) {
  1009. if (!this.baseUrl) {
  1010. throw new Error('The standard font "baseUrl" parameter must be specified, ensure that ' + 'the "standardFontDataUrl" API parameter is provided.');
  1011. }
  1012. if (!filename) {
  1013. throw new Error("Font filename must be specified.");
  1014. }
  1015. url = "".concat(this.baseUrl).concat(filename);
  1016. return [2 /*return*/, this._fetchData(url).catch(function (reason) {
  1017. throw new Error("Unable to load font data at: ".concat(url));
  1018. })];
  1019. });
  1020. });
  1021. };
  1022. BaseStandardFontDataFactory.prototype._fetchData = function (url) {
  1023. unreachable("Abstract method `_fetchData` called.");
  1024. };
  1025. return BaseStandardFontDataFactory;
  1026. }());
  1027. var BaseSVGFactory = /** @class */ (function () {
  1028. function BaseSVGFactory() {
  1029. if (this.constructor === BaseSVGFactory) {
  1030. unreachable("Cannot initialize BaseSVGFactory.");
  1031. }
  1032. }
  1033. BaseSVGFactory.prototype.create = function (width, height, skipDimensions) {
  1034. if (skipDimensions === void 0) { skipDimensions = false; }
  1035. if (width <= 0 || height <= 0) {
  1036. throw new Error("Invalid SVG dimensions");
  1037. }
  1038. var svg = this._createSVG("svg:svg");
  1039. svg.setAttribute("version", "1.1");
  1040. if (!skipDimensions) {
  1041. svg.setAttribute("width", "".concat(width, "px"));
  1042. svg.setAttribute("height", "".concat(height, "px"));
  1043. }
  1044. svg.setAttribute("preserveAspectRatio", "none");
  1045. svg.setAttribute("viewBox", "0 0 ".concat(width, " ").concat(height));
  1046. return svg;
  1047. };
  1048. BaseSVGFactory.prototype.createElement = function (type) {
  1049. if (typeof type !== "string") {
  1050. throw new Error("Invalid SVG element type");
  1051. }
  1052. return this._createSVG(type);
  1053. };
  1054. BaseSVGFactory.prototype._createSVG = function (type) {
  1055. unreachable("Abstract method `_createSVG` called.");
  1056. };
  1057. return BaseSVGFactory;
  1058. }());
  1059. ; // CONCATENATED MODULE: ./src/display/display_utils.js
  1060. var SVG_NS = "http://www.w3.org/2000/svg";
  1061. var PixelsPerInch = /** @class */ (function () {
  1062. function PixelsPerInch() {
  1063. }
  1064. var _e;
  1065. _e = PixelsPerInch;
  1066. PixelsPerInch.CSS = 96.0;
  1067. PixelsPerInch.PDF = 72.0;
  1068. PixelsPerInch.PDF_TO_CSS_UNITS = _e.CSS / _e.PDF;
  1069. return PixelsPerInch;
  1070. }());
  1071. var DOMFilterFactory = /** @class */ (function (_super) {
  1072. tslib_1.__extends(DOMFilterFactory, _super);
  1073. function DOMFilterFactory(_f) {
  1074. var _g = _f === void 0 ? {} : _f, docId = _g.docId, _h = _g.ownerDocument, ownerDocument = _h === void 0 ? globalThis.document : _h;
  1075. var _this = _super.call(this) || this;
  1076. _DOMFilterFactory_instances.add(_this);
  1077. _DOMFilterFactory__cache.set(_this, void 0);
  1078. _DOMFilterFactory__defs.set(_this, void 0);
  1079. _DOMFilterFactory_docId.set(_this, void 0);
  1080. _DOMFilterFactory_document.set(_this, void 0);
  1081. _DOMFilterFactory__hcmCache.set(_this, void 0);
  1082. _DOMFilterFactory_id.set(_this, 0);
  1083. tslib_1.__classPrivateFieldSet(_this, _DOMFilterFactory_docId, docId, "f");
  1084. tslib_1.__classPrivateFieldSet(_this, _DOMFilterFactory_document, ownerDocument, "f");
  1085. return _this;
  1086. }
  1087. DOMFilterFactory.prototype.addFilter = function (maps) {
  1088. var _f, _g;
  1089. if (!maps) {
  1090. return "none";
  1091. }
  1092. var value = tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "a", _DOMFilterFactory_cache_get).get(maps);
  1093. if (value) {
  1094. return value;
  1095. }
  1096. var _h = tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "m", _DOMFilterFactory_createTables).call(this, maps), tableR = _h[0], tableG = _h[1], tableB = _h[2];
  1097. var key = maps.length === 1 ? tableR : "".concat(tableR).concat(tableG).concat(tableB);
  1098. value = tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "a", _DOMFilterFactory_cache_get).get(key);
  1099. if (value) {
  1100. tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "a", _DOMFilterFactory_cache_get).set(maps, value);
  1101. return value;
  1102. }
  1103. var id = "g_".concat(tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_docId, "f"), "_transfer_map_").concat((tslib_1.__classPrivateFieldSet(this, _DOMFilterFactory_id, (_g = tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_id, "f"), _f = _g++, _g), "f"), _f));
  1104. var url = "url(#".concat(id, ")");
  1105. tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "a", _DOMFilterFactory_cache_get).set(maps, url);
  1106. tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "a", _DOMFilterFactory_cache_get).set(key, url);
  1107. var filter = tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "m", _DOMFilterFactory_createFilter).call(this, id);
  1108. tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "m", _DOMFilterFactory_addTransferMapConversion).call(this, tableR, tableG, tableB, filter);
  1109. return url;
  1110. };
  1111. DOMFilterFactory.prototype.addHCMFilter = function (fgColor, bgColor) {
  1112. var _f;
  1113. var key = "".concat(fgColor, "-").concat(bgColor);
  1114. var filterName = "base";
  1115. var info = tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "a", _DOMFilterFactory_hcmCache_get).get(filterName);
  1116. if ((info === null || info === void 0 ? void 0 : info.key) === key) {
  1117. return info.url;
  1118. }
  1119. if (info) {
  1120. (_f = info.filter) === null || _f === void 0 ? void 0 : _f.remove();
  1121. info.key = key;
  1122. info.url = "none";
  1123. info.filter = null;
  1124. }
  1125. else {
  1126. info = {
  1127. key: key,
  1128. url: "none",
  1129. filter: null
  1130. };
  1131. tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "a", _DOMFilterFactory_hcmCache_get).set(filterName, info);
  1132. }
  1133. if (!fgColor || !bgColor) {
  1134. return info.url;
  1135. }
  1136. var fgRGB = tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "m", _DOMFilterFactory_getRGB).call(this, fgColor);
  1137. fgColor = Util.makeHexColor.apply(Util, fgRGB);
  1138. var bgRGB = tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "m", _DOMFilterFactory_getRGB).call(this, bgColor);
  1139. bgColor = Util.makeHexColor.apply(Util, bgRGB);
  1140. tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "a", _DOMFilterFactory_defs_get).style.color = "";
  1141. if (fgColor === "#000000" && bgColor === "#ffffff" || fgColor === bgColor) {
  1142. return info.url;
  1143. }
  1144. var map = new Array(256);
  1145. for (var i = 0; i <= 255; i++) {
  1146. var x = i / 255;
  1147. map[i] = x <= 0.03928 ? x / 12.92 : Math.pow(((x + 0.055) / 1.055), 2.4);
  1148. }
  1149. var table = map.join(",");
  1150. var id = "g_".concat(tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_docId, "f"), "_hcm_filter");
  1151. var filter = info.filter = tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "m", _DOMFilterFactory_createFilter).call(this, id);
  1152. tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "m", _DOMFilterFactory_addTransferMapConversion).call(this, table, table, table, filter);
  1153. tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "m", _DOMFilterFactory_addGrayConversion).call(this, filter);
  1154. var getSteps = function (c, n) {
  1155. var start = fgRGB[c] / 255;
  1156. var end = bgRGB[c] / 255;
  1157. var arr = new Array(n + 1);
  1158. for (var i = 0; i <= n; i++) {
  1159. arr[i] = start + i / n * (end - start);
  1160. }
  1161. return arr.join(",");
  1162. };
  1163. tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "m", _DOMFilterFactory_addTransferMapConversion).call(this, getSteps(0, 5), getSteps(1, 5), getSteps(2, 5), filter);
  1164. info.url = "url(#".concat(id, ")");
  1165. return info.url;
  1166. };
  1167. DOMFilterFactory.prototype.addAlphaFilter = function (map) {
  1168. var _f, _g;
  1169. var value = tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "a", _DOMFilterFactory_cache_get).get(map);
  1170. if (value) {
  1171. return value;
  1172. }
  1173. var tableA = tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "m", _DOMFilterFactory_createTables).call(this, [map])[0];
  1174. var key = "alpha_".concat(tableA);
  1175. value = tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "a", _DOMFilterFactory_cache_get).get(key);
  1176. if (value) {
  1177. tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "a", _DOMFilterFactory_cache_get).set(map, value);
  1178. return value;
  1179. }
  1180. var id = "g_".concat(tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_docId, "f"), "_alpha_map_").concat((tslib_1.__classPrivateFieldSet(this, _DOMFilterFactory_id, (_g = tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_id, "f"), _f = _g++, _g), "f"), _f));
  1181. var url = "url(#".concat(id, ")");
  1182. tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "a", _DOMFilterFactory_cache_get).set(map, url);
  1183. tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "a", _DOMFilterFactory_cache_get).set(key, url);
  1184. var filter = tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "m", _DOMFilterFactory_createFilter).call(this, id);
  1185. tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "m", _DOMFilterFactory_addTransferMapAlphaConversion).call(this, tableA, filter);
  1186. return url;
  1187. };
  1188. DOMFilterFactory.prototype.addLuminosityFilter = function (map) {
  1189. var _f, _g;
  1190. var value = tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "a", _DOMFilterFactory_cache_get).get(map || "luminosity");
  1191. if (value) {
  1192. return value;
  1193. }
  1194. var tableA, key;
  1195. if (map) {
  1196. tableA = tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "m", _DOMFilterFactory_createTables).call(this, [map])[0];
  1197. key = "luminosity_".concat(tableA);
  1198. }
  1199. else {
  1200. key = "luminosity";
  1201. }
  1202. value = tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "a", _DOMFilterFactory_cache_get).get(key);
  1203. if (value) {
  1204. tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "a", _DOMFilterFactory_cache_get).set(map, value);
  1205. return value;
  1206. }
  1207. var id = "g_".concat(tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_docId, "f"), "_luminosity_map_").concat((tslib_1.__classPrivateFieldSet(this, _DOMFilterFactory_id, (_g = tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_id, "f"), _f = _g++, _g), "f"), _f));
  1208. var url = "url(#".concat(id, ")");
  1209. tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "a", _DOMFilterFactory_cache_get).set(map, url);
  1210. tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "a", _DOMFilterFactory_cache_get).set(key, url);
  1211. var filter = tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "m", _DOMFilterFactory_createFilter).call(this, id);
  1212. tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "m", _DOMFilterFactory_addLuminosityConversion).call(this, filter);
  1213. if (map) {
  1214. tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "m", _DOMFilterFactory_addTransferMapAlphaConversion).call(this, tableA, filter);
  1215. }
  1216. return url;
  1217. };
  1218. DOMFilterFactory.prototype.addHighlightHCMFilter = function (filterName, fgColor, bgColor, newFgColor, newBgColor) {
  1219. var _f;
  1220. var _g;
  1221. var key = "".concat(fgColor, "-").concat(bgColor, "-").concat(newFgColor, "-").concat(newBgColor);
  1222. var info = tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "a", _DOMFilterFactory_hcmCache_get).get(filterName);
  1223. if ((info === null || info === void 0 ? void 0 : info.key) === key) {
  1224. return info.url;
  1225. }
  1226. if (info) {
  1227. (_g = info.filter) === null || _g === void 0 ? void 0 : _g.remove();
  1228. info.key = key;
  1229. info.url = "none";
  1230. info.filter = null;
  1231. }
  1232. else {
  1233. info = {
  1234. key: key,
  1235. url: "none",
  1236. filter: null
  1237. };
  1238. tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "a", _DOMFilterFactory_hcmCache_get).set(filterName, info);
  1239. }
  1240. if (!fgColor || !bgColor) {
  1241. return info.url;
  1242. }
  1243. var _h = [fgColor, bgColor].map(tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "m", _DOMFilterFactory_getRGB).bind(this)), fgRGB = _h[0], bgRGB = _h[1];
  1244. var fgGray = Math.round(0.2126 * fgRGB[0] + 0.7152 * fgRGB[1] + 0.0722 * fgRGB[2]);
  1245. var bgGray = Math.round(0.2126 * bgRGB[0] + 0.7152 * bgRGB[1] + 0.0722 * bgRGB[2]);
  1246. var _j = [newFgColor, newBgColor].map(tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "m", _DOMFilterFactory_getRGB).bind(this)), newFgRGB = _j[0], newBgRGB = _j[1];
  1247. if (bgGray < fgGray) {
  1248. _f = [bgGray, fgGray, newBgRGB, newFgRGB], fgGray = _f[0], bgGray = _f[1], newFgRGB = _f[2], newBgRGB = _f[3];
  1249. }
  1250. tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "a", _DOMFilterFactory_defs_get).style.color = "";
  1251. var getSteps = function (fg, bg, n) {
  1252. var arr = new Array(256);
  1253. var step = (bgGray - fgGray) / n;
  1254. var newStart = fg / 255;
  1255. var newStep = (bg - fg) / (255 * n);
  1256. var prev = 0;
  1257. for (var i = 0; i <= n; i++) {
  1258. var k = Math.round(fgGray + i * step);
  1259. var value = newStart + i * newStep;
  1260. for (var j = prev; j <= k; j++) {
  1261. arr[j] = value;
  1262. }
  1263. prev = k + 1;
  1264. }
  1265. for (var i = prev; i < 256; i++) {
  1266. arr[i] = arr[prev - 1];
  1267. }
  1268. return arr.join(",");
  1269. };
  1270. var id = "g_".concat(tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_docId, "f"), "_hcm_").concat(filterName, "_filter");
  1271. var filter = info.filter = tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "m", _DOMFilterFactory_createFilter).call(this, id);
  1272. tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "m", _DOMFilterFactory_addGrayConversion).call(this, filter);
  1273. tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "m", _DOMFilterFactory_addTransferMapConversion).call(this, getSteps(newFgRGB[0], newBgRGB[0], 5), getSteps(newFgRGB[1], newBgRGB[1], 5), getSteps(newFgRGB[2], newBgRGB[2], 5), filter);
  1274. info.url = "url(#".concat(id, ")");
  1275. return info.url;
  1276. };
  1277. DOMFilterFactory.prototype.destroy = function (keepHCM) {
  1278. if (keepHCM === void 0) { keepHCM = false; }
  1279. if (keepHCM && tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "a", _DOMFilterFactory_hcmCache_get).size !== 0) {
  1280. return;
  1281. }
  1282. if (tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory__defs, "f")) {
  1283. tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory__defs, "f").parentNode.parentNode.remove();
  1284. tslib_1.__classPrivateFieldSet(this, _DOMFilterFactory__defs, null, "f");
  1285. }
  1286. if (tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory__cache, "f")) {
  1287. tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory__cache, "f").clear();
  1288. tslib_1.__classPrivateFieldSet(this, _DOMFilterFactory__cache, null, "f");
  1289. }
  1290. tslib_1.__classPrivateFieldSet(this, _DOMFilterFactory_id, 0, "f");
  1291. };
  1292. return DOMFilterFactory;
  1293. }(BaseFilterFactory));
  1294. _DOMFilterFactory__cache = new WeakMap(), _DOMFilterFactory__defs = new WeakMap(), _DOMFilterFactory_docId = new WeakMap(), _DOMFilterFactory_document = new WeakMap(), _DOMFilterFactory__hcmCache = new WeakMap(), _DOMFilterFactory_id = new WeakMap(), _DOMFilterFactory_instances = new WeakSet(), _DOMFilterFactory_cache_get = function _DOMFilterFactory_cache_get() {
  1295. return tslib_1.__classPrivateFieldSet(this, _DOMFilterFactory__cache, tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory__cache, "f") || new Map(), "f");
  1296. }, _DOMFilterFactory_hcmCache_get = function _DOMFilterFactory_hcmCache_get() {
  1297. return tslib_1.__classPrivateFieldSet(this, _DOMFilterFactory__hcmCache, tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory__hcmCache, "f") || new Map(), "f");
  1298. }, _DOMFilterFactory_defs_get = function _DOMFilterFactory_defs_get() {
  1299. if (!tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory__defs, "f")) {
  1300. var div = tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_document, "f").createElement("div");
  1301. var style = div.style;
  1302. style.visibility = "hidden";
  1303. style.contain = "strict";
  1304. style.width = style.height = 0;
  1305. style.position = "absolute";
  1306. style.top = style.left = 0;
  1307. style.zIndex = -1;
  1308. var svg = tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_document, "f").createElementNS(SVG_NS, "svg");
  1309. svg.setAttribute("width", 0);
  1310. svg.setAttribute("height", 0);
  1311. tslib_1.__classPrivateFieldSet(this, _DOMFilterFactory__defs, tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_document, "f").createElementNS(SVG_NS, "defs"), "f");
  1312. div.append(svg);
  1313. svg.append(tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory__defs, "f"));
  1314. tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_document, "f").body.append(div);
  1315. }
  1316. return tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory__defs, "f");
  1317. }, _DOMFilterFactory_createTables = function _DOMFilterFactory_createTables(maps) {
  1318. if (maps.length === 1) {
  1319. var mapR_1 = maps[0];
  1320. var buffer = new Array(256);
  1321. for (var i = 0; i < 256; i++) {
  1322. buffer[i] = mapR_1[i] / 255;
  1323. }
  1324. var table = buffer.join(",");
  1325. return [table, table, table];
  1326. }
  1327. var mapR = maps[0], mapG = maps[1], mapB = maps[2];
  1328. var bufferR = new Array(256);
  1329. var bufferG = new Array(256);
  1330. var bufferB = new Array(256);
  1331. for (var i = 0; i < 256; i++) {
  1332. bufferR[i] = mapR[i] / 255;
  1333. bufferG[i] = mapG[i] / 255;
  1334. bufferB[i] = mapB[i] / 255;
  1335. }
  1336. return [bufferR.join(","), bufferG.join(","), bufferB.join(",")];
  1337. }, _DOMFilterFactory_addLuminosityConversion = function _DOMFilterFactory_addLuminosityConversion(filter) {
  1338. var feColorMatrix = tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_document, "f").createElementNS(SVG_NS, "feColorMatrix");
  1339. feColorMatrix.setAttribute("type", "matrix");
  1340. feColorMatrix.setAttribute("values", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3 0.59 0.11 0 0");
  1341. filter.append(feColorMatrix);
  1342. }, _DOMFilterFactory_addGrayConversion = function _DOMFilterFactory_addGrayConversion(filter) {
  1343. var feColorMatrix = tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_document, "f").createElementNS(SVG_NS, "feColorMatrix");
  1344. feColorMatrix.setAttribute("type", "matrix");
  1345. 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");
  1346. filter.append(feColorMatrix);
  1347. }, _DOMFilterFactory_createFilter = function _DOMFilterFactory_createFilter(id) {
  1348. var filter = tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_document, "f").createElementNS(SVG_NS, "filter");
  1349. filter.setAttribute("color-interpolation-filters", "sRGB");
  1350. filter.setAttribute("id", id);
  1351. tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "a", _DOMFilterFactory_defs_get).append(filter);
  1352. return filter;
  1353. }, _DOMFilterFactory_appendFeFunc = function _DOMFilterFactory_appendFeFunc(feComponentTransfer, func, table) {
  1354. var feFunc = tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_document, "f").createElementNS(SVG_NS, func);
  1355. feFunc.setAttribute("type", "discrete");
  1356. feFunc.setAttribute("tableValues", table);
  1357. feComponentTransfer.append(feFunc);
  1358. }, _DOMFilterFactory_addTransferMapConversion = function _DOMFilterFactory_addTransferMapConversion(rTable, gTable, bTable, filter) {
  1359. var feComponentTransfer = tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_document, "f").createElementNS(SVG_NS, "feComponentTransfer");
  1360. filter.append(feComponentTransfer);
  1361. tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "m", _DOMFilterFactory_appendFeFunc).call(this, feComponentTransfer, "feFuncR", rTable);
  1362. tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "m", _DOMFilterFactory_appendFeFunc).call(this, feComponentTransfer, "feFuncG", gTable);
  1363. tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "m", _DOMFilterFactory_appendFeFunc).call(this, feComponentTransfer, "feFuncB", bTable);
  1364. }, _DOMFilterFactory_addTransferMapAlphaConversion = function _DOMFilterFactory_addTransferMapAlphaConversion(aTable, filter) {
  1365. var feComponentTransfer = tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_document, "f").createElementNS(SVG_NS, "feComponentTransfer");
  1366. filter.append(feComponentTransfer);
  1367. tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "m", _DOMFilterFactory_appendFeFunc).call(this, feComponentTransfer, "feFuncA", aTable);
  1368. }, _DOMFilterFactory_getRGB = function _DOMFilterFactory_getRGB(color) {
  1369. tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "a", _DOMFilterFactory_defs_get).style.color = color;
  1370. return getRGB(getComputedStyle(tslib_1.__classPrivateFieldGet(this, _DOMFilterFactory_instances, "a", _DOMFilterFactory_defs_get)).getPropertyValue("color"));
  1371. };
  1372. var DOMCanvasFactory = /** @class */ (function (_super) {
  1373. tslib_1.__extends(DOMCanvasFactory, _super);
  1374. function DOMCanvasFactory(_f) {
  1375. var _g = _f === void 0 ? {} : _f, _h = _g.ownerDocument, ownerDocument = _h === void 0 ? globalThis.document : _h;
  1376. var _this = _super.call(this) || this;
  1377. _this._document = ownerDocument;
  1378. return _this;
  1379. }
  1380. DOMCanvasFactory.prototype._createCanvas = function (width, height) {
  1381. var canvas = this._document.createElement("canvas");
  1382. canvas.width = width;
  1383. canvas.height = height;
  1384. return canvas;
  1385. };
  1386. return DOMCanvasFactory;
  1387. }(BaseCanvasFactory));
  1388. function fetchData(url, type) {
  1389. if (type === void 0) { type = "text"; }
  1390. return tslib_1.__awaiter(this, void 0, void 0, function () {
  1391. var response;
  1392. return tslib_1.__generator(this, function (_f) {
  1393. switch (_f.label) {
  1394. case 0:
  1395. if (!isValidFetchUrl(url, document.baseURI)) return [3 /*break*/, 2];
  1396. return [4 /*yield*/, fetch(url)];
  1397. case 1:
  1398. response = _f.sent();
  1399. if (!response.ok) {
  1400. throw new Error(response.statusText);
  1401. }
  1402. switch (type) {
  1403. case "arraybuffer":
  1404. return [2 /*return*/, response.arrayBuffer()];
  1405. case "blob":
  1406. return [2 /*return*/, response.blob()];
  1407. case "json":
  1408. return [2 /*return*/, response.json()];
  1409. }
  1410. return [2 /*return*/, response.text()];
  1411. case 2: return [2 /*return*/, new Promise(function (resolve, reject) {
  1412. var request = new XMLHttpRequest();
  1413. request.open("GET", url, true);
  1414. request.responseType = type;
  1415. request.onreadystatechange = function () {
  1416. if (request.readyState !== XMLHttpRequest.DONE) {
  1417. return;
  1418. }
  1419. if (request.status === 200 || request.status === 0) {
  1420. switch (type) {
  1421. case "arraybuffer":
  1422. case "blob":
  1423. case "json":
  1424. resolve(request.response);
  1425. return;
  1426. }
  1427. resolve(request.responseText);
  1428. return;
  1429. }
  1430. reject(new Error(request.statusText));
  1431. };
  1432. request.send(null);
  1433. })];
  1434. }
  1435. });
  1436. });
  1437. }
  1438. var DOMCMapReaderFactory = /** @class */ (function (_super) {
  1439. tslib_1.__extends(DOMCMapReaderFactory, _super);
  1440. function DOMCMapReaderFactory() {
  1441. return _super !== null && _super.apply(this, arguments) || this;
  1442. }
  1443. DOMCMapReaderFactory.prototype._fetchData = function (url, compressionType) {
  1444. return fetchData(url, this.isCompressed ? "arraybuffer" : "text").then(function (data) { return ({
  1445. cMapData: data instanceof ArrayBuffer ? new Uint8Array(data) : stringToBytes(data),
  1446. compressionType: compressionType
  1447. }); });
  1448. };
  1449. return DOMCMapReaderFactory;
  1450. }(BaseCMapReaderFactory));
  1451. var DOMStandardFontDataFactory = /** @class */ (function (_super) {
  1452. tslib_1.__extends(DOMStandardFontDataFactory, _super);
  1453. function DOMStandardFontDataFactory() {
  1454. return _super !== null && _super.apply(this, arguments) || this;
  1455. }
  1456. DOMStandardFontDataFactory.prototype._fetchData = function (url) {
  1457. return fetchData(url, "arraybuffer").then(function (data) { return new Uint8Array(data); });
  1458. };
  1459. return DOMStandardFontDataFactory;
  1460. }(BaseStandardFontDataFactory));
  1461. var DOMSVGFactory = /** @class */ (function (_super) {
  1462. tslib_1.__extends(DOMSVGFactory, _super);
  1463. function DOMSVGFactory() {
  1464. return _super !== null && _super.apply(this, arguments) || this;
  1465. }
  1466. DOMSVGFactory.prototype._createSVG = function (type) {
  1467. return document.createElementNS(SVG_NS, type);
  1468. };
  1469. return DOMSVGFactory;
  1470. }(BaseSVGFactory));
  1471. var PageViewport = /** @class */ (function () {
  1472. function PageViewport(_f) {
  1473. var viewBox = _f.viewBox, scale = _f.scale, rotation = _f.rotation, _g = _f.offsetX, offsetX = _g === void 0 ? 0 : _g, _h = _f.offsetY, offsetY = _h === void 0 ? 0 : _h, _j = _f.dontFlip, dontFlip = _j === void 0 ? false : _j;
  1474. this.viewBox = viewBox;
  1475. this.scale = scale;
  1476. this.rotation = rotation;
  1477. this.offsetX = offsetX;
  1478. this.offsetY = offsetY;
  1479. var centerX = (viewBox[2] + viewBox[0]) / 2;
  1480. var centerY = (viewBox[3] + viewBox[1]) / 2;
  1481. var rotateA, rotateB, rotateC, rotateD;
  1482. rotation %= 360;
  1483. if (rotation < 0) {
  1484. rotation += 360;
  1485. }
  1486. switch (rotation) {
  1487. case 180:
  1488. rotateA = -1;
  1489. rotateB = 0;
  1490. rotateC = 0;
  1491. rotateD = 1;
  1492. break;
  1493. case 90:
  1494. rotateA = 0;
  1495. rotateB = 1;
  1496. rotateC = 1;
  1497. rotateD = 0;
  1498. break;
  1499. case 270:
  1500. rotateA = 0;
  1501. rotateB = -1;
  1502. rotateC = -1;
  1503. rotateD = 0;
  1504. break;
  1505. case 0:
  1506. rotateA = 1;
  1507. rotateB = 0;
  1508. rotateC = 0;
  1509. rotateD = -1;
  1510. break;
  1511. default:
  1512. throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.");
  1513. }
  1514. if (dontFlip) {
  1515. rotateC = -rotateC;
  1516. rotateD = -rotateD;
  1517. }
  1518. var offsetCanvasX, offsetCanvasY;
  1519. var width, height;
  1520. if (rotateA === 0) {
  1521. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  1522. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  1523. width = (viewBox[3] - viewBox[1]) * scale;
  1524. height = (viewBox[2] - viewBox[0]) * scale;
  1525. }
  1526. else {
  1527. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  1528. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  1529. width = (viewBox[2] - viewBox[0]) * scale;
  1530. height = (viewBox[3] - viewBox[1]) * scale;
  1531. }
  1532. this.transform = [rotateA * scale, rotateB * scale, rotateC * scale, rotateD * scale, offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY, offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY];
  1533. this.width = width;
  1534. this.height = height;
  1535. }
  1536. Object.defineProperty(PageViewport.prototype, "rawDims", {
  1537. get: function () {
  1538. var viewBox = this.viewBox;
  1539. return shadow(this, "rawDims", {
  1540. pageWidth: viewBox[2] - viewBox[0],
  1541. pageHeight: viewBox[3] - viewBox[1],
  1542. pageX: viewBox[0],
  1543. pageY: viewBox[1]
  1544. });
  1545. },
  1546. enumerable: false,
  1547. configurable: true
  1548. });
  1549. PageViewport.prototype.clone = function (_f) {
  1550. var _g = _f === void 0 ? {} : _f, _h = _g.scale, scale = _h === void 0 ? this.scale : _h, _j = _g.rotation, rotation = _j === void 0 ? this.rotation : _j, _k = _g.offsetX, offsetX = _k === void 0 ? this.offsetX : _k, _l = _g.offsetY, offsetY = _l === void 0 ? this.offsetY : _l, _m = _g.dontFlip, dontFlip = _m === void 0 ? false : _m;
  1551. return new PageViewport({
  1552. viewBox: this.viewBox.slice(),
  1553. scale: scale,
  1554. rotation: rotation,
  1555. offsetX: offsetX,
  1556. offsetY: offsetY,
  1557. dontFlip: dontFlip
  1558. });
  1559. };
  1560. PageViewport.prototype.convertToViewportPoint = function (x, y) {
  1561. return Util.applyTransform([x, y], this.transform);
  1562. };
  1563. PageViewport.prototype.convertToViewportRectangle = function (rect) {
  1564. var topLeft = Util.applyTransform([rect[0], rect[1]], this.transform);
  1565. var bottomRight = Util.applyTransform([rect[2], rect[3]], this.transform);
  1566. return [topLeft[0], topLeft[1], bottomRight[0], bottomRight[1]];
  1567. };
  1568. PageViewport.prototype.convertToPdfPoint = function (x, y) {
  1569. return Util.applyInverseTransform([x, y], this.transform);
  1570. };
  1571. return PageViewport;
  1572. }());
  1573. var RenderingCancelledException = /** @class */ (function (_super) {
  1574. tslib_1.__extends(RenderingCancelledException, _super);
  1575. function RenderingCancelledException(msg, extraDelay) {
  1576. if (extraDelay === void 0) { extraDelay = 0; }
  1577. var _this = _super.call(this, msg, "RenderingCancelledException") || this;
  1578. _this.extraDelay = extraDelay;
  1579. return _this;
  1580. }
  1581. return RenderingCancelledException;
  1582. }(BaseException));
  1583. function isDataScheme(url) {
  1584. var ii = url.length;
  1585. var i = 0;
  1586. while (i < ii && url[i].trim() === "") {
  1587. i++;
  1588. }
  1589. return url.substring(i, i + 5).toLowerCase() === "data:";
  1590. }
  1591. function isPdfFile(filename) {
  1592. return typeof filename === "string" && /\.pdf$/i.test(filename);
  1593. }
  1594. function getFilenameFromUrl(url) {
  1595. url = url.split(/[#?]/, 1)[0];
  1596. return url.substring(url.lastIndexOf("/") + 1);
  1597. }
  1598. function getPdfFilenameFromUrl(url, defaultFilename) {
  1599. if (defaultFilename === void 0) { defaultFilename = "document.pdf"; }
  1600. if (typeof url !== "string") {
  1601. return defaultFilename;
  1602. }
  1603. if (isDataScheme(url)) {
  1604. warn('getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.');
  1605. return defaultFilename;
  1606. }
  1607. var reURI = /^(?:(?:[^:]+:)?\/\/[^/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
  1608. var reFilename = /[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
  1609. var splitURI = reURI.exec(url);
  1610. var suggestedFilename = reFilename.exec(splitURI[1]) || reFilename.exec(splitURI[2]) || reFilename.exec(splitURI[3]);
  1611. if (suggestedFilename) {
  1612. suggestedFilename = suggestedFilename[0];
  1613. if (suggestedFilename.includes("%")) {
  1614. try {
  1615. suggestedFilename = reFilename.exec(decodeURIComponent(suggestedFilename))[0];
  1616. }
  1617. catch (_f) { }
  1618. }
  1619. }
  1620. return suggestedFilename || defaultFilename;
  1621. }
  1622. var StatTimer = /** @class */ (function () {
  1623. function StatTimer() {
  1624. this.started = Object.create(null);
  1625. this.times = [];
  1626. }
  1627. StatTimer.prototype.time = function (name) {
  1628. if (name in this.started) {
  1629. warn("Timer is already running for ".concat(name));
  1630. }
  1631. this.started[name] = Date.now();
  1632. };
  1633. StatTimer.prototype.timeEnd = function (name) {
  1634. if (!(name in this.started)) {
  1635. warn("Timer has not been started for ".concat(name));
  1636. }
  1637. this.times.push({
  1638. name: name,
  1639. start: this.started[name],
  1640. end: Date.now()
  1641. });
  1642. delete this.started[name];
  1643. };
  1644. StatTimer.prototype.toString = function () {
  1645. var outBuf = [];
  1646. var longest = 0;
  1647. for (var _i = 0, _f = this.times; _i < _f.length; _i++) {
  1648. var name = _f[_i].name;
  1649. longest = Math.max(name.length, longest);
  1650. }
  1651. for (var _g = 0, _h = this.times; _g < _h.length; _g++) {
  1652. var _j = _h[_g], name = _j.name, start = _j.start, end = _j.end;
  1653. outBuf.push("".concat(name.padEnd(longest), " ").concat(end - start, "ms\n"));
  1654. }
  1655. return outBuf.join("");
  1656. };
  1657. return StatTimer;
  1658. }());
  1659. function isValidFetchUrl(url, baseUrl) {
  1660. try {
  1661. var protocol = (baseUrl ? new URL(url, baseUrl) : new URL(url)).protocol;
  1662. return protocol === "http:" || protocol === "https:";
  1663. }
  1664. catch (_f) {
  1665. return false;
  1666. }
  1667. }
  1668. function noContextMenu(e) {
  1669. e.preventDefault();
  1670. }
  1671. function deprecated(details) {
  1672. console.log("Deprecated API usage: " + details);
  1673. }
  1674. var pdfDateStringRegex;
  1675. var PDFDateString = /** @class */ (function () {
  1676. function PDFDateString() {
  1677. }
  1678. PDFDateString.toDateObject = function (input) {
  1679. if (!input || typeof input !== "string") {
  1680. return null;
  1681. }
  1682. pdfDateStringRegex || (pdfDateStringRegex = new RegExp("^D:" + "(\\d{4})" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "([Z|+|-])?" + "(\\d{2})?" + "'?" + "(\\d{2})?" + "'?"));
  1683. var matches = pdfDateStringRegex.exec(input);
  1684. if (!matches) {
  1685. return null;
  1686. }
  1687. var year = parseInt(matches[1], 10);
  1688. var month = parseInt(matches[2], 10);
  1689. month = month >= 1 && month <= 12 ? month - 1 : 0;
  1690. var day = parseInt(matches[3], 10);
  1691. day = day >= 1 && day <= 31 ? day : 1;
  1692. var hour = parseInt(matches[4], 10);
  1693. hour = hour >= 0 && hour <= 23 ? hour : 0;
  1694. var minute = parseInt(matches[5], 10);
  1695. minute = minute >= 0 && minute <= 59 ? minute : 0;
  1696. var second = parseInt(matches[6], 10);
  1697. second = second >= 0 && second <= 59 ? second : 0;
  1698. var universalTimeRelation = matches[7] || "Z";
  1699. var offsetHour = parseInt(matches[8], 10);
  1700. offsetHour = offsetHour >= 0 && offsetHour <= 23 ? offsetHour : 0;
  1701. var offsetMinute = parseInt(matches[9], 10) || 0;
  1702. offsetMinute = offsetMinute >= 0 && offsetMinute <= 59 ? offsetMinute : 0;
  1703. if (universalTimeRelation === "-") {
  1704. hour += offsetHour;
  1705. minute += offsetMinute;
  1706. }
  1707. else if (universalTimeRelation === "+") {
  1708. hour -= offsetHour;
  1709. minute -= offsetMinute;
  1710. }
  1711. return new Date(Date.UTC(year, month, day, hour, minute, second));
  1712. };
  1713. return PDFDateString;
  1714. }());
  1715. function getXfaPageViewport(xfaPage, _f) {
  1716. var _g = _f.scale, scale = _g === void 0 ? 1 : _g, _h = _f.rotation, rotation = _h === void 0 ? 0 : _h;
  1717. var _j = xfaPage.attributes.style, width = _j.width, height = _j.height;
  1718. var viewBox = [0, 0, parseInt(width), parseInt(height)];
  1719. return new PageViewport({
  1720. viewBox: viewBox,
  1721. scale: scale,
  1722. rotation: rotation
  1723. });
  1724. }
  1725. function getRGB(color) {
  1726. if (color.startsWith("#")) {
  1727. var colorRGB = parseInt(color.slice(1), 16);
  1728. return [(colorRGB & 0xff0000) >> 16, (colorRGB & 0x00ff00) >> 8, colorRGB & 0x0000ff];
  1729. }
  1730. if (color.startsWith("rgb(")) {
  1731. return color.slice(4, -1).split(",").map(function (x) { return parseInt(x); });
  1732. }
  1733. if (color.startsWith("rgba(")) {
  1734. return color.slice(5, -1).split(",").map(function (x) { return parseInt(x); }).slice(0, 3);
  1735. }
  1736. warn("Not a valid color format: \"".concat(color, "\""));
  1737. return [0, 0, 0];
  1738. }
  1739. function getColorValues(colors) {
  1740. var span = document.createElement("span");
  1741. span.style.visibility = "hidden";
  1742. document.body.append(span);
  1743. for (var _i = 0, _f = colors.keys(); _i < _f.length; _i++) {
  1744. var name = _f[_i];
  1745. span.style.color = name;
  1746. var computedColor = window.getComputedStyle(span).color;
  1747. colors.set(name, getRGB(computedColor));
  1748. }
  1749. span.remove();
  1750. }
  1751. function getCurrentTransform(ctx) {
  1752. var _f = ctx.getTransform(), a = _f.a, b = _f.b, c = _f.c, d = _f.d, e = _f.e, f = _f.f;
  1753. return [a, b, c, d, e, f];
  1754. }
  1755. function getCurrentTransformInverse(ctx) {
  1756. var _f = ctx.getTransform().invertSelf(), a = _f.a, b = _f.b, c = _f.c, d = _f.d, e = _f.e, f = _f.f;
  1757. return [a, b, c, d, e, f];
  1758. }
  1759. function setLayerDimensions(div, viewport, mustFlip, mustRotate) {
  1760. if (mustFlip === void 0) { mustFlip = false; }
  1761. if (mustRotate === void 0) { mustRotate = true; }
  1762. if (viewport instanceof PageViewport) {
  1763. var _f = viewport.rawDims, pageWidth = _f.pageWidth, pageHeight = _f.pageHeight;
  1764. var style = div.style;
  1765. var useRound = util_FeatureTest.isCSSRoundSupported;
  1766. var w = "var(--scale-factor) * ".concat(pageWidth, "px"), h = "var(--scale-factor) * ".concat(pageHeight, "px");
  1767. var widthStr = useRound ? "round(".concat(w, ", 1px)") : "calc(".concat(w, ")"), heightStr = useRound ? "round(".concat(h, ", 1px)") : "calc(".concat(h, ")");
  1768. if (!mustFlip || viewport.rotation % 180 === 0) {
  1769. style.width = widthStr;
  1770. style.height = heightStr;
  1771. }
  1772. else {
  1773. style.width = heightStr;
  1774. style.height = widthStr;
  1775. }
  1776. }
  1777. if (mustRotate) {
  1778. div.setAttribute("data-main-rotation", viewport.rotation);
  1779. }
  1780. }
  1781. ; // CONCATENATED MODULE: ./src/display/editor/toolbar.js
  1782. var EditorToolbar = /** @class */ (function () {
  1783. function EditorToolbar(editor) {
  1784. _EditorToolbar_instances.add(this);
  1785. _EditorToolbar_toolbar.set(this, null);
  1786. _EditorToolbar_colorPicker.set(this, null);
  1787. _EditorToolbar_editor.set(this, void 0);
  1788. _EditorToolbar_buttons.set(this, null);
  1789. tslib_1.__classPrivateFieldSet(this, _EditorToolbar_editor, editor, "f");
  1790. }
  1791. EditorToolbar.prototype.render = function () {
  1792. var editToolbar = tslib_1.__classPrivateFieldSet(this, _EditorToolbar_toolbar, document.createElement("div"), "f");
  1793. editToolbar.className = "editToolbar";
  1794. editToolbar.setAttribute("role", "toolbar");
  1795. editToolbar.addEventListener("contextmenu", noContextMenu);
  1796. editToolbar.addEventListener("pointerdown", tslib_1.__classPrivateFieldGet(EditorToolbar, _b, "m", _EditorToolbar_pointerDown));
  1797. var buttons = tslib_1.__classPrivateFieldSet(this, _EditorToolbar_buttons, document.createElement("div"), "f");
  1798. buttons.className = "buttons";
  1799. editToolbar.append(buttons);
  1800. var position = tslib_1.__classPrivateFieldGet(this, _EditorToolbar_editor, "f").toolbarPosition;
  1801. if (position) {
  1802. var style = editToolbar.style;
  1803. var x = tslib_1.__classPrivateFieldGet(this, _EditorToolbar_editor, "f")._uiManager.direction === "ltr" ? 1 - position[0] : position[0];
  1804. style.insetInlineEnd = "".concat(100 * x, "%");
  1805. style.top = "calc(".concat(100 * position[1], "% + var(--editor-toolbar-vert-offset))");
  1806. }
  1807. tslib_1.__classPrivateFieldGet(this, _EditorToolbar_instances, "m", _EditorToolbar_addDeleteButton).call(this);
  1808. return editToolbar;
  1809. };
  1810. EditorToolbar.prototype.hide = function () {
  1811. var _f;
  1812. tslib_1.__classPrivateFieldGet(this, _EditorToolbar_toolbar, "f").classList.add("hidden");
  1813. (_f = tslib_1.__classPrivateFieldGet(this, _EditorToolbar_colorPicker, "f")) === null || _f === void 0 ? void 0 : _f.hideDropdown();
  1814. };
  1815. EditorToolbar.prototype.show = function () {
  1816. tslib_1.__classPrivateFieldGet(this, _EditorToolbar_toolbar, "f").classList.remove("hidden");
  1817. };
  1818. EditorToolbar.prototype.addAltTextButton = function (button) {
  1819. tslib_1.__classPrivateFieldGet(this, _EditorToolbar_instances, "m", _EditorToolbar_addListenersToElement).call(this, button);
  1820. tslib_1.__classPrivateFieldGet(this, _EditorToolbar_buttons, "f").prepend(button, tslib_1.__classPrivateFieldGet(this, _EditorToolbar_instances, "a", _EditorToolbar_divider_get));
  1821. };
  1822. EditorToolbar.prototype.addColorPicker = function (colorPicker) {
  1823. tslib_1.__classPrivateFieldSet(this, _EditorToolbar_colorPicker, colorPicker, "f");
  1824. var button = colorPicker.renderButton();
  1825. tslib_1.__classPrivateFieldGet(this, _EditorToolbar_instances, "m", _EditorToolbar_addListenersToElement).call(this, button);
  1826. tslib_1.__classPrivateFieldGet(this, _EditorToolbar_buttons, "f").prepend(button, tslib_1.__classPrivateFieldGet(this, _EditorToolbar_instances, "a", _EditorToolbar_divider_get));
  1827. };
  1828. EditorToolbar.prototype.remove = function () {
  1829. var _f;
  1830. tslib_1.__classPrivateFieldGet(this, _EditorToolbar_toolbar, "f").remove();
  1831. (_f = tslib_1.__classPrivateFieldGet(this, _EditorToolbar_colorPicker, "f")) === null || _f === void 0 ? void 0 : _f.destroy();
  1832. tslib_1.__classPrivateFieldSet(this, _EditorToolbar_colorPicker, null, "f");
  1833. };
  1834. return EditorToolbar;
  1835. }());
  1836. _b = EditorToolbar, _EditorToolbar_toolbar = new WeakMap(), _EditorToolbar_colorPicker = new WeakMap(), _EditorToolbar_editor = new WeakMap(), _EditorToolbar_buttons = new WeakMap(), _EditorToolbar_instances = new WeakSet(), _EditorToolbar_pointerDown = function _EditorToolbar_pointerDown(e) {
  1837. e.stopPropagation();
  1838. }, _EditorToolbar_focusIn = function _EditorToolbar_focusIn(e) {
  1839. tslib_1.__classPrivateFieldGet(this, _EditorToolbar_editor, "f")._focusEventsAllowed = false;
  1840. e.preventDefault();
  1841. e.stopPropagation();
  1842. }, _EditorToolbar_focusOut = function _EditorToolbar_focusOut(e) {
  1843. tslib_1.__classPrivateFieldGet(this, _EditorToolbar_editor, "f")._focusEventsAllowed = true;
  1844. e.preventDefault();
  1845. e.stopPropagation();
  1846. }, _EditorToolbar_addListenersToElement = function _EditorToolbar_addListenersToElement(element) {
  1847. element.addEventListener("focusin", tslib_1.__classPrivateFieldGet(this, _EditorToolbar_instances, "m", _EditorToolbar_focusIn).bind(this), {
  1848. capture: true
  1849. });
  1850. element.addEventListener("focusout", tslib_1.__classPrivateFieldGet(this, _EditorToolbar_instances, "m", _EditorToolbar_focusOut).bind(this), {
  1851. capture: true
  1852. });
  1853. element.addEventListener("contextmenu", noContextMenu);
  1854. }, _EditorToolbar_addDeleteButton = function _EditorToolbar_addDeleteButton() {
  1855. var _this = this;
  1856. var button = document.createElement("button");
  1857. button.className = "delete";
  1858. button.tabIndex = 0;
  1859. button.setAttribute("data-l10n-id", "pdfjs-editor-remove-".concat(tslib_1.__classPrivateFieldGet(this, _EditorToolbar_editor, "f").editorType, "-button"));
  1860. tslib_1.__classPrivateFieldGet(this, _EditorToolbar_instances, "m", _EditorToolbar_addListenersToElement).call(this, button);
  1861. button.addEventListener("click", function (e) {
  1862. tslib_1.__classPrivateFieldGet(_this, _EditorToolbar_editor, "f")._uiManager.delete();
  1863. });
  1864. tslib_1.__classPrivateFieldGet(this, _EditorToolbar_buttons, "f").append(button);
  1865. }, _EditorToolbar_divider_get = function _EditorToolbar_divider_get() {
  1866. var divider = document.createElement("div");
  1867. divider.className = "divider";
  1868. return divider;
  1869. };
  1870. var HighlightToolbar = /** @class */ (function () {
  1871. function HighlightToolbar(uiManager) {
  1872. _HighlightToolbar_instances.add(this);
  1873. _HighlightToolbar_buttons.set(this, null);
  1874. _HighlightToolbar_toolbar.set(this, null);
  1875. _HighlightToolbar_uiManager.set(this, void 0);
  1876. tslib_1.__classPrivateFieldSet(this, _HighlightToolbar_uiManager, uiManager, "f");
  1877. }
  1878. HighlightToolbar.prototype.show = function (parent, boxes, isLTR) {
  1879. var _f = tslib_1.__classPrivateFieldGet(this, _HighlightToolbar_instances, "m", _HighlightToolbar_getLastPoint).call(this, boxes, isLTR), x = _f[0], y = _f[1];
  1880. var style = tslib_1.__classPrivateFieldSet(this, _HighlightToolbar_toolbar, tslib_1.__classPrivateFieldGet(this, _HighlightToolbar_toolbar, "f") || tslib_1.__classPrivateFieldGet(this, _HighlightToolbar_instances, "m", _HighlightToolbar_render).call(this), "f").style;
  1881. parent.append(tslib_1.__classPrivateFieldGet(this, _HighlightToolbar_toolbar, "f"));
  1882. style.insetInlineEnd = "".concat(100 * x, "%");
  1883. style.top = "calc(".concat(100 * y, "% + var(--editor-toolbar-vert-offset))");
  1884. };
  1885. HighlightToolbar.prototype.hide = function () {
  1886. tslib_1.__classPrivateFieldGet(this, _HighlightToolbar_toolbar, "f").remove();
  1887. };
  1888. return HighlightToolbar;
  1889. }());
  1890. _HighlightToolbar_buttons = new WeakMap(), _HighlightToolbar_toolbar = new WeakMap(), _HighlightToolbar_uiManager = new WeakMap(), _HighlightToolbar_instances = new WeakSet(), _HighlightToolbar_render = function _HighlightToolbar_render() {
  1891. var editToolbar = tslib_1.__classPrivateFieldSet(this, _HighlightToolbar_toolbar, document.createElement("div"), "f");
  1892. editToolbar.className = "editToolbar";
  1893. editToolbar.setAttribute("role", "toolbar");
  1894. editToolbar.addEventListener("contextmenu", noContextMenu);
  1895. var buttons = tslib_1.__classPrivateFieldSet(this, _HighlightToolbar_buttons, document.createElement("div"), "f");
  1896. buttons.className = "buttons";
  1897. editToolbar.append(buttons);
  1898. tslib_1.__classPrivateFieldGet(this, _HighlightToolbar_instances, "m", _HighlightToolbar_addHighlightButton).call(this);
  1899. return editToolbar;
  1900. }, _HighlightToolbar_getLastPoint = function _HighlightToolbar_getLastPoint(boxes, isLTR) {
  1901. var lastY = 0;
  1902. var lastX = 0;
  1903. for (var _i = 0, boxes_1 = boxes; _i < boxes_1.length; _i++) {
  1904. var box = boxes_1[_i];
  1905. var y = box.y + box.height;
  1906. if (y < lastY) {
  1907. continue;
  1908. }
  1909. var x = box.x + (isLTR ? box.width : 0);
  1910. if (y > lastY) {
  1911. lastX = x;
  1912. lastY = y;
  1913. continue;
  1914. }
  1915. if (isLTR) {
  1916. if (x > lastX) {
  1917. lastX = x;
  1918. }
  1919. }
  1920. else if (x < lastX) {
  1921. lastX = x;
  1922. }
  1923. }
  1924. return [isLTR ? 1 - lastX : lastX, lastY];
  1925. }, _HighlightToolbar_addHighlightButton = function _HighlightToolbar_addHighlightButton() {
  1926. var _this = this;
  1927. var button = document.createElement("button");
  1928. button.className = "highlightButton";
  1929. button.tabIndex = 0;
  1930. button.setAttribute("data-l10n-id", "pdfjs-highlight-floating-button1");
  1931. var span = document.createElement("span");
  1932. button.append(span);
  1933. span.className = "visuallyHidden";
  1934. span.setAttribute("data-l10n-id", "pdfjs-highlight-floating-button-label");
  1935. button.addEventListener("contextmenu", noContextMenu);
  1936. button.addEventListener("click", function () {
  1937. tslib_1.__classPrivateFieldGet(_this, _HighlightToolbar_uiManager, "f").highlightSelection("floating_button");
  1938. });
  1939. tslib_1.__classPrivateFieldGet(this, _HighlightToolbar_buttons, "f").append(button);
  1940. };
  1941. ; // CONCATENATED MODULE: ./src/display/editor/tools.js
  1942. function bindEvents(obj, element, names) {
  1943. for (var _i = 0, names_1 = names; _i < names_1.length; _i++) {
  1944. var name = names_1[_i];
  1945. element.addEventListener(name, obj[name].bind(obj));
  1946. }
  1947. }
  1948. function opacityToHex(opacity) {
  1949. return Math.round(Math.min(255, Math.max(1, 255 * opacity))).toString(16).padStart(2, "0");
  1950. }
  1951. var IdManager = /** @class */ (function () {
  1952. function IdManager() {
  1953. _IdManager_id.set(this, 0);
  1954. }
  1955. Object.defineProperty(IdManager.prototype, "id", {
  1956. get: function () {
  1957. var _f, _g;
  1958. return "".concat(AnnotationEditorPrefix).concat((tslib_1.__classPrivateFieldSet(this, _IdManager_id, (_g = tslib_1.__classPrivateFieldGet(this, _IdManager_id, "f"), _f = _g++, _g), "f"), _f));
  1959. },
  1960. enumerable: false,
  1961. configurable: true
  1962. });
  1963. return IdManager;
  1964. }());
  1965. _IdManager_id = new WeakMap();
  1966. var ImageManager = /** @class */ (function () {
  1967. function ImageManager() {
  1968. _ImageManager_instances.add(this);
  1969. _ImageManager_baseId.set(this, getUuid());
  1970. _ImageManager_id.set(this, 0);
  1971. _ImageManager_cache.set(this, null);
  1972. }
  1973. Object.defineProperty(ImageManager, "_isSVGFittingCanvas", {
  1974. get: function () {
  1975. var 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>";
  1976. var canvas = new OffscreenCanvas(1, 3);
  1977. var ctx = canvas.getContext("2d");
  1978. var image = new Image();
  1979. image.src = svg;
  1980. var promise = image.decode().then(function () {
  1981. ctx.drawImage(image, 0, 0, 1, 1, 0, 0, 1, 3);
  1982. return new Uint32Array(ctx.getImageData(0, 0, 1, 1).data.buffer)[0] === 0;
  1983. });
  1984. return shadow(this, "_isSVGFittingCanvas", promise);
  1985. },
  1986. enumerable: false,
  1987. configurable: true
  1988. });
  1989. ImageManager.prototype.getFromFile = function (file) {
  1990. return tslib_1.__awaiter(this, void 0, void 0, function () {
  1991. var lastModified, name, size, type;
  1992. return tslib_1.__generator(this, function (_f) {
  1993. lastModified = file.lastModified, name = file.name, size = file.size, type = file.type;
  1994. return [2 /*return*/, tslib_1.__classPrivateFieldGet(this, _ImageManager_instances, "m", _ImageManager_get).call(this, "".concat(lastModified, "_").concat(name, "_").concat(size, "_").concat(type), file)];
  1995. });
  1996. });
  1997. };
  1998. ImageManager.prototype.getFromUrl = function (url) {
  1999. return tslib_1.__awaiter(this, void 0, void 0, function () {
  2000. return tslib_1.__generator(this, function (_f) {
  2001. return [2 /*return*/, tslib_1.__classPrivateFieldGet(this, _ImageManager_instances, "m", _ImageManager_get).call(this, url, url)];
  2002. });
  2003. });
  2004. };
  2005. ImageManager.prototype.getFromId = function (id) {
  2006. return tslib_1.__awaiter(this, void 0, void 0, function () {
  2007. var data;
  2008. return tslib_1.__generator(this, function (_f) {
  2009. tslib_1.__classPrivateFieldSet(this, _ImageManager_cache, tslib_1.__classPrivateFieldGet(this, _ImageManager_cache, "f") || new Map(), "f");
  2010. data = tslib_1.__classPrivateFieldGet(this, _ImageManager_cache, "f").get(id);
  2011. if (!data) {
  2012. return [2 /*return*/, null];
  2013. }
  2014. if (data.bitmap) {
  2015. data.refCounter += 1;
  2016. return [2 /*return*/, data];
  2017. }
  2018. if (data.file) {
  2019. return [2 /*return*/, this.getFromFile(data.file)];
  2020. }
  2021. return [2 /*return*/, this.getFromUrl(data.url)];
  2022. });
  2023. });
  2024. };
  2025. ImageManager.prototype.getSvgUrl = function (id) {
  2026. var data = tslib_1.__classPrivateFieldGet(this, _ImageManager_cache, "f").get(id);
  2027. if (!(data === null || data === void 0 ? void 0 : data.isSvg)) {
  2028. return null;
  2029. }
  2030. return data.svgUrl;
  2031. };
  2032. ImageManager.prototype.deleteId = function (id) {
  2033. tslib_1.__classPrivateFieldSet(this, _ImageManager_cache, tslib_1.__classPrivateFieldGet(this, _ImageManager_cache, "f") || new Map(), "f");
  2034. var data = tslib_1.__classPrivateFieldGet(this, _ImageManager_cache, "f").get(id);
  2035. if (!data) {
  2036. return;
  2037. }
  2038. data.refCounter -= 1;
  2039. if (data.refCounter !== 0) {
  2040. return;
  2041. }
  2042. data.bitmap = null;
  2043. };
  2044. ImageManager.prototype.isValidId = function (id) {
  2045. return id.startsWith("image_".concat(tslib_1.__classPrivateFieldGet(this, _ImageManager_baseId, "f"), "_"));
  2046. };
  2047. return ImageManager;
  2048. }());
  2049. _ImageManager_baseId = new WeakMap(), _ImageManager_id = new WeakMap(), _ImageManager_cache = new WeakMap(), _ImageManager_instances = new WeakSet(), _ImageManager_get = function _ImageManager_get(key, rawData) {
  2050. var _f, _g;
  2051. return tslib_1.__awaiter(this, void 0, void 0, function () {
  2052. var data, image, mustRemoveAspectRatioPromise_1, fileReader_1, imageElement_1, imagePromise, _h, e_1;
  2053. var _this = this;
  2054. return tslib_1.__generator(this, function (_j) {
  2055. switch (_j.label) {
  2056. case 0:
  2057. tslib_1.__classPrivateFieldSet(this, _ImageManager_cache, tslib_1.__classPrivateFieldGet(this, _ImageManager_cache, "f") || new Map(), "f");
  2058. data = tslib_1.__classPrivateFieldGet(this, _ImageManager_cache, "f").get(key);
  2059. if (data === null) {
  2060. return [2 /*return*/, null];
  2061. }
  2062. if (data === null || data === void 0 ? void 0 : data.bitmap) {
  2063. data.refCounter += 1;
  2064. return [2 /*return*/, data];
  2065. }
  2066. _j.label = 1;
  2067. case 1:
  2068. _j.trys.push([1, 9, , 10]);
  2069. data || (data = {
  2070. bitmap: null,
  2071. id: "image_".concat(tslib_1.__classPrivateFieldGet(this, _ImageManager_baseId, "f"), "_").concat((tslib_1.__classPrivateFieldSet(this, _ImageManager_id, (_g = tslib_1.__classPrivateFieldGet(this, _ImageManager_id, "f"), _f = _g++, _g), "f"), _f)),
  2072. refCounter: 0,
  2073. isSvg: false
  2074. });
  2075. image = void 0;
  2076. if (!(typeof rawData === "string")) return [3 /*break*/, 3];
  2077. data.url = rawData;
  2078. return [4 /*yield*/, fetchData(rawData, "blob")];
  2079. case 2:
  2080. image = _j.sent();
  2081. return [3 /*break*/, 4];
  2082. case 3:
  2083. image = data.file = rawData;
  2084. _j.label = 4;
  2085. case 4:
  2086. if (!(image.type === "image/svg+xml")) return [3 /*break*/, 6];
  2087. mustRemoveAspectRatioPromise_1 = ImageManager._isSVGFittingCanvas;
  2088. fileReader_1 = new FileReader();
  2089. imageElement_1 = new Image();
  2090. imagePromise = new Promise(function (resolve, reject) {
  2091. imageElement_1.onload = function () {
  2092. data.bitmap = imageElement_1;
  2093. data.isSvg = true;
  2094. resolve();
  2095. };
  2096. fileReader_1.onload = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
  2097. var url, _f;
  2098. return tslib_1.__generator(this, function (_g) {
  2099. switch (_g.label) {
  2100. case 0:
  2101. url = data.svgUrl = fileReader_1.result;
  2102. _f = imageElement_1;
  2103. return [4 /*yield*/, mustRemoveAspectRatioPromise_1];
  2104. case 1:
  2105. _f.src = (_g.sent()) ? "".concat(url, "#svgView(preserveAspectRatio(none))") : url;
  2106. return [2 /*return*/];
  2107. }
  2108. });
  2109. }); };
  2110. imageElement_1.onerror = fileReader_1.onerror = reject;
  2111. });
  2112. fileReader_1.readAsDataURL(image);
  2113. return [4 /*yield*/, imagePromise];
  2114. case 5:
  2115. _j.sent();
  2116. return [3 /*break*/, 8];
  2117. case 6:
  2118. _h = data;
  2119. return [4 /*yield*/, createImageBitmap(image)];
  2120. case 7:
  2121. _h.bitmap = _j.sent();
  2122. _j.label = 8;
  2123. case 8:
  2124. data.refCounter = 1;
  2125. return [3 /*break*/, 10];
  2126. case 9:
  2127. e_1 = _j.sent();
  2128. console.error(e_1);
  2129. data = null;
  2130. return [3 /*break*/, 10];
  2131. case 10:
  2132. tslib_1.__classPrivateFieldGet(this, _ImageManager_cache, "f").set(key, data);
  2133. if (data) {
  2134. tslib_1.__classPrivateFieldGet(this, _ImageManager_cache, "f").set(data.id, data);
  2135. }
  2136. return [2 /*return*/, data];
  2137. }
  2138. });
  2139. });
  2140. };
  2141. var CommandManager = /** @class */ (function () {
  2142. function CommandManager(maxSize) {
  2143. if (maxSize === void 0) { maxSize = 128; }
  2144. _CommandManager_commands.set(this, []);
  2145. _CommandManager_locked.set(this, false);
  2146. _CommandManager_maxSize.set(this, void 0);
  2147. _CommandManager_position.set(this, -1);
  2148. tslib_1.__classPrivateFieldSet(this, _CommandManager_maxSize, maxSize, "f");
  2149. }
  2150. CommandManager.prototype.add = function (_f) {
  2151. var cmd = _f.cmd, undo = _f.undo, post = _f.post, mustExec = _f.mustExec, _g = _f.type, type = _g === void 0 ? NaN : _g, _h = _f.overwriteIfSameType, overwriteIfSameType = _h === void 0 ? false : _h, _j = _f.keepUndo, keepUndo = _j === void 0 ? false : _j;
  2152. if (mustExec) {
  2153. cmd();
  2154. }
  2155. if (tslib_1.__classPrivateFieldGet(this, _CommandManager_locked, "f")) {
  2156. return;
  2157. }
  2158. var save = {
  2159. cmd: cmd,
  2160. undo: undo,
  2161. post: post,
  2162. type: type
  2163. };
  2164. if (tslib_1.__classPrivateFieldGet(this, _CommandManager_position, "f") === -1) {
  2165. if (tslib_1.__classPrivateFieldGet(this, _CommandManager_commands, "f").length > 0) {
  2166. tslib_1.__classPrivateFieldGet(this, _CommandManager_commands, "f").length = 0;
  2167. }
  2168. tslib_1.__classPrivateFieldSet(this, _CommandManager_position, 0, "f");
  2169. tslib_1.__classPrivateFieldGet(this, _CommandManager_commands, "f").push(save);
  2170. return;
  2171. }
  2172. if (overwriteIfSameType && tslib_1.__classPrivateFieldGet(this, _CommandManager_commands, "f")[tslib_1.__classPrivateFieldGet(this, _CommandManager_position, "f")].type === type) {
  2173. if (keepUndo) {
  2174. save.undo = tslib_1.__classPrivateFieldGet(this, _CommandManager_commands, "f")[tslib_1.__classPrivateFieldGet(this, _CommandManager_position, "f")].undo;
  2175. }
  2176. tslib_1.__classPrivateFieldGet(this, _CommandManager_commands, "f")[tslib_1.__classPrivateFieldGet(this, _CommandManager_position, "f")] = save;
  2177. return;
  2178. }
  2179. var next = tslib_1.__classPrivateFieldGet(this, _CommandManager_position, "f") + 1;
  2180. if (next === tslib_1.__classPrivateFieldGet(this, _CommandManager_maxSize, "f")) {
  2181. tslib_1.__classPrivateFieldGet(this, _CommandManager_commands, "f").splice(0, 1);
  2182. }
  2183. else {
  2184. tslib_1.__classPrivateFieldSet(this, _CommandManager_position, next, "f");
  2185. if (next < tslib_1.__classPrivateFieldGet(this, _CommandManager_commands, "f").length) {
  2186. tslib_1.__classPrivateFieldGet(this, _CommandManager_commands, "f").splice(next);
  2187. }
  2188. }
  2189. tslib_1.__classPrivateFieldGet(this, _CommandManager_commands, "f").push(save);
  2190. };
  2191. CommandManager.prototype.undo = function () {
  2192. if (tslib_1.__classPrivateFieldGet(this, _CommandManager_position, "f") === -1) {
  2193. return;
  2194. }
  2195. tslib_1.__classPrivateFieldSet(this, _CommandManager_locked, true, "f");
  2196. var _f = tslib_1.__classPrivateFieldGet(this, _CommandManager_commands, "f")[tslib_1.__classPrivateFieldGet(this, _CommandManager_position, "f")], undo = _f.undo, post = _f.post;
  2197. undo();
  2198. post === null || post === void 0 ? void 0 : post();
  2199. tslib_1.__classPrivateFieldSet(this, _CommandManager_locked, false, "f");
  2200. tslib_1.__classPrivateFieldSet(this, _CommandManager_position, tslib_1.__classPrivateFieldGet(this, _CommandManager_position, "f") - 1, "f");
  2201. };
  2202. CommandManager.prototype.redo = function () {
  2203. if (tslib_1.__classPrivateFieldGet(this, _CommandManager_position, "f") < tslib_1.__classPrivateFieldGet(this, _CommandManager_commands, "f").length - 1) {
  2204. tslib_1.__classPrivateFieldSet(this, _CommandManager_position, tslib_1.__classPrivateFieldGet(this, _CommandManager_position, "f") + 1, "f");
  2205. tslib_1.__classPrivateFieldSet(this, _CommandManager_locked, true, "f");
  2206. var _f = tslib_1.__classPrivateFieldGet(this, _CommandManager_commands, "f")[tslib_1.__classPrivateFieldGet(this, _CommandManager_position, "f")], cmd = _f.cmd, post = _f.post;
  2207. cmd();
  2208. post === null || post === void 0 ? void 0 : post();
  2209. tslib_1.__classPrivateFieldSet(this, _CommandManager_locked, false, "f");
  2210. }
  2211. };
  2212. CommandManager.prototype.hasSomethingToUndo = function () {
  2213. return tslib_1.__classPrivateFieldGet(this, _CommandManager_position, "f") !== -1;
  2214. };
  2215. CommandManager.prototype.hasSomethingToRedo = function () {
  2216. return tslib_1.__classPrivateFieldGet(this, _CommandManager_position, "f") < tslib_1.__classPrivateFieldGet(this, _CommandManager_commands, "f").length - 1;
  2217. };
  2218. CommandManager.prototype.destroy = function () {
  2219. tslib_1.__classPrivateFieldSet(this, _CommandManager_commands, null, "f");
  2220. };
  2221. return CommandManager;
  2222. }());
  2223. _CommandManager_commands = new WeakMap(), _CommandManager_locked = new WeakMap(), _CommandManager_maxSize = new WeakMap(), _CommandManager_position = new WeakMap();
  2224. var KeyboardManager = /** @class */ (function () {
  2225. function KeyboardManager(callbacks) {
  2226. _KeyboardManager_instances.add(this);
  2227. this.buffer = [];
  2228. this.callbacks = new Map();
  2229. this.allKeys = new Set();
  2230. var isMac = util_FeatureTest.platform.isMac;
  2231. for (var _i = 0, callbacks_1 = callbacks; _i < callbacks_1.length; _i++) {
  2232. var _f = callbacks_1[_i], keys = _f[0], callback = _f[1], _g = _f[2], options = _g === void 0 ? {} : _g;
  2233. for (var _h = 0, keys_1 = keys; _h < keys_1.length; _h++) {
  2234. var key = keys_1[_h];
  2235. var isMacKey = key.startsWith("mac+");
  2236. if (isMac && isMacKey) {
  2237. this.callbacks.set(key.slice(4), {
  2238. callback: callback,
  2239. options: options
  2240. });
  2241. this.allKeys.add(key.split("+").at(-1));
  2242. }
  2243. else if (!isMac && !isMacKey) {
  2244. this.callbacks.set(key, {
  2245. callback: callback,
  2246. options: options
  2247. });
  2248. this.allKeys.add(key.split("+").at(-1));
  2249. }
  2250. }
  2251. }
  2252. }
  2253. KeyboardManager.prototype.exec = function (self, event) {
  2254. if (!this.allKeys.has(event.key)) {
  2255. return;
  2256. }
  2257. var info = this.callbacks.get(tslib_1.__classPrivateFieldGet(this, _KeyboardManager_instances, "m", _KeyboardManager_serialize).call(this, event));
  2258. if (!info) {
  2259. return;
  2260. }
  2261. var callback = info.callback, _f = info.options, _g = _f.bubbles, bubbles = _g === void 0 ? false : _g, _h = _f.args, args = _h === void 0 ? [] : _h, _j = _f.checker, checker = _j === void 0 ? null : _j;
  2262. if (checker && !checker(self, event)) {
  2263. return;
  2264. }
  2265. callback.bind.apply(callback, tslib_1.__spreadArray(tslib_1.__spreadArray([self], args, false), [event], false))();
  2266. if (!bubbles) {
  2267. event.stopPropagation();
  2268. event.preventDefault();
  2269. }
  2270. };
  2271. return KeyboardManager;
  2272. }());
  2273. _KeyboardManager_instances = new WeakSet(), _KeyboardManager_serialize = function _KeyboardManager_serialize(event) {
  2274. if (event.altKey) {
  2275. this.buffer.push("alt");
  2276. }
  2277. if (event.ctrlKey) {
  2278. this.buffer.push("ctrl");
  2279. }
  2280. if (event.metaKey) {
  2281. this.buffer.push("meta");
  2282. }
  2283. if (event.shiftKey) {
  2284. this.buffer.push("shift");
  2285. }
  2286. this.buffer.push(event.key);
  2287. var str = this.buffer.join("+");
  2288. this.buffer.length = 0;
  2289. return str;
  2290. };
  2291. var ColorManager = /** @class */ (function () {
  2292. function ColorManager() {
  2293. }
  2294. Object.defineProperty(ColorManager.prototype, "_colors", {
  2295. get: function () {
  2296. var colors = new Map([["CanvasText", null], ["Canvas", null]]);
  2297. getColorValues(colors);
  2298. return shadow(this, "_colors", colors);
  2299. },
  2300. enumerable: false,
  2301. configurable: true
  2302. });
  2303. ColorManager.prototype.convert = function (color) {
  2304. var rgb = getRGB(color);
  2305. if (!window.matchMedia("(forced-colors: active)").matches) {
  2306. return rgb;
  2307. }
  2308. for (var _i = 0, _f = this._colors; _i < _f.length; _i++) {
  2309. var _g = _f[_i], name = _g[0], RGB = _g[1];
  2310. if (RGB.every(function (x, i) { return x === rgb[i]; })) {
  2311. return ColorManager._colorsMapping.get(name);
  2312. }
  2313. }
  2314. return rgb;
  2315. };
  2316. ColorManager.prototype.getHexCode = function (name) {
  2317. var rgb = this._colors.get(name);
  2318. if (!rgb) {
  2319. return name;
  2320. }
  2321. return Util.makeHexColor.apply(Util, rgb);
  2322. };
  2323. ColorManager._colorsMapping = new Map([["CanvasText", [0, 0, 0]], ["Canvas", [255, 255, 255]]]);
  2324. return ColorManager;
  2325. }());
  2326. var AnnotationEditorUIManager = /** @class */ (function () {
  2327. function AnnotationEditorUIManager(container, viewer, altTextManager, eventBus, pdfDocument, pageColors, highlightColors, enableHighlightFloatingButton, mlManager) {
  2328. _AnnotationEditorUIManager_instances.add(this);
  2329. _AnnotationEditorUIManager_activeEditor.set(this, null);
  2330. _AnnotationEditorUIManager_allEditors.set(this, new Map());
  2331. _AnnotationEditorUIManager_allLayers.set(this, new Map());
  2332. _AnnotationEditorUIManager_altTextManager.set(this, null);
  2333. _AnnotationEditorUIManager_annotationStorage.set(this, null);
  2334. _AnnotationEditorUIManager_changedExistingAnnotations.set(this, null);
  2335. _AnnotationEditorUIManager_commandManager.set(this, new CommandManager());
  2336. _AnnotationEditorUIManager_currentPageIndex.set(this, 0);
  2337. _AnnotationEditorUIManager_deletedAnnotationsElementIds.set(this, new Set());
  2338. _AnnotationEditorUIManager_draggingEditors.set(this, null);
  2339. _AnnotationEditorUIManager_editorTypes.set(this, null);
  2340. _AnnotationEditorUIManager_editorsToRescale.set(this, new Set());
  2341. _AnnotationEditorUIManager_enableHighlightFloatingButton.set(this, false);
  2342. _AnnotationEditorUIManager_filterFactory.set(this, null);
  2343. _AnnotationEditorUIManager_focusMainContainerTimeoutId.set(this, null);
  2344. _AnnotationEditorUIManager_highlightColors.set(this, null);
  2345. _AnnotationEditorUIManager_highlightWhenShiftUp.set(this, false);
  2346. _AnnotationEditorUIManager_highlightToolbar.set(this, null);
  2347. _AnnotationEditorUIManager_idManager.set(this, new IdManager());
  2348. _AnnotationEditorUIManager_isEnabled.set(this, false);
  2349. _AnnotationEditorUIManager_isWaiting.set(this, false);
  2350. _AnnotationEditorUIManager_lastActiveElement.set(this, null);
  2351. _AnnotationEditorUIManager_mainHighlightColorPicker.set(this, null);
  2352. _AnnotationEditorUIManager_mlManager.set(this, null);
  2353. _AnnotationEditorUIManager_mode.set(this, AnnotationEditorType.NONE);
  2354. _AnnotationEditorUIManager_selectedEditors.set(this, new Set());
  2355. _AnnotationEditorUIManager_selectedTextNode.set(this, null);
  2356. _AnnotationEditorUIManager_pageColors.set(this, null);
  2357. _AnnotationEditorUIManager_showAllStates.set(this, null);
  2358. _AnnotationEditorUIManager_boundBlur.set(this, this.blur.bind(this));
  2359. _AnnotationEditorUIManager_boundFocus.set(this, this.focus.bind(this));
  2360. _AnnotationEditorUIManager_boundCopy.set(this, this.copy.bind(this));
  2361. _AnnotationEditorUIManager_boundCut.set(this, this.cut.bind(this));
  2362. _AnnotationEditorUIManager_boundPaste.set(this, this.paste.bind(this));
  2363. _AnnotationEditorUIManager_boundKeydown.set(this, this.keydown.bind(this));
  2364. _AnnotationEditorUIManager_boundKeyup.set(this, this.keyup.bind(this));
  2365. _AnnotationEditorUIManager_boundOnEditingAction.set(this, this.onEditingAction.bind(this));
  2366. _AnnotationEditorUIManager_boundOnPageChanging.set(this, this.onPageChanging.bind(this));
  2367. _AnnotationEditorUIManager_boundOnScaleChanging.set(this, this.onScaleChanging.bind(this));
  2368. _AnnotationEditorUIManager_boundSelectionChange.set(this, tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_selectionChange).bind(this));
  2369. _AnnotationEditorUIManager_boundOnRotationChanging.set(this, this.onRotationChanging.bind(this));
  2370. _AnnotationEditorUIManager_previousStates.set(this, {
  2371. isEditing: false,
  2372. isEmpty: true,
  2373. hasSomethingToUndo: false,
  2374. hasSomethingToRedo: false,
  2375. hasSelectedEditor: false,
  2376. hasSelectedText: false
  2377. });
  2378. _AnnotationEditorUIManager_translation.set(this, [0, 0]);
  2379. _AnnotationEditorUIManager_translationTimeoutId.set(this, null);
  2380. _AnnotationEditorUIManager_container.set(this, null);
  2381. _AnnotationEditorUIManager_viewer.set(this, null);
  2382. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_container, container, "f");
  2383. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_viewer, viewer, "f");
  2384. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_altTextManager, altTextManager, "f");
  2385. this._eventBus = eventBus;
  2386. this._eventBus._on("editingaction", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_boundOnEditingAction, "f"));
  2387. this._eventBus._on("pagechanging", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_boundOnPageChanging, "f"));
  2388. this._eventBus._on("scalechanging", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_boundOnScaleChanging, "f"));
  2389. this._eventBus._on("rotationchanging", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_boundOnRotationChanging, "f"));
  2390. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_addSelectionListener).call(this);
  2391. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_addKeyboardManager).call(this);
  2392. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_annotationStorage, pdfDocument.annotationStorage, "f");
  2393. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_filterFactory, pdfDocument.filterFactory, "f");
  2394. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_pageColors, pageColors, "f");
  2395. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_highlightColors, highlightColors || null, "f");
  2396. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_enableHighlightFloatingButton, enableHighlightFloatingButton, "f");
  2397. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_mlManager, mlManager || null, "f");
  2398. this.viewParameters = {
  2399. realScale: PixelsPerInch.PDF_TO_CSS_UNITS,
  2400. rotation: 0
  2401. };
  2402. this.isShiftKeyDown = false;
  2403. }
  2404. Object.defineProperty(AnnotationEditorUIManager, "_keyboardManager", {
  2405. get: function () {
  2406. var proto = AnnotationEditorUIManager.prototype;
  2407. var arrowChecker = function (self) { return tslib_1.__classPrivateFieldGet(self, _AnnotationEditorUIManager_container, "f").contains(document.activeElement) && document.activeElement.tagName !== "BUTTON" && self.hasSomethingToControl(); };
  2408. var textInputChecker = function (_self, _f) {
  2409. var el = _f.target;
  2410. if (el instanceof HTMLInputElement) {
  2411. var type = el.type;
  2412. return type !== "text" && type !== "number";
  2413. }
  2414. return true;
  2415. };
  2416. var small = this.TRANSLATE_SMALL;
  2417. var big = this.TRANSLATE_BIG;
  2418. return shadow(this, "_keyboardManager", new KeyboardManager([[["ctrl+a", "mac+meta+a"], proto.selectAll, {
  2419. checker: textInputChecker
  2420. }], [["ctrl+z", "mac+meta+z"], proto.undo, {
  2421. checker: textInputChecker
  2422. }], [["ctrl+y", "ctrl+shift+z", "mac+meta+shift+z", "ctrl+shift+Z", "mac+meta+shift+Z"], proto.redo, {
  2423. checker: textInputChecker
  2424. }], [["Backspace", "alt+Backspace", "ctrl+Backspace", "shift+Backspace", "mac+Backspace", "mac+alt+Backspace", "mac+ctrl+Backspace", "Delete", "ctrl+Delete", "shift+Delete", "mac+Delete"], proto.delete, {
  2425. checker: textInputChecker
  2426. }], [["Enter", "mac+Enter"], proto.addNewEditorFromKeyboard, {
  2427. checker: function (self, _f) {
  2428. var el = _f.target;
  2429. return !(el instanceof HTMLButtonElement) && tslib_1.__classPrivateFieldGet(self, _AnnotationEditorUIManager_container, "f").contains(el) && !self.isEnterHandled;
  2430. }
  2431. }], [[" ", "mac+ "], proto.addNewEditorFromKeyboard, {
  2432. checker: function (self, _f) {
  2433. var el = _f.target;
  2434. return !(el instanceof HTMLButtonElement) && tslib_1.__classPrivateFieldGet(self, _AnnotationEditorUIManager_container, "f").contains(document.activeElement);
  2435. }
  2436. }], [["Escape", "mac+Escape"], proto.unselectAll], [["ArrowLeft", "mac+ArrowLeft"], proto.translateSelectedEditors, {
  2437. args: [-small, 0],
  2438. checker: arrowChecker
  2439. }], [["ctrl+ArrowLeft", "mac+shift+ArrowLeft"], proto.translateSelectedEditors, {
  2440. args: [-big, 0],
  2441. checker: arrowChecker
  2442. }], [["ArrowRight", "mac+ArrowRight"], proto.translateSelectedEditors, {
  2443. args: [small, 0],
  2444. checker: arrowChecker
  2445. }], [["ctrl+ArrowRight", "mac+shift+ArrowRight"], proto.translateSelectedEditors, {
  2446. args: [big, 0],
  2447. checker: arrowChecker
  2448. }], [["ArrowUp", "mac+ArrowUp"], proto.translateSelectedEditors, {
  2449. args: [0, -small],
  2450. checker: arrowChecker
  2451. }], [["ctrl+ArrowUp", "mac+shift+ArrowUp"], proto.translateSelectedEditors, {
  2452. args: [0, -big],
  2453. checker: arrowChecker
  2454. }], [["ArrowDown", "mac+ArrowDown"], proto.translateSelectedEditors, {
  2455. args: [0, small],
  2456. checker: arrowChecker
  2457. }], [["ctrl+ArrowDown", "mac+shift+ArrowDown"], proto.translateSelectedEditors, {
  2458. args: [0, big],
  2459. checker: arrowChecker
  2460. }]]));
  2461. },
  2462. enumerable: false,
  2463. configurable: true
  2464. });
  2465. AnnotationEditorUIManager.prototype.destroy = function () {
  2466. var _f, _g;
  2467. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_removeKeyboardManager).call(this);
  2468. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_removeFocusManager).call(this);
  2469. this._eventBus._off("editingaction", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_boundOnEditingAction, "f"));
  2470. this._eventBus._off("pagechanging", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_boundOnPageChanging, "f"));
  2471. this._eventBus._off("scalechanging", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_boundOnScaleChanging, "f"));
  2472. this._eventBus._off("rotationchanging", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_boundOnRotationChanging, "f"));
  2473. for (var _i = 0, _h = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allLayers, "f").values(); _i < _h.length; _i++) {
  2474. var layer = _h[_i];
  2475. layer.destroy();
  2476. }
  2477. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allLayers, "f").clear();
  2478. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allEditors, "f").clear();
  2479. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_editorsToRescale, "f").clear();
  2480. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_activeEditor, null, "f");
  2481. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f").clear();
  2482. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_commandManager, "f").destroy();
  2483. (_f = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_altTextManager, "f")) === null || _f === void 0 ? void 0 : _f.destroy();
  2484. (_g = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_highlightToolbar, "f")) === null || _g === void 0 ? void 0 : _g.hide();
  2485. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_highlightToolbar, null, "f");
  2486. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_focusMainContainerTimeoutId, "f")) {
  2487. clearTimeout(tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_focusMainContainerTimeoutId, "f"));
  2488. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_focusMainContainerTimeoutId, null, "f");
  2489. }
  2490. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_translationTimeoutId, "f")) {
  2491. clearTimeout(tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_translationTimeoutId, "f"));
  2492. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_translationTimeoutId, null, "f");
  2493. }
  2494. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_removeSelectionListener).call(this);
  2495. };
  2496. AnnotationEditorUIManager.prototype.mlGuess = function (data) {
  2497. var _f;
  2498. return tslib_1.__awaiter(this, void 0, void 0, function () {
  2499. return tslib_1.__generator(this, function (_g) {
  2500. return [2 /*return*/, ((_f = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_mlManager, "f")) === null || _f === void 0 ? void 0 : _f.guess(data)) || null];
  2501. });
  2502. });
  2503. };
  2504. Object.defineProperty(AnnotationEditorUIManager.prototype, "hasMLManager", {
  2505. get: function () {
  2506. return !!tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_mlManager, "f");
  2507. },
  2508. enumerable: false,
  2509. configurable: true
  2510. });
  2511. Object.defineProperty(AnnotationEditorUIManager.prototype, "hcmFilter", {
  2512. get: function () {
  2513. return shadow(this, "hcmFilter", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_pageColors, "f") ? tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_filterFactory, "f").addHCMFilter(tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_pageColors, "f").foreground, tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_pageColors, "f").background) : "none");
  2514. },
  2515. enumerable: false,
  2516. configurable: true
  2517. });
  2518. Object.defineProperty(AnnotationEditorUIManager.prototype, "direction", {
  2519. get: function () {
  2520. return shadow(this, "direction", getComputedStyle(tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_container, "f")).direction);
  2521. },
  2522. enumerable: false,
  2523. configurable: true
  2524. });
  2525. Object.defineProperty(AnnotationEditorUIManager.prototype, "highlightColors", {
  2526. get: function () {
  2527. return shadow(this, "highlightColors", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_highlightColors, "f") ? new Map(tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_highlightColors, "f").split(",").map(function (pair) { return pair.split("=").map(function (x) { return x.trim(); }); })) : null);
  2528. },
  2529. enumerable: false,
  2530. configurable: true
  2531. });
  2532. Object.defineProperty(AnnotationEditorUIManager.prototype, "highlightColorNames", {
  2533. get: function () {
  2534. return shadow(this, "highlightColorNames", this.highlightColors ? new Map(Array.from(this.highlightColors, function (e) { return e.reverse(); })) : null);
  2535. },
  2536. enumerable: false,
  2537. configurable: true
  2538. });
  2539. AnnotationEditorUIManager.prototype.setMainHighlightColorPicker = function (colorPicker) {
  2540. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_mainHighlightColorPicker, colorPicker, "f");
  2541. };
  2542. AnnotationEditorUIManager.prototype.editAltText = function (editor) {
  2543. var _f;
  2544. (_f = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_altTextManager, "f")) === null || _f === void 0 ? void 0 : _f.editAltText(this, editor);
  2545. };
  2546. AnnotationEditorUIManager.prototype.onPageChanging = function (_f) {
  2547. var pageNumber = _f.pageNumber;
  2548. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_currentPageIndex, pageNumber - 1, "f");
  2549. };
  2550. AnnotationEditorUIManager.prototype.focusMainContainer = function () {
  2551. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_container, "f").focus();
  2552. };
  2553. AnnotationEditorUIManager.prototype.findParent = function (x, y) {
  2554. for (var _i = 0, _f = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allLayers, "f").values(); _i < _f.length; _i++) {
  2555. var layer = _f[_i];
  2556. var _g = layer.div.getBoundingClientRect(), layerX = _g.x, layerY = _g.y, width = _g.width, height = _g.height;
  2557. if (x >= layerX && x <= layerX + width && y >= layerY && y <= layerY + height) {
  2558. return layer;
  2559. }
  2560. }
  2561. return null;
  2562. };
  2563. AnnotationEditorUIManager.prototype.disableUserSelect = function (value) {
  2564. if (value === void 0) { value = false; }
  2565. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_viewer, "f").classList.toggle("noUserSelect", value);
  2566. };
  2567. AnnotationEditorUIManager.prototype.addShouldRescale = function (editor) {
  2568. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_editorsToRescale, "f").add(editor);
  2569. };
  2570. AnnotationEditorUIManager.prototype.removeShouldRescale = function (editor) {
  2571. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_editorsToRescale, "f").delete(editor);
  2572. };
  2573. AnnotationEditorUIManager.prototype.onScaleChanging = function (_f) {
  2574. var scale = _f.scale;
  2575. this.commitOrRemove();
  2576. this.viewParameters.realScale = scale * PixelsPerInch.PDF_TO_CSS_UNITS;
  2577. for (var _i = 0, _g = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_editorsToRescale, "f"); _i < _g.length; _i++) {
  2578. var editor = _g[_i];
  2579. editor.onScaleChanging();
  2580. }
  2581. };
  2582. AnnotationEditorUIManager.prototype.onRotationChanging = function (_f) {
  2583. var pagesRotation = _f.pagesRotation;
  2584. this.commitOrRemove();
  2585. this.viewParameters.rotation = pagesRotation;
  2586. };
  2587. AnnotationEditorUIManager.prototype.highlightSelection = function (methodOfCreation) {
  2588. if (methodOfCreation === void 0) { methodOfCreation = ""; }
  2589. var selection = document.getSelection();
  2590. if (!selection || selection.isCollapsed) {
  2591. return;
  2592. }
  2593. var anchorNode = selection.anchorNode, anchorOffset = selection.anchorOffset, focusNode = selection.focusNode, focusOffset = selection.focusOffset;
  2594. var text = selection.toString();
  2595. var anchorElement = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_getAnchorElementForSelection).call(this, selection);
  2596. var textLayer = anchorElement.closest(".textLayer");
  2597. var boxes = this.getSelectionBoxes(textLayer);
  2598. if (!boxes) {
  2599. return;
  2600. }
  2601. selection.empty();
  2602. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_mode, "f") === AnnotationEditorType.NONE) {
  2603. this._eventBus.dispatch("showannotationeditorui", {
  2604. source: this,
  2605. mode: AnnotationEditorType.HIGHLIGHT
  2606. });
  2607. this.showAllEditors("highlight", true, true);
  2608. }
  2609. for (var _i = 0, _f = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allLayers, "f").values(); _i < _f.length; _i++) {
  2610. var layer = _f[_i];
  2611. if (layer.hasTextLayer(textLayer)) {
  2612. layer.createAndAddNewEditor({
  2613. x: 0,
  2614. y: 0
  2615. }, false, {
  2616. methodOfCreation: methodOfCreation,
  2617. boxes: boxes,
  2618. anchorNode: anchorNode,
  2619. anchorOffset: anchorOffset,
  2620. focusNode: focusNode,
  2621. focusOffset: focusOffset,
  2622. text: text
  2623. });
  2624. break;
  2625. }
  2626. }
  2627. };
  2628. AnnotationEditorUIManager.prototype.addToAnnotationStorage = function (editor) {
  2629. if (!editor.isEmpty() && tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_annotationStorage, "f") && !tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_annotationStorage, "f").has(editor.id)) {
  2630. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_annotationStorage, "f").setValue(editor.id, editor);
  2631. }
  2632. };
  2633. AnnotationEditorUIManager.prototype.blur = function () {
  2634. this.isShiftKeyDown = false;
  2635. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_highlightWhenShiftUp, "f")) {
  2636. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_highlightWhenShiftUp, false, "f");
  2637. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_onSelectEnd).call(this, "main_toolbar");
  2638. }
  2639. if (!this.hasSelection) {
  2640. return;
  2641. }
  2642. var activeElement = document.activeElement;
  2643. for (var _i = 0, _f = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f"); _i < _f.length; _i++) {
  2644. var editor = _f[_i];
  2645. if (editor.div.contains(activeElement)) {
  2646. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_lastActiveElement, [editor, activeElement], "f");
  2647. editor._focusEventsAllowed = false;
  2648. break;
  2649. }
  2650. }
  2651. };
  2652. AnnotationEditorUIManager.prototype.focus = function () {
  2653. if (!tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_lastActiveElement, "f")) {
  2654. return;
  2655. }
  2656. var _f = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_lastActiveElement, "f"), lastEditor = _f[0], lastActiveElement = _f[1];
  2657. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_lastActiveElement, null, "f");
  2658. lastActiveElement.addEventListener("focusin", function () {
  2659. lastEditor._focusEventsAllowed = true;
  2660. }, {
  2661. once: true
  2662. });
  2663. lastActiveElement.focus();
  2664. };
  2665. AnnotationEditorUIManager.prototype.addEditListeners = function () {
  2666. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_addKeyboardManager).call(this);
  2667. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_addCopyPasteListeners).call(this);
  2668. };
  2669. AnnotationEditorUIManager.prototype.removeEditListeners = function () {
  2670. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_removeKeyboardManager).call(this);
  2671. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_removeCopyPasteListeners).call(this);
  2672. };
  2673. AnnotationEditorUIManager.prototype.copy = function (event) {
  2674. var _f;
  2675. event.preventDefault();
  2676. (_f = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_activeEditor, "f")) === null || _f === void 0 ? void 0 : _f.commitOrRemove();
  2677. if (!this.hasSelection) {
  2678. return;
  2679. }
  2680. var editors = [];
  2681. for (var _i = 0, _g = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f"); _i < _g.length; _i++) {
  2682. var editor = _g[_i];
  2683. var serialized = editor.serialize(true);
  2684. if (serialized) {
  2685. editors.push(serialized);
  2686. }
  2687. }
  2688. if (editors.length === 0) {
  2689. return;
  2690. }
  2691. event.clipboardData.setData("application/pdfjs", JSON.stringify(editors));
  2692. };
  2693. AnnotationEditorUIManager.prototype.cut = function (event) {
  2694. this.copy(event);
  2695. this.delete();
  2696. };
  2697. AnnotationEditorUIManager.prototype.paste = function (event) {
  2698. var _this = this;
  2699. event.preventDefault();
  2700. var clipboardData = event.clipboardData;
  2701. for (var _i = 0, _f = clipboardData.items; _i < _f.length; _i++) {
  2702. var item = _f[_i];
  2703. for (var _g = 0, _h = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_editorTypes, "f"); _g < _h.length; _g++) {
  2704. var editorType = _h[_g];
  2705. if (editorType.isHandlingMimeForPasting(item.type)) {
  2706. editorType.paste(item, this.currentLayer);
  2707. return;
  2708. }
  2709. }
  2710. }
  2711. var data = clipboardData.getData("application/pdfjs");
  2712. if (!data) {
  2713. return;
  2714. }
  2715. try {
  2716. data = JSON.parse(data);
  2717. }
  2718. catch (ex) {
  2719. warn("paste: \"".concat(ex.message, "\"."));
  2720. return;
  2721. }
  2722. if (!Array.isArray(data)) {
  2723. return;
  2724. }
  2725. this.unselectAll();
  2726. var layer = this.currentLayer;
  2727. try {
  2728. var newEditors_1 = [];
  2729. for (var _j = 0, data_1 = data; _j < data_1.length; _j++) {
  2730. var editor = data_1[_j];
  2731. var deserializedEditor = layer.deserialize(editor);
  2732. if (!deserializedEditor) {
  2733. return;
  2734. }
  2735. newEditors_1.push(deserializedEditor);
  2736. }
  2737. var cmd = function () {
  2738. for (var _i = 0, newEditors_2 = newEditors_1; _i < newEditors_2.length; _i++) {
  2739. var editor = newEditors_2[_i];
  2740. tslib_1.__classPrivateFieldGet(_this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_addEditorToLayer).call(_this, editor);
  2741. }
  2742. tslib_1.__classPrivateFieldGet(_this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_selectEditors).call(_this, newEditors_1);
  2743. };
  2744. var undo = function () {
  2745. for (var _i = 0, newEditors_3 = newEditors_1; _i < newEditors_3.length; _i++) {
  2746. var editor = newEditors_3[_i];
  2747. editor.remove();
  2748. }
  2749. };
  2750. this.addCommands({
  2751. cmd: cmd,
  2752. undo: undo,
  2753. mustExec: true
  2754. });
  2755. }
  2756. catch (ex) {
  2757. warn("paste: \"".concat(ex.message, "\"."));
  2758. }
  2759. };
  2760. AnnotationEditorUIManager.prototype.keydown = function (event) {
  2761. if (!this.isShiftKeyDown && event.key === "Shift") {
  2762. this.isShiftKeyDown = true;
  2763. }
  2764. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_mode, "f") !== AnnotationEditorType.NONE && !this.isEditorHandlingKeyboard) {
  2765. AnnotationEditorUIManager._keyboardManager.exec(this, event);
  2766. }
  2767. };
  2768. AnnotationEditorUIManager.prototype.keyup = function (event) {
  2769. if (this.isShiftKeyDown && event.key === "Shift") {
  2770. this.isShiftKeyDown = false;
  2771. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_highlightWhenShiftUp, "f")) {
  2772. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_highlightWhenShiftUp, false, "f");
  2773. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_onSelectEnd).call(this, "main_toolbar");
  2774. }
  2775. }
  2776. };
  2777. AnnotationEditorUIManager.prototype.onEditingAction = function (_f) {
  2778. var name = _f.name;
  2779. switch (name) {
  2780. case "undo":
  2781. case "redo":
  2782. case "delete":
  2783. case "selectAll":
  2784. this[name]();
  2785. break;
  2786. case "highlightSelection":
  2787. this.highlightSelection("context_menu");
  2788. break;
  2789. }
  2790. };
  2791. AnnotationEditorUIManager.prototype.setEditingState = function (isEditing) {
  2792. if (isEditing) {
  2793. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_addFocusManager).call(this);
  2794. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_addCopyPasteListeners).call(this);
  2795. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateStates).call(this, {
  2796. isEditing: tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_mode, "f") !== AnnotationEditorType.NONE,
  2797. isEmpty: tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_isEmpty).call(this),
  2798. hasSomethingToUndo: tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_commandManager, "f").hasSomethingToUndo(),
  2799. hasSomethingToRedo: tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_commandManager, "f").hasSomethingToRedo(),
  2800. hasSelectedEditor: false
  2801. });
  2802. }
  2803. else {
  2804. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_removeFocusManager).call(this);
  2805. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_removeCopyPasteListeners).call(this);
  2806. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateStates).call(this, {
  2807. isEditing: false
  2808. });
  2809. this.disableUserSelect(false);
  2810. }
  2811. };
  2812. AnnotationEditorUIManager.prototype.registerEditorTypes = function (types) {
  2813. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_editorTypes, "f")) {
  2814. return;
  2815. }
  2816. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_editorTypes, types, "f");
  2817. for (var _i = 0, _f = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_editorTypes, "f"); _i < _f.length; _i++) {
  2818. var editorType = _f[_i];
  2819. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateUI).call(this, editorType.defaultPropertiesToUpdate);
  2820. }
  2821. };
  2822. AnnotationEditorUIManager.prototype.getId = function () {
  2823. return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_idManager, "f").id;
  2824. };
  2825. Object.defineProperty(AnnotationEditorUIManager.prototype, "currentLayer", {
  2826. get: function () {
  2827. return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allLayers, "f").get(tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_currentPageIndex, "f"));
  2828. },
  2829. enumerable: false,
  2830. configurable: true
  2831. });
  2832. AnnotationEditorUIManager.prototype.getLayer = function (pageIndex) {
  2833. return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allLayers, "f").get(pageIndex);
  2834. };
  2835. Object.defineProperty(AnnotationEditorUIManager.prototype, "currentPageIndex", {
  2836. get: function () {
  2837. return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_currentPageIndex, "f");
  2838. },
  2839. enumerable: false,
  2840. configurable: true
  2841. });
  2842. AnnotationEditorUIManager.prototype.addLayer = function (layer) {
  2843. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allLayers, "f").set(layer.pageIndex, layer);
  2844. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_isEnabled, "f")) {
  2845. layer.enable();
  2846. }
  2847. else {
  2848. layer.disable();
  2849. }
  2850. };
  2851. AnnotationEditorUIManager.prototype.removeLayer = function (layer) {
  2852. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allLayers, "f").delete(layer.pageIndex);
  2853. };
  2854. AnnotationEditorUIManager.prototype.updateMode = function (mode, editId, isFromKeyboard) {
  2855. if (editId === void 0) { editId = null; }
  2856. if (isFromKeyboard === void 0) { isFromKeyboard = false; }
  2857. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_mode, "f") === mode) {
  2858. return;
  2859. }
  2860. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_mode, mode, "f");
  2861. if (mode === AnnotationEditorType.NONE) {
  2862. this.setEditingState(false);
  2863. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_disableAll).call(this);
  2864. return;
  2865. }
  2866. this.setEditingState(true);
  2867. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_enableAll).call(this);
  2868. this.unselectAll();
  2869. for (var _i = 0, _f = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allLayers, "f").values(); _i < _f.length; _i++) {
  2870. var layer = _f[_i];
  2871. layer.updateMode(mode);
  2872. }
  2873. if (!editId && isFromKeyboard) {
  2874. this.addNewEditorFromKeyboard();
  2875. return;
  2876. }
  2877. if (!editId) {
  2878. return;
  2879. }
  2880. for (var _g = 0, _h = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allEditors, "f").values(); _g < _h.length; _g++) {
  2881. var editor = _h[_g];
  2882. if (editor.annotationElementId === editId) {
  2883. this.setSelected(editor);
  2884. editor.enterInEditMode();
  2885. break;
  2886. }
  2887. }
  2888. };
  2889. AnnotationEditorUIManager.prototype.addNewEditorFromKeyboard = function () {
  2890. if (this.currentLayer.canCreateNewEmptyEditor()) {
  2891. this.currentLayer.addNewEditor();
  2892. }
  2893. };
  2894. AnnotationEditorUIManager.prototype.updateToolbar = function (mode) {
  2895. if (mode === tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_mode, "f")) {
  2896. return;
  2897. }
  2898. this._eventBus.dispatch("switchannotationeditormode", {
  2899. source: this,
  2900. mode: mode
  2901. });
  2902. };
  2903. AnnotationEditorUIManager.prototype.updateParams = function (type, value) {
  2904. var _f;
  2905. if (!tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_editorTypes, "f")) {
  2906. return;
  2907. }
  2908. switch (type) {
  2909. case AnnotationEditorParamsType.CREATE:
  2910. this.currentLayer.addNewEditor();
  2911. return;
  2912. case AnnotationEditorParamsType.HIGHLIGHT_DEFAULT_COLOR:
  2913. (_f = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_mainHighlightColorPicker, "f")) === null || _f === void 0 ? void 0 : _f.updateColor(value);
  2914. break;
  2915. case AnnotationEditorParamsType.HIGHLIGHT_SHOW_ALL:
  2916. this._eventBus.dispatch("reporttelemetry", {
  2917. source: this,
  2918. details: {
  2919. type: "editing",
  2920. data: {
  2921. type: "highlight",
  2922. action: "toggle_visibility"
  2923. }
  2924. }
  2925. });
  2926. (tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_showAllStates, tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_showAllStates, "f") || new Map(), "f")).set(type, value);
  2927. this.showAllEditors("highlight", value);
  2928. break;
  2929. }
  2930. for (var _i = 0, _g = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f"); _i < _g.length; _i++) {
  2931. var editor = _g[_i];
  2932. editor.updateParams(type, value);
  2933. }
  2934. for (var _h = 0, _j = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_editorTypes, "f"); _h < _j.length; _h++) {
  2935. var editorType = _j[_h];
  2936. editorType.updateDefaultParams(type, value);
  2937. }
  2938. };
  2939. AnnotationEditorUIManager.prototype.showAllEditors = function (type, visible, updateButton) {
  2940. var _f, _g;
  2941. if (updateButton === void 0) { updateButton = false; }
  2942. for (var _i = 0, _h = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allEditors, "f").values(); _i < _h.length; _i++) {
  2943. var editor = _h[_i];
  2944. if (editor.editorType === type) {
  2945. editor.show(visible);
  2946. }
  2947. }
  2948. var state = (_g = (_f = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_showAllStates, "f")) === null || _f === void 0 ? void 0 : _f.get(AnnotationEditorParamsType.HIGHLIGHT_SHOW_ALL)) !== null && _g !== void 0 ? _g : true;
  2949. if (state !== visible) {
  2950. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateUI).call(this, [[AnnotationEditorParamsType.HIGHLIGHT_SHOW_ALL, visible]]);
  2951. }
  2952. };
  2953. AnnotationEditorUIManager.prototype.enableWaiting = function (mustWait) {
  2954. if (mustWait === void 0) { mustWait = false; }
  2955. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_isWaiting, "f") === mustWait) {
  2956. return;
  2957. }
  2958. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_isWaiting, mustWait, "f");
  2959. for (var _i = 0, _f = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allLayers, "f").values(); _i < _f.length; _i++) {
  2960. var layer = _f[_i];
  2961. if (mustWait) {
  2962. layer.disableClick();
  2963. }
  2964. else {
  2965. layer.enableClick();
  2966. }
  2967. layer.div.classList.toggle("waiting", mustWait);
  2968. }
  2969. };
  2970. AnnotationEditorUIManager.prototype.getEditors = function (pageIndex) {
  2971. var editors = [];
  2972. for (var _i = 0, _f = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allEditors, "f").values(); _i < _f.length; _i++) {
  2973. var editor = _f[_i];
  2974. if (editor.pageIndex === pageIndex) {
  2975. editors.push(editor);
  2976. }
  2977. }
  2978. return editors;
  2979. };
  2980. AnnotationEditorUIManager.prototype.getEditor = function (id) {
  2981. return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allEditors, "f").get(id);
  2982. };
  2983. AnnotationEditorUIManager.prototype.addEditor = function (editor) {
  2984. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allEditors, "f").set(editor.id, editor);
  2985. };
  2986. AnnotationEditorUIManager.prototype.removeEditor = function (editor) {
  2987. var _this = this;
  2988. var _f;
  2989. if (editor.div.contains(document.activeElement)) {
  2990. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_focusMainContainerTimeoutId, "f")) {
  2991. clearTimeout(tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_focusMainContainerTimeoutId, "f"));
  2992. }
  2993. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_focusMainContainerTimeoutId, setTimeout(function () {
  2994. _this.focusMainContainer();
  2995. tslib_1.__classPrivateFieldSet(_this, _AnnotationEditorUIManager_focusMainContainerTimeoutId, null, "f");
  2996. }, 0), "f");
  2997. }
  2998. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allEditors, "f").delete(editor.id);
  2999. this.unselect(editor);
  3000. if (!editor.annotationElementId || !tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_deletedAnnotationsElementIds, "f").has(editor.annotationElementId)) {
  3001. (_f = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_annotationStorage, "f")) === null || _f === void 0 ? void 0 : _f.remove(editor.id);
  3002. }
  3003. };
  3004. AnnotationEditorUIManager.prototype.addDeletedAnnotationElement = function (editor) {
  3005. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_deletedAnnotationsElementIds, "f").add(editor.annotationElementId);
  3006. this.addChangedExistingAnnotation(editor);
  3007. editor.deleted = true;
  3008. };
  3009. AnnotationEditorUIManager.prototype.isDeletedAnnotationElement = function (annotationElementId) {
  3010. return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_deletedAnnotationsElementIds, "f").has(annotationElementId);
  3011. };
  3012. AnnotationEditorUIManager.prototype.removeDeletedAnnotationElement = function (editor) {
  3013. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_deletedAnnotationsElementIds, "f").delete(editor.annotationElementId);
  3014. this.removeChangedExistingAnnotation(editor);
  3015. editor.deleted = false;
  3016. };
  3017. AnnotationEditorUIManager.prototype.setActiveEditor = function (editor) {
  3018. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_activeEditor, "f") === editor) {
  3019. return;
  3020. }
  3021. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_activeEditor, editor, "f");
  3022. if (editor) {
  3023. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateUI).call(this, editor.propertiesToUpdate);
  3024. }
  3025. };
  3026. AnnotationEditorUIManager.prototype.updateUI = function (editor) {
  3027. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "a", _AnnotationEditorUIManager_lastSelectedEditor_get) === editor) {
  3028. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateUI).call(this, editor.propertiesToUpdate);
  3029. }
  3030. };
  3031. AnnotationEditorUIManager.prototype.toggleSelected = function (editor) {
  3032. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f").has(editor)) {
  3033. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f").delete(editor);
  3034. editor.unselect();
  3035. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateStates).call(this, {
  3036. hasSelectedEditor: this.hasSelection
  3037. });
  3038. return;
  3039. }
  3040. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f").add(editor);
  3041. editor.select();
  3042. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateUI).call(this, editor.propertiesToUpdate);
  3043. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateStates).call(this, {
  3044. hasSelectedEditor: true
  3045. });
  3046. };
  3047. AnnotationEditorUIManager.prototype.setSelected = function (editor) {
  3048. for (var _i = 0, _f = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f"); _i < _f.length; _i++) {
  3049. var ed = _f[_i];
  3050. if (ed !== editor) {
  3051. ed.unselect();
  3052. }
  3053. }
  3054. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f").clear();
  3055. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f").add(editor);
  3056. editor.select();
  3057. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateUI).call(this, editor.propertiesToUpdate);
  3058. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateStates).call(this, {
  3059. hasSelectedEditor: true
  3060. });
  3061. };
  3062. AnnotationEditorUIManager.prototype.isSelected = function (editor) {
  3063. return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f").has(editor);
  3064. };
  3065. Object.defineProperty(AnnotationEditorUIManager.prototype, "firstSelectedEditor", {
  3066. get: function () {
  3067. return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f").values().next().value;
  3068. },
  3069. enumerable: false,
  3070. configurable: true
  3071. });
  3072. AnnotationEditorUIManager.prototype.unselect = function (editor) {
  3073. editor.unselect();
  3074. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f").delete(editor);
  3075. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateStates).call(this, {
  3076. hasSelectedEditor: this.hasSelection
  3077. });
  3078. };
  3079. Object.defineProperty(AnnotationEditorUIManager.prototype, "hasSelection", {
  3080. get: function () {
  3081. return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f").size !== 0;
  3082. },
  3083. enumerable: false,
  3084. configurable: true
  3085. });
  3086. Object.defineProperty(AnnotationEditorUIManager.prototype, "isEnterHandled", {
  3087. get: function () {
  3088. return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f").size === 1 && this.firstSelectedEditor.isEnterHandled;
  3089. },
  3090. enumerable: false,
  3091. configurable: true
  3092. });
  3093. AnnotationEditorUIManager.prototype.undo = function () {
  3094. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_commandManager, "f").undo();
  3095. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateStates).call(this, {
  3096. hasSomethingToUndo: tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_commandManager, "f").hasSomethingToUndo(),
  3097. hasSomethingToRedo: true,
  3098. isEmpty: tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_isEmpty).call(this)
  3099. });
  3100. };
  3101. AnnotationEditorUIManager.prototype.redo = function () {
  3102. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_commandManager, "f").redo();
  3103. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateStates).call(this, {
  3104. hasSomethingToUndo: true,
  3105. hasSomethingToRedo: tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_commandManager, "f").hasSomethingToRedo(),
  3106. isEmpty: tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_isEmpty).call(this)
  3107. });
  3108. };
  3109. AnnotationEditorUIManager.prototype.addCommands = function (params) {
  3110. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_commandManager, "f").add(params);
  3111. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateStates).call(this, {
  3112. hasSomethingToUndo: true,
  3113. hasSomethingToRedo: false,
  3114. isEmpty: tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_isEmpty).call(this)
  3115. });
  3116. };
  3117. AnnotationEditorUIManager.prototype.delete = function () {
  3118. var _this = this;
  3119. this.commitOrRemove();
  3120. if (!this.hasSelection) {
  3121. return;
  3122. }
  3123. var editors = tslib_1.__spreadArray([], tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f"), true);
  3124. var cmd = function () {
  3125. for (var _i = 0, editors_1 = editors; _i < editors_1.length; _i++) {
  3126. var editor = editors_1[_i];
  3127. editor.remove();
  3128. }
  3129. };
  3130. var undo = function () {
  3131. for (var _i = 0, editors_2 = editors; _i < editors_2.length; _i++) {
  3132. var editor = editors_2[_i];
  3133. tslib_1.__classPrivateFieldGet(_this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_addEditorToLayer).call(_this, editor);
  3134. }
  3135. };
  3136. this.addCommands({
  3137. cmd: cmd,
  3138. undo: undo,
  3139. mustExec: true
  3140. });
  3141. };
  3142. AnnotationEditorUIManager.prototype.commitOrRemove = function () {
  3143. var _f;
  3144. (_f = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_activeEditor, "f")) === null || _f === void 0 ? void 0 : _f.commitOrRemove();
  3145. };
  3146. AnnotationEditorUIManager.prototype.hasSomethingToControl = function () {
  3147. return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_activeEditor, "f") || this.hasSelection;
  3148. };
  3149. AnnotationEditorUIManager.prototype.selectAll = function () {
  3150. for (var _i = 0, _f = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f"); _i < _f.length; _i++) {
  3151. var editor = _f[_i];
  3152. editor.commit();
  3153. }
  3154. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_selectEditors).call(this, tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allEditors, "f").values());
  3155. };
  3156. AnnotationEditorUIManager.prototype.unselectAll = function () {
  3157. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_activeEditor, "f")) {
  3158. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_activeEditor, "f").commitOrRemove();
  3159. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_mode, "f") !== AnnotationEditorType.NONE) {
  3160. return;
  3161. }
  3162. }
  3163. if (!this.hasSelection) {
  3164. return;
  3165. }
  3166. for (var _i = 0, _f = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f"); _i < _f.length; _i++) {
  3167. var editor = _f[_i];
  3168. editor.unselect();
  3169. }
  3170. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f").clear();
  3171. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateStates).call(this, {
  3172. hasSelectedEditor: false
  3173. });
  3174. };
  3175. AnnotationEditorUIManager.prototype.translateSelectedEditors = function (x, y, noCommit) {
  3176. var _this = this;
  3177. if (noCommit === void 0) { noCommit = false; }
  3178. if (!noCommit) {
  3179. this.commitOrRemove();
  3180. }
  3181. if (!this.hasSelection) {
  3182. return;
  3183. }
  3184. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_translation, "f")[0] += x;
  3185. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_translation, "f")[1] += y;
  3186. var _f = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_translation, "f"), totalX = _f[0], totalY = _f[1];
  3187. var editors = tslib_1.__spreadArray([], tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f"), true);
  3188. var TIME_TO_WAIT = 1000;
  3189. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_translationTimeoutId, "f")) {
  3190. clearTimeout(tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_translationTimeoutId, "f"));
  3191. }
  3192. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_translationTimeoutId, setTimeout(function () {
  3193. tslib_1.__classPrivateFieldSet(_this, _AnnotationEditorUIManager_translationTimeoutId, null, "f");
  3194. tslib_1.__classPrivateFieldGet(_this, _AnnotationEditorUIManager_translation, "f")[0] = tslib_1.__classPrivateFieldGet(_this, _AnnotationEditorUIManager_translation, "f")[1] = 0;
  3195. _this.addCommands({
  3196. cmd: function () {
  3197. for (var _i = 0, editors_4 = editors; _i < editors_4.length; _i++) {
  3198. var editor = editors_4[_i];
  3199. if (tslib_1.__classPrivateFieldGet(_this, _AnnotationEditorUIManager_allEditors, "f").has(editor.id)) {
  3200. editor.translateInPage(totalX, totalY);
  3201. }
  3202. }
  3203. },
  3204. undo: function () {
  3205. for (var _i = 0, editors_5 = editors; _i < editors_5.length; _i++) {
  3206. var editor = editors_5[_i];
  3207. if (tslib_1.__classPrivateFieldGet(_this, _AnnotationEditorUIManager_allEditors, "f").has(editor.id)) {
  3208. editor.translateInPage(-totalX, -totalY);
  3209. }
  3210. }
  3211. },
  3212. mustExec: false
  3213. });
  3214. }, TIME_TO_WAIT), "f");
  3215. for (var _i = 0, editors_3 = editors; _i < editors_3.length; _i++) {
  3216. var editor = editors_3[_i];
  3217. editor.translateInPage(x, y);
  3218. }
  3219. };
  3220. AnnotationEditorUIManager.prototype.setUpDragSession = function () {
  3221. if (!this.hasSelection) {
  3222. return;
  3223. }
  3224. this.disableUserSelect(true);
  3225. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_draggingEditors, new Map(), "f");
  3226. for (var _i = 0, _f = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f"); _i < _f.length; _i++) {
  3227. var editor = _f[_i];
  3228. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_draggingEditors, "f").set(editor, {
  3229. savedX: editor.x,
  3230. savedY: editor.y,
  3231. savedPageIndex: editor.pageIndex,
  3232. newX: 0,
  3233. newY: 0,
  3234. newPageIndex: -1
  3235. });
  3236. }
  3237. };
  3238. AnnotationEditorUIManager.prototype.endDragSession = function () {
  3239. var _this = this;
  3240. if (!tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_draggingEditors, "f")) {
  3241. return false;
  3242. }
  3243. this.disableUserSelect(false);
  3244. var map = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_draggingEditors, "f");
  3245. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_draggingEditors, null, "f");
  3246. var mustBeAddedInUndoStack = false;
  3247. for (var _i = 0, map_2 = map; _i < map_2.length; _i++) {
  3248. var _f = map_2[_i], _g = _f[0], x = _g.x, y = _g.y, pageIndex = _g.pageIndex, value = _f[1];
  3249. value.newX = x;
  3250. value.newY = y;
  3251. value.newPageIndex = pageIndex;
  3252. mustBeAddedInUndoStack || (mustBeAddedInUndoStack = x !== value.savedX || y !== value.savedY || pageIndex !== value.savedPageIndex);
  3253. }
  3254. if (!mustBeAddedInUndoStack) {
  3255. return false;
  3256. }
  3257. var move = function (editor, x, y, pageIndex) {
  3258. if (tslib_1.__classPrivateFieldGet(_this, _AnnotationEditorUIManager_allEditors, "f").has(editor.id)) {
  3259. var parent = tslib_1.__classPrivateFieldGet(_this, _AnnotationEditorUIManager_allLayers, "f").get(pageIndex);
  3260. if (parent) {
  3261. editor._setParentAndPosition(parent, x, y);
  3262. }
  3263. else {
  3264. editor.pageIndex = pageIndex;
  3265. editor.x = x;
  3266. editor.y = y;
  3267. }
  3268. }
  3269. };
  3270. this.addCommands({
  3271. cmd: function () {
  3272. for (var _i = 0, map_3 = map; _i < map_3.length; _i++) {
  3273. var _f = map_3[_i], editor = _f[0], _g = _f[1], newX = _g.newX, newY = _g.newY, newPageIndex = _g.newPageIndex;
  3274. move(editor, newX, newY, newPageIndex);
  3275. }
  3276. },
  3277. undo: function () {
  3278. for (var _i = 0, map_4 = map; _i < map_4.length; _i++) {
  3279. var _f = map_4[_i], editor = _f[0], _g = _f[1], savedX = _g.savedX, savedY = _g.savedY, savedPageIndex = _g.savedPageIndex;
  3280. move(editor, savedX, savedY, savedPageIndex);
  3281. }
  3282. },
  3283. mustExec: true
  3284. });
  3285. return true;
  3286. };
  3287. AnnotationEditorUIManager.prototype.dragSelectedEditors = function (tx, ty) {
  3288. if (!tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_draggingEditors, "f")) {
  3289. return;
  3290. }
  3291. for (var _i = 0, _f = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_draggingEditors, "f").keys(); _i < _f.length; _i++) {
  3292. var editor = _f[_i];
  3293. editor.drag(tx, ty);
  3294. }
  3295. };
  3296. AnnotationEditorUIManager.prototype.rebuild = function (editor) {
  3297. if (editor.parent === null) {
  3298. var parent = this.getLayer(editor.pageIndex);
  3299. if (parent) {
  3300. parent.changeParent(editor);
  3301. parent.addOrRebuild(editor);
  3302. }
  3303. else {
  3304. this.addEditor(editor);
  3305. this.addToAnnotationStorage(editor);
  3306. editor.rebuild();
  3307. }
  3308. }
  3309. else {
  3310. editor.parent.addOrRebuild(editor);
  3311. }
  3312. };
  3313. Object.defineProperty(AnnotationEditorUIManager.prototype, "isEditorHandlingKeyboard", {
  3314. get: function () {
  3315. var _f;
  3316. return ((_f = this.getActive()) === null || _f === void 0 ? void 0 : _f.shouldGetKeyboardEvents()) || tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f").size === 1 && this.firstSelectedEditor.shouldGetKeyboardEvents();
  3317. },
  3318. enumerable: false,
  3319. configurable: true
  3320. });
  3321. AnnotationEditorUIManager.prototype.isActive = function (editor) {
  3322. return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_activeEditor, "f") === editor;
  3323. };
  3324. AnnotationEditorUIManager.prototype.getActive = function () {
  3325. return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_activeEditor, "f");
  3326. };
  3327. AnnotationEditorUIManager.prototype.getMode = function () {
  3328. return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_mode, "f");
  3329. };
  3330. Object.defineProperty(AnnotationEditorUIManager.prototype, "imageManager", {
  3331. get: function () {
  3332. return shadow(this, "imageManager", new ImageManager());
  3333. },
  3334. enumerable: false,
  3335. configurable: true
  3336. });
  3337. AnnotationEditorUIManager.prototype.getSelectionBoxes = function (textLayer) {
  3338. if (!textLayer) {
  3339. return null;
  3340. }
  3341. var selection = document.getSelection();
  3342. for (var i = 0, ii = selection.rangeCount; i < ii; i++) {
  3343. if (!textLayer.contains(selection.getRangeAt(i).commonAncestorContainer)) {
  3344. return null;
  3345. }
  3346. }
  3347. var _f = textLayer.getBoundingClientRect(), layerX = _f.x, layerY = _f.y, parentWidth = _f.width, parentHeight = _f.height;
  3348. var rotator;
  3349. switch (textLayer.getAttribute("data-main-rotation")) {
  3350. case "90":
  3351. rotator = function (x, y, w, h) { return ({
  3352. x: (y - layerY) / parentHeight,
  3353. y: 1 - (x + w - layerX) / parentWidth,
  3354. width: h / parentHeight,
  3355. height: w / parentWidth
  3356. }); };
  3357. break;
  3358. case "180":
  3359. rotator = function (x, y, w, h) { return ({
  3360. x: 1 - (x + w - layerX) / parentWidth,
  3361. y: 1 - (y + h - layerY) / parentHeight,
  3362. width: w / parentWidth,
  3363. height: h / parentHeight
  3364. }); };
  3365. break;
  3366. case "270":
  3367. rotator = function (x, y, w, h) { return ({
  3368. x: 1 - (y + h - layerY) / parentHeight,
  3369. y: (x - layerX) / parentWidth,
  3370. width: h / parentHeight,
  3371. height: w / parentWidth
  3372. }); };
  3373. break;
  3374. default:
  3375. rotator = function (x, y, w, h) { return ({
  3376. x: (x - layerX) / parentWidth,
  3377. y: (y - layerY) / parentHeight,
  3378. width: w / parentWidth,
  3379. height: h / parentHeight
  3380. }); };
  3381. break;
  3382. }
  3383. var boxes = [];
  3384. for (var i = 0, ii = selection.rangeCount; i < ii; i++) {
  3385. var range = selection.getRangeAt(i);
  3386. if (range.collapsed) {
  3387. continue;
  3388. }
  3389. for (var _i = 0, _g = range.getClientRects(); _i < _g.length; _i++) {
  3390. var _h = _g[_i], x = _h.x, y = _h.y, width = _h.width, height = _h.height;
  3391. if (width === 0 || height === 0) {
  3392. continue;
  3393. }
  3394. boxes.push(rotator(x, y, width, height));
  3395. }
  3396. }
  3397. return boxes.length === 0 ? null : boxes;
  3398. };
  3399. AnnotationEditorUIManager.prototype.addChangedExistingAnnotation = function (_f) {
  3400. var annotationElementId = _f.annotationElementId, id = _f.id;
  3401. (tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_changedExistingAnnotations, tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_changedExistingAnnotations, "f") || new Map(), "f")).set(annotationElementId, id);
  3402. };
  3403. AnnotationEditorUIManager.prototype.removeChangedExistingAnnotation = function (_f) {
  3404. var _g;
  3405. var annotationElementId = _f.annotationElementId;
  3406. (_g = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_changedExistingAnnotations, "f")) === null || _g === void 0 ? void 0 : _g.delete(annotationElementId);
  3407. };
  3408. AnnotationEditorUIManager.prototype.renderAnnotationElement = function (annotation) {
  3409. var _f;
  3410. var editorId = (_f = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_changedExistingAnnotations, "f")) === null || _f === void 0 ? void 0 : _f.get(annotation.data.id);
  3411. if (!editorId) {
  3412. return;
  3413. }
  3414. var editor = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_annotationStorage, "f").getRawValue(editorId);
  3415. if (!editor) {
  3416. return;
  3417. }
  3418. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_mode, "f") === AnnotationEditorType.NONE && !editor.hasBeenModified) {
  3419. return;
  3420. }
  3421. editor.renderAnnotationElement(annotation);
  3422. };
  3423. var _AnnotationEditorUIManager_instances, _AnnotationEditorUIManager_activeEditor, _AnnotationEditorUIManager_allEditors, _AnnotationEditorUIManager_allLayers, _AnnotationEditorUIManager_altTextManager, _AnnotationEditorUIManager_annotationStorage, _AnnotationEditorUIManager_changedExistingAnnotations, _AnnotationEditorUIManager_commandManager, _AnnotationEditorUIManager_currentPageIndex, _AnnotationEditorUIManager_deletedAnnotationsElementIds, _AnnotationEditorUIManager_draggingEditors, _AnnotationEditorUIManager_editorTypes, _AnnotationEditorUIManager_editorsToRescale, _AnnotationEditorUIManager_enableHighlightFloatingButton, _AnnotationEditorUIManager_filterFactory, _AnnotationEditorUIManager_focusMainContainerTimeoutId, _AnnotationEditorUIManager_highlightColors, _AnnotationEditorUIManager_highlightWhenShiftUp, _AnnotationEditorUIManager_highlightToolbar, _AnnotationEditorUIManager_idManager, _AnnotationEditorUIManager_isEnabled, _AnnotationEditorUIManager_isWaiting, _AnnotationEditorUIManager_lastActiveElement, _AnnotationEditorUIManager_mainHighlightColorPicker, _AnnotationEditorUIManager_mlManager, _AnnotationEditorUIManager_mode, _AnnotationEditorUIManager_selectedEditors, _AnnotationEditorUIManager_selectedTextNode, _AnnotationEditorUIManager_pageColors, _AnnotationEditorUIManager_showAllStates, _AnnotationEditorUIManager_boundBlur, _AnnotationEditorUIManager_boundFocus, _AnnotationEditorUIManager_boundCopy, _AnnotationEditorUIManager_boundCut, _AnnotationEditorUIManager_boundPaste, _AnnotationEditorUIManager_boundKeydown, _AnnotationEditorUIManager_boundKeyup, _AnnotationEditorUIManager_boundOnEditingAction, _AnnotationEditorUIManager_boundOnPageChanging, _AnnotationEditorUIManager_boundOnScaleChanging, _AnnotationEditorUIManager_boundSelectionChange, _AnnotationEditorUIManager_boundOnRotationChanging, _AnnotationEditorUIManager_previousStates, _AnnotationEditorUIManager_translation, _AnnotationEditorUIManager_translationTimeoutId, _AnnotationEditorUIManager_container, _AnnotationEditorUIManager_viewer, _AnnotationEditorUIManager_getAnchorElementForSelection, _AnnotationEditorUIManager_displayHighlightToolbar, _AnnotationEditorUIManager_selectionChange, _AnnotationEditorUIManager_onSelectEnd, _AnnotationEditorUIManager_addSelectionListener, _AnnotationEditorUIManager_removeSelectionListener, _AnnotationEditorUIManager_addFocusManager, _AnnotationEditorUIManager_removeFocusManager, _AnnotationEditorUIManager_addKeyboardManager, _AnnotationEditorUIManager_removeKeyboardManager, _AnnotationEditorUIManager_addCopyPasteListeners, _AnnotationEditorUIManager_removeCopyPasteListeners, _AnnotationEditorUIManager_dispatchUpdateStates, _AnnotationEditorUIManager_dispatchUpdateUI, _AnnotationEditorUIManager_enableAll, _AnnotationEditorUIManager_disableAll, _AnnotationEditorUIManager_addEditorToLayer, _AnnotationEditorUIManager_lastSelectedEditor_get, _AnnotationEditorUIManager_isEmpty, _AnnotationEditorUIManager_selectEditors;
  3424. _AnnotationEditorUIManager_activeEditor = new WeakMap(), _AnnotationEditorUIManager_allEditors = new WeakMap(), _AnnotationEditorUIManager_allLayers = new WeakMap(), _AnnotationEditorUIManager_altTextManager = new WeakMap(), _AnnotationEditorUIManager_annotationStorage = new WeakMap(), _AnnotationEditorUIManager_changedExistingAnnotations = new WeakMap(), _AnnotationEditorUIManager_commandManager = new WeakMap(), _AnnotationEditorUIManager_currentPageIndex = new WeakMap(), _AnnotationEditorUIManager_deletedAnnotationsElementIds = new WeakMap(), _AnnotationEditorUIManager_draggingEditors = new WeakMap(), _AnnotationEditorUIManager_editorTypes = new WeakMap(), _AnnotationEditorUIManager_editorsToRescale = new WeakMap(), _AnnotationEditorUIManager_enableHighlightFloatingButton = new WeakMap(), _AnnotationEditorUIManager_filterFactory = new WeakMap(), _AnnotationEditorUIManager_focusMainContainerTimeoutId = new WeakMap(), _AnnotationEditorUIManager_highlightColors = new WeakMap(), _AnnotationEditorUIManager_highlightWhenShiftUp = new WeakMap(), _AnnotationEditorUIManager_highlightToolbar = new WeakMap(), _AnnotationEditorUIManager_idManager = new WeakMap(), _AnnotationEditorUIManager_isEnabled = new WeakMap(), _AnnotationEditorUIManager_isWaiting = new WeakMap(), _AnnotationEditorUIManager_lastActiveElement = new WeakMap(), _AnnotationEditorUIManager_mainHighlightColorPicker = new WeakMap(), _AnnotationEditorUIManager_mlManager = new WeakMap(), _AnnotationEditorUIManager_mode = new WeakMap(), _AnnotationEditorUIManager_selectedEditors = new WeakMap(), _AnnotationEditorUIManager_selectedTextNode = new WeakMap(), _AnnotationEditorUIManager_pageColors = new WeakMap(), _AnnotationEditorUIManager_showAllStates = new WeakMap(), _AnnotationEditorUIManager_boundBlur = new WeakMap(), _AnnotationEditorUIManager_boundFocus = new WeakMap(), _AnnotationEditorUIManager_boundCopy = new WeakMap(), _AnnotationEditorUIManager_boundCut = new WeakMap(), _AnnotationEditorUIManager_boundPaste = new WeakMap(), _AnnotationEditorUIManager_boundKeydown = new WeakMap(), _AnnotationEditorUIManager_boundKeyup = new WeakMap(), _AnnotationEditorUIManager_boundOnEditingAction = new WeakMap(), _AnnotationEditorUIManager_boundOnPageChanging = new WeakMap(), _AnnotationEditorUIManager_boundOnScaleChanging = new WeakMap(), _AnnotationEditorUIManager_boundSelectionChange = new WeakMap(), _AnnotationEditorUIManager_boundOnRotationChanging = new WeakMap(), _AnnotationEditorUIManager_previousStates = new WeakMap(), _AnnotationEditorUIManager_translation = new WeakMap(), _AnnotationEditorUIManager_translationTimeoutId = new WeakMap(), _AnnotationEditorUIManager_container = new WeakMap(), _AnnotationEditorUIManager_viewer = new WeakMap(), _AnnotationEditorUIManager_instances = new WeakSet(), _AnnotationEditorUIManager_getAnchorElementForSelection = function _AnnotationEditorUIManager_getAnchorElementForSelection(_f) {
  3425. var anchorNode = _f.anchorNode;
  3426. return anchorNode.nodeType === Node.TEXT_NODE ? anchorNode.parentElement : anchorNode;
  3427. }, _AnnotationEditorUIManager_displayHighlightToolbar = function _AnnotationEditorUIManager_displayHighlightToolbar() {
  3428. var selection = document.getSelection();
  3429. if (!selection || selection.isCollapsed) {
  3430. return;
  3431. }
  3432. var anchorElement = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_getAnchorElementForSelection).call(this, selection);
  3433. var textLayer = anchorElement.closest(".textLayer");
  3434. var boxes = this.getSelectionBoxes(textLayer);
  3435. if (!boxes) {
  3436. return;
  3437. }
  3438. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_highlightToolbar, tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_highlightToolbar, "f") || new HighlightToolbar(this), "f");
  3439. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_highlightToolbar, "f").show(textLayer, boxes, this.direction === "ltr");
  3440. }, _AnnotationEditorUIManager_selectionChange = function _AnnotationEditorUIManager_selectionChange() {
  3441. var _this = this;
  3442. var _f, _g, _h;
  3443. var selection = document.getSelection();
  3444. if (!selection || selection.isCollapsed) {
  3445. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedTextNode, "f")) {
  3446. (_f = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_highlightToolbar, "f")) === null || _f === void 0 ? void 0 : _f.hide();
  3447. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_selectedTextNode, null, "f");
  3448. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateStates).call(this, {
  3449. hasSelectedText: false
  3450. });
  3451. }
  3452. return;
  3453. }
  3454. var anchorNode = selection.anchorNode;
  3455. if (anchorNode === tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedTextNode, "f")) {
  3456. return;
  3457. }
  3458. var anchorElement = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_getAnchorElementForSelection).call(this, selection);
  3459. var textLayer = anchorElement.closest(".textLayer");
  3460. if (!textLayer) {
  3461. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedTextNode, "f")) {
  3462. (_g = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_highlightToolbar, "f")) === null || _g === void 0 ? void 0 : _g.hide();
  3463. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_selectedTextNode, null, "f");
  3464. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateStates).call(this, {
  3465. hasSelectedText: false
  3466. });
  3467. }
  3468. return;
  3469. }
  3470. (_h = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_highlightToolbar, "f")) === null || _h === void 0 ? void 0 : _h.hide();
  3471. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_selectedTextNode, anchorNode, "f");
  3472. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateStates).call(this, {
  3473. hasSelectedText: true
  3474. });
  3475. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_mode, "f") !== AnnotationEditorType.HIGHLIGHT && tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_mode, "f") !== AnnotationEditorType.NONE) {
  3476. return;
  3477. }
  3478. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_mode, "f") === AnnotationEditorType.HIGHLIGHT) {
  3479. this.showAllEditors("highlight", true, true);
  3480. }
  3481. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_highlightWhenShiftUp, this.isShiftKeyDown, "f");
  3482. if (!this.isShiftKeyDown) {
  3483. var pointerup_1 = function (e) {
  3484. if (e.type === "pointerup" && e.button !== 0) {
  3485. return;
  3486. }
  3487. window.removeEventListener("pointerup", pointerup_1);
  3488. window.removeEventListener("blur", pointerup_1);
  3489. if (e.type === "pointerup") {
  3490. tslib_1.__classPrivateFieldGet(_this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_onSelectEnd).call(_this, "main_toolbar");
  3491. }
  3492. };
  3493. window.addEventListener("pointerup", pointerup_1);
  3494. window.addEventListener("blur", pointerup_1);
  3495. }
  3496. }, _AnnotationEditorUIManager_onSelectEnd = function _AnnotationEditorUIManager_onSelectEnd(methodOfCreation) {
  3497. if (methodOfCreation === void 0) { methodOfCreation = ""; }
  3498. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_mode, "f") === AnnotationEditorType.HIGHLIGHT) {
  3499. this.highlightSelection(methodOfCreation);
  3500. }
  3501. else if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_enableHighlightFloatingButton, "f")) {
  3502. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_displayHighlightToolbar).call(this);
  3503. }
  3504. }, _AnnotationEditorUIManager_addSelectionListener = function _AnnotationEditorUIManager_addSelectionListener() {
  3505. document.addEventListener("selectionchange", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_boundSelectionChange, "f"));
  3506. }, _AnnotationEditorUIManager_removeSelectionListener = function _AnnotationEditorUIManager_removeSelectionListener() {
  3507. document.removeEventListener("selectionchange", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_boundSelectionChange, "f"));
  3508. }, _AnnotationEditorUIManager_addFocusManager = function _AnnotationEditorUIManager_addFocusManager() {
  3509. window.addEventListener("focus", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_boundFocus, "f"));
  3510. window.addEventListener("blur", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_boundBlur, "f"));
  3511. }, _AnnotationEditorUIManager_removeFocusManager = function _AnnotationEditorUIManager_removeFocusManager() {
  3512. window.removeEventListener("focus", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_boundFocus, "f"));
  3513. window.removeEventListener("blur", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_boundBlur, "f"));
  3514. }, _AnnotationEditorUIManager_addKeyboardManager = function _AnnotationEditorUIManager_addKeyboardManager() {
  3515. window.addEventListener("keydown", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_boundKeydown, "f"));
  3516. window.addEventListener("keyup", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_boundKeyup, "f"));
  3517. }, _AnnotationEditorUIManager_removeKeyboardManager = function _AnnotationEditorUIManager_removeKeyboardManager() {
  3518. window.removeEventListener("keydown", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_boundKeydown, "f"));
  3519. window.removeEventListener("keyup", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_boundKeyup, "f"));
  3520. }, _AnnotationEditorUIManager_addCopyPasteListeners = function _AnnotationEditorUIManager_addCopyPasteListeners() {
  3521. document.addEventListener("copy", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_boundCopy, "f"));
  3522. document.addEventListener("cut", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_boundCut, "f"));
  3523. document.addEventListener("paste", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_boundPaste, "f"));
  3524. }, _AnnotationEditorUIManager_removeCopyPasteListeners = function _AnnotationEditorUIManager_removeCopyPasteListeners() {
  3525. document.removeEventListener("copy", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_boundCopy, "f"));
  3526. document.removeEventListener("cut", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_boundCut, "f"));
  3527. document.removeEventListener("paste", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_boundPaste, "f"));
  3528. }, _AnnotationEditorUIManager_dispatchUpdateStates = function _AnnotationEditorUIManager_dispatchUpdateStates(details) {
  3529. var _this = this;
  3530. var hasChanged = Object.entries(details).some(function (_f) {
  3531. var key = _f[0], value = _f[1];
  3532. return tslib_1.__classPrivateFieldGet(_this, _AnnotationEditorUIManager_previousStates, "f")[key] !== value;
  3533. });
  3534. if (hasChanged) {
  3535. this._eventBus.dispatch("annotationeditorstateschanged", {
  3536. source: this,
  3537. details: Object.assign(tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_previousStates, "f"), details)
  3538. });
  3539. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_mode, "f") === AnnotationEditorType.HIGHLIGHT && details.hasSelectedEditor === false) {
  3540. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateUI).call(this, [[AnnotationEditorParamsType.HIGHLIGHT_FREE, true]]);
  3541. }
  3542. }
  3543. }, _AnnotationEditorUIManager_dispatchUpdateUI = function _AnnotationEditorUIManager_dispatchUpdateUI(details) {
  3544. this._eventBus.dispatch("annotationeditorparamschanged", {
  3545. source: this,
  3546. details: details
  3547. });
  3548. }, _AnnotationEditorUIManager_enableAll = function _AnnotationEditorUIManager_enableAll() {
  3549. if (!tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_isEnabled, "f")) {
  3550. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_isEnabled, true, "f");
  3551. for (var _i = 0, _f = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allLayers, "f").values(); _i < _f.length; _i++) {
  3552. var layer = _f[_i];
  3553. layer.enable();
  3554. }
  3555. for (var _g = 0, _h = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allEditors, "f").values(); _g < _h.length; _g++) {
  3556. var editor = _h[_g];
  3557. editor.enable();
  3558. }
  3559. }
  3560. }, _AnnotationEditorUIManager_disableAll = function _AnnotationEditorUIManager_disableAll() {
  3561. this.unselectAll();
  3562. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_isEnabled, "f")) {
  3563. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_isEnabled, false, "f");
  3564. for (var _i = 0, _f = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allLayers, "f").values(); _i < _f.length; _i++) {
  3565. var layer = _f[_i];
  3566. layer.disable();
  3567. }
  3568. for (var _g = 0, _h = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allEditors, "f").values(); _g < _h.length; _g++) {
  3569. var editor = _h[_g];
  3570. editor.disable();
  3571. }
  3572. }
  3573. }, _AnnotationEditorUIManager_addEditorToLayer = function _AnnotationEditorUIManager_addEditorToLayer(editor) {
  3574. var layer = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allLayers, "f").get(editor.pageIndex);
  3575. if (layer) {
  3576. layer.addOrRebuild(editor);
  3577. }
  3578. else {
  3579. this.addEditor(editor);
  3580. this.addToAnnotationStorage(editor);
  3581. }
  3582. }, _AnnotationEditorUIManager_lastSelectedEditor_get = function _AnnotationEditorUIManager_lastSelectedEditor_get() {
  3583. var ed = null;
  3584. for (var _i = 0, _f = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f"); _i < _f.length; _i++) {
  3585. ed = _f[_i];
  3586. }
  3587. return ed;
  3588. }, _AnnotationEditorUIManager_isEmpty = function _AnnotationEditorUIManager_isEmpty() {
  3589. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allEditors, "f").size === 0) {
  3590. return true;
  3591. }
  3592. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allEditors, "f").size === 1) {
  3593. for (var _i = 0, _f = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allEditors, "f").values(); _i < _f.length; _i++) {
  3594. var editor = _f[_i];
  3595. return editor.isEmpty();
  3596. }
  3597. }
  3598. return false;
  3599. }, _AnnotationEditorUIManager_selectEditors = function _AnnotationEditorUIManager_selectEditors(editors) {
  3600. for (var _i = 0, _f = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f"); _i < _f.length; _i++) {
  3601. var editor = _f[_i];
  3602. editor.unselect();
  3603. }
  3604. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f").clear();
  3605. for (var _g = 0, editors_6 = editors; _g < editors_6.length; _g++) {
  3606. var editor = editors_6[_g];
  3607. if (editor.isEmpty()) {
  3608. continue;
  3609. }
  3610. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f").add(editor);
  3611. editor.select();
  3612. }
  3613. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateStates).call(this, {
  3614. hasSelectedEditor: this.hasSelection
  3615. });
  3616. };
  3617. AnnotationEditorUIManager.TRANSLATE_SMALL = 1;
  3618. AnnotationEditorUIManager.TRANSLATE_BIG = 10;
  3619. return AnnotationEditorUIManager;
  3620. }());
  3621. ; // CONCATENATED MODULE: ./src/display/editor/alt_text.js
  3622. var AltText = /** @class */ (function () {
  3623. function AltText(editor) {
  3624. _AltText_instances.add(this);
  3625. _AltText_altText.set(this, "");
  3626. _AltText_altTextDecorative.set(this, false);
  3627. _AltText_altTextButton.set(this, null);
  3628. _AltText_altTextTooltip.set(this, null);
  3629. _AltText_altTextTooltipTimeout.set(this, null);
  3630. _AltText_altTextWasFromKeyBoard.set(this, false);
  3631. _AltText_editor.set(this, null);
  3632. tslib_1.__classPrivateFieldSet(this, _AltText_editor, editor, "f");
  3633. }
  3634. AltText.initialize = function (l10nPromise) {
  3635. AltText._l10nPromise || (AltText._l10nPromise = l10nPromise);
  3636. };
  3637. AltText.prototype.render = function () {
  3638. return tslib_1.__awaiter(this, void 0, void 0, function () {
  3639. var altText, msg, onClick;
  3640. var _this = this;
  3641. return tslib_1.__generator(this, function (_f) {
  3642. switch (_f.label) {
  3643. case 0:
  3644. altText = tslib_1.__classPrivateFieldSet(this, _AltText_altTextButton, document.createElement("button"), "f");
  3645. altText.className = "altText";
  3646. return [4 /*yield*/, AltText._l10nPromise.get("pdfjs-editor-alt-text-button-label")];
  3647. case 1:
  3648. msg = _f.sent();
  3649. altText.textContent = msg;
  3650. altText.setAttribute("aria-label", msg);
  3651. altText.tabIndex = "0";
  3652. altText.addEventListener("contextmenu", noContextMenu);
  3653. altText.addEventListener("pointerdown", function (event) { return event.stopPropagation(); });
  3654. onClick = function (event) {
  3655. event.preventDefault();
  3656. tslib_1.__classPrivateFieldGet(_this, _AltText_editor, "f")._uiManager.editAltText(tslib_1.__classPrivateFieldGet(_this, _AltText_editor, "f"));
  3657. };
  3658. altText.addEventListener("click", onClick, {
  3659. capture: true
  3660. });
  3661. altText.addEventListener("keydown", function (event) {
  3662. if (event.target === altText && event.key === "Enter") {
  3663. tslib_1.__classPrivateFieldSet(_this, _AltText_altTextWasFromKeyBoard, true, "f");
  3664. onClick(event);
  3665. }
  3666. });
  3667. return [4 /*yield*/, tslib_1.__classPrivateFieldGet(this, _AltText_instances, "m", _AltText_setState).call(this)];
  3668. case 2:
  3669. _f.sent();
  3670. return [2 /*return*/, altText];
  3671. }
  3672. });
  3673. });
  3674. };
  3675. AltText.prototype.finish = function () {
  3676. if (!tslib_1.__classPrivateFieldGet(this, _AltText_altTextButton, "f")) {
  3677. return;
  3678. }
  3679. tslib_1.__classPrivateFieldGet(this, _AltText_altTextButton, "f").focus({
  3680. focusVisible: tslib_1.__classPrivateFieldGet(this, _AltText_altTextWasFromKeyBoard, "f")
  3681. });
  3682. tslib_1.__classPrivateFieldSet(this, _AltText_altTextWasFromKeyBoard, false, "f");
  3683. };
  3684. AltText.prototype.isEmpty = function () {
  3685. return !tslib_1.__classPrivateFieldGet(this, _AltText_altText, "f") && !tslib_1.__classPrivateFieldGet(this, _AltText_altTextDecorative, "f");
  3686. };
  3687. Object.defineProperty(AltText.prototype, "data", {
  3688. get: function () {
  3689. return {
  3690. altText: tslib_1.__classPrivateFieldGet(this, _AltText_altText, "f"),
  3691. decorative: tslib_1.__classPrivateFieldGet(this, _AltText_altTextDecorative, "f")
  3692. };
  3693. },
  3694. set: function (_f) {
  3695. var altText = _f.altText, decorative = _f.decorative;
  3696. if (tslib_1.__classPrivateFieldGet(this, _AltText_altText, "f") === altText && tslib_1.__classPrivateFieldGet(this, _AltText_altTextDecorative, "f") === decorative) {
  3697. return;
  3698. }
  3699. tslib_1.__classPrivateFieldSet(this, _AltText_altText, altText, "f");
  3700. tslib_1.__classPrivateFieldSet(this, _AltText_altTextDecorative, decorative, "f");
  3701. tslib_1.__classPrivateFieldGet(this, _AltText_instances, "m", _AltText_setState).call(this);
  3702. },
  3703. enumerable: false,
  3704. configurable: true
  3705. });
  3706. AltText.prototype.toggle = function (enabled) {
  3707. if (enabled === void 0) { enabled = false; }
  3708. if (!tslib_1.__classPrivateFieldGet(this, _AltText_altTextButton, "f")) {
  3709. return;
  3710. }
  3711. if (!enabled && tslib_1.__classPrivateFieldGet(this, _AltText_altTextTooltipTimeout, "f")) {
  3712. clearTimeout(tslib_1.__classPrivateFieldGet(this, _AltText_altTextTooltipTimeout, "f"));
  3713. tslib_1.__classPrivateFieldSet(this, _AltText_altTextTooltipTimeout, null, "f");
  3714. }
  3715. tslib_1.__classPrivateFieldGet(this, _AltText_altTextButton, "f").disabled = !enabled;
  3716. };
  3717. AltText.prototype.destroy = function () {
  3718. var _f;
  3719. (_f = tslib_1.__classPrivateFieldGet(this, _AltText_altTextButton, "f")) === null || _f === void 0 ? void 0 : _f.remove();
  3720. tslib_1.__classPrivateFieldSet(this, _AltText_altTextButton, null, "f");
  3721. tslib_1.__classPrivateFieldSet(this, _AltText_altTextTooltip, null, "f");
  3722. };
  3723. var _AltText_instances, _AltText_altText, _AltText_altTextDecorative, _AltText_altTextButton, _AltText_altTextTooltip, _AltText_altTextTooltipTimeout, _AltText_altTextWasFromKeyBoard, _AltText_editor, _AltText_setState;
  3724. _AltText_altText = new WeakMap(), _AltText_altTextDecorative = new WeakMap(), _AltText_altTextButton = new WeakMap(), _AltText_altTextTooltip = new WeakMap(), _AltText_altTextTooltipTimeout = new WeakMap(), _AltText_altTextWasFromKeyBoard = new WeakMap(), _AltText_editor = new WeakMap(), _AltText_instances = new WeakSet(), _AltText_setState = function _AltText_setState() {
  3725. var _f;
  3726. return tslib_1.__awaiter(this, void 0, void 0, function () {
  3727. var button, tooltip, id, DELAY_TO_SHOW_TOOLTIP_1, _g, _h, element;
  3728. var _this = this;
  3729. return tslib_1.__generator(this, function (_j) {
  3730. switch (_j.label) {
  3731. case 0:
  3732. button = tslib_1.__classPrivateFieldGet(this, _AltText_altTextButton, "f");
  3733. if (!button) {
  3734. return [2 /*return*/];
  3735. }
  3736. if (!tslib_1.__classPrivateFieldGet(this, _AltText_altText, "f") && !tslib_1.__classPrivateFieldGet(this, _AltText_altTextDecorative, "f")) {
  3737. button.classList.remove("done");
  3738. (_f = tslib_1.__classPrivateFieldGet(this, _AltText_altTextTooltip, "f")) === null || _f === void 0 ? void 0 : _f.remove();
  3739. return [2 /*return*/];
  3740. }
  3741. button.classList.add("done");
  3742. AltText._l10nPromise.get("pdfjs-editor-alt-text-edit-button-label").then(function (msg) {
  3743. button.setAttribute("aria-label", msg);
  3744. });
  3745. tooltip = tslib_1.__classPrivateFieldGet(this, _AltText_altTextTooltip, "f");
  3746. if (!tooltip) {
  3747. tslib_1.__classPrivateFieldSet(this, _AltText_altTextTooltip, tooltip = document.createElement("span"), "f");
  3748. tooltip.className = "tooltip";
  3749. tooltip.setAttribute("role", "tooltip");
  3750. id = tooltip.id = "alt-text-tooltip-".concat(tslib_1.__classPrivateFieldGet(this, _AltText_editor, "f").id);
  3751. button.setAttribute("aria-describedby", id);
  3752. DELAY_TO_SHOW_TOOLTIP_1 = 100;
  3753. button.addEventListener("mouseenter", function () {
  3754. tslib_1.__classPrivateFieldSet(_this, _AltText_altTextTooltipTimeout, setTimeout(function () {
  3755. tslib_1.__classPrivateFieldSet(_this, _AltText_altTextTooltipTimeout, null, "f");
  3756. tslib_1.__classPrivateFieldGet(_this, _AltText_altTextTooltip, "f").classList.add("show");
  3757. tslib_1.__classPrivateFieldGet(_this, _AltText_editor, "f")._reportTelemetry({
  3758. action: "alt_text_tooltip"
  3759. });
  3760. }, DELAY_TO_SHOW_TOOLTIP_1), "f");
  3761. });
  3762. button.addEventListener("mouseleave", function () {
  3763. var _f;
  3764. if (tslib_1.__classPrivateFieldGet(_this, _AltText_altTextTooltipTimeout, "f")) {
  3765. clearTimeout(tslib_1.__classPrivateFieldGet(_this, _AltText_altTextTooltipTimeout, "f"));
  3766. tslib_1.__classPrivateFieldSet(_this, _AltText_altTextTooltipTimeout, null, "f");
  3767. }
  3768. (_f = tslib_1.__classPrivateFieldGet(_this, _AltText_altTextTooltip, "f")) === null || _f === void 0 ? void 0 : _f.classList.remove("show");
  3769. });
  3770. }
  3771. _g = tooltip;
  3772. if (!tslib_1.__classPrivateFieldGet(this, _AltText_altTextDecorative, "f")) return [3 /*break*/, 2];
  3773. return [4 /*yield*/, AltText._l10nPromise.get("pdfjs-editor-alt-text-decorative-tooltip")];
  3774. case 1:
  3775. _h = _j.sent();
  3776. return [3 /*break*/, 3];
  3777. case 2:
  3778. _h = tslib_1.__classPrivateFieldGet(this, _AltText_altText, "f");
  3779. _j.label = 3;
  3780. case 3:
  3781. _g.innerText = _h;
  3782. if (!tooltip.parentNode) {
  3783. button.append(tooltip);
  3784. }
  3785. element = tslib_1.__classPrivateFieldGet(this, _AltText_editor, "f").getImageForAltText();
  3786. element === null || element === void 0 ? void 0 : element.setAttribute("aria-describedby", tooltip.id);
  3787. return [2 /*return*/];
  3788. }
  3789. });
  3790. });
  3791. };
  3792. AltText._l10nPromise = null;
  3793. return AltText;
  3794. }());
  3795. ; // CONCATENATED MODULE: ./src/display/editor/editor.js
  3796. var AnnotationEditor = /** @class */ (function () {
  3797. function AnnotationEditor(parameters) {
  3798. _AnnotationEditor_instances.add(this);
  3799. _AnnotationEditor_allResizerDivs.set(this, null);
  3800. _AnnotationEditor_altText.set(this, null);
  3801. _AnnotationEditor_disabled.set(this, false);
  3802. _AnnotationEditor_keepAspectRatio.set(this, false);
  3803. _AnnotationEditor_resizersDiv.set(this, null);
  3804. _AnnotationEditor_savedDimensions.set(this, null);
  3805. _AnnotationEditor_boundFocusin.set(this, this.focusin.bind(this));
  3806. _AnnotationEditor_boundFocusout.set(this, this.focusout.bind(this));
  3807. _AnnotationEditor_editToolbar.set(this, null);
  3808. _AnnotationEditor_focusedResizerName.set(this, "");
  3809. _AnnotationEditor_hasBeenClicked.set(this, false);
  3810. _AnnotationEditor_initialPosition.set(this, null);
  3811. _AnnotationEditor_isEditing.set(this, false);
  3812. _AnnotationEditor_isInEditMode.set(this, false);
  3813. _AnnotationEditor_isResizerEnabledForKeyboard.set(this, false);
  3814. _AnnotationEditor_moveInDOMTimeout.set(this, null);
  3815. _AnnotationEditor_prevDragX.set(this, 0);
  3816. _AnnotationEditor_prevDragY.set(this, 0);
  3817. _AnnotationEditor_telemetryTimeouts.set(this, null);
  3818. this._initialOptions = Object.create(null);
  3819. this._isVisible = true;
  3820. this._uiManager = null;
  3821. this._focusEventsAllowed = true;
  3822. this._l10nPromise = null;
  3823. _AnnotationEditor_isDraggable.set(this, false);
  3824. _AnnotationEditor_zIndex.set(this, AnnotationEditor._zIndex++);
  3825. if (this.constructor === AnnotationEditor) {
  3826. unreachable("Cannot initialize AnnotationEditor.");
  3827. }
  3828. this.parent = parameters.parent;
  3829. this.id = parameters.id;
  3830. this.width = this.height = null;
  3831. this.pageIndex = parameters.parent.pageIndex;
  3832. this.name = parameters.name;
  3833. this.div = null;
  3834. this._uiManager = parameters.uiManager;
  3835. this.annotationElementId = null;
  3836. this._willKeepAspectRatio = false;
  3837. this._initialOptions.isCentered = parameters.isCentered;
  3838. this._structTreeParentId = null;
  3839. var _g = this.parent.viewport, rotation = _g.rotation, _h = _g.rawDims, pageWidth = _h.pageWidth, pageHeight = _h.pageHeight, pageX = _h.pageX, pageY = _h.pageY;
  3840. this.rotation = rotation;
  3841. this.pageRotation = (360 + rotation - this._uiManager.viewParameters.rotation) % 360;
  3842. this.pageDimensions = [pageWidth, pageHeight];
  3843. this.pageTranslation = [pageX, pageY];
  3844. var _j = this.parentDimensions, width = _j[0], height = _j[1];
  3845. this.x = parameters.x / width;
  3846. this.y = parameters.y / height;
  3847. this.isAttachedToDOM = false;
  3848. this.deleted = false;
  3849. }
  3850. Object.defineProperty(AnnotationEditor, "_resizerKeyboardManager", {
  3851. get: function () {
  3852. var resize = AnnotationEditor.prototype._resizeWithKeyboard;
  3853. var small = AnnotationEditorUIManager.TRANSLATE_SMALL;
  3854. var big = AnnotationEditorUIManager.TRANSLATE_BIG;
  3855. return shadow(this, "_resizerKeyboardManager", new KeyboardManager([[["ArrowLeft", "mac+ArrowLeft"], resize, {
  3856. args: [-small, 0]
  3857. }], [["ctrl+ArrowLeft", "mac+shift+ArrowLeft"], resize, {
  3858. args: [-big, 0]
  3859. }], [["ArrowRight", "mac+ArrowRight"], resize, {
  3860. args: [small, 0]
  3861. }], [["ctrl+ArrowRight", "mac+shift+ArrowRight"], resize, {
  3862. args: [big, 0]
  3863. }], [["ArrowUp", "mac+ArrowUp"], resize, {
  3864. args: [0, -small]
  3865. }], [["ctrl+ArrowUp", "mac+shift+ArrowUp"], resize, {
  3866. args: [0, -big]
  3867. }], [["ArrowDown", "mac+ArrowDown"], resize, {
  3868. args: [0, small]
  3869. }], [["ctrl+ArrowDown", "mac+shift+ArrowDown"], resize, {
  3870. args: [0, big]
  3871. }], [["Escape", "mac+Escape"], AnnotationEditor.prototype._stopResizingWithKeyboard]]));
  3872. },
  3873. enumerable: false,
  3874. configurable: true
  3875. });
  3876. Object.defineProperty(AnnotationEditor.prototype, "editorType", {
  3877. get: function () {
  3878. return Object.getPrototypeOf(this).constructor._type;
  3879. },
  3880. enumerable: false,
  3881. configurable: true
  3882. });
  3883. Object.defineProperty(AnnotationEditor, "_defaultLineColor", {
  3884. get: function () {
  3885. return shadow(this, "_defaultLineColor", this._colorManager.getHexCode("CanvasText"));
  3886. },
  3887. enumerable: false,
  3888. configurable: true
  3889. });
  3890. AnnotationEditor.deleteAnnotationElement = function (editor) {
  3891. var fakeEditor = new FakeEditor({
  3892. id: editor.parent.getNextId(),
  3893. parent: editor.parent,
  3894. uiManager: editor._uiManager
  3895. });
  3896. fakeEditor.annotationElementId = editor.annotationElementId;
  3897. fakeEditor.deleted = true;
  3898. fakeEditor._uiManager.addToAnnotationStorage(fakeEditor);
  3899. };
  3900. AnnotationEditor.initialize = function (l10n, _uiManager, options) {
  3901. AnnotationEditor._l10nPromise || (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(function (str) { return [str, l10n.get(str.replaceAll(/([A-Z])/g, function (c) { return "-".concat(c.toLowerCase()); }))]; })));
  3902. if (options === null || options === void 0 ? void 0 : options.strings) {
  3903. for (var _i = 0, _g = options.strings; _i < _g.length; _i++) {
  3904. var str = _g[_i];
  3905. AnnotationEditor._l10nPromise.set(str, l10n.get(str));
  3906. }
  3907. }
  3908. if (AnnotationEditor._borderLineWidth !== -1) {
  3909. return;
  3910. }
  3911. var style = getComputedStyle(document.documentElement);
  3912. AnnotationEditor._borderLineWidth = parseFloat(style.getPropertyValue("--outline-width")) || 0;
  3913. };
  3914. AnnotationEditor.updateDefaultParams = function (_type, _value) { };
  3915. Object.defineProperty(AnnotationEditor, "defaultPropertiesToUpdate", {
  3916. get: function () {
  3917. return [];
  3918. },
  3919. enumerable: false,
  3920. configurable: true
  3921. });
  3922. AnnotationEditor.isHandlingMimeForPasting = function (mime) {
  3923. return false;
  3924. };
  3925. AnnotationEditor.paste = function (item, parent) {
  3926. unreachable("Not implemented");
  3927. };
  3928. Object.defineProperty(AnnotationEditor.prototype, "propertiesToUpdate", {
  3929. get: function () {
  3930. return [];
  3931. },
  3932. enumerable: false,
  3933. configurable: true
  3934. });
  3935. Object.defineProperty(AnnotationEditor.prototype, "_isDraggable", {
  3936. get: function () {
  3937. return tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_isDraggable, "f");
  3938. },
  3939. set: function (value) {
  3940. var _g;
  3941. tslib_1.__classPrivateFieldSet(this, _AnnotationEditor_isDraggable, value, "f");
  3942. (_g = this.div) === null || _g === void 0 ? void 0 : _g.classList.toggle("draggable", value);
  3943. },
  3944. enumerable: false,
  3945. configurable: true
  3946. });
  3947. Object.defineProperty(AnnotationEditor.prototype, "isEnterHandled", {
  3948. get: function () {
  3949. return true;
  3950. },
  3951. enumerable: false,
  3952. configurable: true
  3953. });
  3954. AnnotationEditor.prototype.center = function () {
  3955. var _g = this.pageDimensions, pageWidth = _g[0], pageHeight = _g[1];
  3956. switch (this.parentRotation) {
  3957. case 90:
  3958. this.x -= this.height * pageHeight / (pageWidth * 2);
  3959. this.y += this.width * pageWidth / (pageHeight * 2);
  3960. break;
  3961. case 180:
  3962. this.x += this.width / 2;
  3963. this.y += this.height / 2;
  3964. break;
  3965. case 270:
  3966. this.x += this.height * pageHeight / (pageWidth * 2);
  3967. this.y -= this.width * pageWidth / (pageHeight * 2);
  3968. break;
  3969. default:
  3970. this.x -= this.width / 2;
  3971. this.y -= this.height / 2;
  3972. break;
  3973. }
  3974. this.fixAndSetPosition();
  3975. };
  3976. AnnotationEditor.prototype.addCommands = function (params) {
  3977. this._uiManager.addCommands(params);
  3978. };
  3979. Object.defineProperty(AnnotationEditor.prototype, "currentLayer", {
  3980. get: function () {
  3981. return this._uiManager.currentLayer;
  3982. },
  3983. enumerable: false,
  3984. configurable: true
  3985. });
  3986. AnnotationEditor.prototype.setInBackground = function () {
  3987. this.div.style.zIndex = 0;
  3988. };
  3989. AnnotationEditor.prototype.setInForeground = function () {
  3990. this.div.style.zIndex = tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_zIndex, "f");
  3991. };
  3992. AnnotationEditor.prototype.setParent = function (parent) {
  3993. if (parent !== null) {
  3994. this.pageIndex = parent.pageIndex;
  3995. this.pageDimensions = parent.pageDimensions;
  3996. }
  3997. else {
  3998. tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_instances, "m", _AnnotationEditor_stopResizing).call(this);
  3999. }
  4000. this.parent = parent;
  4001. };
  4002. AnnotationEditor.prototype.focusin = function (event) {
  4003. if (!this._focusEventsAllowed) {
  4004. return;
  4005. }
  4006. if (!tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_hasBeenClicked, "f")) {
  4007. this.parent.setSelected(this);
  4008. }
  4009. else {
  4010. tslib_1.__classPrivateFieldSet(this, _AnnotationEditor_hasBeenClicked, false, "f");
  4011. }
  4012. };
  4013. AnnotationEditor.prototype.focusout = function (event) {
  4014. var _g;
  4015. if (!this._focusEventsAllowed) {
  4016. return;
  4017. }
  4018. if (!this.isAttachedToDOM) {
  4019. return;
  4020. }
  4021. var target = event.relatedTarget;
  4022. if (target === null || target === void 0 ? void 0 : target.closest("#".concat(this.id))) {
  4023. return;
  4024. }
  4025. event.preventDefault();
  4026. if (!((_g = this.parent) === null || _g === void 0 ? void 0 : _g.isMultipleSelection)) {
  4027. this.commitOrRemove();
  4028. }
  4029. };
  4030. AnnotationEditor.prototype.commitOrRemove = function () {
  4031. if (this.isEmpty()) {
  4032. this.remove();
  4033. }
  4034. else {
  4035. this.commit();
  4036. }
  4037. };
  4038. AnnotationEditor.prototype.commit = function () {
  4039. this.addToAnnotationStorage();
  4040. };
  4041. AnnotationEditor.prototype.addToAnnotationStorage = function () {
  4042. this._uiManager.addToAnnotationStorage(this);
  4043. };
  4044. AnnotationEditor.prototype.setAt = function (x, y, tx, ty) {
  4045. var _g;
  4046. var _h = this.parentDimensions, width = _h[0], height = _h[1];
  4047. _g = this.screenToPageTranslation(tx, ty), tx = _g[0], ty = _g[1];
  4048. this.x = (x + tx) / width;
  4049. this.y = (y + ty) / height;
  4050. this.fixAndSetPosition();
  4051. };
  4052. AnnotationEditor.prototype.translate = function (x, y) {
  4053. tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_instances, "m", _AnnotationEditor_translate).call(this, this.parentDimensions, x, y);
  4054. };
  4055. AnnotationEditor.prototype.translateInPage = function (x, y) {
  4056. tslib_1.__classPrivateFieldSet(this, _AnnotationEditor_initialPosition, tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_initialPosition, "f") || [this.x, this.y], "f");
  4057. tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_instances, "m", _AnnotationEditor_translate).call(this, this.pageDimensions, x, y);
  4058. this.div.scrollIntoView({
  4059. block: "nearest"
  4060. });
  4061. };
  4062. AnnotationEditor.prototype.drag = function (tx, ty) {
  4063. tslib_1.__classPrivateFieldSet(this, _AnnotationEditor_initialPosition, tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_initialPosition, "f") || [this.x, this.y], "f");
  4064. var _g = this.parentDimensions, parentWidth = _g[0], parentHeight = _g[1];
  4065. this.x += tx / parentWidth;
  4066. this.y += ty / parentHeight;
  4067. if (this.parent && (this.x < 0 || this.x > 1 || this.y < 0 || this.y > 1)) {
  4068. var _h = this.div.getBoundingClientRect(), x_1 = _h.x, y_1 = _h.y;
  4069. if (this.parent.findNewParent(this, x_1, y_1)) {
  4070. this.x -= Math.floor(this.x);
  4071. this.y -= Math.floor(this.y);
  4072. }
  4073. }
  4074. var _j = this, x = _j.x, y = _j.y;
  4075. var _k = this.getBaseTranslation(), bx = _k[0], by = _k[1];
  4076. x += bx;
  4077. y += by;
  4078. this.div.style.left = "".concat((100 * x).toFixed(2), "%");
  4079. this.div.style.top = "".concat((100 * y).toFixed(2), "%");
  4080. this.div.scrollIntoView({
  4081. block: "nearest"
  4082. });
  4083. };
  4084. Object.defineProperty(AnnotationEditor.prototype, "_hasBeenMoved", {
  4085. get: function () {
  4086. return !!tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_initialPosition, "f") && (tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_initialPosition, "f")[0] !== this.x || tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_initialPosition, "f")[1] !== this.y);
  4087. },
  4088. enumerable: false,
  4089. configurable: true
  4090. });
  4091. AnnotationEditor.prototype.getBaseTranslation = function () {
  4092. var _g = this.parentDimensions, parentWidth = _g[0], parentHeight = _g[1];
  4093. var _borderLineWidth = AnnotationEditor._borderLineWidth;
  4094. var x = _borderLineWidth / parentWidth;
  4095. var y = _borderLineWidth / parentHeight;
  4096. switch (this.rotation) {
  4097. case 90:
  4098. return [-x, y];
  4099. case 180:
  4100. return [x, y];
  4101. case 270:
  4102. return [x, -y];
  4103. default:
  4104. return [-x, -y];
  4105. }
  4106. };
  4107. Object.defineProperty(AnnotationEditor.prototype, "_mustFixPosition", {
  4108. get: function () {
  4109. return true;
  4110. },
  4111. enumerable: false,
  4112. configurable: true
  4113. });
  4114. AnnotationEditor.prototype.fixAndSetPosition = function (rotation) {
  4115. if (rotation === void 0) { rotation = this.rotation; }
  4116. var _g = this.pageDimensions, pageWidth = _g[0], pageHeight = _g[1];
  4117. var _h = this, x = _h.x, y = _h.y, width = _h.width, height = _h.height;
  4118. width *= pageWidth;
  4119. height *= pageHeight;
  4120. x *= pageWidth;
  4121. y *= pageHeight;
  4122. if (this._mustFixPosition) {
  4123. switch (rotation) {
  4124. case 0:
  4125. x = Math.max(0, Math.min(pageWidth - width, x));
  4126. y = Math.max(0, Math.min(pageHeight - height, y));
  4127. break;
  4128. case 90:
  4129. x = Math.max(0, Math.min(pageWidth - height, x));
  4130. y = Math.min(pageHeight, Math.max(width, y));
  4131. break;
  4132. case 180:
  4133. x = Math.min(pageWidth, Math.max(width, x));
  4134. y = Math.min(pageHeight, Math.max(height, y));
  4135. break;
  4136. case 270:
  4137. x = Math.min(pageWidth, Math.max(height, x));
  4138. y = Math.max(0, Math.min(pageHeight - width, y));
  4139. break;
  4140. }
  4141. }
  4142. this.x = x /= pageWidth;
  4143. this.y = y /= pageHeight;
  4144. var _j = this.getBaseTranslation(), bx = _j[0], by = _j[1];
  4145. x += bx;
  4146. y += by;
  4147. var style = this.div.style;
  4148. style.left = "".concat((100 * x).toFixed(2), "%");
  4149. style.top = "".concat((100 * y).toFixed(2), "%");
  4150. this.moveInDOM();
  4151. };
  4152. AnnotationEditor.prototype.screenToPageTranslation = function (x, y) {
  4153. return tslib_1.__classPrivateFieldGet(AnnotationEditor, _f, "m", _AnnotationEditor_rotatePoint).call(AnnotationEditor, x, y, this.parentRotation);
  4154. };
  4155. AnnotationEditor.prototype.pageTranslationToScreen = function (x, y) {
  4156. return tslib_1.__classPrivateFieldGet(AnnotationEditor, _f, "m", _AnnotationEditor_rotatePoint).call(AnnotationEditor, x, y, 360 - this.parentRotation);
  4157. };
  4158. Object.defineProperty(AnnotationEditor.prototype, "parentScale", {
  4159. get: function () {
  4160. return this._uiManager.viewParameters.realScale;
  4161. },
  4162. enumerable: false,
  4163. configurable: true
  4164. });
  4165. Object.defineProperty(AnnotationEditor.prototype, "parentRotation", {
  4166. get: function () {
  4167. return (this._uiManager.viewParameters.rotation + this.pageRotation) % 360;
  4168. },
  4169. enumerable: false,
  4170. configurable: true
  4171. });
  4172. Object.defineProperty(AnnotationEditor.prototype, "parentDimensions", {
  4173. get: function () {
  4174. var _g = this, parentScale = _g.parentScale, _h = _g.pageDimensions, pageWidth = _h[0], pageHeight = _h[1];
  4175. var scaledWidth = pageWidth * parentScale;
  4176. var scaledHeight = pageHeight * parentScale;
  4177. return util_FeatureTest.isCSSRoundSupported ? [Math.round(scaledWidth), Math.round(scaledHeight)] : [scaledWidth, scaledHeight];
  4178. },
  4179. enumerable: false,
  4180. configurable: true
  4181. });
  4182. AnnotationEditor.prototype.setDims = function (width, height) {
  4183. var _g = this.parentDimensions, parentWidth = _g[0], parentHeight = _g[1];
  4184. this.div.style.width = "".concat((100 * width / parentWidth).toFixed(2), "%");
  4185. if (!tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_keepAspectRatio, "f")) {
  4186. this.div.style.height = "".concat((100 * height / parentHeight).toFixed(2), "%");
  4187. }
  4188. };
  4189. AnnotationEditor.prototype.fixDims = function () {
  4190. var style = this.div.style;
  4191. var height = style.height, width = style.width;
  4192. var widthPercent = width.endsWith("%");
  4193. var heightPercent = !tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_keepAspectRatio, "f") && height.endsWith("%");
  4194. if (widthPercent && heightPercent) {
  4195. return;
  4196. }
  4197. var _g = this.parentDimensions, parentWidth = _g[0], parentHeight = _g[1];
  4198. if (!widthPercent) {
  4199. style.width = "".concat((100 * parseFloat(width) / parentWidth).toFixed(2), "%");
  4200. }
  4201. if (!tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_keepAspectRatio, "f") && !heightPercent) {
  4202. style.height = "".concat((100 * parseFloat(height) / parentHeight).toFixed(2), "%");
  4203. }
  4204. };
  4205. AnnotationEditor.prototype.getInitialTranslation = function () {
  4206. return [0, 0];
  4207. };
  4208. AnnotationEditor.prototype.altTextFinish = function () {
  4209. var _g;
  4210. (_g = tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_altText, "f")) === null || _g === void 0 ? void 0 : _g.finish();
  4211. };
  4212. AnnotationEditor.prototype.addEditToolbar = function () {
  4213. return tslib_1.__awaiter(this, void 0, void 0, function () {
  4214. var _g, _h;
  4215. return tslib_1.__generator(this, function (_j) {
  4216. switch (_j.label) {
  4217. case 0:
  4218. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_editToolbar, "f") || tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_isInEditMode, "f")) {
  4219. return [2 /*return*/, tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_editToolbar, "f")];
  4220. }
  4221. tslib_1.__classPrivateFieldSet(this, _AnnotationEditor_editToolbar, new EditorToolbar(this), "f");
  4222. this.div.append(tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_editToolbar, "f").render());
  4223. if (!tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_altText, "f")) return [3 /*break*/, 2];
  4224. _h = (_g = tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_editToolbar, "f")).addAltTextButton;
  4225. return [4 /*yield*/, tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_altText, "f").render()];
  4226. case 1:
  4227. _h.apply(_g, [_j.sent()]);
  4228. _j.label = 2;
  4229. case 2: return [2 /*return*/, tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_editToolbar, "f")];
  4230. }
  4231. });
  4232. });
  4233. };
  4234. AnnotationEditor.prototype.removeEditToolbar = function () {
  4235. var _g;
  4236. if (!tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_editToolbar, "f")) {
  4237. return;
  4238. }
  4239. tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_editToolbar, "f").remove();
  4240. tslib_1.__classPrivateFieldSet(this, _AnnotationEditor_editToolbar, null, "f");
  4241. (_g = tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_altText, "f")) === null || _g === void 0 ? void 0 : _g.destroy();
  4242. };
  4243. AnnotationEditor.prototype.getClientDimensions = function () {
  4244. return this.div.getBoundingClientRect();
  4245. };
  4246. AnnotationEditor.prototype.addAltTextButton = function () {
  4247. return tslib_1.__awaiter(this, void 0, void 0, function () {
  4248. return tslib_1.__generator(this, function (_g) {
  4249. switch (_g.label) {
  4250. case 0:
  4251. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_altText, "f")) {
  4252. return [2 /*return*/];
  4253. }
  4254. AltText.initialize(AnnotationEditor._l10nPromise);
  4255. tslib_1.__classPrivateFieldSet(this, _AnnotationEditor_altText, new AltText(this), "f");
  4256. return [4 /*yield*/, this.addEditToolbar()];
  4257. case 1:
  4258. _g.sent();
  4259. return [2 /*return*/];
  4260. }
  4261. });
  4262. });
  4263. };
  4264. Object.defineProperty(AnnotationEditor.prototype, "altTextData", {
  4265. get: function () {
  4266. var _g;
  4267. return (_g = tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_altText, "f")) === null || _g === void 0 ? void 0 : _g.data;
  4268. },
  4269. set: function (data) {
  4270. if (!tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_altText, "f")) {
  4271. return;
  4272. }
  4273. tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_altText, "f").data = data;
  4274. },
  4275. enumerable: false,
  4276. configurable: true
  4277. });
  4278. AnnotationEditor.prototype.hasAltText = function () {
  4279. var _g;
  4280. return !((_g = tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_altText, "f")) === null || _g === void 0 ? void 0 : _g.isEmpty());
  4281. };
  4282. AnnotationEditor.prototype.render = function () {
  4283. this.div = document.createElement("div");
  4284. this.div.setAttribute("data-editor-rotation", (360 - this.rotation) % 360);
  4285. this.div.className = this.name;
  4286. this.div.setAttribute("id", this.id);
  4287. this.div.tabIndex = tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_disabled, "f") ? -1 : 0;
  4288. if (!this._isVisible) {
  4289. this.div.classList.add("hidden");
  4290. }
  4291. this.setInForeground();
  4292. this.div.addEventListener("focusin", tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_boundFocusin, "f"));
  4293. this.div.addEventListener("focusout", tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_boundFocusout, "f"));
  4294. var _g = this.parentDimensions, parentWidth = _g[0], parentHeight = _g[1];
  4295. if (this.parentRotation % 180 !== 0) {
  4296. this.div.style.maxWidth = "".concat((100 * parentHeight / parentWidth).toFixed(2), "%");
  4297. this.div.style.maxHeight = "".concat((100 * parentWidth / parentHeight).toFixed(2), "%");
  4298. }
  4299. var _h = this.getInitialTranslation(), tx = _h[0], ty = _h[1];
  4300. this.translate(tx, ty);
  4301. bindEvents(this, this.div, ["pointerdown"]);
  4302. return this.div;
  4303. };
  4304. AnnotationEditor.prototype.pointerdown = function (event) {
  4305. var isMac = util_FeatureTest.platform.isMac;
  4306. if (event.button !== 0 || event.ctrlKey && isMac) {
  4307. event.preventDefault();
  4308. return;
  4309. }
  4310. tslib_1.__classPrivateFieldSet(this, _AnnotationEditor_hasBeenClicked, true, "f");
  4311. if (this._isDraggable) {
  4312. tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_instances, "m", _AnnotationEditor_setUpDragSession).call(this, event);
  4313. return;
  4314. }
  4315. tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_instances, "m", _AnnotationEditor_selectOnPointerEvent).call(this, event);
  4316. };
  4317. AnnotationEditor.prototype.moveInDOM = function () {
  4318. var _this = this;
  4319. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_moveInDOMTimeout, "f")) {
  4320. clearTimeout(tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_moveInDOMTimeout, "f"));
  4321. }
  4322. tslib_1.__classPrivateFieldSet(this, _AnnotationEditor_moveInDOMTimeout, setTimeout(function () {
  4323. var _g;
  4324. tslib_1.__classPrivateFieldSet(_this, _AnnotationEditor_moveInDOMTimeout, null, "f");
  4325. (_g = _this.parent) === null || _g === void 0 ? void 0 : _g.moveEditorInDOM(_this);
  4326. }, 0), "f");
  4327. };
  4328. AnnotationEditor.prototype._setParentAndPosition = function (parent, x, y) {
  4329. parent.changeParent(this);
  4330. this.x = x;
  4331. this.y = y;
  4332. this.fixAndSetPosition();
  4333. };
  4334. AnnotationEditor.prototype.getRect = function (tx, ty, rotation) {
  4335. if (rotation === void 0) { rotation = this.rotation; }
  4336. var scale = this.parentScale;
  4337. var _g = this.pageDimensions, pageWidth = _g[0], pageHeight = _g[1];
  4338. var _h = this.pageTranslation, pageX = _h[0], pageY = _h[1];
  4339. var shiftX = tx / scale;
  4340. var shiftY = ty / scale;
  4341. var x = this.x * pageWidth;
  4342. var y = this.y * pageHeight;
  4343. var width = this.width * pageWidth;
  4344. var height = this.height * pageHeight;
  4345. switch (rotation) {
  4346. case 0:
  4347. return [x + shiftX + pageX, pageHeight - y - shiftY - height + pageY, x + shiftX + width + pageX, pageHeight - y - shiftY + pageY];
  4348. case 90:
  4349. return [x + shiftY + pageX, pageHeight - y + shiftX + pageY, x + shiftY + height + pageX, pageHeight - y + shiftX + width + pageY];
  4350. case 180:
  4351. return [x - shiftX - width + pageX, pageHeight - y + shiftY + pageY, x - shiftX + pageX, pageHeight - y + shiftY + height + pageY];
  4352. case 270:
  4353. return [x - shiftY - height + pageX, pageHeight - y - shiftX - width + pageY, x - shiftY + pageX, pageHeight - y - shiftX + pageY];
  4354. default:
  4355. throw new Error("Invalid rotation");
  4356. }
  4357. };
  4358. AnnotationEditor.prototype.getRectInCurrentCoords = function (rect, pageHeight) {
  4359. var x1 = rect[0], y1 = rect[1], x2 = rect[2], y2 = rect[3];
  4360. var width = x2 - x1;
  4361. var height = y2 - y1;
  4362. switch (this.rotation) {
  4363. case 0:
  4364. return [x1, pageHeight - y2, width, height];
  4365. case 90:
  4366. return [x1, pageHeight - y1, height, width];
  4367. case 180:
  4368. return [x2, pageHeight - y1, width, height];
  4369. case 270:
  4370. return [x2, pageHeight - y2, height, width];
  4371. default:
  4372. throw new Error("Invalid rotation");
  4373. }
  4374. };
  4375. AnnotationEditor.prototype.onceAdded = function () { };
  4376. AnnotationEditor.prototype.isEmpty = function () {
  4377. return false;
  4378. };
  4379. AnnotationEditor.prototype.enableEditMode = function () {
  4380. tslib_1.__classPrivateFieldSet(this, _AnnotationEditor_isInEditMode, true, "f");
  4381. };
  4382. AnnotationEditor.prototype.disableEditMode = function () {
  4383. tslib_1.__classPrivateFieldSet(this, _AnnotationEditor_isInEditMode, false, "f");
  4384. };
  4385. AnnotationEditor.prototype.isInEditMode = function () {
  4386. return tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_isInEditMode, "f");
  4387. };
  4388. AnnotationEditor.prototype.shouldGetKeyboardEvents = function () {
  4389. return tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_isResizerEnabledForKeyboard, "f");
  4390. };
  4391. AnnotationEditor.prototype.needsToBeRebuilt = function () {
  4392. return this.div && !this.isAttachedToDOM;
  4393. };
  4394. AnnotationEditor.prototype.rebuild = function () {
  4395. var _g, _h;
  4396. (_g = this.div) === null || _g === void 0 ? void 0 : _g.addEventListener("focusin", tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_boundFocusin, "f"));
  4397. (_h = this.div) === null || _h === void 0 ? void 0 : _h.addEventListener("focusout", tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_boundFocusout, "f"));
  4398. };
  4399. AnnotationEditor.prototype.rotate = function (_angle) { };
  4400. AnnotationEditor.prototype.serialize = function (isForCopying, context) {
  4401. if (isForCopying === void 0) { isForCopying = false; }
  4402. if (context === void 0) { context = null; }
  4403. unreachable("An editor must be serializable");
  4404. };
  4405. AnnotationEditor.deserialize = function (data, parent, uiManager) {
  4406. var editor = new this.prototype.constructor({
  4407. parent: parent,
  4408. id: parent.getNextId(),
  4409. uiManager: uiManager
  4410. });
  4411. editor.rotation = data.rotation;
  4412. var _g = editor.pageDimensions, pageWidth = _g[0], pageHeight = _g[1];
  4413. var _h = editor.getRectInCurrentCoords(data.rect, pageHeight), x = _h[0], y = _h[1], width = _h[2], height = _h[3];
  4414. editor.x = x / pageWidth;
  4415. editor.y = y / pageHeight;
  4416. editor.width = width / pageWidth;
  4417. editor.height = height / pageHeight;
  4418. return editor;
  4419. };
  4420. Object.defineProperty(AnnotationEditor.prototype, "hasBeenModified", {
  4421. get: function () {
  4422. return !!this.annotationElementId && (this.deleted || this.serialize() !== null);
  4423. },
  4424. enumerable: false,
  4425. configurable: true
  4426. });
  4427. AnnotationEditor.prototype.remove = function () {
  4428. this.div.removeEventListener("focusin", tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_boundFocusin, "f"));
  4429. this.div.removeEventListener("focusout", tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_boundFocusout, "f"));
  4430. if (!this.isEmpty()) {
  4431. this.commit();
  4432. }
  4433. if (this.parent) {
  4434. this.parent.remove(this);
  4435. }
  4436. else {
  4437. this._uiManager.removeEditor(this);
  4438. }
  4439. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_moveInDOMTimeout, "f")) {
  4440. clearTimeout(tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_moveInDOMTimeout, "f"));
  4441. tslib_1.__classPrivateFieldSet(this, _AnnotationEditor_moveInDOMTimeout, null, "f");
  4442. }
  4443. tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_instances, "m", _AnnotationEditor_stopResizing).call(this);
  4444. this.removeEditToolbar();
  4445. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_telemetryTimeouts, "f")) {
  4446. for (var _i = 0, _g = tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_telemetryTimeouts, "f").values(); _i < _g.length; _i++) {
  4447. var timeout = _g[_i];
  4448. clearTimeout(timeout);
  4449. }
  4450. tslib_1.__classPrivateFieldSet(this, _AnnotationEditor_telemetryTimeouts, null, "f");
  4451. }
  4452. this.parent = null;
  4453. };
  4454. Object.defineProperty(AnnotationEditor.prototype, "isResizable", {
  4455. get: function () {
  4456. return false;
  4457. },
  4458. enumerable: false,
  4459. configurable: true
  4460. });
  4461. AnnotationEditor.prototype.makeResizable = function () {
  4462. if (this.isResizable) {
  4463. tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_instances, "m", _AnnotationEditor_createResizers).call(this);
  4464. tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_resizersDiv, "f").classList.remove("hidden");
  4465. bindEvents(this, this.div, ["keydown"]);
  4466. }
  4467. };
  4468. Object.defineProperty(AnnotationEditor.prototype, "toolbarPosition", {
  4469. get: function () {
  4470. return null;
  4471. },
  4472. enumerable: false,
  4473. configurable: true
  4474. });
  4475. AnnotationEditor.prototype.keydown = function (event) {
  4476. if (!this.isResizable || event.target !== this.div || event.key !== "Enter") {
  4477. return;
  4478. }
  4479. this._uiManager.setSelected(this);
  4480. tslib_1.__classPrivateFieldSet(this, _AnnotationEditor_savedDimensions, {
  4481. savedX: this.x,
  4482. savedY: this.y,
  4483. savedWidth: this.width,
  4484. savedHeight: this.height
  4485. }, "f");
  4486. var children = tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_resizersDiv, "f").children;
  4487. if (!tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_allResizerDivs, "f")) {
  4488. tslib_1.__classPrivateFieldSet(this, _AnnotationEditor_allResizerDivs, Array.from(children), "f");
  4489. var boundResizerKeydown = tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_instances, "m", _AnnotationEditor_resizerKeydown).bind(this);
  4490. var boundResizerBlur = tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_instances, "m", _AnnotationEditor_resizerBlur).bind(this);
  4491. var _loop_1 = function (div) {
  4492. var name = div.getAttribute("data-resizer-name");
  4493. div.setAttribute("role", "spinbutton");
  4494. div.addEventListener("keydown", boundResizerKeydown);
  4495. div.addEventListener("blur", boundResizerBlur);
  4496. div.addEventListener("focus", tslib_1.__classPrivateFieldGet(this_1, _AnnotationEditor_instances, "m", _AnnotationEditor_resizerFocus).bind(this_1, name));
  4497. AnnotationEditor._l10nPromise.get("pdfjs-editor-resizer-label-".concat(name)).then(function (msg) { return div.setAttribute("aria-label", msg); });
  4498. };
  4499. var this_1 = this;
  4500. for (var _i = 0, _g = tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_allResizerDivs, "f"); _i < _g.length; _i++) {
  4501. var div = _g[_i];
  4502. _loop_1(div);
  4503. }
  4504. }
  4505. var first = tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_allResizerDivs, "f")[0];
  4506. var firstPosition = 0;
  4507. for (var _h = 0, children_1 = children; _h < children_1.length; _h++) {
  4508. var div = children_1[_h];
  4509. if (div === first) {
  4510. break;
  4511. }
  4512. firstPosition++;
  4513. }
  4514. var nextFirstPosition = (360 - this.rotation + this.parentRotation) % 360 / 90 * (tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_allResizerDivs, "f").length / 4);
  4515. if (nextFirstPosition !== firstPosition) {
  4516. if (nextFirstPosition < firstPosition) {
  4517. for (var i_1 = 0; i_1 < firstPosition - nextFirstPosition; i_1++) {
  4518. tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_resizersDiv, "f").append(tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_resizersDiv, "f").firstChild);
  4519. }
  4520. }
  4521. else if (nextFirstPosition > firstPosition) {
  4522. for (var i_2 = 0; i_2 < nextFirstPosition - firstPosition; i_2++) {
  4523. tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_resizersDiv, "f").firstChild.before(tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_resizersDiv, "f").lastChild);
  4524. }
  4525. }
  4526. var i = 0;
  4527. var _loop_2 = function (child) {
  4528. var div = tslib_1.__classPrivateFieldGet(this_2, _AnnotationEditor_allResizerDivs, "f")[i++];
  4529. var name = div.getAttribute("data-resizer-name");
  4530. AnnotationEditor._l10nPromise.get("pdfjs-editor-resizer-label-".concat(name)).then(function (msg) { return child.setAttribute("aria-label", msg); });
  4531. };
  4532. var this_2 = this;
  4533. for (var _j = 0, children_2 = children; _j < children_2.length; _j++) {
  4534. var child = children_2[_j];
  4535. _loop_2(child);
  4536. }
  4537. }
  4538. tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_instances, "m", _AnnotationEditor_setResizerTabIndex).call(this, 0);
  4539. tslib_1.__classPrivateFieldSet(this, _AnnotationEditor_isResizerEnabledForKeyboard, true, "f");
  4540. tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_resizersDiv, "f").firstChild.focus({
  4541. focusVisible: true
  4542. });
  4543. event.preventDefault();
  4544. event.stopImmediatePropagation();
  4545. };
  4546. AnnotationEditor.prototype._resizeWithKeyboard = function (x, y) {
  4547. if (!tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_isResizerEnabledForKeyboard, "f")) {
  4548. return;
  4549. }
  4550. tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_instances, "m", _AnnotationEditor_resizerPointermove).call(this, tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_focusedResizerName, "f"), {
  4551. movementX: x,
  4552. movementY: y
  4553. });
  4554. };
  4555. AnnotationEditor.prototype._stopResizingWithKeyboard = function () {
  4556. tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_instances, "m", _AnnotationEditor_stopResizing).call(this);
  4557. this.div.focus();
  4558. };
  4559. AnnotationEditor.prototype.select = function () {
  4560. var _this = this;
  4561. var _g, _h;
  4562. this.makeResizable();
  4563. (_g = this.div) === null || _g === void 0 ? void 0 : _g.classList.add("selectedEditor");
  4564. if (!tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_editToolbar, "f")) {
  4565. this.addEditToolbar().then(function () {
  4566. var _g, _h;
  4567. if ((_g = _this.div) === null || _g === void 0 ? void 0 : _g.classList.contains("selectedEditor")) {
  4568. (_h = tslib_1.__classPrivateFieldGet(_this, _AnnotationEditor_editToolbar, "f")) === null || _h === void 0 ? void 0 : _h.show();
  4569. }
  4570. });
  4571. return;
  4572. }
  4573. (_h = tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_editToolbar, "f")) === null || _h === void 0 ? void 0 : _h.show();
  4574. };
  4575. AnnotationEditor.prototype.unselect = function () {
  4576. var _g, _h, _j, _k;
  4577. (_g = tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_resizersDiv, "f")) === null || _g === void 0 ? void 0 : _g.classList.add("hidden");
  4578. (_h = this.div) === null || _h === void 0 ? void 0 : _h.classList.remove("selectedEditor");
  4579. if ((_j = this.div) === null || _j === void 0 ? void 0 : _j.contains(document.activeElement)) {
  4580. this._uiManager.currentLayer.div.focus({
  4581. preventScroll: true
  4582. });
  4583. }
  4584. (_k = tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_editToolbar, "f")) === null || _k === void 0 ? void 0 : _k.hide();
  4585. };
  4586. AnnotationEditor.prototype.updateParams = function (type, value) { };
  4587. AnnotationEditor.prototype.disableEditing = function () { };
  4588. AnnotationEditor.prototype.enableEditing = function () { };
  4589. AnnotationEditor.prototype.enterInEditMode = function () { };
  4590. AnnotationEditor.prototype.getImageForAltText = function () {
  4591. return null;
  4592. };
  4593. Object.defineProperty(AnnotationEditor.prototype, "contentDiv", {
  4594. get: function () {
  4595. return this.div;
  4596. },
  4597. enumerable: false,
  4598. configurable: true
  4599. });
  4600. Object.defineProperty(AnnotationEditor.prototype, "isEditing", {
  4601. get: function () {
  4602. return tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_isEditing, "f");
  4603. },
  4604. set: function (value) {
  4605. tslib_1.__classPrivateFieldSet(this, _AnnotationEditor_isEditing, value, "f");
  4606. if (!this.parent) {
  4607. return;
  4608. }
  4609. if (value) {
  4610. this.parent.setSelected(this);
  4611. this.parent.setActiveEditor(this);
  4612. }
  4613. else {
  4614. this.parent.setActiveEditor(null);
  4615. }
  4616. },
  4617. enumerable: false,
  4618. configurable: true
  4619. });
  4620. AnnotationEditor.prototype.setAspectRatio = function (width, height) {
  4621. tslib_1.__classPrivateFieldSet(this, _AnnotationEditor_keepAspectRatio, true, "f");
  4622. var aspectRatio = width / height;
  4623. var style = this.div.style;
  4624. style.aspectRatio = aspectRatio;
  4625. style.height = "auto";
  4626. };
  4627. Object.defineProperty(AnnotationEditor, "MIN_SIZE", {
  4628. get: function () {
  4629. return 16;
  4630. },
  4631. enumerable: false,
  4632. configurable: true
  4633. });
  4634. AnnotationEditor.canCreateNewEmptyEditor = function () {
  4635. return true;
  4636. };
  4637. Object.defineProperty(AnnotationEditor.prototype, "telemetryInitialData", {
  4638. get: function () {
  4639. return {
  4640. action: "added"
  4641. };
  4642. },
  4643. enumerable: false,
  4644. configurable: true
  4645. });
  4646. Object.defineProperty(AnnotationEditor.prototype, "telemetryFinalData", {
  4647. get: function () {
  4648. return null;
  4649. },
  4650. enumerable: false,
  4651. configurable: true
  4652. });
  4653. AnnotationEditor.prototype._reportTelemetry = function (data, mustWait) {
  4654. var _this = this;
  4655. if (mustWait === void 0) { mustWait = false; }
  4656. if (mustWait) {
  4657. tslib_1.__classPrivateFieldSet(this, _AnnotationEditor_telemetryTimeouts, tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_telemetryTimeouts, "f") || new Map(), "f");
  4658. var action_1 = data.action;
  4659. var timeout = tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_telemetryTimeouts, "f").get(action_1);
  4660. if (timeout) {
  4661. clearTimeout(timeout);
  4662. }
  4663. timeout = setTimeout(function () {
  4664. _this._reportTelemetry(data);
  4665. tslib_1.__classPrivateFieldGet(_this, _AnnotationEditor_telemetryTimeouts, "f").delete(action_1);
  4666. if (tslib_1.__classPrivateFieldGet(_this, _AnnotationEditor_telemetryTimeouts, "f").size === 0) {
  4667. tslib_1.__classPrivateFieldSet(_this, _AnnotationEditor_telemetryTimeouts, null, "f");
  4668. }
  4669. }, AnnotationEditor._telemetryTimeout);
  4670. tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_telemetryTimeouts, "f").set(action_1, timeout);
  4671. return;
  4672. }
  4673. data.type || (data.type = this.editorType);
  4674. this._uiManager._eventBus.dispatch("reporttelemetry", {
  4675. source: this,
  4676. details: {
  4677. type: "editing",
  4678. data: data
  4679. }
  4680. });
  4681. };
  4682. AnnotationEditor.prototype.show = function (visible) {
  4683. if (visible === void 0) { visible = this._isVisible; }
  4684. this.div.classList.toggle("hidden", !visible);
  4685. this._isVisible = visible;
  4686. };
  4687. AnnotationEditor.prototype.enable = function () {
  4688. if (this.div) {
  4689. this.div.tabIndex = 0;
  4690. }
  4691. tslib_1.__classPrivateFieldSet(this, _AnnotationEditor_disabled, false, "f");
  4692. };
  4693. AnnotationEditor.prototype.disable = function () {
  4694. if (this.div) {
  4695. this.div.tabIndex = -1;
  4696. }
  4697. tslib_1.__classPrivateFieldSet(this, _AnnotationEditor_disabled, true, "f");
  4698. };
  4699. AnnotationEditor.prototype.renderAnnotationElement = function (annotation) {
  4700. var content = annotation.container.querySelector(".annotationContent");
  4701. if (!content) {
  4702. content = document.createElement("div");
  4703. content.classList.add("annotationContent", this.editorType);
  4704. annotation.container.prepend(content);
  4705. }
  4706. else if (content.nodeName === "CANVAS") {
  4707. var canvas = content;
  4708. content = document.createElement("div");
  4709. content.classList.add("annotationContent", this.editorType);
  4710. canvas.before(content);
  4711. }
  4712. return content;
  4713. };
  4714. AnnotationEditor.prototype.resetAnnotationElement = function (annotation) {
  4715. var firstChild = annotation.container.firstChild;
  4716. if (firstChild.nodeName === "DIV" && firstChild.classList.contains("annotationContent")) {
  4717. firstChild.remove();
  4718. }
  4719. };
  4720. var _AnnotationEditor_instances, _f, _AnnotationEditor_allResizerDivs, _AnnotationEditor_altText, _AnnotationEditor_disabled, _AnnotationEditor_keepAspectRatio, _AnnotationEditor_resizersDiv, _AnnotationEditor_savedDimensions, _AnnotationEditor_boundFocusin, _AnnotationEditor_boundFocusout, _AnnotationEditor_editToolbar, _AnnotationEditor_focusedResizerName, _AnnotationEditor_hasBeenClicked, _AnnotationEditor_initialPosition, _AnnotationEditor_isEditing, _AnnotationEditor_isInEditMode, _AnnotationEditor_isResizerEnabledForKeyboard, _AnnotationEditor_moveInDOMTimeout, _AnnotationEditor_prevDragX, _AnnotationEditor_prevDragY, _AnnotationEditor_telemetryTimeouts, _AnnotationEditor_isDraggable, _AnnotationEditor_zIndex, _AnnotationEditor_translate, _AnnotationEditor_rotatePoint, _AnnotationEditor_getRotationMatrix, _AnnotationEditor_createResizers, _AnnotationEditor_resizerPointerdown, _AnnotationEditor_addResizeToUndoStack, _AnnotationEditor_resizerPointermove, _AnnotationEditor_selectOnPointerEvent, _AnnotationEditor_setUpDragSession, _AnnotationEditor_resizerKeydown, _AnnotationEditor_resizerBlur, _AnnotationEditor_resizerFocus, _AnnotationEditor_setResizerTabIndex, _AnnotationEditor_stopResizing;
  4721. _f = AnnotationEditor, _AnnotationEditor_allResizerDivs = new WeakMap(), _AnnotationEditor_altText = new WeakMap(), _AnnotationEditor_disabled = new WeakMap(), _AnnotationEditor_keepAspectRatio = new WeakMap(), _AnnotationEditor_resizersDiv = new WeakMap(), _AnnotationEditor_savedDimensions = new WeakMap(), _AnnotationEditor_boundFocusin = new WeakMap(), _AnnotationEditor_boundFocusout = new WeakMap(), _AnnotationEditor_editToolbar = new WeakMap(), _AnnotationEditor_focusedResizerName = new WeakMap(), _AnnotationEditor_hasBeenClicked = new WeakMap(), _AnnotationEditor_initialPosition = new WeakMap(), _AnnotationEditor_isEditing = new WeakMap(), _AnnotationEditor_isInEditMode = new WeakMap(), _AnnotationEditor_isResizerEnabledForKeyboard = new WeakMap(), _AnnotationEditor_moveInDOMTimeout = new WeakMap(), _AnnotationEditor_prevDragX = new WeakMap(), _AnnotationEditor_prevDragY = new WeakMap(), _AnnotationEditor_telemetryTimeouts = new WeakMap(), _AnnotationEditor_isDraggable = new WeakMap(), _AnnotationEditor_zIndex = new WeakMap(), _AnnotationEditor_instances = new WeakSet(), _AnnotationEditor_translate = function _AnnotationEditor_translate(_g, x, y) {
  4722. var _h;
  4723. var width = _g[0], height = _g[1];
  4724. _h = this.screenToPageTranslation(x, y), x = _h[0], y = _h[1];
  4725. this.x += x / width;
  4726. this.y += y / height;
  4727. this.fixAndSetPosition();
  4728. }, _AnnotationEditor_rotatePoint = function _AnnotationEditor_rotatePoint(x, y, angle) {
  4729. switch (angle) {
  4730. case 90:
  4731. return [y, -x];
  4732. case 180:
  4733. return [-x, -y];
  4734. case 270:
  4735. return [-y, x];
  4736. default:
  4737. return [x, y];
  4738. }
  4739. }, _AnnotationEditor_getRotationMatrix = function _AnnotationEditor_getRotationMatrix(rotation) {
  4740. switch (rotation) {
  4741. case 90:
  4742. {
  4743. var _g = this.pageDimensions, pageWidth = _g[0], pageHeight = _g[1];
  4744. return [0, -pageWidth / pageHeight, pageHeight / pageWidth, 0];
  4745. }
  4746. case 180:
  4747. return [-1, 0, 0, -1];
  4748. case 270:
  4749. {
  4750. var _h = this.pageDimensions, pageWidth = _h[0], pageHeight = _h[1];
  4751. return [0, pageWidth / pageHeight, -pageHeight / pageWidth, 0];
  4752. }
  4753. default:
  4754. return [1, 0, 0, 1];
  4755. }
  4756. }, _AnnotationEditor_createResizers = function _AnnotationEditor_createResizers() {
  4757. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_resizersDiv, "f")) {
  4758. return;
  4759. }
  4760. tslib_1.__classPrivateFieldSet(this, _AnnotationEditor_resizersDiv, document.createElement("div"), "f");
  4761. tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_resizersDiv, "f").classList.add("resizers");
  4762. var classes = this._willKeepAspectRatio ? ["topLeft", "topRight", "bottomRight", "bottomLeft"] : ["topLeft", "topMiddle", "topRight", "middleRight", "bottomRight", "bottomMiddle", "bottomLeft", "middleLeft"];
  4763. for (var _i = 0, classes_1 = classes; _i < classes_1.length; _i++) {
  4764. var name = classes_1[_i];
  4765. var div = document.createElement("div");
  4766. tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_resizersDiv, "f").append(div);
  4767. div.classList.add("resizer", name);
  4768. div.setAttribute("data-resizer-name", name);
  4769. div.addEventListener("pointerdown", tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_instances, "m", _AnnotationEditor_resizerPointerdown).bind(this, name));
  4770. div.addEventListener("contextmenu", noContextMenu);
  4771. div.tabIndex = -1;
  4772. }
  4773. this.div.prepend(tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_resizersDiv, "f"));
  4774. }, _AnnotationEditor_resizerPointerdown = function _AnnotationEditor_resizerPointerdown(name, event) {
  4775. var _this = this;
  4776. var _g;
  4777. event.preventDefault();
  4778. var isMac = util_FeatureTest.platform.isMac;
  4779. if (event.button !== 0 || event.ctrlKey && isMac) {
  4780. return;
  4781. }
  4782. (_g = tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_altText, "f")) === null || _g === void 0 ? void 0 : _g.toggle(false);
  4783. var boundResizerPointermove = tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_instances, "m", _AnnotationEditor_resizerPointermove).bind(this, name);
  4784. var savedDraggable = this._isDraggable;
  4785. this._isDraggable = false;
  4786. var pointerMoveOptions = {
  4787. passive: true,
  4788. capture: true
  4789. };
  4790. this.parent.togglePointerEvents(false);
  4791. window.addEventListener("pointermove", boundResizerPointermove, pointerMoveOptions);
  4792. window.addEventListener("contextmenu", noContextMenu);
  4793. var savedX = this.x;
  4794. var savedY = this.y;
  4795. var savedWidth = this.width;
  4796. var savedHeight = this.height;
  4797. var savedParentCursor = this.parent.div.style.cursor;
  4798. var savedCursor = this.div.style.cursor;
  4799. this.div.style.cursor = this.parent.div.style.cursor = window.getComputedStyle(event.target).cursor;
  4800. var pointerUpCallback = function () {
  4801. var _g;
  4802. _this.parent.togglePointerEvents(true);
  4803. (_g = tslib_1.__classPrivateFieldGet(_this, _AnnotationEditor_altText, "f")) === null || _g === void 0 ? void 0 : _g.toggle(true);
  4804. _this._isDraggable = savedDraggable;
  4805. window.removeEventListener("pointerup", pointerUpCallback);
  4806. window.removeEventListener("blur", pointerUpCallback);
  4807. window.removeEventListener("pointermove", boundResizerPointermove, pointerMoveOptions);
  4808. window.removeEventListener("contextmenu", noContextMenu);
  4809. _this.parent.div.style.cursor = savedParentCursor;
  4810. _this.div.style.cursor = savedCursor;
  4811. tslib_1.__classPrivateFieldGet(_this, _AnnotationEditor_instances, "m", _AnnotationEditor_addResizeToUndoStack).call(_this, savedX, savedY, savedWidth, savedHeight);
  4812. };
  4813. window.addEventListener("pointerup", pointerUpCallback);
  4814. window.addEventListener("blur", pointerUpCallback);
  4815. }, _AnnotationEditor_addResizeToUndoStack = function _AnnotationEditor_addResizeToUndoStack(savedX, savedY, savedWidth, savedHeight) {
  4816. var _this = this;
  4817. var newX = this.x;
  4818. var newY = this.y;
  4819. var newWidth = this.width;
  4820. var newHeight = this.height;
  4821. if (newX === savedX && newY === savedY && newWidth === savedWidth && newHeight === savedHeight) {
  4822. return;
  4823. }
  4824. this.addCommands({
  4825. cmd: function () {
  4826. _this.width = newWidth;
  4827. _this.height = newHeight;
  4828. _this.x = newX;
  4829. _this.y = newY;
  4830. var _g = _this.parentDimensions, parentWidth = _g[0], parentHeight = _g[1];
  4831. _this.setDims(parentWidth * newWidth, parentHeight * newHeight);
  4832. _this.fixAndSetPosition();
  4833. },
  4834. undo: function () {
  4835. _this.width = savedWidth;
  4836. _this.height = savedHeight;
  4837. _this.x = savedX;
  4838. _this.y = savedY;
  4839. var _g = _this.parentDimensions, parentWidth = _g[0], parentHeight = _g[1];
  4840. _this.setDims(parentWidth * savedWidth, parentHeight * savedHeight);
  4841. _this.fixAndSetPosition();
  4842. },
  4843. mustExec: true
  4844. });
  4845. }, _AnnotationEditor_resizerPointermove = function _AnnotationEditor_resizerPointermove(name, event) {
  4846. var _g;
  4847. var _h = this.parentDimensions, parentWidth = _h[0], parentHeight = _h[1];
  4848. var savedX = this.x;
  4849. var savedY = this.y;
  4850. var savedWidth = this.width;
  4851. var savedHeight = this.height;
  4852. var minWidth = AnnotationEditor.MIN_SIZE / parentWidth;
  4853. var minHeight = AnnotationEditor.MIN_SIZE / parentHeight;
  4854. var round = function (x) { return Math.round(x * 10000) / 10000; };
  4855. var rotationMatrix = tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_instances, "m", _AnnotationEditor_getRotationMatrix).call(this, this.rotation);
  4856. var transf = function (x, y) { return [rotationMatrix[0] * x + rotationMatrix[2] * y, rotationMatrix[1] * x + rotationMatrix[3] * y]; };
  4857. var invRotationMatrix = tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_instances, "m", _AnnotationEditor_getRotationMatrix).call(this, 360 - this.rotation);
  4858. var invTransf = function (x, y) { return [invRotationMatrix[0] * x + invRotationMatrix[2] * y, invRotationMatrix[1] * x + invRotationMatrix[3] * y]; };
  4859. var getPoint;
  4860. var getOpposite;
  4861. var isDiagonal = false;
  4862. var isHorizontal = false;
  4863. switch (name) {
  4864. case "topLeft":
  4865. isDiagonal = true;
  4866. getPoint = function (w, h) { return [0, 0]; };
  4867. getOpposite = function (w, h) { return [w, h]; };
  4868. break;
  4869. case "topMiddle":
  4870. getPoint = function (w, h) { return [w / 2, 0]; };
  4871. getOpposite = function (w, h) { return [w / 2, h]; };
  4872. break;
  4873. case "topRight":
  4874. isDiagonal = true;
  4875. getPoint = function (w, h) { return [w, 0]; };
  4876. getOpposite = function (w, h) { return [0, h]; };
  4877. break;
  4878. case "middleRight":
  4879. isHorizontal = true;
  4880. getPoint = function (w, h) { return [w, h / 2]; };
  4881. getOpposite = function (w, h) { return [0, h / 2]; };
  4882. break;
  4883. case "bottomRight":
  4884. isDiagonal = true;
  4885. getPoint = function (w, h) { return [w, h]; };
  4886. getOpposite = function (w, h) { return [0, 0]; };
  4887. break;
  4888. case "bottomMiddle":
  4889. getPoint = function (w, h) { return [w / 2, h]; };
  4890. getOpposite = function (w, h) { return [w / 2, 0]; };
  4891. break;
  4892. case "bottomLeft":
  4893. isDiagonal = true;
  4894. getPoint = function (w, h) { return [0, h]; };
  4895. getOpposite = function (w, h) { return [w, 0]; };
  4896. break;
  4897. case "middleLeft":
  4898. isHorizontal = true;
  4899. getPoint = function (w, h) { return [0, h / 2]; };
  4900. getOpposite = function (w, h) { return [w, h / 2]; };
  4901. break;
  4902. }
  4903. var point = getPoint(savedWidth, savedHeight);
  4904. var oppositePoint = getOpposite(savedWidth, savedHeight);
  4905. var transfOppositePoint = transf.apply(void 0, oppositePoint);
  4906. var oppositeX = round(savedX + transfOppositePoint[0]);
  4907. var oppositeY = round(savedY + transfOppositePoint[1]);
  4908. var ratioX = 1;
  4909. var ratioY = 1;
  4910. var _j = this.screenToPageTranslation(event.movementX, event.movementY), deltaX = _j[0], deltaY = _j[1];
  4911. _g = invTransf(deltaX / parentWidth, deltaY / parentHeight), deltaX = _g[0], deltaY = _g[1];
  4912. if (isDiagonal) {
  4913. var oldDiag = Math.hypot(savedWidth, savedHeight);
  4914. 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);
  4915. }
  4916. else if (isHorizontal) {
  4917. ratioX = Math.max(minWidth, Math.min(1, Math.abs(oppositePoint[0] - point[0] - deltaX))) / savedWidth;
  4918. }
  4919. else {
  4920. ratioY = Math.max(minHeight, Math.min(1, Math.abs(oppositePoint[1] - point[1] - deltaY))) / savedHeight;
  4921. }
  4922. var newWidth = round(savedWidth * ratioX);
  4923. var newHeight = round(savedHeight * ratioY);
  4924. transfOppositePoint = transf.apply(void 0, getOpposite(newWidth, newHeight));
  4925. var newX = oppositeX - transfOppositePoint[0];
  4926. var newY = oppositeY - transfOppositePoint[1];
  4927. this.width = newWidth;
  4928. this.height = newHeight;
  4929. this.x = newX;
  4930. this.y = newY;
  4931. this.setDims(parentWidth * newWidth, parentHeight * newHeight);
  4932. this.fixAndSetPosition();
  4933. }, _AnnotationEditor_selectOnPointerEvent = function _AnnotationEditor_selectOnPointerEvent(event) {
  4934. var isMac = util_FeatureTest.platform.isMac;
  4935. if (event.ctrlKey && !isMac || event.shiftKey || event.metaKey && isMac) {
  4936. this.parent.toggleSelected(this);
  4937. }
  4938. else {
  4939. this.parent.setSelected(this);
  4940. }
  4941. }, _AnnotationEditor_setUpDragSession = function _AnnotationEditor_setUpDragSession(event) {
  4942. var _this = this;
  4943. var isSelected = this._uiManager.isSelected(this);
  4944. this._uiManager.setUpDragSession();
  4945. var pointerMoveOptions, pointerMoveCallback;
  4946. if (isSelected) {
  4947. this.div.classList.add("moving");
  4948. pointerMoveOptions = {
  4949. passive: true,
  4950. capture: true
  4951. };
  4952. tslib_1.__classPrivateFieldSet(this, _AnnotationEditor_prevDragX, event.clientX, "f");
  4953. tslib_1.__classPrivateFieldSet(this, _AnnotationEditor_prevDragY, event.clientY, "f");
  4954. pointerMoveCallback = function (e) {
  4955. var x = e.clientX, y = e.clientY;
  4956. var _g = _this.screenToPageTranslation(x - tslib_1.__classPrivateFieldGet(_this, _AnnotationEditor_prevDragX, "f"), y - tslib_1.__classPrivateFieldGet(_this, _AnnotationEditor_prevDragY, "f")), tx = _g[0], ty = _g[1];
  4957. tslib_1.__classPrivateFieldSet(_this, _AnnotationEditor_prevDragX, x, "f");
  4958. tslib_1.__classPrivateFieldSet(_this, _AnnotationEditor_prevDragY, y, "f");
  4959. _this._uiManager.dragSelectedEditors(tx, ty);
  4960. };
  4961. window.addEventListener("pointermove", pointerMoveCallback, pointerMoveOptions);
  4962. }
  4963. var pointerUpCallback = function () {
  4964. window.removeEventListener("pointerup", pointerUpCallback);
  4965. window.removeEventListener("blur", pointerUpCallback);
  4966. if (isSelected) {
  4967. _this.div.classList.remove("moving");
  4968. window.removeEventListener("pointermove", pointerMoveCallback, pointerMoveOptions);
  4969. }
  4970. tslib_1.__classPrivateFieldSet(_this, _AnnotationEditor_hasBeenClicked, false, "f");
  4971. if (!_this._uiManager.endDragSession()) {
  4972. tslib_1.__classPrivateFieldGet(_this, _AnnotationEditor_instances, "m", _AnnotationEditor_selectOnPointerEvent).call(_this, event);
  4973. }
  4974. };
  4975. window.addEventListener("pointerup", pointerUpCallback);
  4976. window.addEventListener("blur", pointerUpCallback);
  4977. }, _AnnotationEditor_resizerKeydown = function _AnnotationEditor_resizerKeydown(event) {
  4978. AnnotationEditor._resizerKeyboardManager.exec(this, event);
  4979. }, _AnnotationEditor_resizerBlur = function _AnnotationEditor_resizerBlur(event) {
  4980. var _g;
  4981. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_isResizerEnabledForKeyboard, "f") && ((_g = event.relatedTarget) === null || _g === void 0 ? void 0 : _g.parentNode) !== tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_resizersDiv, "f")) {
  4982. tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_instances, "m", _AnnotationEditor_stopResizing).call(this);
  4983. }
  4984. }, _AnnotationEditor_resizerFocus = function _AnnotationEditor_resizerFocus(name) {
  4985. tslib_1.__classPrivateFieldSet(this, _AnnotationEditor_focusedResizerName, tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_isResizerEnabledForKeyboard, "f") ? name : "", "f");
  4986. }, _AnnotationEditor_setResizerTabIndex = function _AnnotationEditor_setResizerTabIndex(value) {
  4987. if (!tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_allResizerDivs, "f")) {
  4988. return;
  4989. }
  4990. for (var _i = 0, _g = tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_allResizerDivs, "f"); _i < _g.length; _i++) {
  4991. var div = _g[_i];
  4992. div.tabIndex = value;
  4993. }
  4994. }, _AnnotationEditor_stopResizing = function _AnnotationEditor_stopResizing() {
  4995. tslib_1.__classPrivateFieldSet(this, _AnnotationEditor_isResizerEnabledForKeyboard, false, "f");
  4996. tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_instances, "m", _AnnotationEditor_setResizerTabIndex).call(this, -1);
  4997. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_savedDimensions, "f")) {
  4998. var _g = tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_savedDimensions, "f"), savedX = _g.savedX, savedY = _g.savedY, savedWidth = _g.savedWidth, savedHeight = _g.savedHeight;
  4999. tslib_1.__classPrivateFieldGet(this, _AnnotationEditor_instances, "m", _AnnotationEditor_addResizeToUndoStack).call(this, savedX, savedY, savedWidth, savedHeight);
  5000. tslib_1.__classPrivateFieldSet(this, _AnnotationEditor_savedDimensions, null, "f");
  5001. }
  5002. };
  5003. AnnotationEditor._borderLineWidth = -1;
  5004. AnnotationEditor._colorManager = new ColorManager();
  5005. AnnotationEditor._zIndex = 1;
  5006. AnnotationEditor._telemetryTimeout = 1000;
  5007. return AnnotationEditor;
  5008. }());
  5009. var FakeEditor = /** @class */ (function (_super) {
  5010. tslib_1.__extends(FakeEditor, _super);
  5011. function FakeEditor(params) {
  5012. var _this = _super.call(this, params) || this;
  5013. _this.annotationElementId = params.annotationElementId;
  5014. _this.deleted = true;
  5015. return _this;
  5016. }
  5017. FakeEditor.prototype.serialize = function () {
  5018. return {
  5019. id: this.annotationElementId,
  5020. deleted: true,
  5021. pageIndex: this.pageIndex
  5022. };
  5023. };
  5024. return FakeEditor;
  5025. }(AnnotationEditor));
  5026. ; // CONCATENATED MODULE: ./src/shared/murmurhash3.js
  5027. var SEED = 0xc3d2e1f0;
  5028. var MASK_HIGH = 0xffff0000;
  5029. var MASK_LOW = 0xffff;
  5030. var MurmurHash3_64 = /** @class */ (function () {
  5031. function MurmurHash3_64(seed) {
  5032. this.h1 = seed ? seed & 0xffffffff : SEED;
  5033. this.h2 = seed ? seed & 0xffffffff : SEED;
  5034. }
  5035. MurmurHash3_64.prototype.update = function (input) {
  5036. var data, length;
  5037. if (typeof input === "string") {
  5038. data = new Uint8Array(input.length * 2);
  5039. length = 0;
  5040. for (var i = 0, ii = input.length; i < ii; i++) {
  5041. var code = input.charCodeAt(i);
  5042. if (code <= 0xff) {
  5043. data[length++] = code;
  5044. }
  5045. else {
  5046. data[length++] = code >>> 8;
  5047. data[length++] = code & 0xff;
  5048. }
  5049. }
  5050. }
  5051. else if (ArrayBuffer.isView(input)) {
  5052. data = input.slice();
  5053. length = data.byteLength;
  5054. }
  5055. else {
  5056. throw new Error("Invalid data format, must be a string or TypedArray.");
  5057. }
  5058. var blockCounts = length >> 2;
  5059. var tailLength = length - blockCounts * 4;
  5060. var dataUint32 = new Uint32Array(data.buffer, 0, blockCounts);
  5061. var k1 = 0, k2 = 0;
  5062. var h1 = this.h1, h2 = this.h2;
  5063. var C1 = 0xcc9e2d51, C2 = 0x1b873593;
  5064. var C1_LOW = C1 & MASK_LOW, C2_LOW = C2 & MASK_LOW;
  5065. for (var i = 0; i < blockCounts; i++) {
  5066. if (i & 1) {
  5067. k1 = dataUint32[i];
  5068. k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
  5069. k1 = k1 << 15 | k1 >>> 17;
  5070. k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
  5071. h1 ^= k1;
  5072. h1 = h1 << 13 | h1 >>> 19;
  5073. h1 = h1 * 5 + 0xe6546b64;
  5074. }
  5075. else {
  5076. k2 = dataUint32[i];
  5077. k2 = k2 * C1 & MASK_HIGH | k2 * C1_LOW & MASK_LOW;
  5078. k2 = k2 << 15 | k2 >>> 17;
  5079. k2 = k2 * C2 & MASK_HIGH | k2 * C2_LOW & MASK_LOW;
  5080. h2 ^= k2;
  5081. h2 = h2 << 13 | h2 >>> 19;
  5082. h2 = h2 * 5 + 0xe6546b64;
  5083. }
  5084. }
  5085. k1 = 0;
  5086. switch (tailLength) {
  5087. case 3:
  5088. k1 ^= data[blockCounts * 4 + 2] << 16;
  5089. case 2:
  5090. k1 ^= data[blockCounts * 4 + 1] << 8;
  5091. case 1:
  5092. k1 ^= data[blockCounts * 4];
  5093. k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
  5094. k1 = k1 << 15 | k1 >>> 17;
  5095. k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
  5096. if (blockCounts & 1) {
  5097. h1 ^= k1;
  5098. }
  5099. else {
  5100. h2 ^= k1;
  5101. }
  5102. }
  5103. this.h1 = h1;
  5104. this.h2 = h2;
  5105. };
  5106. MurmurHash3_64.prototype.hexdigest = function () {
  5107. var h1 = this.h1, h2 = this.h2;
  5108. h1 ^= h2 >>> 1;
  5109. h1 = h1 * 0xed558ccd & MASK_HIGH | h1 * 0x8ccd & MASK_LOW;
  5110. h2 = h2 * 0xff51afd7 & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16;
  5111. h1 ^= h2 >>> 1;
  5112. h1 = h1 * 0x1a85ec53 & MASK_HIGH | h1 * 0xec53 & MASK_LOW;
  5113. h2 = h2 * 0xc4ceb9fe & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16;
  5114. h1 ^= h2 >>> 1;
  5115. return (h1 >>> 0).toString(16).padStart(8, "0") + (h2 >>> 0).toString(16).padStart(8, "0");
  5116. };
  5117. return MurmurHash3_64;
  5118. }());
  5119. ; // CONCATENATED MODULE: ./src/display/annotation_storage.js
  5120. var SerializableEmpty = Object.freeze({
  5121. map: null,
  5122. hash: "",
  5123. transfer: undefined
  5124. });
  5125. var AnnotationStorage = /** @class */ (function () {
  5126. function AnnotationStorage() {
  5127. _AnnotationStorage_instances.add(this);
  5128. _AnnotationStorage_modified.set(this, false);
  5129. _AnnotationStorage_storage.set(this, new Map());
  5130. this.onSetModified = null;
  5131. this.onResetModified = null;
  5132. this.onAnnotationEditor = null;
  5133. }
  5134. AnnotationStorage.prototype.getValue = function (key, defaultValue) {
  5135. var value = tslib_1.__classPrivateFieldGet(this, _AnnotationStorage_storage, "f").get(key);
  5136. if (value === undefined) {
  5137. return defaultValue;
  5138. }
  5139. return Object.assign(defaultValue, value);
  5140. };
  5141. AnnotationStorage.prototype.getRawValue = function (key) {
  5142. return tslib_1.__classPrivateFieldGet(this, _AnnotationStorage_storage, "f").get(key);
  5143. };
  5144. AnnotationStorage.prototype.remove = function (key) {
  5145. tslib_1.__classPrivateFieldGet(this, _AnnotationStorage_storage, "f").delete(key);
  5146. if (tslib_1.__classPrivateFieldGet(this, _AnnotationStorage_storage, "f").size === 0) {
  5147. this.resetModified();
  5148. }
  5149. if (typeof this.onAnnotationEditor === "function") {
  5150. for (var _i = 0, _g = tslib_1.__classPrivateFieldGet(this, _AnnotationStorage_storage, "f").values(); _i < _g.length; _i++) {
  5151. var value = _g[_i];
  5152. if (value instanceof AnnotationEditor) {
  5153. return;
  5154. }
  5155. }
  5156. this.onAnnotationEditor(null);
  5157. }
  5158. };
  5159. AnnotationStorage.prototype.setValue = function (key, value) {
  5160. var obj = tslib_1.__classPrivateFieldGet(this, _AnnotationStorage_storage, "f").get(key);
  5161. var modified = false;
  5162. if (obj !== undefined) {
  5163. for (var _i = 0, _g = Object.entries(value); _i < _g.length; _i++) {
  5164. var _h = _g[_i], entry = _h[0], val = _h[1];
  5165. if (obj[entry] !== val) {
  5166. modified = true;
  5167. obj[entry] = val;
  5168. }
  5169. }
  5170. }
  5171. else {
  5172. modified = true;
  5173. tslib_1.__classPrivateFieldGet(this, _AnnotationStorage_storage, "f").set(key, value);
  5174. }
  5175. if (modified) {
  5176. tslib_1.__classPrivateFieldGet(this, _AnnotationStorage_instances, "m", _AnnotationStorage_setModified).call(this);
  5177. }
  5178. if (value instanceof AnnotationEditor && typeof this.onAnnotationEditor === "function") {
  5179. this.onAnnotationEditor(value.constructor._type);
  5180. }
  5181. };
  5182. AnnotationStorage.prototype.has = function (key) {
  5183. return tslib_1.__classPrivateFieldGet(this, _AnnotationStorage_storage, "f").has(key);
  5184. };
  5185. AnnotationStorage.prototype.getAll = function () {
  5186. return tslib_1.__classPrivateFieldGet(this, _AnnotationStorage_storage, "f").size > 0 ? objectFromMap(tslib_1.__classPrivateFieldGet(this, _AnnotationStorage_storage, "f")) : null;
  5187. };
  5188. AnnotationStorage.prototype.setAll = function (obj) {
  5189. for (var _i = 0, _g = Object.entries(obj); _i < _g.length; _i++) {
  5190. var _h = _g[_i], key = _h[0], val = _h[1];
  5191. this.setValue(key, val);
  5192. }
  5193. };
  5194. Object.defineProperty(AnnotationStorage.prototype, "size", {
  5195. get: function () {
  5196. return tslib_1.__classPrivateFieldGet(this, _AnnotationStorage_storage, "f").size;
  5197. },
  5198. enumerable: false,
  5199. configurable: true
  5200. });
  5201. AnnotationStorage.prototype.resetModified = function () {
  5202. if (tslib_1.__classPrivateFieldGet(this, _AnnotationStorage_modified, "f")) {
  5203. tslib_1.__classPrivateFieldSet(this, _AnnotationStorage_modified, false, "f");
  5204. if (typeof this.onResetModified === "function") {
  5205. this.onResetModified();
  5206. }
  5207. }
  5208. };
  5209. Object.defineProperty(AnnotationStorage.prototype, "print", {
  5210. get: function () {
  5211. return new PrintAnnotationStorage(this);
  5212. },
  5213. enumerable: false,
  5214. configurable: true
  5215. });
  5216. Object.defineProperty(AnnotationStorage.prototype, "serializable", {
  5217. get: function () {
  5218. if (tslib_1.__classPrivateFieldGet(this, _AnnotationStorage_storage, "f").size === 0) {
  5219. return SerializableEmpty;
  5220. }
  5221. var map = new Map(), hash = new MurmurHash3_64(), transfer = [];
  5222. var context = Object.create(null);
  5223. var hasBitmap = false;
  5224. for (var _i = 0, _g = tslib_1.__classPrivateFieldGet(this, _AnnotationStorage_storage, "f"); _i < _g.length; _i++) {
  5225. var _h = _g[_i], key = _h[0], val = _h[1];
  5226. var serialized = val instanceof AnnotationEditor ? val.serialize(false, context) : val;
  5227. if (serialized) {
  5228. map.set(key, serialized);
  5229. hash.update("".concat(key, ":").concat(JSON.stringify(serialized)));
  5230. hasBitmap || (hasBitmap = !!serialized.bitmap);
  5231. }
  5232. }
  5233. if (hasBitmap) {
  5234. for (var _j = 0, _k = map.values(); _j < _k.length; _j++) {
  5235. var value = _k[_j];
  5236. if (value.bitmap) {
  5237. transfer.push(value.bitmap);
  5238. }
  5239. }
  5240. }
  5241. return map.size > 0 ? {
  5242. map: map,
  5243. hash: hash.hexdigest(),
  5244. transfer: transfer
  5245. } : SerializableEmpty;
  5246. },
  5247. enumerable: false,
  5248. configurable: true
  5249. });
  5250. Object.defineProperty(AnnotationStorage.prototype, "editorStats", {
  5251. get: function () {
  5252. var _g;
  5253. var stats = null;
  5254. var typeToEditor = new Map();
  5255. for (var _i = 0, _h = tslib_1.__classPrivateFieldGet(this, _AnnotationStorage_storage, "f").values(); _i < _h.length; _i++) {
  5256. var value = _h[_i];
  5257. if (!(value instanceof AnnotationEditor)) {
  5258. continue;
  5259. }
  5260. var editorStats = value.telemetryFinalData;
  5261. if (!editorStats) {
  5262. continue;
  5263. }
  5264. var type = editorStats.type;
  5265. if (!typeToEditor.has(type)) {
  5266. typeToEditor.set(type, Object.getPrototypeOf(value).constructor);
  5267. }
  5268. stats || (stats = Object.create(null));
  5269. var map = stats[type] || (stats[type] = new Map());
  5270. for (var _j = 0, _k = Object.entries(editorStats); _j < _k.length; _j++) {
  5271. var _l = _k[_j], key = _l[0], val = _l[1];
  5272. if (key === "type") {
  5273. continue;
  5274. }
  5275. var counters = map.get(key);
  5276. if (!counters) {
  5277. counters = new Map();
  5278. map.set(key, counters);
  5279. }
  5280. var count = (_g = counters.get(val)) !== null && _g !== void 0 ? _g : 0;
  5281. counters.set(val, count + 1);
  5282. }
  5283. }
  5284. for (var _m = 0, typeToEditor_1 = typeToEditor; _m < typeToEditor_1.length; _m++) {
  5285. var _o = typeToEditor_1[_m], type = _o[0], editor = _o[1];
  5286. stats[type] = editor.computeTelemetryFinalData(stats[type]);
  5287. }
  5288. return stats;
  5289. },
  5290. enumerable: false,
  5291. configurable: true
  5292. });
  5293. return AnnotationStorage;
  5294. }());
  5295. _AnnotationStorage_modified = new WeakMap(), _AnnotationStorage_storage = new WeakMap(), _AnnotationStorage_instances = new WeakSet(), _AnnotationStorage_setModified = function _AnnotationStorage_setModified() {
  5296. if (!tslib_1.__classPrivateFieldGet(this, _AnnotationStorage_modified, "f")) {
  5297. tslib_1.__classPrivateFieldSet(this, _AnnotationStorage_modified, true, "f");
  5298. if (typeof this.onSetModified === "function") {
  5299. this.onSetModified();
  5300. }
  5301. }
  5302. };
  5303. var PrintAnnotationStorage = /** @class */ (function (_super) {
  5304. tslib_1.__extends(PrintAnnotationStorage, _super);
  5305. function PrintAnnotationStorage(parent) {
  5306. var _this = _super.call(this) || this;
  5307. _PrintAnnotationStorage_serializable.set(_this, void 0);
  5308. var _g = parent.serializable, map = _g.map, hash = _g.hash, transfer = _g.transfer;
  5309. var clone = structuredClone(map, transfer ? {
  5310. transfer: transfer
  5311. } : null);
  5312. tslib_1.__classPrivateFieldSet(_this, _PrintAnnotationStorage_serializable, {
  5313. map: clone,
  5314. hash: hash,
  5315. transfer: transfer
  5316. }, "f");
  5317. return _this;
  5318. }
  5319. Object.defineProperty(PrintAnnotationStorage.prototype, "print", {
  5320. get: function () {
  5321. unreachable("Should not call PrintAnnotationStorage.print");
  5322. },
  5323. enumerable: false,
  5324. configurable: true
  5325. });
  5326. Object.defineProperty(PrintAnnotationStorage.prototype, "serializable", {
  5327. get: function () {
  5328. return tslib_1.__classPrivateFieldGet(this, _PrintAnnotationStorage_serializable, "f");
  5329. },
  5330. enumerable: false,
  5331. configurable: true
  5332. });
  5333. return PrintAnnotationStorage;
  5334. }(AnnotationStorage));
  5335. _PrintAnnotationStorage_serializable = new WeakMap();
  5336. ; // CONCATENATED MODULE: ./src/display/font_loader.js
  5337. var FontLoader = /** @class */ (function () {
  5338. function FontLoader(_g) {
  5339. var _h = _g.ownerDocument, ownerDocument = _h === void 0 ? globalThis.document : _h, _j = _g.styleElement, styleElement = _j === void 0 ? null : _j;
  5340. _FontLoader_systemFonts.set(this, new Set());
  5341. this._document = ownerDocument;
  5342. this.nativeFontFaces = new Set();
  5343. this.styleElement = null;
  5344. this.loadingRequests = [];
  5345. this.loadTestFontId = 0;
  5346. }
  5347. FontLoader.prototype.addNativeFontFace = function (nativeFontFace) {
  5348. this.nativeFontFaces.add(nativeFontFace);
  5349. this._document.fonts.add(nativeFontFace);
  5350. };
  5351. FontLoader.prototype.removeNativeFontFace = function (nativeFontFace) {
  5352. this.nativeFontFaces.delete(nativeFontFace);
  5353. this._document.fonts.delete(nativeFontFace);
  5354. };
  5355. FontLoader.prototype.insertRule = function (rule) {
  5356. if (!this.styleElement) {
  5357. this.styleElement = this._document.createElement("style");
  5358. this._document.documentElement.getElementsByTagName("head")[0].append(this.styleElement);
  5359. }
  5360. var styleSheet = this.styleElement.sheet;
  5361. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  5362. };
  5363. FontLoader.prototype.clear = function () {
  5364. for (var _i = 0, _g = this.nativeFontFaces; _i < _g.length; _i++) {
  5365. var nativeFontFace = _g[_i];
  5366. this._document.fonts.delete(nativeFontFace);
  5367. }
  5368. this.nativeFontFaces.clear();
  5369. tslib_1.__classPrivateFieldGet(this, _FontLoader_systemFonts, "f").clear();
  5370. if (this.styleElement) {
  5371. this.styleElement.remove();
  5372. this.styleElement = null;
  5373. }
  5374. };
  5375. FontLoader.prototype.loadSystemFont = function (_g) {
  5376. var info = _g.systemFontInfo, _inspectFont = _g._inspectFont;
  5377. return tslib_1.__awaiter(this, void 0, void 0, function () {
  5378. var loadedName, src, style, fontFace, _h;
  5379. return tslib_1.__generator(this, function (_j) {
  5380. switch (_j.label) {
  5381. case 0:
  5382. if (!info || tslib_1.__classPrivateFieldGet(this, _FontLoader_systemFonts, "f").has(info.loadedName)) {
  5383. return [2 /*return*/];
  5384. }
  5385. assert(!this.disableFontFace, "loadSystemFont shouldn't be called when `disableFontFace` is set.");
  5386. if (!this.isFontLoadingAPISupported) return [3 /*break*/, 5];
  5387. loadedName = info.loadedName, src = info.src, style = info.style;
  5388. fontFace = new FontFace(loadedName, src, style);
  5389. this.addNativeFontFace(fontFace);
  5390. _j.label = 1;
  5391. case 1:
  5392. _j.trys.push([1, 3, , 4]);
  5393. return [4 /*yield*/, fontFace.load()];
  5394. case 2:
  5395. _j.sent();
  5396. tslib_1.__classPrivateFieldGet(this, _FontLoader_systemFonts, "f").add(loadedName);
  5397. _inspectFont === null || _inspectFont === void 0 ? void 0 : _inspectFont(info);
  5398. return [3 /*break*/, 4];
  5399. case 3:
  5400. _h = _j.sent();
  5401. warn("Cannot load system font: ".concat(info.baseFontName, ", installing it could help to improve PDF rendering."));
  5402. this.removeNativeFontFace(fontFace);
  5403. return [3 /*break*/, 4];
  5404. case 4: return [2 /*return*/];
  5405. case 5:
  5406. unreachable("Not implemented: loadSystemFont without the Font Loading API.");
  5407. return [2 /*return*/];
  5408. }
  5409. });
  5410. });
  5411. };
  5412. FontLoader.prototype.bind = function (font) {
  5413. return tslib_1.__awaiter(this, void 0, void 0, function () {
  5414. var nativeFontFace, ex_1, rule;
  5415. var _this = this;
  5416. return tslib_1.__generator(this, function (_g) {
  5417. switch (_g.label) {
  5418. case 0:
  5419. if (font.attached || font.missingFile && !font.systemFontInfo) {
  5420. return [2 /*return*/];
  5421. }
  5422. font.attached = true;
  5423. if (!font.systemFontInfo) return [3 /*break*/, 2];
  5424. return [4 /*yield*/, this.loadSystemFont(font)];
  5425. case 1:
  5426. _g.sent();
  5427. return [2 /*return*/];
  5428. case 2:
  5429. if (!this.isFontLoadingAPISupported) return [3 /*break*/, 7];
  5430. nativeFontFace = font.createNativeFontFace();
  5431. if (!nativeFontFace) return [3 /*break*/, 6];
  5432. this.addNativeFontFace(nativeFontFace);
  5433. _g.label = 3;
  5434. case 3:
  5435. _g.trys.push([3, 5, , 6]);
  5436. return [4 /*yield*/, nativeFontFace.loaded];
  5437. case 4:
  5438. _g.sent();
  5439. return [3 /*break*/, 6];
  5440. case 5:
  5441. ex_1 = _g.sent();
  5442. warn("Failed to load font '".concat(nativeFontFace.family, "': '").concat(ex_1, "'."));
  5443. font.disableFontFace = true;
  5444. throw ex_1;
  5445. case 6: return [2 /*return*/];
  5446. case 7:
  5447. rule = font.createFontFaceRule();
  5448. if (!rule) return [3 /*break*/, 9];
  5449. this.insertRule(rule);
  5450. if (this.isSyncFontLoadingSupported) {
  5451. return [2 /*return*/];
  5452. }
  5453. return [4 /*yield*/, new Promise(function (resolve) {
  5454. var request = _this._queueLoadingCallback(resolve);
  5455. _this._prepareFontLoadEvent(font, request);
  5456. })];
  5457. case 8:
  5458. _g.sent();
  5459. _g.label = 9;
  5460. case 9: return [2 /*return*/];
  5461. }
  5462. });
  5463. });
  5464. };
  5465. Object.defineProperty(FontLoader.prototype, "isFontLoadingAPISupported", {
  5466. get: function () {
  5467. var _g;
  5468. var hasFonts = !!((_g = this._document) === null || _g === void 0 ? void 0 : _g.fonts);
  5469. return shadow(this, "isFontLoadingAPISupported", hasFonts);
  5470. },
  5471. enumerable: false,
  5472. configurable: true
  5473. });
  5474. Object.defineProperty(FontLoader.prototype, "isSyncFontLoadingSupported", {
  5475. get: function () {
  5476. var supported = false;
  5477. if (isNodeJS) {
  5478. supported = true;
  5479. }
  5480. else if (typeof navigator !== "undefined" && typeof (navigator === null || navigator === void 0 ? void 0 : navigator.userAgent) === "string" && /Mozilla\/5.0.*?rv:\d+.*? Gecko/.test(navigator.userAgent)) {
  5481. supported = true;
  5482. }
  5483. return shadow(this, "isSyncFontLoadingSupported", supported);
  5484. },
  5485. enumerable: false,
  5486. configurable: true
  5487. });
  5488. FontLoader.prototype._queueLoadingCallback = function (callback) {
  5489. function completeRequest() {
  5490. assert(!request.done, "completeRequest() cannot be called twice.");
  5491. request.done = true;
  5492. while (loadingRequests.length > 0 && loadingRequests[0].done) {
  5493. var otherRequest = loadingRequests.shift();
  5494. setTimeout(otherRequest.callback, 0);
  5495. }
  5496. }
  5497. var loadingRequests = this.loadingRequests;
  5498. var request = {
  5499. done: false,
  5500. complete: completeRequest,
  5501. callback: callback
  5502. };
  5503. loadingRequests.push(request);
  5504. return request;
  5505. };
  5506. Object.defineProperty(FontLoader.prototype, "_loadTestFont", {
  5507. get: function () {
  5508. var 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==");
  5509. return shadow(this, "_loadTestFont", testFont);
  5510. },
  5511. enumerable: false,
  5512. configurable: true
  5513. });
  5514. FontLoader.prototype._prepareFontLoadEvent = function (font, request) {
  5515. function int32(data, offset) {
  5516. return data.charCodeAt(offset) << 24 | data.charCodeAt(offset + 1) << 16 | data.charCodeAt(offset + 2) << 8 | data.charCodeAt(offset + 3) & 0xff;
  5517. }
  5518. function spliceString(s, offset, remove, insert) {
  5519. var chunk1 = s.substring(0, offset);
  5520. var chunk2 = s.substring(offset + remove);
  5521. return chunk1 + insert + chunk2;
  5522. }
  5523. var i, ii;
  5524. var canvas = this._document.createElement("canvas");
  5525. canvas.width = 1;
  5526. canvas.height = 1;
  5527. var ctx = canvas.getContext("2d");
  5528. var called = 0;
  5529. function isFontReady(name, callback) {
  5530. if (++called > 30) {
  5531. warn("Load test font never loaded.");
  5532. callback();
  5533. return;
  5534. }
  5535. ctx.font = "30px " + name;
  5536. ctx.fillText(".", 0, 20);
  5537. var imageData = ctx.getImageData(0, 0, 1, 1);
  5538. if (imageData.data[3] > 0) {
  5539. callback();
  5540. return;
  5541. }
  5542. setTimeout(isFontReady.bind(null, name, callback));
  5543. }
  5544. var loadTestFontId = "lt".concat(Date.now()).concat(this.loadTestFontId++);
  5545. var data = this._loadTestFont;
  5546. var COMMENT_OFFSET = 976;
  5547. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length, loadTestFontId);
  5548. var CFF_CHECKSUM_OFFSET = 16;
  5549. var XXXX_VALUE = 0x58585858;
  5550. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  5551. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  5552. checksum = checksum - XXXX_VALUE + int32(loadTestFontId, i) | 0;
  5553. }
  5554. if (i < loadTestFontId.length) {
  5555. checksum = checksum - XXXX_VALUE + int32(loadTestFontId + "XXX", i) | 0;
  5556. }
  5557. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
  5558. var url = "url(data:font/opentype;base64,".concat(btoa(data), ");");
  5559. var rule = "@font-face {font-family:\"".concat(loadTestFontId, "\";src:").concat(url, "}");
  5560. this.insertRule(rule);
  5561. var div = this._document.createElement("div");
  5562. div.style.visibility = "hidden";
  5563. div.style.width = div.style.height = "10px";
  5564. div.style.position = "absolute";
  5565. div.style.top = div.style.left = "0px";
  5566. for (var _i = 0, _g = [font.loadedName, loadTestFontId]; _i < _g.length; _i++) {
  5567. var name = _g[_i];
  5568. var span = this._document.createElement("span");
  5569. span.textContent = "Hi";
  5570. span.style.fontFamily = name;
  5571. div.append(span);
  5572. }
  5573. this._document.body.append(div);
  5574. isFontReady(loadTestFontId, function () {
  5575. div.remove();
  5576. request.complete();
  5577. });
  5578. };
  5579. return FontLoader;
  5580. }());
  5581. _FontLoader_systemFonts = new WeakMap();
  5582. var FontFaceObject = /** @class */ (function () {
  5583. function FontFaceObject(translatedData, _g) {
  5584. var _h = _g.disableFontFace, disableFontFace = _h === void 0 ? false : _h, _j = _g.inspectFont, inspectFont = _j === void 0 ? null : _j;
  5585. this.compiledGlyphs = Object.create(null);
  5586. for (var i in translatedData) {
  5587. this[i] = translatedData[i];
  5588. }
  5589. this.disableFontFace = disableFontFace === true;
  5590. this._inspectFont = inspectFont;
  5591. }
  5592. FontFaceObject.prototype.createNativeFontFace = function () {
  5593. var _g;
  5594. if (!this.data || this.disableFontFace) {
  5595. return null;
  5596. }
  5597. var nativeFontFace;
  5598. if (!this.cssFontInfo) {
  5599. nativeFontFace = new FontFace(this.loadedName, this.data, {});
  5600. }
  5601. else {
  5602. var css = {
  5603. weight: this.cssFontInfo.fontWeight
  5604. };
  5605. if (this.cssFontInfo.italicAngle) {
  5606. css.style = "oblique ".concat(this.cssFontInfo.italicAngle, "deg");
  5607. }
  5608. nativeFontFace = new FontFace(this.cssFontInfo.fontFamily, this.data, css);
  5609. }
  5610. (_g = this._inspectFont) === null || _g === void 0 ? void 0 : _g.call(this, this);
  5611. return nativeFontFace;
  5612. };
  5613. FontFaceObject.prototype.createFontFaceRule = function () {
  5614. var _g;
  5615. if (!this.data || this.disableFontFace) {
  5616. return null;
  5617. }
  5618. var data = bytesToString(this.data);
  5619. var url = "url(data:".concat(this.mimetype, ";base64,").concat(btoa(data), ");");
  5620. var rule;
  5621. if (!this.cssFontInfo) {
  5622. rule = "@font-face {font-family:\"".concat(this.loadedName, "\";src:").concat(url, "}");
  5623. }
  5624. else {
  5625. var css = "font-weight: ".concat(this.cssFontInfo.fontWeight, ";");
  5626. if (this.cssFontInfo.italicAngle) {
  5627. css += "font-style: oblique ".concat(this.cssFontInfo.italicAngle, "deg;");
  5628. }
  5629. rule = "@font-face {font-family:\"".concat(this.cssFontInfo.fontFamily, "\";").concat(css, "src:").concat(url, "}");
  5630. }
  5631. (_g = this._inspectFont) === null || _g === void 0 ? void 0 : _g.call(this, this, url);
  5632. return rule;
  5633. };
  5634. FontFaceObject.prototype.getPathGenerator = function (objs, character) {
  5635. if (this.compiledGlyphs[character] !== undefined) {
  5636. return this.compiledGlyphs[character];
  5637. }
  5638. var cmds;
  5639. try {
  5640. cmds = objs.get(this.loadedName + "_path_" + character);
  5641. }
  5642. catch (ex) {
  5643. warn("getPathGenerator - ignoring character: \"".concat(ex, "\"."));
  5644. }
  5645. if (!Array.isArray(cmds) || cmds.length === 0) {
  5646. return this.compiledGlyphs[character] = function (c, size) { };
  5647. }
  5648. var commands = [];
  5649. var _loop_3 = function (i, ii) {
  5650. switch (cmds[i++]) {
  5651. case FontRenderOps.BEZIER_CURVE_TO:
  5652. {
  5653. var _g = cmds.slice(i, i + 6), a_1 = _g[0], b_1 = _g[1], c_1 = _g[2], d_1 = _g[3], e_2 = _g[4], f_1 = _g[5];
  5654. commands.push(function (ctx) { return ctx.bezierCurveTo(a_1, b_1, c_1, d_1, e_2, f_1); });
  5655. i += 6;
  5656. }
  5657. break;
  5658. case FontRenderOps.MOVE_TO:
  5659. {
  5660. var _h = cmds.slice(i, i + 2), a_2 = _h[0], b_2 = _h[1];
  5661. commands.push(function (ctx) { return ctx.moveTo(a_2, b_2); });
  5662. i += 2;
  5663. }
  5664. break;
  5665. case FontRenderOps.LINE_TO:
  5666. {
  5667. var _j = cmds.slice(i, i + 2), a_3 = _j[0], b_3 = _j[1];
  5668. commands.push(function (ctx) { return ctx.lineTo(a_3, b_3); });
  5669. i += 2;
  5670. }
  5671. break;
  5672. case FontRenderOps.QUADRATIC_CURVE_TO:
  5673. {
  5674. var _k = cmds.slice(i, i + 4), a_4 = _k[0], b_4 = _k[1], c_2 = _k[2], d_2 = _k[3];
  5675. commands.push(function (ctx) { return ctx.quadraticCurveTo(a_4, b_4, c_2, d_2); });
  5676. i += 4;
  5677. }
  5678. break;
  5679. case FontRenderOps.RESTORE:
  5680. commands.push(function (ctx) { return ctx.restore(); });
  5681. break;
  5682. case FontRenderOps.SAVE:
  5683. commands.push(function (ctx) { return ctx.save(); });
  5684. break;
  5685. case FontRenderOps.SCALE:
  5686. assert(commands.length === 2, "Scale command is only valid at the third position.");
  5687. break;
  5688. case FontRenderOps.TRANSFORM:
  5689. {
  5690. var _l = cmds.slice(i, i + 6), a_5 = _l[0], b_5 = _l[1], c_3 = _l[2], d_3 = _l[3], e_3 = _l[4], f_2 = _l[5];
  5691. commands.push(function (ctx) { return ctx.transform(a_5, b_5, c_3, d_3, e_3, f_2); });
  5692. i += 6;
  5693. }
  5694. break;
  5695. case FontRenderOps.TRANSLATE:
  5696. {
  5697. var _m = cmds.slice(i, i + 2), a_6 = _m[0], b_6 = _m[1];
  5698. commands.push(function (ctx) { return ctx.translate(a_6, b_6); });
  5699. i += 2;
  5700. }
  5701. break;
  5702. }
  5703. out_i_1 = i;
  5704. };
  5705. var out_i_1;
  5706. for (var i = 0, ii = cmds.length; i < ii;) {
  5707. _loop_3(i, ii);
  5708. i = out_i_1;
  5709. }
  5710. return this.compiledGlyphs[character] = function glyphDrawer(ctx, size) {
  5711. commands[0](ctx);
  5712. commands[1](ctx);
  5713. ctx.scale(size, -size);
  5714. for (var i = 2, ii = commands.length; i < ii; i++) {
  5715. commands[i](ctx);
  5716. }
  5717. };
  5718. };
  5719. return FontFaceObject;
  5720. }());
  5721. ; // CONCATENATED MODULE: ./src/display/node_utils.js
  5722. if (isNodeJS) {
  5723. var packageCapability = Promise.withResolvers();
  5724. var packageMap = null;
  5725. var loadPackages = function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
  5726. var fs, http, https, url, canvas, path2d;
  5727. return tslib_1.__generator(this, function (_g) {
  5728. switch (_g.label) {
  5729. case 0: return [4 /*yield*/, Promise.resolve().then(function () { return tslib_1.__importStar(require(/*webpackIgnore: true*/ "fs")); })];
  5730. case 1:
  5731. fs = _g.sent();
  5732. return [4 /*yield*/, Promise.resolve().then(function () { return tslib_1.__importStar(require(/*webpackIgnore: true*/ "http")); })];
  5733. case 2:
  5734. http = _g.sent();
  5735. return [4 /*yield*/, Promise.resolve().then(function () { return tslib_1.__importStar(require(/*webpackIgnore: true*/ "https")); })];
  5736. case 3:
  5737. https = _g.sent();
  5738. return [4 /*yield*/, Promise.resolve().then(function () { return tslib_1.__importStar(require(/*webpackIgnore: true*/ "url")); })];
  5739. case 4:
  5740. url = _g.sent();
  5741. return [2 /*return*/, new Map(Object.entries({
  5742. fs: fs,
  5743. http: http,
  5744. https: https,
  5745. url: url,
  5746. canvas: canvas,
  5747. path2d: path2d
  5748. }))];
  5749. }
  5750. });
  5751. }); };
  5752. loadPackages().then(function (map) {
  5753. packageMap = map;
  5754. packageCapability.resolve();
  5755. }, function (reason) {
  5756. warn("loadPackages: ".concat(reason));
  5757. packageMap = new Map();
  5758. packageCapability.resolve();
  5759. });
  5760. }
  5761. var NodePackages = /** @class */ (function () {
  5762. function NodePackages() {
  5763. }
  5764. Object.defineProperty(NodePackages, "promise", {
  5765. get: function () {
  5766. return packageCapability.promise;
  5767. },
  5768. enumerable: false,
  5769. configurable: true
  5770. });
  5771. NodePackages.get = function (name) {
  5772. return packageMap === null || packageMap === void 0 ? void 0 : packageMap.get(name);
  5773. };
  5774. return NodePackages;
  5775. }());
  5776. var node_utils_fetchData = function (url) {
  5777. var fs = NodePackages.get("fs");
  5778. return fs.promises.readFile(url).then(function (data) { return new Uint8Array(data); });
  5779. };
  5780. var NodeFilterFactory = /** @class */ (function (_super) {
  5781. tslib_1.__extends(NodeFilterFactory, _super);
  5782. function NodeFilterFactory() {
  5783. return _super !== null && _super.apply(this, arguments) || this;
  5784. }
  5785. return NodeFilterFactory;
  5786. }(BaseFilterFactory));
  5787. var NodeCanvasFactory = /** @class */ (function (_super) {
  5788. tslib_1.__extends(NodeCanvasFactory, _super);
  5789. function NodeCanvasFactory() {
  5790. return _super !== null && _super.apply(this, arguments) || this;
  5791. }
  5792. NodeCanvasFactory.prototype._createCanvas = function (width, height) {
  5793. var canvas = NodePackages.get("canvas");
  5794. return canvas.createCanvas(width, height);
  5795. };
  5796. return NodeCanvasFactory;
  5797. }(BaseCanvasFactory));
  5798. var NodeCMapReaderFactory = /** @class */ (function (_super) {
  5799. tslib_1.__extends(NodeCMapReaderFactory, _super);
  5800. function NodeCMapReaderFactory() {
  5801. return _super !== null && _super.apply(this, arguments) || this;
  5802. }
  5803. NodeCMapReaderFactory.prototype._fetchData = function (url, compressionType) {
  5804. return node_utils_fetchData(url).then(function (data) { return ({
  5805. cMapData: data,
  5806. compressionType: compressionType
  5807. }); });
  5808. };
  5809. return NodeCMapReaderFactory;
  5810. }(BaseCMapReaderFactory));
  5811. var NodeStandardFontDataFactory = /** @class */ (function (_super) {
  5812. tslib_1.__extends(NodeStandardFontDataFactory, _super);
  5813. function NodeStandardFontDataFactory() {
  5814. return _super !== null && _super.apply(this, arguments) || this;
  5815. }
  5816. NodeStandardFontDataFactory.prototype._fetchData = function (url) {
  5817. return node_utils_fetchData(url);
  5818. };
  5819. return NodeStandardFontDataFactory;
  5820. }(BaseStandardFontDataFactory));
  5821. ; // CONCATENATED MODULE: ./src/display/pattern_helper.js
  5822. var PathType = {
  5823. FILL: "Fill",
  5824. STROKE: "Stroke",
  5825. SHADING: "Shading"
  5826. };
  5827. function applyBoundingBox(ctx, bbox) {
  5828. if (!bbox) {
  5829. return;
  5830. }
  5831. var width = bbox[2] - bbox[0];
  5832. var height = bbox[3] - bbox[1];
  5833. var region = new Path2D();
  5834. region.rect(bbox[0], bbox[1], width, height);
  5835. ctx.clip(region);
  5836. }
  5837. var BaseShadingPattern = /** @class */ (function () {
  5838. function BaseShadingPattern() {
  5839. if (this.constructor === BaseShadingPattern) {
  5840. unreachable("Cannot initialize BaseShadingPattern.");
  5841. }
  5842. }
  5843. BaseShadingPattern.prototype.getPattern = function () {
  5844. unreachable("Abstract method `getPattern` called.");
  5845. };
  5846. return BaseShadingPattern;
  5847. }());
  5848. var RadialAxialShadingPattern = /** @class */ (function (_super) {
  5849. tslib_1.__extends(RadialAxialShadingPattern, _super);
  5850. function RadialAxialShadingPattern(IR) {
  5851. var _this = _super.call(this) || this;
  5852. _this._type = IR[1];
  5853. _this._bbox = IR[2];
  5854. _this._colorStops = IR[3];
  5855. _this._p0 = IR[4];
  5856. _this._p1 = IR[5];
  5857. _this._r0 = IR[6];
  5858. _this._r1 = IR[7];
  5859. _this.matrix = null;
  5860. return _this;
  5861. }
  5862. RadialAxialShadingPattern.prototype._createGradient = function (ctx) {
  5863. var grad;
  5864. if (this._type === "axial") {
  5865. grad = ctx.createLinearGradient(this._p0[0], this._p0[1], this._p1[0], this._p1[1]);
  5866. }
  5867. else if (this._type === "radial") {
  5868. grad = ctx.createRadialGradient(this._p0[0], this._p0[1], this._r0, this._p1[0], this._p1[1], this._r1);
  5869. }
  5870. for (var _i = 0, _g = this._colorStops; _i < _g.length; _i++) {
  5871. var colorStop = _g[_i];
  5872. grad.addColorStop(colorStop[0], colorStop[1]);
  5873. }
  5874. return grad;
  5875. };
  5876. RadialAxialShadingPattern.prototype.getPattern = function (ctx, owner, inverse, pathType) {
  5877. var pattern;
  5878. if (pathType === PathType.STROKE || pathType === PathType.FILL) {
  5879. var ownerBBox = owner.current.getClippedPathBoundingBox(pathType, getCurrentTransform(ctx)) || [0, 0, 0, 0];
  5880. var width = Math.ceil(ownerBBox[2] - ownerBBox[0]) || 1;
  5881. var height = Math.ceil(ownerBBox[3] - ownerBBox[1]) || 1;
  5882. var tmpCanvas = owner.cachedCanvases.getCanvas("pattern", width, height, true);
  5883. var tmpCtx = tmpCanvas.context;
  5884. tmpCtx.clearRect(0, 0, tmpCtx.canvas.width, tmpCtx.canvas.height);
  5885. tmpCtx.beginPath();
  5886. tmpCtx.rect(0, 0, tmpCtx.canvas.width, tmpCtx.canvas.height);
  5887. tmpCtx.translate(-ownerBBox[0], -ownerBBox[1]);
  5888. inverse = Util.transform(inverse, [1, 0, 0, 1, ownerBBox[0], ownerBBox[1]]);
  5889. tmpCtx.transform.apply(tmpCtx, owner.baseTransform);
  5890. if (this.matrix) {
  5891. tmpCtx.transform.apply(tmpCtx, this.matrix);
  5892. }
  5893. applyBoundingBox(tmpCtx, this._bbox);
  5894. tmpCtx.fillStyle = this._createGradient(tmpCtx);
  5895. tmpCtx.fill();
  5896. pattern = ctx.createPattern(tmpCanvas.canvas, "no-repeat");
  5897. var domMatrix = new DOMMatrix(inverse);
  5898. pattern.setTransform(domMatrix);
  5899. }
  5900. else {
  5901. applyBoundingBox(ctx, this._bbox);
  5902. pattern = this._createGradient(ctx);
  5903. }
  5904. return pattern;
  5905. };
  5906. return RadialAxialShadingPattern;
  5907. }(BaseShadingPattern));
  5908. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  5909. var coords = context.coords, colors = context.colors;
  5910. var bytes = data.data, rowSize = data.width * 4;
  5911. var tmp;
  5912. if (coords[p1 + 1] > coords[p2 + 1]) {
  5913. tmp = p1;
  5914. p1 = p2;
  5915. p2 = tmp;
  5916. tmp = c1;
  5917. c1 = c2;
  5918. c2 = tmp;
  5919. }
  5920. if (coords[p2 + 1] > coords[p3 + 1]) {
  5921. tmp = p2;
  5922. p2 = p3;
  5923. p3 = tmp;
  5924. tmp = c2;
  5925. c2 = c3;
  5926. c3 = tmp;
  5927. }
  5928. if (coords[p1 + 1] > coords[p2 + 1]) {
  5929. tmp = p1;
  5930. p1 = p2;
  5931. p2 = tmp;
  5932. tmp = c1;
  5933. c1 = c2;
  5934. c2 = tmp;
  5935. }
  5936. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  5937. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  5938. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  5939. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  5940. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  5941. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  5942. if (y1 >= y3) {
  5943. return;
  5944. }
  5945. var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
  5946. var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
  5947. var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
  5948. var minY = Math.round(y1), maxY = Math.round(y3);
  5949. var xa, car, cag, cab;
  5950. var xb, cbr, cbg, cbb;
  5951. for (var y = minY; y <= maxY; y++) {
  5952. if (y < y2) {
  5953. var k_1 = y < y1 ? 0 : (y1 - y) / (y1 - y2);
  5954. xa = x1 - (x1 - x2) * k_1;
  5955. car = c1r - (c1r - c2r) * k_1;
  5956. cag = c1g - (c1g - c2g) * k_1;
  5957. cab = c1b - (c1b - c2b) * k_1;
  5958. }
  5959. else {
  5960. var k_2 = void 0;
  5961. if (y > y3) {
  5962. k_2 = 1;
  5963. }
  5964. else if (y2 === y3) {
  5965. k_2 = 0;
  5966. }
  5967. else {
  5968. k_2 = (y2 - y) / (y2 - y3);
  5969. }
  5970. xa = x2 - (x2 - x3) * k_2;
  5971. car = c2r - (c2r - c3r) * k_2;
  5972. cag = c2g - (c2g - c3g) * k_2;
  5973. cab = c2b - (c2b - c3b) * k_2;
  5974. }
  5975. var k = void 0;
  5976. if (y < y1) {
  5977. k = 0;
  5978. }
  5979. else if (y > y3) {
  5980. k = 1;
  5981. }
  5982. else {
  5983. k = (y1 - y) / (y1 - y3);
  5984. }
  5985. xb = x1 - (x1 - x3) * k;
  5986. cbr = c1r - (c1r - c3r) * k;
  5987. cbg = c1g - (c1g - c3g) * k;
  5988. cbb = c1b - (c1b - c3b) * k;
  5989. var x1_ = Math.round(Math.min(xa, xb));
  5990. var x2_ = Math.round(Math.max(xa, xb));
  5991. var j = rowSize * y + x1_ * 4;
  5992. for (var x = x1_; x <= x2_; x++) {
  5993. k = (xa - x) / (xa - xb);
  5994. if (k < 0) {
  5995. k = 0;
  5996. }
  5997. else if (k > 1) {
  5998. k = 1;
  5999. }
  6000. bytes[j++] = car - (car - cbr) * k | 0;
  6001. bytes[j++] = cag - (cag - cbg) * k | 0;
  6002. bytes[j++] = cab - (cab - cbb) * k | 0;
  6003. bytes[j++] = 255;
  6004. }
  6005. }
  6006. }
  6007. function drawFigure(data, figure, context) {
  6008. var ps = figure.coords;
  6009. var cs = figure.colors;
  6010. var i, ii;
  6011. switch (figure.type) {
  6012. case "lattice":
  6013. var verticesPerRow = figure.verticesPerRow;
  6014. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  6015. var cols = verticesPerRow - 1;
  6016. for (i = 0; i < rows; i++) {
  6017. var q = i * verticesPerRow;
  6018. for (var j = 0; j < cols; j++, q++) {
  6019. drawTriangle(data, context, ps[q], ps[q + 1], ps[q + verticesPerRow], cs[q], cs[q + 1], cs[q + verticesPerRow]);
  6020. drawTriangle(data, context, ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow], cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  6021. }
  6022. }
  6023. break;
  6024. case "triangles":
  6025. for (i = 0, ii = ps.length; i < ii; i += 3) {
  6026. drawTriangle(data, context, ps[i], ps[i + 1], ps[i + 2], cs[i], cs[i + 1], cs[i + 2]);
  6027. }
  6028. break;
  6029. default:
  6030. throw new Error("illegal figure");
  6031. }
  6032. }
  6033. var MeshShadingPattern = /** @class */ (function (_super) {
  6034. tslib_1.__extends(MeshShadingPattern, _super);
  6035. function MeshShadingPattern(IR) {
  6036. var _this = _super.call(this) || this;
  6037. _this._coords = IR[2];
  6038. _this._colors = IR[3];
  6039. _this._figures = IR[4];
  6040. _this._bounds = IR[5];
  6041. _this._bbox = IR[7];
  6042. _this._background = IR[8];
  6043. _this.matrix = null;
  6044. return _this;
  6045. }
  6046. MeshShadingPattern.prototype._createMeshCanvas = function (combinedScale, backgroundColor, cachedCanvases) {
  6047. var EXPECTED_SCALE = 1.1;
  6048. var MAX_PATTERN_SIZE = 3000;
  6049. var BORDER_SIZE = 2;
  6050. var offsetX = Math.floor(this._bounds[0]);
  6051. var offsetY = Math.floor(this._bounds[1]);
  6052. var boundsWidth = Math.ceil(this._bounds[2]) - offsetX;
  6053. var boundsHeight = Math.ceil(this._bounds[3]) - offsetY;
  6054. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinedScale[0] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  6055. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinedScale[1] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  6056. var scaleX = boundsWidth / width;
  6057. var scaleY = boundsHeight / height;
  6058. var context = {
  6059. coords: this._coords,
  6060. colors: this._colors,
  6061. offsetX: -offsetX,
  6062. offsetY: -offsetY,
  6063. scaleX: 1 / scaleX,
  6064. scaleY: 1 / scaleY
  6065. };
  6066. var paddedWidth = width + BORDER_SIZE * 2;
  6067. var paddedHeight = height + BORDER_SIZE * 2;
  6068. var tmpCanvas = cachedCanvases.getCanvas("mesh", paddedWidth, paddedHeight, false);
  6069. var tmpCtx = tmpCanvas.context;
  6070. var data = tmpCtx.createImageData(width, height);
  6071. if (backgroundColor) {
  6072. var bytes = data.data;
  6073. for (var i = 0, ii = bytes.length; i < ii; i += 4) {
  6074. bytes[i] = backgroundColor[0];
  6075. bytes[i + 1] = backgroundColor[1];
  6076. bytes[i + 2] = backgroundColor[2];
  6077. bytes[i + 3] = 255;
  6078. }
  6079. }
  6080. for (var _i = 0, _g = this._figures; _i < _g.length; _i++) {
  6081. var figure = _g[_i];
  6082. drawFigure(data, figure, context);
  6083. }
  6084. tmpCtx.putImageData(data, BORDER_SIZE, BORDER_SIZE);
  6085. var canvas = tmpCanvas.canvas;
  6086. return {
  6087. canvas: canvas,
  6088. offsetX: offsetX - BORDER_SIZE * scaleX,
  6089. offsetY: offsetY - BORDER_SIZE * scaleY,
  6090. scaleX: scaleX,
  6091. scaleY: scaleY
  6092. };
  6093. };
  6094. MeshShadingPattern.prototype.getPattern = function (ctx, owner, inverse, pathType) {
  6095. applyBoundingBox(ctx, this._bbox);
  6096. var scale;
  6097. if (pathType === PathType.SHADING) {
  6098. scale = Util.singularValueDecompose2dScale(getCurrentTransform(ctx));
  6099. }
  6100. else {
  6101. scale = Util.singularValueDecompose2dScale(owner.baseTransform);
  6102. if (this.matrix) {
  6103. var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
  6104. scale = [scale[0] * matrixScale[0], scale[1] * matrixScale[1]];
  6105. }
  6106. }
  6107. var temporaryPatternCanvas = this._createMeshCanvas(scale, pathType === PathType.SHADING ? null : this._background, owner.cachedCanvases);
  6108. if (pathType !== PathType.SHADING) {
  6109. ctx.setTransform.apply(ctx, owner.baseTransform);
  6110. if (this.matrix) {
  6111. ctx.transform.apply(ctx, this.matrix);
  6112. }
  6113. }
  6114. ctx.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY);
  6115. ctx.scale(temporaryPatternCanvas.scaleX, temporaryPatternCanvas.scaleY);
  6116. return ctx.createPattern(temporaryPatternCanvas.canvas, "no-repeat");
  6117. };
  6118. return MeshShadingPattern;
  6119. }(BaseShadingPattern));
  6120. var DummyShadingPattern = /** @class */ (function (_super) {
  6121. tslib_1.__extends(DummyShadingPattern, _super);
  6122. function DummyShadingPattern() {
  6123. return _super !== null && _super.apply(this, arguments) || this;
  6124. }
  6125. DummyShadingPattern.prototype.getPattern = function () {
  6126. return "hotpink";
  6127. };
  6128. return DummyShadingPattern;
  6129. }(BaseShadingPattern));
  6130. function getShadingPattern(IR) {
  6131. switch (IR[0]) {
  6132. case "RadialAxial":
  6133. return new RadialAxialShadingPattern(IR);
  6134. case "Mesh":
  6135. return new MeshShadingPattern(IR);
  6136. case "Dummy":
  6137. return new DummyShadingPattern();
  6138. }
  6139. throw new Error("Unknown IR type: ".concat(IR[0]));
  6140. }
  6141. var PaintType = {
  6142. COLORED: 1,
  6143. UNCOLORED: 2
  6144. };
  6145. var TilingPattern = /** @class */ (function () {
  6146. function TilingPattern(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
  6147. this.operatorList = IR[2];
  6148. this.matrix = IR[3];
  6149. this.bbox = IR[4];
  6150. this.xstep = IR[5];
  6151. this.ystep = IR[6];
  6152. this.paintType = IR[7];
  6153. this.tilingType = IR[8];
  6154. this.color = color;
  6155. this.ctx = ctx;
  6156. this.canvasGraphicsFactory = canvasGraphicsFactory;
  6157. this.baseTransform = baseTransform;
  6158. }
  6159. TilingPattern.prototype.createPatternCanvas = function (owner) {
  6160. var operatorList = this.operatorList;
  6161. var bbox = this.bbox;
  6162. var xstep = this.xstep;
  6163. var ystep = this.ystep;
  6164. var paintType = this.paintType;
  6165. var tilingType = this.tilingType;
  6166. var color = this.color;
  6167. var canvasGraphicsFactory = this.canvasGraphicsFactory;
  6168. info("TilingType: " + tilingType);
  6169. var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
  6170. var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
  6171. var curMatrixScale = Util.singularValueDecompose2dScale(this.baseTransform);
  6172. var combinedScale = [matrixScale[0] * curMatrixScale[0], matrixScale[1] * curMatrixScale[1]];
  6173. var dimx = this.getSizeAndScale(xstep, this.ctx.canvas.width, combinedScale[0]);
  6174. var dimy = this.getSizeAndScale(ystep, this.ctx.canvas.height, combinedScale[1]);
  6175. var tmpCanvas = owner.cachedCanvases.getCanvas("pattern", dimx.size, dimy.size, true);
  6176. var tmpCtx = tmpCanvas.context;
  6177. var graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
  6178. graphics.groupLevel = owner.groupLevel;
  6179. this.setFillAndStrokeStyleToContext(graphics, paintType, color);
  6180. var adjustedX0 = x0;
  6181. var adjustedY0 = y0;
  6182. var adjustedX1 = x1;
  6183. var adjustedY1 = y1;
  6184. if (x0 < 0) {
  6185. adjustedX0 = 0;
  6186. adjustedX1 += Math.abs(x0);
  6187. }
  6188. if (y0 < 0) {
  6189. adjustedY0 = 0;
  6190. adjustedY1 += Math.abs(y0);
  6191. }
  6192. tmpCtx.translate(-(dimx.scale * adjustedX0), -(dimy.scale * adjustedY0));
  6193. graphics.transform(dimx.scale, 0, 0, dimy.scale, 0, 0);
  6194. tmpCtx.save();
  6195. this.clipBbox(graphics, adjustedX0, adjustedY0, adjustedX1, adjustedY1);
  6196. graphics.baseTransform = getCurrentTransform(graphics.ctx);
  6197. graphics.executeOperatorList(operatorList);
  6198. graphics.endDrawing();
  6199. return {
  6200. canvas: tmpCanvas.canvas,
  6201. scaleX: dimx.scale,
  6202. scaleY: dimy.scale,
  6203. offsetX: adjustedX0,
  6204. offsetY: adjustedY0
  6205. };
  6206. };
  6207. TilingPattern.prototype.getSizeAndScale = function (step, realOutputSize, scale) {
  6208. step = Math.abs(step);
  6209. var maxSize = Math.max(TilingPattern.MAX_PATTERN_SIZE, realOutputSize);
  6210. var size = Math.ceil(step * scale);
  6211. if (size >= maxSize) {
  6212. size = maxSize;
  6213. }
  6214. else {
  6215. scale = size / step;
  6216. }
  6217. return {
  6218. scale: scale,
  6219. size: size
  6220. };
  6221. };
  6222. TilingPattern.prototype.clipBbox = function (graphics, x0, y0, x1, y1) {
  6223. var bboxWidth = x1 - x0;
  6224. var bboxHeight = y1 - y0;
  6225. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  6226. graphics.current.updateRectMinMax(getCurrentTransform(graphics.ctx), [x0, y0, x1, y1]);
  6227. graphics.clip();
  6228. graphics.endPath();
  6229. };
  6230. TilingPattern.prototype.setFillAndStrokeStyleToContext = function (graphics, paintType, color) {
  6231. var context = graphics.ctx, current = graphics.current;
  6232. switch (paintType) {
  6233. case PaintType.COLORED:
  6234. var ctx = this.ctx;
  6235. context.fillStyle = ctx.fillStyle;
  6236. context.strokeStyle = ctx.strokeStyle;
  6237. current.fillColor = ctx.fillStyle;
  6238. current.strokeColor = ctx.strokeStyle;
  6239. break;
  6240. case PaintType.UNCOLORED:
  6241. var cssColor = Util.makeHexColor(color[0], color[1], color[2]);
  6242. context.fillStyle = cssColor;
  6243. context.strokeStyle = cssColor;
  6244. current.fillColor = cssColor;
  6245. current.strokeColor = cssColor;
  6246. break;
  6247. default:
  6248. throw new FormatError("Unsupported paint type: ".concat(paintType));
  6249. }
  6250. };
  6251. TilingPattern.prototype.getPattern = function (ctx, owner, inverse, pathType) {
  6252. var matrix = inverse;
  6253. if (pathType !== PathType.SHADING) {
  6254. matrix = Util.transform(matrix, owner.baseTransform);
  6255. if (this.matrix) {
  6256. matrix = Util.transform(matrix, this.matrix);
  6257. }
  6258. }
  6259. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  6260. var domMatrix = new DOMMatrix(matrix);
  6261. domMatrix = domMatrix.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY);
  6262. domMatrix = domMatrix.scale(1 / temporaryPatternCanvas.scaleX, 1 / temporaryPatternCanvas.scaleY);
  6263. var pattern = ctx.createPattern(temporaryPatternCanvas.canvas, "repeat");
  6264. pattern.setTransform(domMatrix);
  6265. return pattern;
  6266. };
  6267. TilingPattern.MAX_PATTERN_SIZE = 3000;
  6268. return TilingPattern;
  6269. }());
  6270. ; // CONCATENATED MODULE: ./src/shared/image_utils.js
  6271. function convertToRGBA(params) {
  6272. switch (params.kind) {
  6273. case ImageKind.GRAYSCALE_1BPP:
  6274. return convertBlackAndWhiteToRGBA(params);
  6275. case ImageKind.RGB_24BPP:
  6276. return convertRGBToRGBA(params);
  6277. }
  6278. return null;
  6279. }
  6280. function convertBlackAndWhiteToRGBA(_g) {
  6281. var src = _g.src, _h = _g.srcPos, srcPos = _h === void 0 ? 0 : _h, dest = _g.dest, width = _g.width, height = _g.height, _j = _g.nonBlackColor, nonBlackColor = _j === void 0 ? 0xffffffff : _j, _k = _g.inverseDecode, inverseDecode = _k === void 0 ? false : _k;
  6282. var black = util_FeatureTest.isLittleEndian ? 0xff000000 : 0x000000ff;
  6283. var _l = inverseDecode ? [nonBlackColor, black] : [black, nonBlackColor], zeroMapping = _l[0], oneMapping = _l[1];
  6284. var widthInSource = width >> 3;
  6285. var widthRemainder = width & 7;
  6286. var srcLength = src.length;
  6287. dest = new Uint32Array(dest.buffer);
  6288. var destPos = 0;
  6289. for (var i = 0; i < height; i++) {
  6290. for (var max = srcPos + widthInSource; srcPos < max; srcPos++) {
  6291. var elem_1 = srcPos < srcLength ? src[srcPos] : 255;
  6292. dest[destPos++] = elem_1 & 128 ? oneMapping : zeroMapping;
  6293. dest[destPos++] = elem_1 & 64 ? oneMapping : zeroMapping;
  6294. dest[destPos++] = elem_1 & 32 ? oneMapping : zeroMapping;
  6295. dest[destPos++] = elem_1 & 16 ? oneMapping : zeroMapping;
  6296. dest[destPos++] = elem_1 & 8 ? oneMapping : zeroMapping;
  6297. dest[destPos++] = elem_1 & 4 ? oneMapping : zeroMapping;
  6298. dest[destPos++] = elem_1 & 2 ? oneMapping : zeroMapping;
  6299. dest[destPos++] = elem_1 & 1 ? oneMapping : zeroMapping;
  6300. }
  6301. if (widthRemainder === 0) {
  6302. continue;
  6303. }
  6304. var elem = srcPos < srcLength ? src[srcPos++] : 255;
  6305. for (var j = 0; j < widthRemainder; j++) {
  6306. dest[destPos++] = elem & 1 << 7 - j ? oneMapping : zeroMapping;
  6307. }
  6308. }
  6309. return {
  6310. srcPos: srcPos,
  6311. destPos: destPos
  6312. };
  6313. }
  6314. function convertRGBToRGBA(_g) {
  6315. var src = _g.src, _h = _g.srcPos, srcPos = _h === void 0 ? 0 : _h, dest = _g.dest, _j = _g.destPos, destPos = _j === void 0 ? 0 : _j, width = _g.width, height = _g.height;
  6316. var i = 0;
  6317. var len32 = src.length >> 2;
  6318. var src32 = new Uint32Array(src.buffer, srcPos, len32);
  6319. if (FeatureTest.isLittleEndian) {
  6320. for (; i < len32 - 2; i += 3, destPos += 4) {
  6321. var s1 = src32[i];
  6322. var s2 = src32[i + 1];
  6323. var s3 = src32[i + 2];
  6324. dest[destPos] = s1 | 0xff000000;
  6325. dest[destPos + 1] = s1 >>> 24 | s2 << 8 | 0xff000000;
  6326. dest[destPos + 2] = s2 >>> 16 | s3 << 16 | 0xff000000;
  6327. dest[destPos + 3] = s3 >>> 8 | 0xff000000;
  6328. }
  6329. for (var j = i * 4, jj = src.length; j < jj; j += 3) {
  6330. dest[destPos++] = src[j] | src[j + 1] << 8 | src[j + 2] << 16 | 0xff000000;
  6331. }
  6332. }
  6333. else {
  6334. for (; i < len32 - 2; i += 3, destPos += 4) {
  6335. var s1 = src32[i];
  6336. var s2 = src32[i + 1];
  6337. var s3 = src32[i + 2];
  6338. dest[destPos] = s1 | 0xff;
  6339. dest[destPos + 1] = s1 << 24 | s2 >>> 8 | 0xff;
  6340. dest[destPos + 2] = s2 << 16 | s3 >>> 16 | 0xff;
  6341. dest[destPos + 3] = s3 << 8 | 0xff;
  6342. }
  6343. for (var j = i * 4, jj = src.length; j < jj; j += 3) {
  6344. dest[destPos++] = src[j] << 24 | src[j + 1] << 16 | src[j + 2] << 8 | 0xff;
  6345. }
  6346. }
  6347. return {
  6348. srcPos: srcPos,
  6349. destPos: destPos
  6350. };
  6351. }
  6352. function grayToRGBA(src, dest) {
  6353. if (FeatureTest.isLittleEndian) {
  6354. for (var i = 0, ii = src.length; i < ii; i++) {
  6355. dest[i] = src[i] * 0x10101 | 0xff000000;
  6356. }
  6357. }
  6358. else {
  6359. for (var i = 0, ii = src.length; i < ii; i++) {
  6360. dest[i] = src[i] * 0x1010100 | 0x000000ff;
  6361. }
  6362. }
  6363. }
  6364. ; // CONCATENATED MODULE: ./src/display/canvas.js
  6365. var MIN_FONT_SIZE = 16;
  6366. var MAX_FONT_SIZE = 100;
  6367. var EXECUTION_TIME = 15;
  6368. var EXECUTION_STEPS = 10;
  6369. var MAX_SIZE_TO_COMPILE = 1000;
  6370. var FULL_CHUNK_HEIGHT = 16;
  6371. function mirrorContextOperations(ctx, destCtx) {
  6372. if (ctx._removeMirroring) {
  6373. throw new Error("Context is already forwarding operations.");
  6374. }
  6375. ctx.__originalSave = ctx.save;
  6376. ctx.__originalRestore = ctx.restore;
  6377. ctx.__originalRotate = ctx.rotate;
  6378. ctx.__originalScale = ctx.scale;
  6379. ctx.__originalTranslate = ctx.translate;
  6380. ctx.__originalTransform = ctx.transform;
  6381. ctx.__originalSetTransform = ctx.setTransform;
  6382. ctx.__originalResetTransform = ctx.resetTransform;
  6383. ctx.__originalClip = ctx.clip;
  6384. ctx.__originalMoveTo = ctx.moveTo;
  6385. ctx.__originalLineTo = ctx.lineTo;
  6386. ctx.__originalBezierCurveTo = ctx.bezierCurveTo;
  6387. ctx.__originalRect = ctx.rect;
  6388. ctx.__originalClosePath = ctx.closePath;
  6389. ctx.__originalBeginPath = ctx.beginPath;
  6390. ctx._removeMirroring = function () {
  6391. ctx.save = ctx.__originalSave;
  6392. ctx.restore = ctx.__originalRestore;
  6393. ctx.rotate = ctx.__originalRotate;
  6394. ctx.scale = ctx.__originalScale;
  6395. ctx.translate = ctx.__originalTranslate;
  6396. ctx.transform = ctx.__originalTransform;
  6397. ctx.setTransform = ctx.__originalSetTransform;
  6398. ctx.resetTransform = ctx.__originalResetTransform;
  6399. ctx.clip = ctx.__originalClip;
  6400. ctx.moveTo = ctx.__originalMoveTo;
  6401. ctx.lineTo = ctx.__originalLineTo;
  6402. ctx.bezierCurveTo = ctx.__originalBezierCurveTo;
  6403. ctx.rect = ctx.__originalRect;
  6404. ctx.closePath = ctx.__originalClosePath;
  6405. ctx.beginPath = ctx.__originalBeginPath;
  6406. delete ctx._removeMirroring;
  6407. };
  6408. ctx.save = function ctxSave() {
  6409. destCtx.save();
  6410. this.__originalSave();
  6411. };
  6412. ctx.restore = function ctxRestore() {
  6413. destCtx.restore();
  6414. this.__originalRestore();
  6415. };
  6416. ctx.translate = function ctxTranslate(x, y) {
  6417. destCtx.translate(x, y);
  6418. this.__originalTranslate(x, y);
  6419. };
  6420. ctx.scale = function ctxScale(x, y) {
  6421. destCtx.scale(x, y);
  6422. this.__originalScale(x, y);
  6423. };
  6424. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  6425. destCtx.transform(a, b, c, d, e, f);
  6426. this.__originalTransform(a, b, c, d, e, f);
  6427. };
  6428. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  6429. destCtx.setTransform(a, b, c, d, e, f);
  6430. this.__originalSetTransform(a, b, c, d, e, f);
  6431. };
  6432. ctx.resetTransform = function ctxResetTransform() {
  6433. destCtx.resetTransform();
  6434. this.__originalResetTransform();
  6435. };
  6436. ctx.rotate = function ctxRotate(angle) {
  6437. destCtx.rotate(angle);
  6438. this.__originalRotate(angle);
  6439. };
  6440. ctx.clip = function ctxRotate(rule) {
  6441. destCtx.clip(rule);
  6442. this.__originalClip(rule);
  6443. };
  6444. ctx.moveTo = function (x, y) {
  6445. destCtx.moveTo(x, y);
  6446. this.__originalMoveTo(x, y);
  6447. };
  6448. ctx.lineTo = function (x, y) {
  6449. destCtx.lineTo(x, y);
  6450. this.__originalLineTo(x, y);
  6451. };
  6452. ctx.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
  6453. destCtx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
  6454. this.__originalBezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
  6455. };
  6456. ctx.rect = function (x, y, width, height) {
  6457. destCtx.rect(x, y, width, height);
  6458. this.__originalRect(x, y, width, height);
  6459. };
  6460. ctx.closePath = function () {
  6461. destCtx.closePath();
  6462. this.__originalClosePath();
  6463. };
  6464. ctx.beginPath = function () {
  6465. destCtx.beginPath();
  6466. this.__originalBeginPath();
  6467. };
  6468. }
  6469. var CachedCanvases = /** @class */ (function () {
  6470. function CachedCanvases(canvasFactory) {
  6471. this.canvasFactory = canvasFactory;
  6472. this.cache = Object.create(null);
  6473. }
  6474. CachedCanvases.prototype.getCanvas = function (id, width, height) {
  6475. var canvasEntry;
  6476. if (this.cache[id] !== undefined) {
  6477. canvasEntry = this.cache[id];
  6478. this.canvasFactory.reset(canvasEntry, width, height);
  6479. }
  6480. else {
  6481. canvasEntry = this.canvasFactory.create(width, height);
  6482. this.cache[id] = canvasEntry;
  6483. }
  6484. return canvasEntry;
  6485. };
  6486. CachedCanvases.prototype.delete = function (id) {
  6487. delete this.cache[id];
  6488. };
  6489. CachedCanvases.prototype.clear = function () {
  6490. for (var id in this.cache) {
  6491. var canvasEntry = this.cache[id];
  6492. this.canvasFactory.destroy(canvasEntry);
  6493. delete this.cache[id];
  6494. }
  6495. };
  6496. return CachedCanvases;
  6497. }());
  6498. function drawImageAtIntegerCoords(ctx, srcImg, srcX, srcY, srcW, srcH, destX, destY, destW, destH) {
  6499. var _g = getCurrentTransform(ctx), a = _g[0], b = _g[1], c = _g[2], d = _g[3], tx = _g[4], ty = _g[5];
  6500. if (b === 0 && c === 0) {
  6501. var tlX = destX * a + tx;
  6502. var rTlX = Math.round(tlX);
  6503. var tlY = destY * d + ty;
  6504. var rTlY = Math.round(tlY);
  6505. var brX = (destX + destW) * a + tx;
  6506. var rWidth = Math.abs(Math.round(brX) - rTlX) || 1;
  6507. var brY = (destY + destH) * d + ty;
  6508. var rHeight = Math.abs(Math.round(brY) - rTlY) || 1;
  6509. ctx.setTransform(Math.sign(a), 0, 0, Math.sign(d), rTlX, rTlY);
  6510. ctx.drawImage(srcImg, srcX, srcY, srcW, srcH, 0, 0, rWidth, rHeight);
  6511. ctx.setTransform(a, b, c, d, tx, ty);
  6512. return [rWidth, rHeight];
  6513. }
  6514. if (a === 0 && d === 0) {
  6515. var tlX = destY * c + tx;
  6516. var rTlX = Math.round(tlX);
  6517. var tlY = destX * b + ty;
  6518. var rTlY = Math.round(tlY);
  6519. var brX = (destY + destH) * c + tx;
  6520. var rWidth = Math.abs(Math.round(brX) - rTlX) || 1;
  6521. var brY = (destX + destW) * b + ty;
  6522. var rHeight = Math.abs(Math.round(brY) - rTlY) || 1;
  6523. ctx.setTransform(0, Math.sign(b), Math.sign(c), 0, rTlX, rTlY);
  6524. ctx.drawImage(srcImg, srcX, srcY, srcW, srcH, 0, 0, rHeight, rWidth);
  6525. ctx.setTransform(a, b, c, d, tx, ty);
  6526. return [rHeight, rWidth];
  6527. }
  6528. ctx.drawImage(srcImg, srcX, srcY, srcW, srcH, destX, destY, destW, destH);
  6529. var scaleX = Math.hypot(a, b);
  6530. var scaleY = Math.hypot(c, d);
  6531. return [scaleX * destW, scaleY * destH];
  6532. }
  6533. function compileType3Glyph(imgData) {
  6534. var width = imgData.width, height = imgData.height;
  6535. if (width > MAX_SIZE_TO_COMPILE || height > MAX_SIZE_TO_COMPILE) {
  6536. return null;
  6537. }
  6538. var POINT_TO_PROCESS_LIMIT = 1000;
  6539. var POINT_TYPES = new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  6540. var width1 = width + 1;
  6541. var points = new Uint8Array(width1 * (height + 1));
  6542. var i, j, j0;
  6543. var lineSize = width + 7 & ~7;
  6544. var data = new Uint8Array(lineSize * height), pos = 0;
  6545. for (var _i = 0, _g = imgData.data; _i < _g.length; _i++) {
  6546. var elem = _g[_i];
  6547. var mask = 128;
  6548. while (mask > 0) {
  6549. data[pos++] = elem & mask ? 0 : 255;
  6550. mask >>= 1;
  6551. }
  6552. }
  6553. var count = 0;
  6554. pos = 0;
  6555. if (data[pos] !== 0) {
  6556. points[0] = 1;
  6557. ++count;
  6558. }
  6559. for (j = 1; j < width; j++) {
  6560. if (data[pos] !== data[pos + 1]) {
  6561. points[j] = data[pos] ? 2 : 1;
  6562. ++count;
  6563. }
  6564. pos++;
  6565. }
  6566. if (data[pos] !== 0) {
  6567. points[j] = 2;
  6568. ++count;
  6569. }
  6570. for (i = 1; i < height; i++) {
  6571. pos = i * lineSize;
  6572. j0 = i * width1;
  6573. if (data[pos - lineSize] !== data[pos]) {
  6574. points[j0] = data[pos] ? 1 : 8;
  6575. ++count;
  6576. }
  6577. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  6578. for (j = 1; j < width; j++) {
  6579. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) + (data[pos - lineSize + 1] ? 8 : 0);
  6580. if (POINT_TYPES[sum]) {
  6581. points[j0 + j] = POINT_TYPES[sum];
  6582. ++count;
  6583. }
  6584. pos++;
  6585. }
  6586. if (data[pos - lineSize] !== data[pos]) {
  6587. points[j0 + j] = data[pos] ? 2 : 4;
  6588. ++count;
  6589. }
  6590. if (count > POINT_TO_PROCESS_LIMIT) {
  6591. return null;
  6592. }
  6593. }
  6594. pos = lineSize * (height - 1);
  6595. j0 = i * width1;
  6596. if (data[pos] !== 0) {
  6597. points[j0] = 8;
  6598. ++count;
  6599. }
  6600. for (j = 1; j < width; j++) {
  6601. if (data[pos] !== data[pos + 1]) {
  6602. points[j0 + j] = data[pos] ? 4 : 8;
  6603. ++count;
  6604. }
  6605. pos++;
  6606. }
  6607. if (data[pos] !== 0) {
  6608. points[j0 + j] = 4;
  6609. ++count;
  6610. }
  6611. if (count > POINT_TO_PROCESS_LIMIT) {
  6612. return null;
  6613. }
  6614. var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  6615. var path = new Path2D();
  6616. for (i = 0; count && i <= height; i++) {
  6617. var p = i * width1;
  6618. var end = p + width;
  6619. while (p < end && !points[p]) {
  6620. p++;
  6621. }
  6622. if (p === end) {
  6623. continue;
  6624. }
  6625. path.moveTo(p % width1, i);
  6626. var p0 = p;
  6627. var type = points[p];
  6628. do {
  6629. var step = steps[type];
  6630. do {
  6631. p += step;
  6632. } while (!points[p]);
  6633. var pp = points[p];
  6634. if (pp !== 5 && pp !== 10) {
  6635. type = pp;
  6636. points[p] = 0;
  6637. }
  6638. else {
  6639. type = pp & 0x33 * type >> 4;
  6640. points[p] &= type >> 2 | type << 2;
  6641. }
  6642. path.lineTo(p % width1, p / width1 | 0);
  6643. if (!points[p]) {
  6644. --count;
  6645. }
  6646. } while (p0 !== p);
  6647. --i;
  6648. }
  6649. data = null;
  6650. points = null;
  6651. var drawOutline = function (c) {
  6652. c.save();
  6653. c.scale(1 / width, -1 / height);
  6654. c.translate(0, -height);
  6655. c.fill(path);
  6656. c.beginPath();
  6657. c.restore();
  6658. };
  6659. return drawOutline;
  6660. }
  6661. var CanvasExtraState = /** @class */ (function () {
  6662. function CanvasExtraState(width, height) {
  6663. this.alphaIsShape = false;
  6664. this.fontSize = 0;
  6665. this.fontSizeScale = 1;
  6666. this.textMatrix = IDENTITY_MATRIX;
  6667. this.textMatrixScale = 1;
  6668. this.fontMatrix = FONT_IDENTITY_MATRIX;
  6669. this.leading = 0;
  6670. this.x = 0;
  6671. this.y = 0;
  6672. this.lineX = 0;
  6673. this.lineY = 0;
  6674. this.charSpacing = 0;
  6675. this.wordSpacing = 0;
  6676. this.textHScale = 1;
  6677. this.textRenderingMode = TextRenderingMode.FILL;
  6678. this.textRise = 0;
  6679. this.fillColor = "#000000";
  6680. this.strokeColor = "#000000";
  6681. this.patternFill = false;
  6682. this.fillAlpha = 1;
  6683. this.strokeAlpha = 1;
  6684. this.lineWidth = 1;
  6685. this.activeSMask = null;
  6686. this.transferMaps = "none";
  6687. this.startNewPathAndClipBox([0, 0, width, height]);
  6688. }
  6689. CanvasExtraState.prototype.clone = function () {
  6690. var clone = Object.create(this);
  6691. clone.clipBox = this.clipBox.slice();
  6692. return clone;
  6693. };
  6694. CanvasExtraState.prototype.setCurrentPoint = function (x, y) {
  6695. this.x = x;
  6696. this.y = y;
  6697. };
  6698. CanvasExtraState.prototype.updatePathMinMax = function (transform, x, y) {
  6699. var _g;
  6700. _g = Util.applyTransform([x, y], transform), x = _g[0], y = _g[1];
  6701. this.minX = Math.min(this.minX, x);
  6702. this.minY = Math.min(this.minY, y);
  6703. this.maxX = Math.max(this.maxX, x);
  6704. this.maxY = Math.max(this.maxY, y);
  6705. };
  6706. CanvasExtraState.prototype.updateRectMinMax = function (transform, rect) {
  6707. var p1 = Util.applyTransform(rect, transform);
  6708. var p2 = Util.applyTransform(rect.slice(2), transform);
  6709. var p3 = Util.applyTransform([rect[0], rect[3]], transform);
  6710. var p4 = Util.applyTransform([rect[2], rect[1]], transform);
  6711. this.minX = Math.min(this.minX, p1[0], p2[0], p3[0], p4[0]);
  6712. this.minY = Math.min(this.minY, p1[1], p2[1], p3[1], p4[1]);
  6713. this.maxX = Math.max(this.maxX, p1[0], p2[0], p3[0], p4[0]);
  6714. this.maxY = Math.max(this.maxY, p1[1], p2[1], p3[1], p4[1]);
  6715. };
  6716. CanvasExtraState.prototype.updateScalingPathMinMax = function (transform, minMax) {
  6717. Util.scaleMinMax(transform, minMax);
  6718. this.minX = Math.min(this.minX, minMax[0]);
  6719. this.minY = Math.min(this.minY, minMax[1]);
  6720. this.maxX = Math.max(this.maxX, minMax[2]);
  6721. this.maxY = Math.max(this.maxY, minMax[3]);
  6722. };
  6723. CanvasExtraState.prototype.updateCurvePathMinMax = function (transform, x0, y0, x1, y1, x2, y2, x3, y3, minMax) {
  6724. var box = Util.bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3, minMax);
  6725. if (minMax) {
  6726. return;
  6727. }
  6728. this.updateRectMinMax(transform, box);
  6729. };
  6730. CanvasExtraState.prototype.getPathBoundingBox = function (pathType, transform) {
  6731. if (pathType === void 0) { pathType = PathType.FILL; }
  6732. if (transform === void 0) { transform = null; }
  6733. var box = [this.minX, this.minY, this.maxX, this.maxY];
  6734. if (pathType === PathType.STROKE) {
  6735. if (!transform) {
  6736. unreachable("Stroke bounding box must include transform.");
  6737. }
  6738. var scale = Util.singularValueDecompose2dScale(transform);
  6739. var xStrokePad = scale[0] * this.lineWidth / 2;
  6740. var yStrokePad = scale[1] * this.lineWidth / 2;
  6741. box[0] -= xStrokePad;
  6742. box[1] -= yStrokePad;
  6743. box[2] += xStrokePad;
  6744. box[3] += yStrokePad;
  6745. }
  6746. return box;
  6747. };
  6748. CanvasExtraState.prototype.updateClipFromPath = function () {
  6749. var intersect = Util.intersect(this.clipBox, this.getPathBoundingBox());
  6750. this.startNewPathAndClipBox(intersect || [0, 0, 0, 0]);
  6751. };
  6752. CanvasExtraState.prototype.isEmptyClip = function () {
  6753. return this.minX === Infinity;
  6754. };
  6755. CanvasExtraState.prototype.startNewPathAndClipBox = function (box) {
  6756. this.clipBox = box;
  6757. this.minX = Infinity;
  6758. this.minY = Infinity;
  6759. this.maxX = 0;
  6760. this.maxY = 0;
  6761. };
  6762. CanvasExtraState.prototype.getClippedPathBoundingBox = function (pathType, transform) {
  6763. if (pathType === void 0) { pathType = PathType.FILL; }
  6764. if (transform === void 0) { transform = null; }
  6765. return Util.intersect(this.clipBox, this.getPathBoundingBox(pathType, transform));
  6766. };
  6767. return CanvasExtraState;
  6768. }());
  6769. function putBinaryImageData(ctx, imgData) {
  6770. if (typeof ImageData !== "undefined" && imgData instanceof ImageData) {
  6771. ctx.putImageData(imgData, 0, 0);
  6772. return;
  6773. }
  6774. var height = imgData.height, width = imgData.width;
  6775. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  6776. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  6777. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  6778. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  6779. var srcPos = 0, destPos;
  6780. var src = imgData.data;
  6781. var dest = chunkImgData.data;
  6782. var i, j, thisChunkHeight, elemsInThisChunk;
  6783. if (imgData.kind === util_ImageKind.GRAYSCALE_1BPP) {
  6784. var srcLength = src.byteLength;
  6785. var dest32 = new Uint32Array(dest.buffer, 0, dest.byteLength >> 2);
  6786. var dest32DataLength = dest32.length;
  6787. var fullSrcDiff = width + 7 >> 3;
  6788. var white = 0xffffffff;
  6789. var black = util_FeatureTest.isLittleEndian ? 0xff000000 : 0x000000ff;
  6790. for (i = 0; i < totalChunks; i++) {
  6791. thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  6792. destPos = 0;
  6793. for (j = 0; j < thisChunkHeight; j++) {
  6794. var srcDiff = srcLength - srcPos;
  6795. var k = 0;
  6796. var kEnd = srcDiff > fullSrcDiff ? width : srcDiff * 8 - 7;
  6797. var kEndUnrolled = kEnd & ~7;
  6798. var mask = 0;
  6799. var srcByte = 0;
  6800. for (; k < kEndUnrolled; k += 8) {
  6801. srcByte = src[srcPos++];
  6802. dest32[destPos++] = srcByte & 128 ? white : black;
  6803. dest32[destPos++] = srcByte & 64 ? white : black;
  6804. dest32[destPos++] = srcByte & 32 ? white : black;
  6805. dest32[destPos++] = srcByte & 16 ? white : black;
  6806. dest32[destPos++] = srcByte & 8 ? white : black;
  6807. dest32[destPos++] = srcByte & 4 ? white : black;
  6808. dest32[destPos++] = srcByte & 2 ? white : black;
  6809. dest32[destPos++] = srcByte & 1 ? white : black;
  6810. }
  6811. for (; k < kEnd; k++) {
  6812. if (mask === 0) {
  6813. srcByte = src[srcPos++];
  6814. mask = 128;
  6815. }
  6816. dest32[destPos++] = srcByte & mask ? white : black;
  6817. mask >>= 1;
  6818. }
  6819. }
  6820. while (destPos < dest32DataLength) {
  6821. dest32[destPos++] = 0;
  6822. }
  6823. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  6824. }
  6825. }
  6826. else if (imgData.kind === util_ImageKind.RGBA_32BPP) {
  6827. j = 0;
  6828. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  6829. for (i = 0; i < fullChunks; i++) {
  6830. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  6831. srcPos += elemsInThisChunk;
  6832. ctx.putImageData(chunkImgData, 0, j);
  6833. j += FULL_CHUNK_HEIGHT;
  6834. }
  6835. if (i < totalChunks) {
  6836. elemsInThisChunk = width * partialChunkHeight * 4;
  6837. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  6838. ctx.putImageData(chunkImgData, 0, j);
  6839. }
  6840. }
  6841. else if (imgData.kind === util_ImageKind.RGB_24BPP) {
  6842. thisChunkHeight = FULL_CHUNK_HEIGHT;
  6843. elemsInThisChunk = width * thisChunkHeight;
  6844. for (i = 0; i < totalChunks; i++) {
  6845. if (i >= fullChunks) {
  6846. thisChunkHeight = partialChunkHeight;
  6847. elemsInThisChunk = width * thisChunkHeight;
  6848. }
  6849. destPos = 0;
  6850. for (j = elemsInThisChunk; j--;) {
  6851. dest[destPos++] = src[srcPos++];
  6852. dest[destPos++] = src[srcPos++];
  6853. dest[destPos++] = src[srcPos++];
  6854. dest[destPos++] = 255;
  6855. }
  6856. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  6857. }
  6858. }
  6859. else {
  6860. throw new Error("bad image kind: ".concat(imgData.kind));
  6861. }
  6862. }
  6863. function putBinaryImageMask(ctx, imgData) {
  6864. if (imgData.bitmap) {
  6865. ctx.drawImage(imgData.bitmap, 0, 0);
  6866. return;
  6867. }
  6868. var height = imgData.height, width = imgData.width;
  6869. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  6870. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  6871. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  6872. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  6873. var srcPos = 0;
  6874. var src = imgData.data;
  6875. var dest = chunkImgData.data;
  6876. for (var i = 0; i < totalChunks; i++) {
  6877. var thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  6878. (srcPos = convertBlackAndWhiteToRGBA({
  6879. src: src,
  6880. srcPos: srcPos,
  6881. dest: dest,
  6882. width: width,
  6883. height: thisChunkHeight,
  6884. nonBlackColor: 0
  6885. }).srcPos);
  6886. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  6887. }
  6888. }
  6889. function copyCtxState(sourceCtx, destCtx) {
  6890. var properties = ["strokeStyle", "fillStyle", "fillRule", "globalAlpha", "lineWidth", "lineCap", "lineJoin", "miterLimit", "globalCompositeOperation", "font", "filter"];
  6891. for (var _i = 0, properties_1 = properties; _i < properties_1.length; _i++) {
  6892. var property = properties_1[_i];
  6893. if (sourceCtx[property] !== undefined) {
  6894. destCtx[property] = sourceCtx[property];
  6895. }
  6896. }
  6897. if (sourceCtx.setLineDash !== undefined) {
  6898. destCtx.setLineDash(sourceCtx.getLineDash());
  6899. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  6900. }
  6901. }
  6902. function resetCtxToDefault(ctx) {
  6903. ctx.strokeStyle = ctx.fillStyle = "#000000";
  6904. ctx.fillRule = "nonzero";
  6905. ctx.globalAlpha = 1;
  6906. ctx.lineWidth = 1;
  6907. ctx.lineCap = "butt";
  6908. ctx.lineJoin = "miter";
  6909. ctx.miterLimit = 10;
  6910. ctx.globalCompositeOperation = "source-over";
  6911. ctx.font = "10px sans-serif";
  6912. if (ctx.setLineDash !== undefined) {
  6913. ctx.setLineDash([]);
  6914. ctx.lineDashOffset = 0;
  6915. }
  6916. if (!isNodeJS) {
  6917. var filter = ctx.filter;
  6918. if (filter !== "none" && filter !== "") {
  6919. ctx.filter = "none";
  6920. }
  6921. }
  6922. }
  6923. function getImageSmoothingEnabled(transform, interpolate) {
  6924. if (interpolate) {
  6925. return true;
  6926. }
  6927. var scale = Util.singularValueDecompose2dScale(transform);
  6928. scale[0] = Math.fround(scale[0]);
  6929. scale[1] = Math.fround(scale[1]);
  6930. var actualScale = Math.fround((globalThis.devicePixelRatio || 1) * PixelsPerInch.PDF_TO_CSS_UNITS);
  6931. return scale[0] <= actualScale && scale[1] <= actualScale;
  6932. }
  6933. var LINE_CAP_STYLES = ["butt", "round", "square"];
  6934. var LINE_JOIN_STYLES = ["miter", "round", "bevel"];
  6935. var NORMAL_CLIP = {};
  6936. var EO_CLIP = {};
  6937. var CanvasGraphics = /** @class */ (function () {
  6938. function CanvasGraphics(canvasCtx, commonObjs, objs, canvasFactory, filterFactory, _g, annotationCanvasMap, pageColors) {
  6939. var optionalContentConfig = _g.optionalContentConfig, _h = _g.markedContentStack, markedContentStack = _h === void 0 ? null : _h;
  6940. _CanvasGraphics_instances.add(this);
  6941. this.ctx = canvasCtx;
  6942. this.current = new CanvasExtraState(this.ctx.canvas.width, this.ctx.canvas.height);
  6943. this.stateStack = [];
  6944. this.pendingClip = null;
  6945. this.pendingEOFill = false;
  6946. this.res = null;
  6947. this.xobjs = null;
  6948. this.commonObjs = commonObjs;
  6949. this.objs = objs;
  6950. this.canvasFactory = canvasFactory;
  6951. this.filterFactory = filterFactory;
  6952. this.groupStack = [];
  6953. this.processingType3 = null;
  6954. this.baseTransform = null;
  6955. this.baseTransformStack = [];
  6956. this.groupLevel = 0;
  6957. this.smaskStack = [];
  6958. this.smaskCounter = 0;
  6959. this.tempSMask = null;
  6960. this.suspendedCtx = null;
  6961. this.contentVisible = true;
  6962. this.markedContentStack = markedContentStack || [];
  6963. this.optionalContentConfig = optionalContentConfig;
  6964. this.cachedCanvases = new CachedCanvases(this.canvasFactory);
  6965. this.cachedPatterns = new Map();
  6966. this.annotationCanvasMap = annotationCanvasMap;
  6967. this.viewportScale = 1;
  6968. this.outputScaleX = 1;
  6969. this.outputScaleY = 1;
  6970. this.pageColors = pageColors;
  6971. this._cachedScaleForStroking = [-1, 0];
  6972. this._cachedGetSinglePixelWidth = null;
  6973. this._cachedBitmapsMap = new Map();
  6974. }
  6975. CanvasGraphics.prototype.getObject = function (data, fallback) {
  6976. if (fallback === void 0) { fallback = null; }
  6977. if (typeof data === "string") {
  6978. return data.startsWith("g_") ? this.commonObjs.get(data) : this.objs.get(data);
  6979. }
  6980. return fallback;
  6981. };
  6982. CanvasGraphics.prototype.beginDrawing = function (_g) {
  6983. var _h, _j, _k;
  6984. var transform = _g.transform, viewport = _g.viewport, _l = _g.transparency, transparency = _l === void 0 ? false : _l, _m = _g.background, background = _m === void 0 ? null : _m;
  6985. var width = this.ctx.canvas.width;
  6986. var height = this.ctx.canvas.height;
  6987. var savedFillStyle = this.ctx.fillStyle;
  6988. this.ctx.fillStyle = background || "#ffffff";
  6989. this.ctx.fillRect(0, 0, width, height);
  6990. this.ctx.fillStyle = savedFillStyle;
  6991. if (transparency) {
  6992. var transparentCanvas = this.cachedCanvases.getCanvas("transparent", width, height);
  6993. this.compositeCtx = this.ctx;
  6994. this.transparentCanvas = transparentCanvas.canvas;
  6995. this.ctx = transparentCanvas.context;
  6996. this.ctx.save();
  6997. (_h = this.ctx).transform.apply(_h, getCurrentTransform(this.compositeCtx));
  6998. }
  6999. this.ctx.save();
  7000. resetCtxToDefault(this.ctx);
  7001. if (transform) {
  7002. (_j = this.ctx).transform.apply(_j, transform);
  7003. this.outputScaleX = transform[0];
  7004. this.outputScaleY = transform[0];
  7005. }
  7006. (_k = this.ctx).transform.apply(_k, viewport.transform);
  7007. this.viewportScale = viewport.scale;
  7008. this.baseTransform = getCurrentTransform(this.ctx);
  7009. };
  7010. CanvasGraphics.prototype.executeOperatorList = function (operatorList, executionStartIdx, continueCallback, stepper) {
  7011. var argsArray = operatorList.argsArray;
  7012. var fnArray = operatorList.fnArray;
  7013. var i = executionStartIdx || 0;
  7014. var argsArrayLen = argsArray.length;
  7015. if (argsArrayLen === i) {
  7016. return i;
  7017. }
  7018. var chunkOperations = argsArrayLen - i > EXECUTION_STEPS && typeof continueCallback === "function";
  7019. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  7020. var steps = 0;
  7021. var commonObjs = this.commonObjs;
  7022. var objs = this.objs;
  7023. var fnId;
  7024. while (true) {
  7025. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  7026. stepper.breakIt(i, continueCallback);
  7027. return i;
  7028. }
  7029. fnId = fnArray[i];
  7030. if (fnId !== OPS.dependency) {
  7031. this[fnId].apply(this, argsArray[i]);
  7032. }
  7033. else {
  7034. for (var _i = 0, _g = argsArray[i]; _i < _g.length; _i++) {
  7035. var depObjId = _g[_i];
  7036. var objsPool = depObjId.startsWith("g_") ? commonObjs : objs;
  7037. if (!objsPool.has(depObjId)) {
  7038. objsPool.get(depObjId, continueCallback);
  7039. return i;
  7040. }
  7041. }
  7042. }
  7043. i++;
  7044. if (i === argsArrayLen) {
  7045. return i;
  7046. }
  7047. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  7048. if (Date.now() > endTime) {
  7049. continueCallback();
  7050. return i;
  7051. }
  7052. steps = 0;
  7053. }
  7054. }
  7055. };
  7056. CanvasGraphics.prototype.endDrawing = function () {
  7057. tslib_1.__classPrivateFieldGet(this, _CanvasGraphics_instances, "m", _CanvasGraphics_restoreInitialState).call(this);
  7058. this.cachedCanvases.clear();
  7059. this.cachedPatterns.clear();
  7060. for (var _i = 0, _g = this._cachedBitmapsMap.values(); _i < _g.length; _i++) {
  7061. var cache = _g[_i];
  7062. for (var _h = 0, _j = cache.values(); _h < _j.length; _h++) {
  7063. var canvas = _j[_h];
  7064. if (typeof HTMLCanvasElement !== "undefined" && canvas instanceof HTMLCanvasElement) {
  7065. canvas.width = canvas.height = 0;
  7066. }
  7067. }
  7068. cache.clear();
  7069. }
  7070. this._cachedBitmapsMap.clear();
  7071. tslib_1.__classPrivateFieldGet(this, _CanvasGraphics_instances, "m", _CanvasGraphics_drawFilter).call(this);
  7072. };
  7073. CanvasGraphics.prototype._scaleImage = function (img, inverseTransform) {
  7074. var width = img.width;
  7075. var height = img.height;
  7076. var widthScale = Math.max(Math.hypot(inverseTransform[0], inverseTransform[1]), 1);
  7077. var heightScale = Math.max(Math.hypot(inverseTransform[2], inverseTransform[3]), 1);
  7078. var paintWidth = width, paintHeight = height;
  7079. var tmpCanvasId = "prescale1";
  7080. var tmpCanvas, tmpCtx;
  7081. while (widthScale > 2 && paintWidth > 1 || heightScale > 2 && paintHeight > 1) {
  7082. var newWidth = paintWidth, newHeight = paintHeight;
  7083. if (widthScale > 2 && paintWidth > 1) {
  7084. newWidth = paintWidth >= 16384 ? Math.floor(paintWidth / 2) - 1 || 1 : Math.ceil(paintWidth / 2);
  7085. widthScale /= paintWidth / newWidth;
  7086. }
  7087. if (heightScale > 2 && paintHeight > 1) {
  7088. newHeight = paintHeight >= 16384 ? Math.floor(paintHeight / 2) - 1 || 1 : Math.ceil(paintHeight) / 2;
  7089. heightScale /= paintHeight / newHeight;
  7090. }
  7091. tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
  7092. tmpCtx = tmpCanvas.context;
  7093. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  7094. tmpCtx.drawImage(img, 0, 0, paintWidth, paintHeight, 0, 0, newWidth, newHeight);
  7095. img = tmpCanvas.canvas;
  7096. paintWidth = newWidth;
  7097. paintHeight = newHeight;
  7098. tmpCanvasId = tmpCanvasId === "prescale1" ? "prescale2" : "prescale1";
  7099. }
  7100. return {
  7101. img: img,
  7102. paintWidth: paintWidth,
  7103. paintHeight: paintHeight
  7104. };
  7105. };
  7106. CanvasGraphics.prototype._createMaskCanvas = function (img) {
  7107. var ctx = this.ctx;
  7108. var width = img.width, height = img.height;
  7109. var fillColor = this.current.fillColor;
  7110. var isPatternFill = this.current.patternFill;
  7111. var currentTransform = getCurrentTransform(ctx);
  7112. var cache, cacheKey, scaled, maskCanvas;
  7113. if ((img.bitmap || img.data) && img.count > 1) {
  7114. var mainKey = img.bitmap || img.data.buffer;
  7115. cacheKey = JSON.stringify(isPatternFill ? currentTransform : [currentTransform.slice(0, 4), fillColor]);
  7116. cache = this._cachedBitmapsMap.get(mainKey);
  7117. if (!cache) {
  7118. cache = new Map();
  7119. this._cachedBitmapsMap.set(mainKey, cache);
  7120. }
  7121. var cachedImage = cache.get(cacheKey);
  7122. if (cachedImage && !isPatternFill) {
  7123. var offsetX_1 = Math.round(Math.min(currentTransform[0], currentTransform[2]) + currentTransform[4]);
  7124. var offsetY_1 = Math.round(Math.min(currentTransform[1], currentTransform[3]) + currentTransform[5]);
  7125. return {
  7126. canvas: cachedImage,
  7127. offsetX: offsetX_1,
  7128. offsetY: offsetY_1
  7129. };
  7130. }
  7131. scaled = cachedImage;
  7132. }
  7133. if (!scaled) {
  7134. maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
  7135. putBinaryImageMask(maskCanvas.context, img);
  7136. }
  7137. var maskToCanvas = Util.transform(currentTransform, [1 / width, 0, 0, -1 / height, 0, 0]);
  7138. maskToCanvas = Util.transform(maskToCanvas, [1, 0, 0, 1, 0, -height]);
  7139. var _g = Util.getAxialAlignedBoundingBox([0, 0, width, height], maskToCanvas), minX = _g[0], minY = _g[1], maxX = _g[2], maxY = _g[3];
  7140. var drawnWidth = Math.round(maxX - minX) || 1;
  7141. var drawnHeight = Math.round(maxY - minY) || 1;
  7142. var fillCanvas = this.cachedCanvases.getCanvas("fillCanvas", drawnWidth, drawnHeight);
  7143. var fillCtx = fillCanvas.context;
  7144. var offsetX = minX;
  7145. var offsetY = minY;
  7146. fillCtx.translate(-offsetX, -offsetY);
  7147. fillCtx.transform.apply(fillCtx, maskToCanvas);
  7148. if (!scaled) {
  7149. scaled = this._scaleImage(maskCanvas.canvas, getCurrentTransformInverse(fillCtx));
  7150. scaled = scaled.img;
  7151. if (cache && isPatternFill) {
  7152. cache.set(cacheKey, scaled);
  7153. }
  7154. }
  7155. fillCtx.imageSmoothingEnabled = getImageSmoothingEnabled(getCurrentTransform(fillCtx), img.interpolate);
  7156. drawImageAtIntegerCoords(fillCtx, scaled, 0, 0, scaled.width, scaled.height, 0, 0, width, height);
  7157. fillCtx.globalCompositeOperation = "source-in";
  7158. var inverse = Util.transform(getCurrentTransformInverse(fillCtx), [1, 0, 0, 1, -offsetX, -offsetY]);
  7159. fillCtx.fillStyle = isPatternFill ? fillColor.getPattern(ctx, this, inverse, PathType.FILL) : fillColor;
  7160. fillCtx.fillRect(0, 0, width, height);
  7161. if (cache && !isPatternFill) {
  7162. this.cachedCanvases.delete("fillCanvas");
  7163. cache.set(cacheKey, fillCanvas.canvas);
  7164. }
  7165. return {
  7166. canvas: fillCanvas.canvas,
  7167. offsetX: Math.round(offsetX),
  7168. offsetY: Math.round(offsetY)
  7169. };
  7170. };
  7171. CanvasGraphics.prototype.setLineWidth = function (width) {
  7172. if (width !== this.current.lineWidth) {
  7173. this._cachedScaleForStroking[0] = -1;
  7174. }
  7175. this.current.lineWidth = width;
  7176. this.ctx.lineWidth = width;
  7177. };
  7178. CanvasGraphics.prototype.setLineCap = function (style) {
  7179. this.ctx.lineCap = LINE_CAP_STYLES[style];
  7180. };
  7181. CanvasGraphics.prototype.setLineJoin = function (style) {
  7182. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  7183. };
  7184. CanvasGraphics.prototype.setMiterLimit = function (limit) {
  7185. this.ctx.miterLimit = limit;
  7186. };
  7187. CanvasGraphics.prototype.setDash = function (dashArray, dashPhase) {
  7188. var ctx = this.ctx;
  7189. if (ctx.setLineDash !== undefined) {
  7190. ctx.setLineDash(dashArray);
  7191. ctx.lineDashOffset = dashPhase;
  7192. }
  7193. };
  7194. CanvasGraphics.prototype.setRenderingIntent = function (intent) { };
  7195. CanvasGraphics.prototype.setFlatness = function (flatness) { };
  7196. CanvasGraphics.prototype.setGState = function (states) {
  7197. for (var _i = 0, states_1 = states; _i < states_1.length; _i++) {
  7198. var _g = states_1[_i], key = _g[0], value = _g[1];
  7199. switch (key) {
  7200. case "LW":
  7201. this.setLineWidth(value);
  7202. break;
  7203. case "LC":
  7204. this.setLineCap(value);
  7205. break;
  7206. case "LJ":
  7207. this.setLineJoin(value);
  7208. break;
  7209. case "ML":
  7210. this.setMiterLimit(value);
  7211. break;
  7212. case "D":
  7213. this.setDash(value[0], value[1]);
  7214. break;
  7215. case "RI":
  7216. this.setRenderingIntent(value);
  7217. break;
  7218. case "FL":
  7219. this.setFlatness(value);
  7220. break;
  7221. case "Font":
  7222. this.setFont(value[0], value[1]);
  7223. break;
  7224. case "CA":
  7225. this.current.strokeAlpha = value;
  7226. break;
  7227. case "ca":
  7228. this.current.fillAlpha = value;
  7229. this.ctx.globalAlpha = value;
  7230. break;
  7231. case "BM":
  7232. this.ctx.globalCompositeOperation = value;
  7233. break;
  7234. case "SMask":
  7235. this.current.activeSMask = value ? this.tempSMask : null;
  7236. this.tempSMask = null;
  7237. this.checkSMaskState();
  7238. break;
  7239. case "TR":
  7240. this.ctx.filter = this.current.transferMaps = this.filterFactory.addFilter(value);
  7241. break;
  7242. }
  7243. }
  7244. };
  7245. Object.defineProperty(CanvasGraphics.prototype, "inSMaskMode", {
  7246. get: function () {
  7247. return !!this.suspendedCtx;
  7248. },
  7249. enumerable: false,
  7250. configurable: true
  7251. });
  7252. CanvasGraphics.prototype.checkSMaskState = function () {
  7253. var inSMaskMode = this.inSMaskMode;
  7254. if (this.current.activeSMask && !inSMaskMode) {
  7255. this.beginSMaskMode();
  7256. }
  7257. else if (!this.current.activeSMask && inSMaskMode) {
  7258. this.endSMaskMode();
  7259. }
  7260. };
  7261. CanvasGraphics.prototype.beginSMaskMode = function () {
  7262. if (this.inSMaskMode) {
  7263. throw new Error("beginSMaskMode called while already in smask mode");
  7264. }
  7265. var drawnWidth = this.ctx.canvas.width;
  7266. var drawnHeight = this.ctx.canvas.height;
  7267. var cacheId = "smaskGroupAt" + this.groupLevel;
  7268. var scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight);
  7269. this.suspendedCtx = this.ctx;
  7270. this.ctx = scratchCanvas.context;
  7271. var ctx = this.ctx;
  7272. ctx.setTransform.apply(ctx, getCurrentTransform(this.suspendedCtx));
  7273. copyCtxState(this.suspendedCtx, ctx);
  7274. mirrorContextOperations(ctx, this.suspendedCtx);
  7275. this.setGState([["BM", "source-over"], ["ca", 1], ["CA", 1]]);
  7276. };
  7277. CanvasGraphics.prototype.endSMaskMode = function () {
  7278. if (!this.inSMaskMode) {
  7279. throw new Error("endSMaskMode called while not in smask mode");
  7280. }
  7281. this.ctx._removeMirroring();
  7282. copyCtxState(this.ctx, this.suspendedCtx);
  7283. this.ctx = this.suspendedCtx;
  7284. this.suspendedCtx = null;
  7285. };
  7286. CanvasGraphics.prototype.compose = function (dirtyBox) {
  7287. if (!this.current.activeSMask) {
  7288. return;
  7289. }
  7290. if (!dirtyBox) {
  7291. dirtyBox = [0, 0, this.ctx.canvas.width, this.ctx.canvas.height];
  7292. }
  7293. else {
  7294. dirtyBox[0] = Math.floor(dirtyBox[0]);
  7295. dirtyBox[1] = Math.floor(dirtyBox[1]);
  7296. dirtyBox[2] = Math.ceil(dirtyBox[2]);
  7297. dirtyBox[3] = Math.ceil(dirtyBox[3]);
  7298. }
  7299. var smask = this.current.activeSMask;
  7300. var suspendedCtx = this.suspendedCtx;
  7301. this.composeSMask(suspendedCtx, smask, this.ctx, dirtyBox);
  7302. this.ctx.save();
  7303. this.ctx.setTransform(1, 0, 0, 1, 0, 0);
  7304. this.ctx.clearRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height);
  7305. this.ctx.restore();
  7306. };
  7307. CanvasGraphics.prototype.composeSMask = function (ctx, smask, layerCtx, layerBox) {
  7308. var layerOffsetX = layerBox[0];
  7309. var layerOffsetY = layerBox[1];
  7310. var layerWidth = layerBox[2] - layerOffsetX;
  7311. var layerHeight = layerBox[3] - layerOffsetY;
  7312. if (layerWidth === 0 || layerHeight === 0) {
  7313. return;
  7314. }
  7315. this.genericComposeSMask(smask.context, layerCtx, layerWidth, layerHeight, smask.subtype, smask.backdrop, smask.transferMap, layerOffsetX, layerOffsetY, smask.offsetX, smask.offsetY);
  7316. ctx.save();
  7317. ctx.globalAlpha = 1;
  7318. ctx.globalCompositeOperation = "source-over";
  7319. ctx.setTransform(1, 0, 0, 1, 0, 0);
  7320. ctx.drawImage(layerCtx.canvas, 0, 0);
  7321. ctx.restore();
  7322. };
  7323. CanvasGraphics.prototype.genericComposeSMask = function (maskCtx, layerCtx, width, height, subtype, backdrop, transferMap, layerOffsetX, layerOffsetY, maskOffsetX, maskOffsetY) {
  7324. var maskCanvas = maskCtx.canvas;
  7325. var maskX = layerOffsetX - maskOffsetX;
  7326. var maskY = layerOffsetY - maskOffsetY;
  7327. if (backdrop) {
  7328. if (maskX < 0 || maskY < 0 || maskX + width > maskCanvas.width || maskY + height > maskCanvas.height) {
  7329. var canvas = this.cachedCanvases.getCanvas("maskExtension", width, height);
  7330. var ctx = canvas.context;
  7331. ctx.drawImage(maskCanvas, -maskX, -maskY);
  7332. if (backdrop.some(function (c) { return c !== 0; })) {
  7333. ctx.globalCompositeOperation = "destination-atop";
  7334. ctx.fillStyle = Util.makeHexColor.apply(Util, backdrop);
  7335. ctx.fillRect(0, 0, width, height);
  7336. ctx.globalCompositeOperation = "source-over";
  7337. }
  7338. maskCanvas = canvas.canvas;
  7339. maskX = maskY = 0;
  7340. }
  7341. else if (backdrop.some(function (c) { return c !== 0; })) {
  7342. maskCtx.save();
  7343. maskCtx.globalAlpha = 1;
  7344. maskCtx.setTransform(1, 0, 0, 1, 0, 0);
  7345. var clip_1 = new Path2D();
  7346. clip_1.rect(maskX, maskY, width, height);
  7347. maskCtx.clip(clip_1);
  7348. maskCtx.globalCompositeOperation = "destination-atop";
  7349. maskCtx.fillStyle = Util.makeHexColor.apply(Util, backdrop);
  7350. maskCtx.fillRect(maskX, maskY, width, height);
  7351. maskCtx.restore();
  7352. }
  7353. }
  7354. layerCtx.save();
  7355. layerCtx.globalAlpha = 1;
  7356. layerCtx.setTransform(1, 0, 0, 1, 0, 0);
  7357. if (subtype === "Alpha" && transferMap) {
  7358. layerCtx.filter = this.filterFactory.addAlphaFilter(transferMap);
  7359. }
  7360. else if (subtype === "Luminosity") {
  7361. layerCtx.filter = this.filterFactory.addLuminosityFilter(transferMap);
  7362. }
  7363. var clip = new Path2D();
  7364. clip.rect(layerOffsetX, layerOffsetY, width, height);
  7365. layerCtx.clip(clip);
  7366. layerCtx.globalCompositeOperation = "destination-in";
  7367. layerCtx.drawImage(maskCanvas, maskX, maskY, width, height, layerOffsetX, layerOffsetY, width, height);
  7368. layerCtx.restore();
  7369. };
  7370. CanvasGraphics.prototype.save = function () {
  7371. if (this.inSMaskMode) {
  7372. copyCtxState(this.ctx, this.suspendedCtx);
  7373. this.suspendedCtx.save();
  7374. }
  7375. else {
  7376. this.ctx.save();
  7377. }
  7378. var old = this.current;
  7379. this.stateStack.push(old);
  7380. this.current = old.clone();
  7381. };
  7382. CanvasGraphics.prototype.restore = function () {
  7383. if (this.stateStack.length === 0 && this.inSMaskMode) {
  7384. this.endSMaskMode();
  7385. }
  7386. if (this.stateStack.length !== 0) {
  7387. this.current = this.stateStack.pop();
  7388. if (this.inSMaskMode) {
  7389. this.suspendedCtx.restore();
  7390. copyCtxState(this.suspendedCtx, this.ctx);
  7391. }
  7392. else {
  7393. this.ctx.restore();
  7394. }
  7395. this.checkSMaskState();
  7396. this.pendingClip = null;
  7397. this._cachedScaleForStroking[0] = -1;
  7398. this._cachedGetSinglePixelWidth = null;
  7399. }
  7400. };
  7401. CanvasGraphics.prototype.transform = function (a, b, c, d, e, f) {
  7402. this.ctx.transform(a, b, c, d, e, f);
  7403. this._cachedScaleForStroking[0] = -1;
  7404. this._cachedGetSinglePixelWidth = null;
  7405. };
  7406. CanvasGraphics.prototype.constructPath = function (ops, args, minMax) {
  7407. var ctx = this.ctx;
  7408. var current = this.current;
  7409. var x = current.x, y = current.y;
  7410. var startX, startY;
  7411. var currentTransform = getCurrentTransform(ctx);
  7412. var isScalingMatrix = currentTransform[0] === 0 && currentTransform[3] === 0 || currentTransform[1] === 0 && currentTransform[2] === 0;
  7413. var minMaxForBezier = isScalingMatrix ? minMax.slice(0) : null;
  7414. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  7415. switch (ops[i] | 0) {
  7416. case OPS.rectangle:
  7417. x = args[j++];
  7418. y = args[j++];
  7419. var width = args[j++];
  7420. var height = args[j++];
  7421. var xw = x + width;
  7422. var yh = y + height;
  7423. ctx.moveTo(x, y);
  7424. if (width === 0 || height === 0) {
  7425. ctx.lineTo(xw, yh);
  7426. }
  7427. else {
  7428. ctx.lineTo(xw, y);
  7429. ctx.lineTo(xw, yh);
  7430. ctx.lineTo(x, yh);
  7431. }
  7432. if (!isScalingMatrix) {
  7433. current.updateRectMinMax(currentTransform, [x, y, xw, yh]);
  7434. }
  7435. ctx.closePath();
  7436. break;
  7437. case OPS.moveTo:
  7438. x = args[j++];
  7439. y = args[j++];
  7440. ctx.moveTo(x, y);
  7441. if (!isScalingMatrix) {
  7442. current.updatePathMinMax(currentTransform, x, y);
  7443. }
  7444. break;
  7445. case OPS.lineTo:
  7446. x = args[j++];
  7447. y = args[j++];
  7448. ctx.lineTo(x, y);
  7449. if (!isScalingMatrix) {
  7450. current.updatePathMinMax(currentTransform, x, y);
  7451. }
  7452. break;
  7453. case OPS.curveTo:
  7454. startX = x;
  7455. startY = y;
  7456. x = args[j + 4];
  7457. y = args[j + 5];
  7458. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3], x, y);
  7459. current.updateCurvePathMinMax(currentTransform, startX, startY, args[j], args[j + 1], args[j + 2], args[j + 3], x, y, minMaxForBezier);
  7460. j += 6;
  7461. break;
  7462. case OPS.curveTo2:
  7463. startX = x;
  7464. startY = y;
  7465. ctx.bezierCurveTo(x, y, args[j], args[j + 1], args[j + 2], args[j + 3]);
  7466. current.updateCurvePathMinMax(currentTransform, startX, startY, x, y, args[j], args[j + 1], args[j + 2], args[j + 3], minMaxForBezier);
  7467. x = args[j + 2];
  7468. y = args[j + 3];
  7469. j += 4;
  7470. break;
  7471. case OPS.curveTo3:
  7472. startX = x;
  7473. startY = y;
  7474. x = args[j + 2];
  7475. y = args[j + 3];
  7476. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  7477. current.updateCurvePathMinMax(currentTransform, startX, startY, args[j], args[j + 1], x, y, x, y, minMaxForBezier);
  7478. j += 4;
  7479. break;
  7480. case OPS.closePath:
  7481. ctx.closePath();
  7482. break;
  7483. }
  7484. }
  7485. if (isScalingMatrix) {
  7486. current.updateScalingPathMinMax(currentTransform, minMaxForBezier);
  7487. }
  7488. current.setCurrentPoint(x, y);
  7489. };
  7490. CanvasGraphics.prototype.closePath = function () {
  7491. this.ctx.closePath();
  7492. };
  7493. CanvasGraphics.prototype.stroke = function (consumePath) {
  7494. if (consumePath === void 0) { consumePath = true; }
  7495. var ctx = this.ctx;
  7496. var strokeColor = this.current.strokeColor;
  7497. ctx.globalAlpha = this.current.strokeAlpha;
  7498. if (this.contentVisible) {
  7499. if (typeof strokeColor === "object" && (strokeColor === null || strokeColor === void 0 ? void 0 : strokeColor.getPattern)) {
  7500. ctx.save();
  7501. ctx.strokeStyle = strokeColor.getPattern(ctx, this, getCurrentTransformInverse(ctx), PathType.STROKE);
  7502. this.rescaleAndStroke(false);
  7503. ctx.restore();
  7504. }
  7505. else {
  7506. this.rescaleAndStroke(true);
  7507. }
  7508. }
  7509. if (consumePath) {
  7510. this.consumePath(this.current.getClippedPathBoundingBox());
  7511. }
  7512. ctx.globalAlpha = this.current.fillAlpha;
  7513. };
  7514. CanvasGraphics.prototype.closeStroke = function () {
  7515. this.closePath();
  7516. this.stroke();
  7517. };
  7518. CanvasGraphics.prototype.fill = function (consumePath) {
  7519. if (consumePath === void 0) { consumePath = true; }
  7520. var ctx = this.ctx;
  7521. var fillColor = this.current.fillColor;
  7522. var isPatternFill = this.current.patternFill;
  7523. var needRestore = false;
  7524. if (isPatternFill) {
  7525. ctx.save();
  7526. ctx.fillStyle = fillColor.getPattern(ctx, this, getCurrentTransformInverse(ctx), PathType.FILL);
  7527. needRestore = true;
  7528. }
  7529. var intersect = this.current.getClippedPathBoundingBox();
  7530. if (this.contentVisible && intersect !== null) {
  7531. if (this.pendingEOFill) {
  7532. ctx.fill("evenodd");
  7533. this.pendingEOFill = false;
  7534. }
  7535. else {
  7536. ctx.fill();
  7537. }
  7538. }
  7539. if (needRestore) {
  7540. ctx.restore();
  7541. }
  7542. if (consumePath) {
  7543. this.consumePath(intersect);
  7544. }
  7545. };
  7546. CanvasGraphics.prototype.eoFill = function () {
  7547. this.pendingEOFill = true;
  7548. this.fill();
  7549. };
  7550. CanvasGraphics.prototype.fillStroke = function () {
  7551. this.fill(false);
  7552. this.stroke(false);
  7553. this.consumePath();
  7554. };
  7555. CanvasGraphics.prototype.eoFillStroke = function () {
  7556. this.pendingEOFill = true;
  7557. this.fillStroke();
  7558. };
  7559. CanvasGraphics.prototype.closeFillStroke = function () {
  7560. this.closePath();
  7561. this.fillStroke();
  7562. };
  7563. CanvasGraphics.prototype.closeEOFillStroke = function () {
  7564. this.pendingEOFill = true;
  7565. this.closePath();
  7566. this.fillStroke();
  7567. };
  7568. CanvasGraphics.prototype.endPath = function () {
  7569. this.consumePath();
  7570. };
  7571. CanvasGraphics.prototype.clip = function () {
  7572. this.pendingClip = NORMAL_CLIP;
  7573. };
  7574. CanvasGraphics.prototype.eoClip = function () {
  7575. this.pendingClip = EO_CLIP;
  7576. };
  7577. CanvasGraphics.prototype.beginText = function () {
  7578. this.current.textMatrix = IDENTITY_MATRIX;
  7579. this.current.textMatrixScale = 1;
  7580. this.current.x = this.current.lineX = 0;
  7581. this.current.y = this.current.lineY = 0;
  7582. };
  7583. CanvasGraphics.prototype.endText = function () {
  7584. var paths = this.pendingTextPaths;
  7585. var ctx = this.ctx;
  7586. if (paths === undefined) {
  7587. ctx.beginPath();
  7588. return;
  7589. }
  7590. ctx.save();
  7591. ctx.beginPath();
  7592. for (var _i = 0, paths_1 = paths; _i < paths_1.length; _i++) {
  7593. var path = paths_1[_i];
  7594. ctx.setTransform.apply(ctx, path.transform);
  7595. ctx.translate(path.x, path.y);
  7596. path.addToPath(ctx, path.fontSize);
  7597. }
  7598. ctx.restore();
  7599. ctx.clip();
  7600. ctx.beginPath();
  7601. delete this.pendingTextPaths;
  7602. };
  7603. CanvasGraphics.prototype.setCharSpacing = function (spacing) {
  7604. this.current.charSpacing = spacing;
  7605. };
  7606. CanvasGraphics.prototype.setWordSpacing = function (spacing) {
  7607. this.current.wordSpacing = spacing;
  7608. };
  7609. CanvasGraphics.prototype.setHScale = function (scale) {
  7610. this.current.textHScale = scale / 100;
  7611. };
  7612. CanvasGraphics.prototype.setLeading = function (leading) {
  7613. this.current.leading = -leading;
  7614. };
  7615. CanvasGraphics.prototype.setFont = function (fontRefName, size) {
  7616. var _g;
  7617. var fontObj = this.commonObjs.get(fontRefName);
  7618. var current = this.current;
  7619. if (!fontObj) {
  7620. throw new Error("Can't find font for ".concat(fontRefName));
  7621. }
  7622. current.fontMatrix = fontObj.fontMatrix || FONT_IDENTITY_MATRIX;
  7623. if (current.fontMatrix[0] === 0 || current.fontMatrix[3] === 0) {
  7624. warn("Invalid font matrix for font " + fontRefName);
  7625. }
  7626. if (size < 0) {
  7627. size = -size;
  7628. current.fontDirection = -1;
  7629. }
  7630. else {
  7631. current.fontDirection = 1;
  7632. }
  7633. this.current.font = fontObj;
  7634. this.current.fontSize = size;
  7635. if (fontObj.isType3Font) {
  7636. return;
  7637. }
  7638. var name = fontObj.loadedName || "sans-serif";
  7639. var typeface = ((_g = fontObj.systemFontInfo) === null || _g === void 0 ? void 0 : _g.css) || "\"".concat(name, "\", ").concat(fontObj.fallbackName);
  7640. var bold = "normal";
  7641. if (fontObj.black) {
  7642. bold = "900";
  7643. }
  7644. else if (fontObj.bold) {
  7645. bold = "bold";
  7646. }
  7647. var italic = fontObj.italic ? "italic" : "normal";
  7648. var browserFontSize = size;
  7649. if (size < MIN_FONT_SIZE) {
  7650. browserFontSize = MIN_FONT_SIZE;
  7651. }
  7652. else if (size > MAX_FONT_SIZE) {
  7653. browserFontSize = MAX_FONT_SIZE;
  7654. }
  7655. this.current.fontSizeScale = size / browserFontSize;
  7656. this.ctx.font = "".concat(italic, " ").concat(bold, " ").concat(browserFontSize, "px ").concat(typeface);
  7657. };
  7658. CanvasGraphics.prototype.setTextRenderingMode = function (mode) {
  7659. this.current.textRenderingMode = mode;
  7660. };
  7661. CanvasGraphics.prototype.setTextRise = function (rise) {
  7662. this.current.textRise = rise;
  7663. };
  7664. CanvasGraphics.prototype.moveText = function (x, y) {
  7665. this.current.x = this.current.lineX += x;
  7666. this.current.y = this.current.lineY += y;
  7667. };
  7668. CanvasGraphics.prototype.setLeadingMoveText = function (x, y) {
  7669. this.setLeading(-y);
  7670. this.moveText(x, y);
  7671. };
  7672. CanvasGraphics.prototype.setTextMatrix = function (a, b, c, d, e, f) {
  7673. this.current.textMatrix = [a, b, c, d, e, f];
  7674. this.current.textMatrixScale = Math.hypot(a, b);
  7675. this.current.x = this.current.lineX = 0;
  7676. this.current.y = this.current.lineY = 0;
  7677. };
  7678. CanvasGraphics.prototype.nextLine = function () {
  7679. this.moveText(0, this.current.leading);
  7680. };
  7681. CanvasGraphics.prototype.paintChar = function (character, x, y, patternTransform) {
  7682. var ctx = this.ctx;
  7683. var current = this.current;
  7684. var font = current.font;
  7685. var textRenderingMode = current.textRenderingMode;
  7686. var fontSize = current.fontSize / current.fontSizeScale;
  7687. var fillStrokeMode = textRenderingMode & TextRenderingMode.FILL_STROKE_MASK;
  7688. var isAddToPathSet = !!(textRenderingMode & TextRenderingMode.ADD_TO_PATH_FLAG);
  7689. var patternFill = current.patternFill && !font.missingFile;
  7690. var addToPath;
  7691. if (font.disableFontFace || isAddToPathSet || patternFill) {
  7692. addToPath = font.getPathGenerator(this.commonObjs, character);
  7693. }
  7694. if (font.disableFontFace || patternFill) {
  7695. ctx.save();
  7696. ctx.translate(x, y);
  7697. ctx.beginPath();
  7698. addToPath(ctx, fontSize);
  7699. if (patternTransform) {
  7700. ctx.setTransform.apply(ctx, patternTransform);
  7701. }
  7702. if (fillStrokeMode === TextRenderingMode.FILL || fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  7703. ctx.fill();
  7704. }
  7705. if (fillStrokeMode === TextRenderingMode.STROKE || fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  7706. ctx.stroke();
  7707. }
  7708. ctx.restore();
  7709. }
  7710. else {
  7711. if (fillStrokeMode === TextRenderingMode.FILL || fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  7712. ctx.fillText(character, x, y);
  7713. }
  7714. if (fillStrokeMode === TextRenderingMode.STROKE || fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  7715. ctx.strokeText(character, x, y);
  7716. }
  7717. }
  7718. if (isAddToPathSet) {
  7719. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  7720. paths.push({
  7721. transform: getCurrentTransform(ctx),
  7722. x: x,
  7723. y: y,
  7724. fontSize: fontSize,
  7725. addToPath: addToPath
  7726. });
  7727. }
  7728. };
  7729. Object.defineProperty(CanvasGraphics.prototype, "isFontSubpixelAAEnabled", {
  7730. get: function () {
  7731. var ctx = this.cachedCanvases.getCanvas("isFontSubpixelAAEnabled", 10, 10).context;
  7732. ctx.scale(1.5, 1);
  7733. ctx.fillText("I", 0, 10);
  7734. var data = ctx.getImageData(0, 0, 10, 10).data;
  7735. var enabled = false;
  7736. for (var i = 3; i < data.length; i += 4) {
  7737. if (data[i] > 0 && data[i] < 255) {
  7738. enabled = true;
  7739. break;
  7740. }
  7741. }
  7742. return shadow(this, "isFontSubpixelAAEnabled", enabled);
  7743. },
  7744. enumerable: false,
  7745. configurable: true
  7746. });
  7747. CanvasGraphics.prototype.showText = function (glyphs) {
  7748. var current = this.current;
  7749. var font = current.font;
  7750. if (font.isType3Font) {
  7751. return this.showType3Text(glyphs);
  7752. }
  7753. var fontSize = current.fontSize;
  7754. if (fontSize === 0) {
  7755. return undefined;
  7756. }
  7757. var ctx = this.ctx;
  7758. var fontSizeScale = current.fontSizeScale;
  7759. var charSpacing = current.charSpacing;
  7760. var wordSpacing = current.wordSpacing;
  7761. var fontDirection = current.fontDirection;
  7762. var textHScale = current.textHScale * fontDirection;
  7763. var glyphsLength = glyphs.length;
  7764. var vertical = font.vertical;
  7765. var spacingDir = vertical ? 1 : -1;
  7766. var defaultVMetrics = font.defaultVMetrics;
  7767. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  7768. var simpleFillText = current.textRenderingMode === TextRenderingMode.FILL && !font.disableFontFace && !current.patternFill;
  7769. ctx.save();
  7770. ctx.transform.apply(ctx, current.textMatrix);
  7771. ctx.translate(current.x, current.y + current.textRise);
  7772. if (fontDirection > 0) {
  7773. ctx.scale(textHScale, -1);
  7774. }
  7775. else {
  7776. ctx.scale(textHScale, 1);
  7777. }
  7778. var patternTransform;
  7779. if (current.patternFill) {
  7780. ctx.save();
  7781. var pattern = current.fillColor.getPattern(ctx, this, getCurrentTransformInverse(ctx), PathType.FILL);
  7782. patternTransform = getCurrentTransform(ctx);
  7783. ctx.restore();
  7784. ctx.fillStyle = pattern;
  7785. }
  7786. var lineWidth = current.lineWidth;
  7787. var scale = current.textMatrixScale;
  7788. if (scale === 0 || lineWidth === 0) {
  7789. var fillStrokeMode = current.textRenderingMode & TextRenderingMode.FILL_STROKE_MASK;
  7790. if (fillStrokeMode === TextRenderingMode.STROKE || fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  7791. lineWidth = this.getSinglePixelWidth();
  7792. }
  7793. }
  7794. else {
  7795. lineWidth /= scale;
  7796. }
  7797. if (fontSizeScale !== 1.0) {
  7798. ctx.scale(fontSizeScale, fontSizeScale);
  7799. lineWidth /= fontSizeScale;
  7800. }
  7801. ctx.lineWidth = lineWidth;
  7802. if (font.isInvalidPDFjsFont) {
  7803. var chars = [];
  7804. var width = 0;
  7805. for (var _i = 0, glyphs_1 = glyphs; _i < glyphs_1.length; _i++) {
  7806. var glyph = glyphs_1[_i];
  7807. chars.push(glyph.unicode);
  7808. width += glyph.width;
  7809. }
  7810. ctx.fillText(chars.join(""), 0, 0);
  7811. current.x += width * widthAdvanceScale * textHScale;
  7812. ctx.restore();
  7813. this.compose();
  7814. return undefined;
  7815. }
  7816. var x = 0, i;
  7817. for (i = 0; i < glyphsLength; ++i) {
  7818. var glyph = glyphs[i];
  7819. if (typeof glyph === "number") {
  7820. x += spacingDir * glyph * fontSize / 1000;
  7821. continue;
  7822. }
  7823. var restoreNeeded = false;
  7824. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  7825. var character = glyph.fontChar;
  7826. var accent = glyph.accent;
  7827. var scaledX = void 0, scaledY = void 0;
  7828. var width = glyph.width;
  7829. if (vertical) {
  7830. var vmetric = glyph.vmetric || defaultVMetrics;
  7831. var vx = -(glyph.vmetric ? vmetric[1] : width * 0.5) * widthAdvanceScale;
  7832. var vy = vmetric[2] * widthAdvanceScale;
  7833. width = vmetric ? -vmetric[0] : width;
  7834. scaledX = vx / fontSizeScale;
  7835. scaledY = (x + vy) / fontSizeScale;
  7836. }
  7837. else {
  7838. scaledX = x / fontSizeScale;
  7839. scaledY = 0;
  7840. }
  7841. if (font.remeasure && width > 0) {
  7842. var measuredWidth = ctx.measureText(character).width * 1000 / fontSize * fontSizeScale;
  7843. if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
  7844. var characterScaleX = width / measuredWidth;
  7845. restoreNeeded = true;
  7846. ctx.save();
  7847. ctx.scale(characterScaleX, 1);
  7848. scaledX /= characterScaleX;
  7849. }
  7850. else if (width !== measuredWidth) {
  7851. scaledX += (width - measuredWidth) / 2000 * fontSize / fontSizeScale;
  7852. }
  7853. }
  7854. if (this.contentVisible && (glyph.isInFont || font.missingFile)) {
  7855. if (simpleFillText && !accent) {
  7856. ctx.fillText(character, scaledX, scaledY);
  7857. }
  7858. else {
  7859. this.paintChar(character, scaledX, scaledY, patternTransform);
  7860. if (accent) {
  7861. var scaledAccentX = scaledX + fontSize * accent.offset.x / fontSizeScale;
  7862. var scaledAccentY = scaledY - fontSize * accent.offset.y / fontSizeScale;
  7863. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY, patternTransform);
  7864. }
  7865. }
  7866. }
  7867. var charWidth = vertical ? width * widthAdvanceScale - spacing * fontDirection : width * widthAdvanceScale + spacing * fontDirection;
  7868. x += charWidth;
  7869. if (restoreNeeded) {
  7870. ctx.restore();
  7871. }
  7872. }
  7873. if (vertical) {
  7874. current.y -= x;
  7875. }
  7876. else {
  7877. current.x += x * textHScale;
  7878. }
  7879. ctx.restore();
  7880. this.compose();
  7881. return undefined;
  7882. };
  7883. CanvasGraphics.prototype.showType3Text = function (glyphs) {
  7884. var ctx = this.ctx;
  7885. var current = this.current;
  7886. var font = current.font;
  7887. var fontSize = current.fontSize;
  7888. var fontDirection = current.fontDirection;
  7889. var spacingDir = font.vertical ? 1 : -1;
  7890. var charSpacing = current.charSpacing;
  7891. var wordSpacing = current.wordSpacing;
  7892. var textHScale = current.textHScale * fontDirection;
  7893. var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
  7894. var glyphsLength = glyphs.length;
  7895. var isTextInvisible = current.textRenderingMode === TextRenderingMode.INVISIBLE;
  7896. var i, glyph, width, spacingLength;
  7897. if (isTextInvisible || fontSize === 0) {
  7898. return;
  7899. }
  7900. this._cachedScaleForStroking[0] = -1;
  7901. this._cachedGetSinglePixelWidth = null;
  7902. ctx.save();
  7903. ctx.transform.apply(ctx, current.textMatrix);
  7904. ctx.translate(current.x, current.y);
  7905. ctx.scale(textHScale, fontDirection);
  7906. for (i = 0; i < glyphsLength; ++i) {
  7907. glyph = glyphs[i];
  7908. if (typeof glyph === "number") {
  7909. spacingLength = spacingDir * glyph * fontSize / 1000;
  7910. this.ctx.translate(spacingLength, 0);
  7911. current.x += spacingLength * textHScale;
  7912. continue;
  7913. }
  7914. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  7915. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  7916. if (!operatorList) {
  7917. warn("Type3 character \"".concat(glyph.operatorListId, "\" is not available."));
  7918. continue;
  7919. }
  7920. if (this.contentVisible) {
  7921. this.processingType3 = glyph;
  7922. this.save();
  7923. ctx.scale(fontSize, fontSize);
  7924. ctx.transform.apply(ctx, fontMatrix);
  7925. this.executeOperatorList(operatorList);
  7926. this.restore();
  7927. }
  7928. var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
  7929. width = transformed[0] * fontSize + spacing;
  7930. ctx.translate(width, 0);
  7931. current.x += width * textHScale;
  7932. }
  7933. ctx.restore();
  7934. this.processingType3 = null;
  7935. };
  7936. CanvasGraphics.prototype.setCharWidth = function (xWidth, yWidth) { };
  7937. CanvasGraphics.prototype.setCharWidthAndBounds = function (xWidth, yWidth, llx, lly, urx, ury) {
  7938. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  7939. this.ctx.clip();
  7940. this.endPath();
  7941. };
  7942. CanvasGraphics.prototype.getColorN_Pattern = function (IR) {
  7943. var _this = this;
  7944. var pattern;
  7945. if (IR[0] === "TilingPattern") {
  7946. var color = IR[1];
  7947. var baseTransform = this.baseTransform || getCurrentTransform(this.ctx);
  7948. var canvasGraphicsFactory = {
  7949. createCanvasGraphics: function (ctx) { return new CanvasGraphics(ctx, _this.commonObjs, _this.objs, _this.canvasFactory, _this.filterFactory, {
  7950. optionalContentConfig: _this.optionalContentConfig,
  7951. markedContentStack: _this.markedContentStack
  7952. }); }
  7953. };
  7954. pattern = new TilingPattern(IR, color, this.ctx, canvasGraphicsFactory, baseTransform);
  7955. }
  7956. else {
  7957. pattern = this._getPattern(IR[1], IR[2]);
  7958. }
  7959. return pattern;
  7960. };
  7961. CanvasGraphics.prototype.setStrokeColorN = function () {
  7962. this.current.strokeColor = this.getColorN_Pattern(arguments);
  7963. };
  7964. CanvasGraphics.prototype.setFillColorN = function () {
  7965. this.current.fillColor = this.getColorN_Pattern(arguments);
  7966. this.current.patternFill = true;
  7967. };
  7968. CanvasGraphics.prototype.setStrokeRGBColor = function (r, g, b) {
  7969. var color = Util.makeHexColor(r, g, b);
  7970. this.ctx.strokeStyle = color;
  7971. this.current.strokeColor = color;
  7972. };
  7973. CanvasGraphics.prototype.setFillRGBColor = function (r, g, b) {
  7974. var color = Util.makeHexColor(r, g, b);
  7975. this.ctx.fillStyle = color;
  7976. this.current.fillColor = color;
  7977. this.current.patternFill = false;
  7978. };
  7979. CanvasGraphics.prototype._getPattern = function (objId, matrix) {
  7980. if (matrix === void 0) { matrix = null; }
  7981. var pattern;
  7982. if (this.cachedPatterns.has(objId)) {
  7983. pattern = this.cachedPatterns.get(objId);
  7984. }
  7985. else {
  7986. pattern = getShadingPattern(this.getObject(objId));
  7987. this.cachedPatterns.set(objId, pattern);
  7988. }
  7989. if (matrix) {
  7990. pattern.matrix = matrix;
  7991. }
  7992. return pattern;
  7993. };
  7994. CanvasGraphics.prototype.shadingFill = function (objId) {
  7995. if (!this.contentVisible) {
  7996. return;
  7997. }
  7998. var ctx = this.ctx;
  7999. this.save();
  8000. var pattern = this._getPattern(objId);
  8001. ctx.fillStyle = pattern.getPattern(ctx, this, getCurrentTransformInverse(ctx), PathType.SHADING);
  8002. var inv = getCurrentTransformInverse(ctx);
  8003. if (inv) {
  8004. var _g = ctx.canvas, width = _g.width, height = _g.height;
  8005. var _h = Util.getAxialAlignedBoundingBox([0, 0, width, height], inv), x0 = _h[0], y0 = _h[1], x1 = _h[2], y1 = _h[3];
  8006. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  8007. }
  8008. else {
  8009. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  8010. }
  8011. this.compose(this.current.getClippedPathBoundingBox());
  8012. this.restore();
  8013. };
  8014. CanvasGraphics.prototype.beginInlineImage = function () {
  8015. unreachable("Should not call beginInlineImage");
  8016. };
  8017. CanvasGraphics.prototype.beginImageData = function () {
  8018. unreachable("Should not call beginImageData");
  8019. };
  8020. CanvasGraphics.prototype.paintFormXObjectBegin = function (matrix, bbox) {
  8021. if (!this.contentVisible) {
  8022. return;
  8023. }
  8024. this.save();
  8025. this.baseTransformStack.push(this.baseTransform);
  8026. if (matrix) {
  8027. this.transform.apply(this, matrix);
  8028. }
  8029. this.baseTransform = getCurrentTransform(this.ctx);
  8030. if (bbox) {
  8031. var width = bbox[2] - bbox[0];
  8032. var height = bbox[3] - bbox[1];
  8033. this.ctx.rect(bbox[0], bbox[1], width, height);
  8034. this.current.updateRectMinMax(getCurrentTransform(this.ctx), bbox);
  8035. this.clip();
  8036. this.endPath();
  8037. }
  8038. };
  8039. CanvasGraphics.prototype.paintFormXObjectEnd = function () {
  8040. if (!this.contentVisible) {
  8041. return;
  8042. }
  8043. this.restore();
  8044. this.baseTransform = this.baseTransformStack.pop();
  8045. };
  8046. CanvasGraphics.prototype.beginGroup = function (group) {
  8047. if (!this.contentVisible) {
  8048. return;
  8049. }
  8050. this.save();
  8051. if (this.inSMaskMode) {
  8052. this.endSMaskMode();
  8053. this.current.activeSMask = null;
  8054. }
  8055. var currentCtx = this.ctx;
  8056. if (!group.isolated) {
  8057. info("TODO: Support non-isolated groups.");
  8058. }
  8059. if (group.knockout) {
  8060. warn("Knockout groups not supported.");
  8061. }
  8062. var currentTransform = getCurrentTransform(currentCtx);
  8063. if (group.matrix) {
  8064. currentCtx.transform.apply(currentCtx, group.matrix);
  8065. }
  8066. if (!group.bbox) {
  8067. throw new Error("Bounding box is required.");
  8068. }
  8069. var bounds = Util.getAxialAlignedBoundingBox(group.bbox, getCurrentTransform(currentCtx));
  8070. var canvasBounds = [0, 0, currentCtx.canvas.width, currentCtx.canvas.height];
  8071. bounds = Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  8072. var offsetX = Math.floor(bounds[0]);
  8073. var offsetY = Math.floor(bounds[1]);
  8074. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  8075. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  8076. this.current.startNewPathAndClipBox([0, 0, drawnWidth, drawnHeight]);
  8077. var cacheId = "groupAt" + this.groupLevel;
  8078. if (group.smask) {
  8079. cacheId += "_smask_" + this.smaskCounter++ % 2;
  8080. }
  8081. var scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight);
  8082. var groupCtx = scratchCanvas.context;
  8083. groupCtx.translate(-offsetX, -offsetY);
  8084. groupCtx.transform.apply(groupCtx, currentTransform);
  8085. if (group.smask) {
  8086. this.smaskStack.push({
  8087. canvas: scratchCanvas.canvas,
  8088. context: groupCtx,
  8089. offsetX: offsetX,
  8090. offsetY: offsetY,
  8091. subtype: group.smask.subtype,
  8092. backdrop: group.smask.backdrop,
  8093. transferMap: group.smask.transferMap || null,
  8094. startTransformInverse: null
  8095. });
  8096. }
  8097. else {
  8098. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  8099. currentCtx.translate(offsetX, offsetY);
  8100. currentCtx.save();
  8101. }
  8102. copyCtxState(currentCtx, groupCtx);
  8103. this.ctx = groupCtx;
  8104. this.setGState([["BM", "source-over"], ["ca", 1], ["CA", 1]]);
  8105. this.groupStack.push(currentCtx);
  8106. this.groupLevel++;
  8107. };
  8108. CanvasGraphics.prototype.endGroup = function (group) {
  8109. var _g;
  8110. if (!this.contentVisible) {
  8111. return;
  8112. }
  8113. this.groupLevel--;
  8114. var groupCtx = this.ctx;
  8115. var ctx = this.groupStack.pop();
  8116. this.ctx = ctx;
  8117. this.ctx.imageSmoothingEnabled = false;
  8118. if (group.smask) {
  8119. this.tempSMask = this.smaskStack.pop();
  8120. this.restore();
  8121. }
  8122. else {
  8123. this.ctx.restore();
  8124. var currentMtx = getCurrentTransform(this.ctx);
  8125. this.restore();
  8126. this.ctx.save();
  8127. (_g = this.ctx).setTransform.apply(_g, currentMtx);
  8128. var dirtyBox = Util.getAxialAlignedBoundingBox([0, 0, groupCtx.canvas.width, groupCtx.canvas.height], currentMtx);
  8129. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  8130. this.ctx.restore();
  8131. this.compose(dirtyBox);
  8132. }
  8133. };
  8134. CanvasGraphics.prototype.beginAnnotation = function (id, rect, transform, matrix, hasOwnCanvas) {
  8135. var _g;
  8136. tslib_1.__classPrivateFieldGet(this, _CanvasGraphics_instances, "m", _CanvasGraphics_restoreInitialState).call(this);
  8137. resetCtxToDefault(this.ctx);
  8138. this.ctx.save();
  8139. this.save();
  8140. if (this.baseTransform) {
  8141. (_g = this.ctx).setTransform.apply(_g, this.baseTransform);
  8142. }
  8143. if (rect) {
  8144. var width = rect[2] - rect[0];
  8145. var height = rect[3] - rect[1];
  8146. if (hasOwnCanvas && this.annotationCanvasMap) {
  8147. transform = transform.slice();
  8148. transform[4] -= rect[0];
  8149. transform[5] -= rect[1];
  8150. rect = rect.slice();
  8151. rect[0] = rect[1] = 0;
  8152. rect[2] = width;
  8153. rect[3] = height;
  8154. var _h = Util.singularValueDecompose2dScale(getCurrentTransform(this.ctx)), scaleX = _h[0], scaleY = _h[1];
  8155. var viewportScale = this.viewportScale;
  8156. var canvasWidth = Math.ceil(width * this.outputScaleX * viewportScale);
  8157. var canvasHeight = Math.ceil(height * this.outputScaleY * viewportScale);
  8158. this.annotationCanvas = this.canvasFactory.create(canvasWidth, canvasHeight);
  8159. var _j = this.annotationCanvas, canvas = _j.canvas, context = _j.context;
  8160. this.annotationCanvasMap.set(id, canvas);
  8161. this.annotationCanvas.savedCtx = this.ctx;
  8162. this.ctx = context;
  8163. this.ctx.save();
  8164. this.ctx.setTransform(scaleX, 0, 0, -scaleY, 0, height * scaleY);
  8165. resetCtxToDefault(this.ctx);
  8166. }
  8167. else {
  8168. resetCtxToDefault(this.ctx);
  8169. this.ctx.rect(rect[0], rect[1], width, height);
  8170. this.ctx.clip();
  8171. this.endPath();
  8172. }
  8173. }
  8174. this.current = new CanvasExtraState(this.ctx.canvas.width, this.ctx.canvas.height);
  8175. this.transform.apply(this, transform);
  8176. this.transform.apply(this, matrix);
  8177. };
  8178. CanvasGraphics.prototype.endAnnotation = function () {
  8179. if (this.annotationCanvas) {
  8180. this.ctx.restore();
  8181. tslib_1.__classPrivateFieldGet(this, _CanvasGraphics_instances, "m", _CanvasGraphics_drawFilter).call(this);
  8182. this.ctx = this.annotationCanvas.savedCtx;
  8183. delete this.annotationCanvas.savedCtx;
  8184. delete this.annotationCanvas;
  8185. }
  8186. };
  8187. CanvasGraphics.prototype.paintImageMaskXObject = function (img) {
  8188. if (!this.contentVisible) {
  8189. return;
  8190. }
  8191. var count = img.count;
  8192. img = this.getObject(img.data, img);
  8193. img.count = count;
  8194. var ctx = this.ctx;
  8195. var glyph = this.processingType3;
  8196. if (glyph) {
  8197. if (glyph.compiled === undefined) {
  8198. glyph.compiled = compileType3Glyph(img);
  8199. }
  8200. if (glyph.compiled) {
  8201. glyph.compiled(ctx);
  8202. return;
  8203. }
  8204. }
  8205. var mask = this._createMaskCanvas(img);
  8206. var maskCanvas = mask.canvas;
  8207. ctx.save();
  8208. ctx.setTransform(1, 0, 0, 1, 0, 0);
  8209. ctx.drawImage(maskCanvas, mask.offsetX, mask.offsetY);
  8210. ctx.restore();
  8211. this.compose();
  8212. };
  8213. CanvasGraphics.prototype.paintImageMaskXObjectRepeat = function (img, scaleX, skewX, skewY, scaleY, positions) {
  8214. if (skewX === void 0) { skewX = 0; }
  8215. if (skewY === void 0) { skewY = 0; }
  8216. if (!this.contentVisible) {
  8217. return;
  8218. }
  8219. img = this.getObject(img.data, img);
  8220. var ctx = this.ctx;
  8221. ctx.save();
  8222. var currentTransform = getCurrentTransform(ctx);
  8223. ctx.transform(scaleX, skewX, skewY, scaleY, 0, 0);
  8224. var mask = this._createMaskCanvas(img);
  8225. ctx.setTransform(1, 0, 0, 1, mask.offsetX - currentTransform[4], mask.offsetY - currentTransform[5]);
  8226. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  8227. var trans = Util.transform(currentTransform, [scaleX, skewX, skewY, scaleY, positions[i], positions[i + 1]]);
  8228. var _g = Util.applyTransform([0, 0], trans), x = _g[0], y = _g[1];
  8229. ctx.drawImage(mask.canvas, x, y);
  8230. }
  8231. ctx.restore();
  8232. this.compose();
  8233. };
  8234. CanvasGraphics.prototype.paintImageMaskXObjectGroup = function (images) {
  8235. if (!this.contentVisible) {
  8236. return;
  8237. }
  8238. var ctx = this.ctx;
  8239. var fillColor = this.current.fillColor;
  8240. var isPatternFill = this.current.patternFill;
  8241. for (var _i = 0, images_1 = images; _i < images_1.length; _i++) {
  8242. var image = images_1[_i];
  8243. var data = image.data, width = image.width, height = image.height, transform = image.transform;
  8244. var maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
  8245. var maskCtx = maskCanvas.context;
  8246. maskCtx.save();
  8247. var img = this.getObject(data, image);
  8248. putBinaryImageMask(maskCtx, img);
  8249. maskCtx.globalCompositeOperation = "source-in";
  8250. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this, getCurrentTransformInverse(ctx), PathType.FILL) : fillColor;
  8251. maskCtx.fillRect(0, 0, width, height);
  8252. maskCtx.restore();
  8253. ctx.save();
  8254. ctx.transform.apply(ctx, transform);
  8255. ctx.scale(1, -1);
  8256. drawImageAtIntegerCoords(ctx, maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1);
  8257. ctx.restore();
  8258. }
  8259. this.compose();
  8260. };
  8261. CanvasGraphics.prototype.paintImageXObject = function (objId) {
  8262. if (!this.contentVisible) {
  8263. return;
  8264. }
  8265. var imgData = this.getObject(objId);
  8266. if (!imgData) {
  8267. warn("Dependent image isn't ready yet");
  8268. return;
  8269. }
  8270. this.paintInlineImageXObject(imgData);
  8271. };
  8272. CanvasGraphics.prototype.paintImageXObjectRepeat = function (objId, scaleX, scaleY, positions) {
  8273. if (!this.contentVisible) {
  8274. return;
  8275. }
  8276. var imgData = this.getObject(objId);
  8277. if (!imgData) {
  8278. warn("Dependent image isn't ready yet");
  8279. return;
  8280. }
  8281. var width = imgData.width;
  8282. var height = imgData.height;
  8283. var map = [];
  8284. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  8285. map.push({
  8286. transform: [scaleX, 0, 0, scaleY, positions[i], positions[i + 1]],
  8287. x: 0,
  8288. y: 0,
  8289. w: width,
  8290. h: height
  8291. });
  8292. }
  8293. this.paintInlineImageXObjectGroup(imgData, map);
  8294. };
  8295. CanvasGraphics.prototype.applyTransferMapsToCanvas = function (ctx) {
  8296. if (this.current.transferMaps !== "none") {
  8297. ctx.filter = this.current.transferMaps;
  8298. ctx.drawImage(ctx.canvas, 0, 0);
  8299. ctx.filter = "none";
  8300. }
  8301. return ctx.canvas;
  8302. };
  8303. CanvasGraphics.prototype.applyTransferMapsToBitmap = function (imgData) {
  8304. if (this.current.transferMaps === "none") {
  8305. return imgData.bitmap;
  8306. }
  8307. var bitmap = imgData.bitmap, width = imgData.width, height = imgData.height;
  8308. var tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", width, height);
  8309. var tmpCtx = tmpCanvas.context;
  8310. tmpCtx.filter = this.current.transferMaps;
  8311. tmpCtx.drawImage(bitmap, 0, 0);
  8312. tmpCtx.filter = "none";
  8313. return tmpCanvas.canvas;
  8314. };
  8315. CanvasGraphics.prototype.paintInlineImageXObject = function (imgData) {
  8316. if (!this.contentVisible) {
  8317. return;
  8318. }
  8319. var width = imgData.width;
  8320. var height = imgData.height;
  8321. var ctx = this.ctx;
  8322. this.save();
  8323. if (!isNodeJS) {
  8324. var filter = ctx.filter;
  8325. if (filter !== "none" && filter !== "") {
  8326. ctx.filter = "none";
  8327. }
  8328. }
  8329. ctx.scale(1 / width, -1 / height);
  8330. var imgToPaint;
  8331. if (imgData.bitmap) {
  8332. imgToPaint = this.applyTransferMapsToBitmap(imgData);
  8333. }
  8334. else if (typeof HTMLElement === "function" && imgData instanceof HTMLElement || !imgData.data) {
  8335. imgToPaint = imgData;
  8336. }
  8337. else {
  8338. var tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", width, height);
  8339. var tmpCtx = tmpCanvas.context;
  8340. putBinaryImageData(tmpCtx, imgData);
  8341. imgToPaint = this.applyTransferMapsToCanvas(tmpCtx);
  8342. }
  8343. var scaled = this._scaleImage(imgToPaint, getCurrentTransformInverse(ctx));
  8344. ctx.imageSmoothingEnabled = getImageSmoothingEnabled(getCurrentTransform(ctx), imgData.interpolate);
  8345. drawImageAtIntegerCoords(ctx, scaled.img, 0, 0, scaled.paintWidth, scaled.paintHeight, 0, -height, width, height);
  8346. this.compose();
  8347. this.restore();
  8348. };
  8349. CanvasGraphics.prototype.paintInlineImageXObjectGroup = function (imgData, map) {
  8350. if (!this.contentVisible) {
  8351. return;
  8352. }
  8353. var ctx = this.ctx;
  8354. var imgToPaint;
  8355. if (imgData.bitmap) {
  8356. imgToPaint = imgData.bitmap;
  8357. }
  8358. else {
  8359. var w = imgData.width;
  8360. var h = imgData.height;
  8361. var tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", w, h);
  8362. var tmpCtx = tmpCanvas.context;
  8363. putBinaryImageData(tmpCtx, imgData);
  8364. imgToPaint = this.applyTransferMapsToCanvas(tmpCtx);
  8365. }
  8366. for (var _i = 0, map_5 = map; _i < map_5.length; _i++) {
  8367. var entry = map_5[_i];
  8368. ctx.save();
  8369. ctx.transform.apply(ctx, entry.transform);
  8370. ctx.scale(1, -1);
  8371. drawImageAtIntegerCoords(ctx, imgToPaint, entry.x, entry.y, entry.w, entry.h, 0, -1, 1, 1);
  8372. ctx.restore();
  8373. }
  8374. this.compose();
  8375. };
  8376. CanvasGraphics.prototype.paintSolidColorImageMask = function () {
  8377. if (!this.contentVisible) {
  8378. return;
  8379. }
  8380. this.ctx.fillRect(0, 0, 1, 1);
  8381. this.compose();
  8382. };
  8383. CanvasGraphics.prototype.markPoint = function (tag) { };
  8384. CanvasGraphics.prototype.markPointProps = function (tag, properties) { };
  8385. CanvasGraphics.prototype.beginMarkedContent = function (tag) {
  8386. this.markedContentStack.push({
  8387. visible: true
  8388. });
  8389. };
  8390. CanvasGraphics.prototype.beginMarkedContentProps = function (tag, properties) {
  8391. if (tag === "OC") {
  8392. this.markedContentStack.push({
  8393. visible: this.optionalContentConfig.isVisible(properties)
  8394. });
  8395. }
  8396. else {
  8397. this.markedContentStack.push({
  8398. visible: true
  8399. });
  8400. }
  8401. this.contentVisible = this.isContentVisible();
  8402. };
  8403. CanvasGraphics.prototype.endMarkedContent = function () {
  8404. this.markedContentStack.pop();
  8405. this.contentVisible = this.isContentVisible();
  8406. };
  8407. CanvasGraphics.prototype.beginCompat = function () { };
  8408. CanvasGraphics.prototype.endCompat = function () { };
  8409. CanvasGraphics.prototype.consumePath = function (clipBox) {
  8410. var isEmpty = this.current.isEmptyClip();
  8411. if (this.pendingClip) {
  8412. this.current.updateClipFromPath();
  8413. }
  8414. if (!this.pendingClip) {
  8415. this.compose(clipBox);
  8416. }
  8417. var ctx = this.ctx;
  8418. if (this.pendingClip) {
  8419. if (!isEmpty) {
  8420. if (this.pendingClip === EO_CLIP) {
  8421. ctx.clip("evenodd");
  8422. }
  8423. else {
  8424. ctx.clip();
  8425. }
  8426. }
  8427. this.pendingClip = null;
  8428. }
  8429. this.current.startNewPathAndClipBox(this.current.clipBox);
  8430. ctx.beginPath();
  8431. };
  8432. CanvasGraphics.prototype.getSinglePixelWidth = function () {
  8433. if (!this._cachedGetSinglePixelWidth) {
  8434. var m = getCurrentTransform(this.ctx);
  8435. if (m[1] === 0 && m[2] === 0) {
  8436. this._cachedGetSinglePixelWidth = 1 / Math.min(Math.abs(m[0]), Math.abs(m[3]));
  8437. }
  8438. else {
  8439. var absDet = Math.abs(m[0] * m[3] - m[2] * m[1]);
  8440. var normX = Math.hypot(m[0], m[2]);
  8441. var normY = Math.hypot(m[1], m[3]);
  8442. this._cachedGetSinglePixelWidth = Math.max(normX, normY) / absDet;
  8443. }
  8444. }
  8445. return this._cachedGetSinglePixelWidth;
  8446. };
  8447. CanvasGraphics.prototype.getScaleForStroking = function () {
  8448. if (this._cachedScaleForStroking[0] === -1) {
  8449. var lineWidth = this.current.lineWidth;
  8450. var _g = this.ctx.getTransform(), a = _g.a, b = _g.b, c = _g.c, d = _g.d;
  8451. var scaleX = void 0, scaleY = void 0;
  8452. if (b === 0 && c === 0) {
  8453. var normX = Math.abs(a);
  8454. var normY = Math.abs(d);
  8455. if (normX === normY) {
  8456. if (lineWidth === 0) {
  8457. scaleX = scaleY = 1 / normX;
  8458. }
  8459. else {
  8460. var scaledLineWidth = normX * lineWidth;
  8461. scaleX = scaleY = scaledLineWidth < 1 ? 1 / scaledLineWidth : 1;
  8462. }
  8463. }
  8464. else if (lineWidth === 0) {
  8465. scaleX = 1 / normX;
  8466. scaleY = 1 / normY;
  8467. }
  8468. else {
  8469. var scaledXLineWidth = normX * lineWidth;
  8470. var scaledYLineWidth = normY * lineWidth;
  8471. scaleX = scaledXLineWidth < 1 ? 1 / scaledXLineWidth : 1;
  8472. scaleY = scaledYLineWidth < 1 ? 1 / scaledYLineWidth : 1;
  8473. }
  8474. }
  8475. else {
  8476. var absDet = Math.abs(a * d - b * c);
  8477. var normX = Math.hypot(a, b);
  8478. var normY = Math.hypot(c, d);
  8479. if (lineWidth === 0) {
  8480. scaleX = normY / absDet;
  8481. scaleY = normX / absDet;
  8482. }
  8483. else {
  8484. var baseArea = lineWidth * absDet;
  8485. scaleX = normY > baseArea ? normY / baseArea : 1;
  8486. scaleY = normX > baseArea ? normX / baseArea : 1;
  8487. }
  8488. }
  8489. this._cachedScaleForStroking[0] = scaleX;
  8490. this._cachedScaleForStroking[1] = scaleY;
  8491. }
  8492. return this._cachedScaleForStroking;
  8493. };
  8494. CanvasGraphics.prototype.rescaleAndStroke = function (saveRestore) {
  8495. var ctx = this.ctx;
  8496. var lineWidth = this.current.lineWidth;
  8497. var _g = this.getScaleForStroking(), scaleX = _g[0], scaleY = _g[1];
  8498. ctx.lineWidth = lineWidth || 1;
  8499. if (scaleX === 1 && scaleY === 1) {
  8500. ctx.stroke();
  8501. return;
  8502. }
  8503. var dashes = ctx.getLineDash();
  8504. if (saveRestore) {
  8505. ctx.save();
  8506. }
  8507. ctx.scale(scaleX, scaleY);
  8508. if (dashes.length > 0) {
  8509. var scale_1 = Math.max(scaleX, scaleY);
  8510. ctx.setLineDash(dashes.map(function (x) { return x / scale_1; }));
  8511. ctx.lineDashOffset /= scale_1;
  8512. }
  8513. ctx.stroke();
  8514. if (saveRestore) {
  8515. ctx.restore();
  8516. }
  8517. };
  8518. CanvasGraphics.prototype.isContentVisible = function () {
  8519. for (var i = this.markedContentStack.length - 1; i >= 0; i--) {
  8520. if (!this.markedContentStack[i].visible) {
  8521. return false;
  8522. }
  8523. }
  8524. return true;
  8525. };
  8526. return CanvasGraphics;
  8527. }());
  8528. _CanvasGraphics_instances = new WeakSet(), _CanvasGraphics_restoreInitialState = function _CanvasGraphics_restoreInitialState() {
  8529. while (this.stateStack.length || this.inSMaskMode) {
  8530. this.restore();
  8531. }
  8532. this.ctx.restore();
  8533. if (this.transparentCanvas) {
  8534. this.ctx = this.compositeCtx;
  8535. this.ctx.save();
  8536. this.ctx.setTransform(1, 0, 0, 1, 0, 0);
  8537. this.ctx.drawImage(this.transparentCanvas, 0, 0);
  8538. this.ctx.restore();
  8539. this.transparentCanvas = null;
  8540. }
  8541. }, _CanvasGraphics_drawFilter = function _CanvasGraphics_drawFilter() {
  8542. if (this.pageColors) {
  8543. var hcmFilterId = this.filterFactory.addHCMFilter(this.pageColors.foreground, this.pageColors.background);
  8544. if (hcmFilterId !== "none") {
  8545. var savedFilter = this.ctx.filter;
  8546. this.ctx.filter = hcmFilterId;
  8547. this.ctx.drawImage(this.ctx.canvas, 0, 0);
  8548. this.ctx.filter = savedFilter;
  8549. }
  8550. }
  8551. };
  8552. for (var op in OPS) {
  8553. if (CanvasGraphics.prototype[op] !== undefined) {
  8554. CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
  8555. }
  8556. }
  8557. ; // CONCATENATED MODULE: ./src/display/worker_options.js
  8558. var GlobalWorkerOptions = /** @class */ (function () {
  8559. function GlobalWorkerOptions() {
  8560. }
  8561. Object.defineProperty(GlobalWorkerOptions, "workerPort", {
  8562. get: function () {
  8563. return tslib_1.__classPrivateFieldGet(this, _g, "f", _GlobalWorkerOptions_port);
  8564. },
  8565. set: function (val) {
  8566. if (!(typeof Worker !== "undefined" && val instanceof Worker) && val !== null) {
  8567. throw new Error("Invalid `workerPort` type.");
  8568. }
  8569. tslib_1.__classPrivateFieldSet(this, _g, val, "f", _GlobalWorkerOptions_port);
  8570. },
  8571. enumerable: false,
  8572. configurable: true
  8573. });
  8574. Object.defineProperty(GlobalWorkerOptions, "workerSrc", {
  8575. get: function () {
  8576. return tslib_1.__classPrivateFieldGet(this, _g, "f", _GlobalWorkerOptions_src);
  8577. },
  8578. set: function (val) {
  8579. if (typeof val !== "string") {
  8580. throw new Error("Invalid `workerSrc` type.");
  8581. }
  8582. tslib_1.__classPrivateFieldSet(this, _g, val, "f", _GlobalWorkerOptions_src);
  8583. },
  8584. enumerable: false,
  8585. configurable: true
  8586. });
  8587. var _g, _GlobalWorkerOptions_port, _GlobalWorkerOptions_src;
  8588. _g = GlobalWorkerOptions;
  8589. _GlobalWorkerOptions_port = { value: null };
  8590. _GlobalWorkerOptions_src = { value: "" };
  8591. return GlobalWorkerOptions;
  8592. }());
  8593. ; // CONCATENATED MODULE: ./src/shared/message_handler.js
  8594. var CallbackKind = {
  8595. UNKNOWN: 0,
  8596. DATA: 1,
  8597. ERROR: 2
  8598. };
  8599. var StreamKind = {
  8600. UNKNOWN: 0,
  8601. CANCEL: 1,
  8602. CANCEL_COMPLETE: 2,
  8603. CLOSE: 3,
  8604. ENQUEUE: 4,
  8605. ERROR: 5,
  8606. PULL: 6,
  8607. PULL_COMPLETE: 7,
  8608. START_COMPLETE: 8
  8609. };
  8610. function wrapReason(reason) {
  8611. if (!(reason instanceof Error || typeof reason === "object" && reason !== null)) {
  8612. unreachable('wrapReason: Expected "reason" to be a (possibly cloned) Error.');
  8613. }
  8614. switch (reason.name) {
  8615. case "AbortException":
  8616. return new AbortException(reason.message);
  8617. case "MissingPDFException":
  8618. return new MissingPDFException(reason.message);
  8619. case "PasswordException":
  8620. return new PasswordException(reason.message, reason.code);
  8621. case "UnexpectedResponseException":
  8622. return new UnexpectedResponseException(reason.message, reason.status);
  8623. case "UnknownErrorException":
  8624. return new UnknownErrorException(reason.message, reason.details);
  8625. default:
  8626. return new UnknownErrorException(reason.message, reason.toString());
  8627. }
  8628. }
  8629. var MessageHandler = /** @class */ (function () {
  8630. function MessageHandler(sourceName, targetName, comObj) {
  8631. var _this = this;
  8632. _MessageHandler_instances.add(this);
  8633. this.sourceName = sourceName;
  8634. this.targetName = targetName;
  8635. this.comObj = comObj;
  8636. this.callbackId = 1;
  8637. this.streamId = 1;
  8638. this.streamSinks = Object.create(null);
  8639. this.streamControllers = Object.create(null);
  8640. this.callbackCapabilities = Object.create(null);
  8641. this.actionHandler = Object.create(null);
  8642. this._onComObjOnMessage = function (event) {
  8643. var data = event.data;
  8644. if (data.targetName !== _this.sourceName) {
  8645. return;
  8646. }
  8647. if (data.stream) {
  8648. tslib_1.__classPrivateFieldGet(_this, _MessageHandler_instances, "m", _MessageHandler_processStreamMessage).call(_this, data);
  8649. return;
  8650. }
  8651. if (data.callback) {
  8652. var callbackId = data.callbackId;
  8653. var capability = _this.callbackCapabilities[callbackId];
  8654. if (!capability) {
  8655. throw new Error("Cannot resolve callback ".concat(callbackId));
  8656. }
  8657. delete _this.callbackCapabilities[callbackId];
  8658. if (data.callback === CallbackKind.DATA) {
  8659. capability.resolve(data.data);
  8660. }
  8661. else if (data.callback === CallbackKind.ERROR) {
  8662. capability.reject(wrapReason(data.reason));
  8663. }
  8664. else {
  8665. throw new Error("Unexpected callback case");
  8666. }
  8667. return;
  8668. }
  8669. var action = _this.actionHandler[data.action];
  8670. if (!action) {
  8671. throw new Error("Unknown action from worker: ".concat(data.action));
  8672. }
  8673. if (data.callbackId) {
  8674. var cbSourceName_1 = _this.sourceName;
  8675. var cbTargetName_1 = data.sourceName;
  8676. new Promise(function (resolve) {
  8677. resolve(action(data.data));
  8678. }).then(function (result) {
  8679. comObj.postMessage({
  8680. sourceName: cbSourceName_1,
  8681. targetName: cbTargetName_1,
  8682. callback: CallbackKind.DATA,
  8683. callbackId: data.callbackId,
  8684. data: result
  8685. });
  8686. }, function (reason) {
  8687. comObj.postMessage({
  8688. sourceName: cbSourceName_1,
  8689. targetName: cbTargetName_1,
  8690. callback: CallbackKind.ERROR,
  8691. callbackId: data.callbackId,
  8692. reason: wrapReason(reason)
  8693. });
  8694. });
  8695. return;
  8696. }
  8697. if (data.streamId) {
  8698. tslib_1.__classPrivateFieldGet(_this, _MessageHandler_instances, "m", _MessageHandler_createStreamSink).call(_this, data);
  8699. return;
  8700. }
  8701. action(data.data);
  8702. };
  8703. comObj.addEventListener("message", this._onComObjOnMessage);
  8704. }
  8705. MessageHandler.prototype.on = function (actionName, handler) {
  8706. var ah = this.actionHandler;
  8707. if (ah[actionName]) {
  8708. throw new Error("There is already an actionName called \"".concat(actionName, "\""));
  8709. }
  8710. ah[actionName] = handler;
  8711. };
  8712. MessageHandler.prototype.send = function (actionName, data, transfers) {
  8713. this.comObj.postMessage({
  8714. sourceName: this.sourceName,
  8715. targetName: this.targetName,
  8716. action: actionName,
  8717. data: data
  8718. }, transfers);
  8719. };
  8720. MessageHandler.prototype.sendWithPromise = function (actionName, data, transfers) {
  8721. var callbackId = this.callbackId++;
  8722. var capability = Promise.withResolvers();
  8723. this.callbackCapabilities[callbackId] = capability;
  8724. try {
  8725. this.comObj.postMessage({
  8726. sourceName: this.sourceName,
  8727. targetName: this.targetName,
  8728. action: actionName,
  8729. callbackId: callbackId,
  8730. data: data
  8731. }, transfers);
  8732. }
  8733. catch (ex) {
  8734. capability.reject(ex);
  8735. }
  8736. return capability.promise;
  8737. };
  8738. MessageHandler.prototype.sendWithStream = function (actionName, data, queueingStrategy, transfers) {
  8739. var _this = this;
  8740. var streamId = this.streamId++, sourceName = this.sourceName, targetName = this.targetName, comObj = this.comObj;
  8741. return new ReadableStream({
  8742. start: function (controller) {
  8743. var startCapability = Promise.withResolvers();
  8744. _this.streamControllers[streamId] = {
  8745. controller: controller,
  8746. startCall: startCapability,
  8747. pullCall: null,
  8748. cancelCall: null,
  8749. isClosed: false
  8750. };
  8751. comObj.postMessage({
  8752. sourceName: sourceName,
  8753. targetName: targetName,
  8754. action: actionName,
  8755. streamId: streamId,
  8756. data: data,
  8757. desiredSize: controller.desiredSize
  8758. }, transfers);
  8759. return startCapability.promise;
  8760. },
  8761. pull: function (controller) {
  8762. var pullCapability = Promise.withResolvers();
  8763. _this.streamControllers[streamId].pullCall = pullCapability;
  8764. comObj.postMessage({
  8765. sourceName: sourceName,
  8766. targetName: targetName,
  8767. stream: StreamKind.PULL,
  8768. streamId: streamId,
  8769. desiredSize: controller.desiredSize
  8770. });
  8771. return pullCapability.promise;
  8772. },
  8773. cancel: function (reason) {
  8774. assert(reason instanceof Error, "cancel must have a valid reason");
  8775. var cancelCapability = Promise.withResolvers();
  8776. _this.streamControllers[streamId].cancelCall = cancelCapability;
  8777. _this.streamControllers[streamId].isClosed = true;
  8778. comObj.postMessage({
  8779. sourceName: sourceName,
  8780. targetName: targetName,
  8781. stream: StreamKind.CANCEL,
  8782. streamId: streamId,
  8783. reason: wrapReason(reason)
  8784. });
  8785. return cancelCapability.promise;
  8786. }
  8787. }, queueingStrategy);
  8788. };
  8789. MessageHandler.prototype.destroy = function () {
  8790. this.comObj.removeEventListener("message", this._onComObjOnMessage);
  8791. };
  8792. return MessageHandler;
  8793. }());
  8794. _MessageHandler_instances = new WeakSet(), _MessageHandler_createStreamSink = function _MessageHandler_createStreamSink(data) {
  8795. var streamId = data.streamId, sourceName = this.sourceName, targetName = data.sourceName, comObj = this.comObj;
  8796. var self = this, action = this.actionHandler[data.action];
  8797. var streamSink = {
  8798. enqueue: function (chunk, size, transfers) {
  8799. if (size === void 0) { size = 1; }
  8800. if (this.isCancelled) {
  8801. return;
  8802. }
  8803. var lastDesiredSize = this.desiredSize;
  8804. this.desiredSize -= size;
  8805. if (lastDesiredSize > 0 && this.desiredSize <= 0) {
  8806. this.sinkCapability = Promise.withResolvers();
  8807. this.ready = this.sinkCapability.promise;
  8808. }
  8809. comObj.postMessage({
  8810. sourceName: sourceName,
  8811. targetName: targetName,
  8812. stream: StreamKind.ENQUEUE,
  8813. streamId: streamId,
  8814. chunk: chunk
  8815. }, transfers);
  8816. },
  8817. close: function () {
  8818. if (this.isCancelled) {
  8819. return;
  8820. }
  8821. this.isCancelled = true;
  8822. comObj.postMessage({
  8823. sourceName: sourceName,
  8824. targetName: targetName,
  8825. stream: StreamKind.CLOSE,
  8826. streamId: streamId
  8827. });
  8828. delete self.streamSinks[streamId];
  8829. },
  8830. error: function (reason) {
  8831. assert(reason instanceof Error, "error must have a valid reason");
  8832. if (this.isCancelled) {
  8833. return;
  8834. }
  8835. this.isCancelled = true;
  8836. comObj.postMessage({
  8837. sourceName: sourceName,
  8838. targetName: targetName,
  8839. stream: StreamKind.ERROR,
  8840. streamId: streamId,
  8841. reason: wrapReason(reason)
  8842. });
  8843. },
  8844. sinkCapability: Promise.withResolvers(),
  8845. onPull: null,
  8846. onCancel: null,
  8847. isCancelled: false,
  8848. desiredSize: data.desiredSize,
  8849. ready: null
  8850. };
  8851. streamSink.sinkCapability.resolve();
  8852. streamSink.ready = streamSink.sinkCapability.promise;
  8853. this.streamSinks[streamId] = streamSink;
  8854. new Promise(function (resolve) {
  8855. resolve(action(data.data, streamSink));
  8856. }).then(function () {
  8857. comObj.postMessage({
  8858. sourceName: sourceName,
  8859. targetName: targetName,
  8860. stream: StreamKind.START_COMPLETE,
  8861. streamId: streamId,
  8862. success: true
  8863. });
  8864. }, function (reason) {
  8865. comObj.postMessage({
  8866. sourceName: sourceName,
  8867. targetName: targetName,
  8868. stream: StreamKind.START_COMPLETE,
  8869. streamId: streamId,
  8870. reason: wrapReason(reason)
  8871. });
  8872. });
  8873. }, _MessageHandler_processStreamMessage = function _MessageHandler_processStreamMessage(data) {
  8874. var streamId = data.streamId, sourceName = this.sourceName, targetName = data.sourceName, comObj = this.comObj;
  8875. var streamController = this.streamControllers[streamId], streamSink = this.streamSinks[streamId];
  8876. switch (data.stream) {
  8877. case StreamKind.START_COMPLETE:
  8878. if (data.success) {
  8879. streamController.startCall.resolve();
  8880. }
  8881. else {
  8882. streamController.startCall.reject(wrapReason(data.reason));
  8883. }
  8884. break;
  8885. case StreamKind.PULL_COMPLETE:
  8886. if (data.success) {
  8887. streamController.pullCall.resolve();
  8888. }
  8889. else {
  8890. streamController.pullCall.reject(wrapReason(data.reason));
  8891. }
  8892. break;
  8893. case StreamKind.PULL:
  8894. if (!streamSink) {
  8895. comObj.postMessage({
  8896. sourceName: sourceName,
  8897. targetName: targetName,
  8898. stream: StreamKind.PULL_COMPLETE,
  8899. streamId: streamId,
  8900. success: true
  8901. });
  8902. break;
  8903. }
  8904. if (streamSink.desiredSize <= 0 && data.desiredSize > 0) {
  8905. streamSink.sinkCapability.resolve();
  8906. }
  8907. streamSink.desiredSize = data.desiredSize;
  8908. new Promise(function (resolve) {
  8909. var _h;
  8910. resolve((_h = streamSink.onPull) === null || _h === void 0 ? void 0 : _h.call(streamSink));
  8911. }).then(function () {
  8912. comObj.postMessage({
  8913. sourceName: sourceName,
  8914. targetName: targetName,
  8915. stream: StreamKind.PULL_COMPLETE,
  8916. streamId: streamId,
  8917. success: true
  8918. });
  8919. }, function (reason) {
  8920. comObj.postMessage({
  8921. sourceName: sourceName,
  8922. targetName: targetName,
  8923. stream: StreamKind.PULL_COMPLETE,
  8924. streamId: streamId,
  8925. reason: wrapReason(reason)
  8926. });
  8927. });
  8928. break;
  8929. case StreamKind.ENQUEUE:
  8930. assert(streamController, "enqueue should have stream controller");
  8931. if (streamController.isClosed) {
  8932. break;
  8933. }
  8934. streamController.controller.enqueue(data.chunk);
  8935. break;
  8936. case StreamKind.CLOSE:
  8937. assert(streamController, "close should have stream controller");
  8938. if (streamController.isClosed) {
  8939. break;
  8940. }
  8941. streamController.isClosed = true;
  8942. streamController.controller.close();
  8943. tslib_1.__classPrivateFieldGet(this, _MessageHandler_instances, "m", _MessageHandler_deleteStreamController).call(this, streamController, streamId);
  8944. break;
  8945. case StreamKind.ERROR:
  8946. assert(streamController, "error should have stream controller");
  8947. streamController.controller.error(wrapReason(data.reason));
  8948. tslib_1.__classPrivateFieldGet(this, _MessageHandler_instances, "m", _MessageHandler_deleteStreamController).call(this, streamController, streamId);
  8949. break;
  8950. case StreamKind.CANCEL_COMPLETE:
  8951. if (data.success) {
  8952. streamController.cancelCall.resolve();
  8953. }
  8954. else {
  8955. streamController.cancelCall.reject(wrapReason(data.reason));
  8956. }
  8957. tslib_1.__classPrivateFieldGet(this, _MessageHandler_instances, "m", _MessageHandler_deleteStreamController).call(this, streamController, streamId);
  8958. break;
  8959. case StreamKind.CANCEL:
  8960. if (!streamSink) {
  8961. break;
  8962. }
  8963. new Promise(function (resolve) {
  8964. var _h;
  8965. resolve((_h = streamSink.onCancel) === null || _h === void 0 ? void 0 : _h.call(streamSink, wrapReason(data.reason)));
  8966. }).then(function () {
  8967. comObj.postMessage({
  8968. sourceName: sourceName,
  8969. targetName: targetName,
  8970. stream: StreamKind.CANCEL_COMPLETE,
  8971. streamId: streamId,
  8972. success: true
  8973. });
  8974. }, function (reason) {
  8975. comObj.postMessage({
  8976. sourceName: sourceName,
  8977. targetName: targetName,
  8978. stream: StreamKind.CANCEL_COMPLETE,
  8979. streamId: streamId,
  8980. reason: wrapReason(reason)
  8981. });
  8982. });
  8983. streamSink.sinkCapability.reject(wrapReason(data.reason));
  8984. streamSink.isCancelled = true;
  8985. delete this.streamSinks[streamId];
  8986. break;
  8987. default:
  8988. throw new Error("Unexpected stream case");
  8989. }
  8990. }, _MessageHandler_deleteStreamController = function _MessageHandler_deleteStreamController(streamController, streamId) {
  8991. var _h, _j, _k;
  8992. return tslib_1.__awaiter(this, void 0, void 0, function () {
  8993. return tslib_1.__generator(this, function (_l) {
  8994. switch (_l.label) {
  8995. case 0: return [4 /*yield*/, Promise.allSettled([(_h = streamController.startCall) === null || _h === void 0 ? void 0 : _h.promise, (_j = streamController.pullCall) === null || _j === void 0 ? void 0 : _j.promise, (_k = streamController.cancelCall) === null || _k === void 0 ? void 0 : _k.promise])];
  8996. case 1:
  8997. _l.sent();
  8998. delete this.streamControllers[streamId];
  8999. return [2 /*return*/];
  9000. }
  9001. });
  9002. });
  9003. };
  9004. ; // CONCATENATED MODULE: ./src/display/metadata.js
  9005. var Metadata = /** @class */ (function () {
  9006. function Metadata(_h) {
  9007. var parsedData = _h.parsedData, rawData = _h.rawData;
  9008. _Metadata_metadataMap.set(this, void 0);
  9009. _Metadata_data.set(this, void 0);
  9010. tslib_1.__classPrivateFieldSet(this, _Metadata_metadataMap, parsedData, "f");
  9011. tslib_1.__classPrivateFieldSet(this, _Metadata_data, rawData, "f");
  9012. }
  9013. Metadata.prototype.getRaw = function () {
  9014. return tslib_1.__classPrivateFieldGet(this, _Metadata_data, "f");
  9015. };
  9016. Metadata.prototype.get = function (name) {
  9017. var _h;
  9018. return (_h = tslib_1.__classPrivateFieldGet(this, _Metadata_metadataMap, "f").get(name)) !== null && _h !== void 0 ? _h : null;
  9019. };
  9020. Metadata.prototype.getAll = function () {
  9021. return objectFromMap(tslib_1.__classPrivateFieldGet(this, _Metadata_metadataMap, "f"));
  9022. };
  9023. Metadata.prototype.has = function (name) {
  9024. return tslib_1.__classPrivateFieldGet(this, _Metadata_metadataMap, "f").has(name);
  9025. };
  9026. return Metadata;
  9027. }());
  9028. _Metadata_metadataMap = new WeakMap(), _Metadata_data = new WeakMap();
  9029. ; // CONCATENATED MODULE: ./src/display/optional_content_config.js
  9030. var INTERNAL = Symbol("INTERNAL");
  9031. var OptionalContentGroup = /** @class */ (function () {
  9032. function OptionalContentGroup(renderingIntent, _h) {
  9033. var name = _h.name, intent = _h.intent, usage = _h.usage;
  9034. _OptionalContentGroup_isDisplay.set(this, false);
  9035. _OptionalContentGroup_isPrint.set(this, false);
  9036. _OptionalContentGroup_userSet.set(this, false);
  9037. _OptionalContentGroup_visible.set(this, true);
  9038. tslib_1.__classPrivateFieldSet(this, _OptionalContentGroup_isDisplay, !!(renderingIntent & RenderingIntentFlag.DISPLAY), "f");
  9039. tslib_1.__classPrivateFieldSet(this, _OptionalContentGroup_isPrint, !!(renderingIntent & RenderingIntentFlag.PRINT), "f");
  9040. this.name = name;
  9041. this.intent = intent;
  9042. this.usage = usage;
  9043. }
  9044. Object.defineProperty(OptionalContentGroup.prototype, "visible", {
  9045. get: function () {
  9046. if (tslib_1.__classPrivateFieldGet(this, _OptionalContentGroup_userSet, "f")) {
  9047. return tslib_1.__classPrivateFieldGet(this, _OptionalContentGroup_visible, "f");
  9048. }
  9049. if (!tslib_1.__classPrivateFieldGet(this, _OptionalContentGroup_visible, "f")) {
  9050. return false;
  9051. }
  9052. var _h = this.usage, print = _h.print, view = _h.view;
  9053. if (tslib_1.__classPrivateFieldGet(this, _OptionalContentGroup_isDisplay, "f")) {
  9054. return (view === null || view === void 0 ? void 0 : view.viewState) !== "OFF";
  9055. }
  9056. else if (tslib_1.__classPrivateFieldGet(this, _OptionalContentGroup_isPrint, "f")) {
  9057. return (print === null || print === void 0 ? void 0 : print.printState) !== "OFF";
  9058. }
  9059. return true;
  9060. },
  9061. enumerable: false,
  9062. configurable: true
  9063. });
  9064. OptionalContentGroup.prototype._setVisible = function (internal, visible, userSet) {
  9065. if (userSet === void 0) { userSet = false; }
  9066. if (internal !== INTERNAL) {
  9067. unreachable("Internal method `_setVisible` called.");
  9068. }
  9069. tslib_1.__classPrivateFieldSet(this, _OptionalContentGroup_userSet, userSet, "f");
  9070. tslib_1.__classPrivateFieldSet(this, _OptionalContentGroup_visible, visible, "f");
  9071. };
  9072. return OptionalContentGroup;
  9073. }());
  9074. _OptionalContentGroup_isDisplay = new WeakMap(), _OptionalContentGroup_isPrint = new WeakMap(), _OptionalContentGroup_userSet = new WeakMap(), _OptionalContentGroup_visible = new WeakMap();
  9075. var OptionalContentConfig = /** @class */ (function () {
  9076. function OptionalContentConfig(data, renderingIntent) {
  9077. if (renderingIntent === void 0) { renderingIntent = RenderingIntentFlag.DISPLAY; }
  9078. _OptionalContentConfig_instances.add(this);
  9079. _OptionalContentConfig_cachedGetHash.set(this, null);
  9080. _OptionalContentConfig_groups.set(this, new Map());
  9081. _OptionalContentConfig_initialHash.set(this, null);
  9082. _OptionalContentConfig_order.set(this, null);
  9083. this.renderingIntent = renderingIntent;
  9084. this.name = null;
  9085. this.creator = null;
  9086. if (data === null) {
  9087. return;
  9088. }
  9089. this.name = data.name;
  9090. this.creator = data.creator;
  9091. tslib_1.__classPrivateFieldSet(this, _OptionalContentConfig_order, data.order, "f");
  9092. for (var _i = 0, _h = data.groups; _i < _h.length; _i++) {
  9093. var group = _h[_i];
  9094. tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_groups, "f").set(group.id, new OptionalContentGroup(renderingIntent, group));
  9095. }
  9096. if (data.baseState === "OFF") {
  9097. for (var _j = 0, _k = tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_groups, "f").values(); _j < _k.length; _j++) {
  9098. var group = _k[_j];
  9099. group._setVisible(INTERNAL, false);
  9100. }
  9101. }
  9102. for (var _l = 0, _m = data.on; _l < _m.length; _l++) {
  9103. var on = _m[_l];
  9104. tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_groups, "f").get(on)._setVisible(INTERNAL, true);
  9105. }
  9106. for (var _o = 0, _p = data.off; _o < _p.length; _o++) {
  9107. var off = _p[_o];
  9108. tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_groups, "f").get(off)._setVisible(INTERNAL, false);
  9109. }
  9110. tslib_1.__classPrivateFieldSet(this, _OptionalContentConfig_initialHash, this.getHash(), "f");
  9111. }
  9112. OptionalContentConfig.prototype.isVisible = function (group) {
  9113. if (tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_groups, "f").size === 0) {
  9114. return true;
  9115. }
  9116. if (!group) {
  9117. info("Optional content group not defined.");
  9118. return true;
  9119. }
  9120. if (group.type === "OCG") {
  9121. if (!tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_groups, "f").has(group.id)) {
  9122. warn("Optional content group not found: ".concat(group.id));
  9123. return true;
  9124. }
  9125. return tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_groups, "f").get(group.id).visible;
  9126. }
  9127. else if (group.type === "OCMD") {
  9128. if (group.expression) {
  9129. return tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_instances, "m", _OptionalContentConfig_evaluateVisibilityExpression).call(this, group.expression);
  9130. }
  9131. if (!group.policy || group.policy === "AnyOn") {
  9132. for (var _i = 0, _h = group.ids; _i < _h.length; _i++) {
  9133. var id = _h[_i];
  9134. if (!tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_groups, "f").has(id)) {
  9135. warn("Optional content group not found: ".concat(id));
  9136. return true;
  9137. }
  9138. if (tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_groups, "f").get(id).visible) {
  9139. return true;
  9140. }
  9141. }
  9142. return false;
  9143. }
  9144. else if (group.policy === "AllOn") {
  9145. for (var _j = 0, _k = group.ids; _j < _k.length; _j++) {
  9146. var id = _k[_j];
  9147. if (!tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_groups, "f").has(id)) {
  9148. warn("Optional content group not found: ".concat(id));
  9149. return true;
  9150. }
  9151. if (!tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_groups, "f").get(id).visible) {
  9152. return false;
  9153. }
  9154. }
  9155. return true;
  9156. }
  9157. else if (group.policy === "AnyOff") {
  9158. for (var _l = 0, _m = group.ids; _l < _m.length; _l++) {
  9159. var id = _m[_l];
  9160. if (!tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_groups, "f").has(id)) {
  9161. warn("Optional content group not found: ".concat(id));
  9162. return true;
  9163. }
  9164. if (!tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_groups, "f").get(id).visible) {
  9165. return true;
  9166. }
  9167. }
  9168. return false;
  9169. }
  9170. else if (group.policy === "AllOff") {
  9171. for (var _o = 0, _p = group.ids; _o < _p.length; _o++) {
  9172. var id = _p[_o];
  9173. if (!tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_groups, "f").has(id)) {
  9174. warn("Optional content group not found: ".concat(id));
  9175. return true;
  9176. }
  9177. if (tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_groups, "f").get(id).visible) {
  9178. return false;
  9179. }
  9180. }
  9181. return true;
  9182. }
  9183. warn("Unknown optional content policy ".concat(group.policy, "."));
  9184. return true;
  9185. }
  9186. warn("Unknown group type ".concat(group.type, "."));
  9187. return true;
  9188. };
  9189. OptionalContentConfig.prototype.setVisibility = function (id, visible) {
  9190. if (visible === void 0) { visible = true; }
  9191. var group = tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_groups, "f").get(id);
  9192. if (!group) {
  9193. warn("Optional content group not found: ".concat(id));
  9194. return;
  9195. }
  9196. group._setVisible(INTERNAL, !!visible, true);
  9197. tslib_1.__classPrivateFieldSet(this, _OptionalContentConfig_cachedGetHash, null, "f");
  9198. };
  9199. OptionalContentConfig.prototype.setOCGState = function (_h) {
  9200. var state = _h.state, preserveRB = _h.preserveRB;
  9201. var operator;
  9202. for (var _i = 0, state_1 = state; _i < state_1.length; _i++) {
  9203. var elem = state_1[_i];
  9204. switch (elem) {
  9205. case "ON":
  9206. case "OFF":
  9207. case "Toggle":
  9208. operator = elem;
  9209. continue;
  9210. }
  9211. var group = tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_groups, "f").get(elem);
  9212. if (!group) {
  9213. continue;
  9214. }
  9215. switch (operator) {
  9216. case "ON":
  9217. group._setVisible(INTERNAL, true);
  9218. break;
  9219. case "OFF":
  9220. group._setVisible(INTERNAL, false);
  9221. break;
  9222. case "Toggle":
  9223. group._setVisible(INTERNAL, !group.visible);
  9224. break;
  9225. }
  9226. }
  9227. tslib_1.__classPrivateFieldSet(this, _OptionalContentConfig_cachedGetHash, null, "f");
  9228. };
  9229. Object.defineProperty(OptionalContentConfig.prototype, "hasInitialVisibility", {
  9230. get: function () {
  9231. return tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_initialHash, "f") === null || this.getHash() === tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_initialHash, "f");
  9232. },
  9233. enumerable: false,
  9234. configurable: true
  9235. });
  9236. OptionalContentConfig.prototype.getOrder = function () {
  9237. if (!tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_groups, "f").size) {
  9238. return null;
  9239. }
  9240. if (tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_order, "f")) {
  9241. return tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_order, "f").slice();
  9242. }
  9243. return tslib_1.__spreadArray([], tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_groups, "f").keys(), true);
  9244. };
  9245. OptionalContentConfig.prototype.getGroups = function () {
  9246. return tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_groups, "f").size > 0 ? objectFromMap(tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_groups, "f")) : null;
  9247. };
  9248. OptionalContentConfig.prototype.getGroup = function (id) {
  9249. return tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_groups, "f").get(id) || null;
  9250. };
  9251. OptionalContentConfig.prototype.getHash = function () {
  9252. if (tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_cachedGetHash, "f") !== null) {
  9253. return tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_cachedGetHash, "f");
  9254. }
  9255. var hash = new MurmurHash3_64();
  9256. for (var _i = 0, _h = tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_groups, "f"); _i < _h.length; _i++) {
  9257. var _j = _h[_i], id = _j[0], group = _j[1];
  9258. hash.update("".concat(id, ":").concat(group.visible));
  9259. }
  9260. return tslib_1.__classPrivateFieldSet(this, _OptionalContentConfig_cachedGetHash, hash.hexdigest(), "f");
  9261. };
  9262. return OptionalContentConfig;
  9263. }());
  9264. _OptionalContentConfig_cachedGetHash = new WeakMap(), _OptionalContentConfig_groups = new WeakMap(), _OptionalContentConfig_initialHash = new WeakMap(), _OptionalContentConfig_order = new WeakMap(), _OptionalContentConfig_instances = new WeakSet(), _OptionalContentConfig_evaluateVisibilityExpression = function _OptionalContentConfig_evaluateVisibilityExpression(array) {
  9265. var length = array.length;
  9266. if (length < 2) {
  9267. return true;
  9268. }
  9269. var operator = array[0];
  9270. for (var i = 1; i < length; i++) {
  9271. var element = array[i];
  9272. var state = void 0;
  9273. if (Array.isArray(element)) {
  9274. state = tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_instances, "m", _OptionalContentConfig_evaluateVisibilityExpression).call(this, element);
  9275. }
  9276. else if (tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_groups, "f").has(element)) {
  9277. state = tslib_1.__classPrivateFieldGet(this, _OptionalContentConfig_groups, "f").get(element).visible;
  9278. }
  9279. else {
  9280. warn("Optional content group not found: ".concat(element));
  9281. return true;
  9282. }
  9283. switch (operator) {
  9284. case "And":
  9285. if (!state) {
  9286. return false;
  9287. }
  9288. break;
  9289. case "Or":
  9290. if (state) {
  9291. return true;
  9292. }
  9293. break;
  9294. case "Not":
  9295. return !state;
  9296. default:
  9297. return true;
  9298. }
  9299. }
  9300. return operator === "And";
  9301. };
  9302. ; // CONCATENATED MODULE: ./src/display/transport_stream.js
  9303. var PDFDataTransportStream = /** @class */ (function () {
  9304. function PDFDataTransportStream(pdfDataRangeTransport, _h) {
  9305. var _j = _h.disableRange, disableRange = _j === void 0 ? false : _j, _k = _h.disableStream, disableStream = _k === void 0 ? false : _k;
  9306. var _this = this;
  9307. assert(pdfDataRangeTransport, 'PDFDataTransportStream - missing required "pdfDataRangeTransport" argument.');
  9308. var length = pdfDataRangeTransport.length, initialData = pdfDataRangeTransport.initialData, progressiveDone = pdfDataRangeTransport.progressiveDone, contentDispositionFilename = pdfDataRangeTransport.contentDispositionFilename;
  9309. this._queuedChunks = [];
  9310. this._progressiveDone = progressiveDone;
  9311. this._contentDispositionFilename = contentDispositionFilename;
  9312. if ((initialData === null || initialData === void 0 ? void 0 : initialData.length) > 0) {
  9313. var buffer = initialData instanceof Uint8Array && initialData.byteLength === initialData.buffer.byteLength ? initialData.buffer : new Uint8Array(initialData).buffer;
  9314. this._queuedChunks.push(buffer);
  9315. }
  9316. this._pdfDataRangeTransport = pdfDataRangeTransport;
  9317. this._isStreamingSupported = !disableStream;
  9318. this._isRangeSupported = !disableRange;
  9319. this._contentLength = length;
  9320. this._fullRequestReader = null;
  9321. this._rangeReaders = [];
  9322. pdfDataRangeTransport.addRangeListener(function (begin, chunk) {
  9323. _this._onReceiveData({
  9324. begin: begin,
  9325. chunk: chunk
  9326. });
  9327. });
  9328. pdfDataRangeTransport.addProgressListener(function (loaded, total) {
  9329. _this._onProgress({
  9330. loaded: loaded,
  9331. total: total
  9332. });
  9333. });
  9334. pdfDataRangeTransport.addProgressiveReadListener(function (chunk) {
  9335. _this._onReceiveData({
  9336. chunk: chunk
  9337. });
  9338. });
  9339. pdfDataRangeTransport.addProgressiveDoneListener(function () {
  9340. _this._onProgressiveDone();
  9341. });
  9342. pdfDataRangeTransport.transportReady();
  9343. }
  9344. PDFDataTransportStream.prototype._onReceiveData = function (_h) {
  9345. var begin = _h.begin, chunk = _h.chunk;
  9346. var buffer = chunk instanceof Uint8Array && chunk.byteLength === chunk.buffer.byteLength ? chunk.buffer : new Uint8Array(chunk).buffer;
  9347. if (begin === undefined) {
  9348. if (this._fullRequestReader) {
  9349. this._fullRequestReader._enqueue(buffer);
  9350. }
  9351. else {
  9352. this._queuedChunks.push(buffer);
  9353. }
  9354. }
  9355. else {
  9356. var found = this._rangeReaders.some(function (rangeReader) {
  9357. if (rangeReader._begin !== begin) {
  9358. return false;
  9359. }
  9360. rangeReader._enqueue(buffer);
  9361. return true;
  9362. });
  9363. assert(found, "_onReceiveData - no `PDFDataTransportStreamRangeReader` instance found.");
  9364. }
  9365. };
  9366. Object.defineProperty(PDFDataTransportStream.prototype, "_progressiveDataLength", {
  9367. get: function () {
  9368. var _h, _j;
  9369. return (_j = (_h = this._fullRequestReader) === null || _h === void 0 ? void 0 : _h._loaded) !== null && _j !== void 0 ? _j : 0;
  9370. },
  9371. enumerable: false,
  9372. configurable: true
  9373. });
  9374. PDFDataTransportStream.prototype._onProgress = function (evt) {
  9375. var _h, _j, _k, _l;
  9376. if (evt.total === undefined) {
  9377. (_j = (_h = this._rangeReaders[0]) === null || _h === void 0 ? void 0 : _h.onProgress) === null || _j === void 0 ? void 0 : _j.call(_h, {
  9378. loaded: evt.loaded
  9379. });
  9380. }
  9381. else {
  9382. (_l = (_k = this._fullRequestReader) === null || _k === void 0 ? void 0 : _k.onProgress) === null || _l === void 0 ? void 0 : _l.call(_k, {
  9383. loaded: evt.loaded,
  9384. total: evt.total
  9385. });
  9386. }
  9387. };
  9388. PDFDataTransportStream.prototype._onProgressiveDone = function () {
  9389. var _h;
  9390. (_h = this._fullRequestReader) === null || _h === void 0 ? void 0 : _h.progressiveDone();
  9391. this._progressiveDone = true;
  9392. };
  9393. PDFDataTransportStream.prototype._removeRangeReader = function (reader) {
  9394. var i = this._rangeReaders.indexOf(reader);
  9395. if (i >= 0) {
  9396. this._rangeReaders.splice(i, 1);
  9397. }
  9398. };
  9399. PDFDataTransportStream.prototype.getFullReader = function () {
  9400. assert(!this._fullRequestReader, "PDFDataTransportStream.getFullReader can only be called once.");
  9401. var queuedChunks = this._queuedChunks;
  9402. this._queuedChunks = null;
  9403. return new PDFDataTransportStreamReader(this, queuedChunks, this._progressiveDone, this._contentDispositionFilename);
  9404. };
  9405. PDFDataTransportStream.prototype.getRangeReader = function (begin, end) {
  9406. if (end <= this._progressiveDataLength) {
  9407. return null;
  9408. }
  9409. var reader = new PDFDataTransportStreamRangeReader(this, begin, end);
  9410. this._pdfDataRangeTransport.requestDataRange(begin, end);
  9411. this._rangeReaders.push(reader);
  9412. return reader;
  9413. };
  9414. PDFDataTransportStream.prototype.cancelAllRequests = function (reason) {
  9415. var _h;
  9416. (_h = this._fullRequestReader) === null || _h === void 0 ? void 0 : _h.cancel(reason);
  9417. for (var _i = 0, _j = this._rangeReaders.slice(0); _i < _j.length; _i++) {
  9418. var reader = _j[_i];
  9419. reader.cancel(reason);
  9420. }
  9421. this._pdfDataRangeTransport.abort();
  9422. };
  9423. return PDFDataTransportStream;
  9424. }());
  9425. var PDFDataTransportStreamReader = /** @class */ (function () {
  9426. function PDFDataTransportStreamReader(stream, queuedChunks, progressiveDone, contentDispositionFilename) {
  9427. if (progressiveDone === void 0) { progressiveDone = false; }
  9428. if (contentDispositionFilename === void 0) { contentDispositionFilename = null; }
  9429. this._stream = stream;
  9430. this._done = progressiveDone || false;
  9431. this._filename = isPdfFile(contentDispositionFilename) ? contentDispositionFilename : null;
  9432. this._queuedChunks = queuedChunks || [];
  9433. this._loaded = 0;
  9434. for (var _i = 0, _h = this._queuedChunks; _i < _h.length; _i++) {
  9435. var chunk = _h[_i];
  9436. this._loaded += chunk.byteLength;
  9437. }
  9438. this._requests = [];
  9439. this._headersReady = Promise.resolve();
  9440. stream._fullRequestReader = this;
  9441. this.onProgress = null;
  9442. }
  9443. PDFDataTransportStreamReader.prototype._enqueue = function (chunk) {
  9444. if (this._done) {
  9445. return;
  9446. }
  9447. if (this._requests.length > 0) {
  9448. var requestCapability = this._requests.shift();
  9449. requestCapability.resolve({
  9450. value: chunk,
  9451. done: false
  9452. });
  9453. }
  9454. else {
  9455. this._queuedChunks.push(chunk);
  9456. }
  9457. this._loaded += chunk.byteLength;
  9458. };
  9459. Object.defineProperty(PDFDataTransportStreamReader.prototype, "headersReady", {
  9460. get: function () {
  9461. return this._headersReady;
  9462. },
  9463. enumerable: false,
  9464. configurable: true
  9465. });
  9466. Object.defineProperty(PDFDataTransportStreamReader.prototype, "filename", {
  9467. get: function () {
  9468. return this._filename;
  9469. },
  9470. enumerable: false,
  9471. configurable: true
  9472. });
  9473. Object.defineProperty(PDFDataTransportStreamReader.prototype, "isRangeSupported", {
  9474. get: function () {
  9475. return this._stream._isRangeSupported;
  9476. },
  9477. enumerable: false,
  9478. configurable: true
  9479. });
  9480. Object.defineProperty(PDFDataTransportStreamReader.prototype, "isStreamingSupported", {
  9481. get: function () {
  9482. return this._stream._isStreamingSupported;
  9483. },
  9484. enumerable: false,
  9485. configurable: true
  9486. });
  9487. Object.defineProperty(PDFDataTransportStreamReader.prototype, "contentLength", {
  9488. get: function () {
  9489. return this._stream._contentLength;
  9490. },
  9491. enumerable: false,
  9492. configurable: true
  9493. });
  9494. PDFDataTransportStreamReader.prototype.read = function () {
  9495. return tslib_1.__awaiter(this, void 0, void 0, function () {
  9496. var chunk, requestCapability;
  9497. return tslib_1.__generator(this, function (_h) {
  9498. if (this._queuedChunks.length > 0) {
  9499. chunk = this._queuedChunks.shift();
  9500. return [2 /*return*/, {
  9501. value: chunk,
  9502. done: false
  9503. }];
  9504. }
  9505. if (this._done) {
  9506. return [2 /*return*/, {
  9507. value: undefined,
  9508. done: true
  9509. }];
  9510. }
  9511. requestCapability = Promise.withResolvers();
  9512. this._requests.push(requestCapability);
  9513. return [2 /*return*/, requestCapability.promise];
  9514. });
  9515. });
  9516. };
  9517. PDFDataTransportStreamReader.prototype.cancel = function (reason) {
  9518. this._done = true;
  9519. for (var _i = 0, _h = this._requests; _i < _h.length; _i++) {
  9520. var requestCapability = _h[_i];
  9521. requestCapability.resolve({
  9522. value: undefined,
  9523. done: true
  9524. });
  9525. }
  9526. this._requests.length = 0;
  9527. };
  9528. PDFDataTransportStreamReader.prototype.progressiveDone = function () {
  9529. if (this._done) {
  9530. return;
  9531. }
  9532. this._done = true;
  9533. };
  9534. return PDFDataTransportStreamReader;
  9535. }());
  9536. var PDFDataTransportStreamRangeReader = /** @class */ (function () {
  9537. function PDFDataTransportStreamRangeReader(stream, begin, end) {
  9538. this._stream = stream;
  9539. this._begin = begin;
  9540. this._end = end;
  9541. this._queuedChunk = null;
  9542. this._requests = [];
  9543. this._done = false;
  9544. this.onProgress = null;
  9545. }
  9546. PDFDataTransportStreamRangeReader.prototype._enqueue = function (chunk) {
  9547. if (this._done) {
  9548. return;
  9549. }
  9550. if (this._requests.length === 0) {
  9551. this._queuedChunk = chunk;
  9552. }
  9553. else {
  9554. var requestsCapability = this._requests.shift();
  9555. requestsCapability.resolve({
  9556. value: chunk,
  9557. done: false
  9558. });
  9559. for (var _i = 0, _h = this._requests; _i < _h.length; _i++) {
  9560. var requestCapability = _h[_i];
  9561. requestCapability.resolve({
  9562. value: undefined,
  9563. done: true
  9564. });
  9565. }
  9566. this._requests.length = 0;
  9567. }
  9568. this._done = true;
  9569. this._stream._removeRangeReader(this);
  9570. };
  9571. Object.defineProperty(PDFDataTransportStreamRangeReader.prototype, "isStreamingSupported", {
  9572. get: function () {
  9573. return false;
  9574. },
  9575. enumerable: false,
  9576. configurable: true
  9577. });
  9578. PDFDataTransportStreamRangeReader.prototype.read = function () {
  9579. return tslib_1.__awaiter(this, void 0, void 0, function () {
  9580. var chunk, requestCapability;
  9581. return tslib_1.__generator(this, function (_h) {
  9582. if (this._queuedChunk) {
  9583. chunk = this._queuedChunk;
  9584. this._queuedChunk = null;
  9585. return [2 /*return*/, {
  9586. value: chunk,
  9587. done: false
  9588. }];
  9589. }
  9590. if (this._done) {
  9591. return [2 /*return*/, {
  9592. value: undefined,
  9593. done: true
  9594. }];
  9595. }
  9596. requestCapability = Promise.withResolvers();
  9597. this._requests.push(requestCapability);
  9598. return [2 /*return*/, requestCapability.promise];
  9599. });
  9600. });
  9601. };
  9602. PDFDataTransportStreamRangeReader.prototype.cancel = function (reason) {
  9603. this._done = true;
  9604. for (var _i = 0, _h = this._requests; _i < _h.length; _i++) {
  9605. var requestCapability = _h[_i];
  9606. requestCapability.resolve({
  9607. value: undefined,
  9608. done: true
  9609. });
  9610. }
  9611. this._requests.length = 0;
  9612. this._stream._removeRangeReader(this);
  9613. };
  9614. return PDFDataTransportStreamRangeReader;
  9615. }());
  9616. ; // CONCATENATED MODULE: ./src/display/content_disposition.js
  9617. function getFilenameFromContentDispositionHeader(contentDisposition) {
  9618. var needsEncodingFixup = true;
  9619. var tmp = toParamRegExp("filename\\*", "i").exec(contentDisposition);
  9620. if (tmp) {
  9621. tmp = tmp[1];
  9622. var filename = rfc2616unquote(tmp);
  9623. filename = unescape(filename);
  9624. filename = rfc5987decode(filename);
  9625. filename = rfc2047decode(filename);
  9626. return fixupEncoding(filename);
  9627. }
  9628. tmp = rfc2231getparam(contentDisposition);
  9629. if (tmp) {
  9630. var filename = rfc2047decode(tmp);
  9631. return fixupEncoding(filename);
  9632. }
  9633. tmp = toParamRegExp("filename", "i").exec(contentDisposition);
  9634. if (tmp) {
  9635. tmp = tmp[1];
  9636. var filename = rfc2616unquote(tmp);
  9637. filename = rfc2047decode(filename);
  9638. return fixupEncoding(filename);
  9639. }
  9640. function toParamRegExp(attributePattern, flags) {
  9641. return new RegExp("(?:^|;)\\s*" + attributePattern + "\\s*=\\s*" + "(" + '[^";\\s][^;\\s]*' + "|" + '"(?:[^"\\\\]|\\\\"?)+"?' + ")", flags);
  9642. }
  9643. function textdecode(encoding, value) {
  9644. if (encoding) {
  9645. if (!/^[\x00-\xFF]+$/.test(value)) {
  9646. return value;
  9647. }
  9648. try {
  9649. var decoder = new TextDecoder(encoding, {
  9650. fatal: true
  9651. });
  9652. var buffer = stringToBytes(value);
  9653. value = decoder.decode(buffer);
  9654. needsEncodingFixup = false;
  9655. }
  9656. catch (_h) { }
  9657. }
  9658. return value;
  9659. }
  9660. function fixupEncoding(value) {
  9661. if (needsEncodingFixup && /[\x80-\xff]/.test(value)) {
  9662. value = textdecode("utf-8", value);
  9663. if (needsEncodingFixup) {
  9664. value = textdecode("iso-8859-1", value);
  9665. }
  9666. }
  9667. return value;
  9668. }
  9669. function rfc2231getparam(contentDispositionStr) {
  9670. var matches = [];
  9671. var match;
  9672. var iter = toParamRegExp("filename\\*((?!0\\d)\\d+)(\\*?)", "ig");
  9673. while ((match = iter.exec(contentDispositionStr)) !== null) {
  9674. var n = match[1], quot = match[2], part = match[3];
  9675. n = parseInt(n, 10);
  9676. if (n in matches) {
  9677. if (n === 0) {
  9678. break;
  9679. }
  9680. continue;
  9681. }
  9682. matches[n] = [quot, part];
  9683. }
  9684. var parts = [];
  9685. for (var n = 0; n < matches.length; ++n) {
  9686. if (!(n in matches)) {
  9687. break;
  9688. }
  9689. var _h = matches[n], quot = _h[0], part = _h[1];
  9690. part = rfc2616unquote(part);
  9691. if (quot) {
  9692. part = unescape(part);
  9693. if (n === 0) {
  9694. part = rfc5987decode(part);
  9695. }
  9696. }
  9697. parts.push(part);
  9698. }
  9699. return parts.join("");
  9700. }
  9701. function rfc2616unquote(value) {
  9702. if (value.startsWith('"')) {
  9703. var parts = value.slice(1).split('\\"');
  9704. for (var i = 0; i < parts.length; ++i) {
  9705. var quotindex = parts[i].indexOf('"');
  9706. if (quotindex !== -1) {
  9707. parts[i] = parts[i].slice(0, quotindex);
  9708. parts.length = i + 1;
  9709. }
  9710. parts[i] = parts[i].replaceAll(/\\(.)/g, "$1");
  9711. }
  9712. value = parts.join('"');
  9713. }
  9714. return value;
  9715. }
  9716. function rfc5987decode(extvalue) {
  9717. var encodingend = extvalue.indexOf("'");
  9718. if (encodingend === -1) {
  9719. return extvalue;
  9720. }
  9721. var encoding = extvalue.slice(0, encodingend);
  9722. var langvalue = extvalue.slice(encodingend + 1);
  9723. var value = langvalue.replace(/^[^']*'/, "");
  9724. return textdecode(encoding, value);
  9725. }
  9726. function rfc2047decode(value) {
  9727. if (!value.startsWith("=?") || /[\x00-\x19\x80-\xff]/.test(value)) {
  9728. return value;
  9729. }
  9730. return value.replaceAll(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g, function (matches, charset, encoding, text) {
  9731. if (encoding === "q" || encoding === "Q") {
  9732. text = text.replaceAll("_", " ");
  9733. text = text.replaceAll(/=([0-9a-fA-F]{2})/g, function (match, hex) {
  9734. return String.fromCharCode(parseInt(hex, 16));
  9735. });
  9736. return textdecode(charset, text);
  9737. }
  9738. try {
  9739. text = atob(text);
  9740. }
  9741. catch (_h) { }
  9742. return textdecode(charset, text);
  9743. });
  9744. }
  9745. return "";
  9746. }
  9747. ; // CONCATENATED MODULE: ./src/display/network_utils.js
  9748. function validateRangeRequestCapabilities(_h) {
  9749. var getResponseHeader = _h.getResponseHeader, isHttp = _h.isHttp, rangeChunkSize = _h.rangeChunkSize, disableRange = _h.disableRange;
  9750. var returnValues = {
  9751. allowRangeRequests: false,
  9752. suggestedLength: undefined
  9753. };
  9754. var length = parseInt(getResponseHeader("Content-Length"), 10);
  9755. if (!Number.isInteger(length)) {
  9756. return returnValues;
  9757. }
  9758. returnValues.suggestedLength = length;
  9759. if (length <= 2 * rangeChunkSize) {
  9760. return returnValues;
  9761. }
  9762. if (disableRange || !isHttp) {
  9763. return returnValues;
  9764. }
  9765. if (getResponseHeader("Accept-Ranges") !== "bytes") {
  9766. return returnValues;
  9767. }
  9768. var contentEncoding = getResponseHeader("Content-Encoding") || "identity";
  9769. if (contentEncoding !== "identity") {
  9770. return returnValues;
  9771. }
  9772. returnValues.allowRangeRequests = true;
  9773. return returnValues;
  9774. }
  9775. function extractFilenameFromHeader(getResponseHeader) {
  9776. var contentDisposition = getResponseHeader("Content-Disposition");
  9777. if (contentDisposition) {
  9778. var filename = getFilenameFromContentDispositionHeader(contentDisposition);
  9779. if (filename.includes("%")) {
  9780. try {
  9781. filename = decodeURIComponent(filename);
  9782. }
  9783. catch (_h) { }
  9784. }
  9785. if (isPdfFile(filename)) {
  9786. return filename;
  9787. }
  9788. }
  9789. return null;
  9790. }
  9791. function createResponseStatusError(status, url) {
  9792. if (status === 404 || status === 0 && url.startsWith("file:")) {
  9793. return new MissingPDFException('Missing PDF "' + url + '".');
  9794. }
  9795. return new UnexpectedResponseException("Unexpected server response (".concat(status, ") while retrieving PDF \"").concat(url, "\"."), status);
  9796. }
  9797. function validateResponseStatus(status) {
  9798. return status === 200 || status === 206;
  9799. }
  9800. ; // CONCATENATED MODULE: ./src/display/fetch_stream.js
  9801. function createFetchOptions(headers, withCredentials, abortController) {
  9802. return {
  9803. method: "GET",
  9804. headers: headers,
  9805. signal: abortController.signal,
  9806. mode: "cors",
  9807. credentials: withCredentials ? "include" : "same-origin",
  9808. redirect: "follow"
  9809. };
  9810. }
  9811. function createHeaders(httpHeaders) {
  9812. var headers = new Headers();
  9813. for (var property in httpHeaders) {
  9814. var value = httpHeaders[property];
  9815. if (value === undefined) {
  9816. continue;
  9817. }
  9818. headers.append(property, value);
  9819. }
  9820. return headers;
  9821. }
  9822. function getArrayBuffer(val) {
  9823. if (val instanceof Uint8Array) {
  9824. return val.buffer;
  9825. }
  9826. if (val instanceof ArrayBuffer) {
  9827. return val;
  9828. }
  9829. warn("getArrayBuffer - unexpected data format: ".concat(val));
  9830. return new Uint8Array(val).buffer;
  9831. }
  9832. var PDFFetchStream = /** @class */ (function () {
  9833. function PDFFetchStream(source) {
  9834. this.source = source;
  9835. this.isHttp = /^https?:/i.test(source.url);
  9836. this.httpHeaders = this.isHttp && source.httpHeaders || {};
  9837. this._fullRequestReader = null;
  9838. this._rangeRequestReaders = [];
  9839. }
  9840. Object.defineProperty(PDFFetchStream.prototype, "_progressiveDataLength", {
  9841. get: function () {
  9842. var _h, _j;
  9843. return (_j = (_h = this._fullRequestReader) === null || _h === void 0 ? void 0 : _h._loaded) !== null && _j !== void 0 ? _j : 0;
  9844. },
  9845. enumerable: false,
  9846. configurable: true
  9847. });
  9848. PDFFetchStream.prototype.getFullReader = function () {
  9849. assert(!this._fullRequestReader, "PDFFetchStream.getFullReader can only be called once.");
  9850. this._fullRequestReader = new PDFFetchStreamReader(this);
  9851. return this._fullRequestReader;
  9852. };
  9853. PDFFetchStream.prototype.getRangeReader = function (begin, end) {
  9854. if (end <= this._progressiveDataLength) {
  9855. return null;
  9856. }
  9857. var reader = new PDFFetchStreamRangeReader(this, begin, end);
  9858. this._rangeRequestReaders.push(reader);
  9859. return reader;
  9860. };
  9861. PDFFetchStream.prototype.cancelAllRequests = function (reason) {
  9862. var _h;
  9863. (_h = this._fullRequestReader) === null || _h === void 0 ? void 0 : _h.cancel(reason);
  9864. for (var _i = 0, _j = this._rangeRequestReaders.slice(0); _i < _j.length; _i++) {
  9865. var reader = _j[_i];
  9866. reader.cancel(reason);
  9867. }
  9868. };
  9869. return PDFFetchStream;
  9870. }());
  9871. var PDFFetchStreamReader = /** @class */ (function () {
  9872. function PDFFetchStreamReader(stream) {
  9873. var _this = this;
  9874. this._stream = stream;
  9875. this._reader = null;
  9876. this._loaded = 0;
  9877. this._filename = null;
  9878. var source = stream.source;
  9879. this._withCredentials = source.withCredentials || false;
  9880. this._contentLength = source.length;
  9881. this._headersCapability = Promise.withResolvers();
  9882. this._disableRange = source.disableRange || false;
  9883. this._rangeChunkSize = source.rangeChunkSize;
  9884. if (!this._rangeChunkSize && !this._disableRange) {
  9885. this._disableRange = true;
  9886. }
  9887. this._abortController = new AbortController();
  9888. this._isStreamingSupported = !source.disableStream;
  9889. this._isRangeSupported = !source.disableRange;
  9890. this._headers = createHeaders(this._stream.httpHeaders);
  9891. var url = source.url;
  9892. fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(function (response) {
  9893. if (!validateResponseStatus(response.status)) {
  9894. throw createResponseStatusError(response.status, url);
  9895. }
  9896. _this._reader = response.body.getReader();
  9897. _this._headersCapability.resolve();
  9898. var getResponseHeader = function (name) { return response.headers.get(name); };
  9899. var _h = validateRangeRequestCapabilities({
  9900. getResponseHeader: getResponseHeader,
  9901. isHttp: _this._stream.isHttp,
  9902. rangeChunkSize: _this._rangeChunkSize,
  9903. disableRange: _this._disableRange
  9904. }), allowRangeRequests = _h.allowRangeRequests, suggestedLength = _h.suggestedLength;
  9905. _this._isRangeSupported = allowRangeRequests;
  9906. _this._contentLength = suggestedLength || _this._contentLength;
  9907. _this._filename = extractFilenameFromHeader(getResponseHeader);
  9908. if (!_this._isStreamingSupported && _this._isRangeSupported) {
  9909. _this.cancel(new AbortException("Streaming is disabled."));
  9910. }
  9911. }).catch(this._headersCapability.reject);
  9912. this.onProgress = null;
  9913. }
  9914. Object.defineProperty(PDFFetchStreamReader.prototype, "headersReady", {
  9915. get: function () {
  9916. return this._headersCapability.promise;
  9917. },
  9918. enumerable: false,
  9919. configurable: true
  9920. });
  9921. Object.defineProperty(PDFFetchStreamReader.prototype, "filename", {
  9922. get: function () {
  9923. return this._filename;
  9924. },
  9925. enumerable: false,
  9926. configurable: true
  9927. });
  9928. Object.defineProperty(PDFFetchStreamReader.prototype, "contentLength", {
  9929. get: function () {
  9930. return this._contentLength;
  9931. },
  9932. enumerable: false,
  9933. configurable: true
  9934. });
  9935. Object.defineProperty(PDFFetchStreamReader.prototype, "isRangeSupported", {
  9936. get: function () {
  9937. return this._isRangeSupported;
  9938. },
  9939. enumerable: false,
  9940. configurable: true
  9941. });
  9942. Object.defineProperty(PDFFetchStreamReader.prototype, "isStreamingSupported", {
  9943. get: function () {
  9944. return this._isStreamingSupported;
  9945. },
  9946. enumerable: false,
  9947. configurable: true
  9948. });
  9949. PDFFetchStreamReader.prototype.read = function () {
  9950. var _h;
  9951. return tslib_1.__awaiter(this, void 0, void 0, function () {
  9952. var _j, value, done;
  9953. return tslib_1.__generator(this, function (_k) {
  9954. switch (_k.label) {
  9955. case 0: return [4 /*yield*/, this._headersCapability.promise];
  9956. case 1:
  9957. _k.sent();
  9958. return [4 /*yield*/, this._reader.read()];
  9959. case 2:
  9960. _j = _k.sent(), value = _j.value, done = _j.done;
  9961. if (done) {
  9962. return [2 /*return*/, {
  9963. value: value,
  9964. done: done
  9965. }];
  9966. }
  9967. this._loaded += value.byteLength;
  9968. (_h = this.onProgress) === null || _h === void 0 ? void 0 : _h.call(this, {
  9969. loaded: this._loaded,
  9970. total: this._contentLength
  9971. });
  9972. return [2 /*return*/, {
  9973. value: getArrayBuffer(value),
  9974. done: false
  9975. }];
  9976. }
  9977. });
  9978. });
  9979. };
  9980. PDFFetchStreamReader.prototype.cancel = function (reason) {
  9981. var _h;
  9982. (_h = this._reader) === null || _h === void 0 ? void 0 : _h.cancel(reason);
  9983. this._abortController.abort();
  9984. };
  9985. return PDFFetchStreamReader;
  9986. }());
  9987. var PDFFetchStreamRangeReader = /** @class */ (function () {
  9988. function PDFFetchStreamRangeReader(stream, begin, end) {
  9989. var _this = this;
  9990. this._stream = stream;
  9991. this._reader = null;
  9992. this._loaded = 0;
  9993. var source = stream.source;
  9994. this._withCredentials = source.withCredentials || false;
  9995. this._readCapability = Promise.withResolvers();
  9996. this._isStreamingSupported = !source.disableStream;
  9997. this._abortController = new AbortController();
  9998. this._headers = createHeaders(this._stream.httpHeaders);
  9999. this._headers.append("Range", "bytes=".concat(begin, "-").concat(end - 1));
  10000. var url = source.url;
  10001. fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(function (response) {
  10002. if (!validateResponseStatus(response.status)) {
  10003. throw createResponseStatusError(response.status, url);
  10004. }
  10005. _this._readCapability.resolve();
  10006. _this._reader = response.body.getReader();
  10007. }).catch(this._readCapability.reject);
  10008. this.onProgress = null;
  10009. }
  10010. Object.defineProperty(PDFFetchStreamRangeReader.prototype, "isStreamingSupported", {
  10011. get: function () {
  10012. return this._isStreamingSupported;
  10013. },
  10014. enumerable: false,
  10015. configurable: true
  10016. });
  10017. PDFFetchStreamRangeReader.prototype.read = function () {
  10018. var _h;
  10019. return tslib_1.__awaiter(this, void 0, void 0, function () {
  10020. var _j, value, done;
  10021. return tslib_1.__generator(this, function (_k) {
  10022. switch (_k.label) {
  10023. case 0: return [4 /*yield*/, this._readCapability.promise];
  10024. case 1:
  10025. _k.sent();
  10026. return [4 /*yield*/, this._reader.read()];
  10027. case 2:
  10028. _j = _k.sent(), value = _j.value, done = _j.done;
  10029. if (done) {
  10030. return [2 /*return*/, {
  10031. value: value,
  10032. done: done
  10033. }];
  10034. }
  10035. this._loaded += value.byteLength;
  10036. (_h = this.onProgress) === null || _h === void 0 ? void 0 : _h.call(this, {
  10037. loaded: this._loaded
  10038. });
  10039. return [2 /*return*/, {
  10040. value: getArrayBuffer(value),
  10041. done: false
  10042. }];
  10043. }
  10044. });
  10045. });
  10046. };
  10047. PDFFetchStreamRangeReader.prototype.cancel = function (reason) {
  10048. var _h;
  10049. (_h = this._reader) === null || _h === void 0 ? void 0 : _h.cancel(reason);
  10050. this._abortController.abort();
  10051. };
  10052. return PDFFetchStreamRangeReader;
  10053. }());
  10054. ; // CONCATENATED MODULE: ./src/display/network.js
  10055. var OK_RESPONSE = 200;
  10056. var PARTIAL_CONTENT_RESPONSE = 206;
  10057. function network_getArrayBuffer(xhr) {
  10058. var data = xhr.response;
  10059. if (typeof data !== "string") {
  10060. return data;
  10061. }
  10062. return stringToBytes(data).buffer;
  10063. }
  10064. var NetworkManager = /** @class */ (function () {
  10065. function NetworkManager(url, args) {
  10066. if (args === void 0) { args = {}; }
  10067. this.url = url;
  10068. this.isHttp = /^https?:/i.test(url);
  10069. this.httpHeaders = this.isHttp && args.httpHeaders || Object.create(null);
  10070. this.withCredentials = args.withCredentials || false;
  10071. this.currXhrId = 0;
  10072. this.pendingRequests = Object.create(null);
  10073. }
  10074. NetworkManager.prototype.requestRange = function (begin, end, listeners) {
  10075. var args = {
  10076. begin: begin,
  10077. end: end
  10078. };
  10079. for (var prop in listeners) {
  10080. args[prop] = listeners[prop];
  10081. }
  10082. return this.request(args);
  10083. };
  10084. NetworkManager.prototype.requestFull = function (listeners) {
  10085. return this.request(listeners);
  10086. };
  10087. NetworkManager.prototype.request = function (args) {
  10088. var xhr = new XMLHttpRequest();
  10089. var xhrId = this.currXhrId++;
  10090. var pendingRequest = this.pendingRequests[xhrId] = {
  10091. xhr: xhr
  10092. };
  10093. xhr.open("GET", this.url);
  10094. xhr.withCredentials = this.withCredentials;
  10095. for (var property in this.httpHeaders) {
  10096. var value = this.httpHeaders[property];
  10097. if (value === undefined) {
  10098. continue;
  10099. }
  10100. xhr.setRequestHeader(property, value);
  10101. }
  10102. if (this.isHttp && "begin" in args && "end" in args) {
  10103. xhr.setRequestHeader("Range", "bytes=".concat(args.begin, "-").concat(args.end - 1));
  10104. pendingRequest.expectedStatus = PARTIAL_CONTENT_RESPONSE;
  10105. }
  10106. else {
  10107. pendingRequest.expectedStatus = OK_RESPONSE;
  10108. }
  10109. xhr.responseType = "arraybuffer";
  10110. if (args.onError) {
  10111. xhr.onerror = function (evt) {
  10112. args.onError(xhr.status);
  10113. };
  10114. }
  10115. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  10116. xhr.onprogress = this.onProgress.bind(this, xhrId);
  10117. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  10118. pendingRequest.onDone = args.onDone;
  10119. pendingRequest.onError = args.onError;
  10120. pendingRequest.onProgress = args.onProgress;
  10121. xhr.send(null);
  10122. return xhrId;
  10123. };
  10124. NetworkManager.prototype.onProgress = function (xhrId, evt) {
  10125. var _h;
  10126. var pendingRequest = this.pendingRequests[xhrId];
  10127. if (!pendingRequest) {
  10128. return;
  10129. }
  10130. (_h = pendingRequest.onProgress) === null || _h === void 0 ? void 0 : _h.call(pendingRequest, evt);
  10131. };
  10132. NetworkManager.prototype.onStateChange = function (xhrId, evt) {
  10133. var _h, _j, _k;
  10134. var pendingRequest = this.pendingRequests[xhrId];
  10135. if (!pendingRequest) {
  10136. return;
  10137. }
  10138. var xhr = pendingRequest.xhr;
  10139. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  10140. pendingRequest.onHeadersReceived();
  10141. delete pendingRequest.onHeadersReceived;
  10142. }
  10143. if (xhr.readyState !== 4) {
  10144. return;
  10145. }
  10146. if (!(xhrId in this.pendingRequests)) {
  10147. return;
  10148. }
  10149. delete this.pendingRequests[xhrId];
  10150. if (xhr.status === 0 && this.isHttp) {
  10151. (_h = pendingRequest.onError) === null || _h === void 0 ? void 0 : _h.call(pendingRequest, xhr.status);
  10152. return;
  10153. }
  10154. var xhrStatus = xhr.status || OK_RESPONSE;
  10155. var ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  10156. if (!ok_response_on_range_request && xhrStatus !== pendingRequest.expectedStatus) {
  10157. (_j = pendingRequest.onError) === null || _j === void 0 ? void 0 : _j.call(pendingRequest, xhr.status);
  10158. return;
  10159. }
  10160. var chunk = network_getArrayBuffer(xhr);
  10161. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  10162. var rangeHeader = xhr.getResponseHeader("Content-Range");
  10163. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  10164. pendingRequest.onDone({
  10165. begin: parseInt(matches[1], 10),
  10166. chunk: chunk
  10167. });
  10168. }
  10169. else if (chunk) {
  10170. pendingRequest.onDone({
  10171. begin: 0,
  10172. chunk: chunk
  10173. });
  10174. }
  10175. else {
  10176. (_k = pendingRequest.onError) === null || _k === void 0 ? void 0 : _k.call(pendingRequest, xhr.status);
  10177. }
  10178. };
  10179. NetworkManager.prototype.getRequestXhr = function (xhrId) {
  10180. return this.pendingRequests[xhrId].xhr;
  10181. };
  10182. NetworkManager.prototype.isPendingRequest = function (xhrId) {
  10183. return xhrId in this.pendingRequests;
  10184. };
  10185. NetworkManager.prototype.abortRequest = function (xhrId) {
  10186. var xhr = this.pendingRequests[xhrId].xhr;
  10187. delete this.pendingRequests[xhrId];
  10188. xhr.abort();
  10189. };
  10190. return NetworkManager;
  10191. }());
  10192. var PDFNetworkStream = /** @class */ (function () {
  10193. function PDFNetworkStream(source) {
  10194. this._source = source;
  10195. this._manager = new NetworkManager(source.url, {
  10196. httpHeaders: source.httpHeaders,
  10197. withCredentials: source.withCredentials
  10198. });
  10199. this._rangeChunkSize = source.rangeChunkSize;
  10200. this._fullRequestReader = null;
  10201. this._rangeRequestReaders = [];
  10202. }
  10203. PDFNetworkStream.prototype._onRangeRequestReaderClosed = function (reader) {
  10204. var i = this._rangeRequestReaders.indexOf(reader);
  10205. if (i >= 0) {
  10206. this._rangeRequestReaders.splice(i, 1);
  10207. }
  10208. };
  10209. PDFNetworkStream.prototype.getFullReader = function () {
  10210. assert(!this._fullRequestReader, "PDFNetworkStream.getFullReader can only be called once.");
  10211. this._fullRequestReader = new PDFNetworkStreamFullRequestReader(this._manager, this._source);
  10212. return this._fullRequestReader;
  10213. };
  10214. PDFNetworkStream.prototype.getRangeReader = function (begin, end) {
  10215. var reader = new PDFNetworkStreamRangeRequestReader(this._manager, begin, end);
  10216. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  10217. this._rangeRequestReaders.push(reader);
  10218. return reader;
  10219. };
  10220. PDFNetworkStream.prototype.cancelAllRequests = function (reason) {
  10221. var _h;
  10222. (_h = this._fullRequestReader) === null || _h === void 0 ? void 0 : _h.cancel(reason);
  10223. for (var _i = 0, _j = this._rangeRequestReaders.slice(0); _i < _j.length; _i++) {
  10224. var reader = _j[_i];
  10225. reader.cancel(reason);
  10226. }
  10227. };
  10228. return PDFNetworkStream;
  10229. }());
  10230. var PDFNetworkStreamFullRequestReader = /** @class */ (function () {
  10231. function PDFNetworkStreamFullRequestReader(manager, source) {
  10232. this._manager = manager;
  10233. var args = {
  10234. onHeadersReceived: this._onHeadersReceived.bind(this),
  10235. onDone: this._onDone.bind(this),
  10236. onError: this._onError.bind(this),
  10237. onProgress: this._onProgress.bind(this)
  10238. };
  10239. this._url = source.url;
  10240. this._fullRequestId = manager.requestFull(args);
  10241. this._headersReceivedCapability = Promise.withResolvers();
  10242. this._disableRange = source.disableRange || false;
  10243. this._contentLength = source.length;
  10244. this._rangeChunkSize = source.rangeChunkSize;
  10245. if (!this._rangeChunkSize && !this._disableRange) {
  10246. this._disableRange = true;
  10247. }
  10248. this._isStreamingSupported = false;
  10249. this._isRangeSupported = false;
  10250. this._cachedChunks = [];
  10251. this._requests = [];
  10252. this._done = false;
  10253. this._storedError = undefined;
  10254. this._filename = null;
  10255. this.onProgress = null;
  10256. }
  10257. PDFNetworkStreamFullRequestReader.prototype._onHeadersReceived = function () {
  10258. var fullRequestXhrId = this._fullRequestId;
  10259. var fullRequestXhr = this._manager.getRequestXhr(fullRequestXhrId);
  10260. var getResponseHeader = function (name) { return fullRequestXhr.getResponseHeader(name); };
  10261. var _h = validateRangeRequestCapabilities({
  10262. getResponseHeader: getResponseHeader,
  10263. isHttp: this._manager.isHttp,
  10264. rangeChunkSize: this._rangeChunkSize,
  10265. disableRange: this._disableRange
  10266. }), allowRangeRequests = _h.allowRangeRequests, suggestedLength = _h.suggestedLength;
  10267. if (allowRangeRequests) {
  10268. this._isRangeSupported = true;
  10269. }
  10270. this._contentLength = suggestedLength || this._contentLength;
  10271. this._filename = extractFilenameFromHeader(getResponseHeader);
  10272. if (this._isRangeSupported) {
  10273. this._manager.abortRequest(fullRequestXhrId);
  10274. }
  10275. this._headersReceivedCapability.resolve();
  10276. };
  10277. PDFNetworkStreamFullRequestReader.prototype._onDone = function (data) {
  10278. if (data) {
  10279. if (this._requests.length > 0) {
  10280. var requestCapability = this._requests.shift();
  10281. requestCapability.resolve({
  10282. value: data.chunk,
  10283. done: false
  10284. });
  10285. }
  10286. else {
  10287. this._cachedChunks.push(data.chunk);
  10288. }
  10289. }
  10290. this._done = true;
  10291. if (this._cachedChunks.length > 0) {
  10292. return;
  10293. }
  10294. for (var _i = 0, _h = this._requests; _i < _h.length; _i++) {
  10295. var requestCapability = _h[_i];
  10296. requestCapability.resolve({
  10297. value: undefined,
  10298. done: true
  10299. });
  10300. }
  10301. this._requests.length = 0;
  10302. };
  10303. PDFNetworkStreamFullRequestReader.prototype._onError = function (status) {
  10304. this._storedError = createResponseStatusError(status, this._url);
  10305. this._headersReceivedCapability.reject(this._storedError);
  10306. for (var _i = 0, _h = this._requests; _i < _h.length; _i++) {
  10307. var requestCapability = _h[_i];
  10308. requestCapability.reject(this._storedError);
  10309. }
  10310. this._requests.length = 0;
  10311. this._cachedChunks.length = 0;
  10312. };
  10313. PDFNetworkStreamFullRequestReader.prototype._onProgress = function (evt) {
  10314. var _h;
  10315. (_h = this.onProgress) === null || _h === void 0 ? void 0 : _h.call(this, {
  10316. loaded: evt.loaded,
  10317. total: evt.lengthComputable ? evt.total : this._contentLength
  10318. });
  10319. };
  10320. Object.defineProperty(PDFNetworkStreamFullRequestReader.prototype, "filename", {
  10321. get: function () {
  10322. return this._filename;
  10323. },
  10324. enumerable: false,
  10325. configurable: true
  10326. });
  10327. Object.defineProperty(PDFNetworkStreamFullRequestReader.prototype, "isRangeSupported", {
  10328. get: function () {
  10329. return this._isRangeSupported;
  10330. },
  10331. enumerable: false,
  10332. configurable: true
  10333. });
  10334. Object.defineProperty(PDFNetworkStreamFullRequestReader.prototype, "isStreamingSupported", {
  10335. get: function () {
  10336. return this._isStreamingSupported;
  10337. },
  10338. enumerable: false,
  10339. configurable: true
  10340. });
  10341. Object.defineProperty(PDFNetworkStreamFullRequestReader.prototype, "contentLength", {
  10342. get: function () {
  10343. return this._contentLength;
  10344. },
  10345. enumerable: false,
  10346. configurable: true
  10347. });
  10348. Object.defineProperty(PDFNetworkStreamFullRequestReader.prototype, "headersReady", {
  10349. get: function () {
  10350. return this._headersReceivedCapability.promise;
  10351. },
  10352. enumerable: false,
  10353. configurable: true
  10354. });
  10355. PDFNetworkStreamFullRequestReader.prototype.read = function () {
  10356. return tslib_1.__awaiter(this, void 0, void 0, function () {
  10357. var chunk, requestCapability;
  10358. return tslib_1.__generator(this, function (_h) {
  10359. if (this._storedError) {
  10360. throw this._storedError;
  10361. }
  10362. if (this._cachedChunks.length > 0) {
  10363. chunk = this._cachedChunks.shift();
  10364. return [2 /*return*/, {
  10365. value: chunk,
  10366. done: false
  10367. }];
  10368. }
  10369. if (this._done) {
  10370. return [2 /*return*/, {
  10371. value: undefined,
  10372. done: true
  10373. }];
  10374. }
  10375. requestCapability = Promise.withResolvers();
  10376. this._requests.push(requestCapability);
  10377. return [2 /*return*/, requestCapability.promise];
  10378. });
  10379. });
  10380. };
  10381. PDFNetworkStreamFullRequestReader.prototype.cancel = function (reason) {
  10382. this._done = true;
  10383. this._headersReceivedCapability.reject(reason);
  10384. for (var _i = 0, _h = this._requests; _i < _h.length; _i++) {
  10385. var requestCapability = _h[_i];
  10386. requestCapability.resolve({
  10387. value: undefined,
  10388. done: true
  10389. });
  10390. }
  10391. this._requests.length = 0;
  10392. if (this._manager.isPendingRequest(this._fullRequestId)) {
  10393. this._manager.abortRequest(this._fullRequestId);
  10394. }
  10395. this._fullRequestReader = null;
  10396. };
  10397. return PDFNetworkStreamFullRequestReader;
  10398. }());
  10399. var PDFNetworkStreamRangeRequestReader = /** @class */ (function () {
  10400. function PDFNetworkStreamRangeRequestReader(manager, begin, end) {
  10401. this._manager = manager;
  10402. var args = {
  10403. onDone: this._onDone.bind(this),
  10404. onError: this._onError.bind(this),
  10405. onProgress: this._onProgress.bind(this)
  10406. };
  10407. this._url = manager.url;
  10408. this._requestId = manager.requestRange(begin, end, args);
  10409. this._requests = [];
  10410. this._queuedChunk = null;
  10411. this._done = false;
  10412. this._storedError = undefined;
  10413. this.onProgress = null;
  10414. this.onClosed = null;
  10415. }
  10416. PDFNetworkStreamRangeRequestReader.prototype._close = function () {
  10417. var _h;
  10418. (_h = this.onClosed) === null || _h === void 0 ? void 0 : _h.call(this, this);
  10419. };
  10420. PDFNetworkStreamRangeRequestReader.prototype._onDone = function (data) {
  10421. var chunk = data.chunk;
  10422. if (this._requests.length > 0) {
  10423. var requestCapability = this._requests.shift();
  10424. requestCapability.resolve({
  10425. value: chunk,
  10426. done: false
  10427. });
  10428. }
  10429. else {
  10430. this._queuedChunk = chunk;
  10431. }
  10432. this._done = true;
  10433. for (var _i = 0, _h = this._requests; _i < _h.length; _i++) {
  10434. var requestCapability = _h[_i];
  10435. requestCapability.resolve({
  10436. value: undefined,
  10437. done: true
  10438. });
  10439. }
  10440. this._requests.length = 0;
  10441. this._close();
  10442. };
  10443. PDFNetworkStreamRangeRequestReader.prototype._onError = function (status) {
  10444. this._storedError = createResponseStatusError(status, this._url);
  10445. for (var _i = 0, _h = this._requests; _i < _h.length; _i++) {
  10446. var requestCapability = _h[_i];
  10447. requestCapability.reject(this._storedError);
  10448. }
  10449. this._requests.length = 0;
  10450. this._queuedChunk = null;
  10451. };
  10452. PDFNetworkStreamRangeRequestReader.prototype._onProgress = function (evt) {
  10453. var _h;
  10454. if (!this.isStreamingSupported) {
  10455. (_h = this.onProgress) === null || _h === void 0 ? void 0 : _h.call(this, {
  10456. loaded: evt.loaded
  10457. });
  10458. }
  10459. };
  10460. Object.defineProperty(PDFNetworkStreamRangeRequestReader.prototype, "isStreamingSupported", {
  10461. get: function () {
  10462. return false;
  10463. },
  10464. enumerable: false,
  10465. configurable: true
  10466. });
  10467. PDFNetworkStreamRangeRequestReader.prototype.read = function () {
  10468. return tslib_1.__awaiter(this, void 0, void 0, function () {
  10469. var chunk, requestCapability;
  10470. return tslib_1.__generator(this, function (_h) {
  10471. if (this._storedError) {
  10472. throw this._storedError;
  10473. }
  10474. if (this._queuedChunk !== null) {
  10475. chunk = this._queuedChunk;
  10476. this._queuedChunk = null;
  10477. return [2 /*return*/, {
  10478. value: chunk,
  10479. done: false
  10480. }];
  10481. }
  10482. if (this._done) {
  10483. return [2 /*return*/, {
  10484. value: undefined,
  10485. done: true
  10486. }];
  10487. }
  10488. requestCapability = Promise.withResolvers();
  10489. this._requests.push(requestCapability);
  10490. return [2 /*return*/, requestCapability.promise];
  10491. });
  10492. });
  10493. };
  10494. PDFNetworkStreamRangeRequestReader.prototype.cancel = function (reason) {
  10495. this._done = true;
  10496. for (var _i = 0, _h = this._requests; _i < _h.length; _i++) {
  10497. var requestCapability = _h[_i];
  10498. requestCapability.resolve({
  10499. value: undefined,
  10500. done: true
  10501. });
  10502. }
  10503. this._requests.length = 0;
  10504. if (this._manager.isPendingRequest(this._requestId)) {
  10505. this._manager.abortRequest(this._requestId);
  10506. }
  10507. this._close();
  10508. };
  10509. return PDFNetworkStreamRangeRequestReader;
  10510. }());
  10511. ; // CONCATENATED MODULE: ./src/display/node_stream.js
  10512. var fileUriRegex = /^file:\/\/\/[a-zA-Z]:\//;
  10513. function parseUrl(sourceUrl) {
  10514. var url = NodePackages.get("url");
  10515. var parsedUrl = url.parse(sourceUrl);
  10516. if (parsedUrl.protocol === "file:" || parsedUrl.host) {
  10517. return parsedUrl;
  10518. }
  10519. if (/^[a-z]:[/\\]/i.test(sourceUrl)) {
  10520. return url.parse("file:///".concat(sourceUrl));
  10521. }
  10522. if (!parsedUrl.host) {
  10523. parsedUrl.protocol = "file:";
  10524. }
  10525. return parsedUrl;
  10526. }
  10527. var PDFNodeStream = /** @class */ (function () {
  10528. function PDFNodeStream(source) {
  10529. this.source = source;
  10530. this.url = parseUrl(source.url);
  10531. this.isHttp = this.url.protocol === "http:" || this.url.protocol === "https:";
  10532. this.isFsUrl = this.url.protocol === "file:";
  10533. this.httpHeaders = this.isHttp && source.httpHeaders || {};
  10534. this._fullRequestReader = null;
  10535. this._rangeRequestReaders = [];
  10536. }
  10537. Object.defineProperty(PDFNodeStream.prototype, "_progressiveDataLength", {
  10538. get: function () {
  10539. var _h, _j;
  10540. return (_j = (_h = this._fullRequestReader) === null || _h === void 0 ? void 0 : _h._loaded) !== null && _j !== void 0 ? _j : 0;
  10541. },
  10542. enumerable: false,
  10543. configurable: true
  10544. });
  10545. PDFNodeStream.prototype.getFullReader = function () {
  10546. assert(!this._fullRequestReader, "PDFNodeStream.getFullReader can only be called once.");
  10547. this._fullRequestReader = this.isFsUrl ? new PDFNodeStreamFsFullReader(this) : new PDFNodeStreamFullReader(this);
  10548. return this._fullRequestReader;
  10549. };
  10550. PDFNodeStream.prototype.getRangeReader = function (start, end) {
  10551. if (end <= this._progressiveDataLength) {
  10552. return null;
  10553. }
  10554. var rangeReader = this.isFsUrl ? new PDFNodeStreamFsRangeReader(this, start, end) : new PDFNodeStreamRangeReader(this, start, end);
  10555. this._rangeRequestReaders.push(rangeReader);
  10556. return rangeReader;
  10557. };
  10558. PDFNodeStream.prototype.cancelAllRequests = function (reason) {
  10559. var _h;
  10560. (_h = this._fullRequestReader) === null || _h === void 0 ? void 0 : _h.cancel(reason);
  10561. for (var _i = 0, _j = this._rangeRequestReaders.slice(0); _i < _j.length; _i++) {
  10562. var reader = _j[_i];
  10563. reader.cancel(reason);
  10564. }
  10565. };
  10566. return PDFNodeStream;
  10567. }());
  10568. var BaseFullReader = /** @class */ (function () {
  10569. function BaseFullReader(stream) {
  10570. this._url = stream.url;
  10571. this._done = false;
  10572. this._storedError = null;
  10573. this.onProgress = null;
  10574. var source = stream.source;
  10575. this._contentLength = source.length;
  10576. this._loaded = 0;
  10577. this._filename = null;
  10578. this._disableRange = source.disableRange || false;
  10579. this._rangeChunkSize = source.rangeChunkSize;
  10580. if (!this._rangeChunkSize && !this._disableRange) {
  10581. this._disableRange = true;
  10582. }
  10583. this._isStreamingSupported = !source.disableStream;
  10584. this._isRangeSupported = !source.disableRange;
  10585. this._readableStream = null;
  10586. this._readCapability = Promise.withResolvers();
  10587. this._headersCapability = Promise.withResolvers();
  10588. }
  10589. Object.defineProperty(BaseFullReader.prototype, "headersReady", {
  10590. get: function () {
  10591. return this._headersCapability.promise;
  10592. },
  10593. enumerable: false,
  10594. configurable: true
  10595. });
  10596. Object.defineProperty(BaseFullReader.prototype, "filename", {
  10597. get: function () {
  10598. return this._filename;
  10599. },
  10600. enumerable: false,
  10601. configurable: true
  10602. });
  10603. Object.defineProperty(BaseFullReader.prototype, "contentLength", {
  10604. get: function () {
  10605. return this._contentLength;
  10606. },
  10607. enumerable: false,
  10608. configurable: true
  10609. });
  10610. Object.defineProperty(BaseFullReader.prototype, "isRangeSupported", {
  10611. get: function () {
  10612. return this._isRangeSupported;
  10613. },
  10614. enumerable: false,
  10615. configurable: true
  10616. });
  10617. Object.defineProperty(BaseFullReader.prototype, "isStreamingSupported", {
  10618. get: function () {
  10619. return this._isStreamingSupported;
  10620. },
  10621. enumerable: false,
  10622. configurable: true
  10623. });
  10624. BaseFullReader.prototype.read = function () {
  10625. var _h;
  10626. return tslib_1.__awaiter(this, void 0, void 0, function () {
  10627. var chunk, buffer;
  10628. return tslib_1.__generator(this, function (_j) {
  10629. switch (_j.label) {
  10630. case 0: return [4 /*yield*/, this._readCapability.promise];
  10631. case 1:
  10632. _j.sent();
  10633. if (this._done) {
  10634. return [2 /*return*/, {
  10635. value: undefined,
  10636. done: true
  10637. }];
  10638. }
  10639. if (this._storedError) {
  10640. throw this._storedError;
  10641. }
  10642. chunk = this._readableStream.read();
  10643. if (chunk === null) {
  10644. this._readCapability = Promise.withResolvers();
  10645. return [2 /*return*/, this.read()];
  10646. }
  10647. this._loaded += chunk.length;
  10648. (_h = this.onProgress) === null || _h === void 0 ? void 0 : _h.call(this, {
  10649. loaded: this._loaded,
  10650. total: this._contentLength
  10651. });
  10652. buffer = new Uint8Array(chunk).buffer;
  10653. return [2 /*return*/, {
  10654. value: buffer,
  10655. done: false
  10656. }];
  10657. }
  10658. });
  10659. });
  10660. };
  10661. BaseFullReader.prototype.cancel = function (reason) {
  10662. if (!this._readableStream) {
  10663. this._error(reason);
  10664. return;
  10665. }
  10666. this._readableStream.destroy(reason);
  10667. };
  10668. BaseFullReader.prototype._error = function (reason) {
  10669. this._storedError = reason;
  10670. this._readCapability.resolve();
  10671. };
  10672. BaseFullReader.prototype._setReadableStream = function (readableStream) {
  10673. var _this = this;
  10674. this._readableStream = readableStream;
  10675. readableStream.on("readable", function () {
  10676. _this._readCapability.resolve();
  10677. });
  10678. readableStream.on("end", function () {
  10679. readableStream.destroy();
  10680. _this._done = true;
  10681. _this._readCapability.resolve();
  10682. });
  10683. readableStream.on("error", function (reason) {
  10684. _this._error(reason);
  10685. });
  10686. if (!this._isStreamingSupported && this._isRangeSupported) {
  10687. this._error(new AbortException("streaming is disabled"));
  10688. }
  10689. if (this._storedError) {
  10690. this._readableStream.destroy(this._storedError);
  10691. }
  10692. };
  10693. return BaseFullReader;
  10694. }());
  10695. var BaseRangeReader = /** @class */ (function () {
  10696. function BaseRangeReader(stream) {
  10697. this._url = stream.url;
  10698. this._done = false;
  10699. this._storedError = null;
  10700. this.onProgress = null;
  10701. this._loaded = 0;
  10702. this._readableStream = null;
  10703. this._readCapability = Promise.withResolvers();
  10704. var source = stream.source;
  10705. this._isStreamingSupported = !source.disableStream;
  10706. }
  10707. Object.defineProperty(BaseRangeReader.prototype, "isStreamingSupported", {
  10708. get: function () {
  10709. return this._isStreamingSupported;
  10710. },
  10711. enumerable: false,
  10712. configurable: true
  10713. });
  10714. BaseRangeReader.prototype.read = function () {
  10715. var _h;
  10716. return tslib_1.__awaiter(this, void 0, void 0, function () {
  10717. var chunk, buffer;
  10718. return tslib_1.__generator(this, function (_j) {
  10719. switch (_j.label) {
  10720. case 0: return [4 /*yield*/, this._readCapability.promise];
  10721. case 1:
  10722. _j.sent();
  10723. if (this._done) {
  10724. return [2 /*return*/, {
  10725. value: undefined,
  10726. done: true
  10727. }];
  10728. }
  10729. if (this._storedError) {
  10730. throw this._storedError;
  10731. }
  10732. chunk = this._readableStream.read();
  10733. if (chunk === null) {
  10734. this._readCapability = Promise.withResolvers();
  10735. return [2 /*return*/, this.read()];
  10736. }
  10737. this._loaded += chunk.length;
  10738. (_h = this.onProgress) === null || _h === void 0 ? void 0 : _h.call(this, {
  10739. loaded: this._loaded
  10740. });
  10741. buffer = new Uint8Array(chunk).buffer;
  10742. return [2 /*return*/, {
  10743. value: buffer,
  10744. done: false
  10745. }];
  10746. }
  10747. });
  10748. });
  10749. };
  10750. BaseRangeReader.prototype.cancel = function (reason) {
  10751. if (!this._readableStream) {
  10752. this._error(reason);
  10753. return;
  10754. }
  10755. this._readableStream.destroy(reason);
  10756. };
  10757. BaseRangeReader.prototype._error = function (reason) {
  10758. this._storedError = reason;
  10759. this._readCapability.resolve();
  10760. };
  10761. BaseRangeReader.prototype._setReadableStream = function (readableStream) {
  10762. var _this = this;
  10763. this._readableStream = readableStream;
  10764. readableStream.on("readable", function () {
  10765. _this._readCapability.resolve();
  10766. });
  10767. readableStream.on("end", function () {
  10768. readableStream.destroy();
  10769. _this._done = true;
  10770. _this._readCapability.resolve();
  10771. });
  10772. readableStream.on("error", function (reason) {
  10773. _this._error(reason);
  10774. });
  10775. if (this._storedError) {
  10776. this._readableStream.destroy(this._storedError);
  10777. }
  10778. };
  10779. return BaseRangeReader;
  10780. }());
  10781. function createRequestOptions(parsedUrl, headers) {
  10782. return {
  10783. protocol: parsedUrl.protocol,
  10784. auth: parsedUrl.auth,
  10785. host: parsedUrl.hostname,
  10786. port: parsedUrl.port,
  10787. path: parsedUrl.path,
  10788. method: "GET",
  10789. headers: headers
  10790. };
  10791. }
  10792. var PDFNodeStreamFullReader = /** @class */ (function (_super) {
  10793. tslib_1.__extends(PDFNodeStreamFullReader, _super);
  10794. function PDFNodeStreamFullReader(stream) {
  10795. var _this = _super.call(this, stream) || this;
  10796. var handleResponse = function (response) {
  10797. if (response.statusCode === 404) {
  10798. var error = new MissingPDFException("Missing PDF \"".concat(_this._url, "\"."));
  10799. _this._storedError = error;
  10800. _this._headersCapability.reject(error);
  10801. return;
  10802. }
  10803. _this._headersCapability.resolve();
  10804. _this._setReadableStream(response);
  10805. var getResponseHeader = function (name) { return _this._readableStream.headers[name.toLowerCase()]; };
  10806. var _h = validateRangeRequestCapabilities({
  10807. getResponseHeader: getResponseHeader,
  10808. isHttp: stream.isHttp,
  10809. rangeChunkSize: _this._rangeChunkSize,
  10810. disableRange: _this._disableRange
  10811. }), allowRangeRequests = _h.allowRangeRequests, suggestedLength = _h.suggestedLength;
  10812. _this._isRangeSupported = allowRangeRequests;
  10813. _this._contentLength = suggestedLength || _this._contentLength;
  10814. _this._filename = extractFilenameFromHeader(getResponseHeader);
  10815. };
  10816. _this._request = null;
  10817. if (_this._url.protocol === "http:") {
  10818. var http = NodePackages.get("http");
  10819. _this._request = http.request(createRequestOptions(_this._url, stream.httpHeaders), handleResponse);
  10820. }
  10821. else {
  10822. var https = NodePackages.get("https");
  10823. _this._request = https.request(createRequestOptions(_this._url, stream.httpHeaders), handleResponse);
  10824. }
  10825. _this._request.on("error", function (reason) {
  10826. _this._storedError = reason;
  10827. _this._headersCapability.reject(reason);
  10828. });
  10829. _this._request.end();
  10830. return _this;
  10831. }
  10832. return PDFNodeStreamFullReader;
  10833. }(BaseFullReader));
  10834. var PDFNodeStreamRangeReader = /** @class */ (function (_super) {
  10835. tslib_1.__extends(PDFNodeStreamRangeReader, _super);
  10836. function PDFNodeStreamRangeReader(stream, start, end) {
  10837. var _this = _super.call(this, stream) || this;
  10838. _this._httpHeaders = {};
  10839. for (var property in stream.httpHeaders) {
  10840. var value = stream.httpHeaders[property];
  10841. if (value === undefined) {
  10842. continue;
  10843. }
  10844. _this._httpHeaders[property] = value;
  10845. }
  10846. _this._httpHeaders.Range = "bytes=".concat(start, "-").concat(end - 1);
  10847. var handleResponse = function (response) {
  10848. if (response.statusCode === 404) {
  10849. var error = new MissingPDFException("Missing PDF \"".concat(_this._url, "\"."));
  10850. _this._storedError = error;
  10851. return;
  10852. }
  10853. _this._setReadableStream(response);
  10854. };
  10855. _this._request = null;
  10856. if (_this._url.protocol === "http:") {
  10857. var http = NodePackages.get("http");
  10858. _this._request = http.request(createRequestOptions(_this._url, _this._httpHeaders), handleResponse);
  10859. }
  10860. else {
  10861. var https = NodePackages.get("https");
  10862. _this._request = https.request(createRequestOptions(_this._url, _this._httpHeaders), handleResponse);
  10863. }
  10864. _this._request.on("error", function (reason) {
  10865. _this._storedError = reason;
  10866. });
  10867. _this._request.end();
  10868. return _this;
  10869. }
  10870. return PDFNodeStreamRangeReader;
  10871. }(BaseRangeReader));
  10872. var PDFNodeStreamFsFullReader = /** @class */ (function (_super) {
  10873. tslib_1.__extends(PDFNodeStreamFsFullReader, _super);
  10874. function PDFNodeStreamFsFullReader(stream) {
  10875. var _this = _super.call(this, stream) || this;
  10876. var path = decodeURIComponent(_this._url.path);
  10877. if (fileUriRegex.test(_this._url.href)) {
  10878. path = path.replace(/^\//, "");
  10879. }
  10880. var fs = NodePackages.get("fs");
  10881. fs.promises.lstat(path).then(function (stat) {
  10882. _this._contentLength = stat.size;
  10883. _this._setReadableStream(fs.createReadStream(path));
  10884. _this._headersCapability.resolve();
  10885. }, function (error) {
  10886. if (error.code === "ENOENT") {
  10887. error = new MissingPDFException("Missing PDF \"".concat(path, "\"."));
  10888. }
  10889. _this._storedError = error;
  10890. _this._headersCapability.reject(error);
  10891. });
  10892. return _this;
  10893. }
  10894. return PDFNodeStreamFsFullReader;
  10895. }(BaseFullReader));
  10896. var PDFNodeStreamFsRangeReader = /** @class */ (function (_super) {
  10897. tslib_1.__extends(PDFNodeStreamFsRangeReader, _super);
  10898. function PDFNodeStreamFsRangeReader(stream, start, end) {
  10899. var _this = _super.call(this, stream) || this;
  10900. var path = decodeURIComponent(_this._url.path);
  10901. if (fileUriRegex.test(_this._url.href)) {
  10902. path = path.replace(/^\//, "");
  10903. }
  10904. var fs = NodePackages.get("fs");
  10905. _this._setReadableStream(fs.createReadStream(path, {
  10906. start: start,
  10907. end: end - 1
  10908. }));
  10909. return _this;
  10910. }
  10911. return PDFNodeStreamFsRangeReader;
  10912. }(BaseRangeReader));
  10913. ; // CONCATENATED MODULE: ./src/display/text_layer.js
  10914. var MAX_TEXT_DIVS_TO_RENDER = 100000;
  10915. var DEFAULT_FONT_SIZE = 30;
  10916. var DEFAULT_FONT_ASCENT = 0.8;
  10917. var TextLayer = /** @class */ (function () {
  10918. function TextLayer(_j) {
  10919. var textContentSource = _j.textContentSource, container = _j.container, viewport = _j.viewport;
  10920. var _this = this;
  10921. var _k;
  10922. _TextLayer_instances.add(this);
  10923. _TextLayer_capability.set(this, Promise.withResolvers());
  10924. _TextLayer_container.set(this, null);
  10925. _TextLayer_disableProcessItems.set(this, false);
  10926. _TextLayer_fontInspectorEnabled.set(this, !!((_k = globalThis.FontInspector) === null || _k === void 0 ? void 0 : _k.enabled));
  10927. _TextLayer_lang.set(this, null);
  10928. _TextLayer_layoutTextParams.set(this, null);
  10929. _TextLayer_pageHeight.set(this, 0);
  10930. _TextLayer_pageWidth.set(this, 0);
  10931. _TextLayer_reader.set(this, null);
  10932. _TextLayer_rootContainer.set(this, null);
  10933. _TextLayer_rotation.set(this, 0);
  10934. _TextLayer_scale.set(this, 0);
  10935. _TextLayer_styleCache.set(this, Object.create(null));
  10936. _TextLayer_textContentItemsStr.set(this, []);
  10937. _TextLayer_textContentSource.set(this, null);
  10938. _TextLayer_textDivs.set(this, []);
  10939. _TextLayer_textDivProperties.set(this, new WeakMap());
  10940. _TextLayer_transform.set(this, null);
  10941. if (textContentSource instanceof ReadableStream) {
  10942. tslib_1.__classPrivateFieldSet(this, _TextLayer_textContentSource, textContentSource, "f");
  10943. }
  10944. else if (typeof textContentSource === "object") {
  10945. tslib_1.__classPrivateFieldSet(this, _TextLayer_textContentSource, new ReadableStream({
  10946. start: function (controller) {
  10947. controller.enqueue(textContentSource);
  10948. controller.close();
  10949. }
  10950. }), "f");
  10951. }
  10952. else {
  10953. throw new Error('No "textContentSource" parameter specified.');
  10954. }
  10955. tslib_1.__classPrivateFieldSet(this, _TextLayer_container, tslib_1.__classPrivateFieldSet(this, _TextLayer_rootContainer, container, "f"), "f");
  10956. tslib_1.__classPrivateFieldSet(this, _TextLayer_scale, viewport.scale * (globalThis.devicePixelRatio || 1), "f");
  10957. tslib_1.__classPrivateFieldSet(this, _TextLayer_rotation, viewport.rotation, "f");
  10958. tslib_1.__classPrivateFieldSet(this, _TextLayer_layoutTextParams, {
  10959. prevFontSize: null,
  10960. prevFontFamily: null,
  10961. div: null,
  10962. properties: null,
  10963. ctx: null
  10964. }, "f");
  10965. var _l = viewport.rawDims, pageWidth = _l.pageWidth, pageHeight = _l.pageHeight, pageX = _l.pageX, pageY = _l.pageY;
  10966. tslib_1.__classPrivateFieldSet(this, _TextLayer_transform, [1, 0, 0, -1, -pageX, pageY + pageHeight], "f");
  10967. tslib_1.__classPrivateFieldSet(this, _TextLayer_pageWidth, pageWidth, "f");
  10968. tslib_1.__classPrivateFieldSet(this, _TextLayer_pageHeight, pageHeight, "f");
  10969. setLayerDimensions(container, viewport);
  10970. tslib_1.__classPrivateFieldGet(this, _TextLayer_capability, "f").promise.catch(function () { }).then(function () {
  10971. tslib_1.__classPrivateFieldGet(TextLayer, _h, "f", _TextLayer_pendingTextLayers).delete(_this);
  10972. tslib_1.__classPrivateFieldSet(_this, _TextLayer_layoutTextParams, null, "f");
  10973. tslib_1.__classPrivateFieldSet(_this, _TextLayer_styleCache, null, "f");
  10974. });
  10975. }
  10976. TextLayer.prototype.render = function () {
  10977. var _this = this;
  10978. var pump = function () {
  10979. tslib_1.__classPrivateFieldGet(_this, _TextLayer_reader, "f").read().then(function (_j) {
  10980. var _k;
  10981. var value = _j.value, done = _j.done;
  10982. if (done) {
  10983. tslib_1.__classPrivateFieldGet(_this, _TextLayer_capability, "f").resolve();
  10984. return;
  10985. }
  10986. tslib_1.__classPrivateFieldSet(_this, _TextLayer_lang, (_k = tslib_1.__classPrivateFieldGet(_this, _TextLayer_lang, "f")) !== null && _k !== void 0 ? _k : value.lang, "f");
  10987. Object.assign(tslib_1.__classPrivateFieldGet(_this, _TextLayer_styleCache, "f"), value.styles);
  10988. tslib_1.__classPrivateFieldGet(_this, _TextLayer_instances, "m", _TextLayer_processItems).call(_this, value.items);
  10989. pump();
  10990. }, tslib_1.__classPrivateFieldGet(_this, _TextLayer_capability, "f").reject);
  10991. };
  10992. tslib_1.__classPrivateFieldSet(this, _TextLayer_reader, tslib_1.__classPrivateFieldGet(this, _TextLayer_textContentSource, "f").getReader(), "f");
  10993. tslib_1.__classPrivateFieldGet(TextLayer, _h, "f", _TextLayer_pendingTextLayers).add(this);
  10994. pump();
  10995. return tslib_1.__classPrivateFieldGet(this, _TextLayer_capability, "f").promise;
  10996. };
  10997. TextLayer.prototype.update = function (_j) {
  10998. var viewport = _j.viewport, _k = _j.onBefore, onBefore = _k === void 0 ? null : _k;
  10999. var scale = viewport.scale * (globalThis.devicePixelRatio || 1);
  11000. var rotation = viewport.rotation;
  11001. if (rotation !== tslib_1.__classPrivateFieldGet(this, _TextLayer_rotation, "f")) {
  11002. onBefore === null || onBefore === void 0 ? void 0 : onBefore();
  11003. tslib_1.__classPrivateFieldSet(this, _TextLayer_rotation, rotation, "f");
  11004. setLayerDimensions(tslib_1.__classPrivateFieldGet(this, _TextLayer_rootContainer, "f"), {
  11005. rotation: rotation
  11006. });
  11007. }
  11008. if (scale !== tslib_1.__classPrivateFieldGet(this, _TextLayer_scale, "f")) {
  11009. onBefore === null || onBefore === void 0 ? void 0 : onBefore();
  11010. tslib_1.__classPrivateFieldSet(this, _TextLayer_scale, scale, "f");
  11011. var params = {
  11012. prevFontSize: null,
  11013. prevFontFamily: null,
  11014. div: null,
  11015. properties: null,
  11016. ctx: tslib_1.__classPrivateFieldGet(TextLayer, _h, "m", _TextLayer_getCtx).call(TextLayer, tslib_1.__classPrivateFieldGet(this, _TextLayer_lang, "f"))
  11017. };
  11018. for (var _i = 0, _l = tslib_1.__classPrivateFieldGet(this, _TextLayer_textDivs, "f"); _i < _l.length; _i++) {
  11019. var div = _l[_i];
  11020. params.properties = tslib_1.__classPrivateFieldGet(this, _TextLayer_textDivProperties, "f").get(div);
  11021. params.div = div;
  11022. tslib_1.__classPrivateFieldGet(this, _TextLayer_instances, "m", _TextLayer_layout).call(this, params);
  11023. }
  11024. }
  11025. };
  11026. TextLayer.prototype.cancel = function () {
  11027. var _j;
  11028. var abortEx = new AbortException("TextLayer task cancelled.");
  11029. (_j = tslib_1.__classPrivateFieldGet(this, _TextLayer_reader, "f")) === null || _j === void 0 ? void 0 : _j.cancel(abortEx).catch(function () { });
  11030. tslib_1.__classPrivateFieldSet(this, _TextLayer_reader, null, "f");
  11031. tslib_1.__classPrivateFieldGet(this, _TextLayer_capability, "f").reject(abortEx);
  11032. };
  11033. Object.defineProperty(TextLayer.prototype, "textDivs", {
  11034. get: function () {
  11035. return tslib_1.__classPrivateFieldGet(this, _TextLayer_textDivs, "f");
  11036. },
  11037. enumerable: false,
  11038. configurable: true
  11039. });
  11040. Object.defineProperty(TextLayer.prototype, "textContentItemsStr", {
  11041. get: function () {
  11042. return tslib_1.__classPrivateFieldGet(this, _TextLayer_textContentItemsStr, "f");
  11043. },
  11044. enumerable: false,
  11045. configurable: true
  11046. });
  11047. TextLayer.cleanup = function () {
  11048. if (tslib_1.__classPrivateFieldGet(this, _h, "f", _TextLayer_pendingTextLayers).size > 0) {
  11049. return;
  11050. }
  11051. tslib_1.__classPrivateFieldGet(this, _h, "f", _TextLayer_ascentCache).clear();
  11052. for (var _i = 0, _j = tslib_1.__classPrivateFieldGet(this, _h, "f", _TextLayer_canvasContexts).values(); _i < _j.length; _i++) {
  11053. var canvas = _j[_i].canvas;
  11054. canvas.remove();
  11055. }
  11056. tslib_1.__classPrivateFieldGet(this, _h, "f", _TextLayer_canvasContexts).clear();
  11057. };
  11058. var _TextLayer_instances, _h, _TextLayer_capability, _TextLayer_container, _TextLayer_disableProcessItems, _TextLayer_fontInspectorEnabled, _TextLayer_lang, _TextLayer_layoutTextParams, _TextLayer_pageHeight, _TextLayer_pageWidth, _TextLayer_reader, _TextLayer_rootContainer, _TextLayer_rotation, _TextLayer_scale, _TextLayer_styleCache, _TextLayer_textContentItemsStr, _TextLayer_textContentSource, _TextLayer_textDivs, _TextLayer_textDivProperties, _TextLayer_transform, _TextLayer_ascentCache, _TextLayer_canvasContexts, _TextLayer_pendingTextLayers, _TextLayer_processItems, _TextLayer_appendText, _TextLayer_layout, _TextLayer_getCtx, _TextLayer_getAscent;
  11059. _h = TextLayer, _TextLayer_capability = new WeakMap(), _TextLayer_container = new WeakMap(), _TextLayer_disableProcessItems = new WeakMap(), _TextLayer_fontInspectorEnabled = new WeakMap(), _TextLayer_lang = new WeakMap(), _TextLayer_layoutTextParams = new WeakMap(), _TextLayer_pageHeight = new WeakMap(), _TextLayer_pageWidth = new WeakMap(), _TextLayer_reader = new WeakMap(), _TextLayer_rootContainer = new WeakMap(), _TextLayer_rotation = new WeakMap(), _TextLayer_scale = new WeakMap(), _TextLayer_styleCache = new WeakMap(), _TextLayer_textContentItemsStr = new WeakMap(), _TextLayer_textContentSource = new WeakMap(), _TextLayer_textDivs = new WeakMap(), _TextLayer_textDivProperties = new WeakMap(), _TextLayer_transform = new WeakMap(), _TextLayer_instances = new WeakSet(), _TextLayer_processItems = function _TextLayer_processItems(items) {
  11060. var _j;
  11061. if (tslib_1.__classPrivateFieldGet(this, _TextLayer_disableProcessItems, "f")) {
  11062. return;
  11063. }
  11064. (_j = tslib_1.__classPrivateFieldGet(this, _TextLayer_layoutTextParams, "f")).ctx || (_j.ctx = tslib_1.__classPrivateFieldGet(TextLayer, _h, "m", _TextLayer_getCtx).call(TextLayer, tslib_1.__classPrivateFieldGet(this, _TextLayer_lang, "f")));
  11065. var textDivs = tslib_1.__classPrivateFieldGet(this, _TextLayer_textDivs, "f"), textContentItemsStr = tslib_1.__classPrivateFieldGet(this, _TextLayer_textContentItemsStr, "f");
  11066. for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
  11067. var item = items_1[_i];
  11068. if (textDivs.length > MAX_TEXT_DIVS_TO_RENDER) {
  11069. warn("Ignoring additional textDivs for performance reasons.");
  11070. tslib_1.__classPrivateFieldSet(this, _TextLayer_disableProcessItems, true, "f");
  11071. return;
  11072. }
  11073. if (item.str === undefined) {
  11074. if (item.type === "beginMarkedContentProps" || item.type === "beginMarkedContent") {
  11075. var parent = tslib_1.__classPrivateFieldGet(this, _TextLayer_container, "f");
  11076. tslib_1.__classPrivateFieldSet(this, _TextLayer_container, document.createElement("span"), "f");
  11077. tslib_1.__classPrivateFieldGet(this, _TextLayer_container, "f").classList.add("markedContent");
  11078. if (item.id !== null) {
  11079. tslib_1.__classPrivateFieldGet(this, _TextLayer_container, "f").setAttribute("id", "".concat(item.id));
  11080. }
  11081. parent.append(tslib_1.__classPrivateFieldGet(this, _TextLayer_container, "f"));
  11082. }
  11083. else if (item.type === "endMarkedContent") {
  11084. tslib_1.__classPrivateFieldSet(this, _TextLayer_container, tslib_1.__classPrivateFieldGet(this, _TextLayer_container, "f").parentNode, "f");
  11085. }
  11086. continue;
  11087. }
  11088. textContentItemsStr.push(item.str);
  11089. tslib_1.__classPrivateFieldGet(this, _TextLayer_instances, "m", _TextLayer_appendText).call(this, item);
  11090. }
  11091. }, _TextLayer_appendText = function _TextLayer_appendText(geom) {
  11092. var textDiv = document.createElement("span");
  11093. var textDivProperties = {
  11094. angle: 0,
  11095. canvasWidth: 0,
  11096. hasText: geom.str !== "",
  11097. hasEOL: geom.hasEOL,
  11098. fontSize: 0
  11099. };
  11100. tslib_1.__classPrivateFieldGet(this, _TextLayer_textDivs, "f").push(textDiv);
  11101. var tx = Util.transform(tslib_1.__classPrivateFieldGet(this, _TextLayer_transform, "f"), geom.transform);
  11102. var angle = Math.atan2(tx[1], tx[0]);
  11103. var style = tslib_1.__classPrivateFieldGet(this, _TextLayer_styleCache, "f")[geom.fontName];
  11104. if (style.vertical) {
  11105. angle += Math.PI / 2;
  11106. }
  11107. var fontFamily = tslib_1.__classPrivateFieldGet(this, _TextLayer_fontInspectorEnabled, "f") && style.fontSubstitution || style.fontFamily;
  11108. var fontHeight = Math.hypot(tx[2], tx[3]);
  11109. var fontAscent = fontHeight * tslib_1.__classPrivateFieldGet(TextLayer, _h, "m", _TextLayer_getAscent).call(TextLayer, fontFamily, tslib_1.__classPrivateFieldGet(this, _TextLayer_lang, "f"));
  11110. var left, top;
  11111. if (angle === 0) {
  11112. left = tx[4];
  11113. top = tx[5] - fontAscent;
  11114. }
  11115. else {
  11116. left = tx[4] + fontAscent * Math.sin(angle);
  11117. top = tx[5] - fontAscent * Math.cos(angle);
  11118. }
  11119. var scaleFactorStr = "calc(var(--scale-factor)*";
  11120. var divStyle = textDiv.style;
  11121. if (tslib_1.__classPrivateFieldGet(this, _TextLayer_container, "f") === tslib_1.__classPrivateFieldGet(this, _TextLayer_rootContainer, "f")) {
  11122. divStyle.left = "".concat((100 * left / tslib_1.__classPrivateFieldGet(this, _TextLayer_pageWidth, "f")).toFixed(2), "%");
  11123. divStyle.top = "".concat((100 * top / tslib_1.__classPrivateFieldGet(this, _TextLayer_pageHeight, "f")).toFixed(2), "%");
  11124. }
  11125. else {
  11126. divStyle.left = "".concat(scaleFactorStr).concat(left.toFixed(2), "px)");
  11127. divStyle.top = "".concat(scaleFactorStr).concat(top.toFixed(2), "px)");
  11128. }
  11129. divStyle.fontSize = "".concat(scaleFactorStr).concat(fontHeight.toFixed(2), "px)");
  11130. divStyle.fontFamily = fontFamily;
  11131. textDivProperties.fontSize = fontHeight;
  11132. textDiv.setAttribute("role", "presentation");
  11133. textDiv.textContent = geom.str;
  11134. textDiv.dir = geom.dir;
  11135. if (tslib_1.__classPrivateFieldGet(this, _TextLayer_fontInspectorEnabled, "f")) {
  11136. textDiv.dataset.fontName = style.fontSubstitutionLoadedName || geom.fontName;
  11137. }
  11138. if (angle !== 0) {
  11139. textDivProperties.angle = angle * (180 / Math.PI);
  11140. }
  11141. var shouldScaleText = false;
  11142. if (geom.str.length > 1) {
  11143. shouldScaleText = true;
  11144. }
  11145. else if (geom.str !== " " && geom.transform[0] !== geom.transform[3]) {
  11146. var absScaleX = Math.abs(geom.transform[0]), absScaleY = Math.abs(geom.transform[3]);
  11147. if (absScaleX !== absScaleY && Math.max(absScaleX, absScaleY) / Math.min(absScaleX, absScaleY) > 1.5) {
  11148. shouldScaleText = true;
  11149. }
  11150. }
  11151. if (shouldScaleText) {
  11152. textDivProperties.canvasWidth = style.vertical ? geom.height : geom.width;
  11153. }
  11154. tslib_1.__classPrivateFieldGet(this, _TextLayer_textDivProperties, "f").set(textDiv, textDivProperties);
  11155. tslib_1.__classPrivateFieldGet(this, _TextLayer_layoutTextParams, "f").div = textDiv;
  11156. tslib_1.__classPrivateFieldGet(this, _TextLayer_layoutTextParams, "f").properties = textDivProperties;
  11157. tslib_1.__classPrivateFieldGet(this, _TextLayer_instances, "m", _TextLayer_layout).call(this, tslib_1.__classPrivateFieldGet(this, _TextLayer_layoutTextParams, "f"));
  11158. if (textDivProperties.hasText) {
  11159. tslib_1.__classPrivateFieldGet(this, _TextLayer_container, "f").append(textDiv);
  11160. }
  11161. if (textDivProperties.hasEOL) {
  11162. var br = document.createElement("br");
  11163. br.setAttribute("role", "presentation");
  11164. tslib_1.__classPrivateFieldGet(this, _TextLayer_container, "f").append(br);
  11165. }
  11166. }, _TextLayer_layout = function _TextLayer_layout(params) {
  11167. var div = params.div, properties = params.properties, ctx = params.ctx, prevFontSize = params.prevFontSize, prevFontFamily = params.prevFontFamily;
  11168. var style = div.style;
  11169. var transform = "";
  11170. if (properties.canvasWidth !== 0 && properties.hasText) {
  11171. var fontFamily = style.fontFamily;
  11172. var canvasWidth = properties.canvasWidth, fontSize = properties.fontSize;
  11173. if (prevFontSize !== fontSize || prevFontFamily !== fontFamily) {
  11174. ctx.font = "".concat(fontSize * tslib_1.__classPrivateFieldGet(this, _TextLayer_scale, "f"), "px ").concat(fontFamily);
  11175. params.prevFontSize = fontSize;
  11176. params.prevFontFamily = fontFamily;
  11177. }
  11178. var width = ctx.measureText(div.textContent).width;
  11179. if (width > 0) {
  11180. transform = "scaleX(".concat(canvasWidth * tslib_1.__classPrivateFieldGet(this, _TextLayer_scale, "f") / width, ")");
  11181. }
  11182. }
  11183. if (properties.angle !== 0) {
  11184. transform = "rotate(".concat(properties.angle, "deg) ").concat(transform);
  11185. }
  11186. if (transform.length > 0) {
  11187. style.transform = transform;
  11188. }
  11189. }, _TextLayer_getCtx = function _TextLayer_getCtx(lang) {
  11190. if (lang === void 0) { lang = null; }
  11191. var canvasContext = tslib_1.__classPrivateFieldGet(this, _h, "f", _TextLayer_canvasContexts).get(lang || (lang = ""));
  11192. if (!canvasContext) {
  11193. var canvas = document.createElement("canvas");
  11194. canvas.className = "hiddenCanvasElement";
  11195. canvas.lang = lang;
  11196. document.body.append(canvas);
  11197. canvasContext = canvas.getContext("2d", {
  11198. alpha: false
  11199. });
  11200. tslib_1.__classPrivateFieldGet(this, _h, "f", _TextLayer_canvasContexts).set(lang, canvasContext);
  11201. }
  11202. return canvasContext;
  11203. }, _TextLayer_getAscent = function _TextLayer_getAscent(fontFamily, lang) {
  11204. var cachedAscent = tslib_1.__classPrivateFieldGet(this, _h, "f", _TextLayer_ascentCache).get(fontFamily);
  11205. if (cachedAscent) {
  11206. return cachedAscent;
  11207. }
  11208. var ctx = tslib_1.__classPrivateFieldGet(this, _h, "m", _TextLayer_getCtx).call(this, lang);
  11209. var savedFont = ctx.font;
  11210. ctx.canvas.width = ctx.canvas.height = DEFAULT_FONT_SIZE;
  11211. ctx.font = "".concat(DEFAULT_FONT_SIZE, "px ").concat(fontFamily);
  11212. var metrics = ctx.measureText("");
  11213. var ascent = metrics.fontBoundingBoxAscent;
  11214. var descent = Math.abs(metrics.fontBoundingBoxDescent);
  11215. if (ascent) {
  11216. var ratio_1 = ascent / (ascent + descent);
  11217. tslib_1.__classPrivateFieldGet(this, _h, "f", _TextLayer_ascentCache).set(fontFamily, ratio_1);
  11218. ctx.canvas.width = ctx.canvas.height = 0;
  11219. ctx.font = savedFont;
  11220. return ratio_1;
  11221. }
  11222. ctx.strokeStyle = "red";
  11223. ctx.clearRect(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE);
  11224. ctx.strokeText("g", 0, 0);
  11225. var pixels = ctx.getImageData(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE).data;
  11226. descent = 0;
  11227. for (var i = pixels.length - 1 - 3; i >= 0; i -= 4) {
  11228. if (pixels[i] > 0) {
  11229. descent = Math.ceil(i / 4 / DEFAULT_FONT_SIZE);
  11230. break;
  11231. }
  11232. }
  11233. ctx.clearRect(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE);
  11234. ctx.strokeText("A", 0, DEFAULT_FONT_SIZE);
  11235. pixels = ctx.getImageData(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE).data;
  11236. ascent = 0;
  11237. for (var i = 0, ii = pixels.length; i < ii; i += 4) {
  11238. if (pixels[i] > 0) {
  11239. ascent = DEFAULT_FONT_SIZE - Math.floor(i / 4 / DEFAULT_FONT_SIZE);
  11240. break;
  11241. }
  11242. }
  11243. ctx.canvas.width = ctx.canvas.height = 0;
  11244. ctx.font = savedFont;
  11245. var ratio = ascent ? ascent / (ascent + descent) : DEFAULT_FONT_ASCENT;
  11246. tslib_1.__classPrivateFieldGet(this, _h, "f", _TextLayer_ascentCache).set(fontFamily, ratio);
  11247. return ratio;
  11248. };
  11249. _TextLayer_ascentCache = { value: new Map() };
  11250. _TextLayer_canvasContexts = { value: new Map() };
  11251. _TextLayer_pendingTextLayers = { value: new Set() };
  11252. return TextLayer;
  11253. }());
  11254. function renderTextLayer() {
  11255. deprecated("`renderTextLayer`, please use `TextLayer` instead.");
  11256. var _j = arguments[0], textContentSource = _j.textContentSource, container = _j.container, viewport = _j.viewport, rest = tslib_1.__rest(_j, ["textContentSource", "container", "viewport"]);
  11257. var restKeys = Object.keys(rest);
  11258. if (restKeys.length > 0) {
  11259. warn("Ignoring `renderTextLayer` parameters: " + restKeys.join(", "));
  11260. }
  11261. var textLayer = new TextLayer({
  11262. textContentSource: textContentSource,
  11263. container: container,
  11264. viewport: viewport
  11265. });
  11266. var textDivs = textLayer.textDivs, textContentItemsStr = textLayer.textContentItemsStr;
  11267. var promise = textLayer.render();
  11268. return {
  11269. promise: promise,
  11270. textDivs: textDivs,
  11271. textContentItemsStr: textContentItemsStr
  11272. };
  11273. }
  11274. function updateTextLayer() {
  11275. deprecated("`updateTextLayer`, please use `TextLayer` instead.");
  11276. }
  11277. ; // CONCATENATED MODULE: ./src/display/xfa_text.js
  11278. var XfaText = /** @class */ (function () {
  11279. function XfaText() {
  11280. }
  11281. XfaText.textContent = function (xfa) {
  11282. var items = [];
  11283. var output = {
  11284. items: items,
  11285. styles: Object.create(null)
  11286. };
  11287. function walk(node) {
  11288. var _j;
  11289. if (!node) {
  11290. return;
  11291. }
  11292. var str = null;
  11293. var name = node.name;
  11294. if (name === "#text") {
  11295. str = node.value;
  11296. }
  11297. else if (!XfaText.shouldBuildText(name)) {
  11298. return;
  11299. }
  11300. else if ((_j = node === null || node === void 0 ? void 0 : node.attributes) === null || _j === void 0 ? void 0 : _j.textContent) {
  11301. str = node.attributes.textContent;
  11302. }
  11303. else if (node.value) {
  11304. str = node.value;
  11305. }
  11306. if (str !== null) {
  11307. items.push({
  11308. str: str
  11309. });
  11310. }
  11311. if (!node.children) {
  11312. return;
  11313. }
  11314. for (var _i = 0, _k = node.children; _i < _k.length; _i++) {
  11315. var child = _k[_i];
  11316. walk(child);
  11317. }
  11318. }
  11319. walk(xfa);
  11320. return output;
  11321. };
  11322. XfaText.shouldBuildText = function (name) {
  11323. return !(name === "textarea" || name === "input" || name === "option" || name === "select");
  11324. };
  11325. return XfaText;
  11326. }());
  11327. ; // CONCATENATED MODULE: ./src/display/api.js
  11328. var DEFAULT_RANGE_CHUNK_SIZE = 65536;
  11329. var RENDERING_CANCELLED_TIMEOUT = 100;
  11330. var DELAYED_CLEANUP_TIMEOUT = 5000;
  11331. var DefaultCanvasFactory = isNodeJS ? NodeCanvasFactory : DOMCanvasFactory;
  11332. var DefaultCMapReaderFactory = isNodeJS ? NodeCMapReaderFactory : DOMCMapReaderFactory;
  11333. var DefaultFilterFactory = isNodeJS ? NodeFilterFactory : DOMFilterFactory;
  11334. var DefaultStandardFontDataFactory = isNodeJS ? NodeStandardFontDataFactory : DOMStandardFontDataFactory;
  11335. function getDocument(src) {
  11336. var _j, _k;
  11337. if (typeof src === "string" || src instanceof URL) {
  11338. src = {
  11339. url: src
  11340. };
  11341. }
  11342. else if (src instanceof ArrayBuffer || ArrayBuffer.isView(src)) {
  11343. src = {
  11344. data: src
  11345. };
  11346. }
  11347. if (typeof src !== "object") {
  11348. throw new Error("Invalid parameter in getDocument, need parameter object.");
  11349. }
  11350. if (!src.url && !src.data && !src.range) {
  11351. throw new Error("Invalid parameter object: need either .data, .range or .url");
  11352. }
  11353. var task = new PDFDocumentLoadingTask();
  11354. var docId = task.docId;
  11355. var url = src.url ? getUrlProp(src.url) : null;
  11356. var data = src.data ? getDataProp(src.data) : null;
  11357. var httpHeaders = src.httpHeaders || null;
  11358. var withCredentials = src.withCredentials === true;
  11359. var password = (_j = src.password) !== null && _j !== void 0 ? _j : null;
  11360. var rangeTransport = src.range instanceof PDFDataRangeTransport ? src.range : null;
  11361. var rangeChunkSize = Number.isInteger(src.rangeChunkSize) && src.rangeChunkSize > 0 ? src.rangeChunkSize : DEFAULT_RANGE_CHUNK_SIZE;
  11362. var worker = src.worker instanceof PDFWorker ? src.worker : null;
  11363. var verbosity = src.verbosity;
  11364. var docBaseUrl = typeof src.docBaseUrl === "string" && !isDataScheme(src.docBaseUrl) ? src.docBaseUrl : null;
  11365. var cMapUrl = typeof src.cMapUrl === "string" ? src.cMapUrl : null;
  11366. var cMapPacked = src.cMapPacked !== false;
  11367. var CMapReaderFactory = src.CMapReaderFactory || DefaultCMapReaderFactory;
  11368. var standardFontDataUrl = typeof src.standardFontDataUrl === "string" ? src.standardFontDataUrl : null;
  11369. var StandardFontDataFactory = src.StandardFontDataFactory || DefaultStandardFontDataFactory;
  11370. var ignoreErrors = src.stopAtErrors !== true;
  11371. var maxImageSize = Number.isInteger(src.maxImageSize) && src.maxImageSize > -1 ? src.maxImageSize : -1;
  11372. var isEvalSupported = src.isEvalSupported !== false;
  11373. var isOffscreenCanvasSupported = typeof src.isOffscreenCanvasSupported === "boolean" ? src.isOffscreenCanvasSupported : !isNodeJS;
  11374. var canvasMaxAreaInBytes = Number.isInteger(src.canvasMaxAreaInBytes) ? src.canvasMaxAreaInBytes : -1;
  11375. var disableFontFace = typeof src.disableFontFace === "boolean" ? src.disableFontFace : isNodeJS;
  11376. var fontExtraProperties = src.fontExtraProperties === true;
  11377. var enableXfa = src.enableXfa === true;
  11378. var ownerDocument = src.ownerDocument || globalThis.document;
  11379. var disableRange = src.disableRange === true;
  11380. var disableStream = src.disableStream === true;
  11381. var disableAutoFetch = src.disableAutoFetch === true;
  11382. var pdfBug = src.pdfBug === true;
  11383. var length = rangeTransport ? rangeTransport.length : (_k = src.length) !== null && _k !== void 0 ? _k : NaN;
  11384. var useSystemFonts = typeof src.useSystemFonts === "boolean" ? src.useSystemFonts : !isNodeJS && !disableFontFace;
  11385. var useWorkerFetch = typeof src.useWorkerFetch === "boolean" ? src.useWorkerFetch : CMapReaderFactory === DOMCMapReaderFactory && StandardFontDataFactory === DOMStandardFontDataFactory && cMapUrl && standardFontDataUrl && isValidFetchUrl(cMapUrl, document.baseURI) && isValidFetchUrl(standardFontDataUrl, document.baseURI);
  11386. var canvasFactory = src.canvasFactory || new DefaultCanvasFactory({
  11387. ownerDocument: ownerDocument
  11388. });
  11389. var filterFactory = src.filterFactory || new DefaultFilterFactory({
  11390. docId: docId,
  11391. ownerDocument: ownerDocument
  11392. });
  11393. var styleElement = null;
  11394. setVerbosityLevel(verbosity);
  11395. var transportFactory = {
  11396. canvasFactory: canvasFactory,
  11397. filterFactory: filterFactory
  11398. };
  11399. if (!useWorkerFetch) {
  11400. transportFactory.cMapReaderFactory = new CMapReaderFactory({
  11401. baseUrl: cMapUrl,
  11402. isCompressed: cMapPacked
  11403. });
  11404. transportFactory.standardFontDataFactory = new StandardFontDataFactory({
  11405. baseUrl: standardFontDataUrl
  11406. });
  11407. }
  11408. if (!worker) {
  11409. var workerParams = {
  11410. verbosity: verbosity,
  11411. port: GlobalWorkerOptions.workerPort
  11412. };
  11413. worker = workerParams.port ? PDFWorker.fromPort(workerParams) : new PDFWorker(workerParams);
  11414. task._worker = worker;
  11415. }
  11416. var docParams = {
  11417. docId: docId,
  11418. apiVersion: "4.3.136",
  11419. data: data,
  11420. password: password,
  11421. disableAutoFetch: disableAutoFetch,
  11422. rangeChunkSize: rangeChunkSize,
  11423. length: length,
  11424. docBaseUrl: docBaseUrl,
  11425. enableXfa: enableXfa,
  11426. evaluatorOptions: {
  11427. maxImageSize: maxImageSize,
  11428. disableFontFace: disableFontFace,
  11429. ignoreErrors: ignoreErrors,
  11430. isEvalSupported: isEvalSupported,
  11431. isOffscreenCanvasSupported: isOffscreenCanvasSupported,
  11432. canvasMaxAreaInBytes: canvasMaxAreaInBytes,
  11433. fontExtraProperties: fontExtraProperties,
  11434. useSystemFonts: useSystemFonts,
  11435. cMapUrl: useWorkerFetch ? cMapUrl : null,
  11436. standardFontDataUrl: useWorkerFetch ? standardFontDataUrl : null
  11437. }
  11438. };
  11439. var transportParams = {
  11440. disableFontFace: disableFontFace,
  11441. fontExtraProperties: fontExtraProperties,
  11442. ownerDocument: ownerDocument,
  11443. pdfBug: pdfBug,
  11444. styleElement: styleElement,
  11445. loadingParams: {
  11446. disableAutoFetch: disableAutoFetch,
  11447. enableXfa: enableXfa
  11448. }
  11449. };
  11450. worker.promise.then(function () {
  11451. if (task.destroyed) {
  11452. throw new Error("Loading aborted");
  11453. }
  11454. if (worker.destroyed) {
  11455. throw new Error("Worker was destroyed");
  11456. }
  11457. var workerIdPromise = worker.messageHandler.sendWithPromise("GetDocRequest", docParams, data ? [data.buffer] : null);
  11458. var networkStream;
  11459. if (rangeTransport) {
  11460. networkStream = new PDFDataTransportStream(rangeTransport, {
  11461. disableRange: disableRange,
  11462. disableStream: disableStream
  11463. });
  11464. }
  11465. else if (!data) {
  11466. var createPDFNetworkStream = function (params) {
  11467. if (isNodeJS) {
  11468. var isFetchSupported = function () {
  11469. return typeof fetch !== "undefined" && typeof Response !== "undefined" && "body" in Response.prototype;
  11470. };
  11471. return isFetchSupported() && isValidFetchUrl(params.url) ? new PDFFetchStream(params) : new PDFNodeStream(params);
  11472. }
  11473. return isValidFetchUrl(params.url) ? new PDFFetchStream(params) : new PDFNetworkStream(params);
  11474. };
  11475. networkStream = createPDFNetworkStream({
  11476. url: url,
  11477. length: length,
  11478. httpHeaders: httpHeaders,
  11479. withCredentials: withCredentials,
  11480. rangeChunkSize: rangeChunkSize,
  11481. disableRange: disableRange,
  11482. disableStream: disableStream
  11483. });
  11484. }
  11485. return workerIdPromise.then(function (workerId) {
  11486. if (task.destroyed) {
  11487. throw new Error("Loading aborted");
  11488. }
  11489. if (worker.destroyed) {
  11490. throw new Error("Worker was destroyed");
  11491. }
  11492. var messageHandler = new MessageHandler(docId, workerId, worker.port);
  11493. var transport = new WorkerTransport(messageHandler, task, networkStream, transportParams, transportFactory);
  11494. task._transport = transport;
  11495. messageHandler.send("Ready", null);
  11496. });
  11497. }).catch(task._capability.reject);
  11498. return task;
  11499. }
  11500. function getUrlProp(val) {
  11501. if (val instanceof URL) {
  11502. return val.href;
  11503. }
  11504. try {
  11505. return new URL(val, window.location).href;
  11506. }
  11507. catch (_j) {
  11508. if (isNodeJS && typeof val === "string") {
  11509. return val;
  11510. }
  11511. }
  11512. throw new Error("Invalid PDF url data: " + "either string or URL-object is expected in the url property.");
  11513. }
  11514. function getDataProp(val) {
  11515. if (isNodeJS && typeof Buffer !== "undefined" && val instanceof Buffer) {
  11516. throw new Error("Please provide binary data as `Uint8Array`, rather than `Buffer`.");
  11517. }
  11518. if (val instanceof Uint8Array && val.byteLength === val.buffer.byteLength) {
  11519. return val;
  11520. }
  11521. if (typeof val === "string") {
  11522. return stringToBytes(val);
  11523. }
  11524. if (val instanceof ArrayBuffer || ArrayBuffer.isView(val) || typeof val === "object" && !isNaN(val === null || val === void 0 ? void 0 : val.length)) {
  11525. return new Uint8Array(val);
  11526. }
  11527. throw new Error("Invalid PDF binary data: either TypedArray, " + "string, or array-like object is expected in the data property.");
  11528. }
  11529. function isRefProxy(ref) {
  11530. return typeof ref === "object" && Number.isInteger(ref === null || ref === void 0 ? void 0 : ref.num) && ref.num >= 0 && Number.isInteger(ref === null || ref === void 0 ? void 0 : ref.gen) && ref.gen >= 0;
  11531. }
  11532. var PDFDocumentLoadingTask = /** @class */ (function () {
  11533. function PDFDocumentLoadingTask() {
  11534. var _k, _l, _m;
  11535. this._capability = Promise.withResolvers();
  11536. this._transport = null;
  11537. this._worker = null;
  11538. this.docId = "d".concat((tslib_1.__classPrivateFieldSet(_k = PDFDocumentLoadingTask, _j, (_m = tslib_1.__classPrivateFieldGet(_k, _j, "f", _PDFDocumentLoadingTask_docId), _l = _m++, _m), "f", _PDFDocumentLoadingTask_docId), _l));
  11539. this.destroyed = false;
  11540. this.onPassword = null;
  11541. this.onProgress = null;
  11542. }
  11543. Object.defineProperty(PDFDocumentLoadingTask.prototype, "promise", {
  11544. get: function () {
  11545. return this._capability.promise;
  11546. },
  11547. enumerable: false,
  11548. configurable: true
  11549. });
  11550. PDFDocumentLoadingTask.prototype.destroy = function () {
  11551. var _k, _l, _m;
  11552. return tslib_1.__awaiter(this, void 0, void 0, function () {
  11553. var ex_2;
  11554. return tslib_1.__generator(this, function (_o) {
  11555. switch (_o.label) {
  11556. case 0:
  11557. this.destroyed = true;
  11558. _o.label = 1;
  11559. case 1:
  11560. _o.trys.push([1, 3, , 4]);
  11561. if ((_k = this._worker) === null || _k === void 0 ? void 0 : _k.port) {
  11562. this._worker._pendingDestroy = true;
  11563. }
  11564. return [4 /*yield*/, ((_l = this._transport) === null || _l === void 0 ? void 0 : _l.destroy())];
  11565. case 2:
  11566. _o.sent();
  11567. return [3 /*break*/, 4];
  11568. case 3:
  11569. ex_2 = _o.sent();
  11570. if ((_m = this._worker) === null || _m === void 0 ? void 0 : _m.port) {
  11571. delete this._worker._pendingDestroy;
  11572. }
  11573. throw ex_2;
  11574. case 4:
  11575. this._transport = null;
  11576. if (this._worker) {
  11577. this._worker.destroy();
  11578. this._worker = null;
  11579. }
  11580. return [2 /*return*/];
  11581. }
  11582. });
  11583. });
  11584. };
  11585. var _j, _PDFDocumentLoadingTask_docId;
  11586. _j = PDFDocumentLoadingTask;
  11587. _PDFDocumentLoadingTask_docId = { value: 0 };
  11588. return PDFDocumentLoadingTask;
  11589. }());
  11590. var PDFDataRangeTransport = /** @class */ (function () {
  11591. function PDFDataRangeTransport(length, initialData, progressiveDone, contentDispositionFilename) {
  11592. if (progressiveDone === void 0) { progressiveDone = false; }
  11593. if (contentDispositionFilename === void 0) { contentDispositionFilename = null; }
  11594. this.length = length;
  11595. this.initialData = initialData;
  11596. this.progressiveDone = progressiveDone;
  11597. this.contentDispositionFilename = contentDispositionFilename;
  11598. this._rangeListeners = [];
  11599. this._progressListeners = [];
  11600. this._progressiveReadListeners = [];
  11601. this._progressiveDoneListeners = [];
  11602. this._readyCapability = Promise.withResolvers();
  11603. }
  11604. PDFDataRangeTransport.prototype.addRangeListener = function (listener) {
  11605. this._rangeListeners.push(listener);
  11606. };
  11607. PDFDataRangeTransport.prototype.addProgressListener = function (listener) {
  11608. this._progressListeners.push(listener);
  11609. };
  11610. PDFDataRangeTransport.prototype.addProgressiveReadListener = function (listener) {
  11611. this._progressiveReadListeners.push(listener);
  11612. };
  11613. PDFDataRangeTransport.prototype.addProgressiveDoneListener = function (listener) {
  11614. this._progressiveDoneListeners.push(listener);
  11615. };
  11616. PDFDataRangeTransport.prototype.onDataRange = function (begin, chunk) {
  11617. for (var _i = 0, _k = this._rangeListeners; _i < _k.length; _i++) {
  11618. var listener = _k[_i];
  11619. listener(begin, chunk);
  11620. }
  11621. };
  11622. PDFDataRangeTransport.prototype.onDataProgress = function (loaded, total) {
  11623. var _this = this;
  11624. this._readyCapability.promise.then(function () {
  11625. for (var _i = 0, _k = _this._progressListeners; _i < _k.length; _i++) {
  11626. var listener = _k[_i];
  11627. listener(loaded, total);
  11628. }
  11629. });
  11630. };
  11631. PDFDataRangeTransport.prototype.onDataProgressiveRead = function (chunk) {
  11632. var _this = this;
  11633. this._readyCapability.promise.then(function () {
  11634. for (var _i = 0, _k = _this._progressiveReadListeners; _i < _k.length; _i++) {
  11635. var listener = _k[_i];
  11636. listener(chunk);
  11637. }
  11638. });
  11639. };
  11640. PDFDataRangeTransport.prototype.onDataProgressiveDone = function () {
  11641. var _this = this;
  11642. this._readyCapability.promise.then(function () {
  11643. for (var _i = 0, _k = _this._progressiveDoneListeners; _i < _k.length; _i++) {
  11644. var listener = _k[_i];
  11645. listener();
  11646. }
  11647. });
  11648. };
  11649. PDFDataRangeTransport.prototype.transportReady = function () {
  11650. this._readyCapability.resolve();
  11651. };
  11652. PDFDataRangeTransport.prototype.requestDataRange = function (begin, end) {
  11653. unreachable("Abstract method PDFDataRangeTransport.requestDataRange");
  11654. };
  11655. PDFDataRangeTransport.prototype.abort = function () { };
  11656. return PDFDataRangeTransport;
  11657. }());
  11658. var PDFDocumentProxy = /** @class */ (function () {
  11659. function PDFDocumentProxy(pdfInfo, transport) {
  11660. this._pdfInfo = pdfInfo;
  11661. this._transport = transport;
  11662. }
  11663. Object.defineProperty(PDFDocumentProxy.prototype, "annotationStorage", {
  11664. get: function () {
  11665. return this._transport.annotationStorage;
  11666. },
  11667. enumerable: false,
  11668. configurable: true
  11669. });
  11670. Object.defineProperty(PDFDocumentProxy.prototype, "filterFactory", {
  11671. get: function () {
  11672. return this._transport.filterFactory;
  11673. },
  11674. enumerable: false,
  11675. configurable: true
  11676. });
  11677. Object.defineProperty(PDFDocumentProxy.prototype, "numPages", {
  11678. get: function () {
  11679. return this._pdfInfo.numPages;
  11680. },
  11681. enumerable: false,
  11682. configurable: true
  11683. });
  11684. Object.defineProperty(PDFDocumentProxy.prototype, "fingerprints", {
  11685. get: function () {
  11686. return this._pdfInfo.fingerprints;
  11687. },
  11688. enumerable: false,
  11689. configurable: true
  11690. });
  11691. Object.defineProperty(PDFDocumentProxy.prototype, "isPureXfa", {
  11692. get: function () {
  11693. return shadow(this, "isPureXfa", !!this._transport._htmlForXfa);
  11694. },
  11695. enumerable: false,
  11696. configurable: true
  11697. });
  11698. Object.defineProperty(PDFDocumentProxy.prototype, "allXfaHtml", {
  11699. get: function () {
  11700. return this._transport._htmlForXfa;
  11701. },
  11702. enumerable: false,
  11703. configurable: true
  11704. });
  11705. PDFDocumentProxy.prototype.getPage = function (pageNumber) {
  11706. return this._transport.getPage(pageNumber);
  11707. };
  11708. PDFDocumentProxy.prototype.getPageIndex = function (ref) {
  11709. return this._transport.getPageIndex(ref);
  11710. };
  11711. PDFDocumentProxy.prototype.getDestinations = function () {
  11712. return this._transport.getDestinations();
  11713. };
  11714. PDFDocumentProxy.prototype.getDestination = function (id) {
  11715. return this._transport.getDestination(id);
  11716. };
  11717. PDFDocumentProxy.prototype.getPageLabels = function () {
  11718. return this._transport.getPageLabels();
  11719. };
  11720. PDFDocumentProxy.prototype.getPageLayout = function () {
  11721. return this._transport.getPageLayout();
  11722. };
  11723. PDFDocumentProxy.prototype.getPageMode = function () {
  11724. return this._transport.getPageMode();
  11725. };
  11726. PDFDocumentProxy.prototype.getViewerPreferences = function () {
  11727. return this._transport.getViewerPreferences();
  11728. };
  11729. PDFDocumentProxy.prototype.getOpenAction = function () {
  11730. return this._transport.getOpenAction();
  11731. };
  11732. PDFDocumentProxy.prototype.getAttachments = function () {
  11733. return this._transport.getAttachments();
  11734. };
  11735. PDFDocumentProxy.prototype.getJSActions = function () {
  11736. return this._transport.getDocJSActions();
  11737. };
  11738. PDFDocumentProxy.prototype.getOutline = function () {
  11739. return this._transport.getOutline();
  11740. };
  11741. PDFDocumentProxy.prototype.getOptionalContentConfig = function (_k) {
  11742. var _l = _k === void 0 ? {} : _k, _m = _l.intent, intent = _m === void 0 ? "display" : _m;
  11743. var renderingIntent = this._transport.getRenderingIntent(intent).renderingIntent;
  11744. return this._transport.getOptionalContentConfig(renderingIntent);
  11745. };
  11746. PDFDocumentProxy.prototype.getPermissions = function () {
  11747. return this._transport.getPermissions();
  11748. };
  11749. PDFDocumentProxy.prototype.getMetadata = function () {
  11750. return this._transport.getMetadata();
  11751. };
  11752. PDFDocumentProxy.prototype.getMarkInfo = function () {
  11753. return this._transport.getMarkInfo();
  11754. };
  11755. PDFDocumentProxy.prototype.getData = function () {
  11756. return this._transport.getData();
  11757. };
  11758. PDFDocumentProxy.prototype.saveDocument = function () {
  11759. return this._transport.saveDocument();
  11760. };
  11761. PDFDocumentProxy.prototype.getDownloadInfo = function () {
  11762. return this._transport.downloadInfoCapability.promise;
  11763. };
  11764. PDFDocumentProxy.prototype.cleanup = function (keepLoadedFonts) {
  11765. if (keepLoadedFonts === void 0) { keepLoadedFonts = false; }
  11766. return this._transport.startCleanup(keepLoadedFonts || this.isPureXfa);
  11767. };
  11768. PDFDocumentProxy.prototype.destroy = function () {
  11769. return this.loadingTask.destroy();
  11770. };
  11771. PDFDocumentProxy.prototype.cachedPageNumber = function (ref) {
  11772. return this._transport.cachedPageNumber(ref);
  11773. };
  11774. Object.defineProperty(PDFDocumentProxy.prototype, "loadingParams", {
  11775. get: function () {
  11776. return this._transport.loadingParams;
  11777. },
  11778. enumerable: false,
  11779. configurable: true
  11780. });
  11781. Object.defineProperty(PDFDocumentProxy.prototype, "loadingTask", {
  11782. get: function () {
  11783. return this._transport.loadingTask;
  11784. },
  11785. enumerable: false,
  11786. configurable: true
  11787. });
  11788. PDFDocumentProxy.prototype.getFieldObjects = function () {
  11789. return this._transport.getFieldObjects();
  11790. };
  11791. PDFDocumentProxy.prototype.hasJSActions = function () {
  11792. return this._transport.hasJSActions();
  11793. };
  11794. PDFDocumentProxy.prototype.getCalculationOrderIds = function () {
  11795. return this._transport.getCalculationOrderIds();
  11796. };
  11797. return PDFDocumentProxy;
  11798. }());
  11799. var PDFPageProxy = /** @class */ (function () {
  11800. function PDFPageProxy(pageIndex, pageInfo, transport, pdfBug) {
  11801. if (pdfBug === void 0) { pdfBug = false; }
  11802. _PDFPageProxy_instances.add(this);
  11803. _PDFPageProxy_delayedCleanupTimeout.set(this, null);
  11804. _PDFPageProxy_pendingCleanup.set(this, false);
  11805. this._pageIndex = pageIndex;
  11806. this._pageInfo = pageInfo;
  11807. this._transport = transport;
  11808. this._stats = pdfBug ? new StatTimer() : null;
  11809. this._pdfBug = pdfBug;
  11810. this.commonObjs = transport.commonObjs;
  11811. this.objs = new PDFObjects();
  11812. this._maybeCleanupAfterRender = false;
  11813. this._intentStates = new Map();
  11814. this.destroyed = false;
  11815. }
  11816. Object.defineProperty(PDFPageProxy.prototype, "pageNumber", {
  11817. get: function () {
  11818. return this._pageIndex + 1;
  11819. },
  11820. enumerable: false,
  11821. configurable: true
  11822. });
  11823. Object.defineProperty(PDFPageProxy.prototype, "rotate", {
  11824. get: function () {
  11825. return this._pageInfo.rotate;
  11826. },
  11827. enumerable: false,
  11828. configurable: true
  11829. });
  11830. Object.defineProperty(PDFPageProxy.prototype, "ref", {
  11831. get: function () {
  11832. return this._pageInfo.ref;
  11833. },
  11834. enumerable: false,
  11835. configurable: true
  11836. });
  11837. Object.defineProperty(PDFPageProxy.prototype, "userUnit", {
  11838. get: function () {
  11839. return this._pageInfo.userUnit;
  11840. },
  11841. enumerable: false,
  11842. configurable: true
  11843. });
  11844. Object.defineProperty(PDFPageProxy.prototype, "view", {
  11845. get: function () {
  11846. return this._pageInfo.view;
  11847. },
  11848. enumerable: false,
  11849. configurable: true
  11850. });
  11851. PDFPageProxy.prototype.getViewport = function (_k) {
  11852. var _l = _k === void 0 ? {} : _k, scale = _l.scale, _m = _l.rotation, rotation = _m === void 0 ? this.rotate : _m, _o = _l.offsetX, offsetX = _o === void 0 ? 0 : _o, _p = _l.offsetY, offsetY = _p === void 0 ? 0 : _p, _q = _l.dontFlip, dontFlip = _q === void 0 ? false : _q;
  11853. return new PageViewport({
  11854. viewBox: this.view,
  11855. scale: scale,
  11856. rotation: rotation,
  11857. offsetX: offsetX,
  11858. offsetY: offsetY,
  11859. dontFlip: dontFlip
  11860. });
  11861. };
  11862. PDFPageProxy.prototype.getAnnotations = function (_k) {
  11863. var _l = _k === void 0 ? {} : _k, _m = _l.intent, intent = _m === void 0 ? "display" : _m;
  11864. var renderingIntent = this._transport.getRenderingIntent(intent).renderingIntent;
  11865. return this._transport.getAnnotations(this._pageIndex, renderingIntent);
  11866. };
  11867. PDFPageProxy.prototype.getJSActions = function () {
  11868. return this._transport.getPageJSActions(this._pageIndex);
  11869. };
  11870. Object.defineProperty(PDFPageProxy.prototype, "filterFactory", {
  11871. get: function () {
  11872. return this._transport.filterFactory;
  11873. },
  11874. enumerable: false,
  11875. configurable: true
  11876. });
  11877. Object.defineProperty(PDFPageProxy.prototype, "isPureXfa", {
  11878. get: function () {
  11879. return shadow(this, "isPureXfa", !!this._transport._htmlForXfa);
  11880. },
  11881. enumerable: false,
  11882. configurable: true
  11883. });
  11884. PDFPageProxy.prototype.getXfa = function () {
  11885. var _k;
  11886. return tslib_1.__awaiter(this, void 0, void 0, function () {
  11887. return tslib_1.__generator(this, function (_l) {
  11888. return [2 /*return*/, ((_k = this._transport._htmlForXfa) === null || _k === void 0 ? void 0 : _k.children[this._pageIndex]) || null];
  11889. });
  11890. });
  11891. };
  11892. PDFPageProxy.prototype.render = function (_k) {
  11893. var _this = this;
  11894. var _l, _m;
  11895. var canvasContext = _k.canvasContext, viewport = _k.viewport, _o = _k.intent, intent = _o === void 0 ? "display" : _o, _p = _k.annotationMode, annotationMode = _p === void 0 ? AnnotationMode.ENABLE : _p, _q = _k.transform, transform = _q === void 0 ? null : _q, _r = _k.background, background = _r === void 0 ? null : _r, _s = _k.optionalContentConfigPromise, optionalContentConfigPromise = _s === void 0 ? null : _s, _t = _k.annotationCanvasMap, annotationCanvasMap = _t === void 0 ? null : _t, _u = _k.pageColors, pageColors = _u === void 0 ? null : _u, _v = _k.printAnnotationStorage, printAnnotationStorage = _v === void 0 ? null : _v;
  11896. (_l = this._stats) === null || _l === void 0 ? void 0 : _l.time("Overall");
  11897. var intentArgs = this._transport.getRenderingIntent(intent, annotationMode, printAnnotationStorage);
  11898. var renderingIntent = intentArgs.renderingIntent, cacheKey = intentArgs.cacheKey;
  11899. tslib_1.__classPrivateFieldSet(this, _PDFPageProxy_pendingCleanup, false, "f");
  11900. tslib_1.__classPrivateFieldGet(this, _PDFPageProxy_instances, "m", _PDFPageProxy_abortDelayedCleanup).call(this);
  11901. optionalContentConfigPromise || (optionalContentConfigPromise = this._transport.getOptionalContentConfig(renderingIntent));
  11902. var intentState = this._intentStates.get(cacheKey);
  11903. if (!intentState) {
  11904. intentState = Object.create(null);
  11905. this._intentStates.set(cacheKey, intentState);
  11906. }
  11907. if (intentState.streamReaderCancelTimeout) {
  11908. clearTimeout(intentState.streamReaderCancelTimeout);
  11909. intentState.streamReaderCancelTimeout = null;
  11910. }
  11911. var intentPrint = !!(renderingIntent & RenderingIntentFlag.PRINT);
  11912. if (!intentState.displayReadyCapability) {
  11913. intentState.displayReadyCapability = Promise.withResolvers();
  11914. intentState.operatorList = {
  11915. fnArray: [],
  11916. argsArray: [],
  11917. lastChunk: false,
  11918. separateAnnots: null
  11919. };
  11920. (_m = this._stats) === null || _m === void 0 ? void 0 : _m.time("Page Request");
  11921. this._pumpOperatorList(intentArgs);
  11922. }
  11923. var complete = function (error) {
  11924. var _k;
  11925. intentState.renderTasks.delete(internalRenderTask);
  11926. if (_this._maybeCleanupAfterRender || intentPrint) {
  11927. tslib_1.__classPrivateFieldSet(_this, _PDFPageProxy_pendingCleanup, true, "f");
  11928. }
  11929. tslib_1.__classPrivateFieldGet(_this, _PDFPageProxy_instances, "m", _PDFPageProxy_tryCleanup).call(_this, !intentPrint);
  11930. if (error) {
  11931. internalRenderTask.capability.reject(error);
  11932. _this._abortOperatorList({
  11933. intentState: intentState,
  11934. reason: error instanceof Error ? error : new Error(error)
  11935. });
  11936. }
  11937. else {
  11938. internalRenderTask.capability.resolve();
  11939. }
  11940. if (_this._stats) {
  11941. _this._stats.timeEnd("Rendering");
  11942. _this._stats.timeEnd("Overall");
  11943. if ((_k = globalThis.Stats) === null || _k === void 0 ? void 0 : _k.enabled) {
  11944. globalThis.Stats.add(_this.pageNumber, _this._stats);
  11945. }
  11946. }
  11947. };
  11948. var internalRenderTask = new InternalRenderTask({
  11949. callback: complete,
  11950. params: {
  11951. canvasContext: canvasContext,
  11952. viewport: viewport,
  11953. transform: transform,
  11954. background: background
  11955. },
  11956. objs: this.objs,
  11957. commonObjs: this.commonObjs,
  11958. annotationCanvasMap: annotationCanvasMap,
  11959. operatorList: intentState.operatorList,
  11960. pageIndex: this._pageIndex,
  11961. canvasFactory: this._transport.canvasFactory,
  11962. filterFactory: this._transport.filterFactory,
  11963. useRequestAnimationFrame: !intentPrint,
  11964. pdfBug: this._pdfBug,
  11965. pageColors: pageColors
  11966. });
  11967. (intentState.renderTasks || (intentState.renderTasks = new Set())).add(internalRenderTask);
  11968. var renderTask = internalRenderTask.task;
  11969. Promise.all([intentState.displayReadyCapability.promise, optionalContentConfigPromise]).then(function (_k) {
  11970. var _l;
  11971. var transparency = _k[0], optionalContentConfig = _k[1];
  11972. if (_this.destroyed) {
  11973. complete();
  11974. return;
  11975. }
  11976. (_l = _this._stats) === null || _l === void 0 ? void 0 : _l.time("Rendering");
  11977. if (!(optionalContentConfig.renderingIntent & renderingIntent)) {
  11978. throw new Error("Must use the same `intent`-argument when calling the `PDFPageProxy.render` " + "and `PDFDocumentProxy.getOptionalContentConfig` methods.");
  11979. }
  11980. internalRenderTask.initializeGraphics({
  11981. transparency: transparency,
  11982. optionalContentConfig: optionalContentConfig
  11983. });
  11984. internalRenderTask.operatorListChanged();
  11985. }).catch(complete);
  11986. return renderTask;
  11987. };
  11988. PDFPageProxy.prototype.getOperatorList = function (_k) {
  11989. var _l;
  11990. var _m = _k === void 0 ? {} : _k, _o = _m.intent, intent = _o === void 0 ? "display" : _o, _p = _m.annotationMode, annotationMode = _p === void 0 ? AnnotationMode.ENABLE : _p, _q = _m.printAnnotationStorage, printAnnotationStorage = _q === void 0 ? null : _q;
  11991. function operatorListChanged() {
  11992. if (intentState.operatorList.lastChunk) {
  11993. intentState.opListReadCapability.resolve(intentState.operatorList);
  11994. intentState.renderTasks.delete(opListTask);
  11995. }
  11996. }
  11997. var intentArgs = this._transport.getRenderingIntent(intent, annotationMode, printAnnotationStorage, true);
  11998. var intentState = this._intentStates.get(intentArgs.cacheKey);
  11999. if (!intentState) {
  12000. intentState = Object.create(null);
  12001. this._intentStates.set(intentArgs.cacheKey, intentState);
  12002. }
  12003. var opListTask;
  12004. if (!intentState.opListReadCapability) {
  12005. opListTask = Object.create(null);
  12006. opListTask.operatorListChanged = operatorListChanged;
  12007. intentState.opListReadCapability = Promise.withResolvers();
  12008. (intentState.renderTasks || (intentState.renderTasks = new Set())).add(opListTask);
  12009. intentState.operatorList = {
  12010. fnArray: [],
  12011. argsArray: [],
  12012. lastChunk: false,
  12013. separateAnnots: null
  12014. };
  12015. (_l = this._stats) === null || _l === void 0 ? void 0 : _l.time("Page Request");
  12016. this._pumpOperatorList(intentArgs);
  12017. }
  12018. return intentState.opListReadCapability.promise;
  12019. };
  12020. PDFPageProxy.prototype.streamTextContent = function (_k) {
  12021. var _l = _k === void 0 ? {} : _k, _m = _l.includeMarkedContent, includeMarkedContent = _m === void 0 ? false : _m, _o = _l.disableNormalization, disableNormalization = _o === void 0 ? false : _o;
  12022. var TEXT_CONTENT_CHUNK_SIZE = 100;
  12023. return this._transport.messageHandler.sendWithStream("GetTextContent", {
  12024. pageIndex: this._pageIndex,
  12025. includeMarkedContent: includeMarkedContent === true,
  12026. disableNormalization: disableNormalization === true
  12027. }, {
  12028. highWaterMark: TEXT_CONTENT_CHUNK_SIZE,
  12029. size: function (textContent) {
  12030. return textContent.items.length;
  12031. }
  12032. });
  12033. };
  12034. PDFPageProxy.prototype.getTextContent = function (params) {
  12035. if (params === void 0) { params = {}; }
  12036. if (this._transport._htmlForXfa) {
  12037. return this.getXfa().then(function (xfa) { return XfaText.textContent(xfa); });
  12038. }
  12039. var readableStream = this.streamTextContent(params);
  12040. return new Promise(function (resolve, reject) {
  12041. function pump() {
  12042. reader.read().then(function (_k) {
  12043. var _l;
  12044. var _m;
  12045. var value = _k.value, done = _k.done;
  12046. if (done) {
  12047. resolve(textContent);
  12048. return;
  12049. }
  12050. (_m = textContent.lang) !== null && _m !== void 0 ? _m : (textContent.lang = value.lang);
  12051. Object.assign(textContent.styles, value.styles);
  12052. (_l = textContent.items).push.apply(_l, value.items);
  12053. pump();
  12054. }, reject);
  12055. }
  12056. var reader = readableStream.getReader();
  12057. var textContent = {
  12058. items: [],
  12059. styles: Object.create(null),
  12060. lang: null
  12061. };
  12062. pump();
  12063. });
  12064. };
  12065. PDFPageProxy.prototype.getStructTree = function () {
  12066. return this._transport.getStructTree(this._pageIndex);
  12067. };
  12068. PDFPageProxy.prototype._destroy = function () {
  12069. this.destroyed = true;
  12070. var waitOn = [];
  12071. for (var _i = 0, _k = this._intentStates.values(); _i < _k.length; _i++) {
  12072. var intentState = _k[_i];
  12073. this._abortOperatorList({
  12074. intentState: intentState,
  12075. reason: new Error("Page was destroyed."),
  12076. force: true
  12077. });
  12078. if (intentState.opListReadCapability) {
  12079. continue;
  12080. }
  12081. for (var _l = 0, _m = intentState.renderTasks; _l < _m.length; _l++) {
  12082. var internalRenderTask = _m[_l];
  12083. waitOn.push(internalRenderTask.completed);
  12084. internalRenderTask.cancel();
  12085. }
  12086. }
  12087. this.objs.clear();
  12088. tslib_1.__classPrivateFieldSet(this, _PDFPageProxy_pendingCleanup, false, "f");
  12089. tslib_1.__classPrivateFieldGet(this, _PDFPageProxy_instances, "m", _PDFPageProxy_abortDelayedCleanup).call(this);
  12090. return Promise.all(waitOn);
  12091. };
  12092. PDFPageProxy.prototype.cleanup = function (resetStats) {
  12093. if (resetStats === void 0) { resetStats = false; }
  12094. tslib_1.__classPrivateFieldSet(this, _PDFPageProxy_pendingCleanup, true, "f");
  12095. var success = tslib_1.__classPrivateFieldGet(this, _PDFPageProxy_instances, "m", _PDFPageProxy_tryCleanup).call(this, false);
  12096. if (resetStats && success) {
  12097. this._stats && (this._stats = new StatTimer());
  12098. }
  12099. return success;
  12100. };
  12101. PDFPageProxy.prototype._startRenderPage = function (transparency, cacheKey) {
  12102. var _k, _l;
  12103. var intentState = this._intentStates.get(cacheKey);
  12104. if (!intentState) {
  12105. return;
  12106. }
  12107. (_k = this._stats) === null || _k === void 0 ? void 0 : _k.timeEnd("Page Request");
  12108. (_l = intentState.displayReadyCapability) === null || _l === void 0 ? void 0 : _l.resolve(transparency);
  12109. };
  12110. PDFPageProxy.prototype._renderPageChunk = function (operatorListChunk, intentState) {
  12111. for (var i = 0, ii = operatorListChunk.length; i < ii; i++) {
  12112. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  12113. intentState.operatorList.argsArray.push(operatorListChunk.argsArray[i]);
  12114. }
  12115. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  12116. intentState.operatorList.separateAnnots = operatorListChunk.separateAnnots;
  12117. for (var _i = 0, _k = intentState.renderTasks; _i < _k.length; _i++) {
  12118. var internalRenderTask = _k[_i];
  12119. internalRenderTask.operatorListChanged();
  12120. }
  12121. if (operatorListChunk.lastChunk) {
  12122. tslib_1.__classPrivateFieldGet(this, _PDFPageProxy_instances, "m", _PDFPageProxy_tryCleanup).call(this, true);
  12123. }
  12124. };
  12125. PDFPageProxy.prototype._pumpOperatorList = function (_k) {
  12126. var _this = this;
  12127. var renderingIntent = _k.renderingIntent, cacheKey = _k.cacheKey, annotationStorageSerializable = _k.annotationStorageSerializable;
  12128. var map = annotationStorageSerializable.map, transfer = annotationStorageSerializable.transfer;
  12129. var readableStream = this._transport.messageHandler.sendWithStream("GetOperatorList", {
  12130. pageIndex: this._pageIndex,
  12131. intent: renderingIntent,
  12132. cacheKey: cacheKey,
  12133. annotationStorage: map
  12134. }, transfer);
  12135. var reader = readableStream.getReader();
  12136. var intentState = this._intentStates.get(cacheKey);
  12137. intentState.streamReader = reader;
  12138. var pump = function () {
  12139. reader.read().then(function (_k) {
  12140. var value = _k.value, done = _k.done;
  12141. if (done) {
  12142. intentState.streamReader = null;
  12143. return;
  12144. }
  12145. if (_this._transport.destroyed) {
  12146. return;
  12147. }
  12148. _this._renderPageChunk(value, intentState);
  12149. pump();
  12150. }, function (reason) {
  12151. intentState.streamReader = null;
  12152. if (_this._transport.destroyed) {
  12153. return;
  12154. }
  12155. if (intentState.operatorList) {
  12156. intentState.operatorList.lastChunk = true;
  12157. for (var _i = 0, _k = intentState.renderTasks; _i < _k.length; _i++) {
  12158. var internalRenderTask = _k[_i];
  12159. internalRenderTask.operatorListChanged();
  12160. }
  12161. tslib_1.__classPrivateFieldGet(_this, _PDFPageProxy_instances, "m", _PDFPageProxy_tryCleanup).call(_this, true);
  12162. }
  12163. if (intentState.displayReadyCapability) {
  12164. intentState.displayReadyCapability.reject(reason);
  12165. }
  12166. else if (intentState.opListReadCapability) {
  12167. intentState.opListReadCapability.reject(reason);
  12168. }
  12169. else {
  12170. throw reason;
  12171. }
  12172. });
  12173. };
  12174. pump();
  12175. };
  12176. PDFPageProxy.prototype._abortOperatorList = function (_k) {
  12177. var _this = this;
  12178. var intentState = _k.intentState, reason = _k.reason, _l = _k.force, force = _l === void 0 ? false : _l;
  12179. if (!intentState.streamReader) {
  12180. return;
  12181. }
  12182. if (intentState.streamReaderCancelTimeout) {
  12183. clearTimeout(intentState.streamReaderCancelTimeout);
  12184. intentState.streamReaderCancelTimeout = null;
  12185. }
  12186. if (!force) {
  12187. if (intentState.renderTasks.size > 0) {
  12188. return;
  12189. }
  12190. if (reason instanceof RenderingCancelledException) {
  12191. var delay = RENDERING_CANCELLED_TIMEOUT;
  12192. if (reason.extraDelay > 0 && reason.extraDelay < 1000) {
  12193. delay += reason.extraDelay;
  12194. }
  12195. intentState.streamReaderCancelTimeout = setTimeout(function () {
  12196. intentState.streamReaderCancelTimeout = null;
  12197. _this._abortOperatorList({
  12198. intentState: intentState,
  12199. reason: reason,
  12200. force: true
  12201. });
  12202. }, delay);
  12203. return;
  12204. }
  12205. }
  12206. intentState.streamReader.cancel(new AbortException(reason.message)).catch(function () { });
  12207. intentState.streamReader = null;
  12208. if (this._transport.destroyed) {
  12209. return;
  12210. }
  12211. for (var _i = 0, _m = this._intentStates; _i < _m.length; _i++) {
  12212. var _o = _m[_i], curCacheKey = _o[0], curIntentState = _o[1];
  12213. if (curIntentState === intentState) {
  12214. this._intentStates.delete(curCacheKey);
  12215. break;
  12216. }
  12217. }
  12218. this.cleanup();
  12219. };
  12220. Object.defineProperty(PDFPageProxy.prototype, "stats", {
  12221. get: function () {
  12222. return this._stats;
  12223. },
  12224. enumerable: false,
  12225. configurable: true
  12226. });
  12227. return PDFPageProxy;
  12228. }());
  12229. _PDFPageProxy_delayedCleanupTimeout = new WeakMap(), _PDFPageProxy_pendingCleanup = new WeakMap(), _PDFPageProxy_instances = new WeakSet(), _PDFPageProxy_tryCleanup = function _PDFPageProxy_tryCleanup(delayed) {
  12230. var _this = this;
  12231. if (delayed === void 0) { delayed = false; }
  12232. tslib_1.__classPrivateFieldGet(this, _PDFPageProxy_instances, "m", _PDFPageProxy_abortDelayedCleanup).call(this);
  12233. if (!tslib_1.__classPrivateFieldGet(this, _PDFPageProxy_pendingCleanup, "f") || this.destroyed) {
  12234. return false;
  12235. }
  12236. if (delayed) {
  12237. tslib_1.__classPrivateFieldSet(this, _PDFPageProxy_delayedCleanupTimeout, setTimeout(function () {
  12238. tslib_1.__classPrivateFieldSet(_this, _PDFPageProxy_delayedCleanupTimeout, null, "f");
  12239. tslib_1.__classPrivateFieldGet(_this, _PDFPageProxy_instances, "m", _PDFPageProxy_tryCleanup).call(_this, false);
  12240. }, DELAYED_CLEANUP_TIMEOUT), "f");
  12241. return false;
  12242. }
  12243. for (var _i = 0, _k = this._intentStates.values(); _i < _k.length; _i++) {
  12244. var _l = _k[_i], renderTasks = _l.renderTasks, operatorList = _l.operatorList;
  12245. if (renderTasks.size > 0 || !operatorList.lastChunk) {
  12246. return false;
  12247. }
  12248. }
  12249. this._intentStates.clear();
  12250. this.objs.clear();
  12251. tslib_1.__classPrivateFieldSet(this, _PDFPageProxy_pendingCleanup, false, "f");
  12252. return true;
  12253. }, _PDFPageProxy_abortDelayedCleanup = function _PDFPageProxy_abortDelayedCleanup() {
  12254. if (tslib_1.__classPrivateFieldGet(this, _PDFPageProxy_delayedCleanupTimeout, "f")) {
  12255. clearTimeout(tslib_1.__classPrivateFieldGet(this, _PDFPageProxy_delayedCleanupTimeout, "f"));
  12256. tslib_1.__classPrivateFieldSet(this, _PDFPageProxy_delayedCleanupTimeout, null, "f");
  12257. }
  12258. };
  12259. var LoopbackPort = /** @class */ (function () {
  12260. function LoopbackPort() {
  12261. _LoopbackPort_listeners.set(this, new Set());
  12262. _LoopbackPort_deferred.set(this, Promise.resolve());
  12263. }
  12264. LoopbackPort.prototype.postMessage = function (obj, transfer) {
  12265. var _this = this;
  12266. var event = {
  12267. data: structuredClone(obj, transfer ? {
  12268. transfer: transfer
  12269. } : null)
  12270. };
  12271. tslib_1.__classPrivateFieldGet(this, _LoopbackPort_deferred, "f").then(function () {
  12272. for (var _i = 0, _k = tslib_1.__classPrivateFieldGet(_this, _LoopbackPort_listeners, "f"); _i < _k.length; _i++) {
  12273. var listener = _k[_i];
  12274. listener.call(_this, event);
  12275. }
  12276. });
  12277. };
  12278. LoopbackPort.prototype.addEventListener = function (name, listener) {
  12279. tslib_1.__classPrivateFieldGet(this, _LoopbackPort_listeners, "f").add(listener);
  12280. };
  12281. LoopbackPort.prototype.removeEventListener = function (name, listener) {
  12282. tslib_1.__classPrivateFieldGet(this, _LoopbackPort_listeners, "f").delete(listener);
  12283. };
  12284. LoopbackPort.prototype.terminate = function () {
  12285. tslib_1.__classPrivateFieldGet(this, _LoopbackPort_listeners, "f").clear();
  12286. };
  12287. return LoopbackPort;
  12288. }());
  12289. _LoopbackPort_listeners = new WeakMap(), _LoopbackPort_deferred = new WeakMap();
  12290. var PDFWorkerUtil = {
  12291. isWorkerDisabled: false,
  12292. fakeWorkerId: 0
  12293. };
  12294. {
  12295. if (isNodeJS) {
  12296. PDFWorkerUtil.isWorkerDisabled = true;
  12297. GlobalWorkerOptions.workerSrc || (GlobalWorkerOptions.workerSrc = "./pdf.worker.mjs");
  12298. }
  12299. PDFWorkerUtil.isSameOrigin = function (baseUrl, otherUrl) {
  12300. var base;
  12301. try {
  12302. base = new URL(baseUrl);
  12303. if (!base.origin || base.origin === "null") {
  12304. return false;
  12305. }
  12306. }
  12307. catch (_k) {
  12308. return false;
  12309. }
  12310. var other = new URL(otherUrl, base);
  12311. return base.origin === other.origin;
  12312. };
  12313. PDFWorkerUtil.createCDNWrapper = function (url) {
  12314. var wrapper = "await import(\"".concat(url, "\");");
  12315. return URL.createObjectURL(new Blob([wrapper], {
  12316. type: "text/javascript"
  12317. }));
  12318. };
  12319. }
  12320. var PDFWorker = /** @class */ (function () {
  12321. function PDFWorker(_k) {
  12322. var _l = _k === void 0 ? {} : _k, _m = _l.name, name = _m === void 0 ? null : _m, _o = _l.port, port = _o === void 0 ? null : _o, _p = _l.verbosity, verbosity = _p === void 0 ? getVerbosityLevel() : _p;
  12323. var _q;
  12324. var _r;
  12325. this.name = name;
  12326. this.destroyed = false;
  12327. this.verbosity = verbosity;
  12328. this._readyCapability = Promise.withResolvers();
  12329. this._port = null;
  12330. this._webWorker = null;
  12331. this._messageHandler = null;
  12332. if (port) {
  12333. if ((_q = tslib_1.__classPrivateFieldGet(PDFWorker, _c, "f", _PDFWorker_workerPorts)) === null || _q === void 0 ? void 0 : _q.has(port)) {
  12334. throw new Error("Cannot use more than one PDFWorker per port.");
  12335. }
  12336. (tslib_1.__classPrivateFieldSet(_r = PDFWorker, _c, tslib_1.__classPrivateFieldGet(_r, _c, "f", _PDFWorker_workerPorts) || new WeakMap(), "f", _PDFWorker_workerPorts)).set(port, this);
  12337. this._initializeFromPort(port);
  12338. return;
  12339. }
  12340. this._initialize();
  12341. }
  12342. Object.defineProperty(PDFWorker.prototype, "promise", {
  12343. get: function () {
  12344. if (isNodeJS) {
  12345. return Promise.all([NodePackages.promise, this._readyCapability.promise]);
  12346. }
  12347. return this._readyCapability.promise;
  12348. },
  12349. enumerable: false,
  12350. configurable: true
  12351. });
  12352. Object.defineProperty(PDFWorker.prototype, "port", {
  12353. get: function () {
  12354. return this._port;
  12355. },
  12356. enumerable: false,
  12357. configurable: true
  12358. });
  12359. Object.defineProperty(PDFWorker.prototype, "messageHandler", {
  12360. get: function () {
  12361. return this._messageHandler;
  12362. },
  12363. enumerable: false,
  12364. configurable: true
  12365. });
  12366. PDFWorker.prototype._initializeFromPort = function (port) {
  12367. this._port = port;
  12368. this._messageHandler = new MessageHandler("main", "worker", port);
  12369. this._messageHandler.on("ready", function () { });
  12370. this._readyCapability.resolve();
  12371. this._messageHandler.send("configure", {
  12372. verbosity: this.verbosity
  12373. });
  12374. };
  12375. PDFWorker.prototype._initialize = function () {
  12376. var _this = this;
  12377. if (!PDFWorkerUtil.isWorkerDisabled && !tslib_1.__classPrivateFieldGet(PDFWorker, _c, "a", _PDFWorker_mainThreadWorkerMessageHandler_get)) {
  12378. var workerSrc = PDFWorker.workerSrc;
  12379. try {
  12380. if (!PDFWorkerUtil.isSameOrigin(window.location.href, workerSrc)) {
  12381. workerSrc = PDFWorkerUtil.createCDNWrapper(new URL(workerSrc, window.location).href);
  12382. }
  12383. var worker_1 = new Worker(workerSrc, {
  12384. type: "module"
  12385. });
  12386. var messageHandler_1 = new MessageHandler("main", "worker", worker_1);
  12387. var terminateEarly_1 = function () {
  12388. worker_1.removeEventListener("error", onWorkerError_1);
  12389. messageHandler_1.destroy();
  12390. worker_1.terminate();
  12391. if (_this.destroyed) {
  12392. _this._readyCapability.reject(new Error("Worker was destroyed"));
  12393. }
  12394. else {
  12395. _this._setupFakeWorker();
  12396. }
  12397. };
  12398. var onWorkerError_1 = function () {
  12399. if (!_this._webWorker) {
  12400. terminateEarly_1();
  12401. }
  12402. };
  12403. worker_1.addEventListener("error", onWorkerError_1);
  12404. messageHandler_1.on("test", function (data) {
  12405. worker_1.removeEventListener("error", onWorkerError_1);
  12406. if (_this.destroyed) {
  12407. terminateEarly_1();
  12408. return;
  12409. }
  12410. if (data) {
  12411. _this._messageHandler = messageHandler_1;
  12412. _this._port = worker_1;
  12413. _this._webWorker = worker_1;
  12414. _this._readyCapability.resolve();
  12415. messageHandler_1.send("configure", {
  12416. verbosity: _this.verbosity
  12417. });
  12418. }
  12419. else {
  12420. _this._setupFakeWorker();
  12421. messageHandler_1.destroy();
  12422. worker_1.terminate();
  12423. }
  12424. });
  12425. messageHandler_1.on("ready", function (data) {
  12426. worker_1.removeEventListener("error", onWorkerError_1);
  12427. if (_this.destroyed) {
  12428. terminateEarly_1();
  12429. return;
  12430. }
  12431. try {
  12432. sendTest_1();
  12433. }
  12434. catch (_k) {
  12435. _this._setupFakeWorker();
  12436. }
  12437. });
  12438. var sendTest_1 = function () {
  12439. var testObj = new Uint8Array();
  12440. messageHandler_1.send("test", testObj, [testObj.buffer]);
  12441. };
  12442. sendTest_1();
  12443. return;
  12444. }
  12445. catch (_k) {
  12446. info("The worker has been disabled.");
  12447. }
  12448. }
  12449. this._setupFakeWorker();
  12450. };
  12451. PDFWorker.prototype._setupFakeWorker = function () {
  12452. var _this = this;
  12453. if (!PDFWorkerUtil.isWorkerDisabled) {
  12454. warn("Setting up fake worker.");
  12455. PDFWorkerUtil.isWorkerDisabled = true;
  12456. }
  12457. PDFWorker._setupFakeWorkerGlobal.then(function (WorkerMessageHandler) {
  12458. if (_this.destroyed) {
  12459. _this._readyCapability.reject(new Error("Worker was destroyed"));
  12460. return;
  12461. }
  12462. var port = new LoopbackPort();
  12463. _this._port = port;
  12464. var id = "fake".concat(PDFWorkerUtil.fakeWorkerId++);
  12465. var workerHandler = new MessageHandler(id + "_worker", id, port);
  12466. WorkerMessageHandler.setup(workerHandler, port);
  12467. var messageHandler = new MessageHandler(id, id + "_worker", port);
  12468. _this._messageHandler = messageHandler;
  12469. _this._readyCapability.resolve();
  12470. messageHandler.send("configure", {
  12471. verbosity: _this.verbosity
  12472. });
  12473. }).catch(function (reason) {
  12474. _this._readyCapability.reject(new Error("Setting up fake worker failed: \"".concat(reason.message, "\".")));
  12475. });
  12476. };
  12477. PDFWorker.prototype.destroy = function () {
  12478. var _k;
  12479. this.destroyed = true;
  12480. if (this._webWorker) {
  12481. this._webWorker.terminate();
  12482. this._webWorker = null;
  12483. }
  12484. (_k = tslib_1.__classPrivateFieldGet(PDFWorker, _c, "f", _PDFWorker_workerPorts)) === null || _k === void 0 ? void 0 : _k.delete(this._port);
  12485. this._port = null;
  12486. if (this._messageHandler) {
  12487. this._messageHandler.destroy();
  12488. this._messageHandler = null;
  12489. }
  12490. };
  12491. PDFWorker.fromPort = function (params) {
  12492. var _k;
  12493. if (!(params === null || params === void 0 ? void 0 : params.port)) {
  12494. throw new Error("PDFWorker.fromPort - invalid method signature.");
  12495. }
  12496. var cachedPort = (_k = tslib_1.__classPrivateFieldGet(this, _c, "f", _PDFWorker_workerPorts)) === null || _k === void 0 ? void 0 : _k.get(params.port);
  12497. if (cachedPort) {
  12498. if (cachedPort._pendingDestroy) {
  12499. throw new Error("PDFWorker.fromPort - the worker is being destroyed.\n" + "Please remember to await `PDFDocumentLoadingTask.destroy()`-calls.");
  12500. }
  12501. return cachedPort;
  12502. }
  12503. return new PDFWorker(params);
  12504. };
  12505. Object.defineProperty(PDFWorker, "workerSrc", {
  12506. get: function () {
  12507. if (GlobalWorkerOptions.workerSrc) {
  12508. return GlobalWorkerOptions.workerSrc;
  12509. }
  12510. throw new Error('No "GlobalWorkerOptions.workerSrc" specified.');
  12511. },
  12512. enumerable: false,
  12513. configurable: true
  12514. });
  12515. Object.defineProperty(PDFWorker, "_setupFakeWorkerGlobal", {
  12516. get: function () {
  12517. var _this = this;
  12518. var loader = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
  12519. var worker;
  12520. return tslib_1.__generator(this, function (_k) {
  12521. var _l;
  12522. switch (_k.label) {
  12523. case 0:
  12524. if (tslib_1.__classPrivateFieldGet(this, _c, "a", _PDFWorker_mainThreadWorkerMessageHandler_get)) {
  12525. return [2 /*return*/, tslib_1.__classPrivateFieldGet(this, _c, "a", _PDFWorker_mainThreadWorkerMessageHandler_get)];
  12526. }
  12527. return [4 /*yield*/, (_l = this.workerSrc, Promise.resolve().then(function () { return tslib_1.__importStar(require(_l)); }))];
  12528. case 1:
  12529. worker = _k.sent();
  12530. return [2 /*return*/, worker.WorkerMessageHandler];
  12531. }
  12532. });
  12533. }); };
  12534. return shadow(this, "_setupFakeWorkerGlobal", loader());
  12535. },
  12536. enumerable: false,
  12537. configurable: true
  12538. });
  12539. return PDFWorker;
  12540. }());
  12541. _c = PDFWorker, _PDFWorker_mainThreadWorkerMessageHandler_get = function _PDFWorker_mainThreadWorkerMessageHandler_get() {
  12542. var _k;
  12543. try {
  12544. return ((_k = globalThis.pdfjsWorker) === null || _k === void 0 ? void 0 : _k.WorkerMessageHandler) || null;
  12545. }
  12546. catch (_l) {
  12547. return null;
  12548. }
  12549. };
  12550. _PDFWorker_workerPorts = { value: void 0 };
  12551. var WorkerTransport = /** @class */ (function () {
  12552. function WorkerTransport(messageHandler, loadingTask, networkStream, params, factory) {
  12553. _WorkerTransport_instances.add(this);
  12554. _WorkerTransport_methodPromises.set(this, new Map());
  12555. _WorkerTransport_pageCache.set(this, new Map());
  12556. _WorkerTransport_pagePromises.set(this, new Map());
  12557. _WorkerTransport_pageRefCache.set(this, new Map());
  12558. _WorkerTransport_passwordCapability.set(this, null);
  12559. this.messageHandler = messageHandler;
  12560. this.loadingTask = loadingTask;
  12561. this.commonObjs = new PDFObjects();
  12562. this.fontLoader = new FontLoader({
  12563. ownerDocument: params.ownerDocument,
  12564. styleElement: params.styleElement
  12565. });
  12566. this.loadingParams = params.loadingParams;
  12567. this._params = params;
  12568. this.canvasFactory = factory.canvasFactory;
  12569. this.filterFactory = factory.filterFactory;
  12570. this.cMapReaderFactory = factory.cMapReaderFactory;
  12571. this.standardFontDataFactory = factory.standardFontDataFactory;
  12572. this.destroyed = false;
  12573. this.destroyCapability = null;
  12574. this._networkStream = networkStream;
  12575. this._fullReader = null;
  12576. this._lastProgress = null;
  12577. this.downloadInfoCapability = Promise.withResolvers();
  12578. this.setupMessageHandler();
  12579. }
  12580. Object.defineProperty(WorkerTransport.prototype, "annotationStorage", {
  12581. get: function () {
  12582. return shadow(this, "annotationStorage", new AnnotationStorage());
  12583. },
  12584. enumerable: false,
  12585. configurable: true
  12586. });
  12587. WorkerTransport.prototype.getRenderingIntent = function (intent, annotationMode, printAnnotationStorage, isOpList) {
  12588. if (annotationMode === void 0) { annotationMode = AnnotationMode.ENABLE; }
  12589. if (printAnnotationStorage === void 0) { printAnnotationStorage = null; }
  12590. if (isOpList === void 0) { isOpList = false; }
  12591. var renderingIntent = RenderingIntentFlag.DISPLAY;
  12592. var annotationStorageSerializable = SerializableEmpty;
  12593. switch (intent) {
  12594. case "any":
  12595. renderingIntent = RenderingIntentFlag.ANY;
  12596. break;
  12597. case "display":
  12598. break;
  12599. case "print":
  12600. renderingIntent = RenderingIntentFlag.PRINT;
  12601. break;
  12602. default:
  12603. warn("getRenderingIntent - invalid intent: ".concat(intent));
  12604. }
  12605. switch (annotationMode) {
  12606. case AnnotationMode.DISABLE:
  12607. renderingIntent += RenderingIntentFlag.ANNOTATIONS_DISABLE;
  12608. break;
  12609. case AnnotationMode.ENABLE:
  12610. break;
  12611. case AnnotationMode.ENABLE_FORMS:
  12612. renderingIntent += RenderingIntentFlag.ANNOTATIONS_FORMS;
  12613. break;
  12614. case AnnotationMode.ENABLE_STORAGE:
  12615. renderingIntent += RenderingIntentFlag.ANNOTATIONS_STORAGE;
  12616. var annotationStorage = renderingIntent & RenderingIntentFlag.PRINT && printAnnotationStorage instanceof PrintAnnotationStorage ? printAnnotationStorage : this.annotationStorage;
  12617. annotationStorageSerializable = annotationStorage.serializable;
  12618. break;
  12619. default:
  12620. warn("getRenderingIntent - invalid annotationMode: ".concat(annotationMode));
  12621. }
  12622. if (isOpList) {
  12623. renderingIntent += RenderingIntentFlag.OPLIST;
  12624. }
  12625. return {
  12626. renderingIntent: renderingIntent,
  12627. cacheKey: "".concat(renderingIntent, "_").concat(annotationStorageSerializable.hash),
  12628. annotationStorageSerializable: annotationStorageSerializable
  12629. };
  12630. };
  12631. WorkerTransport.prototype.destroy = function () {
  12632. var _this = this;
  12633. var _k;
  12634. if (this.destroyCapability) {
  12635. return this.destroyCapability.promise;
  12636. }
  12637. this.destroyed = true;
  12638. this.destroyCapability = Promise.withResolvers();
  12639. (_k = tslib_1.__classPrivateFieldGet(this, _WorkerTransport_passwordCapability, "f")) === null || _k === void 0 ? void 0 : _k.reject(new Error("Worker was destroyed during onPassword callback"));
  12640. var waitOn = [];
  12641. for (var _i = 0, _l = tslib_1.__classPrivateFieldGet(this, _WorkerTransport_pageCache, "f").values(); _i < _l.length; _i++) {
  12642. var page = _l[_i];
  12643. waitOn.push(page._destroy());
  12644. }
  12645. tslib_1.__classPrivateFieldGet(this, _WorkerTransport_pageCache, "f").clear();
  12646. tslib_1.__classPrivateFieldGet(this, _WorkerTransport_pagePromises, "f").clear();
  12647. tslib_1.__classPrivateFieldGet(this, _WorkerTransport_pageRefCache, "f").clear();
  12648. if (this.hasOwnProperty("annotationStorage")) {
  12649. this.annotationStorage.resetModified();
  12650. }
  12651. var terminated = this.messageHandler.sendWithPromise("Terminate", null);
  12652. waitOn.push(terminated);
  12653. Promise.all(waitOn).then(function () {
  12654. var _k;
  12655. _this.commonObjs.clear();
  12656. _this.fontLoader.clear();
  12657. tslib_1.__classPrivateFieldGet(_this, _WorkerTransport_methodPromises, "f").clear();
  12658. _this.filterFactory.destroy();
  12659. TextLayer.cleanup();
  12660. (_k = _this._networkStream) === null || _k === void 0 ? void 0 : _k.cancelAllRequests(new AbortException("Worker was terminated."));
  12661. if (_this.messageHandler) {
  12662. _this.messageHandler.destroy();
  12663. _this.messageHandler = null;
  12664. }
  12665. _this.destroyCapability.resolve();
  12666. }, this.destroyCapability.reject);
  12667. return this.destroyCapability.promise;
  12668. };
  12669. WorkerTransport.prototype.setupMessageHandler = function () {
  12670. var _this = this;
  12671. var _k = this, messageHandler = _k.messageHandler, loadingTask = _k.loadingTask;
  12672. messageHandler.on("GetReader", function (data, sink) {
  12673. assert(_this._networkStream, "GetReader - no `IPDFStream` instance available.");
  12674. _this._fullReader = _this._networkStream.getFullReader();
  12675. _this._fullReader.onProgress = function (evt) {
  12676. _this._lastProgress = {
  12677. loaded: evt.loaded,
  12678. total: evt.total
  12679. };
  12680. };
  12681. sink.onPull = function () {
  12682. _this._fullReader.read().then(function (_k) {
  12683. var value = _k.value, done = _k.done;
  12684. if (done) {
  12685. sink.close();
  12686. return;
  12687. }
  12688. assert(value instanceof ArrayBuffer, "GetReader - expected an ArrayBuffer.");
  12689. sink.enqueue(new Uint8Array(value), 1, [value]);
  12690. }).catch(function (reason) {
  12691. sink.error(reason);
  12692. });
  12693. };
  12694. sink.onCancel = function (reason) {
  12695. _this._fullReader.cancel(reason);
  12696. sink.ready.catch(function (readyReason) {
  12697. if (_this.destroyed) {
  12698. return;
  12699. }
  12700. throw readyReason;
  12701. });
  12702. };
  12703. });
  12704. messageHandler.on("ReaderHeadersReady", function (data) {
  12705. var headersCapability = Promise.withResolvers();
  12706. var fullReader = _this._fullReader;
  12707. fullReader.headersReady.then(function () {
  12708. var _k;
  12709. if (!fullReader.isStreamingSupported || !fullReader.isRangeSupported) {
  12710. if (_this._lastProgress) {
  12711. (_k = loadingTask.onProgress) === null || _k === void 0 ? void 0 : _k.call(loadingTask, _this._lastProgress);
  12712. }
  12713. fullReader.onProgress = function (evt) {
  12714. var _k;
  12715. (_k = loadingTask.onProgress) === null || _k === void 0 ? void 0 : _k.call(loadingTask, {
  12716. loaded: evt.loaded,
  12717. total: evt.total
  12718. });
  12719. };
  12720. }
  12721. headersCapability.resolve({
  12722. isStreamingSupported: fullReader.isStreamingSupported,
  12723. isRangeSupported: fullReader.isRangeSupported,
  12724. contentLength: fullReader.contentLength
  12725. });
  12726. }, headersCapability.reject);
  12727. return headersCapability.promise;
  12728. });
  12729. messageHandler.on("GetRangeReader", function (data, sink) {
  12730. assert(_this._networkStream, "GetRangeReader - no `IPDFStream` instance available.");
  12731. var rangeReader = _this._networkStream.getRangeReader(data.begin, data.end);
  12732. if (!rangeReader) {
  12733. sink.close();
  12734. return;
  12735. }
  12736. sink.onPull = function () {
  12737. rangeReader.read().then(function (_k) {
  12738. var value = _k.value, done = _k.done;
  12739. if (done) {
  12740. sink.close();
  12741. return;
  12742. }
  12743. assert(value instanceof ArrayBuffer, "GetRangeReader - expected an ArrayBuffer.");
  12744. sink.enqueue(new Uint8Array(value), 1, [value]);
  12745. }).catch(function (reason) {
  12746. sink.error(reason);
  12747. });
  12748. };
  12749. sink.onCancel = function (reason) {
  12750. rangeReader.cancel(reason);
  12751. sink.ready.catch(function (readyReason) {
  12752. if (_this.destroyed) {
  12753. return;
  12754. }
  12755. throw readyReason;
  12756. });
  12757. };
  12758. });
  12759. messageHandler.on("GetDoc", function (_k) {
  12760. var pdfInfo = _k.pdfInfo;
  12761. _this._numPages = pdfInfo.numPages;
  12762. _this._htmlForXfa = pdfInfo.htmlForXfa;
  12763. delete pdfInfo.htmlForXfa;
  12764. loadingTask._capability.resolve(new PDFDocumentProxy(pdfInfo, _this));
  12765. });
  12766. messageHandler.on("DocException", function (ex) {
  12767. var reason;
  12768. switch (ex.name) {
  12769. case "PasswordException":
  12770. reason = new PasswordException(ex.message, ex.code);
  12771. break;
  12772. case "InvalidPDFException":
  12773. reason = new InvalidPDFException(ex.message);
  12774. break;
  12775. case "MissingPDFException":
  12776. reason = new MissingPDFException(ex.message);
  12777. break;
  12778. case "UnexpectedResponseException":
  12779. reason = new UnexpectedResponseException(ex.message, ex.status);
  12780. break;
  12781. case "UnknownErrorException":
  12782. reason = new UnknownErrorException(ex.message, ex.details);
  12783. break;
  12784. default:
  12785. unreachable("DocException - expected a valid Error.");
  12786. }
  12787. loadingTask._capability.reject(reason);
  12788. });
  12789. messageHandler.on("PasswordRequest", function (exception) {
  12790. tslib_1.__classPrivateFieldSet(_this, _WorkerTransport_passwordCapability, Promise.withResolvers(), "f");
  12791. if (loadingTask.onPassword) {
  12792. var updatePassword = function (password) {
  12793. if (password instanceof Error) {
  12794. tslib_1.__classPrivateFieldGet(_this, _WorkerTransport_passwordCapability, "f").reject(password);
  12795. }
  12796. else {
  12797. tslib_1.__classPrivateFieldGet(_this, _WorkerTransport_passwordCapability, "f").resolve({
  12798. password: password
  12799. });
  12800. }
  12801. };
  12802. try {
  12803. loadingTask.onPassword(updatePassword, exception.code);
  12804. }
  12805. catch (ex) {
  12806. tslib_1.__classPrivateFieldGet(_this, _WorkerTransport_passwordCapability, "f").reject(ex);
  12807. }
  12808. }
  12809. else {
  12810. tslib_1.__classPrivateFieldGet(_this, _WorkerTransport_passwordCapability, "f").reject(new PasswordException(exception.message, exception.code));
  12811. }
  12812. return tslib_1.__classPrivateFieldGet(_this, _WorkerTransport_passwordCapability, "f").promise;
  12813. });
  12814. messageHandler.on("DataLoaded", function (data) {
  12815. var _k;
  12816. (_k = loadingTask.onProgress) === null || _k === void 0 ? void 0 : _k.call(loadingTask, {
  12817. loaded: data.length,
  12818. total: data.length
  12819. });
  12820. _this.downloadInfoCapability.resolve(data);
  12821. });
  12822. messageHandler.on("StartRenderPage", function (data) {
  12823. if (_this.destroyed) {
  12824. return;
  12825. }
  12826. var page = tslib_1.__classPrivateFieldGet(_this, _WorkerTransport_pageCache, "f").get(data.pageIndex);
  12827. page._startRenderPage(data.transparency, data.cacheKey);
  12828. });
  12829. messageHandler.on("commonobj", function (_k) {
  12830. var _l;
  12831. var id = _k[0], type = _k[1], exportedData = _k[2];
  12832. if (_this.destroyed) {
  12833. return null;
  12834. }
  12835. if (_this.commonObjs.has(id)) {
  12836. return null;
  12837. }
  12838. switch (type) {
  12839. case "Font":
  12840. var _m = _this._params, disableFontFace = _m.disableFontFace, fontExtraProperties_1 = _m.fontExtraProperties, pdfBug = _m.pdfBug;
  12841. if ("error" in exportedData) {
  12842. var exportedError = exportedData.error;
  12843. warn("Error during font loading: ".concat(exportedError));
  12844. _this.commonObjs.resolve(id, exportedError);
  12845. break;
  12846. }
  12847. var inspectFont = pdfBug && ((_l = globalThis.FontInspector) === null || _l === void 0 ? void 0 : _l.enabled) ? function (font, url) { return globalThis.FontInspector.fontAdded(font, url); } : null;
  12848. var font_1 = new FontFaceObject(exportedData, {
  12849. disableFontFace: disableFontFace,
  12850. inspectFont: inspectFont
  12851. });
  12852. _this.fontLoader.bind(font_1).catch(function () { return messageHandler.sendWithPromise("FontFallback", {
  12853. id: id
  12854. }); }).finally(function () {
  12855. if (!fontExtraProperties_1 && font_1.data) {
  12856. font_1.data = null;
  12857. }
  12858. _this.commonObjs.resolve(id, font_1);
  12859. });
  12860. break;
  12861. case "CopyLocalImage":
  12862. var imageRef = exportedData.imageRef;
  12863. assert(imageRef, "The imageRef must be defined.");
  12864. for (var _i = 0, _o = tslib_1.__classPrivateFieldGet(_this, _WorkerTransport_pageCache, "f").values(); _i < _o.length; _i++) {
  12865. var pageProxy = _o[_i];
  12866. for (var _p = 0, _q = pageProxy.objs; _p < _q.length; _p++) {
  12867. var _r = _q[_p], data = _r[1];
  12868. if ((data === null || data === void 0 ? void 0 : data.ref) !== imageRef) {
  12869. continue;
  12870. }
  12871. if (!data.dataLen) {
  12872. return null;
  12873. }
  12874. _this.commonObjs.resolve(id, structuredClone(data));
  12875. return data.dataLen;
  12876. }
  12877. }
  12878. break;
  12879. case "FontPath":
  12880. case "Image":
  12881. case "Pattern":
  12882. _this.commonObjs.resolve(id, exportedData);
  12883. break;
  12884. default:
  12885. throw new Error("Got unknown common object type ".concat(type));
  12886. }
  12887. return null;
  12888. });
  12889. messageHandler.on("obj", function (_k) {
  12890. var _l;
  12891. var id = _k[0], pageIndex = _k[1], type = _k[2], imageData = _k[3];
  12892. if (_this.destroyed) {
  12893. return;
  12894. }
  12895. var pageProxy = tslib_1.__classPrivateFieldGet(_this, _WorkerTransport_pageCache, "f").get(pageIndex);
  12896. if (pageProxy.objs.has(id)) {
  12897. return;
  12898. }
  12899. if (pageProxy._intentStates.size === 0) {
  12900. (_l = imageData === null || imageData === void 0 ? void 0 : imageData.bitmap) === null || _l === void 0 ? void 0 : _l.close();
  12901. return;
  12902. }
  12903. switch (type) {
  12904. case "Image":
  12905. pageProxy.objs.resolve(id, imageData);
  12906. if ((imageData === null || imageData === void 0 ? void 0 : imageData.dataLen) > MAX_IMAGE_SIZE_TO_CACHE) {
  12907. pageProxy._maybeCleanupAfterRender = true;
  12908. }
  12909. break;
  12910. case "Pattern":
  12911. pageProxy.objs.resolve(id, imageData);
  12912. break;
  12913. default:
  12914. throw new Error("Got unknown object type ".concat(type));
  12915. }
  12916. });
  12917. messageHandler.on("DocProgress", function (data) {
  12918. var _k;
  12919. if (_this.destroyed) {
  12920. return;
  12921. }
  12922. (_k = loadingTask.onProgress) === null || _k === void 0 ? void 0 : _k.call(loadingTask, {
  12923. loaded: data.loaded,
  12924. total: data.total
  12925. });
  12926. });
  12927. messageHandler.on("FetchBuiltInCMap", function (data) {
  12928. if (_this.destroyed) {
  12929. return Promise.reject(new Error("Worker was destroyed."));
  12930. }
  12931. if (!_this.cMapReaderFactory) {
  12932. return Promise.reject(new Error("CMapReaderFactory not initialized, see the `useWorkerFetch` parameter."));
  12933. }
  12934. return _this.cMapReaderFactory.fetch(data);
  12935. });
  12936. messageHandler.on("FetchStandardFontData", function (data) {
  12937. if (_this.destroyed) {
  12938. return Promise.reject(new Error("Worker was destroyed."));
  12939. }
  12940. if (!_this.standardFontDataFactory) {
  12941. return Promise.reject(new Error("StandardFontDataFactory not initialized, see the `useWorkerFetch` parameter."));
  12942. }
  12943. return _this.standardFontDataFactory.fetch(data);
  12944. });
  12945. };
  12946. WorkerTransport.prototype.getData = function () {
  12947. return this.messageHandler.sendWithPromise("GetData", null);
  12948. };
  12949. WorkerTransport.prototype.saveDocument = function () {
  12950. var _this = this;
  12951. var _k, _l;
  12952. if (this.annotationStorage.size <= 0) {
  12953. warn("saveDocument called while `annotationStorage` is empty, " + "please use the getData-method instead.");
  12954. }
  12955. var _m = this.annotationStorage.serializable, map = _m.map, transfer = _m.transfer;
  12956. return this.messageHandler.sendWithPromise("SaveDocument", {
  12957. isPureXfa: !!this._htmlForXfa,
  12958. numPages: this._numPages,
  12959. annotationStorage: map,
  12960. filename: (_l = (_k = this._fullReader) === null || _k === void 0 ? void 0 : _k.filename) !== null && _l !== void 0 ? _l : null
  12961. }, transfer).finally(function () {
  12962. _this.annotationStorage.resetModified();
  12963. });
  12964. };
  12965. WorkerTransport.prototype.getPage = function (pageNumber) {
  12966. var _this = this;
  12967. if (!Number.isInteger(pageNumber) || pageNumber <= 0 || pageNumber > this._numPages) {
  12968. return Promise.reject(new Error("Invalid page request."));
  12969. }
  12970. var pageIndex = pageNumber - 1, cachedPromise = tslib_1.__classPrivateFieldGet(this, _WorkerTransport_pagePromises, "f").get(pageIndex);
  12971. if (cachedPromise) {
  12972. return cachedPromise;
  12973. }
  12974. var promise = this.messageHandler.sendWithPromise("GetPage", {
  12975. pageIndex: pageIndex
  12976. }).then(function (pageInfo) {
  12977. if (_this.destroyed) {
  12978. throw new Error("Transport destroyed");
  12979. }
  12980. if (pageInfo.refStr) {
  12981. tslib_1.__classPrivateFieldGet(_this, _WorkerTransport_pageRefCache, "f").set(pageInfo.refStr, pageNumber);
  12982. }
  12983. var page = new PDFPageProxy(pageIndex, pageInfo, _this, _this._params.pdfBug);
  12984. tslib_1.__classPrivateFieldGet(_this, _WorkerTransport_pageCache, "f").set(pageIndex, page);
  12985. return page;
  12986. });
  12987. tslib_1.__classPrivateFieldGet(this, _WorkerTransport_pagePromises, "f").set(pageIndex, promise);
  12988. return promise;
  12989. };
  12990. WorkerTransport.prototype.getPageIndex = function (ref) {
  12991. if (!isRefProxy(ref)) {
  12992. return Promise.reject(new Error("Invalid pageIndex request."));
  12993. }
  12994. return this.messageHandler.sendWithPromise("GetPageIndex", {
  12995. num: ref.num,
  12996. gen: ref.gen
  12997. });
  12998. };
  12999. WorkerTransport.prototype.getAnnotations = function (pageIndex, intent) {
  13000. return this.messageHandler.sendWithPromise("GetAnnotations", {
  13001. pageIndex: pageIndex,
  13002. intent: intent
  13003. });
  13004. };
  13005. WorkerTransport.prototype.getFieldObjects = function () {
  13006. return tslib_1.__classPrivateFieldGet(this, _WorkerTransport_instances, "m", _WorkerTransport_cacheSimpleMethod).call(this, "GetFieldObjects");
  13007. };
  13008. WorkerTransport.prototype.hasJSActions = function () {
  13009. return tslib_1.__classPrivateFieldGet(this, _WorkerTransport_instances, "m", _WorkerTransport_cacheSimpleMethod).call(this, "HasJSActions");
  13010. };
  13011. WorkerTransport.prototype.getCalculationOrderIds = function () {
  13012. return this.messageHandler.sendWithPromise("GetCalculationOrderIds", null);
  13013. };
  13014. WorkerTransport.prototype.getDestinations = function () {
  13015. return this.messageHandler.sendWithPromise("GetDestinations", null);
  13016. };
  13017. WorkerTransport.prototype.getDestination = function (id) {
  13018. if (typeof id !== "string") {
  13019. return Promise.reject(new Error("Invalid destination request."));
  13020. }
  13021. return this.messageHandler.sendWithPromise("GetDestination", {
  13022. id: id
  13023. });
  13024. };
  13025. WorkerTransport.prototype.getPageLabels = function () {
  13026. return this.messageHandler.sendWithPromise("GetPageLabels", null);
  13027. };
  13028. WorkerTransport.prototype.getPageLayout = function () {
  13029. return this.messageHandler.sendWithPromise("GetPageLayout", null);
  13030. };
  13031. WorkerTransport.prototype.getPageMode = function () {
  13032. return this.messageHandler.sendWithPromise("GetPageMode", null);
  13033. };
  13034. WorkerTransport.prototype.getViewerPreferences = function () {
  13035. return this.messageHandler.sendWithPromise("GetViewerPreferences", null);
  13036. };
  13037. WorkerTransport.prototype.getOpenAction = function () {
  13038. return this.messageHandler.sendWithPromise("GetOpenAction", null);
  13039. };
  13040. WorkerTransport.prototype.getAttachments = function () {
  13041. return this.messageHandler.sendWithPromise("GetAttachments", null);
  13042. };
  13043. WorkerTransport.prototype.getDocJSActions = function () {
  13044. return tslib_1.__classPrivateFieldGet(this, _WorkerTransport_instances, "m", _WorkerTransport_cacheSimpleMethod).call(this, "GetDocJSActions");
  13045. };
  13046. WorkerTransport.prototype.getPageJSActions = function (pageIndex) {
  13047. return this.messageHandler.sendWithPromise("GetPageJSActions", {
  13048. pageIndex: pageIndex
  13049. });
  13050. };
  13051. WorkerTransport.prototype.getStructTree = function (pageIndex) {
  13052. return this.messageHandler.sendWithPromise("GetStructTree", {
  13053. pageIndex: pageIndex
  13054. });
  13055. };
  13056. WorkerTransport.prototype.getOutline = function () {
  13057. return this.messageHandler.sendWithPromise("GetOutline", null);
  13058. };
  13059. WorkerTransport.prototype.getOptionalContentConfig = function (renderingIntent) {
  13060. return tslib_1.__classPrivateFieldGet(this, _WorkerTransport_instances, "m", _WorkerTransport_cacheSimpleMethod).call(this, "GetOptionalContentConfig").then(function (data) { return new OptionalContentConfig(data, renderingIntent); });
  13061. };
  13062. WorkerTransport.prototype.getPermissions = function () {
  13063. return this.messageHandler.sendWithPromise("GetPermissions", null);
  13064. };
  13065. WorkerTransport.prototype.getMetadata = function () {
  13066. var _this = this;
  13067. var name = "GetMetadata", cachedPromise = tslib_1.__classPrivateFieldGet(this, _WorkerTransport_methodPromises, "f").get(name);
  13068. if (cachedPromise) {
  13069. return cachedPromise;
  13070. }
  13071. var promise = this.messageHandler.sendWithPromise(name, null).then(function (results) {
  13072. var _k, _l, _m, _o;
  13073. return ({
  13074. info: results[0],
  13075. metadata: results[1] ? new Metadata(results[1]) : null,
  13076. contentDispositionFilename: (_l = (_k = _this._fullReader) === null || _k === void 0 ? void 0 : _k.filename) !== null && _l !== void 0 ? _l : null,
  13077. contentLength: (_o = (_m = _this._fullReader) === null || _m === void 0 ? void 0 : _m.contentLength) !== null && _o !== void 0 ? _o : null
  13078. });
  13079. });
  13080. tslib_1.__classPrivateFieldGet(this, _WorkerTransport_methodPromises, "f").set(name, promise);
  13081. return promise;
  13082. };
  13083. WorkerTransport.prototype.getMarkInfo = function () {
  13084. return this.messageHandler.sendWithPromise("GetMarkInfo", null);
  13085. };
  13086. WorkerTransport.prototype.startCleanup = function (keepLoadedFonts) {
  13087. if (keepLoadedFonts === void 0) { keepLoadedFonts = false; }
  13088. return tslib_1.__awaiter(this, void 0, void 0, function () {
  13089. var _i, _k, page, cleanupSuccessful;
  13090. return tslib_1.__generator(this, function (_l) {
  13091. switch (_l.label) {
  13092. case 0:
  13093. if (this.destroyed) {
  13094. return [2 /*return*/];
  13095. }
  13096. return [4 /*yield*/, this.messageHandler.sendWithPromise("Cleanup", null)];
  13097. case 1:
  13098. _l.sent();
  13099. for (_i = 0, _k = tslib_1.__classPrivateFieldGet(this, _WorkerTransport_pageCache, "f").values(); _i < _k.length; _i++) {
  13100. page = _k[_i];
  13101. cleanupSuccessful = page.cleanup();
  13102. if (!cleanupSuccessful) {
  13103. throw new Error("startCleanup: Page ".concat(page.pageNumber, " is currently rendering."));
  13104. }
  13105. }
  13106. this.commonObjs.clear();
  13107. if (!keepLoadedFonts) {
  13108. this.fontLoader.clear();
  13109. }
  13110. tslib_1.__classPrivateFieldGet(this, _WorkerTransport_methodPromises, "f").clear();
  13111. this.filterFactory.destroy(true);
  13112. TextLayer.cleanup();
  13113. return [2 /*return*/];
  13114. }
  13115. });
  13116. });
  13117. };
  13118. WorkerTransport.prototype.cachedPageNumber = function (ref) {
  13119. var _k;
  13120. if (!isRefProxy(ref)) {
  13121. return null;
  13122. }
  13123. var refStr = ref.gen === 0 ? "".concat(ref.num, "R") : "".concat(ref.num, "R").concat(ref.gen);
  13124. return (_k = tslib_1.__classPrivateFieldGet(this, _WorkerTransport_pageRefCache, "f").get(refStr)) !== null && _k !== void 0 ? _k : null;
  13125. };
  13126. return WorkerTransport;
  13127. }());
  13128. _WorkerTransport_methodPromises = new WeakMap(), _WorkerTransport_pageCache = new WeakMap(), _WorkerTransport_pagePromises = new WeakMap(), _WorkerTransport_pageRefCache = new WeakMap(), _WorkerTransport_passwordCapability = new WeakMap(), _WorkerTransport_instances = new WeakSet(), _WorkerTransport_cacheSimpleMethod = function _WorkerTransport_cacheSimpleMethod(name, data) {
  13129. if (data === void 0) { data = null; }
  13130. var cachedPromise = tslib_1.__classPrivateFieldGet(this, _WorkerTransport_methodPromises, "f").get(name);
  13131. if (cachedPromise) {
  13132. return cachedPromise;
  13133. }
  13134. var promise = this.messageHandler.sendWithPromise(name, data);
  13135. tslib_1.__classPrivateFieldGet(this, _WorkerTransport_methodPromises, "f").set(name, promise);
  13136. return promise;
  13137. };
  13138. var INITIAL_DATA = Symbol("INITIAL_DATA");
  13139. var PDFObjects = /** @class */ (function () {
  13140. function PDFObjects() {
  13141. _PDFObjects_instances.add(this);
  13142. _PDFObjects_objs.set(this, Object.create(null));
  13143. }
  13144. PDFObjects.prototype.get = function (objId, callback) {
  13145. if (callback === void 0) { callback = null; }
  13146. if (callback) {
  13147. var obj_1 = tslib_1.__classPrivateFieldGet(this, _PDFObjects_instances, "m", _PDFObjects_ensureObj).call(this, objId);
  13148. obj_1.promise.then(function () { return callback(obj_1.data); });
  13149. return null;
  13150. }
  13151. var obj = tslib_1.__classPrivateFieldGet(this, _PDFObjects_objs, "f")[objId];
  13152. if (!obj || obj.data === INITIAL_DATA) {
  13153. throw new Error("Requesting object that isn't resolved yet ".concat(objId, "."));
  13154. }
  13155. return obj.data;
  13156. };
  13157. PDFObjects.prototype.has = function (objId) {
  13158. var obj = tslib_1.__classPrivateFieldGet(this, _PDFObjects_objs, "f")[objId];
  13159. return !!obj && obj.data !== INITIAL_DATA;
  13160. };
  13161. PDFObjects.prototype.resolve = function (objId, data) {
  13162. if (data === void 0) { data = null; }
  13163. var obj = tslib_1.__classPrivateFieldGet(this, _PDFObjects_instances, "m", _PDFObjects_ensureObj).call(this, objId);
  13164. obj.data = data;
  13165. obj.resolve();
  13166. };
  13167. PDFObjects.prototype.clear = function () {
  13168. var _k;
  13169. for (var objId in tslib_1.__classPrivateFieldGet(this, _PDFObjects_objs, "f")) {
  13170. var data = tslib_1.__classPrivateFieldGet(this, _PDFObjects_objs, "f")[objId].data;
  13171. (_k = data === null || data === void 0 ? void 0 : data.bitmap) === null || _k === void 0 ? void 0 : _k.close();
  13172. }
  13173. tslib_1.__classPrivateFieldSet(this, _PDFObjects_objs, Object.create(null), "f");
  13174. };
  13175. PDFObjects.prototype[(_PDFObjects_objs = new WeakMap(), _PDFObjects_instances = new WeakSet(), _PDFObjects_ensureObj = function _PDFObjects_ensureObj(objId) {
  13176. var _k;
  13177. return (_k = tslib_1.__classPrivateFieldGet(this, _PDFObjects_objs, "f"))[objId] || (_k[objId] = tslib_1.__assign(tslib_1.__assign({}, Promise.withResolvers()), { data: INITIAL_DATA }));
  13178. }, Symbol.iterator)] = function () {
  13179. var _k, _l, _m, _i, objId, data;
  13180. return tslib_1.__generator(this, function (_o) {
  13181. switch (_o.label) {
  13182. case 0:
  13183. _k = tslib_1.__classPrivateFieldGet(this, _PDFObjects_objs, "f");
  13184. _l = [];
  13185. for (_m in _k)
  13186. _l.push(_m);
  13187. _i = 0;
  13188. _o.label = 1;
  13189. case 1:
  13190. if (!(_i < _l.length)) return [3 /*break*/, 4];
  13191. _m = _l[_i];
  13192. if (!(_m in _k)) return [3 /*break*/, 3];
  13193. objId = _m;
  13194. data = tslib_1.__classPrivateFieldGet(this, _PDFObjects_objs, "f")[objId].data;
  13195. if (data === INITIAL_DATA) {
  13196. return [3 /*break*/, 3];
  13197. }
  13198. return [4 /*yield*/, [objId, data]];
  13199. case 2:
  13200. _o.sent();
  13201. _o.label = 3;
  13202. case 3:
  13203. _i++;
  13204. return [3 /*break*/, 1];
  13205. case 4: return [2 /*return*/];
  13206. }
  13207. });
  13208. };
  13209. return PDFObjects;
  13210. }());
  13211. var RenderTask = /** @class */ (function () {
  13212. function RenderTask(internalRenderTask) {
  13213. _RenderTask_internalRenderTask.set(this, null);
  13214. tslib_1.__classPrivateFieldSet(this, _RenderTask_internalRenderTask, internalRenderTask, "f");
  13215. this.onContinue = null;
  13216. }
  13217. Object.defineProperty(RenderTask.prototype, "promise", {
  13218. get: function () {
  13219. return tslib_1.__classPrivateFieldGet(this, _RenderTask_internalRenderTask, "f").capability.promise;
  13220. },
  13221. enumerable: false,
  13222. configurable: true
  13223. });
  13224. RenderTask.prototype.cancel = function (extraDelay) {
  13225. if (extraDelay === void 0) { extraDelay = 0; }
  13226. tslib_1.__classPrivateFieldGet(this, _RenderTask_internalRenderTask, "f").cancel(null, extraDelay);
  13227. };
  13228. Object.defineProperty(RenderTask.prototype, "separateAnnots", {
  13229. get: function () {
  13230. var separateAnnots = tslib_1.__classPrivateFieldGet(this, _RenderTask_internalRenderTask, "f").operatorList.separateAnnots;
  13231. if (!separateAnnots) {
  13232. return false;
  13233. }
  13234. var annotationCanvasMap = tslib_1.__classPrivateFieldGet(this, _RenderTask_internalRenderTask, "f").annotationCanvasMap;
  13235. return separateAnnots.form || separateAnnots.canvas && (annotationCanvasMap === null || annotationCanvasMap === void 0 ? void 0 : annotationCanvasMap.size) > 0;
  13236. },
  13237. enumerable: false,
  13238. configurable: true
  13239. });
  13240. return RenderTask;
  13241. }());
  13242. _RenderTask_internalRenderTask = new WeakMap();
  13243. var InternalRenderTask = /** @class */ (function () {
  13244. function InternalRenderTask(_l) {
  13245. var callback = _l.callback, params = _l.params, objs = _l.objs, commonObjs = _l.commonObjs, annotationCanvasMap = _l.annotationCanvasMap, operatorList = _l.operatorList, pageIndex = _l.pageIndex, canvasFactory = _l.canvasFactory, filterFactory = _l.filterFactory, _m = _l.useRequestAnimationFrame, useRequestAnimationFrame = _m === void 0 ? false : _m, _o = _l.pdfBug, pdfBug = _o === void 0 ? false : _o, _p = _l.pageColors, pageColors = _p === void 0 ? null : _p;
  13246. this.callback = callback;
  13247. this.params = params;
  13248. this.objs = objs;
  13249. this.commonObjs = commonObjs;
  13250. this.annotationCanvasMap = annotationCanvasMap;
  13251. this.operatorListIdx = null;
  13252. this.operatorList = operatorList;
  13253. this._pageIndex = pageIndex;
  13254. this.canvasFactory = canvasFactory;
  13255. this.filterFactory = filterFactory;
  13256. this._pdfBug = pdfBug;
  13257. this.pageColors = pageColors;
  13258. this.running = false;
  13259. this.graphicsReadyCallback = null;
  13260. this.graphicsReady = false;
  13261. this._useRequestAnimationFrame = useRequestAnimationFrame === true && typeof window !== "undefined";
  13262. this.cancelled = false;
  13263. this.capability = Promise.withResolvers();
  13264. this.task = new RenderTask(this);
  13265. this._cancelBound = this.cancel.bind(this);
  13266. this._continueBound = this._continue.bind(this);
  13267. this._scheduleNextBound = this._scheduleNext.bind(this);
  13268. this._nextBound = this._next.bind(this);
  13269. this._canvas = params.canvasContext.canvas;
  13270. }
  13271. Object.defineProperty(InternalRenderTask.prototype, "completed", {
  13272. get: function () {
  13273. return this.capability.promise.catch(function () { });
  13274. },
  13275. enumerable: false,
  13276. configurable: true
  13277. });
  13278. InternalRenderTask.prototype.initializeGraphics = function (_l) {
  13279. var _m, _o;
  13280. var _p = _l.transparency, transparency = _p === void 0 ? false : _p, optionalContentConfig = _l.optionalContentConfig;
  13281. if (this.cancelled) {
  13282. return;
  13283. }
  13284. if (this._canvas) {
  13285. if (tslib_1.__classPrivateFieldGet(InternalRenderTask, _k, "f", _InternalRenderTask_canvasInUse).has(this._canvas)) {
  13286. throw new Error("Cannot use the same canvas during multiple render() operations. " + "Use different canvas or ensure previous operations were " + "cancelled or completed.");
  13287. }
  13288. tslib_1.__classPrivateFieldGet(InternalRenderTask, _k, "f", _InternalRenderTask_canvasInUse).add(this._canvas);
  13289. }
  13290. if (this._pdfBug && ((_m = globalThis.StepperManager) === null || _m === void 0 ? void 0 : _m.enabled)) {
  13291. this.stepper = globalThis.StepperManager.create(this._pageIndex);
  13292. this.stepper.init(this.operatorList);
  13293. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  13294. }
  13295. var _q = this.params, canvasContext = _q.canvasContext, viewport = _q.viewport, transform = _q.transform, background = _q.background;
  13296. this.gfx = new CanvasGraphics(canvasContext, this.commonObjs, this.objs, this.canvasFactory, this.filterFactory, {
  13297. optionalContentConfig: optionalContentConfig
  13298. }, this.annotationCanvasMap, this.pageColors);
  13299. this.gfx.beginDrawing({
  13300. transform: transform,
  13301. viewport: viewport,
  13302. transparency: transparency,
  13303. background: background
  13304. });
  13305. this.operatorListIdx = 0;
  13306. this.graphicsReady = true;
  13307. (_o = this.graphicsReadyCallback) === null || _o === void 0 ? void 0 : _o.call(this);
  13308. };
  13309. InternalRenderTask.prototype.cancel = function (error, extraDelay) {
  13310. var _l;
  13311. if (error === void 0) { error = null; }
  13312. if (extraDelay === void 0) { extraDelay = 0; }
  13313. this.running = false;
  13314. this.cancelled = true;
  13315. (_l = this.gfx) === null || _l === void 0 ? void 0 : _l.endDrawing();
  13316. tslib_1.__classPrivateFieldGet(InternalRenderTask, _k, "f", _InternalRenderTask_canvasInUse).delete(this._canvas);
  13317. this.callback(error || new RenderingCancelledException("Rendering cancelled, page ".concat(this._pageIndex + 1), extraDelay));
  13318. };
  13319. InternalRenderTask.prototype.operatorListChanged = function () {
  13320. var _l;
  13321. if (!this.graphicsReady) {
  13322. this.graphicsReadyCallback || (this.graphicsReadyCallback = this._continueBound);
  13323. return;
  13324. }
  13325. (_l = this.stepper) === null || _l === void 0 ? void 0 : _l.updateOperatorList(this.operatorList);
  13326. if (this.running) {
  13327. return;
  13328. }
  13329. this._continue();
  13330. };
  13331. InternalRenderTask.prototype._continue = function () {
  13332. this.running = true;
  13333. if (this.cancelled) {
  13334. return;
  13335. }
  13336. if (this.task.onContinue) {
  13337. this.task.onContinue(this._scheduleNextBound);
  13338. }
  13339. else {
  13340. this._scheduleNext();
  13341. }
  13342. };
  13343. InternalRenderTask.prototype._scheduleNext = function () {
  13344. var _this = this;
  13345. if (this._useRequestAnimationFrame) {
  13346. window.requestAnimationFrame(function () {
  13347. _this._nextBound().catch(_this._cancelBound);
  13348. });
  13349. }
  13350. else {
  13351. Promise.resolve().then(this._nextBound).catch(this._cancelBound);
  13352. }
  13353. };
  13354. InternalRenderTask.prototype._next = function () {
  13355. return tslib_1.__awaiter(this, void 0, void 0, function () {
  13356. return tslib_1.__generator(this, function (_l) {
  13357. if (this.cancelled) {
  13358. return [2 /*return*/];
  13359. }
  13360. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList, this.operatorListIdx, this._continueBound, this.stepper);
  13361. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  13362. this.running = false;
  13363. if (this.operatorList.lastChunk) {
  13364. this.gfx.endDrawing();
  13365. tslib_1.__classPrivateFieldGet(InternalRenderTask, _k, "f", _InternalRenderTask_canvasInUse).delete(this._canvas);
  13366. this.callback();
  13367. }
  13368. }
  13369. return [2 /*return*/];
  13370. });
  13371. });
  13372. };
  13373. var _k, _InternalRenderTask_canvasInUse;
  13374. _k = InternalRenderTask;
  13375. _InternalRenderTask_canvasInUse = { value: new WeakSet() };
  13376. return InternalRenderTask;
  13377. }());
  13378. var version = "4.3.136";
  13379. var build = "0cec64437";
  13380. ; // CONCATENATED MODULE: ./src/shared/scripting_utils.js
  13381. function makeColorComp(n) {
  13382. return Math.floor(Math.max(0, Math.min(1, n)) * 255).toString(16).padStart(2, "0");
  13383. }
  13384. function scaleAndClamp(x) {
  13385. return Math.max(0, Math.min(255, 255 * x));
  13386. }
  13387. var ColorConverters = /** @class */ (function () {
  13388. function ColorConverters() {
  13389. }
  13390. ColorConverters.CMYK_G = function (_l) {
  13391. var c = _l[0], y = _l[1], m = _l[2], k = _l[3];
  13392. return ["G", 1 - Math.min(1, 0.3 * c + 0.59 * m + 0.11 * y + k)];
  13393. };
  13394. ColorConverters.G_CMYK = function (_l) {
  13395. var g = _l[0];
  13396. return ["CMYK", 0, 0, 0, 1 - g];
  13397. };
  13398. ColorConverters.G_RGB = function (_l) {
  13399. var g = _l[0];
  13400. return ["RGB", g, g, g];
  13401. };
  13402. ColorConverters.G_rgb = function (_l) {
  13403. var g = _l[0];
  13404. g = scaleAndClamp(g);
  13405. return [g, g, g];
  13406. };
  13407. ColorConverters.G_HTML = function (_l) {
  13408. var g = _l[0];
  13409. var G = makeColorComp(g);
  13410. return "#".concat(G).concat(G).concat(G);
  13411. };
  13412. ColorConverters.RGB_G = function (_l) {
  13413. var r = _l[0], g = _l[1], b = _l[2];
  13414. return ["G", 0.3 * r + 0.59 * g + 0.11 * b];
  13415. };
  13416. ColorConverters.RGB_rgb = function (color) {
  13417. return color.map(scaleAndClamp);
  13418. };
  13419. ColorConverters.RGB_HTML = function (color) {
  13420. return "#".concat(color.map(makeColorComp).join(""));
  13421. };
  13422. ColorConverters.T_HTML = function () {
  13423. return "#00000000";
  13424. };
  13425. ColorConverters.T_rgb = function () {
  13426. return [null];
  13427. };
  13428. ColorConverters.CMYK_RGB = function (_l) {
  13429. var c = _l[0], y = _l[1], m = _l[2], k = _l[3];
  13430. return ["RGB", 1 - Math.min(1, c + k), 1 - Math.min(1, m + k), 1 - Math.min(1, y + k)];
  13431. };
  13432. ColorConverters.CMYK_rgb = function (_l) {
  13433. var c = _l[0], y = _l[1], m = _l[2], k = _l[3];
  13434. return [scaleAndClamp(1 - Math.min(1, c + k)), scaleAndClamp(1 - Math.min(1, m + k)), scaleAndClamp(1 - Math.min(1, y + k))];
  13435. };
  13436. ColorConverters.CMYK_HTML = function (components) {
  13437. var rgb = this.CMYK_RGB(components).slice(1);
  13438. return this.RGB_HTML(rgb);
  13439. };
  13440. ColorConverters.RGB_CMYK = function (_l) {
  13441. var r = _l[0], g = _l[1], b = _l[2];
  13442. var c = 1 - r;
  13443. var m = 1 - g;
  13444. var y = 1 - b;
  13445. var k = Math.min(c, m, y);
  13446. return ["CMYK", c, m, y, k];
  13447. };
  13448. return ColorConverters;
  13449. }());
  13450. ; // CONCATENATED MODULE: ./src/display/xfa_layer.js
  13451. var XfaLayer = /** @class */ (function () {
  13452. function XfaLayer() {
  13453. }
  13454. XfaLayer.setupStorage = function (html, id, element, storage, intent) {
  13455. var storedData = storage.getValue(id, {
  13456. value: null
  13457. });
  13458. switch (element.name) {
  13459. case "textarea":
  13460. if (storedData.value !== null) {
  13461. html.textContent = storedData.value;
  13462. }
  13463. if (intent === "print") {
  13464. break;
  13465. }
  13466. html.addEventListener("input", function (event) {
  13467. storage.setValue(id, {
  13468. value: event.target.value
  13469. });
  13470. });
  13471. break;
  13472. case "input":
  13473. if (element.attributes.type === "radio" || element.attributes.type === "checkbox") {
  13474. if (storedData.value === element.attributes.xfaOn) {
  13475. html.setAttribute("checked", true);
  13476. }
  13477. else if (storedData.value === element.attributes.xfaOff) {
  13478. html.removeAttribute("checked");
  13479. }
  13480. if (intent === "print") {
  13481. break;
  13482. }
  13483. html.addEventListener("change", function (event) {
  13484. storage.setValue(id, {
  13485. value: event.target.checked ? event.target.getAttribute("xfaOn") : event.target.getAttribute("xfaOff")
  13486. });
  13487. });
  13488. }
  13489. else {
  13490. if (storedData.value !== null) {
  13491. html.setAttribute("value", storedData.value);
  13492. }
  13493. if (intent === "print") {
  13494. break;
  13495. }
  13496. html.addEventListener("input", function (event) {
  13497. storage.setValue(id, {
  13498. value: event.target.value
  13499. });
  13500. });
  13501. }
  13502. break;
  13503. case "select":
  13504. if (storedData.value !== null) {
  13505. html.setAttribute("value", storedData.value);
  13506. for (var _i = 0, _l = element.children; _i < _l.length; _i++) {
  13507. var option = _l[_i];
  13508. if (option.attributes.value === storedData.value) {
  13509. option.attributes.selected = true;
  13510. }
  13511. else if (option.attributes.hasOwnProperty("selected")) {
  13512. delete option.attributes.selected;
  13513. }
  13514. }
  13515. }
  13516. html.addEventListener("input", function (event) {
  13517. var options = event.target.options;
  13518. var value = options.selectedIndex === -1 ? "" : options[options.selectedIndex].value;
  13519. storage.setValue(id, {
  13520. value: value
  13521. });
  13522. });
  13523. break;
  13524. }
  13525. };
  13526. XfaLayer.setAttributes = function (_l) {
  13527. var html = _l.html, element = _l.element, _m = _l.storage, storage = _m === void 0 ? null : _m, intent = _l.intent, linkService = _l.linkService;
  13528. var attributes = element.attributes;
  13529. var isHTMLAnchorElement = html instanceof HTMLAnchorElement;
  13530. if (attributes.type === "radio") {
  13531. attributes.name = "".concat(attributes.name, "-").concat(intent);
  13532. }
  13533. for (var _i = 0, _o = Object.entries(attributes); _i < _o.length; _i++) {
  13534. var _p = _o[_i], key = _p[0], value = _p[1];
  13535. if (value === null || value === undefined) {
  13536. continue;
  13537. }
  13538. switch (key) {
  13539. case "class":
  13540. if (value.length) {
  13541. html.setAttribute(key, value.join(" "));
  13542. }
  13543. break;
  13544. case "dataId":
  13545. break;
  13546. case "id":
  13547. html.setAttribute("data-element-id", value);
  13548. break;
  13549. case "style":
  13550. Object.assign(html.style, value);
  13551. break;
  13552. case "textContent":
  13553. html.textContent = value;
  13554. break;
  13555. default:
  13556. if (!isHTMLAnchorElement || key !== "href" && key !== "newWindow") {
  13557. html.setAttribute(key, value);
  13558. }
  13559. }
  13560. }
  13561. if (isHTMLAnchorElement) {
  13562. linkService.addLinkAttributes(html, attributes.href, attributes.newWindow);
  13563. }
  13564. if (storage && attributes.dataId) {
  13565. this.setupStorage(html, attributes.dataId, element, storage);
  13566. }
  13567. };
  13568. XfaLayer.render = function (parameters) {
  13569. var _l, _m;
  13570. var storage = parameters.annotationStorage;
  13571. var linkService = parameters.linkService;
  13572. var root = parameters.xfaHtml;
  13573. var intent = parameters.intent || "display";
  13574. var rootHtml = document.createElement(root.name);
  13575. if (root.attributes) {
  13576. this.setAttributes({
  13577. html: rootHtml,
  13578. element: root,
  13579. intent: intent,
  13580. linkService: linkService
  13581. });
  13582. }
  13583. var isNotForRichText = intent !== "richText";
  13584. var rootDiv = parameters.div;
  13585. rootDiv.append(rootHtml);
  13586. if (parameters.viewport) {
  13587. var transform = "matrix(".concat(parameters.viewport.transform.join(","), ")");
  13588. rootDiv.style.transform = transform;
  13589. }
  13590. if (isNotForRichText) {
  13591. rootDiv.setAttribute("class", "xfaLayer xfaFont");
  13592. }
  13593. var textDivs = [];
  13594. if (root.children.length === 0) {
  13595. if (root.value) {
  13596. var node = document.createTextNode(root.value);
  13597. rootHtml.append(node);
  13598. if (isNotForRichText && XfaText.shouldBuildText(root.name)) {
  13599. textDivs.push(node);
  13600. }
  13601. }
  13602. return {
  13603. textDivs: textDivs
  13604. };
  13605. }
  13606. var stack = [[root, -1, rootHtml]];
  13607. while (stack.length > 0) {
  13608. var _o = stack.at(-1), parent = _o[0], i = _o[1], html = _o[2];
  13609. if (i + 1 === parent.children.length) {
  13610. stack.pop();
  13611. continue;
  13612. }
  13613. var child = parent.children[++stack.at(-1)[1]];
  13614. if (child === null) {
  13615. continue;
  13616. }
  13617. var name = child.name;
  13618. if (name === "#text") {
  13619. var node = document.createTextNode(child.value);
  13620. textDivs.push(node);
  13621. html.append(node);
  13622. continue;
  13623. }
  13624. var childHtml = ((_l = child === null || child === void 0 ? void 0 : child.attributes) === null || _l === void 0 ? void 0 : _l.xmlns) ? document.createElementNS(child.attributes.xmlns, name) : document.createElement(name);
  13625. html.append(childHtml);
  13626. if (child.attributes) {
  13627. this.setAttributes({
  13628. html: childHtml,
  13629. element: child,
  13630. storage: storage,
  13631. intent: intent,
  13632. linkService: linkService
  13633. });
  13634. }
  13635. if (((_m = child.children) === null || _m === void 0 ? void 0 : _m.length) > 0) {
  13636. stack.push([child, -1, childHtml]);
  13637. }
  13638. else if (child.value) {
  13639. var node = document.createTextNode(child.value);
  13640. if (isNotForRichText && XfaText.shouldBuildText(name)) {
  13641. textDivs.push(node);
  13642. }
  13643. childHtml.append(node);
  13644. }
  13645. }
  13646. for (var _i = 0, _p = rootDiv.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea"); _i < _p.length; _i++) {
  13647. var el = _p[_i];
  13648. el.setAttribute("readOnly", true);
  13649. }
  13650. return {
  13651. textDivs: textDivs
  13652. };
  13653. };
  13654. XfaLayer.update = function (parameters) {
  13655. var transform = "matrix(".concat(parameters.viewport.transform.join(","), ")");
  13656. parameters.div.style.transform = transform;
  13657. parameters.div.hidden = false;
  13658. };
  13659. return XfaLayer;
  13660. }());
  13661. ; // CONCATENATED MODULE: ./src/display/annotation_layer.js
  13662. var DEFAULT_TAB_INDEX = 1000;
  13663. var annotation_layer_DEFAULT_FONT_SIZE = 9;
  13664. var GetElementsByNameSet = new WeakSet();
  13665. function getRectDims(rect) {
  13666. return {
  13667. width: rect[2] - rect[0],
  13668. height: rect[3] - rect[1]
  13669. };
  13670. }
  13671. var AnnotationElementFactory = /** @class */ (function () {
  13672. function AnnotationElementFactory() {
  13673. }
  13674. AnnotationElementFactory.create = function (parameters) {
  13675. var subtype = parameters.data.annotationType;
  13676. switch (subtype) {
  13677. case AnnotationType.LINK:
  13678. return new LinkAnnotationElement(parameters);
  13679. case AnnotationType.TEXT:
  13680. return new TextAnnotationElement(parameters);
  13681. case AnnotationType.WIDGET:
  13682. var fieldType = parameters.data.fieldType;
  13683. switch (fieldType) {
  13684. case "Tx":
  13685. return new TextWidgetAnnotationElement(parameters);
  13686. case "Btn":
  13687. if (parameters.data.radioButton) {
  13688. return new RadioButtonWidgetAnnotationElement(parameters);
  13689. }
  13690. else if (parameters.data.checkBox) {
  13691. return new CheckboxWidgetAnnotationElement(parameters);
  13692. }
  13693. return new PushButtonWidgetAnnotationElement(parameters);
  13694. case "Ch":
  13695. return new ChoiceWidgetAnnotationElement(parameters);
  13696. case "Sig":
  13697. return new SignatureWidgetAnnotationElement(parameters);
  13698. }
  13699. return new WidgetAnnotationElement(parameters);
  13700. case AnnotationType.POPUP:
  13701. return new PopupAnnotationElement(parameters);
  13702. case AnnotationType.FREETEXT:
  13703. return new FreeTextAnnotationElement(parameters);
  13704. case AnnotationType.LINE:
  13705. return new LineAnnotationElement(parameters);
  13706. case AnnotationType.SQUARE:
  13707. return new SquareAnnotationElement(parameters);
  13708. case AnnotationType.CIRCLE:
  13709. return new CircleAnnotationElement(parameters);
  13710. case AnnotationType.POLYLINE:
  13711. return new PolylineAnnotationElement(parameters);
  13712. case AnnotationType.CARET:
  13713. return new CaretAnnotationElement(parameters);
  13714. case AnnotationType.INK:
  13715. return new InkAnnotationElement(parameters);
  13716. case AnnotationType.POLYGON:
  13717. return new PolygonAnnotationElement(parameters);
  13718. case AnnotationType.HIGHLIGHT:
  13719. return new HighlightAnnotationElement(parameters);
  13720. case AnnotationType.UNDERLINE:
  13721. return new UnderlineAnnotationElement(parameters);
  13722. case AnnotationType.SQUIGGLY:
  13723. return new SquigglyAnnotationElement(parameters);
  13724. case AnnotationType.STRIKEOUT:
  13725. return new StrikeOutAnnotationElement(parameters);
  13726. case AnnotationType.STAMP:
  13727. return new StampAnnotationElement(parameters);
  13728. case AnnotationType.FILEATTACHMENT:
  13729. return new FileAttachmentAnnotationElement(parameters);
  13730. default:
  13731. return new AnnotationElement(parameters);
  13732. }
  13733. };
  13734. return AnnotationElementFactory;
  13735. }());
  13736. var AnnotationElement = /** @class */ (function () {
  13737. function AnnotationElement(parameters, _l) {
  13738. var _m = _l === void 0 ? {} : _l, _o = _m.isRenderable, isRenderable = _o === void 0 ? false : _o, _p = _m.ignoreBorder, ignoreBorder = _p === void 0 ? false : _p, _q = _m.createQuadrilaterals, createQuadrilaterals = _q === void 0 ? false : _q;
  13739. _AnnotationElement_instances.add(this);
  13740. _AnnotationElement_updates.set(this, null);
  13741. _AnnotationElement_hasBorder.set(this, false);
  13742. _AnnotationElement_popupElement.set(this, null);
  13743. this.isRenderable = isRenderable;
  13744. this.data = parameters.data;
  13745. this.layer = parameters.layer;
  13746. this.linkService = parameters.linkService;
  13747. this.downloadManager = parameters.downloadManager;
  13748. this.imageResourcesPath = parameters.imageResourcesPath;
  13749. this.renderForms = parameters.renderForms;
  13750. this.svgFactory = parameters.svgFactory;
  13751. this.annotationStorage = parameters.annotationStorage;
  13752. this.enableScripting = parameters.enableScripting;
  13753. this.hasJSActions = parameters.hasJSActions;
  13754. this._fieldObjects = parameters.fieldObjects;
  13755. this.parent = parameters.parent;
  13756. if (isRenderable) {
  13757. this.container = this._createContainer(ignoreBorder);
  13758. }
  13759. if (createQuadrilaterals) {
  13760. this._createQuadrilaterals();
  13761. }
  13762. }
  13763. AnnotationElement._hasPopupData = function (_l) {
  13764. var titleObj = _l.titleObj, contentsObj = _l.contentsObj, richText = _l.richText;
  13765. return !!((titleObj === null || titleObj === void 0 ? void 0 : titleObj.str) || (contentsObj === null || contentsObj === void 0 ? void 0 : contentsObj.str) || (richText === null || richText === void 0 ? void 0 : richText.str));
  13766. };
  13767. Object.defineProperty(AnnotationElement.prototype, "hasPopupData", {
  13768. get: function () {
  13769. return AnnotationElement._hasPopupData(this.data);
  13770. },
  13771. enumerable: false,
  13772. configurable: true
  13773. });
  13774. AnnotationElement.prototype.updateEdited = function (params) {
  13775. var _l;
  13776. if (!this.container) {
  13777. return;
  13778. }
  13779. tslib_1.__classPrivateFieldSet(this, _AnnotationElement_updates, tslib_1.__classPrivateFieldGet(this, _AnnotationElement_updates, "f") || {
  13780. rect: this.data.rect.slice(0)
  13781. }, "f");
  13782. var rect = params.rect;
  13783. if (rect) {
  13784. tslib_1.__classPrivateFieldGet(this, _AnnotationElement_instances, "m", _AnnotationElement_setRectEdited).call(this, rect);
  13785. }
  13786. (_l = tslib_1.__classPrivateFieldGet(this, _AnnotationElement_popupElement, "f")) === null || _l === void 0 ? void 0 : _l.popup.updateEdited(params);
  13787. };
  13788. AnnotationElement.prototype.resetEdited = function () {
  13789. var _l;
  13790. if (!tslib_1.__classPrivateFieldGet(this, _AnnotationElement_updates, "f")) {
  13791. return;
  13792. }
  13793. tslib_1.__classPrivateFieldGet(this, _AnnotationElement_instances, "m", _AnnotationElement_setRectEdited).call(this, tslib_1.__classPrivateFieldGet(this, _AnnotationElement_updates, "f").rect);
  13794. (_l = tslib_1.__classPrivateFieldGet(this, _AnnotationElement_popupElement, "f")) === null || _l === void 0 ? void 0 : _l.popup.resetEdited();
  13795. tslib_1.__classPrivateFieldSet(this, _AnnotationElement_updates, null, "f");
  13796. };
  13797. AnnotationElement.prototype._createContainer = function (ignoreBorder) {
  13798. var _l = this, data = _l.data, _m = _l.parent, page = _m.page, viewport = _m.viewport;
  13799. var container = document.createElement("section");
  13800. container.setAttribute("data-annotation-id", data.id);
  13801. if (!(this instanceof WidgetAnnotationElement)) {
  13802. container.tabIndex = DEFAULT_TAB_INDEX;
  13803. }
  13804. var style = container.style;
  13805. style.zIndex = this.parent.zIndex++;
  13806. if (data.popupRef) {
  13807. container.setAttribute("aria-haspopup", "dialog");
  13808. }
  13809. if (data.alternativeText) {
  13810. container.title = data.alternativeText;
  13811. }
  13812. if (data.noRotate) {
  13813. container.classList.add("norotate");
  13814. }
  13815. if (!data.rect || this instanceof PopupAnnotationElement) {
  13816. var rotation_1 = data.rotation;
  13817. if (!data.hasOwnCanvas && rotation_1 !== 0) {
  13818. this.setRotation(rotation_1, container);
  13819. }
  13820. return container;
  13821. }
  13822. var _o = getRectDims(data.rect), width = _o.width, height = _o.height;
  13823. if (!ignoreBorder && data.borderStyle.width > 0) {
  13824. style.borderWidth = "".concat(data.borderStyle.width, "px");
  13825. var horizontalRadius = data.borderStyle.horizontalCornerRadius;
  13826. var verticalRadius = data.borderStyle.verticalCornerRadius;
  13827. if (horizontalRadius > 0 || verticalRadius > 0) {
  13828. var radius = "calc(".concat(horizontalRadius, "px * var(--scale-factor)) / calc(").concat(verticalRadius, "px * var(--scale-factor))");
  13829. style.borderRadius = radius;
  13830. }
  13831. else if (this instanceof RadioButtonWidgetAnnotationElement) {
  13832. var radius = "calc(".concat(width, "px * var(--scale-factor)) / calc(").concat(height, "px * var(--scale-factor))");
  13833. style.borderRadius = radius;
  13834. }
  13835. switch (data.borderStyle.style) {
  13836. case AnnotationBorderStyleType.SOLID:
  13837. style.borderStyle = "solid";
  13838. break;
  13839. case AnnotationBorderStyleType.DASHED:
  13840. style.borderStyle = "dashed";
  13841. break;
  13842. case AnnotationBorderStyleType.BEVELED:
  13843. warn("Unimplemented border style: beveled");
  13844. break;
  13845. case AnnotationBorderStyleType.INSET:
  13846. warn("Unimplemented border style: inset");
  13847. break;
  13848. case AnnotationBorderStyleType.UNDERLINE:
  13849. style.borderBottomStyle = "solid";
  13850. break;
  13851. default:
  13852. break;
  13853. }
  13854. var borderColor = data.borderColor || null;
  13855. if (borderColor) {
  13856. tslib_1.__classPrivateFieldSet(this, _AnnotationElement_hasBorder, true, "f");
  13857. style.borderColor = Util.makeHexColor(borderColor[0] | 0, borderColor[1] | 0, borderColor[2] | 0);
  13858. }
  13859. else {
  13860. style.borderWidth = 0;
  13861. }
  13862. }
  13863. var rect = 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]]);
  13864. var _p = viewport.rawDims, pageWidth = _p.pageWidth, pageHeight = _p.pageHeight, pageX = _p.pageX, pageY = _p.pageY;
  13865. style.left = "".concat(100 * (rect[0] - pageX) / pageWidth, "%");
  13866. style.top = "".concat(100 * (rect[1] - pageY) / pageHeight, "%");
  13867. var rotation = data.rotation;
  13868. if (data.hasOwnCanvas || rotation === 0) {
  13869. style.width = "".concat(100 * width / pageWidth, "%");
  13870. style.height = "".concat(100 * height / pageHeight, "%");
  13871. }
  13872. else {
  13873. this.setRotation(rotation, container);
  13874. }
  13875. return container;
  13876. };
  13877. AnnotationElement.prototype.setRotation = function (angle, container) {
  13878. if (container === void 0) { container = this.container; }
  13879. if (!this.data.rect) {
  13880. return;
  13881. }
  13882. var _l = this.parent.viewport.rawDims, pageWidth = _l.pageWidth, pageHeight = _l.pageHeight;
  13883. var _m = getRectDims(this.data.rect), width = _m.width, height = _m.height;
  13884. var elementWidth, elementHeight;
  13885. if (angle % 180 === 0) {
  13886. elementWidth = 100 * width / pageWidth;
  13887. elementHeight = 100 * height / pageHeight;
  13888. }
  13889. else {
  13890. elementWidth = 100 * height / pageWidth;
  13891. elementHeight = 100 * width / pageHeight;
  13892. }
  13893. container.style.width = "".concat(elementWidth, "%");
  13894. container.style.height = "".concat(elementHeight, "%");
  13895. container.setAttribute("data-main-rotation", (360 - angle) % 360);
  13896. };
  13897. Object.defineProperty(AnnotationElement.prototype, "_commonActions", {
  13898. get: function () {
  13899. var _this = this;
  13900. var setColor = function (jsName, styleName, event) {
  13901. var _l;
  13902. var color = event.detail[jsName];
  13903. var colorType = color[0];
  13904. var colorArray = color.slice(1);
  13905. event.target.style[styleName] = ColorConverters["".concat(colorType, "_HTML")](colorArray);
  13906. _this.annotationStorage.setValue(_this.data.id, (_l = {},
  13907. _l[styleName] = ColorConverters["".concat(colorType, "_rgb")](colorArray),
  13908. _l));
  13909. };
  13910. return shadow(this, "_commonActions", {
  13911. display: function (event) {
  13912. var display = event.detail.display;
  13913. var hidden = display % 2 === 1;
  13914. _this.container.style.visibility = hidden ? "hidden" : "visible";
  13915. _this.annotationStorage.setValue(_this.data.id, {
  13916. noView: hidden,
  13917. noPrint: display === 1 || display === 2
  13918. });
  13919. },
  13920. print: function (event) {
  13921. _this.annotationStorage.setValue(_this.data.id, {
  13922. noPrint: !event.detail.print
  13923. });
  13924. },
  13925. hidden: function (event) {
  13926. var hidden = event.detail.hidden;
  13927. _this.container.style.visibility = hidden ? "hidden" : "visible";
  13928. _this.annotationStorage.setValue(_this.data.id, {
  13929. noPrint: hidden,
  13930. noView: hidden
  13931. });
  13932. },
  13933. focus: function (event) {
  13934. setTimeout(function () { return event.target.focus({
  13935. preventScroll: false
  13936. }); }, 0);
  13937. },
  13938. userName: function (event) {
  13939. event.target.title = event.detail.userName;
  13940. },
  13941. readonly: function (event) {
  13942. event.target.disabled = event.detail.readonly;
  13943. },
  13944. required: function (event) {
  13945. _this._setRequired(event.target, event.detail.required);
  13946. },
  13947. bgColor: function (event) {
  13948. setColor("bgColor", "backgroundColor", event);
  13949. },
  13950. fillColor: function (event) {
  13951. setColor("fillColor", "backgroundColor", event);
  13952. },
  13953. fgColor: function (event) {
  13954. setColor("fgColor", "color", event);
  13955. },
  13956. textColor: function (event) {
  13957. setColor("textColor", "color", event);
  13958. },
  13959. borderColor: function (event) {
  13960. setColor("borderColor", "borderColor", event);
  13961. },
  13962. strokeColor: function (event) {
  13963. setColor("strokeColor", "borderColor", event);
  13964. },
  13965. rotation: function (event) {
  13966. var angle = event.detail.rotation;
  13967. _this.setRotation(angle);
  13968. _this.annotationStorage.setValue(_this.data.id, {
  13969. rotation: angle
  13970. });
  13971. }
  13972. });
  13973. },
  13974. enumerable: false,
  13975. configurable: true
  13976. });
  13977. AnnotationElement.prototype._dispatchEventFromSandbox = function (actions, jsEvent) {
  13978. var commonActions = this._commonActions;
  13979. for (var _i = 0, _l = Object.keys(jsEvent.detail); _i < _l.length; _i++) {
  13980. var name = _l[_i];
  13981. var action = actions[name] || commonActions[name];
  13982. action === null || action === void 0 ? void 0 : action(jsEvent);
  13983. }
  13984. };
  13985. AnnotationElement.prototype._setDefaultPropertiesFromJS = function (element) {
  13986. var _l;
  13987. if (!this.enableScripting) {
  13988. return;
  13989. }
  13990. var storedData = this.annotationStorage.getRawValue(this.data.id);
  13991. if (!storedData) {
  13992. return;
  13993. }
  13994. var commonActions = this._commonActions;
  13995. for (var _i = 0, _m = Object.entries(storedData); _i < _m.length; _i++) {
  13996. var _o = _m[_i], actionName = _o[0], detail = _o[1];
  13997. var action = commonActions[actionName];
  13998. if (action) {
  13999. var eventProxy = {
  14000. detail: (_l = {},
  14001. _l[actionName] = detail,
  14002. _l),
  14003. target: element
  14004. };
  14005. action(eventProxy);
  14006. delete storedData[actionName];
  14007. }
  14008. }
  14009. };
  14010. AnnotationElement.prototype._createQuadrilaterals = function () {
  14011. if (!this.container) {
  14012. return;
  14013. }
  14014. var quadPoints = this.data.quadPoints;
  14015. if (!quadPoints) {
  14016. return;
  14017. }
  14018. var _l = this.data.rect, rectBlX = _l[0], rectBlY = _l[1], rectTrX = _l[2], rectTrY = _l[3];
  14019. if (quadPoints.length === 1) {
  14020. var _m = quadPoints[0], _o = _m[1], trX = _o.x, trY = _o.y, _p = _m[2], blX = _p.x, blY = _p.y;
  14021. if (rectTrX === trX && rectTrY === trY && rectBlX === blX && rectBlY === blY) {
  14022. return;
  14023. }
  14024. }
  14025. var style = this.container.style;
  14026. var svgBuffer;
  14027. if (tslib_1.__classPrivateFieldGet(this, _AnnotationElement_hasBorder, "f")) {
  14028. var borderColor = style.borderColor, borderWidth = style.borderWidth;
  14029. style.borderWidth = 0;
  14030. 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=\"".concat(borderColor, "\" stroke-width=\"").concat(borderWidth, "\">")];
  14031. this.container.classList.add("hasBorder");
  14032. }
  14033. var width = rectTrX - rectBlX;
  14034. var height = rectTrY - rectBlY;
  14035. var svgFactory = this.svgFactory;
  14036. var svg = svgFactory.createElement("svg");
  14037. svg.classList.add("quadrilateralsContainer");
  14038. svg.setAttribute("width", 0);
  14039. svg.setAttribute("height", 0);
  14040. var defs = svgFactory.createElement("defs");
  14041. svg.append(defs);
  14042. var clipPath = svgFactory.createElement("clipPath");
  14043. var id = "clippath_".concat(this.data.id);
  14044. clipPath.setAttribute("id", id);
  14045. clipPath.setAttribute("clipPathUnits", "objectBoundingBox");
  14046. defs.append(clipPath);
  14047. for (var _i = 0, quadPoints_1 = quadPoints; _i < quadPoints_1.length; _i++) {
  14048. var _q = quadPoints_1[_i], _r = _q[1], trX = _r.x, trY = _r.y, _s = _q[2], blX = _s.x, blY = _s.y;
  14049. var rect = svgFactory.createElement("rect");
  14050. var x = (blX - rectBlX) / width;
  14051. var y = (rectTrY - trY) / height;
  14052. var rectWidth = (trX - blX) / width;
  14053. var rectHeight = (trY - blY) / height;
  14054. rect.setAttribute("x", x);
  14055. rect.setAttribute("y", y);
  14056. rect.setAttribute("width", rectWidth);
  14057. rect.setAttribute("height", rectHeight);
  14058. clipPath.append(rect);
  14059. svgBuffer === null || svgBuffer === void 0 ? void 0 : svgBuffer.push("<rect vector-effect=\"non-scaling-stroke\" x=\"".concat(x, "\" y=\"").concat(y, "\" width=\"").concat(rectWidth, "\" height=\"").concat(rectHeight, "\"/>"));
  14060. }
  14061. if (tslib_1.__classPrivateFieldGet(this, _AnnotationElement_hasBorder, "f")) {
  14062. svgBuffer.push("</g></svg>')");
  14063. style.backgroundImage = svgBuffer.join("");
  14064. }
  14065. this.container.append(svg);
  14066. this.container.style.clipPath = "url(#".concat(id, ")");
  14067. };
  14068. AnnotationElement.prototype._createPopup = function () {
  14069. var _l = this, container = _l.container, data = _l.data;
  14070. container.setAttribute("aria-haspopup", "dialog");
  14071. var popup = tslib_1.__classPrivateFieldSet(this, _AnnotationElement_popupElement, new PopupAnnotationElement({
  14072. data: {
  14073. color: data.color,
  14074. titleObj: data.titleObj,
  14075. modificationDate: data.modificationDate,
  14076. contentsObj: data.contentsObj,
  14077. richText: data.richText,
  14078. parentRect: data.rect,
  14079. borderStyle: 0,
  14080. id: "popup_".concat(data.id),
  14081. rotation: data.rotation
  14082. },
  14083. parent: this.parent,
  14084. elements: [this]
  14085. }), "f");
  14086. this.parent.div.append(popup.render());
  14087. };
  14088. AnnotationElement.prototype.render = function () {
  14089. unreachable("Abstract method `AnnotationElement.render` called");
  14090. };
  14091. AnnotationElement.prototype._getElementsByName = function (name, skipId) {
  14092. if (skipId === void 0) { skipId = null; }
  14093. var fields = [];
  14094. if (this._fieldObjects) {
  14095. var fieldObj = this._fieldObjects[name];
  14096. if (fieldObj) {
  14097. for (var _i = 0, fieldObj_1 = fieldObj; _i < fieldObj_1.length; _i++) {
  14098. var _l = fieldObj_1[_i], page = _l.page, id = _l.id, exportValues = _l.exportValues;
  14099. if (page === -1) {
  14100. continue;
  14101. }
  14102. if (id === skipId) {
  14103. continue;
  14104. }
  14105. var exportValue = typeof exportValues === "string" ? exportValues : null;
  14106. var domElement = document.querySelector("[data-element-id=\"".concat(id, "\"]"));
  14107. if (domElement && !GetElementsByNameSet.has(domElement)) {
  14108. warn("_getElementsByName - element not allowed: ".concat(id));
  14109. continue;
  14110. }
  14111. fields.push({
  14112. id: id,
  14113. exportValue: exportValue,
  14114. domElement: domElement
  14115. });
  14116. }
  14117. }
  14118. return fields;
  14119. }
  14120. for (var _m = 0, _o = document.getElementsByName(name); _m < _o.length; _m++) {
  14121. var domElement = _o[_m];
  14122. var exportValue = domElement.exportValue;
  14123. var id = domElement.getAttribute("data-element-id");
  14124. if (id === skipId) {
  14125. continue;
  14126. }
  14127. if (!GetElementsByNameSet.has(domElement)) {
  14128. continue;
  14129. }
  14130. fields.push({
  14131. id: id,
  14132. exportValue: exportValue,
  14133. domElement: domElement
  14134. });
  14135. }
  14136. return fields;
  14137. };
  14138. AnnotationElement.prototype.show = function () {
  14139. var _l;
  14140. if (this.container) {
  14141. this.container.hidden = false;
  14142. }
  14143. (_l = this.popup) === null || _l === void 0 ? void 0 : _l.maybeShow();
  14144. };
  14145. AnnotationElement.prototype.hide = function () {
  14146. var _l;
  14147. if (this.container) {
  14148. this.container.hidden = true;
  14149. }
  14150. (_l = this.popup) === null || _l === void 0 ? void 0 : _l.forceHide();
  14151. };
  14152. AnnotationElement.prototype.getElementsToTriggerPopup = function () {
  14153. return this.container;
  14154. };
  14155. AnnotationElement.prototype.addHighlightArea = function () {
  14156. var triggers = this.getElementsToTriggerPopup();
  14157. if (Array.isArray(triggers)) {
  14158. for (var _i = 0, triggers_1 = triggers; _i < triggers_1.length; _i++) {
  14159. var element = triggers_1[_i];
  14160. element.classList.add("highlightArea");
  14161. }
  14162. }
  14163. else {
  14164. triggers.classList.add("highlightArea");
  14165. }
  14166. };
  14167. Object.defineProperty(AnnotationElement.prototype, "_isEditable", {
  14168. get: function () {
  14169. return false;
  14170. },
  14171. enumerable: false,
  14172. configurable: true
  14173. });
  14174. AnnotationElement.prototype._editOnDoubleClick = function () {
  14175. var _this = this;
  14176. if (!this._isEditable) {
  14177. return;
  14178. }
  14179. var _l = this, mode = _l.annotationEditorType, editId = _l.data.id;
  14180. this.container.addEventListener("dblclick", function () {
  14181. var _l;
  14182. (_l = _this.linkService.eventBus) === null || _l === void 0 ? void 0 : _l.dispatch("switchannotationeditormode", {
  14183. source: _this,
  14184. mode: mode,
  14185. editId: editId
  14186. });
  14187. });
  14188. };
  14189. return AnnotationElement;
  14190. }());
  14191. _AnnotationElement_updates = new WeakMap(), _AnnotationElement_hasBorder = new WeakMap(), _AnnotationElement_popupElement = new WeakMap(), _AnnotationElement_instances = new WeakSet(), _AnnotationElement_setRectEdited = function _AnnotationElement_setRectEdited(rect) {
  14192. var _l = this, style = _l.container.style, _m = _l.data, currentRect = _m.rect, rotation = _m.rotation, _o = _l.parent.viewport.rawDims, pageWidth = _o.pageWidth, pageHeight = _o.pageHeight, pageX = _o.pageX, pageY = _o.pageY;
  14193. currentRect === null || currentRect === void 0 ? void 0 : currentRect.splice.apply(currentRect, tslib_1.__spreadArray([0, 4], rect, false));
  14194. var _p = getRectDims(rect), width = _p.width, height = _p.height;
  14195. style.left = "".concat(100 * (rect[0] - pageX) / pageWidth, "%");
  14196. style.top = "".concat(100 * (pageHeight - rect[3] + pageY) / pageHeight, "%");
  14197. if (rotation === 0) {
  14198. style.width = "".concat(100 * width / pageWidth, "%");
  14199. style.height = "".concat(100 * height / pageHeight, "%");
  14200. }
  14201. else {
  14202. this.setRotation(rotation);
  14203. }
  14204. };
  14205. var LinkAnnotationElement = /** @class */ (function (_super) {
  14206. tslib_1.__extends(LinkAnnotationElement, _super);
  14207. function LinkAnnotationElement(parameters, options) {
  14208. if (options === void 0) { options = null; }
  14209. var _this = _super.call(this, parameters, {
  14210. isRenderable: true,
  14211. ignoreBorder: !!(options === null || options === void 0 ? void 0 : options.ignoreBorder),
  14212. createQuadrilaterals: true
  14213. }) || this;
  14214. _LinkAnnotationElement_instances.add(_this);
  14215. _this.isTooltipOnly = parameters.data.isTooltipOnly;
  14216. return _this;
  14217. }
  14218. LinkAnnotationElement.prototype.render = function () {
  14219. var _l = this, data = _l.data, linkService = _l.linkService;
  14220. var link = document.createElement("a");
  14221. link.setAttribute("data-element-id", data.id);
  14222. var isBound = false;
  14223. if (data.url) {
  14224. linkService.addLinkAttributes(link, data.url, data.newWindow);
  14225. isBound = true;
  14226. }
  14227. else if (data.action) {
  14228. this._bindNamedAction(link, data.action);
  14229. isBound = true;
  14230. }
  14231. else if (data.attachment) {
  14232. tslib_1.__classPrivateFieldGet(this, _LinkAnnotationElement_instances, "m", _LinkAnnotationElement_bindAttachment).call(this, link, data.attachment, data.attachmentDest);
  14233. isBound = true;
  14234. }
  14235. else if (data.setOCGState) {
  14236. tslib_1.__classPrivateFieldGet(this, _LinkAnnotationElement_instances, "m", _LinkAnnotationElement_bindSetOCGState).call(this, link, data.setOCGState);
  14237. isBound = true;
  14238. }
  14239. else if (data.dest) {
  14240. this._bindLink(link, data.dest);
  14241. isBound = true;
  14242. }
  14243. else {
  14244. if (data.actions && (data.actions.Action || data.actions["Mouse Up"] || data.actions["Mouse Down"]) && this.enableScripting && this.hasJSActions) {
  14245. this._bindJSAction(link, data);
  14246. isBound = true;
  14247. }
  14248. if (data.resetForm) {
  14249. this._bindResetFormAction(link, data.resetForm);
  14250. isBound = true;
  14251. }
  14252. else if (this.isTooltipOnly && !isBound) {
  14253. this._bindLink(link, "");
  14254. isBound = true;
  14255. }
  14256. }
  14257. this.container.classList.add("linkAnnotation");
  14258. if (isBound) {
  14259. this.container.append(link);
  14260. }
  14261. return this.container;
  14262. };
  14263. LinkAnnotationElement.prototype._bindLink = function (link, destination) {
  14264. var _this = this;
  14265. link.href = this.linkService.getDestinationHash(destination);
  14266. link.onclick = function () {
  14267. if (destination) {
  14268. _this.linkService.goToDestination(destination);
  14269. }
  14270. return false;
  14271. };
  14272. if (destination || destination === "") {
  14273. tslib_1.__classPrivateFieldGet(this, _LinkAnnotationElement_instances, "m", _LinkAnnotationElement_setInternalLink).call(this);
  14274. }
  14275. };
  14276. LinkAnnotationElement.prototype._bindNamedAction = function (link, action) {
  14277. var _this = this;
  14278. link.href = this.linkService.getAnchorUrl("");
  14279. link.onclick = function () {
  14280. _this.linkService.executeNamedAction(action);
  14281. return false;
  14282. };
  14283. tslib_1.__classPrivateFieldGet(this, _LinkAnnotationElement_instances, "m", _LinkAnnotationElement_setInternalLink).call(this);
  14284. };
  14285. LinkAnnotationElement.prototype._bindJSAction = function (link, data) {
  14286. var _this = this;
  14287. link.href = this.linkService.getAnchorUrl("");
  14288. var map = new Map([["Action", "onclick"], ["Mouse Up", "onmouseup"], ["Mouse Down", "onmousedown"]]);
  14289. var _loop_4 = function (name) {
  14290. var jsName = map.get(name);
  14291. if (!jsName) {
  14292. return "continue";
  14293. }
  14294. link[jsName] = function () {
  14295. var _l;
  14296. (_l = _this.linkService.eventBus) === null || _l === void 0 ? void 0 : _l.dispatch("dispatcheventinsandbox", {
  14297. source: _this,
  14298. detail: {
  14299. id: data.id,
  14300. name: name
  14301. }
  14302. });
  14303. return false;
  14304. };
  14305. };
  14306. for (var _i = 0, _l = Object.keys(data.actions); _i < _l.length; _i++) {
  14307. var name = _l[_i];
  14308. _loop_4(name);
  14309. }
  14310. if (!link.onclick) {
  14311. link.onclick = function () { return false; };
  14312. }
  14313. tslib_1.__classPrivateFieldGet(this, _LinkAnnotationElement_instances, "m", _LinkAnnotationElement_setInternalLink).call(this);
  14314. };
  14315. LinkAnnotationElement.prototype._bindResetFormAction = function (link, resetForm) {
  14316. var _this = this;
  14317. var otherClickAction = link.onclick;
  14318. if (!otherClickAction) {
  14319. link.href = this.linkService.getAnchorUrl("");
  14320. }
  14321. tslib_1.__classPrivateFieldGet(this, _LinkAnnotationElement_instances, "m", _LinkAnnotationElement_setInternalLink).call(this);
  14322. if (!this._fieldObjects) {
  14323. warn("_bindResetFormAction - \"resetForm\" action not supported, " + "ensure that the `fieldObjects` parameter is provided.");
  14324. if (!otherClickAction) {
  14325. link.onclick = function () { return false; };
  14326. }
  14327. return;
  14328. }
  14329. link.onclick = function () {
  14330. var _l;
  14331. otherClickAction === null || otherClickAction === void 0 ? void 0 : otherClickAction();
  14332. var resetFormFields = resetForm.fields, resetFormRefs = resetForm.refs, include = resetForm.include;
  14333. var allFields = [];
  14334. if (resetFormFields.length !== 0 || resetFormRefs.length !== 0) {
  14335. var fieldIds = new Set(resetFormRefs);
  14336. for (var _i = 0, resetFormFields_1 = resetFormFields; _i < resetFormFields_1.length; _i++) {
  14337. var fieldName = resetFormFields_1[_i];
  14338. var fields = _this._fieldObjects[fieldName] || [];
  14339. for (var _m = 0, fields_1 = fields; _m < fields_1.length; _m++) {
  14340. var id = fields_1[_m].id;
  14341. fieldIds.add(id);
  14342. }
  14343. }
  14344. for (var _o = 0, _p = Object.values(_this._fieldObjects); _o < _p.length; _o++) {
  14345. var fields = _p[_o];
  14346. for (var _q = 0, fields_2 = fields; _q < fields_2.length; _q++) {
  14347. var field = fields_2[_q];
  14348. if (fieldIds.has(field.id) === include) {
  14349. allFields.push(field);
  14350. }
  14351. }
  14352. }
  14353. }
  14354. else {
  14355. for (var _r = 0, _s = Object.values(_this._fieldObjects); _r < _s.length; _r++) {
  14356. var fields = _s[_r];
  14357. allFields.push.apply(allFields, fields);
  14358. }
  14359. }
  14360. var storage = _this.annotationStorage;
  14361. var allIds = [];
  14362. for (var _t = 0, allFields_1 = allFields; _t < allFields_1.length; _t++) {
  14363. var field = allFields_1[_t];
  14364. var id = field.id;
  14365. allIds.push(id);
  14366. switch (field.type) {
  14367. case "text":
  14368. {
  14369. var value = field.defaultValue || "";
  14370. storage.setValue(id, {
  14371. value: value
  14372. });
  14373. break;
  14374. }
  14375. case "checkbox":
  14376. case "radiobutton":
  14377. {
  14378. var value = field.defaultValue === field.exportValues;
  14379. storage.setValue(id, {
  14380. value: value
  14381. });
  14382. break;
  14383. }
  14384. case "combobox":
  14385. case "listbox":
  14386. {
  14387. var value = field.defaultValue || "";
  14388. storage.setValue(id, {
  14389. value: value
  14390. });
  14391. break;
  14392. }
  14393. default:
  14394. continue;
  14395. }
  14396. var domElement = document.querySelector("[data-element-id=\"".concat(id, "\"]"));
  14397. if (!domElement) {
  14398. continue;
  14399. }
  14400. else if (!GetElementsByNameSet.has(domElement)) {
  14401. warn("_bindResetFormAction - element not allowed: ".concat(id));
  14402. continue;
  14403. }
  14404. domElement.dispatchEvent(new Event("resetform"));
  14405. }
  14406. if (_this.enableScripting) {
  14407. (_l = _this.linkService.eventBus) === null || _l === void 0 ? void 0 : _l.dispatch("dispatcheventinsandbox", {
  14408. source: _this,
  14409. detail: {
  14410. id: "app",
  14411. ids: allIds,
  14412. name: "ResetForm"
  14413. }
  14414. });
  14415. }
  14416. return false;
  14417. };
  14418. };
  14419. return LinkAnnotationElement;
  14420. }(AnnotationElement));
  14421. _LinkAnnotationElement_instances = new WeakSet(), _LinkAnnotationElement_setInternalLink = function _LinkAnnotationElement_setInternalLink() {
  14422. this.container.setAttribute("data-internal-link", "");
  14423. }, _LinkAnnotationElement_bindAttachment = function _LinkAnnotationElement_bindAttachment(link, attachment, dest) {
  14424. var _this = this;
  14425. if (dest === void 0) { dest = null; }
  14426. link.href = this.linkService.getAnchorUrl("");
  14427. if (attachment.description) {
  14428. link.title = attachment.description;
  14429. }
  14430. link.onclick = function () {
  14431. var _l;
  14432. (_l = _this.downloadManager) === null || _l === void 0 ? void 0 : _l.openOrDownloadData(attachment.content, attachment.filename, dest);
  14433. return false;
  14434. };
  14435. tslib_1.__classPrivateFieldGet(this, _LinkAnnotationElement_instances, "m", _LinkAnnotationElement_setInternalLink).call(this);
  14436. }, _LinkAnnotationElement_bindSetOCGState = function _LinkAnnotationElement_bindSetOCGState(link, action) {
  14437. var _this = this;
  14438. link.href = this.linkService.getAnchorUrl("");
  14439. link.onclick = function () {
  14440. _this.linkService.executeSetOCGState(action);
  14441. return false;
  14442. };
  14443. tslib_1.__classPrivateFieldGet(this, _LinkAnnotationElement_instances, "m", _LinkAnnotationElement_setInternalLink).call(this);
  14444. };
  14445. var TextAnnotationElement = /** @class */ (function (_super) {
  14446. tslib_1.__extends(TextAnnotationElement, _super);
  14447. function TextAnnotationElement(parameters) {
  14448. return _super.call(this, parameters, {
  14449. isRenderable: true
  14450. }) || this;
  14451. }
  14452. TextAnnotationElement.prototype.render = function () {
  14453. this.container.classList.add("textAnnotation");
  14454. var image = document.createElement("img");
  14455. image.src = this.imageResourcesPath + "annotation-" + this.data.name.toLowerCase() + ".svg";
  14456. image.setAttribute("data-l10n-id", "pdfjs-text-annotation-type");
  14457. image.setAttribute("data-l10n-args", JSON.stringify({
  14458. type: this.data.name
  14459. }));
  14460. if (!this.data.popupRef && this.hasPopupData) {
  14461. this._createPopup();
  14462. }
  14463. this.container.append(image);
  14464. return this.container;
  14465. };
  14466. return TextAnnotationElement;
  14467. }(AnnotationElement));
  14468. var WidgetAnnotationElement = /** @class */ (function (_super) {
  14469. tslib_1.__extends(WidgetAnnotationElement, _super);
  14470. function WidgetAnnotationElement() {
  14471. return _super !== null && _super.apply(this, arguments) || this;
  14472. }
  14473. WidgetAnnotationElement.prototype.render = function () {
  14474. return this.container;
  14475. };
  14476. WidgetAnnotationElement.prototype.showElementAndHideCanvas = function (element) {
  14477. var _l;
  14478. if (this.data.hasOwnCanvas) {
  14479. if (((_l = element.previousSibling) === null || _l === void 0 ? void 0 : _l.nodeName) === "CANVAS") {
  14480. element.previousSibling.hidden = true;
  14481. }
  14482. element.hidden = false;
  14483. }
  14484. };
  14485. WidgetAnnotationElement.prototype._getKeyModifier = function (event) {
  14486. return util_FeatureTest.platform.isMac ? event.metaKey : event.ctrlKey;
  14487. };
  14488. WidgetAnnotationElement.prototype._setEventListener = function (element, elementData, baseName, eventName, valueGetter) {
  14489. var _this = this;
  14490. if (baseName.includes("mouse")) {
  14491. element.addEventListener(baseName, function (event) {
  14492. var _l;
  14493. (_l = _this.linkService.eventBus) === null || _l === void 0 ? void 0 : _l.dispatch("dispatcheventinsandbox", {
  14494. source: _this,
  14495. detail: {
  14496. id: _this.data.id,
  14497. name: eventName,
  14498. value: valueGetter(event),
  14499. shift: event.shiftKey,
  14500. modifier: _this._getKeyModifier(event)
  14501. }
  14502. });
  14503. });
  14504. }
  14505. else {
  14506. element.addEventListener(baseName, function (event) {
  14507. var _l;
  14508. if (baseName === "blur") {
  14509. if (!elementData.focused || !event.relatedTarget) {
  14510. return;
  14511. }
  14512. elementData.focused = false;
  14513. }
  14514. else if (baseName === "focus") {
  14515. if (elementData.focused) {
  14516. return;
  14517. }
  14518. elementData.focused = true;
  14519. }
  14520. if (!valueGetter) {
  14521. return;
  14522. }
  14523. (_l = _this.linkService.eventBus) === null || _l === void 0 ? void 0 : _l.dispatch("dispatcheventinsandbox", {
  14524. source: _this,
  14525. detail: {
  14526. id: _this.data.id,
  14527. name: eventName,
  14528. value: valueGetter(event)
  14529. }
  14530. });
  14531. });
  14532. }
  14533. };
  14534. WidgetAnnotationElement.prototype._setEventListeners = function (element, elementData, names, getter) {
  14535. var _l, _m, _o;
  14536. for (var _i = 0, names_2 = names; _i < names_2.length; _i++) {
  14537. var _p = names_2[_i], baseName = _p[0], eventName = _p[1];
  14538. if (eventName === "Action" || ((_l = this.data.actions) === null || _l === void 0 ? void 0 : _l[eventName])) {
  14539. if (eventName === "Focus" || eventName === "Blur") {
  14540. elementData || (elementData = {
  14541. focused: false
  14542. });
  14543. }
  14544. this._setEventListener(element, elementData, baseName, eventName, getter);
  14545. if (eventName === "Focus" && !((_m = this.data.actions) === null || _m === void 0 ? void 0 : _m.Blur)) {
  14546. this._setEventListener(element, elementData, "blur", "Blur", null);
  14547. }
  14548. else if (eventName === "Blur" && !((_o = this.data.actions) === null || _o === void 0 ? void 0 : _o.Focus)) {
  14549. this._setEventListener(element, elementData, "focus", "Focus", null);
  14550. }
  14551. }
  14552. }
  14553. };
  14554. WidgetAnnotationElement.prototype._setBackgroundColor = function (element) {
  14555. var color = this.data.backgroundColor || null;
  14556. element.style.backgroundColor = color === null ? "transparent" : Util.makeHexColor(color[0], color[1], color[2]);
  14557. };
  14558. WidgetAnnotationElement.prototype._setTextStyle = function (element) {
  14559. var TEXT_ALIGNMENT = ["left", "center", "right"];
  14560. var fontColor = this.data.defaultAppearanceData.fontColor;
  14561. var fontSize = this.data.defaultAppearanceData.fontSize || annotation_layer_DEFAULT_FONT_SIZE;
  14562. var style = element.style;
  14563. var computedFontSize;
  14564. var BORDER_SIZE = 2;
  14565. var roundToOneDecimal = function (x) { return Math.round(10 * x) / 10; };
  14566. if (this.data.multiLine) {
  14567. var height = Math.abs(this.data.rect[3] - this.data.rect[1] - BORDER_SIZE);
  14568. var numberOfLines = Math.round(height / (LINE_FACTOR * fontSize)) || 1;
  14569. var lineHeight = height / numberOfLines;
  14570. computedFontSize = Math.min(fontSize, roundToOneDecimal(lineHeight / LINE_FACTOR));
  14571. }
  14572. else {
  14573. var height = Math.abs(this.data.rect[3] - this.data.rect[1] - BORDER_SIZE);
  14574. computedFontSize = Math.min(fontSize, roundToOneDecimal(height / LINE_FACTOR));
  14575. }
  14576. style.fontSize = "calc(".concat(computedFontSize, "px * var(--scale-factor))");
  14577. style.color = Util.makeHexColor(fontColor[0], fontColor[1], fontColor[2]);
  14578. if (this.data.textAlignment !== null) {
  14579. style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
  14580. }
  14581. };
  14582. WidgetAnnotationElement.prototype._setRequired = function (element, isRequired) {
  14583. if (isRequired) {
  14584. element.setAttribute("required", true);
  14585. }
  14586. else {
  14587. element.removeAttribute("required");
  14588. }
  14589. element.setAttribute("aria-required", isRequired);
  14590. };
  14591. return WidgetAnnotationElement;
  14592. }(AnnotationElement));
  14593. var TextWidgetAnnotationElement = /** @class */ (function (_super) {
  14594. tslib_1.__extends(TextWidgetAnnotationElement, _super);
  14595. function TextWidgetAnnotationElement(parameters) {
  14596. var isRenderable = parameters.renderForms || parameters.data.hasOwnCanvas || !parameters.data.hasAppearance && !!parameters.data.fieldValue;
  14597. return _super.call(this, parameters, {
  14598. isRenderable: isRenderable
  14599. }) || this;
  14600. }
  14601. TextWidgetAnnotationElement.prototype.setPropertyOnSiblings = function (base, key, value, keyInStorage) {
  14602. var _l;
  14603. var storage = this.annotationStorage;
  14604. for (var _i = 0, _m = this._getElementsByName(base.name, base.id); _i < _m.length; _i++) {
  14605. var element = _m[_i];
  14606. if (element.domElement) {
  14607. element.domElement[key] = value;
  14608. }
  14609. storage.setValue(element.id, (_l = {},
  14610. _l[keyInStorage] = value,
  14611. _l));
  14612. }
  14613. };
  14614. TextWidgetAnnotationElement.prototype.render = function () {
  14615. var _this = this;
  14616. var _l, _m;
  14617. var storage = this.annotationStorage;
  14618. var id = this.data.id;
  14619. this.container.classList.add("textWidgetAnnotation");
  14620. var element = null;
  14621. if (this.renderForms) {
  14622. var storedData = storage.getValue(id, {
  14623. value: this.data.fieldValue
  14624. });
  14625. var textContent = storedData.value || "";
  14626. var maxLen = storage.getValue(id, {
  14627. charLimit: this.data.maxLen
  14628. }).charLimit;
  14629. if (maxLen && textContent.length > maxLen) {
  14630. textContent = textContent.slice(0, maxLen);
  14631. }
  14632. var fieldFormattedValues = storedData.formattedValue || ((_l = this.data.textContent) === null || _l === void 0 ? void 0 : _l.join("\n")) || null;
  14633. if (fieldFormattedValues && this.data.comb) {
  14634. fieldFormattedValues = fieldFormattedValues.replaceAll(/\s+/g, "");
  14635. }
  14636. var elementData_1 = {
  14637. userValue: textContent,
  14638. formattedValue: fieldFormattedValues,
  14639. lastCommittedValue: null,
  14640. commitKey: 1,
  14641. focused: false
  14642. };
  14643. if (this.data.multiLine) {
  14644. element = document.createElement("textarea");
  14645. element.textContent = fieldFormattedValues !== null && fieldFormattedValues !== void 0 ? fieldFormattedValues : textContent;
  14646. if (this.data.doNotScroll) {
  14647. element.style.overflowY = "hidden";
  14648. }
  14649. }
  14650. else {
  14651. element = document.createElement("input");
  14652. element.type = "text";
  14653. element.setAttribute("value", fieldFormattedValues !== null && fieldFormattedValues !== void 0 ? fieldFormattedValues : textContent);
  14654. if (this.data.doNotScroll) {
  14655. element.style.overflowX = "hidden";
  14656. }
  14657. }
  14658. if (this.data.hasOwnCanvas) {
  14659. element.hidden = true;
  14660. }
  14661. GetElementsByNameSet.add(element);
  14662. element.setAttribute("data-element-id", id);
  14663. element.disabled = this.data.readOnly;
  14664. element.name = this.data.fieldName;
  14665. element.tabIndex = DEFAULT_TAB_INDEX;
  14666. this._setRequired(element, this.data.required);
  14667. if (maxLen) {
  14668. element.maxLength = maxLen;
  14669. }
  14670. element.addEventListener("input", function (event) {
  14671. storage.setValue(id, {
  14672. value: event.target.value
  14673. });
  14674. _this.setPropertyOnSiblings(element, "value", event.target.value, "value");
  14675. elementData_1.formattedValue = null;
  14676. });
  14677. element.addEventListener("resetform", function (event) {
  14678. var _l;
  14679. var defaultValue = (_l = _this.data.defaultFieldValue) !== null && _l !== void 0 ? _l : "";
  14680. element.value = elementData_1.userValue = defaultValue;
  14681. elementData_1.formattedValue = null;
  14682. });
  14683. var blurListener = function (event) {
  14684. var formattedValue = elementData_1.formattedValue;
  14685. if (formattedValue !== null && formattedValue !== undefined) {
  14686. event.target.value = formattedValue;
  14687. }
  14688. event.target.scrollLeft = 0;
  14689. };
  14690. if (this.enableScripting && this.hasJSActions) {
  14691. element.addEventListener("focus", function (event) {
  14692. var _l;
  14693. if (elementData_1.focused) {
  14694. return;
  14695. }
  14696. var target = event.target;
  14697. if (elementData_1.userValue) {
  14698. target.value = elementData_1.userValue;
  14699. }
  14700. elementData_1.lastCommittedValue = target.value;
  14701. elementData_1.commitKey = 1;
  14702. if (!((_l = _this.data.actions) === null || _l === void 0 ? void 0 : _l.Focus)) {
  14703. elementData_1.focused = true;
  14704. }
  14705. });
  14706. element.addEventListener("updatefromsandbox", function (jsEvent) {
  14707. _this.showElementAndHideCanvas(jsEvent.target);
  14708. var actions = {
  14709. value: function (event) {
  14710. var _l;
  14711. elementData_1.userValue = (_l = event.detail.value) !== null && _l !== void 0 ? _l : "";
  14712. storage.setValue(id, {
  14713. value: elementData_1.userValue.toString()
  14714. });
  14715. event.target.value = elementData_1.userValue;
  14716. },
  14717. formattedValue: function (event) {
  14718. var formattedValue = event.detail.formattedValue;
  14719. elementData_1.formattedValue = formattedValue;
  14720. if (formattedValue !== null && formattedValue !== undefined && event.target !== document.activeElement) {
  14721. event.target.value = formattedValue;
  14722. }
  14723. storage.setValue(id, {
  14724. formattedValue: formattedValue
  14725. });
  14726. },
  14727. selRange: function (event) {
  14728. var _l;
  14729. (_l = event.target).setSelectionRange.apply(_l, event.detail.selRange);
  14730. },
  14731. charLimit: function (event) {
  14732. var _l;
  14733. var charLimit = event.detail.charLimit;
  14734. var target = event.target;
  14735. if (charLimit === 0) {
  14736. target.removeAttribute("maxLength");
  14737. return;
  14738. }
  14739. target.setAttribute("maxLength", charLimit);
  14740. var value = elementData_1.userValue;
  14741. if (!value || value.length <= charLimit) {
  14742. return;
  14743. }
  14744. value = value.slice(0, charLimit);
  14745. target.value = elementData_1.userValue = value;
  14746. storage.setValue(id, {
  14747. value: value
  14748. });
  14749. (_l = _this.linkService.eventBus) === null || _l === void 0 ? void 0 : _l.dispatch("dispatcheventinsandbox", {
  14750. source: _this,
  14751. detail: {
  14752. id: id,
  14753. name: "Keystroke",
  14754. value: value,
  14755. willCommit: true,
  14756. commitKey: 1,
  14757. selStart: target.selectionStart,
  14758. selEnd: target.selectionEnd
  14759. }
  14760. });
  14761. }
  14762. };
  14763. _this._dispatchEventFromSandbox(actions, jsEvent);
  14764. });
  14765. element.addEventListener("keydown", function (event) {
  14766. var _l;
  14767. elementData_1.commitKey = 1;
  14768. var commitKey = -1;
  14769. if (event.key === "Escape") {
  14770. commitKey = 0;
  14771. }
  14772. else if (event.key === "Enter" && !_this.data.multiLine) {
  14773. commitKey = 2;
  14774. }
  14775. else if (event.key === "Tab") {
  14776. elementData_1.commitKey = 3;
  14777. }
  14778. if (commitKey === -1) {
  14779. return;
  14780. }
  14781. var value = event.target.value;
  14782. if (elementData_1.lastCommittedValue === value) {
  14783. return;
  14784. }
  14785. elementData_1.lastCommittedValue = value;
  14786. elementData_1.userValue = value;
  14787. (_l = _this.linkService.eventBus) === null || _l === void 0 ? void 0 : _l.dispatch("dispatcheventinsandbox", {
  14788. source: _this,
  14789. detail: {
  14790. id: id,
  14791. name: "Keystroke",
  14792. value: value,
  14793. willCommit: true,
  14794. commitKey: commitKey,
  14795. selStart: event.target.selectionStart,
  14796. selEnd: event.target.selectionEnd
  14797. }
  14798. });
  14799. });
  14800. var _blurListener_1 = blurListener;
  14801. blurListener = null;
  14802. element.addEventListener("blur", function (event) {
  14803. var _l, _m;
  14804. if (!elementData_1.focused || !event.relatedTarget) {
  14805. return;
  14806. }
  14807. if (!((_l = _this.data.actions) === null || _l === void 0 ? void 0 : _l.Blur)) {
  14808. elementData_1.focused = false;
  14809. }
  14810. var value = event.target.value;
  14811. elementData_1.userValue = value;
  14812. if (elementData_1.lastCommittedValue !== value) {
  14813. (_m = _this.linkService.eventBus) === null || _m === void 0 ? void 0 : _m.dispatch("dispatcheventinsandbox", {
  14814. source: _this,
  14815. detail: {
  14816. id: id,
  14817. name: "Keystroke",
  14818. value: value,
  14819. willCommit: true,
  14820. commitKey: elementData_1.commitKey,
  14821. selStart: event.target.selectionStart,
  14822. selEnd: event.target.selectionEnd
  14823. }
  14824. });
  14825. }
  14826. _blurListener_1(event);
  14827. });
  14828. if ((_m = this.data.actions) === null || _m === void 0 ? void 0 : _m.Keystroke) {
  14829. element.addEventListener("beforeinput", function (event) {
  14830. var _l;
  14831. elementData_1.lastCommittedValue = null;
  14832. var data = event.data, target = event.target;
  14833. var value = target.value, selectionStart = target.selectionStart, selectionEnd = target.selectionEnd;
  14834. var selStart = selectionStart, selEnd = selectionEnd;
  14835. switch (event.inputType) {
  14836. case "deleteWordBackward":
  14837. {
  14838. var match = value.substring(0, selectionStart).match(/\w*[^\w]*$/);
  14839. if (match) {
  14840. selStart -= match[0].length;
  14841. }
  14842. break;
  14843. }
  14844. case "deleteWordForward":
  14845. {
  14846. var match = value.substring(selectionStart).match(/^[^\w]*\w*/);
  14847. if (match) {
  14848. selEnd += match[0].length;
  14849. }
  14850. break;
  14851. }
  14852. case "deleteContentBackward":
  14853. if (selectionStart === selectionEnd) {
  14854. selStart -= 1;
  14855. }
  14856. break;
  14857. case "deleteContentForward":
  14858. if (selectionStart === selectionEnd) {
  14859. selEnd += 1;
  14860. }
  14861. break;
  14862. }
  14863. event.preventDefault();
  14864. (_l = _this.linkService.eventBus) === null || _l === void 0 ? void 0 : _l.dispatch("dispatcheventinsandbox", {
  14865. source: _this,
  14866. detail: {
  14867. id: id,
  14868. name: "Keystroke",
  14869. value: value,
  14870. change: data || "",
  14871. willCommit: false,
  14872. selStart: selStart,
  14873. selEnd: selEnd
  14874. }
  14875. });
  14876. });
  14877. }
  14878. this._setEventListeners(element, elementData_1, [["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"]], function (event) { return event.target.value; });
  14879. }
  14880. if (blurListener) {
  14881. element.addEventListener("blur", blurListener);
  14882. }
  14883. if (this.data.comb) {
  14884. var fieldWidth = this.data.rect[2] - this.data.rect[0];
  14885. var combWidth = fieldWidth / maxLen;
  14886. element.classList.add("comb");
  14887. element.style.letterSpacing = "calc(".concat(combWidth, "px * var(--scale-factor) - 1ch)");
  14888. }
  14889. }
  14890. else {
  14891. element = document.createElement("div");
  14892. element.textContent = this.data.fieldValue;
  14893. element.style.verticalAlign = "middle";
  14894. element.style.display = "table-cell";
  14895. if (this.data.hasOwnCanvas) {
  14896. element.hidden = true;
  14897. }
  14898. }
  14899. this._setTextStyle(element);
  14900. this._setBackgroundColor(element);
  14901. this._setDefaultPropertiesFromJS(element);
  14902. this.container.append(element);
  14903. return this.container;
  14904. };
  14905. return TextWidgetAnnotationElement;
  14906. }(WidgetAnnotationElement));
  14907. var SignatureWidgetAnnotationElement = /** @class */ (function (_super) {
  14908. tslib_1.__extends(SignatureWidgetAnnotationElement, _super);
  14909. function SignatureWidgetAnnotationElement(parameters) {
  14910. return _super.call(this, parameters, {
  14911. isRenderable: !!parameters.data.hasOwnCanvas
  14912. }) || this;
  14913. }
  14914. return SignatureWidgetAnnotationElement;
  14915. }(WidgetAnnotationElement));
  14916. var CheckboxWidgetAnnotationElement = /** @class */ (function (_super) {
  14917. tslib_1.__extends(CheckboxWidgetAnnotationElement, _super);
  14918. function CheckboxWidgetAnnotationElement(parameters) {
  14919. return _super.call(this, parameters, {
  14920. isRenderable: parameters.renderForms
  14921. }) || this;
  14922. }
  14923. CheckboxWidgetAnnotationElement.prototype.render = function () {
  14924. var _this = this;
  14925. var storage = this.annotationStorage;
  14926. var data = this.data;
  14927. var id = data.id;
  14928. var value = storage.getValue(id, {
  14929. value: data.exportValue === data.fieldValue
  14930. }).value;
  14931. if (typeof value === "string") {
  14932. value = value !== "Off";
  14933. storage.setValue(id, {
  14934. value: value
  14935. });
  14936. }
  14937. this.container.classList.add("buttonWidgetAnnotation", "checkBox");
  14938. var element = document.createElement("input");
  14939. GetElementsByNameSet.add(element);
  14940. element.setAttribute("data-element-id", id);
  14941. element.disabled = data.readOnly;
  14942. this._setRequired(element, this.data.required);
  14943. element.type = "checkbox";
  14944. element.name = data.fieldName;
  14945. if (value) {
  14946. element.setAttribute("checked", true);
  14947. }
  14948. element.setAttribute("exportValue", data.exportValue);
  14949. element.tabIndex = DEFAULT_TAB_INDEX;
  14950. element.addEventListener("change", function (event) {
  14951. var _l = event.target, name = _l.name, checked = _l.checked;
  14952. for (var _i = 0, _m = _this._getElementsByName(name, id); _i < _m.length; _i++) {
  14953. var checkbox = _m[_i];
  14954. var curChecked = checked && checkbox.exportValue === data.exportValue;
  14955. if (checkbox.domElement) {
  14956. checkbox.domElement.checked = curChecked;
  14957. }
  14958. storage.setValue(checkbox.id, {
  14959. value: curChecked
  14960. });
  14961. }
  14962. storage.setValue(id, {
  14963. value: checked
  14964. });
  14965. });
  14966. element.addEventListener("resetform", function (event) {
  14967. var defaultValue = data.defaultFieldValue || "Off";
  14968. event.target.checked = defaultValue === data.exportValue;
  14969. });
  14970. if (this.enableScripting && this.hasJSActions) {
  14971. element.addEventListener("updatefromsandbox", function (jsEvent) {
  14972. var actions = {
  14973. value: function (event) {
  14974. event.target.checked = event.detail.value !== "Off";
  14975. storage.setValue(id, {
  14976. value: event.target.checked
  14977. });
  14978. }
  14979. };
  14980. _this._dispatchEventFromSandbox(actions, jsEvent);
  14981. });
  14982. this._setEventListeners(element, null, [["change", "Validate"], ["change", "Action"], ["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"]], function (event) { return event.target.checked; });
  14983. }
  14984. this._setBackgroundColor(element);
  14985. this._setDefaultPropertiesFromJS(element);
  14986. this.container.append(element);
  14987. return this.container;
  14988. };
  14989. return CheckboxWidgetAnnotationElement;
  14990. }(WidgetAnnotationElement));
  14991. var RadioButtonWidgetAnnotationElement = /** @class */ (function (_super) {
  14992. tslib_1.__extends(RadioButtonWidgetAnnotationElement, _super);
  14993. function RadioButtonWidgetAnnotationElement(parameters) {
  14994. return _super.call(this, parameters, {
  14995. isRenderable: parameters.renderForms
  14996. }) || this;
  14997. }
  14998. RadioButtonWidgetAnnotationElement.prototype.render = function () {
  14999. var _this = this;
  15000. this.container.classList.add("buttonWidgetAnnotation", "radioButton");
  15001. var storage = this.annotationStorage;
  15002. var data = this.data;
  15003. var id = data.id;
  15004. var value = storage.getValue(id, {
  15005. value: data.fieldValue === data.buttonValue
  15006. }).value;
  15007. if (typeof value === "string") {
  15008. value = value !== data.buttonValue;
  15009. storage.setValue(id, {
  15010. value: value
  15011. });
  15012. }
  15013. if (value) {
  15014. for (var _i = 0, _l = this._getElementsByName(data.fieldName, id); _i < _l.length; _i++) {
  15015. var radio = _l[_i];
  15016. storage.setValue(radio.id, {
  15017. value: false
  15018. });
  15019. }
  15020. }
  15021. var element = document.createElement("input");
  15022. GetElementsByNameSet.add(element);
  15023. element.setAttribute("data-element-id", id);
  15024. element.disabled = data.readOnly;
  15025. this._setRequired(element, this.data.required);
  15026. element.type = "radio";
  15027. element.name = data.fieldName;
  15028. if (value) {
  15029. element.setAttribute("checked", true);
  15030. }
  15031. element.tabIndex = DEFAULT_TAB_INDEX;
  15032. element.addEventListener("change", function (event) {
  15033. var _l = event.target, name = _l.name, checked = _l.checked;
  15034. for (var _i = 0, _m = _this._getElementsByName(name, id); _i < _m.length; _i++) {
  15035. var radio = _m[_i];
  15036. storage.setValue(radio.id, {
  15037. value: false
  15038. });
  15039. }
  15040. storage.setValue(id, {
  15041. value: checked
  15042. });
  15043. });
  15044. element.addEventListener("resetform", function (event) {
  15045. var defaultValue = data.defaultFieldValue;
  15046. event.target.checked = defaultValue !== null && defaultValue !== undefined && defaultValue === data.buttonValue;
  15047. });
  15048. if (this.enableScripting && this.hasJSActions) {
  15049. var pdfButtonValue_1 = data.buttonValue;
  15050. element.addEventListener("updatefromsandbox", function (jsEvent) {
  15051. var actions = {
  15052. value: function (event) {
  15053. var checked = pdfButtonValue_1 === event.detail.value;
  15054. for (var _i = 0, _l = _this._getElementsByName(event.target.name); _i < _l.length; _i++) {
  15055. var radio = _l[_i];
  15056. var curChecked = checked && radio.id === id;
  15057. if (radio.domElement) {
  15058. radio.domElement.checked = curChecked;
  15059. }
  15060. storage.setValue(radio.id, {
  15061. value: curChecked
  15062. });
  15063. }
  15064. }
  15065. };
  15066. _this._dispatchEventFromSandbox(actions, jsEvent);
  15067. });
  15068. this._setEventListeners(element, null, [["change", "Validate"], ["change", "Action"], ["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"]], function (event) { return event.target.checked; });
  15069. }
  15070. this._setBackgroundColor(element);
  15071. this._setDefaultPropertiesFromJS(element);
  15072. this.container.append(element);
  15073. return this.container;
  15074. };
  15075. return RadioButtonWidgetAnnotationElement;
  15076. }(WidgetAnnotationElement));
  15077. var PushButtonWidgetAnnotationElement = /** @class */ (function (_super) {
  15078. tslib_1.__extends(PushButtonWidgetAnnotationElement, _super);
  15079. function PushButtonWidgetAnnotationElement(parameters) {
  15080. return _super.call(this, parameters, {
  15081. ignoreBorder: parameters.data.hasAppearance
  15082. }) || this;
  15083. }
  15084. PushButtonWidgetAnnotationElement.prototype.render = function () {
  15085. var _this = this;
  15086. var container = _super.prototype.render.call(this);
  15087. container.classList.add("buttonWidgetAnnotation", "pushButton");
  15088. var linkElement = container.lastChild;
  15089. if (this.enableScripting && this.hasJSActions && linkElement) {
  15090. this._setDefaultPropertiesFromJS(linkElement);
  15091. linkElement.addEventListener("updatefromsandbox", function (jsEvent) {
  15092. _this._dispatchEventFromSandbox({}, jsEvent);
  15093. });
  15094. }
  15095. return container;
  15096. };
  15097. return PushButtonWidgetAnnotationElement;
  15098. }(LinkAnnotationElement));
  15099. var ChoiceWidgetAnnotationElement = /** @class */ (function (_super) {
  15100. tslib_1.__extends(ChoiceWidgetAnnotationElement, _super);
  15101. function ChoiceWidgetAnnotationElement(parameters) {
  15102. return _super.call(this, parameters, {
  15103. isRenderable: parameters.renderForms
  15104. }) || this;
  15105. }
  15106. ChoiceWidgetAnnotationElement.prototype.render = function () {
  15107. var _this = this;
  15108. this.container.classList.add("choiceWidgetAnnotation");
  15109. var storage = this.annotationStorage;
  15110. var id = this.data.id;
  15111. var storedData = storage.getValue(id, {
  15112. value: this.data.fieldValue
  15113. });
  15114. var selectElement = document.createElement("select");
  15115. GetElementsByNameSet.add(selectElement);
  15116. selectElement.setAttribute("data-element-id", id);
  15117. selectElement.disabled = this.data.readOnly;
  15118. this._setRequired(selectElement, this.data.required);
  15119. selectElement.name = this.data.fieldName;
  15120. selectElement.tabIndex = DEFAULT_TAB_INDEX;
  15121. var addAnEmptyEntry = this.data.combo && this.data.options.length > 0;
  15122. if (!this.data.combo) {
  15123. selectElement.size = this.data.options.length;
  15124. if (this.data.multiSelect) {
  15125. selectElement.multiple = true;
  15126. }
  15127. }
  15128. selectElement.addEventListener("resetform", function (event) {
  15129. var defaultValue = _this.data.defaultFieldValue;
  15130. for (var _i = 0, _l = selectElement.options; _i < _l.length; _i++) {
  15131. var option = _l[_i];
  15132. option.selected = option.value === defaultValue;
  15133. }
  15134. });
  15135. for (var _i = 0, _l = this.data.options; _i < _l.length; _i++) {
  15136. var option = _l[_i];
  15137. var optionElement = document.createElement("option");
  15138. optionElement.textContent = option.displayValue;
  15139. optionElement.value = option.exportValue;
  15140. if (storedData.value.includes(option.exportValue)) {
  15141. optionElement.setAttribute("selected", true);
  15142. addAnEmptyEntry = false;
  15143. }
  15144. selectElement.append(optionElement);
  15145. }
  15146. var removeEmptyEntry = null;
  15147. if (addAnEmptyEntry) {
  15148. var noneOptionElement_1 = document.createElement("option");
  15149. noneOptionElement_1.value = " ";
  15150. noneOptionElement_1.setAttribute("hidden", true);
  15151. noneOptionElement_1.setAttribute("selected", true);
  15152. selectElement.prepend(noneOptionElement_1);
  15153. removeEmptyEntry = function () {
  15154. noneOptionElement_1.remove();
  15155. selectElement.removeEventListener("input", removeEmptyEntry);
  15156. removeEmptyEntry = null;
  15157. };
  15158. selectElement.addEventListener("input", removeEmptyEntry);
  15159. }
  15160. var getValue = function (isExport) {
  15161. var name = isExport ? "value" : "textContent";
  15162. var options = selectElement.options, multiple = selectElement.multiple;
  15163. if (!multiple) {
  15164. return options.selectedIndex === -1 ? null : options[options.selectedIndex][name];
  15165. }
  15166. return Array.prototype.filter.call(options, function (option) { return option.selected; }).map(function (option) { return option[name]; });
  15167. };
  15168. var selectedValues = getValue(false);
  15169. var getItems = function (event) {
  15170. var options = event.target.options;
  15171. return Array.prototype.map.call(options, function (option) { return ({
  15172. displayValue: option.textContent,
  15173. exportValue: option.value
  15174. }); });
  15175. };
  15176. if (this.enableScripting && this.hasJSActions) {
  15177. selectElement.addEventListener("updatefromsandbox", function (jsEvent) {
  15178. var actions = {
  15179. value: function (event) {
  15180. removeEmptyEntry === null || removeEmptyEntry === void 0 ? void 0 : removeEmptyEntry();
  15181. var value = event.detail.value;
  15182. var values = new Set(Array.isArray(value) ? value : [value]);
  15183. for (var _i = 0, _l = selectElement.options; _i < _l.length; _i++) {
  15184. var option = _l[_i];
  15185. option.selected = values.has(option.value);
  15186. }
  15187. storage.setValue(id, {
  15188. value: getValue(true)
  15189. });
  15190. selectedValues = getValue(false);
  15191. },
  15192. multipleSelection: function (event) {
  15193. selectElement.multiple = true;
  15194. },
  15195. remove: function (event) {
  15196. var options = selectElement.options;
  15197. var index = event.detail.remove;
  15198. options[index].selected = false;
  15199. selectElement.remove(index);
  15200. if (options.length > 0) {
  15201. var i = Array.prototype.findIndex.call(options, function (option) { return option.selected; });
  15202. if (i === -1) {
  15203. options[0].selected = true;
  15204. }
  15205. }
  15206. storage.setValue(id, {
  15207. value: getValue(true),
  15208. items: getItems(event)
  15209. });
  15210. selectedValues = getValue(false);
  15211. },
  15212. clear: function (event) {
  15213. while (selectElement.length !== 0) {
  15214. selectElement.remove(0);
  15215. }
  15216. storage.setValue(id, {
  15217. value: null,
  15218. items: []
  15219. });
  15220. selectedValues = getValue(false);
  15221. },
  15222. insert: function (event) {
  15223. var _l = event.detail.insert, index = _l.index, displayValue = _l.displayValue, exportValue = _l.exportValue;
  15224. var selectChild = selectElement.children[index];
  15225. var optionElement = document.createElement("option");
  15226. optionElement.textContent = displayValue;
  15227. optionElement.value = exportValue;
  15228. if (selectChild) {
  15229. selectChild.before(optionElement);
  15230. }
  15231. else {
  15232. selectElement.append(optionElement);
  15233. }
  15234. storage.setValue(id, {
  15235. value: getValue(true),
  15236. items: getItems(event)
  15237. });
  15238. selectedValues = getValue(false);
  15239. },
  15240. items: function (event) {
  15241. var items = event.detail.items;
  15242. while (selectElement.length !== 0) {
  15243. selectElement.remove(0);
  15244. }
  15245. for (var _i = 0, items_2 = items; _i < items_2.length; _i++) {
  15246. var item = items_2[_i];
  15247. var displayValue = item.displayValue, exportValue = item.exportValue;
  15248. var optionElement = document.createElement("option");
  15249. optionElement.textContent = displayValue;
  15250. optionElement.value = exportValue;
  15251. selectElement.append(optionElement);
  15252. }
  15253. if (selectElement.options.length > 0) {
  15254. selectElement.options[0].selected = true;
  15255. }
  15256. storage.setValue(id, {
  15257. value: getValue(true),
  15258. items: getItems(event)
  15259. });
  15260. selectedValues = getValue(false);
  15261. },
  15262. indices: function (event) {
  15263. var indices = new Set(event.detail.indices);
  15264. for (var _i = 0, _l = event.target.options; _i < _l.length; _i++) {
  15265. var option = _l[_i];
  15266. option.selected = indices.has(option.index);
  15267. }
  15268. storage.setValue(id, {
  15269. value: getValue(true)
  15270. });
  15271. selectedValues = getValue(false);
  15272. },
  15273. editable: function (event) {
  15274. event.target.disabled = !event.detail.editable;
  15275. }
  15276. };
  15277. _this._dispatchEventFromSandbox(actions, jsEvent);
  15278. });
  15279. selectElement.addEventListener("input", function (event) {
  15280. var _l;
  15281. var exportValue = getValue(true);
  15282. var change = getValue(false);
  15283. storage.setValue(id, {
  15284. value: exportValue
  15285. });
  15286. event.preventDefault();
  15287. (_l = _this.linkService.eventBus) === null || _l === void 0 ? void 0 : _l.dispatch("dispatcheventinsandbox", {
  15288. source: _this,
  15289. detail: {
  15290. id: id,
  15291. name: "Keystroke",
  15292. value: selectedValues,
  15293. change: change,
  15294. changeEx: exportValue,
  15295. willCommit: false,
  15296. commitKey: 1,
  15297. keyDown: false
  15298. }
  15299. });
  15300. });
  15301. this._setEventListeners(selectElement, null, [["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"], ["input", "Action"], ["input", "Validate"]], function (event) { return event.target.value; });
  15302. }
  15303. else {
  15304. selectElement.addEventListener("input", function (event) {
  15305. storage.setValue(id, {
  15306. value: getValue(true)
  15307. });
  15308. });
  15309. }
  15310. if (this.data.combo) {
  15311. this._setTextStyle(selectElement);
  15312. }
  15313. else { }
  15314. this._setBackgroundColor(selectElement);
  15315. this._setDefaultPropertiesFromJS(selectElement);
  15316. this.container.append(selectElement);
  15317. return this.container;
  15318. };
  15319. return ChoiceWidgetAnnotationElement;
  15320. }(WidgetAnnotationElement));
  15321. var PopupAnnotationElement = /** @class */ (function (_super) {
  15322. tslib_1.__extends(PopupAnnotationElement, _super);
  15323. function PopupAnnotationElement(parameters) {
  15324. var _this = this;
  15325. var data = parameters.data, elements = parameters.elements;
  15326. _this = _super.call(this, parameters, {
  15327. isRenderable: AnnotationElement._hasPopupData(data)
  15328. }) || this;
  15329. _this.elements = elements;
  15330. _this.popup = null;
  15331. return _this;
  15332. }
  15333. PopupAnnotationElement.prototype.render = function () {
  15334. this.container.classList.add("popupAnnotation");
  15335. var popup = this.popup = new PopupElement({
  15336. container: this.container,
  15337. color: this.data.color,
  15338. titleObj: this.data.titleObj,
  15339. modificationDate: this.data.modificationDate,
  15340. contentsObj: this.data.contentsObj,
  15341. richText: this.data.richText,
  15342. rect: this.data.rect,
  15343. parentRect: this.data.parentRect || null,
  15344. parent: this.parent,
  15345. elements: this.elements,
  15346. open: this.data.open
  15347. });
  15348. var elementIds = [];
  15349. for (var _i = 0, _l = this.elements; _i < _l.length; _i++) {
  15350. var element = _l[_i];
  15351. element.popup = popup;
  15352. elementIds.push(element.data.id);
  15353. element.addHighlightArea();
  15354. }
  15355. this.container.setAttribute("aria-controls", elementIds.map(function (id) { return "".concat(AnnotationPrefix).concat(id); }).join(","));
  15356. return this.container;
  15357. };
  15358. return PopupAnnotationElement;
  15359. }(AnnotationElement));
  15360. var PopupElement = /** @class */ (function () {
  15361. function PopupElement(_l) {
  15362. var container = _l.container, color = _l.color, elements = _l.elements, titleObj = _l.titleObj, modificationDate = _l.modificationDate, contentsObj = _l.contentsObj, richText = _l.richText, parent = _l.parent, rect = _l.rect, parentRect = _l.parentRect, open = _l.open;
  15363. var _m;
  15364. _PopupElement_instances.add(this);
  15365. _PopupElement_boundKeyDown.set(this, tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "m", _PopupElement_keyDown).bind(this));
  15366. _PopupElement_boundHide.set(this, tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "m", _PopupElement_hide).bind(this));
  15367. _PopupElement_boundShow.set(this, tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "m", _PopupElement_show).bind(this));
  15368. _PopupElement_boundToggle.set(this, tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "m", _PopupElement_toggle).bind(this));
  15369. _PopupElement_color.set(this, null);
  15370. _PopupElement_container.set(this, null);
  15371. _PopupElement_contentsObj.set(this, null);
  15372. _PopupElement_dateObj.set(this, null);
  15373. _PopupElement_elements.set(this, null);
  15374. _PopupElement_parent.set(this, null);
  15375. _PopupElement_parentRect.set(this, null);
  15376. _PopupElement_pinned.set(this, false);
  15377. _PopupElement_popup.set(this, null);
  15378. _PopupElement_position.set(this, null);
  15379. _PopupElement_rect.set(this, null);
  15380. _PopupElement_richText.set(this, null);
  15381. _PopupElement_titleObj.set(this, null);
  15382. _PopupElement_updates.set(this, null);
  15383. _PopupElement_wasVisible.set(this, false);
  15384. tslib_1.__classPrivateFieldSet(this, _PopupElement_container, container, "f");
  15385. tslib_1.__classPrivateFieldSet(this, _PopupElement_titleObj, titleObj, "f");
  15386. tslib_1.__classPrivateFieldSet(this, _PopupElement_contentsObj, contentsObj, "f");
  15387. tslib_1.__classPrivateFieldSet(this, _PopupElement_richText, richText, "f");
  15388. tslib_1.__classPrivateFieldSet(this, _PopupElement_parent, parent, "f");
  15389. tslib_1.__classPrivateFieldSet(this, _PopupElement_color, color, "f");
  15390. tslib_1.__classPrivateFieldSet(this, _PopupElement_rect, rect, "f");
  15391. tslib_1.__classPrivateFieldSet(this, _PopupElement_parentRect, parentRect, "f");
  15392. tslib_1.__classPrivateFieldSet(this, _PopupElement_elements, elements, "f");
  15393. tslib_1.__classPrivateFieldSet(this, _PopupElement_dateObj, PDFDateString.toDateObject(modificationDate), "f");
  15394. this.trigger = elements.flatMap(function (e) { return e.getElementsToTriggerPopup(); });
  15395. for (var _i = 0, _o = this.trigger; _i < _o.length; _i++) {
  15396. var element = _o[_i];
  15397. element.addEventListener("click", tslib_1.__classPrivateFieldGet(this, _PopupElement_boundToggle, "f"));
  15398. element.addEventListener("mouseenter", tslib_1.__classPrivateFieldGet(this, _PopupElement_boundShow, "f"));
  15399. element.addEventListener("mouseleave", tslib_1.__classPrivateFieldGet(this, _PopupElement_boundHide, "f"));
  15400. element.classList.add("popupTriggerArea");
  15401. }
  15402. for (var _p = 0, elements_1 = elements; _p < elements_1.length; _p++) {
  15403. var element = elements_1[_p];
  15404. (_m = element.container) === null || _m === void 0 ? void 0 : _m.addEventListener("keydown", tslib_1.__classPrivateFieldGet(this, _PopupElement_boundKeyDown, "f"));
  15405. }
  15406. tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").hidden = true;
  15407. if (open) {
  15408. tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "m", _PopupElement_toggle).call(this);
  15409. }
  15410. }
  15411. PopupElement.prototype.render = function () {
  15412. var _l;
  15413. if (tslib_1.__classPrivateFieldGet(this, _PopupElement_popup, "f")) {
  15414. return;
  15415. }
  15416. var popup = tslib_1.__classPrivateFieldSet(this, _PopupElement_popup, document.createElement("div"), "f");
  15417. popup.className = "popup";
  15418. if (tslib_1.__classPrivateFieldGet(this, _PopupElement_color, "f")) {
  15419. var baseColor = popup.style.outlineColor = Util.makeHexColor.apply(Util, tslib_1.__classPrivateFieldGet(this, _PopupElement_color, "f"));
  15420. if (CSS.supports("background-color", "color-mix(in srgb, red 30%, white)")) {
  15421. popup.style.backgroundColor = "color-mix(in srgb, ".concat(baseColor, " 30%, white)");
  15422. }
  15423. else {
  15424. var BACKGROUND_ENLIGHT_1 = 0.7;
  15425. popup.style.backgroundColor = Util.makeHexColor.apply(Util, tslib_1.__classPrivateFieldGet(this, _PopupElement_color, "f").map(function (c) { return Math.floor(BACKGROUND_ENLIGHT_1 * (255 - c) + c); }));
  15426. }
  15427. }
  15428. var header = document.createElement("span");
  15429. header.className = "header";
  15430. var title = document.createElement("h1");
  15431. header.append(title);
  15432. (_l = tslib_1.__classPrivateFieldGet(this, _PopupElement_titleObj, "f"), title.dir = _l.dir, title.textContent = _l.str);
  15433. popup.append(header);
  15434. if (tslib_1.__classPrivateFieldGet(this, _PopupElement_dateObj, "f")) {
  15435. var modificationDate = document.createElement("span");
  15436. modificationDate.classList.add("popupDate");
  15437. modificationDate.setAttribute("data-l10n-id", "pdfjs-annotation-date-string");
  15438. modificationDate.setAttribute("data-l10n-args", JSON.stringify({
  15439. date: tslib_1.__classPrivateFieldGet(this, _PopupElement_dateObj, "f").toLocaleDateString(),
  15440. time: tslib_1.__classPrivateFieldGet(this, _PopupElement_dateObj, "f").toLocaleTimeString()
  15441. }));
  15442. header.append(modificationDate);
  15443. }
  15444. var html = tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "a", _PopupElement_html_get);
  15445. if (html) {
  15446. XfaLayer.render({
  15447. xfaHtml: html,
  15448. intent: "richText",
  15449. div: popup
  15450. });
  15451. popup.lastChild.classList.add("richText", "popupContent");
  15452. }
  15453. else {
  15454. var contents = this._formatContents(tslib_1.__classPrivateFieldGet(this, _PopupElement_contentsObj, "f"));
  15455. popup.append(contents);
  15456. }
  15457. tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").append(popup);
  15458. };
  15459. PopupElement.prototype._formatContents = function (_l) {
  15460. var str = _l.str, dir = _l.dir;
  15461. var p = document.createElement("p");
  15462. p.classList.add("popupContent");
  15463. p.dir = dir;
  15464. var lines = str.split(/(?:\r\n?|\n)/);
  15465. for (var i = 0, ii = lines.length; i < ii; ++i) {
  15466. var line = lines[i];
  15467. p.append(document.createTextNode(line));
  15468. if (i < ii - 1) {
  15469. p.append(document.createElement("br"));
  15470. }
  15471. }
  15472. return p;
  15473. };
  15474. PopupElement.prototype.updateEdited = function (_l) {
  15475. var _m;
  15476. var rect = _l.rect, popupContent = _l.popupContent;
  15477. tslib_1.__classPrivateFieldSet(this, _PopupElement_updates, tslib_1.__classPrivateFieldGet(this, _PopupElement_updates, "f") || {
  15478. contentsObj: tslib_1.__classPrivateFieldGet(this, _PopupElement_contentsObj, "f"),
  15479. richText: tslib_1.__classPrivateFieldGet(this, _PopupElement_richText, "f")
  15480. }, "f");
  15481. if (rect) {
  15482. tslib_1.__classPrivateFieldSet(this, _PopupElement_position, null, "f");
  15483. }
  15484. if (popupContent) {
  15485. tslib_1.__classPrivateFieldSet(this, _PopupElement_richText, tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "m", _PopupElement_makePopupContent).call(this, popupContent), "f");
  15486. tslib_1.__classPrivateFieldSet(this, _PopupElement_contentsObj, null, "f");
  15487. }
  15488. (_m = tslib_1.__classPrivateFieldGet(this, _PopupElement_popup, "f")) === null || _m === void 0 ? void 0 : _m.remove();
  15489. tslib_1.__classPrivateFieldSet(this, _PopupElement_popup, null, "f");
  15490. };
  15491. PopupElement.prototype.resetEdited = function () {
  15492. var _l;
  15493. var _m;
  15494. var _o, _p;
  15495. if (!tslib_1.__classPrivateFieldGet(this, _PopupElement_updates, "f")) {
  15496. return;
  15497. }
  15498. (_o = this, _p = this, _l = tslib_1.__classPrivateFieldGet(this, _PopupElement_updates, "f"), ({ set value(_a) { tslib_1.__classPrivateFieldSet(_o, _PopupElement_contentsObj, _a, "f"); } }).value = _l.contentsObj, ({ set value(_a) { tslib_1.__classPrivateFieldSet(_p, _PopupElement_richText, _a, "f"); } }).value = _l.richText);
  15499. tslib_1.__classPrivateFieldSet(this, _PopupElement_updates, null, "f");
  15500. (_m = tslib_1.__classPrivateFieldGet(this, _PopupElement_popup, "f")) === null || _m === void 0 ? void 0 : _m.remove();
  15501. tslib_1.__classPrivateFieldSet(this, _PopupElement_popup, null, "f");
  15502. tslib_1.__classPrivateFieldSet(this, _PopupElement_position, null, "f");
  15503. };
  15504. PopupElement.prototype.forceHide = function () {
  15505. tslib_1.__classPrivateFieldSet(this, _PopupElement_wasVisible, this.isVisible, "f");
  15506. if (!tslib_1.__classPrivateFieldGet(this, _PopupElement_wasVisible, "f")) {
  15507. return;
  15508. }
  15509. tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").hidden = true;
  15510. };
  15511. PopupElement.prototype.maybeShow = function () {
  15512. if (!tslib_1.__classPrivateFieldGet(this, _PopupElement_wasVisible, "f")) {
  15513. return;
  15514. }
  15515. if (!tslib_1.__classPrivateFieldGet(this, _PopupElement_popup, "f")) {
  15516. tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "m", _PopupElement_show).call(this);
  15517. }
  15518. tslib_1.__classPrivateFieldSet(this, _PopupElement_wasVisible, false, "f");
  15519. tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").hidden = false;
  15520. };
  15521. Object.defineProperty(PopupElement.prototype, "isVisible", {
  15522. get: function () {
  15523. return tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").hidden === false;
  15524. },
  15525. enumerable: false,
  15526. configurable: true
  15527. });
  15528. return PopupElement;
  15529. }());
  15530. _PopupElement_boundKeyDown = new WeakMap(), _PopupElement_boundHide = new WeakMap(), _PopupElement_boundShow = new WeakMap(), _PopupElement_boundToggle = new WeakMap(), _PopupElement_color = new WeakMap(), _PopupElement_container = new WeakMap(), _PopupElement_contentsObj = new WeakMap(), _PopupElement_dateObj = new WeakMap(), _PopupElement_elements = new WeakMap(), _PopupElement_parent = new WeakMap(), _PopupElement_parentRect = new WeakMap(), _PopupElement_pinned = new WeakMap(), _PopupElement_popup = new WeakMap(), _PopupElement_position = new WeakMap(), _PopupElement_rect = new WeakMap(), _PopupElement_richText = new WeakMap(), _PopupElement_titleObj = new WeakMap(), _PopupElement_updates = new WeakMap(), _PopupElement_wasVisible = new WeakMap(), _PopupElement_instances = new WeakSet(), _PopupElement_html_get = function _PopupElement_html_get() {
  15531. var richText = tslib_1.__classPrivateFieldGet(this, _PopupElement_richText, "f");
  15532. var contentsObj = tslib_1.__classPrivateFieldGet(this, _PopupElement_contentsObj, "f");
  15533. if ((richText === null || richText === void 0 ? void 0 : richText.str) && (!(contentsObj === null || contentsObj === void 0 ? void 0 : contentsObj.str) || contentsObj.str === richText.str)) {
  15534. return tslib_1.__classPrivateFieldGet(this, _PopupElement_richText, "f").html || null;
  15535. }
  15536. return null;
  15537. }, _PopupElement_fontSize_get = function _PopupElement_fontSize_get() {
  15538. var _l, _m, _o;
  15539. return ((_o = (_m = (_l = tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "a", _PopupElement_html_get)) === null || _l === void 0 ? void 0 : _l.attributes) === null || _m === void 0 ? void 0 : _m.style) === null || _o === void 0 ? void 0 : _o.fontSize) || 0;
  15540. }, _PopupElement_fontColor_get = function _PopupElement_fontColor_get() {
  15541. var _l, _m, _o;
  15542. return ((_o = (_m = (_l = tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "a", _PopupElement_html_get)) === null || _l === void 0 ? void 0 : _l.attributes) === null || _m === void 0 ? void 0 : _m.style) === null || _o === void 0 ? void 0 : _o.color) || null;
  15543. }, _PopupElement_makePopupContent = function _PopupElement_makePopupContent(text) {
  15544. var popupLines = [];
  15545. var popupContent = {
  15546. str: text,
  15547. html: {
  15548. name: "div",
  15549. attributes: {
  15550. dir: "auto"
  15551. },
  15552. children: [{
  15553. name: "p",
  15554. children: popupLines
  15555. }]
  15556. }
  15557. };
  15558. var lineAttributes = {
  15559. style: {
  15560. color: tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "a", _PopupElement_fontColor_get),
  15561. fontSize: tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "a", _PopupElement_fontSize_get) ? "calc(".concat(tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "a", _PopupElement_fontSize_get), "px * var(--scale-factor))") : ""
  15562. }
  15563. };
  15564. for (var _i = 0, _l = text.split("\n"); _i < _l.length; _i++) {
  15565. var line = _l[_i];
  15566. popupLines.push({
  15567. name: "span",
  15568. value: line,
  15569. attributes: lineAttributes
  15570. });
  15571. }
  15572. return popupContent;
  15573. }, _PopupElement_keyDown = function _PopupElement_keyDown(event) {
  15574. if (event.altKey || event.shiftKey || event.ctrlKey || event.metaKey) {
  15575. return;
  15576. }
  15577. if (event.key === "Enter" || event.key === "Escape" && tslib_1.__classPrivateFieldGet(this, _PopupElement_pinned, "f")) {
  15578. tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "m", _PopupElement_toggle).call(this);
  15579. }
  15580. }, _PopupElement_setPosition = function _PopupElement_setPosition() {
  15581. if (tslib_1.__classPrivateFieldGet(this, _PopupElement_position, "f") !== null) {
  15582. return;
  15583. }
  15584. var _l = tslib_1.__classPrivateFieldGet(this, _PopupElement_parent, "f"), view = _l.page.view, _m = _l.viewport.rawDims, pageWidth = _m.pageWidth, pageHeight = _m.pageHeight, pageX = _m.pageX, pageY = _m.pageY;
  15585. var useParentRect = !!tslib_1.__classPrivateFieldGet(this, _PopupElement_parentRect, "f");
  15586. var rect = useParentRect ? tslib_1.__classPrivateFieldGet(this, _PopupElement_parentRect, "f") : tslib_1.__classPrivateFieldGet(this, _PopupElement_rect, "f");
  15587. for (var _i = 0, _o = tslib_1.__classPrivateFieldGet(this, _PopupElement_elements, "f"); _i < _o.length; _i++) {
  15588. var element = _o[_i];
  15589. if (!rect || Util.intersect(element.data.rect, rect) !== null) {
  15590. rect = element.data.rect;
  15591. useParentRect = true;
  15592. break;
  15593. }
  15594. }
  15595. var normalizedRect = Util.normalizeRect([rect[0], view[3] - rect[1] + view[1], rect[2], view[3] - rect[3] + view[1]]);
  15596. var HORIZONTAL_SPACE_AFTER_ANNOTATION = 5;
  15597. var parentWidth = useParentRect ? rect[2] - rect[0] + HORIZONTAL_SPACE_AFTER_ANNOTATION : 0;
  15598. var popupLeft = normalizedRect[0] + parentWidth;
  15599. var popupTop = normalizedRect[1];
  15600. tslib_1.__classPrivateFieldSet(this, _PopupElement_position, [100 * (popupLeft - pageX) / pageWidth, 100 * (popupTop - pageY) / pageHeight], "f");
  15601. var style = tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").style;
  15602. style.left = "".concat(tslib_1.__classPrivateFieldGet(this, _PopupElement_position, "f")[0], "%");
  15603. style.top = "".concat(tslib_1.__classPrivateFieldGet(this, _PopupElement_position, "f")[1], "%");
  15604. }, _PopupElement_toggle = function _PopupElement_toggle() {
  15605. tslib_1.__classPrivateFieldSet(this, _PopupElement_pinned, !tslib_1.__classPrivateFieldGet(this, _PopupElement_pinned, "f"), "f");
  15606. if (tslib_1.__classPrivateFieldGet(this, _PopupElement_pinned, "f")) {
  15607. tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "m", _PopupElement_show).call(this);
  15608. tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").addEventListener("click", tslib_1.__classPrivateFieldGet(this, _PopupElement_boundToggle, "f"));
  15609. tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").addEventListener("keydown", tslib_1.__classPrivateFieldGet(this, _PopupElement_boundKeyDown, "f"));
  15610. }
  15611. else {
  15612. tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "m", _PopupElement_hide).call(this);
  15613. tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").removeEventListener("click", tslib_1.__classPrivateFieldGet(this, _PopupElement_boundToggle, "f"));
  15614. tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").removeEventListener("keydown", tslib_1.__classPrivateFieldGet(this, _PopupElement_boundKeyDown, "f"));
  15615. }
  15616. }, _PopupElement_show = function _PopupElement_show() {
  15617. if (!tslib_1.__classPrivateFieldGet(this, _PopupElement_popup, "f")) {
  15618. this.render();
  15619. }
  15620. if (!this.isVisible) {
  15621. tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "m", _PopupElement_setPosition).call(this);
  15622. tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").hidden = false;
  15623. tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").style.zIndex = parseInt(tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").style.zIndex) + 1000;
  15624. }
  15625. else if (tslib_1.__classPrivateFieldGet(this, _PopupElement_pinned, "f")) {
  15626. tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").classList.add("focused");
  15627. }
  15628. }, _PopupElement_hide = function _PopupElement_hide() {
  15629. tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").classList.remove("focused");
  15630. if (tslib_1.__classPrivateFieldGet(this, _PopupElement_pinned, "f") || !this.isVisible) {
  15631. return;
  15632. }
  15633. tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").hidden = true;
  15634. tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").style.zIndex = parseInt(tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").style.zIndex) - 1000;
  15635. };
  15636. var FreeTextAnnotationElement = /** @class */ (function (_super) {
  15637. tslib_1.__extends(FreeTextAnnotationElement, _super);
  15638. function FreeTextAnnotationElement(parameters) {
  15639. var _this = _super.call(this, parameters, {
  15640. isRenderable: true,
  15641. ignoreBorder: true
  15642. }) || this;
  15643. _this.textContent = parameters.data.textContent;
  15644. _this.textPosition = parameters.data.textPosition;
  15645. _this.annotationEditorType = AnnotationEditorType.FREETEXT;
  15646. return _this;
  15647. }
  15648. FreeTextAnnotationElement.prototype.render = function () {
  15649. this.container.classList.add("freeTextAnnotation");
  15650. if (this.textContent) {
  15651. var content = document.createElement("div");
  15652. content.classList.add("annotationTextContent");
  15653. content.setAttribute("role", "comment");
  15654. for (var _i = 0, _l = this.textContent; _i < _l.length; _i++) {
  15655. var line = _l[_i];
  15656. var lineSpan = document.createElement("span");
  15657. lineSpan.textContent = line;
  15658. content.append(lineSpan);
  15659. }
  15660. this.container.append(content);
  15661. }
  15662. if (!this.data.popupRef && this.hasPopupData) {
  15663. this._createPopup();
  15664. }
  15665. this._editOnDoubleClick();
  15666. return this.container;
  15667. };
  15668. Object.defineProperty(FreeTextAnnotationElement.prototype, "_isEditable", {
  15669. get: function () {
  15670. return this.data.hasOwnCanvas;
  15671. },
  15672. enumerable: false,
  15673. configurable: true
  15674. });
  15675. return FreeTextAnnotationElement;
  15676. }(AnnotationElement));
  15677. var LineAnnotationElement = /** @class */ (function (_super) {
  15678. tslib_1.__extends(LineAnnotationElement, _super);
  15679. function LineAnnotationElement(parameters) {
  15680. var _this = _super.call(this, parameters, {
  15681. isRenderable: true,
  15682. ignoreBorder: true
  15683. }) || this;
  15684. _LineAnnotationElement_line.set(_this, null);
  15685. return _this;
  15686. }
  15687. LineAnnotationElement.prototype.render = function () {
  15688. this.container.classList.add("lineAnnotation");
  15689. var data = this.data;
  15690. var _l = getRectDims(data.rect), width = _l.width, height = _l.height;
  15691. var svg = this.svgFactory.create(width, height, true);
  15692. var line = tslib_1.__classPrivateFieldSet(this, _LineAnnotationElement_line, this.svgFactory.createElement("svg:line"), "f");
  15693. line.setAttribute("x1", data.rect[2] - data.lineCoordinates[0]);
  15694. line.setAttribute("y1", data.rect[3] - data.lineCoordinates[1]);
  15695. line.setAttribute("x2", data.rect[2] - data.lineCoordinates[2]);
  15696. line.setAttribute("y2", data.rect[3] - data.lineCoordinates[3]);
  15697. line.setAttribute("stroke-width", data.borderStyle.width || 1);
  15698. line.setAttribute("stroke", "transparent");
  15699. line.setAttribute("fill", "transparent");
  15700. svg.append(line);
  15701. this.container.append(svg);
  15702. if (!data.popupRef && this.hasPopupData) {
  15703. this._createPopup();
  15704. }
  15705. return this.container;
  15706. };
  15707. LineAnnotationElement.prototype.getElementsToTriggerPopup = function () {
  15708. return tslib_1.__classPrivateFieldGet(this, _LineAnnotationElement_line, "f");
  15709. };
  15710. LineAnnotationElement.prototype.addHighlightArea = function () {
  15711. this.container.classList.add("highlightArea");
  15712. };
  15713. return LineAnnotationElement;
  15714. }(AnnotationElement));
  15715. _LineAnnotationElement_line = new WeakMap();
  15716. var SquareAnnotationElement = /** @class */ (function (_super) {
  15717. tslib_1.__extends(SquareAnnotationElement, _super);
  15718. function SquareAnnotationElement(parameters) {
  15719. var _this = _super.call(this, parameters, {
  15720. isRenderable: true,
  15721. ignoreBorder: true
  15722. }) || this;
  15723. _SquareAnnotationElement_square.set(_this, null);
  15724. return _this;
  15725. }
  15726. SquareAnnotationElement.prototype.render = function () {
  15727. this.container.classList.add("squareAnnotation");
  15728. var data = this.data;
  15729. var _l = getRectDims(data.rect), width = _l.width, height = _l.height;
  15730. var svg = this.svgFactory.create(width, height, true);
  15731. var borderWidth = data.borderStyle.width;
  15732. var square = tslib_1.__classPrivateFieldSet(this, _SquareAnnotationElement_square, this.svgFactory.createElement("svg:rect"), "f");
  15733. square.setAttribute("x", borderWidth / 2);
  15734. square.setAttribute("y", borderWidth / 2);
  15735. square.setAttribute("width", width - borderWidth);
  15736. square.setAttribute("height", height - borderWidth);
  15737. square.setAttribute("stroke-width", borderWidth || 1);
  15738. square.setAttribute("stroke", "transparent");
  15739. square.setAttribute("fill", "transparent");
  15740. svg.append(square);
  15741. this.container.append(svg);
  15742. if (!data.popupRef && this.hasPopupData) {
  15743. this._createPopup();
  15744. }
  15745. return this.container;
  15746. };
  15747. SquareAnnotationElement.prototype.getElementsToTriggerPopup = function () {
  15748. return tslib_1.__classPrivateFieldGet(this, _SquareAnnotationElement_square, "f");
  15749. };
  15750. SquareAnnotationElement.prototype.addHighlightArea = function () {
  15751. this.container.classList.add("highlightArea");
  15752. };
  15753. return SquareAnnotationElement;
  15754. }(AnnotationElement));
  15755. _SquareAnnotationElement_square = new WeakMap();
  15756. var CircleAnnotationElement = /** @class */ (function (_super) {
  15757. tslib_1.__extends(CircleAnnotationElement, _super);
  15758. function CircleAnnotationElement(parameters) {
  15759. var _this = _super.call(this, parameters, {
  15760. isRenderable: true,
  15761. ignoreBorder: true
  15762. }) || this;
  15763. _CircleAnnotationElement_circle.set(_this, null);
  15764. return _this;
  15765. }
  15766. CircleAnnotationElement.prototype.render = function () {
  15767. this.container.classList.add("circleAnnotation");
  15768. var data = this.data;
  15769. var _l = getRectDims(data.rect), width = _l.width, height = _l.height;
  15770. var svg = this.svgFactory.create(width, height, true);
  15771. var borderWidth = data.borderStyle.width;
  15772. var circle = tslib_1.__classPrivateFieldSet(this, _CircleAnnotationElement_circle, this.svgFactory.createElement("svg:ellipse"), "f");
  15773. circle.setAttribute("cx", width / 2);
  15774. circle.setAttribute("cy", height / 2);
  15775. circle.setAttribute("rx", width / 2 - borderWidth / 2);
  15776. circle.setAttribute("ry", height / 2 - borderWidth / 2);
  15777. circle.setAttribute("stroke-width", borderWidth || 1);
  15778. circle.setAttribute("stroke", "transparent");
  15779. circle.setAttribute("fill", "transparent");
  15780. svg.append(circle);
  15781. this.container.append(svg);
  15782. if (!data.popupRef && this.hasPopupData) {
  15783. this._createPopup();
  15784. }
  15785. return this.container;
  15786. };
  15787. CircleAnnotationElement.prototype.getElementsToTriggerPopup = function () {
  15788. return tslib_1.__classPrivateFieldGet(this, _CircleAnnotationElement_circle, "f");
  15789. };
  15790. CircleAnnotationElement.prototype.addHighlightArea = function () {
  15791. this.container.classList.add("highlightArea");
  15792. };
  15793. return CircleAnnotationElement;
  15794. }(AnnotationElement));
  15795. _CircleAnnotationElement_circle = new WeakMap();
  15796. var PolylineAnnotationElement = /** @class */ (function (_super) {
  15797. tslib_1.__extends(PolylineAnnotationElement, _super);
  15798. function PolylineAnnotationElement(parameters) {
  15799. var _this = _super.call(this, parameters, {
  15800. isRenderable: true,
  15801. ignoreBorder: true
  15802. }) || this;
  15803. _PolylineAnnotationElement_polyline.set(_this, null);
  15804. _this.containerClassName = "polylineAnnotation";
  15805. _this.svgElementName = "svg:polyline";
  15806. return _this;
  15807. }
  15808. PolylineAnnotationElement.prototype.render = function () {
  15809. this.container.classList.add(this.containerClassName);
  15810. var data = this.data;
  15811. var _l = getRectDims(data.rect), width = _l.width, height = _l.height;
  15812. var svg = this.svgFactory.create(width, height, true);
  15813. var points = [];
  15814. for (var _i = 0, _m = data.vertices; _i < _m.length; _i++) {
  15815. var coordinate = _m[_i];
  15816. var x = coordinate.x - data.rect[0];
  15817. var y = data.rect[3] - coordinate.y;
  15818. points.push(x + "," + y);
  15819. }
  15820. points = points.join(" ");
  15821. var polyline = tslib_1.__classPrivateFieldSet(this, _PolylineAnnotationElement_polyline, this.svgFactory.createElement(this.svgElementName), "f");
  15822. polyline.setAttribute("points", points);
  15823. polyline.setAttribute("stroke-width", data.borderStyle.width || 1);
  15824. polyline.setAttribute("stroke", "transparent");
  15825. polyline.setAttribute("fill", "transparent");
  15826. svg.append(polyline);
  15827. this.container.append(svg);
  15828. if (!data.popupRef && this.hasPopupData) {
  15829. this._createPopup();
  15830. }
  15831. return this.container;
  15832. };
  15833. PolylineAnnotationElement.prototype.getElementsToTriggerPopup = function () {
  15834. return tslib_1.__classPrivateFieldGet(this, _PolylineAnnotationElement_polyline, "f");
  15835. };
  15836. PolylineAnnotationElement.prototype.addHighlightArea = function () {
  15837. this.container.classList.add("highlightArea");
  15838. };
  15839. return PolylineAnnotationElement;
  15840. }(AnnotationElement));
  15841. _PolylineAnnotationElement_polyline = new WeakMap();
  15842. var PolygonAnnotationElement = /** @class */ (function (_super) {
  15843. tslib_1.__extends(PolygonAnnotationElement, _super);
  15844. function PolygonAnnotationElement(parameters) {
  15845. var _this = _super.call(this, parameters) || this;
  15846. _this.containerClassName = "polygonAnnotation";
  15847. _this.svgElementName = "svg:polygon";
  15848. return _this;
  15849. }
  15850. return PolygonAnnotationElement;
  15851. }(PolylineAnnotationElement));
  15852. var CaretAnnotationElement = /** @class */ (function (_super) {
  15853. tslib_1.__extends(CaretAnnotationElement, _super);
  15854. function CaretAnnotationElement(parameters) {
  15855. return _super.call(this, parameters, {
  15856. isRenderable: true,
  15857. ignoreBorder: true
  15858. }) || this;
  15859. }
  15860. CaretAnnotationElement.prototype.render = function () {
  15861. this.container.classList.add("caretAnnotation");
  15862. if (!this.data.popupRef && this.hasPopupData) {
  15863. this._createPopup();
  15864. }
  15865. return this.container;
  15866. };
  15867. return CaretAnnotationElement;
  15868. }(AnnotationElement));
  15869. var InkAnnotationElement = /** @class */ (function (_super) {
  15870. tslib_1.__extends(InkAnnotationElement, _super);
  15871. function InkAnnotationElement(parameters) {
  15872. var _this = _super.call(this, parameters, {
  15873. isRenderable: true,
  15874. ignoreBorder: true
  15875. }) || this;
  15876. _InkAnnotationElement_polylines.set(_this, []);
  15877. _this.containerClassName = "inkAnnotation";
  15878. _this.svgElementName = "svg:polyline";
  15879. _this.annotationEditorType = AnnotationEditorType.INK;
  15880. return _this;
  15881. }
  15882. InkAnnotationElement.prototype.render = function () {
  15883. this.container.classList.add(this.containerClassName);
  15884. var data = this.data;
  15885. var _l = getRectDims(data.rect), width = _l.width, height = _l.height;
  15886. var svg = this.svgFactory.create(width, height, true);
  15887. for (var _i = 0, _m = data.inkLists; _i < _m.length; _i++) {
  15888. var inkList = _m[_i];
  15889. var points = [];
  15890. for (var _o = 0, inkList_1 = inkList; _o < inkList_1.length; _o++) {
  15891. var coordinate = inkList_1[_o];
  15892. var x = coordinate.x - data.rect[0];
  15893. var y = data.rect[3] - coordinate.y;
  15894. points.push("".concat(x, ",").concat(y));
  15895. }
  15896. points = points.join(" ");
  15897. var polyline = this.svgFactory.createElement(this.svgElementName);
  15898. tslib_1.__classPrivateFieldGet(this, _InkAnnotationElement_polylines, "f").push(polyline);
  15899. polyline.setAttribute("points", points);
  15900. polyline.setAttribute("stroke-width", data.borderStyle.width || 1);
  15901. polyline.setAttribute("stroke", "transparent");
  15902. polyline.setAttribute("fill", "transparent");
  15903. if (!data.popupRef && this.hasPopupData) {
  15904. this._createPopup();
  15905. }
  15906. svg.append(polyline);
  15907. }
  15908. this.container.append(svg);
  15909. return this.container;
  15910. };
  15911. InkAnnotationElement.prototype.getElementsToTriggerPopup = function () {
  15912. return tslib_1.__classPrivateFieldGet(this, _InkAnnotationElement_polylines, "f");
  15913. };
  15914. InkAnnotationElement.prototype.addHighlightArea = function () {
  15915. this.container.classList.add("highlightArea");
  15916. };
  15917. return InkAnnotationElement;
  15918. }(AnnotationElement));
  15919. _InkAnnotationElement_polylines = new WeakMap();
  15920. var HighlightAnnotationElement = /** @class */ (function (_super) {
  15921. tslib_1.__extends(HighlightAnnotationElement, _super);
  15922. function HighlightAnnotationElement(parameters) {
  15923. return _super.call(this, parameters, {
  15924. isRenderable: true,
  15925. ignoreBorder: true,
  15926. createQuadrilaterals: true
  15927. }) || this;
  15928. }
  15929. HighlightAnnotationElement.prototype.render = function () {
  15930. if (!this.data.popupRef && this.hasPopupData) {
  15931. this._createPopup();
  15932. }
  15933. this.container.classList.add("highlightAnnotation");
  15934. return this.container;
  15935. };
  15936. return HighlightAnnotationElement;
  15937. }(AnnotationElement));
  15938. var UnderlineAnnotationElement = /** @class */ (function (_super) {
  15939. tslib_1.__extends(UnderlineAnnotationElement, _super);
  15940. function UnderlineAnnotationElement(parameters) {
  15941. return _super.call(this, parameters, {
  15942. isRenderable: true,
  15943. ignoreBorder: true,
  15944. createQuadrilaterals: true
  15945. }) || this;
  15946. }
  15947. UnderlineAnnotationElement.prototype.render = function () {
  15948. if (!this.data.popupRef && this.hasPopupData) {
  15949. this._createPopup();
  15950. }
  15951. this.container.classList.add("underlineAnnotation");
  15952. return this.container;
  15953. };
  15954. return UnderlineAnnotationElement;
  15955. }(AnnotationElement));
  15956. var SquigglyAnnotationElement = /** @class */ (function (_super) {
  15957. tslib_1.__extends(SquigglyAnnotationElement, _super);
  15958. function SquigglyAnnotationElement(parameters) {
  15959. return _super.call(this, parameters, {
  15960. isRenderable: true,
  15961. ignoreBorder: true,
  15962. createQuadrilaterals: true
  15963. }) || this;
  15964. }
  15965. SquigglyAnnotationElement.prototype.render = function () {
  15966. if (!this.data.popupRef && this.hasPopupData) {
  15967. this._createPopup();
  15968. }
  15969. this.container.classList.add("squigglyAnnotation");
  15970. return this.container;
  15971. };
  15972. return SquigglyAnnotationElement;
  15973. }(AnnotationElement));
  15974. var StrikeOutAnnotationElement = /** @class */ (function (_super) {
  15975. tslib_1.__extends(StrikeOutAnnotationElement, _super);
  15976. function StrikeOutAnnotationElement(parameters) {
  15977. return _super.call(this, parameters, {
  15978. isRenderable: true,
  15979. ignoreBorder: true,
  15980. createQuadrilaterals: true
  15981. }) || this;
  15982. }
  15983. StrikeOutAnnotationElement.prototype.render = function () {
  15984. if (!this.data.popupRef && this.hasPopupData) {
  15985. this._createPopup();
  15986. }
  15987. this.container.classList.add("strikeoutAnnotation");
  15988. return this.container;
  15989. };
  15990. return StrikeOutAnnotationElement;
  15991. }(AnnotationElement));
  15992. var StampAnnotationElement = /** @class */ (function (_super) {
  15993. tslib_1.__extends(StampAnnotationElement, _super);
  15994. function StampAnnotationElement(parameters) {
  15995. return _super.call(this, parameters, {
  15996. isRenderable: true,
  15997. ignoreBorder: true
  15998. }) || this;
  15999. }
  16000. StampAnnotationElement.prototype.render = function () {
  16001. this.container.classList.add("stampAnnotation");
  16002. if (!this.data.popupRef && this.hasPopupData) {
  16003. this._createPopup();
  16004. }
  16005. return this.container;
  16006. };
  16007. return StampAnnotationElement;
  16008. }(AnnotationElement));
  16009. var FileAttachmentAnnotationElement = /** @class */ (function (_super) {
  16010. tslib_1.__extends(FileAttachmentAnnotationElement, _super);
  16011. function FileAttachmentAnnotationElement(parameters) {
  16012. var _this = this;
  16013. var _l;
  16014. _this = _super.call(this, parameters, {
  16015. isRenderable: true
  16016. }) || this;
  16017. _FileAttachmentAnnotationElement_instances.add(_this);
  16018. _FileAttachmentAnnotationElement_trigger.set(_this, null);
  16019. var file = _this.data.file;
  16020. _this.filename = file.filename;
  16021. _this.content = file.content;
  16022. (_l = _this.linkService.eventBus) === null || _l === void 0 ? void 0 : _l.dispatch("fileattachmentannotation", tslib_1.__assign({ source: _this }, file));
  16023. return _this;
  16024. }
  16025. FileAttachmentAnnotationElement.prototype.render = function () {
  16026. var _this = this;
  16027. this.container.classList.add("fileAttachmentAnnotation");
  16028. var _l = this, container = _l.container, data = _l.data;
  16029. var trigger;
  16030. if (data.hasAppearance || data.fillAlpha === 0) {
  16031. trigger = document.createElement("div");
  16032. }
  16033. else {
  16034. trigger = document.createElement("img");
  16035. trigger.src = "".concat(this.imageResourcesPath, "annotation-").concat(/paperclip/i.test(data.name) ? "paperclip" : "pushpin", ".svg");
  16036. if (data.fillAlpha && data.fillAlpha < 1) {
  16037. trigger.style = "filter: opacity(".concat(Math.round(data.fillAlpha * 100), "%);");
  16038. }
  16039. }
  16040. trigger.addEventListener("dblclick", tslib_1.__classPrivateFieldGet(this, _FileAttachmentAnnotationElement_instances, "m", _FileAttachmentAnnotationElement_download).bind(this));
  16041. tslib_1.__classPrivateFieldSet(this, _FileAttachmentAnnotationElement_trigger, trigger, "f");
  16042. var isMac = util_FeatureTest.platform.isMac;
  16043. container.addEventListener("keydown", function (evt) {
  16044. if (evt.key === "Enter" && (isMac ? evt.metaKey : evt.ctrlKey)) {
  16045. tslib_1.__classPrivateFieldGet(_this, _FileAttachmentAnnotationElement_instances, "m", _FileAttachmentAnnotationElement_download).call(_this);
  16046. }
  16047. });
  16048. if (!data.popupRef && this.hasPopupData) {
  16049. this._createPopup();
  16050. }
  16051. else {
  16052. trigger.classList.add("popupTriggerArea");
  16053. }
  16054. container.append(trigger);
  16055. return container;
  16056. };
  16057. FileAttachmentAnnotationElement.prototype.getElementsToTriggerPopup = function () {
  16058. return tslib_1.__classPrivateFieldGet(this, _FileAttachmentAnnotationElement_trigger, "f");
  16059. };
  16060. FileAttachmentAnnotationElement.prototype.addHighlightArea = function () {
  16061. this.container.classList.add("highlightArea");
  16062. };
  16063. return FileAttachmentAnnotationElement;
  16064. }(AnnotationElement));
  16065. _FileAttachmentAnnotationElement_trigger = new WeakMap(), _FileAttachmentAnnotationElement_instances = new WeakSet(), _FileAttachmentAnnotationElement_download = function _FileAttachmentAnnotationElement_download() {
  16066. var _l;
  16067. (_l = this.downloadManager) === null || _l === void 0 ? void 0 : _l.openOrDownloadData(this.content, this.filename);
  16068. };
  16069. var AnnotationLayer = /** @class */ (function () {
  16070. function AnnotationLayer(_l) {
  16071. var div = _l.div, accessibilityManager = _l.accessibilityManager, annotationCanvasMap = _l.annotationCanvasMap, annotationEditorUIManager = _l.annotationEditorUIManager, page = _l.page, viewport = _l.viewport;
  16072. _AnnotationLayer_instances.add(this);
  16073. _AnnotationLayer_accessibilityManager.set(this, null);
  16074. _AnnotationLayer_annotationCanvasMap.set(this, null);
  16075. _AnnotationLayer_editableAnnotations.set(this, new Map());
  16076. this.div = div;
  16077. tslib_1.__classPrivateFieldSet(this, _AnnotationLayer_accessibilityManager, accessibilityManager, "f");
  16078. tslib_1.__classPrivateFieldSet(this, _AnnotationLayer_annotationCanvasMap, annotationCanvasMap, "f");
  16079. this.page = page;
  16080. this.viewport = viewport;
  16081. this.zIndex = 0;
  16082. this._annotationEditorUIManager = annotationEditorUIManager;
  16083. }
  16084. AnnotationLayer.prototype.render = function (params) {
  16085. var _l;
  16086. return tslib_1.__awaiter(this, void 0, void 0, function () {
  16087. var annotations, layer, popupToElements, elementParams, _i, annotations_1, data, isPopupAnnotation, _m, width, height, elements, element, elements, rendered;
  16088. return tslib_1.__generator(this, function (_o) {
  16089. annotations = params.annotations;
  16090. layer = this.div;
  16091. setLayerDimensions(layer, this.viewport);
  16092. popupToElements = new Map();
  16093. elementParams = {
  16094. data: null,
  16095. layer: layer,
  16096. linkService: params.linkService,
  16097. downloadManager: params.downloadManager,
  16098. imageResourcesPath: params.imageResourcesPath || "",
  16099. renderForms: params.renderForms !== false,
  16100. svgFactory: new DOMSVGFactory(),
  16101. annotationStorage: params.annotationStorage || new AnnotationStorage(),
  16102. enableScripting: params.enableScripting === true,
  16103. hasJSActions: params.hasJSActions,
  16104. fieldObjects: params.fieldObjects,
  16105. parent: this,
  16106. elements: null
  16107. };
  16108. for (_i = 0, annotations_1 = annotations; _i < annotations_1.length; _i++) {
  16109. data = annotations_1[_i];
  16110. if (data.noHTML) {
  16111. continue;
  16112. }
  16113. isPopupAnnotation = data.annotationType === AnnotationType.POPUP;
  16114. if (!isPopupAnnotation) {
  16115. _m = getRectDims(data.rect), width = _m.width, height = _m.height;
  16116. if (width <= 0 || height <= 0) {
  16117. continue;
  16118. }
  16119. }
  16120. else {
  16121. elements = popupToElements.get(data.id);
  16122. if (!elements) {
  16123. continue;
  16124. }
  16125. elementParams.elements = elements;
  16126. }
  16127. elementParams.data = data;
  16128. element = AnnotationElementFactory.create(elementParams);
  16129. if (!element.isRenderable) {
  16130. continue;
  16131. }
  16132. if (!isPopupAnnotation && data.popupRef) {
  16133. elements = popupToElements.get(data.popupRef);
  16134. if (!elements) {
  16135. popupToElements.set(data.popupRef, [element]);
  16136. }
  16137. else {
  16138. elements.push(element);
  16139. }
  16140. }
  16141. rendered = element.render();
  16142. if (data.hidden) {
  16143. rendered.style.visibility = "hidden";
  16144. }
  16145. tslib_1.__classPrivateFieldGet(this, _AnnotationLayer_instances, "m", _AnnotationLayer_appendElement).call(this, rendered, data.id);
  16146. if (element.annotationEditorType > 0) {
  16147. tslib_1.__classPrivateFieldGet(this, _AnnotationLayer_editableAnnotations, "f").set(element.data.id, element);
  16148. (_l = this._annotationEditorUIManager) === null || _l === void 0 ? void 0 : _l.renderAnnotationElement(element);
  16149. }
  16150. }
  16151. tslib_1.__classPrivateFieldGet(this, _AnnotationLayer_instances, "m", _AnnotationLayer_setAnnotationCanvasMap).call(this);
  16152. return [2 /*return*/];
  16153. });
  16154. });
  16155. };
  16156. AnnotationLayer.prototype.update = function (_l) {
  16157. var viewport = _l.viewport;
  16158. var layer = this.div;
  16159. this.viewport = viewport;
  16160. setLayerDimensions(layer, {
  16161. rotation: viewport.rotation
  16162. });
  16163. tslib_1.__classPrivateFieldGet(this, _AnnotationLayer_instances, "m", _AnnotationLayer_setAnnotationCanvasMap).call(this);
  16164. layer.hidden = false;
  16165. };
  16166. AnnotationLayer.prototype.getEditableAnnotations = function () {
  16167. return Array.from(tslib_1.__classPrivateFieldGet(this, _AnnotationLayer_editableAnnotations, "f").values());
  16168. };
  16169. AnnotationLayer.prototype.getEditableAnnotation = function (id) {
  16170. return tslib_1.__classPrivateFieldGet(this, _AnnotationLayer_editableAnnotations, "f").get(id);
  16171. };
  16172. return AnnotationLayer;
  16173. }());
  16174. _AnnotationLayer_accessibilityManager = new WeakMap(), _AnnotationLayer_annotationCanvasMap = new WeakMap(), _AnnotationLayer_editableAnnotations = new WeakMap(), _AnnotationLayer_instances = new WeakSet(), _AnnotationLayer_appendElement = function _AnnotationLayer_appendElement(element, id) {
  16175. var _l;
  16176. var contentElement = element.firstChild || element;
  16177. contentElement.id = "".concat(AnnotationPrefix).concat(id);
  16178. this.div.append(element);
  16179. (_l = tslib_1.__classPrivateFieldGet(this, _AnnotationLayer_accessibilityManager, "f")) === null || _l === void 0 ? void 0 : _l.moveElementInDOM(this.div, element, contentElement, false);
  16180. }, _AnnotationLayer_setAnnotationCanvasMap = function _AnnotationLayer_setAnnotationCanvasMap() {
  16181. if (!tslib_1.__classPrivateFieldGet(this, _AnnotationLayer_annotationCanvasMap, "f")) {
  16182. return;
  16183. }
  16184. var layer = this.div;
  16185. for (var _i = 0, _l = tslib_1.__classPrivateFieldGet(this, _AnnotationLayer_annotationCanvasMap, "f"); _i < _l.length; _i++) {
  16186. var _m = _l[_i], id = _m[0], canvas = _m[1];
  16187. var element = layer.querySelector("[data-annotation-id=\"".concat(id, "\"]"));
  16188. if (!element) {
  16189. continue;
  16190. }
  16191. canvas.className = "annotationContent";
  16192. var firstChild = element.firstChild;
  16193. if (!firstChild) {
  16194. element.append(canvas);
  16195. }
  16196. else if (firstChild.nodeName === "CANVAS") {
  16197. firstChild.replaceWith(canvas);
  16198. }
  16199. else if (!firstChild.classList.contains("annotationContent")) {
  16200. firstChild.before(canvas);
  16201. }
  16202. else {
  16203. firstChild.after(canvas);
  16204. }
  16205. }
  16206. tslib_1.__classPrivateFieldGet(this, _AnnotationLayer_annotationCanvasMap, "f").clear();
  16207. };
  16208. ; // CONCATENATED MODULE: ./src/display/editor/freetext.js
  16209. var EOL_PATTERN = /\r\n?|\n/g;
  16210. var FreeTextEditor = /** @class */ (function (_super) {
  16211. tslib_1.__extends(FreeTextEditor, _super);
  16212. function FreeTextEditor(params) {
  16213. var _this = _super.call(this, tslib_1.__assign(tslib_1.__assign({}, params), { name: "freeTextEditor" })) || this;
  16214. _FreeTextEditor_instances.add(_this);
  16215. _FreeTextEditor_boundEditorDivBlur.set(_this, _this.editorDivBlur.bind(_this));
  16216. _FreeTextEditor_boundEditorDivFocus.set(_this, _this.editorDivFocus.bind(_this));
  16217. _FreeTextEditor_boundEditorDivInput.set(_this, _this.editorDivInput.bind(_this));
  16218. _FreeTextEditor_boundEditorDivKeydown.set(_this, _this.editorDivKeydown.bind(_this));
  16219. _FreeTextEditor_boundEditorDivPaste.set(_this, _this.editorDivPaste.bind(_this));
  16220. _FreeTextEditor_color.set(_this, void 0);
  16221. _FreeTextEditor_content.set(_this, "");
  16222. _FreeTextEditor_editorDivId.set(_this, "".concat(_this.id, "-editor"));
  16223. _FreeTextEditor_fontSize.set(_this, void 0);
  16224. _FreeTextEditor_initialData.set(_this, null);
  16225. tslib_1.__classPrivateFieldSet(_this, _FreeTextEditor_color, params.color || FreeTextEditor._defaultColor || AnnotationEditor._defaultLineColor, "f");
  16226. tslib_1.__classPrivateFieldSet(_this, _FreeTextEditor_fontSize, params.fontSize || FreeTextEditor._defaultFontSize, "f");
  16227. return _this;
  16228. }
  16229. Object.defineProperty(FreeTextEditor, "_keyboardManager", {
  16230. get: function () {
  16231. var proto = FreeTextEditor.prototype;
  16232. var arrowChecker = function (self) { return self.isEmpty(); };
  16233. var small = AnnotationEditorUIManager.TRANSLATE_SMALL;
  16234. var big = AnnotationEditorUIManager.TRANSLATE_BIG;
  16235. return shadow(this, "_keyboardManager", new KeyboardManager([[["ctrl+s", "mac+meta+s", "ctrl+p", "mac+meta+p"], proto.commitOrRemove, {
  16236. bubbles: true
  16237. }], [["ctrl+Enter", "mac+meta+Enter", "Escape", "mac+Escape"], proto.commitOrRemove], [["ArrowLeft", "mac+ArrowLeft"], proto._translateEmpty, {
  16238. args: [-small, 0],
  16239. checker: arrowChecker
  16240. }], [["ctrl+ArrowLeft", "mac+shift+ArrowLeft"], proto._translateEmpty, {
  16241. args: [-big, 0],
  16242. checker: arrowChecker
  16243. }], [["ArrowRight", "mac+ArrowRight"], proto._translateEmpty, {
  16244. args: [small, 0],
  16245. checker: arrowChecker
  16246. }], [["ctrl+ArrowRight", "mac+shift+ArrowRight"], proto._translateEmpty, {
  16247. args: [big, 0],
  16248. checker: arrowChecker
  16249. }], [["ArrowUp", "mac+ArrowUp"], proto._translateEmpty, {
  16250. args: [0, -small],
  16251. checker: arrowChecker
  16252. }], [["ctrl+ArrowUp", "mac+shift+ArrowUp"], proto._translateEmpty, {
  16253. args: [0, -big],
  16254. checker: arrowChecker
  16255. }], [["ArrowDown", "mac+ArrowDown"], proto._translateEmpty, {
  16256. args: [0, small],
  16257. checker: arrowChecker
  16258. }], [["ctrl+ArrowDown", "mac+shift+ArrowDown"], proto._translateEmpty, {
  16259. args: [0, big],
  16260. checker: arrowChecker
  16261. }]]));
  16262. },
  16263. enumerable: false,
  16264. configurable: true
  16265. });
  16266. FreeTextEditor.initialize = function (l10n, uiManager) {
  16267. AnnotationEditor.initialize(l10n, uiManager, {
  16268. strings: ["pdfjs-free-text-default-content"]
  16269. });
  16270. var style = getComputedStyle(document.documentElement);
  16271. this._internalPadding = parseFloat(style.getPropertyValue("--freetext-padding"));
  16272. };
  16273. FreeTextEditor.updateDefaultParams = function (type, value) {
  16274. switch (type) {
  16275. case AnnotationEditorParamsType.FREETEXT_SIZE:
  16276. FreeTextEditor._defaultFontSize = value;
  16277. break;
  16278. case AnnotationEditorParamsType.FREETEXT_COLOR:
  16279. FreeTextEditor._defaultColor = value;
  16280. break;
  16281. }
  16282. };
  16283. FreeTextEditor.prototype.updateParams = function (type, value) {
  16284. switch (type) {
  16285. case AnnotationEditorParamsType.FREETEXT_SIZE:
  16286. tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_instances, "m", _FreeTextEditor_updateFontSize).call(this, value);
  16287. break;
  16288. case AnnotationEditorParamsType.FREETEXT_COLOR:
  16289. tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_instances, "m", _FreeTextEditor_updateColor).call(this, value);
  16290. break;
  16291. }
  16292. };
  16293. Object.defineProperty(FreeTextEditor, "defaultPropertiesToUpdate", {
  16294. get: function () {
  16295. return [[AnnotationEditorParamsType.FREETEXT_SIZE, FreeTextEditor._defaultFontSize], [AnnotationEditorParamsType.FREETEXT_COLOR, FreeTextEditor._defaultColor || AnnotationEditor._defaultLineColor]];
  16296. },
  16297. enumerable: false,
  16298. configurable: true
  16299. });
  16300. Object.defineProperty(FreeTextEditor.prototype, "propertiesToUpdate", {
  16301. get: function () {
  16302. return [[AnnotationEditorParamsType.FREETEXT_SIZE, tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_fontSize, "f")], [AnnotationEditorParamsType.FREETEXT_COLOR, tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_color, "f")]];
  16303. },
  16304. enumerable: false,
  16305. configurable: true
  16306. });
  16307. FreeTextEditor.prototype._translateEmpty = function (x, y) {
  16308. this._uiManager.translateSelectedEditors(x, y, true);
  16309. };
  16310. FreeTextEditor.prototype.getInitialTranslation = function () {
  16311. var scale = this.parentScale;
  16312. return [-FreeTextEditor._internalPadding * scale, -(FreeTextEditor._internalPadding + tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_fontSize, "f")) * scale];
  16313. };
  16314. FreeTextEditor.prototype.rebuild = function () {
  16315. if (!this.parent) {
  16316. return;
  16317. }
  16318. _super.prototype.rebuild.call(this);
  16319. if (this.div === null) {
  16320. return;
  16321. }
  16322. if (!this.isAttachedToDOM) {
  16323. this.parent.add(this);
  16324. }
  16325. };
  16326. FreeTextEditor.prototype.enableEditMode = function () {
  16327. if (this.isInEditMode()) {
  16328. return;
  16329. }
  16330. this.parent.setEditingState(false);
  16331. this.parent.updateToolbar(AnnotationEditorType.FREETEXT);
  16332. _super.prototype.enableEditMode.call(this);
  16333. this.overlayDiv.classList.remove("enabled");
  16334. this.editorDiv.contentEditable = true;
  16335. this._isDraggable = false;
  16336. this.div.removeAttribute("aria-activedescendant");
  16337. this.editorDiv.addEventListener("keydown", tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_boundEditorDivKeydown, "f"));
  16338. this.editorDiv.addEventListener("focus", tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_boundEditorDivFocus, "f"));
  16339. this.editorDiv.addEventListener("blur", tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_boundEditorDivBlur, "f"));
  16340. this.editorDiv.addEventListener("input", tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_boundEditorDivInput, "f"));
  16341. this.editorDiv.addEventListener("paste", tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_boundEditorDivPaste, "f"));
  16342. };
  16343. FreeTextEditor.prototype.disableEditMode = function () {
  16344. if (!this.isInEditMode()) {
  16345. return;
  16346. }
  16347. this.parent.setEditingState(true);
  16348. _super.prototype.disableEditMode.call(this);
  16349. this.overlayDiv.classList.add("enabled");
  16350. this.editorDiv.contentEditable = false;
  16351. this.div.setAttribute("aria-activedescendant", tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_editorDivId, "f"));
  16352. this._isDraggable = true;
  16353. this.editorDiv.removeEventListener("keydown", tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_boundEditorDivKeydown, "f"));
  16354. this.editorDiv.removeEventListener("focus", tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_boundEditorDivFocus, "f"));
  16355. this.editorDiv.removeEventListener("blur", tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_boundEditorDivBlur, "f"));
  16356. this.editorDiv.removeEventListener("input", tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_boundEditorDivInput, "f"));
  16357. this.editorDiv.removeEventListener("paste", tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_boundEditorDivPaste, "f"));
  16358. this.div.focus({
  16359. preventScroll: true
  16360. });
  16361. this.isEditing = false;
  16362. this.parent.div.classList.add("freetextEditing");
  16363. };
  16364. FreeTextEditor.prototype.focusin = function (event) {
  16365. if (!this._focusEventsAllowed) {
  16366. return;
  16367. }
  16368. _super.prototype.focusin.call(this, event);
  16369. if (event.target !== this.editorDiv) {
  16370. this.editorDiv.focus();
  16371. }
  16372. };
  16373. FreeTextEditor.prototype.onceAdded = function () {
  16374. var _m;
  16375. if (this.width) {
  16376. return;
  16377. }
  16378. this.enableEditMode();
  16379. this.editorDiv.focus();
  16380. if ((_m = this._initialOptions) === null || _m === void 0 ? void 0 : _m.isCentered) {
  16381. this.center();
  16382. }
  16383. this._initialOptions = null;
  16384. };
  16385. FreeTextEditor.prototype.isEmpty = function () {
  16386. return !this.editorDiv || this.editorDiv.innerText.trim() === "";
  16387. };
  16388. FreeTextEditor.prototype.remove = function () {
  16389. this.isEditing = false;
  16390. if (this.parent) {
  16391. this.parent.setEditingState(true);
  16392. this.parent.div.classList.add("freetextEditing");
  16393. }
  16394. _super.prototype.remove.call(this);
  16395. };
  16396. FreeTextEditor.prototype.commit = function () {
  16397. var _this = this;
  16398. if (!this.isInEditMode()) {
  16399. return;
  16400. }
  16401. _super.prototype.commit.call(this);
  16402. this.disableEditMode();
  16403. var savedText = tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_content, "f");
  16404. var newText = tslib_1.__classPrivateFieldSet(this, _FreeTextEditor_content, tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_instances, "m", _FreeTextEditor_extractText).call(this).trimEnd(), "f");
  16405. if (savedText === newText) {
  16406. return;
  16407. }
  16408. var setText = function (text) {
  16409. tslib_1.__classPrivateFieldSet(_this, _FreeTextEditor_content, text, "f");
  16410. if (!text) {
  16411. _this.remove();
  16412. return;
  16413. }
  16414. tslib_1.__classPrivateFieldGet(_this, _FreeTextEditor_instances, "m", _FreeTextEditor_setContent).call(_this);
  16415. _this._uiManager.rebuild(_this);
  16416. tslib_1.__classPrivateFieldGet(_this, _FreeTextEditor_instances, "m", _FreeTextEditor_setEditorDimensions).call(_this);
  16417. };
  16418. this.addCommands({
  16419. cmd: function () {
  16420. setText(newText);
  16421. },
  16422. undo: function () {
  16423. setText(savedText);
  16424. },
  16425. mustExec: false
  16426. });
  16427. tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_instances, "m", _FreeTextEditor_setEditorDimensions).call(this);
  16428. };
  16429. FreeTextEditor.prototype.shouldGetKeyboardEvents = function () {
  16430. return this.isInEditMode();
  16431. };
  16432. FreeTextEditor.prototype.enterInEditMode = function () {
  16433. this.enableEditMode();
  16434. this.editorDiv.focus();
  16435. };
  16436. FreeTextEditor.prototype.dblclick = function (event) {
  16437. this.enterInEditMode();
  16438. };
  16439. FreeTextEditor.prototype.keydown = function (event) {
  16440. if (event.target === this.div && event.key === "Enter") {
  16441. this.enterInEditMode();
  16442. event.preventDefault();
  16443. }
  16444. };
  16445. FreeTextEditor.prototype.editorDivKeydown = function (event) {
  16446. FreeTextEditor._keyboardManager.exec(this, event);
  16447. };
  16448. FreeTextEditor.prototype.editorDivFocus = function (event) {
  16449. this.isEditing = true;
  16450. };
  16451. FreeTextEditor.prototype.editorDivBlur = function (event) {
  16452. this.isEditing = false;
  16453. };
  16454. FreeTextEditor.prototype.editorDivInput = function (event) {
  16455. this.parent.div.classList.toggle("freetextEditing", this.isEmpty());
  16456. };
  16457. FreeTextEditor.prototype.disableEditing = function () {
  16458. this.editorDiv.setAttribute("role", "comment");
  16459. this.editorDiv.removeAttribute("aria-multiline");
  16460. };
  16461. FreeTextEditor.prototype.enableEditing = function () {
  16462. this.editorDiv.setAttribute("role", "textbox");
  16463. this.editorDiv.setAttribute("aria-multiline", true);
  16464. };
  16465. FreeTextEditor.prototype.render = function () {
  16466. var _m, _o, _p, _q;
  16467. var _this = this;
  16468. if (this.div) {
  16469. return this.div;
  16470. }
  16471. var baseX, baseY;
  16472. if (this.width) {
  16473. baseX = this.x;
  16474. baseY = this.y;
  16475. }
  16476. _super.prototype.render.call(this);
  16477. this.editorDiv = document.createElement("div");
  16478. this.editorDiv.className = "internal";
  16479. this.editorDiv.setAttribute("id", tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_editorDivId, "f"));
  16480. this.editorDiv.setAttribute("data-l10n-id", "pdfjs-free-text");
  16481. this.enableEditing();
  16482. AnnotationEditor._l10nPromise.get("pdfjs-free-text-default-content").then(function (msg) { var _m; return (_m = _this.editorDiv) === null || _m === void 0 ? void 0 : _m.setAttribute("default-content", msg); });
  16483. this.editorDiv.contentEditable = true;
  16484. var style = this.editorDiv.style;
  16485. style.fontSize = "calc(".concat(tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_fontSize, "f"), "px * var(--scale-factor))");
  16486. style.color = tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_color, "f");
  16487. this.div.append(this.editorDiv);
  16488. this.overlayDiv = document.createElement("div");
  16489. this.overlayDiv.classList.add("overlay", "enabled");
  16490. this.div.append(this.overlayDiv);
  16491. bindEvents(this, this.div, ["dblclick", "keydown"]);
  16492. if (this.width) {
  16493. var _r = this.parentDimensions, parentWidth = _r[0], parentHeight = _r[1];
  16494. if (this.annotationElementId) {
  16495. var position = tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_initialData, "f").position;
  16496. var _s = this.getInitialTranslation(), tx = _s[0], ty = _s[1];
  16497. _m = this.pageTranslationToScreen(tx, ty), tx = _m[0], ty = _m[1];
  16498. var _t = this.pageDimensions, pageWidth = _t[0], pageHeight = _t[1];
  16499. var _u = this.pageTranslation, pageX = _u[0], pageY = _u[1];
  16500. var posX = void 0, posY = void 0;
  16501. switch (this.rotation) {
  16502. case 0:
  16503. posX = baseX + (position[0] - pageX) / pageWidth;
  16504. posY = baseY + this.height - (position[1] - pageY) / pageHeight;
  16505. break;
  16506. case 90:
  16507. posX = baseX + (position[0] - pageX) / pageWidth;
  16508. posY = baseY - (position[1] - pageY) / pageHeight;
  16509. _o = [ty, -tx], tx = _o[0], ty = _o[1];
  16510. break;
  16511. case 180:
  16512. posX = baseX - this.width + (position[0] - pageX) / pageWidth;
  16513. posY = baseY - (position[1] - pageY) / pageHeight;
  16514. _p = [-tx, -ty], tx = _p[0], ty = _p[1];
  16515. break;
  16516. case 270:
  16517. posX = baseX + (position[0] - pageX - this.height * pageHeight) / pageWidth;
  16518. posY = baseY + (position[1] - pageY - this.width * pageWidth) / pageHeight;
  16519. _q = [-ty, tx], tx = _q[0], ty = _q[1];
  16520. break;
  16521. }
  16522. this.setAt(posX * parentWidth, posY * parentHeight, tx, ty);
  16523. }
  16524. else {
  16525. this.setAt(baseX * parentWidth, baseY * parentHeight, this.width * parentWidth, this.height * parentHeight);
  16526. }
  16527. tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_instances, "m", _FreeTextEditor_setContent).call(this);
  16528. this._isDraggable = true;
  16529. this.editorDiv.contentEditable = false;
  16530. }
  16531. else {
  16532. this._isDraggable = false;
  16533. this.editorDiv.contentEditable = true;
  16534. }
  16535. return this.div;
  16536. };
  16537. FreeTextEditor.prototype.editorDivPaste = function (event) {
  16538. var clipboardData = event.clipboardData || window.clipboardData;
  16539. var types = clipboardData.types;
  16540. if (types.length === 1 && types[0] === "text/plain") {
  16541. return;
  16542. }
  16543. event.preventDefault();
  16544. var paste = tslib_1.__classPrivateFieldGet(FreeTextEditor, _l, "m", _FreeTextEditor_deserializeContent).call(FreeTextEditor, clipboardData.getData("text") || "").replaceAll(EOL_PATTERN, "\n");
  16545. if (!paste) {
  16546. return;
  16547. }
  16548. var selection = window.getSelection();
  16549. if (!selection.rangeCount) {
  16550. return;
  16551. }
  16552. this.editorDiv.normalize();
  16553. selection.deleteFromDocument();
  16554. var range = selection.getRangeAt(0);
  16555. if (!paste.includes("\n")) {
  16556. range.insertNode(document.createTextNode(paste));
  16557. this.editorDiv.normalize();
  16558. selection.collapseToStart();
  16559. return;
  16560. }
  16561. var startContainer = range.startContainer, startOffset = range.startOffset;
  16562. var bufferBefore = [];
  16563. var bufferAfter = [];
  16564. if (startContainer.nodeType === Node.TEXT_NODE) {
  16565. var parent = startContainer.parentElement;
  16566. bufferAfter.push(startContainer.nodeValue.slice(startOffset).replaceAll(EOL_PATTERN, ""));
  16567. if (parent !== this.editorDiv) {
  16568. var buffer = bufferBefore;
  16569. for (var _i = 0, _m = this.editorDiv.childNodes; _i < _m.length; _i++) {
  16570. var child = _m[_i];
  16571. if (child === parent) {
  16572. buffer = bufferAfter;
  16573. continue;
  16574. }
  16575. buffer.push(tslib_1.__classPrivateFieldGet(FreeTextEditor, _l, "m", _FreeTextEditor_getNodeContent).call(FreeTextEditor, child));
  16576. }
  16577. }
  16578. bufferBefore.push(startContainer.nodeValue.slice(0, startOffset).replaceAll(EOL_PATTERN, ""));
  16579. }
  16580. else if (startContainer === this.editorDiv) {
  16581. var buffer = bufferBefore;
  16582. var i = 0;
  16583. for (var _o = 0, _p = this.editorDiv.childNodes; _o < _p.length; _o++) {
  16584. var child = _p[_o];
  16585. if (i++ === startOffset) {
  16586. buffer = bufferAfter;
  16587. }
  16588. buffer.push(tslib_1.__classPrivateFieldGet(FreeTextEditor, _l, "m", _FreeTextEditor_getNodeContent).call(FreeTextEditor, child));
  16589. }
  16590. }
  16591. tslib_1.__classPrivateFieldSet(this, _FreeTextEditor_content, "".concat(bufferBefore.join("\n")).concat(paste).concat(bufferAfter.join("\n")), "f");
  16592. tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_instances, "m", _FreeTextEditor_setContent).call(this);
  16593. var newRange = new Range();
  16594. var beforeLength = bufferBefore.reduce(function (acc, line) { return acc + line.length; }, 0);
  16595. for (var _q = 0, _r = this.editorDiv.childNodes; _q < _r.length; _q++) {
  16596. var firstChild = _r[_q].firstChild;
  16597. if (firstChild.nodeType === Node.TEXT_NODE) {
  16598. var length = firstChild.nodeValue.length;
  16599. if (beforeLength <= length) {
  16600. newRange.setStart(firstChild, beforeLength);
  16601. newRange.setEnd(firstChild, beforeLength);
  16602. break;
  16603. }
  16604. beforeLength -= length;
  16605. }
  16606. }
  16607. selection.removeAllRanges();
  16608. selection.addRange(newRange);
  16609. };
  16610. Object.defineProperty(FreeTextEditor.prototype, "contentDiv", {
  16611. get: function () {
  16612. return this.editorDiv;
  16613. },
  16614. enumerable: false,
  16615. configurable: true
  16616. });
  16617. FreeTextEditor.deserialize = function (data, parent, uiManager) {
  16618. var initialData = null;
  16619. if (data instanceof FreeTextAnnotationElement) {
  16620. var _m = data.data, _o = _m.defaultAppearanceData, fontSize = _o.fontSize, fontColor = _o.fontColor, rect = _m.rect, rotation = _m.rotation, id = _m.id, textContent = data.textContent, textPosition = data.textPosition, pageNumber = data.parent.page.pageNumber;
  16621. if (!textContent || textContent.length === 0) {
  16622. return null;
  16623. }
  16624. initialData = data = {
  16625. annotationType: AnnotationEditorType.FREETEXT,
  16626. color: Array.from(fontColor),
  16627. fontSize: fontSize,
  16628. value: textContent.join("\n"),
  16629. position: textPosition,
  16630. pageIndex: pageNumber - 1,
  16631. rect: rect.slice(0),
  16632. rotation: rotation,
  16633. id: id,
  16634. deleted: false
  16635. };
  16636. }
  16637. var editor = _super.deserialize.call(this, data, parent, uiManager);
  16638. tslib_1.__classPrivateFieldSet(editor, _FreeTextEditor_fontSize, data.fontSize, "f");
  16639. tslib_1.__classPrivateFieldSet(editor, _FreeTextEditor_color, Util.makeHexColor.apply(Util, data.color), "f");
  16640. tslib_1.__classPrivateFieldSet(editor, _FreeTextEditor_content, tslib_1.__classPrivateFieldGet(FreeTextEditor, _l, "m", _FreeTextEditor_deserializeContent).call(FreeTextEditor, data.value), "f");
  16641. editor.annotationElementId = data.id || null;
  16642. tslib_1.__classPrivateFieldSet(editor, _FreeTextEditor_initialData, initialData, "f");
  16643. return editor;
  16644. };
  16645. FreeTextEditor.prototype.serialize = function (isForCopying) {
  16646. if (isForCopying === void 0) { isForCopying = false; }
  16647. if (this.isEmpty()) {
  16648. return null;
  16649. }
  16650. if (this.deleted) {
  16651. return {
  16652. pageIndex: this.pageIndex,
  16653. id: this.annotationElementId,
  16654. deleted: true
  16655. };
  16656. }
  16657. var padding = FreeTextEditor._internalPadding * this.parentScale;
  16658. var rect = this.getRect(padding, padding);
  16659. var color = AnnotationEditor._colorManager.convert(this.isAttachedToDOM ? getComputedStyle(this.editorDiv).color : tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_color, "f"));
  16660. var serialized = {
  16661. annotationType: AnnotationEditorType.FREETEXT,
  16662. color: color,
  16663. fontSize: tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_fontSize, "f"),
  16664. value: tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_instances, "m", _FreeTextEditor_serializeContent).call(this),
  16665. pageIndex: this.pageIndex,
  16666. rect: rect,
  16667. rotation: this.rotation,
  16668. structTreeParentId: this._structTreeParentId
  16669. };
  16670. if (isForCopying) {
  16671. return serialized;
  16672. }
  16673. if (this.annotationElementId && !tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_instances, "m", _FreeTextEditor_hasElementChanged).call(this, serialized)) {
  16674. return null;
  16675. }
  16676. serialized.id = this.annotationElementId;
  16677. return serialized;
  16678. };
  16679. FreeTextEditor.prototype.renderAnnotationElement = function (annotation) {
  16680. var content = _super.prototype.renderAnnotationElement.call(this, annotation);
  16681. if (this.deleted) {
  16682. return content;
  16683. }
  16684. var style = content.style;
  16685. style.fontSize = "calc(".concat(tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_fontSize, "f"), "px * var(--scale-factor))");
  16686. style.color = tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_color, "f");
  16687. content.replaceChildren();
  16688. for (var _i = 0, _m = tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_content, "f").split("\n"); _i < _m.length; _i++) {
  16689. var line = _m[_i];
  16690. var div = document.createElement("div");
  16691. div.append(line ? document.createTextNode(line) : document.createElement("br"));
  16692. content.append(div);
  16693. }
  16694. var padding = FreeTextEditor._internalPadding * this.parentScale;
  16695. annotation.updateEdited({
  16696. rect: this.getRect(padding, padding),
  16697. popupContent: tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_content, "f")
  16698. });
  16699. return content;
  16700. };
  16701. FreeTextEditor.prototype.resetAnnotationElement = function (annotation) {
  16702. _super.prototype.resetAnnotationElement.call(this, annotation);
  16703. annotation.resetEdited();
  16704. };
  16705. var _FreeTextEditor_instances, _l, _FreeTextEditor_boundEditorDivBlur, _FreeTextEditor_boundEditorDivFocus, _FreeTextEditor_boundEditorDivInput, _FreeTextEditor_boundEditorDivKeydown, _FreeTextEditor_boundEditorDivPaste, _FreeTextEditor_color, _FreeTextEditor_content, _FreeTextEditor_editorDivId, _FreeTextEditor_fontSize, _FreeTextEditor_initialData, _FreeTextEditor_updateFontSize, _FreeTextEditor_updateColor, _FreeTextEditor_extractText, _FreeTextEditor_setEditorDimensions, _FreeTextEditor_getNodeContent, _FreeTextEditor_setContent, _FreeTextEditor_serializeContent, _FreeTextEditor_deserializeContent, _FreeTextEditor_hasElementChanged;
  16706. _l = FreeTextEditor, _FreeTextEditor_boundEditorDivBlur = new WeakMap(), _FreeTextEditor_boundEditorDivFocus = new WeakMap(), _FreeTextEditor_boundEditorDivInput = new WeakMap(), _FreeTextEditor_boundEditorDivKeydown = new WeakMap(), _FreeTextEditor_boundEditorDivPaste = new WeakMap(), _FreeTextEditor_color = new WeakMap(), _FreeTextEditor_content = new WeakMap(), _FreeTextEditor_editorDivId = new WeakMap(), _FreeTextEditor_fontSize = new WeakMap(), _FreeTextEditor_initialData = new WeakMap(), _FreeTextEditor_instances = new WeakSet(), _FreeTextEditor_updateFontSize = function _FreeTextEditor_updateFontSize(fontSize) {
  16707. var _this = this;
  16708. var setFontsize = function (size) {
  16709. _this.editorDiv.style.fontSize = "calc(".concat(size, "px * var(--scale-factor))");
  16710. _this.translate(0, -(size - tslib_1.__classPrivateFieldGet(_this, _FreeTextEditor_fontSize, "f")) * _this.parentScale);
  16711. tslib_1.__classPrivateFieldSet(_this, _FreeTextEditor_fontSize, size, "f");
  16712. tslib_1.__classPrivateFieldGet(_this, _FreeTextEditor_instances, "m", _FreeTextEditor_setEditorDimensions).call(_this);
  16713. };
  16714. var savedFontsize = tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_fontSize, "f");
  16715. this.addCommands({
  16716. cmd: setFontsize.bind(this, fontSize),
  16717. undo: setFontsize.bind(this, savedFontsize),
  16718. post: this._uiManager.updateUI.bind(this._uiManager, this),
  16719. mustExec: true,
  16720. type: AnnotationEditorParamsType.FREETEXT_SIZE,
  16721. overwriteIfSameType: true,
  16722. keepUndo: true
  16723. });
  16724. }, _FreeTextEditor_updateColor = function _FreeTextEditor_updateColor(color) {
  16725. var _this = this;
  16726. var setColor = function (col) {
  16727. tslib_1.__classPrivateFieldSet(_this, _FreeTextEditor_color, _this.editorDiv.style.color = col, "f");
  16728. };
  16729. var savedColor = tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_color, "f");
  16730. this.addCommands({
  16731. cmd: setColor.bind(this, color),
  16732. undo: setColor.bind(this, savedColor),
  16733. post: this._uiManager.updateUI.bind(this._uiManager, this),
  16734. mustExec: true,
  16735. type: AnnotationEditorParamsType.FREETEXT_COLOR,
  16736. overwriteIfSameType: true,
  16737. keepUndo: true
  16738. });
  16739. }, _FreeTextEditor_extractText = function _FreeTextEditor_extractText() {
  16740. var buffer = [];
  16741. this.editorDiv.normalize();
  16742. for (var _i = 0, _m = this.editorDiv.childNodes; _i < _m.length; _i++) {
  16743. var child = _m[_i];
  16744. buffer.push(tslib_1.__classPrivateFieldGet(FreeTextEditor, _l, "m", _FreeTextEditor_getNodeContent).call(FreeTextEditor, child));
  16745. }
  16746. return buffer.join("\n");
  16747. }, _FreeTextEditor_setEditorDimensions = function _FreeTextEditor_setEditorDimensions() {
  16748. var _m = this.parentDimensions, parentWidth = _m[0], parentHeight = _m[1];
  16749. var rect;
  16750. if (this.isAttachedToDOM) {
  16751. rect = this.div.getBoundingClientRect();
  16752. }
  16753. else {
  16754. var _o = this, currentLayer = _o.currentLayer, div = _o.div;
  16755. var savedDisplay = div.style.display;
  16756. var savedVisibility = div.classList.contains("hidden");
  16757. div.classList.remove("hidden");
  16758. div.style.display = "hidden";
  16759. currentLayer.div.append(this.div);
  16760. rect = div.getBoundingClientRect();
  16761. div.remove();
  16762. div.style.display = savedDisplay;
  16763. div.classList.toggle("hidden", savedVisibility);
  16764. }
  16765. if (this.rotation % 180 === this.parentRotation % 180) {
  16766. this.width = rect.width / parentWidth;
  16767. this.height = rect.height / parentHeight;
  16768. }
  16769. else {
  16770. this.width = rect.height / parentWidth;
  16771. this.height = rect.width / parentHeight;
  16772. }
  16773. this.fixAndSetPosition();
  16774. }, _FreeTextEditor_getNodeContent = function _FreeTextEditor_getNodeContent(node) {
  16775. return (node.nodeType === Node.TEXT_NODE ? node.nodeValue : node.innerText).replaceAll(EOL_PATTERN, "");
  16776. }, _FreeTextEditor_setContent = function _FreeTextEditor_setContent() {
  16777. this.editorDiv.replaceChildren();
  16778. if (!tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_content, "f")) {
  16779. return;
  16780. }
  16781. for (var _i = 0, _m = tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_content, "f").split("\n"); _i < _m.length; _i++) {
  16782. var line = _m[_i];
  16783. var div = document.createElement("div");
  16784. div.append(line ? document.createTextNode(line) : document.createElement("br"));
  16785. this.editorDiv.append(div);
  16786. }
  16787. }, _FreeTextEditor_serializeContent = function _FreeTextEditor_serializeContent() {
  16788. return tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_content, "f").replaceAll("\xa0", " ");
  16789. }, _FreeTextEditor_deserializeContent = function _FreeTextEditor_deserializeContent(content) {
  16790. return content.replaceAll(" ", "\xa0");
  16791. }, _FreeTextEditor_hasElementChanged = function _FreeTextEditor_hasElementChanged(serialized) {
  16792. var _m = tslib_1.__classPrivateFieldGet(this, _FreeTextEditor_initialData, "f"), value = _m.value, fontSize = _m.fontSize, color = _m.color, pageIndex = _m.pageIndex;
  16793. return this._hasBeenMoved || serialized.value !== value || serialized.fontSize !== fontSize || serialized.color.some(function (c, i) { return c !== color[i]; }) || serialized.pageIndex !== pageIndex;
  16794. };
  16795. FreeTextEditor._freeTextDefaultContent = "";
  16796. FreeTextEditor._internalPadding = 0;
  16797. FreeTextEditor._defaultColor = null;
  16798. FreeTextEditor._defaultFontSize = 10;
  16799. FreeTextEditor._type = "freetext";
  16800. FreeTextEditor._editorType = AnnotationEditorType.FREETEXT;
  16801. return FreeTextEditor;
  16802. }(AnnotationEditor));
  16803. ; // CONCATENATED MODULE: ./src/display/editor/outliner.js
  16804. var Outliner = /** @class */ (function () {
  16805. function Outliner(boxes, borderWidth, innerMargin, isLTR) {
  16806. if (borderWidth === void 0) { borderWidth = 0; }
  16807. if (innerMargin === void 0) { innerMargin = 0; }
  16808. if (isLTR === void 0) { isLTR = true; }
  16809. _Outliner_instances.add(this);
  16810. _Outliner_box.set(this, void 0);
  16811. _Outliner_verticalEdges.set(this, []);
  16812. _Outliner_intervals.set(this, []);
  16813. var minX = Infinity;
  16814. var maxX = -Infinity;
  16815. var minY = Infinity;
  16816. var maxY = -Infinity;
  16817. var NUMBER_OF_DIGITS = 4;
  16818. var EPSILON = Math.pow(10, -NUMBER_OF_DIGITS);
  16819. for (var _i = 0, boxes_2 = boxes; _i < boxes_2.length; _i++) {
  16820. var _m = boxes_2[_i], x = _m.x, y = _m.y, width = _m.width, height = _m.height;
  16821. var x1 = Math.floor((x - borderWidth) / EPSILON) * EPSILON;
  16822. var x2 = Math.ceil((x + width + borderWidth) / EPSILON) * EPSILON;
  16823. var y1 = Math.floor((y - borderWidth) / EPSILON) * EPSILON;
  16824. var y2 = Math.ceil((y + height + borderWidth) / EPSILON) * EPSILON;
  16825. var left = [x1, y1, y2, true];
  16826. var right = [x2, y1, y2, false];
  16827. tslib_1.__classPrivateFieldGet(this, _Outliner_verticalEdges, "f").push(left, right);
  16828. minX = Math.min(minX, x1);
  16829. maxX = Math.max(maxX, x2);
  16830. minY = Math.min(minY, y1);
  16831. maxY = Math.max(maxY, y2);
  16832. }
  16833. var bboxWidth = maxX - minX + 2 * innerMargin;
  16834. var bboxHeight = maxY - minY + 2 * innerMargin;
  16835. var shiftedMinX = minX - innerMargin;
  16836. var shiftedMinY = minY - innerMargin;
  16837. var lastEdge = tslib_1.__classPrivateFieldGet(this, _Outliner_verticalEdges, "f").at(isLTR ? -1 : -2);
  16838. var lastPoint = [lastEdge[0], lastEdge[2]];
  16839. for (var _o = 0, _p = tslib_1.__classPrivateFieldGet(this, _Outliner_verticalEdges, "f"); _o < _p.length; _o++) {
  16840. var edge = _p[_o];
  16841. var x = edge[0], y1 = edge[1], y2 = edge[2];
  16842. edge[0] = (x - shiftedMinX) / bboxWidth;
  16843. edge[1] = (y1 - shiftedMinY) / bboxHeight;
  16844. edge[2] = (y2 - shiftedMinY) / bboxHeight;
  16845. }
  16846. tslib_1.__classPrivateFieldSet(this, _Outliner_box, {
  16847. x: shiftedMinX,
  16848. y: shiftedMinY,
  16849. width: bboxWidth,
  16850. height: bboxHeight,
  16851. lastPoint: lastPoint
  16852. }, "f");
  16853. }
  16854. Outliner.prototype.getOutlines = function () {
  16855. tslib_1.__classPrivateFieldGet(this, _Outliner_verticalEdges, "f").sort(function (a, b) { return a[0] - b[0] || a[1] - b[1] || a[2] - b[2]; });
  16856. var outlineVerticalEdges = [];
  16857. for (var _i = 0, _m = tslib_1.__classPrivateFieldGet(this, _Outliner_verticalEdges, "f"); _i < _m.length; _i++) {
  16858. var edge = _m[_i];
  16859. if (edge[3]) {
  16860. outlineVerticalEdges.push.apply(outlineVerticalEdges, tslib_1.__classPrivateFieldGet(this, _Outliner_instances, "m", _Outliner_breakEdge).call(this, edge));
  16861. tslib_1.__classPrivateFieldGet(this, _Outliner_instances, "m", _Outliner_insert).call(this, edge);
  16862. }
  16863. else {
  16864. tslib_1.__classPrivateFieldGet(this, _Outliner_instances, "m", _Outliner_remove).call(this, edge);
  16865. outlineVerticalEdges.push.apply(outlineVerticalEdges, tslib_1.__classPrivateFieldGet(this, _Outliner_instances, "m", _Outliner_breakEdge).call(this, edge));
  16866. }
  16867. }
  16868. return tslib_1.__classPrivateFieldGet(this, _Outliner_instances, "m", _Outliner_getOutlines).call(this, outlineVerticalEdges);
  16869. };
  16870. return Outliner;
  16871. }());
  16872. _Outliner_box = new WeakMap(), _Outliner_verticalEdges = new WeakMap(), _Outliner_intervals = new WeakMap(), _Outliner_instances = new WeakSet(), _Outliner_getOutlines = function _Outliner_getOutlines(outlineVerticalEdges) {
  16873. var edges = [];
  16874. var allEdges = new Set();
  16875. for (var _i = 0, outlineVerticalEdges_1 = outlineVerticalEdges; _i < outlineVerticalEdges_1.length; _i++) {
  16876. var edge = outlineVerticalEdges_1[_i];
  16877. var x = edge[0], y1 = edge[1], y2 = edge[2];
  16878. edges.push([x, y1, edge], [x, y2, edge]);
  16879. }
  16880. edges.sort(function (a, b) { return a[1] - b[1] || a[0] - b[0]; });
  16881. for (var i = 0, ii = edges.length; i < ii; i += 2) {
  16882. var edge1 = edges[i][2];
  16883. var edge2 = edges[i + 1][2];
  16884. edge1.push(edge2);
  16885. edge2.push(edge1);
  16886. allEdges.add(edge1);
  16887. allEdges.add(edge2);
  16888. }
  16889. var outlines = [];
  16890. var outline;
  16891. while (allEdges.size > 0) {
  16892. var edge = allEdges.values().next().value;
  16893. var x = edge[0], y1 = edge[1], y2 = edge[2], edge1 = edge[3], edge2 = edge[4];
  16894. allEdges.delete(edge);
  16895. var lastPointX = x;
  16896. var lastPointY = y1;
  16897. outline = [x, y2];
  16898. outlines.push(outline);
  16899. while (true) {
  16900. var e = void 0;
  16901. if (allEdges.has(edge1)) {
  16902. e = edge1;
  16903. }
  16904. else if (allEdges.has(edge2)) {
  16905. e = edge2;
  16906. }
  16907. else {
  16908. break;
  16909. }
  16910. allEdges.delete(e);
  16911. x = e[0], y1 = e[1], y2 = e[2], edge1 = e[3], edge2 = e[4];
  16912. if (lastPointX !== x) {
  16913. outline.push(lastPointX, lastPointY, x, lastPointY === y1 ? y1 : y2);
  16914. lastPointX = x;
  16915. }
  16916. lastPointY = lastPointY === y1 ? y2 : y1;
  16917. }
  16918. outline.push(lastPointX, lastPointY);
  16919. }
  16920. return new HighlightOutline(outlines, tslib_1.__classPrivateFieldGet(this, _Outliner_box, "f"));
  16921. }, _Outliner_binarySearch = function _Outliner_binarySearch(y) {
  16922. var array = tslib_1.__classPrivateFieldGet(this, _Outliner_intervals, "f");
  16923. var start = 0;
  16924. var end = array.length - 1;
  16925. while (start <= end) {
  16926. var middle = start + end >> 1;
  16927. var y1 = array[middle][0];
  16928. if (y1 === y) {
  16929. return middle;
  16930. }
  16931. if (y1 < y) {
  16932. start = middle + 1;
  16933. }
  16934. else {
  16935. end = middle - 1;
  16936. }
  16937. }
  16938. return end + 1;
  16939. }, _Outliner_insert = function _Outliner_insert(_m) {
  16940. var y1 = _m[1], y2 = _m[2];
  16941. var index = tslib_1.__classPrivateFieldGet(this, _Outliner_instances, "m", _Outliner_binarySearch).call(this, y1);
  16942. tslib_1.__classPrivateFieldGet(this, _Outliner_intervals, "f").splice(index, 0, [y1, y2]);
  16943. }, _Outliner_remove = function _Outliner_remove(_m) {
  16944. var y1 = _m[1], y2 = _m[2];
  16945. var index = tslib_1.__classPrivateFieldGet(this, _Outliner_instances, "m", _Outliner_binarySearch).call(this, y1);
  16946. for (var i = index; i < tslib_1.__classPrivateFieldGet(this, _Outliner_intervals, "f").length; i++) {
  16947. var _o = tslib_1.__classPrivateFieldGet(this, _Outliner_intervals, "f")[i], start = _o[0], end = _o[1];
  16948. if (start !== y1) {
  16949. break;
  16950. }
  16951. if (start === y1 && end === y2) {
  16952. tslib_1.__classPrivateFieldGet(this, _Outliner_intervals, "f").splice(i, 1);
  16953. return;
  16954. }
  16955. }
  16956. for (var i = index - 1; i >= 0; i--) {
  16957. var _p = tslib_1.__classPrivateFieldGet(this, _Outliner_intervals, "f")[i], start = _p[0], end = _p[1];
  16958. if (start !== y1) {
  16959. break;
  16960. }
  16961. if (start === y1 && end === y2) {
  16962. tslib_1.__classPrivateFieldGet(this, _Outliner_intervals, "f").splice(i, 1);
  16963. return;
  16964. }
  16965. }
  16966. }, _Outliner_breakEdge = function _Outliner_breakEdge(edge) {
  16967. var x = edge[0], y1 = edge[1], y2 = edge[2];
  16968. var results = [[x, y1, y2]];
  16969. var index = tslib_1.__classPrivateFieldGet(this, _Outliner_instances, "m", _Outliner_binarySearch).call(this, y2);
  16970. for (var i = 0; i < index; i++) {
  16971. var _m = tslib_1.__classPrivateFieldGet(this, _Outliner_intervals, "f")[i], start = _m[0], end = _m[1];
  16972. for (var j = 0, jj = results.length; j < jj; j++) {
  16973. var _o = results[j], y3 = _o[1], y4 = _o[2];
  16974. if (end <= y3 || y4 <= start) {
  16975. continue;
  16976. }
  16977. if (y3 >= start) {
  16978. if (y4 > end) {
  16979. results[j][1] = end;
  16980. }
  16981. else {
  16982. if (jj === 1) {
  16983. return [];
  16984. }
  16985. results.splice(j, 1);
  16986. j--;
  16987. jj--;
  16988. }
  16989. continue;
  16990. }
  16991. results[j][2] = start;
  16992. if (y4 > end) {
  16993. results.push([x, end, y4]);
  16994. }
  16995. }
  16996. }
  16997. return results;
  16998. };
  16999. var Outline = /** @class */ (function () {
  17000. function Outline() {
  17001. }
  17002. Outline.prototype.toSVGPath = function () {
  17003. throw new Error("Abstract method `toSVGPath` must be implemented.");
  17004. };
  17005. Object.defineProperty(Outline.prototype, "box", {
  17006. get: function () {
  17007. throw new Error("Abstract getter `box` must be implemented.");
  17008. },
  17009. enumerable: false,
  17010. configurable: true
  17011. });
  17012. Outline.prototype.serialize = function (_bbox, _rotation) {
  17013. throw new Error("Abstract method `serialize` must be implemented.");
  17014. };
  17015. Object.defineProperty(Outline.prototype, "free", {
  17016. get: function () {
  17017. return this instanceof FreeHighlightOutline;
  17018. },
  17019. enumerable: false,
  17020. configurable: true
  17021. });
  17022. return Outline;
  17023. }());
  17024. var HighlightOutline = /** @class */ (function (_super) {
  17025. tslib_1.__extends(HighlightOutline, _super);
  17026. function HighlightOutline(outlines, box) {
  17027. var _this = _super.call(this) || this;
  17028. _HighlightOutline_box.set(_this, void 0);
  17029. _HighlightOutline_outlines.set(_this, void 0);
  17030. tslib_1.__classPrivateFieldSet(_this, _HighlightOutline_outlines, outlines, "f");
  17031. tslib_1.__classPrivateFieldSet(_this, _HighlightOutline_box, box, "f");
  17032. return _this;
  17033. }
  17034. HighlightOutline.prototype.toSVGPath = function () {
  17035. var buffer = [];
  17036. for (var _i = 0, _m = tslib_1.__classPrivateFieldGet(this, _HighlightOutline_outlines, "f"); _i < _m.length; _i++) {
  17037. var polygon = _m[_i];
  17038. var prevX = polygon[0], prevY = polygon[1];
  17039. buffer.push("M".concat(prevX, " ").concat(prevY));
  17040. for (var i = 2; i < polygon.length; i += 2) {
  17041. var x = polygon[i];
  17042. var y = polygon[i + 1];
  17043. if (x === prevX) {
  17044. buffer.push("V".concat(y));
  17045. prevY = y;
  17046. }
  17047. else if (y === prevY) {
  17048. buffer.push("H".concat(x));
  17049. prevX = x;
  17050. }
  17051. }
  17052. buffer.push("Z");
  17053. }
  17054. return buffer.join(" ");
  17055. };
  17056. HighlightOutline.prototype.serialize = function (_m, _rotation) {
  17057. var blX = _m[0], blY = _m[1], trX = _m[2], trY = _m[3];
  17058. var outlines = [];
  17059. var width = trX - blX;
  17060. var height = trY - blY;
  17061. for (var _i = 0, _o = tslib_1.__classPrivateFieldGet(this, _HighlightOutline_outlines, "f"); _i < _o.length; _i++) {
  17062. var outline = _o[_i];
  17063. var points = new Array(outline.length);
  17064. for (var i = 0; i < outline.length; i += 2) {
  17065. points[i] = blX + outline[i] * width;
  17066. points[i + 1] = trY - outline[i + 1] * height;
  17067. }
  17068. outlines.push(points);
  17069. }
  17070. return outlines;
  17071. };
  17072. Object.defineProperty(HighlightOutline.prototype, "box", {
  17073. get: function () {
  17074. return tslib_1.__classPrivateFieldGet(this, _HighlightOutline_box, "f");
  17075. },
  17076. enumerable: false,
  17077. configurable: true
  17078. });
  17079. return HighlightOutline;
  17080. }(Outline));
  17081. _HighlightOutline_box = new WeakMap(), _HighlightOutline_outlines = new WeakMap();
  17082. var FreeOutliner = /** @class */ (function () {
  17083. function FreeOutliner(_o, box, scaleFactor, thickness, isLTR, innerMargin) {
  17084. var x = _o.x, y = _o.y;
  17085. if (innerMargin === void 0) { innerMargin = 0; }
  17086. _FreeOutliner_instances.add(this);
  17087. _FreeOutliner_box.set(this, void 0);
  17088. _FreeOutliner_bottom.set(this, []);
  17089. _FreeOutliner_innerMargin.set(this, void 0);
  17090. _FreeOutliner_isLTR.set(this, void 0);
  17091. _FreeOutliner_top.set(this, []);
  17092. _FreeOutliner_last.set(this, new Float64Array(18));
  17093. _FreeOutliner_lastX.set(this, void 0);
  17094. _FreeOutliner_lastY.set(this, void 0);
  17095. _FreeOutliner_min.set(this, void 0);
  17096. _FreeOutliner_min_dist.set(this, void 0);
  17097. _FreeOutliner_scaleFactor.set(this, void 0);
  17098. _FreeOutliner_thickness.set(this, void 0);
  17099. _FreeOutliner_points.set(this, []);
  17100. tslib_1.__classPrivateFieldSet(this, _FreeOutliner_box, box, "f");
  17101. tslib_1.__classPrivateFieldSet(this, _FreeOutliner_thickness, thickness * scaleFactor, "f");
  17102. tslib_1.__classPrivateFieldSet(this, _FreeOutliner_isLTR, isLTR, "f");
  17103. tslib_1.__classPrivateFieldGet(this, _FreeOutliner_last, "f").set([NaN, NaN, NaN, NaN, x, y], 6);
  17104. tslib_1.__classPrivateFieldSet(this, _FreeOutliner_innerMargin, innerMargin, "f");
  17105. tslib_1.__classPrivateFieldSet(this, _FreeOutliner_min_dist, tslib_1.__classPrivateFieldGet(FreeOutliner, _m, "f", _FreeOutliner_MIN_DIST) * scaleFactor, "f");
  17106. tslib_1.__classPrivateFieldSet(this, _FreeOutliner_min, tslib_1.__classPrivateFieldGet(FreeOutliner, _m, "f", _FreeOutliner_MIN) * scaleFactor, "f");
  17107. tslib_1.__classPrivateFieldSet(this, _FreeOutliner_scaleFactor, scaleFactor, "f");
  17108. tslib_1.__classPrivateFieldGet(this, _FreeOutliner_points, "f").push(x, y);
  17109. }
  17110. Object.defineProperty(FreeOutliner.prototype, "free", {
  17111. get: function () {
  17112. return true;
  17113. },
  17114. enumerable: false,
  17115. configurable: true
  17116. });
  17117. FreeOutliner.prototype.isEmpty = function () {
  17118. return isNaN(tslib_1.__classPrivateFieldGet(this, _FreeOutliner_last, "f")[8]);
  17119. };
  17120. FreeOutliner.prototype.add = function (_o) {
  17121. var _p, _q, _r, _s;
  17122. var _t;
  17123. var x = _o.x, y = _o.y;
  17124. tslib_1.__classPrivateFieldSet(this, _FreeOutliner_lastX, x, "f");
  17125. tslib_1.__classPrivateFieldSet(this, _FreeOutliner_lastY, y, "f");
  17126. var _u = tslib_1.__classPrivateFieldGet(this, _FreeOutliner_box, "f"), layerX = _u[0], layerY = _u[1], layerWidth = _u[2], layerHeight = _u[3];
  17127. var _v = tslib_1.__classPrivateFieldGet(this, _FreeOutliner_last, "f").subarray(8, 12), x1 = _v[0], y1 = _v[1], x2 = _v[2], y2 = _v[3];
  17128. var diffX = x - x2;
  17129. var diffY = y - y2;
  17130. var d = Math.hypot(diffX, diffY);
  17131. if (d < tslib_1.__classPrivateFieldGet(this, _FreeOutliner_min, "f")) {
  17132. return false;
  17133. }
  17134. var diffD = d - tslib_1.__classPrivateFieldGet(this, _FreeOutliner_min_dist, "f");
  17135. var K = diffD / d;
  17136. var shiftX = K * diffX;
  17137. var shiftY = K * diffY;
  17138. var x0 = x1;
  17139. var y0 = y1;
  17140. x1 = x2;
  17141. y1 = y2;
  17142. x2 += shiftX;
  17143. y2 += shiftY;
  17144. (_t = tslib_1.__classPrivateFieldGet(this, _FreeOutliner_points, "f")) === null || _t === void 0 ? void 0 : _t.push(x, y);
  17145. var nX = -shiftY / diffD;
  17146. var nY = shiftX / diffD;
  17147. var thX = nX * tslib_1.__classPrivateFieldGet(this, _FreeOutliner_thickness, "f");
  17148. var thY = nY * tslib_1.__classPrivateFieldGet(this, _FreeOutliner_thickness, "f");
  17149. tslib_1.__classPrivateFieldGet(this, _FreeOutliner_last, "f").set(tslib_1.__classPrivateFieldGet(this, _FreeOutliner_last, "f").subarray(2, 8), 0);
  17150. tslib_1.__classPrivateFieldGet(this, _FreeOutliner_last, "f").set([x2 + thX, y2 + thY], 4);
  17151. tslib_1.__classPrivateFieldGet(this, _FreeOutliner_last, "f").set(tslib_1.__classPrivateFieldGet(this, _FreeOutliner_last, "f").subarray(14, 18), 12);
  17152. tslib_1.__classPrivateFieldGet(this, _FreeOutliner_last, "f").set([x2 - thX, y2 - thY], 16);
  17153. if (isNaN(tslib_1.__classPrivateFieldGet(this, _FreeOutliner_last, "f")[6])) {
  17154. if (tslib_1.__classPrivateFieldGet(this, _FreeOutliner_top, "f").length === 0) {
  17155. tslib_1.__classPrivateFieldGet(this, _FreeOutliner_last, "f").set([x1 + thX, y1 + thY], 2);
  17156. tslib_1.__classPrivateFieldGet(this, _FreeOutliner_top, "f").push(NaN, NaN, NaN, NaN, (x1 + thX - layerX) / layerWidth, (y1 + thY - layerY) / layerHeight);
  17157. tslib_1.__classPrivateFieldGet(this, _FreeOutliner_last, "f").set([x1 - thX, y1 - thY], 14);
  17158. tslib_1.__classPrivateFieldGet(this, _FreeOutliner_bottom, "f").push(NaN, NaN, NaN, NaN, (x1 - thX - layerX) / layerWidth, (y1 - thY - layerY) / layerHeight);
  17159. }
  17160. tslib_1.__classPrivateFieldGet(this, _FreeOutliner_last, "f").set([x0, y0, x1, y1, x2, y2], 6);
  17161. return !this.isEmpty();
  17162. }
  17163. tslib_1.__classPrivateFieldGet(this, _FreeOutliner_last, "f").set([x0, y0, x1, y1, x2, y2], 6);
  17164. var angle = Math.abs(Math.atan2(y0 - y1, x0 - x1) - Math.atan2(shiftY, shiftX));
  17165. if (angle < Math.PI / 2) {
  17166. _p = tslib_1.__classPrivateFieldGet(this, _FreeOutliner_last, "f").subarray(2, 6), x1 = _p[0], y1 = _p[1], x2 = _p[2], y2 = _p[3];
  17167. tslib_1.__classPrivateFieldGet(this, _FreeOutliner_top, "f").push(NaN, NaN, NaN, NaN, ((x1 + x2) / 2 - layerX) / layerWidth, ((y1 + y2) / 2 - layerY) / layerHeight);
  17168. _q = tslib_1.__classPrivateFieldGet(this, _FreeOutliner_last, "f").subarray(14, 18), x1 = _q[0], y1 = _q[1], x0 = _q[2], y0 = _q[3];
  17169. tslib_1.__classPrivateFieldGet(this, _FreeOutliner_bottom, "f").push(NaN, NaN, NaN, NaN, ((x0 + x1) / 2 - layerX) / layerWidth, ((y0 + y1) / 2 - layerY) / layerHeight);
  17170. return true;
  17171. }
  17172. _r = tslib_1.__classPrivateFieldGet(this, _FreeOutliner_last, "f").subarray(0, 6), x0 = _r[0], y0 = _r[1], x1 = _r[2], y1 = _r[3], x2 = _r[4], y2 = _r[5];
  17173. tslib_1.__classPrivateFieldGet(this, _FreeOutliner_top, "f").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);
  17174. _s = tslib_1.__classPrivateFieldGet(this, _FreeOutliner_last, "f").subarray(12, 18), x2 = _s[0], y2 = _s[1], x1 = _s[2], y1 = _s[3], x0 = _s[4], y0 = _s[5];
  17175. tslib_1.__classPrivateFieldGet(this, _FreeOutliner_bottom, "f").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);
  17176. return true;
  17177. };
  17178. FreeOutliner.prototype.toSVGPath = function () {
  17179. if (this.isEmpty()) {
  17180. return "";
  17181. }
  17182. var top = tslib_1.__classPrivateFieldGet(this, _FreeOutliner_top, "f");
  17183. var bottom = tslib_1.__classPrivateFieldGet(this, _FreeOutliner_bottom, "f");
  17184. var lastTop = tslib_1.__classPrivateFieldGet(this, _FreeOutliner_last, "f").subarray(4, 6);
  17185. var lastBottom = tslib_1.__classPrivateFieldGet(this, _FreeOutliner_last, "f").subarray(16, 18);
  17186. var _o = tslib_1.__classPrivateFieldGet(this, _FreeOutliner_box, "f"), x = _o[0], y = _o[1], width = _o[2], height = _o[3];
  17187. var _p = tslib_1.__classPrivateFieldGet(this, _FreeOutliner_instances, "m", _FreeOutliner_getLastCoords).call(this), lastTopX = _p[0], lastTopY = _p[1], lastBottomX = _p[2], lastBottomY = _p[3];
  17188. if (isNaN(tslib_1.__classPrivateFieldGet(this, _FreeOutliner_last, "f")[6]) && !this.isEmpty()) {
  17189. return "M".concat((tslib_1.__classPrivateFieldGet(this, _FreeOutliner_last, "f")[2] - x) / width, " ").concat((tslib_1.__classPrivateFieldGet(this, _FreeOutliner_last, "f")[3] - y) / height, " L").concat((tslib_1.__classPrivateFieldGet(this, _FreeOutliner_last, "f")[4] - x) / width, " ").concat((tslib_1.__classPrivateFieldGet(this, _FreeOutliner_last, "f")[5] - y) / height, " L").concat(lastTopX, " ").concat(lastTopY, " L").concat(lastBottomX, " ").concat(lastBottomY, " L").concat((tslib_1.__classPrivateFieldGet(this, _FreeOutliner_last, "f")[16] - x) / width, " ").concat((tslib_1.__classPrivateFieldGet(this, _FreeOutliner_last, "f")[17] - y) / height, " L").concat((tslib_1.__classPrivateFieldGet(this, _FreeOutliner_last, "f")[14] - x) / width, " ").concat((tslib_1.__classPrivateFieldGet(this, _FreeOutliner_last, "f")[15] - y) / height, " Z");
  17190. }
  17191. var buffer = [];
  17192. buffer.push("M".concat(top[4], " ").concat(top[5]));
  17193. for (var i = 6; i < top.length; i += 6) {
  17194. if (isNaN(top[i])) {
  17195. buffer.push("L".concat(top[i + 4], " ").concat(top[i + 5]));
  17196. }
  17197. else {
  17198. buffer.push("C".concat(top[i], " ").concat(top[i + 1], " ").concat(top[i + 2], " ").concat(top[i + 3], " ").concat(top[i + 4], " ").concat(top[i + 5]));
  17199. }
  17200. }
  17201. buffer.push("L".concat((lastTop[0] - x) / width, " ").concat((lastTop[1] - y) / height, " L").concat(lastTopX, " ").concat(lastTopY, " L").concat(lastBottomX, " ").concat(lastBottomY, " L").concat((lastBottom[0] - x) / width, " ").concat((lastBottom[1] - y) / height));
  17202. for (var i = bottom.length - 6; i >= 6; i -= 6) {
  17203. if (isNaN(bottom[i])) {
  17204. buffer.push("L".concat(bottom[i + 4], " ").concat(bottom[i + 5]));
  17205. }
  17206. else {
  17207. buffer.push("C".concat(bottom[i], " ").concat(bottom[i + 1], " ").concat(bottom[i + 2], " ").concat(bottom[i + 3], " ").concat(bottom[i + 4], " ").concat(bottom[i + 5]));
  17208. }
  17209. }
  17210. buffer.push("L".concat(bottom[4], " ").concat(bottom[5], " Z"));
  17211. return buffer.join(" ");
  17212. };
  17213. FreeOutliner.prototype.getOutlines = function () {
  17214. var _o, _p;
  17215. var top = tslib_1.__classPrivateFieldGet(this, _FreeOutliner_top, "f");
  17216. var bottom = tslib_1.__classPrivateFieldGet(this, _FreeOutliner_bottom, "f");
  17217. var last = tslib_1.__classPrivateFieldGet(this, _FreeOutliner_last, "f");
  17218. var lastTop = last.subarray(4, 6);
  17219. var lastBottom = last.subarray(16, 18);
  17220. var _q = tslib_1.__classPrivateFieldGet(this, _FreeOutliner_box, "f"), layerX = _q[0], layerY = _q[1], layerWidth = _q[2], layerHeight = _q[3];
  17221. var points = new Float64Array(((_p = (_o = tslib_1.__classPrivateFieldGet(this, _FreeOutliner_points, "f")) === null || _o === void 0 ? void 0 : _o.length) !== null && _p !== void 0 ? _p : 0) + 2);
  17222. for (var i = 0, ii = points.length - 2; i < ii; i += 2) {
  17223. points[i] = (tslib_1.__classPrivateFieldGet(this, _FreeOutliner_points, "f")[i] - layerX) / layerWidth;
  17224. points[i + 1] = (tslib_1.__classPrivateFieldGet(this, _FreeOutliner_points, "f")[i + 1] - layerY) / layerHeight;
  17225. }
  17226. points[points.length - 2] = (tslib_1.__classPrivateFieldGet(this, _FreeOutliner_lastX, "f") - layerX) / layerWidth;
  17227. points[points.length - 1] = (tslib_1.__classPrivateFieldGet(this, _FreeOutliner_lastY, "f") - layerY) / layerHeight;
  17228. var _r = tslib_1.__classPrivateFieldGet(this, _FreeOutliner_instances, "m", _FreeOutliner_getLastCoords).call(this), lastTopX = _r[0], lastTopY = _r[1], lastBottomX = _r[2], lastBottomY = _r[3];
  17229. if (isNaN(last[6]) && !this.isEmpty()) {
  17230. var outline_1 = new Float64Array(36);
  17231. outline_1.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);
  17232. return new FreeHighlightOutline(outline_1, points, tslib_1.__classPrivateFieldGet(this, _FreeOutliner_box, "f"), tslib_1.__classPrivateFieldGet(this, _FreeOutliner_scaleFactor, "f"), tslib_1.__classPrivateFieldGet(this, _FreeOutliner_innerMargin, "f"), tslib_1.__classPrivateFieldGet(this, _FreeOutliner_isLTR, "f"));
  17233. }
  17234. var outline = new Float64Array(tslib_1.__classPrivateFieldGet(this, _FreeOutliner_top, "f").length + 24 + tslib_1.__classPrivateFieldGet(this, _FreeOutliner_bottom, "f").length);
  17235. var N = top.length;
  17236. for (var i = 0; i < N; i += 2) {
  17237. if (isNaN(top[i])) {
  17238. outline[i] = outline[i + 1] = NaN;
  17239. continue;
  17240. }
  17241. outline[i] = top[i];
  17242. outline[i + 1] = top[i + 1];
  17243. }
  17244. 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);
  17245. N += 24;
  17246. for (var i = bottom.length - 6; i >= 6; i -= 6) {
  17247. for (var j = 0; j < 6; j += 2) {
  17248. if (isNaN(bottom[i + j])) {
  17249. outline[N] = outline[N + 1] = NaN;
  17250. N += 2;
  17251. continue;
  17252. }
  17253. outline[N] = bottom[i + j];
  17254. outline[N + 1] = bottom[i + j + 1];
  17255. N += 2;
  17256. }
  17257. }
  17258. outline.set([NaN, NaN, NaN, NaN, bottom[4], bottom[5]], N);
  17259. return new FreeHighlightOutline(outline, points, tslib_1.__classPrivateFieldGet(this, _FreeOutliner_box, "f"), tslib_1.__classPrivateFieldGet(this, _FreeOutliner_scaleFactor, "f"), tslib_1.__classPrivateFieldGet(this, _FreeOutliner_innerMargin, "f"), tslib_1.__classPrivateFieldGet(this, _FreeOutliner_isLTR, "f"));
  17260. };
  17261. var _FreeOutliner_instances, _m, _FreeOutliner_box, _FreeOutliner_bottom, _FreeOutliner_innerMargin, _FreeOutliner_isLTR, _FreeOutliner_top, _FreeOutliner_last, _FreeOutliner_lastX, _FreeOutliner_lastY, _FreeOutliner_min, _FreeOutliner_min_dist, _FreeOutliner_scaleFactor, _FreeOutliner_thickness, _FreeOutliner_points, _FreeOutliner_MIN_DIST, _FreeOutliner_MIN_DIFF, _FreeOutliner_MIN, _FreeOutliner_getLastCoords;
  17262. _m = FreeOutliner, _FreeOutliner_box = new WeakMap(), _FreeOutliner_bottom = new WeakMap(), _FreeOutliner_innerMargin = new WeakMap(), _FreeOutliner_isLTR = new WeakMap(), _FreeOutliner_top = new WeakMap(), _FreeOutliner_last = new WeakMap(), _FreeOutliner_lastX = new WeakMap(), _FreeOutliner_lastY = new WeakMap(), _FreeOutliner_min = new WeakMap(), _FreeOutliner_min_dist = new WeakMap(), _FreeOutliner_scaleFactor = new WeakMap(), _FreeOutliner_thickness = new WeakMap(), _FreeOutliner_points = new WeakMap(), _FreeOutliner_instances = new WeakSet(), _FreeOutliner_getLastCoords = function _FreeOutliner_getLastCoords() {
  17263. var lastTop = tslib_1.__classPrivateFieldGet(this, _FreeOutliner_last, "f").subarray(4, 6);
  17264. var lastBottom = tslib_1.__classPrivateFieldGet(this, _FreeOutliner_last, "f").subarray(16, 18);
  17265. var _o = tslib_1.__classPrivateFieldGet(this, _FreeOutliner_box, "f"), x = _o[0], y = _o[1], width = _o[2], height = _o[3];
  17266. return [(tslib_1.__classPrivateFieldGet(this, _FreeOutliner_lastX, "f") + (lastTop[0] - lastBottom[0]) / 2 - x) / width, (tslib_1.__classPrivateFieldGet(this, _FreeOutliner_lastY, "f") + (lastTop[1] - lastBottom[1]) / 2 - y) / height, (tslib_1.__classPrivateFieldGet(this, _FreeOutliner_lastX, "f") + (lastBottom[0] - lastTop[0]) / 2 - x) / width, (tslib_1.__classPrivateFieldGet(this, _FreeOutliner_lastY, "f") + (lastBottom[1] - lastTop[1]) / 2 - y) / height];
  17267. };
  17268. _FreeOutliner_MIN_DIST = { value: 8 };
  17269. _FreeOutliner_MIN_DIFF = { value: 2 };
  17270. _FreeOutliner_MIN = { value: tslib_1.__classPrivateFieldGet(FreeOutliner, _m, "f", _FreeOutliner_MIN_DIST) + tslib_1.__classPrivateFieldGet(FreeOutliner, _m, "f", _FreeOutliner_MIN_DIFF) };
  17271. return FreeOutliner;
  17272. }());
  17273. var FreeHighlightOutline = /** @class */ (function (_super) {
  17274. tslib_1.__extends(FreeHighlightOutline, _super);
  17275. function FreeHighlightOutline(outline, points, box, scaleFactor, innerMargin, isLTR) {
  17276. var _this = _super.call(this) || this;
  17277. _FreeHighlightOutline_instances.add(_this);
  17278. _FreeHighlightOutline_box.set(_this, void 0);
  17279. _FreeHighlightOutline_bbox.set(_this, null);
  17280. _FreeHighlightOutline_innerMargin.set(_this, void 0);
  17281. _FreeHighlightOutline_isLTR.set(_this, void 0);
  17282. _FreeHighlightOutline_points.set(_this, void 0);
  17283. _FreeHighlightOutline_scaleFactor.set(_this, void 0);
  17284. _FreeHighlightOutline_outline.set(_this, void 0);
  17285. tslib_1.__classPrivateFieldSet(_this, _FreeHighlightOutline_outline, outline, "f");
  17286. tslib_1.__classPrivateFieldSet(_this, _FreeHighlightOutline_points, points, "f");
  17287. tslib_1.__classPrivateFieldSet(_this, _FreeHighlightOutline_box, box, "f");
  17288. tslib_1.__classPrivateFieldSet(_this, _FreeHighlightOutline_scaleFactor, scaleFactor, "f");
  17289. tslib_1.__classPrivateFieldSet(_this, _FreeHighlightOutline_innerMargin, innerMargin, "f");
  17290. tslib_1.__classPrivateFieldSet(_this, _FreeHighlightOutline_isLTR, isLTR, "f");
  17291. tslib_1.__classPrivateFieldGet(_this, _FreeHighlightOutline_instances, "m", _FreeHighlightOutline_computeMinMax).call(_this, isLTR);
  17292. var _o = tslib_1.__classPrivateFieldGet(_this, _FreeHighlightOutline_bbox, "f"), x = _o.x, y = _o.y, width = _o.width, height = _o.height;
  17293. for (var i = 0, ii = outline.length; i < ii; i += 2) {
  17294. outline[i] = (outline[i] - x) / width;
  17295. outline[i + 1] = (outline[i + 1] - y) / height;
  17296. }
  17297. for (var i = 0, ii = points.length; i < ii; i += 2) {
  17298. points[i] = (points[i] - x) / width;
  17299. points[i + 1] = (points[i + 1] - y) / height;
  17300. }
  17301. return _this;
  17302. }
  17303. FreeHighlightOutline.prototype.toSVGPath = function () {
  17304. var buffer = ["M".concat(tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f")[4], " ").concat(tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f")[5])];
  17305. for (var i = 6, ii = tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f").length; i < ii; i += 6) {
  17306. if (isNaN(tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f")[i])) {
  17307. buffer.push("L".concat(tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f")[i + 4], " ").concat(tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f")[i + 5]));
  17308. continue;
  17309. }
  17310. buffer.push("C".concat(tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f")[i], " ").concat(tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f")[i + 1], " ").concat(tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f")[i + 2], " ").concat(tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f")[i + 3], " ").concat(tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f")[i + 4], " ").concat(tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f")[i + 5]));
  17311. }
  17312. buffer.push("Z");
  17313. return buffer.join(" ");
  17314. };
  17315. FreeHighlightOutline.prototype.serialize = function (_o, rotation) {
  17316. var blX = _o[0], blY = _o[1], trX = _o[2], trY = _o[3];
  17317. var width = trX - blX;
  17318. var height = trY - blY;
  17319. var outline;
  17320. var points;
  17321. switch (rotation) {
  17322. case 0:
  17323. outline = tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_instances, "m", _FreeHighlightOutline_rescale).call(this, tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f"), blX, trY, width, -height);
  17324. points = tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_instances, "m", _FreeHighlightOutline_rescale).call(this, tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_points, "f"), blX, trY, width, -height);
  17325. break;
  17326. case 90:
  17327. outline = tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_instances, "m", _FreeHighlightOutline_rescaleAndSwap).call(this, tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f"), blX, blY, width, height);
  17328. points = tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_instances, "m", _FreeHighlightOutline_rescaleAndSwap).call(this, tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_points, "f"), blX, blY, width, height);
  17329. break;
  17330. case 180:
  17331. outline = tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_instances, "m", _FreeHighlightOutline_rescale).call(this, tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f"), trX, blY, -width, height);
  17332. points = tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_instances, "m", _FreeHighlightOutline_rescale).call(this, tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_points, "f"), trX, blY, -width, height);
  17333. break;
  17334. case 270:
  17335. outline = tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_instances, "m", _FreeHighlightOutline_rescaleAndSwap).call(this, tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f"), trX, trY, -width, -height);
  17336. points = tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_instances, "m", _FreeHighlightOutline_rescaleAndSwap).call(this, tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_points, "f"), trX, trY, -width, -height);
  17337. break;
  17338. }
  17339. return {
  17340. outline: Array.from(outline),
  17341. points: [Array.from(points)]
  17342. };
  17343. };
  17344. Object.defineProperty(FreeHighlightOutline.prototype, "box", {
  17345. get: function () {
  17346. return tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_bbox, "f");
  17347. },
  17348. enumerable: false,
  17349. configurable: true
  17350. });
  17351. FreeHighlightOutline.prototype.getNewOutline = function (thickness, innerMargin) {
  17352. var _o = tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_bbox, "f"), x = _o.x, y = _o.y, width = _o.width, height = _o.height;
  17353. var _p = tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_box, "f"), layerX = _p[0], layerY = _p[1], layerWidth = _p[2], layerHeight = _p[3];
  17354. var sx = width * layerWidth;
  17355. var sy = height * layerHeight;
  17356. var tx = x * layerWidth + layerX;
  17357. var ty = y * layerHeight + layerY;
  17358. var outliner = new FreeOutliner({
  17359. x: tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_points, "f")[0] * sx + tx,
  17360. y: tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_points, "f")[1] * sy + ty
  17361. }, tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_box, "f"), tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_scaleFactor, "f"), thickness, tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_isLTR, "f"), innerMargin !== null && innerMargin !== void 0 ? innerMargin : tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_innerMargin, "f"));
  17362. for (var i = 2; i < tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_points, "f").length; i += 2) {
  17363. outliner.add({
  17364. x: tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_points, "f")[i] * sx + tx,
  17365. y: tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_points, "f")[i + 1] * sy + ty
  17366. });
  17367. }
  17368. return outliner.getOutlines();
  17369. };
  17370. return FreeHighlightOutline;
  17371. }(Outline));
  17372. _FreeHighlightOutline_box = new WeakMap(), _FreeHighlightOutline_bbox = new WeakMap(), _FreeHighlightOutline_innerMargin = new WeakMap(), _FreeHighlightOutline_isLTR = new WeakMap(), _FreeHighlightOutline_points = new WeakMap(), _FreeHighlightOutline_scaleFactor = new WeakMap(), _FreeHighlightOutline_outline = new WeakMap(), _FreeHighlightOutline_instances = new WeakSet(), _FreeHighlightOutline_rescale = function _FreeHighlightOutline_rescale(src, tx, ty, sx, sy) {
  17373. var dest = new Float64Array(src.length);
  17374. for (var i = 0, ii = src.length; i < ii; i += 2) {
  17375. dest[i] = tx + src[i] * sx;
  17376. dest[i + 1] = ty + src[i + 1] * sy;
  17377. }
  17378. return dest;
  17379. }, _FreeHighlightOutline_rescaleAndSwap = function _FreeHighlightOutline_rescaleAndSwap(src, tx, ty, sx, sy) {
  17380. var dest = new Float64Array(src.length);
  17381. for (var i = 0, ii = src.length; i < ii; i += 2) {
  17382. dest[i] = tx + src[i + 1] * sx;
  17383. dest[i + 1] = ty + src[i] * sy;
  17384. }
  17385. return dest;
  17386. }, _FreeHighlightOutline_computeMinMax = function _FreeHighlightOutline_computeMinMax(isLTR) {
  17387. var outline = tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f");
  17388. var lastX = outline[4];
  17389. var lastY = outline[5];
  17390. var minX = lastX;
  17391. var minY = lastY;
  17392. var maxX = lastX;
  17393. var maxY = lastY;
  17394. var lastPointX = lastX;
  17395. var lastPointY = lastY;
  17396. var ltrCallback = isLTR ? Math.max : Math.min;
  17397. for (var i = 6, ii = outline.length; i < ii; i += 6) {
  17398. if (isNaN(outline[i])) {
  17399. minX = Math.min(minX, outline[i + 4]);
  17400. minY = Math.min(minY, outline[i + 5]);
  17401. maxX = Math.max(maxX, outline[i + 4]);
  17402. maxY = Math.max(maxY, outline[i + 5]);
  17403. if (lastPointY < outline[i + 5]) {
  17404. lastPointX = outline[i + 4];
  17405. lastPointY = outline[i + 5];
  17406. }
  17407. else if (lastPointY === outline[i + 5]) {
  17408. lastPointX = ltrCallback(lastPointX, outline[i + 4]);
  17409. }
  17410. }
  17411. else {
  17412. var bbox = Util.bezierBoundingBox.apply(Util, tslib_1.__spreadArray([lastX, lastY], outline.slice(i, i + 6), false));
  17413. minX = Math.min(minX, bbox[0]);
  17414. minY = Math.min(minY, bbox[1]);
  17415. maxX = Math.max(maxX, bbox[2]);
  17416. maxY = Math.max(maxY, bbox[3]);
  17417. if (lastPointY < bbox[3]) {
  17418. lastPointX = bbox[2];
  17419. lastPointY = bbox[3];
  17420. }
  17421. else if (lastPointY === bbox[3]) {
  17422. lastPointX = ltrCallback(lastPointX, bbox[2]);
  17423. }
  17424. }
  17425. lastX = outline[i + 4];
  17426. lastY = outline[i + 5];
  17427. }
  17428. var x = minX - tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_innerMargin, "f"), y = minY - tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_innerMargin, "f"), width = maxX - minX + 2 * tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_innerMargin, "f"), height = maxY - minY + 2 * tslib_1.__classPrivateFieldGet(this, _FreeHighlightOutline_innerMargin, "f");
  17429. tslib_1.__classPrivateFieldSet(this, _FreeHighlightOutline_bbox, {
  17430. x: x,
  17431. y: y,
  17432. width: width,
  17433. height: height,
  17434. lastPoint: [lastPointX, lastPointY]
  17435. }, "f");
  17436. };
  17437. ; // CONCATENATED MODULE: ./src/display/editor/color_picker.js
  17438. var ColorPicker = /** @class */ (function () {
  17439. function ColorPicker(_o) {
  17440. var _p = _o.editor, editor = _p === void 0 ? null : _p, _q = _o.uiManager, uiManager = _q === void 0 ? null : _q;
  17441. var _r;
  17442. _ColorPicker_instances.add(this);
  17443. _ColorPicker_boundKeyDown.set(this, tslib_1.__classPrivateFieldGet(this, _ColorPicker_instances, "m", _ColorPicker_keyDown).bind(this));
  17444. _ColorPicker_boundPointerDown.set(this, tslib_1.__classPrivateFieldGet(this, _ColorPicker_instances, "m", _ColorPicker_pointerDown).bind(this));
  17445. _ColorPicker_button.set(this, null);
  17446. _ColorPicker_buttonSwatch.set(this, null);
  17447. _ColorPicker_defaultColor.set(this, void 0);
  17448. _ColorPicker_dropdown.set(this, null);
  17449. _ColorPicker_dropdownWasFromKeyboard.set(this, false);
  17450. _ColorPicker_isMainColorPicker.set(this, false);
  17451. _ColorPicker_editor.set(this, null);
  17452. _ColorPicker_eventBus.set(this, void 0);
  17453. _ColorPicker_uiManager.set(this, null);
  17454. _ColorPicker_type.set(this, void 0);
  17455. if (editor) {
  17456. tslib_1.__classPrivateFieldSet(this, _ColorPicker_isMainColorPicker, false, "f");
  17457. tslib_1.__classPrivateFieldSet(this, _ColorPicker_type, AnnotationEditorParamsType.HIGHLIGHT_COLOR, "f");
  17458. tslib_1.__classPrivateFieldSet(this, _ColorPicker_editor, editor, "f");
  17459. }
  17460. else {
  17461. tslib_1.__classPrivateFieldSet(this, _ColorPicker_isMainColorPicker, true, "f");
  17462. tslib_1.__classPrivateFieldSet(this, _ColorPicker_type, AnnotationEditorParamsType.HIGHLIGHT_DEFAULT_COLOR, "f");
  17463. }
  17464. tslib_1.__classPrivateFieldSet(this, _ColorPicker_uiManager, (editor === null || editor === void 0 ? void 0 : editor._uiManager) || uiManager, "f");
  17465. tslib_1.__classPrivateFieldSet(this, _ColorPicker_eventBus, tslib_1.__classPrivateFieldGet(this, _ColorPicker_uiManager, "f")._eventBus, "f");
  17466. tslib_1.__classPrivateFieldSet(this, _ColorPicker_defaultColor, (editor === null || editor === void 0 ? void 0 : editor.color) || ((_r = tslib_1.__classPrivateFieldGet(this, _ColorPicker_uiManager, "f")) === null || _r === void 0 ? void 0 : _r.highlightColors.values().next().value) || "#FFFF98", "f");
  17467. }
  17468. Object.defineProperty(ColorPicker, "_keyboardManager", {
  17469. get: function () {
  17470. return shadow(this, "_keyboardManager", new 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]]));
  17471. },
  17472. enumerable: false,
  17473. configurable: true
  17474. });
  17475. ColorPicker.prototype.renderButton = function () {
  17476. var button = tslib_1.__classPrivateFieldSet(this, _ColorPicker_button, document.createElement("button"), "f");
  17477. button.className = "colorPicker";
  17478. button.tabIndex = "0";
  17479. button.setAttribute("data-l10n-id", "pdfjs-editor-colorpicker-button");
  17480. button.setAttribute("aria-haspopup", true);
  17481. button.addEventListener("click", tslib_1.__classPrivateFieldGet(this, _ColorPicker_instances, "m", _ColorPicker_openDropdown).bind(this));
  17482. button.addEventListener("keydown", tslib_1.__classPrivateFieldGet(this, _ColorPicker_boundKeyDown, "f"));
  17483. var swatch = tslib_1.__classPrivateFieldSet(this, _ColorPicker_buttonSwatch, document.createElement("span"), "f");
  17484. swatch.className = "swatch";
  17485. swatch.setAttribute("aria-hidden", true);
  17486. swatch.style.backgroundColor = tslib_1.__classPrivateFieldGet(this, _ColorPicker_defaultColor, "f");
  17487. button.append(swatch);
  17488. return button;
  17489. };
  17490. ColorPicker.prototype.renderMainDropdown = function () {
  17491. var dropdown = tslib_1.__classPrivateFieldSet(this, _ColorPicker_dropdown, tslib_1.__classPrivateFieldGet(this, _ColorPicker_instances, "m", _ColorPicker_getDropdownRoot).call(this), "f");
  17492. dropdown.setAttribute("aria-orientation", "horizontal");
  17493. dropdown.setAttribute("aria-labelledby", "highlightColorPickerLabel");
  17494. return dropdown;
  17495. };
  17496. ColorPicker.prototype._colorSelectFromKeyboard = function (event) {
  17497. if (event.target === tslib_1.__classPrivateFieldGet(this, _ColorPicker_button, "f")) {
  17498. tslib_1.__classPrivateFieldGet(this, _ColorPicker_instances, "m", _ColorPicker_openDropdown).call(this, event);
  17499. return;
  17500. }
  17501. var color = event.target.getAttribute("data-color");
  17502. if (!color) {
  17503. return;
  17504. }
  17505. tslib_1.__classPrivateFieldGet(this, _ColorPicker_instances, "m", _ColorPicker_colorSelect).call(this, color, event);
  17506. };
  17507. ColorPicker.prototype._moveToNext = function (event) {
  17508. var _o, _p;
  17509. if (!tslib_1.__classPrivateFieldGet(this, _ColorPicker_instances, "a", _ColorPicker_isDropdownVisible_get)) {
  17510. tslib_1.__classPrivateFieldGet(this, _ColorPicker_instances, "m", _ColorPicker_openDropdown).call(this, event);
  17511. return;
  17512. }
  17513. if (event.target === tslib_1.__classPrivateFieldGet(this, _ColorPicker_button, "f")) {
  17514. (_o = tslib_1.__classPrivateFieldGet(this, _ColorPicker_dropdown, "f").firstChild) === null || _o === void 0 ? void 0 : _o.focus();
  17515. return;
  17516. }
  17517. (_p = event.target.nextSibling) === null || _p === void 0 ? void 0 : _p.focus();
  17518. };
  17519. ColorPicker.prototype._moveToPrevious = function (event) {
  17520. var _o, _p;
  17521. if (event.target === ((_o = tslib_1.__classPrivateFieldGet(this, _ColorPicker_dropdown, "f")) === null || _o === void 0 ? void 0 : _o.firstChild) || event.target === tslib_1.__classPrivateFieldGet(this, _ColorPicker_button, "f")) {
  17522. if (tslib_1.__classPrivateFieldGet(this, _ColorPicker_instances, "a", _ColorPicker_isDropdownVisible_get)) {
  17523. this._hideDropdownFromKeyboard();
  17524. }
  17525. return;
  17526. }
  17527. if (!tslib_1.__classPrivateFieldGet(this, _ColorPicker_instances, "a", _ColorPicker_isDropdownVisible_get)) {
  17528. tslib_1.__classPrivateFieldGet(this, _ColorPicker_instances, "m", _ColorPicker_openDropdown).call(this, event);
  17529. }
  17530. (_p = event.target.previousSibling) === null || _p === void 0 ? void 0 : _p.focus();
  17531. };
  17532. ColorPicker.prototype._moveToBeginning = function (event) {
  17533. var _o;
  17534. if (!tslib_1.__classPrivateFieldGet(this, _ColorPicker_instances, "a", _ColorPicker_isDropdownVisible_get)) {
  17535. tslib_1.__classPrivateFieldGet(this, _ColorPicker_instances, "m", _ColorPicker_openDropdown).call(this, event);
  17536. return;
  17537. }
  17538. (_o = tslib_1.__classPrivateFieldGet(this, _ColorPicker_dropdown, "f").firstChild) === null || _o === void 0 ? void 0 : _o.focus();
  17539. };
  17540. ColorPicker.prototype._moveToEnd = function (event) {
  17541. var _o;
  17542. if (!tslib_1.__classPrivateFieldGet(this, _ColorPicker_instances, "a", _ColorPicker_isDropdownVisible_get)) {
  17543. tslib_1.__classPrivateFieldGet(this, _ColorPicker_instances, "m", _ColorPicker_openDropdown).call(this, event);
  17544. return;
  17545. }
  17546. (_o = tslib_1.__classPrivateFieldGet(this, _ColorPicker_dropdown, "f").lastChild) === null || _o === void 0 ? void 0 : _o.focus();
  17547. };
  17548. ColorPicker.prototype.hideDropdown = function () {
  17549. var _o;
  17550. (_o = tslib_1.__classPrivateFieldGet(this, _ColorPicker_dropdown, "f")) === null || _o === void 0 ? void 0 : _o.classList.add("hidden");
  17551. window.removeEventListener("pointerdown", tslib_1.__classPrivateFieldGet(this, _ColorPicker_boundPointerDown, "f"));
  17552. };
  17553. ColorPicker.prototype._hideDropdownFromKeyboard = function () {
  17554. var _o;
  17555. if (tslib_1.__classPrivateFieldGet(this, _ColorPicker_isMainColorPicker, "f")) {
  17556. return;
  17557. }
  17558. if (!tslib_1.__classPrivateFieldGet(this, _ColorPicker_instances, "a", _ColorPicker_isDropdownVisible_get)) {
  17559. (_o = tslib_1.__classPrivateFieldGet(this, _ColorPicker_editor, "f")) === null || _o === void 0 ? void 0 : _o.unselect();
  17560. return;
  17561. }
  17562. this.hideDropdown();
  17563. tslib_1.__classPrivateFieldGet(this, _ColorPicker_button, "f").focus({
  17564. preventScroll: true,
  17565. focusVisible: tslib_1.__classPrivateFieldGet(this, _ColorPicker_dropdownWasFromKeyboard, "f")
  17566. });
  17567. };
  17568. ColorPicker.prototype.updateColor = function (color) {
  17569. if (tslib_1.__classPrivateFieldGet(this, _ColorPicker_buttonSwatch, "f")) {
  17570. tslib_1.__classPrivateFieldGet(this, _ColorPicker_buttonSwatch, "f").style.backgroundColor = color;
  17571. }
  17572. if (!tslib_1.__classPrivateFieldGet(this, _ColorPicker_dropdown, "f")) {
  17573. return;
  17574. }
  17575. var i = tslib_1.__classPrivateFieldGet(this, _ColorPicker_uiManager, "f").highlightColors.values();
  17576. for (var _i = 0, _o = tslib_1.__classPrivateFieldGet(this, _ColorPicker_dropdown, "f").children; _i < _o.length; _i++) {
  17577. var child = _o[_i];
  17578. child.setAttribute("aria-selected", i.next().value === color);
  17579. }
  17580. };
  17581. ColorPicker.prototype.destroy = function () {
  17582. var _o, _p;
  17583. (_o = tslib_1.__classPrivateFieldGet(this, _ColorPicker_button, "f")) === null || _o === void 0 ? void 0 : _o.remove();
  17584. tslib_1.__classPrivateFieldSet(this, _ColorPicker_button, null, "f");
  17585. tslib_1.__classPrivateFieldSet(this, _ColorPicker_buttonSwatch, null, "f");
  17586. (_p = tslib_1.__classPrivateFieldGet(this, _ColorPicker_dropdown, "f")) === null || _p === void 0 ? void 0 : _p.remove();
  17587. tslib_1.__classPrivateFieldSet(this, _ColorPicker_dropdown, null, "f");
  17588. };
  17589. return ColorPicker;
  17590. }());
  17591. _ColorPicker_boundKeyDown = new WeakMap(), _ColorPicker_boundPointerDown = new WeakMap(), _ColorPicker_button = new WeakMap(), _ColorPicker_buttonSwatch = new WeakMap(), _ColorPicker_defaultColor = new WeakMap(), _ColorPicker_dropdown = new WeakMap(), _ColorPicker_dropdownWasFromKeyboard = new WeakMap(), _ColorPicker_isMainColorPicker = new WeakMap(), _ColorPicker_editor = new WeakMap(), _ColorPicker_eventBus = new WeakMap(), _ColorPicker_uiManager = new WeakMap(), _ColorPicker_type = new WeakMap(), _ColorPicker_instances = new WeakSet(), _ColorPicker_getDropdownRoot = function _ColorPicker_getDropdownRoot() {
  17592. var div = document.createElement("div");
  17593. div.addEventListener("contextmenu", noContextMenu);
  17594. div.className = "dropdown";
  17595. div.role = "listbox";
  17596. div.setAttribute("aria-multiselectable", false);
  17597. div.setAttribute("aria-orientation", "vertical");
  17598. div.setAttribute("data-l10n-id", "pdfjs-editor-colorpicker-dropdown");
  17599. for (var _i = 0, _o = tslib_1.__classPrivateFieldGet(this, _ColorPicker_uiManager, "f").highlightColors; _i < _o.length; _i++) {
  17600. var _p = _o[_i], name = _p[0], color = _p[1];
  17601. var button = document.createElement("button");
  17602. button.tabIndex = "0";
  17603. button.role = "option";
  17604. button.setAttribute("data-color", color);
  17605. button.title = name;
  17606. button.setAttribute("data-l10n-id", "pdfjs-editor-colorpicker-".concat(name));
  17607. var swatch = document.createElement("span");
  17608. button.append(swatch);
  17609. swatch.className = "swatch";
  17610. swatch.style.backgroundColor = color;
  17611. button.setAttribute("aria-selected", color === tslib_1.__classPrivateFieldGet(this, _ColorPicker_defaultColor, "f"));
  17612. button.addEventListener("click", tslib_1.__classPrivateFieldGet(this, _ColorPicker_instances, "m", _ColorPicker_colorSelect).bind(this, color));
  17613. div.append(button);
  17614. }
  17615. div.addEventListener("keydown", tslib_1.__classPrivateFieldGet(this, _ColorPicker_boundKeyDown, "f"));
  17616. return div;
  17617. }, _ColorPicker_colorSelect = function _ColorPicker_colorSelect(color, event) {
  17618. event.stopPropagation();
  17619. tslib_1.__classPrivateFieldGet(this, _ColorPicker_eventBus, "f").dispatch("switchannotationeditorparams", {
  17620. source: this,
  17621. type: tslib_1.__classPrivateFieldGet(this, _ColorPicker_type, "f"),
  17622. value: color
  17623. });
  17624. }, _ColorPicker_keyDown = function _ColorPicker_keyDown(event) {
  17625. ColorPicker._keyboardManager.exec(this, event);
  17626. }, _ColorPicker_openDropdown = function _ColorPicker_openDropdown(event) {
  17627. if (tslib_1.__classPrivateFieldGet(this, _ColorPicker_instances, "a", _ColorPicker_isDropdownVisible_get)) {
  17628. this.hideDropdown();
  17629. return;
  17630. }
  17631. tslib_1.__classPrivateFieldSet(this, _ColorPicker_dropdownWasFromKeyboard, event.detail === 0, "f");
  17632. window.addEventListener("pointerdown", tslib_1.__classPrivateFieldGet(this, _ColorPicker_boundPointerDown, "f"));
  17633. if (tslib_1.__classPrivateFieldGet(this, _ColorPicker_dropdown, "f")) {
  17634. tslib_1.__classPrivateFieldGet(this, _ColorPicker_dropdown, "f").classList.remove("hidden");
  17635. return;
  17636. }
  17637. var root = tslib_1.__classPrivateFieldSet(this, _ColorPicker_dropdown, tslib_1.__classPrivateFieldGet(this, _ColorPicker_instances, "m", _ColorPicker_getDropdownRoot).call(this), "f");
  17638. tslib_1.__classPrivateFieldGet(this, _ColorPicker_button, "f").append(root);
  17639. }, _ColorPicker_pointerDown = function _ColorPicker_pointerDown(event) {
  17640. var _o;
  17641. if ((_o = tslib_1.__classPrivateFieldGet(this, _ColorPicker_dropdown, "f")) === null || _o === void 0 ? void 0 : _o.contains(event.target)) {
  17642. return;
  17643. }
  17644. this.hideDropdown();
  17645. }, _ColorPicker_isDropdownVisible_get = function _ColorPicker_isDropdownVisible_get() {
  17646. return tslib_1.__classPrivateFieldGet(this, _ColorPicker_dropdown, "f") && !tslib_1.__classPrivateFieldGet(this, _ColorPicker_dropdown, "f").classList.contains("hidden");
  17647. };
  17648. ; // CONCATENATED MODULE: ./src/display/editor/highlight.js
  17649. var HighlightEditor = /** @class */ (function (_super) {
  17650. tslib_1.__extends(HighlightEditor, _super);
  17651. function HighlightEditor(params) {
  17652. var _this = _super.call(this, tslib_1.__assign(tslib_1.__assign({}, params), { name: "highlightEditor" })) || this;
  17653. _HighlightEditor_instances.add(_this);
  17654. _HighlightEditor_anchorNode.set(_this, null);
  17655. _HighlightEditor_anchorOffset.set(_this, 0);
  17656. _HighlightEditor_boxes.set(_this, void 0);
  17657. _HighlightEditor_clipPathId.set(_this, null);
  17658. _HighlightEditor_colorPicker.set(_this, null);
  17659. _HighlightEditor_focusOutlines.set(_this, null);
  17660. _HighlightEditor_focusNode.set(_this, null);
  17661. _HighlightEditor_focusOffset.set(_this, 0);
  17662. _HighlightEditor_highlightDiv.set(_this, null);
  17663. _HighlightEditor_highlightOutlines.set(_this, null);
  17664. _HighlightEditor_id.set(_this, null);
  17665. _HighlightEditor_isFreeHighlight.set(_this, false);
  17666. _HighlightEditor_boundKeydown.set(_this, tslib_1.__classPrivateFieldGet(_this, _HighlightEditor_instances, "m", _HighlightEditor_keydown).bind(_this));
  17667. _HighlightEditor_lastPoint.set(_this, null);
  17668. _HighlightEditor_opacity.set(_this, void 0);
  17669. _HighlightEditor_outlineId.set(_this, null);
  17670. _HighlightEditor_text.set(_this, "");
  17671. _HighlightEditor_thickness.set(_this, void 0);
  17672. _HighlightEditor_methodOfCreation.set(_this, "");
  17673. _this.color = params.color || HighlightEditor._defaultColor;
  17674. tslib_1.__classPrivateFieldSet(_this, _HighlightEditor_thickness, params.thickness || HighlightEditor._defaultThickness, "f");
  17675. tslib_1.__classPrivateFieldSet(_this, _HighlightEditor_opacity, params.opacity || HighlightEditor._defaultOpacity, "f");
  17676. tslib_1.__classPrivateFieldSet(_this, _HighlightEditor_boxes, params.boxes || null, "f");
  17677. tslib_1.__classPrivateFieldSet(_this, _HighlightEditor_methodOfCreation, params.methodOfCreation || "", "f");
  17678. tslib_1.__classPrivateFieldSet(_this, _HighlightEditor_text, params.text || "", "f");
  17679. _this._isDraggable = false;
  17680. if (params.highlightId > -1) {
  17681. tslib_1.__classPrivateFieldSet(_this, _HighlightEditor_isFreeHighlight, true, "f");
  17682. tslib_1.__classPrivateFieldGet(_this, _HighlightEditor_instances, "m", _HighlightEditor_createFreeOutlines).call(_this, params);
  17683. tslib_1.__classPrivateFieldGet(_this, _HighlightEditor_instances, "m", _HighlightEditor_addToDrawLayer).call(_this);
  17684. }
  17685. else {
  17686. tslib_1.__classPrivateFieldSet(_this, _HighlightEditor_anchorNode, params.anchorNode, "f");
  17687. tslib_1.__classPrivateFieldSet(_this, _HighlightEditor_anchorOffset, params.anchorOffset, "f");
  17688. tslib_1.__classPrivateFieldSet(_this, _HighlightEditor_focusNode, params.focusNode, "f");
  17689. tslib_1.__classPrivateFieldSet(_this, _HighlightEditor_focusOffset, params.focusOffset, "f");
  17690. tslib_1.__classPrivateFieldGet(_this, _HighlightEditor_instances, "m", _HighlightEditor_createOutlines).call(_this);
  17691. tslib_1.__classPrivateFieldGet(_this, _HighlightEditor_instances, "m", _HighlightEditor_addToDrawLayer).call(_this);
  17692. _this.rotate(_this.rotation);
  17693. }
  17694. return _this;
  17695. }
  17696. Object.defineProperty(HighlightEditor, "_keyboardManager", {
  17697. get: function () {
  17698. var proto = HighlightEditor.prototype;
  17699. return shadow(this, "_keyboardManager", new KeyboardManager([[["ArrowLeft", "mac+ArrowLeft"], proto._moveCaret, {
  17700. args: [0]
  17701. }], [["ArrowRight", "mac+ArrowRight"], proto._moveCaret, {
  17702. args: [1]
  17703. }], [["ArrowUp", "mac+ArrowUp"], proto._moveCaret, {
  17704. args: [2]
  17705. }], [["ArrowDown", "mac+ArrowDown"], proto._moveCaret, {
  17706. args: [3]
  17707. }]]));
  17708. },
  17709. enumerable: false,
  17710. configurable: true
  17711. });
  17712. Object.defineProperty(HighlightEditor.prototype, "telemetryInitialData", {
  17713. get: function () {
  17714. return {
  17715. action: "added",
  17716. type: tslib_1.__classPrivateFieldGet(this, _HighlightEditor_isFreeHighlight, "f") ? "free_highlight" : "highlight",
  17717. color: this._uiManager.highlightColorNames.get(this.color),
  17718. thickness: tslib_1.__classPrivateFieldGet(this, _HighlightEditor_thickness, "f"),
  17719. methodOfCreation: tslib_1.__classPrivateFieldGet(this, _HighlightEditor_methodOfCreation, "f")
  17720. };
  17721. },
  17722. enumerable: false,
  17723. configurable: true
  17724. });
  17725. Object.defineProperty(HighlightEditor.prototype, "telemetryFinalData", {
  17726. get: function () {
  17727. return {
  17728. type: "highlight",
  17729. color: this._uiManager.highlightColorNames.get(this.color)
  17730. };
  17731. },
  17732. enumerable: false,
  17733. configurable: true
  17734. });
  17735. HighlightEditor.computeTelemetryFinalData = function (data) {
  17736. return {
  17737. numberOfColors: data.get("color").size
  17738. };
  17739. };
  17740. HighlightEditor.initialize = function (l10n, uiManager) {
  17741. var _p;
  17742. AnnotationEditor.initialize(l10n, uiManager);
  17743. HighlightEditor._defaultColor || (HighlightEditor._defaultColor = ((_p = uiManager.highlightColors) === null || _p === void 0 ? void 0 : _p.values().next().value) || "#fff066");
  17744. };
  17745. HighlightEditor.updateDefaultParams = function (type, value) {
  17746. switch (type) {
  17747. case AnnotationEditorParamsType.HIGHLIGHT_DEFAULT_COLOR:
  17748. HighlightEditor._defaultColor = value;
  17749. break;
  17750. case AnnotationEditorParamsType.HIGHLIGHT_THICKNESS:
  17751. HighlightEditor._defaultThickness = value;
  17752. break;
  17753. }
  17754. };
  17755. HighlightEditor.prototype.translateInPage = function (x, y) { };
  17756. Object.defineProperty(HighlightEditor.prototype, "toolbarPosition", {
  17757. get: function () {
  17758. return tslib_1.__classPrivateFieldGet(this, _HighlightEditor_lastPoint, "f");
  17759. },
  17760. enumerable: false,
  17761. configurable: true
  17762. });
  17763. HighlightEditor.prototype.updateParams = function (type, value) {
  17764. switch (type) {
  17765. case AnnotationEditorParamsType.HIGHLIGHT_COLOR:
  17766. tslib_1.__classPrivateFieldGet(this, _HighlightEditor_instances, "m", _HighlightEditor_updateColor).call(this, value);
  17767. break;
  17768. case AnnotationEditorParamsType.HIGHLIGHT_THICKNESS:
  17769. tslib_1.__classPrivateFieldGet(this, _HighlightEditor_instances, "m", _HighlightEditor_updateThickness).call(this, value);
  17770. break;
  17771. }
  17772. };
  17773. Object.defineProperty(HighlightEditor, "defaultPropertiesToUpdate", {
  17774. get: function () {
  17775. return [[AnnotationEditorParamsType.HIGHLIGHT_DEFAULT_COLOR, HighlightEditor._defaultColor], [AnnotationEditorParamsType.HIGHLIGHT_THICKNESS, HighlightEditor._defaultThickness]];
  17776. },
  17777. enumerable: false,
  17778. configurable: true
  17779. });
  17780. Object.defineProperty(HighlightEditor.prototype, "propertiesToUpdate", {
  17781. get: function () {
  17782. return [[AnnotationEditorParamsType.HIGHLIGHT_COLOR, this.color || HighlightEditor._defaultColor], [AnnotationEditorParamsType.HIGHLIGHT_THICKNESS, tslib_1.__classPrivateFieldGet(this, _HighlightEditor_thickness, "f") || HighlightEditor._defaultThickness], [AnnotationEditorParamsType.HIGHLIGHT_FREE, tslib_1.__classPrivateFieldGet(this, _HighlightEditor_isFreeHighlight, "f")]];
  17783. },
  17784. enumerable: false,
  17785. configurable: true
  17786. });
  17787. HighlightEditor.prototype.addEditToolbar = function () {
  17788. return tslib_1.__awaiter(this, void 0, void 0, function () {
  17789. var toolbar;
  17790. return tslib_1.__generator(this, function (_p) {
  17791. switch (_p.label) {
  17792. case 0: return [4 /*yield*/, _super.prototype.addEditToolbar.call(this)];
  17793. case 1:
  17794. toolbar = _p.sent();
  17795. if (!toolbar) {
  17796. return [2 /*return*/, null];
  17797. }
  17798. if (this._uiManager.highlightColors) {
  17799. tslib_1.__classPrivateFieldSet(this, _HighlightEditor_colorPicker, new ColorPicker({
  17800. editor: this
  17801. }), "f");
  17802. toolbar.addColorPicker(tslib_1.__classPrivateFieldGet(this, _HighlightEditor_colorPicker, "f"));
  17803. }
  17804. return [2 /*return*/, toolbar];
  17805. }
  17806. });
  17807. });
  17808. };
  17809. HighlightEditor.prototype.disableEditing = function () {
  17810. _super.prototype.disableEditing.call(this);
  17811. this.div.classList.toggle("disabled", true);
  17812. };
  17813. HighlightEditor.prototype.enableEditing = function () {
  17814. _super.prototype.enableEditing.call(this);
  17815. this.div.classList.toggle("disabled", false);
  17816. };
  17817. HighlightEditor.prototype.fixAndSetPosition = function () {
  17818. return _super.prototype.fixAndSetPosition.call(this, tslib_1.__classPrivateFieldGet(this, _HighlightEditor_instances, "m", _HighlightEditor_getRotation).call(this));
  17819. };
  17820. HighlightEditor.prototype.getBaseTranslation = function () {
  17821. return [0, 0];
  17822. };
  17823. HighlightEditor.prototype.getRect = function (tx, ty) {
  17824. return _super.prototype.getRect.call(this, tx, ty, tslib_1.__classPrivateFieldGet(this, _HighlightEditor_instances, "m", _HighlightEditor_getRotation).call(this));
  17825. };
  17826. HighlightEditor.prototype.onceAdded = function () {
  17827. this.parent.addUndoableEditor(this);
  17828. this.div.focus();
  17829. };
  17830. HighlightEditor.prototype.remove = function () {
  17831. tslib_1.__classPrivateFieldGet(this, _HighlightEditor_instances, "m", _HighlightEditor_cleanDrawLayer).call(this);
  17832. this._reportTelemetry({
  17833. action: "deleted"
  17834. });
  17835. _super.prototype.remove.call(this);
  17836. };
  17837. HighlightEditor.prototype.rebuild = function () {
  17838. if (!this.parent) {
  17839. return;
  17840. }
  17841. _super.prototype.rebuild.call(this);
  17842. if (this.div === null) {
  17843. return;
  17844. }
  17845. tslib_1.__classPrivateFieldGet(this, _HighlightEditor_instances, "m", _HighlightEditor_addToDrawLayer).call(this);
  17846. if (!this.isAttachedToDOM) {
  17847. this.parent.add(this);
  17848. }
  17849. };
  17850. HighlightEditor.prototype.setParent = function (parent) {
  17851. var _p;
  17852. var mustBeSelected = false;
  17853. if (this.parent && !parent) {
  17854. tslib_1.__classPrivateFieldGet(this, _HighlightEditor_instances, "m", _HighlightEditor_cleanDrawLayer).call(this);
  17855. }
  17856. else if (parent) {
  17857. tslib_1.__classPrivateFieldGet(this, _HighlightEditor_instances, "m", _HighlightEditor_addToDrawLayer).call(this, parent);
  17858. mustBeSelected = !this.parent && ((_p = this.div) === null || _p === void 0 ? void 0 : _p.classList.contains("selectedEditor"));
  17859. }
  17860. _super.prototype.setParent.call(this, parent);
  17861. this.show(this._isVisible);
  17862. if (mustBeSelected) {
  17863. this.select();
  17864. }
  17865. };
  17866. HighlightEditor.prototype.rotate = function (angle) {
  17867. var drawLayer = this.parent.drawLayer;
  17868. var box;
  17869. if (tslib_1.__classPrivateFieldGet(this, _HighlightEditor_isFreeHighlight, "f")) {
  17870. angle = (angle - this.rotation + 360) % 360;
  17871. box = tslib_1.__classPrivateFieldGet(HighlightEditor, _o, "m", _HighlightEditor_rotateBbox).call(HighlightEditor, tslib_1.__classPrivateFieldGet(this, _HighlightEditor_highlightOutlines, "f").box, angle);
  17872. }
  17873. else {
  17874. box = tslib_1.__classPrivateFieldGet(HighlightEditor, _o, "m", _HighlightEditor_rotateBbox).call(HighlightEditor, this, angle);
  17875. }
  17876. drawLayer.rotate(tslib_1.__classPrivateFieldGet(this, _HighlightEditor_id, "f"), angle);
  17877. drawLayer.rotate(tslib_1.__classPrivateFieldGet(this, _HighlightEditor_outlineId, "f"), angle);
  17878. drawLayer.updateBox(tslib_1.__classPrivateFieldGet(this, _HighlightEditor_id, "f"), box);
  17879. drawLayer.updateBox(tslib_1.__classPrivateFieldGet(this, _HighlightEditor_outlineId, "f"), tslib_1.__classPrivateFieldGet(HighlightEditor, _o, "m", _HighlightEditor_rotateBbox).call(HighlightEditor, tslib_1.__classPrivateFieldGet(this, _HighlightEditor_focusOutlines, "f").box, angle));
  17880. };
  17881. HighlightEditor.prototype.render = function () {
  17882. if (this.div) {
  17883. return this.div;
  17884. }
  17885. var div = _super.prototype.render.call(this);
  17886. if (tslib_1.__classPrivateFieldGet(this, _HighlightEditor_text, "f")) {
  17887. div.setAttribute("aria-label", tslib_1.__classPrivateFieldGet(this, _HighlightEditor_text, "f"));
  17888. div.setAttribute("role", "mark");
  17889. }
  17890. if (tslib_1.__classPrivateFieldGet(this, _HighlightEditor_isFreeHighlight, "f")) {
  17891. div.classList.add("free");
  17892. }
  17893. else {
  17894. this.div.addEventListener("keydown", tslib_1.__classPrivateFieldGet(this, _HighlightEditor_boundKeydown, "f"));
  17895. }
  17896. var highlightDiv = tslib_1.__classPrivateFieldSet(this, _HighlightEditor_highlightDiv, document.createElement("div"), "f");
  17897. div.append(highlightDiv);
  17898. highlightDiv.setAttribute("aria-hidden", "true");
  17899. highlightDiv.className = "internal";
  17900. highlightDiv.style.clipPath = tslib_1.__classPrivateFieldGet(this, _HighlightEditor_clipPathId, "f");
  17901. var _p = this.parentDimensions, parentWidth = _p[0], parentHeight = _p[1];
  17902. this.setDims(this.width * parentWidth, this.height * parentHeight);
  17903. bindEvents(this, tslib_1.__classPrivateFieldGet(this, _HighlightEditor_highlightDiv, "f"), ["pointerover", "pointerleave"]);
  17904. this.enableEditing();
  17905. return div;
  17906. };
  17907. HighlightEditor.prototype.pointerover = function () {
  17908. this.parent.drawLayer.addClass(tslib_1.__classPrivateFieldGet(this, _HighlightEditor_outlineId, "f"), "hovered");
  17909. };
  17910. HighlightEditor.prototype.pointerleave = function () {
  17911. this.parent.drawLayer.removeClass(tslib_1.__classPrivateFieldGet(this, _HighlightEditor_outlineId, "f"), "hovered");
  17912. };
  17913. HighlightEditor.prototype._moveCaret = function (direction) {
  17914. this.parent.unselect(this);
  17915. switch (direction) {
  17916. case 0:
  17917. case 2:
  17918. tslib_1.__classPrivateFieldGet(this, _HighlightEditor_instances, "m", _HighlightEditor_setCaret).call(this, true);
  17919. break;
  17920. case 1:
  17921. case 3:
  17922. tslib_1.__classPrivateFieldGet(this, _HighlightEditor_instances, "m", _HighlightEditor_setCaret).call(this, false);
  17923. break;
  17924. }
  17925. };
  17926. HighlightEditor.prototype.select = function () {
  17927. var _p, _q;
  17928. _super.prototype.select.call(this);
  17929. if (!tslib_1.__classPrivateFieldGet(this, _HighlightEditor_outlineId, "f")) {
  17930. return;
  17931. }
  17932. (_p = this.parent) === null || _p === void 0 ? void 0 : _p.drawLayer.removeClass(tslib_1.__classPrivateFieldGet(this, _HighlightEditor_outlineId, "f"), "hovered");
  17933. (_q = this.parent) === null || _q === void 0 ? void 0 : _q.drawLayer.addClass(tslib_1.__classPrivateFieldGet(this, _HighlightEditor_outlineId, "f"), "selected");
  17934. };
  17935. HighlightEditor.prototype.unselect = function () {
  17936. var _p;
  17937. _super.prototype.unselect.call(this);
  17938. if (!tslib_1.__classPrivateFieldGet(this, _HighlightEditor_outlineId, "f")) {
  17939. return;
  17940. }
  17941. (_p = this.parent) === null || _p === void 0 ? void 0 : _p.drawLayer.removeClass(tslib_1.__classPrivateFieldGet(this, _HighlightEditor_outlineId, "f"), "selected");
  17942. if (!tslib_1.__classPrivateFieldGet(this, _HighlightEditor_isFreeHighlight, "f")) {
  17943. tslib_1.__classPrivateFieldGet(this, _HighlightEditor_instances, "m", _HighlightEditor_setCaret).call(this, false);
  17944. }
  17945. };
  17946. Object.defineProperty(HighlightEditor.prototype, "_mustFixPosition", {
  17947. get: function () {
  17948. return !tslib_1.__classPrivateFieldGet(this, _HighlightEditor_isFreeHighlight, "f");
  17949. },
  17950. enumerable: false,
  17951. configurable: true
  17952. });
  17953. HighlightEditor.prototype.show = function (visible) {
  17954. if (visible === void 0) { visible = this._isVisible; }
  17955. _super.prototype.show.call(this, visible);
  17956. if (this.parent) {
  17957. this.parent.drawLayer.show(tslib_1.__classPrivateFieldGet(this, _HighlightEditor_id, "f"), visible);
  17958. this.parent.drawLayer.show(tslib_1.__classPrivateFieldGet(this, _HighlightEditor_outlineId, "f"), visible);
  17959. }
  17960. };
  17961. HighlightEditor.startHighlighting = function (parent, isLTR, _p) {
  17962. var _q;
  17963. var _this = this;
  17964. var textLayer = _p.target, x = _p.x, y = _p.y;
  17965. var _r = textLayer.getBoundingClientRect(), layerX = _r.x, layerY = _r.y, parentWidth = _r.width, parentHeight = _r.height;
  17966. var pointerMove = function (e) {
  17967. tslib_1.__classPrivateFieldGet(_this, _o, "m", _HighlightEditor_highlightMove).call(_this, parent, e);
  17968. };
  17969. var pointerDownOptions = {
  17970. capture: true,
  17971. passive: false
  17972. };
  17973. var pointerDown = function (e) {
  17974. e.preventDefault();
  17975. e.stopPropagation();
  17976. };
  17977. var pointerUpCallback = function (e) {
  17978. textLayer.removeEventListener("pointermove", pointerMove);
  17979. window.removeEventListener("blur", pointerUpCallback);
  17980. window.removeEventListener("pointerup", pointerUpCallback);
  17981. window.removeEventListener("pointerdown", pointerDown, pointerDownOptions);
  17982. window.removeEventListener("contextmenu", noContextMenu);
  17983. tslib_1.__classPrivateFieldGet(_this, _o, "m", _HighlightEditor_endHighlight).call(_this, parent, e);
  17984. };
  17985. window.addEventListener("blur", pointerUpCallback);
  17986. window.addEventListener("pointerup", pointerUpCallback);
  17987. window.addEventListener("pointerdown", pointerDown, pointerDownOptions);
  17988. window.addEventListener("contextmenu", noContextMenu);
  17989. textLayer.addEventListener("pointermove", pointerMove);
  17990. this._freeHighlight = new FreeOutliner({
  17991. x: x,
  17992. y: y
  17993. }, [layerX, layerY, parentWidth, parentHeight], parent.scale, this._defaultThickness / 2, isLTR, 0.001);
  17994. (_q = parent.drawLayer.highlight(this._freeHighlight, this._defaultColor, this._defaultOpacity, true), this._freeHighlightId = _q.id, this._freeHighlightClipId = _q.clipPathId);
  17995. };
  17996. HighlightEditor.deserialize = function (data, parent, uiManager) {
  17997. var editor = _super.deserialize.call(this, data, parent, uiManager);
  17998. var _p = data.rect, blX = _p[0], blY = _p[1], trX = _p[2], trY = _p[3], color = data.color, quadPoints = data.quadPoints;
  17999. editor.color = Util.makeHexColor.apply(Util, color);
  18000. tslib_1.__classPrivateFieldSet(editor, _HighlightEditor_opacity, data.opacity, "f");
  18001. var _q = editor.pageDimensions, pageWidth = _q[0], pageHeight = _q[1];
  18002. editor.width = (trX - blX) / pageWidth;
  18003. editor.height = (trY - blY) / pageHeight;
  18004. var boxes = tslib_1.__classPrivateFieldSet(editor, _HighlightEditor_boxes, [], "f");
  18005. for (var i = 0; i < quadPoints.length; i += 8) {
  18006. boxes.push({
  18007. x: (quadPoints[4] - trX) / pageWidth,
  18008. y: (trY - (1 - quadPoints[i + 5])) / pageHeight,
  18009. width: (quadPoints[i + 2] - quadPoints[i]) / pageWidth,
  18010. height: (quadPoints[i + 5] - quadPoints[i + 1]) / pageHeight
  18011. });
  18012. }
  18013. tslib_1.__classPrivateFieldGet(editor, _HighlightEditor_instances, "m", _HighlightEditor_createOutlines).call(editor);
  18014. return editor;
  18015. };
  18016. HighlightEditor.prototype.serialize = function (isForCopying) {
  18017. if (isForCopying === void 0) { isForCopying = false; }
  18018. if (this.isEmpty() || isForCopying) {
  18019. return null;
  18020. }
  18021. var rect = this.getRect(0, 0);
  18022. var color = AnnotationEditor._colorManager.convert(this.color);
  18023. return {
  18024. annotationType: AnnotationEditorType.HIGHLIGHT,
  18025. color: color,
  18026. opacity: tslib_1.__classPrivateFieldGet(this, _HighlightEditor_opacity, "f"),
  18027. thickness: tslib_1.__classPrivateFieldGet(this, _HighlightEditor_thickness, "f"),
  18028. quadPoints: tslib_1.__classPrivateFieldGet(this, _HighlightEditor_instances, "m", _HighlightEditor_serializeBoxes).call(this),
  18029. outlines: tslib_1.__classPrivateFieldGet(this, _HighlightEditor_instances, "m", _HighlightEditor_serializeOutlines).call(this, rect),
  18030. pageIndex: this.pageIndex,
  18031. rect: rect,
  18032. rotation: tslib_1.__classPrivateFieldGet(this, _HighlightEditor_instances, "m", _HighlightEditor_getRotation).call(this),
  18033. structTreeParentId: this._structTreeParentId
  18034. };
  18035. };
  18036. HighlightEditor.canCreateNewEmptyEditor = function () {
  18037. return false;
  18038. };
  18039. var _HighlightEditor_instances, _o, _HighlightEditor_anchorNode, _HighlightEditor_anchorOffset, _HighlightEditor_boxes, _HighlightEditor_clipPathId, _HighlightEditor_colorPicker, _HighlightEditor_focusOutlines, _HighlightEditor_focusNode, _HighlightEditor_focusOffset, _HighlightEditor_highlightDiv, _HighlightEditor_highlightOutlines, _HighlightEditor_id, _HighlightEditor_isFreeHighlight, _HighlightEditor_boundKeydown, _HighlightEditor_lastPoint, _HighlightEditor_opacity, _HighlightEditor_outlineId, _HighlightEditor_text, _HighlightEditor_thickness, _HighlightEditor_methodOfCreation, _HighlightEditor_createOutlines, _HighlightEditor_createFreeOutlines, _HighlightEditor_updateColor, _HighlightEditor_updateThickness, _HighlightEditor_changeThickness, _HighlightEditor_cleanDrawLayer, _HighlightEditor_addToDrawLayer, _HighlightEditor_rotateBbox, _HighlightEditor_keydown, _HighlightEditor_setCaret, _HighlightEditor_getRotation, _HighlightEditor_serializeBoxes, _HighlightEditor_serializeOutlines, _HighlightEditor_highlightMove, _HighlightEditor_endHighlight;
  18040. _o = HighlightEditor, _HighlightEditor_anchorNode = new WeakMap(), _HighlightEditor_anchorOffset = new WeakMap(), _HighlightEditor_boxes = new WeakMap(), _HighlightEditor_clipPathId = new WeakMap(), _HighlightEditor_colorPicker = new WeakMap(), _HighlightEditor_focusOutlines = new WeakMap(), _HighlightEditor_focusNode = new WeakMap(), _HighlightEditor_focusOffset = new WeakMap(), _HighlightEditor_highlightDiv = new WeakMap(), _HighlightEditor_highlightOutlines = new WeakMap(), _HighlightEditor_id = new WeakMap(), _HighlightEditor_isFreeHighlight = new WeakMap(), _HighlightEditor_boundKeydown = new WeakMap(), _HighlightEditor_lastPoint = new WeakMap(), _HighlightEditor_opacity = new WeakMap(), _HighlightEditor_outlineId = new WeakMap(), _HighlightEditor_text = new WeakMap(), _HighlightEditor_thickness = new WeakMap(), _HighlightEditor_methodOfCreation = new WeakMap(), _HighlightEditor_instances = new WeakSet(), _HighlightEditor_createOutlines = function _HighlightEditor_createOutlines() {
  18041. var _p;
  18042. var outliner = new Outliner(tslib_1.__classPrivateFieldGet(this, _HighlightEditor_boxes, "f"), 0.001);
  18043. tslib_1.__classPrivateFieldSet(this, _HighlightEditor_highlightOutlines, outliner.getOutlines(), "f");
  18044. (_p = tslib_1.__classPrivateFieldGet(this, _HighlightEditor_highlightOutlines, "f").box, this.x = _p.x, this.y = _p.y, this.width = _p.width, this.height = _p.height);
  18045. var outlinerForOutline = new Outliner(tslib_1.__classPrivateFieldGet(this, _HighlightEditor_boxes, "f"), 0.0025, 0.001, this._uiManager.direction === "ltr");
  18046. tslib_1.__classPrivateFieldSet(this, _HighlightEditor_focusOutlines, outlinerForOutline.getOutlines(), "f");
  18047. var lastPoint = tslib_1.__classPrivateFieldGet(this, _HighlightEditor_focusOutlines, "f").box.lastPoint;
  18048. tslib_1.__classPrivateFieldSet(this, _HighlightEditor_lastPoint, [(lastPoint[0] - this.x) / this.width, (lastPoint[1] - this.y) / this.height], "f");
  18049. }, _HighlightEditor_createFreeOutlines = function _HighlightEditor_createFreeOutlines(_p) {
  18050. var highlightOutlines = _p.highlightOutlines, highlightId = _p.highlightId, clipPathId = _p.clipPathId;
  18051. tslib_1.__classPrivateFieldSet(this, _HighlightEditor_highlightOutlines, highlightOutlines, "f");
  18052. var extraThickness = 1.5;
  18053. tslib_1.__classPrivateFieldSet(this, _HighlightEditor_focusOutlines, highlightOutlines.getNewOutline(tslib_1.__classPrivateFieldGet(this, _HighlightEditor_thickness, "f") / 2 + extraThickness, 0.0025), "f");
  18054. if (highlightId >= 0) {
  18055. tslib_1.__classPrivateFieldSet(this, _HighlightEditor_id, highlightId, "f");
  18056. tslib_1.__classPrivateFieldSet(this, _HighlightEditor_clipPathId, clipPathId, "f");
  18057. this.parent.drawLayer.finalizeLine(highlightId, highlightOutlines);
  18058. tslib_1.__classPrivateFieldSet(this, _HighlightEditor_outlineId, this.parent.drawLayer.highlightOutline(tslib_1.__classPrivateFieldGet(this, _HighlightEditor_focusOutlines, "f")), "f");
  18059. }
  18060. else if (this.parent) {
  18061. var angle = this.parent.viewport.rotation;
  18062. this.parent.drawLayer.updateLine(tslib_1.__classPrivateFieldGet(this, _HighlightEditor_id, "f"), highlightOutlines);
  18063. this.parent.drawLayer.updateBox(tslib_1.__classPrivateFieldGet(this, _HighlightEditor_id, "f"), tslib_1.__classPrivateFieldGet(HighlightEditor, _o, "m", _HighlightEditor_rotateBbox).call(HighlightEditor, tslib_1.__classPrivateFieldGet(this, _HighlightEditor_highlightOutlines, "f").box, (angle - this.rotation + 360) % 360));
  18064. this.parent.drawLayer.updateLine(tslib_1.__classPrivateFieldGet(this, _HighlightEditor_outlineId, "f"), tslib_1.__classPrivateFieldGet(this, _HighlightEditor_focusOutlines, "f"));
  18065. this.parent.drawLayer.updateBox(tslib_1.__classPrivateFieldGet(this, _HighlightEditor_outlineId, "f"), tslib_1.__classPrivateFieldGet(HighlightEditor, _o, "m", _HighlightEditor_rotateBbox).call(HighlightEditor, tslib_1.__classPrivateFieldGet(this, _HighlightEditor_focusOutlines, "f").box, angle));
  18066. }
  18067. var _q = highlightOutlines.box, x = _q.x, y = _q.y, width = _q.width, height = _q.height;
  18068. switch (this.rotation) {
  18069. case 0:
  18070. this.x = x;
  18071. this.y = y;
  18072. this.width = width;
  18073. this.height = height;
  18074. break;
  18075. case 90:
  18076. {
  18077. var _r = this.parentDimensions, pageWidth = _r[0], pageHeight = _r[1];
  18078. this.x = y;
  18079. this.y = 1 - x;
  18080. this.width = width * pageHeight / pageWidth;
  18081. this.height = height * pageWidth / pageHeight;
  18082. break;
  18083. }
  18084. case 180:
  18085. this.x = 1 - x;
  18086. this.y = 1 - y;
  18087. this.width = width;
  18088. this.height = height;
  18089. break;
  18090. case 270:
  18091. {
  18092. var _s = this.parentDimensions, pageWidth = _s[0], pageHeight = _s[1];
  18093. this.x = 1 - y;
  18094. this.y = x;
  18095. this.width = width * pageHeight / pageWidth;
  18096. this.height = height * pageWidth / pageHeight;
  18097. break;
  18098. }
  18099. }
  18100. var lastPoint = tslib_1.__classPrivateFieldGet(this, _HighlightEditor_focusOutlines, "f").box.lastPoint;
  18101. tslib_1.__classPrivateFieldSet(this, _HighlightEditor_lastPoint, [(lastPoint[0] - x) / width, (lastPoint[1] - y) / height], "f");
  18102. }, _HighlightEditor_updateColor = function _HighlightEditor_updateColor(color) {
  18103. var _this = this;
  18104. var setColor = function (col) {
  18105. var _p, _q;
  18106. _this.color = col;
  18107. (_p = _this.parent) === null || _p === void 0 ? void 0 : _p.drawLayer.changeColor(tslib_1.__classPrivateFieldGet(_this, _HighlightEditor_id, "f"), col);
  18108. (_q = tslib_1.__classPrivateFieldGet(_this, _HighlightEditor_colorPicker, "f")) === null || _q === void 0 ? void 0 : _q.updateColor(col);
  18109. };
  18110. var savedColor = this.color;
  18111. this.addCommands({
  18112. cmd: setColor.bind(this, color),
  18113. undo: setColor.bind(this, savedColor),
  18114. post: this._uiManager.updateUI.bind(this._uiManager, this),
  18115. mustExec: true,
  18116. type: AnnotationEditorParamsType.HIGHLIGHT_COLOR,
  18117. overwriteIfSameType: true,
  18118. keepUndo: true
  18119. });
  18120. this._reportTelemetry({
  18121. action: "color_changed",
  18122. color: this._uiManager.highlightColorNames.get(color)
  18123. }, true);
  18124. }, _HighlightEditor_updateThickness = function _HighlightEditor_updateThickness(thickness) {
  18125. var _this = this;
  18126. var savedThickness = tslib_1.__classPrivateFieldGet(this, _HighlightEditor_thickness, "f");
  18127. var setThickness = function (th) {
  18128. tslib_1.__classPrivateFieldSet(_this, _HighlightEditor_thickness, th, "f");
  18129. tslib_1.__classPrivateFieldGet(_this, _HighlightEditor_instances, "m", _HighlightEditor_changeThickness).call(_this, th);
  18130. };
  18131. this.addCommands({
  18132. cmd: setThickness.bind(this, thickness),
  18133. undo: setThickness.bind(this, savedThickness),
  18134. post: this._uiManager.updateUI.bind(this._uiManager, this),
  18135. mustExec: true,
  18136. type: AnnotationEditorParamsType.INK_THICKNESS,
  18137. overwriteIfSameType: true,
  18138. keepUndo: true
  18139. });
  18140. this._reportTelemetry({
  18141. action: "thickness_changed",
  18142. thickness: thickness
  18143. }, true);
  18144. }, _HighlightEditor_changeThickness = function _HighlightEditor_changeThickness(thickness) {
  18145. if (!tslib_1.__classPrivateFieldGet(this, _HighlightEditor_isFreeHighlight, "f")) {
  18146. return;
  18147. }
  18148. tslib_1.__classPrivateFieldGet(this, _HighlightEditor_instances, "m", _HighlightEditor_createFreeOutlines).call(this, {
  18149. highlightOutlines: tslib_1.__classPrivateFieldGet(this, _HighlightEditor_highlightOutlines, "f").getNewOutline(thickness / 2)
  18150. });
  18151. this.fixAndSetPosition();
  18152. var _p = this.parentDimensions, parentWidth = _p[0], parentHeight = _p[1];
  18153. this.setDims(this.width * parentWidth, this.height * parentHeight);
  18154. }, _HighlightEditor_cleanDrawLayer = function _HighlightEditor_cleanDrawLayer() {
  18155. if (tslib_1.__classPrivateFieldGet(this, _HighlightEditor_id, "f") === null || !this.parent) {
  18156. return;
  18157. }
  18158. this.parent.drawLayer.remove(tslib_1.__classPrivateFieldGet(this, _HighlightEditor_id, "f"));
  18159. tslib_1.__classPrivateFieldSet(this, _HighlightEditor_id, null, "f");
  18160. this.parent.drawLayer.remove(tslib_1.__classPrivateFieldGet(this, _HighlightEditor_outlineId, "f"));
  18161. tslib_1.__classPrivateFieldSet(this, _HighlightEditor_outlineId, null, "f");
  18162. }, _HighlightEditor_addToDrawLayer = function _HighlightEditor_addToDrawLayer(parent) {
  18163. var _p;
  18164. var _q, _r;
  18165. if (parent === void 0) { parent = this.parent; }
  18166. if (tslib_1.__classPrivateFieldGet(this, _HighlightEditor_id, "f") !== null) {
  18167. return;
  18168. }
  18169. (_q = this, _r = this, _p = parent.drawLayer.highlight(tslib_1.__classPrivateFieldGet(this, _HighlightEditor_highlightOutlines, "f"), this.color, tslib_1.__classPrivateFieldGet(this, _HighlightEditor_opacity, "f")), ({ set value(_a) { tslib_1.__classPrivateFieldSet(_q, _HighlightEditor_id, _a, "f"); } }).value = _p.id, ({ set value(_a) { tslib_1.__classPrivateFieldSet(_r, _HighlightEditor_clipPathId, _a, "f"); } }).value = _p.clipPathId);
  18170. tslib_1.__classPrivateFieldSet(this, _HighlightEditor_outlineId, parent.drawLayer.highlightOutline(tslib_1.__classPrivateFieldGet(this, _HighlightEditor_focusOutlines, "f")), "f");
  18171. if (tslib_1.__classPrivateFieldGet(this, _HighlightEditor_highlightDiv, "f")) {
  18172. tslib_1.__classPrivateFieldGet(this, _HighlightEditor_highlightDiv, "f").style.clipPath = tslib_1.__classPrivateFieldGet(this, _HighlightEditor_clipPathId, "f");
  18173. }
  18174. }, _HighlightEditor_rotateBbox = function _HighlightEditor_rotateBbox(_p, angle) {
  18175. var x = _p.x, y = _p.y, width = _p.width, height = _p.height;
  18176. switch (angle) {
  18177. case 90:
  18178. return {
  18179. x: 1 - y - height,
  18180. y: x,
  18181. width: height,
  18182. height: width
  18183. };
  18184. case 180:
  18185. return {
  18186. x: 1 - x - width,
  18187. y: 1 - y - height,
  18188. width: width,
  18189. height: height
  18190. };
  18191. case 270:
  18192. return {
  18193. x: y,
  18194. y: 1 - x - width,
  18195. width: height,
  18196. height: width
  18197. };
  18198. }
  18199. return {
  18200. x: x,
  18201. y: y,
  18202. width: width,
  18203. height: height
  18204. };
  18205. }, _HighlightEditor_keydown = function _HighlightEditor_keydown(event) {
  18206. HighlightEditor._keyboardManager.exec(this, event);
  18207. }, _HighlightEditor_setCaret = function _HighlightEditor_setCaret(start) {
  18208. if (!tslib_1.__classPrivateFieldGet(this, _HighlightEditor_anchorNode, "f")) {
  18209. return;
  18210. }
  18211. var selection = window.getSelection();
  18212. if (start) {
  18213. selection.setPosition(tslib_1.__classPrivateFieldGet(this, _HighlightEditor_anchorNode, "f"), tslib_1.__classPrivateFieldGet(this, _HighlightEditor_anchorOffset, "f"));
  18214. }
  18215. else {
  18216. selection.setPosition(tslib_1.__classPrivateFieldGet(this, _HighlightEditor_focusNode, "f"), tslib_1.__classPrivateFieldGet(this, _HighlightEditor_focusOffset, "f"));
  18217. }
  18218. }, _HighlightEditor_getRotation = function _HighlightEditor_getRotation() {
  18219. return tslib_1.__classPrivateFieldGet(this, _HighlightEditor_isFreeHighlight, "f") ? this.rotation : 0;
  18220. }, _HighlightEditor_serializeBoxes = function _HighlightEditor_serializeBoxes() {
  18221. if (tslib_1.__classPrivateFieldGet(this, _HighlightEditor_isFreeHighlight, "f")) {
  18222. return null;
  18223. }
  18224. var _p = this.pageDimensions, pageWidth = _p[0], pageHeight = _p[1];
  18225. var boxes = tslib_1.__classPrivateFieldGet(this, _HighlightEditor_boxes, "f");
  18226. var quadPoints = new Array(boxes.length * 8);
  18227. var i = 0;
  18228. for (var _i = 0, boxes_3 = boxes; _i < boxes_3.length; _i++) {
  18229. var _q = boxes_3[_i], x = _q.x, y = _q.y, width = _q.width, height = _q.height;
  18230. var sx = x * pageWidth;
  18231. var sy = (1 - y - height) * pageHeight;
  18232. quadPoints[i] = quadPoints[i + 4] = sx;
  18233. quadPoints[i + 1] = quadPoints[i + 3] = sy;
  18234. quadPoints[i + 2] = quadPoints[i + 6] = sx + width * pageWidth;
  18235. quadPoints[i + 5] = quadPoints[i + 7] = sy + height * pageHeight;
  18236. i += 8;
  18237. }
  18238. return quadPoints;
  18239. }, _HighlightEditor_serializeOutlines = function _HighlightEditor_serializeOutlines(rect) {
  18240. return tslib_1.__classPrivateFieldGet(this, _HighlightEditor_highlightOutlines, "f").serialize(rect, tslib_1.__classPrivateFieldGet(this, _HighlightEditor_instances, "m", _HighlightEditor_getRotation).call(this));
  18241. }, _HighlightEditor_highlightMove = function _HighlightEditor_highlightMove(parent, event) {
  18242. if (this._freeHighlight.add(event)) {
  18243. parent.drawLayer.updatePath(this._freeHighlightId, this._freeHighlight);
  18244. }
  18245. }, _HighlightEditor_endHighlight = function _HighlightEditor_endHighlight(parent, event) {
  18246. if (!this._freeHighlight.isEmpty()) {
  18247. parent.createAndAddNewEditor(event, false, {
  18248. highlightId: this._freeHighlightId,
  18249. highlightOutlines: this._freeHighlight.getOutlines(),
  18250. clipPathId: this._freeHighlightClipId,
  18251. methodOfCreation: "main_toolbar"
  18252. });
  18253. }
  18254. else {
  18255. parent.drawLayer.removeFreeHighlight(this._freeHighlightId);
  18256. }
  18257. this._freeHighlightId = -1;
  18258. this._freeHighlight = null;
  18259. this._freeHighlightClipId = "";
  18260. };
  18261. HighlightEditor._defaultColor = null;
  18262. HighlightEditor._defaultOpacity = 1;
  18263. HighlightEditor._defaultThickness = 12;
  18264. HighlightEditor._type = "highlight";
  18265. HighlightEditor._editorType = AnnotationEditorType.HIGHLIGHT;
  18266. HighlightEditor._freeHighlightId = -1;
  18267. HighlightEditor._freeHighlight = null;
  18268. HighlightEditor._freeHighlightClipId = "";
  18269. return HighlightEditor;
  18270. }(AnnotationEditor));
  18271. ; // CONCATENATED MODULE: ./src/display/editor/ink.js
  18272. var InkEditor = /** @class */ (function (_super) {
  18273. tslib_1.__extends(InkEditor, _super);
  18274. function InkEditor(params) {
  18275. var _this = _super.call(this, tslib_1.__assign(tslib_1.__assign({}, params), { name: "inkEditor" })) || this;
  18276. _InkEditor_instances.add(_this);
  18277. _InkEditor_baseHeight.set(_this, 0);
  18278. _InkEditor_baseWidth.set(_this, 0);
  18279. _InkEditor_boundCanvasPointermove.set(_this, _this.canvasPointermove.bind(_this));
  18280. _InkEditor_boundCanvasPointerleave.set(_this, _this.canvasPointerleave.bind(_this));
  18281. _InkEditor_boundCanvasPointerup.set(_this, _this.canvasPointerup.bind(_this));
  18282. _InkEditor_boundCanvasPointerdown.set(_this, _this.canvasPointerdown.bind(_this));
  18283. _InkEditor_canvasContextMenuTimeoutId.set(_this, null);
  18284. _InkEditor_currentPath2D.set(_this, new Path2D());
  18285. _InkEditor_disableEditing.set(_this, false);
  18286. _InkEditor_hasSomethingToDraw.set(_this, false);
  18287. _InkEditor_isCanvasInitialized.set(_this, false);
  18288. _InkEditor_observer.set(_this, null);
  18289. _InkEditor_realWidth.set(_this, 0);
  18290. _InkEditor_realHeight.set(_this, 0);
  18291. _InkEditor_requestFrameCallback.set(_this, null);
  18292. _this.color = params.color || null;
  18293. _this.thickness = params.thickness || null;
  18294. _this.opacity = params.opacity || null;
  18295. _this.paths = [];
  18296. _this.bezierPath2D = [];
  18297. _this.allRawPaths = [];
  18298. _this.currentPath = [];
  18299. _this.scaleFactor = 1;
  18300. _this.translationX = _this.translationY = 0;
  18301. _this.x = 0;
  18302. _this.y = 0;
  18303. _this._willKeepAspectRatio = true;
  18304. return _this;
  18305. }
  18306. InkEditor.initialize = function (l10n, uiManager) {
  18307. AnnotationEditor.initialize(l10n, uiManager);
  18308. };
  18309. InkEditor.updateDefaultParams = function (type, value) {
  18310. switch (type) {
  18311. case AnnotationEditorParamsType.INK_THICKNESS:
  18312. InkEditor._defaultThickness = value;
  18313. break;
  18314. case AnnotationEditorParamsType.INK_COLOR:
  18315. InkEditor._defaultColor = value;
  18316. break;
  18317. case AnnotationEditorParamsType.INK_OPACITY:
  18318. InkEditor._defaultOpacity = value / 100;
  18319. break;
  18320. }
  18321. };
  18322. InkEditor.prototype.updateParams = function (type, value) {
  18323. switch (type) {
  18324. case AnnotationEditorParamsType.INK_THICKNESS:
  18325. tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_updateThickness).call(this, value);
  18326. break;
  18327. case AnnotationEditorParamsType.INK_COLOR:
  18328. tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_updateColor).call(this, value);
  18329. break;
  18330. case AnnotationEditorParamsType.INK_OPACITY:
  18331. tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_updateOpacity).call(this, value);
  18332. break;
  18333. }
  18334. };
  18335. Object.defineProperty(InkEditor, "defaultPropertiesToUpdate", {
  18336. get: function () {
  18337. return [[AnnotationEditorParamsType.INK_THICKNESS, InkEditor._defaultThickness], [AnnotationEditorParamsType.INK_COLOR, InkEditor._defaultColor || AnnotationEditor._defaultLineColor], [AnnotationEditorParamsType.INK_OPACITY, Math.round(InkEditor._defaultOpacity * 100)]];
  18338. },
  18339. enumerable: false,
  18340. configurable: true
  18341. });
  18342. Object.defineProperty(InkEditor.prototype, "propertiesToUpdate", {
  18343. get: function () {
  18344. var _q;
  18345. return [[AnnotationEditorParamsType.INK_THICKNESS, this.thickness || InkEditor._defaultThickness], [AnnotationEditorParamsType.INK_COLOR, this.color || InkEditor._defaultColor || AnnotationEditor._defaultLineColor], [AnnotationEditorParamsType.INK_OPACITY, Math.round(100 * ((_q = this.opacity) !== null && _q !== void 0 ? _q : InkEditor._defaultOpacity))]];
  18346. },
  18347. enumerable: false,
  18348. configurable: true
  18349. });
  18350. InkEditor.prototype.rebuild = function () {
  18351. if (!this.parent) {
  18352. return;
  18353. }
  18354. _super.prototype.rebuild.call(this);
  18355. if (this.div === null) {
  18356. return;
  18357. }
  18358. if (!this.canvas) {
  18359. tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_createCanvas).call(this);
  18360. tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_createObserver).call(this);
  18361. }
  18362. if (!this.isAttachedToDOM) {
  18363. this.parent.add(this);
  18364. tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_setCanvasDims).call(this);
  18365. }
  18366. tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_fitToContent).call(this);
  18367. };
  18368. InkEditor.prototype.remove = function () {
  18369. if (this.canvas === null) {
  18370. return;
  18371. }
  18372. if (!this.isEmpty()) {
  18373. this.commit();
  18374. }
  18375. this.canvas.width = this.canvas.height = 0;
  18376. this.canvas.remove();
  18377. this.canvas = null;
  18378. if (tslib_1.__classPrivateFieldGet(this, _InkEditor_canvasContextMenuTimeoutId, "f")) {
  18379. clearTimeout(tslib_1.__classPrivateFieldGet(this, _InkEditor_canvasContextMenuTimeoutId, "f"));
  18380. tslib_1.__classPrivateFieldSet(this, _InkEditor_canvasContextMenuTimeoutId, null, "f");
  18381. }
  18382. tslib_1.__classPrivateFieldGet(this, _InkEditor_observer, "f").disconnect();
  18383. tslib_1.__classPrivateFieldSet(this, _InkEditor_observer, null, "f");
  18384. _super.prototype.remove.call(this);
  18385. };
  18386. InkEditor.prototype.setParent = function (parent) {
  18387. if (!this.parent && parent) {
  18388. this._uiManager.removeShouldRescale(this);
  18389. }
  18390. else if (this.parent && parent === null) {
  18391. this._uiManager.addShouldRescale(this);
  18392. }
  18393. _super.prototype.setParent.call(this, parent);
  18394. };
  18395. InkEditor.prototype.onScaleChanging = function () {
  18396. var _q = this.parentDimensions, parentWidth = _q[0], parentHeight = _q[1];
  18397. var width = this.width * parentWidth;
  18398. var height = this.height * parentHeight;
  18399. this.setDimensions(width, height);
  18400. };
  18401. InkEditor.prototype.enableEditMode = function () {
  18402. if (tslib_1.__classPrivateFieldGet(this, _InkEditor_disableEditing, "f") || this.canvas === null) {
  18403. return;
  18404. }
  18405. _super.prototype.enableEditMode.call(this);
  18406. this._isDraggable = false;
  18407. this.canvas.addEventListener("pointerdown", tslib_1.__classPrivateFieldGet(this, _InkEditor_boundCanvasPointerdown, "f"));
  18408. };
  18409. InkEditor.prototype.disableEditMode = function () {
  18410. if (!this.isInEditMode() || this.canvas === null) {
  18411. return;
  18412. }
  18413. _super.prototype.disableEditMode.call(this);
  18414. this._isDraggable = !this.isEmpty();
  18415. this.div.classList.remove("editing");
  18416. this.canvas.removeEventListener("pointerdown", tslib_1.__classPrivateFieldGet(this, _InkEditor_boundCanvasPointerdown, "f"));
  18417. };
  18418. InkEditor.prototype.onceAdded = function () {
  18419. this._isDraggable = !this.isEmpty();
  18420. };
  18421. InkEditor.prototype.isEmpty = function () {
  18422. return this.paths.length === 0 || this.paths.length === 1 && this.paths[0].length === 0;
  18423. };
  18424. InkEditor.prototype.commit = function () {
  18425. if (tslib_1.__classPrivateFieldGet(this, _InkEditor_disableEditing, "f")) {
  18426. return;
  18427. }
  18428. _super.prototype.commit.call(this);
  18429. this.isEditing = false;
  18430. this.disableEditMode();
  18431. this.setInForeground();
  18432. tslib_1.__classPrivateFieldSet(this, _InkEditor_disableEditing, true, "f");
  18433. this.div.classList.add("disabled");
  18434. tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_fitToContent).call(this, true);
  18435. this.select();
  18436. this.parent.addInkEditorIfNeeded(true);
  18437. this.moveInDOM();
  18438. this.div.focus({
  18439. preventScroll: true
  18440. });
  18441. };
  18442. InkEditor.prototype.focusin = function (event) {
  18443. if (!this._focusEventsAllowed) {
  18444. return;
  18445. }
  18446. _super.prototype.focusin.call(this, event);
  18447. this.enableEditMode();
  18448. };
  18449. InkEditor.prototype.canvasPointerdown = function (event) {
  18450. if (event.button !== 0 || !this.isInEditMode() || tslib_1.__classPrivateFieldGet(this, _InkEditor_disableEditing, "f")) {
  18451. return;
  18452. }
  18453. this.setInForeground();
  18454. event.preventDefault();
  18455. if (!this.div.contains(document.activeElement)) {
  18456. this.div.focus({
  18457. preventScroll: true
  18458. });
  18459. }
  18460. tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_startDrawing).call(this, event.offsetX, event.offsetY);
  18461. };
  18462. InkEditor.prototype.canvasPointermove = function (event) {
  18463. event.preventDefault();
  18464. tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_draw).call(this, event.offsetX, event.offsetY);
  18465. };
  18466. InkEditor.prototype.canvasPointerup = function (event) {
  18467. event.preventDefault();
  18468. tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_endDrawing).call(this, event);
  18469. };
  18470. InkEditor.prototype.canvasPointerleave = function (event) {
  18471. tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_endDrawing).call(this, event);
  18472. };
  18473. Object.defineProperty(InkEditor.prototype, "isResizable", {
  18474. get: function () {
  18475. return !this.isEmpty() && tslib_1.__classPrivateFieldGet(this, _InkEditor_disableEditing, "f");
  18476. },
  18477. enumerable: false,
  18478. configurable: true
  18479. });
  18480. InkEditor.prototype.render = function () {
  18481. if (this.div) {
  18482. return this.div;
  18483. }
  18484. var baseX, baseY;
  18485. if (this.width) {
  18486. baseX = this.x;
  18487. baseY = this.y;
  18488. }
  18489. _super.prototype.render.call(this);
  18490. this.div.setAttribute("data-l10n-id", "pdfjs-ink");
  18491. var _q = tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_getInitialBBox).call(this), x = _q[0], y = _q[1], w = _q[2], h = _q[3];
  18492. this.setAt(x, y, 0, 0);
  18493. this.setDims(w, h);
  18494. tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_createCanvas).call(this);
  18495. if (this.width) {
  18496. var _r = this.parentDimensions, parentWidth = _r[0], parentHeight = _r[1];
  18497. this.setAspectRatio(this.width * parentWidth, this.height * parentHeight);
  18498. this.setAt(baseX * parentWidth, baseY * parentHeight, this.width * parentWidth, this.height * parentHeight);
  18499. tslib_1.__classPrivateFieldSet(this, _InkEditor_isCanvasInitialized, true, "f");
  18500. tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_setCanvasDims).call(this);
  18501. this.setDims(this.width * parentWidth, this.height * parentHeight);
  18502. tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_redraw).call(this);
  18503. this.div.classList.add("disabled");
  18504. }
  18505. else {
  18506. this.div.classList.add("editing");
  18507. this.enableEditMode();
  18508. }
  18509. tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_createObserver).call(this);
  18510. return this.div;
  18511. };
  18512. InkEditor.prototype.setDimensions = function (width, height) {
  18513. var roundedWidth = Math.round(width);
  18514. var roundedHeight = Math.round(height);
  18515. if (tslib_1.__classPrivateFieldGet(this, _InkEditor_realWidth, "f") === roundedWidth && tslib_1.__classPrivateFieldGet(this, _InkEditor_realHeight, "f") === roundedHeight) {
  18516. return;
  18517. }
  18518. tslib_1.__classPrivateFieldSet(this, _InkEditor_realWidth, roundedWidth, "f");
  18519. tslib_1.__classPrivateFieldSet(this, _InkEditor_realHeight, roundedHeight, "f");
  18520. this.canvas.style.visibility = "hidden";
  18521. var _q = this.parentDimensions, parentWidth = _q[0], parentHeight = _q[1];
  18522. this.width = width / parentWidth;
  18523. this.height = height / parentHeight;
  18524. this.fixAndSetPosition();
  18525. if (tslib_1.__classPrivateFieldGet(this, _InkEditor_disableEditing, "f")) {
  18526. tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_setScaleFactor).call(this, width, height);
  18527. }
  18528. tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_setCanvasDims).call(this);
  18529. tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_redraw).call(this);
  18530. this.canvas.style.visibility = "visible";
  18531. this.fixDims();
  18532. };
  18533. InkEditor.deserialize = function (data, parent, uiManager) {
  18534. if (data instanceof InkAnnotationElement) {
  18535. return null;
  18536. }
  18537. var editor = _super.deserialize.call(this, data, parent, uiManager);
  18538. editor.thickness = data.thickness;
  18539. editor.color = Util.makeHexColor.apply(Util, data.color);
  18540. editor.opacity = data.opacity;
  18541. var _q = editor.pageDimensions, pageWidth = _q[0], pageHeight = _q[1];
  18542. var width = editor.width * pageWidth;
  18543. var height = editor.height * pageHeight;
  18544. var scaleFactor = editor.parentScale;
  18545. var padding = data.thickness / 2;
  18546. tslib_1.__classPrivateFieldSet(editor, _InkEditor_disableEditing, true, "f");
  18547. tslib_1.__classPrivateFieldSet(editor, _InkEditor_realWidth, Math.round(width), "f");
  18548. tslib_1.__classPrivateFieldSet(editor, _InkEditor_realHeight, Math.round(height), "f");
  18549. var paths = data.paths, rect = data.rect, rotation = data.rotation;
  18550. for (var _i = 0, paths_2 = paths; _i < paths_2.length; _i++) {
  18551. var bezier = paths_2[_i].bezier;
  18552. bezier = tslib_1.__classPrivateFieldGet(InkEditor, _p, "m", _InkEditor_fromPDFCoordinates).call(InkEditor, bezier, rect, rotation);
  18553. var path = [];
  18554. editor.paths.push(path);
  18555. var p0 = scaleFactor * (bezier[0] - padding);
  18556. var p1 = scaleFactor * (bezier[1] - padding);
  18557. for (var i = 2, ii = bezier.length; i < ii; i += 6) {
  18558. var p10 = scaleFactor * (bezier[i] - padding);
  18559. var p11 = scaleFactor * (bezier[i + 1] - padding);
  18560. var p20 = scaleFactor * (bezier[i + 2] - padding);
  18561. var p21 = scaleFactor * (bezier[i + 3] - padding);
  18562. var p30 = scaleFactor * (bezier[i + 4] - padding);
  18563. var p31 = scaleFactor * (bezier[i + 5] - padding);
  18564. path.push([[p0, p1], [p10, p11], [p20, p21], [p30, p31]]);
  18565. p0 = p30;
  18566. p1 = p31;
  18567. }
  18568. var path2D = tslib_1.__classPrivateFieldGet(this, _p, "m", _InkEditor_buildPath2D).call(this, path);
  18569. editor.bezierPath2D.push(path2D);
  18570. }
  18571. var bbox = tslib_1.__classPrivateFieldGet(editor, _InkEditor_instances, "m", _InkEditor_getBbox).call(editor);
  18572. tslib_1.__classPrivateFieldSet(editor, _InkEditor_baseWidth, Math.max(AnnotationEditor.MIN_SIZE, bbox[2] - bbox[0]), "f");
  18573. tslib_1.__classPrivateFieldSet(editor, _InkEditor_baseHeight, Math.max(AnnotationEditor.MIN_SIZE, bbox[3] - bbox[1]), "f");
  18574. tslib_1.__classPrivateFieldGet(editor, _InkEditor_instances, "m", _InkEditor_setScaleFactor).call(editor, width, height);
  18575. return editor;
  18576. };
  18577. InkEditor.prototype.serialize = function () {
  18578. if (this.isEmpty()) {
  18579. return null;
  18580. }
  18581. var rect = this.getRect(0, 0);
  18582. var color = AnnotationEditor._colorManager.convert(this.ctx.strokeStyle);
  18583. return {
  18584. annotationType: AnnotationEditorType.INK,
  18585. color: color,
  18586. thickness: this.thickness,
  18587. opacity: this.opacity,
  18588. paths: tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_serializePaths).call(this, this.scaleFactor / this.parentScale, this.translationX, this.translationY, rect),
  18589. pageIndex: this.pageIndex,
  18590. rect: rect,
  18591. rotation: this.rotation,
  18592. structTreeParentId: this._structTreeParentId
  18593. };
  18594. };
  18595. var _InkEditor_instances, _p, _InkEditor_baseHeight, _InkEditor_baseWidth, _InkEditor_boundCanvasPointermove, _InkEditor_boundCanvasPointerleave, _InkEditor_boundCanvasPointerup, _InkEditor_boundCanvasPointerdown, _InkEditor_canvasContextMenuTimeoutId, _InkEditor_currentPath2D, _InkEditor_disableEditing, _InkEditor_hasSomethingToDraw, _InkEditor_isCanvasInitialized, _InkEditor_observer, _InkEditor_realWidth, _InkEditor_realHeight, _InkEditor_requestFrameCallback, _InkEditor_updateThickness, _InkEditor_updateColor, _InkEditor_updateOpacity, _InkEditor_getInitialBBox, _InkEditor_setStroke, _InkEditor_startDrawing, _InkEditor_draw, _InkEditor_endPath, _InkEditor_stopDrawing, _InkEditor_drawPoints, _InkEditor_makeBezierCurve, _InkEditor_generateBezierPoints, _InkEditor_redraw, _InkEditor_endDrawing, _InkEditor_createCanvas, _InkEditor_createObserver, _InkEditor_setCanvasDims, _InkEditor_setScaleFactor, _InkEditor_updateTransform, _InkEditor_buildPath2D, _InkEditor_toPDFCoordinates, _InkEditor_fromPDFCoordinates, _InkEditor_serializePaths, _InkEditor_getBbox, _InkEditor_getPadding, _InkEditor_fitToContent;
  18596. _p = InkEditor, _InkEditor_baseHeight = new WeakMap(), _InkEditor_baseWidth = new WeakMap(), _InkEditor_boundCanvasPointermove = new WeakMap(), _InkEditor_boundCanvasPointerleave = new WeakMap(), _InkEditor_boundCanvasPointerup = new WeakMap(), _InkEditor_boundCanvasPointerdown = new WeakMap(), _InkEditor_canvasContextMenuTimeoutId = new WeakMap(), _InkEditor_currentPath2D = new WeakMap(), _InkEditor_disableEditing = new WeakMap(), _InkEditor_hasSomethingToDraw = new WeakMap(), _InkEditor_isCanvasInitialized = new WeakMap(), _InkEditor_observer = new WeakMap(), _InkEditor_realWidth = new WeakMap(), _InkEditor_realHeight = new WeakMap(), _InkEditor_requestFrameCallback = new WeakMap(), _InkEditor_instances = new WeakSet(), _InkEditor_updateThickness = function _InkEditor_updateThickness(thickness) {
  18597. var _this = this;
  18598. var setThickness = function (th) {
  18599. _this.thickness = th;
  18600. tslib_1.__classPrivateFieldGet(_this, _InkEditor_instances, "m", _InkEditor_fitToContent).call(_this);
  18601. };
  18602. var savedThickness = this.thickness;
  18603. this.addCommands({
  18604. cmd: setThickness.bind(this, thickness),
  18605. undo: setThickness.bind(this, savedThickness),
  18606. post: this._uiManager.updateUI.bind(this._uiManager, this),
  18607. mustExec: true,
  18608. type: AnnotationEditorParamsType.INK_THICKNESS,
  18609. overwriteIfSameType: true,
  18610. keepUndo: true
  18611. });
  18612. }, _InkEditor_updateColor = function _InkEditor_updateColor(color) {
  18613. var _this = this;
  18614. var setColor = function (col) {
  18615. _this.color = col;
  18616. tslib_1.__classPrivateFieldGet(_this, _InkEditor_instances, "m", _InkEditor_redraw).call(_this);
  18617. };
  18618. var savedColor = this.color;
  18619. this.addCommands({
  18620. cmd: setColor.bind(this, color),
  18621. undo: setColor.bind(this, savedColor),
  18622. post: this._uiManager.updateUI.bind(this._uiManager, this),
  18623. mustExec: true,
  18624. type: AnnotationEditorParamsType.INK_COLOR,
  18625. overwriteIfSameType: true,
  18626. keepUndo: true
  18627. });
  18628. }, _InkEditor_updateOpacity = function _InkEditor_updateOpacity(opacity) {
  18629. var _this = this;
  18630. var setOpacity = function (op) {
  18631. _this.opacity = op;
  18632. tslib_1.__classPrivateFieldGet(_this, _InkEditor_instances, "m", _InkEditor_redraw).call(_this);
  18633. };
  18634. opacity /= 100;
  18635. var savedOpacity = this.opacity;
  18636. this.addCommands({
  18637. cmd: setOpacity.bind(this, opacity),
  18638. undo: setOpacity.bind(this, savedOpacity),
  18639. post: this._uiManager.updateUI.bind(this._uiManager, this),
  18640. mustExec: true,
  18641. type: AnnotationEditorParamsType.INK_OPACITY,
  18642. overwriteIfSameType: true,
  18643. keepUndo: true
  18644. });
  18645. }, _InkEditor_getInitialBBox = function _InkEditor_getInitialBBox() {
  18646. var _q = this, parentRotation = _q.parentRotation, _r = _q.parentDimensions, width = _r[0], height = _r[1];
  18647. switch (parentRotation) {
  18648. case 90:
  18649. return [0, height, height, width];
  18650. case 180:
  18651. return [width, height, width, height];
  18652. case 270:
  18653. return [width, 0, height, width];
  18654. default:
  18655. return [0, 0, width, height];
  18656. }
  18657. }, _InkEditor_setStroke = function _InkEditor_setStroke() {
  18658. var _q = this, ctx = _q.ctx, color = _q.color, opacity = _q.opacity, thickness = _q.thickness, parentScale = _q.parentScale, scaleFactor = _q.scaleFactor;
  18659. ctx.lineWidth = thickness * parentScale / scaleFactor;
  18660. ctx.lineCap = "round";
  18661. ctx.lineJoin = "round";
  18662. ctx.miterLimit = 10;
  18663. ctx.strokeStyle = "".concat(color).concat(opacityToHex(opacity));
  18664. }, _InkEditor_startDrawing = function _InkEditor_startDrawing(x, y) {
  18665. var _this = this;
  18666. var _q;
  18667. this.canvas.addEventListener("contextmenu", noContextMenu);
  18668. this.canvas.addEventListener("pointerleave", tslib_1.__classPrivateFieldGet(this, _InkEditor_boundCanvasPointerleave, "f"));
  18669. this.canvas.addEventListener("pointermove", tslib_1.__classPrivateFieldGet(this, _InkEditor_boundCanvasPointermove, "f"));
  18670. this.canvas.addEventListener("pointerup", tslib_1.__classPrivateFieldGet(this, _InkEditor_boundCanvasPointerup, "f"));
  18671. this.canvas.removeEventListener("pointerdown", tslib_1.__classPrivateFieldGet(this, _InkEditor_boundCanvasPointerdown, "f"));
  18672. this.isEditing = true;
  18673. if (!tslib_1.__classPrivateFieldGet(this, _InkEditor_isCanvasInitialized, "f")) {
  18674. tslib_1.__classPrivateFieldSet(this, _InkEditor_isCanvasInitialized, true, "f");
  18675. tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_setCanvasDims).call(this);
  18676. this.thickness || (this.thickness = InkEditor._defaultThickness);
  18677. this.color || (this.color = InkEditor._defaultColor || AnnotationEditor._defaultLineColor);
  18678. (_q = this.opacity) !== null && _q !== void 0 ? _q : (this.opacity = InkEditor._defaultOpacity);
  18679. }
  18680. this.currentPath.push([x, y]);
  18681. tslib_1.__classPrivateFieldSet(this, _InkEditor_hasSomethingToDraw, false, "f");
  18682. tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_setStroke).call(this);
  18683. tslib_1.__classPrivateFieldSet(this, _InkEditor_requestFrameCallback, function () {
  18684. tslib_1.__classPrivateFieldGet(_this, _InkEditor_instances, "m", _InkEditor_drawPoints).call(_this);
  18685. if (tslib_1.__classPrivateFieldGet(_this, _InkEditor_requestFrameCallback, "f")) {
  18686. window.requestAnimationFrame(tslib_1.__classPrivateFieldGet(_this, _InkEditor_requestFrameCallback, "f"));
  18687. }
  18688. }, "f");
  18689. window.requestAnimationFrame(tslib_1.__classPrivateFieldGet(this, _InkEditor_requestFrameCallback, "f"));
  18690. }, _InkEditor_draw = function _InkEditor_draw(x, y) {
  18691. var _q;
  18692. var _r = this.currentPath.at(-1), lastX = _r[0], lastY = _r[1];
  18693. if (this.currentPath.length > 1 && x === lastX && y === lastY) {
  18694. return;
  18695. }
  18696. var currentPath = this.currentPath;
  18697. var path2D = tslib_1.__classPrivateFieldGet(this, _InkEditor_currentPath2D, "f");
  18698. currentPath.push([x, y]);
  18699. tslib_1.__classPrivateFieldSet(this, _InkEditor_hasSomethingToDraw, true, "f");
  18700. if (currentPath.length <= 2) {
  18701. path2D.moveTo.apply(path2D, currentPath[0]);
  18702. path2D.lineTo(x, y);
  18703. return;
  18704. }
  18705. if (currentPath.length === 3) {
  18706. tslib_1.__classPrivateFieldSet(this, _InkEditor_currentPath2D, path2D = new Path2D(), "f");
  18707. path2D.moveTo.apply(path2D, currentPath[0]);
  18708. }
  18709. (_q = tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_makeBezierCurve)).call.apply(_q, tslib_1.__spreadArray(tslib_1.__spreadArray(tslib_1.__spreadArray([this, path2D], currentPath.at(-3), false), currentPath.at(-2), false), [x, y], false));
  18710. }, _InkEditor_endPath = function _InkEditor_endPath() {
  18711. var _q;
  18712. if (this.currentPath.length === 0) {
  18713. return;
  18714. }
  18715. var lastPoint = this.currentPath.at(-1);
  18716. (_q = tslib_1.__classPrivateFieldGet(this, _InkEditor_currentPath2D, "f")).lineTo.apply(_q, lastPoint);
  18717. }, _InkEditor_stopDrawing = function _InkEditor_stopDrawing(x, y) {
  18718. var _this = this;
  18719. tslib_1.__classPrivateFieldSet(this, _InkEditor_requestFrameCallback, null, "f");
  18720. x = Math.min(Math.max(x, 0), this.canvas.width);
  18721. y = Math.min(Math.max(y, 0), this.canvas.height);
  18722. tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_draw).call(this, x, y);
  18723. tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_endPath).call(this);
  18724. var bezier;
  18725. if (this.currentPath.length !== 1) {
  18726. bezier = tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_generateBezierPoints).call(this);
  18727. }
  18728. else {
  18729. var xy = [x, y];
  18730. bezier = [[xy, xy.slice(), xy.slice(), xy]];
  18731. }
  18732. var path2D = tslib_1.__classPrivateFieldGet(this, _InkEditor_currentPath2D, "f");
  18733. var currentPath = this.currentPath;
  18734. this.currentPath = [];
  18735. tslib_1.__classPrivateFieldSet(this, _InkEditor_currentPath2D, new Path2D(), "f");
  18736. var cmd = function () {
  18737. _this.allRawPaths.push(currentPath);
  18738. _this.paths.push(bezier);
  18739. _this.bezierPath2D.push(path2D);
  18740. _this._uiManager.rebuild(_this);
  18741. };
  18742. var undo = function () {
  18743. _this.allRawPaths.pop();
  18744. _this.paths.pop();
  18745. _this.bezierPath2D.pop();
  18746. if (_this.paths.length === 0) {
  18747. _this.remove();
  18748. }
  18749. else {
  18750. if (!_this.canvas) {
  18751. tslib_1.__classPrivateFieldGet(_this, _InkEditor_instances, "m", _InkEditor_createCanvas).call(_this);
  18752. tslib_1.__classPrivateFieldGet(_this, _InkEditor_instances, "m", _InkEditor_createObserver).call(_this);
  18753. }
  18754. tslib_1.__classPrivateFieldGet(_this, _InkEditor_instances, "m", _InkEditor_fitToContent).call(_this);
  18755. }
  18756. };
  18757. this.addCommands({
  18758. cmd: cmd,
  18759. undo: undo,
  18760. mustExec: true
  18761. });
  18762. }, _InkEditor_drawPoints = function _InkEditor_drawPoints() {
  18763. if (!tslib_1.__classPrivateFieldGet(this, _InkEditor_hasSomethingToDraw, "f")) {
  18764. return;
  18765. }
  18766. tslib_1.__classPrivateFieldSet(this, _InkEditor_hasSomethingToDraw, false, "f");
  18767. var thickness = Math.ceil(this.thickness * this.parentScale);
  18768. var lastPoints = this.currentPath.slice(-3);
  18769. var x = lastPoints.map(function (xy) { return xy[0]; });
  18770. var y = lastPoints.map(function (xy) { return xy[1]; });
  18771. var xMin = Math.min.apply(Math, x) - thickness;
  18772. var xMax = Math.max.apply(Math, x) + thickness;
  18773. var yMin = Math.min.apply(Math, y) - thickness;
  18774. var yMax = Math.max.apply(Math, y) + thickness;
  18775. var ctx = this.ctx;
  18776. ctx.save();
  18777. ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
  18778. for (var _i = 0, _q = this.bezierPath2D; _i < _q.length; _i++) {
  18779. var path = _q[_i];
  18780. ctx.stroke(path);
  18781. }
  18782. ctx.stroke(tslib_1.__classPrivateFieldGet(this, _InkEditor_currentPath2D, "f"));
  18783. ctx.restore();
  18784. }, _InkEditor_makeBezierCurve = function _InkEditor_makeBezierCurve(path2D, x0, y0, x1, y1, x2, y2) {
  18785. var prevX = (x0 + x1) / 2;
  18786. var prevY = (y0 + y1) / 2;
  18787. var x3 = (x1 + x2) / 2;
  18788. var y3 = (y1 + y2) / 2;
  18789. path2D.bezierCurveTo(prevX + 2 * (x1 - prevX) / 3, prevY + 2 * (y1 - prevY) / 3, x3 + 2 * (x1 - x3) / 3, y3 + 2 * (y1 - y3) / 3, x3, y3);
  18790. }, _InkEditor_generateBezierPoints = function _InkEditor_generateBezierPoints() {
  18791. var _q;
  18792. var path = this.currentPath;
  18793. if (path.length <= 2) {
  18794. return [[path[0], path[0], path.at(-1), path.at(-1)]];
  18795. }
  18796. var bezierPoints = [];
  18797. var i;
  18798. var _r = path[0], x0 = _r[0], y0 = _r[1];
  18799. for (i = 1; i < path.length - 2; i++) {
  18800. var _s = path[i], x1_1 = _s[0], y1_1 = _s[1];
  18801. var _t = path[i + 1], x2_1 = _t[0], y2_1 = _t[1];
  18802. var x3 = (x1_1 + x2_1) / 2;
  18803. var y3 = (y1_1 + y2_1) / 2;
  18804. var control1_1 = [x0 + 2 * (x1_1 - x0) / 3, y0 + 2 * (y1_1 - y0) / 3];
  18805. var control2_1 = [x3 + 2 * (x1_1 - x3) / 3, y3 + 2 * (y1_1 - y3) / 3];
  18806. bezierPoints.push([[x0, y0], control1_1, control2_1, [x3, y3]]);
  18807. _q = [x3, y3], x0 = _q[0], y0 = _q[1];
  18808. }
  18809. var _u = path[i], x1 = _u[0], y1 = _u[1];
  18810. var _v = path[i + 1], x2 = _v[0], y2 = _v[1];
  18811. var control1 = [x0 + 2 * (x1 - x0) / 3, y0 + 2 * (y1 - y0) / 3];
  18812. var control2 = [x2 + 2 * (x1 - x2) / 3, y2 + 2 * (y1 - y2) / 3];
  18813. bezierPoints.push([[x0, y0], control1, control2, [x2, y2]]);
  18814. return bezierPoints;
  18815. }, _InkEditor_redraw = function _InkEditor_redraw() {
  18816. if (this.isEmpty()) {
  18817. tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_updateTransform).call(this);
  18818. return;
  18819. }
  18820. tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_setStroke).call(this);
  18821. var _q = this, canvas = _q.canvas, ctx = _q.ctx;
  18822. ctx.setTransform(1, 0, 0, 1, 0, 0);
  18823. ctx.clearRect(0, 0, canvas.width, canvas.height);
  18824. tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_updateTransform).call(this);
  18825. for (var _i = 0, _r = this.bezierPath2D; _i < _r.length; _i++) {
  18826. var path = _r[_i];
  18827. ctx.stroke(path);
  18828. }
  18829. }, _InkEditor_endDrawing = function _InkEditor_endDrawing(event) {
  18830. var _this = this;
  18831. this.canvas.removeEventListener("pointerleave", tslib_1.__classPrivateFieldGet(this, _InkEditor_boundCanvasPointerleave, "f"));
  18832. this.canvas.removeEventListener("pointermove", tslib_1.__classPrivateFieldGet(this, _InkEditor_boundCanvasPointermove, "f"));
  18833. this.canvas.removeEventListener("pointerup", tslib_1.__classPrivateFieldGet(this, _InkEditor_boundCanvasPointerup, "f"));
  18834. this.canvas.addEventListener("pointerdown", tslib_1.__classPrivateFieldGet(this, _InkEditor_boundCanvasPointerdown, "f"));
  18835. if (tslib_1.__classPrivateFieldGet(this, _InkEditor_canvasContextMenuTimeoutId, "f")) {
  18836. clearTimeout(tslib_1.__classPrivateFieldGet(this, _InkEditor_canvasContextMenuTimeoutId, "f"));
  18837. }
  18838. tslib_1.__classPrivateFieldSet(this, _InkEditor_canvasContextMenuTimeoutId, setTimeout(function () {
  18839. tslib_1.__classPrivateFieldSet(_this, _InkEditor_canvasContextMenuTimeoutId, null, "f");
  18840. _this.canvas.removeEventListener("contextmenu", noContextMenu);
  18841. }, 10), "f");
  18842. tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_stopDrawing).call(this, event.offsetX, event.offsetY);
  18843. this.addToAnnotationStorage();
  18844. this.setInBackground();
  18845. }, _InkEditor_createCanvas = function _InkEditor_createCanvas() {
  18846. this.canvas = document.createElement("canvas");
  18847. this.canvas.width = this.canvas.height = 0;
  18848. this.canvas.className = "inkEditorCanvas";
  18849. this.canvas.setAttribute("data-l10n-id", "pdfjs-ink-canvas");
  18850. this.div.append(this.canvas);
  18851. this.ctx = this.canvas.getContext("2d");
  18852. }, _InkEditor_createObserver = function _InkEditor_createObserver() {
  18853. var _this = this;
  18854. tslib_1.__classPrivateFieldSet(this, _InkEditor_observer, new ResizeObserver(function (entries) {
  18855. var rect = entries[0].contentRect;
  18856. if (rect.width && rect.height) {
  18857. _this.setDimensions(rect.width, rect.height);
  18858. }
  18859. }), "f");
  18860. tslib_1.__classPrivateFieldGet(this, _InkEditor_observer, "f").observe(this.div);
  18861. }, _InkEditor_setCanvasDims = function _InkEditor_setCanvasDims() {
  18862. if (!tslib_1.__classPrivateFieldGet(this, _InkEditor_isCanvasInitialized, "f")) {
  18863. return;
  18864. }
  18865. var _q = this.parentDimensions, parentWidth = _q[0], parentHeight = _q[1];
  18866. this.canvas.width = Math.ceil(this.width * parentWidth);
  18867. this.canvas.height = Math.ceil(this.height * parentHeight);
  18868. tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_updateTransform).call(this);
  18869. }, _InkEditor_setScaleFactor = function _InkEditor_setScaleFactor(width, height) {
  18870. var padding = tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_getPadding).call(this);
  18871. var scaleFactorW = (width - padding) / tslib_1.__classPrivateFieldGet(this, _InkEditor_baseWidth, "f");
  18872. var scaleFactorH = (height - padding) / tslib_1.__classPrivateFieldGet(this, _InkEditor_baseHeight, "f");
  18873. this.scaleFactor = Math.min(scaleFactorW, scaleFactorH);
  18874. }, _InkEditor_updateTransform = function _InkEditor_updateTransform() {
  18875. var padding = tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_getPadding).call(this) / 2;
  18876. this.ctx.setTransform(this.scaleFactor, 0, 0, this.scaleFactor, this.translationX * this.scaleFactor + padding, this.translationY * this.scaleFactor + padding);
  18877. }, _InkEditor_buildPath2D = function _InkEditor_buildPath2D(bezier) {
  18878. var path2D = new Path2D();
  18879. for (var i = 0, ii = bezier.length; i < ii; i++) {
  18880. var _q = bezier[i], first = _q[0], control1 = _q[1], control2 = _q[2], second = _q[3];
  18881. if (i === 0) {
  18882. path2D.moveTo.apply(path2D, first);
  18883. }
  18884. path2D.bezierCurveTo(control1[0], control1[1], control2[0], control2[1], second[0], second[1]);
  18885. }
  18886. return path2D;
  18887. }, _InkEditor_toPDFCoordinates = function _InkEditor_toPDFCoordinates(points, rect, rotation) {
  18888. var blX = rect[0], blY = rect[1], trX = rect[2], trY = rect[3];
  18889. switch (rotation) {
  18890. case 0:
  18891. for (var i = 0, ii = points.length; i < ii; i += 2) {
  18892. points[i] += blX;
  18893. points[i + 1] = trY - points[i + 1];
  18894. }
  18895. break;
  18896. case 90:
  18897. for (var i = 0, ii = points.length; i < ii; i += 2) {
  18898. var x = points[i];
  18899. points[i] = points[i + 1] + blX;
  18900. points[i + 1] = x + blY;
  18901. }
  18902. break;
  18903. case 180:
  18904. for (var i = 0, ii = points.length; i < ii; i += 2) {
  18905. points[i] = trX - points[i];
  18906. points[i + 1] += blY;
  18907. }
  18908. break;
  18909. case 270:
  18910. for (var i = 0, ii = points.length; i < ii; i += 2) {
  18911. var x = points[i];
  18912. points[i] = trX - points[i + 1];
  18913. points[i + 1] = trY - x;
  18914. }
  18915. break;
  18916. default:
  18917. throw new Error("Invalid rotation");
  18918. }
  18919. return points;
  18920. }, _InkEditor_fromPDFCoordinates = function _InkEditor_fromPDFCoordinates(points, rect, rotation) {
  18921. var blX = rect[0], blY = rect[1], trX = rect[2], trY = rect[3];
  18922. switch (rotation) {
  18923. case 0:
  18924. for (var i = 0, ii = points.length; i < ii; i += 2) {
  18925. points[i] -= blX;
  18926. points[i + 1] = trY - points[i + 1];
  18927. }
  18928. break;
  18929. case 90:
  18930. for (var i = 0, ii = points.length; i < ii; i += 2) {
  18931. var x = points[i];
  18932. points[i] = points[i + 1] - blY;
  18933. points[i + 1] = x - blX;
  18934. }
  18935. break;
  18936. case 180:
  18937. for (var i = 0, ii = points.length; i < ii; i += 2) {
  18938. points[i] = trX - points[i];
  18939. points[i + 1] -= blY;
  18940. }
  18941. break;
  18942. case 270:
  18943. for (var i = 0, ii = points.length; i < ii; i += 2) {
  18944. var x = points[i];
  18945. points[i] = trY - points[i + 1];
  18946. points[i + 1] = trX - x;
  18947. }
  18948. break;
  18949. default:
  18950. throw new Error("Invalid rotation");
  18951. }
  18952. return points;
  18953. }, _InkEditor_serializePaths = function _InkEditor_serializePaths(s, tx, ty, rect) {
  18954. var paths = [];
  18955. var padding = this.thickness / 2;
  18956. var shiftX = s * tx + padding;
  18957. var shiftY = s * ty + padding;
  18958. for (var _i = 0, _q = this.paths; _i < _q.length; _i++) {
  18959. var bezier = _q[_i];
  18960. var buffer = [];
  18961. var points = [];
  18962. for (var j = 0, jj = bezier.length; j < jj; j++) {
  18963. var _r = bezier[j], first = _r[0], control1 = _r[1], control2 = _r[2], second = _r[3];
  18964. if (first[0] === second[0] && first[1] === second[1] && jj === 1) {
  18965. var p0 = s * first[0] + shiftX;
  18966. var p1 = s * first[1] + shiftY;
  18967. buffer.push(p0, p1);
  18968. points.push(p0, p1);
  18969. break;
  18970. }
  18971. var p10 = s * first[0] + shiftX;
  18972. var p11 = s * first[1] + shiftY;
  18973. var p20 = s * control1[0] + shiftX;
  18974. var p21 = s * control1[1] + shiftY;
  18975. var p30 = s * control2[0] + shiftX;
  18976. var p31 = s * control2[1] + shiftY;
  18977. var p40 = s * second[0] + shiftX;
  18978. var p41 = s * second[1] + shiftY;
  18979. if (j === 0) {
  18980. buffer.push(p10, p11);
  18981. points.push(p10, p11);
  18982. }
  18983. buffer.push(p20, p21, p30, p31, p40, p41);
  18984. points.push(p20, p21);
  18985. if (j === jj - 1) {
  18986. points.push(p40, p41);
  18987. }
  18988. }
  18989. paths.push({
  18990. bezier: tslib_1.__classPrivateFieldGet(InkEditor, _p, "m", _InkEditor_toPDFCoordinates).call(InkEditor, buffer, rect, this.rotation),
  18991. points: tslib_1.__classPrivateFieldGet(InkEditor, _p, "m", _InkEditor_toPDFCoordinates).call(InkEditor, points, rect, this.rotation)
  18992. });
  18993. }
  18994. return paths;
  18995. }, _InkEditor_getBbox = function _InkEditor_getBbox() {
  18996. var xMin = Infinity;
  18997. var xMax = -Infinity;
  18998. var yMin = Infinity;
  18999. var yMax = -Infinity;
  19000. for (var _i = 0, _q = this.paths; _i < _q.length; _i++) {
  19001. var path = _q[_i];
  19002. for (var _r = 0, path_1 = path; _r < path_1.length; _r++) {
  19003. var _s = path_1[_r], first = _s[0], control1 = _s[1], control2 = _s[2], second = _s[3];
  19004. var bbox = Util.bezierBoundingBox.apply(Util, tslib_1.__spreadArray(tslib_1.__spreadArray(tslib_1.__spreadArray(tslib_1.__spreadArray([], first, false), control1, false), control2, false), second, false));
  19005. xMin = Math.min(xMin, bbox[0]);
  19006. yMin = Math.min(yMin, bbox[1]);
  19007. xMax = Math.max(xMax, bbox[2]);
  19008. yMax = Math.max(yMax, bbox[3]);
  19009. }
  19010. }
  19011. return [xMin, yMin, xMax, yMax];
  19012. }, _InkEditor_getPadding = function _InkEditor_getPadding() {
  19013. return tslib_1.__classPrivateFieldGet(this, _InkEditor_disableEditing, "f") ? Math.ceil(this.thickness * this.parentScale) : 0;
  19014. }, _InkEditor_fitToContent = function _InkEditor_fitToContent(firstTime) {
  19015. if (firstTime === void 0) { firstTime = false; }
  19016. if (this.isEmpty()) {
  19017. return;
  19018. }
  19019. if (!tslib_1.__classPrivateFieldGet(this, _InkEditor_disableEditing, "f")) {
  19020. tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_redraw).call(this);
  19021. return;
  19022. }
  19023. var bbox = tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_getBbox).call(this);
  19024. var padding = tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_getPadding).call(this);
  19025. tslib_1.__classPrivateFieldSet(this, _InkEditor_baseWidth, Math.max(AnnotationEditor.MIN_SIZE, bbox[2] - bbox[0]), "f");
  19026. tslib_1.__classPrivateFieldSet(this, _InkEditor_baseHeight, Math.max(AnnotationEditor.MIN_SIZE, bbox[3] - bbox[1]), "f");
  19027. var width = Math.ceil(padding + tslib_1.__classPrivateFieldGet(this, _InkEditor_baseWidth, "f") * this.scaleFactor);
  19028. var height = Math.ceil(padding + tslib_1.__classPrivateFieldGet(this, _InkEditor_baseHeight, "f") * this.scaleFactor);
  19029. var _q = this.parentDimensions, parentWidth = _q[0], parentHeight = _q[1];
  19030. this.width = width / parentWidth;
  19031. this.height = height / parentHeight;
  19032. this.setAspectRatio(width, height);
  19033. var prevTranslationX = this.translationX;
  19034. var prevTranslationY = this.translationY;
  19035. this.translationX = -bbox[0];
  19036. this.translationY = -bbox[1];
  19037. tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_setCanvasDims).call(this);
  19038. tslib_1.__classPrivateFieldGet(this, _InkEditor_instances, "m", _InkEditor_redraw).call(this);
  19039. tslib_1.__classPrivateFieldSet(this, _InkEditor_realWidth, width, "f");
  19040. tslib_1.__classPrivateFieldSet(this, _InkEditor_realHeight, height, "f");
  19041. this.setDims(width, height);
  19042. var unscaledPadding = firstTime ? padding / this.scaleFactor / 2 : 0;
  19043. this.translate(prevTranslationX - this.translationX - unscaledPadding, prevTranslationY - this.translationY - unscaledPadding);
  19044. };
  19045. InkEditor._defaultColor = null;
  19046. InkEditor._defaultOpacity = 1;
  19047. InkEditor._defaultThickness = 1;
  19048. InkEditor._type = "ink";
  19049. InkEditor._editorType = AnnotationEditorType.INK;
  19050. return InkEditor;
  19051. }(AnnotationEditor));
  19052. ; // CONCATENATED MODULE: ./src/display/editor/stamp.js
  19053. var StampEditor = /** @class */ (function (_super) {
  19054. tslib_1.__extends(StampEditor, _super);
  19055. function StampEditor(params) {
  19056. var _this = _super.call(this, tslib_1.__assign(tslib_1.__assign({}, params), { name: "stampEditor" })) || this;
  19057. _StampEditor_instances.add(_this);
  19058. _StampEditor_bitmap.set(_this, null);
  19059. _StampEditor_bitmapId.set(_this, null);
  19060. _StampEditor_bitmapPromise.set(_this, null);
  19061. _StampEditor_bitmapUrl.set(_this, null);
  19062. _StampEditor_bitmapFile.set(_this, null);
  19063. _StampEditor_bitmapFileName.set(_this, "");
  19064. _StampEditor_canvas.set(_this, null);
  19065. _StampEditor_observer.set(_this, null);
  19066. _StampEditor_resizeTimeoutId.set(_this, null);
  19067. _StampEditor_isSvg.set(_this, false);
  19068. _StampEditor_hasBeenAddedInUndoStack.set(_this, false);
  19069. tslib_1.__classPrivateFieldSet(_this, _StampEditor_bitmapUrl, params.bitmapUrl, "f");
  19070. tslib_1.__classPrivateFieldSet(_this, _StampEditor_bitmapFile, params.bitmapFile, "f");
  19071. return _this;
  19072. }
  19073. StampEditor.initialize = function (l10n, uiManager) {
  19074. AnnotationEditor.initialize(l10n, uiManager);
  19075. };
  19076. Object.defineProperty(StampEditor, "supportedTypes", {
  19077. get: function () {
  19078. var types = ["apng", "avif", "bmp", "gif", "jpeg", "png", "svg+xml", "webp", "x-icon"];
  19079. return shadow(this, "supportedTypes", types.map(function (type) { return "image/".concat(type); }));
  19080. },
  19081. enumerable: false,
  19082. configurable: true
  19083. });
  19084. Object.defineProperty(StampEditor, "supportedTypesStr", {
  19085. get: function () {
  19086. return shadow(this, "supportedTypesStr", this.supportedTypes.join(","));
  19087. },
  19088. enumerable: false,
  19089. configurable: true
  19090. });
  19091. StampEditor.isHandlingMimeForPasting = function (mime) {
  19092. return this.supportedTypes.includes(mime);
  19093. };
  19094. StampEditor.paste = function (item, parent) {
  19095. parent.pasteEditor(AnnotationEditorType.STAMP, {
  19096. bitmapFile: item.getAsFile()
  19097. });
  19098. };
  19099. StampEditor.prototype.remove = function () {
  19100. var _q, _r;
  19101. if (tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmapId, "f")) {
  19102. tslib_1.__classPrivateFieldSet(this, _StampEditor_bitmap, null, "f");
  19103. this._uiManager.imageManager.deleteId(tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmapId, "f"));
  19104. (_q = tslib_1.__classPrivateFieldGet(this, _StampEditor_canvas, "f")) === null || _q === void 0 ? void 0 : _q.remove();
  19105. tslib_1.__classPrivateFieldSet(this, _StampEditor_canvas, null, "f");
  19106. (_r = tslib_1.__classPrivateFieldGet(this, _StampEditor_observer, "f")) === null || _r === void 0 ? void 0 : _r.disconnect();
  19107. tslib_1.__classPrivateFieldSet(this, _StampEditor_observer, null, "f");
  19108. if (tslib_1.__classPrivateFieldGet(this, _StampEditor_resizeTimeoutId, "f")) {
  19109. clearTimeout(tslib_1.__classPrivateFieldGet(this, _StampEditor_resizeTimeoutId, "f"));
  19110. tslib_1.__classPrivateFieldSet(this, _StampEditor_resizeTimeoutId, null, "f");
  19111. }
  19112. }
  19113. _super.prototype.remove.call(this);
  19114. };
  19115. StampEditor.prototype.rebuild = function () {
  19116. if (!this.parent) {
  19117. if (tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmapId, "f")) {
  19118. tslib_1.__classPrivateFieldGet(this, _StampEditor_instances, "m", _StampEditor_getBitmap).call(this);
  19119. }
  19120. return;
  19121. }
  19122. _super.prototype.rebuild.call(this);
  19123. if (this.div === null) {
  19124. return;
  19125. }
  19126. if (tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmapId, "f") && tslib_1.__classPrivateFieldGet(this, _StampEditor_canvas, "f") === null) {
  19127. tslib_1.__classPrivateFieldGet(this, _StampEditor_instances, "m", _StampEditor_getBitmap).call(this);
  19128. }
  19129. if (!this.isAttachedToDOM) {
  19130. this.parent.add(this);
  19131. }
  19132. };
  19133. StampEditor.prototype.onceAdded = function () {
  19134. this._isDraggable = true;
  19135. this.div.focus();
  19136. };
  19137. StampEditor.prototype.isEmpty = function () {
  19138. return !(tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmapPromise, "f") || tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmap, "f") || tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmapUrl, "f") || tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmapFile, "f") || tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmapId, "f"));
  19139. };
  19140. Object.defineProperty(StampEditor.prototype, "isResizable", {
  19141. get: function () {
  19142. return true;
  19143. },
  19144. enumerable: false,
  19145. configurable: true
  19146. });
  19147. StampEditor.prototype.render = function () {
  19148. if (this.div) {
  19149. return this.div;
  19150. }
  19151. var baseX, baseY;
  19152. if (this.width) {
  19153. baseX = this.x;
  19154. baseY = this.y;
  19155. }
  19156. _super.prototype.render.call(this);
  19157. this.div.hidden = true;
  19158. this.addAltTextButton();
  19159. if (tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmap, "f")) {
  19160. tslib_1.__classPrivateFieldGet(this, _StampEditor_instances, "m", _StampEditor_createCanvas).call(this);
  19161. }
  19162. else {
  19163. tslib_1.__classPrivateFieldGet(this, _StampEditor_instances, "m", _StampEditor_getBitmap).call(this);
  19164. }
  19165. if (this.width) {
  19166. var _q = this.parentDimensions, parentWidth = _q[0], parentHeight = _q[1];
  19167. this.setAt(baseX * parentWidth, baseY * parentHeight, this.width * parentWidth, this.height * parentHeight);
  19168. }
  19169. return this.div;
  19170. };
  19171. StampEditor.prototype.getImageForAltText = function () {
  19172. return tslib_1.__classPrivateFieldGet(this, _StampEditor_canvas, "f");
  19173. };
  19174. StampEditor.deserialize = function (data, parent, uiManager) {
  19175. if (data instanceof StampAnnotationElement) {
  19176. return null;
  19177. }
  19178. var editor = _super.deserialize.call(this, data, parent, uiManager);
  19179. var rect = data.rect, bitmapUrl = data.bitmapUrl, bitmapId = data.bitmapId, isSvg = data.isSvg, accessibilityData = data.accessibilityData;
  19180. if (bitmapId && uiManager.imageManager.isValidId(bitmapId)) {
  19181. tslib_1.__classPrivateFieldSet(editor, _StampEditor_bitmapId, bitmapId, "f");
  19182. }
  19183. else {
  19184. tslib_1.__classPrivateFieldSet(editor, _StampEditor_bitmapUrl, bitmapUrl, "f");
  19185. }
  19186. tslib_1.__classPrivateFieldSet(editor, _StampEditor_isSvg, isSvg, "f");
  19187. var _q = editor.pageDimensions, parentWidth = _q[0], parentHeight = _q[1];
  19188. editor.width = (rect[2] - rect[0]) / parentWidth;
  19189. editor.height = (rect[3] - rect[1]) / parentHeight;
  19190. if (accessibilityData) {
  19191. editor.altTextData = accessibilityData;
  19192. }
  19193. return editor;
  19194. };
  19195. StampEditor.prototype.serialize = function (isForCopying, context) {
  19196. if (isForCopying === void 0) { isForCopying = false; }
  19197. if (context === void 0) { context = null; }
  19198. if (this.isEmpty()) {
  19199. return null;
  19200. }
  19201. var serialized = {
  19202. annotationType: AnnotationEditorType.STAMP,
  19203. bitmapId: tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmapId, "f"),
  19204. pageIndex: this.pageIndex,
  19205. rect: this.getRect(0, 0),
  19206. rotation: this.rotation,
  19207. isSvg: tslib_1.__classPrivateFieldGet(this, _StampEditor_isSvg, "f"),
  19208. structTreeParentId: this._structTreeParentId
  19209. };
  19210. if (isForCopying) {
  19211. serialized.bitmapUrl = tslib_1.__classPrivateFieldGet(this, _StampEditor_instances, "m", _StampEditor_serializeBitmap).call(this, true);
  19212. serialized.accessibilityData = this.altTextData;
  19213. return serialized;
  19214. }
  19215. var _q = this.altTextData, decorative = _q.decorative, altText = _q.altText;
  19216. if (!decorative && altText) {
  19217. serialized.accessibilityData = {
  19218. type: "Figure",
  19219. alt: altText
  19220. };
  19221. }
  19222. if (context === null) {
  19223. return serialized;
  19224. }
  19225. context.stamps || (context.stamps = new Map());
  19226. var area = tslib_1.__classPrivateFieldGet(this, _StampEditor_isSvg, "f") ? (serialized.rect[2] - serialized.rect[0]) * (serialized.rect[3] - serialized.rect[1]) : null;
  19227. if (!context.stamps.has(tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmapId, "f"))) {
  19228. context.stamps.set(tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmapId, "f"), {
  19229. area: area,
  19230. serialized: serialized
  19231. });
  19232. serialized.bitmap = tslib_1.__classPrivateFieldGet(this, _StampEditor_instances, "m", _StampEditor_serializeBitmap).call(this, false);
  19233. }
  19234. else if (tslib_1.__classPrivateFieldGet(this, _StampEditor_isSvg, "f")) {
  19235. var prevData = context.stamps.get(tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmapId, "f"));
  19236. if (area > prevData.area) {
  19237. prevData.area = area;
  19238. prevData.serialized.bitmap.close();
  19239. prevData.serialized.bitmap = tslib_1.__classPrivateFieldGet(this, _StampEditor_instances, "m", _StampEditor_serializeBitmap).call(this, false);
  19240. }
  19241. }
  19242. return serialized;
  19243. };
  19244. var _StampEditor_instances, _StampEditor_bitmap, _StampEditor_bitmapId, _StampEditor_bitmapPromise, _StampEditor_bitmapUrl, _StampEditor_bitmapFile, _StampEditor_bitmapFileName, _StampEditor_canvas, _StampEditor_observer, _StampEditor_resizeTimeoutId, _StampEditor_isSvg, _StampEditor_hasBeenAddedInUndoStack, _StampEditor_getBitmapFetched, _StampEditor_getBitmapDone, _StampEditor_getBitmap, _StampEditor_createCanvas, _StampEditor_setDimensions, _StampEditor_scaleBitmap, _StampEditor_drawBitmap, _StampEditor_serializeBitmap, _StampEditor_createObserver;
  19245. _StampEditor_bitmap = new WeakMap(), _StampEditor_bitmapId = new WeakMap(), _StampEditor_bitmapPromise = new WeakMap(), _StampEditor_bitmapUrl = new WeakMap(), _StampEditor_bitmapFile = new WeakMap(), _StampEditor_bitmapFileName = new WeakMap(), _StampEditor_canvas = new WeakMap(), _StampEditor_observer = new WeakMap(), _StampEditor_resizeTimeoutId = new WeakMap(), _StampEditor_isSvg = new WeakMap(), _StampEditor_hasBeenAddedInUndoStack = new WeakMap(), _StampEditor_instances = new WeakSet(), _StampEditor_getBitmapFetched = function _StampEditor_getBitmapFetched(data, fromId) {
  19246. if (fromId === void 0) { fromId = false; }
  19247. if (!data) {
  19248. this.remove();
  19249. return;
  19250. }
  19251. tslib_1.__classPrivateFieldSet(this, _StampEditor_bitmap, data.bitmap, "f");
  19252. if (!fromId) {
  19253. tslib_1.__classPrivateFieldSet(this, _StampEditor_bitmapId, data.id, "f");
  19254. tslib_1.__classPrivateFieldSet(this, _StampEditor_isSvg, data.isSvg, "f");
  19255. }
  19256. if (data.file) {
  19257. tslib_1.__classPrivateFieldSet(this, _StampEditor_bitmapFileName, data.file.name, "f");
  19258. }
  19259. tslib_1.__classPrivateFieldGet(this, _StampEditor_instances, "m", _StampEditor_createCanvas).call(this);
  19260. }, _StampEditor_getBitmapDone = function _StampEditor_getBitmapDone() {
  19261. tslib_1.__classPrivateFieldSet(this, _StampEditor_bitmapPromise, null, "f");
  19262. this._uiManager.enableWaiting(false);
  19263. if (tslib_1.__classPrivateFieldGet(this, _StampEditor_canvas, "f")) {
  19264. this.div.focus();
  19265. }
  19266. }, _StampEditor_getBitmap = function _StampEditor_getBitmap() {
  19267. var _this = this;
  19268. if (tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmapId, "f")) {
  19269. this._uiManager.enableWaiting(true);
  19270. this._uiManager.imageManager.getFromId(tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmapId, "f")).then(function (data) { return tslib_1.__classPrivateFieldGet(_this, _StampEditor_instances, "m", _StampEditor_getBitmapFetched).call(_this, data, true); }).finally(function () { return tslib_1.__classPrivateFieldGet(_this, _StampEditor_instances, "m", _StampEditor_getBitmapDone).call(_this); });
  19271. return;
  19272. }
  19273. if (tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmapUrl, "f")) {
  19274. var url = tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmapUrl, "f");
  19275. tslib_1.__classPrivateFieldSet(this, _StampEditor_bitmapUrl, null, "f");
  19276. this._uiManager.enableWaiting(true);
  19277. tslib_1.__classPrivateFieldSet(this, _StampEditor_bitmapPromise, this._uiManager.imageManager.getFromUrl(url).then(function (data) { return tslib_1.__classPrivateFieldGet(_this, _StampEditor_instances, "m", _StampEditor_getBitmapFetched).call(_this, data); }).finally(function () { return tslib_1.__classPrivateFieldGet(_this, _StampEditor_instances, "m", _StampEditor_getBitmapDone).call(_this); }), "f");
  19278. return;
  19279. }
  19280. if (tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmapFile, "f")) {
  19281. var file = tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmapFile, "f");
  19282. tslib_1.__classPrivateFieldSet(this, _StampEditor_bitmapFile, null, "f");
  19283. this._uiManager.enableWaiting(true);
  19284. tslib_1.__classPrivateFieldSet(this, _StampEditor_bitmapPromise, this._uiManager.imageManager.getFromFile(file).then(function (data) { return tslib_1.__classPrivateFieldGet(_this, _StampEditor_instances, "m", _StampEditor_getBitmapFetched).call(_this, data); }).finally(function () { return tslib_1.__classPrivateFieldGet(_this, _StampEditor_instances, "m", _StampEditor_getBitmapDone).call(_this); }), "f");
  19285. return;
  19286. }
  19287. var input = document.createElement("input");
  19288. input.type = "file";
  19289. input.accept = StampEditor.supportedTypesStr;
  19290. tslib_1.__classPrivateFieldSet(this, _StampEditor_bitmapPromise, new Promise(function (resolve) {
  19291. input.addEventListener("change", function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
  19292. var data;
  19293. return tslib_1.__generator(this, function (_q) {
  19294. switch (_q.label) {
  19295. case 0:
  19296. if (!(!input.files || input.files.length === 0)) return [3 /*break*/, 1];
  19297. this.remove();
  19298. return [3 /*break*/, 3];
  19299. case 1:
  19300. this._uiManager.enableWaiting(true);
  19301. return [4 /*yield*/, this._uiManager.imageManager.getFromFile(input.files[0])];
  19302. case 2:
  19303. data = _q.sent();
  19304. tslib_1.__classPrivateFieldGet(this, _StampEditor_instances, "m", _StampEditor_getBitmapFetched).call(this, data);
  19305. _q.label = 3;
  19306. case 3:
  19307. resolve();
  19308. return [2 /*return*/];
  19309. }
  19310. });
  19311. }); });
  19312. input.addEventListener("cancel", function () {
  19313. _this.remove();
  19314. resolve();
  19315. });
  19316. }).finally(function () { return tslib_1.__classPrivateFieldGet(_this, _StampEditor_instances, "m", _StampEditor_getBitmapDone).call(_this); }), "f");
  19317. input.click();
  19318. }, _StampEditor_createCanvas = function _StampEditor_createCanvas() {
  19319. var div = this.div;
  19320. var _q = tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmap, "f"), width = _q.width, height = _q.height;
  19321. var _r = this.pageDimensions, pageWidth = _r[0], pageHeight = _r[1];
  19322. var MAX_RATIO = 0.75;
  19323. if (this.width) {
  19324. width = this.width * pageWidth;
  19325. height = this.height * pageHeight;
  19326. }
  19327. else if (width > MAX_RATIO * pageWidth || height > MAX_RATIO * pageHeight) {
  19328. var factor = Math.min(MAX_RATIO * pageWidth / width, MAX_RATIO * pageHeight / height);
  19329. width *= factor;
  19330. height *= factor;
  19331. }
  19332. var _s = this.parentDimensions, parentWidth = _s[0], parentHeight = _s[1];
  19333. this.setDims(width * parentWidth / pageWidth, height * parentHeight / pageHeight);
  19334. this._uiManager.enableWaiting(false);
  19335. var canvas = tslib_1.__classPrivateFieldSet(this, _StampEditor_canvas, document.createElement("canvas"), "f");
  19336. div.append(canvas);
  19337. div.hidden = false;
  19338. tslib_1.__classPrivateFieldGet(this, _StampEditor_instances, "m", _StampEditor_drawBitmap).call(this, width, height);
  19339. tslib_1.__classPrivateFieldGet(this, _StampEditor_instances, "m", _StampEditor_createObserver).call(this);
  19340. if (!tslib_1.__classPrivateFieldGet(this, _StampEditor_hasBeenAddedInUndoStack, "f")) {
  19341. this.parent.addUndoableEditor(this);
  19342. tslib_1.__classPrivateFieldSet(this, _StampEditor_hasBeenAddedInUndoStack, true, "f");
  19343. }
  19344. this._reportTelemetry({
  19345. action: "inserted_image"
  19346. });
  19347. if (tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmapFileName, "f")) {
  19348. canvas.setAttribute("aria-label", tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmapFileName, "f"));
  19349. }
  19350. }, _StampEditor_setDimensions = function _StampEditor_setDimensions(width, height) {
  19351. var _this = this;
  19352. var _q;
  19353. var _r = this.parentDimensions, parentWidth = _r[0], parentHeight = _r[1];
  19354. this.width = width / parentWidth;
  19355. this.height = height / parentHeight;
  19356. this.setDims(width, height);
  19357. if ((_q = this._initialOptions) === null || _q === void 0 ? void 0 : _q.isCentered) {
  19358. this.center();
  19359. }
  19360. else {
  19361. this.fixAndSetPosition();
  19362. }
  19363. this._initialOptions = null;
  19364. if (tslib_1.__classPrivateFieldGet(this, _StampEditor_resizeTimeoutId, "f") !== null) {
  19365. clearTimeout(tslib_1.__classPrivateFieldGet(this, _StampEditor_resizeTimeoutId, "f"));
  19366. }
  19367. var TIME_TO_WAIT = 200;
  19368. tslib_1.__classPrivateFieldSet(this, _StampEditor_resizeTimeoutId, setTimeout(function () {
  19369. tslib_1.__classPrivateFieldSet(_this, _StampEditor_resizeTimeoutId, null, "f");
  19370. tslib_1.__classPrivateFieldGet(_this, _StampEditor_instances, "m", _StampEditor_drawBitmap).call(_this, width, height);
  19371. }, TIME_TO_WAIT), "f");
  19372. }, _StampEditor_scaleBitmap = function _StampEditor_scaleBitmap(width, height) {
  19373. var _q = tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmap, "f"), bitmapWidth = _q.width, bitmapHeight = _q.height;
  19374. var newWidth = bitmapWidth;
  19375. var newHeight = bitmapHeight;
  19376. var bitmap = tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmap, "f");
  19377. while (newWidth > 2 * width || newHeight > 2 * height) {
  19378. var prevWidth = newWidth;
  19379. var prevHeight = newHeight;
  19380. if (newWidth > 2 * width) {
  19381. newWidth = newWidth >= 16384 ? Math.floor(newWidth / 2) - 1 : Math.ceil(newWidth / 2);
  19382. }
  19383. if (newHeight > 2 * height) {
  19384. newHeight = newHeight >= 16384 ? Math.floor(newHeight / 2) - 1 : Math.ceil(newHeight / 2);
  19385. }
  19386. var offscreen = new OffscreenCanvas(newWidth, newHeight);
  19387. var ctx = offscreen.getContext("2d");
  19388. ctx.drawImage(bitmap, 0, 0, prevWidth, prevHeight, 0, 0, newWidth, newHeight);
  19389. bitmap = offscreen.transferToImageBitmap();
  19390. }
  19391. return bitmap;
  19392. }, _StampEditor_drawBitmap = function _StampEditor_drawBitmap(width, height) {
  19393. var _this = this;
  19394. width = Math.ceil(width);
  19395. height = Math.ceil(height);
  19396. var canvas = tslib_1.__classPrivateFieldGet(this, _StampEditor_canvas, "f");
  19397. if (!canvas || canvas.width === width && canvas.height === height) {
  19398. return;
  19399. }
  19400. canvas.width = width;
  19401. canvas.height = height;
  19402. var bitmap = tslib_1.__classPrivateFieldGet(this, _StampEditor_isSvg, "f") ? tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmap, "f") : tslib_1.__classPrivateFieldGet(this, _StampEditor_instances, "m", _StampEditor_scaleBitmap).call(this, width, height);
  19403. if (this._uiManager.hasMLManager && !this.hasAltText()) {
  19404. var offscreen = new OffscreenCanvas(width, height);
  19405. var ctx_1 = offscreen.getContext("2d");
  19406. ctx_1.drawImage(bitmap, 0, 0, bitmap.width, bitmap.height, 0, 0, width, height);
  19407. this._uiManager.mlGuess({
  19408. service: "image-to-text",
  19409. request: {
  19410. data: ctx_1.getImageData(0, 0, width, height).data,
  19411. width: width,
  19412. height: height,
  19413. channels: 4
  19414. }
  19415. }).then(function (response) {
  19416. var altText = (response === null || response === void 0 ? void 0 : response.output) || "";
  19417. if (_this.parent && altText && !_this.hasAltText()) {
  19418. _this.altTextData = {
  19419. altText: altText,
  19420. decorative: false
  19421. };
  19422. }
  19423. });
  19424. }
  19425. var ctx = canvas.getContext("2d");
  19426. ctx.filter = this._uiManager.hcmFilter;
  19427. ctx.drawImage(bitmap, 0, 0, bitmap.width, bitmap.height, 0, 0, width, height);
  19428. }, _StampEditor_serializeBitmap = function _StampEditor_serializeBitmap(toUrl) {
  19429. var _q;
  19430. if (toUrl) {
  19431. if (tslib_1.__classPrivateFieldGet(this, _StampEditor_isSvg, "f")) {
  19432. var url = this._uiManager.imageManager.getSvgUrl(tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmapId, "f"));
  19433. if (url) {
  19434. return url;
  19435. }
  19436. }
  19437. var canvas = document.createElement("canvas");
  19438. (_q = tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmap, "f"), canvas.width = _q.width, canvas.height = _q.height);
  19439. var ctx = canvas.getContext("2d");
  19440. ctx.drawImage(tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmap, "f"), 0, 0);
  19441. return canvas.toDataURL();
  19442. }
  19443. if (tslib_1.__classPrivateFieldGet(this, _StampEditor_isSvg, "f")) {
  19444. var _r = this.pageDimensions, pageWidth = _r[0], pageHeight = _r[1];
  19445. var width = Math.round(this.width * pageWidth * PixelsPerInch.PDF_TO_CSS_UNITS);
  19446. var height = Math.round(this.height * pageHeight * PixelsPerInch.PDF_TO_CSS_UNITS);
  19447. var offscreen = new OffscreenCanvas(width, height);
  19448. var ctx = offscreen.getContext("2d");
  19449. ctx.drawImage(tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmap, "f"), 0, 0, tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmap, "f").width, tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmap, "f").height, 0, 0, width, height);
  19450. return offscreen.transferToImageBitmap();
  19451. }
  19452. return structuredClone(tslib_1.__classPrivateFieldGet(this, _StampEditor_bitmap, "f"));
  19453. }, _StampEditor_createObserver = function _StampEditor_createObserver() {
  19454. var _this = this;
  19455. tslib_1.__classPrivateFieldSet(this, _StampEditor_observer, new ResizeObserver(function (entries) {
  19456. var rect = entries[0].contentRect;
  19457. if (rect.width && rect.height) {
  19458. tslib_1.__classPrivateFieldGet(_this, _StampEditor_instances, "m", _StampEditor_setDimensions).call(_this, rect.width, rect.height);
  19459. }
  19460. }), "f");
  19461. tslib_1.__classPrivateFieldGet(this, _StampEditor_observer, "f").observe(this.div);
  19462. };
  19463. StampEditor._type = "stamp";
  19464. StampEditor._editorType = AnnotationEditorType.STAMP;
  19465. return StampEditor;
  19466. }(AnnotationEditor));
  19467. ; // CONCATENATED MODULE: ./src/display/editor/annotation_editor_layer.js
  19468. var AnnotationEditorLayer = /** @class */ (function () {
  19469. function AnnotationEditorLayer(_r) {
  19470. var uiManager = _r.uiManager, pageIndex = _r.pageIndex, div = _r.div, accessibilityManager = _r.accessibilityManager, annotationLayer = _r.annotationLayer, drawLayer = _r.drawLayer, textLayer = _r.textLayer, viewport = _r.viewport, l10n = _r.l10n;
  19471. _AnnotationEditorLayer_instances.add(this);
  19472. _AnnotationEditorLayer_accessibilityManager.set(this, void 0);
  19473. _AnnotationEditorLayer_allowClick.set(this, false);
  19474. _AnnotationEditorLayer_annotationLayer.set(this, null);
  19475. _AnnotationEditorLayer_boundPointerup.set(this, null);
  19476. _AnnotationEditorLayer_boundPointerdown.set(this, null);
  19477. _AnnotationEditorLayer_boundTextLayerPointerDown.set(this, null);
  19478. _AnnotationEditorLayer_editorFocusTimeoutId.set(this, null);
  19479. _AnnotationEditorLayer_editors.set(this, new Map());
  19480. _AnnotationEditorLayer_hadPointerDown.set(this, false);
  19481. _AnnotationEditorLayer_isCleaningUp.set(this, false);
  19482. _AnnotationEditorLayer_isDisabling.set(this, false);
  19483. _AnnotationEditorLayer_textLayer.set(this, null);
  19484. _AnnotationEditorLayer_uiManager.set(this, void 0);
  19485. var editorTypes = tslib_1.__spreadArray([], tslib_1.__classPrivateFieldGet(AnnotationEditorLayer, _q, "f", _AnnotationEditorLayer_editorTypes).values(), true);
  19486. if (!AnnotationEditorLayer._initialized) {
  19487. AnnotationEditorLayer._initialized = true;
  19488. for (var _i = 0, editorTypes_1 = editorTypes; _i < editorTypes_1.length; _i++) {
  19489. var editorType = editorTypes_1[_i];
  19490. editorType.initialize(l10n, uiManager);
  19491. }
  19492. }
  19493. uiManager.registerEditorTypes(editorTypes);
  19494. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_uiManager, uiManager, "f");
  19495. this.pageIndex = pageIndex;
  19496. this.div = div;
  19497. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_accessibilityManager, accessibilityManager, "f");
  19498. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_annotationLayer, annotationLayer, "f");
  19499. this.viewport = viewport;
  19500. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_textLayer, textLayer, "f");
  19501. this.drawLayer = drawLayer;
  19502. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").addLayer(this);
  19503. }
  19504. Object.defineProperty(AnnotationEditorLayer.prototype, "isEmpty", {
  19505. get: function () {
  19506. return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_editors, "f").size === 0;
  19507. },
  19508. enumerable: false,
  19509. configurable: true
  19510. });
  19511. Object.defineProperty(AnnotationEditorLayer.prototype, "isInvisible", {
  19512. get: function () {
  19513. return this.isEmpty && tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").getMode() === AnnotationEditorType.NONE;
  19514. },
  19515. enumerable: false,
  19516. configurable: true
  19517. });
  19518. AnnotationEditorLayer.prototype.updateToolbar = function (mode) {
  19519. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").updateToolbar(mode);
  19520. };
  19521. AnnotationEditorLayer.prototype.updateMode = function (mode) {
  19522. if (mode === void 0) { mode = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").getMode(); }
  19523. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_instances, "m", _AnnotationEditorLayer_cleanup).call(this);
  19524. switch (mode) {
  19525. case AnnotationEditorType.NONE:
  19526. this.disableTextSelection();
  19527. this.togglePointerEvents(false);
  19528. this.toggleAnnotationLayerPointerEvents(true);
  19529. this.disableClick();
  19530. return;
  19531. case AnnotationEditorType.INK:
  19532. this.addInkEditorIfNeeded(false);
  19533. this.disableTextSelection();
  19534. this.togglePointerEvents(true);
  19535. this.disableClick();
  19536. break;
  19537. case AnnotationEditorType.HIGHLIGHT:
  19538. this.enableTextSelection();
  19539. this.togglePointerEvents(false);
  19540. this.disableClick();
  19541. break;
  19542. default:
  19543. this.disableTextSelection();
  19544. this.togglePointerEvents(true);
  19545. this.enableClick();
  19546. }
  19547. this.toggleAnnotationLayerPointerEvents(false);
  19548. var classList = this.div.classList;
  19549. for (var _i = 0, _r = tslib_1.__classPrivateFieldGet(AnnotationEditorLayer, _q, "f", _AnnotationEditorLayer_editorTypes).values(); _i < _r.length; _i++) {
  19550. var editorType = _r[_i];
  19551. classList.toggle("".concat(editorType._type, "Editing"), mode === editorType._editorType);
  19552. }
  19553. this.div.hidden = false;
  19554. };
  19555. AnnotationEditorLayer.prototype.hasTextLayer = function (textLayer) {
  19556. var _r;
  19557. return textLayer === ((_r = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_textLayer, "f")) === null || _r === void 0 ? void 0 : _r.div);
  19558. };
  19559. AnnotationEditorLayer.prototype.addInkEditorIfNeeded = function (isCommitting) {
  19560. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").getMode() !== AnnotationEditorType.INK) {
  19561. return;
  19562. }
  19563. if (!isCommitting) {
  19564. for (var _i = 0, _r = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_editors, "f").values(); _i < _r.length; _i++) {
  19565. var editor_1 = _r[_i];
  19566. if (editor_1.isEmpty()) {
  19567. editor_1.setInBackground();
  19568. return;
  19569. }
  19570. }
  19571. }
  19572. var editor = this.createAndAddNewEditor({
  19573. offsetX: 0,
  19574. offsetY: 0
  19575. }, false);
  19576. editor.setInBackground();
  19577. };
  19578. AnnotationEditorLayer.prototype.setEditingState = function (isEditing) {
  19579. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").setEditingState(isEditing);
  19580. };
  19581. AnnotationEditorLayer.prototype.addCommands = function (params) {
  19582. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").addCommands(params);
  19583. };
  19584. AnnotationEditorLayer.prototype.togglePointerEvents = function (enabled) {
  19585. if (enabled === void 0) { enabled = false; }
  19586. this.div.classList.toggle("disabled", !enabled);
  19587. };
  19588. AnnotationEditorLayer.prototype.toggleAnnotationLayerPointerEvents = function (enabled) {
  19589. var _r;
  19590. if (enabled === void 0) { enabled = false; }
  19591. (_r = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_annotationLayer, "f")) === null || _r === void 0 ? void 0 : _r.div.classList.toggle("disabled", !enabled);
  19592. };
  19593. AnnotationEditorLayer.prototype.enable = function () {
  19594. this.div.tabIndex = 0;
  19595. this.togglePointerEvents(true);
  19596. var annotationElementIds = new Set();
  19597. for (var _i = 0, _r = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_editors, "f").values(); _i < _r.length; _i++) {
  19598. var editor = _r[_i];
  19599. editor.enableEditing();
  19600. editor.show(true);
  19601. if (editor.annotationElementId) {
  19602. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").removeChangedExistingAnnotation(editor);
  19603. annotationElementIds.add(editor.annotationElementId);
  19604. }
  19605. }
  19606. if (!tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_annotationLayer, "f")) {
  19607. return;
  19608. }
  19609. var editables = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_annotationLayer, "f").getEditableAnnotations();
  19610. for (var _s = 0, editables_1 = editables; _s < editables_1.length; _s++) {
  19611. var editable = editables_1[_s];
  19612. editable.hide();
  19613. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").isDeletedAnnotationElement(editable.data.id)) {
  19614. continue;
  19615. }
  19616. if (annotationElementIds.has(editable.data.id)) {
  19617. continue;
  19618. }
  19619. var editor = this.deserialize(editable);
  19620. if (!editor) {
  19621. continue;
  19622. }
  19623. this.addOrRebuild(editor);
  19624. editor.enableEditing();
  19625. }
  19626. };
  19627. AnnotationEditorLayer.prototype.disable = function () {
  19628. var _r;
  19629. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_isDisabling, true, "f");
  19630. this.div.tabIndex = -1;
  19631. this.togglePointerEvents(false);
  19632. var changedAnnotations = new Map();
  19633. var resetAnnotations = new Map();
  19634. for (var _i = 0, _s = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_editors, "f").values(); _i < _s.length; _i++) {
  19635. var editor = _s[_i];
  19636. editor.disableEditing();
  19637. if (!editor.annotationElementId) {
  19638. continue;
  19639. }
  19640. if (editor.serialize() !== null) {
  19641. changedAnnotations.set(editor.annotationElementId, editor);
  19642. continue;
  19643. }
  19644. else {
  19645. resetAnnotations.set(editor.annotationElementId, editor);
  19646. }
  19647. (_r = this.getEditableAnnotation(editor.annotationElementId)) === null || _r === void 0 ? void 0 : _r.show();
  19648. editor.remove();
  19649. }
  19650. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_annotationLayer, "f")) {
  19651. var editables = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_annotationLayer, "f").getEditableAnnotations();
  19652. for (var _t = 0, editables_2 = editables; _t < editables_2.length; _t++) {
  19653. var editable = editables_2[_t];
  19654. var id = editable.data.id;
  19655. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").isDeletedAnnotationElement(id)) {
  19656. continue;
  19657. }
  19658. var editor = resetAnnotations.get(id);
  19659. if (editor) {
  19660. editor.resetAnnotationElement(editable);
  19661. editor.show(false);
  19662. editable.show();
  19663. continue;
  19664. }
  19665. editor = changedAnnotations.get(id);
  19666. if (editor) {
  19667. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").addChangedExistingAnnotation(editor);
  19668. editor.renderAnnotationElement(editable);
  19669. editor.show(false);
  19670. }
  19671. editable.show();
  19672. }
  19673. }
  19674. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_instances, "m", _AnnotationEditorLayer_cleanup).call(this);
  19675. if (this.isEmpty) {
  19676. this.div.hidden = true;
  19677. }
  19678. var classList = this.div.classList;
  19679. for (var _u = 0, _v = tslib_1.__classPrivateFieldGet(AnnotationEditorLayer, _q, "f", _AnnotationEditorLayer_editorTypes).values(); _u < _v.length; _u++) {
  19680. var editorType = _v[_u];
  19681. classList.remove("".concat(editorType._type, "Editing"));
  19682. }
  19683. this.disableTextSelection();
  19684. this.toggleAnnotationLayerPointerEvents(true);
  19685. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_isDisabling, false, "f");
  19686. };
  19687. AnnotationEditorLayer.prototype.getEditableAnnotation = function (id) {
  19688. var _r;
  19689. return ((_r = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_annotationLayer, "f")) === null || _r === void 0 ? void 0 : _r.getEditableAnnotation(id)) || null;
  19690. };
  19691. AnnotationEditorLayer.prototype.setActiveEditor = function (editor) {
  19692. var currentActive = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").getActive();
  19693. if (currentActive === editor) {
  19694. return;
  19695. }
  19696. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").setActiveEditor(editor);
  19697. };
  19698. AnnotationEditorLayer.prototype.enableTextSelection = function () {
  19699. var _r;
  19700. this.div.tabIndex = -1;
  19701. if (((_r = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_textLayer, "f")) === null || _r === void 0 ? void 0 : _r.div) && !tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_boundTextLayerPointerDown, "f")) {
  19702. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_boundTextLayerPointerDown, tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_instances, "m", _AnnotationEditorLayer_textLayerPointerDown).bind(this), "f");
  19703. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_textLayer, "f").div.addEventListener("pointerdown", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_boundTextLayerPointerDown, "f"));
  19704. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_textLayer, "f").div.classList.add("highlighting");
  19705. }
  19706. };
  19707. AnnotationEditorLayer.prototype.disableTextSelection = function () {
  19708. var _r;
  19709. this.div.tabIndex = 0;
  19710. if (((_r = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_textLayer, "f")) === null || _r === void 0 ? void 0 : _r.div) && tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_boundTextLayerPointerDown, "f")) {
  19711. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_textLayer, "f").div.removeEventListener("pointerdown", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_boundTextLayerPointerDown, "f"));
  19712. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_boundTextLayerPointerDown, null, "f");
  19713. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_textLayer, "f").div.classList.remove("highlighting");
  19714. }
  19715. };
  19716. AnnotationEditorLayer.prototype.enableClick = function () {
  19717. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_boundPointerdown, "f")) {
  19718. return;
  19719. }
  19720. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_boundPointerdown, this.pointerdown.bind(this), "f");
  19721. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_boundPointerup, this.pointerup.bind(this), "f");
  19722. this.div.addEventListener("pointerdown", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_boundPointerdown, "f"));
  19723. this.div.addEventListener("pointerup", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_boundPointerup, "f"));
  19724. };
  19725. AnnotationEditorLayer.prototype.disableClick = function () {
  19726. if (!tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_boundPointerdown, "f")) {
  19727. return;
  19728. }
  19729. this.div.removeEventListener("pointerdown", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_boundPointerdown, "f"));
  19730. this.div.removeEventListener("pointerup", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_boundPointerup, "f"));
  19731. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_boundPointerdown, null, "f");
  19732. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_boundPointerup, null, "f");
  19733. };
  19734. AnnotationEditorLayer.prototype.attach = function (editor) {
  19735. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_editors, "f").set(editor.id, editor);
  19736. var annotationElementId = editor.annotationElementId;
  19737. if (annotationElementId && tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").isDeletedAnnotationElement(annotationElementId)) {
  19738. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").removeDeletedAnnotationElement(editor);
  19739. }
  19740. };
  19741. AnnotationEditorLayer.prototype.detach = function (editor) {
  19742. var _r;
  19743. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_editors, "f").delete(editor.id);
  19744. (_r = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_accessibilityManager, "f")) === null || _r === void 0 ? void 0 : _r.removePointerInTextLayer(editor.contentDiv);
  19745. if (!tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_isDisabling, "f") && editor.annotationElementId) {
  19746. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").addDeletedAnnotationElement(editor);
  19747. }
  19748. };
  19749. AnnotationEditorLayer.prototype.remove = function (editor) {
  19750. this.detach(editor);
  19751. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").removeEditor(editor);
  19752. editor.div.remove();
  19753. editor.isAttachedToDOM = false;
  19754. if (!tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_isCleaningUp, "f")) {
  19755. this.addInkEditorIfNeeded(false);
  19756. }
  19757. };
  19758. AnnotationEditorLayer.prototype.changeParent = function (editor) {
  19759. var _r;
  19760. if (editor.parent === this) {
  19761. return;
  19762. }
  19763. if (editor.parent && editor.annotationElementId) {
  19764. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").addDeletedAnnotationElement(editor.annotationElementId);
  19765. AnnotationEditor.deleteAnnotationElement(editor);
  19766. editor.annotationElementId = null;
  19767. }
  19768. this.attach(editor);
  19769. (_r = editor.parent) === null || _r === void 0 ? void 0 : _r.detach(editor);
  19770. editor.setParent(this);
  19771. if (editor.div && editor.isAttachedToDOM) {
  19772. editor.div.remove();
  19773. this.div.append(editor.div);
  19774. }
  19775. };
  19776. AnnotationEditorLayer.prototype.add = function (editor) {
  19777. if (editor.parent === this && editor.isAttachedToDOM) {
  19778. return;
  19779. }
  19780. this.changeParent(editor);
  19781. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").addEditor(editor);
  19782. this.attach(editor);
  19783. if (!editor.isAttachedToDOM) {
  19784. var div = editor.render();
  19785. this.div.append(div);
  19786. editor.isAttachedToDOM = true;
  19787. }
  19788. editor.fixAndSetPosition();
  19789. editor.onceAdded();
  19790. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").addToAnnotationStorage(editor);
  19791. editor._reportTelemetry(editor.telemetryInitialData);
  19792. };
  19793. AnnotationEditorLayer.prototype.moveEditorInDOM = function (editor) {
  19794. var _this = this;
  19795. var _r;
  19796. if (!editor.isAttachedToDOM) {
  19797. return;
  19798. }
  19799. var activeElement = document.activeElement;
  19800. if (editor.div.contains(activeElement) && !tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_editorFocusTimeoutId, "f")) {
  19801. editor._focusEventsAllowed = false;
  19802. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_editorFocusTimeoutId, setTimeout(function () {
  19803. tslib_1.__classPrivateFieldSet(_this, _AnnotationEditorLayer_editorFocusTimeoutId, null, "f");
  19804. if (!editor.div.contains(document.activeElement)) {
  19805. editor.div.addEventListener("focusin", function () {
  19806. editor._focusEventsAllowed = true;
  19807. }, {
  19808. once: true
  19809. });
  19810. activeElement.focus();
  19811. }
  19812. else {
  19813. editor._focusEventsAllowed = true;
  19814. }
  19815. }, 0), "f");
  19816. }
  19817. editor._structTreeParentId = (_r = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_accessibilityManager, "f")) === null || _r === void 0 ? void 0 : _r.moveElementInDOM(this.div, editor.div, editor.contentDiv, true);
  19818. };
  19819. AnnotationEditorLayer.prototype.addOrRebuild = function (editor) {
  19820. if (editor.needsToBeRebuilt()) {
  19821. editor.parent || (editor.parent = this);
  19822. editor.rebuild();
  19823. editor.show();
  19824. }
  19825. else {
  19826. this.add(editor);
  19827. }
  19828. };
  19829. AnnotationEditorLayer.prototype.addUndoableEditor = function (editor) {
  19830. var cmd = function () { return editor._uiManager.rebuild(editor); };
  19831. var undo = function () {
  19832. editor.remove();
  19833. };
  19834. this.addCommands({
  19835. cmd: cmd,
  19836. undo: undo,
  19837. mustExec: false
  19838. });
  19839. };
  19840. AnnotationEditorLayer.prototype.getNextId = function () {
  19841. return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").getId();
  19842. };
  19843. AnnotationEditorLayer.prototype.canCreateNewEmptyEditor = function () {
  19844. var _r;
  19845. return (_r = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_instances, "a", _AnnotationEditorLayer_currentEditorType_get)) === null || _r === void 0 ? void 0 : _r.canCreateNewEmptyEditor();
  19846. };
  19847. AnnotationEditorLayer.prototype.pasteEditor = function (mode, params) {
  19848. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").updateToolbar(mode);
  19849. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").updateMode(mode);
  19850. var _r = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_instances, "m", _AnnotationEditorLayer_getCenterPoint).call(this), offsetX = _r.offsetX, offsetY = _r.offsetY;
  19851. var id = this.getNextId();
  19852. var editor = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_instances, "m", _AnnotationEditorLayer_createNewEditor).call(this, tslib_1.__assign({ parent: this, id: id, x: offsetX, y: offsetY, uiManager: tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f"), isCentered: true }, params));
  19853. if (editor) {
  19854. this.add(editor);
  19855. }
  19856. };
  19857. AnnotationEditorLayer.prototype.deserialize = function (data) {
  19858. var _r, _s;
  19859. return ((_s = tslib_1.__classPrivateFieldGet(AnnotationEditorLayer, _q, "f", _AnnotationEditorLayer_editorTypes).get((_r = data.annotationType) !== null && _r !== void 0 ? _r : data.annotationEditorType)) === null || _s === void 0 ? void 0 : _s.deserialize(data, this, tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f"))) || null;
  19860. };
  19861. AnnotationEditorLayer.prototype.createAndAddNewEditor = function (event, isCentered, data) {
  19862. if (data === void 0) { data = {}; }
  19863. var id = this.getNextId();
  19864. var editor = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_instances, "m", _AnnotationEditorLayer_createNewEditor).call(this, tslib_1.__assign({ parent: this, id: id, x: event.offsetX, y: event.offsetY, uiManager: tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f"), isCentered: isCentered }, data));
  19865. if (editor) {
  19866. this.add(editor);
  19867. }
  19868. return editor;
  19869. };
  19870. AnnotationEditorLayer.prototype.addNewEditor = function () {
  19871. this.createAndAddNewEditor(tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_instances, "m", _AnnotationEditorLayer_getCenterPoint).call(this), true);
  19872. };
  19873. AnnotationEditorLayer.prototype.setSelected = function (editor) {
  19874. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").setSelected(editor);
  19875. };
  19876. AnnotationEditorLayer.prototype.toggleSelected = function (editor) {
  19877. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").toggleSelected(editor);
  19878. };
  19879. AnnotationEditorLayer.prototype.isSelected = function (editor) {
  19880. return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").isSelected(editor);
  19881. };
  19882. AnnotationEditorLayer.prototype.unselect = function (editor) {
  19883. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").unselect(editor);
  19884. };
  19885. AnnotationEditorLayer.prototype.pointerup = function (event) {
  19886. var isMac = util_FeatureTest.platform.isMac;
  19887. if (event.button !== 0 || event.ctrlKey && isMac) {
  19888. return;
  19889. }
  19890. if (event.target !== this.div) {
  19891. return;
  19892. }
  19893. if (!tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_hadPointerDown, "f")) {
  19894. return;
  19895. }
  19896. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_hadPointerDown, false, "f");
  19897. if (!tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_allowClick, "f")) {
  19898. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_allowClick, true, "f");
  19899. return;
  19900. }
  19901. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").getMode() === AnnotationEditorType.STAMP) {
  19902. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").unselectAll();
  19903. return;
  19904. }
  19905. this.createAndAddNewEditor(event, false);
  19906. };
  19907. AnnotationEditorLayer.prototype.pointerdown = function (event) {
  19908. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").getMode() === AnnotationEditorType.HIGHLIGHT) {
  19909. this.enableTextSelection();
  19910. }
  19911. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_hadPointerDown, "f")) {
  19912. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_hadPointerDown, false, "f");
  19913. return;
  19914. }
  19915. var isMac = util_FeatureTest.platform.isMac;
  19916. if (event.button !== 0 || event.ctrlKey && isMac) {
  19917. return;
  19918. }
  19919. if (event.target !== this.div) {
  19920. return;
  19921. }
  19922. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_hadPointerDown, true, "f");
  19923. var editor = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").getActive();
  19924. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_allowClick, !editor || editor.isEmpty(), "f");
  19925. };
  19926. AnnotationEditorLayer.prototype.findNewParent = function (editor, x, y) {
  19927. var layer = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").findParent(x, y);
  19928. if (layer === null || layer === this) {
  19929. return false;
  19930. }
  19931. layer.changeParent(editor);
  19932. return true;
  19933. };
  19934. AnnotationEditorLayer.prototype.destroy = function () {
  19935. var _r, _s;
  19936. if (((_r = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").getActive()) === null || _r === void 0 ? void 0 : _r.parent) === this) {
  19937. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").commitOrRemove();
  19938. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").setActiveEditor(null);
  19939. }
  19940. if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_editorFocusTimeoutId, "f")) {
  19941. clearTimeout(tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_editorFocusTimeoutId, "f"));
  19942. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_editorFocusTimeoutId, null, "f");
  19943. }
  19944. for (var _i = 0, _t = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_editors, "f").values(); _i < _t.length; _i++) {
  19945. var editor = _t[_i];
  19946. (_s = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_accessibilityManager, "f")) === null || _s === void 0 ? void 0 : _s.removePointerInTextLayer(editor.contentDiv);
  19947. editor.setParent(null);
  19948. editor.isAttachedToDOM = false;
  19949. editor.div.remove();
  19950. }
  19951. this.div = null;
  19952. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_editors, "f").clear();
  19953. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").removeLayer(this);
  19954. };
  19955. AnnotationEditorLayer.prototype.render = function (_r) {
  19956. var viewport = _r.viewport;
  19957. this.viewport = viewport;
  19958. setLayerDimensions(this.div, viewport);
  19959. for (var _i = 0, _s = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").getEditors(this.pageIndex); _i < _s.length; _i++) {
  19960. var editor = _s[_i];
  19961. this.add(editor);
  19962. editor.rebuild();
  19963. }
  19964. this.updateMode();
  19965. };
  19966. AnnotationEditorLayer.prototype.update = function (_r) {
  19967. var viewport = _r.viewport;
  19968. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").commitOrRemove();
  19969. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_instances, "m", _AnnotationEditorLayer_cleanup).call(this);
  19970. var oldRotation = this.viewport.rotation;
  19971. var rotation = viewport.rotation;
  19972. this.viewport = viewport;
  19973. setLayerDimensions(this.div, {
  19974. rotation: rotation
  19975. });
  19976. if (oldRotation !== rotation) {
  19977. for (var _i = 0, _s = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_editors, "f").values(); _i < _s.length; _i++) {
  19978. var editor = _s[_i];
  19979. editor.rotate(rotation);
  19980. }
  19981. }
  19982. this.addInkEditorIfNeeded(false);
  19983. };
  19984. Object.defineProperty(AnnotationEditorLayer.prototype, "pageDimensions", {
  19985. get: function () {
  19986. var _r = this.viewport.rawDims, pageWidth = _r.pageWidth, pageHeight = _r.pageHeight;
  19987. return [pageWidth, pageHeight];
  19988. },
  19989. enumerable: false,
  19990. configurable: true
  19991. });
  19992. Object.defineProperty(AnnotationEditorLayer.prototype, "scale", {
  19993. get: function () {
  19994. return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").viewParameters.realScale;
  19995. },
  19996. enumerable: false,
  19997. configurable: true
  19998. });
  19999. var _AnnotationEditorLayer_instances, _q, _AnnotationEditorLayer_accessibilityManager, _AnnotationEditorLayer_allowClick, _AnnotationEditorLayer_annotationLayer, _AnnotationEditorLayer_boundPointerup, _AnnotationEditorLayer_boundPointerdown, _AnnotationEditorLayer_boundTextLayerPointerDown, _AnnotationEditorLayer_editorFocusTimeoutId, _AnnotationEditorLayer_editors, _AnnotationEditorLayer_hadPointerDown, _AnnotationEditorLayer_isCleaningUp, _AnnotationEditorLayer_isDisabling, _AnnotationEditorLayer_textLayer, _AnnotationEditorLayer_uiManager, _AnnotationEditorLayer_editorTypes, _AnnotationEditorLayer_textLayerPointerDown, _AnnotationEditorLayer_currentEditorType_get, _AnnotationEditorLayer_createNewEditor, _AnnotationEditorLayer_getCenterPoint, _AnnotationEditorLayer_cleanup;
  20000. _q = AnnotationEditorLayer, _AnnotationEditorLayer_accessibilityManager = new WeakMap(), _AnnotationEditorLayer_allowClick = new WeakMap(), _AnnotationEditorLayer_annotationLayer = new WeakMap(), _AnnotationEditorLayer_boundPointerup = new WeakMap(), _AnnotationEditorLayer_boundPointerdown = new WeakMap(), _AnnotationEditorLayer_boundTextLayerPointerDown = new WeakMap(), _AnnotationEditorLayer_editorFocusTimeoutId = new WeakMap(), _AnnotationEditorLayer_editors = new WeakMap(), _AnnotationEditorLayer_hadPointerDown = new WeakMap(), _AnnotationEditorLayer_isCleaningUp = new WeakMap(), _AnnotationEditorLayer_isDisabling = new WeakMap(), _AnnotationEditorLayer_textLayer = new WeakMap(), _AnnotationEditorLayer_uiManager = new WeakMap(), _AnnotationEditorLayer_instances = new WeakSet(), _AnnotationEditorLayer_textLayerPointerDown = function _AnnotationEditorLayer_textLayerPointerDown(event) {
  20001. var _this = this;
  20002. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").unselectAll();
  20003. if (event.target === tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_textLayer, "f").div) {
  20004. var isMac = util_FeatureTest.platform.isMac;
  20005. if (event.button !== 0 || event.ctrlKey && isMac) {
  20006. return;
  20007. }
  20008. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").showAllEditors("highlight", true, true);
  20009. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_textLayer, "f").div.classList.add("free");
  20010. HighlightEditor.startHighlighting(this, tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").direction === "ltr", event);
  20011. tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_textLayer, "f").div.addEventListener("pointerup", function () {
  20012. tslib_1.__classPrivateFieldGet(_this, _AnnotationEditorLayer_textLayer, "f").div.classList.remove("free");
  20013. }, {
  20014. once: true
  20015. });
  20016. event.preventDefault();
  20017. }
  20018. }, _AnnotationEditorLayer_currentEditorType_get = function _AnnotationEditorLayer_currentEditorType_get() {
  20019. return tslib_1.__classPrivateFieldGet(AnnotationEditorLayer, _q, "f", _AnnotationEditorLayer_editorTypes).get(tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").getMode());
  20020. }, _AnnotationEditorLayer_createNewEditor = function _AnnotationEditorLayer_createNewEditor(params) {
  20021. var editorType = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_instances, "a", _AnnotationEditorLayer_currentEditorType_get);
  20022. return editorType ? new editorType.prototype.constructor(params) : null;
  20023. }, _AnnotationEditorLayer_getCenterPoint = function _AnnotationEditorLayer_getCenterPoint() {
  20024. var _r = this.div.getBoundingClientRect(), x = _r.x, y = _r.y, width = _r.width, height = _r.height;
  20025. var tlX = Math.max(0, x);
  20026. var tlY = Math.max(0, y);
  20027. var brX = Math.min(window.innerWidth, x + width);
  20028. var brY = Math.min(window.innerHeight, y + height);
  20029. var centerX = (tlX + brX) / 2 - x;
  20030. var centerY = (tlY + brY) / 2 - y;
  20031. var _s = this.viewport.rotation % 180 === 0 ? [centerX, centerY] : [centerY, centerX], offsetX = _s[0], offsetY = _s[1];
  20032. return {
  20033. offsetX: offsetX,
  20034. offsetY: offsetY
  20035. };
  20036. }, _AnnotationEditorLayer_cleanup = function _AnnotationEditorLayer_cleanup() {
  20037. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_isCleaningUp, true, "f");
  20038. for (var _i = 0, _r = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_editors, "f").values(); _i < _r.length; _i++) {
  20039. var editor = _r[_i];
  20040. if (editor.isEmpty()) {
  20041. editor.remove();
  20042. }
  20043. }
  20044. tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_isCleaningUp, false, "f");
  20045. };
  20046. AnnotationEditorLayer._initialized = false;
  20047. _AnnotationEditorLayer_editorTypes = { value: new Map([FreeTextEditor, InkEditor, StampEditor, HighlightEditor].map(function (type) { return [type._editorType, type]; })) };
  20048. return AnnotationEditorLayer;
  20049. }());
  20050. ; // CONCATENATED MODULE: ./src/display/draw_layer.js
  20051. var DrawLayer = /** @class */ (function () {
  20052. function DrawLayer(_r) {
  20053. var pageIndex = _r.pageIndex;
  20054. _DrawLayer_instances.add(this);
  20055. _DrawLayer_parent.set(this, null);
  20056. _DrawLayer_id.set(this, 0);
  20057. _DrawLayer_mapping.set(this, new Map());
  20058. _DrawLayer_toUpdate.set(this, new Map());
  20059. this.pageIndex = pageIndex;
  20060. }
  20061. DrawLayer.prototype.setParent = function (parent) {
  20062. if (!tslib_1.__classPrivateFieldGet(this, _DrawLayer_parent, "f")) {
  20063. tslib_1.__classPrivateFieldSet(this, _DrawLayer_parent, parent, "f");
  20064. return;
  20065. }
  20066. if (tslib_1.__classPrivateFieldGet(this, _DrawLayer_parent, "f") !== parent) {
  20067. if (tslib_1.__classPrivateFieldGet(this, _DrawLayer_mapping, "f").size > 0) {
  20068. for (var _i = 0, _r = tslib_1.__classPrivateFieldGet(this, _DrawLayer_mapping, "f").values(); _i < _r.length; _i++) {
  20069. var root = _r[_i];
  20070. root.remove();
  20071. parent.append(root);
  20072. }
  20073. }
  20074. tslib_1.__classPrivateFieldSet(this, _DrawLayer_parent, parent, "f");
  20075. }
  20076. };
  20077. Object.defineProperty(DrawLayer, "_svgFactory", {
  20078. get: function () {
  20079. return shadow(this, "_svgFactory", new DOMSVGFactory());
  20080. },
  20081. enumerable: false,
  20082. configurable: true
  20083. });
  20084. DrawLayer.prototype.highlight = function (outlines, color, opacity, isPathUpdatable) {
  20085. var _r, _s;
  20086. if (isPathUpdatable === void 0) { isPathUpdatable = false; }
  20087. var id = (tslib_1.__classPrivateFieldSet(this, _DrawLayer_id, (_s = tslib_1.__classPrivateFieldGet(this, _DrawLayer_id, "f"), _r = _s++, _s), "f"), _r);
  20088. var root = tslib_1.__classPrivateFieldGet(this, _DrawLayer_instances, "m", _DrawLayer_createSVG).call(this, outlines.box);
  20089. root.classList.add("highlight");
  20090. if (outlines.free) {
  20091. root.classList.add("free");
  20092. }
  20093. var defs = DrawLayer._svgFactory.createElement("defs");
  20094. root.append(defs);
  20095. var path = DrawLayer._svgFactory.createElement("path");
  20096. defs.append(path);
  20097. var pathId = "path_p".concat(this.pageIndex, "_").concat(id);
  20098. path.setAttribute("id", pathId);
  20099. path.setAttribute("d", outlines.toSVGPath());
  20100. if (isPathUpdatable) {
  20101. tslib_1.__classPrivateFieldGet(this, _DrawLayer_toUpdate, "f").set(id, path);
  20102. }
  20103. var clipPathId = tslib_1.__classPrivateFieldGet(this, _DrawLayer_instances, "m", _DrawLayer_createClipPath).call(this, defs, pathId);
  20104. var use = DrawLayer._svgFactory.createElement("use");
  20105. root.append(use);
  20106. root.setAttribute("fill", color);
  20107. root.setAttribute("fill-opacity", opacity);
  20108. use.setAttribute("href", "#".concat(pathId));
  20109. tslib_1.__classPrivateFieldGet(this, _DrawLayer_mapping, "f").set(id, root);
  20110. return {
  20111. id: id,
  20112. clipPathId: "url(#".concat(clipPathId, ")")
  20113. };
  20114. };
  20115. DrawLayer.prototype.highlightOutline = function (outlines) {
  20116. var _r, _s;
  20117. var id = (tslib_1.__classPrivateFieldSet(this, _DrawLayer_id, (_s = tslib_1.__classPrivateFieldGet(this, _DrawLayer_id, "f"), _r = _s++, _s), "f"), _r);
  20118. var root = tslib_1.__classPrivateFieldGet(this, _DrawLayer_instances, "m", _DrawLayer_createSVG).call(this, outlines.box);
  20119. root.classList.add("highlightOutline");
  20120. var defs = DrawLayer._svgFactory.createElement("defs");
  20121. root.append(defs);
  20122. var path = DrawLayer._svgFactory.createElement("path");
  20123. defs.append(path);
  20124. var pathId = "path_p".concat(this.pageIndex, "_").concat(id);
  20125. path.setAttribute("id", pathId);
  20126. path.setAttribute("d", outlines.toSVGPath());
  20127. path.setAttribute("vector-effect", "non-scaling-stroke");
  20128. var maskId;
  20129. if (outlines.free) {
  20130. root.classList.add("free");
  20131. var mask = DrawLayer._svgFactory.createElement("mask");
  20132. defs.append(mask);
  20133. maskId = "mask_p".concat(this.pageIndex, "_").concat(id);
  20134. mask.setAttribute("id", maskId);
  20135. mask.setAttribute("maskUnits", "objectBoundingBox");
  20136. var rect = DrawLayer._svgFactory.createElement("rect");
  20137. mask.append(rect);
  20138. rect.setAttribute("width", "1");
  20139. rect.setAttribute("height", "1");
  20140. rect.setAttribute("fill", "white");
  20141. var use = DrawLayer._svgFactory.createElement("use");
  20142. mask.append(use);
  20143. use.setAttribute("href", "#".concat(pathId));
  20144. use.setAttribute("stroke", "none");
  20145. use.setAttribute("fill", "black");
  20146. use.setAttribute("fill-rule", "nonzero");
  20147. use.classList.add("mask");
  20148. }
  20149. var use1 = DrawLayer._svgFactory.createElement("use");
  20150. root.append(use1);
  20151. use1.setAttribute("href", "#".concat(pathId));
  20152. if (maskId) {
  20153. use1.setAttribute("mask", "url(#".concat(maskId, ")"));
  20154. }
  20155. var use2 = use1.cloneNode();
  20156. root.append(use2);
  20157. use1.classList.add("mainOutline");
  20158. use2.classList.add("secondaryOutline");
  20159. tslib_1.__classPrivateFieldGet(this, _DrawLayer_mapping, "f").set(id, root);
  20160. return id;
  20161. };
  20162. DrawLayer.prototype.finalizeLine = function (id, line) {
  20163. var path = tslib_1.__classPrivateFieldGet(this, _DrawLayer_toUpdate, "f").get(id);
  20164. tslib_1.__classPrivateFieldGet(this, _DrawLayer_toUpdate, "f").delete(id);
  20165. this.updateBox(id, line.box);
  20166. path.setAttribute("d", line.toSVGPath());
  20167. };
  20168. DrawLayer.prototype.updateLine = function (id, line) {
  20169. var root = tslib_1.__classPrivateFieldGet(this, _DrawLayer_mapping, "f").get(id);
  20170. var defs = root.firstChild;
  20171. var path = defs.firstChild;
  20172. path.setAttribute("d", line.toSVGPath());
  20173. };
  20174. DrawLayer.prototype.removeFreeHighlight = function (id) {
  20175. this.remove(id);
  20176. tslib_1.__classPrivateFieldGet(this, _DrawLayer_toUpdate, "f").delete(id);
  20177. };
  20178. DrawLayer.prototype.updatePath = function (id, line) {
  20179. tslib_1.__classPrivateFieldGet(this, _DrawLayer_toUpdate, "f").get(id).setAttribute("d", line.toSVGPath());
  20180. };
  20181. DrawLayer.prototype.updateBox = function (id, box) {
  20182. tslib_1.__classPrivateFieldGet(DrawLayer, _d, "m", _DrawLayer_setBox).call(DrawLayer, tslib_1.__classPrivateFieldGet(this, _DrawLayer_mapping, "f").get(id), box);
  20183. };
  20184. DrawLayer.prototype.show = function (id, visible) {
  20185. tslib_1.__classPrivateFieldGet(this, _DrawLayer_mapping, "f").get(id).classList.toggle("hidden", !visible);
  20186. };
  20187. DrawLayer.prototype.rotate = function (id, angle) {
  20188. tslib_1.__classPrivateFieldGet(this, _DrawLayer_mapping, "f").get(id).setAttribute("data-main-rotation", angle);
  20189. };
  20190. DrawLayer.prototype.changeColor = function (id, color) {
  20191. tslib_1.__classPrivateFieldGet(this, _DrawLayer_mapping, "f").get(id).setAttribute("fill", color);
  20192. };
  20193. DrawLayer.prototype.changeOpacity = function (id, opacity) {
  20194. tslib_1.__classPrivateFieldGet(this, _DrawLayer_mapping, "f").get(id).setAttribute("fill-opacity", opacity);
  20195. };
  20196. DrawLayer.prototype.addClass = function (id, className) {
  20197. tslib_1.__classPrivateFieldGet(this, _DrawLayer_mapping, "f").get(id).classList.add(className);
  20198. };
  20199. DrawLayer.prototype.removeClass = function (id, className) {
  20200. tslib_1.__classPrivateFieldGet(this, _DrawLayer_mapping, "f").get(id).classList.remove(className);
  20201. };
  20202. DrawLayer.prototype.remove = function (id) {
  20203. if (tslib_1.__classPrivateFieldGet(this, _DrawLayer_parent, "f") === null) {
  20204. return;
  20205. }
  20206. tslib_1.__classPrivateFieldGet(this, _DrawLayer_mapping, "f").get(id).remove();
  20207. tslib_1.__classPrivateFieldGet(this, _DrawLayer_mapping, "f").delete(id);
  20208. };
  20209. DrawLayer.prototype.destroy = function () {
  20210. tslib_1.__classPrivateFieldSet(this, _DrawLayer_parent, null, "f");
  20211. for (var _i = 0, _r = tslib_1.__classPrivateFieldGet(this, _DrawLayer_mapping, "f").values(); _i < _r.length; _i++) {
  20212. var root = _r[_i];
  20213. root.remove();
  20214. }
  20215. tslib_1.__classPrivateFieldGet(this, _DrawLayer_mapping, "f").clear();
  20216. };
  20217. return DrawLayer;
  20218. }());
  20219. _d = DrawLayer, _DrawLayer_parent = new WeakMap(), _DrawLayer_id = new WeakMap(), _DrawLayer_mapping = new WeakMap(), _DrawLayer_toUpdate = new WeakMap(), _DrawLayer_instances = new WeakSet(), _DrawLayer_setBox = function _DrawLayer_setBox(element, _r) {
  20220. var _s = _r === void 0 ? {} : _r, _t = _s.x, x = _t === void 0 ? 0 : _t, _u = _s.y, y = _u === void 0 ? 0 : _u, _v = _s.width, width = _v === void 0 ? 1 : _v, _w = _s.height, height = _w === void 0 ? 1 : _w;
  20221. var style = element.style;
  20222. style.top = "".concat(100 * y, "%");
  20223. style.left = "".concat(100 * x, "%");
  20224. style.width = "".concat(100 * width, "%");
  20225. style.height = "".concat(100 * height, "%");
  20226. }, _DrawLayer_createSVG = function _DrawLayer_createSVG(box) {
  20227. var svg = DrawLayer._svgFactory.create(1, 1, true);
  20228. tslib_1.__classPrivateFieldGet(this, _DrawLayer_parent, "f").append(svg);
  20229. svg.setAttribute("aria-hidden", true);
  20230. tslib_1.__classPrivateFieldGet(DrawLayer, _d, "m", _DrawLayer_setBox).call(DrawLayer, svg, box);
  20231. return svg;
  20232. }, _DrawLayer_createClipPath = function _DrawLayer_createClipPath(defs, pathId) {
  20233. var clipPath = DrawLayer._svgFactory.createElement("clipPath");
  20234. defs.append(clipPath);
  20235. var clipPathId = "clip_".concat(pathId);
  20236. clipPath.setAttribute("id", clipPathId);
  20237. clipPath.setAttribute("clipPathUnits", "objectBoundingBox");
  20238. var clipPathUse = DrawLayer._svgFactory.createElement("use");
  20239. clipPath.append(clipPathUse);
  20240. clipPathUse.setAttribute("href", "#".concat(pathId));
  20241. clipPathUse.classList.add("clip");
  20242. return clipPathId;
  20243. };
  20244. ; // CONCATENATED MODULE: ./src/pdf.js
  20245. var pdfjsVersion = "4.3.136";
  20246. var pdfjsBuild = "0cec64437";
  20247. var __webpack_exports__AbortException = __webpack_exports__.AbortException;
  20248. exports.AbortException = __webpack_exports__AbortException;
  20249. var __webpack_exports__AnnotationEditorLayer = __webpack_exports__.AnnotationEditorLayer;
  20250. exports.AnnotationEditorLayer = __webpack_exports__AnnotationEditorLayer;
  20251. var __webpack_exports__AnnotationEditorParamsType = __webpack_exports__.AnnotationEditorParamsType;
  20252. exports.AnnotationEditorParamsType = __webpack_exports__AnnotationEditorParamsType;
  20253. var __webpack_exports__AnnotationEditorType = __webpack_exports__.AnnotationEditorType;
  20254. exports.AnnotationEditorType = __webpack_exports__AnnotationEditorType;
  20255. var __webpack_exports__AnnotationEditorUIManager = __webpack_exports__.AnnotationEditorUIManager;
  20256. exports.AnnotationEditorUIManager = __webpack_exports__AnnotationEditorUIManager;
  20257. var __webpack_exports__AnnotationLayer = __webpack_exports__.AnnotationLayer;
  20258. exports.AnnotationLayer = __webpack_exports__AnnotationLayer;
  20259. var __webpack_exports__AnnotationMode = __webpack_exports__.AnnotationMode;
  20260. exports.AnnotationMode = __webpack_exports__AnnotationMode;
  20261. var __webpack_exports__CMapCompressionType = __webpack_exports__.CMapCompressionType;
  20262. exports.CMapCompressionType = __webpack_exports__CMapCompressionType;
  20263. var __webpack_exports__ColorPicker = __webpack_exports__.ColorPicker;
  20264. exports.ColorPicker = __webpack_exports__ColorPicker;
  20265. var __webpack_exports__DOMSVGFactory = __webpack_exports__.DOMSVGFactory;
  20266. exports.DOMSVGFactory = __webpack_exports__DOMSVGFactory;
  20267. var __webpack_exports__DrawLayer = __webpack_exports__.DrawLayer;
  20268. exports.DrawLayer = __webpack_exports__DrawLayer;
  20269. var __webpack_exports__FeatureTest = __webpack_exports__.FeatureTest;
  20270. exports.FeatureTest = __webpack_exports__FeatureTest;
  20271. var __webpack_exports__GlobalWorkerOptions = __webpack_exports__.GlobalWorkerOptions;
  20272. exports.GlobalWorkerOptions = __webpack_exports__GlobalWorkerOptions;
  20273. var __webpack_exports__ImageKind = __webpack_exports__.ImageKind;
  20274. exports.ImageKind = __webpack_exports__ImageKind;
  20275. var __webpack_exports__InvalidPDFException = __webpack_exports__.InvalidPDFException;
  20276. exports.InvalidPDFException = __webpack_exports__InvalidPDFException;
  20277. var __webpack_exports__MissingPDFException = __webpack_exports__.MissingPDFException;
  20278. exports.MissingPDFException = __webpack_exports__MissingPDFException;
  20279. var __webpack_exports__OPS = __webpack_exports__.OPS;
  20280. exports.OPS = __webpack_exports__OPS;
  20281. var __webpack_exports__Outliner = __webpack_exports__.Outliner;
  20282. exports.Outliner = __webpack_exports__Outliner;
  20283. var __webpack_exports__PDFDataRangeTransport = __webpack_exports__.PDFDataRangeTransport;
  20284. exports.PDFDataRangeTransport = __webpack_exports__PDFDataRangeTransport;
  20285. var __webpack_exports__PDFDateString = __webpack_exports__.PDFDateString;
  20286. exports.PDFDateString = __webpack_exports__PDFDateString;
  20287. var __webpack_exports__PDFWorker = __webpack_exports__.PDFWorker;
  20288. exports.PDFWorker = __webpack_exports__PDFWorker;
  20289. var __webpack_exports__PasswordResponses = __webpack_exports__.PasswordResponses;
  20290. exports.PasswordResponses = __webpack_exports__PasswordResponses;
  20291. var __webpack_exports__PermissionFlag = __webpack_exports__.PermissionFlag;
  20292. exports.PermissionFlag = __webpack_exports__PermissionFlag;
  20293. var __webpack_exports__PixelsPerInch = __webpack_exports__.PixelsPerInch;
  20294. exports.PixelsPerInch = __webpack_exports__PixelsPerInch;
  20295. var __webpack_exports__RenderingCancelledException = __webpack_exports__.RenderingCancelledException;
  20296. exports.RenderingCancelledException = __webpack_exports__RenderingCancelledException;
  20297. var __webpack_exports__TextLayer = __webpack_exports__.TextLayer;
  20298. exports.TextLayer = __webpack_exports__TextLayer;
  20299. var __webpack_exports__UnexpectedResponseException = __webpack_exports__.UnexpectedResponseException;
  20300. exports.UnexpectedResponseException = __webpack_exports__UnexpectedResponseException;
  20301. var __webpack_exports__Util = __webpack_exports__.Util;
  20302. exports.Util = __webpack_exports__Util;
  20303. var __webpack_exports__VerbosityLevel = __webpack_exports__.VerbosityLevel;
  20304. exports.VerbosityLevel = __webpack_exports__VerbosityLevel;
  20305. var __webpack_exports__XfaLayer = __webpack_exports__.XfaLayer;
  20306. exports.XfaLayer = __webpack_exports__XfaLayer;
  20307. var __webpack_exports__build = __webpack_exports__.build;
  20308. exports.build = __webpack_exports__build;
  20309. var __webpack_exports__createValidAbsoluteUrl = __webpack_exports__.createValidAbsoluteUrl;
  20310. exports.createValidAbsoluteUrl = __webpack_exports__createValidAbsoluteUrl;
  20311. var __webpack_exports__fetchData = __webpack_exports__.fetchData;
  20312. exports.fetchData = __webpack_exports__fetchData;
  20313. var __webpack_exports__getDocument = __webpack_exports__.getDocument;
  20314. exports.getDocument = __webpack_exports__getDocument;
  20315. var __webpack_exports__getFilenameFromUrl = __webpack_exports__.getFilenameFromUrl;
  20316. exports.getFilenameFromUrl = __webpack_exports__getFilenameFromUrl;
  20317. var __webpack_exports__getPdfFilenameFromUrl = __webpack_exports__.getPdfFilenameFromUrl;
  20318. exports.getPdfFilenameFromUrl = __webpack_exports__getPdfFilenameFromUrl;
  20319. var __webpack_exports__getXfaPageViewport = __webpack_exports__.getXfaPageViewport;
  20320. exports.getXfaPageViewport = __webpack_exports__getXfaPageViewport;
  20321. var __webpack_exports__isDataScheme = __webpack_exports__.isDataScheme;
  20322. exports.isDataScheme = __webpack_exports__isDataScheme;
  20323. var __webpack_exports__isPdfFile = __webpack_exports__.isPdfFile;
  20324. exports.isPdfFile = __webpack_exports__isPdfFile;
  20325. var __webpack_exports__noContextMenu = __webpack_exports__.noContextMenu;
  20326. exports.noContextMenu = __webpack_exports__noContextMenu;
  20327. var __webpack_exports__normalizeUnicode = __webpack_exports__.normalizeUnicode;
  20328. exports.normalizeUnicode = __webpack_exports__normalizeUnicode;
  20329. var __webpack_exports__renderTextLayer = __webpack_exports__.renderTextLayer;
  20330. exports.renderTextLayer = __webpack_exports__renderTextLayer;
  20331. var __webpack_exports__setLayerDimensions = __webpack_exports__.setLayerDimensions;
  20332. exports.setLayerDimensions = __webpack_exports__setLayerDimensions;
  20333. var __webpack_exports__shadow = __webpack_exports__.shadow;
  20334. exports.shadow = __webpack_exports__shadow;
  20335. var __webpack_exports__updateTextLayer = __webpack_exports__.updateTextLayer;
  20336. exports.updateTextLayer = __webpack_exports__updateTextLayer;
  20337. var __webpack_exports__version = __webpack_exports__.version;
  20338. exports.version = __webpack_exports__version;
  20339. //# sourceMappingURL=./thirds/pdfjs-dist/build/pdf.mjs.map
  20340. });