pdf.js 397 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2021 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. (function webpackUniversalModuleDefinition(root, factory) {
  23. if(typeof exports === 'object' && typeof module === 'object')
  24. module.exports = factory();
  25. else if(typeof define === 'function' && define.amd)
  26. define("pdfjs-dist/build/pdf", [], factory);
  27. else if(typeof exports === 'object')
  28. exports["pdfjs-dist/build/pdf"] = factory();
  29. else
  30. root["pdfjs-dist/build/pdf"] = root.pdfjsLib = factory();
  31. })(this, function() {
  32. return /******/ (() => { // webpackBootstrap
  33. /******/ "use strict";
  34. /******/ var __webpack_modules__ = ([
  35. /* 0 */,
  36. /* 1 */
  37. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  38. Object.defineProperty(exports, "__esModule", ({
  39. value: true
  40. }));
  41. exports.addLinkAttributes = addLinkAttributes;
  42. exports.deprecated = deprecated;
  43. exports.getFilenameFromUrl = getFilenameFromUrl;
  44. exports.getPdfFilenameFromUrl = getPdfFilenameFromUrl;
  45. exports.isDataScheme = isDataScheme;
  46. exports.isFetchSupported = isFetchSupported;
  47. exports.isPdfFile = isPdfFile;
  48. exports.isValidFetchUrl = isValidFetchUrl;
  49. exports.loadScript = loadScript;
  50. exports.StatTimer = exports.RenderingCancelledException = exports.PDFDateString = exports.PageViewport = exports.LinkTarget = exports.DOMSVGFactory = exports.DOMCMapReaderFactory = exports.DOMCanvasFactory = exports.DEFAULT_LINK_REL = exports.BaseCMapReaderFactory = exports.BaseCanvasFactory = void 0;
  51. var _util = __w_pdfjs_require__(2);
  52. const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
  53. exports.DEFAULT_LINK_REL = DEFAULT_LINK_REL;
  54. const SVG_NS = "http://www.w3.org/2000/svg";
  55. class BaseCanvasFactory {
  56. constructor() {
  57. if (this.constructor === BaseCanvasFactory) {
  58. (0, _util.unreachable)("Cannot initialize BaseCanvasFactory.");
  59. }
  60. }
  61. create(width, height) {
  62. (0, _util.unreachable)("Abstract method `create` called.");
  63. }
  64. reset(canvasAndContext, width, height) {
  65. if (!canvasAndContext.canvas) {
  66. throw new Error("Canvas is not specified");
  67. }
  68. if (width <= 0 || height <= 0) {
  69. throw new Error("Invalid canvas size");
  70. }
  71. canvasAndContext.canvas.width = width;
  72. canvasAndContext.canvas.height = height;
  73. }
  74. destroy(canvasAndContext) {
  75. if (!canvasAndContext.canvas) {
  76. throw new Error("Canvas is not specified");
  77. }
  78. canvasAndContext.canvas.width = 0;
  79. canvasAndContext.canvas.height = 0;
  80. canvasAndContext.canvas = null;
  81. canvasAndContext.context = null;
  82. }
  83. }
  84. exports.BaseCanvasFactory = BaseCanvasFactory;
  85. class DOMCanvasFactory extends BaseCanvasFactory {
  86. constructor({
  87. ownerDocument = globalThis.document
  88. } = {}) {
  89. super();
  90. this._document = ownerDocument;
  91. }
  92. create(width, height) {
  93. if (width <= 0 || height <= 0) {
  94. throw new Error("Invalid canvas size");
  95. }
  96. const canvas = this._document.createElement("canvas");
  97. const context = canvas.getContext("2d");
  98. canvas.width = width;
  99. canvas.height = height;
  100. return {
  101. canvas,
  102. context
  103. };
  104. }
  105. }
  106. exports.DOMCanvasFactory = DOMCanvasFactory;
  107. class BaseCMapReaderFactory {
  108. constructor({
  109. baseUrl = null,
  110. isCompressed = false
  111. }) {
  112. if (this.constructor === BaseCMapReaderFactory) {
  113. (0, _util.unreachable)("Cannot initialize BaseCMapReaderFactory.");
  114. }
  115. this.baseUrl = baseUrl;
  116. this.isCompressed = isCompressed;
  117. }
  118. async fetch({
  119. name
  120. }) {
  121. if (!this.baseUrl) {
  122. throw new Error('The CMap "baseUrl" parameter must be specified, ensure that ' + 'the "cMapUrl" and "cMapPacked" API parameters are provided.');
  123. }
  124. if (!name) {
  125. throw new Error("CMap name must be specified.");
  126. }
  127. const url = this.baseUrl + name + (this.isCompressed ? ".bcmap" : "");
  128. const compressionType = this.isCompressed ? _util.CMapCompressionType.BINARY : _util.CMapCompressionType.NONE;
  129. return this._fetchData(url, compressionType).catch(reason => {
  130. throw new Error(`Unable to load ${this.isCompressed ? "binary " : ""}CMap at: ${url}`);
  131. });
  132. }
  133. _fetchData(url, compressionType) {
  134. (0, _util.unreachable)("Abstract method `_fetchData` called.");
  135. }
  136. }
  137. exports.BaseCMapReaderFactory = BaseCMapReaderFactory;
  138. class DOMCMapReaderFactory extends BaseCMapReaderFactory {
  139. _fetchData(url, compressionType) {
  140. if (isFetchSupported() && isValidFetchUrl(url, document.baseURI)) {
  141. return fetch(url).then(async response => {
  142. if (!response.ok) {
  143. throw new Error(response.statusText);
  144. }
  145. let cMapData;
  146. if (this.isCompressed) {
  147. cMapData = new Uint8Array(await response.arrayBuffer());
  148. } else {
  149. cMapData = (0, _util.stringToBytes)(await response.text());
  150. }
  151. return {
  152. cMapData,
  153. compressionType
  154. };
  155. });
  156. }
  157. return new Promise((resolve, reject) => {
  158. const request = new XMLHttpRequest();
  159. request.open("GET", url, true);
  160. if (this.isCompressed) {
  161. request.responseType = "arraybuffer";
  162. }
  163. request.onreadystatechange = () => {
  164. if (request.readyState !== XMLHttpRequest.DONE) {
  165. return;
  166. }
  167. if (request.status === 200 || request.status === 0) {
  168. let cMapData;
  169. if (this.isCompressed && request.response) {
  170. cMapData = new Uint8Array(request.response);
  171. } else if (!this.isCompressed && request.responseText) {
  172. cMapData = (0, _util.stringToBytes)(request.responseText);
  173. }
  174. if (cMapData) {
  175. resolve({
  176. cMapData,
  177. compressionType
  178. });
  179. return;
  180. }
  181. }
  182. reject(new Error(request.statusText));
  183. };
  184. request.send(null);
  185. });
  186. }
  187. }
  188. exports.DOMCMapReaderFactory = DOMCMapReaderFactory;
  189. class DOMSVGFactory {
  190. create(width, height) {
  191. (0, _util.assert)(width > 0 && height > 0, "Invalid SVG dimensions");
  192. const svg = document.createElementNS(SVG_NS, "svg:svg");
  193. svg.setAttribute("version", "1.1");
  194. svg.setAttribute("width", width + "px");
  195. svg.setAttribute("height", height + "px");
  196. svg.setAttribute("preserveAspectRatio", "none");
  197. svg.setAttribute("viewBox", "0 0 " + width + " " + height);
  198. return svg;
  199. }
  200. createElement(type) {
  201. (0, _util.assert)(typeof type === "string", "Invalid SVG element type");
  202. return document.createElementNS(SVG_NS, type);
  203. }
  204. }
  205. exports.DOMSVGFactory = DOMSVGFactory;
  206. class PageViewport {
  207. constructor({
  208. viewBox,
  209. scale,
  210. rotation,
  211. offsetX = 0,
  212. offsetY = 0,
  213. dontFlip = false
  214. }) {
  215. this.viewBox = viewBox;
  216. this.scale = scale;
  217. this.rotation = rotation;
  218. this.offsetX = offsetX;
  219. this.offsetY = offsetY;
  220. const centerX = (viewBox[2] + viewBox[0]) / 2;
  221. const centerY = (viewBox[3] + viewBox[1]) / 2;
  222. let rotateA, rotateB, rotateC, rotateD;
  223. rotation %= 360;
  224. if (rotation < 0) {
  225. rotation += 360;
  226. }
  227. switch (rotation) {
  228. case 180:
  229. rotateA = -1;
  230. rotateB = 0;
  231. rotateC = 0;
  232. rotateD = 1;
  233. break;
  234. case 90:
  235. rotateA = 0;
  236. rotateB = 1;
  237. rotateC = 1;
  238. rotateD = 0;
  239. break;
  240. case 270:
  241. rotateA = 0;
  242. rotateB = -1;
  243. rotateC = -1;
  244. rotateD = 0;
  245. break;
  246. case 0:
  247. rotateA = 1;
  248. rotateB = 0;
  249. rotateC = 0;
  250. rotateD = -1;
  251. break;
  252. default:
  253. throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.");
  254. }
  255. if (dontFlip) {
  256. rotateC = -rotateC;
  257. rotateD = -rotateD;
  258. }
  259. let offsetCanvasX, offsetCanvasY;
  260. let width, height;
  261. if (rotateA === 0) {
  262. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  263. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  264. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  265. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  266. } else {
  267. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  268. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  269. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  270. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  271. }
  272. this.transform = [rotateA * scale, rotateB * scale, rotateC * scale, rotateD * scale, offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY, offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY];
  273. this.width = width;
  274. this.height = height;
  275. }
  276. clone({
  277. scale = this.scale,
  278. rotation = this.rotation,
  279. offsetX = this.offsetX,
  280. offsetY = this.offsetY,
  281. dontFlip = false
  282. } = {}) {
  283. return new PageViewport({
  284. viewBox: this.viewBox.slice(),
  285. scale,
  286. rotation,
  287. offsetX,
  288. offsetY,
  289. dontFlip
  290. });
  291. }
  292. convertToViewportPoint(x, y) {
  293. return _util.Util.applyTransform([x, y], this.transform);
  294. }
  295. convertToViewportRectangle(rect) {
  296. const topLeft = _util.Util.applyTransform([rect[0], rect[1]], this.transform);
  297. const bottomRight = _util.Util.applyTransform([rect[2], rect[3]], this.transform);
  298. return [topLeft[0], topLeft[1], bottomRight[0], bottomRight[1]];
  299. }
  300. convertToPdfPoint(x, y) {
  301. return _util.Util.applyInverseTransform([x, y], this.transform);
  302. }
  303. }
  304. exports.PageViewport = PageViewport;
  305. class RenderingCancelledException extends _util.BaseException {
  306. constructor(msg, type) {
  307. super(msg);
  308. this.type = type;
  309. }
  310. }
  311. exports.RenderingCancelledException = RenderingCancelledException;
  312. const LinkTarget = {
  313. NONE: 0,
  314. SELF: 1,
  315. BLANK: 2,
  316. PARENT: 3,
  317. TOP: 4
  318. };
  319. exports.LinkTarget = LinkTarget;
  320. function addLinkAttributes(link, {
  321. url,
  322. target,
  323. rel,
  324. enabled = true
  325. } = {}) {
  326. (0, _util.assert)(url && typeof url === "string", 'addLinkAttributes: A valid "url" parameter must provided.');
  327. const urlNullRemoved = (0, _util.removeNullCharacters)(url);
  328. if (enabled) {
  329. link.href = link.title = urlNullRemoved;
  330. } else {
  331. link.href = "";
  332. link.title = `Disabled: ${urlNullRemoved}`;
  333. link.onclick = () => {
  334. return false;
  335. };
  336. }
  337. let targetStr = "";
  338. switch (target) {
  339. case LinkTarget.NONE:
  340. break;
  341. case LinkTarget.SELF:
  342. targetStr = "_self";
  343. break;
  344. case LinkTarget.BLANK:
  345. targetStr = "_blank";
  346. break;
  347. case LinkTarget.PARENT:
  348. targetStr = "_parent";
  349. break;
  350. case LinkTarget.TOP:
  351. targetStr = "_top";
  352. break;
  353. }
  354. link.target = targetStr;
  355. link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL;
  356. }
  357. function isDataScheme(url) {
  358. const ii = url.length;
  359. let i = 0;
  360. while (i < ii && url[i].trim() === "") {
  361. i++;
  362. }
  363. return url.substring(i, i + 5).toLowerCase() === "data:";
  364. }
  365. function isPdfFile(filename) {
  366. return typeof filename === "string" && /\.pdf$/i.test(filename);
  367. }
  368. function getFilenameFromUrl(url) {
  369. const anchor = url.indexOf("#");
  370. const query = url.indexOf("?");
  371. const end = Math.min(anchor > 0 ? anchor : url.length, query > 0 ? query : url.length);
  372. return url.substring(url.lastIndexOf("/", end) + 1, end);
  373. }
  374. function getPdfFilenameFromUrl(url, defaultFilename = "document.pdf") {
  375. if (typeof url !== "string") {
  376. return defaultFilename;
  377. }
  378. if (isDataScheme(url)) {
  379. (0, _util.warn)('getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.');
  380. return defaultFilename;
  381. }
  382. const reURI = /^(?:(?:[^:]+:)?\/\/[^/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
  383. const reFilename = /[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
  384. const splitURI = reURI.exec(url);
  385. let suggestedFilename = reFilename.exec(splitURI[1]) || reFilename.exec(splitURI[2]) || reFilename.exec(splitURI[3]);
  386. if (suggestedFilename) {
  387. suggestedFilename = suggestedFilename[0];
  388. if (suggestedFilename.includes("%")) {
  389. try {
  390. suggestedFilename = reFilename.exec(decodeURIComponent(suggestedFilename))[0];
  391. } catch (ex) {}
  392. }
  393. }
  394. return suggestedFilename || defaultFilename;
  395. }
  396. class StatTimer {
  397. constructor() {
  398. this.started = Object.create(null);
  399. this.times = [];
  400. }
  401. time(name) {
  402. if (name in this.started) {
  403. (0, _util.warn)(`Timer is already running for ${name}`);
  404. }
  405. this.started[name] = Date.now();
  406. }
  407. timeEnd(name) {
  408. if (!(name in this.started)) {
  409. (0, _util.warn)(`Timer has not been started for ${name}`);
  410. }
  411. this.times.push({
  412. name,
  413. start: this.started[name],
  414. end: Date.now()
  415. });
  416. delete this.started[name];
  417. }
  418. toString() {
  419. const outBuf = [];
  420. let longest = 0;
  421. for (const time of this.times) {
  422. const name = time.name;
  423. if (name.length > longest) {
  424. longest = name.length;
  425. }
  426. }
  427. for (const time of this.times) {
  428. const duration = time.end - time.start;
  429. outBuf.push(`${time.name.padEnd(longest)} ${duration}ms\n`);
  430. }
  431. return outBuf.join("");
  432. }
  433. }
  434. exports.StatTimer = StatTimer;
  435. function isFetchSupported() {
  436. return typeof fetch !== "undefined" && typeof Response !== "undefined" && "body" in Response.prototype && typeof ReadableStream !== "undefined";
  437. }
  438. function isValidFetchUrl(url, baseUrl) {
  439. try {
  440. const {
  441. protocol
  442. } = baseUrl ? new URL(url, baseUrl) : new URL(url);
  443. return protocol === "http:" || protocol === "https:";
  444. } catch (ex) {
  445. return false;
  446. }
  447. }
  448. function loadScript(src, removeScriptElement = false) {
  449. return new Promise((resolve, reject) => {
  450. const script = document.createElement("script");
  451. script.src = src;
  452. script.onload = function (evt) {
  453. if (removeScriptElement) {
  454. script.remove();
  455. }
  456. resolve(evt);
  457. };
  458. script.onerror = function () {
  459. reject(new Error(`Cannot load script at: ${script.src}`));
  460. };
  461. (document.head || document.documentElement).appendChild(script);
  462. });
  463. }
  464. function deprecated(details) {
  465. console.log("Deprecated API usage: " + details);
  466. }
  467. let pdfDateStringRegex;
  468. class PDFDateString {
  469. static toDateObject(input) {
  470. if (!input || !(0, _util.isString)(input)) {
  471. return null;
  472. }
  473. if (!pdfDateStringRegex) {
  474. pdfDateStringRegex = new RegExp("^D:" + "(\\d{4})" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "([Z|+|-])?" + "(\\d{2})?" + "'?" + "(\\d{2})?" + "'?");
  475. }
  476. const matches = pdfDateStringRegex.exec(input);
  477. if (!matches) {
  478. return null;
  479. }
  480. const year = parseInt(matches[1], 10);
  481. let month = parseInt(matches[2], 10);
  482. month = month >= 1 && month <= 12 ? month - 1 : 0;
  483. let day = parseInt(matches[3], 10);
  484. day = day >= 1 && day <= 31 ? day : 1;
  485. let hour = parseInt(matches[4], 10);
  486. hour = hour >= 0 && hour <= 23 ? hour : 0;
  487. let minute = parseInt(matches[5], 10);
  488. minute = minute >= 0 && minute <= 59 ? minute : 0;
  489. let second = parseInt(matches[6], 10);
  490. second = second >= 0 && second <= 59 ? second : 0;
  491. const universalTimeRelation = matches[7] || "Z";
  492. let offsetHour = parseInt(matches[8], 10);
  493. offsetHour = offsetHour >= 0 && offsetHour <= 23 ? offsetHour : 0;
  494. let offsetMinute = parseInt(matches[9], 10) || 0;
  495. offsetMinute = offsetMinute >= 0 && offsetMinute <= 59 ? offsetMinute : 0;
  496. if (universalTimeRelation === "-") {
  497. hour += offsetHour;
  498. minute += offsetMinute;
  499. } else if (universalTimeRelation === "+") {
  500. hour -= offsetHour;
  501. minute -= offsetMinute;
  502. }
  503. return new Date(Date.UTC(year, month, day, hour, minute, second));
  504. }
  505. }
  506. exports.PDFDateString = PDFDateString;
  507. /***/ }),
  508. /* 2 */
  509. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  510. Object.defineProperty(exports, "__esModule", ({
  511. value: true
  512. }));
  513. exports.arrayByteLength = arrayByteLength;
  514. exports.arraysToBytes = arraysToBytes;
  515. exports.assert = assert;
  516. exports.bytesToString = bytesToString;
  517. exports.createObjectURL = createObjectURL;
  518. exports.createPromiseCapability = createPromiseCapability;
  519. exports.createValidAbsoluteUrl = createValidAbsoluteUrl;
  520. exports.escapeString = escapeString;
  521. exports.getModificationDate = getModificationDate;
  522. exports.getVerbosityLevel = getVerbosityLevel;
  523. exports.info = info;
  524. exports.isArrayBuffer = isArrayBuffer;
  525. exports.isArrayEqual = isArrayEqual;
  526. exports.isAscii = isAscii;
  527. exports.isBool = isBool;
  528. exports.isNum = isNum;
  529. exports.isSameOrigin = isSameOrigin;
  530. exports.isString = isString;
  531. exports.objectFromMap = objectFromMap;
  532. exports.objectSize = objectSize;
  533. exports.removeNullCharacters = removeNullCharacters;
  534. exports.setVerbosityLevel = setVerbosityLevel;
  535. exports.shadow = shadow;
  536. exports.string32 = string32;
  537. exports.stringToBytes = stringToBytes;
  538. exports.stringToPDFString = stringToPDFString;
  539. exports.stringToUTF16BEString = stringToUTF16BEString;
  540. exports.stringToUTF8String = stringToUTF8String;
  541. exports.unreachable = unreachable;
  542. exports.utf8StringToString = utf8StringToString;
  543. exports.warn = warn;
  544. exports.VerbosityLevel = exports.Util = exports.UNSUPPORTED_FEATURES = exports.UnknownErrorException = exports.UnexpectedResponseException = exports.TextRenderingMode = exports.StreamType = exports.PermissionFlag = exports.PasswordResponses = exports.PasswordException = exports.PageActionEventType = exports.OPS = exports.MissingPDFException = exports.IsLittleEndianCached = exports.IsEvalSupportedCached = exports.InvalidPDFException = exports.ImageKind = exports.IDENTITY_MATRIX = exports.FormatError = exports.FontType = exports.FONT_IDENTITY_MATRIX = exports.DocumentActionEventType = exports.CMapCompressionType = exports.BaseException = exports.AnnotationType = exports.AnnotationStateModelType = exports.AnnotationReviewState = exports.AnnotationReplyType = exports.AnnotationMarkedState = exports.AnnotationFlag = exports.AnnotationFieldFlag = exports.AnnotationBorderStyleType = exports.AnnotationActionEventType = exports.AbortException = void 0;
  545. __w_pdfjs_require__(3);
  546. const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  547. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  548. const FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  549. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  550. const PermissionFlag = {
  551. PRINT: 0x04,
  552. MODIFY_CONTENTS: 0x08,
  553. COPY: 0x10,
  554. MODIFY_ANNOTATIONS: 0x20,
  555. FILL_INTERACTIVE_FORMS: 0x100,
  556. COPY_FOR_ACCESSIBILITY: 0x200,
  557. ASSEMBLE: 0x400,
  558. PRINT_HIGH_QUALITY: 0x800
  559. };
  560. exports.PermissionFlag = PermissionFlag;
  561. const TextRenderingMode = {
  562. FILL: 0,
  563. STROKE: 1,
  564. FILL_STROKE: 2,
  565. INVISIBLE: 3,
  566. FILL_ADD_TO_PATH: 4,
  567. STROKE_ADD_TO_PATH: 5,
  568. FILL_STROKE_ADD_TO_PATH: 6,
  569. ADD_TO_PATH: 7,
  570. FILL_STROKE_MASK: 3,
  571. ADD_TO_PATH_FLAG: 4
  572. };
  573. exports.TextRenderingMode = TextRenderingMode;
  574. const ImageKind = {
  575. GRAYSCALE_1BPP: 1,
  576. RGB_24BPP: 2,
  577. RGBA_32BPP: 3
  578. };
  579. exports.ImageKind = ImageKind;
  580. const AnnotationType = {
  581. TEXT: 1,
  582. LINK: 2,
  583. FREETEXT: 3,
  584. LINE: 4,
  585. SQUARE: 5,
  586. CIRCLE: 6,
  587. POLYGON: 7,
  588. POLYLINE: 8,
  589. HIGHLIGHT: 9,
  590. UNDERLINE: 10,
  591. SQUIGGLY: 11,
  592. STRIKEOUT: 12,
  593. STAMP: 13,
  594. CARET: 14,
  595. INK: 15,
  596. POPUP: 16,
  597. FILEATTACHMENT: 17,
  598. SOUND: 18,
  599. MOVIE: 19,
  600. WIDGET: 20,
  601. SCREEN: 21,
  602. PRINTERMARK: 22,
  603. TRAPNET: 23,
  604. WATERMARK: 24,
  605. THREED: 25,
  606. REDACT: 26
  607. };
  608. exports.AnnotationType = AnnotationType;
  609. const AnnotationStateModelType = {
  610. MARKED: "Marked",
  611. REVIEW: "Review"
  612. };
  613. exports.AnnotationStateModelType = AnnotationStateModelType;
  614. const AnnotationMarkedState = {
  615. MARKED: "Marked",
  616. UNMARKED: "Unmarked"
  617. };
  618. exports.AnnotationMarkedState = AnnotationMarkedState;
  619. const AnnotationReviewState = {
  620. ACCEPTED: "Accepted",
  621. REJECTED: "Rejected",
  622. CANCELLED: "Cancelled",
  623. COMPLETED: "Completed",
  624. NONE: "None"
  625. };
  626. exports.AnnotationReviewState = AnnotationReviewState;
  627. const AnnotationReplyType = {
  628. GROUP: "Group",
  629. REPLY: "R"
  630. };
  631. exports.AnnotationReplyType = AnnotationReplyType;
  632. const AnnotationFlag = {
  633. INVISIBLE: 0x01,
  634. HIDDEN: 0x02,
  635. PRINT: 0x04,
  636. NOZOOM: 0x08,
  637. NOROTATE: 0x10,
  638. NOVIEW: 0x20,
  639. READONLY: 0x40,
  640. LOCKED: 0x80,
  641. TOGGLENOVIEW: 0x100,
  642. LOCKEDCONTENTS: 0x200
  643. };
  644. exports.AnnotationFlag = AnnotationFlag;
  645. const AnnotationFieldFlag = {
  646. READONLY: 0x0000001,
  647. REQUIRED: 0x0000002,
  648. NOEXPORT: 0x0000004,
  649. MULTILINE: 0x0001000,
  650. PASSWORD: 0x0002000,
  651. NOTOGGLETOOFF: 0x0004000,
  652. RADIO: 0x0008000,
  653. PUSHBUTTON: 0x0010000,
  654. COMBO: 0x0020000,
  655. EDIT: 0x0040000,
  656. SORT: 0x0080000,
  657. FILESELECT: 0x0100000,
  658. MULTISELECT: 0x0200000,
  659. DONOTSPELLCHECK: 0x0400000,
  660. DONOTSCROLL: 0x0800000,
  661. COMB: 0x1000000,
  662. RICHTEXT: 0x2000000,
  663. RADIOSINUNISON: 0x2000000,
  664. COMMITONSELCHANGE: 0x4000000
  665. };
  666. exports.AnnotationFieldFlag = AnnotationFieldFlag;
  667. const AnnotationBorderStyleType = {
  668. SOLID: 1,
  669. DASHED: 2,
  670. BEVELED: 3,
  671. INSET: 4,
  672. UNDERLINE: 5
  673. };
  674. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  675. const AnnotationActionEventType = {
  676. E: "Mouse Enter",
  677. X: "Mouse Exit",
  678. D: "Mouse Down",
  679. U: "Mouse Up",
  680. Fo: "Focus",
  681. Bl: "Blur",
  682. PO: "PageOpen",
  683. PC: "PageClose",
  684. PV: "PageVisible",
  685. PI: "PageInvisible",
  686. K: "Keystroke",
  687. F: "Format",
  688. V: "Validate",
  689. C: "Calculate"
  690. };
  691. exports.AnnotationActionEventType = AnnotationActionEventType;
  692. const DocumentActionEventType = {
  693. WC: "WillClose",
  694. WS: "WillSave",
  695. DS: "DidSave",
  696. WP: "WillPrint",
  697. DP: "DidPrint"
  698. };
  699. exports.DocumentActionEventType = DocumentActionEventType;
  700. const PageActionEventType = {
  701. O: "PageOpen",
  702. C: "PageClose"
  703. };
  704. exports.PageActionEventType = PageActionEventType;
  705. const StreamType = {
  706. UNKNOWN: "UNKNOWN",
  707. FLATE: "FLATE",
  708. LZW: "LZW",
  709. DCT: "DCT",
  710. JPX: "JPX",
  711. JBIG: "JBIG",
  712. A85: "A85",
  713. AHX: "AHX",
  714. CCF: "CCF",
  715. RLX: "RLX"
  716. };
  717. exports.StreamType = StreamType;
  718. const FontType = {
  719. UNKNOWN: "UNKNOWN",
  720. TYPE1: "TYPE1",
  721. TYPE1C: "TYPE1C",
  722. CIDFONTTYPE0: "CIDFONTTYPE0",
  723. CIDFONTTYPE0C: "CIDFONTTYPE0C",
  724. TRUETYPE: "TRUETYPE",
  725. CIDFONTTYPE2: "CIDFONTTYPE2",
  726. TYPE3: "TYPE3",
  727. OPENTYPE: "OPENTYPE",
  728. TYPE0: "TYPE0",
  729. MMTYPE1: "MMTYPE1"
  730. };
  731. exports.FontType = FontType;
  732. const VerbosityLevel = {
  733. ERRORS: 0,
  734. WARNINGS: 1,
  735. INFOS: 5
  736. };
  737. exports.VerbosityLevel = VerbosityLevel;
  738. const CMapCompressionType = {
  739. NONE: 0,
  740. BINARY: 1,
  741. STREAM: 2
  742. };
  743. exports.CMapCompressionType = CMapCompressionType;
  744. const OPS = {
  745. dependency: 1,
  746. setLineWidth: 2,
  747. setLineCap: 3,
  748. setLineJoin: 4,
  749. setMiterLimit: 5,
  750. setDash: 6,
  751. setRenderingIntent: 7,
  752. setFlatness: 8,
  753. setGState: 9,
  754. save: 10,
  755. restore: 11,
  756. transform: 12,
  757. moveTo: 13,
  758. lineTo: 14,
  759. curveTo: 15,
  760. curveTo2: 16,
  761. curveTo3: 17,
  762. closePath: 18,
  763. rectangle: 19,
  764. stroke: 20,
  765. closeStroke: 21,
  766. fill: 22,
  767. eoFill: 23,
  768. fillStroke: 24,
  769. eoFillStroke: 25,
  770. closeFillStroke: 26,
  771. closeEOFillStroke: 27,
  772. endPath: 28,
  773. clip: 29,
  774. eoClip: 30,
  775. beginText: 31,
  776. endText: 32,
  777. setCharSpacing: 33,
  778. setWordSpacing: 34,
  779. setHScale: 35,
  780. setLeading: 36,
  781. setFont: 37,
  782. setTextRenderingMode: 38,
  783. setTextRise: 39,
  784. moveText: 40,
  785. setLeadingMoveText: 41,
  786. setTextMatrix: 42,
  787. nextLine: 43,
  788. showText: 44,
  789. showSpacedText: 45,
  790. nextLineShowText: 46,
  791. nextLineSetSpacingShowText: 47,
  792. setCharWidth: 48,
  793. setCharWidthAndBounds: 49,
  794. setStrokeColorSpace: 50,
  795. setFillColorSpace: 51,
  796. setStrokeColor: 52,
  797. setStrokeColorN: 53,
  798. setFillColor: 54,
  799. setFillColorN: 55,
  800. setStrokeGray: 56,
  801. setFillGray: 57,
  802. setStrokeRGBColor: 58,
  803. setFillRGBColor: 59,
  804. setStrokeCMYKColor: 60,
  805. setFillCMYKColor: 61,
  806. shadingFill: 62,
  807. beginInlineImage: 63,
  808. beginImageData: 64,
  809. endInlineImage: 65,
  810. paintXObject: 66,
  811. markPoint: 67,
  812. markPointProps: 68,
  813. beginMarkedContent: 69,
  814. beginMarkedContentProps: 70,
  815. endMarkedContent: 71,
  816. beginCompat: 72,
  817. endCompat: 73,
  818. paintFormXObjectBegin: 74,
  819. paintFormXObjectEnd: 75,
  820. beginGroup: 76,
  821. endGroup: 77,
  822. beginAnnotations: 78,
  823. endAnnotations: 79,
  824. beginAnnotation: 80,
  825. endAnnotation: 81,
  826. paintJpegXObject: 82,
  827. paintImageMaskXObject: 83,
  828. paintImageMaskXObjectGroup: 84,
  829. paintImageXObject: 85,
  830. paintInlineImageXObject: 86,
  831. paintInlineImageXObjectGroup: 87,
  832. paintImageXObjectRepeat: 88,
  833. paintImageMaskXObjectRepeat: 89,
  834. paintSolidColorImageMask: 90,
  835. constructPath: 91
  836. };
  837. exports.OPS = OPS;
  838. const UNSUPPORTED_FEATURES = {
  839. unknown: "unknown",
  840. forms: "forms",
  841. javaScript: "javaScript",
  842. smask: "smask",
  843. shadingPattern: "shadingPattern",
  844. font: "font",
  845. errorTilingPattern: "errorTilingPattern",
  846. errorExtGState: "errorExtGState",
  847. errorXObject: "errorXObject",
  848. errorFontLoadType3: "errorFontLoadType3",
  849. errorFontState: "errorFontState",
  850. errorFontMissing: "errorFontMissing",
  851. errorFontTranslate: "errorFontTranslate",
  852. errorColorSpace: "errorColorSpace",
  853. errorOperatorList: "errorOperatorList",
  854. errorFontToUnicode: "errorFontToUnicode",
  855. errorFontLoadNative: "errorFontLoadNative",
  856. errorFontGetPath: "errorFontGetPath",
  857. errorMarkedContent: "errorMarkedContent"
  858. };
  859. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  860. const PasswordResponses = {
  861. NEED_PASSWORD: 1,
  862. INCORRECT_PASSWORD: 2
  863. };
  864. exports.PasswordResponses = PasswordResponses;
  865. let verbosity = VerbosityLevel.WARNINGS;
  866. function setVerbosityLevel(level) {
  867. if (Number.isInteger(level)) {
  868. verbosity = level;
  869. }
  870. }
  871. function getVerbosityLevel() {
  872. return verbosity;
  873. }
  874. function info(msg) {
  875. if (verbosity >= VerbosityLevel.INFOS) {
  876. console.log(`Info: ${msg}`);
  877. }
  878. }
  879. function warn(msg) {
  880. if (verbosity >= VerbosityLevel.WARNINGS) {
  881. console.log(`Warning: ${msg}`);
  882. }
  883. }
  884. function unreachable(msg) {
  885. throw new Error(msg);
  886. }
  887. function assert(cond, msg) {
  888. if (!cond) {
  889. unreachable(msg);
  890. }
  891. }
  892. function isSameOrigin(baseUrl, otherUrl) {
  893. let base;
  894. try {
  895. base = new URL(baseUrl);
  896. if (!base.origin || base.origin === "null") {
  897. return false;
  898. }
  899. } catch (e) {
  900. return false;
  901. }
  902. const other = new URL(otherUrl, base);
  903. return base.origin === other.origin;
  904. }
  905. function _isValidProtocol(url) {
  906. if (!url) {
  907. return false;
  908. }
  909. switch (url.protocol) {
  910. case "http:":
  911. case "https:":
  912. case "ftp:":
  913. case "mailto:":
  914. case "tel:":
  915. return true;
  916. default:
  917. return false;
  918. }
  919. }
  920. function createValidAbsoluteUrl(url, baseUrl) {
  921. if (!url) {
  922. return null;
  923. }
  924. try {
  925. const absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url);
  926. if (_isValidProtocol(absoluteUrl)) {
  927. return absoluteUrl;
  928. }
  929. } catch (ex) {}
  930. return null;
  931. }
  932. function shadow(obj, prop, value) {
  933. Object.defineProperty(obj, prop, {
  934. value,
  935. enumerable: true,
  936. configurable: true,
  937. writable: false
  938. });
  939. return value;
  940. }
  941. const BaseException = function BaseExceptionClosure() {
  942. function BaseException(message) {
  943. if (this.constructor === BaseException) {
  944. unreachable("Cannot initialize BaseException.");
  945. }
  946. this.message = message;
  947. this.name = this.constructor.name;
  948. }
  949. BaseException.prototype = new Error();
  950. BaseException.constructor = BaseException;
  951. return BaseException;
  952. }();
  953. exports.BaseException = BaseException;
  954. class PasswordException extends BaseException {
  955. constructor(msg, code) {
  956. super(msg);
  957. this.code = code;
  958. }
  959. }
  960. exports.PasswordException = PasswordException;
  961. class UnknownErrorException extends BaseException {
  962. constructor(msg, details) {
  963. super(msg);
  964. this.details = details;
  965. }
  966. }
  967. exports.UnknownErrorException = UnknownErrorException;
  968. class InvalidPDFException extends BaseException {}
  969. exports.InvalidPDFException = InvalidPDFException;
  970. class MissingPDFException extends BaseException {}
  971. exports.MissingPDFException = MissingPDFException;
  972. class UnexpectedResponseException extends BaseException {
  973. constructor(msg, status) {
  974. super(msg);
  975. this.status = status;
  976. }
  977. }
  978. exports.UnexpectedResponseException = UnexpectedResponseException;
  979. class FormatError extends BaseException {}
  980. exports.FormatError = FormatError;
  981. class AbortException extends BaseException {}
  982. exports.AbortException = AbortException;
  983. const NullCharactersRegExp = /\x00/g;
  984. function removeNullCharacters(str) {
  985. if (typeof str !== "string") {
  986. warn("The argument for removeNullCharacters must be a string.");
  987. return str;
  988. }
  989. return str.replace(NullCharactersRegExp, "");
  990. }
  991. function bytesToString(bytes) {
  992. assert(bytes !== null && typeof bytes === "object" && bytes.length !== undefined, "Invalid argument for bytesToString");
  993. const length = bytes.length;
  994. const MAX_ARGUMENT_COUNT = 8192;
  995. if (length < MAX_ARGUMENT_COUNT) {
  996. return String.fromCharCode.apply(null, bytes);
  997. }
  998. const strBuf = [];
  999. for (let i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  1000. const chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  1001. const chunk = bytes.subarray(i, chunkEnd);
  1002. strBuf.push(String.fromCharCode.apply(null, chunk));
  1003. }
  1004. return strBuf.join("");
  1005. }
  1006. function stringToBytes(str) {
  1007. assert(typeof str === "string", "Invalid argument for stringToBytes");
  1008. const length = str.length;
  1009. const bytes = new Uint8Array(length);
  1010. for (let i = 0; i < length; ++i) {
  1011. bytes[i] = str.charCodeAt(i) & 0xff;
  1012. }
  1013. return bytes;
  1014. }
  1015. function arrayByteLength(arr) {
  1016. if (arr.length !== undefined) {
  1017. return arr.length;
  1018. }
  1019. assert(arr.byteLength !== undefined, "arrayByteLength - invalid argument.");
  1020. return arr.byteLength;
  1021. }
  1022. function arraysToBytes(arr) {
  1023. const length = arr.length;
  1024. if (length === 1 && arr[0] instanceof Uint8Array) {
  1025. return arr[0];
  1026. }
  1027. let resultLength = 0;
  1028. for (let i = 0; i < length; i++) {
  1029. resultLength += arrayByteLength(arr[i]);
  1030. }
  1031. let pos = 0;
  1032. const data = new Uint8Array(resultLength);
  1033. for (let i = 0; i < length; i++) {
  1034. let item = arr[i];
  1035. if (!(item instanceof Uint8Array)) {
  1036. if (typeof item === "string") {
  1037. item = stringToBytes(item);
  1038. } else {
  1039. item = new Uint8Array(item);
  1040. }
  1041. }
  1042. const itemLength = item.byteLength;
  1043. data.set(item, pos);
  1044. pos += itemLength;
  1045. }
  1046. return data;
  1047. }
  1048. function string32(value) {
  1049. return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
  1050. }
  1051. function objectSize(obj) {
  1052. return Object.keys(obj).length;
  1053. }
  1054. function objectFromMap(map) {
  1055. const obj = Object.create(null);
  1056. for (const [key, value] of map) {
  1057. obj[key] = value;
  1058. }
  1059. return obj;
  1060. }
  1061. function isLittleEndian() {
  1062. const buffer8 = new Uint8Array(4);
  1063. buffer8[0] = 1;
  1064. const view32 = new Uint32Array(buffer8.buffer, 0, 1);
  1065. return view32[0] === 1;
  1066. }
  1067. const IsLittleEndianCached = {
  1068. get value() {
  1069. return shadow(this, "value", isLittleEndian());
  1070. }
  1071. };
  1072. exports.IsLittleEndianCached = IsLittleEndianCached;
  1073. function isEvalSupported() {
  1074. try {
  1075. new Function("");
  1076. return true;
  1077. } catch (e) {
  1078. return false;
  1079. }
  1080. }
  1081. const IsEvalSupportedCached = {
  1082. get value() {
  1083. return shadow(this, "value", isEvalSupported());
  1084. }
  1085. };
  1086. exports.IsEvalSupportedCached = IsEvalSupportedCached;
  1087. const hexNumbers = [...Array(256).keys()].map(n => n.toString(16).padStart(2, "0"));
  1088. class Util {
  1089. static makeHexColor(r, g, b) {
  1090. return `#${hexNumbers[r]}${hexNumbers[g]}${hexNumbers[b]}`;
  1091. }
  1092. static transform(m1, m2) {
  1093. 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]];
  1094. }
  1095. static applyTransform(p, m) {
  1096. const xt = p[0] * m[0] + p[1] * m[2] + m[4];
  1097. const yt = p[0] * m[1] + p[1] * m[3] + m[5];
  1098. return [xt, yt];
  1099. }
  1100. static applyInverseTransform(p, m) {
  1101. const d = m[0] * m[3] - m[1] * m[2];
  1102. const xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  1103. const yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  1104. return [xt, yt];
  1105. }
  1106. static getAxialAlignedBoundingBox(r, m) {
  1107. const p1 = Util.applyTransform(r, m);
  1108. const p2 = Util.applyTransform(r.slice(2, 4), m);
  1109. const p3 = Util.applyTransform([r[0], r[3]], m);
  1110. const p4 = Util.applyTransform([r[2], r[1]], m);
  1111. 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])];
  1112. }
  1113. static inverseTransform(m) {
  1114. const d = m[0] * m[3] - m[1] * m[2];
  1115. 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];
  1116. }
  1117. static apply3dTransform(m, v) {
  1118. return [m[0] * v[0] + m[1] * v[1] + m[2] * v[2], m[3] * v[0] + m[4] * v[1] + m[5] * v[2], m[6] * v[0] + m[7] * v[1] + m[8] * v[2]];
  1119. }
  1120. static singularValueDecompose2dScale(m) {
  1121. const transpose = [m[0], m[2], m[1], m[3]];
  1122. const a = m[0] * transpose[0] + m[1] * transpose[2];
  1123. const b = m[0] * transpose[1] + m[1] * transpose[3];
  1124. const c = m[2] * transpose[0] + m[3] * transpose[2];
  1125. const d = m[2] * transpose[1] + m[3] * transpose[3];
  1126. const first = (a + d) / 2;
  1127. const second = Math.sqrt((a + d) ** 2 - 4 * (a * d - c * b)) / 2;
  1128. const sx = first + second || 1;
  1129. const sy = first - second || 1;
  1130. return [Math.sqrt(sx), Math.sqrt(sy)];
  1131. }
  1132. static normalizeRect(rect) {
  1133. const r = rect.slice(0);
  1134. if (rect[0] > rect[2]) {
  1135. r[0] = rect[2];
  1136. r[2] = rect[0];
  1137. }
  1138. if (rect[1] > rect[3]) {
  1139. r[1] = rect[3];
  1140. r[3] = rect[1];
  1141. }
  1142. return r;
  1143. }
  1144. static intersect(rect1, rect2) {
  1145. function compare(a, b) {
  1146. return a - b;
  1147. }
  1148. const orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare);
  1149. const orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare);
  1150. const result = [];
  1151. rect1 = Util.normalizeRect(rect1);
  1152. rect2 = Util.normalizeRect(rect2);
  1153. if (orderedX[0] === rect1[0] && orderedX[1] === rect2[0] || orderedX[0] === rect2[0] && orderedX[1] === rect1[0]) {
  1154. result[0] = orderedX[1];
  1155. result[2] = orderedX[2];
  1156. } else {
  1157. return null;
  1158. }
  1159. if (orderedY[0] === rect1[1] && orderedY[1] === rect2[1] || orderedY[0] === rect2[1] && orderedY[1] === rect1[1]) {
  1160. result[1] = orderedY[1];
  1161. result[3] = orderedY[2];
  1162. } else {
  1163. return null;
  1164. }
  1165. return result;
  1166. }
  1167. }
  1168. exports.Util = Util;
  1169. const PDFStringTranslateTable = [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];
  1170. function stringToPDFString(str) {
  1171. const length = str.length,
  1172. strBuf = [];
  1173. if (str[0] === "\xFE" && str[1] === "\xFF") {
  1174. for (let i = 2; i < length; i += 2) {
  1175. strBuf.push(String.fromCharCode(str.charCodeAt(i) << 8 | str.charCodeAt(i + 1)));
  1176. }
  1177. } else if (str[0] === "\xFF" && str[1] === "\xFE") {
  1178. for (let i = 2; i < length; i += 2) {
  1179. strBuf.push(String.fromCharCode(str.charCodeAt(i + 1) << 8 | str.charCodeAt(i)));
  1180. }
  1181. } else {
  1182. for (let i = 0; i < length; ++i) {
  1183. const code = PDFStringTranslateTable[str.charCodeAt(i)];
  1184. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  1185. }
  1186. }
  1187. return strBuf.join("");
  1188. }
  1189. function escapeString(str) {
  1190. return str.replace(/([()\\\n\r])/g, match => {
  1191. if (match === "\n") {
  1192. return "\\n";
  1193. } else if (match === "\r") {
  1194. return "\\r";
  1195. }
  1196. return `\\${match}`;
  1197. });
  1198. }
  1199. function isAscii(str) {
  1200. return /^[\x00-\x7F]*$/.test(str);
  1201. }
  1202. function stringToUTF16BEString(str) {
  1203. const buf = ["\xFE\xFF"];
  1204. for (let i = 0, ii = str.length; i < ii; i++) {
  1205. const char = str.charCodeAt(i);
  1206. buf.push(String.fromCharCode(char >> 8 & 0xff));
  1207. buf.push(String.fromCharCode(char & 0xff));
  1208. }
  1209. return buf.join("");
  1210. }
  1211. function stringToUTF8String(str) {
  1212. return decodeURIComponent(escape(str));
  1213. }
  1214. function utf8StringToString(str) {
  1215. return unescape(encodeURIComponent(str));
  1216. }
  1217. function isBool(v) {
  1218. return typeof v === "boolean";
  1219. }
  1220. function isNum(v) {
  1221. return typeof v === "number";
  1222. }
  1223. function isString(v) {
  1224. return typeof v === "string";
  1225. }
  1226. function isArrayBuffer(v) {
  1227. return typeof v === "object" && v !== null && v.byteLength !== undefined;
  1228. }
  1229. function isArrayEqual(arr1, arr2) {
  1230. if (arr1.length !== arr2.length) {
  1231. return false;
  1232. }
  1233. for (let i = 0, ii = arr1.length; i < ii; i++) {
  1234. if (arr1[i] !== arr2[i]) {
  1235. return false;
  1236. }
  1237. }
  1238. return true;
  1239. }
  1240. function getModificationDate(date = new Date()) {
  1241. const buffer = [date.getUTCFullYear().toString(), (date.getUTCMonth() + 1).toString().padStart(2, "0"), date.getUTCDate().toString().padStart(2, "0"), date.getUTCHours().toString().padStart(2, "0"), date.getUTCMinutes().toString().padStart(2, "0"), date.getUTCSeconds().toString().padStart(2, "0")];
  1242. return buffer.join("");
  1243. }
  1244. function createPromiseCapability() {
  1245. const capability = Object.create(null);
  1246. let isSettled = false;
  1247. Object.defineProperty(capability, "settled", {
  1248. get() {
  1249. return isSettled;
  1250. }
  1251. });
  1252. capability.promise = new Promise(function (resolve, reject) {
  1253. capability.resolve = function (data) {
  1254. isSettled = true;
  1255. resolve(data);
  1256. };
  1257. capability.reject = function (reason) {
  1258. isSettled = true;
  1259. reject(reason);
  1260. };
  1261. });
  1262. return capability;
  1263. }
  1264. function createObjectURL(data, contentType = "", forceDataSchema = false) {
  1265. if (URL.createObjectURL && !forceDataSchema) {
  1266. return URL.createObjectURL(new Blob([data], {
  1267. type: contentType
  1268. }));
  1269. }
  1270. const digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  1271. let buffer = `data:${contentType};base64,`;
  1272. for (let i = 0, ii = data.length; i < ii; i += 3) {
  1273. const b1 = data[i] & 0xff;
  1274. const b2 = data[i + 1] & 0xff;
  1275. const b3 = data[i + 2] & 0xff;
  1276. const d1 = b1 >> 2,
  1277. d2 = (b1 & 3) << 4 | b2 >> 4;
  1278. const d3 = i + 1 < ii ? (b2 & 0xf) << 2 | b3 >> 6 : 64;
  1279. const d4 = i + 2 < ii ? b3 & 0x3f : 64;
  1280. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1281. }
  1282. return buffer;
  1283. }
  1284. /***/ }),
  1285. /* 3 */
  1286. /***/ ((__unused_webpack_module, __unused_webpack_exports, __w_pdfjs_require__) => {
  1287. var _is_node = __w_pdfjs_require__(4);
  1288. ;
  1289. /***/ }),
  1290. /* 4 */
  1291. /***/ ((__unused_webpack_module, exports) => {
  1292. Object.defineProperty(exports, "__esModule", ({
  1293. value: true
  1294. }));
  1295. exports.isNodeJS = void 0;
  1296. const isNodeJS = typeof process === "object" && process + "" === "[object process]" && !process.versions.nw && !(process.versions.electron && process.type && process.type !== "browser");
  1297. exports.isNodeJS = isNodeJS;
  1298. /***/ }),
  1299. /* 5 */
  1300. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  1301. Object.defineProperty(exports, "__esModule", ({
  1302. value: true
  1303. }));
  1304. exports.getDocument = getDocument;
  1305. exports.setPDFNetworkStreamFactory = setPDFNetworkStreamFactory;
  1306. exports.version = exports.PDFWorker = exports.PDFPageProxy = exports.PDFDocumentProxy = exports.PDFDataRangeTransport = exports.LoopbackPort = exports.DefaultCMapReaderFactory = exports.DefaultCanvasFactory = exports.build = void 0;
  1307. var _util = __w_pdfjs_require__(2);
  1308. var _display_utils = __w_pdfjs_require__(1);
  1309. var _font_loader = __w_pdfjs_require__(6);
  1310. var _node_utils = __w_pdfjs_require__(7);
  1311. var _annotation_storage = __w_pdfjs_require__(8);
  1312. var _api_compatibility = __w_pdfjs_require__(9);
  1313. var _canvas = __w_pdfjs_require__(10);
  1314. var _worker_options = __w_pdfjs_require__(12);
  1315. var _is_node = __w_pdfjs_require__(4);
  1316. var _message_handler = __w_pdfjs_require__(13);
  1317. var _metadata = __w_pdfjs_require__(14);
  1318. var _optional_content_config = __w_pdfjs_require__(15);
  1319. var _transport_stream = __w_pdfjs_require__(16);
  1320. var _webgl = __w_pdfjs_require__(17);
  1321. const DEFAULT_RANGE_CHUNK_SIZE = 65536;
  1322. const RENDERING_CANCELLED_TIMEOUT = 100;
  1323. const DefaultCanvasFactory = _is_node.isNodeJS ? _node_utils.NodeCanvasFactory : _display_utils.DOMCanvasFactory;
  1324. exports.DefaultCanvasFactory = DefaultCanvasFactory;
  1325. const DefaultCMapReaderFactory = _is_node.isNodeJS ? _node_utils.NodeCMapReaderFactory : _display_utils.DOMCMapReaderFactory;
  1326. exports.DefaultCMapReaderFactory = DefaultCMapReaderFactory;
  1327. let createPDFNetworkStream;
  1328. function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) {
  1329. createPDFNetworkStream = pdfNetworkStreamFactory;
  1330. }
  1331. function getDocument(src) {
  1332. const task = new PDFDocumentLoadingTask();
  1333. let source;
  1334. if (typeof src === "string" || src instanceof URL) {
  1335. source = {
  1336. url: src
  1337. };
  1338. } else if ((0, _util.isArrayBuffer)(src)) {
  1339. source = {
  1340. data: src
  1341. };
  1342. } else if (src instanceof PDFDataRangeTransport) {
  1343. source = {
  1344. range: src
  1345. };
  1346. } else {
  1347. if (typeof src !== "object") {
  1348. throw new Error("Invalid parameter in getDocument, " + "need either string, URL, Uint8Array, or parameter object.");
  1349. }
  1350. if (!src.url && !src.data && !src.range) {
  1351. throw new Error("Invalid parameter object: need either .data, .range or .url");
  1352. }
  1353. source = src;
  1354. }
  1355. const params = Object.create(null);
  1356. let rangeTransport = null,
  1357. worker = null;
  1358. for (const key in source) {
  1359. const value = source[key];
  1360. switch (key) {
  1361. case "url":
  1362. if (typeof window !== "undefined") {
  1363. try {
  1364. params[key] = new URL(value, window.location).href;
  1365. continue;
  1366. } catch (ex) {
  1367. (0, _util.warn)(`Cannot create valid URL: "${ex}".`);
  1368. }
  1369. } else if (typeof value === "string" || value instanceof URL) {
  1370. params[key] = value.toString();
  1371. continue;
  1372. }
  1373. throw new Error("Invalid PDF url data: " + "either string or URL-object is expected in the url property.");
  1374. case "range":
  1375. rangeTransport = value;
  1376. continue;
  1377. case "worker":
  1378. worker = value;
  1379. continue;
  1380. case "data":
  1381. if (_is_node.isNodeJS && typeof Buffer !== "undefined" && value instanceof Buffer) {
  1382. params[key] = new Uint8Array(value);
  1383. } else if (value instanceof Uint8Array) {
  1384. break;
  1385. } else if (typeof value === "string") {
  1386. params[key] = (0, _util.stringToBytes)(value);
  1387. } else if (typeof value === "object" && value !== null && !isNaN(value.length)) {
  1388. params[key] = new Uint8Array(value);
  1389. } else if ((0, _util.isArrayBuffer)(value)) {
  1390. params[key] = new Uint8Array(value);
  1391. } else {
  1392. throw new Error("Invalid PDF binary data: either typed array, " + "string, or array-like object is expected in the data property.");
  1393. }
  1394. continue;
  1395. }
  1396. params[key] = value;
  1397. }
  1398. params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
  1399. params.CMapReaderFactory = params.CMapReaderFactory || DefaultCMapReaderFactory;
  1400. params.ignoreErrors = params.stopAtErrors !== true;
  1401. params.fontExtraProperties = params.fontExtraProperties === true;
  1402. params.pdfBug = params.pdfBug === true;
  1403. params.enableXfa = params.enableXfa === true;
  1404. if (typeof params.docBaseUrl !== "string" || (0, _display_utils.isDataScheme)(params.docBaseUrl)) {
  1405. params.docBaseUrl = null;
  1406. }
  1407. if (!Number.isInteger(params.maxImageSize)) {
  1408. params.maxImageSize = -1;
  1409. }
  1410. if (typeof params.isEvalSupported !== "boolean") {
  1411. params.isEvalSupported = true;
  1412. }
  1413. if (typeof params.disableFontFace !== "boolean") {
  1414. params.disableFontFace = _api_compatibility.apiCompatibilityParams.disableFontFace || false;
  1415. }
  1416. if (typeof params.ownerDocument === "undefined") {
  1417. params.ownerDocument = globalThis.document;
  1418. }
  1419. if (typeof params.disableRange !== "boolean") {
  1420. params.disableRange = false;
  1421. }
  1422. if (typeof params.disableStream !== "boolean") {
  1423. params.disableStream = false;
  1424. }
  1425. if (typeof params.disableAutoFetch !== "boolean") {
  1426. params.disableAutoFetch = false;
  1427. }
  1428. (0, _util.setVerbosityLevel)(params.verbosity);
  1429. if (!worker) {
  1430. const workerParams = {
  1431. verbosity: params.verbosity,
  1432. port: _worker_options.GlobalWorkerOptions.workerPort
  1433. };
  1434. worker = workerParams.port ? PDFWorker.fromPort(workerParams) : new PDFWorker(workerParams);
  1435. task._worker = worker;
  1436. }
  1437. const docId = task.docId;
  1438. worker.promise.then(function () {
  1439. if (task.destroyed) {
  1440. throw new Error("Loading aborted");
  1441. }
  1442. const workerIdPromise = _fetchDocument(worker, params, rangeTransport, docId);
  1443. const networkStreamPromise = new Promise(function (resolve) {
  1444. let networkStream;
  1445. if (rangeTransport) {
  1446. networkStream = new _transport_stream.PDFDataTransportStream({
  1447. length: params.length,
  1448. initialData: params.initialData,
  1449. progressiveDone: params.progressiveDone,
  1450. contentDispositionFilename: params.contentDispositionFilename,
  1451. disableRange: params.disableRange,
  1452. disableStream: params.disableStream
  1453. }, rangeTransport);
  1454. } else if (!params.data) {
  1455. networkStream = createPDFNetworkStream({
  1456. url: params.url,
  1457. length: params.length,
  1458. httpHeaders: params.httpHeaders,
  1459. withCredentials: params.withCredentials,
  1460. rangeChunkSize: params.rangeChunkSize,
  1461. disableRange: params.disableRange,
  1462. disableStream: params.disableStream
  1463. });
  1464. }
  1465. resolve(networkStream);
  1466. });
  1467. return Promise.all([workerIdPromise, networkStreamPromise]).then(function ([workerId, networkStream]) {
  1468. if (task.destroyed) {
  1469. throw new Error("Loading aborted");
  1470. }
  1471. const messageHandler = new _message_handler.MessageHandler(docId, workerId, worker.port);
  1472. messageHandler.postMessageTransfers = worker.postMessageTransfers;
  1473. const transport = new WorkerTransport(messageHandler, task, networkStream, params);
  1474. task._transport = transport;
  1475. messageHandler.send("Ready", null);
  1476. });
  1477. }).catch(task._capability.reject);
  1478. return task;
  1479. }
  1480. function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
  1481. if (worker.destroyed) {
  1482. return Promise.reject(new Error("Worker was destroyed"));
  1483. }
  1484. if (pdfDataRangeTransport) {
  1485. source.length = pdfDataRangeTransport.length;
  1486. source.initialData = pdfDataRangeTransport.initialData;
  1487. source.progressiveDone = pdfDataRangeTransport.progressiveDone;
  1488. source.contentDispositionFilename = pdfDataRangeTransport.contentDispositionFilename;
  1489. }
  1490. return worker.messageHandler.sendWithPromise("GetDocRequest", {
  1491. docId,
  1492. apiVersion: '2.8.335',
  1493. source: {
  1494. data: source.data,
  1495. url: source.url,
  1496. password: source.password,
  1497. disableAutoFetch: source.disableAutoFetch,
  1498. rangeChunkSize: source.rangeChunkSize,
  1499. length: source.length
  1500. },
  1501. maxImageSize: source.maxImageSize,
  1502. disableFontFace: source.disableFontFace,
  1503. postMessageTransfers: worker.postMessageTransfers,
  1504. docBaseUrl: source.docBaseUrl,
  1505. ignoreErrors: source.ignoreErrors,
  1506. isEvalSupported: source.isEvalSupported,
  1507. fontExtraProperties: source.fontExtraProperties,
  1508. enableXfa: source.enableXfa
  1509. }).then(function (workerId) {
  1510. if (worker.destroyed) {
  1511. throw new Error("Worker was destroyed");
  1512. }
  1513. return workerId;
  1514. });
  1515. }
  1516. const PDFDocumentLoadingTask = function PDFDocumentLoadingTaskClosure() {
  1517. let nextDocumentId = 0;
  1518. class PDFDocumentLoadingTask {
  1519. constructor() {
  1520. this._capability = (0, _util.createPromiseCapability)();
  1521. this._transport = null;
  1522. this._worker = null;
  1523. this.docId = "d" + nextDocumentId++;
  1524. this.destroyed = false;
  1525. this.onPassword = null;
  1526. this.onProgress = null;
  1527. this.onUnsupportedFeature = null;
  1528. }
  1529. get promise() {
  1530. return this._capability.promise;
  1531. }
  1532. destroy() {
  1533. this.destroyed = true;
  1534. const transportDestroyed = !this._transport ? Promise.resolve() : this._transport.destroy();
  1535. return transportDestroyed.then(() => {
  1536. this._transport = null;
  1537. if (this._worker) {
  1538. this._worker.destroy();
  1539. this._worker = null;
  1540. }
  1541. });
  1542. }
  1543. }
  1544. return PDFDocumentLoadingTask;
  1545. }();
  1546. class PDFDataRangeTransport {
  1547. constructor(length, initialData, progressiveDone = false, contentDispositionFilename = null) {
  1548. this.length = length;
  1549. this.initialData = initialData;
  1550. this.progressiveDone = progressiveDone;
  1551. this.contentDispositionFilename = contentDispositionFilename;
  1552. this._rangeListeners = [];
  1553. this._progressListeners = [];
  1554. this._progressiveReadListeners = [];
  1555. this._progressiveDoneListeners = [];
  1556. this._readyCapability = (0, _util.createPromiseCapability)();
  1557. }
  1558. addRangeListener(listener) {
  1559. this._rangeListeners.push(listener);
  1560. }
  1561. addProgressListener(listener) {
  1562. this._progressListeners.push(listener);
  1563. }
  1564. addProgressiveReadListener(listener) {
  1565. this._progressiveReadListeners.push(listener);
  1566. }
  1567. addProgressiveDoneListener(listener) {
  1568. this._progressiveDoneListeners.push(listener);
  1569. }
  1570. onDataRange(begin, chunk) {
  1571. for (const listener of this._rangeListeners) {
  1572. listener(begin, chunk);
  1573. }
  1574. }
  1575. onDataProgress(loaded, total) {
  1576. this._readyCapability.promise.then(() => {
  1577. for (const listener of this._progressListeners) {
  1578. listener(loaded, total);
  1579. }
  1580. });
  1581. }
  1582. onDataProgressiveRead(chunk) {
  1583. this._readyCapability.promise.then(() => {
  1584. for (const listener of this._progressiveReadListeners) {
  1585. listener(chunk);
  1586. }
  1587. });
  1588. }
  1589. onDataProgressiveDone() {
  1590. this._readyCapability.promise.then(() => {
  1591. for (const listener of this._progressiveDoneListeners) {
  1592. listener();
  1593. }
  1594. });
  1595. }
  1596. transportReady() {
  1597. this._readyCapability.resolve();
  1598. }
  1599. requestDataRange(begin, end) {
  1600. (0, _util.unreachable)("Abstract method PDFDataRangeTransport.requestDataRange");
  1601. }
  1602. abort() {}
  1603. }
  1604. exports.PDFDataRangeTransport = PDFDataRangeTransport;
  1605. class PDFDocumentProxy {
  1606. constructor(pdfInfo, transport) {
  1607. this._pdfInfo = pdfInfo;
  1608. this._transport = transport;
  1609. }
  1610. get annotationStorage() {
  1611. return (0, _util.shadow)(this, "annotationStorage", new _annotation_storage.AnnotationStorage());
  1612. }
  1613. get numPages() {
  1614. return this._pdfInfo.numPages;
  1615. }
  1616. get fingerprint() {
  1617. return this._pdfInfo.fingerprint;
  1618. }
  1619. get isPureXfa() {
  1620. return this._pdfInfo.isPureXfa;
  1621. }
  1622. getPage(pageNumber) {
  1623. return this._transport.getPage(pageNumber);
  1624. }
  1625. getPageIndex(ref) {
  1626. return this._transport.getPageIndex(ref);
  1627. }
  1628. getDestinations() {
  1629. return this._transport.getDestinations();
  1630. }
  1631. getDestination(id) {
  1632. return this._transport.getDestination(id);
  1633. }
  1634. getPageLabels() {
  1635. return this._transport.getPageLabels();
  1636. }
  1637. getPageLayout() {
  1638. return this._transport.getPageLayout();
  1639. }
  1640. getPageMode() {
  1641. return this._transport.getPageMode();
  1642. }
  1643. getViewerPreferences() {
  1644. return this._transport.getViewerPreferences();
  1645. }
  1646. getOpenAction() {
  1647. return this._transport.getOpenAction();
  1648. }
  1649. getAttachments() {
  1650. return this._transport.getAttachments();
  1651. }
  1652. getJavaScript() {
  1653. return this._transport.getJavaScript();
  1654. }
  1655. getJSActions() {
  1656. return this._transport.getDocJSActions();
  1657. }
  1658. getOutline() {
  1659. return this._transport.getOutline();
  1660. }
  1661. getOptionalContentConfig() {
  1662. return this._transport.getOptionalContentConfig();
  1663. }
  1664. getPermissions() {
  1665. return this._transport.getPermissions();
  1666. }
  1667. getMetadata() {
  1668. return this._transport.getMetadata();
  1669. }
  1670. getMarkInfo() {
  1671. return this._transport.getMarkInfo();
  1672. }
  1673. getData() {
  1674. return this._transport.getData();
  1675. }
  1676. getDownloadInfo() {
  1677. return this._transport.downloadInfoCapability.promise;
  1678. }
  1679. getStats() {
  1680. return this._transport.getStats();
  1681. }
  1682. cleanup(keepLoadedFonts = false) {
  1683. return this._transport.startCleanup(keepLoadedFonts || this.isPureXfa);
  1684. }
  1685. destroy() {
  1686. return this.loadingTask.destroy();
  1687. }
  1688. get loadingParams() {
  1689. return this._transport.loadingParams;
  1690. }
  1691. get loadingTask() {
  1692. return this._transport.loadingTask;
  1693. }
  1694. saveDocument(annotationStorage) {
  1695. return this._transport.saveDocument(annotationStorage);
  1696. }
  1697. getFieldObjects() {
  1698. return this._transport.getFieldObjects();
  1699. }
  1700. hasJSActions() {
  1701. return this._transport.hasJSActions();
  1702. }
  1703. getCalculationOrderIds() {
  1704. return this._transport.getCalculationOrderIds();
  1705. }
  1706. }
  1707. exports.PDFDocumentProxy = PDFDocumentProxy;
  1708. class PDFPageProxy {
  1709. constructor(pageIndex, pageInfo, transport, ownerDocument, pdfBug = false) {
  1710. this._pageIndex = pageIndex;
  1711. this._pageInfo = pageInfo;
  1712. this._ownerDocument = ownerDocument;
  1713. this._transport = transport;
  1714. this._stats = pdfBug ? new _display_utils.StatTimer() : null;
  1715. this._pdfBug = pdfBug;
  1716. this.commonObjs = transport.commonObjs;
  1717. this.objs = new PDFObjects();
  1718. this.cleanupAfterRender = false;
  1719. this.pendingCleanup = false;
  1720. this._intentStates = new Map();
  1721. this.destroyed = false;
  1722. }
  1723. get pageNumber() {
  1724. return this._pageIndex + 1;
  1725. }
  1726. get rotate() {
  1727. return this._pageInfo.rotate;
  1728. }
  1729. get ref() {
  1730. return this._pageInfo.ref;
  1731. }
  1732. get userUnit() {
  1733. return this._pageInfo.userUnit;
  1734. }
  1735. get view() {
  1736. return this._pageInfo.view;
  1737. }
  1738. getViewport({
  1739. scale,
  1740. rotation = this.rotate,
  1741. offsetX = 0,
  1742. offsetY = 0,
  1743. dontFlip = false
  1744. } = {}) {
  1745. return new _display_utils.PageViewport({
  1746. viewBox: this.view,
  1747. scale,
  1748. rotation,
  1749. offsetX,
  1750. offsetY,
  1751. dontFlip
  1752. });
  1753. }
  1754. getAnnotations({
  1755. intent = null
  1756. } = {}) {
  1757. if (!this._annotationsPromise || this._annotationsIntent !== intent) {
  1758. this._annotationsPromise = this._transport.getAnnotations(this._pageIndex, intent);
  1759. this._annotationsIntent = intent;
  1760. }
  1761. return this._annotationsPromise;
  1762. }
  1763. getJSActions() {
  1764. return this._jsActionsPromise || (this._jsActionsPromise = this._transport.getPageJSActions(this._pageIndex));
  1765. }
  1766. getXfa() {
  1767. return this._xfaPromise || (this._xfaPromise = this._transport.getPageXfa(this._pageIndex));
  1768. }
  1769. render({
  1770. canvasContext,
  1771. viewport,
  1772. intent = "display",
  1773. enableWebGL = false,
  1774. renderInteractiveForms = false,
  1775. transform = null,
  1776. imageLayer = null,
  1777. canvasFactory = null,
  1778. background = null,
  1779. annotationStorage = null,
  1780. optionalContentConfigPromise = null
  1781. }) {
  1782. var _intentState;
  1783. if (this._stats) {
  1784. this._stats.time("Overall");
  1785. }
  1786. const renderingIntent = intent === "print" ? "print" : "display";
  1787. this.pendingCleanup = false;
  1788. if (!optionalContentConfigPromise) {
  1789. optionalContentConfigPromise = this._transport.getOptionalContentConfig();
  1790. }
  1791. let intentState = this._intentStates.get(renderingIntent);
  1792. if (!intentState) {
  1793. intentState = Object.create(null);
  1794. this._intentStates.set(renderingIntent, intentState);
  1795. }
  1796. if (intentState.streamReaderCancelTimeout) {
  1797. clearTimeout(intentState.streamReaderCancelTimeout);
  1798. intentState.streamReaderCancelTimeout = null;
  1799. }
  1800. const canvasFactoryInstance = canvasFactory || new DefaultCanvasFactory({
  1801. ownerDocument: this._ownerDocument
  1802. });
  1803. const webGLContext = new _webgl.WebGLContext({
  1804. enable: enableWebGL
  1805. });
  1806. if (!intentState.displayReadyCapability) {
  1807. intentState.displayReadyCapability = (0, _util.createPromiseCapability)();
  1808. intentState.operatorList = {
  1809. fnArray: [],
  1810. argsArray: [],
  1811. lastChunk: false
  1812. };
  1813. if (this._stats) {
  1814. this._stats.time("Page Request");
  1815. }
  1816. this._pumpOperatorList({
  1817. pageIndex: this._pageIndex,
  1818. intent: renderingIntent,
  1819. renderInteractiveForms: renderInteractiveForms === true,
  1820. annotationStorage: annotationStorage?.serializable || null
  1821. });
  1822. }
  1823. const complete = error => {
  1824. intentState.renderTasks.delete(internalRenderTask);
  1825. if (this.cleanupAfterRender || renderingIntent === "print") {
  1826. this.pendingCleanup = true;
  1827. }
  1828. this._tryCleanup();
  1829. if (error) {
  1830. internalRenderTask.capability.reject(error);
  1831. this._abortOperatorList({
  1832. intentState,
  1833. reason: error
  1834. });
  1835. } else {
  1836. internalRenderTask.capability.resolve();
  1837. }
  1838. if (this._stats) {
  1839. this._stats.timeEnd("Rendering");
  1840. this._stats.timeEnd("Overall");
  1841. }
  1842. };
  1843. const internalRenderTask = new InternalRenderTask({
  1844. callback: complete,
  1845. params: {
  1846. canvasContext,
  1847. viewport,
  1848. transform,
  1849. imageLayer,
  1850. background
  1851. },
  1852. objs: this.objs,
  1853. commonObjs: this.commonObjs,
  1854. operatorList: intentState.operatorList,
  1855. pageIndex: this._pageIndex,
  1856. canvasFactory: canvasFactoryInstance,
  1857. webGLContext,
  1858. useRequestAnimationFrame: renderingIntent !== "print",
  1859. pdfBug: this._pdfBug
  1860. });
  1861. ((_intentState = intentState).renderTasks || (_intentState.renderTasks = new Set())).add(internalRenderTask);
  1862. const renderTask = internalRenderTask.task;
  1863. Promise.all([intentState.displayReadyCapability.promise, optionalContentConfigPromise]).then(([transparency, optionalContentConfig]) => {
  1864. if (this.pendingCleanup) {
  1865. complete();
  1866. return;
  1867. }
  1868. if (this._stats) {
  1869. this._stats.time("Rendering");
  1870. }
  1871. internalRenderTask.initializeGraphics({
  1872. transparency,
  1873. optionalContentConfig
  1874. });
  1875. internalRenderTask.operatorListChanged();
  1876. }).catch(complete);
  1877. return renderTask;
  1878. }
  1879. getOperatorList() {
  1880. function operatorListChanged() {
  1881. if (intentState.operatorList.lastChunk) {
  1882. intentState.opListReadCapability.resolve(intentState.operatorList);
  1883. intentState.renderTasks.delete(opListTask);
  1884. }
  1885. }
  1886. const renderingIntent = "oplist";
  1887. let intentState = this._intentStates.get(renderingIntent);
  1888. if (!intentState) {
  1889. intentState = Object.create(null);
  1890. this._intentStates.set(renderingIntent, intentState);
  1891. }
  1892. let opListTask;
  1893. if (!intentState.opListReadCapability) {
  1894. var _intentState2;
  1895. opListTask = Object.create(null);
  1896. opListTask.operatorListChanged = operatorListChanged;
  1897. intentState.opListReadCapability = (0, _util.createPromiseCapability)();
  1898. ((_intentState2 = intentState).renderTasks || (_intentState2.renderTasks = new Set())).add(opListTask);
  1899. intentState.operatorList = {
  1900. fnArray: [],
  1901. argsArray: [],
  1902. lastChunk: false
  1903. };
  1904. if (this._stats) {
  1905. this._stats.time("Page Request");
  1906. }
  1907. this._pumpOperatorList({
  1908. pageIndex: this._pageIndex,
  1909. intent: renderingIntent
  1910. });
  1911. }
  1912. return intentState.opListReadCapability.promise;
  1913. }
  1914. streamTextContent({
  1915. normalizeWhitespace = false,
  1916. disableCombineTextItems = false
  1917. } = {}) {
  1918. const TEXT_CONTENT_CHUNK_SIZE = 100;
  1919. return this._transport.messageHandler.sendWithStream("GetTextContent", {
  1920. pageIndex: this._pageIndex,
  1921. normalizeWhitespace: normalizeWhitespace === true,
  1922. combineTextItems: disableCombineTextItems !== true
  1923. }, {
  1924. highWaterMark: TEXT_CONTENT_CHUNK_SIZE,
  1925. size(textContent) {
  1926. return textContent.items.length;
  1927. }
  1928. });
  1929. }
  1930. getTextContent(params = {}) {
  1931. const readableStream = this.streamTextContent(params);
  1932. return new Promise(function (resolve, reject) {
  1933. function pump() {
  1934. reader.read().then(function ({
  1935. value,
  1936. done
  1937. }) {
  1938. if (done) {
  1939. resolve(textContent);
  1940. return;
  1941. }
  1942. Object.assign(textContent.styles, value.styles);
  1943. textContent.items.push(...value.items);
  1944. pump();
  1945. }, reject);
  1946. }
  1947. const reader = readableStream.getReader();
  1948. const textContent = {
  1949. items: [],
  1950. styles: Object.create(null)
  1951. };
  1952. pump();
  1953. });
  1954. }
  1955. _destroy() {
  1956. this.destroyed = true;
  1957. this._transport.pageCache[this._pageIndex] = null;
  1958. const waitOn = [];
  1959. for (const [intent, intentState] of this._intentStates) {
  1960. this._abortOperatorList({
  1961. intentState,
  1962. reason: new Error("Page was destroyed."),
  1963. force: true
  1964. });
  1965. if (intent === "oplist") {
  1966. continue;
  1967. }
  1968. for (const internalRenderTask of intentState.renderTasks) {
  1969. waitOn.push(internalRenderTask.completed);
  1970. internalRenderTask.cancel();
  1971. }
  1972. }
  1973. this.objs.clear();
  1974. this._annotationsPromise = null;
  1975. this._jsActionsPromise = null;
  1976. this._xfaPromise = null;
  1977. this.pendingCleanup = false;
  1978. return Promise.all(waitOn);
  1979. }
  1980. cleanup(resetStats = false) {
  1981. this.pendingCleanup = true;
  1982. return this._tryCleanup(resetStats);
  1983. }
  1984. _tryCleanup(resetStats = false) {
  1985. if (!this.pendingCleanup) {
  1986. return false;
  1987. }
  1988. for (const {
  1989. renderTasks,
  1990. operatorList
  1991. } of this._intentStates.values()) {
  1992. if (renderTasks.size > 0 || !operatorList.lastChunk) {
  1993. return false;
  1994. }
  1995. }
  1996. this._intentStates.clear();
  1997. this.objs.clear();
  1998. this._annotationsPromise = null;
  1999. this._jsActionsPromise = null;
  2000. this._xfaPromise = null;
  2001. if (resetStats && this._stats) {
  2002. this._stats = new _display_utils.StatTimer();
  2003. }
  2004. this.pendingCleanup = false;
  2005. return true;
  2006. }
  2007. _startRenderPage(transparency, intent) {
  2008. const intentState = this._intentStates.get(intent);
  2009. if (!intentState) {
  2010. return;
  2011. }
  2012. if (this._stats) {
  2013. this._stats.timeEnd("Page Request");
  2014. }
  2015. if (intentState.displayReadyCapability) {
  2016. intentState.displayReadyCapability.resolve(transparency);
  2017. }
  2018. }
  2019. _renderPageChunk(operatorListChunk, intentState) {
  2020. for (let i = 0, ii = operatorListChunk.length; i < ii; i++) {
  2021. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  2022. intentState.operatorList.argsArray.push(operatorListChunk.argsArray[i]);
  2023. }
  2024. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  2025. for (const internalRenderTask of intentState.renderTasks) {
  2026. internalRenderTask.operatorListChanged();
  2027. }
  2028. if (operatorListChunk.lastChunk) {
  2029. this._tryCleanup();
  2030. }
  2031. }
  2032. _pumpOperatorList(args) {
  2033. (0, _util.assert)(args.intent, 'PDFPageProxy._pumpOperatorList: Expected "intent" argument.');
  2034. const readableStream = this._transport.messageHandler.sendWithStream("GetOperatorList", args);
  2035. const reader = readableStream.getReader();
  2036. const intentState = this._intentStates.get(args.intent);
  2037. intentState.streamReader = reader;
  2038. const pump = () => {
  2039. reader.read().then(({
  2040. value,
  2041. done
  2042. }) => {
  2043. if (done) {
  2044. intentState.streamReader = null;
  2045. return;
  2046. }
  2047. if (this._transport.destroyed) {
  2048. return;
  2049. }
  2050. this._renderPageChunk(value, intentState);
  2051. pump();
  2052. }, reason => {
  2053. intentState.streamReader = null;
  2054. if (this._transport.destroyed) {
  2055. return;
  2056. }
  2057. if (intentState.operatorList) {
  2058. intentState.operatorList.lastChunk = true;
  2059. for (const internalRenderTask of intentState.renderTasks) {
  2060. internalRenderTask.operatorListChanged();
  2061. }
  2062. this._tryCleanup();
  2063. }
  2064. if (intentState.displayReadyCapability) {
  2065. intentState.displayReadyCapability.reject(reason);
  2066. } else if (intentState.opListReadCapability) {
  2067. intentState.opListReadCapability.reject(reason);
  2068. } else {
  2069. throw reason;
  2070. }
  2071. });
  2072. };
  2073. pump();
  2074. }
  2075. _abortOperatorList({
  2076. intentState,
  2077. reason,
  2078. force = false
  2079. }) {
  2080. (0, _util.assert)(reason instanceof Error || typeof reason === "object" && reason !== null, 'PDFPageProxy._abortOperatorList: Expected "reason" argument.');
  2081. if (!intentState.streamReader) {
  2082. return;
  2083. }
  2084. if (!force) {
  2085. if (intentState.renderTasks.size > 0) {
  2086. return;
  2087. }
  2088. if (reason instanceof _display_utils.RenderingCancelledException) {
  2089. intentState.streamReaderCancelTimeout = setTimeout(() => {
  2090. this._abortOperatorList({
  2091. intentState,
  2092. reason,
  2093. force: true
  2094. });
  2095. intentState.streamReaderCancelTimeout = null;
  2096. }, RENDERING_CANCELLED_TIMEOUT);
  2097. return;
  2098. }
  2099. }
  2100. intentState.streamReader.cancel(new _util.AbortException(reason?.message));
  2101. intentState.streamReader = null;
  2102. if (this._transport.destroyed) {
  2103. return;
  2104. }
  2105. for (const [intent, curIntentState] of this._intentStates) {
  2106. if (curIntentState === intentState) {
  2107. this._intentStates.delete(intent);
  2108. break;
  2109. }
  2110. }
  2111. this.cleanup();
  2112. }
  2113. get stats() {
  2114. return this._stats;
  2115. }
  2116. }
  2117. exports.PDFPageProxy = PDFPageProxy;
  2118. class LoopbackPort {
  2119. constructor() {
  2120. this._listeners = [];
  2121. this._deferred = Promise.resolve(undefined);
  2122. }
  2123. postMessage(obj, transfers) {
  2124. function cloneValue(value) {
  2125. if (typeof value !== "object" || value === null) {
  2126. return value;
  2127. }
  2128. if (cloned.has(value)) {
  2129. return cloned.get(value);
  2130. }
  2131. let buffer, result;
  2132. if ((buffer = value.buffer) && (0, _util.isArrayBuffer)(buffer)) {
  2133. if (transfers?.includes(buffer)) {
  2134. result = new value.constructor(buffer, value.byteOffset, value.byteLength);
  2135. } else {
  2136. result = new value.constructor(value);
  2137. }
  2138. cloned.set(value, result);
  2139. return result;
  2140. }
  2141. if (value instanceof Map) {
  2142. result = new Map();
  2143. cloned.set(value, result);
  2144. for (const [key, val] of value) {
  2145. result.set(key, cloneValue(val));
  2146. }
  2147. return result;
  2148. }
  2149. if (value instanceof Set) {
  2150. result = new Set();
  2151. cloned.set(value, result);
  2152. for (const val of value) {
  2153. result.add(cloneValue(val));
  2154. }
  2155. return result;
  2156. }
  2157. result = Array.isArray(value) ? [] : {};
  2158. cloned.set(value, result);
  2159. for (const i in value) {
  2160. let desc,
  2161. p = value;
  2162. while (!(desc = Object.getOwnPropertyDescriptor(p, i))) {
  2163. p = Object.getPrototypeOf(p);
  2164. }
  2165. if (typeof desc.value === "undefined") {
  2166. continue;
  2167. }
  2168. if (typeof desc.value === "function") {
  2169. if (value.hasOwnProperty?.(i)) {
  2170. throw new Error(`LoopbackPort.postMessage - cannot clone: ${value[i]}`);
  2171. }
  2172. continue;
  2173. }
  2174. result[i] = cloneValue(desc.value);
  2175. }
  2176. return result;
  2177. }
  2178. const cloned = new WeakMap();
  2179. const event = {
  2180. data: cloneValue(obj)
  2181. };
  2182. this._deferred.then(() => {
  2183. for (const listener of this._listeners) {
  2184. listener.call(this, event);
  2185. }
  2186. });
  2187. }
  2188. addEventListener(name, listener) {
  2189. this._listeners.push(listener);
  2190. }
  2191. removeEventListener(name, listener) {
  2192. const i = this._listeners.indexOf(listener);
  2193. this._listeners.splice(i, 1);
  2194. }
  2195. terminate() {
  2196. this._listeners.length = 0;
  2197. }
  2198. }
  2199. exports.LoopbackPort = LoopbackPort;
  2200. const PDFWorker = function PDFWorkerClosure() {
  2201. const pdfWorkerPorts = new WeakMap();
  2202. let isWorkerDisabled = false;
  2203. let fallbackWorkerSrc;
  2204. let nextFakeWorkerId = 0;
  2205. let fakeWorkerCapability;
  2206. if (_is_node.isNodeJS && typeof require === "function") {
  2207. isWorkerDisabled = true;
  2208. fallbackWorkerSrc = "./pdf.worker.js";
  2209. } else if (typeof document === "object" && "currentScript" in document) {
  2210. const pdfjsFilePath = document.currentScript?.src;
  2211. if (pdfjsFilePath) {
  2212. fallbackWorkerSrc = pdfjsFilePath.replace(/(\.(?:min\.)?js)(\?.*)?$/i, ".worker$1$2");
  2213. }
  2214. }
  2215. function getWorkerSrc() {
  2216. if (_worker_options.GlobalWorkerOptions.workerSrc) {
  2217. return _worker_options.GlobalWorkerOptions.workerSrc;
  2218. }
  2219. if (typeof fallbackWorkerSrc !== "undefined") {
  2220. if (!_is_node.isNodeJS) {
  2221. (0, _display_utils.deprecated)('No "GlobalWorkerOptions.workerSrc" specified.');
  2222. }
  2223. return fallbackWorkerSrc;
  2224. }
  2225. throw new Error('No "GlobalWorkerOptions.workerSrc" specified.');
  2226. }
  2227. function getMainThreadWorkerMessageHandler() {
  2228. let mainWorkerMessageHandler;
  2229. try {
  2230. mainWorkerMessageHandler = globalThis.pdfjsWorker?.WorkerMessageHandler;
  2231. } catch (ex) {}
  2232. return mainWorkerMessageHandler || null;
  2233. }
  2234. function setupFakeWorkerGlobal() {
  2235. if (fakeWorkerCapability) {
  2236. return fakeWorkerCapability.promise;
  2237. }
  2238. fakeWorkerCapability = (0, _util.createPromiseCapability)();
  2239. const loader = async function () {
  2240. const mainWorkerMessageHandler = getMainThreadWorkerMessageHandler();
  2241. if (mainWorkerMessageHandler) {
  2242. return mainWorkerMessageHandler;
  2243. }
  2244. if (_is_node.isNodeJS && typeof require === "function") {
  2245. const worker = eval("require")(getWorkerSrc());
  2246. return worker.WorkerMessageHandler;
  2247. }
  2248. await (0, _display_utils.loadScript)(getWorkerSrc());
  2249. return window.pdfjsWorker.WorkerMessageHandler;
  2250. };
  2251. loader().then(fakeWorkerCapability.resolve, fakeWorkerCapability.reject);
  2252. return fakeWorkerCapability.promise;
  2253. }
  2254. function createCDNWrapper(url) {
  2255. const wrapper = "importScripts('" + url + "');";
  2256. return URL.createObjectURL(new Blob([wrapper]));
  2257. }
  2258. class PDFWorker {
  2259. constructor({
  2260. name = null,
  2261. port = null,
  2262. verbosity = (0, _util.getVerbosityLevel)()
  2263. } = {}) {
  2264. if (port && pdfWorkerPorts.has(port)) {
  2265. throw new Error("Cannot use more than one PDFWorker per port");
  2266. }
  2267. this.name = name;
  2268. this.destroyed = false;
  2269. this.postMessageTransfers = true;
  2270. this.verbosity = verbosity;
  2271. this._readyCapability = (0, _util.createPromiseCapability)();
  2272. this._port = null;
  2273. this._webWorker = null;
  2274. this._messageHandler = null;
  2275. if (port) {
  2276. pdfWorkerPorts.set(port, this);
  2277. this._initializeFromPort(port);
  2278. return;
  2279. }
  2280. this._initialize();
  2281. }
  2282. get promise() {
  2283. return this._readyCapability.promise;
  2284. }
  2285. get port() {
  2286. return this._port;
  2287. }
  2288. get messageHandler() {
  2289. return this._messageHandler;
  2290. }
  2291. _initializeFromPort(port) {
  2292. this._port = port;
  2293. this._messageHandler = new _message_handler.MessageHandler("main", "worker", port);
  2294. this._messageHandler.on("ready", function () {});
  2295. this._readyCapability.resolve();
  2296. }
  2297. _initialize() {
  2298. if (typeof Worker !== "undefined" && !isWorkerDisabled && !getMainThreadWorkerMessageHandler()) {
  2299. let workerSrc = getWorkerSrc();
  2300. try {
  2301. if (!(0, _util.isSameOrigin)(window.location.href, workerSrc)) {
  2302. workerSrc = createCDNWrapper(new URL(workerSrc, window.location).href);
  2303. }
  2304. const worker = new Worker(workerSrc);
  2305. const messageHandler = new _message_handler.MessageHandler("main", "worker", worker);
  2306. const terminateEarly = () => {
  2307. worker.removeEventListener("error", onWorkerError);
  2308. messageHandler.destroy();
  2309. worker.terminate();
  2310. if (this.destroyed) {
  2311. this._readyCapability.reject(new Error("Worker was destroyed"));
  2312. } else {
  2313. this._setupFakeWorker();
  2314. }
  2315. };
  2316. const onWorkerError = () => {
  2317. if (!this._webWorker) {
  2318. terminateEarly();
  2319. }
  2320. };
  2321. worker.addEventListener("error", onWorkerError);
  2322. messageHandler.on("test", data => {
  2323. worker.removeEventListener("error", onWorkerError);
  2324. if (this.destroyed) {
  2325. terminateEarly();
  2326. return;
  2327. }
  2328. if (data) {
  2329. this._messageHandler = messageHandler;
  2330. this._port = worker;
  2331. this._webWorker = worker;
  2332. if (!data.supportTransfers) {
  2333. this.postMessageTransfers = false;
  2334. }
  2335. this._readyCapability.resolve();
  2336. messageHandler.send("configure", {
  2337. verbosity: this.verbosity
  2338. });
  2339. } else {
  2340. this._setupFakeWorker();
  2341. messageHandler.destroy();
  2342. worker.terminate();
  2343. }
  2344. });
  2345. messageHandler.on("ready", data => {
  2346. worker.removeEventListener("error", onWorkerError);
  2347. if (this.destroyed) {
  2348. terminateEarly();
  2349. return;
  2350. }
  2351. try {
  2352. sendTest();
  2353. } catch (e) {
  2354. this._setupFakeWorker();
  2355. }
  2356. });
  2357. const sendTest = () => {
  2358. const testObj = new Uint8Array([this.postMessageTransfers ? 255 : 0]);
  2359. try {
  2360. messageHandler.send("test", testObj, [testObj.buffer]);
  2361. } catch (ex) {
  2362. (0, _util.warn)("Cannot use postMessage transfers.");
  2363. testObj[0] = 0;
  2364. messageHandler.send("test", testObj);
  2365. }
  2366. };
  2367. sendTest();
  2368. return;
  2369. } catch (e) {
  2370. (0, _util.info)("The worker has been disabled.");
  2371. }
  2372. }
  2373. this._setupFakeWorker();
  2374. }
  2375. _setupFakeWorker() {
  2376. if (!isWorkerDisabled) {
  2377. (0, _util.warn)("Setting up fake worker.");
  2378. isWorkerDisabled = true;
  2379. }
  2380. setupFakeWorkerGlobal().then(WorkerMessageHandler => {
  2381. if (this.destroyed) {
  2382. this._readyCapability.reject(new Error("Worker was destroyed"));
  2383. return;
  2384. }
  2385. const port = new LoopbackPort();
  2386. this._port = port;
  2387. const id = "fake" + nextFakeWorkerId++;
  2388. const workerHandler = new _message_handler.MessageHandler(id + "_worker", id, port);
  2389. WorkerMessageHandler.setup(workerHandler, port);
  2390. const messageHandler = new _message_handler.MessageHandler(id, id + "_worker", port);
  2391. this._messageHandler = messageHandler;
  2392. this._readyCapability.resolve();
  2393. messageHandler.send("configure", {
  2394. verbosity: this.verbosity
  2395. });
  2396. }).catch(reason => {
  2397. this._readyCapability.reject(new Error(`Setting up fake worker failed: "${reason.message}".`));
  2398. });
  2399. }
  2400. destroy() {
  2401. this.destroyed = true;
  2402. if (this._webWorker) {
  2403. this._webWorker.terminate();
  2404. this._webWorker = null;
  2405. }
  2406. pdfWorkerPorts.delete(this._port);
  2407. this._port = null;
  2408. if (this._messageHandler) {
  2409. this._messageHandler.destroy();
  2410. this._messageHandler = null;
  2411. }
  2412. }
  2413. static fromPort(params) {
  2414. if (!params || !params.port) {
  2415. throw new Error("PDFWorker.fromPort - invalid method signature.");
  2416. }
  2417. if (pdfWorkerPorts.has(params.port)) {
  2418. return pdfWorkerPorts.get(params.port);
  2419. }
  2420. return new PDFWorker(params);
  2421. }
  2422. static getWorkerSrc() {
  2423. return getWorkerSrc();
  2424. }
  2425. }
  2426. return PDFWorker;
  2427. }();
  2428. exports.PDFWorker = PDFWorker;
  2429. class WorkerTransport {
  2430. constructor(messageHandler, loadingTask, networkStream, params) {
  2431. this.messageHandler = messageHandler;
  2432. this.loadingTask = loadingTask;
  2433. this.commonObjs = new PDFObjects();
  2434. this.fontLoader = new _font_loader.FontLoader({
  2435. docId: loadingTask.docId,
  2436. onUnsupportedFeature: this._onUnsupportedFeature.bind(this),
  2437. ownerDocument: params.ownerDocument
  2438. });
  2439. this._params = params;
  2440. this.CMapReaderFactory = new params.CMapReaderFactory({
  2441. baseUrl: params.cMapUrl,
  2442. isCompressed: params.cMapPacked
  2443. });
  2444. this.destroyed = false;
  2445. this.destroyCapability = null;
  2446. this._passwordCapability = null;
  2447. this._networkStream = networkStream;
  2448. this._fullReader = null;
  2449. this._lastProgress = null;
  2450. this.pageCache = [];
  2451. this.pagePromises = [];
  2452. this.downloadInfoCapability = (0, _util.createPromiseCapability)();
  2453. this.setupMessageHandler();
  2454. }
  2455. get loadingTaskSettled() {
  2456. return this.loadingTask._capability.settled;
  2457. }
  2458. destroy() {
  2459. if (this.destroyCapability) {
  2460. return this.destroyCapability.promise;
  2461. }
  2462. this.destroyed = true;
  2463. this.destroyCapability = (0, _util.createPromiseCapability)();
  2464. if (this._passwordCapability) {
  2465. this._passwordCapability.reject(new Error("Worker was destroyed during onPassword callback"));
  2466. }
  2467. const waitOn = [];
  2468. this.pageCache.forEach(function (page) {
  2469. if (page) {
  2470. waitOn.push(page._destroy());
  2471. }
  2472. });
  2473. this.pageCache.length = 0;
  2474. this.pagePromises.length = 0;
  2475. const terminated = this.messageHandler.sendWithPromise("Terminate", null);
  2476. waitOn.push(terminated);
  2477. if (this.loadingTaskSettled) {
  2478. const annotationStorageResetModified = this.loadingTask.promise.then(pdfDocument => {
  2479. if (pdfDocument.hasOwnProperty("annotationStorage")) {
  2480. pdfDocument.annotationStorage.resetModified();
  2481. }
  2482. }).catch(() => {});
  2483. waitOn.push(annotationStorageResetModified);
  2484. }
  2485. Promise.all(waitOn).then(() => {
  2486. this.commonObjs.clear();
  2487. this.fontLoader.clear();
  2488. this._hasJSActionsPromise = null;
  2489. if (this._networkStream) {
  2490. this._networkStream.cancelAllRequests(new _util.AbortException("Worker was terminated."));
  2491. }
  2492. if (this.messageHandler) {
  2493. this.messageHandler.destroy();
  2494. this.messageHandler = null;
  2495. }
  2496. this.destroyCapability.resolve();
  2497. }, this.destroyCapability.reject);
  2498. return this.destroyCapability.promise;
  2499. }
  2500. setupMessageHandler() {
  2501. const {
  2502. messageHandler,
  2503. loadingTask
  2504. } = this;
  2505. messageHandler.on("GetReader", (data, sink) => {
  2506. (0, _util.assert)(this._networkStream, "GetReader - no `IPDFStream` instance available.");
  2507. this._fullReader = this._networkStream.getFullReader();
  2508. this._fullReader.onProgress = evt => {
  2509. this._lastProgress = {
  2510. loaded: evt.loaded,
  2511. total: evt.total
  2512. };
  2513. };
  2514. sink.onPull = () => {
  2515. this._fullReader.read().then(function ({
  2516. value,
  2517. done
  2518. }) {
  2519. if (done) {
  2520. sink.close();
  2521. return;
  2522. }
  2523. (0, _util.assert)((0, _util.isArrayBuffer)(value), "GetReader - expected an ArrayBuffer.");
  2524. sink.enqueue(new Uint8Array(value), 1, [value]);
  2525. }).catch(reason => {
  2526. sink.error(reason);
  2527. });
  2528. };
  2529. sink.onCancel = reason => {
  2530. this._fullReader.cancel(reason);
  2531. sink.ready.catch(readyReason => {
  2532. if (this.destroyed) {
  2533. return;
  2534. }
  2535. throw readyReason;
  2536. });
  2537. };
  2538. });
  2539. messageHandler.on("ReaderHeadersReady", data => {
  2540. const headersCapability = (0, _util.createPromiseCapability)();
  2541. const fullReader = this._fullReader;
  2542. fullReader.headersReady.then(() => {
  2543. if (!fullReader.isStreamingSupported || !fullReader.isRangeSupported) {
  2544. if (this._lastProgress && loadingTask.onProgress) {
  2545. loadingTask.onProgress(this._lastProgress);
  2546. }
  2547. fullReader.onProgress = evt => {
  2548. if (loadingTask.onProgress) {
  2549. loadingTask.onProgress({
  2550. loaded: evt.loaded,
  2551. total: evt.total
  2552. });
  2553. }
  2554. };
  2555. }
  2556. headersCapability.resolve({
  2557. isStreamingSupported: fullReader.isStreamingSupported,
  2558. isRangeSupported: fullReader.isRangeSupported,
  2559. contentLength: fullReader.contentLength
  2560. });
  2561. }, headersCapability.reject);
  2562. return headersCapability.promise;
  2563. });
  2564. messageHandler.on("GetRangeReader", (data, sink) => {
  2565. (0, _util.assert)(this._networkStream, "GetRangeReader - no `IPDFStream` instance available.");
  2566. const rangeReader = this._networkStream.getRangeReader(data.begin, data.end);
  2567. if (!rangeReader) {
  2568. sink.close();
  2569. return;
  2570. }
  2571. sink.onPull = () => {
  2572. rangeReader.read().then(function ({
  2573. value,
  2574. done
  2575. }) {
  2576. if (done) {
  2577. sink.close();
  2578. return;
  2579. }
  2580. (0, _util.assert)((0, _util.isArrayBuffer)(value), "GetRangeReader - expected an ArrayBuffer.");
  2581. sink.enqueue(new Uint8Array(value), 1, [value]);
  2582. }).catch(reason => {
  2583. sink.error(reason);
  2584. });
  2585. };
  2586. sink.onCancel = reason => {
  2587. rangeReader.cancel(reason);
  2588. sink.ready.catch(readyReason => {
  2589. if (this.destroyed) {
  2590. return;
  2591. }
  2592. throw readyReason;
  2593. });
  2594. };
  2595. });
  2596. messageHandler.on("GetDoc", ({
  2597. pdfInfo
  2598. }) => {
  2599. this._numPages = pdfInfo.numPages;
  2600. loadingTask._capability.resolve(new PDFDocumentProxy(pdfInfo, this));
  2601. });
  2602. messageHandler.on("DocException", function (ex) {
  2603. let reason;
  2604. switch (ex.name) {
  2605. case "PasswordException":
  2606. reason = new _util.PasswordException(ex.message, ex.code);
  2607. break;
  2608. case "InvalidPDFException":
  2609. reason = new _util.InvalidPDFException(ex.message);
  2610. break;
  2611. case "MissingPDFException":
  2612. reason = new _util.MissingPDFException(ex.message);
  2613. break;
  2614. case "UnexpectedResponseException":
  2615. reason = new _util.UnexpectedResponseException(ex.message, ex.status);
  2616. break;
  2617. case "UnknownErrorException":
  2618. reason = new _util.UnknownErrorException(ex.message, ex.details);
  2619. break;
  2620. }
  2621. if (!(reason instanceof Error)) {
  2622. const msg = "DocException - expected a valid Error.";
  2623. (0, _util.warn)(msg);
  2624. }
  2625. loadingTask._capability.reject(reason);
  2626. });
  2627. messageHandler.on("PasswordRequest", exception => {
  2628. this._passwordCapability = (0, _util.createPromiseCapability)();
  2629. if (loadingTask.onPassword) {
  2630. const updatePassword = password => {
  2631. this._passwordCapability.resolve({
  2632. password
  2633. });
  2634. };
  2635. try {
  2636. loadingTask.onPassword(updatePassword, exception.code);
  2637. } catch (ex) {
  2638. this._passwordCapability.reject(ex);
  2639. }
  2640. } else {
  2641. this._passwordCapability.reject(new _util.PasswordException(exception.message, exception.code));
  2642. }
  2643. return this._passwordCapability.promise;
  2644. });
  2645. messageHandler.on("DataLoaded", data => {
  2646. if (loadingTask.onProgress) {
  2647. loadingTask.onProgress({
  2648. loaded: data.length,
  2649. total: data.length
  2650. });
  2651. }
  2652. this.downloadInfoCapability.resolve(data);
  2653. });
  2654. messageHandler.on("StartRenderPage", data => {
  2655. if (this.destroyed) {
  2656. return;
  2657. }
  2658. const page = this.pageCache[data.pageIndex];
  2659. page._startRenderPage(data.transparency, data.intent);
  2660. });
  2661. messageHandler.on("commonobj", data => {
  2662. if (this.destroyed) {
  2663. return;
  2664. }
  2665. const [id, type, exportedData] = data;
  2666. if (this.commonObjs.has(id)) {
  2667. return;
  2668. }
  2669. switch (type) {
  2670. case "Font":
  2671. const params = this._params;
  2672. if ("error" in exportedData) {
  2673. const exportedError = exportedData.error;
  2674. (0, _util.warn)(`Error during font loading: ${exportedError}`);
  2675. this.commonObjs.resolve(id, exportedError);
  2676. break;
  2677. }
  2678. let fontRegistry = null;
  2679. if (params.pdfBug && globalThis.FontInspector?.enabled) {
  2680. fontRegistry = {
  2681. registerFont(font, url) {
  2682. globalThis.FontInspector.fontAdded(font, url);
  2683. }
  2684. };
  2685. }
  2686. const font = new _font_loader.FontFaceObject(exportedData, {
  2687. isEvalSupported: params.isEvalSupported,
  2688. disableFontFace: params.disableFontFace,
  2689. ignoreErrors: params.ignoreErrors,
  2690. onUnsupportedFeature: this._onUnsupportedFeature.bind(this),
  2691. fontRegistry
  2692. });
  2693. this.fontLoader.bind(font).catch(reason => {
  2694. return messageHandler.sendWithPromise("FontFallback", {
  2695. id
  2696. });
  2697. }).finally(() => {
  2698. if (!params.fontExtraProperties && font.data) {
  2699. font.data = null;
  2700. }
  2701. this.commonObjs.resolve(id, font);
  2702. });
  2703. break;
  2704. case "FontPath":
  2705. case "Image":
  2706. this.commonObjs.resolve(id, exportedData);
  2707. break;
  2708. default:
  2709. throw new Error(`Got unknown common object type ${type}`);
  2710. }
  2711. });
  2712. messageHandler.on("obj", data => {
  2713. if (this.destroyed) {
  2714. return undefined;
  2715. }
  2716. const [id, pageIndex, type, imageData] = data;
  2717. const pageProxy = this.pageCache[pageIndex];
  2718. if (pageProxy.objs.has(id)) {
  2719. return undefined;
  2720. }
  2721. switch (type) {
  2722. case "Image":
  2723. pageProxy.objs.resolve(id, imageData);
  2724. const MAX_IMAGE_SIZE_TO_STORE = 8000000;
  2725. if (imageData?.data?.length > MAX_IMAGE_SIZE_TO_STORE) {
  2726. pageProxy.cleanupAfterRender = true;
  2727. }
  2728. break;
  2729. default:
  2730. throw new Error(`Got unknown object type ${type}`);
  2731. }
  2732. return undefined;
  2733. });
  2734. messageHandler.on("DocProgress", data => {
  2735. if (this.destroyed) {
  2736. return;
  2737. }
  2738. if (loadingTask.onProgress) {
  2739. loadingTask.onProgress({
  2740. loaded: data.loaded,
  2741. total: data.total
  2742. });
  2743. }
  2744. });
  2745. messageHandler.on("UnsupportedFeature", this._onUnsupportedFeature.bind(this));
  2746. messageHandler.on("FetchBuiltInCMap", (data, sink) => {
  2747. if (this.destroyed) {
  2748. sink.error(new Error("Worker was destroyed"));
  2749. return;
  2750. }
  2751. let fetched = false;
  2752. sink.onPull = () => {
  2753. if (fetched) {
  2754. sink.close();
  2755. return;
  2756. }
  2757. fetched = true;
  2758. this.CMapReaderFactory.fetch(data).then(function (builtInCMap) {
  2759. sink.enqueue(builtInCMap, 1, [builtInCMap.cMapData.buffer]);
  2760. }).catch(function (reason) {
  2761. sink.error(reason);
  2762. });
  2763. };
  2764. });
  2765. }
  2766. _onUnsupportedFeature({
  2767. featureId
  2768. }) {
  2769. if (this.destroyed) {
  2770. return;
  2771. }
  2772. if (this.loadingTask.onUnsupportedFeature) {
  2773. this.loadingTask.onUnsupportedFeature(featureId);
  2774. }
  2775. }
  2776. getData() {
  2777. return this.messageHandler.sendWithPromise("GetData", null);
  2778. }
  2779. getPage(pageNumber) {
  2780. if (!Number.isInteger(pageNumber) || pageNumber <= 0 || pageNumber > this._numPages) {
  2781. return Promise.reject(new Error("Invalid page request"));
  2782. }
  2783. const pageIndex = pageNumber - 1;
  2784. if (pageIndex in this.pagePromises) {
  2785. return this.pagePromises[pageIndex];
  2786. }
  2787. const promise = this.messageHandler.sendWithPromise("GetPage", {
  2788. pageIndex
  2789. }).then(pageInfo => {
  2790. if (this.destroyed) {
  2791. throw new Error("Transport destroyed");
  2792. }
  2793. const page = new PDFPageProxy(pageIndex, pageInfo, this, this._params.ownerDocument, this._params.pdfBug);
  2794. this.pageCache[pageIndex] = page;
  2795. return page;
  2796. });
  2797. this.pagePromises[pageIndex] = promise;
  2798. return promise;
  2799. }
  2800. getPageIndex(ref) {
  2801. return this.messageHandler.sendWithPromise("GetPageIndex", {
  2802. ref
  2803. }).catch(function (reason) {
  2804. return Promise.reject(new Error(reason));
  2805. });
  2806. }
  2807. getAnnotations(pageIndex, intent) {
  2808. return this.messageHandler.sendWithPromise("GetAnnotations", {
  2809. pageIndex,
  2810. intent
  2811. });
  2812. }
  2813. saveDocument(annotationStorage) {
  2814. return this.messageHandler.sendWithPromise("SaveDocument", {
  2815. numPages: this._numPages,
  2816. annotationStorage: annotationStorage?.serializable || null,
  2817. filename: this._fullReader?.filename ?? null
  2818. }).finally(() => {
  2819. if (annotationStorage) {
  2820. annotationStorage.resetModified();
  2821. }
  2822. });
  2823. }
  2824. getFieldObjects() {
  2825. return this.messageHandler.sendWithPromise("GetFieldObjects", null);
  2826. }
  2827. hasJSActions() {
  2828. return this._hasJSActionsPromise || (this._hasJSActionsPromise = this.messageHandler.sendWithPromise("HasJSActions", null));
  2829. }
  2830. getCalculationOrderIds() {
  2831. return this.messageHandler.sendWithPromise("GetCalculationOrderIds", null);
  2832. }
  2833. getDestinations() {
  2834. return this.messageHandler.sendWithPromise("GetDestinations", null);
  2835. }
  2836. getDestination(id) {
  2837. if (typeof id !== "string") {
  2838. return Promise.reject(new Error("Invalid destination request."));
  2839. }
  2840. return this.messageHandler.sendWithPromise("GetDestination", {
  2841. id
  2842. });
  2843. }
  2844. getPageLabels() {
  2845. return this.messageHandler.sendWithPromise("GetPageLabels", null);
  2846. }
  2847. getPageLayout() {
  2848. return this.messageHandler.sendWithPromise("GetPageLayout", null);
  2849. }
  2850. getPageMode() {
  2851. return this.messageHandler.sendWithPromise("GetPageMode", null);
  2852. }
  2853. getViewerPreferences() {
  2854. return this.messageHandler.sendWithPromise("GetViewerPreferences", null);
  2855. }
  2856. getOpenAction() {
  2857. return this.messageHandler.sendWithPromise("GetOpenAction", null);
  2858. }
  2859. getAttachments() {
  2860. return this.messageHandler.sendWithPromise("GetAttachments", null);
  2861. }
  2862. getJavaScript() {
  2863. return this.messageHandler.sendWithPromise("GetJavaScript", null);
  2864. }
  2865. getDocJSActions() {
  2866. return this.messageHandler.sendWithPromise("GetDocJSActions", null);
  2867. }
  2868. getPageJSActions(pageIndex) {
  2869. return this.messageHandler.sendWithPromise("GetPageJSActions", {
  2870. pageIndex
  2871. });
  2872. }
  2873. getPageXfa(pageIndex) {
  2874. return this.messageHandler.sendWithPromise("GetPageXfa", {
  2875. pageIndex
  2876. });
  2877. }
  2878. getOutline() {
  2879. return this.messageHandler.sendWithPromise("GetOutline", null);
  2880. }
  2881. getOptionalContentConfig() {
  2882. return this.messageHandler.sendWithPromise("GetOptionalContentConfig", null).then(results => {
  2883. return new _optional_content_config.OptionalContentConfig(results);
  2884. });
  2885. }
  2886. getPermissions() {
  2887. return this.messageHandler.sendWithPromise("GetPermissions", null);
  2888. }
  2889. getMetadata() {
  2890. return this.messageHandler.sendWithPromise("GetMetadata", null).then(results => {
  2891. return {
  2892. info: results[0],
  2893. metadata: results[1] ? new _metadata.Metadata(results[1]) : null,
  2894. contentDispositionFilename: this._fullReader?.filename ?? null,
  2895. contentLength: this._fullReader?.contentLength ?? null
  2896. };
  2897. });
  2898. }
  2899. getMarkInfo() {
  2900. return this.messageHandler.sendWithPromise("GetMarkInfo", null);
  2901. }
  2902. getStats() {
  2903. return this.messageHandler.sendWithPromise("GetStats", null);
  2904. }
  2905. async startCleanup(keepLoadedFonts = false) {
  2906. await this.messageHandler.sendWithPromise("Cleanup", null);
  2907. if (this.destroyed) {
  2908. return;
  2909. }
  2910. for (let i = 0, ii = this.pageCache.length; i < ii; i++) {
  2911. const page = this.pageCache[i];
  2912. if (!page) {
  2913. continue;
  2914. }
  2915. const cleanupSuccessful = page.cleanup();
  2916. if (!cleanupSuccessful) {
  2917. throw new Error(`startCleanup: Page ${i + 1} is currently rendering.`);
  2918. }
  2919. }
  2920. this.commonObjs.clear();
  2921. if (!keepLoadedFonts) {
  2922. this.fontLoader.clear();
  2923. }
  2924. this._hasJSActionsPromise = null;
  2925. }
  2926. get loadingParams() {
  2927. const params = this._params;
  2928. return (0, _util.shadow)(this, "loadingParams", {
  2929. disableAutoFetch: params.disableAutoFetch,
  2930. disableFontFace: params.disableFontFace
  2931. });
  2932. }
  2933. }
  2934. class PDFObjects {
  2935. constructor() {
  2936. this._objs = Object.create(null);
  2937. }
  2938. _ensureObj(objId) {
  2939. if (this._objs[objId]) {
  2940. return this._objs[objId];
  2941. }
  2942. return this._objs[objId] = {
  2943. capability: (0, _util.createPromiseCapability)(),
  2944. data: null,
  2945. resolved: false
  2946. };
  2947. }
  2948. get(objId, callback = null) {
  2949. if (callback) {
  2950. this._ensureObj(objId).capability.promise.then(callback);
  2951. return null;
  2952. }
  2953. const obj = this._objs[objId];
  2954. if (!obj || !obj.resolved) {
  2955. throw new Error(`Requesting object that isn't resolved yet ${objId}.`);
  2956. }
  2957. return obj.data;
  2958. }
  2959. has(objId) {
  2960. const obj = this._objs[objId];
  2961. return obj?.resolved || false;
  2962. }
  2963. resolve(objId, data) {
  2964. const obj = this._ensureObj(objId);
  2965. obj.resolved = true;
  2966. obj.data = data;
  2967. obj.capability.resolve(data);
  2968. }
  2969. clear() {
  2970. this._objs = Object.create(null);
  2971. }
  2972. }
  2973. class RenderTask {
  2974. constructor(internalRenderTask) {
  2975. this._internalRenderTask = internalRenderTask;
  2976. this.onContinue = null;
  2977. }
  2978. get promise() {
  2979. return this._internalRenderTask.capability.promise;
  2980. }
  2981. cancel() {
  2982. this._internalRenderTask.cancel();
  2983. }
  2984. }
  2985. const InternalRenderTask = function InternalRenderTaskClosure() {
  2986. const canvasInRendering = new WeakSet();
  2987. class InternalRenderTask {
  2988. constructor({
  2989. callback,
  2990. params,
  2991. objs,
  2992. commonObjs,
  2993. operatorList,
  2994. pageIndex,
  2995. canvasFactory,
  2996. webGLContext,
  2997. useRequestAnimationFrame = false,
  2998. pdfBug = false
  2999. }) {
  3000. this.callback = callback;
  3001. this.params = params;
  3002. this.objs = objs;
  3003. this.commonObjs = commonObjs;
  3004. this.operatorListIdx = null;
  3005. this.operatorList = operatorList;
  3006. this._pageIndex = pageIndex;
  3007. this.canvasFactory = canvasFactory;
  3008. this.webGLContext = webGLContext;
  3009. this._pdfBug = pdfBug;
  3010. this.running = false;
  3011. this.graphicsReadyCallback = null;
  3012. this.graphicsReady = false;
  3013. this._useRequestAnimationFrame = useRequestAnimationFrame === true && typeof window !== "undefined";
  3014. this.cancelled = false;
  3015. this.capability = (0, _util.createPromiseCapability)();
  3016. this.task = new RenderTask(this);
  3017. this._cancelBound = this.cancel.bind(this);
  3018. this._continueBound = this._continue.bind(this);
  3019. this._scheduleNextBound = this._scheduleNext.bind(this);
  3020. this._nextBound = this._next.bind(this);
  3021. this._canvas = params.canvasContext.canvas;
  3022. }
  3023. get completed() {
  3024. return this.capability.promise.catch(function () {});
  3025. }
  3026. initializeGraphics({
  3027. transparency = false,
  3028. optionalContentConfig
  3029. }) {
  3030. if (this.cancelled) {
  3031. return;
  3032. }
  3033. if (this._canvas) {
  3034. if (canvasInRendering.has(this._canvas)) {
  3035. throw new Error("Cannot use the same canvas during multiple render() operations. " + "Use different canvas or ensure previous operations were " + "cancelled or completed.");
  3036. }
  3037. canvasInRendering.add(this._canvas);
  3038. }
  3039. if (this._pdfBug && globalThis.StepperManager?.enabled) {
  3040. this.stepper = globalThis.StepperManager.create(this._pageIndex);
  3041. this.stepper.init(this.operatorList);
  3042. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  3043. }
  3044. const {
  3045. canvasContext,
  3046. viewport,
  3047. transform,
  3048. imageLayer,
  3049. background
  3050. } = this.params;
  3051. this.gfx = new _canvas.CanvasGraphics(canvasContext, this.commonObjs, this.objs, this.canvasFactory, this.webGLContext, imageLayer, optionalContentConfig);
  3052. this.gfx.beginDrawing({
  3053. transform,
  3054. viewport,
  3055. transparency,
  3056. background
  3057. });
  3058. this.operatorListIdx = 0;
  3059. this.graphicsReady = true;
  3060. if (this.graphicsReadyCallback) {
  3061. this.graphicsReadyCallback();
  3062. }
  3063. }
  3064. cancel(error = null) {
  3065. this.running = false;
  3066. this.cancelled = true;
  3067. if (this.gfx) {
  3068. this.gfx.endDrawing();
  3069. }
  3070. if (this._canvas) {
  3071. canvasInRendering.delete(this._canvas);
  3072. }
  3073. this.callback(error || new _display_utils.RenderingCancelledException(`Rendering cancelled, page ${this._pageIndex + 1}`, "canvas"));
  3074. }
  3075. operatorListChanged() {
  3076. if (!this.graphicsReady) {
  3077. if (!this.graphicsReadyCallback) {
  3078. this.graphicsReadyCallback = this._continueBound;
  3079. }
  3080. return;
  3081. }
  3082. if (this.stepper) {
  3083. this.stepper.updateOperatorList(this.operatorList);
  3084. }
  3085. if (this.running) {
  3086. return;
  3087. }
  3088. this._continue();
  3089. }
  3090. _continue() {
  3091. this.running = true;
  3092. if (this.cancelled) {
  3093. return;
  3094. }
  3095. if (this.task.onContinue) {
  3096. this.task.onContinue(this._scheduleNextBound);
  3097. } else {
  3098. this._scheduleNext();
  3099. }
  3100. }
  3101. _scheduleNext() {
  3102. if (this._useRequestAnimationFrame) {
  3103. window.requestAnimationFrame(() => {
  3104. this._nextBound().catch(this._cancelBound);
  3105. });
  3106. } else {
  3107. Promise.resolve().then(this._nextBound).catch(this._cancelBound);
  3108. }
  3109. }
  3110. async _next() {
  3111. if (this.cancelled) {
  3112. return;
  3113. }
  3114. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList, this.operatorListIdx, this._continueBound, this.stepper);
  3115. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  3116. this.running = false;
  3117. if (this.operatorList.lastChunk) {
  3118. this.gfx.endDrawing();
  3119. if (this._canvas) {
  3120. canvasInRendering.delete(this._canvas);
  3121. }
  3122. this.callback();
  3123. }
  3124. }
  3125. }
  3126. }
  3127. return InternalRenderTask;
  3128. }();
  3129. const version = '2.8.335';
  3130. exports.version = version;
  3131. const build = '228adbf67';
  3132. exports.build = build;
  3133. /***/ }),
  3134. /* 6 */
  3135. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3136. Object.defineProperty(exports, "__esModule", ({
  3137. value: true
  3138. }));
  3139. exports.FontLoader = exports.FontFaceObject = void 0;
  3140. var _util = __w_pdfjs_require__(2);
  3141. class BaseFontLoader {
  3142. constructor({
  3143. docId,
  3144. onUnsupportedFeature,
  3145. ownerDocument = globalThis.document
  3146. }) {
  3147. if (this.constructor === BaseFontLoader) {
  3148. (0, _util.unreachable)("Cannot initialize BaseFontLoader.");
  3149. }
  3150. this.docId = docId;
  3151. this._onUnsupportedFeature = onUnsupportedFeature;
  3152. this._document = ownerDocument;
  3153. this.nativeFontFaces = [];
  3154. this.styleElement = null;
  3155. }
  3156. addNativeFontFace(nativeFontFace) {
  3157. this.nativeFontFaces.push(nativeFontFace);
  3158. this._document.fonts.add(nativeFontFace);
  3159. }
  3160. insertRule(rule) {
  3161. let styleElement = this.styleElement;
  3162. if (!styleElement) {
  3163. styleElement = this.styleElement = this._document.createElement("style");
  3164. styleElement.id = `PDFJS_FONT_STYLE_TAG_${this.docId}`;
  3165. this._document.documentElement.getElementsByTagName("head")[0].appendChild(styleElement);
  3166. }
  3167. const styleSheet = styleElement.sheet;
  3168. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  3169. }
  3170. clear() {
  3171. this.nativeFontFaces.forEach(nativeFontFace => {
  3172. this._document.fonts.delete(nativeFontFace);
  3173. });
  3174. this.nativeFontFaces.length = 0;
  3175. if (this.styleElement) {
  3176. this.styleElement.remove();
  3177. this.styleElement = null;
  3178. }
  3179. }
  3180. async bind(font) {
  3181. if (font.attached || font.missingFile) {
  3182. return;
  3183. }
  3184. font.attached = true;
  3185. if (this.isFontLoadingAPISupported) {
  3186. const nativeFontFace = font.createNativeFontFace();
  3187. if (nativeFontFace) {
  3188. this.addNativeFontFace(nativeFontFace);
  3189. try {
  3190. await nativeFontFace.loaded;
  3191. } catch (ex) {
  3192. this._onUnsupportedFeature({
  3193. featureId: _util.UNSUPPORTED_FEATURES.errorFontLoadNative
  3194. });
  3195. (0, _util.warn)(`Failed to load font '${nativeFontFace.family}': '${ex}'.`);
  3196. font.disableFontFace = true;
  3197. throw ex;
  3198. }
  3199. }
  3200. return;
  3201. }
  3202. const rule = font.createFontFaceRule();
  3203. if (rule) {
  3204. this.insertRule(rule);
  3205. if (this.isSyncFontLoadingSupported) {
  3206. return;
  3207. }
  3208. await new Promise(resolve => {
  3209. const request = this._queueLoadingCallback(resolve);
  3210. this._prepareFontLoadEvent([rule], [font], request);
  3211. });
  3212. }
  3213. }
  3214. _queueLoadingCallback(callback) {
  3215. (0, _util.unreachable)("Abstract method `_queueLoadingCallback`.");
  3216. }
  3217. get isFontLoadingAPISupported() {
  3218. return (0, _util.shadow)(this, "isFontLoadingAPISupported", !!this._document?.fonts);
  3219. }
  3220. get isSyncFontLoadingSupported() {
  3221. (0, _util.unreachable)("Abstract method `isSyncFontLoadingSupported`.");
  3222. }
  3223. get _loadTestFont() {
  3224. (0, _util.unreachable)("Abstract method `_loadTestFont`.");
  3225. }
  3226. _prepareFontLoadEvent(rules, fontsToLoad, request) {
  3227. (0, _util.unreachable)("Abstract method `_prepareFontLoadEvent`.");
  3228. }
  3229. }
  3230. let FontLoader;
  3231. exports.FontLoader = FontLoader;
  3232. {
  3233. exports.FontLoader = FontLoader = class GenericFontLoader extends BaseFontLoader {
  3234. constructor(params) {
  3235. super(params);
  3236. this.loadingContext = {
  3237. requests: [],
  3238. nextRequestId: 0
  3239. };
  3240. this.loadTestFontId = 0;
  3241. }
  3242. get isSyncFontLoadingSupported() {
  3243. let supported = false;
  3244. if (typeof navigator === "undefined") {
  3245. supported = true;
  3246. } else {
  3247. const m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(navigator.userAgent);
  3248. if (m?.[1] >= 14) {
  3249. supported = true;
  3250. }
  3251. }
  3252. return (0, _util.shadow)(this, "isSyncFontLoadingSupported", supported);
  3253. }
  3254. _queueLoadingCallback(callback) {
  3255. function completeRequest() {
  3256. (0, _util.assert)(!request.done, "completeRequest() cannot be called twice.");
  3257. request.done = true;
  3258. while (context.requests.length > 0 && context.requests[0].done) {
  3259. const otherRequest = context.requests.shift();
  3260. setTimeout(otherRequest.callback, 0);
  3261. }
  3262. }
  3263. const context = this.loadingContext;
  3264. const request = {
  3265. id: `pdfjs-font-loading-${context.nextRequestId++}`,
  3266. done: false,
  3267. complete: completeRequest,
  3268. callback
  3269. };
  3270. context.requests.push(request);
  3271. return request;
  3272. }
  3273. get _loadTestFont() {
  3274. const getLoadTestFont = function () {
  3275. return 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==");
  3276. };
  3277. return (0, _util.shadow)(this, "_loadTestFont", getLoadTestFont());
  3278. }
  3279. _prepareFontLoadEvent(rules, fonts, request) {
  3280. function int32(data, offset) {
  3281. return data.charCodeAt(offset) << 24 | data.charCodeAt(offset + 1) << 16 | data.charCodeAt(offset + 2) << 8 | data.charCodeAt(offset + 3) & 0xff;
  3282. }
  3283. function spliceString(s, offset, remove, insert) {
  3284. const chunk1 = s.substring(0, offset);
  3285. const chunk2 = s.substring(offset + remove);
  3286. return chunk1 + insert + chunk2;
  3287. }
  3288. let i, ii;
  3289. const canvas = this._document.createElement("canvas");
  3290. canvas.width = 1;
  3291. canvas.height = 1;
  3292. const ctx = canvas.getContext("2d");
  3293. let called = 0;
  3294. function isFontReady(name, callback) {
  3295. called++;
  3296. if (called > 30) {
  3297. (0, _util.warn)("Load test font never loaded.");
  3298. callback();
  3299. return;
  3300. }
  3301. ctx.font = "30px " + name;
  3302. ctx.fillText(".", 0, 20);
  3303. const imageData = ctx.getImageData(0, 0, 1, 1);
  3304. if (imageData.data[3] > 0) {
  3305. callback();
  3306. return;
  3307. }
  3308. setTimeout(isFontReady.bind(null, name, callback));
  3309. }
  3310. const loadTestFontId = `lt${Date.now()}${this.loadTestFontId++}`;
  3311. let data = this._loadTestFont;
  3312. const COMMENT_OFFSET = 976;
  3313. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length, loadTestFontId);
  3314. const CFF_CHECKSUM_OFFSET = 16;
  3315. const XXXX_VALUE = 0x58585858;
  3316. let checksum = int32(data, CFF_CHECKSUM_OFFSET);
  3317. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  3318. checksum = checksum - XXXX_VALUE + int32(loadTestFontId, i) | 0;
  3319. }
  3320. if (i < loadTestFontId.length) {
  3321. checksum = checksum - XXXX_VALUE + int32(loadTestFontId + "XXX", i) | 0;
  3322. }
  3323. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, (0, _util.string32)(checksum));
  3324. const url = `url(data:font/opentype;base64,${btoa(data)});`;
  3325. const rule = `@font-face {font-family:"${loadTestFontId}";src:${url}}`;
  3326. this.insertRule(rule);
  3327. const names = [];
  3328. for (i = 0, ii = fonts.length; i < ii; i++) {
  3329. names.push(fonts[i].loadedName);
  3330. }
  3331. names.push(loadTestFontId);
  3332. const div = this._document.createElement("div");
  3333. div.style.visibility = "hidden";
  3334. div.style.width = div.style.height = "10px";
  3335. div.style.position = "absolute";
  3336. div.style.top = div.style.left = "0px";
  3337. for (i = 0, ii = names.length; i < ii; ++i) {
  3338. const span = this._document.createElement("span");
  3339. span.textContent = "Hi";
  3340. span.style.fontFamily = names[i];
  3341. div.appendChild(span);
  3342. }
  3343. this._document.body.appendChild(div);
  3344. isFontReady(loadTestFontId, () => {
  3345. this._document.body.removeChild(div);
  3346. request.complete();
  3347. });
  3348. }
  3349. };
  3350. }
  3351. class FontFaceObject {
  3352. constructor(translatedData, {
  3353. isEvalSupported = true,
  3354. disableFontFace = false,
  3355. ignoreErrors = false,
  3356. onUnsupportedFeature,
  3357. fontRegistry = null
  3358. }) {
  3359. this.compiledGlyphs = Object.create(null);
  3360. for (const i in translatedData) {
  3361. this[i] = translatedData[i];
  3362. }
  3363. this.isEvalSupported = isEvalSupported !== false;
  3364. this.disableFontFace = disableFontFace === true;
  3365. this.ignoreErrors = ignoreErrors === true;
  3366. this._onUnsupportedFeature = onUnsupportedFeature;
  3367. this.fontRegistry = fontRegistry;
  3368. }
  3369. createNativeFontFace() {
  3370. if (!this.data || this.disableFontFace) {
  3371. return null;
  3372. }
  3373. const nativeFontFace = new FontFace(this.loadedName, this.data, {});
  3374. if (this.fontRegistry) {
  3375. this.fontRegistry.registerFont(this);
  3376. }
  3377. return nativeFontFace;
  3378. }
  3379. createFontFaceRule() {
  3380. if (!this.data || this.disableFontFace) {
  3381. return null;
  3382. }
  3383. const data = (0, _util.bytesToString)(new Uint8Array(this.data));
  3384. const url = `url(data:${this.mimetype};base64,${btoa(data)});`;
  3385. const rule = `@font-face {font-family:"${this.loadedName}";src:${url}}`;
  3386. if (this.fontRegistry) {
  3387. this.fontRegistry.registerFont(this, url);
  3388. }
  3389. return rule;
  3390. }
  3391. getPathGenerator(objs, character) {
  3392. if (this.compiledGlyphs[character] !== undefined) {
  3393. return this.compiledGlyphs[character];
  3394. }
  3395. let cmds, current;
  3396. try {
  3397. cmds = objs.get(this.loadedName + "_path_" + character);
  3398. } catch (ex) {
  3399. if (!this.ignoreErrors) {
  3400. throw ex;
  3401. }
  3402. this._onUnsupportedFeature({
  3403. featureId: _util.UNSUPPORTED_FEATURES.errorFontGetPath
  3404. });
  3405. (0, _util.warn)(`getPathGenerator - ignoring character: "${ex}".`);
  3406. return this.compiledGlyphs[character] = function (c, size) {};
  3407. }
  3408. if (this.isEvalSupported && _util.IsEvalSupportedCached.value) {
  3409. let args,
  3410. js = "";
  3411. for (let i = 0, ii = cmds.length; i < ii; i++) {
  3412. current = cmds[i];
  3413. if (current.args !== undefined) {
  3414. args = current.args.join(",");
  3415. } else {
  3416. args = "";
  3417. }
  3418. js += "c." + current.cmd + "(" + args + ");\n";
  3419. }
  3420. return this.compiledGlyphs[character] = new Function("c", "size", js);
  3421. }
  3422. return this.compiledGlyphs[character] = function (c, size) {
  3423. for (let i = 0, ii = cmds.length; i < ii; i++) {
  3424. current = cmds[i];
  3425. if (current.cmd === "scale") {
  3426. current.args = [size, -size];
  3427. }
  3428. c[current.cmd].apply(c, current.args);
  3429. }
  3430. };
  3431. }
  3432. }
  3433. exports.FontFaceObject = FontFaceObject;
  3434. /***/ }),
  3435. /* 7 */
  3436. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3437. Object.defineProperty(exports, "__esModule", ({
  3438. value: true
  3439. }));
  3440. exports.NodeCMapReaderFactory = exports.NodeCanvasFactory = void 0;
  3441. var _display_utils = __w_pdfjs_require__(1);
  3442. var _is_node = __w_pdfjs_require__(4);
  3443. var _util = __w_pdfjs_require__(2);
  3444. let NodeCanvasFactory = class {
  3445. constructor() {
  3446. (0, _util.unreachable)("Not implemented: NodeCanvasFactory");
  3447. }
  3448. };
  3449. exports.NodeCanvasFactory = NodeCanvasFactory;
  3450. let NodeCMapReaderFactory = class {
  3451. constructor() {
  3452. (0, _util.unreachable)("Not implemented: NodeCMapReaderFactory");
  3453. }
  3454. };
  3455. exports.NodeCMapReaderFactory = NodeCMapReaderFactory;
  3456. if (_is_node.isNodeJS) {
  3457. exports.NodeCanvasFactory = NodeCanvasFactory = class extends _display_utils.BaseCanvasFactory {
  3458. create(width, height) {
  3459. if (width <= 0 || height <= 0) {
  3460. throw new Error("Invalid canvas size");
  3461. }
  3462. const Canvas = require("canvas");
  3463. const canvas = Canvas.createCanvas(width, height);
  3464. return {
  3465. canvas,
  3466. context: canvas.getContext("2d")
  3467. };
  3468. }
  3469. };
  3470. exports.NodeCMapReaderFactory = NodeCMapReaderFactory = class extends _display_utils.BaseCMapReaderFactory {
  3471. _fetchData(url, compressionType) {
  3472. return new Promise((resolve, reject) => {
  3473. const fs = require("fs");
  3474. fs.readFile(url, (error, data) => {
  3475. if (error || !data) {
  3476. reject(new Error(error));
  3477. return;
  3478. }
  3479. resolve({
  3480. cMapData: new Uint8Array(data),
  3481. compressionType
  3482. });
  3483. });
  3484. });
  3485. }
  3486. };
  3487. }
  3488. /***/ }),
  3489. /* 8 */
  3490. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3491. Object.defineProperty(exports, "__esModule", ({
  3492. value: true
  3493. }));
  3494. exports.AnnotationStorage = void 0;
  3495. var _display_utils = __w_pdfjs_require__(1);
  3496. var _util = __w_pdfjs_require__(2);
  3497. class AnnotationStorage {
  3498. constructor() {
  3499. this._storage = new Map();
  3500. this._modified = false;
  3501. this.onSetModified = null;
  3502. this.onResetModified = null;
  3503. }
  3504. getValue(key, defaultValue) {
  3505. const obj = this._storage.get(key);
  3506. return obj !== undefined ? obj : defaultValue;
  3507. }
  3508. getOrCreateValue(key, defaultValue) {
  3509. (0, _display_utils.deprecated)("Use getValue instead.");
  3510. if (this._storage.has(key)) {
  3511. return this._storage.get(key);
  3512. }
  3513. this._storage.set(key, defaultValue);
  3514. return defaultValue;
  3515. }
  3516. setValue(key, value) {
  3517. const obj = this._storage.get(key);
  3518. let modified = false;
  3519. if (obj !== undefined) {
  3520. for (const [entry, val] of Object.entries(value)) {
  3521. if (obj[entry] !== val) {
  3522. modified = true;
  3523. obj[entry] = val;
  3524. }
  3525. }
  3526. } else {
  3527. this._storage.set(key, value);
  3528. modified = true;
  3529. }
  3530. if (modified) {
  3531. this._setModified();
  3532. }
  3533. }
  3534. getAll() {
  3535. return this._storage.size > 0 ? (0, _util.objectFromMap)(this._storage) : null;
  3536. }
  3537. get size() {
  3538. return this._storage.size;
  3539. }
  3540. _setModified() {
  3541. if (!this._modified) {
  3542. this._modified = true;
  3543. if (typeof this.onSetModified === "function") {
  3544. this.onSetModified();
  3545. }
  3546. }
  3547. }
  3548. resetModified() {
  3549. if (this._modified) {
  3550. this._modified = false;
  3551. if (typeof this.onResetModified === "function") {
  3552. this.onResetModified();
  3553. }
  3554. }
  3555. }
  3556. get serializable() {
  3557. return this._storage.size > 0 ? this._storage : null;
  3558. }
  3559. }
  3560. exports.AnnotationStorage = AnnotationStorage;
  3561. /***/ }),
  3562. /* 9 */
  3563. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3564. Object.defineProperty(exports, "__esModule", ({
  3565. value: true
  3566. }));
  3567. exports.apiCompatibilityParams = void 0;
  3568. var _is_node = __w_pdfjs_require__(4);
  3569. const compatibilityParams = Object.create(null);
  3570. {
  3571. (function checkFontFace() {
  3572. if (_is_node.isNodeJS) {
  3573. compatibilityParams.disableFontFace = true;
  3574. }
  3575. })();
  3576. }
  3577. const apiCompatibilityParams = Object.freeze(compatibilityParams);
  3578. exports.apiCompatibilityParams = apiCompatibilityParams;
  3579. /***/ }),
  3580. /* 10 */
  3581. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3582. Object.defineProperty(exports, "__esModule", ({
  3583. value: true
  3584. }));
  3585. exports.CanvasGraphics = void 0;
  3586. var _util = __w_pdfjs_require__(2);
  3587. var _pattern_helper = __w_pdfjs_require__(11);
  3588. const MIN_FONT_SIZE = 16;
  3589. const MAX_FONT_SIZE = 100;
  3590. const MAX_GROUP_SIZE = 4096;
  3591. const COMPILE_TYPE3_GLYPHS = true;
  3592. const MAX_SIZE_TO_COMPILE = 1000;
  3593. const FULL_CHUNK_HEIGHT = 16;
  3594. const LINEWIDTH_SCALE_FACTOR = 1.000001;
  3595. function addContextCurrentTransform(ctx) {
  3596. if (!ctx.mozCurrentTransform) {
  3597. ctx._originalSave = ctx.save;
  3598. ctx._originalRestore = ctx.restore;
  3599. ctx._originalRotate = ctx.rotate;
  3600. ctx._originalScale = ctx.scale;
  3601. ctx._originalTranslate = ctx.translate;
  3602. ctx._originalTransform = ctx.transform;
  3603. ctx._originalSetTransform = ctx.setTransform;
  3604. ctx._originalResetTransform = ctx.resetTransform;
  3605. ctx._transformMatrix = ctx._transformMatrix || [1, 0, 0, 1, 0, 0];
  3606. ctx._transformStack = [];
  3607. try {
  3608. const desc = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(ctx), "lineWidth");
  3609. ctx._setLineWidth = desc.set;
  3610. ctx._getLineWidth = desc.get;
  3611. Object.defineProperty(ctx, "lineWidth", {
  3612. set: function setLineWidth(width) {
  3613. this._setLineWidth(width * LINEWIDTH_SCALE_FACTOR);
  3614. },
  3615. get: function getLineWidth() {
  3616. return this._getLineWidth();
  3617. }
  3618. });
  3619. } catch (_) {}
  3620. Object.defineProperty(ctx, "mozCurrentTransform", {
  3621. get: function getCurrentTransform() {
  3622. return this._transformMatrix;
  3623. }
  3624. });
  3625. Object.defineProperty(ctx, "mozCurrentTransformInverse", {
  3626. get: function getCurrentTransformInverse() {
  3627. const m = this._transformMatrix;
  3628. const a = m[0],
  3629. b = m[1],
  3630. c = m[2],
  3631. d = m[3],
  3632. e = m[4],
  3633. f = m[5];
  3634. const ad_bc = a * d - b * c;
  3635. const bc_ad = b * c - a * d;
  3636. return [d / ad_bc, b / bc_ad, c / bc_ad, a / ad_bc, (d * e - c * f) / bc_ad, (b * e - a * f) / ad_bc];
  3637. }
  3638. });
  3639. ctx.save = function ctxSave() {
  3640. const old = this._transformMatrix;
  3641. this._transformStack.push(old);
  3642. this._transformMatrix = old.slice(0, 6);
  3643. this._originalSave();
  3644. };
  3645. ctx.restore = function ctxRestore() {
  3646. const prev = this._transformStack.pop();
  3647. if (prev) {
  3648. this._transformMatrix = prev;
  3649. this._originalRestore();
  3650. }
  3651. };
  3652. ctx.translate = function ctxTranslate(x, y) {
  3653. const m = this._transformMatrix;
  3654. m[4] = m[0] * x + m[2] * y + m[4];
  3655. m[5] = m[1] * x + m[3] * y + m[5];
  3656. this._originalTranslate(x, y);
  3657. };
  3658. ctx.scale = function ctxScale(x, y) {
  3659. const m = this._transformMatrix;
  3660. m[0] = m[0] * x;
  3661. m[1] = m[1] * x;
  3662. m[2] = m[2] * y;
  3663. m[3] = m[3] * y;
  3664. this._originalScale(x, y);
  3665. };
  3666. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  3667. const m = this._transformMatrix;
  3668. this._transformMatrix = [m[0] * a + m[2] * b, m[1] * a + m[3] * b, m[0] * c + m[2] * d, m[1] * c + m[3] * d, m[0] * e + m[2] * f + m[4], m[1] * e + m[3] * f + m[5]];
  3669. ctx._originalTransform(a, b, c, d, e, f);
  3670. };
  3671. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  3672. this._transformMatrix = [a, b, c, d, e, f];
  3673. ctx._originalSetTransform(a, b, c, d, e, f);
  3674. };
  3675. ctx.resetTransform = function ctxResetTransform() {
  3676. this._transformMatrix = [1, 0, 0, 1, 0, 0];
  3677. ctx._originalResetTransform();
  3678. };
  3679. ctx.rotate = function ctxRotate(angle) {
  3680. const cosValue = Math.cos(angle);
  3681. const sinValue = Math.sin(angle);
  3682. const m = this._transformMatrix;
  3683. this._transformMatrix = [m[0] * cosValue + m[2] * sinValue, m[1] * cosValue + m[3] * sinValue, m[0] * -sinValue + m[2] * cosValue, m[1] * -sinValue + m[3] * cosValue, m[4], m[5]];
  3684. this._originalRotate(angle);
  3685. };
  3686. }
  3687. }
  3688. const CachedCanvases = function CachedCanvasesClosure() {
  3689. function CachedCanvases(canvasFactory) {
  3690. this.canvasFactory = canvasFactory;
  3691. this.cache = Object.create(null);
  3692. }
  3693. CachedCanvases.prototype = {
  3694. getCanvas: function CachedCanvases_getCanvas(id, width, height, trackTransform) {
  3695. let canvasEntry;
  3696. if (this.cache[id] !== undefined) {
  3697. canvasEntry = this.cache[id];
  3698. this.canvasFactory.reset(canvasEntry, width, height);
  3699. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  3700. } else {
  3701. canvasEntry = this.canvasFactory.create(width, height);
  3702. this.cache[id] = canvasEntry;
  3703. }
  3704. if (trackTransform) {
  3705. addContextCurrentTransform(canvasEntry.context);
  3706. }
  3707. return canvasEntry;
  3708. },
  3709. clear() {
  3710. for (const id in this.cache) {
  3711. const canvasEntry = this.cache[id];
  3712. this.canvasFactory.destroy(canvasEntry);
  3713. delete this.cache[id];
  3714. }
  3715. }
  3716. };
  3717. return CachedCanvases;
  3718. }();
  3719. function compileType3Glyph(imgData) {
  3720. const POINT_TO_PROCESS_LIMIT = 1000;
  3721. const width = imgData.width,
  3722. height = imgData.height,
  3723. width1 = width + 1;
  3724. let i, ii, j, j0;
  3725. const points = new Uint8Array(width1 * (height + 1));
  3726. const POINT_TYPES = new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  3727. const lineSize = width + 7 & ~7,
  3728. data0 = imgData.data;
  3729. const data = new Uint8Array(lineSize * height);
  3730. let pos = 0;
  3731. for (i = 0, ii = data0.length; i < ii; i++) {
  3732. const elem = data0[i];
  3733. let mask = 128;
  3734. while (mask > 0) {
  3735. data[pos++] = elem & mask ? 0 : 255;
  3736. mask >>= 1;
  3737. }
  3738. }
  3739. let count = 0;
  3740. pos = 0;
  3741. if (data[pos] !== 0) {
  3742. points[0] = 1;
  3743. ++count;
  3744. }
  3745. for (j = 1; j < width; j++) {
  3746. if (data[pos] !== data[pos + 1]) {
  3747. points[j] = data[pos] ? 2 : 1;
  3748. ++count;
  3749. }
  3750. pos++;
  3751. }
  3752. if (data[pos] !== 0) {
  3753. points[j] = 2;
  3754. ++count;
  3755. }
  3756. for (i = 1; i < height; i++) {
  3757. pos = i * lineSize;
  3758. j0 = i * width1;
  3759. if (data[pos - lineSize] !== data[pos]) {
  3760. points[j0] = data[pos] ? 1 : 8;
  3761. ++count;
  3762. }
  3763. let sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  3764. for (j = 1; j < width; j++) {
  3765. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) + (data[pos - lineSize + 1] ? 8 : 0);
  3766. if (POINT_TYPES[sum]) {
  3767. points[j0 + j] = POINT_TYPES[sum];
  3768. ++count;
  3769. }
  3770. pos++;
  3771. }
  3772. if (data[pos - lineSize] !== data[pos]) {
  3773. points[j0 + j] = data[pos] ? 2 : 4;
  3774. ++count;
  3775. }
  3776. if (count > POINT_TO_PROCESS_LIMIT) {
  3777. return null;
  3778. }
  3779. }
  3780. pos = lineSize * (height - 1);
  3781. j0 = i * width1;
  3782. if (data[pos] !== 0) {
  3783. points[j0] = 8;
  3784. ++count;
  3785. }
  3786. for (j = 1; j < width; j++) {
  3787. if (data[pos] !== data[pos + 1]) {
  3788. points[j0 + j] = data[pos] ? 4 : 8;
  3789. ++count;
  3790. }
  3791. pos++;
  3792. }
  3793. if (data[pos] !== 0) {
  3794. points[j0 + j] = 4;
  3795. ++count;
  3796. }
  3797. if (count > POINT_TO_PROCESS_LIMIT) {
  3798. return null;
  3799. }
  3800. const steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  3801. const outlines = [];
  3802. for (i = 0; count && i <= height; i++) {
  3803. let p = i * width1;
  3804. const end = p + width;
  3805. while (p < end && !points[p]) {
  3806. p++;
  3807. }
  3808. if (p === end) {
  3809. continue;
  3810. }
  3811. const coords = [p % width1, i];
  3812. const p0 = p;
  3813. let type = points[p];
  3814. do {
  3815. const step = steps[type];
  3816. do {
  3817. p += step;
  3818. } while (!points[p]);
  3819. const pp = points[p];
  3820. if (pp !== 5 && pp !== 10) {
  3821. type = pp;
  3822. points[p] = 0;
  3823. } else {
  3824. type = pp & 0x33 * type >> 4;
  3825. points[p] &= type >> 2 | type << 2;
  3826. }
  3827. coords.push(p % width1);
  3828. coords.push(p / width1 | 0);
  3829. if (!points[p]) {
  3830. --count;
  3831. }
  3832. } while (p0 !== p);
  3833. outlines.push(coords);
  3834. --i;
  3835. }
  3836. const drawOutline = function (c) {
  3837. c.save();
  3838. c.scale(1 / width, -1 / height);
  3839. c.translate(0, -height);
  3840. c.beginPath();
  3841. for (let k = 0, kk = outlines.length; k < kk; k++) {
  3842. const o = outlines[k];
  3843. c.moveTo(o[0], o[1]);
  3844. for (let l = 2, ll = o.length; l < ll; l += 2) {
  3845. c.lineTo(o[l], o[l + 1]);
  3846. }
  3847. }
  3848. c.fill();
  3849. c.beginPath();
  3850. c.restore();
  3851. };
  3852. return drawOutline;
  3853. }
  3854. const CanvasExtraState = function CanvasExtraStateClosure() {
  3855. function CanvasExtraState() {
  3856. this.alphaIsShape = false;
  3857. this.fontSize = 0;
  3858. this.fontSizeScale = 1;
  3859. this.textMatrix = _util.IDENTITY_MATRIX;
  3860. this.textMatrixScale = 1;
  3861. this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
  3862. this.leading = 0;
  3863. this.x = 0;
  3864. this.y = 0;
  3865. this.lineX = 0;
  3866. this.lineY = 0;
  3867. this.charSpacing = 0;
  3868. this.wordSpacing = 0;
  3869. this.textHScale = 1;
  3870. this.textRenderingMode = _util.TextRenderingMode.FILL;
  3871. this.textRise = 0;
  3872. this.fillColor = "#000000";
  3873. this.strokeColor = "#000000";
  3874. this.patternFill = false;
  3875. this.fillAlpha = 1;
  3876. this.strokeAlpha = 1;
  3877. this.lineWidth = 1;
  3878. this.activeSMask = null;
  3879. this.resumeSMaskCtx = null;
  3880. this.transferMaps = null;
  3881. }
  3882. CanvasExtraState.prototype = {
  3883. clone: function CanvasExtraState_clone() {
  3884. return Object.create(this);
  3885. },
  3886. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  3887. this.x = x;
  3888. this.y = y;
  3889. }
  3890. };
  3891. return CanvasExtraState;
  3892. }();
  3893. const CanvasGraphics = function CanvasGraphicsClosure() {
  3894. const EXECUTION_TIME = 15;
  3895. const EXECUTION_STEPS = 10;
  3896. function CanvasGraphics(canvasCtx, commonObjs, objs, canvasFactory, webGLContext, imageLayer, optionalContentConfig) {
  3897. this.ctx = canvasCtx;
  3898. this.current = new CanvasExtraState();
  3899. this.stateStack = [];
  3900. this.pendingClip = null;
  3901. this.pendingEOFill = false;
  3902. this.res = null;
  3903. this.xobjs = null;
  3904. this.commonObjs = commonObjs;
  3905. this.objs = objs;
  3906. this.canvasFactory = canvasFactory;
  3907. this.webGLContext = webGLContext;
  3908. this.imageLayer = imageLayer;
  3909. this.groupStack = [];
  3910. this.processingType3 = null;
  3911. this.baseTransform = null;
  3912. this.baseTransformStack = [];
  3913. this.groupLevel = 0;
  3914. this.smaskStack = [];
  3915. this.smaskCounter = 0;
  3916. this.tempSMask = null;
  3917. this.contentVisible = true;
  3918. this.markedContentStack = [];
  3919. this.optionalContentConfig = optionalContentConfig;
  3920. this.cachedCanvases = new CachedCanvases(this.canvasFactory);
  3921. if (canvasCtx) {
  3922. addContextCurrentTransform(canvasCtx);
  3923. }
  3924. this._cachedGetSinglePixelWidth = null;
  3925. }
  3926. function putBinaryImageData(ctx, imgData, transferMaps = null) {
  3927. if (typeof ImageData !== "undefined" && imgData instanceof ImageData) {
  3928. ctx.putImageData(imgData, 0, 0);
  3929. return;
  3930. }
  3931. const height = imgData.height,
  3932. width = imgData.width;
  3933. const partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  3934. const fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  3935. const totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  3936. const chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  3937. let srcPos = 0,
  3938. destPos;
  3939. const src = imgData.data;
  3940. const dest = chunkImgData.data;
  3941. let i, j, thisChunkHeight, elemsInThisChunk;
  3942. let transferMapRed, transferMapGreen, transferMapBlue, transferMapGray;
  3943. if (transferMaps) {
  3944. switch (transferMaps.length) {
  3945. case 1:
  3946. transferMapRed = transferMaps[0];
  3947. transferMapGreen = transferMaps[0];
  3948. transferMapBlue = transferMaps[0];
  3949. transferMapGray = transferMaps[0];
  3950. break;
  3951. case 4:
  3952. transferMapRed = transferMaps[0];
  3953. transferMapGreen = transferMaps[1];
  3954. transferMapBlue = transferMaps[2];
  3955. transferMapGray = transferMaps[3];
  3956. break;
  3957. }
  3958. }
  3959. if (imgData.kind === _util.ImageKind.GRAYSCALE_1BPP) {
  3960. const srcLength = src.byteLength;
  3961. const dest32 = new Uint32Array(dest.buffer, 0, dest.byteLength >> 2);
  3962. const dest32DataLength = dest32.length;
  3963. const fullSrcDiff = width + 7 >> 3;
  3964. let white = 0xffffffff;
  3965. let black = _util.IsLittleEndianCached.value ? 0xff000000 : 0x000000ff;
  3966. if (transferMapGray) {
  3967. if (transferMapGray[0] === 0xff && transferMapGray[0xff] === 0) {
  3968. [white, black] = [black, white];
  3969. }
  3970. }
  3971. for (i = 0; i < totalChunks; i++) {
  3972. thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  3973. destPos = 0;
  3974. for (j = 0; j < thisChunkHeight; j++) {
  3975. const srcDiff = srcLength - srcPos;
  3976. let k = 0;
  3977. const kEnd = srcDiff > fullSrcDiff ? width : srcDiff * 8 - 7;
  3978. const kEndUnrolled = kEnd & ~7;
  3979. let mask = 0;
  3980. let srcByte = 0;
  3981. for (; k < kEndUnrolled; k += 8) {
  3982. srcByte = src[srcPos++];
  3983. dest32[destPos++] = srcByte & 128 ? white : black;
  3984. dest32[destPos++] = srcByte & 64 ? white : black;
  3985. dest32[destPos++] = srcByte & 32 ? white : black;
  3986. dest32[destPos++] = srcByte & 16 ? white : black;
  3987. dest32[destPos++] = srcByte & 8 ? white : black;
  3988. dest32[destPos++] = srcByte & 4 ? white : black;
  3989. dest32[destPos++] = srcByte & 2 ? white : black;
  3990. dest32[destPos++] = srcByte & 1 ? white : black;
  3991. }
  3992. for (; k < kEnd; k++) {
  3993. if (mask === 0) {
  3994. srcByte = src[srcPos++];
  3995. mask = 128;
  3996. }
  3997. dest32[destPos++] = srcByte & mask ? white : black;
  3998. mask >>= 1;
  3999. }
  4000. }
  4001. while (destPos < dest32DataLength) {
  4002. dest32[destPos++] = 0;
  4003. }
  4004. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  4005. }
  4006. } else if (imgData.kind === _util.ImageKind.RGBA_32BPP) {
  4007. const hasTransferMaps = !!(transferMapRed || transferMapGreen || transferMapBlue);
  4008. j = 0;
  4009. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  4010. for (i = 0; i < fullChunks; i++) {
  4011. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  4012. srcPos += elemsInThisChunk;
  4013. if (hasTransferMaps) {
  4014. for (let k = 0; k < elemsInThisChunk; k += 4) {
  4015. if (transferMapRed) {
  4016. dest[k + 0] = transferMapRed[dest[k + 0]];
  4017. }
  4018. if (transferMapGreen) {
  4019. dest[k + 1] = transferMapGreen[dest[k + 1]];
  4020. }
  4021. if (transferMapBlue) {
  4022. dest[k + 2] = transferMapBlue[dest[k + 2]];
  4023. }
  4024. }
  4025. }
  4026. ctx.putImageData(chunkImgData, 0, j);
  4027. j += FULL_CHUNK_HEIGHT;
  4028. }
  4029. if (i < totalChunks) {
  4030. elemsInThisChunk = width * partialChunkHeight * 4;
  4031. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  4032. if (hasTransferMaps) {
  4033. for (let k = 0; k < elemsInThisChunk; k += 4) {
  4034. if (transferMapRed) {
  4035. dest[k + 0] = transferMapRed[dest[k + 0]];
  4036. }
  4037. if (transferMapGreen) {
  4038. dest[k + 1] = transferMapGreen[dest[k + 1]];
  4039. }
  4040. if (transferMapBlue) {
  4041. dest[k + 2] = transferMapBlue[dest[k + 2]];
  4042. }
  4043. }
  4044. }
  4045. ctx.putImageData(chunkImgData, 0, j);
  4046. }
  4047. } else if (imgData.kind === _util.ImageKind.RGB_24BPP) {
  4048. const hasTransferMaps = !!(transferMapRed || transferMapGreen || transferMapBlue);
  4049. thisChunkHeight = FULL_CHUNK_HEIGHT;
  4050. elemsInThisChunk = width * thisChunkHeight;
  4051. for (i = 0; i < totalChunks; i++) {
  4052. if (i >= fullChunks) {
  4053. thisChunkHeight = partialChunkHeight;
  4054. elemsInThisChunk = width * thisChunkHeight;
  4055. }
  4056. destPos = 0;
  4057. for (j = elemsInThisChunk; j--;) {
  4058. dest[destPos++] = src[srcPos++];
  4059. dest[destPos++] = src[srcPos++];
  4060. dest[destPos++] = src[srcPos++];
  4061. dest[destPos++] = 255;
  4062. }
  4063. if (hasTransferMaps) {
  4064. for (let k = 0; k < destPos; k += 4) {
  4065. if (transferMapRed) {
  4066. dest[k + 0] = transferMapRed[dest[k + 0]];
  4067. }
  4068. if (transferMapGreen) {
  4069. dest[k + 1] = transferMapGreen[dest[k + 1]];
  4070. }
  4071. if (transferMapBlue) {
  4072. dest[k + 2] = transferMapBlue[dest[k + 2]];
  4073. }
  4074. }
  4075. }
  4076. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  4077. }
  4078. } else {
  4079. throw new Error(`bad image kind: ${imgData.kind}`);
  4080. }
  4081. }
  4082. function putBinaryImageMask(ctx, imgData) {
  4083. const height = imgData.height,
  4084. width = imgData.width;
  4085. const partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  4086. const fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  4087. const totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  4088. const chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  4089. let srcPos = 0;
  4090. const src = imgData.data;
  4091. const dest = chunkImgData.data;
  4092. for (let i = 0; i < totalChunks; i++) {
  4093. const thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  4094. let destPos = 3;
  4095. for (let j = 0; j < thisChunkHeight; j++) {
  4096. let elem,
  4097. mask = 0;
  4098. for (let k = 0; k < width; k++) {
  4099. if (!mask) {
  4100. elem = src[srcPos++];
  4101. mask = 128;
  4102. }
  4103. dest[destPos] = elem & mask ? 0 : 255;
  4104. destPos += 4;
  4105. mask >>= 1;
  4106. }
  4107. }
  4108. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  4109. }
  4110. }
  4111. function copyCtxState(sourceCtx, destCtx) {
  4112. const properties = ["strokeStyle", "fillStyle", "fillRule", "globalAlpha", "lineWidth", "lineCap", "lineJoin", "miterLimit", "globalCompositeOperation", "font"];
  4113. for (let i = 0, ii = properties.length; i < ii; i++) {
  4114. const property = properties[i];
  4115. if (sourceCtx[property] !== undefined) {
  4116. destCtx[property] = sourceCtx[property];
  4117. }
  4118. }
  4119. if (sourceCtx.setLineDash !== undefined) {
  4120. destCtx.setLineDash(sourceCtx.getLineDash());
  4121. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  4122. }
  4123. }
  4124. function resetCtxToDefault(ctx) {
  4125. ctx.strokeStyle = "#000000";
  4126. ctx.fillStyle = "#000000";
  4127. ctx.fillRule = "nonzero";
  4128. ctx.globalAlpha = 1;
  4129. ctx.lineWidth = 1;
  4130. ctx.lineCap = "butt";
  4131. ctx.lineJoin = "miter";
  4132. ctx.miterLimit = 10;
  4133. ctx.globalCompositeOperation = "source-over";
  4134. ctx.font = "10px sans-serif";
  4135. if (ctx.setLineDash !== undefined) {
  4136. ctx.setLineDash([]);
  4137. ctx.lineDashOffset = 0;
  4138. }
  4139. }
  4140. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  4141. const length = bytes.length;
  4142. for (let i = 3; i < length; i += 4) {
  4143. const alpha = bytes[i];
  4144. if (alpha === 0) {
  4145. bytes[i - 3] = r0;
  4146. bytes[i - 2] = g0;
  4147. bytes[i - 1] = b0;
  4148. } else if (alpha < 255) {
  4149. const alpha_ = 255 - alpha;
  4150. bytes[i - 3] = bytes[i - 3] * alpha + r0 * alpha_ >> 8;
  4151. bytes[i - 2] = bytes[i - 2] * alpha + g0 * alpha_ >> 8;
  4152. bytes[i - 1] = bytes[i - 1] * alpha + b0 * alpha_ >> 8;
  4153. }
  4154. }
  4155. }
  4156. function composeSMaskAlpha(maskData, layerData, transferMap) {
  4157. const length = maskData.length;
  4158. const scale = 1 / 255;
  4159. for (let i = 3; i < length; i += 4) {
  4160. const alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
  4161. layerData[i] = layerData[i] * alpha * scale | 0;
  4162. }
  4163. }
  4164. function composeSMaskLuminosity(maskData, layerData, transferMap) {
  4165. const length = maskData.length;
  4166. for (let i = 3; i < length; i += 4) {
  4167. const y = maskData[i - 3] * 77 + maskData[i - 2] * 152 + maskData[i - 1] * 28;
  4168. layerData[i] = transferMap ? layerData[i] * transferMap[y >> 8] >> 8 : layerData[i] * y >> 16;
  4169. }
  4170. }
  4171. function genericComposeSMask(maskCtx, layerCtx, width, height, subtype, backdrop, transferMap) {
  4172. const hasBackdrop = !!backdrop;
  4173. const r0 = hasBackdrop ? backdrop[0] : 0;
  4174. const g0 = hasBackdrop ? backdrop[1] : 0;
  4175. const b0 = hasBackdrop ? backdrop[2] : 0;
  4176. let composeFn;
  4177. if (subtype === "Luminosity") {
  4178. composeFn = composeSMaskLuminosity;
  4179. } else {
  4180. composeFn = composeSMaskAlpha;
  4181. }
  4182. const PIXELS_TO_PROCESS = 1048576;
  4183. const chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  4184. for (let row = 0; row < height; row += chunkSize) {
  4185. const chunkHeight = Math.min(chunkSize, height - row);
  4186. const maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  4187. const layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  4188. if (hasBackdrop) {
  4189. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  4190. }
  4191. composeFn(maskData.data, layerData.data, transferMap);
  4192. maskCtx.putImageData(layerData, 0, row);
  4193. }
  4194. }
  4195. function composeSMask(ctx, smask, layerCtx, webGLContext) {
  4196. const mask = smask.canvas;
  4197. const maskCtx = smask.context;
  4198. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY, smask.offsetX, smask.offsetY);
  4199. const backdrop = smask.backdrop || null;
  4200. if (!smask.transferMap && webGLContext.isEnabled) {
  4201. const composed = webGLContext.composeSMask({
  4202. layer: layerCtx.canvas,
  4203. mask,
  4204. properties: {
  4205. subtype: smask.subtype,
  4206. backdrop
  4207. }
  4208. });
  4209. ctx.setTransform(1, 0, 0, 1, 0, 0);
  4210. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  4211. return;
  4212. }
  4213. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height, smask.subtype, backdrop, smask.transferMap);
  4214. ctx.drawImage(mask, 0, 0);
  4215. }
  4216. const LINE_CAP_STYLES = ["butt", "round", "square"];
  4217. const LINE_JOIN_STYLES = ["miter", "round", "bevel"];
  4218. const NORMAL_CLIP = {};
  4219. const EO_CLIP = {};
  4220. CanvasGraphics.prototype = {
  4221. beginDrawing({
  4222. transform,
  4223. viewport,
  4224. transparency = false,
  4225. background = null
  4226. }) {
  4227. const width = this.ctx.canvas.width;
  4228. const height = this.ctx.canvas.height;
  4229. this.ctx.save();
  4230. this.ctx.fillStyle = background || "rgb(255, 255, 255)";
  4231. this.ctx.fillRect(0, 0, width, height);
  4232. this.ctx.restore();
  4233. if (transparency) {
  4234. const transparentCanvas = this.cachedCanvases.getCanvas("transparent", width, height, true);
  4235. this.compositeCtx = this.ctx;
  4236. this.transparentCanvas = transparentCanvas.canvas;
  4237. this.ctx = transparentCanvas.context;
  4238. this.ctx.save();
  4239. this.ctx.transform.apply(this.ctx, this.compositeCtx.mozCurrentTransform);
  4240. }
  4241. this.ctx.save();
  4242. resetCtxToDefault(this.ctx);
  4243. if (transform) {
  4244. this.ctx.transform.apply(this.ctx, transform);
  4245. }
  4246. this.ctx.transform.apply(this.ctx, viewport.transform);
  4247. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  4248. this._combinedScaleFactor = Math.hypot(this.baseTransform[0], this.baseTransform[2]);
  4249. if (this.imageLayer) {
  4250. this.imageLayer.beginLayout();
  4251. }
  4252. },
  4253. executeOperatorList: function CanvasGraphics_executeOperatorList(operatorList, executionStartIdx, continueCallback, stepper) {
  4254. const argsArray = operatorList.argsArray;
  4255. const fnArray = operatorList.fnArray;
  4256. let i = executionStartIdx || 0;
  4257. const argsArrayLen = argsArray.length;
  4258. if (argsArrayLen === i) {
  4259. return i;
  4260. }
  4261. const chunkOperations = argsArrayLen - i > EXECUTION_STEPS && typeof continueCallback === "function";
  4262. const endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  4263. let steps = 0;
  4264. const commonObjs = this.commonObjs;
  4265. const objs = this.objs;
  4266. let fnId;
  4267. while (true) {
  4268. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  4269. stepper.breakIt(i, continueCallback);
  4270. return i;
  4271. }
  4272. fnId = fnArray[i];
  4273. if (fnId !== _util.OPS.dependency) {
  4274. this[fnId].apply(this, argsArray[i]);
  4275. } else {
  4276. for (const depObjId of argsArray[i]) {
  4277. const objsPool = depObjId.startsWith("g_") ? commonObjs : objs;
  4278. if (!objsPool.has(depObjId)) {
  4279. objsPool.get(depObjId, continueCallback);
  4280. return i;
  4281. }
  4282. }
  4283. }
  4284. i++;
  4285. if (i === argsArrayLen) {
  4286. return i;
  4287. }
  4288. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  4289. if (Date.now() > endTime) {
  4290. continueCallback();
  4291. return i;
  4292. }
  4293. steps = 0;
  4294. }
  4295. }
  4296. },
  4297. endDrawing: function CanvasGraphics_endDrawing() {
  4298. while (this.stateStack.length || this.current.activeSMask !== null) {
  4299. this.restore();
  4300. }
  4301. this.ctx.restore();
  4302. if (this.transparentCanvas) {
  4303. this.ctx = this.compositeCtx;
  4304. this.ctx.save();
  4305. this.ctx.setTransform(1, 0, 0, 1, 0, 0);
  4306. this.ctx.drawImage(this.transparentCanvas, 0, 0);
  4307. this.ctx.restore();
  4308. this.transparentCanvas = null;
  4309. }
  4310. this.cachedCanvases.clear();
  4311. this.webGLContext.clear();
  4312. if (this.imageLayer) {
  4313. this.imageLayer.endLayout();
  4314. }
  4315. },
  4316. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  4317. this.current.lineWidth = width;
  4318. this.ctx.lineWidth = width;
  4319. },
  4320. setLineCap: function CanvasGraphics_setLineCap(style) {
  4321. this.ctx.lineCap = LINE_CAP_STYLES[style];
  4322. },
  4323. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  4324. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  4325. },
  4326. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  4327. this.ctx.miterLimit = limit;
  4328. },
  4329. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  4330. const ctx = this.ctx;
  4331. if (ctx.setLineDash !== undefined) {
  4332. ctx.setLineDash(dashArray);
  4333. ctx.lineDashOffset = dashPhase;
  4334. }
  4335. },
  4336. setRenderingIntent(intent) {},
  4337. setFlatness(flatness) {},
  4338. setGState: function CanvasGraphics_setGState(states) {
  4339. for (let i = 0, ii = states.length; i < ii; i++) {
  4340. const state = states[i];
  4341. const key = state[0];
  4342. const value = state[1];
  4343. switch (key) {
  4344. case "LW":
  4345. this.setLineWidth(value);
  4346. break;
  4347. case "LC":
  4348. this.setLineCap(value);
  4349. break;
  4350. case "LJ":
  4351. this.setLineJoin(value);
  4352. break;
  4353. case "ML":
  4354. this.setMiterLimit(value);
  4355. break;
  4356. case "D":
  4357. this.setDash(value[0], value[1]);
  4358. break;
  4359. case "RI":
  4360. this.setRenderingIntent(value);
  4361. break;
  4362. case "FL":
  4363. this.setFlatness(value);
  4364. break;
  4365. case "Font":
  4366. this.setFont(value[0], value[1]);
  4367. break;
  4368. case "CA":
  4369. this.current.strokeAlpha = state[1];
  4370. break;
  4371. case "ca":
  4372. this.current.fillAlpha = state[1];
  4373. this.ctx.globalAlpha = state[1];
  4374. break;
  4375. case "BM":
  4376. this.ctx.globalCompositeOperation = value;
  4377. break;
  4378. case "SMask":
  4379. if (this.current.activeSMask) {
  4380. if (this.stateStack.length > 0 && this.stateStack[this.stateStack.length - 1].activeSMask === this.current.activeSMask) {
  4381. this.suspendSMaskGroup();
  4382. } else {
  4383. this.endSMaskGroup();
  4384. }
  4385. }
  4386. this.current.activeSMask = value ? this.tempSMask : null;
  4387. if (this.current.activeSMask) {
  4388. this.beginSMaskGroup();
  4389. }
  4390. this.tempSMask = null;
  4391. break;
  4392. case "TR":
  4393. this.current.transferMaps = value;
  4394. }
  4395. }
  4396. },
  4397. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  4398. const activeSMask = this.current.activeSMask;
  4399. const drawnWidth = activeSMask.canvas.width;
  4400. const drawnHeight = activeSMask.canvas.height;
  4401. const cacheId = "smaskGroupAt" + this.groupLevel;
  4402. const scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true);
  4403. const currentCtx = this.ctx;
  4404. const currentTransform = currentCtx.mozCurrentTransform;
  4405. this.ctx.save();
  4406. const groupCtx = scratchCanvas.context;
  4407. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  4408. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  4409. groupCtx.transform.apply(groupCtx, currentTransform);
  4410. activeSMask.startTransformInverse = groupCtx.mozCurrentTransformInverse;
  4411. copyCtxState(currentCtx, groupCtx);
  4412. this.ctx = groupCtx;
  4413. this.setGState([["BM", "source-over"], ["ca", 1], ["CA", 1]]);
  4414. this.groupStack.push(currentCtx);
  4415. this.groupLevel++;
  4416. },
  4417. suspendSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  4418. const groupCtx = this.ctx;
  4419. this.groupLevel--;
  4420. this.ctx = this.groupStack.pop();
  4421. composeSMask(this.ctx, this.current.activeSMask, groupCtx, this.webGLContext);
  4422. this.ctx.restore();
  4423. this.ctx.save();
  4424. copyCtxState(groupCtx, this.ctx);
  4425. this.current.resumeSMaskCtx = groupCtx;
  4426. const deltaTransform = _util.Util.transform(this.current.activeSMask.startTransformInverse, groupCtx.mozCurrentTransform);
  4427. this.ctx.transform.apply(this.ctx, deltaTransform);
  4428. groupCtx.save();
  4429. groupCtx.setTransform(1, 0, 0, 1, 0, 0);
  4430. groupCtx.clearRect(0, 0, groupCtx.canvas.width, groupCtx.canvas.height);
  4431. groupCtx.restore();
  4432. },
  4433. resumeSMaskGroup: function CanvasGraphics_resumeSMaskGroup() {
  4434. const groupCtx = this.current.resumeSMaskCtx;
  4435. const currentCtx = this.ctx;
  4436. this.ctx = groupCtx;
  4437. this.groupStack.push(currentCtx);
  4438. this.groupLevel++;
  4439. },
  4440. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  4441. const groupCtx = this.ctx;
  4442. this.groupLevel--;
  4443. this.ctx = this.groupStack.pop();
  4444. composeSMask(this.ctx, this.current.activeSMask, groupCtx, this.webGLContext);
  4445. this.ctx.restore();
  4446. copyCtxState(groupCtx, this.ctx);
  4447. const deltaTransform = _util.Util.transform(this.current.activeSMask.startTransformInverse, groupCtx.mozCurrentTransform);
  4448. this.ctx.transform.apply(this.ctx, deltaTransform);
  4449. },
  4450. save: function CanvasGraphics_save() {
  4451. this.ctx.save();
  4452. const old = this.current;
  4453. this.stateStack.push(old);
  4454. this.current = old.clone();
  4455. this.current.resumeSMaskCtx = null;
  4456. },
  4457. restore: function CanvasGraphics_restore() {
  4458. if (this.current.resumeSMaskCtx) {
  4459. this.resumeSMaskGroup();
  4460. }
  4461. if (this.current.activeSMask !== null && (this.stateStack.length === 0 || this.stateStack[this.stateStack.length - 1].activeSMask !== this.current.activeSMask)) {
  4462. this.endSMaskGroup();
  4463. }
  4464. if (this.stateStack.length !== 0) {
  4465. this.current = this.stateStack.pop();
  4466. this.ctx.restore();
  4467. this.pendingClip = null;
  4468. this._cachedGetSinglePixelWidth = null;
  4469. } else {
  4470. this.current.activeSMask = null;
  4471. }
  4472. },
  4473. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  4474. this.ctx.transform(a, b, c, d, e, f);
  4475. this._cachedGetSinglePixelWidth = null;
  4476. },
  4477. constructPath: function CanvasGraphics_constructPath(ops, args) {
  4478. const ctx = this.ctx;
  4479. const current = this.current;
  4480. let x = current.x,
  4481. y = current.y;
  4482. for (let i = 0, j = 0, ii = ops.length; i < ii; i++) {
  4483. switch (ops[i] | 0) {
  4484. case _util.OPS.rectangle:
  4485. x = args[j++];
  4486. y = args[j++];
  4487. const width = args[j++];
  4488. const height = args[j++];
  4489. const xw = x + width;
  4490. const yh = y + height;
  4491. ctx.moveTo(x, y);
  4492. if (width === 0 || height === 0) {
  4493. ctx.lineTo(xw, yh);
  4494. } else {
  4495. ctx.lineTo(xw, y);
  4496. ctx.lineTo(xw, yh);
  4497. ctx.lineTo(x, yh);
  4498. }
  4499. ctx.closePath();
  4500. break;
  4501. case _util.OPS.moveTo:
  4502. x = args[j++];
  4503. y = args[j++];
  4504. ctx.moveTo(x, y);
  4505. break;
  4506. case _util.OPS.lineTo:
  4507. x = args[j++];
  4508. y = args[j++];
  4509. ctx.lineTo(x, y);
  4510. break;
  4511. case _util.OPS.curveTo:
  4512. x = args[j + 4];
  4513. y = args[j + 5];
  4514. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3], x, y);
  4515. j += 6;
  4516. break;
  4517. case _util.OPS.curveTo2:
  4518. ctx.bezierCurveTo(x, y, args[j], args[j + 1], args[j + 2], args[j + 3]);
  4519. x = args[j + 2];
  4520. y = args[j + 3];
  4521. j += 4;
  4522. break;
  4523. case _util.OPS.curveTo3:
  4524. x = args[j + 2];
  4525. y = args[j + 3];
  4526. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  4527. j += 4;
  4528. break;
  4529. case _util.OPS.closePath:
  4530. ctx.closePath();
  4531. break;
  4532. }
  4533. }
  4534. current.setCurrentPoint(x, y);
  4535. },
  4536. closePath: function CanvasGraphics_closePath() {
  4537. this.ctx.closePath();
  4538. },
  4539. stroke: function CanvasGraphics_stroke(consumePath) {
  4540. consumePath = typeof consumePath !== "undefined" ? consumePath : true;
  4541. const ctx = this.ctx;
  4542. const strokeColor = this.current.strokeColor;
  4543. ctx.globalAlpha = this.current.strokeAlpha;
  4544. if (this.contentVisible) {
  4545. if (typeof strokeColor === "object" && strokeColor?.getPattern) {
  4546. ctx.save();
  4547. const transform = ctx.mozCurrentTransform;
  4548. const scale = _util.Util.singularValueDecompose2dScale(transform)[0];
  4549. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  4550. const lineWidth = this.getSinglePixelWidth();
  4551. const scaledLineWidth = this.current.lineWidth * scale;
  4552. if (lineWidth < 0 && -lineWidth >= scaledLineWidth) {
  4553. ctx.resetTransform();
  4554. ctx.lineWidth = Math.round(this._combinedScaleFactor);
  4555. } else {
  4556. ctx.lineWidth = Math.max(lineWidth, scaledLineWidth);
  4557. }
  4558. ctx.stroke();
  4559. ctx.restore();
  4560. } else {
  4561. const lineWidth = this.getSinglePixelWidth();
  4562. if (lineWidth < 0 && -lineWidth >= this.current.lineWidth) {
  4563. ctx.save();
  4564. ctx.resetTransform();
  4565. ctx.lineWidth = Math.round(this._combinedScaleFactor);
  4566. ctx.stroke();
  4567. ctx.restore();
  4568. } else {
  4569. ctx.lineWidth = Math.max(lineWidth, this.current.lineWidth);
  4570. ctx.stroke();
  4571. }
  4572. }
  4573. }
  4574. if (consumePath) {
  4575. this.consumePath();
  4576. }
  4577. ctx.globalAlpha = this.current.fillAlpha;
  4578. },
  4579. closeStroke: function CanvasGraphics_closeStroke() {
  4580. this.closePath();
  4581. this.stroke();
  4582. },
  4583. fill: function CanvasGraphics_fill(consumePath) {
  4584. consumePath = typeof consumePath !== "undefined" ? consumePath : true;
  4585. const ctx = this.ctx;
  4586. const fillColor = this.current.fillColor;
  4587. const isPatternFill = this.current.patternFill;
  4588. let needRestore = false;
  4589. if (isPatternFill) {
  4590. ctx.save();
  4591. if (this.baseTransform) {
  4592. ctx.setTransform.apply(ctx, this.baseTransform);
  4593. }
  4594. ctx.fillStyle = fillColor.getPattern(ctx, this);
  4595. needRestore = true;
  4596. }
  4597. if (this.contentVisible) {
  4598. if (this.pendingEOFill) {
  4599. ctx.fill("evenodd");
  4600. this.pendingEOFill = false;
  4601. } else {
  4602. ctx.fill();
  4603. }
  4604. }
  4605. if (needRestore) {
  4606. ctx.restore();
  4607. }
  4608. if (consumePath) {
  4609. this.consumePath();
  4610. }
  4611. },
  4612. eoFill: function CanvasGraphics_eoFill() {
  4613. this.pendingEOFill = true;
  4614. this.fill();
  4615. },
  4616. fillStroke: function CanvasGraphics_fillStroke() {
  4617. this.fill(false);
  4618. this.stroke(false);
  4619. this.consumePath();
  4620. },
  4621. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  4622. this.pendingEOFill = true;
  4623. this.fillStroke();
  4624. },
  4625. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  4626. this.closePath();
  4627. this.fillStroke();
  4628. },
  4629. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  4630. this.pendingEOFill = true;
  4631. this.closePath();
  4632. this.fillStroke();
  4633. },
  4634. endPath: function CanvasGraphics_endPath() {
  4635. this.consumePath();
  4636. },
  4637. clip: function CanvasGraphics_clip() {
  4638. this.pendingClip = NORMAL_CLIP;
  4639. },
  4640. eoClip: function CanvasGraphics_eoClip() {
  4641. this.pendingClip = EO_CLIP;
  4642. },
  4643. beginText: function CanvasGraphics_beginText() {
  4644. this.current.textMatrix = _util.IDENTITY_MATRIX;
  4645. this.current.textMatrixScale = 1;
  4646. this.current.x = this.current.lineX = 0;
  4647. this.current.y = this.current.lineY = 0;
  4648. },
  4649. endText: function CanvasGraphics_endText() {
  4650. const paths = this.pendingTextPaths;
  4651. const ctx = this.ctx;
  4652. if (paths === undefined) {
  4653. ctx.beginPath();
  4654. return;
  4655. }
  4656. ctx.save();
  4657. ctx.beginPath();
  4658. for (let i = 0; i < paths.length; i++) {
  4659. const path = paths[i];
  4660. ctx.setTransform.apply(ctx, path.transform);
  4661. ctx.translate(path.x, path.y);
  4662. path.addToPath(ctx, path.fontSize);
  4663. }
  4664. ctx.restore();
  4665. ctx.clip();
  4666. ctx.beginPath();
  4667. delete this.pendingTextPaths;
  4668. },
  4669. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  4670. this.current.charSpacing = spacing;
  4671. },
  4672. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  4673. this.current.wordSpacing = spacing;
  4674. },
  4675. setHScale: function CanvasGraphics_setHScale(scale) {
  4676. this.current.textHScale = scale / 100;
  4677. },
  4678. setLeading: function CanvasGraphics_setLeading(leading) {
  4679. this.current.leading = -leading;
  4680. },
  4681. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  4682. const fontObj = this.commonObjs.get(fontRefName);
  4683. const current = this.current;
  4684. if (!fontObj) {
  4685. throw new Error(`Can't find font for ${fontRefName}`);
  4686. }
  4687. current.fontMatrix = fontObj.fontMatrix || _util.FONT_IDENTITY_MATRIX;
  4688. if (current.fontMatrix[0] === 0 || current.fontMatrix[3] === 0) {
  4689. (0, _util.warn)("Invalid font matrix for font " + fontRefName);
  4690. }
  4691. if (size < 0) {
  4692. size = -size;
  4693. current.fontDirection = -1;
  4694. } else {
  4695. current.fontDirection = 1;
  4696. }
  4697. this.current.font = fontObj;
  4698. this.current.fontSize = size;
  4699. if (fontObj.isType3Font) {
  4700. return;
  4701. }
  4702. const name = fontObj.loadedName || "sans-serif";
  4703. let bold = "normal";
  4704. if (fontObj.black) {
  4705. bold = "900";
  4706. } else if (fontObj.bold) {
  4707. bold = "bold";
  4708. }
  4709. const italic = fontObj.italic ? "italic" : "normal";
  4710. const typeface = `"${name}", ${fontObj.fallbackName}`;
  4711. let browserFontSize = size;
  4712. if (size < MIN_FONT_SIZE) {
  4713. browserFontSize = MIN_FONT_SIZE;
  4714. } else if (size > MAX_FONT_SIZE) {
  4715. browserFontSize = MAX_FONT_SIZE;
  4716. }
  4717. this.current.fontSizeScale = size / browserFontSize;
  4718. this.ctx.font = `${italic} ${bold} ${browserFontSize}px ${typeface}`;
  4719. },
  4720. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  4721. this.current.textRenderingMode = mode;
  4722. },
  4723. setTextRise: function CanvasGraphics_setTextRise(rise) {
  4724. this.current.textRise = rise;
  4725. },
  4726. moveText: function CanvasGraphics_moveText(x, y) {
  4727. this.current.x = this.current.lineX += x;
  4728. this.current.y = this.current.lineY += y;
  4729. },
  4730. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  4731. this.setLeading(-y);
  4732. this.moveText(x, y);
  4733. },
  4734. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  4735. this.current.textMatrix = [a, b, c, d, e, f];
  4736. this.current.textMatrixScale = Math.hypot(a, b);
  4737. this.current.x = this.current.lineX = 0;
  4738. this.current.y = this.current.lineY = 0;
  4739. },
  4740. nextLine: function CanvasGraphics_nextLine() {
  4741. this.moveText(0, this.current.leading);
  4742. },
  4743. paintChar(character, x, y, patternTransform, resetLineWidthToOne) {
  4744. const ctx = this.ctx;
  4745. const current = this.current;
  4746. const font = current.font;
  4747. const textRenderingMode = current.textRenderingMode;
  4748. const fontSize = current.fontSize / current.fontSizeScale;
  4749. const fillStrokeMode = textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  4750. const isAddToPathSet = !!(textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG);
  4751. const patternFill = current.patternFill && !font.missingFile;
  4752. let addToPath;
  4753. if (font.disableFontFace || isAddToPathSet || patternFill) {
  4754. addToPath = font.getPathGenerator(this.commonObjs, character);
  4755. }
  4756. if (font.disableFontFace || patternFill) {
  4757. ctx.save();
  4758. ctx.translate(x, y);
  4759. ctx.beginPath();
  4760. addToPath(ctx, fontSize);
  4761. if (patternTransform) {
  4762. ctx.setTransform.apply(ctx, patternTransform);
  4763. }
  4764. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  4765. ctx.fill();
  4766. }
  4767. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  4768. if (resetLineWidthToOne) {
  4769. ctx.resetTransform();
  4770. ctx.lineWidth = Math.round(this._combinedScaleFactor);
  4771. }
  4772. ctx.stroke();
  4773. }
  4774. ctx.restore();
  4775. } else {
  4776. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  4777. ctx.fillText(character, x, y);
  4778. }
  4779. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  4780. if (resetLineWidthToOne) {
  4781. ctx.save();
  4782. ctx.moveTo(x, y);
  4783. ctx.resetTransform();
  4784. ctx.lineWidth = Math.round(this._combinedScaleFactor);
  4785. ctx.strokeText(character, 0, 0);
  4786. ctx.restore();
  4787. } else {
  4788. ctx.strokeText(character, x, y);
  4789. }
  4790. }
  4791. }
  4792. if (isAddToPathSet) {
  4793. const paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  4794. paths.push({
  4795. transform: ctx.mozCurrentTransform,
  4796. x,
  4797. y,
  4798. fontSize,
  4799. addToPath
  4800. });
  4801. }
  4802. },
  4803. get isFontSubpixelAAEnabled() {
  4804. const {
  4805. context: ctx
  4806. } = this.cachedCanvases.getCanvas("isFontSubpixelAAEnabled", 10, 10);
  4807. ctx.scale(1.5, 1);
  4808. ctx.fillText("I", 0, 10);
  4809. const data = ctx.getImageData(0, 0, 10, 10).data;
  4810. let enabled = false;
  4811. for (let i = 3; i < data.length; i += 4) {
  4812. if (data[i] > 0 && data[i] < 255) {
  4813. enabled = true;
  4814. break;
  4815. }
  4816. }
  4817. return (0, _util.shadow)(this, "isFontSubpixelAAEnabled", enabled);
  4818. },
  4819. showText: function CanvasGraphics_showText(glyphs) {
  4820. const current = this.current;
  4821. const font = current.font;
  4822. if (font.isType3Font) {
  4823. return this.showType3Text(glyphs);
  4824. }
  4825. const fontSize = current.fontSize;
  4826. if (fontSize === 0) {
  4827. return undefined;
  4828. }
  4829. const ctx = this.ctx;
  4830. const fontSizeScale = current.fontSizeScale;
  4831. const charSpacing = current.charSpacing;
  4832. const wordSpacing = current.wordSpacing;
  4833. const fontDirection = current.fontDirection;
  4834. const textHScale = current.textHScale * fontDirection;
  4835. const glyphsLength = glyphs.length;
  4836. const vertical = font.vertical;
  4837. const spacingDir = vertical ? 1 : -1;
  4838. const defaultVMetrics = font.defaultVMetrics;
  4839. const widthAdvanceScale = fontSize * current.fontMatrix[0];
  4840. const simpleFillText = current.textRenderingMode === _util.TextRenderingMode.FILL && !font.disableFontFace && !current.patternFill;
  4841. ctx.save();
  4842. let patternTransform;
  4843. if (current.patternFill) {
  4844. ctx.save();
  4845. const pattern = current.fillColor.getPattern(ctx, this);
  4846. patternTransform = ctx.mozCurrentTransform;
  4847. ctx.restore();
  4848. ctx.fillStyle = pattern;
  4849. }
  4850. ctx.transform.apply(ctx, current.textMatrix);
  4851. ctx.translate(current.x, current.y + current.textRise);
  4852. if (fontDirection > 0) {
  4853. ctx.scale(textHScale, -1);
  4854. } else {
  4855. ctx.scale(textHScale, 1);
  4856. }
  4857. let lineWidth = current.lineWidth;
  4858. let resetLineWidthToOne = false;
  4859. const scale = current.textMatrixScale;
  4860. if (scale === 0 || lineWidth === 0) {
  4861. const fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  4862. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  4863. this._cachedGetSinglePixelWidth = null;
  4864. lineWidth = this.getSinglePixelWidth();
  4865. resetLineWidthToOne = lineWidth < 0;
  4866. }
  4867. } else {
  4868. lineWidth /= scale;
  4869. }
  4870. if (fontSizeScale !== 1.0) {
  4871. ctx.scale(fontSizeScale, fontSizeScale);
  4872. lineWidth /= fontSizeScale;
  4873. }
  4874. ctx.lineWidth = lineWidth;
  4875. let x = 0,
  4876. i;
  4877. for (i = 0; i < glyphsLength; ++i) {
  4878. const glyph = glyphs[i];
  4879. if ((0, _util.isNum)(glyph)) {
  4880. x += spacingDir * glyph * fontSize / 1000;
  4881. continue;
  4882. }
  4883. let restoreNeeded = false;
  4884. const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  4885. const character = glyph.fontChar;
  4886. const accent = glyph.accent;
  4887. let scaledX, scaledY;
  4888. let width = glyph.width;
  4889. if (vertical) {
  4890. const vmetric = glyph.vmetric || defaultVMetrics;
  4891. const vx = -(glyph.vmetric ? vmetric[1] : width * 0.5) * widthAdvanceScale;
  4892. const vy = vmetric[2] * widthAdvanceScale;
  4893. width = vmetric ? -vmetric[0] : width;
  4894. scaledX = vx / fontSizeScale;
  4895. scaledY = (x + vy) / fontSizeScale;
  4896. } else {
  4897. scaledX = x / fontSizeScale;
  4898. scaledY = 0;
  4899. }
  4900. if (font.remeasure && width > 0) {
  4901. const measuredWidth = ctx.measureText(character).width * 1000 / fontSize * fontSizeScale;
  4902. if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
  4903. const characterScaleX = width / measuredWidth;
  4904. restoreNeeded = true;
  4905. ctx.save();
  4906. ctx.scale(characterScaleX, 1);
  4907. scaledX /= characterScaleX;
  4908. } else if (width !== measuredWidth) {
  4909. scaledX += (width - measuredWidth) / 2000 * fontSize / fontSizeScale;
  4910. }
  4911. }
  4912. if (this.contentVisible && (glyph.isInFont || font.missingFile)) {
  4913. if (simpleFillText && !accent) {
  4914. ctx.fillText(character, scaledX, scaledY);
  4915. } else {
  4916. this.paintChar(character, scaledX, scaledY, patternTransform, resetLineWidthToOne);
  4917. if (accent) {
  4918. const scaledAccentX = scaledX + fontSize * accent.offset.x / fontSizeScale;
  4919. const scaledAccentY = scaledY - fontSize * accent.offset.y / fontSizeScale;
  4920. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY, patternTransform, resetLineWidthToOne);
  4921. }
  4922. }
  4923. }
  4924. let charWidth;
  4925. if (vertical) {
  4926. charWidth = width * widthAdvanceScale - spacing * fontDirection;
  4927. } else {
  4928. charWidth = width * widthAdvanceScale + spacing * fontDirection;
  4929. }
  4930. x += charWidth;
  4931. if (restoreNeeded) {
  4932. ctx.restore();
  4933. }
  4934. }
  4935. if (vertical) {
  4936. current.y -= x;
  4937. } else {
  4938. current.x += x * textHScale;
  4939. }
  4940. ctx.restore();
  4941. },
  4942. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  4943. const ctx = this.ctx;
  4944. const current = this.current;
  4945. const font = current.font;
  4946. const fontSize = current.fontSize;
  4947. const fontDirection = current.fontDirection;
  4948. const spacingDir = font.vertical ? 1 : -1;
  4949. const charSpacing = current.charSpacing;
  4950. const wordSpacing = current.wordSpacing;
  4951. const textHScale = current.textHScale * fontDirection;
  4952. const fontMatrix = current.fontMatrix || _util.FONT_IDENTITY_MATRIX;
  4953. const glyphsLength = glyphs.length;
  4954. const isTextInvisible = current.textRenderingMode === _util.TextRenderingMode.INVISIBLE;
  4955. let i, glyph, width, spacingLength;
  4956. if (isTextInvisible || fontSize === 0) {
  4957. return;
  4958. }
  4959. this._cachedGetSinglePixelWidth = null;
  4960. ctx.save();
  4961. ctx.transform.apply(ctx, current.textMatrix);
  4962. ctx.translate(current.x, current.y);
  4963. ctx.scale(textHScale, fontDirection);
  4964. for (i = 0; i < glyphsLength; ++i) {
  4965. glyph = glyphs[i];
  4966. if ((0, _util.isNum)(glyph)) {
  4967. spacingLength = spacingDir * glyph * fontSize / 1000;
  4968. this.ctx.translate(spacingLength, 0);
  4969. current.x += spacingLength * textHScale;
  4970. continue;
  4971. }
  4972. const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  4973. const operatorList = font.charProcOperatorList[glyph.operatorListId];
  4974. if (!operatorList) {
  4975. (0, _util.warn)(`Type3 character "${glyph.operatorListId}" is not available.`);
  4976. continue;
  4977. }
  4978. if (this.contentVisible) {
  4979. this.processingType3 = glyph;
  4980. this.save();
  4981. ctx.scale(fontSize, fontSize);
  4982. ctx.transform.apply(ctx, fontMatrix);
  4983. this.executeOperatorList(operatorList);
  4984. this.restore();
  4985. }
  4986. const transformed = _util.Util.applyTransform([glyph.width, 0], fontMatrix);
  4987. width = transformed[0] * fontSize + spacing;
  4988. ctx.translate(width, 0);
  4989. current.x += width * textHScale;
  4990. }
  4991. ctx.restore();
  4992. this.processingType3 = null;
  4993. },
  4994. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {},
  4995. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth, yWidth, llx, lly, urx, ury) {
  4996. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  4997. this.clip();
  4998. this.endPath();
  4999. },
  5000. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  5001. let pattern;
  5002. if (IR[0] === "TilingPattern") {
  5003. const color = IR[1];
  5004. const baseTransform = this.baseTransform || this.ctx.mozCurrentTransform.slice();
  5005. const canvasGraphicsFactory = {
  5006. createCanvasGraphics: ctx => {
  5007. return new CanvasGraphics(ctx, this.commonObjs, this.objs, this.canvasFactory, this.webGLContext);
  5008. }
  5009. };
  5010. pattern = new _pattern_helper.TilingPattern(IR, color, this.ctx, canvasGraphicsFactory, baseTransform);
  5011. } else {
  5012. pattern = (0, _pattern_helper.getShadingPatternFromIR)(IR);
  5013. }
  5014. return pattern;
  5015. },
  5016. setStrokeColorN: function CanvasGraphics_setStrokeColorN() {
  5017. this.current.strokeColor = this.getColorN_Pattern(arguments);
  5018. },
  5019. setFillColorN: function CanvasGraphics_setFillColorN() {
  5020. this.current.fillColor = this.getColorN_Pattern(arguments);
  5021. this.current.patternFill = true;
  5022. },
  5023. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  5024. const color = _util.Util.makeHexColor(r, g, b);
  5025. this.ctx.strokeStyle = color;
  5026. this.current.strokeColor = color;
  5027. },
  5028. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  5029. const color = _util.Util.makeHexColor(r, g, b);
  5030. this.ctx.fillStyle = color;
  5031. this.current.fillColor = color;
  5032. this.current.patternFill = false;
  5033. },
  5034. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  5035. if (!this.contentVisible) {
  5036. return;
  5037. }
  5038. const ctx = this.ctx;
  5039. this.save();
  5040. const pattern = (0, _pattern_helper.getShadingPatternFromIR)(patternIR);
  5041. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  5042. const inv = ctx.mozCurrentTransformInverse;
  5043. if (inv) {
  5044. const canvas = ctx.canvas;
  5045. const width = canvas.width;
  5046. const height = canvas.height;
  5047. const bl = _util.Util.applyTransform([0, 0], inv);
  5048. const br = _util.Util.applyTransform([0, height], inv);
  5049. const ul = _util.Util.applyTransform([width, 0], inv);
  5050. const ur = _util.Util.applyTransform([width, height], inv);
  5051. const x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  5052. const y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  5053. const x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  5054. const y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  5055. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  5056. } else {
  5057. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  5058. }
  5059. this.restore();
  5060. },
  5061. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  5062. (0, _util.unreachable)("Should not call beginInlineImage");
  5063. },
  5064. beginImageData: function CanvasGraphics_beginImageData() {
  5065. (0, _util.unreachable)("Should not call beginImageData");
  5066. },
  5067. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix, bbox) {
  5068. if (!this.contentVisible) {
  5069. return;
  5070. }
  5071. this.save();
  5072. this.baseTransformStack.push(this.baseTransform);
  5073. if (Array.isArray(matrix) && matrix.length === 6) {
  5074. this.transform.apply(this, matrix);
  5075. }
  5076. this.baseTransform = this.ctx.mozCurrentTransform;
  5077. if (bbox) {
  5078. const width = bbox[2] - bbox[0];
  5079. const height = bbox[3] - bbox[1];
  5080. this.ctx.rect(bbox[0], bbox[1], width, height);
  5081. this.clip();
  5082. this.endPath();
  5083. }
  5084. },
  5085. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  5086. if (!this.contentVisible) {
  5087. return;
  5088. }
  5089. this.restore();
  5090. this.baseTransform = this.baseTransformStack.pop();
  5091. },
  5092. beginGroup: function CanvasGraphics_beginGroup(group) {
  5093. if (!this.contentVisible) {
  5094. return;
  5095. }
  5096. this.save();
  5097. const currentCtx = this.ctx;
  5098. if (!group.isolated) {
  5099. (0, _util.info)("TODO: Support non-isolated groups.");
  5100. }
  5101. if (group.knockout) {
  5102. (0, _util.warn)("Knockout groups not supported.");
  5103. }
  5104. const currentTransform = currentCtx.mozCurrentTransform;
  5105. if (group.matrix) {
  5106. currentCtx.transform.apply(currentCtx, group.matrix);
  5107. }
  5108. if (!group.bbox) {
  5109. throw new Error("Bounding box is required.");
  5110. }
  5111. let bounds = _util.Util.getAxialAlignedBoundingBox(group.bbox, currentCtx.mozCurrentTransform);
  5112. const canvasBounds = [0, 0, currentCtx.canvas.width, currentCtx.canvas.height];
  5113. bounds = _util.Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  5114. const offsetX = Math.floor(bounds[0]);
  5115. const offsetY = Math.floor(bounds[1]);
  5116. let drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  5117. let drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  5118. let scaleX = 1,
  5119. scaleY = 1;
  5120. if (drawnWidth > MAX_GROUP_SIZE) {
  5121. scaleX = drawnWidth / MAX_GROUP_SIZE;
  5122. drawnWidth = MAX_GROUP_SIZE;
  5123. }
  5124. if (drawnHeight > MAX_GROUP_SIZE) {
  5125. scaleY = drawnHeight / MAX_GROUP_SIZE;
  5126. drawnHeight = MAX_GROUP_SIZE;
  5127. }
  5128. let cacheId = "groupAt" + this.groupLevel;
  5129. if (group.smask) {
  5130. cacheId += "_smask_" + this.smaskCounter++ % 2;
  5131. }
  5132. const scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true);
  5133. const groupCtx = scratchCanvas.context;
  5134. groupCtx.scale(1 / scaleX, 1 / scaleY);
  5135. groupCtx.translate(-offsetX, -offsetY);
  5136. groupCtx.transform.apply(groupCtx, currentTransform);
  5137. if (group.smask) {
  5138. this.smaskStack.push({
  5139. canvas: scratchCanvas.canvas,
  5140. context: groupCtx,
  5141. offsetX,
  5142. offsetY,
  5143. scaleX,
  5144. scaleY,
  5145. subtype: group.smask.subtype,
  5146. backdrop: group.smask.backdrop,
  5147. transferMap: group.smask.transferMap || null,
  5148. startTransformInverse: null
  5149. });
  5150. } else {
  5151. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  5152. currentCtx.translate(offsetX, offsetY);
  5153. currentCtx.scale(scaleX, scaleY);
  5154. }
  5155. copyCtxState(currentCtx, groupCtx);
  5156. this.ctx = groupCtx;
  5157. this.setGState([["BM", "source-over"], ["ca", 1], ["CA", 1]]);
  5158. this.groupStack.push(currentCtx);
  5159. this.groupLevel++;
  5160. this.current.activeSMask = null;
  5161. },
  5162. endGroup: function CanvasGraphics_endGroup(group) {
  5163. if (!this.contentVisible) {
  5164. return;
  5165. }
  5166. this.groupLevel--;
  5167. const groupCtx = this.ctx;
  5168. this.ctx = this.groupStack.pop();
  5169. if (this.ctx.imageSmoothingEnabled !== undefined) {
  5170. this.ctx.imageSmoothingEnabled = false;
  5171. } else {
  5172. this.ctx.mozImageSmoothingEnabled = false;
  5173. }
  5174. if (group.smask) {
  5175. this.tempSMask = this.smaskStack.pop();
  5176. } else {
  5177. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  5178. }
  5179. this.restore();
  5180. },
  5181. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  5182. this.save();
  5183. if (this.baseTransform) {
  5184. this.ctx.setTransform.apply(this.ctx, this.baseTransform);
  5185. }
  5186. },
  5187. endAnnotations: function CanvasGraphics_endAnnotations() {
  5188. this.restore();
  5189. },
  5190. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform, matrix) {
  5191. this.save();
  5192. resetCtxToDefault(this.ctx);
  5193. this.current = new CanvasExtraState();
  5194. if (Array.isArray(rect) && rect.length === 4) {
  5195. const width = rect[2] - rect[0];
  5196. const height = rect[3] - rect[1];
  5197. this.ctx.rect(rect[0], rect[1], width, height);
  5198. this.clip();
  5199. this.endPath();
  5200. }
  5201. this.transform.apply(this, transform);
  5202. this.transform.apply(this, matrix);
  5203. },
  5204. endAnnotation: function CanvasGraphics_endAnnotation() {
  5205. this.restore();
  5206. },
  5207. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  5208. if (!this.contentVisible) {
  5209. return;
  5210. }
  5211. const ctx = this.ctx;
  5212. const width = img.width,
  5213. height = img.height;
  5214. const fillColor = this.current.fillColor;
  5215. const isPatternFill = this.current.patternFill;
  5216. const glyph = this.processingType3;
  5217. if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
  5218. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  5219. glyph.compiled = compileType3Glyph({
  5220. data: img.data,
  5221. width,
  5222. height
  5223. });
  5224. } else {
  5225. glyph.compiled = null;
  5226. }
  5227. }
  5228. if (glyph?.compiled) {
  5229. glyph.compiled(ctx);
  5230. return;
  5231. }
  5232. const maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
  5233. const maskCtx = maskCanvas.context;
  5234. maskCtx.save();
  5235. putBinaryImageMask(maskCtx, img);
  5236. maskCtx.globalCompositeOperation = "source-in";
  5237. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor;
  5238. maskCtx.fillRect(0, 0, width, height);
  5239. maskCtx.restore();
  5240. this.paintInlineImageXObject(maskCanvas.canvas);
  5241. },
  5242. paintImageMaskXObjectRepeat(imgData, scaleX, skewX = 0, skewY = 0, scaleY, positions) {
  5243. if (!this.contentVisible) {
  5244. return;
  5245. }
  5246. const width = imgData.width;
  5247. const height = imgData.height;
  5248. const fillColor = this.current.fillColor;
  5249. const isPatternFill = this.current.patternFill;
  5250. const maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
  5251. const maskCtx = maskCanvas.context;
  5252. maskCtx.save();
  5253. putBinaryImageMask(maskCtx, imgData);
  5254. maskCtx.globalCompositeOperation = "source-in";
  5255. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor;
  5256. maskCtx.fillRect(0, 0, width, height);
  5257. maskCtx.restore();
  5258. const ctx = this.ctx;
  5259. for (let i = 0, ii = positions.length; i < ii; i += 2) {
  5260. ctx.save();
  5261. ctx.transform(scaleX, skewX, skewY, scaleY, positions[i], positions[i + 1]);
  5262. ctx.scale(1, -1);
  5263. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1);
  5264. ctx.restore();
  5265. }
  5266. },
  5267. paintImageMaskXObjectGroup: function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  5268. if (!this.contentVisible) {
  5269. return;
  5270. }
  5271. const ctx = this.ctx;
  5272. const fillColor = this.current.fillColor;
  5273. const isPatternFill = this.current.patternFill;
  5274. for (let i = 0, ii = images.length; i < ii; i++) {
  5275. const image = images[i];
  5276. const width = image.width,
  5277. height = image.height;
  5278. const maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
  5279. const maskCtx = maskCanvas.context;
  5280. maskCtx.save();
  5281. putBinaryImageMask(maskCtx, image);
  5282. maskCtx.globalCompositeOperation = "source-in";
  5283. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor;
  5284. maskCtx.fillRect(0, 0, width, height);
  5285. maskCtx.restore();
  5286. ctx.save();
  5287. ctx.transform.apply(ctx, image.transform);
  5288. ctx.scale(1, -1);
  5289. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1);
  5290. ctx.restore();
  5291. }
  5292. },
  5293. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  5294. if (!this.contentVisible) {
  5295. return;
  5296. }
  5297. const imgData = objId.startsWith("g_") ? this.commonObjs.get(objId) : this.objs.get(objId);
  5298. if (!imgData) {
  5299. (0, _util.warn)("Dependent image isn't ready yet");
  5300. return;
  5301. }
  5302. this.paintInlineImageXObject(imgData);
  5303. },
  5304. paintImageXObjectRepeat: function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY, positions) {
  5305. if (!this.contentVisible) {
  5306. return;
  5307. }
  5308. const imgData = objId.startsWith("g_") ? this.commonObjs.get(objId) : this.objs.get(objId);
  5309. if (!imgData) {
  5310. (0, _util.warn)("Dependent image isn't ready yet");
  5311. return;
  5312. }
  5313. const width = imgData.width;
  5314. const height = imgData.height;
  5315. const map = [];
  5316. for (let i = 0, ii = positions.length; i < ii; i += 2) {
  5317. map.push({
  5318. transform: [scaleX, 0, 0, scaleY, positions[i], positions[i + 1]],
  5319. x: 0,
  5320. y: 0,
  5321. w: width,
  5322. h: height
  5323. });
  5324. }
  5325. this.paintInlineImageXObjectGroup(imgData, map);
  5326. },
  5327. paintInlineImageXObject: function CanvasGraphics_paintInlineImageXObject(imgData) {
  5328. if (!this.contentVisible) {
  5329. return;
  5330. }
  5331. const width = imgData.width;
  5332. const height = imgData.height;
  5333. const ctx = this.ctx;
  5334. this.save();
  5335. ctx.scale(1 / width, -1 / height);
  5336. const currentTransform = ctx.mozCurrentTransformInverse;
  5337. let widthScale = Math.max(Math.hypot(currentTransform[0], currentTransform[1]), 1);
  5338. let heightScale = Math.max(Math.hypot(currentTransform[2], currentTransform[3]), 1);
  5339. let imgToPaint, tmpCanvas, tmpCtx;
  5340. if (typeof HTMLElement === "function" && imgData instanceof HTMLElement || !imgData.data) {
  5341. imgToPaint = imgData;
  5342. } else {
  5343. tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", width, height);
  5344. tmpCtx = tmpCanvas.context;
  5345. putBinaryImageData(tmpCtx, imgData, this.current.transferMaps);
  5346. imgToPaint = tmpCanvas.canvas;
  5347. }
  5348. let paintWidth = width,
  5349. paintHeight = height;
  5350. let tmpCanvasId = "prescale1";
  5351. while (widthScale > 2 && paintWidth > 1 || heightScale > 2 && paintHeight > 1) {
  5352. let newWidth = paintWidth,
  5353. newHeight = paintHeight;
  5354. if (widthScale > 2 && paintWidth > 1) {
  5355. newWidth = Math.ceil(paintWidth / 2);
  5356. widthScale /= paintWidth / newWidth;
  5357. }
  5358. if (heightScale > 2 && paintHeight > 1) {
  5359. newHeight = Math.ceil(paintHeight / 2);
  5360. heightScale /= paintHeight / newHeight;
  5361. }
  5362. tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
  5363. tmpCtx = tmpCanvas.context;
  5364. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  5365. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, 0, 0, newWidth, newHeight);
  5366. imgToPaint = tmpCanvas.canvas;
  5367. paintWidth = newWidth;
  5368. paintHeight = newHeight;
  5369. tmpCanvasId = tmpCanvasId === "prescale1" ? "prescale2" : "prescale1";
  5370. }
  5371. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, 0, -height, width, height);
  5372. if (this.imageLayer) {
  5373. const position = this.getCanvasPosition(0, -height);
  5374. this.imageLayer.appendImage({
  5375. imgData,
  5376. left: position[0],
  5377. top: position[1],
  5378. width: width / currentTransform[0],
  5379. height: height / currentTransform[3]
  5380. });
  5381. }
  5382. this.restore();
  5383. },
  5384. paintInlineImageXObjectGroup: function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  5385. if (!this.contentVisible) {
  5386. return;
  5387. }
  5388. const ctx = this.ctx;
  5389. const w = imgData.width;
  5390. const h = imgData.height;
  5391. const tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", w, h);
  5392. const tmpCtx = tmpCanvas.context;
  5393. putBinaryImageData(tmpCtx, imgData, this.current.transferMaps);
  5394. for (let i = 0, ii = map.length; i < ii; i++) {
  5395. const entry = map[i];
  5396. ctx.save();
  5397. ctx.transform.apply(ctx, entry.transform);
  5398. ctx.scale(1, -1);
  5399. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h, 0, -1, 1, 1);
  5400. if (this.imageLayer) {
  5401. const position = this.getCanvasPosition(entry.x, entry.y);
  5402. this.imageLayer.appendImage({
  5403. imgData,
  5404. left: position[0],
  5405. top: position[1],
  5406. width: w,
  5407. height: h
  5408. });
  5409. }
  5410. ctx.restore();
  5411. }
  5412. },
  5413. paintSolidColorImageMask: function CanvasGraphics_paintSolidColorImageMask() {
  5414. if (!this.contentVisible) {
  5415. return;
  5416. }
  5417. this.ctx.fillRect(0, 0, 1, 1);
  5418. },
  5419. markPoint: function CanvasGraphics_markPoint(tag) {},
  5420. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {},
  5421. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  5422. this.markedContentStack.push({
  5423. visible: true
  5424. });
  5425. },
  5426. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(tag, properties) {
  5427. if (tag === "OC") {
  5428. this.markedContentStack.push({
  5429. visible: this.optionalContentConfig.isVisible(properties)
  5430. });
  5431. } else {
  5432. this.markedContentStack.push({
  5433. visible: true
  5434. });
  5435. }
  5436. this.contentVisible = this.isContentVisible();
  5437. },
  5438. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  5439. this.markedContentStack.pop();
  5440. this.contentVisible = this.isContentVisible();
  5441. },
  5442. beginCompat: function CanvasGraphics_beginCompat() {},
  5443. endCompat: function CanvasGraphics_endCompat() {},
  5444. consumePath: function CanvasGraphics_consumePath() {
  5445. const ctx = this.ctx;
  5446. if (this.pendingClip) {
  5447. if (this.pendingClip === EO_CLIP) {
  5448. ctx.clip("evenodd");
  5449. } else {
  5450. ctx.clip();
  5451. }
  5452. this.pendingClip = null;
  5453. }
  5454. ctx.beginPath();
  5455. },
  5456. getSinglePixelWidth() {
  5457. if (this._cachedGetSinglePixelWidth === null) {
  5458. const m = this.ctx.mozCurrentTransform;
  5459. const absDet = Math.abs(m[0] * m[3] - m[2] * m[1]);
  5460. const sqNorm1 = m[0] ** 2 + m[2] ** 2;
  5461. const sqNorm2 = m[1] ** 2 + m[3] ** 2;
  5462. const pixelHeight = Math.sqrt(Math.max(sqNorm1, sqNorm2)) / absDet;
  5463. if (sqNorm1 !== sqNorm2 && this._combinedScaleFactor * pixelHeight > 1) {
  5464. this._cachedGetSinglePixelWidth = -(this._combinedScaleFactor * pixelHeight);
  5465. } else if (absDet > Number.EPSILON) {
  5466. this._cachedGetSinglePixelWidth = pixelHeight;
  5467. } else {
  5468. this._cachedGetSinglePixelWidth = 1;
  5469. }
  5470. }
  5471. return this._cachedGetSinglePixelWidth;
  5472. },
  5473. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  5474. const transform = this.ctx.mozCurrentTransform;
  5475. return [transform[0] * x + transform[2] * y + transform[4], transform[1] * x + transform[3] * y + transform[5]];
  5476. },
  5477. isContentVisible: function CanvasGraphics_isContentVisible() {
  5478. for (let i = this.markedContentStack.length - 1; i >= 0; i--) {
  5479. if (!this.markedContentStack[i].visible) {
  5480. return false;
  5481. }
  5482. }
  5483. return true;
  5484. }
  5485. };
  5486. for (const op in _util.OPS) {
  5487. CanvasGraphics.prototype[_util.OPS[op]] = CanvasGraphics.prototype[op];
  5488. }
  5489. return CanvasGraphics;
  5490. }();
  5491. exports.CanvasGraphics = CanvasGraphics;
  5492. /***/ }),
  5493. /* 11 */
  5494. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  5495. Object.defineProperty(exports, "__esModule", ({
  5496. value: true
  5497. }));
  5498. exports.getShadingPatternFromIR = getShadingPatternFromIR;
  5499. exports.TilingPattern = void 0;
  5500. var _util = __w_pdfjs_require__(2);
  5501. const ShadingIRs = {};
  5502. function applyBoundingBox(ctx, bbox) {
  5503. if (!bbox || typeof Path2D === "undefined") {
  5504. return;
  5505. }
  5506. const width = bbox[2] - bbox[0];
  5507. const height = bbox[3] - bbox[1];
  5508. const region = new Path2D();
  5509. region.rect(bbox[0], bbox[1], width, height);
  5510. ctx.clip(region);
  5511. }
  5512. ShadingIRs.RadialAxial = {
  5513. fromIR: function RadialAxial_fromIR(raw) {
  5514. const type = raw[1];
  5515. const bbox = raw[2];
  5516. const colorStops = raw[3];
  5517. const p0 = raw[4];
  5518. const p1 = raw[5];
  5519. const r0 = raw[6];
  5520. const r1 = raw[7];
  5521. return {
  5522. getPattern: function RadialAxial_getPattern(ctx) {
  5523. applyBoundingBox(ctx, bbox);
  5524. let grad;
  5525. if (type === "axial") {
  5526. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  5527. } else if (type === "radial") {
  5528. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  5529. }
  5530. for (let i = 0, ii = colorStops.length; i < ii; ++i) {
  5531. const c = colorStops[i];
  5532. grad.addColorStop(c[0], c[1]);
  5533. }
  5534. return grad;
  5535. }
  5536. };
  5537. }
  5538. };
  5539. const createMeshCanvas = function createMeshCanvasClosure() {
  5540. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  5541. const coords = context.coords,
  5542. colors = context.colors;
  5543. const bytes = data.data,
  5544. rowSize = data.width * 4;
  5545. let tmp;
  5546. if (coords[p1 + 1] > coords[p2 + 1]) {
  5547. tmp = p1;
  5548. p1 = p2;
  5549. p2 = tmp;
  5550. tmp = c1;
  5551. c1 = c2;
  5552. c2 = tmp;
  5553. }
  5554. if (coords[p2 + 1] > coords[p3 + 1]) {
  5555. tmp = p2;
  5556. p2 = p3;
  5557. p3 = tmp;
  5558. tmp = c2;
  5559. c2 = c3;
  5560. c3 = tmp;
  5561. }
  5562. if (coords[p1 + 1] > coords[p2 + 1]) {
  5563. tmp = p1;
  5564. p1 = p2;
  5565. p2 = tmp;
  5566. tmp = c1;
  5567. c1 = c2;
  5568. c2 = tmp;
  5569. }
  5570. const x1 = (coords[p1] + context.offsetX) * context.scaleX;
  5571. const y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  5572. const x2 = (coords[p2] + context.offsetX) * context.scaleX;
  5573. const y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  5574. const x3 = (coords[p3] + context.offsetX) * context.scaleX;
  5575. const y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  5576. if (y1 >= y3) {
  5577. return;
  5578. }
  5579. const c1r = colors[c1],
  5580. c1g = colors[c1 + 1],
  5581. c1b = colors[c1 + 2];
  5582. const c2r = colors[c2],
  5583. c2g = colors[c2 + 1],
  5584. c2b = colors[c2 + 2];
  5585. const c3r = colors[c3],
  5586. c3g = colors[c3 + 1],
  5587. c3b = colors[c3 + 2];
  5588. const minY = Math.round(y1),
  5589. maxY = Math.round(y3);
  5590. let xa, car, cag, cab;
  5591. let xb, cbr, cbg, cbb;
  5592. for (let y = minY; y <= maxY; y++) {
  5593. if (y < y2) {
  5594. let k;
  5595. if (y < y1) {
  5596. k = 0;
  5597. } else if (y1 === y2) {
  5598. k = 1;
  5599. } else {
  5600. k = (y1 - y) / (y1 - y2);
  5601. }
  5602. xa = x1 - (x1 - x2) * k;
  5603. car = c1r - (c1r - c2r) * k;
  5604. cag = c1g - (c1g - c2g) * k;
  5605. cab = c1b - (c1b - c2b) * k;
  5606. } else {
  5607. let k;
  5608. if (y > y3) {
  5609. k = 1;
  5610. } else if (y2 === y3) {
  5611. k = 0;
  5612. } else {
  5613. k = (y2 - y) / (y2 - y3);
  5614. }
  5615. xa = x2 - (x2 - x3) * k;
  5616. car = c2r - (c2r - c3r) * k;
  5617. cag = c2g - (c2g - c3g) * k;
  5618. cab = c2b - (c2b - c3b) * k;
  5619. }
  5620. let k;
  5621. if (y < y1) {
  5622. k = 0;
  5623. } else if (y > y3) {
  5624. k = 1;
  5625. } else {
  5626. k = (y1 - y) / (y1 - y3);
  5627. }
  5628. xb = x1 - (x1 - x3) * k;
  5629. cbr = c1r - (c1r - c3r) * k;
  5630. cbg = c1g - (c1g - c3g) * k;
  5631. cbb = c1b - (c1b - c3b) * k;
  5632. const x1_ = Math.round(Math.min(xa, xb));
  5633. const x2_ = Math.round(Math.max(xa, xb));
  5634. let j = rowSize * y + x1_ * 4;
  5635. for (let x = x1_; x <= x2_; x++) {
  5636. k = (xa - x) / (xa - xb);
  5637. if (k < 0) {
  5638. k = 0;
  5639. } else if (k > 1) {
  5640. k = 1;
  5641. }
  5642. bytes[j++] = car - (car - cbr) * k | 0;
  5643. bytes[j++] = cag - (cag - cbg) * k | 0;
  5644. bytes[j++] = cab - (cab - cbb) * k | 0;
  5645. bytes[j++] = 255;
  5646. }
  5647. }
  5648. }
  5649. function drawFigure(data, figure, context) {
  5650. const ps = figure.coords;
  5651. const cs = figure.colors;
  5652. let i, ii;
  5653. switch (figure.type) {
  5654. case "lattice":
  5655. const verticesPerRow = figure.verticesPerRow;
  5656. const rows = Math.floor(ps.length / verticesPerRow) - 1;
  5657. const cols = verticesPerRow - 1;
  5658. for (i = 0; i < rows; i++) {
  5659. let q = i * verticesPerRow;
  5660. for (let j = 0; j < cols; j++, q++) {
  5661. drawTriangle(data, context, ps[q], ps[q + 1], ps[q + verticesPerRow], cs[q], cs[q + 1], cs[q + verticesPerRow]);
  5662. drawTriangle(data, context, ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow], cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  5663. }
  5664. }
  5665. break;
  5666. case "triangles":
  5667. for (i = 0, ii = ps.length; i < ii; i += 3) {
  5668. drawTriangle(data, context, ps[i], ps[i + 1], ps[i + 2], cs[i], cs[i + 1], cs[i + 2]);
  5669. }
  5670. break;
  5671. default:
  5672. throw new Error("illegal figure");
  5673. }
  5674. }
  5675. function createMeshCanvas(bounds, combinesScale, coords, colors, figures, backgroundColor, cachedCanvases, webGLContext) {
  5676. const EXPECTED_SCALE = 1.1;
  5677. const MAX_PATTERN_SIZE = 3000;
  5678. const BORDER_SIZE = 2;
  5679. const offsetX = Math.floor(bounds[0]);
  5680. const offsetY = Math.floor(bounds[1]);
  5681. const boundsWidth = Math.ceil(bounds[2]) - offsetX;
  5682. const boundsHeight = Math.ceil(bounds[3]) - offsetY;
  5683. const width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5684. const height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5685. const scaleX = boundsWidth / width;
  5686. const scaleY = boundsHeight / height;
  5687. const context = {
  5688. coords,
  5689. colors,
  5690. offsetX: -offsetX,
  5691. offsetY: -offsetY,
  5692. scaleX: 1 / scaleX,
  5693. scaleY: 1 / scaleY
  5694. };
  5695. const paddedWidth = width + BORDER_SIZE * 2;
  5696. const paddedHeight = height + BORDER_SIZE * 2;
  5697. let canvas, tmpCanvas, i, ii;
  5698. if (webGLContext.isEnabled) {
  5699. canvas = webGLContext.drawFigures({
  5700. width,
  5701. height,
  5702. backgroundColor,
  5703. figures,
  5704. context
  5705. });
  5706. tmpCanvas = cachedCanvases.getCanvas("mesh", paddedWidth, paddedHeight, false);
  5707. tmpCanvas.context.drawImage(canvas, BORDER_SIZE, BORDER_SIZE);
  5708. canvas = tmpCanvas.canvas;
  5709. } else {
  5710. tmpCanvas = cachedCanvases.getCanvas("mesh", paddedWidth, paddedHeight, false);
  5711. const tmpCtx = tmpCanvas.context;
  5712. const data = tmpCtx.createImageData(width, height);
  5713. if (backgroundColor) {
  5714. const bytes = data.data;
  5715. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  5716. bytes[i] = backgroundColor[0];
  5717. bytes[i + 1] = backgroundColor[1];
  5718. bytes[i + 2] = backgroundColor[2];
  5719. bytes[i + 3] = 255;
  5720. }
  5721. }
  5722. for (i = 0; i < figures.length; i++) {
  5723. drawFigure(data, figures[i], context);
  5724. }
  5725. tmpCtx.putImageData(data, BORDER_SIZE, BORDER_SIZE);
  5726. canvas = tmpCanvas.canvas;
  5727. }
  5728. return {
  5729. canvas,
  5730. offsetX: offsetX - BORDER_SIZE * scaleX,
  5731. offsetY: offsetY - BORDER_SIZE * scaleY,
  5732. scaleX,
  5733. scaleY
  5734. };
  5735. }
  5736. return createMeshCanvas;
  5737. }();
  5738. ShadingIRs.Mesh = {
  5739. fromIR: function Mesh_fromIR(raw) {
  5740. const coords = raw[2];
  5741. const colors = raw[3];
  5742. const figures = raw[4];
  5743. const bounds = raw[5];
  5744. const matrix = raw[6];
  5745. const bbox = raw[7];
  5746. const background = raw[8];
  5747. return {
  5748. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  5749. applyBoundingBox(ctx, bbox);
  5750. let scale;
  5751. if (shadingFill) {
  5752. scale = _util.Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  5753. } else {
  5754. scale = _util.Util.singularValueDecompose2dScale(owner.baseTransform);
  5755. if (matrix) {
  5756. const matrixScale = _util.Util.singularValueDecompose2dScale(matrix);
  5757. scale = [scale[0] * matrixScale[0], scale[1] * matrixScale[1]];
  5758. }
  5759. }
  5760. const temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords, colors, figures, shadingFill ? null : background, owner.cachedCanvases, owner.webGLContext);
  5761. if (!shadingFill) {
  5762. ctx.setTransform.apply(ctx, owner.baseTransform);
  5763. if (matrix) {
  5764. ctx.transform.apply(ctx, matrix);
  5765. }
  5766. }
  5767. ctx.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY);
  5768. ctx.scale(temporaryPatternCanvas.scaleX, temporaryPatternCanvas.scaleY);
  5769. return ctx.createPattern(temporaryPatternCanvas.canvas, "no-repeat");
  5770. }
  5771. };
  5772. }
  5773. };
  5774. ShadingIRs.Dummy = {
  5775. fromIR: function Dummy_fromIR() {
  5776. return {
  5777. getPattern: function Dummy_fromIR_getPattern() {
  5778. return "hotpink";
  5779. }
  5780. };
  5781. }
  5782. };
  5783. function getShadingPatternFromIR(raw) {
  5784. const shadingIR = ShadingIRs[raw[0]];
  5785. if (!shadingIR) {
  5786. throw new Error(`Unknown IR type: ${raw[0]}`);
  5787. }
  5788. return shadingIR.fromIR(raw);
  5789. }
  5790. const TilingPattern = function TilingPatternClosure() {
  5791. const PaintType = {
  5792. COLORED: 1,
  5793. UNCOLORED: 2
  5794. };
  5795. const MAX_PATTERN_SIZE = 3000;
  5796. function TilingPattern(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
  5797. this.operatorList = IR[2];
  5798. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  5799. this.bbox = IR[4];
  5800. this.xstep = IR[5];
  5801. this.ystep = IR[6];
  5802. this.paintType = IR[7];
  5803. this.tilingType = IR[8];
  5804. this.color = color;
  5805. this.canvasGraphicsFactory = canvasGraphicsFactory;
  5806. this.baseTransform = baseTransform;
  5807. this.ctx = ctx;
  5808. }
  5809. TilingPattern.prototype = {
  5810. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  5811. const operatorList = this.operatorList;
  5812. const bbox = this.bbox;
  5813. const xstep = this.xstep;
  5814. const ystep = this.ystep;
  5815. const paintType = this.paintType;
  5816. const tilingType = this.tilingType;
  5817. const color = this.color;
  5818. const canvasGraphicsFactory = this.canvasGraphicsFactory;
  5819. (0, _util.info)("TilingType: " + tilingType);
  5820. const x0 = bbox[0],
  5821. y0 = bbox[1],
  5822. x1 = bbox[2],
  5823. y1 = bbox[3];
  5824. const matrixScale = _util.Util.singularValueDecompose2dScale(this.matrix);
  5825. const curMatrixScale = _util.Util.singularValueDecompose2dScale(this.baseTransform);
  5826. const combinedScale = [matrixScale[0] * curMatrixScale[0], matrixScale[1] * curMatrixScale[1]];
  5827. const dimx = this.getSizeAndScale(xstep, this.ctx.canvas.width, combinedScale[0]);
  5828. const dimy = this.getSizeAndScale(ystep, this.ctx.canvas.height, combinedScale[1]);
  5829. const tmpCanvas = owner.cachedCanvases.getCanvas("pattern", dimx.size, dimy.size, true);
  5830. const tmpCtx = tmpCanvas.context;
  5831. const graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
  5832. graphics.groupLevel = owner.groupLevel;
  5833. this.setFillAndStrokeStyleToContext(graphics, paintType, color);
  5834. graphics.transform(dimx.scale, 0, 0, dimy.scale, 0, 0);
  5835. graphics.transform(1, 0, 0, 1, -x0, -y0);
  5836. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  5837. graphics.executeOperatorList(operatorList);
  5838. this.ctx.transform(1, 0, 0, 1, x0, y0);
  5839. this.ctx.scale(1 / dimx.scale, 1 / dimy.scale);
  5840. return tmpCanvas.canvas;
  5841. },
  5842. getSizeAndScale: function TilingPattern_getSizeAndScale(step, realOutputSize, scale) {
  5843. step = Math.abs(step);
  5844. const maxSize = Math.max(MAX_PATTERN_SIZE, realOutputSize);
  5845. let size = Math.ceil(step * scale);
  5846. if (size >= maxSize) {
  5847. size = maxSize;
  5848. } else {
  5849. scale = size / step;
  5850. }
  5851. return {
  5852. scale,
  5853. size
  5854. };
  5855. },
  5856. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  5857. if (Array.isArray(bbox) && bbox.length === 4) {
  5858. const bboxWidth = x1 - x0;
  5859. const bboxHeight = y1 - y0;
  5860. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  5861. graphics.clip();
  5862. graphics.endPath();
  5863. }
  5864. },
  5865. setFillAndStrokeStyleToContext: function setFillAndStrokeStyleToContext(graphics, paintType, color) {
  5866. const context = graphics.ctx,
  5867. current = graphics.current;
  5868. switch (paintType) {
  5869. case PaintType.COLORED:
  5870. const ctx = this.ctx;
  5871. context.fillStyle = ctx.fillStyle;
  5872. context.strokeStyle = ctx.strokeStyle;
  5873. current.fillColor = ctx.fillStyle;
  5874. current.strokeColor = ctx.strokeStyle;
  5875. break;
  5876. case PaintType.UNCOLORED:
  5877. const cssColor = _util.Util.makeHexColor(color[0], color[1], color[2]);
  5878. context.fillStyle = cssColor;
  5879. context.strokeStyle = cssColor;
  5880. current.fillColor = cssColor;
  5881. current.strokeColor = cssColor;
  5882. break;
  5883. default:
  5884. throw new _util.FormatError(`Unsupported paint type: ${paintType}`);
  5885. }
  5886. },
  5887. getPattern: function TilingPattern_getPattern(ctx, owner) {
  5888. ctx = this.ctx;
  5889. ctx.setTransform.apply(ctx, this.baseTransform);
  5890. ctx.transform.apply(ctx, this.matrix);
  5891. const temporaryPatternCanvas = this.createPatternCanvas(owner);
  5892. return ctx.createPattern(temporaryPatternCanvas, "repeat");
  5893. }
  5894. };
  5895. return TilingPattern;
  5896. }();
  5897. exports.TilingPattern = TilingPattern;
  5898. /***/ }),
  5899. /* 12 */
  5900. /***/ ((__unused_webpack_module, exports) => {
  5901. Object.defineProperty(exports, "__esModule", ({
  5902. value: true
  5903. }));
  5904. exports.GlobalWorkerOptions = void 0;
  5905. const GlobalWorkerOptions = Object.create(null);
  5906. exports.GlobalWorkerOptions = GlobalWorkerOptions;
  5907. GlobalWorkerOptions.workerPort = GlobalWorkerOptions.workerPort === undefined ? null : GlobalWorkerOptions.workerPort;
  5908. GlobalWorkerOptions.workerSrc = GlobalWorkerOptions.workerSrc === undefined ? "" : GlobalWorkerOptions.workerSrc;
  5909. /***/ }),
  5910. /* 13 */
  5911. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  5912. Object.defineProperty(exports, "__esModule", ({
  5913. value: true
  5914. }));
  5915. exports.MessageHandler = void 0;
  5916. var _util = __w_pdfjs_require__(2);
  5917. const CallbackKind = {
  5918. UNKNOWN: 0,
  5919. DATA: 1,
  5920. ERROR: 2
  5921. };
  5922. const StreamKind = {
  5923. UNKNOWN: 0,
  5924. CANCEL: 1,
  5925. CANCEL_COMPLETE: 2,
  5926. CLOSE: 3,
  5927. ENQUEUE: 4,
  5928. ERROR: 5,
  5929. PULL: 6,
  5930. PULL_COMPLETE: 7,
  5931. START_COMPLETE: 8
  5932. };
  5933. function wrapReason(reason) {
  5934. if (typeof reason !== "object" || reason === null) {
  5935. return reason;
  5936. }
  5937. switch (reason.name) {
  5938. case "AbortException":
  5939. return new _util.AbortException(reason.message);
  5940. case "MissingPDFException":
  5941. return new _util.MissingPDFException(reason.message);
  5942. case "UnexpectedResponseException":
  5943. return new _util.UnexpectedResponseException(reason.message, reason.status);
  5944. case "UnknownErrorException":
  5945. return new _util.UnknownErrorException(reason.message, reason.details);
  5946. default:
  5947. return new _util.UnknownErrorException(reason.message, reason.toString());
  5948. }
  5949. }
  5950. class MessageHandler {
  5951. constructor(sourceName, targetName, comObj) {
  5952. this.sourceName = sourceName;
  5953. this.targetName = targetName;
  5954. this.comObj = comObj;
  5955. this.callbackId = 1;
  5956. this.streamId = 1;
  5957. this.postMessageTransfers = true;
  5958. this.streamSinks = Object.create(null);
  5959. this.streamControllers = Object.create(null);
  5960. this.callbackCapabilities = Object.create(null);
  5961. this.actionHandler = Object.create(null);
  5962. this._onComObjOnMessage = event => {
  5963. const data = event.data;
  5964. if (data.targetName !== this.sourceName) {
  5965. return;
  5966. }
  5967. if (data.stream) {
  5968. this._processStreamMessage(data);
  5969. return;
  5970. }
  5971. if (data.callback) {
  5972. const callbackId = data.callbackId;
  5973. const capability = this.callbackCapabilities[callbackId];
  5974. if (!capability) {
  5975. throw new Error(`Cannot resolve callback ${callbackId}`);
  5976. }
  5977. delete this.callbackCapabilities[callbackId];
  5978. if (data.callback === CallbackKind.DATA) {
  5979. capability.resolve(data.data);
  5980. } else if (data.callback === CallbackKind.ERROR) {
  5981. capability.reject(wrapReason(data.reason));
  5982. } else {
  5983. throw new Error("Unexpected callback case");
  5984. }
  5985. return;
  5986. }
  5987. const action = this.actionHandler[data.action];
  5988. if (!action) {
  5989. throw new Error(`Unknown action from worker: ${data.action}`);
  5990. }
  5991. if (data.callbackId) {
  5992. const cbSourceName = this.sourceName;
  5993. const cbTargetName = data.sourceName;
  5994. new Promise(function (resolve) {
  5995. resolve(action(data.data));
  5996. }).then(function (result) {
  5997. comObj.postMessage({
  5998. sourceName: cbSourceName,
  5999. targetName: cbTargetName,
  6000. callback: CallbackKind.DATA,
  6001. callbackId: data.callbackId,
  6002. data: result
  6003. });
  6004. }, function (reason) {
  6005. comObj.postMessage({
  6006. sourceName: cbSourceName,
  6007. targetName: cbTargetName,
  6008. callback: CallbackKind.ERROR,
  6009. callbackId: data.callbackId,
  6010. reason: wrapReason(reason)
  6011. });
  6012. });
  6013. return;
  6014. }
  6015. if (data.streamId) {
  6016. this._createStreamSink(data);
  6017. return;
  6018. }
  6019. action(data.data);
  6020. };
  6021. comObj.addEventListener("message", this._onComObjOnMessage);
  6022. }
  6023. on(actionName, handler) {
  6024. const ah = this.actionHandler;
  6025. if (ah[actionName]) {
  6026. throw new Error(`There is already an actionName called "${actionName}"`);
  6027. }
  6028. ah[actionName] = handler;
  6029. }
  6030. send(actionName, data, transfers) {
  6031. this._postMessage({
  6032. sourceName: this.sourceName,
  6033. targetName: this.targetName,
  6034. action: actionName,
  6035. data
  6036. }, transfers);
  6037. }
  6038. sendWithPromise(actionName, data, transfers) {
  6039. const callbackId = this.callbackId++;
  6040. const capability = (0, _util.createPromiseCapability)();
  6041. this.callbackCapabilities[callbackId] = capability;
  6042. try {
  6043. this._postMessage({
  6044. sourceName: this.sourceName,
  6045. targetName: this.targetName,
  6046. action: actionName,
  6047. callbackId,
  6048. data
  6049. }, transfers);
  6050. } catch (ex) {
  6051. capability.reject(ex);
  6052. }
  6053. return capability.promise;
  6054. }
  6055. sendWithStream(actionName, data, queueingStrategy, transfers) {
  6056. const streamId = this.streamId++;
  6057. const sourceName = this.sourceName;
  6058. const targetName = this.targetName;
  6059. const comObj = this.comObj;
  6060. return new ReadableStream({
  6061. start: controller => {
  6062. const startCapability = (0, _util.createPromiseCapability)();
  6063. this.streamControllers[streamId] = {
  6064. controller,
  6065. startCall: startCapability,
  6066. pullCall: null,
  6067. cancelCall: null,
  6068. isClosed: false
  6069. };
  6070. this._postMessage({
  6071. sourceName,
  6072. targetName,
  6073. action: actionName,
  6074. streamId,
  6075. data,
  6076. desiredSize: controller.desiredSize
  6077. }, transfers);
  6078. return startCapability.promise;
  6079. },
  6080. pull: controller => {
  6081. const pullCapability = (0, _util.createPromiseCapability)();
  6082. this.streamControllers[streamId].pullCall = pullCapability;
  6083. comObj.postMessage({
  6084. sourceName,
  6085. targetName,
  6086. stream: StreamKind.PULL,
  6087. streamId,
  6088. desiredSize: controller.desiredSize
  6089. });
  6090. return pullCapability.promise;
  6091. },
  6092. cancel: reason => {
  6093. (0, _util.assert)(reason instanceof Error, "cancel must have a valid reason");
  6094. const cancelCapability = (0, _util.createPromiseCapability)();
  6095. this.streamControllers[streamId].cancelCall = cancelCapability;
  6096. this.streamControllers[streamId].isClosed = true;
  6097. comObj.postMessage({
  6098. sourceName,
  6099. targetName,
  6100. stream: StreamKind.CANCEL,
  6101. streamId,
  6102. reason: wrapReason(reason)
  6103. });
  6104. return cancelCapability.promise;
  6105. }
  6106. }, queueingStrategy);
  6107. }
  6108. _createStreamSink(data) {
  6109. const self = this;
  6110. const action = this.actionHandler[data.action];
  6111. const streamId = data.streamId;
  6112. const sourceName = this.sourceName;
  6113. const targetName = data.sourceName;
  6114. const comObj = this.comObj;
  6115. const streamSink = {
  6116. enqueue(chunk, size = 1, transfers) {
  6117. if (this.isCancelled) {
  6118. return;
  6119. }
  6120. const lastDesiredSize = this.desiredSize;
  6121. this.desiredSize -= size;
  6122. if (lastDesiredSize > 0 && this.desiredSize <= 0) {
  6123. this.sinkCapability = (0, _util.createPromiseCapability)();
  6124. this.ready = this.sinkCapability.promise;
  6125. }
  6126. self._postMessage({
  6127. sourceName,
  6128. targetName,
  6129. stream: StreamKind.ENQUEUE,
  6130. streamId,
  6131. chunk
  6132. }, transfers);
  6133. },
  6134. close() {
  6135. if (this.isCancelled) {
  6136. return;
  6137. }
  6138. this.isCancelled = true;
  6139. comObj.postMessage({
  6140. sourceName,
  6141. targetName,
  6142. stream: StreamKind.CLOSE,
  6143. streamId
  6144. });
  6145. delete self.streamSinks[streamId];
  6146. },
  6147. error(reason) {
  6148. (0, _util.assert)(reason instanceof Error, "error must have a valid reason");
  6149. if (this.isCancelled) {
  6150. return;
  6151. }
  6152. this.isCancelled = true;
  6153. comObj.postMessage({
  6154. sourceName,
  6155. targetName,
  6156. stream: StreamKind.ERROR,
  6157. streamId,
  6158. reason: wrapReason(reason)
  6159. });
  6160. },
  6161. sinkCapability: (0, _util.createPromiseCapability)(),
  6162. onPull: null,
  6163. onCancel: null,
  6164. isCancelled: false,
  6165. desiredSize: data.desiredSize,
  6166. ready: null
  6167. };
  6168. streamSink.sinkCapability.resolve();
  6169. streamSink.ready = streamSink.sinkCapability.promise;
  6170. this.streamSinks[streamId] = streamSink;
  6171. new Promise(function (resolve) {
  6172. resolve(action(data.data, streamSink));
  6173. }).then(function () {
  6174. comObj.postMessage({
  6175. sourceName,
  6176. targetName,
  6177. stream: StreamKind.START_COMPLETE,
  6178. streamId,
  6179. success: true
  6180. });
  6181. }, function (reason) {
  6182. comObj.postMessage({
  6183. sourceName,
  6184. targetName,
  6185. stream: StreamKind.START_COMPLETE,
  6186. streamId,
  6187. reason: wrapReason(reason)
  6188. });
  6189. });
  6190. }
  6191. _processStreamMessage(data) {
  6192. const streamId = data.streamId;
  6193. const sourceName = this.sourceName;
  6194. const targetName = data.sourceName;
  6195. const comObj = this.comObj;
  6196. switch (data.stream) {
  6197. case StreamKind.START_COMPLETE:
  6198. if (data.success) {
  6199. this.streamControllers[streamId].startCall.resolve();
  6200. } else {
  6201. this.streamControllers[streamId].startCall.reject(wrapReason(data.reason));
  6202. }
  6203. break;
  6204. case StreamKind.PULL_COMPLETE:
  6205. if (data.success) {
  6206. this.streamControllers[streamId].pullCall.resolve();
  6207. } else {
  6208. this.streamControllers[streamId].pullCall.reject(wrapReason(data.reason));
  6209. }
  6210. break;
  6211. case StreamKind.PULL:
  6212. if (!this.streamSinks[streamId]) {
  6213. comObj.postMessage({
  6214. sourceName,
  6215. targetName,
  6216. stream: StreamKind.PULL_COMPLETE,
  6217. streamId,
  6218. success: true
  6219. });
  6220. break;
  6221. }
  6222. if (this.streamSinks[streamId].desiredSize <= 0 && data.desiredSize > 0) {
  6223. this.streamSinks[streamId].sinkCapability.resolve();
  6224. }
  6225. this.streamSinks[streamId].desiredSize = data.desiredSize;
  6226. const {
  6227. onPull
  6228. } = this.streamSinks[data.streamId];
  6229. new Promise(function (resolve) {
  6230. resolve(onPull && onPull());
  6231. }).then(function () {
  6232. comObj.postMessage({
  6233. sourceName,
  6234. targetName,
  6235. stream: StreamKind.PULL_COMPLETE,
  6236. streamId,
  6237. success: true
  6238. });
  6239. }, function (reason) {
  6240. comObj.postMessage({
  6241. sourceName,
  6242. targetName,
  6243. stream: StreamKind.PULL_COMPLETE,
  6244. streamId,
  6245. reason: wrapReason(reason)
  6246. });
  6247. });
  6248. break;
  6249. case StreamKind.ENQUEUE:
  6250. (0, _util.assert)(this.streamControllers[streamId], "enqueue should have stream controller");
  6251. if (this.streamControllers[streamId].isClosed) {
  6252. break;
  6253. }
  6254. this.streamControllers[streamId].controller.enqueue(data.chunk);
  6255. break;
  6256. case StreamKind.CLOSE:
  6257. (0, _util.assert)(this.streamControllers[streamId], "close should have stream controller");
  6258. if (this.streamControllers[streamId].isClosed) {
  6259. break;
  6260. }
  6261. this.streamControllers[streamId].isClosed = true;
  6262. this.streamControllers[streamId].controller.close();
  6263. this._deleteStreamController(streamId);
  6264. break;
  6265. case StreamKind.ERROR:
  6266. (0, _util.assert)(this.streamControllers[streamId], "error should have stream controller");
  6267. this.streamControllers[streamId].controller.error(wrapReason(data.reason));
  6268. this._deleteStreamController(streamId);
  6269. break;
  6270. case StreamKind.CANCEL_COMPLETE:
  6271. if (data.success) {
  6272. this.streamControllers[streamId].cancelCall.resolve();
  6273. } else {
  6274. this.streamControllers[streamId].cancelCall.reject(wrapReason(data.reason));
  6275. }
  6276. this._deleteStreamController(streamId);
  6277. break;
  6278. case StreamKind.CANCEL:
  6279. if (!this.streamSinks[streamId]) {
  6280. break;
  6281. }
  6282. const {
  6283. onCancel
  6284. } = this.streamSinks[data.streamId];
  6285. new Promise(function (resolve) {
  6286. resolve(onCancel && onCancel(wrapReason(data.reason)));
  6287. }).then(function () {
  6288. comObj.postMessage({
  6289. sourceName,
  6290. targetName,
  6291. stream: StreamKind.CANCEL_COMPLETE,
  6292. streamId,
  6293. success: true
  6294. });
  6295. }, function (reason) {
  6296. comObj.postMessage({
  6297. sourceName,
  6298. targetName,
  6299. stream: StreamKind.CANCEL_COMPLETE,
  6300. streamId,
  6301. reason: wrapReason(reason)
  6302. });
  6303. });
  6304. this.streamSinks[streamId].sinkCapability.reject(wrapReason(data.reason));
  6305. this.streamSinks[streamId].isCancelled = true;
  6306. delete this.streamSinks[streamId];
  6307. break;
  6308. default:
  6309. throw new Error("Unexpected stream case");
  6310. }
  6311. }
  6312. async _deleteStreamController(streamId) {
  6313. await Promise.allSettled([this.streamControllers[streamId].startCall, this.streamControllers[streamId].pullCall, this.streamControllers[streamId].cancelCall].map(function (capability) {
  6314. return capability && capability.promise;
  6315. }));
  6316. delete this.streamControllers[streamId];
  6317. }
  6318. _postMessage(message, transfers) {
  6319. if (transfers && this.postMessageTransfers) {
  6320. this.comObj.postMessage(message, transfers);
  6321. } else {
  6322. this.comObj.postMessage(message);
  6323. }
  6324. }
  6325. destroy() {
  6326. this.comObj.removeEventListener("message", this._onComObjOnMessage);
  6327. }
  6328. }
  6329. exports.MessageHandler = MessageHandler;
  6330. /***/ }),
  6331. /* 14 */
  6332. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  6333. Object.defineProperty(exports, "__esModule", ({
  6334. value: true
  6335. }));
  6336. exports.Metadata = void 0;
  6337. var _util = __w_pdfjs_require__(2);
  6338. class Metadata {
  6339. constructor({
  6340. parsedData,
  6341. rawData
  6342. }) {
  6343. this._metadataMap = parsedData;
  6344. this._data = rawData;
  6345. }
  6346. getRaw() {
  6347. return this._data;
  6348. }
  6349. get(name) {
  6350. return this._metadataMap.get(name) ?? null;
  6351. }
  6352. getAll() {
  6353. return (0, _util.objectFromMap)(this._metadataMap);
  6354. }
  6355. has(name) {
  6356. return this._metadataMap.has(name);
  6357. }
  6358. }
  6359. exports.Metadata = Metadata;
  6360. /***/ }),
  6361. /* 15 */
  6362. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  6363. Object.defineProperty(exports, "__esModule", ({
  6364. value: true
  6365. }));
  6366. exports.OptionalContentConfig = void 0;
  6367. var _util = __w_pdfjs_require__(2);
  6368. class OptionalContentGroup {
  6369. constructor(name, intent) {
  6370. this.visible = true;
  6371. this.name = name;
  6372. this.intent = intent;
  6373. }
  6374. }
  6375. class OptionalContentConfig {
  6376. constructor(data) {
  6377. this.name = null;
  6378. this.creator = null;
  6379. this._order = null;
  6380. this._groups = new Map();
  6381. if (data === null) {
  6382. return;
  6383. }
  6384. this.name = data.name;
  6385. this.creator = data.creator;
  6386. this._order = data.order;
  6387. for (const group of data.groups) {
  6388. this._groups.set(group.id, new OptionalContentGroup(group.name, group.intent));
  6389. }
  6390. if (data.baseState === "OFF") {
  6391. for (const group of this._groups) {
  6392. group.visible = false;
  6393. }
  6394. }
  6395. for (const on of data.on) {
  6396. this._groups.get(on).visible = true;
  6397. }
  6398. for (const off of data.off) {
  6399. this._groups.get(off).visible = false;
  6400. }
  6401. }
  6402. isVisible(group) {
  6403. if (group.type === "OCG") {
  6404. if (!this._groups.has(group.id)) {
  6405. (0, _util.warn)(`Optional content group not found: ${group.id}`);
  6406. return true;
  6407. }
  6408. return this._groups.get(group.id).visible;
  6409. } else if (group.type === "OCMD") {
  6410. if (group.expression) {
  6411. (0, _util.warn)("Visibility expression not supported yet.");
  6412. }
  6413. if (!group.policy || group.policy === "AnyOn") {
  6414. for (const id of group.ids) {
  6415. if (!this._groups.has(id)) {
  6416. (0, _util.warn)(`Optional content group not found: ${id}`);
  6417. return true;
  6418. }
  6419. if (this._groups.get(id).visible) {
  6420. return true;
  6421. }
  6422. }
  6423. return false;
  6424. } else if (group.policy === "AllOn") {
  6425. for (const id of group.ids) {
  6426. if (!this._groups.has(id)) {
  6427. (0, _util.warn)(`Optional content group not found: ${id}`);
  6428. return true;
  6429. }
  6430. if (!this._groups.get(id).visible) {
  6431. return false;
  6432. }
  6433. }
  6434. return true;
  6435. } else if (group.policy === "AnyOff") {
  6436. for (const id of group.ids) {
  6437. if (!this._groups.has(id)) {
  6438. (0, _util.warn)(`Optional content group not found: ${id}`);
  6439. return true;
  6440. }
  6441. if (!this._groups.get(id).visible) {
  6442. return true;
  6443. }
  6444. }
  6445. return false;
  6446. } else if (group.policy === "AllOff") {
  6447. for (const id of group.ids) {
  6448. if (!this._groups.has(id)) {
  6449. (0, _util.warn)(`Optional content group not found: ${id}`);
  6450. return true;
  6451. }
  6452. if (this._groups.get(id).visible) {
  6453. return false;
  6454. }
  6455. }
  6456. return true;
  6457. }
  6458. (0, _util.warn)(`Unknown optional content policy ${group.policy}.`);
  6459. return true;
  6460. }
  6461. (0, _util.warn)(`Unknown group type ${group.type}.`);
  6462. return true;
  6463. }
  6464. setVisibility(id, visible = true) {
  6465. if (!this._groups.has(id)) {
  6466. (0, _util.warn)(`Optional content group not found: ${id}`);
  6467. return;
  6468. }
  6469. this._groups.get(id).visible = !!visible;
  6470. }
  6471. getOrder() {
  6472. if (!this._groups.size) {
  6473. return null;
  6474. }
  6475. if (this._order) {
  6476. return this._order.slice();
  6477. }
  6478. return Array.from(this._groups.keys());
  6479. }
  6480. getGroups() {
  6481. return this._groups.size > 0 ? (0, _util.objectFromMap)(this._groups) : null;
  6482. }
  6483. getGroup(id) {
  6484. return this._groups.get(id) || null;
  6485. }
  6486. }
  6487. exports.OptionalContentConfig = OptionalContentConfig;
  6488. /***/ }),
  6489. /* 16 */
  6490. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  6491. Object.defineProperty(exports, "__esModule", ({
  6492. value: true
  6493. }));
  6494. exports.PDFDataTransportStream = void 0;
  6495. var _util = __w_pdfjs_require__(2);
  6496. var _display_utils = __w_pdfjs_require__(1);
  6497. class PDFDataTransportStream {
  6498. constructor(params, pdfDataRangeTransport) {
  6499. (0, _util.assert)(pdfDataRangeTransport, 'PDFDataTransportStream - missing required "pdfDataRangeTransport" argument.');
  6500. this._queuedChunks = [];
  6501. this._progressiveDone = params.progressiveDone || false;
  6502. this._contentDispositionFilename = params.contentDispositionFilename || null;
  6503. const initialData = params.initialData;
  6504. if (initialData?.length > 0) {
  6505. const buffer = new Uint8Array(initialData).buffer;
  6506. this._queuedChunks.push(buffer);
  6507. }
  6508. this._pdfDataRangeTransport = pdfDataRangeTransport;
  6509. this._isStreamingSupported = !params.disableStream;
  6510. this._isRangeSupported = !params.disableRange;
  6511. this._contentLength = params.length;
  6512. this._fullRequestReader = null;
  6513. this._rangeReaders = [];
  6514. this._pdfDataRangeTransport.addRangeListener((begin, chunk) => {
  6515. this._onReceiveData({
  6516. begin,
  6517. chunk
  6518. });
  6519. });
  6520. this._pdfDataRangeTransport.addProgressListener((loaded, total) => {
  6521. this._onProgress({
  6522. loaded,
  6523. total
  6524. });
  6525. });
  6526. this._pdfDataRangeTransport.addProgressiveReadListener(chunk => {
  6527. this._onReceiveData({
  6528. chunk
  6529. });
  6530. });
  6531. this._pdfDataRangeTransport.addProgressiveDoneListener(() => {
  6532. this._onProgressiveDone();
  6533. });
  6534. this._pdfDataRangeTransport.transportReady();
  6535. }
  6536. _onReceiveData(args) {
  6537. const buffer = new Uint8Array(args.chunk).buffer;
  6538. if (args.begin === undefined) {
  6539. if (this._fullRequestReader) {
  6540. this._fullRequestReader._enqueue(buffer);
  6541. } else {
  6542. this._queuedChunks.push(buffer);
  6543. }
  6544. } else {
  6545. const found = this._rangeReaders.some(function (rangeReader) {
  6546. if (rangeReader._begin !== args.begin) {
  6547. return false;
  6548. }
  6549. rangeReader._enqueue(buffer);
  6550. return true;
  6551. });
  6552. (0, _util.assert)(found, "_onReceiveData - no `PDFDataTransportStreamRangeReader` instance found.");
  6553. }
  6554. }
  6555. get _progressiveDataLength() {
  6556. return this._fullRequestReader?._loaded ?? 0;
  6557. }
  6558. _onProgress(evt) {
  6559. if (evt.total === undefined) {
  6560. const firstReader = this._rangeReaders[0];
  6561. if (firstReader?.onProgress) {
  6562. firstReader.onProgress({
  6563. loaded: evt.loaded
  6564. });
  6565. }
  6566. } else {
  6567. const fullReader = this._fullRequestReader;
  6568. if (fullReader?.onProgress) {
  6569. fullReader.onProgress({
  6570. loaded: evt.loaded,
  6571. total: evt.total
  6572. });
  6573. }
  6574. }
  6575. }
  6576. _onProgressiveDone() {
  6577. if (this._fullRequestReader) {
  6578. this._fullRequestReader.progressiveDone();
  6579. }
  6580. this._progressiveDone = true;
  6581. }
  6582. _removeRangeReader(reader) {
  6583. const i = this._rangeReaders.indexOf(reader);
  6584. if (i >= 0) {
  6585. this._rangeReaders.splice(i, 1);
  6586. }
  6587. }
  6588. getFullReader() {
  6589. (0, _util.assert)(!this._fullRequestReader, "PDFDataTransportStream.getFullReader can only be called once.");
  6590. const queuedChunks = this._queuedChunks;
  6591. this._queuedChunks = null;
  6592. return new PDFDataTransportStreamReader(this, queuedChunks, this._progressiveDone, this._contentDispositionFilename);
  6593. }
  6594. getRangeReader(begin, end) {
  6595. if (end <= this._progressiveDataLength) {
  6596. return null;
  6597. }
  6598. const reader = new PDFDataTransportStreamRangeReader(this, begin, end);
  6599. this._pdfDataRangeTransport.requestDataRange(begin, end);
  6600. this._rangeReaders.push(reader);
  6601. return reader;
  6602. }
  6603. cancelAllRequests(reason) {
  6604. if (this._fullRequestReader) {
  6605. this._fullRequestReader.cancel(reason);
  6606. }
  6607. const readers = this._rangeReaders.slice(0);
  6608. readers.forEach(function (rangeReader) {
  6609. rangeReader.cancel(reason);
  6610. });
  6611. this._pdfDataRangeTransport.abort();
  6612. }
  6613. }
  6614. exports.PDFDataTransportStream = PDFDataTransportStream;
  6615. class PDFDataTransportStreamReader {
  6616. constructor(stream, queuedChunks, progressiveDone = false, contentDispositionFilename = null) {
  6617. this._stream = stream;
  6618. this._done = progressiveDone || false;
  6619. this._filename = (0, _display_utils.isPdfFile)(contentDispositionFilename) ? contentDispositionFilename : null;
  6620. this._queuedChunks = queuedChunks || [];
  6621. this._loaded = 0;
  6622. for (const chunk of this._queuedChunks) {
  6623. this._loaded += chunk.byteLength;
  6624. }
  6625. this._requests = [];
  6626. this._headersReady = Promise.resolve();
  6627. stream._fullRequestReader = this;
  6628. this.onProgress = null;
  6629. }
  6630. _enqueue(chunk) {
  6631. if (this._done) {
  6632. return;
  6633. }
  6634. if (this._requests.length > 0) {
  6635. const requestCapability = this._requests.shift();
  6636. requestCapability.resolve({
  6637. value: chunk,
  6638. done: false
  6639. });
  6640. } else {
  6641. this._queuedChunks.push(chunk);
  6642. }
  6643. this._loaded += chunk.byteLength;
  6644. }
  6645. get headersReady() {
  6646. return this._headersReady;
  6647. }
  6648. get filename() {
  6649. return this._filename;
  6650. }
  6651. get isRangeSupported() {
  6652. return this._stream._isRangeSupported;
  6653. }
  6654. get isStreamingSupported() {
  6655. return this._stream._isStreamingSupported;
  6656. }
  6657. get contentLength() {
  6658. return this._stream._contentLength;
  6659. }
  6660. async read() {
  6661. if (this._queuedChunks.length > 0) {
  6662. const chunk = this._queuedChunks.shift();
  6663. return {
  6664. value: chunk,
  6665. done: false
  6666. };
  6667. }
  6668. if (this._done) {
  6669. return {
  6670. value: undefined,
  6671. done: true
  6672. };
  6673. }
  6674. const requestCapability = (0, _util.createPromiseCapability)();
  6675. this._requests.push(requestCapability);
  6676. return requestCapability.promise;
  6677. }
  6678. cancel(reason) {
  6679. this._done = true;
  6680. this._requests.forEach(function (requestCapability) {
  6681. requestCapability.resolve({
  6682. value: undefined,
  6683. done: true
  6684. });
  6685. });
  6686. this._requests = [];
  6687. }
  6688. progressiveDone() {
  6689. if (this._done) {
  6690. return;
  6691. }
  6692. this._done = true;
  6693. }
  6694. }
  6695. class PDFDataTransportStreamRangeReader {
  6696. constructor(stream, begin, end) {
  6697. this._stream = stream;
  6698. this._begin = begin;
  6699. this._end = end;
  6700. this._queuedChunk = null;
  6701. this._requests = [];
  6702. this._done = false;
  6703. this.onProgress = null;
  6704. }
  6705. _enqueue(chunk) {
  6706. if (this._done) {
  6707. return;
  6708. }
  6709. if (this._requests.length === 0) {
  6710. this._queuedChunk = chunk;
  6711. } else {
  6712. const requestsCapability = this._requests.shift();
  6713. requestsCapability.resolve({
  6714. value: chunk,
  6715. done: false
  6716. });
  6717. this._requests.forEach(function (requestCapability) {
  6718. requestCapability.resolve({
  6719. value: undefined,
  6720. done: true
  6721. });
  6722. });
  6723. this._requests = [];
  6724. }
  6725. this._done = true;
  6726. this._stream._removeRangeReader(this);
  6727. }
  6728. get isStreamingSupported() {
  6729. return false;
  6730. }
  6731. async read() {
  6732. if (this._queuedChunk) {
  6733. const chunk = this._queuedChunk;
  6734. this._queuedChunk = null;
  6735. return {
  6736. value: chunk,
  6737. done: false
  6738. };
  6739. }
  6740. if (this._done) {
  6741. return {
  6742. value: undefined,
  6743. done: true
  6744. };
  6745. }
  6746. const requestCapability = (0, _util.createPromiseCapability)();
  6747. this._requests.push(requestCapability);
  6748. return requestCapability.promise;
  6749. }
  6750. cancel(reason) {
  6751. this._done = true;
  6752. this._requests.forEach(function (requestCapability) {
  6753. requestCapability.resolve({
  6754. value: undefined,
  6755. done: true
  6756. });
  6757. });
  6758. this._requests = [];
  6759. this._stream._removeRangeReader(this);
  6760. }
  6761. }
  6762. /***/ }),
  6763. /* 17 */
  6764. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  6765. Object.defineProperty(exports, "__esModule", ({
  6766. value: true
  6767. }));
  6768. exports.WebGLContext = void 0;
  6769. var _util = __w_pdfjs_require__(2);
  6770. class WebGLContext {
  6771. constructor({
  6772. enable = false
  6773. }) {
  6774. this._enabled = enable === true;
  6775. }
  6776. get isEnabled() {
  6777. let enabled = this._enabled;
  6778. if (enabled) {
  6779. enabled = WebGLUtils.tryInitGL();
  6780. }
  6781. return (0, _util.shadow)(this, "isEnabled", enabled);
  6782. }
  6783. composeSMask({
  6784. layer,
  6785. mask,
  6786. properties
  6787. }) {
  6788. return WebGLUtils.composeSMask(layer, mask, properties);
  6789. }
  6790. drawFigures({
  6791. width,
  6792. height,
  6793. backgroundColor,
  6794. figures,
  6795. context
  6796. }) {
  6797. return WebGLUtils.drawFigures(width, height, backgroundColor, figures, context);
  6798. }
  6799. clear() {
  6800. WebGLUtils.cleanup();
  6801. }
  6802. }
  6803. exports.WebGLContext = WebGLContext;
  6804. const WebGLUtils = function WebGLUtilsClosure() {
  6805. function loadShader(gl, code, shaderType) {
  6806. const shader = gl.createShader(shaderType);
  6807. gl.shaderSource(shader, code);
  6808. gl.compileShader(shader);
  6809. const compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  6810. if (!compiled) {
  6811. const errorMsg = gl.getShaderInfoLog(shader);
  6812. throw new Error("Error during shader compilation: " + errorMsg);
  6813. }
  6814. return shader;
  6815. }
  6816. function createVertexShader(gl, code) {
  6817. return loadShader(gl, code, gl.VERTEX_SHADER);
  6818. }
  6819. function createFragmentShader(gl, code) {
  6820. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  6821. }
  6822. function createProgram(gl, shaders) {
  6823. const program = gl.createProgram();
  6824. for (let i = 0, ii = shaders.length; i < ii; ++i) {
  6825. gl.attachShader(program, shaders[i]);
  6826. }
  6827. gl.linkProgram(program);
  6828. const linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  6829. if (!linked) {
  6830. const errorMsg = gl.getProgramInfoLog(program);
  6831. throw new Error("Error during program linking: " + errorMsg);
  6832. }
  6833. return program;
  6834. }
  6835. function createTexture(gl, image, textureId) {
  6836. gl.activeTexture(textureId);
  6837. const texture = gl.createTexture();
  6838. gl.bindTexture(gl.TEXTURE_2D, texture);
  6839. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  6840. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  6841. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  6842. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  6843. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  6844. return texture;
  6845. }
  6846. let currentGL, currentCanvas;
  6847. function generateGL() {
  6848. if (currentGL) {
  6849. return;
  6850. }
  6851. currentCanvas = document.createElement("canvas");
  6852. currentGL = currentCanvas.getContext("webgl", {
  6853. premultipliedalpha: false
  6854. });
  6855. }
  6856. const smaskVertexShaderCode = "\
  6857. attribute vec2 a_position; \
  6858. attribute vec2 a_texCoord; \
  6859. \
  6860. uniform vec2 u_resolution; \
  6861. \
  6862. varying vec2 v_texCoord; \
  6863. \
  6864. void main() { \
  6865. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  6866. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  6867. \
  6868. v_texCoord = a_texCoord; \
  6869. } ";
  6870. const smaskFragmentShaderCode = "\
  6871. precision mediump float; \
  6872. \
  6873. uniform vec4 u_backdrop; \
  6874. uniform int u_subtype; \
  6875. uniform sampler2D u_image; \
  6876. uniform sampler2D u_mask; \
  6877. \
  6878. varying vec2 v_texCoord; \
  6879. \
  6880. void main() { \
  6881. vec4 imageColor = texture2D(u_image, v_texCoord); \
  6882. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  6883. if (u_backdrop.a > 0.0) { \
  6884. maskColor.rgb = maskColor.rgb * maskColor.a + \
  6885. u_backdrop.rgb * (1.0 - maskColor.a); \
  6886. } \
  6887. float lum; \
  6888. if (u_subtype == 0) { \
  6889. lum = maskColor.a; \
  6890. } else { \
  6891. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  6892. maskColor.b * 0.11; \
  6893. } \
  6894. imageColor.a *= lum; \
  6895. imageColor.rgb *= imageColor.a; \
  6896. gl_FragColor = imageColor; \
  6897. } ";
  6898. let smaskCache = null;
  6899. function initSmaskGL() {
  6900. generateGL();
  6901. const canvas = currentCanvas;
  6902. currentCanvas = null;
  6903. const gl = currentGL;
  6904. currentGL = null;
  6905. const vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  6906. const fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  6907. const program = createProgram(gl, [vertexShader, fragmentShader]);
  6908. gl.useProgram(program);
  6909. const cache = {};
  6910. cache.gl = gl;
  6911. cache.canvas = canvas;
  6912. cache.resolutionLocation = gl.getUniformLocation(program, "u_resolution");
  6913. cache.positionLocation = gl.getAttribLocation(program, "a_position");
  6914. cache.backdropLocation = gl.getUniformLocation(program, "u_backdrop");
  6915. cache.subtypeLocation = gl.getUniformLocation(program, "u_subtype");
  6916. const texCoordLocation = gl.getAttribLocation(program, "a_texCoord");
  6917. const texLayerLocation = gl.getUniformLocation(program, "u_image");
  6918. const texMaskLocation = gl.getUniformLocation(program, "u_mask");
  6919. const texCoordBuffer = gl.createBuffer();
  6920. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  6921. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0]), gl.STATIC_DRAW);
  6922. gl.enableVertexAttribArray(texCoordLocation);
  6923. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  6924. gl.uniform1i(texLayerLocation, 0);
  6925. gl.uniform1i(texMaskLocation, 1);
  6926. smaskCache = cache;
  6927. }
  6928. function composeSMask(layer, mask, properties) {
  6929. const width = layer.width,
  6930. height = layer.height;
  6931. if (!smaskCache) {
  6932. initSmaskGL();
  6933. }
  6934. const cache = smaskCache,
  6935. canvas = cache.canvas,
  6936. gl = cache.gl;
  6937. canvas.width = width;
  6938. canvas.height = height;
  6939. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  6940. gl.uniform2f(cache.resolutionLocation, width, height);
  6941. if (properties.backdrop) {
  6942. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0], properties.backdrop[1], properties.backdrop[2], 1);
  6943. } else {
  6944. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  6945. }
  6946. gl.uniform1i(cache.subtypeLocation, properties.subtype === "Luminosity" ? 1 : 0);
  6947. const texture = createTexture(gl, layer, gl.TEXTURE0);
  6948. const maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  6949. const buffer = gl.createBuffer();
  6950. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  6951. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0, 0, width, 0, 0, height, 0, height, width, 0, width, height]), gl.STATIC_DRAW);
  6952. gl.enableVertexAttribArray(cache.positionLocation);
  6953. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  6954. gl.clearColor(0, 0, 0, 0);
  6955. gl.enable(gl.BLEND);
  6956. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  6957. gl.clear(gl.COLOR_BUFFER_BIT);
  6958. gl.drawArrays(gl.TRIANGLES, 0, 6);
  6959. gl.flush();
  6960. gl.deleteTexture(texture);
  6961. gl.deleteTexture(maskTexture);
  6962. gl.deleteBuffer(buffer);
  6963. return canvas;
  6964. }
  6965. const figuresVertexShaderCode = "\
  6966. attribute vec2 a_position; \
  6967. attribute vec3 a_color; \
  6968. \
  6969. uniform vec2 u_resolution; \
  6970. uniform vec2 u_scale; \
  6971. uniform vec2 u_offset; \
  6972. \
  6973. varying vec4 v_color; \
  6974. \
  6975. void main() { \
  6976. vec2 position = (a_position + u_offset) * u_scale; \
  6977. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  6978. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  6979. \
  6980. v_color = vec4(a_color / 255.0, 1.0); \
  6981. } ";
  6982. const figuresFragmentShaderCode = "\
  6983. precision mediump float; \
  6984. \
  6985. varying vec4 v_color; \
  6986. \
  6987. void main() { \
  6988. gl_FragColor = v_color; \
  6989. } ";
  6990. let figuresCache = null;
  6991. function initFiguresGL() {
  6992. generateGL();
  6993. const canvas = currentCanvas;
  6994. currentCanvas = null;
  6995. const gl = currentGL;
  6996. currentGL = null;
  6997. const vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  6998. const fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  6999. const program = createProgram(gl, [vertexShader, fragmentShader]);
  7000. gl.useProgram(program);
  7001. const cache = {};
  7002. cache.gl = gl;
  7003. cache.canvas = canvas;
  7004. cache.resolutionLocation = gl.getUniformLocation(program, "u_resolution");
  7005. cache.scaleLocation = gl.getUniformLocation(program, "u_scale");
  7006. cache.offsetLocation = gl.getUniformLocation(program, "u_offset");
  7007. cache.positionLocation = gl.getAttribLocation(program, "a_position");
  7008. cache.colorLocation = gl.getAttribLocation(program, "a_color");
  7009. figuresCache = cache;
  7010. }
  7011. function drawFigures(width, height, backgroundColor, figures, context) {
  7012. if (!figuresCache) {
  7013. initFiguresGL();
  7014. }
  7015. const cache = figuresCache,
  7016. canvas = cache.canvas,
  7017. gl = cache.gl;
  7018. canvas.width = width;
  7019. canvas.height = height;
  7020. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  7021. gl.uniform2f(cache.resolutionLocation, width, height);
  7022. let count = 0;
  7023. for (let i = 0, ii = figures.length; i < ii; i++) {
  7024. switch (figures[i].type) {
  7025. case "lattice":
  7026. const rows = figures[i].coords.length / figures[i].verticesPerRow | 0;
  7027. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  7028. break;
  7029. case "triangles":
  7030. count += figures[i].coords.length;
  7031. break;
  7032. }
  7033. }
  7034. const coords = new Float32Array(count * 2);
  7035. const colors = new Uint8Array(count * 3);
  7036. const coordsMap = context.coords,
  7037. colorsMap = context.colors;
  7038. let pIndex = 0,
  7039. cIndex = 0;
  7040. for (let i = 0, ii = figures.length; i < ii; i++) {
  7041. const figure = figures[i],
  7042. ps = figure.coords,
  7043. cs = figure.colors;
  7044. switch (figure.type) {
  7045. case "lattice":
  7046. const cols = figure.verticesPerRow;
  7047. const rows = ps.length / cols | 0;
  7048. for (let row = 1; row < rows; row++) {
  7049. let offset = row * cols + 1;
  7050. for (let col = 1; col < cols; col++, offset++) {
  7051. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  7052. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  7053. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  7054. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  7055. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  7056. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  7057. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  7058. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  7059. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  7060. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  7061. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  7062. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  7063. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  7064. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  7065. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  7066. coords[pIndex + 6] = coords[pIndex + 2];
  7067. coords[pIndex + 7] = coords[pIndex + 3];
  7068. coords[pIndex + 8] = coords[pIndex + 4];
  7069. coords[pIndex + 9] = coords[pIndex + 5];
  7070. coords[pIndex + 10] = coordsMap[ps[offset]];
  7071. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  7072. colors[cIndex + 9] = colors[cIndex + 3];
  7073. colors[cIndex + 10] = colors[cIndex + 4];
  7074. colors[cIndex + 11] = colors[cIndex + 5];
  7075. colors[cIndex + 12] = colors[cIndex + 6];
  7076. colors[cIndex + 13] = colors[cIndex + 7];
  7077. colors[cIndex + 14] = colors[cIndex + 8];
  7078. colors[cIndex + 15] = colorsMap[cs[offset]];
  7079. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  7080. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  7081. pIndex += 12;
  7082. cIndex += 18;
  7083. }
  7084. }
  7085. break;
  7086. case "triangles":
  7087. for (let j = 0, jj = ps.length; j < jj; j++) {
  7088. coords[pIndex] = coordsMap[ps[j]];
  7089. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  7090. colors[cIndex] = colorsMap[cs[j]];
  7091. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  7092. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  7093. pIndex += 2;
  7094. cIndex += 3;
  7095. }
  7096. break;
  7097. }
  7098. }
  7099. if (backgroundColor) {
  7100. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255, backgroundColor[2] / 255, 1.0);
  7101. } else {
  7102. gl.clearColor(0, 0, 0, 0);
  7103. }
  7104. gl.clear(gl.COLOR_BUFFER_BIT);
  7105. const coordsBuffer = gl.createBuffer();
  7106. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  7107. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  7108. gl.enableVertexAttribArray(cache.positionLocation);
  7109. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  7110. const colorsBuffer = gl.createBuffer();
  7111. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  7112. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  7113. gl.enableVertexAttribArray(cache.colorLocation);
  7114. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false, 0, 0);
  7115. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  7116. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  7117. gl.drawArrays(gl.TRIANGLES, 0, count);
  7118. gl.flush();
  7119. gl.deleteBuffer(coordsBuffer);
  7120. gl.deleteBuffer(colorsBuffer);
  7121. return canvas;
  7122. }
  7123. return {
  7124. tryInitGL() {
  7125. try {
  7126. generateGL();
  7127. return !!currentGL;
  7128. } catch (ex) {}
  7129. return false;
  7130. },
  7131. composeSMask,
  7132. drawFigures,
  7133. cleanup() {
  7134. if (smaskCache?.canvas) {
  7135. smaskCache.canvas.width = 0;
  7136. smaskCache.canvas.height = 0;
  7137. }
  7138. if (figuresCache?.canvas) {
  7139. figuresCache.canvas.width = 0;
  7140. figuresCache.canvas.height = 0;
  7141. }
  7142. smaskCache = null;
  7143. figuresCache = null;
  7144. }
  7145. };
  7146. }();
  7147. /***/ }),
  7148. /* 18 */
  7149. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  7150. Object.defineProperty(exports, "__esModule", ({
  7151. value: true
  7152. }));
  7153. exports.AnnotationLayer = void 0;
  7154. var _display_utils = __w_pdfjs_require__(1);
  7155. var _util = __w_pdfjs_require__(2);
  7156. var _annotation_storage = __w_pdfjs_require__(8);
  7157. var _scripting_utils = __w_pdfjs_require__(19);
  7158. class AnnotationElementFactory {
  7159. static create(parameters) {
  7160. const subtype = parameters.data.annotationType;
  7161. switch (subtype) {
  7162. case _util.AnnotationType.LINK:
  7163. return new LinkAnnotationElement(parameters);
  7164. case _util.AnnotationType.TEXT:
  7165. return new TextAnnotationElement(parameters);
  7166. case _util.AnnotationType.WIDGET:
  7167. const fieldType = parameters.data.fieldType;
  7168. switch (fieldType) {
  7169. case "Tx":
  7170. return new TextWidgetAnnotationElement(parameters);
  7171. case "Btn":
  7172. if (parameters.data.radioButton) {
  7173. return new RadioButtonWidgetAnnotationElement(parameters);
  7174. } else if (parameters.data.checkBox) {
  7175. return new CheckboxWidgetAnnotationElement(parameters);
  7176. }
  7177. return new PushButtonWidgetAnnotationElement(parameters);
  7178. case "Ch":
  7179. return new ChoiceWidgetAnnotationElement(parameters);
  7180. }
  7181. return new WidgetAnnotationElement(parameters);
  7182. case _util.AnnotationType.POPUP:
  7183. return new PopupAnnotationElement(parameters);
  7184. case _util.AnnotationType.FREETEXT:
  7185. return new FreeTextAnnotationElement(parameters);
  7186. case _util.AnnotationType.LINE:
  7187. return new LineAnnotationElement(parameters);
  7188. case _util.AnnotationType.SQUARE:
  7189. return new SquareAnnotationElement(parameters);
  7190. case _util.AnnotationType.CIRCLE:
  7191. return new CircleAnnotationElement(parameters);
  7192. case _util.AnnotationType.POLYLINE:
  7193. return new PolylineAnnotationElement(parameters);
  7194. case _util.AnnotationType.CARET:
  7195. return new CaretAnnotationElement(parameters);
  7196. case _util.AnnotationType.INK:
  7197. return new InkAnnotationElement(parameters);
  7198. case _util.AnnotationType.POLYGON:
  7199. return new PolygonAnnotationElement(parameters);
  7200. case _util.AnnotationType.HIGHLIGHT:
  7201. return new HighlightAnnotationElement(parameters);
  7202. case _util.AnnotationType.UNDERLINE:
  7203. return new UnderlineAnnotationElement(parameters);
  7204. case _util.AnnotationType.SQUIGGLY:
  7205. return new SquigglyAnnotationElement(parameters);
  7206. case _util.AnnotationType.STRIKEOUT:
  7207. return new StrikeOutAnnotationElement(parameters);
  7208. case _util.AnnotationType.STAMP:
  7209. return new StampAnnotationElement(parameters);
  7210. case _util.AnnotationType.FILEATTACHMENT:
  7211. return new FileAttachmentAnnotationElement(parameters);
  7212. default:
  7213. return new AnnotationElement(parameters);
  7214. }
  7215. }
  7216. }
  7217. class AnnotationElement {
  7218. constructor(parameters, {
  7219. isRenderable = false,
  7220. ignoreBorder = false,
  7221. createQuadrilaterals = false
  7222. } = {}) {
  7223. this.isRenderable = isRenderable;
  7224. this.data = parameters.data;
  7225. this.layer = parameters.layer;
  7226. this.page = parameters.page;
  7227. this.viewport = parameters.viewport;
  7228. this.linkService = parameters.linkService;
  7229. this.downloadManager = parameters.downloadManager;
  7230. this.imageResourcesPath = parameters.imageResourcesPath;
  7231. this.renderInteractiveForms = parameters.renderInteractiveForms;
  7232. this.svgFactory = parameters.svgFactory;
  7233. this.annotationStorage = parameters.annotationStorage;
  7234. this.enableScripting = parameters.enableScripting;
  7235. this.hasJSActions = parameters.hasJSActions;
  7236. this._mouseState = parameters.mouseState;
  7237. if (isRenderable) {
  7238. this.container = this._createContainer(ignoreBorder);
  7239. }
  7240. if (createQuadrilaterals) {
  7241. this.quadrilaterals = this._createQuadrilaterals(ignoreBorder);
  7242. }
  7243. }
  7244. _createContainer(ignoreBorder = false) {
  7245. const data = this.data,
  7246. page = this.page,
  7247. viewport = this.viewport;
  7248. const container = document.createElement("section");
  7249. let width = data.rect[2] - data.rect[0];
  7250. let height = data.rect[3] - data.rect[1];
  7251. container.setAttribute("data-annotation-id", data.id);
  7252. const rect = _util.Util.normalizeRect([data.rect[0], page.view[3] - data.rect[1] + page.view[1], data.rect[2], page.view[3] - data.rect[3] + page.view[1]]);
  7253. container.style.transform = `matrix(${viewport.transform.join(",")})`;
  7254. container.style.transformOrigin = `${-rect[0]}px ${-rect[1]}px`;
  7255. if (!ignoreBorder && data.borderStyle.width > 0) {
  7256. container.style.borderWidth = `${data.borderStyle.width}px`;
  7257. if (data.borderStyle.style !== _util.AnnotationBorderStyleType.UNDERLINE) {
  7258. width = width - 2 * data.borderStyle.width;
  7259. height = height - 2 * data.borderStyle.width;
  7260. }
  7261. const horizontalRadius = data.borderStyle.horizontalCornerRadius;
  7262. const verticalRadius = data.borderStyle.verticalCornerRadius;
  7263. if (horizontalRadius > 0 || verticalRadius > 0) {
  7264. const radius = `${horizontalRadius}px / ${verticalRadius}px`;
  7265. container.style.borderRadius = radius;
  7266. }
  7267. switch (data.borderStyle.style) {
  7268. case _util.AnnotationBorderStyleType.SOLID:
  7269. container.style.borderStyle = "solid";
  7270. break;
  7271. case _util.AnnotationBorderStyleType.DASHED:
  7272. container.style.borderStyle = "dashed";
  7273. break;
  7274. case _util.AnnotationBorderStyleType.BEVELED:
  7275. (0, _util.warn)("Unimplemented border style: beveled");
  7276. break;
  7277. case _util.AnnotationBorderStyleType.INSET:
  7278. (0, _util.warn)("Unimplemented border style: inset");
  7279. break;
  7280. case _util.AnnotationBorderStyleType.UNDERLINE:
  7281. container.style.borderBottomStyle = "solid";
  7282. break;
  7283. default:
  7284. break;
  7285. }
  7286. if (data.color) {
  7287. container.style.borderColor = _util.Util.makeHexColor(data.color[0] | 0, data.color[1] | 0, data.color[2] | 0);
  7288. } else {
  7289. container.style.borderWidth = 0;
  7290. }
  7291. }
  7292. container.style.left = `${rect[0]}px`;
  7293. container.style.top = `${rect[1]}px`;
  7294. container.style.width = `${width}px`;
  7295. container.style.height = `${height}px`;
  7296. return container;
  7297. }
  7298. _createQuadrilaterals(ignoreBorder = false) {
  7299. if (!this.data.quadPoints) {
  7300. return null;
  7301. }
  7302. const quadrilaterals = [];
  7303. const savedRect = this.data.rect;
  7304. for (const quadPoint of this.data.quadPoints) {
  7305. this.data.rect = [quadPoint[2].x, quadPoint[2].y, quadPoint[1].x, quadPoint[1].y];
  7306. quadrilaterals.push(this._createContainer(ignoreBorder));
  7307. }
  7308. this.data.rect = savedRect;
  7309. return quadrilaterals;
  7310. }
  7311. _createPopup(trigger, data) {
  7312. let container = this.container;
  7313. if (this.quadrilaterals) {
  7314. trigger = trigger || this.quadrilaterals;
  7315. container = this.quadrilaterals[0];
  7316. }
  7317. if (!trigger) {
  7318. trigger = document.createElement("div");
  7319. trigger.style.height = container.style.height;
  7320. trigger.style.width = container.style.width;
  7321. container.appendChild(trigger);
  7322. }
  7323. const popupElement = new PopupElement({
  7324. container,
  7325. trigger,
  7326. color: data.color,
  7327. title: data.title,
  7328. modificationDate: data.modificationDate,
  7329. contents: data.contents,
  7330. hideWrapper: true
  7331. });
  7332. const popup = popupElement.render();
  7333. popup.style.left = container.style.width;
  7334. container.appendChild(popup);
  7335. }
  7336. _renderQuadrilaterals(className) {
  7337. this.quadrilaterals.forEach(quadrilateral => {
  7338. quadrilateral.className = className;
  7339. });
  7340. return this.quadrilaterals;
  7341. }
  7342. render() {
  7343. (0, _util.unreachable)("Abstract method `AnnotationElement.render` called");
  7344. }
  7345. }
  7346. class LinkAnnotationElement extends AnnotationElement {
  7347. constructor(parameters) {
  7348. const isRenderable = !!(parameters.data.url || parameters.data.dest || parameters.data.action || parameters.data.isTooltipOnly || parameters.data.actions && (parameters.data.actions.Action || parameters.data.actions["Mouse Up"] || parameters.data.actions["Mouse Down"]));
  7349. super(parameters, {
  7350. isRenderable,
  7351. createQuadrilaterals: true
  7352. });
  7353. }
  7354. render() {
  7355. const {
  7356. data,
  7357. linkService
  7358. } = this;
  7359. const link = document.createElement("a");
  7360. if (data.url) {
  7361. (0, _display_utils.addLinkAttributes)(link, {
  7362. url: data.url,
  7363. target: data.newWindow ? _display_utils.LinkTarget.BLANK : linkService.externalLinkTarget,
  7364. rel: linkService.externalLinkRel,
  7365. enabled: linkService.externalLinkEnabled
  7366. });
  7367. } else if (data.action) {
  7368. this._bindNamedAction(link, data.action);
  7369. } else if (data.dest) {
  7370. this._bindLink(link, data.dest);
  7371. } else if (data.actions && (data.actions.Action || data.actions["Mouse Up"] || data.actions["Mouse Down"]) && this.enableScripting && this.hasJSActions) {
  7372. this._bindJSAction(link, data);
  7373. } else {
  7374. this._bindLink(link, "");
  7375. }
  7376. if (this.quadrilaterals) {
  7377. return this._renderQuadrilaterals("linkAnnotation").map((quadrilateral, index) => {
  7378. const linkElement = index === 0 ? link : link.cloneNode();
  7379. quadrilateral.appendChild(linkElement);
  7380. return quadrilateral;
  7381. });
  7382. }
  7383. this.container.className = "linkAnnotation";
  7384. this.container.appendChild(link);
  7385. return this.container;
  7386. }
  7387. _bindLink(link, destination) {
  7388. link.href = this.linkService.getDestinationHash(destination);
  7389. link.onclick = () => {
  7390. if (destination) {
  7391. this.linkService.goToDestination(destination);
  7392. }
  7393. return false;
  7394. };
  7395. if (destination || destination === "") {
  7396. link.className = "internalLink";
  7397. }
  7398. }
  7399. _bindNamedAction(link, action) {
  7400. link.href = this.linkService.getAnchorUrl("");
  7401. link.onclick = () => {
  7402. this.linkService.executeNamedAction(action);
  7403. return false;
  7404. };
  7405. link.className = "internalLink";
  7406. }
  7407. _bindJSAction(link, data) {
  7408. link.href = this.linkService.getAnchorUrl("");
  7409. const map = new Map([["Action", "onclick"], ["Mouse Up", "onmouseup"], ["Mouse Down", "onmousedown"]]);
  7410. for (const name of Object.keys(data.actions)) {
  7411. const jsName = map.get(name);
  7412. if (!jsName) {
  7413. continue;
  7414. }
  7415. link[jsName] = () => {
  7416. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  7417. source: this,
  7418. detail: {
  7419. id: data.id,
  7420. name
  7421. }
  7422. });
  7423. return false;
  7424. };
  7425. }
  7426. link.className = "internalLink";
  7427. }
  7428. }
  7429. class TextAnnotationElement extends AnnotationElement {
  7430. constructor(parameters) {
  7431. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  7432. super(parameters, {
  7433. isRenderable
  7434. });
  7435. }
  7436. render() {
  7437. this.container.className = "textAnnotation";
  7438. const image = document.createElement("img");
  7439. image.style.height = this.container.style.height;
  7440. image.style.width = this.container.style.width;
  7441. image.src = this.imageResourcesPath + "annotation-" + this.data.name.toLowerCase() + ".svg";
  7442. image.alt = "[{{type}} Annotation]";
  7443. image.dataset.l10nId = "text_annotation_type";
  7444. image.dataset.l10nArgs = JSON.stringify({
  7445. type: this.data.name
  7446. });
  7447. if (!this.data.hasPopup) {
  7448. this._createPopup(image, this.data);
  7449. }
  7450. this.container.appendChild(image);
  7451. return this.container;
  7452. }
  7453. }
  7454. class WidgetAnnotationElement extends AnnotationElement {
  7455. render() {
  7456. if (this.data.alternativeText) {
  7457. this.container.title = this.data.alternativeText;
  7458. }
  7459. return this.container;
  7460. }
  7461. _getKeyModifier(event) {
  7462. return navigator.platform.includes("Win") && event.ctrlKey || navigator.platform.includes("Mac") && event.metaKey;
  7463. }
  7464. _setEventListener(element, baseName, eventName, valueGetter) {
  7465. if (baseName.includes("mouse")) {
  7466. element.addEventListener(baseName, event => {
  7467. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  7468. source: this,
  7469. detail: {
  7470. id: this.data.id,
  7471. name: eventName,
  7472. value: valueGetter(event),
  7473. shift: event.shiftKey,
  7474. modifier: this._getKeyModifier(event)
  7475. }
  7476. });
  7477. });
  7478. } else {
  7479. element.addEventListener(baseName, event => {
  7480. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  7481. source: this,
  7482. detail: {
  7483. id: this.data.id,
  7484. name: eventName,
  7485. value: event.target.checked
  7486. }
  7487. });
  7488. });
  7489. }
  7490. }
  7491. _setEventListeners(element, names, getter) {
  7492. for (const [baseName, eventName] of names) {
  7493. if (eventName === "Action" || this.data.actions?.[eventName]) {
  7494. this._setEventListener(element, baseName, eventName, getter);
  7495. }
  7496. }
  7497. }
  7498. _setColor(event) {
  7499. const {
  7500. detail,
  7501. target
  7502. } = event;
  7503. const {
  7504. style
  7505. } = target;
  7506. for (const name of ["bgColor", "fillColor", "fgColor", "textColor", "borderColor", "strokeColor"]) {
  7507. let color = detail[name];
  7508. if (!color) {
  7509. continue;
  7510. }
  7511. color = _scripting_utils.ColorConverters[`${color[0]}_HTML`](color.slice(1));
  7512. switch (name) {
  7513. case "bgColor":
  7514. case "fillColor":
  7515. style.backgroundColor = color;
  7516. break;
  7517. case "fgColor":
  7518. case "textColor":
  7519. style.color = color;
  7520. break;
  7521. case "borderColor":
  7522. case "strokeColor":
  7523. style.borderColor = color;
  7524. break;
  7525. }
  7526. }
  7527. }
  7528. }
  7529. class TextWidgetAnnotationElement extends WidgetAnnotationElement {
  7530. constructor(parameters) {
  7531. const isRenderable = parameters.renderInteractiveForms || !parameters.data.hasAppearance && !!parameters.data.fieldValue;
  7532. super(parameters, {
  7533. isRenderable
  7534. });
  7535. }
  7536. render() {
  7537. const storage = this.annotationStorage;
  7538. const id = this.data.id;
  7539. this.container.className = "textWidgetAnnotation";
  7540. let element = null;
  7541. if (this.renderInteractiveForms) {
  7542. const storedData = storage.getValue(id, {
  7543. value: this.data.fieldValue,
  7544. valueAsString: this.data.fieldValue
  7545. });
  7546. const textContent = storedData.valueAsString || storedData.value || "";
  7547. const elementData = {
  7548. userValue: null,
  7549. formattedValue: null,
  7550. beforeInputSelectionRange: null,
  7551. beforeInputValue: null
  7552. };
  7553. if (this.data.multiLine) {
  7554. element = document.createElement("textarea");
  7555. element.textContent = textContent;
  7556. } else {
  7557. element = document.createElement("input");
  7558. element.type = "text";
  7559. element.setAttribute("value", textContent);
  7560. }
  7561. elementData.userValue = textContent;
  7562. element.setAttribute("id", id);
  7563. element.addEventListener("input", function (event) {
  7564. storage.setValue(id, {
  7565. value: event.target.value
  7566. });
  7567. });
  7568. let blurListener = event => {
  7569. if (elementData.formattedValue) {
  7570. event.target.value = elementData.formattedValue;
  7571. }
  7572. event.target.setSelectionRange(0, 0);
  7573. elementData.beforeInputSelectionRange = null;
  7574. };
  7575. if (this.enableScripting && this.hasJSActions) {
  7576. element.addEventListener("focus", event => {
  7577. if (elementData.userValue) {
  7578. event.target.value = elementData.userValue;
  7579. }
  7580. });
  7581. element.addEventListener("updatefromsandbox", event => {
  7582. const {
  7583. detail
  7584. } = event;
  7585. const actions = {
  7586. value() {
  7587. elementData.userValue = detail.value || "";
  7588. storage.setValue(id, {
  7589. value: elementData.userValue.toString()
  7590. });
  7591. if (!elementData.formattedValue) {
  7592. event.target.value = elementData.userValue;
  7593. }
  7594. },
  7595. valueAsString() {
  7596. elementData.formattedValue = detail.valueAsString || "";
  7597. if (event.target !== document.activeElement) {
  7598. event.target.value = elementData.formattedValue;
  7599. }
  7600. storage.setValue(id, {
  7601. formattedValue: elementData.formattedValue
  7602. });
  7603. },
  7604. focus() {
  7605. setTimeout(() => event.target.focus({
  7606. preventScroll: false
  7607. }), 0);
  7608. },
  7609. userName() {
  7610. event.target.title = detail.userName;
  7611. },
  7612. hidden() {
  7613. event.target.style.visibility = detail.hidden ? "hidden" : "visible";
  7614. storage.setValue(id, {
  7615. hidden: detail.hidden
  7616. });
  7617. },
  7618. editable() {
  7619. event.target.disabled = !detail.editable;
  7620. },
  7621. selRange() {
  7622. const [selStart, selEnd] = detail.selRange;
  7623. if (selStart >= 0 && selEnd < event.target.value.length) {
  7624. event.target.setSelectionRange(selStart, selEnd);
  7625. }
  7626. }
  7627. };
  7628. Object.keys(detail).filter(name => name in actions).forEach(name => actions[name]());
  7629. this._setColor(event);
  7630. });
  7631. element.addEventListener("keydown", event => {
  7632. elementData.beforeInputValue = event.target.value;
  7633. let commitKey = -1;
  7634. if (event.key === "Escape") {
  7635. commitKey = 0;
  7636. } else if (event.key === "Enter") {
  7637. commitKey = 2;
  7638. } else if (event.key === "Tab") {
  7639. commitKey = 3;
  7640. }
  7641. if (commitKey === -1) {
  7642. return;
  7643. }
  7644. elementData.userValue = event.target.value;
  7645. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  7646. source: this,
  7647. detail: {
  7648. id,
  7649. name: "Keystroke",
  7650. value: event.target.value,
  7651. willCommit: true,
  7652. commitKey,
  7653. selStart: event.target.selectionStart,
  7654. selEnd: event.target.selectionEnd
  7655. }
  7656. });
  7657. });
  7658. const _blurListener = blurListener;
  7659. blurListener = null;
  7660. element.addEventListener("blur", event => {
  7661. if (this._mouseState.isDown) {
  7662. elementData.userValue = event.target.value;
  7663. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  7664. source: this,
  7665. detail: {
  7666. id,
  7667. name: "Keystroke",
  7668. value: event.target.value,
  7669. willCommit: true,
  7670. commitKey: 1,
  7671. selStart: event.target.selectionStart,
  7672. selEnd: event.target.selectionEnd
  7673. }
  7674. });
  7675. }
  7676. _blurListener(event);
  7677. });
  7678. element.addEventListener("mousedown", event => {
  7679. elementData.beforeInputValue = event.target.value;
  7680. elementData.beforeInputSelectionRange = null;
  7681. });
  7682. element.addEventListener("keyup", event => {
  7683. if (event.target.selectionStart === event.target.selectionEnd) {
  7684. elementData.beforeInputSelectionRange = null;
  7685. }
  7686. });
  7687. element.addEventListener("select", event => {
  7688. elementData.beforeInputSelectionRange = [event.target.selectionStart, event.target.selectionEnd];
  7689. });
  7690. if (this.data.actions?.Keystroke) {
  7691. element.addEventListener("input", event => {
  7692. let selStart = -1;
  7693. let selEnd = -1;
  7694. if (elementData.beforeInputSelectionRange) {
  7695. [selStart, selEnd] = elementData.beforeInputSelectionRange;
  7696. }
  7697. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  7698. source: this,
  7699. detail: {
  7700. id,
  7701. name: "Keystroke",
  7702. value: elementData.beforeInputValue,
  7703. change: event.data,
  7704. willCommit: false,
  7705. selStart,
  7706. selEnd
  7707. }
  7708. });
  7709. });
  7710. }
  7711. this._setEventListeners(element, [["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"]], event => event.target.value);
  7712. }
  7713. if (blurListener) {
  7714. element.addEventListener("blur", blurListener);
  7715. }
  7716. element.disabled = this.data.readOnly;
  7717. element.name = this.data.fieldName;
  7718. if (this.data.maxLen !== null) {
  7719. element.maxLength = this.data.maxLen;
  7720. }
  7721. if (this.data.comb) {
  7722. const fieldWidth = this.data.rect[2] - this.data.rect[0];
  7723. const combWidth = fieldWidth / this.data.maxLen;
  7724. element.classList.add("comb");
  7725. element.style.letterSpacing = `calc(${combWidth}px - 1ch)`;
  7726. }
  7727. } else {
  7728. element = document.createElement("div");
  7729. element.textContent = this.data.fieldValue;
  7730. element.style.verticalAlign = "middle";
  7731. element.style.display = "table-cell";
  7732. }
  7733. this._setTextStyle(element);
  7734. this.container.appendChild(element);
  7735. return this.container;
  7736. }
  7737. _setTextStyle(element) {
  7738. const TEXT_ALIGNMENT = ["left", "center", "right"];
  7739. const {
  7740. fontSize,
  7741. fontColor
  7742. } = this.data.defaultAppearanceData;
  7743. const style = element.style;
  7744. if (fontSize) {
  7745. style.fontSize = `${fontSize}px`;
  7746. }
  7747. style.color = _util.Util.makeHexColor(fontColor[0], fontColor[1], fontColor[2]);
  7748. if (this.data.textAlignment !== null) {
  7749. style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
  7750. }
  7751. }
  7752. }
  7753. class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement {
  7754. constructor(parameters) {
  7755. super(parameters, {
  7756. isRenderable: parameters.renderInteractiveForms
  7757. });
  7758. }
  7759. render() {
  7760. const storage = this.annotationStorage;
  7761. const data = this.data;
  7762. const id = data.id;
  7763. const value = storage.getValue(id, {
  7764. value: data.fieldValue && (data.exportValue && data.exportValue === data.fieldValue || !data.exportValue && data.fieldValue !== "Off")
  7765. }).value;
  7766. this.container.className = "buttonWidgetAnnotation checkBox";
  7767. const element = document.createElement("input");
  7768. element.disabled = data.readOnly;
  7769. element.type = "checkbox";
  7770. element.name = this.data.fieldName;
  7771. if (value) {
  7772. element.setAttribute("checked", true);
  7773. }
  7774. element.setAttribute("id", id);
  7775. element.addEventListener("change", function (event) {
  7776. const name = event.target.name;
  7777. for (const checkbox of document.getElementsByName(name)) {
  7778. if (checkbox !== event.target) {
  7779. checkbox.checked = false;
  7780. storage.setValue(checkbox.parentNode.getAttribute("data-annotation-id"), {
  7781. value: false
  7782. });
  7783. }
  7784. }
  7785. storage.setValue(id, {
  7786. value: event.target.checked
  7787. });
  7788. });
  7789. if (this.enableScripting && this.hasJSActions) {
  7790. element.addEventListener("updatefromsandbox", event => {
  7791. const {
  7792. detail
  7793. } = event;
  7794. const actions = {
  7795. value() {
  7796. event.target.checked = detail.value !== "Off";
  7797. storage.setValue(id, {
  7798. value: event.target.checked
  7799. });
  7800. },
  7801. focus() {
  7802. setTimeout(() => event.target.focus({
  7803. preventScroll: false
  7804. }), 0);
  7805. },
  7806. hidden() {
  7807. event.target.style.visibility = detail.hidden ? "hidden" : "visible";
  7808. storage.setValue(id, {
  7809. hidden: detail.hidden
  7810. });
  7811. },
  7812. editable() {
  7813. event.target.disabled = !detail.editable;
  7814. }
  7815. };
  7816. Object.keys(detail).filter(name => name in actions).forEach(name => actions[name]());
  7817. this._setColor(event);
  7818. });
  7819. this._setEventListeners(element, [["change", "Validate"], ["change", "Action"], ["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"]], event => event.target.checked);
  7820. }
  7821. this.container.appendChild(element);
  7822. return this.container;
  7823. }
  7824. }
  7825. class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
  7826. constructor(parameters) {
  7827. super(parameters, {
  7828. isRenderable: parameters.renderInteractiveForms
  7829. });
  7830. }
  7831. render() {
  7832. this.container.className = "buttonWidgetAnnotation radioButton";
  7833. const storage = this.annotationStorage;
  7834. const data = this.data;
  7835. const id = data.id;
  7836. const value = storage.getValue(id, {
  7837. value: data.fieldValue === data.buttonValue
  7838. }).value;
  7839. const element = document.createElement("input");
  7840. element.disabled = data.readOnly;
  7841. element.type = "radio";
  7842. element.name = data.fieldName;
  7843. if (value) {
  7844. element.setAttribute("checked", true);
  7845. }
  7846. element.setAttribute("id", id);
  7847. element.addEventListener("change", function (event) {
  7848. const {
  7849. target
  7850. } = event;
  7851. for (const radio of document.getElementsByName(target.name)) {
  7852. if (radio !== target) {
  7853. storage.setValue(radio.getAttribute("id"), {
  7854. value: false
  7855. });
  7856. }
  7857. }
  7858. storage.setValue(id, {
  7859. value: target.checked
  7860. });
  7861. });
  7862. if (this.enableScripting && this.hasJSActions) {
  7863. const pdfButtonValue = data.buttonValue;
  7864. element.addEventListener("updatefromsandbox", event => {
  7865. const {
  7866. detail
  7867. } = event;
  7868. const actions = {
  7869. value() {
  7870. const checked = pdfButtonValue === detail.value;
  7871. for (const radio of document.getElementsByName(event.target.name)) {
  7872. const radioId = radio.getAttribute("id");
  7873. radio.checked = radioId === id && checked;
  7874. storage.setValue(radioId, {
  7875. value: radio.checked
  7876. });
  7877. }
  7878. },
  7879. focus() {
  7880. setTimeout(() => event.target.focus({
  7881. preventScroll: false
  7882. }), 0);
  7883. },
  7884. hidden() {
  7885. event.target.style.visibility = detail.hidden ? "hidden" : "visible";
  7886. storage.setValue(id, {
  7887. hidden: detail.hidden
  7888. });
  7889. },
  7890. editable() {
  7891. event.target.disabled = !detail.editable;
  7892. }
  7893. };
  7894. Object.keys(detail).filter(name => name in actions).forEach(name => actions[name]());
  7895. this._setColor(event);
  7896. });
  7897. this._setEventListeners(element, [["change", "Validate"], ["change", "Action"], ["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"]], event => event.target.checked);
  7898. }
  7899. this.container.appendChild(element);
  7900. return this.container;
  7901. }
  7902. }
  7903. class PushButtonWidgetAnnotationElement extends LinkAnnotationElement {
  7904. render() {
  7905. const container = super.render();
  7906. container.className = "buttonWidgetAnnotation pushButton";
  7907. if (this.data.alternativeText) {
  7908. container.title = this.data.alternativeText;
  7909. }
  7910. return container;
  7911. }
  7912. }
  7913. class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
  7914. constructor(parameters) {
  7915. super(parameters, {
  7916. isRenderable: parameters.renderInteractiveForms
  7917. });
  7918. }
  7919. render() {
  7920. this.container.className = "choiceWidgetAnnotation";
  7921. const storage = this.annotationStorage;
  7922. const id = this.data.id;
  7923. storage.getValue(id, {
  7924. value: this.data.fieldValue.length > 0 ? this.data.fieldValue[0] : undefined
  7925. });
  7926. const selectElement = document.createElement("select");
  7927. selectElement.disabled = this.data.readOnly;
  7928. selectElement.name = this.data.fieldName;
  7929. selectElement.setAttribute("id", id);
  7930. if (!this.data.combo) {
  7931. selectElement.size = this.data.options.length;
  7932. if (this.data.multiSelect) {
  7933. selectElement.multiple = true;
  7934. }
  7935. }
  7936. for (const option of this.data.options) {
  7937. const optionElement = document.createElement("option");
  7938. optionElement.textContent = option.displayValue;
  7939. optionElement.value = option.exportValue;
  7940. if (this.data.fieldValue.includes(option.exportValue)) {
  7941. optionElement.setAttribute("selected", true);
  7942. }
  7943. selectElement.appendChild(optionElement);
  7944. }
  7945. const getValue = (event, isExport) => {
  7946. const name = isExport ? "value" : "textContent";
  7947. const options = event.target.options;
  7948. if (!event.target.multiple) {
  7949. return options.selectedIndex === -1 ? null : options[options.selectedIndex][name];
  7950. }
  7951. return Array.prototype.filter.call(options, option => option.selected).map(option => option[name]);
  7952. };
  7953. const getItems = event => {
  7954. const options = event.target.options;
  7955. return Array.prototype.map.call(options, option => {
  7956. return {
  7957. displayValue: option.textContent,
  7958. exportValue: option.value
  7959. };
  7960. });
  7961. };
  7962. if (this.enableScripting && this.hasJSActions) {
  7963. selectElement.addEventListener("updatefromsandbox", event => {
  7964. const {
  7965. detail
  7966. } = event;
  7967. const actions = {
  7968. value() {
  7969. const options = selectElement.options;
  7970. const value = detail.value;
  7971. const values = new Set(Array.isArray(value) ? value : [value]);
  7972. Array.prototype.forEach.call(options, option => {
  7973. option.selected = values.has(option.value);
  7974. });
  7975. storage.setValue(id, {
  7976. value: getValue(event, true)
  7977. });
  7978. },
  7979. multipleSelection() {
  7980. selectElement.multiple = true;
  7981. },
  7982. remove() {
  7983. const options = selectElement.options;
  7984. const index = detail.remove;
  7985. options[index].selected = false;
  7986. selectElement.remove(index);
  7987. if (options.length > 0) {
  7988. const i = Array.prototype.findIndex.call(options, option => option.selected);
  7989. if (i === -1) {
  7990. options[0].selected = true;
  7991. }
  7992. }
  7993. storage.setValue(id, {
  7994. value: getValue(event, true),
  7995. items: getItems(event)
  7996. });
  7997. },
  7998. clear() {
  7999. while (selectElement.length !== 0) {
  8000. selectElement.remove(0);
  8001. }
  8002. storage.setValue(id, {
  8003. value: null,
  8004. items: []
  8005. });
  8006. },
  8007. insert() {
  8008. const {
  8009. index,
  8010. displayValue,
  8011. exportValue
  8012. } = detail.insert;
  8013. const optionElement = document.createElement("option");
  8014. optionElement.textContent = displayValue;
  8015. optionElement.value = exportValue;
  8016. selectElement.insertBefore(optionElement, selectElement.children[index]);
  8017. storage.setValue(id, {
  8018. value: getValue(event, true),
  8019. items: getItems(event)
  8020. });
  8021. },
  8022. items() {
  8023. const {
  8024. items
  8025. } = detail;
  8026. while (selectElement.length !== 0) {
  8027. selectElement.remove(0);
  8028. }
  8029. for (const item of items) {
  8030. const {
  8031. displayValue,
  8032. exportValue
  8033. } = item;
  8034. const optionElement = document.createElement("option");
  8035. optionElement.textContent = displayValue;
  8036. optionElement.value = exportValue;
  8037. selectElement.appendChild(optionElement);
  8038. }
  8039. if (selectElement.options.length > 0) {
  8040. selectElement.options[0].selected = true;
  8041. }
  8042. storage.setValue(id, {
  8043. value: getValue(event, true),
  8044. items: getItems(event)
  8045. });
  8046. },
  8047. indices() {
  8048. const indices = new Set(detail.indices);
  8049. const options = event.target.options;
  8050. Array.prototype.forEach.call(options, (option, i) => {
  8051. option.selected = indices.has(i);
  8052. });
  8053. storage.setValue(id, {
  8054. value: getValue(event, true)
  8055. });
  8056. },
  8057. focus() {
  8058. setTimeout(() => event.target.focus({
  8059. preventScroll: false
  8060. }), 0);
  8061. },
  8062. hidden() {
  8063. event.target.style.visibility = detail.hidden ? "hidden" : "visible";
  8064. storage.setValue(id, {
  8065. hidden: detail.hidden
  8066. });
  8067. },
  8068. editable() {
  8069. event.target.disabled = !detail.editable;
  8070. }
  8071. };
  8072. Object.keys(detail).filter(name => name in actions).forEach(name => actions[name]());
  8073. this._setColor(event);
  8074. });
  8075. selectElement.addEventListener("input", event => {
  8076. const exportValue = getValue(event, true);
  8077. const value = getValue(event, false);
  8078. storage.setValue(id, {
  8079. value: exportValue
  8080. });
  8081. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  8082. source: this,
  8083. detail: {
  8084. id,
  8085. name: "Keystroke",
  8086. value,
  8087. changeEx: exportValue,
  8088. willCommit: true,
  8089. commitKey: 1,
  8090. keyDown: false
  8091. }
  8092. });
  8093. });
  8094. this._setEventListeners(selectElement, [["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"], ["input", "Action"]], event => event.target.checked);
  8095. } else {
  8096. selectElement.addEventListener("input", function (event) {
  8097. storage.setValue(id, {
  8098. value: getValue(event)
  8099. });
  8100. });
  8101. }
  8102. this.container.appendChild(selectElement);
  8103. return this.container;
  8104. }
  8105. }
  8106. class PopupAnnotationElement extends AnnotationElement {
  8107. constructor(parameters) {
  8108. const isRenderable = !!(parameters.data.title || parameters.data.contents);
  8109. super(parameters, {
  8110. isRenderable
  8111. });
  8112. }
  8113. render() {
  8114. const IGNORE_TYPES = ["Line", "Square", "Circle", "PolyLine", "Polygon", "Ink"];
  8115. this.container.className = "popupAnnotation";
  8116. if (IGNORE_TYPES.includes(this.data.parentType)) {
  8117. return this.container;
  8118. }
  8119. const selector = `[data-annotation-id="${this.data.parentId}"]`;
  8120. const parentElements = this.layer.querySelectorAll(selector);
  8121. if (parentElements.length === 0) {
  8122. return this.container;
  8123. }
  8124. const popup = new PopupElement({
  8125. container: this.container,
  8126. trigger: Array.from(parentElements),
  8127. color: this.data.color,
  8128. title: this.data.title,
  8129. modificationDate: this.data.modificationDate,
  8130. contents: this.data.contents
  8131. });
  8132. const page = this.page;
  8133. const rect = _util.Util.normalizeRect([this.data.parentRect[0], page.view[3] - this.data.parentRect[1] + page.view[1], this.data.parentRect[2], page.view[3] - this.data.parentRect[3] + page.view[1]]);
  8134. const popupLeft = rect[0] + this.data.parentRect[2] - this.data.parentRect[0];
  8135. const popupTop = rect[1];
  8136. this.container.style.transformOrigin = `${-popupLeft}px ${-popupTop}px`;
  8137. this.container.style.left = `${popupLeft}px`;
  8138. this.container.style.top = `${popupTop}px`;
  8139. this.container.appendChild(popup.render());
  8140. return this.container;
  8141. }
  8142. }
  8143. class PopupElement {
  8144. constructor(parameters) {
  8145. this.container = parameters.container;
  8146. this.trigger = parameters.trigger;
  8147. this.color = parameters.color;
  8148. this.title = parameters.title;
  8149. this.modificationDate = parameters.modificationDate;
  8150. this.contents = parameters.contents;
  8151. this.hideWrapper = parameters.hideWrapper || false;
  8152. this.pinned = false;
  8153. }
  8154. render() {
  8155. const BACKGROUND_ENLIGHT = 0.7;
  8156. const wrapper = document.createElement("div");
  8157. wrapper.className = "popupWrapper";
  8158. this.hideElement = this.hideWrapper ? wrapper : this.container;
  8159. this.hideElement.hidden = true;
  8160. const popup = document.createElement("div");
  8161. popup.className = "popup";
  8162. const color = this.color;
  8163. if (color) {
  8164. const r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  8165. const g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  8166. const b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  8167. popup.style.backgroundColor = _util.Util.makeHexColor(r | 0, g | 0, b | 0);
  8168. }
  8169. const title = document.createElement("h1");
  8170. title.textContent = this.title;
  8171. popup.appendChild(title);
  8172. const dateObject = _display_utils.PDFDateString.toDateObject(this.modificationDate);
  8173. if (dateObject) {
  8174. const modificationDate = document.createElement("span");
  8175. modificationDate.textContent = "{{date}}, {{time}}";
  8176. modificationDate.dataset.l10nId = "annotation_date_string";
  8177. modificationDate.dataset.l10nArgs = JSON.stringify({
  8178. date: dateObject.toLocaleDateString(),
  8179. time: dateObject.toLocaleTimeString()
  8180. });
  8181. popup.appendChild(modificationDate);
  8182. }
  8183. const contents = this._formatContents(this.contents);
  8184. popup.appendChild(contents);
  8185. if (!Array.isArray(this.trigger)) {
  8186. this.trigger = [this.trigger];
  8187. }
  8188. this.trigger.forEach(element => {
  8189. element.addEventListener("click", this._toggle.bind(this));
  8190. element.addEventListener("mouseover", this._show.bind(this, false));
  8191. element.addEventListener("mouseout", this._hide.bind(this, false));
  8192. });
  8193. popup.addEventListener("click", this._hide.bind(this, true));
  8194. wrapper.appendChild(popup);
  8195. return wrapper;
  8196. }
  8197. _formatContents(contents) {
  8198. const p = document.createElement("p");
  8199. const lines = contents.split(/(?:\r\n?|\n)/);
  8200. for (let i = 0, ii = lines.length; i < ii; ++i) {
  8201. const line = lines[i];
  8202. p.appendChild(document.createTextNode(line));
  8203. if (i < ii - 1) {
  8204. p.appendChild(document.createElement("br"));
  8205. }
  8206. }
  8207. return p;
  8208. }
  8209. _toggle() {
  8210. if (this.pinned) {
  8211. this._hide(true);
  8212. } else {
  8213. this._show(true);
  8214. }
  8215. }
  8216. _show(pin = false) {
  8217. if (pin) {
  8218. this.pinned = true;
  8219. }
  8220. if (this.hideElement.hidden) {
  8221. this.hideElement.hidden = false;
  8222. this.container.style.zIndex += 1;
  8223. }
  8224. }
  8225. _hide(unpin = true) {
  8226. if (unpin) {
  8227. this.pinned = false;
  8228. }
  8229. if (!this.hideElement.hidden && !this.pinned) {
  8230. this.hideElement.hidden = true;
  8231. this.container.style.zIndex -= 1;
  8232. }
  8233. }
  8234. }
  8235. class FreeTextAnnotationElement extends AnnotationElement {
  8236. constructor(parameters) {
  8237. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8238. super(parameters, {
  8239. isRenderable,
  8240. ignoreBorder: true
  8241. });
  8242. }
  8243. render() {
  8244. this.container.className = "freeTextAnnotation";
  8245. if (!this.data.hasPopup) {
  8246. this._createPopup(null, this.data);
  8247. }
  8248. return this.container;
  8249. }
  8250. }
  8251. class LineAnnotationElement extends AnnotationElement {
  8252. constructor(parameters) {
  8253. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8254. super(parameters, {
  8255. isRenderable,
  8256. ignoreBorder: true
  8257. });
  8258. }
  8259. render() {
  8260. this.container.className = "lineAnnotation";
  8261. const data = this.data;
  8262. const width = data.rect[2] - data.rect[0];
  8263. const height = data.rect[3] - data.rect[1];
  8264. const svg = this.svgFactory.create(width, height);
  8265. const line = this.svgFactory.createElement("svg:line");
  8266. line.setAttribute("x1", data.rect[2] - data.lineCoordinates[0]);
  8267. line.setAttribute("y1", data.rect[3] - data.lineCoordinates[1]);
  8268. line.setAttribute("x2", data.rect[2] - data.lineCoordinates[2]);
  8269. line.setAttribute("y2", data.rect[3] - data.lineCoordinates[3]);
  8270. line.setAttribute("stroke-width", data.borderStyle.width || 1);
  8271. line.setAttribute("stroke", "transparent");
  8272. svg.appendChild(line);
  8273. this.container.append(svg);
  8274. this._createPopup(line, data);
  8275. return this.container;
  8276. }
  8277. }
  8278. class SquareAnnotationElement extends AnnotationElement {
  8279. constructor(parameters) {
  8280. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8281. super(parameters, {
  8282. isRenderable,
  8283. ignoreBorder: true
  8284. });
  8285. }
  8286. render() {
  8287. this.container.className = "squareAnnotation";
  8288. const data = this.data;
  8289. const width = data.rect[2] - data.rect[0];
  8290. const height = data.rect[3] - data.rect[1];
  8291. const svg = this.svgFactory.create(width, height);
  8292. const borderWidth = data.borderStyle.width;
  8293. const square = this.svgFactory.createElement("svg:rect");
  8294. square.setAttribute("x", borderWidth / 2);
  8295. square.setAttribute("y", borderWidth / 2);
  8296. square.setAttribute("width", width - borderWidth);
  8297. square.setAttribute("height", height - borderWidth);
  8298. square.setAttribute("stroke-width", borderWidth || 1);
  8299. square.setAttribute("stroke", "transparent");
  8300. square.setAttribute("fill", "none");
  8301. svg.appendChild(square);
  8302. this.container.append(svg);
  8303. this._createPopup(square, data);
  8304. return this.container;
  8305. }
  8306. }
  8307. class CircleAnnotationElement extends AnnotationElement {
  8308. constructor(parameters) {
  8309. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8310. super(parameters, {
  8311. isRenderable,
  8312. ignoreBorder: true
  8313. });
  8314. }
  8315. render() {
  8316. this.container.className = "circleAnnotation";
  8317. const data = this.data;
  8318. const width = data.rect[2] - data.rect[0];
  8319. const height = data.rect[3] - data.rect[1];
  8320. const svg = this.svgFactory.create(width, height);
  8321. const borderWidth = data.borderStyle.width;
  8322. const circle = this.svgFactory.createElement("svg:ellipse");
  8323. circle.setAttribute("cx", width / 2);
  8324. circle.setAttribute("cy", height / 2);
  8325. circle.setAttribute("rx", width / 2 - borderWidth / 2);
  8326. circle.setAttribute("ry", height / 2 - borderWidth / 2);
  8327. circle.setAttribute("stroke-width", borderWidth || 1);
  8328. circle.setAttribute("stroke", "transparent");
  8329. circle.setAttribute("fill", "none");
  8330. svg.appendChild(circle);
  8331. this.container.append(svg);
  8332. this._createPopup(circle, data);
  8333. return this.container;
  8334. }
  8335. }
  8336. class PolylineAnnotationElement extends AnnotationElement {
  8337. constructor(parameters) {
  8338. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8339. super(parameters, {
  8340. isRenderable,
  8341. ignoreBorder: true
  8342. });
  8343. this.containerClassName = "polylineAnnotation";
  8344. this.svgElementName = "svg:polyline";
  8345. }
  8346. render() {
  8347. this.container.className = this.containerClassName;
  8348. const data = this.data;
  8349. const width = data.rect[2] - data.rect[0];
  8350. const height = data.rect[3] - data.rect[1];
  8351. const svg = this.svgFactory.create(width, height);
  8352. let points = [];
  8353. for (const coordinate of data.vertices) {
  8354. const x = coordinate.x - data.rect[0];
  8355. const y = data.rect[3] - coordinate.y;
  8356. points.push(x + "," + y);
  8357. }
  8358. points = points.join(" ");
  8359. const polyline = this.svgFactory.createElement(this.svgElementName);
  8360. polyline.setAttribute("points", points);
  8361. polyline.setAttribute("stroke-width", data.borderStyle.width || 1);
  8362. polyline.setAttribute("stroke", "transparent");
  8363. polyline.setAttribute("fill", "none");
  8364. svg.appendChild(polyline);
  8365. this.container.append(svg);
  8366. this._createPopup(polyline, data);
  8367. return this.container;
  8368. }
  8369. }
  8370. class PolygonAnnotationElement extends PolylineAnnotationElement {
  8371. constructor(parameters) {
  8372. super(parameters);
  8373. this.containerClassName = "polygonAnnotation";
  8374. this.svgElementName = "svg:polygon";
  8375. }
  8376. }
  8377. class CaretAnnotationElement extends AnnotationElement {
  8378. constructor(parameters) {
  8379. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8380. super(parameters, {
  8381. isRenderable,
  8382. ignoreBorder: true
  8383. });
  8384. }
  8385. render() {
  8386. this.container.className = "caretAnnotation";
  8387. if (!this.data.hasPopup) {
  8388. this._createPopup(null, this.data);
  8389. }
  8390. return this.container;
  8391. }
  8392. }
  8393. class InkAnnotationElement extends AnnotationElement {
  8394. constructor(parameters) {
  8395. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8396. super(parameters, {
  8397. isRenderable,
  8398. ignoreBorder: true
  8399. });
  8400. this.containerClassName = "inkAnnotation";
  8401. this.svgElementName = "svg:polyline";
  8402. }
  8403. render() {
  8404. this.container.className = this.containerClassName;
  8405. const data = this.data;
  8406. const width = data.rect[2] - data.rect[0];
  8407. const height = data.rect[3] - data.rect[1];
  8408. const svg = this.svgFactory.create(width, height);
  8409. for (const inkList of data.inkLists) {
  8410. let points = [];
  8411. for (const coordinate of inkList) {
  8412. const x = coordinate.x - data.rect[0];
  8413. const y = data.rect[3] - coordinate.y;
  8414. points.push(`${x},${y}`);
  8415. }
  8416. points = points.join(" ");
  8417. const polyline = this.svgFactory.createElement(this.svgElementName);
  8418. polyline.setAttribute("points", points);
  8419. polyline.setAttribute("stroke-width", data.borderStyle.width || 1);
  8420. polyline.setAttribute("stroke", "transparent");
  8421. polyline.setAttribute("fill", "none");
  8422. this._createPopup(polyline, data);
  8423. svg.appendChild(polyline);
  8424. }
  8425. this.container.append(svg);
  8426. return this.container;
  8427. }
  8428. }
  8429. class HighlightAnnotationElement extends AnnotationElement {
  8430. constructor(parameters) {
  8431. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8432. super(parameters, {
  8433. isRenderable,
  8434. ignoreBorder: true,
  8435. createQuadrilaterals: true
  8436. });
  8437. }
  8438. render() {
  8439. if (!this.data.hasPopup) {
  8440. this._createPopup(null, this.data);
  8441. }
  8442. if (this.quadrilaterals) {
  8443. return this._renderQuadrilaterals("highlightAnnotation");
  8444. }
  8445. this.container.className = "highlightAnnotation";
  8446. return this.container;
  8447. }
  8448. }
  8449. class UnderlineAnnotationElement extends AnnotationElement {
  8450. constructor(parameters) {
  8451. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8452. super(parameters, {
  8453. isRenderable,
  8454. ignoreBorder: true,
  8455. createQuadrilaterals: true
  8456. });
  8457. }
  8458. render() {
  8459. if (!this.data.hasPopup) {
  8460. this._createPopup(null, this.data);
  8461. }
  8462. if (this.quadrilaterals) {
  8463. return this._renderQuadrilaterals("underlineAnnotation");
  8464. }
  8465. this.container.className = "underlineAnnotation";
  8466. return this.container;
  8467. }
  8468. }
  8469. class SquigglyAnnotationElement extends AnnotationElement {
  8470. constructor(parameters) {
  8471. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8472. super(parameters, {
  8473. isRenderable,
  8474. ignoreBorder: true,
  8475. createQuadrilaterals: true
  8476. });
  8477. }
  8478. render() {
  8479. if (!this.data.hasPopup) {
  8480. this._createPopup(null, this.data);
  8481. }
  8482. if (this.quadrilaterals) {
  8483. return this._renderQuadrilaterals("squigglyAnnotation");
  8484. }
  8485. this.container.className = "squigglyAnnotation";
  8486. return this.container;
  8487. }
  8488. }
  8489. class StrikeOutAnnotationElement extends AnnotationElement {
  8490. constructor(parameters) {
  8491. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8492. super(parameters, {
  8493. isRenderable,
  8494. ignoreBorder: true,
  8495. createQuadrilaterals: true
  8496. });
  8497. }
  8498. render() {
  8499. if (!this.data.hasPopup) {
  8500. this._createPopup(null, this.data);
  8501. }
  8502. if (this.quadrilaterals) {
  8503. return this._renderQuadrilaterals("strikeoutAnnotation");
  8504. }
  8505. this.container.className = "strikeoutAnnotation";
  8506. return this.container;
  8507. }
  8508. }
  8509. class StampAnnotationElement extends AnnotationElement {
  8510. constructor(parameters) {
  8511. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8512. super(parameters, {
  8513. isRenderable,
  8514. ignoreBorder: true
  8515. });
  8516. }
  8517. render() {
  8518. this.container.className = "stampAnnotation";
  8519. if (!this.data.hasPopup) {
  8520. this._createPopup(null, this.data);
  8521. }
  8522. return this.container;
  8523. }
  8524. }
  8525. class FileAttachmentAnnotationElement extends AnnotationElement {
  8526. constructor(parameters) {
  8527. super(parameters, {
  8528. isRenderable: true
  8529. });
  8530. const {
  8531. filename,
  8532. content
  8533. } = this.data.file;
  8534. this.filename = (0, _display_utils.getFilenameFromUrl)(filename);
  8535. this.content = content;
  8536. this.linkService.eventBus?.dispatch("fileattachmentannotation", {
  8537. source: this,
  8538. id: (0, _util.stringToPDFString)(filename),
  8539. filename,
  8540. content
  8541. });
  8542. }
  8543. render() {
  8544. this.container.className = "fileAttachmentAnnotation";
  8545. const trigger = document.createElement("div");
  8546. trigger.style.height = this.container.style.height;
  8547. trigger.style.width = this.container.style.width;
  8548. trigger.addEventListener("dblclick", this._download.bind(this));
  8549. if (!this.data.hasPopup && (this.data.title || this.data.contents)) {
  8550. this._createPopup(trigger, this.data);
  8551. }
  8552. this.container.appendChild(trigger);
  8553. return this.container;
  8554. }
  8555. _download() {
  8556. this.downloadManager?.openOrDownloadData(this.container, this.content, this.filename);
  8557. }
  8558. }
  8559. class AnnotationLayer {
  8560. static render(parameters) {
  8561. const sortedAnnotations = [],
  8562. popupAnnotations = [];
  8563. for (const data of parameters.annotations) {
  8564. if (!data) {
  8565. continue;
  8566. }
  8567. if (data.annotationType === _util.AnnotationType.POPUP) {
  8568. popupAnnotations.push(data);
  8569. continue;
  8570. }
  8571. sortedAnnotations.push(data);
  8572. }
  8573. if (popupAnnotations.length) {
  8574. sortedAnnotations.push(...popupAnnotations);
  8575. }
  8576. for (const data of sortedAnnotations) {
  8577. const element = AnnotationElementFactory.create({
  8578. data,
  8579. layer: parameters.div,
  8580. page: parameters.page,
  8581. viewport: parameters.viewport,
  8582. linkService: parameters.linkService,
  8583. downloadManager: parameters.downloadManager,
  8584. imageResourcesPath: parameters.imageResourcesPath || "",
  8585. renderInteractiveForms: parameters.renderInteractiveForms !== false,
  8586. svgFactory: new _display_utils.DOMSVGFactory(),
  8587. annotationStorage: parameters.annotationStorage || new _annotation_storage.AnnotationStorage(),
  8588. enableScripting: parameters.enableScripting,
  8589. hasJSActions: parameters.hasJSActions,
  8590. mouseState: parameters.mouseState || {
  8591. isDown: false
  8592. }
  8593. });
  8594. if (element.isRenderable) {
  8595. const rendered = element.render();
  8596. if (data.hidden) {
  8597. rendered.style.visibility = "hidden";
  8598. }
  8599. if (Array.isArray(rendered)) {
  8600. for (const renderedElement of rendered) {
  8601. parameters.div.appendChild(renderedElement);
  8602. }
  8603. } else {
  8604. if (element instanceof PopupAnnotationElement) {
  8605. parameters.div.prepend(rendered);
  8606. } else {
  8607. parameters.div.appendChild(rendered);
  8608. }
  8609. }
  8610. }
  8611. }
  8612. }
  8613. static update(parameters) {
  8614. const transform = `matrix(${parameters.viewport.transform.join(",")})`;
  8615. for (const data of parameters.annotations) {
  8616. const elements = parameters.div.querySelectorAll(`[data-annotation-id="${data.id}"]`);
  8617. if (elements) {
  8618. elements.forEach(element => {
  8619. element.style.transform = transform;
  8620. });
  8621. }
  8622. }
  8623. parameters.div.hidden = false;
  8624. }
  8625. }
  8626. exports.AnnotationLayer = AnnotationLayer;
  8627. /***/ }),
  8628. /* 19 */
  8629. /***/ ((__unused_webpack_module, exports) => {
  8630. Object.defineProperty(exports, "__esModule", ({
  8631. value: true
  8632. }));
  8633. exports.ColorConverters = void 0;
  8634. function makeColorComp(n) {
  8635. return Math.floor(Math.max(0, Math.min(1, n)) * 255).toString(16).padStart(2, "0");
  8636. }
  8637. class ColorConverters {
  8638. static CMYK_G([c, y, m, k]) {
  8639. return ["G", 1 - Math.min(1, 0.3 * c + 0.59 * m + 0.11 * y + k)];
  8640. }
  8641. static G_CMYK([g]) {
  8642. return ["CMYK", 0, 0, 0, 1 - g];
  8643. }
  8644. static G_RGB([g]) {
  8645. return ["RGB", g, g, g];
  8646. }
  8647. static G_HTML([g]) {
  8648. const G = makeColorComp(g);
  8649. return `#${G}${G}${G}`;
  8650. }
  8651. static RGB_G([r, g, b]) {
  8652. return ["G", 0.3 * r + 0.59 * g + 0.11 * b];
  8653. }
  8654. static RGB_HTML([r, g, b]) {
  8655. const R = makeColorComp(r);
  8656. const G = makeColorComp(g);
  8657. const B = makeColorComp(b);
  8658. return `#${R}${G}${B}`;
  8659. }
  8660. static T_HTML() {
  8661. return "#00000000";
  8662. }
  8663. static CMYK_RGB([c, y, m, k]) {
  8664. return ["RGB", 1 - Math.min(1, c + k), 1 - Math.min(1, m + k), 1 - Math.min(1, y + k)];
  8665. }
  8666. static CMYK_HTML(components) {
  8667. return this.RGB_HTML(this.CMYK_RGB(components));
  8668. }
  8669. static RGB_CMYK([r, g, b]) {
  8670. const c = 1 - r;
  8671. const m = 1 - g;
  8672. const y = 1 - b;
  8673. const k = Math.min(c, m, y);
  8674. return ["CMYK", c, m, y, k];
  8675. }
  8676. }
  8677. exports.ColorConverters = ColorConverters;
  8678. /***/ }),
  8679. /* 20 */
  8680. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  8681. Object.defineProperty(exports, "__esModule", ({
  8682. value: true
  8683. }));
  8684. exports.renderTextLayer = void 0;
  8685. var _util = __w_pdfjs_require__(2);
  8686. const renderTextLayer = function renderTextLayerClosure() {
  8687. const MAX_TEXT_DIVS_TO_RENDER = 100000;
  8688. const DEFAULT_FONT_SIZE = 30;
  8689. const DEFAULT_FONT_ASCENT = 0.8;
  8690. const ascentCache = new Map();
  8691. const NonWhitespaceRegexp = /\S/;
  8692. function isAllWhitespace(str) {
  8693. return !NonWhitespaceRegexp.test(str);
  8694. }
  8695. function getAscent(fontFamily, ctx) {
  8696. const cachedAscent = ascentCache.get(fontFamily);
  8697. if (cachedAscent) {
  8698. return cachedAscent;
  8699. }
  8700. ctx.save();
  8701. ctx.font = `${DEFAULT_FONT_SIZE}px ${fontFamily}`;
  8702. const metrics = ctx.measureText("");
  8703. let ascent = metrics.fontBoundingBoxAscent;
  8704. let descent = Math.abs(metrics.fontBoundingBoxDescent);
  8705. if (ascent) {
  8706. ctx.restore();
  8707. const ratio = ascent / (ascent + descent);
  8708. ascentCache.set(fontFamily, ratio);
  8709. return ratio;
  8710. }
  8711. ctx.strokeStyle = "red";
  8712. ctx.clearRect(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE);
  8713. ctx.strokeText("g", 0, 0);
  8714. let pixels = ctx.getImageData(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE).data;
  8715. descent = 0;
  8716. for (let i = pixels.length - 1 - 3; i >= 0; i -= 4) {
  8717. if (pixels[i] > 0) {
  8718. descent = Math.ceil(i / 4 / DEFAULT_FONT_SIZE);
  8719. break;
  8720. }
  8721. }
  8722. ctx.clearRect(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE);
  8723. ctx.strokeText("A", 0, DEFAULT_FONT_SIZE);
  8724. pixels = ctx.getImageData(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE).data;
  8725. ascent = 0;
  8726. for (let i = 0, ii = pixels.length; i < ii; i += 4) {
  8727. if (pixels[i] > 0) {
  8728. ascent = DEFAULT_FONT_SIZE - Math.floor(i / 4 / DEFAULT_FONT_SIZE);
  8729. break;
  8730. }
  8731. }
  8732. ctx.restore();
  8733. if (ascent) {
  8734. const ratio = ascent / (ascent + descent);
  8735. ascentCache.set(fontFamily, ratio);
  8736. return ratio;
  8737. }
  8738. ascentCache.set(fontFamily, DEFAULT_FONT_ASCENT);
  8739. return DEFAULT_FONT_ASCENT;
  8740. }
  8741. function appendText(task, geom, styles, ctx) {
  8742. const textDiv = document.createElement("span");
  8743. const textDivProperties = {
  8744. angle: 0,
  8745. canvasWidth: 0,
  8746. isWhitespace: false,
  8747. originalTransform: null,
  8748. paddingBottom: 0,
  8749. paddingLeft: 0,
  8750. paddingRight: 0,
  8751. paddingTop: 0,
  8752. scale: 1
  8753. };
  8754. task._textDivs.push(textDiv);
  8755. if (isAllWhitespace(geom.str)) {
  8756. textDivProperties.isWhitespace = true;
  8757. task._textDivProperties.set(textDiv, textDivProperties);
  8758. return;
  8759. }
  8760. const tx = _util.Util.transform(task._viewport.transform, geom.transform);
  8761. let angle = Math.atan2(tx[1], tx[0]);
  8762. const style = styles[geom.fontName];
  8763. if (style.vertical) {
  8764. angle += Math.PI / 2;
  8765. }
  8766. const fontHeight = Math.hypot(tx[2], tx[3]);
  8767. const fontAscent = fontHeight * getAscent(style.fontFamily, ctx);
  8768. let left, top;
  8769. if (angle === 0) {
  8770. left = tx[4];
  8771. top = tx[5] - fontAscent;
  8772. } else {
  8773. left = tx[4] + fontAscent * Math.sin(angle);
  8774. top = tx[5] - fontAscent * Math.cos(angle);
  8775. }
  8776. textDiv.style.left = `${left}px`;
  8777. textDiv.style.top = `${top}px`;
  8778. textDiv.style.fontSize = `${fontHeight}px`;
  8779. textDiv.style.fontFamily = style.fontFamily;
  8780. textDiv.textContent = geom.str;
  8781. textDiv.dir = geom.dir;
  8782. if (task._fontInspectorEnabled) {
  8783. textDiv.dataset.fontName = geom.fontName;
  8784. }
  8785. if (angle !== 0) {
  8786. textDivProperties.angle = angle * (180 / Math.PI);
  8787. }
  8788. let shouldScaleText = false;
  8789. if (geom.str.length > 1) {
  8790. shouldScaleText = true;
  8791. } else if (geom.transform[0] !== geom.transform[3]) {
  8792. const absScaleX = Math.abs(geom.transform[0]),
  8793. absScaleY = Math.abs(geom.transform[3]);
  8794. if (absScaleX !== absScaleY && Math.max(absScaleX, absScaleY) / Math.min(absScaleX, absScaleY) > 1.5) {
  8795. shouldScaleText = true;
  8796. }
  8797. }
  8798. if (shouldScaleText) {
  8799. if (style.vertical) {
  8800. textDivProperties.canvasWidth = geom.height * task._viewport.scale;
  8801. } else {
  8802. textDivProperties.canvasWidth = geom.width * task._viewport.scale;
  8803. }
  8804. }
  8805. task._textDivProperties.set(textDiv, textDivProperties);
  8806. if (task._textContentStream) {
  8807. task._layoutText(textDiv);
  8808. }
  8809. if (task._enhanceTextSelection) {
  8810. let angleCos = 1,
  8811. angleSin = 0;
  8812. if (angle !== 0) {
  8813. angleCos = Math.cos(angle);
  8814. angleSin = Math.sin(angle);
  8815. }
  8816. const divWidth = (style.vertical ? geom.height : geom.width) * task._viewport.scale;
  8817. const divHeight = fontHeight;
  8818. let m, b;
  8819. if (angle !== 0) {
  8820. m = [angleCos, angleSin, -angleSin, angleCos, left, top];
  8821. b = _util.Util.getAxialAlignedBoundingBox([0, 0, divWidth, divHeight], m);
  8822. } else {
  8823. b = [left, top, left + divWidth, top + divHeight];
  8824. }
  8825. task._bounds.push({
  8826. left: b[0],
  8827. top: b[1],
  8828. right: b[2],
  8829. bottom: b[3],
  8830. div: textDiv,
  8831. size: [divWidth, divHeight],
  8832. m
  8833. });
  8834. }
  8835. }
  8836. function render(task) {
  8837. if (task._canceled) {
  8838. return;
  8839. }
  8840. const textDivs = task._textDivs;
  8841. const capability = task._capability;
  8842. const textDivsLength = textDivs.length;
  8843. if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
  8844. task._renderingDone = true;
  8845. capability.resolve();
  8846. return;
  8847. }
  8848. if (!task._textContentStream) {
  8849. for (let i = 0; i < textDivsLength; i++) {
  8850. task._layoutText(textDivs[i]);
  8851. }
  8852. }
  8853. task._renderingDone = true;
  8854. capability.resolve();
  8855. }
  8856. function findPositiveMin(ts, offset, count) {
  8857. let result = 0;
  8858. for (let i = 0; i < count; i++) {
  8859. const t = ts[offset++];
  8860. if (t > 0) {
  8861. result = result ? Math.min(t, result) : t;
  8862. }
  8863. }
  8864. return result;
  8865. }
  8866. function expand(task) {
  8867. const bounds = task._bounds;
  8868. const viewport = task._viewport;
  8869. const expanded = expandBounds(viewport.width, viewport.height, bounds);
  8870. for (let i = 0; i < expanded.length; i++) {
  8871. const div = bounds[i].div;
  8872. const divProperties = task._textDivProperties.get(div);
  8873. if (divProperties.angle === 0) {
  8874. divProperties.paddingLeft = bounds[i].left - expanded[i].left;
  8875. divProperties.paddingTop = bounds[i].top - expanded[i].top;
  8876. divProperties.paddingRight = expanded[i].right - bounds[i].right;
  8877. divProperties.paddingBottom = expanded[i].bottom - bounds[i].bottom;
  8878. task._textDivProperties.set(div, divProperties);
  8879. continue;
  8880. }
  8881. const e = expanded[i],
  8882. b = bounds[i];
  8883. const m = b.m,
  8884. c = m[0],
  8885. s = m[1];
  8886. const points = [[0, 0], [0, b.size[1]], [b.size[0], 0], b.size];
  8887. const ts = new Float64Array(64);
  8888. points.forEach(function (p, j) {
  8889. const t = _util.Util.applyTransform(p, m);
  8890. ts[j + 0] = c && (e.left - t[0]) / c;
  8891. ts[j + 4] = s && (e.top - t[1]) / s;
  8892. ts[j + 8] = c && (e.right - t[0]) / c;
  8893. ts[j + 12] = s && (e.bottom - t[1]) / s;
  8894. ts[j + 16] = s && (e.left - t[0]) / -s;
  8895. ts[j + 20] = c && (e.top - t[1]) / c;
  8896. ts[j + 24] = s && (e.right - t[0]) / -s;
  8897. ts[j + 28] = c && (e.bottom - t[1]) / c;
  8898. ts[j + 32] = c && (e.left - t[0]) / -c;
  8899. ts[j + 36] = s && (e.top - t[1]) / -s;
  8900. ts[j + 40] = c && (e.right - t[0]) / -c;
  8901. ts[j + 44] = s && (e.bottom - t[1]) / -s;
  8902. ts[j + 48] = s && (e.left - t[0]) / s;
  8903. ts[j + 52] = c && (e.top - t[1]) / -c;
  8904. ts[j + 56] = s && (e.right - t[0]) / s;
  8905. ts[j + 60] = c && (e.bottom - t[1]) / -c;
  8906. });
  8907. const boxScale = 1 + Math.min(Math.abs(c), Math.abs(s));
  8908. divProperties.paddingLeft = findPositiveMin(ts, 32, 16) / boxScale;
  8909. divProperties.paddingTop = findPositiveMin(ts, 48, 16) / boxScale;
  8910. divProperties.paddingRight = findPositiveMin(ts, 0, 16) / boxScale;
  8911. divProperties.paddingBottom = findPositiveMin(ts, 16, 16) / boxScale;
  8912. task._textDivProperties.set(div, divProperties);
  8913. }
  8914. }
  8915. function expandBounds(width, height, boxes) {
  8916. const bounds = boxes.map(function (box, i) {
  8917. return {
  8918. x1: box.left,
  8919. y1: box.top,
  8920. x2: box.right,
  8921. y2: box.bottom,
  8922. index: i,
  8923. x1New: undefined,
  8924. x2New: undefined
  8925. };
  8926. });
  8927. expandBoundsLTR(width, bounds);
  8928. const expanded = new Array(boxes.length);
  8929. bounds.forEach(function (b) {
  8930. const i = b.index;
  8931. expanded[i] = {
  8932. left: b.x1New,
  8933. top: 0,
  8934. right: b.x2New,
  8935. bottom: 0
  8936. };
  8937. });
  8938. boxes.map(function (box, i) {
  8939. const e = expanded[i],
  8940. b = bounds[i];
  8941. b.x1 = box.top;
  8942. b.y1 = width - e.right;
  8943. b.x2 = box.bottom;
  8944. b.y2 = width - e.left;
  8945. b.index = i;
  8946. b.x1New = undefined;
  8947. b.x2New = undefined;
  8948. });
  8949. expandBoundsLTR(height, bounds);
  8950. bounds.forEach(function (b) {
  8951. const i = b.index;
  8952. expanded[i].top = b.x1New;
  8953. expanded[i].bottom = b.x2New;
  8954. });
  8955. return expanded;
  8956. }
  8957. function expandBoundsLTR(width, bounds) {
  8958. bounds.sort(function (a, b) {
  8959. return a.x1 - b.x1 || a.index - b.index;
  8960. });
  8961. const fakeBoundary = {
  8962. x1: -Infinity,
  8963. y1: -Infinity,
  8964. x2: 0,
  8965. y2: Infinity,
  8966. index: -1,
  8967. x1New: 0,
  8968. x2New: 0
  8969. };
  8970. const horizon = [{
  8971. start: -Infinity,
  8972. end: Infinity,
  8973. boundary: fakeBoundary
  8974. }];
  8975. bounds.forEach(function (boundary) {
  8976. let i = 0;
  8977. while (i < horizon.length && horizon[i].end <= boundary.y1) {
  8978. i++;
  8979. }
  8980. let j = horizon.length - 1;
  8981. while (j >= 0 && horizon[j].start >= boundary.y2) {
  8982. j--;
  8983. }
  8984. let horizonPart, affectedBoundary;
  8985. let q,
  8986. k,
  8987. maxXNew = -Infinity;
  8988. for (q = i; q <= j; q++) {
  8989. horizonPart = horizon[q];
  8990. affectedBoundary = horizonPart.boundary;
  8991. let xNew;
  8992. if (affectedBoundary.x2 > boundary.x1) {
  8993. xNew = affectedBoundary.index > boundary.index ? affectedBoundary.x1New : boundary.x1;
  8994. } else if (affectedBoundary.x2New === undefined) {
  8995. xNew = (affectedBoundary.x2 + boundary.x1) / 2;
  8996. } else {
  8997. xNew = affectedBoundary.x2New;
  8998. }
  8999. if (xNew > maxXNew) {
  9000. maxXNew = xNew;
  9001. }
  9002. }
  9003. boundary.x1New = maxXNew;
  9004. for (q = i; q <= j; q++) {
  9005. horizonPart = horizon[q];
  9006. affectedBoundary = horizonPart.boundary;
  9007. if (affectedBoundary.x2New === undefined) {
  9008. if (affectedBoundary.x2 > boundary.x1) {
  9009. if (affectedBoundary.index > boundary.index) {
  9010. affectedBoundary.x2New = affectedBoundary.x2;
  9011. }
  9012. } else {
  9013. affectedBoundary.x2New = maxXNew;
  9014. }
  9015. } else if (affectedBoundary.x2New > maxXNew) {
  9016. affectedBoundary.x2New = Math.max(maxXNew, affectedBoundary.x2);
  9017. }
  9018. }
  9019. const changedHorizon = [];
  9020. let lastBoundary = null;
  9021. for (q = i; q <= j; q++) {
  9022. horizonPart = horizon[q];
  9023. affectedBoundary = horizonPart.boundary;
  9024. const useBoundary = affectedBoundary.x2 > boundary.x2 ? affectedBoundary : boundary;
  9025. if (lastBoundary === useBoundary) {
  9026. changedHorizon[changedHorizon.length - 1].end = horizonPart.end;
  9027. } else {
  9028. changedHorizon.push({
  9029. start: horizonPart.start,
  9030. end: horizonPart.end,
  9031. boundary: useBoundary
  9032. });
  9033. lastBoundary = useBoundary;
  9034. }
  9035. }
  9036. if (horizon[i].start < boundary.y1) {
  9037. changedHorizon[0].start = boundary.y1;
  9038. changedHorizon.unshift({
  9039. start: horizon[i].start,
  9040. end: boundary.y1,
  9041. boundary: horizon[i].boundary
  9042. });
  9043. }
  9044. if (boundary.y2 < horizon[j].end) {
  9045. changedHorizon[changedHorizon.length - 1].end = boundary.y2;
  9046. changedHorizon.push({
  9047. start: boundary.y2,
  9048. end: horizon[j].end,
  9049. boundary: horizon[j].boundary
  9050. });
  9051. }
  9052. for (q = i; q <= j; q++) {
  9053. horizonPart = horizon[q];
  9054. affectedBoundary = horizonPart.boundary;
  9055. if (affectedBoundary.x2New !== undefined) {
  9056. continue;
  9057. }
  9058. let used = false;
  9059. for (k = i - 1; !used && k >= 0 && horizon[k].start >= affectedBoundary.y1; k--) {
  9060. used = horizon[k].boundary === affectedBoundary;
  9061. }
  9062. for (k = j + 1; !used && k < horizon.length && horizon[k].end <= affectedBoundary.y2; k++) {
  9063. used = horizon[k].boundary === affectedBoundary;
  9064. }
  9065. for (k = 0; !used && k < changedHorizon.length; k++) {
  9066. used = changedHorizon[k].boundary === affectedBoundary;
  9067. }
  9068. if (!used) {
  9069. affectedBoundary.x2New = maxXNew;
  9070. }
  9071. }
  9072. Array.prototype.splice.apply(horizon, [i, j - i + 1].concat(changedHorizon));
  9073. });
  9074. horizon.forEach(function (horizonPart) {
  9075. const affectedBoundary = horizonPart.boundary;
  9076. if (affectedBoundary.x2New === undefined) {
  9077. affectedBoundary.x2New = Math.max(width, affectedBoundary.x2);
  9078. }
  9079. });
  9080. }
  9081. function TextLayerRenderTask({
  9082. textContent,
  9083. textContentStream,
  9084. container,
  9085. viewport,
  9086. textDivs,
  9087. textContentItemsStr,
  9088. enhanceTextSelection
  9089. }) {
  9090. this._textContent = textContent;
  9091. this._textContentStream = textContentStream;
  9092. this._container = container;
  9093. this._document = container.ownerDocument;
  9094. this._viewport = viewport;
  9095. this._textDivs = textDivs || [];
  9096. this._textContentItemsStr = textContentItemsStr || [];
  9097. this._enhanceTextSelection = !!enhanceTextSelection;
  9098. this._fontInspectorEnabled = !!globalThis.FontInspector?.enabled;
  9099. this._reader = null;
  9100. this._layoutTextLastFontSize = null;
  9101. this._layoutTextLastFontFamily = null;
  9102. this._layoutTextCtx = null;
  9103. this._textDivProperties = new WeakMap();
  9104. this._renderingDone = false;
  9105. this._canceled = false;
  9106. this._capability = (0, _util.createPromiseCapability)();
  9107. this._renderTimer = null;
  9108. this._bounds = [];
  9109. this._capability.promise.finally(() => {
  9110. if (this._layoutTextCtx) {
  9111. this._layoutTextCtx.canvas.width = 0;
  9112. this._layoutTextCtx.canvas.height = 0;
  9113. this._layoutTextCtx = null;
  9114. }
  9115. }).catch(() => {});
  9116. }
  9117. TextLayerRenderTask.prototype = {
  9118. get promise() {
  9119. return this._capability.promise;
  9120. },
  9121. cancel: function TextLayer_cancel() {
  9122. this._canceled = true;
  9123. if (this._reader) {
  9124. this._reader.cancel(new _util.AbortException("TextLayer task cancelled."));
  9125. this._reader = null;
  9126. }
  9127. if (this._renderTimer !== null) {
  9128. clearTimeout(this._renderTimer);
  9129. this._renderTimer = null;
  9130. }
  9131. this._capability.reject(new Error("TextLayer task cancelled."));
  9132. },
  9133. _processItems(items, styleCache) {
  9134. for (let i = 0, len = items.length; i < len; i++) {
  9135. this._textContentItemsStr.push(items[i].str);
  9136. appendText(this, items[i], styleCache, this._layoutTextCtx);
  9137. }
  9138. },
  9139. _layoutText(textDiv) {
  9140. const textDivProperties = this._textDivProperties.get(textDiv);
  9141. if (textDivProperties.isWhitespace) {
  9142. return;
  9143. }
  9144. let transform = "";
  9145. if (textDivProperties.canvasWidth !== 0) {
  9146. const {
  9147. fontSize,
  9148. fontFamily
  9149. } = textDiv.style;
  9150. if (fontSize !== this._layoutTextLastFontSize || fontFamily !== this._layoutTextLastFontFamily) {
  9151. this._layoutTextCtx.font = `${fontSize} ${fontFamily}`;
  9152. this._layoutTextLastFontSize = fontSize;
  9153. this._layoutTextLastFontFamily = fontFamily;
  9154. }
  9155. const {
  9156. width
  9157. } = this._layoutTextCtx.measureText(textDiv.textContent);
  9158. if (width > 0) {
  9159. textDivProperties.scale = textDivProperties.canvasWidth / width;
  9160. transform = `scaleX(${textDivProperties.scale})`;
  9161. }
  9162. }
  9163. if (textDivProperties.angle !== 0) {
  9164. transform = `rotate(${textDivProperties.angle}deg) ${transform}`;
  9165. }
  9166. if (transform.length > 0) {
  9167. if (this._enhanceTextSelection) {
  9168. textDivProperties.originalTransform = transform;
  9169. }
  9170. textDiv.style.transform = transform;
  9171. }
  9172. this._textDivProperties.set(textDiv, textDivProperties);
  9173. this._container.appendChild(textDiv);
  9174. },
  9175. _render: function TextLayer_render(timeout) {
  9176. const capability = (0, _util.createPromiseCapability)();
  9177. let styleCache = Object.create(null);
  9178. const canvas = this._document.createElement("canvas");
  9179. canvas.height = canvas.width = DEFAULT_FONT_SIZE;
  9180. canvas.mozOpaque = true;
  9181. this._layoutTextCtx = canvas.getContext("2d", {
  9182. alpha: false
  9183. });
  9184. if (this._textContent) {
  9185. const textItems = this._textContent.items;
  9186. const textStyles = this._textContent.styles;
  9187. this._processItems(textItems, textStyles);
  9188. capability.resolve();
  9189. } else if (this._textContentStream) {
  9190. const pump = () => {
  9191. this._reader.read().then(({
  9192. value,
  9193. done
  9194. }) => {
  9195. if (done) {
  9196. capability.resolve();
  9197. return;
  9198. }
  9199. Object.assign(styleCache, value.styles);
  9200. this._processItems(value.items, styleCache);
  9201. pump();
  9202. }, capability.reject);
  9203. };
  9204. this._reader = this._textContentStream.getReader();
  9205. pump();
  9206. } else {
  9207. throw new Error('Neither "textContent" nor "textContentStream"' + " parameters specified.");
  9208. }
  9209. capability.promise.then(() => {
  9210. styleCache = null;
  9211. if (!timeout) {
  9212. render(this);
  9213. } else {
  9214. this._renderTimer = setTimeout(() => {
  9215. render(this);
  9216. this._renderTimer = null;
  9217. }, timeout);
  9218. }
  9219. }, this._capability.reject);
  9220. },
  9221. expandTextDivs: function TextLayer_expandTextDivs(expandDivs) {
  9222. if (!this._enhanceTextSelection || !this._renderingDone) {
  9223. return;
  9224. }
  9225. if (this._bounds !== null) {
  9226. expand(this);
  9227. this._bounds = null;
  9228. }
  9229. const transformBuf = [],
  9230. paddingBuf = [];
  9231. for (let i = 0, ii = this._textDivs.length; i < ii; i++) {
  9232. const div = this._textDivs[i];
  9233. const divProps = this._textDivProperties.get(div);
  9234. if (divProps.isWhitespace) {
  9235. continue;
  9236. }
  9237. if (expandDivs) {
  9238. transformBuf.length = 0;
  9239. paddingBuf.length = 0;
  9240. if (divProps.originalTransform) {
  9241. transformBuf.push(divProps.originalTransform);
  9242. }
  9243. if (divProps.paddingTop > 0) {
  9244. paddingBuf.push(`${divProps.paddingTop}px`);
  9245. transformBuf.push(`translateY(${-divProps.paddingTop}px)`);
  9246. } else {
  9247. paddingBuf.push(0);
  9248. }
  9249. if (divProps.paddingRight > 0) {
  9250. paddingBuf.push(`${divProps.paddingRight / divProps.scale}px`);
  9251. } else {
  9252. paddingBuf.push(0);
  9253. }
  9254. if (divProps.paddingBottom > 0) {
  9255. paddingBuf.push(`${divProps.paddingBottom}px`);
  9256. } else {
  9257. paddingBuf.push(0);
  9258. }
  9259. if (divProps.paddingLeft > 0) {
  9260. paddingBuf.push(`${divProps.paddingLeft / divProps.scale}px`);
  9261. transformBuf.push(`translateX(${-divProps.paddingLeft / divProps.scale}px)`);
  9262. } else {
  9263. paddingBuf.push(0);
  9264. }
  9265. div.style.padding = paddingBuf.join(" ");
  9266. if (transformBuf.length) {
  9267. div.style.transform = transformBuf.join(" ");
  9268. }
  9269. } else {
  9270. div.style.padding = null;
  9271. div.style.transform = divProps.originalTransform;
  9272. }
  9273. }
  9274. }
  9275. };
  9276. function renderTextLayer(renderParameters) {
  9277. const task = new TextLayerRenderTask({
  9278. textContent: renderParameters.textContent,
  9279. textContentStream: renderParameters.textContentStream,
  9280. container: renderParameters.container,
  9281. viewport: renderParameters.viewport,
  9282. textDivs: renderParameters.textDivs,
  9283. textContentItemsStr: renderParameters.textContentItemsStr,
  9284. enhanceTextSelection: renderParameters.enhanceTextSelection
  9285. });
  9286. task._render(renderParameters.timeout);
  9287. return task;
  9288. }
  9289. return renderTextLayer;
  9290. }();
  9291. exports.renderTextLayer = renderTextLayer;
  9292. /***/ }),
  9293. /* 21 */
  9294. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  9295. Object.defineProperty(exports, "__esModule", ({
  9296. value: true
  9297. }));
  9298. exports.SVGGraphics = void 0;
  9299. var _util = __w_pdfjs_require__(2);
  9300. var _display_utils = __w_pdfjs_require__(1);
  9301. var _is_node = __w_pdfjs_require__(4);
  9302. let SVGGraphics = function () {
  9303. throw new Error("Not implemented: SVGGraphics");
  9304. };
  9305. exports.SVGGraphics = SVGGraphics;
  9306. {
  9307. const SVG_DEFAULTS = {
  9308. fontStyle: "normal",
  9309. fontWeight: "normal",
  9310. fillColor: "#000000"
  9311. };
  9312. const XML_NS = "http://www.w3.org/XML/1998/namespace";
  9313. const XLINK_NS = "http://www.w3.org/1999/xlink";
  9314. const LINE_CAP_STYLES = ["butt", "round", "square"];
  9315. const LINE_JOIN_STYLES = ["miter", "round", "bevel"];
  9316. const convertImgDataToPng = function () {
  9317. const PNG_HEADER = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  9318. const CHUNK_WRAPPER_SIZE = 12;
  9319. const crcTable = new Int32Array(256);
  9320. for (let i = 0; i < 256; i++) {
  9321. let c = i;
  9322. for (let h = 0; h < 8; h++) {
  9323. if (c & 1) {
  9324. c = 0xedb88320 ^ c >> 1 & 0x7fffffff;
  9325. } else {
  9326. c = c >> 1 & 0x7fffffff;
  9327. }
  9328. }
  9329. crcTable[i] = c;
  9330. }
  9331. function crc32(data, start, end) {
  9332. let crc = -1;
  9333. for (let i = start; i < end; i++) {
  9334. const a = (crc ^ data[i]) & 0xff;
  9335. const b = crcTable[a];
  9336. crc = crc >>> 8 ^ b;
  9337. }
  9338. return crc ^ -1;
  9339. }
  9340. function writePngChunk(type, body, data, offset) {
  9341. let p = offset;
  9342. const len = body.length;
  9343. data[p] = len >> 24 & 0xff;
  9344. data[p + 1] = len >> 16 & 0xff;
  9345. data[p + 2] = len >> 8 & 0xff;
  9346. data[p + 3] = len & 0xff;
  9347. p += 4;
  9348. data[p] = type.charCodeAt(0) & 0xff;
  9349. data[p + 1] = type.charCodeAt(1) & 0xff;
  9350. data[p + 2] = type.charCodeAt(2) & 0xff;
  9351. data[p + 3] = type.charCodeAt(3) & 0xff;
  9352. p += 4;
  9353. data.set(body, p);
  9354. p += body.length;
  9355. const crc = crc32(data, offset + 4, p);
  9356. data[p] = crc >> 24 & 0xff;
  9357. data[p + 1] = crc >> 16 & 0xff;
  9358. data[p + 2] = crc >> 8 & 0xff;
  9359. data[p + 3] = crc & 0xff;
  9360. }
  9361. function adler32(data, start, end) {
  9362. let a = 1;
  9363. let b = 0;
  9364. for (let i = start; i < end; ++i) {
  9365. a = (a + (data[i] & 0xff)) % 65521;
  9366. b = (b + a) % 65521;
  9367. }
  9368. return b << 16 | a;
  9369. }
  9370. function deflateSync(literals) {
  9371. if (!_is_node.isNodeJS) {
  9372. return deflateSyncUncompressed(literals);
  9373. }
  9374. try {
  9375. let input;
  9376. if (parseInt(process.versions.node) >= 8) {
  9377. input = literals;
  9378. } else {
  9379. input = Buffer.from(literals);
  9380. }
  9381. const output = require("zlib").deflateSync(input, {
  9382. level: 9
  9383. });
  9384. return output instanceof Uint8Array ? output : new Uint8Array(output);
  9385. } catch (e) {
  9386. (0, _util.warn)("Not compressing PNG because zlib.deflateSync is unavailable: " + e);
  9387. }
  9388. return deflateSyncUncompressed(literals);
  9389. }
  9390. function deflateSyncUncompressed(literals) {
  9391. let len = literals.length;
  9392. const maxBlockLength = 0xffff;
  9393. const deflateBlocks = Math.ceil(len / maxBlockLength);
  9394. const idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  9395. let pi = 0;
  9396. idat[pi++] = 0x78;
  9397. idat[pi++] = 0x9c;
  9398. let pos = 0;
  9399. while (len > maxBlockLength) {
  9400. idat[pi++] = 0x00;
  9401. idat[pi++] = 0xff;
  9402. idat[pi++] = 0xff;
  9403. idat[pi++] = 0x00;
  9404. idat[pi++] = 0x00;
  9405. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  9406. pi += maxBlockLength;
  9407. pos += maxBlockLength;
  9408. len -= maxBlockLength;
  9409. }
  9410. idat[pi++] = 0x01;
  9411. idat[pi++] = len & 0xff;
  9412. idat[pi++] = len >> 8 & 0xff;
  9413. idat[pi++] = ~len & 0xffff & 0xff;
  9414. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  9415. idat.set(literals.subarray(pos), pi);
  9416. pi += literals.length - pos;
  9417. const adler = adler32(literals, 0, literals.length);
  9418. idat[pi++] = adler >> 24 & 0xff;
  9419. idat[pi++] = adler >> 16 & 0xff;
  9420. idat[pi++] = adler >> 8 & 0xff;
  9421. idat[pi++] = adler & 0xff;
  9422. return idat;
  9423. }
  9424. function encode(imgData, kind, forceDataSchema, isMask) {
  9425. const width = imgData.width;
  9426. const height = imgData.height;
  9427. let bitDepth, colorType, lineSize;
  9428. const bytes = imgData.data;
  9429. switch (kind) {
  9430. case _util.ImageKind.GRAYSCALE_1BPP:
  9431. colorType = 0;
  9432. bitDepth = 1;
  9433. lineSize = width + 7 >> 3;
  9434. break;
  9435. case _util.ImageKind.RGB_24BPP:
  9436. colorType = 2;
  9437. bitDepth = 8;
  9438. lineSize = width * 3;
  9439. break;
  9440. case _util.ImageKind.RGBA_32BPP:
  9441. colorType = 6;
  9442. bitDepth = 8;
  9443. lineSize = width * 4;
  9444. break;
  9445. default:
  9446. throw new Error("invalid format");
  9447. }
  9448. const literals = new Uint8Array((1 + lineSize) * height);
  9449. let offsetLiterals = 0,
  9450. offsetBytes = 0;
  9451. for (let y = 0; y < height; ++y) {
  9452. literals[offsetLiterals++] = 0;
  9453. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize), offsetLiterals);
  9454. offsetBytes += lineSize;
  9455. offsetLiterals += lineSize;
  9456. }
  9457. if (kind === _util.ImageKind.GRAYSCALE_1BPP && isMask) {
  9458. offsetLiterals = 0;
  9459. for (let y = 0; y < height; y++) {
  9460. offsetLiterals++;
  9461. for (let i = 0; i < lineSize; i++) {
  9462. literals[offsetLiterals++] ^= 0xff;
  9463. }
  9464. }
  9465. }
  9466. const ihdr = new Uint8Array([width >> 24 & 0xff, width >> 16 & 0xff, width >> 8 & 0xff, width & 0xff, height >> 24 & 0xff, height >> 16 & 0xff, height >> 8 & 0xff, height & 0xff, bitDepth, colorType, 0x00, 0x00, 0x00]);
  9467. const idat = deflateSync(literals);
  9468. const pngLength = PNG_HEADER.length + CHUNK_WRAPPER_SIZE * 3 + ihdr.length + idat.length;
  9469. const data = new Uint8Array(pngLength);
  9470. let offset = 0;
  9471. data.set(PNG_HEADER, offset);
  9472. offset += PNG_HEADER.length;
  9473. writePngChunk("IHDR", ihdr, data, offset);
  9474. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  9475. writePngChunk("IDATA", idat, data, offset);
  9476. offset += CHUNK_WRAPPER_SIZE + idat.length;
  9477. writePngChunk("IEND", new Uint8Array(0), data, offset);
  9478. return (0, _util.createObjectURL)(data, "image/png", forceDataSchema);
  9479. }
  9480. return function convertImgDataToPng(imgData, forceDataSchema, isMask) {
  9481. const kind = imgData.kind === undefined ? _util.ImageKind.GRAYSCALE_1BPP : imgData.kind;
  9482. return encode(imgData, kind, forceDataSchema, isMask);
  9483. };
  9484. }();
  9485. class SVGExtraState {
  9486. constructor() {
  9487. this.fontSizeScale = 1;
  9488. this.fontWeight = SVG_DEFAULTS.fontWeight;
  9489. this.fontSize = 0;
  9490. this.textMatrix = _util.IDENTITY_MATRIX;
  9491. this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
  9492. this.leading = 0;
  9493. this.textRenderingMode = _util.TextRenderingMode.FILL;
  9494. this.textMatrixScale = 1;
  9495. this.x = 0;
  9496. this.y = 0;
  9497. this.lineX = 0;
  9498. this.lineY = 0;
  9499. this.charSpacing = 0;
  9500. this.wordSpacing = 0;
  9501. this.textHScale = 1;
  9502. this.textRise = 0;
  9503. this.fillColor = SVG_DEFAULTS.fillColor;
  9504. this.strokeColor = "#000000";
  9505. this.fillAlpha = 1;
  9506. this.strokeAlpha = 1;
  9507. this.lineWidth = 1;
  9508. this.lineJoin = "";
  9509. this.lineCap = "";
  9510. this.miterLimit = 0;
  9511. this.dashArray = [];
  9512. this.dashPhase = 0;
  9513. this.dependencies = [];
  9514. this.activeClipUrl = null;
  9515. this.clipGroup = null;
  9516. this.maskId = "";
  9517. }
  9518. clone() {
  9519. return Object.create(this);
  9520. }
  9521. setCurrentPoint(x, y) {
  9522. this.x = x;
  9523. this.y = y;
  9524. }
  9525. }
  9526. function opListToTree(opList) {
  9527. let opTree = [];
  9528. const tmp = [];
  9529. for (const opListElement of opList) {
  9530. if (opListElement.fn === "save") {
  9531. opTree.push({
  9532. fnId: 92,
  9533. fn: "group",
  9534. items: []
  9535. });
  9536. tmp.push(opTree);
  9537. opTree = opTree[opTree.length - 1].items;
  9538. continue;
  9539. }
  9540. if (opListElement.fn === "restore") {
  9541. opTree = tmp.pop();
  9542. } else {
  9543. opTree.push(opListElement);
  9544. }
  9545. }
  9546. return opTree;
  9547. }
  9548. function pf(value) {
  9549. if (Number.isInteger(value)) {
  9550. return value.toString();
  9551. }
  9552. const s = value.toFixed(10);
  9553. let i = s.length - 1;
  9554. if (s[i] !== "0") {
  9555. return s;
  9556. }
  9557. do {
  9558. i--;
  9559. } while (s[i] === "0");
  9560. return s.substring(0, s[i] === "." ? i : i + 1);
  9561. }
  9562. function pm(m) {
  9563. if (m[4] === 0 && m[5] === 0) {
  9564. if (m[1] === 0 && m[2] === 0) {
  9565. if (m[0] === 1 && m[3] === 1) {
  9566. return "";
  9567. }
  9568. return `scale(${pf(m[0])} ${pf(m[3])})`;
  9569. }
  9570. if (m[0] === m[3] && m[1] === -m[2]) {
  9571. const a = Math.acos(m[0]) * 180 / Math.PI;
  9572. return `rotate(${pf(a)})`;
  9573. }
  9574. } else {
  9575. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  9576. return `translate(${pf(m[4])} ${pf(m[5])})`;
  9577. }
  9578. }
  9579. return `matrix(${pf(m[0])} ${pf(m[1])} ${pf(m[2])} ${pf(m[3])} ${pf(m[4])} ` + `${pf(m[5])})`;
  9580. }
  9581. let clipCount = 0;
  9582. let maskCount = 0;
  9583. let shadingCount = 0;
  9584. exports.SVGGraphics = SVGGraphics = class SVGGraphics {
  9585. constructor(commonObjs, objs, forceDataSchema = false) {
  9586. this.svgFactory = new _display_utils.DOMSVGFactory();
  9587. this.current = new SVGExtraState();
  9588. this.transformMatrix = _util.IDENTITY_MATRIX;
  9589. this.transformStack = [];
  9590. this.extraStack = [];
  9591. this.commonObjs = commonObjs;
  9592. this.objs = objs;
  9593. this.pendingClip = null;
  9594. this.pendingEOFill = false;
  9595. this.embedFonts = false;
  9596. this.embeddedFonts = Object.create(null);
  9597. this.cssStyle = null;
  9598. this.forceDataSchema = !!forceDataSchema;
  9599. this._operatorIdMapping = [];
  9600. for (const op in _util.OPS) {
  9601. this._operatorIdMapping[_util.OPS[op]] = op;
  9602. }
  9603. }
  9604. save() {
  9605. this.transformStack.push(this.transformMatrix);
  9606. const old = this.current;
  9607. this.extraStack.push(old);
  9608. this.current = old.clone();
  9609. }
  9610. restore() {
  9611. this.transformMatrix = this.transformStack.pop();
  9612. this.current = this.extraStack.pop();
  9613. this.pendingClip = null;
  9614. this.tgrp = null;
  9615. }
  9616. group(items) {
  9617. this.save();
  9618. this.executeOpTree(items);
  9619. this.restore();
  9620. }
  9621. loadDependencies(operatorList) {
  9622. const fnArray = operatorList.fnArray;
  9623. const argsArray = operatorList.argsArray;
  9624. for (let i = 0, ii = fnArray.length; i < ii; i++) {
  9625. if (fnArray[i] !== _util.OPS.dependency) {
  9626. continue;
  9627. }
  9628. for (const obj of argsArray[i]) {
  9629. const objsPool = obj.startsWith("g_") ? this.commonObjs : this.objs;
  9630. const promise = new Promise(resolve => {
  9631. objsPool.get(obj, resolve);
  9632. });
  9633. this.current.dependencies.push(promise);
  9634. }
  9635. }
  9636. return Promise.all(this.current.dependencies);
  9637. }
  9638. transform(a, b, c, d, e, f) {
  9639. const transformMatrix = [a, b, c, d, e, f];
  9640. this.transformMatrix = _util.Util.transform(this.transformMatrix, transformMatrix);
  9641. this.tgrp = null;
  9642. }
  9643. getSVG(operatorList, viewport) {
  9644. this.viewport = viewport;
  9645. const svgElement = this._initialize(viewport);
  9646. return this.loadDependencies(operatorList).then(() => {
  9647. this.transformMatrix = _util.IDENTITY_MATRIX;
  9648. this.executeOpTree(this.convertOpList(operatorList));
  9649. return svgElement;
  9650. });
  9651. }
  9652. convertOpList(operatorList) {
  9653. const operatorIdMapping = this._operatorIdMapping;
  9654. const argsArray = operatorList.argsArray;
  9655. const fnArray = operatorList.fnArray;
  9656. const opList = [];
  9657. for (let i = 0, ii = fnArray.length; i < ii; i++) {
  9658. const fnId = fnArray[i];
  9659. opList.push({
  9660. fnId,
  9661. fn: operatorIdMapping[fnId],
  9662. args: argsArray[i]
  9663. });
  9664. }
  9665. return opListToTree(opList);
  9666. }
  9667. executeOpTree(opTree) {
  9668. for (const opTreeElement of opTree) {
  9669. const fn = opTreeElement.fn;
  9670. const fnId = opTreeElement.fnId;
  9671. const args = opTreeElement.args;
  9672. switch (fnId | 0) {
  9673. case _util.OPS.beginText:
  9674. this.beginText();
  9675. break;
  9676. case _util.OPS.dependency:
  9677. break;
  9678. case _util.OPS.setLeading:
  9679. this.setLeading(args);
  9680. break;
  9681. case _util.OPS.setLeadingMoveText:
  9682. this.setLeadingMoveText(args[0], args[1]);
  9683. break;
  9684. case _util.OPS.setFont:
  9685. this.setFont(args);
  9686. break;
  9687. case _util.OPS.showText:
  9688. this.showText(args[0]);
  9689. break;
  9690. case _util.OPS.showSpacedText:
  9691. this.showText(args[0]);
  9692. break;
  9693. case _util.OPS.endText:
  9694. this.endText();
  9695. break;
  9696. case _util.OPS.moveText:
  9697. this.moveText(args[0], args[1]);
  9698. break;
  9699. case _util.OPS.setCharSpacing:
  9700. this.setCharSpacing(args[0]);
  9701. break;
  9702. case _util.OPS.setWordSpacing:
  9703. this.setWordSpacing(args[0]);
  9704. break;
  9705. case _util.OPS.setHScale:
  9706. this.setHScale(args[0]);
  9707. break;
  9708. case _util.OPS.setTextMatrix:
  9709. this.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
  9710. break;
  9711. case _util.OPS.setTextRise:
  9712. this.setTextRise(args[0]);
  9713. break;
  9714. case _util.OPS.setTextRenderingMode:
  9715. this.setTextRenderingMode(args[0]);
  9716. break;
  9717. case _util.OPS.setLineWidth:
  9718. this.setLineWidth(args[0]);
  9719. break;
  9720. case _util.OPS.setLineJoin:
  9721. this.setLineJoin(args[0]);
  9722. break;
  9723. case _util.OPS.setLineCap:
  9724. this.setLineCap(args[0]);
  9725. break;
  9726. case _util.OPS.setMiterLimit:
  9727. this.setMiterLimit(args[0]);
  9728. break;
  9729. case _util.OPS.setFillRGBColor:
  9730. this.setFillRGBColor(args[0], args[1], args[2]);
  9731. break;
  9732. case _util.OPS.setStrokeRGBColor:
  9733. this.setStrokeRGBColor(args[0], args[1], args[2]);
  9734. break;
  9735. case _util.OPS.setStrokeColorN:
  9736. this.setStrokeColorN(args);
  9737. break;
  9738. case _util.OPS.setFillColorN:
  9739. this.setFillColorN(args);
  9740. break;
  9741. case _util.OPS.shadingFill:
  9742. this.shadingFill(args[0]);
  9743. break;
  9744. case _util.OPS.setDash:
  9745. this.setDash(args[0], args[1]);
  9746. break;
  9747. case _util.OPS.setRenderingIntent:
  9748. this.setRenderingIntent(args[0]);
  9749. break;
  9750. case _util.OPS.setFlatness:
  9751. this.setFlatness(args[0]);
  9752. break;
  9753. case _util.OPS.setGState:
  9754. this.setGState(args[0]);
  9755. break;
  9756. case _util.OPS.fill:
  9757. this.fill();
  9758. break;
  9759. case _util.OPS.eoFill:
  9760. this.eoFill();
  9761. break;
  9762. case _util.OPS.stroke:
  9763. this.stroke();
  9764. break;
  9765. case _util.OPS.fillStroke:
  9766. this.fillStroke();
  9767. break;
  9768. case _util.OPS.eoFillStroke:
  9769. this.eoFillStroke();
  9770. break;
  9771. case _util.OPS.clip:
  9772. this.clip("nonzero");
  9773. break;
  9774. case _util.OPS.eoClip:
  9775. this.clip("evenodd");
  9776. break;
  9777. case _util.OPS.paintSolidColorImageMask:
  9778. this.paintSolidColorImageMask();
  9779. break;
  9780. case _util.OPS.paintImageXObject:
  9781. this.paintImageXObject(args[0]);
  9782. break;
  9783. case _util.OPS.paintInlineImageXObject:
  9784. this.paintInlineImageXObject(args[0]);
  9785. break;
  9786. case _util.OPS.paintImageMaskXObject:
  9787. this.paintImageMaskXObject(args[0]);
  9788. break;
  9789. case _util.OPS.paintFormXObjectBegin:
  9790. this.paintFormXObjectBegin(args[0], args[1]);
  9791. break;
  9792. case _util.OPS.paintFormXObjectEnd:
  9793. this.paintFormXObjectEnd();
  9794. break;
  9795. case _util.OPS.closePath:
  9796. this.closePath();
  9797. break;
  9798. case _util.OPS.closeStroke:
  9799. this.closeStroke();
  9800. break;
  9801. case _util.OPS.closeFillStroke:
  9802. this.closeFillStroke();
  9803. break;
  9804. case _util.OPS.closeEOFillStroke:
  9805. this.closeEOFillStroke();
  9806. break;
  9807. case _util.OPS.nextLine:
  9808. this.nextLine();
  9809. break;
  9810. case _util.OPS.transform:
  9811. this.transform(args[0], args[1], args[2], args[3], args[4], args[5]);
  9812. break;
  9813. case _util.OPS.constructPath:
  9814. this.constructPath(args[0], args[1]);
  9815. break;
  9816. case _util.OPS.endPath:
  9817. this.endPath();
  9818. break;
  9819. case 92:
  9820. this.group(opTreeElement.items);
  9821. break;
  9822. default:
  9823. (0, _util.warn)(`Unimplemented operator ${fn}`);
  9824. break;
  9825. }
  9826. }
  9827. }
  9828. setWordSpacing(wordSpacing) {
  9829. this.current.wordSpacing = wordSpacing;
  9830. }
  9831. setCharSpacing(charSpacing) {
  9832. this.current.charSpacing = charSpacing;
  9833. }
  9834. nextLine() {
  9835. this.moveText(0, this.current.leading);
  9836. }
  9837. setTextMatrix(a, b, c, d, e, f) {
  9838. const current = this.current;
  9839. current.textMatrix = current.lineMatrix = [a, b, c, d, e, f];
  9840. current.textMatrixScale = Math.hypot(a, b);
  9841. current.x = current.lineX = 0;
  9842. current.y = current.lineY = 0;
  9843. current.xcoords = [];
  9844. current.ycoords = [];
  9845. current.tspan = this.svgFactory.createElement("svg:tspan");
  9846. current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
  9847. current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
  9848. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  9849. current.txtElement = this.svgFactory.createElement("svg:text");
  9850. current.txtElement.appendChild(current.tspan);
  9851. }
  9852. beginText() {
  9853. const current = this.current;
  9854. current.x = current.lineX = 0;
  9855. current.y = current.lineY = 0;
  9856. current.textMatrix = _util.IDENTITY_MATRIX;
  9857. current.lineMatrix = _util.IDENTITY_MATRIX;
  9858. current.textMatrixScale = 1;
  9859. current.tspan = this.svgFactory.createElement("svg:tspan");
  9860. current.txtElement = this.svgFactory.createElement("svg:text");
  9861. current.txtgrp = this.svgFactory.createElement("svg:g");
  9862. current.xcoords = [];
  9863. current.ycoords = [];
  9864. }
  9865. moveText(x, y) {
  9866. const current = this.current;
  9867. current.x = current.lineX += x;
  9868. current.y = current.lineY += y;
  9869. current.xcoords = [];
  9870. current.ycoords = [];
  9871. current.tspan = this.svgFactory.createElement("svg:tspan");
  9872. current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
  9873. current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
  9874. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  9875. }
  9876. showText(glyphs) {
  9877. const current = this.current;
  9878. const font = current.font;
  9879. const fontSize = current.fontSize;
  9880. if (fontSize === 0) {
  9881. return;
  9882. }
  9883. const fontSizeScale = current.fontSizeScale;
  9884. const charSpacing = current.charSpacing;
  9885. const wordSpacing = current.wordSpacing;
  9886. const fontDirection = current.fontDirection;
  9887. const textHScale = current.textHScale * fontDirection;
  9888. const vertical = font.vertical;
  9889. const spacingDir = vertical ? 1 : -1;
  9890. const defaultVMetrics = font.defaultVMetrics;
  9891. const widthAdvanceScale = fontSize * current.fontMatrix[0];
  9892. let x = 0;
  9893. for (const glyph of glyphs) {
  9894. if (glyph === null) {
  9895. x += fontDirection * wordSpacing;
  9896. continue;
  9897. } else if ((0, _util.isNum)(glyph)) {
  9898. x += spacingDir * glyph * fontSize / 1000;
  9899. continue;
  9900. }
  9901. const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  9902. const character = glyph.fontChar;
  9903. let scaledX, scaledY;
  9904. let width = glyph.width;
  9905. if (vertical) {
  9906. let vx;
  9907. const vmetric = glyph.vmetric || defaultVMetrics;
  9908. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  9909. vx = -vx * widthAdvanceScale;
  9910. const vy = vmetric[2] * widthAdvanceScale;
  9911. width = vmetric ? -vmetric[0] : width;
  9912. scaledX = vx / fontSizeScale;
  9913. scaledY = (x + vy) / fontSizeScale;
  9914. } else {
  9915. scaledX = x / fontSizeScale;
  9916. scaledY = 0;
  9917. }
  9918. if (glyph.isInFont || font.missingFile) {
  9919. current.xcoords.push(current.x + scaledX);
  9920. if (vertical) {
  9921. current.ycoords.push(-current.y + scaledY);
  9922. }
  9923. current.tspan.textContent += character;
  9924. } else {}
  9925. let charWidth;
  9926. if (vertical) {
  9927. charWidth = width * widthAdvanceScale - spacing * fontDirection;
  9928. } else {
  9929. charWidth = width * widthAdvanceScale + spacing * fontDirection;
  9930. }
  9931. x += charWidth;
  9932. }
  9933. current.tspan.setAttributeNS(null, "x", current.xcoords.map(pf).join(" "));
  9934. if (vertical) {
  9935. current.tspan.setAttributeNS(null, "y", current.ycoords.map(pf).join(" "));
  9936. } else {
  9937. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  9938. }
  9939. if (vertical) {
  9940. current.y -= x;
  9941. } else {
  9942. current.x += x * textHScale;
  9943. }
  9944. current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
  9945. current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
  9946. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  9947. current.tspan.setAttributeNS(null, "font-style", current.fontStyle);
  9948. }
  9949. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  9950. current.tspan.setAttributeNS(null, "font-weight", current.fontWeight);
  9951. }
  9952. const fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  9953. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  9954. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  9955. current.tspan.setAttributeNS(null, "fill", current.fillColor);
  9956. }
  9957. if (current.fillAlpha < 1) {
  9958. current.tspan.setAttributeNS(null, "fill-opacity", current.fillAlpha);
  9959. }
  9960. } else if (current.textRenderingMode === _util.TextRenderingMode.ADD_TO_PATH) {
  9961. current.tspan.setAttributeNS(null, "fill", "transparent");
  9962. } else {
  9963. current.tspan.setAttributeNS(null, "fill", "none");
  9964. }
  9965. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  9966. const lineWidthScale = 1 / (current.textMatrixScale || 1);
  9967. this._setStrokeAttributes(current.tspan, lineWidthScale);
  9968. }
  9969. let textMatrix = current.textMatrix;
  9970. if (current.textRise !== 0) {
  9971. textMatrix = textMatrix.slice();
  9972. textMatrix[5] += current.textRise;
  9973. }
  9974. current.txtElement.setAttributeNS(null, "transform", `${pm(textMatrix)} scale(${pf(textHScale)}, -1)`);
  9975. current.txtElement.setAttributeNS(XML_NS, "xml:space", "preserve");
  9976. current.txtElement.appendChild(current.tspan);
  9977. current.txtgrp.appendChild(current.txtElement);
  9978. this._ensureTransformGroup().appendChild(current.txtElement);
  9979. }
  9980. setLeadingMoveText(x, y) {
  9981. this.setLeading(-y);
  9982. this.moveText(x, y);
  9983. }
  9984. addFontStyle(fontObj) {
  9985. if (!fontObj.data) {
  9986. throw new Error("addFontStyle: No font data available, " + 'ensure that the "fontExtraProperties" API parameter is set.');
  9987. }
  9988. if (!this.cssStyle) {
  9989. this.cssStyle = this.svgFactory.createElement("svg:style");
  9990. this.cssStyle.setAttributeNS(null, "type", "text/css");
  9991. this.defs.appendChild(this.cssStyle);
  9992. }
  9993. const url = (0, _util.createObjectURL)(fontObj.data, fontObj.mimetype, this.forceDataSchema);
  9994. this.cssStyle.textContent += `@font-face { font-family: "${fontObj.loadedName}";` + ` src: url(${url}); }\n`;
  9995. }
  9996. setFont(details) {
  9997. const current = this.current;
  9998. const fontObj = this.commonObjs.get(details[0]);
  9999. let size = details[1];
  10000. current.font = fontObj;
  10001. if (this.embedFonts && !fontObj.missingFile && !this.embeddedFonts[fontObj.loadedName]) {
  10002. this.addFontStyle(fontObj);
  10003. this.embeddedFonts[fontObj.loadedName] = fontObj;
  10004. }
  10005. current.fontMatrix = fontObj.fontMatrix || _util.FONT_IDENTITY_MATRIX;
  10006. let bold = "normal";
  10007. if (fontObj.black) {
  10008. bold = "900";
  10009. } else if (fontObj.bold) {
  10010. bold = "bold";
  10011. }
  10012. const italic = fontObj.italic ? "italic" : "normal";
  10013. if (size < 0) {
  10014. size = -size;
  10015. current.fontDirection = -1;
  10016. } else {
  10017. current.fontDirection = 1;
  10018. }
  10019. current.fontSize = size;
  10020. current.fontFamily = fontObj.loadedName;
  10021. current.fontWeight = bold;
  10022. current.fontStyle = italic;
  10023. current.tspan = this.svgFactory.createElement("svg:tspan");
  10024. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  10025. current.xcoords = [];
  10026. current.ycoords = [];
  10027. }
  10028. endText() {
  10029. const current = this.current;
  10030. if (current.textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG && current.txtElement?.hasChildNodes()) {
  10031. current.element = current.txtElement;
  10032. this.clip("nonzero");
  10033. this.endPath();
  10034. }
  10035. }
  10036. setLineWidth(width) {
  10037. if (width > 0) {
  10038. this.current.lineWidth = width;
  10039. }
  10040. }
  10041. setLineCap(style) {
  10042. this.current.lineCap = LINE_CAP_STYLES[style];
  10043. }
  10044. setLineJoin(style) {
  10045. this.current.lineJoin = LINE_JOIN_STYLES[style];
  10046. }
  10047. setMiterLimit(limit) {
  10048. this.current.miterLimit = limit;
  10049. }
  10050. setStrokeAlpha(strokeAlpha) {
  10051. this.current.strokeAlpha = strokeAlpha;
  10052. }
  10053. setStrokeRGBColor(r, g, b) {
  10054. this.current.strokeColor = _util.Util.makeHexColor(r, g, b);
  10055. }
  10056. setFillAlpha(fillAlpha) {
  10057. this.current.fillAlpha = fillAlpha;
  10058. }
  10059. setFillRGBColor(r, g, b) {
  10060. this.current.fillColor = _util.Util.makeHexColor(r, g, b);
  10061. this.current.tspan = this.svgFactory.createElement("svg:tspan");
  10062. this.current.xcoords = [];
  10063. this.current.ycoords = [];
  10064. }
  10065. setStrokeColorN(args) {
  10066. this.current.strokeColor = this._makeColorN_Pattern(args);
  10067. }
  10068. setFillColorN(args) {
  10069. this.current.fillColor = this._makeColorN_Pattern(args);
  10070. }
  10071. shadingFill(args) {
  10072. const width = this.viewport.width;
  10073. const height = this.viewport.height;
  10074. const inv = _util.Util.inverseTransform(this.transformMatrix);
  10075. const bl = _util.Util.applyTransform([0, 0], inv);
  10076. const br = _util.Util.applyTransform([0, height], inv);
  10077. const ul = _util.Util.applyTransform([width, 0], inv);
  10078. const ur = _util.Util.applyTransform([width, height], inv);
  10079. const x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  10080. const y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  10081. const x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  10082. const y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  10083. const rect = this.svgFactory.createElement("svg:rect");
  10084. rect.setAttributeNS(null, "x", x0);
  10085. rect.setAttributeNS(null, "y", y0);
  10086. rect.setAttributeNS(null, "width", x1 - x0);
  10087. rect.setAttributeNS(null, "height", y1 - y0);
  10088. rect.setAttributeNS(null, "fill", this._makeShadingPattern(args));
  10089. if (this.current.fillAlpha < 1) {
  10090. rect.setAttributeNS(null, "fill-opacity", this.current.fillAlpha);
  10091. }
  10092. this._ensureTransformGroup().appendChild(rect);
  10093. }
  10094. _makeColorN_Pattern(args) {
  10095. if (args[0] === "TilingPattern") {
  10096. return this._makeTilingPattern(args);
  10097. }
  10098. return this._makeShadingPattern(args);
  10099. }
  10100. _makeTilingPattern(args) {
  10101. const color = args[1];
  10102. const operatorList = args[2];
  10103. const matrix = args[3] || _util.IDENTITY_MATRIX;
  10104. const [x0, y0, x1, y1] = args[4];
  10105. const xstep = args[5];
  10106. const ystep = args[6];
  10107. const paintType = args[7];
  10108. const tilingId = `shading${shadingCount++}`;
  10109. const [tx0, ty0] = _util.Util.applyTransform([x0, y0], matrix);
  10110. const [tx1, ty1] = _util.Util.applyTransform([x1, y1], matrix);
  10111. const [xscale, yscale] = _util.Util.singularValueDecompose2dScale(matrix);
  10112. const txstep = xstep * xscale;
  10113. const tystep = ystep * yscale;
  10114. const tiling = this.svgFactory.createElement("svg:pattern");
  10115. tiling.setAttributeNS(null, "id", tilingId);
  10116. tiling.setAttributeNS(null, "patternUnits", "userSpaceOnUse");
  10117. tiling.setAttributeNS(null, "width", txstep);
  10118. tiling.setAttributeNS(null, "height", tystep);
  10119. tiling.setAttributeNS(null, "x", `${tx0}`);
  10120. tiling.setAttributeNS(null, "y", `${ty0}`);
  10121. const svg = this.svg;
  10122. const transformMatrix = this.transformMatrix;
  10123. const fillColor = this.current.fillColor;
  10124. const strokeColor = this.current.strokeColor;
  10125. const bbox = this.svgFactory.create(tx1 - tx0, ty1 - ty0);
  10126. this.svg = bbox;
  10127. this.transformMatrix = matrix;
  10128. if (paintType === 2) {
  10129. const cssColor = _util.Util.makeHexColor(...color);
  10130. this.current.fillColor = cssColor;
  10131. this.current.strokeColor = cssColor;
  10132. }
  10133. this.executeOpTree(this.convertOpList(operatorList));
  10134. this.svg = svg;
  10135. this.transformMatrix = transformMatrix;
  10136. this.current.fillColor = fillColor;
  10137. this.current.strokeColor = strokeColor;
  10138. tiling.appendChild(bbox.childNodes[0]);
  10139. this.defs.appendChild(tiling);
  10140. return `url(#${tilingId})`;
  10141. }
  10142. _makeShadingPattern(args) {
  10143. switch (args[0]) {
  10144. case "RadialAxial":
  10145. const shadingId = `shading${shadingCount++}`;
  10146. const colorStops = args[3];
  10147. let gradient;
  10148. switch (args[1]) {
  10149. case "axial":
  10150. const point0 = args[4];
  10151. const point1 = args[5];
  10152. gradient = this.svgFactory.createElement("svg:linearGradient");
  10153. gradient.setAttributeNS(null, "id", shadingId);
  10154. gradient.setAttributeNS(null, "gradientUnits", "userSpaceOnUse");
  10155. gradient.setAttributeNS(null, "x1", point0[0]);
  10156. gradient.setAttributeNS(null, "y1", point0[1]);
  10157. gradient.setAttributeNS(null, "x2", point1[0]);
  10158. gradient.setAttributeNS(null, "y2", point1[1]);
  10159. break;
  10160. case "radial":
  10161. const focalPoint = args[4];
  10162. const circlePoint = args[5];
  10163. const focalRadius = args[6];
  10164. const circleRadius = args[7];
  10165. gradient = this.svgFactory.createElement("svg:radialGradient");
  10166. gradient.setAttributeNS(null, "id", shadingId);
  10167. gradient.setAttributeNS(null, "gradientUnits", "userSpaceOnUse");
  10168. gradient.setAttributeNS(null, "cx", circlePoint[0]);
  10169. gradient.setAttributeNS(null, "cy", circlePoint[1]);
  10170. gradient.setAttributeNS(null, "r", circleRadius);
  10171. gradient.setAttributeNS(null, "fx", focalPoint[0]);
  10172. gradient.setAttributeNS(null, "fy", focalPoint[1]);
  10173. gradient.setAttributeNS(null, "fr", focalRadius);
  10174. break;
  10175. default:
  10176. throw new Error(`Unknown RadialAxial type: ${args[1]}`);
  10177. }
  10178. for (const colorStop of colorStops) {
  10179. const stop = this.svgFactory.createElement("svg:stop");
  10180. stop.setAttributeNS(null, "offset", colorStop[0]);
  10181. stop.setAttributeNS(null, "stop-color", colorStop[1]);
  10182. gradient.appendChild(stop);
  10183. }
  10184. this.defs.appendChild(gradient);
  10185. return `url(#${shadingId})`;
  10186. case "Mesh":
  10187. (0, _util.warn)("Unimplemented pattern Mesh");
  10188. return null;
  10189. case "Dummy":
  10190. return "hotpink";
  10191. default:
  10192. throw new Error(`Unknown IR type: ${args[0]}`);
  10193. }
  10194. }
  10195. setDash(dashArray, dashPhase) {
  10196. this.current.dashArray = dashArray;
  10197. this.current.dashPhase = dashPhase;
  10198. }
  10199. constructPath(ops, args) {
  10200. const current = this.current;
  10201. let x = current.x,
  10202. y = current.y;
  10203. let d = [];
  10204. let j = 0;
  10205. for (const op of ops) {
  10206. switch (op | 0) {
  10207. case _util.OPS.rectangle:
  10208. x = args[j++];
  10209. y = args[j++];
  10210. const width = args[j++];
  10211. const height = args[j++];
  10212. const xw = x + width;
  10213. const yh = y + height;
  10214. d.push("M", pf(x), pf(y), "L", pf(xw), pf(y), "L", pf(xw), pf(yh), "L", pf(x), pf(yh), "Z");
  10215. break;
  10216. case _util.OPS.moveTo:
  10217. x = args[j++];
  10218. y = args[j++];
  10219. d.push("M", pf(x), pf(y));
  10220. break;
  10221. case _util.OPS.lineTo:
  10222. x = args[j++];
  10223. y = args[j++];
  10224. d.push("L", pf(x), pf(y));
  10225. break;
  10226. case _util.OPS.curveTo:
  10227. x = args[j + 4];
  10228. y = args[j + 5];
  10229. d.push("C", pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]), pf(x), pf(y));
  10230. j += 6;
  10231. break;
  10232. case _util.OPS.curveTo2:
  10233. d.push("C", pf(x), pf(y), pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]));
  10234. x = args[j + 2];
  10235. y = args[j + 3];
  10236. j += 4;
  10237. break;
  10238. case _util.OPS.curveTo3:
  10239. x = args[j + 2];
  10240. y = args[j + 3];
  10241. d.push("C", pf(args[j]), pf(args[j + 1]), pf(x), pf(y), pf(x), pf(y));
  10242. j += 4;
  10243. break;
  10244. case _util.OPS.closePath:
  10245. d.push("Z");
  10246. break;
  10247. }
  10248. }
  10249. d = d.join(" ");
  10250. if (current.path && ops.length > 0 && ops[0] !== _util.OPS.rectangle && ops[0] !== _util.OPS.moveTo) {
  10251. d = current.path.getAttributeNS(null, "d") + d;
  10252. } else {
  10253. current.path = this.svgFactory.createElement("svg:path");
  10254. this._ensureTransformGroup().appendChild(current.path);
  10255. }
  10256. current.path.setAttributeNS(null, "d", d);
  10257. current.path.setAttributeNS(null, "fill", "none");
  10258. current.element = current.path;
  10259. current.setCurrentPoint(x, y);
  10260. }
  10261. endPath() {
  10262. const current = this.current;
  10263. current.path = null;
  10264. if (!this.pendingClip) {
  10265. return;
  10266. }
  10267. if (!current.element) {
  10268. this.pendingClip = null;
  10269. return;
  10270. }
  10271. const clipId = `clippath${clipCount++}`;
  10272. const clipPath = this.svgFactory.createElement("svg:clipPath");
  10273. clipPath.setAttributeNS(null, "id", clipId);
  10274. clipPath.setAttributeNS(null, "transform", pm(this.transformMatrix));
  10275. const clipElement = current.element.cloneNode(true);
  10276. if (this.pendingClip === "evenodd") {
  10277. clipElement.setAttributeNS(null, "clip-rule", "evenodd");
  10278. } else {
  10279. clipElement.setAttributeNS(null, "clip-rule", "nonzero");
  10280. }
  10281. this.pendingClip = null;
  10282. clipPath.appendChild(clipElement);
  10283. this.defs.appendChild(clipPath);
  10284. if (current.activeClipUrl) {
  10285. current.clipGroup = null;
  10286. this.extraStack.forEach(function (prev) {
  10287. prev.clipGroup = null;
  10288. });
  10289. clipPath.setAttributeNS(null, "clip-path", current.activeClipUrl);
  10290. }
  10291. current.activeClipUrl = `url(#${clipId})`;
  10292. this.tgrp = null;
  10293. }
  10294. clip(type) {
  10295. this.pendingClip = type;
  10296. }
  10297. closePath() {
  10298. const current = this.current;
  10299. if (current.path) {
  10300. const d = `${current.path.getAttributeNS(null, "d")}Z`;
  10301. current.path.setAttributeNS(null, "d", d);
  10302. }
  10303. }
  10304. setLeading(leading) {
  10305. this.current.leading = -leading;
  10306. }
  10307. setTextRise(textRise) {
  10308. this.current.textRise = textRise;
  10309. }
  10310. setTextRenderingMode(textRenderingMode) {
  10311. this.current.textRenderingMode = textRenderingMode;
  10312. }
  10313. setHScale(scale) {
  10314. this.current.textHScale = scale / 100;
  10315. }
  10316. setRenderingIntent(intent) {}
  10317. setFlatness(flatness) {}
  10318. setGState(states) {
  10319. for (const [key, value] of states) {
  10320. switch (key) {
  10321. case "LW":
  10322. this.setLineWidth(value);
  10323. break;
  10324. case "LC":
  10325. this.setLineCap(value);
  10326. break;
  10327. case "LJ":
  10328. this.setLineJoin(value);
  10329. break;
  10330. case "ML":
  10331. this.setMiterLimit(value);
  10332. break;
  10333. case "D":
  10334. this.setDash(value[0], value[1]);
  10335. break;
  10336. case "RI":
  10337. this.setRenderingIntent(value);
  10338. break;
  10339. case "FL":
  10340. this.setFlatness(value);
  10341. break;
  10342. case "Font":
  10343. this.setFont(value);
  10344. break;
  10345. case "CA":
  10346. this.setStrokeAlpha(value);
  10347. break;
  10348. case "ca":
  10349. this.setFillAlpha(value);
  10350. break;
  10351. default:
  10352. (0, _util.warn)(`Unimplemented graphic state operator ${key}`);
  10353. break;
  10354. }
  10355. }
  10356. }
  10357. fill() {
  10358. const current = this.current;
  10359. if (current.element) {
  10360. current.element.setAttributeNS(null, "fill", current.fillColor);
  10361. current.element.setAttributeNS(null, "fill-opacity", current.fillAlpha);
  10362. this.endPath();
  10363. }
  10364. }
  10365. stroke() {
  10366. const current = this.current;
  10367. if (current.element) {
  10368. this._setStrokeAttributes(current.element);
  10369. current.element.setAttributeNS(null, "fill", "none");
  10370. this.endPath();
  10371. }
  10372. }
  10373. _setStrokeAttributes(element, lineWidthScale = 1) {
  10374. const current = this.current;
  10375. let dashArray = current.dashArray;
  10376. if (lineWidthScale !== 1 && dashArray.length > 0) {
  10377. dashArray = dashArray.map(function (value) {
  10378. return lineWidthScale * value;
  10379. });
  10380. }
  10381. element.setAttributeNS(null, "stroke", current.strokeColor);
  10382. element.setAttributeNS(null, "stroke-opacity", current.strokeAlpha);
  10383. element.setAttributeNS(null, "stroke-miterlimit", pf(current.miterLimit));
  10384. element.setAttributeNS(null, "stroke-linecap", current.lineCap);
  10385. element.setAttributeNS(null, "stroke-linejoin", current.lineJoin);
  10386. element.setAttributeNS(null, "stroke-width", pf(lineWidthScale * current.lineWidth) + "px");
  10387. element.setAttributeNS(null, "stroke-dasharray", dashArray.map(pf).join(" "));
  10388. element.setAttributeNS(null, "stroke-dashoffset", pf(lineWidthScale * current.dashPhase) + "px");
  10389. }
  10390. eoFill() {
  10391. if (this.current.element) {
  10392. this.current.element.setAttributeNS(null, "fill-rule", "evenodd");
  10393. }
  10394. this.fill();
  10395. }
  10396. fillStroke() {
  10397. this.stroke();
  10398. this.fill();
  10399. }
  10400. eoFillStroke() {
  10401. if (this.current.element) {
  10402. this.current.element.setAttributeNS(null, "fill-rule", "evenodd");
  10403. }
  10404. this.fillStroke();
  10405. }
  10406. closeStroke() {
  10407. this.closePath();
  10408. this.stroke();
  10409. }
  10410. closeFillStroke() {
  10411. this.closePath();
  10412. this.fillStroke();
  10413. }
  10414. closeEOFillStroke() {
  10415. this.closePath();
  10416. this.eoFillStroke();
  10417. }
  10418. paintSolidColorImageMask() {
  10419. const rect = this.svgFactory.createElement("svg:rect");
  10420. rect.setAttributeNS(null, "x", "0");
  10421. rect.setAttributeNS(null, "y", "0");
  10422. rect.setAttributeNS(null, "width", "1px");
  10423. rect.setAttributeNS(null, "height", "1px");
  10424. rect.setAttributeNS(null, "fill", this.current.fillColor);
  10425. this._ensureTransformGroup().appendChild(rect);
  10426. }
  10427. paintImageXObject(objId) {
  10428. const imgData = objId.startsWith("g_") ? this.commonObjs.get(objId) : this.objs.get(objId);
  10429. if (!imgData) {
  10430. (0, _util.warn)(`Dependent image with object ID ${objId} is not ready yet`);
  10431. return;
  10432. }
  10433. this.paintInlineImageXObject(imgData);
  10434. }
  10435. paintInlineImageXObject(imgData, mask) {
  10436. const width = imgData.width;
  10437. const height = imgData.height;
  10438. const imgSrc = convertImgDataToPng(imgData, this.forceDataSchema, !!mask);
  10439. const cliprect = this.svgFactory.createElement("svg:rect");
  10440. cliprect.setAttributeNS(null, "x", "0");
  10441. cliprect.setAttributeNS(null, "y", "0");
  10442. cliprect.setAttributeNS(null, "width", pf(width));
  10443. cliprect.setAttributeNS(null, "height", pf(height));
  10444. this.current.element = cliprect;
  10445. this.clip("nonzero");
  10446. const imgEl = this.svgFactory.createElement("svg:image");
  10447. imgEl.setAttributeNS(XLINK_NS, "xlink:href", imgSrc);
  10448. imgEl.setAttributeNS(null, "x", "0");
  10449. imgEl.setAttributeNS(null, "y", pf(-height));
  10450. imgEl.setAttributeNS(null, "width", pf(width) + "px");
  10451. imgEl.setAttributeNS(null, "height", pf(height) + "px");
  10452. imgEl.setAttributeNS(null, "transform", `scale(${pf(1 / width)} ${pf(-1 / height)})`);
  10453. if (mask) {
  10454. mask.appendChild(imgEl);
  10455. } else {
  10456. this._ensureTransformGroup().appendChild(imgEl);
  10457. }
  10458. }
  10459. paintImageMaskXObject(imgData) {
  10460. const current = this.current;
  10461. const width = imgData.width;
  10462. const height = imgData.height;
  10463. const fillColor = current.fillColor;
  10464. current.maskId = `mask${maskCount++}`;
  10465. const mask = this.svgFactory.createElement("svg:mask");
  10466. mask.setAttributeNS(null, "id", current.maskId);
  10467. const rect = this.svgFactory.createElement("svg:rect");
  10468. rect.setAttributeNS(null, "x", "0");
  10469. rect.setAttributeNS(null, "y", "0");
  10470. rect.setAttributeNS(null, "width", pf(width));
  10471. rect.setAttributeNS(null, "height", pf(height));
  10472. rect.setAttributeNS(null, "fill", fillColor);
  10473. rect.setAttributeNS(null, "mask", `url(#${current.maskId})`);
  10474. this.defs.appendChild(mask);
  10475. this._ensureTransformGroup().appendChild(rect);
  10476. this.paintInlineImageXObject(imgData, mask);
  10477. }
  10478. paintFormXObjectBegin(matrix, bbox) {
  10479. if (Array.isArray(matrix) && matrix.length === 6) {
  10480. this.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
  10481. }
  10482. if (bbox) {
  10483. const width = bbox[2] - bbox[0];
  10484. const height = bbox[3] - bbox[1];
  10485. const cliprect = this.svgFactory.createElement("svg:rect");
  10486. cliprect.setAttributeNS(null, "x", bbox[0]);
  10487. cliprect.setAttributeNS(null, "y", bbox[1]);
  10488. cliprect.setAttributeNS(null, "width", pf(width));
  10489. cliprect.setAttributeNS(null, "height", pf(height));
  10490. this.current.element = cliprect;
  10491. this.clip("nonzero");
  10492. this.endPath();
  10493. }
  10494. }
  10495. paintFormXObjectEnd() {}
  10496. _initialize(viewport) {
  10497. const svg = this.svgFactory.create(viewport.width, viewport.height);
  10498. const definitions = this.svgFactory.createElement("svg:defs");
  10499. svg.appendChild(definitions);
  10500. this.defs = definitions;
  10501. const rootGroup = this.svgFactory.createElement("svg:g");
  10502. rootGroup.setAttributeNS(null, "transform", pm(viewport.transform));
  10503. svg.appendChild(rootGroup);
  10504. this.svg = rootGroup;
  10505. return svg;
  10506. }
  10507. _ensureClipGroup() {
  10508. if (!this.current.clipGroup) {
  10509. const clipGroup = this.svgFactory.createElement("svg:g");
  10510. clipGroup.setAttributeNS(null, "clip-path", this.current.activeClipUrl);
  10511. this.svg.appendChild(clipGroup);
  10512. this.current.clipGroup = clipGroup;
  10513. }
  10514. return this.current.clipGroup;
  10515. }
  10516. _ensureTransformGroup() {
  10517. if (!this.tgrp) {
  10518. this.tgrp = this.svgFactory.createElement("svg:g");
  10519. this.tgrp.setAttributeNS(null, "transform", pm(this.transformMatrix));
  10520. if (this.current.activeClipUrl) {
  10521. this._ensureClipGroup().appendChild(this.tgrp);
  10522. } else {
  10523. this.svg.appendChild(this.tgrp);
  10524. }
  10525. }
  10526. return this.tgrp;
  10527. }
  10528. };
  10529. }
  10530. /***/ }),
  10531. /* 22 */
  10532. /***/ ((__unused_webpack_module, exports) => {
  10533. Object.defineProperty(exports, "__esModule", ({
  10534. value: true
  10535. }));
  10536. exports.XfaLayer = void 0;
  10537. class XfaLayer {
  10538. static setAttributes(html, attrs) {
  10539. for (const [key, value] of Object.entries(attrs)) {
  10540. if (value === null || value === undefined) {
  10541. continue;
  10542. }
  10543. if (key !== "style") {
  10544. html.setAttribute(key, value);
  10545. } else {
  10546. Object.assign(html.style, value);
  10547. }
  10548. }
  10549. }
  10550. static render(parameters) {
  10551. const root = parameters.xfa;
  10552. const rootHtml = document.createElement(root.name);
  10553. if (root.attributes) {
  10554. XfaLayer.setAttributes(rootHtml, root.attributes);
  10555. }
  10556. const stack = [[root, -1, rootHtml]];
  10557. const rootDiv = parameters.div;
  10558. rootDiv.appendChild(rootHtml);
  10559. const coeffs = parameters.viewport.transform.join(",");
  10560. rootDiv.style.transform = `matrix(${coeffs})`;
  10561. rootDiv.setAttribute("class", "xfaLayer xfaFont");
  10562. while (stack.length > 0) {
  10563. const [parent, i, html] = stack[stack.length - 1];
  10564. if (i + 1 === parent.children.length) {
  10565. stack.pop();
  10566. continue;
  10567. }
  10568. const child = parent.children[++stack[stack.length - 1][1]];
  10569. if (child === null) {
  10570. continue;
  10571. }
  10572. const {
  10573. name
  10574. } = child;
  10575. if (name === "#text") {
  10576. html.appendChild(document.createTextNode(child.value));
  10577. continue;
  10578. }
  10579. const childHtml = document.createElement(name);
  10580. html.appendChild(childHtml);
  10581. if (child.attributes) {
  10582. XfaLayer.setAttributes(childHtml, child.attributes);
  10583. }
  10584. if (child.children && child.children.length > 0) {
  10585. stack.push([child, -1, childHtml]);
  10586. } else if (child.value) {
  10587. childHtml.appendChild(document.createTextNode(child.value));
  10588. }
  10589. }
  10590. }
  10591. static update(parameters) {
  10592. const transform = `matrix(${parameters.viewport.transform.join(",")})`;
  10593. parameters.div.style.transform = transform;
  10594. parameters.div.hidden = false;
  10595. }
  10596. }
  10597. exports.XfaLayer = XfaLayer;
  10598. /***/ }),
  10599. /* 23 */
  10600. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  10601. Object.defineProperty(exports, "__esModule", ({
  10602. value: true
  10603. }));
  10604. exports.PDFNodeStream = void 0;
  10605. var _util = __w_pdfjs_require__(2);
  10606. var _network_utils = __w_pdfjs_require__(24);
  10607. ;
  10608. const fs = require("fs");
  10609. const http = require("http");
  10610. const https = require("https");
  10611. const url = require("url");
  10612. const fileUriRegex = /^file:\/\/\/[a-zA-Z]:\//;
  10613. function parseUrl(sourceUrl) {
  10614. const parsedUrl = url.parse(sourceUrl);
  10615. if (parsedUrl.protocol === "file:" || parsedUrl.host) {
  10616. return parsedUrl;
  10617. }
  10618. if (/^[a-z]:[/\\]/i.test(sourceUrl)) {
  10619. return url.parse(`file:///${sourceUrl}`);
  10620. }
  10621. if (!parsedUrl.host) {
  10622. parsedUrl.protocol = "file:";
  10623. }
  10624. return parsedUrl;
  10625. }
  10626. class PDFNodeStream {
  10627. constructor(source) {
  10628. this.source = source;
  10629. this.url = parseUrl(source.url);
  10630. this.isHttp = this.url.protocol === "http:" || this.url.protocol === "https:";
  10631. this.isFsUrl = this.url.protocol === "file:";
  10632. this.httpHeaders = this.isHttp && source.httpHeaders || {};
  10633. this._fullRequestReader = null;
  10634. this._rangeRequestReaders = [];
  10635. }
  10636. get _progressiveDataLength() {
  10637. return this._fullRequestReader?._loaded ?? 0;
  10638. }
  10639. getFullReader() {
  10640. (0, _util.assert)(!this._fullRequestReader, "PDFNodeStream.getFullReader can only be called once.");
  10641. this._fullRequestReader = this.isFsUrl ? new PDFNodeStreamFsFullReader(this) : new PDFNodeStreamFullReader(this);
  10642. return this._fullRequestReader;
  10643. }
  10644. getRangeReader(start, end) {
  10645. if (end <= this._progressiveDataLength) {
  10646. return null;
  10647. }
  10648. const rangeReader = this.isFsUrl ? new PDFNodeStreamFsRangeReader(this, start, end) : new PDFNodeStreamRangeReader(this, start, end);
  10649. this._rangeRequestReaders.push(rangeReader);
  10650. return rangeReader;
  10651. }
  10652. cancelAllRequests(reason) {
  10653. if (this._fullRequestReader) {
  10654. this._fullRequestReader.cancel(reason);
  10655. }
  10656. const readers = this._rangeRequestReaders.slice(0);
  10657. readers.forEach(function (reader) {
  10658. reader.cancel(reason);
  10659. });
  10660. }
  10661. }
  10662. exports.PDFNodeStream = PDFNodeStream;
  10663. class BaseFullReader {
  10664. constructor(stream) {
  10665. this._url = stream.url;
  10666. this._done = false;
  10667. this._storedError = null;
  10668. this.onProgress = null;
  10669. const source = stream.source;
  10670. this._contentLength = source.length;
  10671. this._loaded = 0;
  10672. this._filename = null;
  10673. this._disableRange = source.disableRange || false;
  10674. this._rangeChunkSize = source.rangeChunkSize;
  10675. if (!this._rangeChunkSize && !this._disableRange) {
  10676. this._disableRange = true;
  10677. }
  10678. this._isStreamingSupported = !source.disableStream;
  10679. this._isRangeSupported = !source.disableRange;
  10680. this._readableStream = null;
  10681. this._readCapability = (0, _util.createPromiseCapability)();
  10682. this._headersCapability = (0, _util.createPromiseCapability)();
  10683. }
  10684. get headersReady() {
  10685. return this._headersCapability.promise;
  10686. }
  10687. get filename() {
  10688. return this._filename;
  10689. }
  10690. get contentLength() {
  10691. return this._contentLength;
  10692. }
  10693. get isRangeSupported() {
  10694. return this._isRangeSupported;
  10695. }
  10696. get isStreamingSupported() {
  10697. return this._isStreamingSupported;
  10698. }
  10699. async read() {
  10700. await this._readCapability.promise;
  10701. if (this._done) {
  10702. return {
  10703. value: undefined,
  10704. done: true
  10705. };
  10706. }
  10707. if (this._storedError) {
  10708. throw this._storedError;
  10709. }
  10710. const chunk = this._readableStream.read();
  10711. if (chunk === null) {
  10712. this._readCapability = (0, _util.createPromiseCapability)();
  10713. return this.read();
  10714. }
  10715. this._loaded += chunk.length;
  10716. if (this.onProgress) {
  10717. this.onProgress({
  10718. loaded: this._loaded,
  10719. total: this._contentLength
  10720. });
  10721. }
  10722. const buffer = new Uint8Array(chunk).buffer;
  10723. return {
  10724. value: buffer,
  10725. done: false
  10726. };
  10727. }
  10728. cancel(reason) {
  10729. if (!this._readableStream) {
  10730. this._error(reason);
  10731. return;
  10732. }
  10733. this._readableStream.destroy(reason);
  10734. }
  10735. _error(reason) {
  10736. this._storedError = reason;
  10737. this._readCapability.resolve();
  10738. }
  10739. _setReadableStream(readableStream) {
  10740. this._readableStream = readableStream;
  10741. readableStream.on("readable", () => {
  10742. this._readCapability.resolve();
  10743. });
  10744. readableStream.on("end", () => {
  10745. readableStream.destroy();
  10746. this._done = true;
  10747. this._readCapability.resolve();
  10748. });
  10749. readableStream.on("error", reason => {
  10750. this._error(reason);
  10751. });
  10752. if (!this._isStreamingSupported && this._isRangeSupported) {
  10753. this._error(new _util.AbortException("streaming is disabled"));
  10754. }
  10755. if (this._storedError) {
  10756. this._readableStream.destroy(this._storedError);
  10757. }
  10758. }
  10759. }
  10760. class BaseRangeReader {
  10761. constructor(stream) {
  10762. this._url = stream.url;
  10763. this._done = false;
  10764. this._storedError = null;
  10765. this.onProgress = null;
  10766. this._loaded = 0;
  10767. this._readableStream = null;
  10768. this._readCapability = (0, _util.createPromiseCapability)();
  10769. const source = stream.source;
  10770. this._isStreamingSupported = !source.disableStream;
  10771. }
  10772. get isStreamingSupported() {
  10773. return this._isStreamingSupported;
  10774. }
  10775. async read() {
  10776. await this._readCapability.promise;
  10777. if (this._done) {
  10778. return {
  10779. value: undefined,
  10780. done: true
  10781. };
  10782. }
  10783. if (this._storedError) {
  10784. throw this._storedError;
  10785. }
  10786. const chunk = this._readableStream.read();
  10787. if (chunk === null) {
  10788. this._readCapability = (0, _util.createPromiseCapability)();
  10789. return this.read();
  10790. }
  10791. this._loaded += chunk.length;
  10792. if (this.onProgress) {
  10793. this.onProgress({
  10794. loaded: this._loaded
  10795. });
  10796. }
  10797. const buffer = new Uint8Array(chunk).buffer;
  10798. return {
  10799. value: buffer,
  10800. done: false
  10801. };
  10802. }
  10803. cancel(reason) {
  10804. if (!this._readableStream) {
  10805. this._error(reason);
  10806. return;
  10807. }
  10808. this._readableStream.destroy(reason);
  10809. }
  10810. _error(reason) {
  10811. this._storedError = reason;
  10812. this._readCapability.resolve();
  10813. }
  10814. _setReadableStream(readableStream) {
  10815. this._readableStream = readableStream;
  10816. readableStream.on("readable", () => {
  10817. this._readCapability.resolve();
  10818. });
  10819. readableStream.on("end", () => {
  10820. readableStream.destroy();
  10821. this._done = true;
  10822. this._readCapability.resolve();
  10823. });
  10824. readableStream.on("error", reason => {
  10825. this._error(reason);
  10826. });
  10827. if (this._storedError) {
  10828. this._readableStream.destroy(this._storedError);
  10829. }
  10830. }
  10831. }
  10832. function createRequestOptions(parsedUrl, headers) {
  10833. return {
  10834. protocol: parsedUrl.protocol,
  10835. auth: parsedUrl.auth,
  10836. host: parsedUrl.hostname,
  10837. port: parsedUrl.port,
  10838. path: parsedUrl.path,
  10839. method: "GET",
  10840. headers
  10841. };
  10842. }
  10843. class PDFNodeStreamFullReader extends BaseFullReader {
  10844. constructor(stream) {
  10845. super(stream);
  10846. const handleResponse = response => {
  10847. if (response.statusCode === 404) {
  10848. const error = new _util.MissingPDFException(`Missing PDF "${this._url}".`);
  10849. this._storedError = error;
  10850. this._headersCapability.reject(error);
  10851. return;
  10852. }
  10853. this._headersCapability.resolve();
  10854. this._setReadableStream(response);
  10855. const getResponseHeader = name => {
  10856. return this._readableStream.headers[name.toLowerCase()];
  10857. };
  10858. const {
  10859. allowRangeRequests,
  10860. suggestedLength
  10861. } = (0, _network_utils.validateRangeRequestCapabilities)({
  10862. getResponseHeader,
  10863. isHttp: stream.isHttp,
  10864. rangeChunkSize: this._rangeChunkSize,
  10865. disableRange: this._disableRange
  10866. });
  10867. this._isRangeSupported = allowRangeRequests;
  10868. this._contentLength = suggestedLength || this._contentLength;
  10869. this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
  10870. };
  10871. this._request = null;
  10872. if (this._url.protocol === "http:") {
  10873. this._request = http.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
  10874. } else {
  10875. this._request = https.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
  10876. }
  10877. this._request.on("error", reason => {
  10878. this._storedError = reason;
  10879. this._headersCapability.reject(reason);
  10880. });
  10881. this._request.end();
  10882. }
  10883. }
  10884. class PDFNodeStreamRangeReader extends BaseRangeReader {
  10885. constructor(stream, start, end) {
  10886. super(stream);
  10887. this._httpHeaders = {};
  10888. for (const property in stream.httpHeaders) {
  10889. const value = stream.httpHeaders[property];
  10890. if (typeof value === "undefined") {
  10891. continue;
  10892. }
  10893. this._httpHeaders[property] = value;
  10894. }
  10895. this._httpHeaders.Range = `bytes=${start}-${end - 1}`;
  10896. const handleResponse = response => {
  10897. if (response.statusCode === 404) {
  10898. const error = new _util.MissingPDFException(`Missing PDF "${this._url}".`);
  10899. this._storedError = error;
  10900. return;
  10901. }
  10902. this._setReadableStream(response);
  10903. };
  10904. this._request = null;
  10905. if (this._url.protocol === "http:") {
  10906. this._request = http.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
  10907. } else {
  10908. this._request = https.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
  10909. }
  10910. this._request.on("error", reason => {
  10911. this._storedError = reason;
  10912. });
  10913. this._request.end();
  10914. }
  10915. }
  10916. class PDFNodeStreamFsFullReader extends BaseFullReader {
  10917. constructor(stream) {
  10918. super(stream);
  10919. let path = decodeURIComponent(this._url.path);
  10920. if (fileUriRegex.test(this._url.href)) {
  10921. path = path.replace(/^\//, "");
  10922. }
  10923. fs.lstat(path, (error, stat) => {
  10924. if (error) {
  10925. if (error.code === "ENOENT") {
  10926. error = new _util.MissingPDFException(`Missing PDF "${path}".`);
  10927. }
  10928. this._storedError = error;
  10929. this._headersCapability.reject(error);
  10930. return;
  10931. }
  10932. this._contentLength = stat.size;
  10933. this._setReadableStream(fs.createReadStream(path));
  10934. this._headersCapability.resolve();
  10935. });
  10936. }
  10937. }
  10938. class PDFNodeStreamFsRangeReader extends BaseRangeReader {
  10939. constructor(stream, start, end) {
  10940. super(stream);
  10941. let path = decodeURIComponent(this._url.path);
  10942. if (fileUriRegex.test(this._url.href)) {
  10943. path = path.replace(/^\//, "");
  10944. }
  10945. this._setReadableStream(fs.createReadStream(path, {
  10946. start,
  10947. end: end - 1
  10948. }));
  10949. }
  10950. }
  10951. /***/ }),
  10952. /* 24 */
  10953. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  10954. Object.defineProperty(exports, "__esModule", ({
  10955. value: true
  10956. }));
  10957. exports.createResponseStatusError = createResponseStatusError;
  10958. exports.extractFilenameFromHeader = extractFilenameFromHeader;
  10959. exports.validateRangeRequestCapabilities = validateRangeRequestCapabilities;
  10960. exports.validateResponseStatus = validateResponseStatus;
  10961. var _util = __w_pdfjs_require__(2);
  10962. var _content_disposition = __w_pdfjs_require__(25);
  10963. var _display_utils = __w_pdfjs_require__(1);
  10964. function validateRangeRequestCapabilities({
  10965. getResponseHeader,
  10966. isHttp,
  10967. rangeChunkSize,
  10968. disableRange
  10969. }) {
  10970. (0, _util.assert)(rangeChunkSize > 0, "Range chunk size must be larger than zero");
  10971. const returnValues = {
  10972. allowRangeRequests: false,
  10973. suggestedLength: undefined
  10974. };
  10975. const length = parseInt(getResponseHeader("Content-Length"), 10);
  10976. if (!Number.isInteger(length)) {
  10977. return returnValues;
  10978. }
  10979. returnValues.suggestedLength = length;
  10980. if (length <= 2 * rangeChunkSize) {
  10981. return returnValues;
  10982. }
  10983. if (disableRange || !isHttp) {
  10984. return returnValues;
  10985. }
  10986. if (getResponseHeader("Accept-Ranges") !== "bytes") {
  10987. return returnValues;
  10988. }
  10989. const contentEncoding = getResponseHeader("Content-Encoding") || "identity";
  10990. if (contentEncoding !== "identity") {
  10991. return returnValues;
  10992. }
  10993. returnValues.allowRangeRequests = true;
  10994. return returnValues;
  10995. }
  10996. function extractFilenameFromHeader(getResponseHeader) {
  10997. const contentDisposition = getResponseHeader("Content-Disposition");
  10998. if (contentDisposition) {
  10999. let filename = (0, _content_disposition.getFilenameFromContentDispositionHeader)(contentDisposition);
  11000. if (filename.includes("%")) {
  11001. try {
  11002. filename = decodeURIComponent(filename);
  11003. } catch (ex) {}
  11004. }
  11005. if ((0, _display_utils.isPdfFile)(filename)) {
  11006. return filename;
  11007. }
  11008. }
  11009. return null;
  11010. }
  11011. function createResponseStatusError(status, url) {
  11012. if (status === 404 || status === 0 && url.startsWith("file:")) {
  11013. return new _util.MissingPDFException('Missing PDF "' + url + '".');
  11014. }
  11015. return new _util.UnexpectedResponseException(`Unexpected server response (${status}) while retrieving PDF "${url}".`, status);
  11016. }
  11017. function validateResponseStatus(status) {
  11018. return status === 200 || status === 206;
  11019. }
  11020. /***/ }),
  11021. /* 25 */
  11022. /***/ ((__unused_webpack_module, exports) => {
  11023. Object.defineProperty(exports, "__esModule", ({
  11024. value: true
  11025. }));
  11026. exports.getFilenameFromContentDispositionHeader = getFilenameFromContentDispositionHeader;
  11027. function getFilenameFromContentDispositionHeader(contentDisposition) {
  11028. let needsEncodingFixup = true;
  11029. let tmp = toParamRegExp("filename\\*", "i").exec(contentDisposition);
  11030. if (tmp) {
  11031. tmp = tmp[1];
  11032. let filename = rfc2616unquote(tmp);
  11033. filename = unescape(filename);
  11034. filename = rfc5987decode(filename);
  11035. filename = rfc2047decode(filename);
  11036. return fixupEncoding(filename);
  11037. }
  11038. tmp = rfc2231getparam(contentDisposition);
  11039. if (tmp) {
  11040. const filename = rfc2047decode(tmp);
  11041. return fixupEncoding(filename);
  11042. }
  11043. tmp = toParamRegExp("filename", "i").exec(contentDisposition);
  11044. if (tmp) {
  11045. tmp = tmp[1];
  11046. let filename = rfc2616unquote(tmp);
  11047. filename = rfc2047decode(filename);
  11048. return fixupEncoding(filename);
  11049. }
  11050. function toParamRegExp(attributePattern, flags) {
  11051. return new RegExp("(?:^|;)\\s*" + attributePattern + "\\s*=\\s*" + "(" + '[^";\\s][^;\\s]*' + "|" + '"(?:[^"\\\\]|\\\\"?)+"?' + ")", flags);
  11052. }
  11053. function textdecode(encoding, value) {
  11054. if (encoding) {
  11055. if (!/^[\x00-\xFF]+$/.test(value)) {
  11056. return value;
  11057. }
  11058. try {
  11059. const decoder = new TextDecoder(encoding, {
  11060. fatal: true
  11061. });
  11062. const bytes = Array.from(value, function (ch) {
  11063. return ch.charCodeAt(0) & 0xff;
  11064. });
  11065. value = decoder.decode(new Uint8Array(bytes));
  11066. needsEncodingFixup = false;
  11067. } catch (e) {
  11068. if (/^utf-?8$/i.test(encoding)) {
  11069. try {
  11070. value = decodeURIComponent(escape(value));
  11071. needsEncodingFixup = false;
  11072. } catch (err) {}
  11073. }
  11074. }
  11075. }
  11076. return value;
  11077. }
  11078. function fixupEncoding(value) {
  11079. if (needsEncodingFixup && /[\x80-\xff]/.test(value)) {
  11080. value = textdecode("utf-8", value);
  11081. if (needsEncodingFixup) {
  11082. value = textdecode("iso-8859-1", value);
  11083. }
  11084. }
  11085. return value;
  11086. }
  11087. function rfc2231getparam(contentDispositionStr) {
  11088. const matches = [];
  11089. let match;
  11090. const iter = toParamRegExp("filename\\*((?!0\\d)\\d+)(\\*?)", "ig");
  11091. while ((match = iter.exec(contentDispositionStr)) !== null) {
  11092. let [, n, quot, part] = match;
  11093. n = parseInt(n, 10);
  11094. if (n in matches) {
  11095. if (n === 0) {
  11096. break;
  11097. }
  11098. continue;
  11099. }
  11100. matches[n] = [quot, part];
  11101. }
  11102. const parts = [];
  11103. for (let n = 0; n < matches.length; ++n) {
  11104. if (!(n in matches)) {
  11105. break;
  11106. }
  11107. let [quot, part] = matches[n];
  11108. part = rfc2616unquote(part);
  11109. if (quot) {
  11110. part = unescape(part);
  11111. if (n === 0) {
  11112. part = rfc5987decode(part);
  11113. }
  11114. }
  11115. parts.push(part);
  11116. }
  11117. return parts.join("");
  11118. }
  11119. function rfc2616unquote(value) {
  11120. if (value.startsWith('"')) {
  11121. const parts = value.slice(1).split('\\"');
  11122. for (let i = 0; i < parts.length; ++i) {
  11123. const quotindex = parts[i].indexOf('"');
  11124. if (quotindex !== -1) {
  11125. parts[i] = parts[i].slice(0, quotindex);
  11126. parts.length = i + 1;
  11127. }
  11128. parts[i] = parts[i].replace(/\\(.)/g, "$1");
  11129. }
  11130. value = parts.join('"');
  11131. }
  11132. return value;
  11133. }
  11134. function rfc5987decode(extvalue) {
  11135. const encodingend = extvalue.indexOf("'");
  11136. if (encodingend === -1) {
  11137. return extvalue;
  11138. }
  11139. const encoding = extvalue.slice(0, encodingend);
  11140. const langvalue = extvalue.slice(encodingend + 1);
  11141. const value = langvalue.replace(/^[^']*'/, "");
  11142. return textdecode(encoding, value);
  11143. }
  11144. function rfc2047decode(value) {
  11145. if (!value.startsWith("=?") || /[\x00-\x19\x80-\xff]/.test(value)) {
  11146. return value;
  11147. }
  11148. return value.replace(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g, function (matches, charset, encoding, text) {
  11149. if (encoding === "q" || encoding === "Q") {
  11150. text = text.replace(/_/g, " ");
  11151. text = text.replace(/=([0-9a-fA-F]{2})/g, function (match, hex) {
  11152. return String.fromCharCode(parseInt(hex, 16));
  11153. });
  11154. return textdecode(charset, text);
  11155. }
  11156. try {
  11157. text = atob(text);
  11158. } catch (e) {}
  11159. return textdecode(charset, text);
  11160. });
  11161. }
  11162. return "";
  11163. }
  11164. /***/ }),
  11165. /* 26 */
  11166. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  11167. Object.defineProperty(exports, "__esModule", ({
  11168. value: true
  11169. }));
  11170. exports.PDFNetworkStream = void 0;
  11171. var _util = __w_pdfjs_require__(2);
  11172. var _network_utils = __w_pdfjs_require__(24);
  11173. ;
  11174. const OK_RESPONSE = 200;
  11175. const PARTIAL_CONTENT_RESPONSE = 206;
  11176. function getArrayBuffer(xhr) {
  11177. const data = xhr.response;
  11178. if (typeof data !== "string") {
  11179. return data;
  11180. }
  11181. const array = (0, _util.stringToBytes)(data);
  11182. return array.buffer;
  11183. }
  11184. class NetworkManager {
  11185. constructor(url, args) {
  11186. this.url = url;
  11187. args = args || {};
  11188. this.isHttp = /^https?:/i.test(url);
  11189. this.httpHeaders = this.isHttp && args.httpHeaders || {};
  11190. this.withCredentials = args.withCredentials || false;
  11191. this.getXhr = args.getXhr || function NetworkManager_getXhr() {
  11192. return new XMLHttpRequest();
  11193. };
  11194. this.currXhrId = 0;
  11195. this.pendingRequests = Object.create(null);
  11196. }
  11197. requestRange(begin, end, listeners) {
  11198. const args = {
  11199. begin,
  11200. end
  11201. };
  11202. for (const prop in listeners) {
  11203. args[prop] = listeners[prop];
  11204. }
  11205. return this.request(args);
  11206. }
  11207. requestFull(listeners) {
  11208. return this.request(listeners);
  11209. }
  11210. request(args) {
  11211. const xhr = this.getXhr();
  11212. const xhrId = this.currXhrId++;
  11213. const pendingRequest = this.pendingRequests[xhrId] = {
  11214. xhr
  11215. };
  11216. xhr.open("GET", this.url);
  11217. xhr.withCredentials = this.withCredentials;
  11218. for (const property in this.httpHeaders) {
  11219. const value = this.httpHeaders[property];
  11220. if (typeof value === "undefined") {
  11221. continue;
  11222. }
  11223. xhr.setRequestHeader(property, value);
  11224. }
  11225. if (this.isHttp && "begin" in args && "end" in args) {
  11226. xhr.setRequestHeader("Range", `bytes=${args.begin}-${args.end - 1}`);
  11227. pendingRequest.expectedStatus = PARTIAL_CONTENT_RESPONSE;
  11228. } else {
  11229. pendingRequest.expectedStatus = OK_RESPONSE;
  11230. }
  11231. xhr.responseType = "arraybuffer";
  11232. if (args.onError) {
  11233. xhr.onerror = function (evt) {
  11234. args.onError(xhr.status);
  11235. };
  11236. }
  11237. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  11238. xhr.onprogress = this.onProgress.bind(this, xhrId);
  11239. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  11240. pendingRequest.onDone = args.onDone;
  11241. pendingRequest.onError = args.onError;
  11242. pendingRequest.onProgress = args.onProgress;
  11243. xhr.send(null);
  11244. return xhrId;
  11245. }
  11246. onProgress(xhrId, evt) {
  11247. const pendingRequest = this.pendingRequests[xhrId];
  11248. if (!pendingRequest) {
  11249. return;
  11250. }
  11251. if (pendingRequest.onProgress) {
  11252. pendingRequest.onProgress(evt);
  11253. }
  11254. }
  11255. onStateChange(xhrId, evt) {
  11256. const pendingRequest = this.pendingRequests[xhrId];
  11257. if (!pendingRequest) {
  11258. return;
  11259. }
  11260. const xhr = pendingRequest.xhr;
  11261. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  11262. pendingRequest.onHeadersReceived();
  11263. delete pendingRequest.onHeadersReceived;
  11264. }
  11265. if (xhr.readyState !== 4) {
  11266. return;
  11267. }
  11268. if (!(xhrId in this.pendingRequests)) {
  11269. return;
  11270. }
  11271. delete this.pendingRequests[xhrId];
  11272. if (xhr.status === 0 && this.isHttp) {
  11273. if (pendingRequest.onError) {
  11274. pendingRequest.onError(xhr.status);
  11275. }
  11276. return;
  11277. }
  11278. const xhrStatus = xhr.status || OK_RESPONSE;
  11279. const ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  11280. if (!ok_response_on_range_request && xhrStatus !== pendingRequest.expectedStatus) {
  11281. if (pendingRequest.onError) {
  11282. pendingRequest.onError(xhr.status);
  11283. }
  11284. return;
  11285. }
  11286. const chunk = getArrayBuffer(xhr);
  11287. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  11288. const rangeHeader = xhr.getResponseHeader("Content-Range");
  11289. const matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  11290. pendingRequest.onDone({
  11291. begin: parseInt(matches[1], 10),
  11292. chunk
  11293. });
  11294. } else if (chunk) {
  11295. pendingRequest.onDone({
  11296. begin: 0,
  11297. chunk
  11298. });
  11299. } else if (pendingRequest.onError) {
  11300. pendingRequest.onError(xhr.status);
  11301. }
  11302. }
  11303. getRequestXhr(xhrId) {
  11304. return this.pendingRequests[xhrId].xhr;
  11305. }
  11306. isPendingRequest(xhrId) {
  11307. return xhrId in this.pendingRequests;
  11308. }
  11309. abortRequest(xhrId) {
  11310. const xhr = this.pendingRequests[xhrId].xhr;
  11311. delete this.pendingRequests[xhrId];
  11312. xhr.abort();
  11313. }
  11314. }
  11315. class PDFNetworkStream {
  11316. constructor(source) {
  11317. this._source = source;
  11318. this._manager = new NetworkManager(source.url, {
  11319. httpHeaders: source.httpHeaders,
  11320. withCredentials: source.withCredentials
  11321. });
  11322. this._rangeChunkSize = source.rangeChunkSize;
  11323. this._fullRequestReader = null;
  11324. this._rangeRequestReaders = [];
  11325. }
  11326. _onRangeRequestReaderClosed(reader) {
  11327. const i = this._rangeRequestReaders.indexOf(reader);
  11328. if (i >= 0) {
  11329. this._rangeRequestReaders.splice(i, 1);
  11330. }
  11331. }
  11332. getFullReader() {
  11333. (0, _util.assert)(!this._fullRequestReader, "PDFNetworkStream.getFullReader can only be called once.");
  11334. this._fullRequestReader = new PDFNetworkStreamFullRequestReader(this._manager, this._source);
  11335. return this._fullRequestReader;
  11336. }
  11337. getRangeReader(begin, end) {
  11338. const reader = new PDFNetworkStreamRangeRequestReader(this._manager, begin, end);
  11339. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  11340. this._rangeRequestReaders.push(reader);
  11341. return reader;
  11342. }
  11343. cancelAllRequests(reason) {
  11344. if (this._fullRequestReader) {
  11345. this._fullRequestReader.cancel(reason);
  11346. }
  11347. const readers = this._rangeRequestReaders.slice(0);
  11348. readers.forEach(function (reader) {
  11349. reader.cancel(reason);
  11350. });
  11351. }
  11352. }
  11353. exports.PDFNetworkStream = PDFNetworkStream;
  11354. class PDFNetworkStreamFullRequestReader {
  11355. constructor(manager, source) {
  11356. this._manager = manager;
  11357. const args = {
  11358. onHeadersReceived: this._onHeadersReceived.bind(this),
  11359. onDone: this._onDone.bind(this),
  11360. onError: this._onError.bind(this),
  11361. onProgress: this._onProgress.bind(this)
  11362. };
  11363. this._url = source.url;
  11364. this._fullRequestId = manager.requestFull(args);
  11365. this._headersReceivedCapability = (0, _util.createPromiseCapability)();
  11366. this._disableRange = source.disableRange || false;
  11367. this._contentLength = source.length;
  11368. this._rangeChunkSize = source.rangeChunkSize;
  11369. if (!this._rangeChunkSize && !this._disableRange) {
  11370. this._disableRange = true;
  11371. }
  11372. this._isStreamingSupported = false;
  11373. this._isRangeSupported = false;
  11374. this._cachedChunks = [];
  11375. this._requests = [];
  11376. this._done = false;
  11377. this._storedError = undefined;
  11378. this._filename = null;
  11379. this.onProgress = null;
  11380. }
  11381. _onHeadersReceived() {
  11382. const fullRequestXhrId = this._fullRequestId;
  11383. const fullRequestXhr = this._manager.getRequestXhr(fullRequestXhrId);
  11384. const getResponseHeader = name => {
  11385. return fullRequestXhr.getResponseHeader(name);
  11386. };
  11387. const {
  11388. allowRangeRequests,
  11389. suggestedLength
  11390. } = (0, _network_utils.validateRangeRequestCapabilities)({
  11391. getResponseHeader,
  11392. isHttp: this._manager.isHttp,
  11393. rangeChunkSize: this._rangeChunkSize,
  11394. disableRange: this._disableRange
  11395. });
  11396. if (allowRangeRequests) {
  11397. this._isRangeSupported = true;
  11398. }
  11399. this._contentLength = suggestedLength || this._contentLength;
  11400. this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
  11401. if (this._isRangeSupported) {
  11402. this._manager.abortRequest(fullRequestXhrId);
  11403. }
  11404. this._headersReceivedCapability.resolve();
  11405. }
  11406. _onDone(args) {
  11407. if (args) {
  11408. if (this._requests.length > 0) {
  11409. const requestCapability = this._requests.shift();
  11410. requestCapability.resolve({
  11411. value: args.chunk,
  11412. done: false
  11413. });
  11414. } else {
  11415. this._cachedChunks.push(args.chunk);
  11416. }
  11417. }
  11418. this._done = true;
  11419. if (this._cachedChunks.length > 0) {
  11420. return;
  11421. }
  11422. this._requests.forEach(function (requestCapability) {
  11423. requestCapability.resolve({
  11424. value: undefined,
  11425. done: true
  11426. });
  11427. });
  11428. this._requests = [];
  11429. }
  11430. _onError(status) {
  11431. const url = this._url;
  11432. const exception = (0, _network_utils.createResponseStatusError)(status, url);
  11433. this._storedError = exception;
  11434. this._headersReceivedCapability.reject(exception);
  11435. this._requests.forEach(function (requestCapability) {
  11436. requestCapability.reject(exception);
  11437. });
  11438. this._requests = [];
  11439. this._cachedChunks = [];
  11440. }
  11441. _onProgress(data) {
  11442. if (this.onProgress) {
  11443. this.onProgress({
  11444. loaded: data.loaded,
  11445. total: data.lengthComputable ? data.total : this._contentLength
  11446. });
  11447. }
  11448. }
  11449. get filename() {
  11450. return this._filename;
  11451. }
  11452. get isRangeSupported() {
  11453. return this._isRangeSupported;
  11454. }
  11455. get isStreamingSupported() {
  11456. return this._isStreamingSupported;
  11457. }
  11458. get contentLength() {
  11459. return this._contentLength;
  11460. }
  11461. get headersReady() {
  11462. return this._headersReceivedCapability.promise;
  11463. }
  11464. async read() {
  11465. if (this._storedError) {
  11466. throw this._storedError;
  11467. }
  11468. if (this._cachedChunks.length > 0) {
  11469. const chunk = this._cachedChunks.shift();
  11470. return {
  11471. value: chunk,
  11472. done: false
  11473. };
  11474. }
  11475. if (this._done) {
  11476. return {
  11477. value: undefined,
  11478. done: true
  11479. };
  11480. }
  11481. const requestCapability = (0, _util.createPromiseCapability)();
  11482. this._requests.push(requestCapability);
  11483. return requestCapability.promise;
  11484. }
  11485. cancel(reason) {
  11486. this._done = true;
  11487. this._headersReceivedCapability.reject(reason);
  11488. this._requests.forEach(function (requestCapability) {
  11489. requestCapability.resolve({
  11490. value: undefined,
  11491. done: true
  11492. });
  11493. });
  11494. this._requests = [];
  11495. if (this._manager.isPendingRequest(this._fullRequestId)) {
  11496. this._manager.abortRequest(this._fullRequestId);
  11497. }
  11498. this._fullRequestReader = null;
  11499. }
  11500. }
  11501. class PDFNetworkStreamRangeRequestReader {
  11502. constructor(manager, begin, end) {
  11503. this._manager = manager;
  11504. const args = {
  11505. onDone: this._onDone.bind(this),
  11506. onProgress: this._onProgress.bind(this)
  11507. };
  11508. this._requestId = manager.requestRange(begin, end, args);
  11509. this._requests = [];
  11510. this._queuedChunk = null;
  11511. this._done = false;
  11512. this.onProgress = null;
  11513. this.onClosed = null;
  11514. }
  11515. _close() {
  11516. if (this.onClosed) {
  11517. this.onClosed(this);
  11518. }
  11519. }
  11520. _onDone(data) {
  11521. const chunk = data.chunk;
  11522. if (this._requests.length > 0) {
  11523. const requestCapability = this._requests.shift();
  11524. requestCapability.resolve({
  11525. value: chunk,
  11526. done: false
  11527. });
  11528. } else {
  11529. this._queuedChunk = chunk;
  11530. }
  11531. this._done = true;
  11532. this._requests.forEach(function (requestCapability) {
  11533. requestCapability.resolve({
  11534. value: undefined,
  11535. done: true
  11536. });
  11537. });
  11538. this._requests = [];
  11539. this._close();
  11540. }
  11541. _onProgress(evt) {
  11542. if (!this.isStreamingSupported && this.onProgress) {
  11543. this.onProgress({
  11544. loaded: evt.loaded
  11545. });
  11546. }
  11547. }
  11548. get isStreamingSupported() {
  11549. return false;
  11550. }
  11551. async read() {
  11552. if (this._queuedChunk !== null) {
  11553. const chunk = this._queuedChunk;
  11554. this._queuedChunk = null;
  11555. return {
  11556. value: chunk,
  11557. done: false
  11558. };
  11559. }
  11560. if (this._done) {
  11561. return {
  11562. value: undefined,
  11563. done: true
  11564. };
  11565. }
  11566. const requestCapability = (0, _util.createPromiseCapability)();
  11567. this._requests.push(requestCapability);
  11568. return requestCapability.promise;
  11569. }
  11570. cancel(reason) {
  11571. this._done = true;
  11572. this._requests.forEach(function (requestCapability) {
  11573. requestCapability.resolve({
  11574. value: undefined,
  11575. done: true
  11576. });
  11577. });
  11578. this._requests = [];
  11579. if (this._manager.isPendingRequest(this._requestId)) {
  11580. this._manager.abortRequest(this._requestId);
  11581. }
  11582. this._close();
  11583. }
  11584. }
  11585. /***/ }),
  11586. /* 27 */
  11587. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  11588. Object.defineProperty(exports, "__esModule", ({
  11589. value: true
  11590. }));
  11591. exports.PDFFetchStream = void 0;
  11592. var _util = __w_pdfjs_require__(2);
  11593. var _network_utils = __w_pdfjs_require__(24);
  11594. ;
  11595. function createFetchOptions(headers, withCredentials, abortController) {
  11596. return {
  11597. method: "GET",
  11598. headers,
  11599. signal: abortController?.signal,
  11600. mode: "cors",
  11601. credentials: withCredentials ? "include" : "same-origin",
  11602. redirect: "follow"
  11603. };
  11604. }
  11605. function createHeaders(httpHeaders) {
  11606. const headers = new Headers();
  11607. for (const property in httpHeaders) {
  11608. const value = httpHeaders[property];
  11609. if (typeof value === "undefined") {
  11610. continue;
  11611. }
  11612. headers.append(property, value);
  11613. }
  11614. return headers;
  11615. }
  11616. class PDFFetchStream {
  11617. constructor(source) {
  11618. this.source = source;
  11619. this.isHttp = /^https?:/i.test(source.url);
  11620. this.httpHeaders = this.isHttp && source.httpHeaders || {};
  11621. this._fullRequestReader = null;
  11622. this._rangeRequestReaders = [];
  11623. }
  11624. get _progressiveDataLength() {
  11625. return this._fullRequestReader?._loaded ?? 0;
  11626. }
  11627. getFullReader() {
  11628. (0, _util.assert)(!this._fullRequestReader, "PDFFetchStream.getFullReader can only be called once.");
  11629. this._fullRequestReader = new PDFFetchStreamReader(this);
  11630. return this._fullRequestReader;
  11631. }
  11632. getRangeReader(begin, end) {
  11633. if (end <= this._progressiveDataLength) {
  11634. return null;
  11635. }
  11636. const reader = new PDFFetchStreamRangeReader(this, begin, end);
  11637. this._rangeRequestReaders.push(reader);
  11638. return reader;
  11639. }
  11640. cancelAllRequests(reason) {
  11641. if (this._fullRequestReader) {
  11642. this._fullRequestReader.cancel(reason);
  11643. }
  11644. const readers = this._rangeRequestReaders.slice(0);
  11645. readers.forEach(function (reader) {
  11646. reader.cancel(reason);
  11647. });
  11648. }
  11649. }
  11650. exports.PDFFetchStream = PDFFetchStream;
  11651. class PDFFetchStreamReader {
  11652. constructor(stream) {
  11653. this._stream = stream;
  11654. this._reader = null;
  11655. this._loaded = 0;
  11656. this._filename = null;
  11657. const source = stream.source;
  11658. this._withCredentials = source.withCredentials || false;
  11659. this._contentLength = source.length;
  11660. this._headersCapability = (0, _util.createPromiseCapability)();
  11661. this._disableRange = source.disableRange || false;
  11662. this._rangeChunkSize = source.rangeChunkSize;
  11663. if (!this._rangeChunkSize && !this._disableRange) {
  11664. this._disableRange = true;
  11665. }
  11666. if (typeof AbortController !== "undefined") {
  11667. this._abortController = new AbortController();
  11668. }
  11669. this._isStreamingSupported = !source.disableStream;
  11670. this._isRangeSupported = !source.disableRange;
  11671. this._headers = createHeaders(this._stream.httpHeaders);
  11672. const url = source.url;
  11673. fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(response => {
  11674. if (!(0, _network_utils.validateResponseStatus)(response.status)) {
  11675. throw (0, _network_utils.createResponseStatusError)(response.status, url);
  11676. }
  11677. this._reader = response.body.getReader();
  11678. this._headersCapability.resolve();
  11679. const getResponseHeader = name => {
  11680. return response.headers.get(name);
  11681. };
  11682. const {
  11683. allowRangeRequests,
  11684. suggestedLength
  11685. } = (0, _network_utils.validateRangeRequestCapabilities)({
  11686. getResponseHeader,
  11687. isHttp: this._stream.isHttp,
  11688. rangeChunkSize: this._rangeChunkSize,
  11689. disableRange: this._disableRange
  11690. });
  11691. this._isRangeSupported = allowRangeRequests;
  11692. this._contentLength = suggestedLength || this._contentLength;
  11693. this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
  11694. if (!this._isStreamingSupported && this._isRangeSupported) {
  11695. this.cancel(new _util.AbortException("Streaming is disabled."));
  11696. }
  11697. }).catch(this._headersCapability.reject);
  11698. this.onProgress = null;
  11699. }
  11700. get headersReady() {
  11701. return this._headersCapability.promise;
  11702. }
  11703. get filename() {
  11704. return this._filename;
  11705. }
  11706. get contentLength() {
  11707. return this._contentLength;
  11708. }
  11709. get isRangeSupported() {
  11710. return this._isRangeSupported;
  11711. }
  11712. get isStreamingSupported() {
  11713. return this._isStreamingSupported;
  11714. }
  11715. async read() {
  11716. await this._headersCapability.promise;
  11717. const {
  11718. value,
  11719. done
  11720. } = await this._reader.read();
  11721. if (done) {
  11722. return {
  11723. value,
  11724. done
  11725. };
  11726. }
  11727. this._loaded += value.byteLength;
  11728. if (this.onProgress) {
  11729. this.onProgress({
  11730. loaded: this._loaded,
  11731. total: this._contentLength
  11732. });
  11733. }
  11734. const buffer = new Uint8Array(value).buffer;
  11735. return {
  11736. value: buffer,
  11737. done: false
  11738. };
  11739. }
  11740. cancel(reason) {
  11741. if (this._reader) {
  11742. this._reader.cancel(reason);
  11743. }
  11744. if (this._abortController) {
  11745. this._abortController.abort();
  11746. }
  11747. }
  11748. }
  11749. class PDFFetchStreamRangeReader {
  11750. constructor(stream, begin, end) {
  11751. this._stream = stream;
  11752. this._reader = null;
  11753. this._loaded = 0;
  11754. const source = stream.source;
  11755. this._withCredentials = source.withCredentials || false;
  11756. this._readCapability = (0, _util.createPromiseCapability)();
  11757. this._isStreamingSupported = !source.disableStream;
  11758. if (typeof AbortController !== "undefined") {
  11759. this._abortController = new AbortController();
  11760. }
  11761. this._headers = createHeaders(this._stream.httpHeaders);
  11762. this._headers.append("Range", `bytes=${begin}-${end - 1}`);
  11763. const url = source.url;
  11764. fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(response => {
  11765. if (!(0, _network_utils.validateResponseStatus)(response.status)) {
  11766. throw (0, _network_utils.createResponseStatusError)(response.status, url);
  11767. }
  11768. this._readCapability.resolve();
  11769. this._reader = response.body.getReader();
  11770. }).catch(reason => {
  11771. if (reason?.name === "AbortError") {
  11772. return;
  11773. }
  11774. throw reason;
  11775. });
  11776. this.onProgress = null;
  11777. }
  11778. get isStreamingSupported() {
  11779. return this._isStreamingSupported;
  11780. }
  11781. async read() {
  11782. await this._readCapability.promise;
  11783. const {
  11784. value,
  11785. done
  11786. } = await this._reader.read();
  11787. if (done) {
  11788. return {
  11789. value,
  11790. done
  11791. };
  11792. }
  11793. this._loaded += value.byteLength;
  11794. if (this.onProgress) {
  11795. this.onProgress({
  11796. loaded: this._loaded
  11797. });
  11798. }
  11799. const buffer = new Uint8Array(value).buffer;
  11800. return {
  11801. value: buffer,
  11802. done: false
  11803. };
  11804. }
  11805. cancel(reason) {
  11806. if (this._reader) {
  11807. this._reader.cancel(reason);
  11808. }
  11809. if (this._abortController) {
  11810. this._abortController.abort();
  11811. }
  11812. }
  11813. }
  11814. /***/ })
  11815. /******/ ]);
  11816. /************************************************************************/
  11817. /******/ // The module cache
  11818. /******/ var __webpack_module_cache__ = {};
  11819. /******/
  11820. /******/ // The require function
  11821. /******/ function __w_pdfjs_require__(moduleId) {
  11822. /******/ // Check if module is in cache
  11823. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  11824. /******/ if (cachedModule !== undefined) {
  11825. /******/ return cachedModule.exports;
  11826. /******/ }
  11827. /******/ // Create a new module (and put it into the cache)
  11828. /******/ var module = __webpack_module_cache__[moduleId] = {
  11829. /******/ // no module.id needed
  11830. /******/ // no module.loaded needed
  11831. /******/ exports: {}
  11832. /******/ };
  11833. /******/
  11834. /******/ // Execute the module function
  11835. /******/ __webpack_modules__[moduleId](module, module.exports, __w_pdfjs_require__);
  11836. /******/
  11837. /******/ // Return the exports of the module
  11838. /******/ return module.exports;
  11839. /******/ }
  11840. /******/
  11841. /************************************************************************/
  11842. var __webpack_exports__ = {};
  11843. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  11844. (() => {
  11845. var exports = __webpack_exports__;
  11846. Object.defineProperty(exports, "__esModule", ({
  11847. value: true
  11848. }));
  11849. Object.defineProperty(exports, "addLinkAttributes", ({
  11850. enumerable: true,
  11851. get: function () {
  11852. return _display_utils.addLinkAttributes;
  11853. }
  11854. }));
  11855. Object.defineProperty(exports, "getFilenameFromUrl", ({
  11856. enumerable: true,
  11857. get: function () {
  11858. return _display_utils.getFilenameFromUrl;
  11859. }
  11860. }));
  11861. Object.defineProperty(exports, "getPdfFilenameFromUrl", ({
  11862. enumerable: true,
  11863. get: function () {
  11864. return _display_utils.getPdfFilenameFromUrl;
  11865. }
  11866. }));
  11867. Object.defineProperty(exports, "isPdfFile", ({
  11868. enumerable: true,
  11869. get: function () {
  11870. return _display_utils.isPdfFile;
  11871. }
  11872. }));
  11873. Object.defineProperty(exports, "LinkTarget", ({
  11874. enumerable: true,
  11875. get: function () {
  11876. return _display_utils.LinkTarget;
  11877. }
  11878. }));
  11879. Object.defineProperty(exports, "loadScript", ({
  11880. enumerable: true,
  11881. get: function () {
  11882. return _display_utils.loadScript;
  11883. }
  11884. }));
  11885. Object.defineProperty(exports, "PDFDateString", ({
  11886. enumerable: true,
  11887. get: function () {
  11888. return _display_utils.PDFDateString;
  11889. }
  11890. }));
  11891. Object.defineProperty(exports, "RenderingCancelledException", ({
  11892. enumerable: true,
  11893. get: function () {
  11894. return _display_utils.RenderingCancelledException;
  11895. }
  11896. }));
  11897. Object.defineProperty(exports, "build", ({
  11898. enumerable: true,
  11899. get: function () {
  11900. return _api.build;
  11901. }
  11902. }));
  11903. Object.defineProperty(exports, "getDocument", ({
  11904. enumerable: true,
  11905. get: function () {
  11906. return _api.getDocument;
  11907. }
  11908. }));
  11909. Object.defineProperty(exports, "LoopbackPort", ({
  11910. enumerable: true,
  11911. get: function () {
  11912. return _api.LoopbackPort;
  11913. }
  11914. }));
  11915. Object.defineProperty(exports, "PDFDataRangeTransport", ({
  11916. enumerable: true,
  11917. get: function () {
  11918. return _api.PDFDataRangeTransport;
  11919. }
  11920. }));
  11921. Object.defineProperty(exports, "PDFWorker", ({
  11922. enumerable: true,
  11923. get: function () {
  11924. return _api.PDFWorker;
  11925. }
  11926. }));
  11927. Object.defineProperty(exports, "version", ({
  11928. enumerable: true,
  11929. get: function () {
  11930. return _api.version;
  11931. }
  11932. }));
  11933. Object.defineProperty(exports, "CMapCompressionType", ({
  11934. enumerable: true,
  11935. get: function () {
  11936. return _util.CMapCompressionType;
  11937. }
  11938. }));
  11939. Object.defineProperty(exports, "createObjectURL", ({
  11940. enumerable: true,
  11941. get: function () {
  11942. return _util.createObjectURL;
  11943. }
  11944. }));
  11945. Object.defineProperty(exports, "createPromiseCapability", ({
  11946. enumerable: true,
  11947. get: function () {
  11948. return _util.createPromiseCapability;
  11949. }
  11950. }));
  11951. Object.defineProperty(exports, "createValidAbsoluteUrl", ({
  11952. enumerable: true,
  11953. get: function () {
  11954. return _util.createValidAbsoluteUrl;
  11955. }
  11956. }));
  11957. Object.defineProperty(exports, "InvalidPDFException", ({
  11958. enumerable: true,
  11959. get: function () {
  11960. return _util.InvalidPDFException;
  11961. }
  11962. }));
  11963. Object.defineProperty(exports, "MissingPDFException", ({
  11964. enumerable: true,
  11965. get: function () {
  11966. return _util.MissingPDFException;
  11967. }
  11968. }));
  11969. Object.defineProperty(exports, "OPS", ({
  11970. enumerable: true,
  11971. get: function () {
  11972. return _util.OPS;
  11973. }
  11974. }));
  11975. Object.defineProperty(exports, "PasswordResponses", ({
  11976. enumerable: true,
  11977. get: function () {
  11978. return _util.PasswordResponses;
  11979. }
  11980. }));
  11981. Object.defineProperty(exports, "PermissionFlag", ({
  11982. enumerable: true,
  11983. get: function () {
  11984. return _util.PermissionFlag;
  11985. }
  11986. }));
  11987. Object.defineProperty(exports, "removeNullCharacters", ({
  11988. enumerable: true,
  11989. get: function () {
  11990. return _util.removeNullCharacters;
  11991. }
  11992. }));
  11993. Object.defineProperty(exports, "shadow", ({
  11994. enumerable: true,
  11995. get: function () {
  11996. return _util.shadow;
  11997. }
  11998. }));
  11999. Object.defineProperty(exports, "UnexpectedResponseException", ({
  12000. enumerable: true,
  12001. get: function () {
  12002. return _util.UnexpectedResponseException;
  12003. }
  12004. }));
  12005. Object.defineProperty(exports, "UNSUPPORTED_FEATURES", ({
  12006. enumerable: true,
  12007. get: function () {
  12008. return _util.UNSUPPORTED_FEATURES;
  12009. }
  12010. }));
  12011. Object.defineProperty(exports, "Util", ({
  12012. enumerable: true,
  12013. get: function () {
  12014. return _util.Util;
  12015. }
  12016. }));
  12017. Object.defineProperty(exports, "VerbosityLevel", ({
  12018. enumerable: true,
  12019. get: function () {
  12020. return _util.VerbosityLevel;
  12021. }
  12022. }));
  12023. Object.defineProperty(exports, "AnnotationLayer", ({
  12024. enumerable: true,
  12025. get: function () {
  12026. return _annotation_layer.AnnotationLayer;
  12027. }
  12028. }));
  12029. Object.defineProperty(exports, "apiCompatibilityParams", ({
  12030. enumerable: true,
  12031. get: function () {
  12032. return _api_compatibility.apiCompatibilityParams;
  12033. }
  12034. }));
  12035. Object.defineProperty(exports, "GlobalWorkerOptions", ({
  12036. enumerable: true,
  12037. get: function () {
  12038. return _worker_options.GlobalWorkerOptions;
  12039. }
  12040. }));
  12041. Object.defineProperty(exports, "renderTextLayer", ({
  12042. enumerable: true,
  12043. get: function () {
  12044. return _text_layer.renderTextLayer;
  12045. }
  12046. }));
  12047. Object.defineProperty(exports, "SVGGraphics", ({
  12048. enumerable: true,
  12049. get: function () {
  12050. return _svg.SVGGraphics;
  12051. }
  12052. }));
  12053. Object.defineProperty(exports, "XfaLayer", ({
  12054. enumerable: true,
  12055. get: function () {
  12056. return _xfa_layer.XfaLayer;
  12057. }
  12058. }));
  12059. var _display_utils = __w_pdfjs_require__(1);
  12060. var _api = __w_pdfjs_require__(5);
  12061. var _util = __w_pdfjs_require__(2);
  12062. var _annotation_layer = __w_pdfjs_require__(18);
  12063. var _api_compatibility = __w_pdfjs_require__(9);
  12064. var _worker_options = __w_pdfjs_require__(12);
  12065. var _text_layer = __w_pdfjs_require__(20);
  12066. var _svg = __w_pdfjs_require__(21);
  12067. var _xfa_layer = __w_pdfjs_require__(22);
  12068. const pdfjsVersion = '2.8.335';
  12069. const pdfjsBuild = '228adbf67';
  12070. {
  12071. const {
  12072. isNodeJS
  12073. } = __w_pdfjs_require__(4);
  12074. if (isNodeJS) {
  12075. const PDFNodeStream = __w_pdfjs_require__(23).PDFNodeStream;
  12076. (0, _api.setPDFNetworkStreamFactory)(params => {
  12077. return new PDFNodeStream(params);
  12078. });
  12079. } else {
  12080. const PDFNetworkStream = __w_pdfjs_require__(26).PDFNetworkStream;
  12081. let PDFFetchStream;
  12082. if ((0, _display_utils.isFetchSupported)()) {
  12083. PDFFetchStream = __w_pdfjs_require__(27).PDFFetchStream;
  12084. }
  12085. (0, _api.setPDFNetworkStreamFactory)(params => {
  12086. if (PDFFetchStream && (0, _display_utils.isValidFetchUrl)(params.url)) {
  12087. return new PDFFetchStream(params);
  12088. }
  12089. return new PDFNetworkStream(params);
  12090. });
  12091. }
  12092. }
  12093. })();
  12094. /******/ return __webpack_exports__;
  12095. /******/ })()
  12096. ;
  12097. });
  12098. //# sourceMappingURL=pdf.js.map