pdf.js 490 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * JavaScript code in this page
  4. *
  5. * Copyright 2023 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * JavaScript code in this page
  21. */
  22. (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. })(globalThis, () => {
  32. return /******/ (() => { // webpackBootstrap
  33. /******/ "use strict";
  34. /******/ var __webpack_modules__ = ([
  35. /* 0 */,
  36. /* 1 */
  37. /***/ ((__unused_webpack_module, exports) => {
  38. Object.defineProperty(exports, "__esModule", ({
  39. value: true
  40. }));
  41. exports.VerbosityLevel = exports.Util = exports.UnknownErrorException = exports.UnexpectedResponseException = exports.TextRenderingMode = exports.RenderingIntentFlag = exports.PromiseCapability = exports.PermissionFlag = exports.PasswordResponses = exports.PasswordException = exports.PageActionEventType = exports.OPS = exports.MissingPDFException = exports.MAX_IMAGE_SIZE_TO_CACHE = exports.LINE_FACTOR = exports.LINE_DESCENT_FACTOR = exports.InvalidPDFException = exports.ImageKind = exports.IDENTITY_MATRIX = exports.FormatError = exports.FeatureTest = exports.FONT_IDENTITY_MATRIX = exports.DocumentActionEventType = exports.CMapCompressionType = exports.BaseException = exports.BASELINE_FACTOR = exports.AnnotationType = exports.AnnotationStateModelType = exports.AnnotationReviewState = exports.AnnotationReplyType = exports.AnnotationMode = exports.AnnotationMarkedState = exports.AnnotationFlag = exports.AnnotationFieldFlag = exports.AnnotationEditorType = exports.AnnotationEditorPrefix = exports.AnnotationEditorParamsType = exports.AnnotationBorderStyleType = exports.AnnotationActionEventType = exports.AbortException = void 0;
  42. exports.assert = assert;
  43. exports.bytesToString = bytesToString;
  44. exports.createValidAbsoluteUrl = createValidAbsoluteUrl;
  45. exports.getModificationDate = getModificationDate;
  46. exports.getVerbosityLevel = getVerbosityLevel;
  47. exports.info = info;
  48. exports.isArrayBuffer = isArrayBuffer;
  49. exports.isArrayEqual = isArrayEqual;
  50. exports.normalizeUnicode = normalizeUnicode;
  51. exports.objectFromMap = objectFromMap;
  52. exports.objectSize = objectSize;
  53. exports.setVerbosityLevel = setVerbosityLevel;
  54. exports.shadow = shadow;
  55. exports.string32 = string32;
  56. exports.stringToBytes = stringToBytes;
  57. exports.stringToPDFString = stringToPDFString;
  58. exports.stringToUTF8String = stringToUTF8String;
  59. exports.unreachable = unreachable;
  60. exports.utf8StringToString = utf8StringToString;
  61. exports.warn = warn;
  62. ;
  63. const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  64. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  65. const FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  66. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  67. const MAX_IMAGE_SIZE_TO_CACHE = 10e6;
  68. exports.MAX_IMAGE_SIZE_TO_CACHE = MAX_IMAGE_SIZE_TO_CACHE;
  69. const LINE_FACTOR = 1.35;
  70. exports.LINE_FACTOR = LINE_FACTOR;
  71. const LINE_DESCENT_FACTOR = 0.35;
  72. exports.LINE_DESCENT_FACTOR = LINE_DESCENT_FACTOR;
  73. const BASELINE_FACTOR = LINE_DESCENT_FACTOR / LINE_FACTOR;
  74. exports.BASELINE_FACTOR = BASELINE_FACTOR;
  75. const RenderingIntentFlag = {
  76. ANY: 0x01,
  77. DISPLAY: 0x02,
  78. PRINT: 0x04,
  79. SAVE: 0x08,
  80. ANNOTATIONS_FORMS: 0x10,
  81. ANNOTATIONS_STORAGE: 0x20,
  82. ANNOTATIONS_DISABLE: 0x40,
  83. OPLIST: 0x100
  84. };
  85. exports.RenderingIntentFlag = RenderingIntentFlag;
  86. const AnnotationMode = {
  87. DISABLE: 0,
  88. ENABLE: 1,
  89. ENABLE_FORMS: 2,
  90. ENABLE_STORAGE: 3
  91. };
  92. exports.AnnotationMode = AnnotationMode;
  93. const AnnotationEditorPrefix = "pdfjs_internal_editor_";
  94. exports.AnnotationEditorPrefix = AnnotationEditorPrefix;
  95. const AnnotationEditorType = {
  96. DISABLE: -1,
  97. NONE: 0,
  98. FREETEXT: 3,
  99. INK: 15
  100. };
  101. exports.AnnotationEditorType = AnnotationEditorType;
  102. const AnnotationEditorParamsType = {
  103. FREETEXT_SIZE: 1,
  104. FREETEXT_COLOR: 2,
  105. FREETEXT_OPACITY: 3,
  106. INK_COLOR: 11,
  107. INK_THICKNESS: 12,
  108. INK_OPACITY: 13
  109. };
  110. exports.AnnotationEditorParamsType = AnnotationEditorParamsType;
  111. const PermissionFlag = {
  112. PRINT: 0x04,
  113. MODIFY_CONTENTS: 0x08,
  114. COPY: 0x10,
  115. MODIFY_ANNOTATIONS: 0x20,
  116. FILL_INTERACTIVE_FORMS: 0x100,
  117. COPY_FOR_ACCESSIBILITY: 0x200,
  118. ASSEMBLE: 0x400,
  119. PRINT_HIGH_QUALITY: 0x800
  120. };
  121. exports.PermissionFlag = PermissionFlag;
  122. const TextRenderingMode = {
  123. FILL: 0,
  124. STROKE: 1,
  125. FILL_STROKE: 2,
  126. INVISIBLE: 3,
  127. FILL_ADD_TO_PATH: 4,
  128. STROKE_ADD_TO_PATH: 5,
  129. FILL_STROKE_ADD_TO_PATH: 6,
  130. ADD_TO_PATH: 7,
  131. FILL_STROKE_MASK: 3,
  132. ADD_TO_PATH_FLAG: 4
  133. };
  134. exports.TextRenderingMode = TextRenderingMode;
  135. const ImageKind = {
  136. GRAYSCALE_1BPP: 1,
  137. RGB_24BPP: 2,
  138. RGBA_32BPP: 3
  139. };
  140. exports.ImageKind = ImageKind;
  141. const AnnotationType = {
  142. TEXT: 1,
  143. LINK: 2,
  144. FREETEXT: 3,
  145. LINE: 4,
  146. SQUARE: 5,
  147. CIRCLE: 6,
  148. POLYGON: 7,
  149. POLYLINE: 8,
  150. HIGHLIGHT: 9,
  151. UNDERLINE: 10,
  152. SQUIGGLY: 11,
  153. STRIKEOUT: 12,
  154. STAMP: 13,
  155. CARET: 14,
  156. INK: 15,
  157. POPUP: 16,
  158. FILEATTACHMENT: 17,
  159. SOUND: 18,
  160. MOVIE: 19,
  161. WIDGET: 20,
  162. SCREEN: 21,
  163. PRINTERMARK: 22,
  164. TRAPNET: 23,
  165. WATERMARK: 24,
  166. THREED: 25,
  167. REDACT: 26
  168. };
  169. exports.AnnotationType = AnnotationType;
  170. const AnnotationStateModelType = {
  171. MARKED: "Marked",
  172. REVIEW: "Review"
  173. };
  174. exports.AnnotationStateModelType = AnnotationStateModelType;
  175. const AnnotationMarkedState = {
  176. MARKED: "Marked",
  177. UNMARKED: "Unmarked"
  178. };
  179. exports.AnnotationMarkedState = AnnotationMarkedState;
  180. const AnnotationReviewState = {
  181. ACCEPTED: "Accepted",
  182. REJECTED: "Rejected",
  183. CANCELLED: "Cancelled",
  184. COMPLETED: "Completed",
  185. NONE: "None"
  186. };
  187. exports.AnnotationReviewState = AnnotationReviewState;
  188. const AnnotationReplyType = {
  189. GROUP: "Group",
  190. REPLY: "R"
  191. };
  192. exports.AnnotationReplyType = AnnotationReplyType;
  193. const AnnotationFlag = {
  194. INVISIBLE: 0x01,
  195. HIDDEN: 0x02,
  196. PRINT: 0x04,
  197. NOZOOM: 0x08,
  198. NOROTATE: 0x10,
  199. NOVIEW: 0x20,
  200. READONLY: 0x40,
  201. LOCKED: 0x80,
  202. TOGGLENOVIEW: 0x100,
  203. LOCKEDCONTENTS: 0x200
  204. };
  205. exports.AnnotationFlag = AnnotationFlag;
  206. const AnnotationFieldFlag = {
  207. READONLY: 0x0000001,
  208. REQUIRED: 0x0000002,
  209. NOEXPORT: 0x0000004,
  210. MULTILINE: 0x0001000,
  211. PASSWORD: 0x0002000,
  212. NOTOGGLETOOFF: 0x0004000,
  213. RADIO: 0x0008000,
  214. PUSHBUTTON: 0x0010000,
  215. COMBO: 0x0020000,
  216. EDIT: 0x0040000,
  217. SORT: 0x0080000,
  218. FILESELECT: 0x0100000,
  219. MULTISELECT: 0x0200000,
  220. DONOTSPELLCHECK: 0x0400000,
  221. DONOTSCROLL: 0x0800000,
  222. COMB: 0x1000000,
  223. RICHTEXT: 0x2000000,
  224. RADIOSINUNISON: 0x2000000,
  225. COMMITONSELCHANGE: 0x4000000
  226. };
  227. exports.AnnotationFieldFlag = AnnotationFieldFlag;
  228. const AnnotationBorderStyleType = {
  229. SOLID: 1,
  230. DASHED: 2,
  231. BEVELED: 3,
  232. INSET: 4,
  233. UNDERLINE: 5
  234. };
  235. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  236. const AnnotationActionEventType = {
  237. E: "Mouse Enter",
  238. X: "Mouse Exit",
  239. D: "Mouse Down",
  240. U: "Mouse Up",
  241. Fo: "Focus",
  242. Bl: "Blur",
  243. PO: "PageOpen",
  244. PC: "PageClose",
  245. PV: "PageVisible",
  246. PI: "PageInvisible",
  247. K: "Keystroke",
  248. F: "Format",
  249. V: "Validate",
  250. C: "Calculate"
  251. };
  252. exports.AnnotationActionEventType = AnnotationActionEventType;
  253. const DocumentActionEventType = {
  254. WC: "WillClose",
  255. WS: "WillSave",
  256. DS: "DidSave",
  257. WP: "WillPrint",
  258. DP: "DidPrint"
  259. };
  260. exports.DocumentActionEventType = DocumentActionEventType;
  261. const PageActionEventType = {
  262. O: "PageOpen",
  263. C: "PageClose"
  264. };
  265. exports.PageActionEventType = PageActionEventType;
  266. const VerbosityLevel = {
  267. ERRORS: 0,
  268. WARNINGS: 1,
  269. INFOS: 5
  270. };
  271. exports.VerbosityLevel = VerbosityLevel;
  272. const CMapCompressionType = {
  273. NONE: 0,
  274. BINARY: 1
  275. };
  276. exports.CMapCompressionType = CMapCompressionType;
  277. const OPS = {
  278. dependency: 1,
  279. setLineWidth: 2,
  280. setLineCap: 3,
  281. setLineJoin: 4,
  282. setMiterLimit: 5,
  283. setDash: 6,
  284. setRenderingIntent: 7,
  285. setFlatness: 8,
  286. setGState: 9,
  287. save: 10,
  288. restore: 11,
  289. transform: 12,
  290. moveTo: 13,
  291. lineTo: 14,
  292. curveTo: 15,
  293. curveTo2: 16,
  294. curveTo3: 17,
  295. closePath: 18,
  296. rectangle: 19,
  297. stroke: 20,
  298. closeStroke: 21,
  299. fill: 22,
  300. eoFill: 23,
  301. fillStroke: 24,
  302. eoFillStroke: 25,
  303. closeFillStroke: 26,
  304. closeEOFillStroke: 27,
  305. endPath: 28,
  306. clip: 29,
  307. eoClip: 30,
  308. beginText: 31,
  309. endText: 32,
  310. setCharSpacing: 33,
  311. setWordSpacing: 34,
  312. setHScale: 35,
  313. setLeading: 36,
  314. setFont: 37,
  315. setTextRenderingMode: 38,
  316. setTextRise: 39,
  317. moveText: 40,
  318. setLeadingMoveText: 41,
  319. setTextMatrix: 42,
  320. nextLine: 43,
  321. showText: 44,
  322. showSpacedText: 45,
  323. nextLineShowText: 46,
  324. nextLineSetSpacingShowText: 47,
  325. setCharWidth: 48,
  326. setCharWidthAndBounds: 49,
  327. setStrokeColorSpace: 50,
  328. setFillColorSpace: 51,
  329. setStrokeColor: 52,
  330. setStrokeColorN: 53,
  331. setFillColor: 54,
  332. setFillColorN: 55,
  333. setStrokeGray: 56,
  334. setFillGray: 57,
  335. setStrokeRGBColor: 58,
  336. setFillRGBColor: 59,
  337. setStrokeCMYKColor: 60,
  338. setFillCMYKColor: 61,
  339. shadingFill: 62,
  340. beginInlineImage: 63,
  341. beginImageData: 64,
  342. endInlineImage: 65,
  343. paintXObject: 66,
  344. markPoint: 67,
  345. markPointProps: 68,
  346. beginMarkedContent: 69,
  347. beginMarkedContentProps: 70,
  348. endMarkedContent: 71,
  349. beginCompat: 72,
  350. endCompat: 73,
  351. paintFormXObjectBegin: 74,
  352. paintFormXObjectEnd: 75,
  353. beginGroup: 76,
  354. endGroup: 77,
  355. beginAnnotation: 80,
  356. endAnnotation: 81,
  357. paintImageMaskXObject: 83,
  358. paintImageMaskXObjectGroup: 84,
  359. paintImageXObject: 85,
  360. paintInlineImageXObject: 86,
  361. paintInlineImageXObjectGroup: 87,
  362. paintImageXObjectRepeat: 88,
  363. paintImageMaskXObjectRepeat: 89,
  364. paintSolidColorImageMask: 90,
  365. constructPath: 91
  366. };
  367. exports.OPS = OPS;
  368. const PasswordResponses = {
  369. NEED_PASSWORD: 1,
  370. INCORRECT_PASSWORD: 2
  371. };
  372. exports.PasswordResponses = PasswordResponses;
  373. let verbosity = VerbosityLevel.WARNINGS;
  374. function setVerbosityLevel(level) {
  375. if (Number.isInteger(level)) {
  376. verbosity = level;
  377. }
  378. }
  379. function getVerbosityLevel() {
  380. return verbosity;
  381. }
  382. function info(msg) {
  383. if (verbosity >= VerbosityLevel.INFOS) {
  384. console.log(`Info: ${msg}`);
  385. }
  386. }
  387. function warn(msg) {
  388. if (verbosity >= VerbosityLevel.WARNINGS) {
  389. console.log(`Warning: ${msg}`);
  390. }
  391. }
  392. function unreachable(msg) {
  393. throw new Error(msg);
  394. }
  395. function assert(cond, msg) {
  396. if (!cond) {
  397. unreachable(msg);
  398. }
  399. }
  400. function _isValidProtocol(url) {
  401. switch (url?.protocol) {
  402. case "http:":
  403. case "https:":
  404. case "ftp:":
  405. case "mailto:":
  406. case "tel:":
  407. return true;
  408. default:
  409. return false;
  410. }
  411. }
  412. function createValidAbsoluteUrl(url, baseUrl = null, options = null) {
  413. if (!url) {
  414. return null;
  415. }
  416. try {
  417. if (options && typeof url === "string") {
  418. if (options.addDefaultProtocol && url.startsWith("www.")) {
  419. const dots = url.match(/\./g);
  420. if (dots?.length >= 2) {
  421. url = `http://${url}`;
  422. }
  423. }
  424. if (options.tryConvertEncoding) {
  425. try {
  426. url = stringToUTF8String(url);
  427. } catch (ex) {}
  428. }
  429. }
  430. const absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url);
  431. if (_isValidProtocol(absoluteUrl)) {
  432. return absoluteUrl;
  433. }
  434. } catch (ex) {}
  435. return null;
  436. }
  437. function shadow(obj, prop, value, nonSerializable = false) {
  438. Object.defineProperty(obj, prop, {
  439. value,
  440. enumerable: !nonSerializable,
  441. configurable: true,
  442. writable: false
  443. });
  444. return value;
  445. }
  446. const BaseException = function BaseExceptionClosure() {
  447. function BaseException(message, name) {
  448. if (this.constructor === BaseException) {
  449. unreachable("Cannot initialize BaseException.");
  450. }
  451. this.message = message;
  452. this.name = name;
  453. }
  454. BaseException.prototype = new Error();
  455. BaseException.constructor = BaseException;
  456. return BaseException;
  457. }();
  458. exports.BaseException = BaseException;
  459. class PasswordException extends BaseException {
  460. constructor(msg, code) {
  461. super(msg, "PasswordException");
  462. this.code = code;
  463. }
  464. }
  465. exports.PasswordException = PasswordException;
  466. class UnknownErrorException extends BaseException {
  467. constructor(msg, details) {
  468. super(msg, "UnknownErrorException");
  469. this.details = details;
  470. }
  471. }
  472. exports.UnknownErrorException = UnknownErrorException;
  473. class InvalidPDFException extends BaseException {
  474. constructor(msg) {
  475. super(msg, "InvalidPDFException");
  476. }
  477. }
  478. exports.InvalidPDFException = InvalidPDFException;
  479. class MissingPDFException extends BaseException {
  480. constructor(msg) {
  481. super(msg, "MissingPDFException");
  482. }
  483. }
  484. exports.MissingPDFException = MissingPDFException;
  485. class UnexpectedResponseException extends BaseException {
  486. constructor(msg, status) {
  487. super(msg, "UnexpectedResponseException");
  488. this.status = status;
  489. }
  490. }
  491. exports.UnexpectedResponseException = UnexpectedResponseException;
  492. class FormatError extends BaseException {
  493. constructor(msg) {
  494. super(msg, "FormatError");
  495. }
  496. }
  497. exports.FormatError = FormatError;
  498. class AbortException extends BaseException {
  499. constructor(msg) {
  500. super(msg, "AbortException");
  501. }
  502. }
  503. exports.AbortException = AbortException;
  504. function bytesToString(bytes) {
  505. if (typeof bytes !== "object" || bytes?.length === undefined) {
  506. unreachable("Invalid argument for bytesToString");
  507. }
  508. const length = bytes.length;
  509. const MAX_ARGUMENT_COUNT = 8192;
  510. if (length < MAX_ARGUMENT_COUNT) {
  511. return String.fromCharCode.apply(null, bytes);
  512. }
  513. const strBuf = [];
  514. for (let i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  515. const chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  516. const chunk = bytes.subarray(i, chunkEnd);
  517. strBuf.push(String.fromCharCode.apply(null, chunk));
  518. }
  519. return strBuf.join("");
  520. }
  521. function stringToBytes(str) {
  522. if (typeof str !== "string") {
  523. unreachable("Invalid argument for stringToBytes");
  524. }
  525. const length = str.length;
  526. const bytes = new Uint8Array(length);
  527. for (let i = 0; i < length; ++i) {
  528. bytes[i] = str.charCodeAt(i) & 0xff;
  529. }
  530. return bytes;
  531. }
  532. function string32(value) {
  533. return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
  534. }
  535. function objectSize(obj) {
  536. return Object.keys(obj).length;
  537. }
  538. function objectFromMap(map) {
  539. const obj = Object.create(null);
  540. for (const [key, value] of map) {
  541. obj[key] = value;
  542. }
  543. return obj;
  544. }
  545. function isLittleEndian() {
  546. const buffer8 = new Uint8Array(4);
  547. buffer8[0] = 1;
  548. const view32 = new Uint32Array(buffer8.buffer, 0, 1);
  549. return view32[0] === 1;
  550. }
  551. function isEvalSupported() {
  552. try {
  553. new Function("");
  554. return true;
  555. } catch (e) {
  556. return false;
  557. }
  558. }
  559. class FeatureTest {
  560. static get isLittleEndian() {
  561. return shadow(this, "isLittleEndian", isLittleEndian());
  562. }
  563. static get isEvalSupported() {
  564. return shadow(this, "isEvalSupported", isEvalSupported());
  565. }
  566. static get isOffscreenCanvasSupported() {
  567. return shadow(this, "isOffscreenCanvasSupported", typeof OffscreenCanvas !== "undefined");
  568. }
  569. static get platform() {
  570. if (typeof navigator === "undefined") {
  571. return shadow(this, "platform", {
  572. isWin: false,
  573. isMac: false
  574. });
  575. }
  576. return shadow(this, "platform", {
  577. isWin: navigator.platform.includes("Win"),
  578. isMac: navigator.platform.includes("Mac")
  579. });
  580. }
  581. }
  582. exports.FeatureTest = FeatureTest;
  583. const hexNumbers = [...Array(256).keys()].map(n => n.toString(16).padStart(2, "0"));
  584. class Util {
  585. static makeHexColor(r, g, b) {
  586. return `#${hexNumbers[r]}${hexNumbers[g]}${hexNumbers[b]}`;
  587. }
  588. static scaleMinMax(transform, minMax) {
  589. let temp;
  590. if (transform[0]) {
  591. if (transform[0] < 0) {
  592. temp = minMax[0];
  593. minMax[0] = minMax[1];
  594. minMax[1] = temp;
  595. }
  596. minMax[0] *= transform[0];
  597. minMax[1] *= transform[0];
  598. if (transform[3] < 0) {
  599. temp = minMax[2];
  600. minMax[2] = minMax[3];
  601. minMax[3] = temp;
  602. }
  603. minMax[2] *= transform[3];
  604. minMax[3] *= transform[3];
  605. } else {
  606. temp = minMax[0];
  607. minMax[0] = minMax[2];
  608. minMax[2] = temp;
  609. temp = minMax[1];
  610. minMax[1] = minMax[3];
  611. minMax[3] = temp;
  612. if (transform[1] < 0) {
  613. temp = minMax[2];
  614. minMax[2] = minMax[3];
  615. minMax[3] = temp;
  616. }
  617. minMax[2] *= transform[1];
  618. minMax[3] *= transform[1];
  619. if (transform[2] < 0) {
  620. temp = minMax[0];
  621. minMax[0] = minMax[1];
  622. minMax[1] = temp;
  623. }
  624. minMax[0] *= transform[2];
  625. minMax[1] *= transform[2];
  626. }
  627. minMax[0] += transform[4];
  628. minMax[1] += transform[4];
  629. minMax[2] += transform[5];
  630. minMax[3] += transform[5];
  631. }
  632. static transform(m1, m2) {
  633. 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]];
  634. }
  635. static applyTransform(p, m) {
  636. const xt = p[0] * m[0] + p[1] * m[2] + m[4];
  637. const yt = p[0] * m[1] + p[1] * m[3] + m[5];
  638. return [xt, yt];
  639. }
  640. static applyInverseTransform(p, m) {
  641. const d = m[0] * m[3] - m[1] * m[2];
  642. const xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  643. const yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  644. return [xt, yt];
  645. }
  646. static getAxialAlignedBoundingBox(r, m) {
  647. const p1 = Util.applyTransform(r, m);
  648. const p2 = Util.applyTransform(r.slice(2, 4), m);
  649. const p3 = Util.applyTransform([r[0], r[3]], m);
  650. const p4 = Util.applyTransform([r[2], r[1]], m);
  651. 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])];
  652. }
  653. static inverseTransform(m) {
  654. const d = m[0] * m[3] - m[1] * m[2];
  655. 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];
  656. }
  657. static singularValueDecompose2dScale(m) {
  658. const transpose = [m[0], m[2], m[1], m[3]];
  659. const a = m[0] * transpose[0] + m[1] * transpose[2];
  660. const b = m[0] * transpose[1] + m[1] * transpose[3];
  661. const c = m[2] * transpose[0] + m[3] * transpose[2];
  662. const d = m[2] * transpose[1] + m[3] * transpose[3];
  663. const first = (a + d) / 2;
  664. const second = Math.sqrt((a + d) ** 2 - 4 * (a * d - c * b)) / 2;
  665. const sx = first + second || 1;
  666. const sy = first - second || 1;
  667. return [Math.sqrt(sx), Math.sqrt(sy)];
  668. }
  669. static normalizeRect(rect) {
  670. const r = rect.slice(0);
  671. if (rect[0] > rect[2]) {
  672. r[0] = rect[2];
  673. r[2] = rect[0];
  674. }
  675. if (rect[1] > rect[3]) {
  676. r[1] = rect[3];
  677. r[3] = rect[1];
  678. }
  679. return r;
  680. }
  681. static intersect(rect1, rect2) {
  682. const xLow = Math.max(Math.min(rect1[0], rect1[2]), Math.min(rect2[0], rect2[2]));
  683. const xHigh = Math.min(Math.max(rect1[0], rect1[2]), Math.max(rect2[0], rect2[2]));
  684. if (xLow > xHigh) {
  685. return null;
  686. }
  687. const yLow = Math.max(Math.min(rect1[1], rect1[3]), Math.min(rect2[1], rect2[3]));
  688. const yHigh = Math.min(Math.max(rect1[1], rect1[3]), Math.max(rect2[1], rect2[3]));
  689. if (yLow > yHigh) {
  690. return null;
  691. }
  692. return [xLow, yLow, xHigh, yHigh];
  693. }
  694. static bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3) {
  695. const tvalues = [],
  696. bounds = [[], []];
  697. let a, b, c, t, t1, t2, b2ac, sqrtb2ac;
  698. for (let i = 0; i < 2; ++i) {
  699. if (i === 0) {
  700. b = 6 * x0 - 12 * x1 + 6 * x2;
  701. a = -3 * x0 + 9 * x1 - 9 * x2 + 3 * x3;
  702. c = 3 * x1 - 3 * x0;
  703. } else {
  704. b = 6 * y0 - 12 * y1 + 6 * y2;
  705. a = -3 * y0 + 9 * y1 - 9 * y2 + 3 * y3;
  706. c = 3 * y1 - 3 * y0;
  707. }
  708. if (Math.abs(a) < 1e-12) {
  709. if (Math.abs(b) < 1e-12) {
  710. continue;
  711. }
  712. t = -c / b;
  713. if (0 < t && t < 1) {
  714. tvalues.push(t);
  715. }
  716. continue;
  717. }
  718. b2ac = b * b - 4 * c * a;
  719. sqrtb2ac = Math.sqrt(b2ac);
  720. if (b2ac < 0) {
  721. continue;
  722. }
  723. t1 = (-b + sqrtb2ac) / (2 * a);
  724. if (0 < t1 && t1 < 1) {
  725. tvalues.push(t1);
  726. }
  727. t2 = (-b - sqrtb2ac) / (2 * a);
  728. if (0 < t2 && t2 < 1) {
  729. tvalues.push(t2);
  730. }
  731. }
  732. let j = tvalues.length,
  733. mt;
  734. const jlen = j;
  735. while (j--) {
  736. t = tvalues[j];
  737. mt = 1 - t;
  738. bounds[0][j] = mt * mt * mt * x0 + 3 * mt * mt * t * x1 + 3 * mt * t * t * x2 + t * t * t * x3;
  739. bounds[1][j] = mt * mt * mt * y0 + 3 * mt * mt * t * y1 + 3 * mt * t * t * y2 + t * t * t * y3;
  740. }
  741. bounds[0][jlen] = x0;
  742. bounds[1][jlen] = y0;
  743. bounds[0][jlen + 1] = x3;
  744. bounds[1][jlen + 1] = y3;
  745. bounds[0].length = bounds[1].length = jlen + 2;
  746. return [Math.min(...bounds[0]), Math.min(...bounds[1]), Math.max(...bounds[0]), Math.max(...bounds[1])];
  747. }
  748. }
  749. exports.Util = Util;
  750. 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];
  751. function stringToPDFString(str) {
  752. if (str[0] >= "\xEF") {
  753. let encoding;
  754. if (str[0] === "\xFE" && str[1] === "\xFF") {
  755. encoding = "utf-16be";
  756. } else if (str[0] === "\xFF" && str[1] === "\xFE") {
  757. encoding = "utf-16le";
  758. } else if (str[0] === "\xEF" && str[1] === "\xBB" && str[2] === "\xBF") {
  759. encoding = "utf-8";
  760. }
  761. if (encoding) {
  762. try {
  763. const decoder = new TextDecoder(encoding, {
  764. fatal: true
  765. });
  766. const buffer = stringToBytes(str);
  767. return decoder.decode(buffer);
  768. } catch (ex) {
  769. warn(`stringToPDFString: "${ex}".`);
  770. }
  771. }
  772. }
  773. const strBuf = [];
  774. for (let i = 0, ii = str.length; i < ii; i++) {
  775. const code = PDFStringTranslateTable[str.charCodeAt(i)];
  776. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  777. }
  778. return strBuf.join("");
  779. }
  780. function stringToUTF8String(str) {
  781. return decodeURIComponent(escape(str));
  782. }
  783. function utf8StringToString(str) {
  784. return unescape(encodeURIComponent(str));
  785. }
  786. function isArrayBuffer(v) {
  787. return typeof v === "object" && v?.byteLength !== undefined;
  788. }
  789. function isArrayEqual(arr1, arr2) {
  790. if (arr1.length !== arr2.length) {
  791. return false;
  792. }
  793. for (let i = 0, ii = arr1.length; i < ii; i++) {
  794. if (arr1[i] !== arr2[i]) {
  795. return false;
  796. }
  797. }
  798. return true;
  799. }
  800. function getModificationDate(date = new Date()) {
  801. 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")];
  802. return buffer.join("");
  803. }
  804. class PromiseCapability {
  805. #settled = false;
  806. constructor() {
  807. this.promise = new Promise((resolve, reject) => {
  808. this.resolve = data => {
  809. this.#settled = true;
  810. resolve(data);
  811. };
  812. this.reject = reason => {
  813. this.#settled = true;
  814. reject(reason);
  815. };
  816. });
  817. }
  818. get settled() {
  819. return this.#settled;
  820. }
  821. }
  822. exports.PromiseCapability = PromiseCapability;
  823. let NormalizeRegex = null;
  824. let NormalizationMap = null;
  825. function normalizeUnicode(str) {
  826. if (!NormalizeRegex) {
  827. NormalizeRegex = /([\u00a0\u00b5\u037e\u0eb3\u2000-\u200a\u202f\u2126\ufb00-\ufb04\ufb06\ufb20-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufba1\ufba4-\ufba9\ufbae-\ufbb1\ufbd3-\ufbdc\ufbde-\ufbe7\ufbea-\ufbf8\ufbfc-\ufbfd\ufc00-\ufc5d\ufc64-\ufcf1\ufcf5-\ufd3d\ufd88\ufdf4\ufdfa-\ufdfb\ufe71\ufe77\ufe79\ufe7b\ufe7d]+)|(\ufb05+)/gu;
  828. NormalizationMap = new Map([["ſt", "ſt"]]);
  829. }
  830. return str.replaceAll(NormalizeRegex, (_, p1, p2) => {
  831. return p1 ? p1.normalize("NFKC") : NormalizationMap.get(p2);
  832. });
  833. }
  834. /***/ }),
  835. /* 2 */
  836. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  837. Object.defineProperty(exports, "__esModule", ({
  838. value: true
  839. }));
  840. exports.build = exports.RenderTask = exports.PDFWorkerUtil = exports.PDFWorker = exports.PDFPageProxy = exports.PDFDocumentProxy = exports.PDFDocumentLoadingTask = exports.PDFDataRangeTransport = exports.LoopbackPort = exports.DefaultStandardFontDataFactory = exports.DefaultFilterFactory = exports.DefaultCanvasFactory = exports.DefaultCMapReaderFactory = void 0;
  841. exports.getDocument = getDocument;
  842. exports.version = void 0;
  843. var _util = __w_pdfjs_require__(1);
  844. var _annotation_storage = __w_pdfjs_require__(3);
  845. var _display_utils = __w_pdfjs_require__(6);
  846. var _font_loader = __w_pdfjs_require__(9);
  847. var _canvas = __w_pdfjs_require__(11);
  848. var _worker_options = __w_pdfjs_require__(14);
  849. var _is_node = __w_pdfjs_require__(10);
  850. var _message_handler = __w_pdfjs_require__(15);
  851. var _metadata = __w_pdfjs_require__(16);
  852. var _optional_content_config = __w_pdfjs_require__(17);
  853. var _transport_stream = __w_pdfjs_require__(18);
  854. var _xfa_text = __w_pdfjs_require__(19);
  855. const DEFAULT_RANGE_CHUNK_SIZE = 65536;
  856. const RENDERING_CANCELLED_TIMEOUT = 100;
  857. const DELAYED_CLEANUP_TIMEOUT = 5000;
  858. let DefaultCanvasFactory = _display_utils.DOMCanvasFactory;
  859. exports.DefaultCanvasFactory = DefaultCanvasFactory;
  860. let DefaultCMapReaderFactory = _display_utils.DOMCMapReaderFactory;
  861. exports.DefaultCMapReaderFactory = DefaultCMapReaderFactory;
  862. let DefaultFilterFactory = _display_utils.DOMFilterFactory;
  863. exports.DefaultFilterFactory = DefaultFilterFactory;
  864. let DefaultStandardFontDataFactory = _display_utils.DOMStandardFontDataFactory;
  865. exports.DefaultStandardFontDataFactory = DefaultStandardFontDataFactory;
  866. if (_is_node.isNodeJS) {
  867. const {
  868. NodeCanvasFactory,
  869. NodeCMapReaderFactory,
  870. NodeFilterFactory,
  871. NodeStandardFontDataFactory
  872. } = __w_pdfjs_require__(20);
  873. exports.DefaultCanvasFactory = DefaultCanvasFactory = NodeCanvasFactory;
  874. exports.DefaultCMapReaderFactory = DefaultCMapReaderFactory = NodeCMapReaderFactory;
  875. exports.DefaultFilterFactory = DefaultFilterFactory = NodeFilterFactory;
  876. exports.DefaultStandardFontDataFactory = DefaultStandardFontDataFactory = NodeStandardFontDataFactory;
  877. }
  878. let createPDFNetworkStream;
  879. {
  880. if (_is_node.isNodeJS) {
  881. const {
  882. PDFNodeStream
  883. } = __w_pdfjs_require__(21);
  884. createPDFNetworkStream = params => {
  885. return new PDFNodeStream(params);
  886. };
  887. } else {
  888. const {
  889. PDFNetworkStream
  890. } = __w_pdfjs_require__(24);
  891. const {
  892. PDFFetchStream
  893. } = __w_pdfjs_require__(25);
  894. createPDFNetworkStream = params => {
  895. return (0, _display_utils.isValidFetchUrl)(params.url) ? new PDFFetchStream(params) : new PDFNetworkStream(params);
  896. };
  897. }
  898. }
  899. function getDocument(src) {
  900. if (typeof src === "string" || src instanceof URL) {
  901. src = {
  902. url: src
  903. };
  904. } else if ((0, _util.isArrayBuffer)(src)) {
  905. src = {
  906. data: src
  907. };
  908. }
  909. if (typeof src !== "object") {
  910. throw new Error("Invalid parameter in getDocument, need parameter object.");
  911. }
  912. if (!src.url && !src.data && !src.range) {
  913. throw new Error("Invalid parameter object: need either .data, .range or .url");
  914. }
  915. const task = new PDFDocumentLoadingTask();
  916. const {
  917. docId
  918. } = task;
  919. const url = src.url ? getUrlProp(src.url) : null;
  920. const data = src.data ? getDataProp(src.data) : null;
  921. const httpHeaders = src.httpHeaders || null;
  922. const withCredentials = src.withCredentials === true;
  923. const password = src.password ?? null;
  924. const rangeTransport = src.range instanceof PDFDataRangeTransport ? src.range : null;
  925. const rangeChunkSize = Number.isInteger(src.rangeChunkSize) && src.rangeChunkSize > 0 ? src.rangeChunkSize : DEFAULT_RANGE_CHUNK_SIZE;
  926. let worker = src.worker instanceof PDFWorker ? src.worker : null;
  927. const verbosity = src.verbosity;
  928. const docBaseUrl = typeof src.docBaseUrl === "string" && !(0, _display_utils.isDataScheme)(src.docBaseUrl) ? src.docBaseUrl : null;
  929. const cMapUrl = typeof src.cMapUrl === "string" ? src.cMapUrl : null;
  930. const cMapPacked = src.cMapPacked !== false;
  931. const CMapReaderFactory = src.CMapReaderFactory || DefaultCMapReaderFactory;
  932. const standardFontDataUrl = typeof src.standardFontDataUrl === "string" ? src.standardFontDataUrl : null;
  933. const StandardFontDataFactory = src.StandardFontDataFactory || DefaultStandardFontDataFactory;
  934. const ignoreErrors = src.stopAtErrors !== true;
  935. const maxImageSize = Number.isInteger(src.maxImageSize) && src.maxImageSize > -1 ? src.maxImageSize : -1;
  936. const isEvalSupported = src.isEvalSupported !== false;
  937. const isOffscreenCanvasSupported = typeof src.isOffscreenCanvasSupported === "boolean" ? src.isOffscreenCanvasSupported : !_is_node.isNodeJS;
  938. const canvasMaxAreaInBytes = Number.isInteger(src.canvasMaxAreaInBytes) ? src.canvasMaxAreaInBytes : -1;
  939. const disableFontFace = typeof src.disableFontFace === "boolean" ? src.disableFontFace : _is_node.isNodeJS;
  940. const fontExtraProperties = src.fontExtraProperties === true;
  941. const enableXfa = src.enableXfa === true;
  942. const ownerDocument = src.ownerDocument || globalThis.document;
  943. const disableRange = src.disableRange === true;
  944. const disableStream = src.disableStream === true;
  945. const disableAutoFetch = src.disableAutoFetch === true;
  946. const pdfBug = src.pdfBug === true;
  947. const length = rangeTransport ? rangeTransport.length : src.length ?? NaN;
  948. const useSystemFonts = typeof src.useSystemFonts === "boolean" ? src.useSystemFonts : !_is_node.isNodeJS && !disableFontFace;
  949. const useWorkerFetch = typeof src.useWorkerFetch === "boolean" ? src.useWorkerFetch : CMapReaderFactory === _display_utils.DOMCMapReaderFactory && StandardFontDataFactory === _display_utils.DOMStandardFontDataFactory && (0, _display_utils.isValidFetchUrl)(cMapUrl, document.baseURI) && (0, _display_utils.isValidFetchUrl)(standardFontDataUrl, document.baseURI);
  950. const canvasFactory = src.canvasFactory || new DefaultCanvasFactory({
  951. ownerDocument
  952. });
  953. const filterFactory = src.filterFactory || new DefaultFilterFactory({
  954. docId,
  955. ownerDocument
  956. });
  957. const styleElement = null;
  958. (0, _util.setVerbosityLevel)(verbosity);
  959. const transportFactory = {
  960. canvasFactory,
  961. filterFactory
  962. };
  963. if (!useWorkerFetch) {
  964. transportFactory.cMapReaderFactory = new CMapReaderFactory({
  965. baseUrl: cMapUrl,
  966. isCompressed: cMapPacked
  967. });
  968. transportFactory.standardFontDataFactory = new StandardFontDataFactory({
  969. baseUrl: standardFontDataUrl
  970. });
  971. }
  972. if (!worker) {
  973. const workerParams = {
  974. verbosity,
  975. port: _worker_options.GlobalWorkerOptions.workerPort
  976. };
  977. worker = workerParams.port ? PDFWorker.fromPort(workerParams) : new PDFWorker(workerParams);
  978. task._worker = worker;
  979. }
  980. const fetchDocParams = {
  981. docId,
  982. apiVersion: '3.7.107',
  983. data,
  984. password,
  985. disableAutoFetch,
  986. rangeChunkSize,
  987. length,
  988. docBaseUrl,
  989. enableXfa,
  990. evaluatorOptions: {
  991. maxImageSize,
  992. disableFontFace,
  993. ignoreErrors,
  994. isEvalSupported,
  995. isOffscreenCanvasSupported,
  996. canvasMaxAreaInBytes,
  997. fontExtraProperties,
  998. useSystemFonts,
  999. cMapUrl: useWorkerFetch ? cMapUrl : null,
  1000. standardFontDataUrl: useWorkerFetch ? standardFontDataUrl : null
  1001. }
  1002. };
  1003. const transportParams = {
  1004. ignoreErrors,
  1005. isEvalSupported,
  1006. disableFontFace,
  1007. fontExtraProperties,
  1008. enableXfa,
  1009. ownerDocument,
  1010. disableAutoFetch,
  1011. pdfBug,
  1012. styleElement
  1013. };
  1014. worker.promise.then(function () {
  1015. if (task.destroyed) {
  1016. throw new Error("Loading aborted");
  1017. }
  1018. const workerIdPromise = _fetchDocument(worker, fetchDocParams);
  1019. const networkStreamPromise = new Promise(function (resolve) {
  1020. let networkStream;
  1021. if (rangeTransport) {
  1022. networkStream = new _transport_stream.PDFDataTransportStream({
  1023. length,
  1024. initialData: rangeTransport.initialData,
  1025. progressiveDone: rangeTransport.progressiveDone,
  1026. contentDispositionFilename: rangeTransport.contentDispositionFilename,
  1027. disableRange,
  1028. disableStream
  1029. }, rangeTransport);
  1030. } else if (!data) {
  1031. networkStream = createPDFNetworkStream({
  1032. url,
  1033. length,
  1034. httpHeaders,
  1035. withCredentials,
  1036. rangeChunkSize,
  1037. disableRange,
  1038. disableStream
  1039. });
  1040. }
  1041. resolve(networkStream);
  1042. });
  1043. return Promise.all([workerIdPromise, networkStreamPromise]).then(function ([workerId, networkStream]) {
  1044. if (task.destroyed) {
  1045. throw new Error("Loading aborted");
  1046. }
  1047. const messageHandler = new _message_handler.MessageHandler(docId, workerId, worker.port);
  1048. const transport = new WorkerTransport(messageHandler, task, networkStream, transportParams, transportFactory);
  1049. task._transport = transport;
  1050. messageHandler.send("Ready", null);
  1051. });
  1052. }).catch(task._capability.reject);
  1053. return task;
  1054. }
  1055. async function _fetchDocument(worker, source) {
  1056. if (worker.destroyed) {
  1057. throw new Error("Worker was destroyed");
  1058. }
  1059. const workerId = await worker.messageHandler.sendWithPromise("GetDocRequest", source, source.data ? [source.data.buffer] : null);
  1060. if (worker.destroyed) {
  1061. throw new Error("Worker was destroyed");
  1062. }
  1063. return workerId;
  1064. }
  1065. function getUrlProp(val) {
  1066. if (val instanceof URL) {
  1067. return val.href;
  1068. }
  1069. try {
  1070. return new URL(val, window.location).href;
  1071. } catch (ex) {
  1072. if (_is_node.isNodeJS && typeof val === "string") {
  1073. return val;
  1074. }
  1075. }
  1076. throw new Error("Invalid PDF url data: " + "either string or URL-object is expected in the url property.");
  1077. }
  1078. function getDataProp(val) {
  1079. if (_is_node.isNodeJS && typeof Buffer !== "undefined" && val instanceof Buffer) {
  1080. (0, _display_utils.deprecated)("Please provide binary data as `Uint8Array`, rather than `Buffer`.");
  1081. return new Uint8Array(val);
  1082. }
  1083. if (val instanceof Uint8Array && val.byteLength === val.buffer.byteLength) {
  1084. return val;
  1085. }
  1086. if (typeof val === "string") {
  1087. return (0, _util.stringToBytes)(val);
  1088. }
  1089. if (typeof val === "object" && !isNaN(val?.length) || (0, _util.isArrayBuffer)(val)) {
  1090. return new Uint8Array(val);
  1091. }
  1092. throw new Error("Invalid PDF binary data: either TypedArray, " + "string, or array-like object is expected in the data property.");
  1093. }
  1094. class PDFDocumentLoadingTask {
  1095. static #docId = 0;
  1096. constructor() {
  1097. this._capability = new _util.PromiseCapability();
  1098. this._transport = null;
  1099. this._worker = null;
  1100. this.docId = `d${PDFDocumentLoadingTask.#docId++}`;
  1101. this.destroyed = false;
  1102. this.onPassword = null;
  1103. this.onProgress = null;
  1104. }
  1105. get promise() {
  1106. return this._capability.promise;
  1107. }
  1108. async destroy() {
  1109. this.destroyed = true;
  1110. await this._transport?.destroy();
  1111. this._transport = null;
  1112. if (this._worker) {
  1113. this._worker.destroy();
  1114. this._worker = null;
  1115. }
  1116. }
  1117. }
  1118. exports.PDFDocumentLoadingTask = PDFDocumentLoadingTask;
  1119. class PDFDataRangeTransport {
  1120. constructor(length, initialData, progressiveDone = false, contentDispositionFilename = null) {
  1121. this.length = length;
  1122. this.initialData = initialData;
  1123. this.progressiveDone = progressiveDone;
  1124. this.contentDispositionFilename = contentDispositionFilename;
  1125. this._rangeListeners = [];
  1126. this._progressListeners = [];
  1127. this._progressiveReadListeners = [];
  1128. this._progressiveDoneListeners = [];
  1129. this._readyCapability = new _util.PromiseCapability();
  1130. }
  1131. addRangeListener(listener) {
  1132. this._rangeListeners.push(listener);
  1133. }
  1134. addProgressListener(listener) {
  1135. this._progressListeners.push(listener);
  1136. }
  1137. addProgressiveReadListener(listener) {
  1138. this._progressiveReadListeners.push(listener);
  1139. }
  1140. addProgressiveDoneListener(listener) {
  1141. this._progressiveDoneListeners.push(listener);
  1142. }
  1143. onDataRange(begin, chunk) {
  1144. for (const listener of this._rangeListeners) {
  1145. listener(begin, chunk);
  1146. }
  1147. }
  1148. onDataProgress(loaded, total) {
  1149. this._readyCapability.promise.then(() => {
  1150. for (const listener of this._progressListeners) {
  1151. listener(loaded, total);
  1152. }
  1153. });
  1154. }
  1155. onDataProgressiveRead(chunk) {
  1156. this._readyCapability.promise.then(() => {
  1157. for (const listener of this._progressiveReadListeners) {
  1158. listener(chunk);
  1159. }
  1160. });
  1161. }
  1162. onDataProgressiveDone() {
  1163. this._readyCapability.promise.then(() => {
  1164. for (const listener of this._progressiveDoneListeners) {
  1165. listener();
  1166. }
  1167. });
  1168. }
  1169. transportReady() {
  1170. this._readyCapability.resolve();
  1171. }
  1172. requestDataRange(begin, end) {
  1173. (0, _util.unreachable)("Abstract method PDFDataRangeTransport.requestDataRange");
  1174. }
  1175. abort() {}
  1176. }
  1177. exports.PDFDataRangeTransport = PDFDataRangeTransport;
  1178. class PDFDocumentProxy {
  1179. constructor(pdfInfo, transport) {
  1180. this._pdfInfo = pdfInfo;
  1181. this._transport = transport;
  1182. }
  1183. get annotationStorage() {
  1184. return this._transport.annotationStorage;
  1185. }
  1186. get filterFactory() {
  1187. return this._transport.filterFactory;
  1188. }
  1189. get numPages() {
  1190. return this._pdfInfo.numPages;
  1191. }
  1192. get fingerprints() {
  1193. return this._pdfInfo.fingerprints;
  1194. }
  1195. get isPureXfa() {
  1196. return (0, _util.shadow)(this, "isPureXfa", !!this._transport._htmlForXfa);
  1197. }
  1198. get allXfaHtml() {
  1199. return this._transport._htmlForXfa;
  1200. }
  1201. getPage(pageNumber) {
  1202. return this._transport.getPage(pageNumber);
  1203. }
  1204. getPageIndex(ref) {
  1205. return this._transport.getPageIndex(ref);
  1206. }
  1207. getDestinations() {
  1208. return this._transport.getDestinations();
  1209. }
  1210. getDestination(id) {
  1211. return this._transport.getDestination(id);
  1212. }
  1213. getPageLabels() {
  1214. return this._transport.getPageLabels();
  1215. }
  1216. getPageLayout() {
  1217. return this._transport.getPageLayout();
  1218. }
  1219. getPageMode() {
  1220. return this._transport.getPageMode();
  1221. }
  1222. getViewerPreferences() {
  1223. return this._transport.getViewerPreferences();
  1224. }
  1225. getOpenAction() {
  1226. return this._transport.getOpenAction();
  1227. }
  1228. getAttachments() {
  1229. return this._transport.getAttachments();
  1230. }
  1231. getJavaScript() {
  1232. return this._transport.getJavaScript();
  1233. }
  1234. getJSActions() {
  1235. return this._transport.getDocJSActions();
  1236. }
  1237. getOutline() {
  1238. return this._transport.getOutline();
  1239. }
  1240. getOptionalContentConfig() {
  1241. return this._transport.getOptionalContentConfig();
  1242. }
  1243. getPermissions() {
  1244. return this._transport.getPermissions();
  1245. }
  1246. getMetadata() {
  1247. return this._transport.getMetadata();
  1248. }
  1249. getMarkInfo() {
  1250. return this._transport.getMarkInfo();
  1251. }
  1252. getData() {
  1253. return this._transport.getData();
  1254. }
  1255. saveDocument() {
  1256. return this._transport.saveDocument();
  1257. }
  1258. getDownloadInfo() {
  1259. return this._transport.downloadInfoCapability.promise;
  1260. }
  1261. cleanup(keepLoadedFonts = false) {
  1262. return this._transport.startCleanup(keepLoadedFonts || this.isPureXfa);
  1263. }
  1264. destroy() {
  1265. return this.loadingTask.destroy();
  1266. }
  1267. get loadingParams() {
  1268. return this._transport.loadingParams;
  1269. }
  1270. get loadingTask() {
  1271. return this._transport.loadingTask;
  1272. }
  1273. getFieldObjects() {
  1274. return this._transport.getFieldObjects();
  1275. }
  1276. hasJSActions() {
  1277. return this._transport.hasJSActions();
  1278. }
  1279. getCalculationOrderIds() {
  1280. return this._transport.getCalculationOrderIds();
  1281. }
  1282. }
  1283. exports.PDFDocumentProxy = PDFDocumentProxy;
  1284. class PDFPageProxy {
  1285. #delayedCleanupTimeout = null;
  1286. #pendingCleanup = false;
  1287. constructor(pageIndex, pageInfo, transport, pdfBug = false) {
  1288. this._pageIndex = pageIndex;
  1289. this._pageInfo = pageInfo;
  1290. this._transport = transport;
  1291. this._stats = pdfBug ? new _display_utils.StatTimer() : null;
  1292. this._pdfBug = pdfBug;
  1293. this.commonObjs = transport.commonObjs;
  1294. this.objs = new PDFObjects();
  1295. this._maybeCleanupAfterRender = false;
  1296. this._intentStates = new Map();
  1297. this.destroyed = false;
  1298. }
  1299. get pageNumber() {
  1300. return this._pageIndex + 1;
  1301. }
  1302. get rotate() {
  1303. return this._pageInfo.rotate;
  1304. }
  1305. get ref() {
  1306. return this._pageInfo.ref;
  1307. }
  1308. get userUnit() {
  1309. return this._pageInfo.userUnit;
  1310. }
  1311. get view() {
  1312. return this._pageInfo.view;
  1313. }
  1314. getViewport({
  1315. scale,
  1316. rotation = this.rotate,
  1317. offsetX = 0,
  1318. offsetY = 0,
  1319. dontFlip = false
  1320. } = {}) {
  1321. return new _display_utils.PageViewport({
  1322. viewBox: this.view,
  1323. scale,
  1324. rotation,
  1325. offsetX,
  1326. offsetY,
  1327. dontFlip
  1328. });
  1329. }
  1330. getAnnotations({
  1331. intent = "display"
  1332. } = {}) {
  1333. const intentArgs = this._transport.getRenderingIntent(intent);
  1334. return this._transport.getAnnotations(this._pageIndex, intentArgs.renderingIntent);
  1335. }
  1336. getJSActions() {
  1337. return this._transport.getPageJSActions(this._pageIndex);
  1338. }
  1339. get isPureXfa() {
  1340. return (0, _util.shadow)(this, "isPureXfa", !!this._transport._htmlForXfa);
  1341. }
  1342. async getXfa() {
  1343. return this._transport._htmlForXfa?.children[this._pageIndex] || null;
  1344. }
  1345. render({
  1346. canvasContext,
  1347. viewport,
  1348. intent = "display",
  1349. annotationMode = _util.AnnotationMode.ENABLE,
  1350. transform = null,
  1351. background = null,
  1352. optionalContentConfigPromise = null,
  1353. annotationCanvasMap = null,
  1354. pageColors = null,
  1355. printAnnotationStorage = null
  1356. }) {
  1357. if (arguments[0]?.canvasFactory) {
  1358. throw new Error("render no longer accepts the `canvasFactory`-option, " + "please pass it to the `getDocument`-function instead.");
  1359. }
  1360. this._stats?.time("Overall");
  1361. const intentArgs = this._transport.getRenderingIntent(intent, annotationMode, printAnnotationStorage);
  1362. this.#pendingCleanup = false;
  1363. this.#abortDelayedCleanup();
  1364. if (!optionalContentConfigPromise) {
  1365. optionalContentConfigPromise = this._transport.getOptionalContentConfig();
  1366. }
  1367. let intentState = this._intentStates.get(intentArgs.cacheKey);
  1368. if (!intentState) {
  1369. intentState = Object.create(null);
  1370. this._intentStates.set(intentArgs.cacheKey, intentState);
  1371. }
  1372. if (intentState.streamReaderCancelTimeout) {
  1373. clearTimeout(intentState.streamReaderCancelTimeout);
  1374. intentState.streamReaderCancelTimeout = null;
  1375. }
  1376. const intentPrint = !!(intentArgs.renderingIntent & _util.RenderingIntentFlag.PRINT);
  1377. if (!intentState.displayReadyCapability) {
  1378. intentState.displayReadyCapability = new _util.PromiseCapability();
  1379. intentState.operatorList = {
  1380. fnArray: [],
  1381. argsArray: [],
  1382. lastChunk: false,
  1383. separateAnnots: null
  1384. };
  1385. this._stats?.time("Page Request");
  1386. this._pumpOperatorList(intentArgs);
  1387. }
  1388. const complete = error => {
  1389. intentState.renderTasks.delete(internalRenderTask);
  1390. if (this._maybeCleanupAfterRender || intentPrint) {
  1391. this.#pendingCleanup = true;
  1392. }
  1393. this.#tryCleanup(!intentPrint);
  1394. if (error) {
  1395. internalRenderTask.capability.reject(error);
  1396. this._abortOperatorList({
  1397. intentState,
  1398. reason: error instanceof Error ? error : new Error(error)
  1399. });
  1400. } else {
  1401. internalRenderTask.capability.resolve();
  1402. }
  1403. this._stats?.timeEnd("Rendering");
  1404. this._stats?.timeEnd("Overall");
  1405. };
  1406. const internalRenderTask = new InternalRenderTask({
  1407. callback: complete,
  1408. params: {
  1409. canvasContext,
  1410. viewport,
  1411. transform,
  1412. background
  1413. },
  1414. objs: this.objs,
  1415. commonObjs: this.commonObjs,
  1416. annotationCanvasMap,
  1417. operatorList: intentState.operatorList,
  1418. pageIndex: this._pageIndex,
  1419. canvasFactory: this._transport.canvasFactory,
  1420. filterFactory: this._transport.filterFactory,
  1421. useRequestAnimationFrame: !intentPrint,
  1422. pdfBug: this._pdfBug,
  1423. pageColors
  1424. });
  1425. (intentState.renderTasks ||= new Set()).add(internalRenderTask);
  1426. const renderTask = internalRenderTask.task;
  1427. Promise.all([intentState.displayReadyCapability.promise, optionalContentConfigPromise]).then(([transparency, optionalContentConfig]) => {
  1428. if (this.#pendingCleanup) {
  1429. complete();
  1430. return;
  1431. }
  1432. this._stats?.time("Rendering");
  1433. internalRenderTask.initializeGraphics({
  1434. transparency,
  1435. optionalContentConfig
  1436. });
  1437. internalRenderTask.operatorListChanged();
  1438. }).catch(complete);
  1439. return renderTask;
  1440. }
  1441. getOperatorList({
  1442. intent = "display",
  1443. annotationMode = _util.AnnotationMode.ENABLE,
  1444. printAnnotationStorage = null
  1445. } = {}) {
  1446. function operatorListChanged() {
  1447. if (intentState.operatorList.lastChunk) {
  1448. intentState.opListReadCapability.resolve(intentState.operatorList);
  1449. intentState.renderTasks.delete(opListTask);
  1450. }
  1451. }
  1452. const intentArgs = this._transport.getRenderingIntent(intent, annotationMode, printAnnotationStorage, true);
  1453. let intentState = this._intentStates.get(intentArgs.cacheKey);
  1454. if (!intentState) {
  1455. intentState = Object.create(null);
  1456. this._intentStates.set(intentArgs.cacheKey, intentState);
  1457. }
  1458. let opListTask;
  1459. if (!intentState.opListReadCapability) {
  1460. opListTask = Object.create(null);
  1461. opListTask.operatorListChanged = operatorListChanged;
  1462. intentState.opListReadCapability = new _util.PromiseCapability();
  1463. (intentState.renderTasks ||= new Set()).add(opListTask);
  1464. intentState.operatorList = {
  1465. fnArray: [],
  1466. argsArray: [],
  1467. lastChunk: false,
  1468. separateAnnots: null
  1469. };
  1470. this._stats?.time("Page Request");
  1471. this._pumpOperatorList(intentArgs);
  1472. }
  1473. return intentState.opListReadCapability.promise;
  1474. }
  1475. streamTextContent({
  1476. includeMarkedContent = false,
  1477. disableNormalization = false
  1478. } = {}) {
  1479. const TEXT_CONTENT_CHUNK_SIZE = 100;
  1480. return this._transport.messageHandler.sendWithStream("GetTextContent", {
  1481. pageIndex: this._pageIndex,
  1482. includeMarkedContent: includeMarkedContent === true,
  1483. disableNormalization: disableNormalization === true
  1484. }, {
  1485. highWaterMark: TEXT_CONTENT_CHUNK_SIZE,
  1486. size(textContent) {
  1487. return textContent.items.length;
  1488. }
  1489. });
  1490. }
  1491. getTextContent(params = {}) {
  1492. if (this._transport._htmlForXfa) {
  1493. return this.getXfa().then(xfa => {
  1494. return _xfa_text.XfaText.textContent(xfa);
  1495. });
  1496. }
  1497. const readableStream = this.streamTextContent(params);
  1498. return new Promise(function (resolve, reject) {
  1499. function pump() {
  1500. reader.read().then(function ({
  1501. value,
  1502. done
  1503. }) {
  1504. if (done) {
  1505. resolve(textContent);
  1506. return;
  1507. }
  1508. Object.assign(textContent.styles, value.styles);
  1509. textContent.items.push(...value.items);
  1510. pump();
  1511. }, reject);
  1512. }
  1513. const reader = readableStream.getReader();
  1514. const textContent = {
  1515. items: [],
  1516. styles: Object.create(null)
  1517. };
  1518. pump();
  1519. });
  1520. }
  1521. getStructTree() {
  1522. return this._transport.getStructTree(this._pageIndex);
  1523. }
  1524. _destroy() {
  1525. this.destroyed = true;
  1526. const waitOn = [];
  1527. for (const intentState of this._intentStates.values()) {
  1528. this._abortOperatorList({
  1529. intentState,
  1530. reason: new Error("Page was destroyed."),
  1531. force: true
  1532. });
  1533. if (intentState.opListReadCapability) {
  1534. continue;
  1535. }
  1536. for (const internalRenderTask of intentState.renderTasks) {
  1537. waitOn.push(internalRenderTask.completed);
  1538. internalRenderTask.cancel();
  1539. }
  1540. }
  1541. this.objs.clear();
  1542. this.#pendingCleanup = false;
  1543. this.#abortDelayedCleanup();
  1544. return Promise.all(waitOn);
  1545. }
  1546. cleanup(resetStats = false) {
  1547. this.#pendingCleanup = true;
  1548. const success = this.#tryCleanup(false);
  1549. if (resetStats && success) {
  1550. this._stats &&= new _display_utils.StatTimer();
  1551. }
  1552. return success;
  1553. }
  1554. #tryCleanup(delayed = false) {
  1555. this.#abortDelayedCleanup();
  1556. if (!this.#pendingCleanup) {
  1557. return false;
  1558. }
  1559. if (delayed) {
  1560. this.#delayedCleanupTimeout = setTimeout(() => {
  1561. this.#delayedCleanupTimeout = null;
  1562. this.#tryCleanup(false);
  1563. }, DELAYED_CLEANUP_TIMEOUT);
  1564. return false;
  1565. }
  1566. for (const {
  1567. renderTasks,
  1568. operatorList
  1569. } of this._intentStates.values()) {
  1570. if (renderTasks.size > 0 || !operatorList.lastChunk) {
  1571. return false;
  1572. }
  1573. }
  1574. this._intentStates.clear();
  1575. this.objs.clear();
  1576. this.#pendingCleanup = false;
  1577. return true;
  1578. }
  1579. #abortDelayedCleanup() {
  1580. if (this.#delayedCleanupTimeout) {
  1581. clearTimeout(this.#delayedCleanupTimeout);
  1582. this.#delayedCleanupTimeout = null;
  1583. }
  1584. }
  1585. _startRenderPage(transparency, cacheKey) {
  1586. const intentState = this._intentStates.get(cacheKey);
  1587. if (!intentState) {
  1588. return;
  1589. }
  1590. this._stats?.timeEnd("Page Request");
  1591. intentState.displayReadyCapability?.resolve(transparency);
  1592. }
  1593. _renderPageChunk(operatorListChunk, intentState) {
  1594. for (let i = 0, ii = operatorListChunk.length; i < ii; i++) {
  1595. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  1596. intentState.operatorList.argsArray.push(operatorListChunk.argsArray[i]);
  1597. }
  1598. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  1599. intentState.operatorList.separateAnnots = operatorListChunk.separateAnnots;
  1600. for (const internalRenderTask of intentState.renderTasks) {
  1601. internalRenderTask.operatorListChanged();
  1602. }
  1603. if (operatorListChunk.lastChunk) {
  1604. this.#tryCleanup(true);
  1605. }
  1606. }
  1607. _pumpOperatorList({
  1608. renderingIntent,
  1609. cacheKey,
  1610. annotationStorageMap
  1611. }) {
  1612. const readableStream = this._transport.messageHandler.sendWithStream("GetOperatorList", {
  1613. pageIndex: this._pageIndex,
  1614. intent: renderingIntent,
  1615. cacheKey,
  1616. annotationStorage: annotationStorageMap
  1617. });
  1618. const reader = readableStream.getReader();
  1619. const intentState = this._intentStates.get(cacheKey);
  1620. intentState.streamReader = reader;
  1621. const pump = () => {
  1622. reader.read().then(({
  1623. value,
  1624. done
  1625. }) => {
  1626. if (done) {
  1627. intentState.streamReader = null;
  1628. return;
  1629. }
  1630. if (this._transport.destroyed) {
  1631. return;
  1632. }
  1633. this._renderPageChunk(value, intentState);
  1634. pump();
  1635. }, reason => {
  1636. intentState.streamReader = null;
  1637. if (this._transport.destroyed) {
  1638. return;
  1639. }
  1640. if (intentState.operatorList) {
  1641. intentState.operatorList.lastChunk = true;
  1642. for (const internalRenderTask of intentState.renderTasks) {
  1643. internalRenderTask.operatorListChanged();
  1644. }
  1645. this.#tryCleanup(true);
  1646. }
  1647. if (intentState.displayReadyCapability) {
  1648. intentState.displayReadyCapability.reject(reason);
  1649. } else if (intentState.opListReadCapability) {
  1650. intentState.opListReadCapability.reject(reason);
  1651. } else {
  1652. throw reason;
  1653. }
  1654. });
  1655. };
  1656. pump();
  1657. }
  1658. _abortOperatorList({
  1659. intentState,
  1660. reason,
  1661. force = false
  1662. }) {
  1663. if (!intentState.streamReader) {
  1664. return;
  1665. }
  1666. if (intentState.streamReaderCancelTimeout) {
  1667. clearTimeout(intentState.streamReaderCancelTimeout);
  1668. intentState.streamReaderCancelTimeout = null;
  1669. }
  1670. if (!force) {
  1671. if (intentState.renderTasks.size > 0) {
  1672. return;
  1673. }
  1674. if (reason instanceof _display_utils.RenderingCancelledException) {
  1675. let delay = RENDERING_CANCELLED_TIMEOUT;
  1676. if (reason.extraDelay > 0 && reason.extraDelay < 1000) {
  1677. delay += reason.extraDelay;
  1678. }
  1679. intentState.streamReaderCancelTimeout = setTimeout(() => {
  1680. intentState.streamReaderCancelTimeout = null;
  1681. this._abortOperatorList({
  1682. intentState,
  1683. reason,
  1684. force: true
  1685. });
  1686. }, delay);
  1687. return;
  1688. }
  1689. }
  1690. intentState.streamReader.cancel(new _util.AbortException(reason.message)).catch(() => {});
  1691. intentState.streamReader = null;
  1692. if (this._transport.destroyed) {
  1693. return;
  1694. }
  1695. for (const [curCacheKey, curIntentState] of this._intentStates) {
  1696. if (curIntentState === intentState) {
  1697. this._intentStates.delete(curCacheKey);
  1698. break;
  1699. }
  1700. }
  1701. this.cleanup();
  1702. }
  1703. get stats() {
  1704. return this._stats;
  1705. }
  1706. }
  1707. exports.PDFPageProxy = PDFPageProxy;
  1708. class LoopbackPort {
  1709. #listeners = new Set();
  1710. #deferred = Promise.resolve();
  1711. postMessage(obj, transfer) {
  1712. const event = {
  1713. data: structuredClone(obj, transfer ? {
  1714. transfer
  1715. } : null)
  1716. };
  1717. this.#deferred.then(() => {
  1718. for (const listener of this.#listeners) {
  1719. listener.call(this, event);
  1720. }
  1721. });
  1722. }
  1723. addEventListener(name, listener) {
  1724. this.#listeners.add(listener);
  1725. }
  1726. removeEventListener(name, listener) {
  1727. this.#listeners.delete(listener);
  1728. }
  1729. terminate() {
  1730. this.#listeners.clear();
  1731. }
  1732. }
  1733. exports.LoopbackPort = LoopbackPort;
  1734. const PDFWorkerUtil = {
  1735. isWorkerDisabled: false,
  1736. fallbackWorkerSrc: null,
  1737. fakeWorkerId: 0
  1738. };
  1739. exports.PDFWorkerUtil = PDFWorkerUtil;
  1740. {
  1741. if (_is_node.isNodeJS && typeof require === "function") {
  1742. PDFWorkerUtil.isWorkerDisabled = true;
  1743. PDFWorkerUtil.fallbackWorkerSrc = "./pdf.worker.js";
  1744. } else if (typeof document === "object") {
  1745. const pdfjsFilePath = document?.currentScript?.src;
  1746. if (pdfjsFilePath) {
  1747. PDFWorkerUtil.fallbackWorkerSrc = pdfjsFilePath.replace(/(\.(?:min\.)?js)(\?.*)?$/i, ".worker$1$2");
  1748. }
  1749. }
  1750. PDFWorkerUtil.isSameOrigin = function (baseUrl, otherUrl) {
  1751. let base;
  1752. try {
  1753. base = new URL(baseUrl);
  1754. if (!base.origin || base.origin === "null") {
  1755. return false;
  1756. }
  1757. } catch (e) {
  1758. return false;
  1759. }
  1760. const other = new URL(otherUrl, base);
  1761. return base.origin === other.origin;
  1762. };
  1763. PDFWorkerUtil.createCDNWrapper = function (url) {
  1764. const wrapper = `importScripts("${url}");`;
  1765. return URL.createObjectURL(new Blob([wrapper]));
  1766. };
  1767. }
  1768. class PDFWorker {
  1769. static #workerPorts = new WeakMap();
  1770. constructor({
  1771. name = null,
  1772. port = null,
  1773. verbosity = (0, _util.getVerbosityLevel)()
  1774. } = {}) {
  1775. if (port && PDFWorker.#workerPorts.has(port)) {
  1776. throw new Error("Cannot use more than one PDFWorker per port.");
  1777. }
  1778. this.name = name;
  1779. this.destroyed = false;
  1780. this.verbosity = verbosity;
  1781. this._readyCapability = new _util.PromiseCapability();
  1782. this._port = null;
  1783. this._webWorker = null;
  1784. this._messageHandler = null;
  1785. if (port) {
  1786. PDFWorker.#workerPorts.set(port, this);
  1787. this._initializeFromPort(port);
  1788. return;
  1789. }
  1790. this._initialize();
  1791. }
  1792. get promise() {
  1793. return this._readyCapability.promise;
  1794. }
  1795. get port() {
  1796. return this._port;
  1797. }
  1798. get messageHandler() {
  1799. return this._messageHandler;
  1800. }
  1801. _initializeFromPort(port) {
  1802. this._port = port;
  1803. this._messageHandler = new _message_handler.MessageHandler("main", "worker", port);
  1804. this._messageHandler.on("ready", function () {});
  1805. this._readyCapability.resolve();
  1806. this._messageHandler.send("configure", {
  1807. verbosity: this.verbosity
  1808. });
  1809. }
  1810. _initialize() {
  1811. if (!PDFWorkerUtil.isWorkerDisabled && !PDFWorker._mainThreadWorkerMessageHandler) {
  1812. let {
  1813. workerSrc
  1814. } = PDFWorker;
  1815. try {
  1816. if (!PDFWorkerUtil.isSameOrigin(window.location.href, workerSrc)) {
  1817. workerSrc = PDFWorkerUtil.createCDNWrapper(new URL(workerSrc, window.location).href);
  1818. }
  1819. const worker = new Worker(workerSrc);
  1820. const messageHandler = new _message_handler.MessageHandler("main", "worker", worker);
  1821. const terminateEarly = () => {
  1822. worker.removeEventListener("error", onWorkerError);
  1823. messageHandler.destroy();
  1824. worker.terminate();
  1825. if (this.destroyed) {
  1826. this._readyCapability.reject(new Error("Worker was destroyed"));
  1827. } else {
  1828. this._setupFakeWorker();
  1829. }
  1830. };
  1831. const onWorkerError = () => {
  1832. if (!this._webWorker) {
  1833. terminateEarly();
  1834. }
  1835. };
  1836. worker.addEventListener("error", onWorkerError);
  1837. messageHandler.on("test", data => {
  1838. worker.removeEventListener("error", onWorkerError);
  1839. if (this.destroyed) {
  1840. terminateEarly();
  1841. return;
  1842. }
  1843. if (data) {
  1844. this._messageHandler = messageHandler;
  1845. this._port = worker;
  1846. this._webWorker = worker;
  1847. this._readyCapability.resolve();
  1848. messageHandler.send("configure", {
  1849. verbosity: this.verbosity
  1850. });
  1851. } else {
  1852. this._setupFakeWorker();
  1853. messageHandler.destroy();
  1854. worker.terminate();
  1855. }
  1856. });
  1857. messageHandler.on("ready", data => {
  1858. worker.removeEventListener("error", onWorkerError);
  1859. if (this.destroyed) {
  1860. terminateEarly();
  1861. return;
  1862. }
  1863. try {
  1864. sendTest();
  1865. } catch (e) {
  1866. this._setupFakeWorker();
  1867. }
  1868. });
  1869. const sendTest = () => {
  1870. const testObj = new Uint8Array();
  1871. messageHandler.send("test", testObj, [testObj.buffer]);
  1872. };
  1873. sendTest();
  1874. return;
  1875. } catch (e) {
  1876. (0, _util.info)("The worker has been disabled.");
  1877. }
  1878. }
  1879. this._setupFakeWorker();
  1880. }
  1881. _setupFakeWorker() {
  1882. if (!PDFWorkerUtil.isWorkerDisabled) {
  1883. (0, _util.warn)("Setting up fake worker.");
  1884. PDFWorkerUtil.isWorkerDisabled = true;
  1885. }
  1886. PDFWorker._setupFakeWorkerGlobal.then(WorkerMessageHandler => {
  1887. if (this.destroyed) {
  1888. this._readyCapability.reject(new Error("Worker was destroyed"));
  1889. return;
  1890. }
  1891. const port = new LoopbackPort();
  1892. this._port = port;
  1893. const id = `fake${PDFWorkerUtil.fakeWorkerId++}`;
  1894. const workerHandler = new _message_handler.MessageHandler(id + "_worker", id, port);
  1895. WorkerMessageHandler.setup(workerHandler, port);
  1896. const messageHandler = new _message_handler.MessageHandler(id, id + "_worker", port);
  1897. this._messageHandler = messageHandler;
  1898. this._readyCapability.resolve();
  1899. messageHandler.send("configure", {
  1900. verbosity: this.verbosity
  1901. });
  1902. }).catch(reason => {
  1903. this._readyCapability.reject(new Error(`Setting up fake worker failed: "${reason.message}".`));
  1904. });
  1905. }
  1906. destroy() {
  1907. this.destroyed = true;
  1908. if (this._webWorker) {
  1909. this._webWorker.terminate();
  1910. this._webWorker = null;
  1911. }
  1912. PDFWorker.#workerPorts.delete(this._port);
  1913. this._port = null;
  1914. if (this._messageHandler) {
  1915. this._messageHandler.destroy();
  1916. this._messageHandler = null;
  1917. }
  1918. }
  1919. static fromPort(params) {
  1920. if (!params?.port) {
  1921. throw new Error("PDFWorker.fromPort - invalid method signature.");
  1922. }
  1923. if (this.#workerPorts.has(params.port)) {
  1924. return this.#workerPorts.get(params.port);
  1925. }
  1926. return new PDFWorker(params);
  1927. }
  1928. static get workerSrc() {
  1929. if (_worker_options.GlobalWorkerOptions.workerSrc) {
  1930. return _worker_options.GlobalWorkerOptions.workerSrc;
  1931. }
  1932. if (PDFWorkerUtil.fallbackWorkerSrc !== null) {
  1933. if (!_is_node.isNodeJS) {
  1934. (0, _display_utils.deprecated)('No "GlobalWorkerOptions.workerSrc" specified.');
  1935. }
  1936. return PDFWorkerUtil.fallbackWorkerSrc;
  1937. }
  1938. throw new Error('No "GlobalWorkerOptions.workerSrc" specified.');
  1939. }
  1940. static get _mainThreadWorkerMessageHandler() {
  1941. try {
  1942. return globalThis.pdfjsWorker?.WorkerMessageHandler || null;
  1943. } catch (ex) {
  1944. return null;
  1945. }
  1946. }
  1947. static get _setupFakeWorkerGlobal() {
  1948. const loader = async () => {
  1949. const mainWorkerMessageHandler = this._mainThreadWorkerMessageHandler;
  1950. if (mainWorkerMessageHandler) {
  1951. return mainWorkerMessageHandler;
  1952. }
  1953. if (_is_node.isNodeJS && typeof require === "function") {
  1954. const worker = eval("require")(this.workerSrc);
  1955. return worker.WorkerMessageHandler;
  1956. }
  1957. await (0, _display_utils.loadScript)(this.workerSrc);
  1958. return window.pdfjsWorker.WorkerMessageHandler;
  1959. };
  1960. return (0, _util.shadow)(this, "_setupFakeWorkerGlobal", loader());
  1961. }
  1962. }
  1963. exports.PDFWorker = PDFWorker;
  1964. class WorkerTransport {
  1965. #methodPromises = new Map();
  1966. #pageCache = new Map();
  1967. #pagePromises = new Map();
  1968. constructor(messageHandler, loadingTask, networkStream, params, factory) {
  1969. this.messageHandler = messageHandler;
  1970. this.loadingTask = loadingTask;
  1971. this.commonObjs = new PDFObjects();
  1972. this.fontLoader = new _font_loader.FontLoader({
  1973. ownerDocument: params.ownerDocument,
  1974. styleElement: params.styleElement
  1975. });
  1976. this._params = params;
  1977. this.canvasFactory = factory.canvasFactory;
  1978. this.filterFactory = factory.filterFactory;
  1979. this.cMapReaderFactory = factory.cMapReaderFactory;
  1980. this.standardFontDataFactory = factory.standardFontDataFactory;
  1981. this.destroyed = false;
  1982. this.destroyCapability = null;
  1983. this._passwordCapability = null;
  1984. this._networkStream = networkStream;
  1985. this._fullReader = null;
  1986. this._lastProgress = null;
  1987. this.downloadInfoCapability = new _util.PromiseCapability();
  1988. this.setupMessageHandler();
  1989. }
  1990. #cacheSimpleMethod(name, data = null) {
  1991. const cachedPromise = this.#methodPromises.get(name);
  1992. if (cachedPromise) {
  1993. return cachedPromise;
  1994. }
  1995. const promise = this.messageHandler.sendWithPromise(name, data);
  1996. this.#methodPromises.set(name, promise);
  1997. return promise;
  1998. }
  1999. get annotationStorage() {
  2000. return (0, _util.shadow)(this, "annotationStorage", new _annotation_storage.AnnotationStorage());
  2001. }
  2002. getRenderingIntent(intent, annotationMode = _util.AnnotationMode.ENABLE, printAnnotationStorage = null, isOpList = false) {
  2003. let renderingIntent = _util.RenderingIntentFlag.DISPLAY;
  2004. let annotationMap = null;
  2005. switch (intent) {
  2006. case "any":
  2007. renderingIntent = _util.RenderingIntentFlag.ANY;
  2008. break;
  2009. case "display":
  2010. break;
  2011. case "print":
  2012. renderingIntent = _util.RenderingIntentFlag.PRINT;
  2013. break;
  2014. default:
  2015. (0, _util.warn)(`getRenderingIntent - invalid intent: ${intent}`);
  2016. }
  2017. switch (annotationMode) {
  2018. case _util.AnnotationMode.DISABLE:
  2019. renderingIntent += _util.RenderingIntentFlag.ANNOTATIONS_DISABLE;
  2020. break;
  2021. case _util.AnnotationMode.ENABLE:
  2022. break;
  2023. case _util.AnnotationMode.ENABLE_FORMS:
  2024. renderingIntent += _util.RenderingIntentFlag.ANNOTATIONS_FORMS;
  2025. break;
  2026. case _util.AnnotationMode.ENABLE_STORAGE:
  2027. renderingIntent += _util.RenderingIntentFlag.ANNOTATIONS_STORAGE;
  2028. const annotationStorage = renderingIntent & _util.RenderingIntentFlag.PRINT && printAnnotationStorage instanceof _annotation_storage.PrintAnnotationStorage ? printAnnotationStorage : this.annotationStorage;
  2029. annotationMap = annotationStorage.serializable;
  2030. break;
  2031. default:
  2032. (0, _util.warn)(`getRenderingIntent - invalid annotationMode: ${annotationMode}`);
  2033. }
  2034. if (isOpList) {
  2035. renderingIntent += _util.RenderingIntentFlag.OPLIST;
  2036. }
  2037. return {
  2038. renderingIntent,
  2039. cacheKey: `${renderingIntent}_${_annotation_storage.AnnotationStorage.getHash(annotationMap)}`,
  2040. annotationStorageMap: annotationMap
  2041. };
  2042. }
  2043. destroy() {
  2044. if (this.destroyCapability) {
  2045. return this.destroyCapability.promise;
  2046. }
  2047. this.destroyed = true;
  2048. this.destroyCapability = new _util.PromiseCapability();
  2049. if (this._passwordCapability) {
  2050. this._passwordCapability.reject(new Error("Worker was destroyed during onPassword callback"));
  2051. }
  2052. const waitOn = [];
  2053. for (const page of this.#pageCache.values()) {
  2054. waitOn.push(page._destroy());
  2055. }
  2056. this.#pageCache.clear();
  2057. this.#pagePromises.clear();
  2058. if (this.hasOwnProperty("annotationStorage")) {
  2059. this.annotationStorage.resetModified();
  2060. }
  2061. const terminated = this.messageHandler.sendWithPromise("Terminate", null);
  2062. waitOn.push(terminated);
  2063. Promise.all(waitOn).then(() => {
  2064. this.commonObjs.clear();
  2065. this.fontLoader.clear();
  2066. this.#methodPromises.clear();
  2067. this.filterFactory.destroy();
  2068. if (this._networkStream) {
  2069. this._networkStream.cancelAllRequests(new _util.AbortException("Worker was terminated."));
  2070. }
  2071. if (this.messageHandler) {
  2072. this.messageHandler.destroy();
  2073. this.messageHandler = null;
  2074. }
  2075. this.destroyCapability.resolve();
  2076. }, this.destroyCapability.reject);
  2077. return this.destroyCapability.promise;
  2078. }
  2079. setupMessageHandler() {
  2080. const {
  2081. messageHandler,
  2082. loadingTask
  2083. } = this;
  2084. messageHandler.on("GetReader", (data, sink) => {
  2085. (0, _util.assert)(this._networkStream, "GetReader - no `IPDFStream` instance available.");
  2086. this._fullReader = this._networkStream.getFullReader();
  2087. this._fullReader.onProgress = evt => {
  2088. this._lastProgress = {
  2089. loaded: evt.loaded,
  2090. total: evt.total
  2091. };
  2092. };
  2093. sink.onPull = () => {
  2094. this._fullReader.read().then(function ({
  2095. value,
  2096. done
  2097. }) {
  2098. if (done) {
  2099. sink.close();
  2100. return;
  2101. }
  2102. (0, _util.assert)(value instanceof ArrayBuffer, "GetReader - expected an ArrayBuffer.");
  2103. sink.enqueue(new Uint8Array(value), 1, [value]);
  2104. }).catch(reason => {
  2105. sink.error(reason);
  2106. });
  2107. };
  2108. sink.onCancel = reason => {
  2109. this._fullReader.cancel(reason);
  2110. sink.ready.catch(readyReason => {
  2111. if (this.destroyed) {
  2112. return;
  2113. }
  2114. throw readyReason;
  2115. });
  2116. };
  2117. });
  2118. messageHandler.on("ReaderHeadersReady", data => {
  2119. const headersCapability = new _util.PromiseCapability();
  2120. const fullReader = this._fullReader;
  2121. fullReader.headersReady.then(() => {
  2122. if (!fullReader.isStreamingSupported || !fullReader.isRangeSupported) {
  2123. if (this._lastProgress) {
  2124. loadingTask.onProgress?.(this._lastProgress);
  2125. }
  2126. fullReader.onProgress = evt => {
  2127. loadingTask.onProgress?.({
  2128. loaded: evt.loaded,
  2129. total: evt.total
  2130. });
  2131. };
  2132. }
  2133. headersCapability.resolve({
  2134. isStreamingSupported: fullReader.isStreamingSupported,
  2135. isRangeSupported: fullReader.isRangeSupported,
  2136. contentLength: fullReader.contentLength
  2137. });
  2138. }, headersCapability.reject);
  2139. return headersCapability.promise;
  2140. });
  2141. messageHandler.on("GetRangeReader", (data, sink) => {
  2142. (0, _util.assert)(this._networkStream, "GetRangeReader - no `IPDFStream` instance available.");
  2143. const rangeReader = this._networkStream.getRangeReader(data.begin, data.end);
  2144. if (!rangeReader) {
  2145. sink.close();
  2146. return;
  2147. }
  2148. sink.onPull = () => {
  2149. rangeReader.read().then(function ({
  2150. value,
  2151. done
  2152. }) {
  2153. if (done) {
  2154. sink.close();
  2155. return;
  2156. }
  2157. (0, _util.assert)(value instanceof ArrayBuffer, "GetRangeReader - expected an ArrayBuffer.");
  2158. sink.enqueue(new Uint8Array(value), 1, [value]);
  2159. }).catch(reason => {
  2160. sink.error(reason);
  2161. });
  2162. };
  2163. sink.onCancel = reason => {
  2164. rangeReader.cancel(reason);
  2165. sink.ready.catch(readyReason => {
  2166. if (this.destroyed) {
  2167. return;
  2168. }
  2169. throw readyReason;
  2170. });
  2171. };
  2172. });
  2173. messageHandler.on("GetDoc", ({
  2174. pdfInfo
  2175. }) => {
  2176. this._numPages = pdfInfo.numPages;
  2177. this._htmlForXfa = pdfInfo.htmlForXfa;
  2178. delete pdfInfo.htmlForXfa;
  2179. loadingTask._capability.resolve(new PDFDocumentProxy(pdfInfo, this));
  2180. });
  2181. messageHandler.on("DocException", function (ex) {
  2182. let reason;
  2183. switch (ex.name) {
  2184. case "PasswordException":
  2185. reason = new _util.PasswordException(ex.message, ex.code);
  2186. break;
  2187. case "InvalidPDFException":
  2188. reason = new _util.InvalidPDFException(ex.message);
  2189. break;
  2190. case "MissingPDFException":
  2191. reason = new _util.MissingPDFException(ex.message);
  2192. break;
  2193. case "UnexpectedResponseException":
  2194. reason = new _util.UnexpectedResponseException(ex.message, ex.status);
  2195. break;
  2196. case "UnknownErrorException":
  2197. reason = new _util.UnknownErrorException(ex.message, ex.details);
  2198. break;
  2199. default:
  2200. (0, _util.unreachable)("DocException - expected a valid Error.");
  2201. }
  2202. loadingTask._capability.reject(reason);
  2203. });
  2204. messageHandler.on("PasswordRequest", exception => {
  2205. this._passwordCapability = new _util.PromiseCapability();
  2206. if (loadingTask.onPassword) {
  2207. const updatePassword = password => {
  2208. if (password instanceof Error) {
  2209. this._passwordCapability.reject(password);
  2210. } else {
  2211. this._passwordCapability.resolve({
  2212. password
  2213. });
  2214. }
  2215. };
  2216. try {
  2217. loadingTask.onPassword(updatePassword, exception.code);
  2218. } catch (ex) {
  2219. this._passwordCapability.reject(ex);
  2220. }
  2221. } else {
  2222. this._passwordCapability.reject(new _util.PasswordException(exception.message, exception.code));
  2223. }
  2224. return this._passwordCapability.promise;
  2225. });
  2226. messageHandler.on("DataLoaded", data => {
  2227. loadingTask.onProgress?.({
  2228. loaded: data.length,
  2229. total: data.length
  2230. });
  2231. this.downloadInfoCapability.resolve(data);
  2232. });
  2233. messageHandler.on("StartRenderPage", data => {
  2234. if (this.destroyed) {
  2235. return;
  2236. }
  2237. const page = this.#pageCache.get(data.pageIndex);
  2238. page._startRenderPage(data.transparency, data.cacheKey);
  2239. });
  2240. messageHandler.on("commonobj", ([id, type, exportedData]) => {
  2241. if (this.destroyed) {
  2242. return;
  2243. }
  2244. if (this.commonObjs.has(id)) {
  2245. return;
  2246. }
  2247. switch (type) {
  2248. case "Font":
  2249. const params = this._params;
  2250. if ("error" in exportedData) {
  2251. const exportedError = exportedData.error;
  2252. (0, _util.warn)(`Error during font loading: ${exportedError}`);
  2253. this.commonObjs.resolve(id, exportedError);
  2254. break;
  2255. }
  2256. const inspectFont = params.pdfBug && globalThis.FontInspector?.enabled ? (font, url) => globalThis.FontInspector.fontAdded(font, url) : null;
  2257. const font = new _font_loader.FontFaceObject(exportedData, {
  2258. isEvalSupported: params.isEvalSupported,
  2259. disableFontFace: params.disableFontFace,
  2260. ignoreErrors: params.ignoreErrors,
  2261. inspectFont
  2262. });
  2263. this.fontLoader.bind(font).catch(reason => {
  2264. return messageHandler.sendWithPromise("FontFallback", {
  2265. id
  2266. });
  2267. }).finally(() => {
  2268. if (!params.fontExtraProperties && font.data) {
  2269. font.data = null;
  2270. }
  2271. this.commonObjs.resolve(id, font);
  2272. });
  2273. break;
  2274. case "FontPath":
  2275. case "Image":
  2276. case "Pattern":
  2277. this.commonObjs.resolve(id, exportedData);
  2278. break;
  2279. default:
  2280. throw new Error(`Got unknown common object type ${type}`);
  2281. }
  2282. });
  2283. messageHandler.on("obj", ([id, pageIndex, type, imageData]) => {
  2284. if (this.destroyed) {
  2285. return;
  2286. }
  2287. const pageProxy = this.#pageCache.get(pageIndex);
  2288. if (pageProxy.objs.has(id)) {
  2289. return;
  2290. }
  2291. switch (type) {
  2292. case "Image":
  2293. pageProxy.objs.resolve(id, imageData);
  2294. if (imageData) {
  2295. let length;
  2296. if (imageData.bitmap) {
  2297. const {
  2298. width,
  2299. height
  2300. } = imageData;
  2301. length = width * height * 4;
  2302. } else {
  2303. length = imageData.data?.length || 0;
  2304. }
  2305. if (length > _util.MAX_IMAGE_SIZE_TO_CACHE) {
  2306. pageProxy._maybeCleanupAfterRender = true;
  2307. }
  2308. }
  2309. break;
  2310. case "Pattern":
  2311. pageProxy.objs.resolve(id, imageData);
  2312. break;
  2313. default:
  2314. throw new Error(`Got unknown object type ${type}`);
  2315. }
  2316. });
  2317. messageHandler.on("DocProgress", data => {
  2318. if (this.destroyed) {
  2319. return;
  2320. }
  2321. loadingTask.onProgress?.({
  2322. loaded: data.loaded,
  2323. total: data.total
  2324. });
  2325. });
  2326. messageHandler.on("FetchBuiltInCMap", data => {
  2327. if (this.destroyed) {
  2328. return Promise.reject(new Error("Worker was destroyed."));
  2329. }
  2330. if (!this.cMapReaderFactory) {
  2331. return Promise.reject(new Error("CMapReaderFactory not initialized, see the `useWorkerFetch` parameter."));
  2332. }
  2333. return this.cMapReaderFactory.fetch(data);
  2334. });
  2335. messageHandler.on("FetchStandardFontData", data => {
  2336. if (this.destroyed) {
  2337. return Promise.reject(new Error("Worker was destroyed."));
  2338. }
  2339. if (!this.standardFontDataFactory) {
  2340. return Promise.reject(new Error("StandardFontDataFactory not initialized, see the `useWorkerFetch` parameter."));
  2341. }
  2342. return this.standardFontDataFactory.fetch(data);
  2343. });
  2344. }
  2345. getData() {
  2346. return this.messageHandler.sendWithPromise("GetData", null);
  2347. }
  2348. saveDocument() {
  2349. if (this.annotationStorage.size <= 0) {
  2350. (0, _util.warn)("saveDocument called while `annotationStorage` is empty, " + "please use the getData-method instead.");
  2351. }
  2352. return this.messageHandler.sendWithPromise("SaveDocument", {
  2353. isPureXfa: !!this._htmlForXfa,
  2354. numPages: this._numPages,
  2355. annotationStorage: this.annotationStorage.serializable,
  2356. filename: this._fullReader?.filename ?? null
  2357. }).finally(() => {
  2358. this.annotationStorage.resetModified();
  2359. });
  2360. }
  2361. getPage(pageNumber) {
  2362. if (!Number.isInteger(pageNumber) || pageNumber <= 0 || pageNumber > this._numPages) {
  2363. return Promise.reject(new Error("Invalid page request."));
  2364. }
  2365. const pageIndex = pageNumber - 1,
  2366. cachedPromise = this.#pagePromises.get(pageIndex);
  2367. if (cachedPromise) {
  2368. return cachedPromise;
  2369. }
  2370. const promise = this.messageHandler.sendWithPromise("GetPage", {
  2371. pageIndex
  2372. }).then(pageInfo => {
  2373. if (this.destroyed) {
  2374. throw new Error("Transport destroyed");
  2375. }
  2376. const page = new PDFPageProxy(pageIndex, pageInfo, this, this._params.pdfBug);
  2377. this.#pageCache.set(pageIndex, page);
  2378. return page;
  2379. });
  2380. this.#pagePromises.set(pageIndex, promise);
  2381. return promise;
  2382. }
  2383. getPageIndex(ref) {
  2384. if (typeof ref !== "object" || ref === null || !Number.isInteger(ref.num) || ref.num < 0 || !Number.isInteger(ref.gen) || ref.gen < 0) {
  2385. return Promise.reject(new Error("Invalid pageIndex request."));
  2386. }
  2387. return this.messageHandler.sendWithPromise("GetPageIndex", {
  2388. num: ref.num,
  2389. gen: ref.gen
  2390. });
  2391. }
  2392. getAnnotations(pageIndex, intent) {
  2393. return this.messageHandler.sendWithPromise("GetAnnotations", {
  2394. pageIndex,
  2395. intent
  2396. });
  2397. }
  2398. getFieldObjects() {
  2399. return this.#cacheSimpleMethod("GetFieldObjects");
  2400. }
  2401. hasJSActions() {
  2402. return this.#cacheSimpleMethod("HasJSActions");
  2403. }
  2404. getCalculationOrderIds() {
  2405. return this.messageHandler.sendWithPromise("GetCalculationOrderIds", null);
  2406. }
  2407. getDestinations() {
  2408. return this.messageHandler.sendWithPromise("GetDestinations", null);
  2409. }
  2410. getDestination(id) {
  2411. if (typeof id !== "string") {
  2412. return Promise.reject(new Error("Invalid destination request."));
  2413. }
  2414. return this.messageHandler.sendWithPromise("GetDestination", {
  2415. id
  2416. });
  2417. }
  2418. getPageLabels() {
  2419. return this.messageHandler.sendWithPromise("GetPageLabels", null);
  2420. }
  2421. getPageLayout() {
  2422. return this.messageHandler.sendWithPromise("GetPageLayout", null);
  2423. }
  2424. getPageMode() {
  2425. return this.messageHandler.sendWithPromise("GetPageMode", null);
  2426. }
  2427. getViewerPreferences() {
  2428. return this.messageHandler.sendWithPromise("GetViewerPreferences", null);
  2429. }
  2430. getOpenAction() {
  2431. return this.messageHandler.sendWithPromise("GetOpenAction", null);
  2432. }
  2433. getAttachments() {
  2434. return this.messageHandler.sendWithPromise("GetAttachments", null);
  2435. }
  2436. getJavaScript() {
  2437. return this.messageHandler.sendWithPromise("GetJavaScript", null);
  2438. }
  2439. getDocJSActions() {
  2440. return this.messageHandler.sendWithPromise("GetDocJSActions", null);
  2441. }
  2442. getPageJSActions(pageIndex) {
  2443. return this.messageHandler.sendWithPromise("GetPageJSActions", {
  2444. pageIndex
  2445. });
  2446. }
  2447. getStructTree(pageIndex) {
  2448. return this.messageHandler.sendWithPromise("GetStructTree", {
  2449. pageIndex
  2450. });
  2451. }
  2452. getOutline() {
  2453. return this.messageHandler.sendWithPromise("GetOutline", null);
  2454. }
  2455. getOptionalContentConfig() {
  2456. return this.messageHandler.sendWithPromise("GetOptionalContentConfig", null).then(results => {
  2457. return new _optional_content_config.OptionalContentConfig(results);
  2458. });
  2459. }
  2460. getPermissions() {
  2461. return this.messageHandler.sendWithPromise("GetPermissions", null);
  2462. }
  2463. getMetadata() {
  2464. const name = "GetMetadata",
  2465. cachedPromise = this.#methodPromises.get(name);
  2466. if (cachedPromise) {
  2467. return cachedPromise;
  2468. }
  2469. const promise = this.messageHandler.sendWithPromise(name, null).then(results => {
  2470. return {
  2471. info: results[0],
  2472. metadata: results[1] ? new _metadata.Metadata(results[1]) : null,
  2473. contentDispositionFilename: this._fullReader?.filename ?? null,
  2474. contentLength: this._fullReader?.contentLength ?? null
  2475. };
  2476. });
  2477. this.#methodPromises.set(name, promise);
  2478. return promise;
  2479. }
  2480. getMarkInfo() {
  2481. return this.messageHandler.sendWithPromise("GetMarkInfo", null);
  2482. }
  2483. async startCleanup(keepLoadedFonts = false) {
  2484. if (this.destroyed) {
  2485. return;
  2486. }
  2487. await this.messageHandler.sendWithPromise("Cleanup", null);
  2488. for (const page of this.#pageCache.values()) {
  2489. const cleanupSuccessful = page.cleanup();
  2490. if (!cleanupSuccessful) {
  2491. throw new Error(`startCleanup: Page ${page.pageNumber} is currently rendering.`);
  2492. }
  2493. }
  2494. this.commonObjs.clear();
  2495. if (!keepLoadedFonts) {
  2496. this.fontLoader.clear();
  2497. }
  2498. this.#methodPromises.clear();
  2499. this.filterFactory.destroy(true);
  2500. }
  2501. get loadingParams() {
  2502. const {
  2503. disableAutoFetch,
  2504. enableXfa
  2505. } = this._params;
  2506. return (0, _util.shadow)(this, "loadingParams", {
  2507. disableAutoFetch,
  2508. enableXfa
  2509. });
  2510. }
  2511. }
  2512. class PDFObjects {
  2513. #objs = Object.create(null);
  2514. #ensureObj(objId) {
  2515. const obj = this.#objs[objId];
  2516. if (obj) {
  2517. return obj;
  2518. }
  2519. return this.#objs[objId] = {
  2520. capability: new _util.PromiseCapability(),
  2521. data: null
  2522. };
  2523. }
  2524. get(objId, callback = null) {
  2525. if (callback) {
  2526. const obj = this.#ensureObj(objId);
  2527. obj.capability.promise.then(() => callback(obj.data));
  2528. return null;
  2529. }
  2530. const obj = this.#objs[objId];
  2531. if (!obj?.capability.settled) {
  2532. throw new Error(`Requesting object that isn't resolved yet ${objId}.`);
  2533. }
  2534. return obj.data;
  2535. }
  2536. has(objId) {
  2537. const obj = this.#objs[objId];
  2538. return obj?.capability.settled || false;
  2539. }
  2540. resolve(objId, data = null) {
  2541. const obj = this.#ensureObj(objId);
  2542. obj.data = data;
  2543. obj.capability.resolve();
  2544. }
  2545. clear() {
  2546. for (const objId in this.#objs) {
  2547. const {
  2548. data
  2549. } = this.#objs[objId];
  2550. data?.bitmap?.close();
  2551. }
  2552. this.#objs = Object.create(null);
  2553. }
  2554. }
  2555. class RenderTask {
  2556. #internalRenderTask = null;
  2557. constructor(internalRenderTask) {
  2558. this.#internalRenderTask = internalRenderTask;
  2559. this.onContinue = null;
  2560. }
  2561. get promise() {
  2562. return this.#internalRenderTask.capability.promise;
  2563. }
  2564. cancel(extraDelay = 0) {
  2565. this.#internalRenderTask.cancel(null, extraDelay);
  2566. }
  2567. get separateAnnots() {
  2568. const {
  2569. separateAnnots
  2570. } = this.#internalRenderTask.operatorList;
  2571. if (!separateAnnots) {
  2572. return false;
  2573. }
  2574. const {
  2575. annotationCanvasMap
  2576. } = this.#internalRenderTask;
  2577. return separateAnnots.form || separateAnnots.canvas && annotationCanvasMap?.size > 0;
  2578. }
  2579. }
  2580. exports.RenderTask = RenderTask;
  2581. class InternalRenderTask {
  2582. static #canvasInUse = new WeakSet();
  2583. constructor({
  2584. callback,
  2585. params,
  2586. objs,
  2587. commonObjs,
  2588. annotationCanvasMap,
  2589. operatorList,
  2590. pageIndex,
  2591. canvasFactory,
  2592. filterFactory,
  2593. useRequestAnimationFrame = false,
  2594. pdfBug = false,
  2595. pageColors = null
  2596. }) {
  2597. this.callback = callback;
  2598. this.params = params;
  2599. this.objs = objs;
  2600. this.commonObjs = commonObjs;
  2601. this.annotationCanvasMap = annotationCanvasMap;
  2602. this.operatorListIdx = null;
  2603. this.operatorList = operatorList;
  2604. this._pageIndex = pageIndex;
  2605. this.canvasFactory = canvasFactory;
  2606. this.filterFactory = filterFactory;
  2607. this._pdfBug = pdfBug;
  2608. this.pageColors = pageColors;
  2609. this.running = false;
  2610. this.graphicsReadyCallback = null;
  2611. this.graphicsReady = false;
  2612. this._useRequestAnimationFrame = useRequestAnimationFrame === true && typeof window !== "undefined";
  2613. this.cancelled = false;
  2614. this.capability = new _util.PromiseCapability();
  2615. this.task = new RenderTask(this);
  2616. this._cancelBound = this.cancel.bind(this);
  2617. this._continueBound = this._continue.bind(this);
  2618. this._scheduleNextBound = this._scheduleNext.bind(this);
  2619. this._nextBound = this._next.bind(this);
  2620. this._canvas = params.canvasContext.canvas;
  2621. }
  2622. get completed() {
  2623. return this.capability.promise.catch(function () {});
  2624. }
  2625. initializeGraphics({
  2626. transparency = false,
  2627. optionalContentConfig
  2628. }) {
  2629. if (this.cancelled) {
  2630. return;
  2631. }
  2632. if (this._canvas) {
  2633. if (InternalRenderTask.#canvasInUse.has(this._canvas)) {
  2634. throw new Error("Cannot use the same canvas during multiple render() operations. " + "Use different canvas or ensure previous operations were " + "cancelled or completed.");
  2635. }
  2636. InternalRenderTask.#canvasInUse.add(this._canvas);
  2637. }
  2638. if (this._pdfBug && globalThis.StepperManager?.enabled) {
  2639. this.stepper = globalThis.StepperManager.create(this._pageIndex);
  2640. this.stepper.init(this.operatorList);
  2641. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  2642. }
  2643. const {
  2644. canvasContext,
  2645. viewport,
  2646. transform,
  2647. background
  2648. } = this.params;
  2649. this.gfx = new _canvas.CanvasGraphics(canvasContext, this.commonObjs, this.objs, this.canvasFactory, this.filterFactory, {
  2650. optionalContentConfig
  2651. }, this.annotationCanvasMap, this.pageColors);
  2652. this.gfx.beginDrawing({
  2653. transform,
  2654. viewport,
  2655. transparency,
  2656. background
  2657. });
  2658. this.operatorListIdx = 0;
  2659. this.graphicsReady = true;
  2660. this.graphicsReadyCallback?.();
  2661. }
  2662. cancel(error = null, extraDelay = 0) {
  2663. this.running = false;
  2664. this.cancelled = true;
  2665. this.gfx?.endDrawing();
  2666. if (this._canvas) {
  2667. InternalRenderTask.#canvasInUse.delete(this._canvas);
  2668. }
  2669. this.callback(error || new _display_utils.RenderingCancelledException(`Rendering cancelled, page ${this._pageIndex + 1}`, "canvas", extraDelay));
  2670. }
  2671. operatorListChanged() {
  2672. if (!this.graphicsReady) {
  2673. this.graphicsReadyCallback ||= this._continueBound;
  2674. return;
  2675. }
  2676. this.stepper?.updateOperatorList(this.operatorList);
  2677. if (this.running) {
  2678. return;
  2679. }
  2680. this._continue();
  2681. }
  2682. _continue() {
  2683. this.running = true;
  2684. if (this.cancelled) {
  2685. return;
  2686. }
  2687. if (this.task.onContinue) {
  2688. this.task.onContinue(this._scheduleNextBound);
  2689. } else {
  2690. this._scheduleNext();
  2691. }
  2692. }
  2693. _scheduleNext() {
  2694. if (this._useRequestAnimationFrame) {
  2695. window.requestAnimationFrame(() => {
  2696. this._nextBound().catch(this._cancelBound);
  2697. });
  2698. } else {
  2699. Promise.resolve().then(this._nextBound).catch(this._cancelBound);
  2700. }
  2701. }
  2702. async _next() {
  2703. if (this.cancelled) {
  2704. return;
  2705. }
  2706. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList, this.operatorListIdx, this._continueBound, this.stepper);
  2707. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  2708. this.running = false;
  2709. if (this.operatorList.lastChunk) {
  2710. this.gfx.endDrawing(this.pageColors);
  2711. if (this._canvas) {
  2712. InternalRenderTask.#canvasInUse.delete(this._canvas);
  2713. }
  2714. this.callback();
  2715. }
  2716. }
  2717. }
  2718. }
  2719. const version = '3.7.107';
  2720. exports.version = version;
  2721. const build = '036f855dc';
  2722. exports.build = build;
  2723. /***/ }),
  2724. /* 3 */
  2725. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  2726. Object.defineProperty(exports, "__esModule", ({
  2727. value: true
  2728. }));
  2729. exports.PrintAnnotationStorage = exports.AnnotationStorage = void 0;
  2730. var _util = __w_pdfjs_require__(1);
  2731. var _editor = __w_pdfjs_require__(4);
  2732. var _murmurhash = __w_pdfjs_require__(8);
  2733. class AnnotationStorage {
  2734. #modified = false;
  2735. #storage = new Map();
  2736. constructor() {
  2737. this.onSetModified = null;
  2738. this.onResetModified = null;
  2739. this.onAnnotationEditor = null;
  2740. }
  2741. getValue(key, defaultValue) {
  2742. const value = this.#storage.get(key);
  2743. if (value === undefined) {
  2744. return defaultValue;
  2745. }
  2746. return Object.assign(defaultValue, value);
  2747. }
  2748. getRawValue(key) {
  2749. return this.#storage.get(key);
  2750. }
  2751. remove(key) {
  2752. this.#storage.delete(key);
  2753. if (this.#storage.size === 0) {
  2754. this.resetModified();
  2755. }
  2756. if (typeof this.onAnnotationEditor === "function") {
  2757. for (const value of this.#storage.values()) {
  2758. if (value instanceof _editor.AnnotationEditor) {
  2759. return;
  2760. }
  2761. }
  2762. this.onAnnotationEditor(null);
  2763. }
  2764. }
  2765. setValue(key, value) {
  2766. const obj = this.#storage.get(key);
  2767. let modified = false;
  2768. if (obj !== undefined) {
  2769. for (const [entry, val] of Object.entries(value)) {
  2770. if (obj[entry] !== val) {
  2771. modified = true;
  2772. obj[entry] = val;
  2773. }
  2774. }
  2775. } else {
  2776. modified = true;
  2777. this.#storage.set(key, value);
  2778. }
  2779. if (modified) {
  2780. this.#setModified();
  2781. }
  2782. if (value instanceof _editor.AnnotationEditor && typeof this.onAnnotationEditor === "function") {
  2783. this.onAnnotationEditor(value.constructor._type);
  2784. }
  2785. }
  2786. has(key) {
  2787. return this.#storage.has(key);
  2788. }
  2789. getAll() {
  2790. return this.#storage.size > 0 ? (0, _util.objectFromMap)(this.#storage) : null;
  2791. }
  2792. setAll(obj) {
  2793. for (const [key, val] of Object.entries(obj)) {
  2794. this.setValue(key, val);
  2795. }
  2796. }
  2797. get size() {
  2798. return this.#storage.size;
  2799. }
  2800. #setModified() {
  2801. if (!this.#modified) {
  2802. this.#modified = true;
  2803. if (typeof this.onSetModified === "function") {
  2804. this.onSetModified();
  2805. }
  2806. }
  2807. }
  2808. resetModified() {
  2809. if (this.#modified) {
  2810. this.#modified = false;
  2811. if (typeof this.onResetModified === "function") {
  2812. this.onResetModified();
  2813. }
  2814. }
  2815. }
  2816. get print() {
  2817. return new PrintAnnotationStorage(this);
  2818. }
  2819. get serializable() {
  2820. if (this.#storage.size === 0) {
  2821. return null;
  2822. }
  2823. const clone = new Map();
  2824. for (const [key, val] of this.#storage) {
  2825. const serialized = val instanceof _editor.AnnotationEditor ? val.serialize() : val;
  2826. if (serialized) {
  2827. clone.set(key, serialized);
  2828. }
  2829. }
  2830. return clone;
  2831. }
  2832. static getHash(map) {
  2833. if (!map) {
  2834. return "";
  2835. }
  2836. const hash = new _murmurhash.MurmurHash3_64();
  2837. for (const [key, val] of map) {
  2838. hash.update(`${key}:${JSON.stringify(val)}`);
  2839. }
  2840. return hash.hexdigest();
  2841. }
  2842. }
  2843. exports.AnnotationStorage = AnnotationStorage;
  2844. class PrintAnnotationStorage extends AnnotationStorage {
  2845. #serializable = null;
  2846. constructor(parent) {
  2847. super();
  2848. this.#serializable = structuredClone(parent.serializable);
  2849. }
  2850. get print() {
  2851. (0, _util.unreachable)("Should not call PrintAnnotationStorage.print");
  2852. }
  2853. get serializable() {
  2854. return this.#serializable;
  2855. }
  2856. }
  2857. exports.PrintAnnotationStorage = PrintAnnotationStorage;
  2858. /***/ }),
  2859. /* 4 */
  2860. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  2861. Object.defineProperty(exports, "__esModule", ({
  2862. value: true
  2863. }));
  2864. exports.AnnotationEditor = void 0;
  2865. var _tools = __w_pdfjs_require__(5);
  2866. var _util = __w_pdfjs_require__(1);
  2867. class AnnotationEditor {
  2868. #boundFocusin = this.focusin.bind(this);
  2869. #boundFocusout = this.focusout.bind(this);
  2870. #hasBeenSelected = false;
  2871. #isEditing = false;
  2872. #isInEditMode = false;
  2873. _uiManager = null;
  2874. #zIndex = AnnotationEditor._zIndex++;
  2875. static _colorManager = new _tools.ColorManager();
  2876. static _zIndex = 1;
  2877. constructor(parameters) {
  2878. if (this.constructor === AnnotationEditor) {
  2879. (0, _util.unreachable)("Cannot initialize AnnotationEditor.");
  2880. }
  2881. this.parent = parameters.parent;
  2882. this.id = parameters.id;
  2883. this.width = this.height = null;
  2884. this.pageIndex = parameters.parent.pageIndex;
  2885. this.name = parameters.name;
  2886. this.div = null;
  2887. this._uiManager = parameters.uiManager;
  2888. const {
  2889. rotation,
  2890. rawDims: {
  2891. pageWidth,
  2892. pageHeight,
  2893. pageX,
  2894. pageY
  2895. }
  2896. } = this.parent.viewport;
  2897. this.rotation = rotation;
  2898. this.pageRotation = (360 + rotation - this._uiManager.viewParameters.rotation) % 360;
  2899. this.pageDimensions = [pageWidth, pageHeight];
  2900. this.pageTranslation = [pageX, pageY];
  2901. const [width, height] = this.parentDimensions;
  2902. this.x = parameters.x / width;
  2903. this.y = parameters.y / height;
  2904. this.isAttachedToDOM = false;
  2905. }
  2906. static get _defaultLineColor() {
  2907. return (0, _util.shadow)(this, "_defaultLineColor", this._colorManager.getHexCode("CanvasText"));
  2908. }
  2909. addCommands(params) {
  2910. this._uiManager.addCommands(params);
  2911. }
  2912. get currentLayer() {
  2913. return this._uiManager.currentLayer;
  2914. }
  2915. setInBackground() {
  2916. this.div.style.zIndex = 0;
  2917. }
  2918. setInForeground() {
  2919. this.div.style.zIndex = this.#zIndex;
  2920. }
  2921. setParent(parent) {
  2922. if (parent !== null) {
  2923. this.pageIndex = parent.pageIndex;
  2924. this.pageDimensions = parent.pageDimensions;
  2925. }
  2926. this.parent = parent;
  2927. }
  2928. focusin(event) {
  2929. if (!this.#hasBeenSelected) {
  2930. this.parent.setSelected(this);
  2931. } else {
  2932. this.#hasBeenSelected = false;
  2933. }
  2934. }
  2935. focusout(event) {
  2936. if (!this.isAttachedToDOM) {
  2937. return;
  2938. }
  2939. const target = event.relatedTarget;
  2940. if (target?.closest(`#${this.id}`)) {
  2941. return;
  2942. }
  2943. event.preventDefault();
  2944. if (!this.parent?.isMultipleSelection) {
  2945. this.commitOrRemove();
  2946. }
  2947. }
  2948. commitOrRemove() {
  2949. if (this.isEmpty()) {
  2950. this.remove();
  2951. } else {
  2952. this.commit();
  2953. }
  2954. }
  2955. commit() {
  2956. this.addToAnnotationStorage();
  2957. }
  2958. addToAnnotationStorage() {
  2959. this._uiManager.addToAnnotationStorage(this);
  2960. }
  2961. dragstart(event) {
  2962. const rect = this.parent.div.getBoundingClientRect();
  2963. this.startX = event.clientX - rect.x;
  2964. this.startY = event.clientY - rect.y;
  2965. event.dataTransfer.setData("text/plain", this.id);
  2966. event.dataTransfer.effectAllowed = "move";
  2967. }
  2968. setAt(x, y, tx, ty) {
  2969. const [width, height] = this.parentDimensions;
  2970. [tx, ty] = this.screenToPageTranslation(tx, ty);
  2971. this.x = (x + tx) / width;
  2972. this.y = (y + ty) / height;
  2973. this.div.style.left = `${100 * this.x}%`;
  2974. this.div.style.top = `${100 * this.y}%`;
  2975. }
  2976. translate(x, y) {
  2977. const [width, height] = this.parentDimensions;
  2978. [x, y] = this.screenToPageTranslation(x, y);
  2979. this.x += x / width;
  2980. this.y += y / height;
  2981. this.div.style.left = `${100 * this.x}%`;
  2982. this.div.style.top = `${100 * this.y}%`;
  2983. }
  2984. screenToPageTranslation(x, y) {
  2985. switch (this.parentRotation) {
  2986. case 90:
  2987. return [y, -x];
  2988. case 180:
  2989. return [-x, -y];
  2990. case 270:
  2991. return [-y, x];
  2992. default:
  2993. return [x, y];
  2994. }
  2995. }
  2996. get parentScale() {
  2997. return this._uiManager.viewParameters.realScale;
  2998. }
  2999. get parentRotation() {
  3000. return (this._uiManager.viewParameters.rotation + this.pageRotation) % 360;
  3001. }
  3002. get parentDimensions() {
  3003. const {
  3004. realScale
  3005. } = this._uiManager.viewParameters;
  3006. const [pageWidth, pageHeight] = this.pageDimensions;
  3007. return [pageWidth * realScale, pageHeight * realScale];
  3008. }
  3009. setDims(width, height) {
  3010. const [parentWidth, parentHeight] = this.parentDimensions;
  3011. this.div.style.width = `${100 * width / parentWidth}%`;
  3012. this.div.style.height = `${100 * height / parentHeight}%`;
  3013. }
  3014. fixDims() {
  3015. const {
  3016. style
  3017. } = this.div;
  3018. const {
  3019. height,
  3020. width
  3021. } = style;
  3022. const widthPercent = width.endsWith("%");
  3023. const heightPercent = height.endsWith("%");
  3024. if (widthPercent && heightPercent) {
  3025. return;
  3026. }
  3027. const [parentWidth, parentHeight] = this.parentDimensions;
  3028. if (!widthPercent) {
  3029. style.width = `${100 * parseFloat(width) / parentWidth}%`;
  3030. }
  3031. if (!heightPercent) {
  3032. style.height = `${100 * parseFloat(height) / parentHeight}%`;
  3033. }
  3034. }
  3035. getInitialTranslation() {
  3036. return [0, 0];
  3037. }
  3038. render() {
  3039. this.div = document.createElement("div");
  3040. this.div.setAttribute("data-editor-rotation", (360 - this.rotation) % 360);
  3041. this.div.className = this.name;
  3042. this.div.setAttribute("id", this.id);
  3043. this.div.setAttribute("tabIndex", 0);
  3044. this.setInForeground();
  3045. this.div.addEventListener("focusin", this.#boundFocusin);
  3046. this.div.addEventListener("focusout", this.#boundFocusout);
  3047. const [tx, ty] = this.getInitialTranslation();
  3048. this.translate(tx, ty);
  3049. (0, _tools.bindEvents)(this, this.div, ["dragstart", "pointerdown"]);
  3050. return this.div;
  3051. }
  3052. pointerdown(event) {
  3053. const {
  3054. isMac
  3055. } = _util.FeatureTest.platform;
  3056. if (event.button !== 0 || event.ctrlKey && isMac) {
  3057. event.preventDefault();
  3058. return;
  3059. }
  3060. if (event.ctrlKey && !isMac || event.shiftKey || event.metaKey && isMac) {
  3061. this.parent.toggleSelected(this);
  3062. } else {
  3063. this.parent.setSelected(this);
  3064. }
  3065. this.#hasBeenSelected = true;
  3066. }
  3067. getRect(tx, ty) {
  3068. const scale = this.parentScale;
  3069. const [pageWidth, pageHeight] = this.pageDimensions;
  3070. const [pageX, pageY] = this.pageTranslation;
  3071. const shiftX = tx / scale;
  3072. const shiftY = ty / scale;
  3073. const x = this.x * pageWidth;
  3074. const y = this.y * pageHeight;
  3075. const width = this.width * pageWidth;
  3076. const height = this.height * pageHeight;
  3077. switch (this.rotation) {
  3078. case 0:
  3079. return [x + shiftX + pageX, pageHeight - y - shiftY - height + pageY, x + shiftX + width + pageX, pageHeight - y - shiftY + pageY];
  3080. case 90:
  3081. return [x + shiftY + pageX, pageHeight - y + shiftX + pageY, x + shiftY + height + pageX, pageHeight - y + shiftX + width + pageY];
  3082. case 180:
  3083. return [x - shiftX - width + pageX, pageHeight - y + shiftY + pageY, x - shiftX + pageX, pageHeight - y + shiftY + height + pageY];
  3084. case 270:
  3085. return [x - shiftY - height + pageX, pageHeight - y - shiftX - width + pageY, x - shiftY + pageX, pageHeight - y - shiftX + pageY];
  3086. default:
  3087. throw new Error("Invalid rotation");
  3088. }
  3089. }
  3090. getRectInCurrentCoords(rect, pageHeight) {
  3091. const [x1, y1, x2, y2] = rect;
  3092. const width = x2 - x1;
  3093. const height = y2 - y1;
  3094. switch (this.rotation) {
  3095. case 0:
  3096. return [x1, pageHeight - y2, width, height];
  3097. case 90:
  3098. return [x1, pageHeight - y1, height, width];
  3099. case 180:
  3100. return [x2, pageHeight - y1, width, height];
  3101. case 270:
  3102. return [x2, pageHeight - y2, height, width];
  3103. default:
  3104. throw new Error("Invalid rotation");
  3105. }
  3106. }
  3107. onceAdded() {}
  3108. isEmpty() {
  3109. return false;
  3110. }
  3111. enableEditMode() {
  3112. this.#isInEditMode = true;
  3113. }
  3114. disableEditMode() {
  3115. this.#isInEditMode = false;
  3116. }
  3117. isInEditMode() {
  3118. return this.#isInEditMode;
  3119. }
  3120. shouldGetKeyboardEvents() {
  3121. return false;
  3122. }
  3123. needsToBeRebuilt() {
  3124. return this.div && !this.isAttachedToDOM;
  3125. }
  3126. rebuild() {
  3127. this.div?.addEventListener("focusin", this.#boundFocusin);
  3128. }
  3129. serialize() {
  3130. (0, _util.unreachable)("An editor must be serializable");
  3131. }
  3132. static deserialize(data, parent, uiManager) {
  3133. const editor = new this.prototype.constructor({
  3134. parent,
  3135. id: parent.getNextId(),
  3136. uiManager
  3137. });
  3138. editor.rotation = data.rotation;
  3139. const [pageWidth, pageHeight] = editor.pageDimensions;
  3140. const [x, y, width, height] = editor.getRectInCurrentCoords(data.rect, pageHeight);
  3141. editor.x = x / pageWidth;
  3142. editor.y = y / pageHeight;
  3143. editor.width = width / pageWidth;
  3144. editor.height = height / pageHeight;
  3145. return editor;
  3146. }
  3147. remove() {
  3148. this.div.removeEventListener("focusin", this.#boundFocusin);
  3149. this.div.removeEventListener("focusout", this.#boundFocusout);
  3150. if (!this.isEmpty()) {
  3151. this.commit();
  3152. }
  3153. this.parent.remove(this);
  3154. }
  3155. select() {
  3156. this.div?.classList.add("selectedEditor");
  3157. }
  3158. unselect() {
  3159. this.div?.classList.remove("selectedEditor");
  3160. }
  3161. updateParams(type, value) {}
  3162. disableEditing() {}
  3163. enableEditing() {}
  3164. get propertiesToUpdate() {
  3165. return {};
  3166. }
  3167. get contentDiv() {
  3168. return this.div;
  3169. }
  3170. get isEditing() {
  3171. return this.#isEditing;
  3172. }
  3173. set isEditing(value) {
  3174. this.#isEditing = value;
  3175. if (value) {
  3176. this.parent.setSelected(this);
  3177. this.parent.setActiveEditor(this);
  3178. } else {
  3179. this.parent.setActiveEditor(null);
  3180. }
  3181. }
  3182. }
  3183. exports.AnnotationEditor = AnnotationEditor;
  3184. /***/ }),
  3185. /* 5 */
  3186. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3187. Object.defineProperty(exports, "__esModule", ({
  3188. value: true
  3189. }));
  3190. exports.KeyboardManager = exports.CommandManager = exports.ColorManager = exports.AnnotationEditorUIManager = void 0;
  3191. exports.bindEvents = bindEvents;
  3192. exports.opacityToHex = opacityToHex;
  3193. var _util = __w_pdfjs_require__(1);
  3194. var _display_utils = __w_pdfjs_require__(6);
  3195. function bindEvents(obj, element, names) {
  3196. for (const name of names) {
  3197. element.addEventListener(name, obj[name].bind(obj));
  3198. }
  3199. }
  3200. function opacityToHex(opacity) {
  3201. return Math.round(Math.min(255, Math.max(1, 255 * opacity))).toString(16).padStart(2, "0");
  3202. }
  3203. class IdManager {
  3204. #id = 0;
  3205. getId() {
  3206. return `${_util.AnnotationEditorPrefix}${this.#id++}`;
  3207. }
  3208. }
  3209. class CommandManager {
  3210. #commands = [];
  3211. #locked = false;
  3212. #maxSize;
  3213. #position = -1;
  3214. constructor(maxSize = 128) {
  3215. this.#maxSize = maxSize;
  3216. }
  3217. add({
  3218. cmd,
  3219. undo,
  3220. mustExec,
  3221. type = NaN,
  3222. overwriteIfSameType = false,
  3223. keepUndo = false
  3224. }) {
  3225. if (mustExec) {
  3226. cmd();
  3227. }
  3228. if (this.#locked) {
  3229. return;
  3230. }
  3231. const save = {
  3232. cmd,
  3233. undo,
  3234. type
  3235. };
  3236. if (this.#position === -1) {
  3237. if (this.#commands.length > 0) {
  3238. this.#commands.length = 0;
  3239. }
  3240. this.#position = 0;
  3241. this.#commands.push(save);
  3242. return;
  3243. }
  3244. if (overwriteIfSameType && this.#commands[this.#position].type === type) {
  3245. if (keepUndo) {
  3246. save.undo = this.#commands[this.#position].undo;
  3247. }
  3248. this.#commands[this.#position] = save;
  3249. return;
  3250. }
  3251. const next = this.#position + 1;
  3252. if (next === this.#maxSize) {
  3253. this.#commands.splice(0, 1);
  3254. } else {
  3255. this.#position = next;
  3256. if (next < this.#commands.length) {
  3257. this.#commands.splice(next);
  3258. }
  3259. }
  3260. this.#commands.push(save);
  3261. }
  3262. undo() {
  3263. if (this.#position === -1) {
  3264. return;
  3265. }
  3266. this.#locked = true;
  3267. this.#commands[this.#position].undo();
  3268. this.#locked = false;
  3269. this.#position -= 1;
  3270. }
  3271. redo() {
  3272. if (this.#position < this.#commands.length - 1) {
  3273. this.#position += 1;
  3274. this.#locked = true;
  3275. this.#commands[this.#position].cmd();
  3276. this.#locked = false;
  3277. }
  3278. }
  3279. hasSomethingToUndo() {
  3280. return this.#position !== -1;
  3281. }
  3282. hasSomethingToRedo() {
  3283. return this.#position < this.#commands.length - 1;
  3284. }
  3285. destroy() {
  3286. this.#commands = null;
  3287. }
  3288. }
  3289. exports.CommandManager = CommandManager;
  3290. class KeyboardManager {
  3291. constructor(callbacks) {
  3292. this.buffer = [];
  3293. this.callbacks = new Map();
  3294. this.allKeys = new Set();
  3295. const {
  3296. isMac
  3297. } = _util.FeatureTest.platform;
  3298. for (const [keys, callback] of callbacks) {
  3299. for (const key of keys) {
  3300. const isMacKey = key.startsWith("mac+");
  3301. if (isMac && isMacKey) {
  3302. this.callbacks.set(key.slice(4), callback);
  3303. this.allKeys.add(key.split("+").at(-1));
  3304. } else if (!isMac && !isMacKey) {
  3305. this.callbacks.set(key, callback);
  3306. this.allKeys.add(key.split("+").at(-1));
  3307. }
  3308. }
  3309. }
  3310. }
  3311. #serialize(event) {
  3312. if (event.altKey) {
  3313. this.buffer.push("alt");
  3314. }
  3315. if (event.ctrlKey) {
  3316. this.buffer.push("ctrl");
  3317. }
  3318. if (event.metaKey) {
  3319. this.buffer.push("meta");
  3320. }
  3321. if (event.shiftKey) {
  3322. this.buffer.push("shift");
  3323. }
  3324. this.buffer.push(event.key);
  3325. const str = this.buffer.join("+");
  3326. this.buffer.length = 0;
  3327. return str;
  3328. }
  3329. exec(self, event) {
  3330. if (!this.allKeys.has(event.key)) {
  3331. return;
  3332. }
  3333. const callback = this.callbacks.get(this.#serialize(event));
  3334. if (!callback) {
  3335. return;
  3336. }
  3337. callback.bind(self)();
  3338. event.stopPropagation();
  3339. event.preventDefault();
  3340. }
  3341. }
  3342. exports.KeyboardManager = KeyboardManager;
  3343. class ColorManager {
  3344. static _colorsMapping = new Map([["CanvasText", [0, 0, 0]], ["Canvas", [255, 255, 255]]]);
  3345. get _colors() {
  3346. const colors = new Map([["CanvasText", null], ["Canvas", null]]);
  3347. (0, _display_utils.getColorValues)(colors);
  3348. return (0, _util.shadow)(this, "_colors", colors);
  3349. }
  3350. convert(color) {
  3351. const rgb = (0, _display_utils.getRGB)(color);
  3352. if (!window.matchMedia("(forced-colors: active)").matches) {
  3353. return rgb;
  3354. }
  3355. for (const [name, RGB] of this._colors) {
  3356. if (RGB.every((x, i) => x === rgb[i])) {
  3357. return ColorManager._colorsMapping.get(name);
  3358. }
  3359. }
  3360. return rgb;
  3361. }
  3362. getHexCode(name) {
  3363. const rgb = this._colors.get(name);
  3364. if (!rgb) {
  3365. return name;
  3366. }
  3367. return _util.Util.makeHexColor(...rgb);
  3368. }
  3369. }
  3370. exports.ColorManager = ColorManager;
  3371. class AnnotationEditorUIManager {
  3372. #activeEditor = null;
  3373. #allEditors = new Map();
  3374. #allLayers = new Map();
  3375. #annotationStorage = null;
  3376. #commandManager = new CommandManager();
  3377. #currentPageIndex = 0;
  3378. #editorTypes = null;
  3379. #editorsToRescale = new Set();
  3380. #eventBus = null;
  3381. #idManager = new IdManager();
  3382. #isEnabled = false;
  3383. #mode = _util.AnnotationEditorType.NONE;
  3384. #selectedEditors = new Set();
  3385. #boundCopy = this.copy.bind(this);
  3386. #boundCut = this.cut.bind(this);
  3387. #boundPaste = this.paste.bind(this);
  3388. #boundKeydown = this.keydown.bind(this);
  3389. #boundOnEditingAction = this.onEditingAction.bind(this);
  3390. #boundOnPageChanging = this.onPageChanging.bind(this);
  3391. #boundOnScaleChanging = this.onScaleChanging.bind(this);
  3392. #boundOnRotationChanging = this.onRotationChanging.bind(this);
  3393. #previousStates = {
  3394. isEditing: false,
  3395. isEmpty: true,
  3396. hasSomethingToUndo: false,
  3397. hasSomethingToRedo: false,
  3398. hasSelectedEditor: false
  3399. };
  3400. #container = null;
  3401. static _keyboardManager = new KeyboardManager([[["ctrl+a", "mac+meta+a"], AnnotationEditorUIManager.prototype.selectAll], [["ctrl+z", "mac+meta+z"], AnnotationEditorUIManager.prototype.undo], [["ctrl+y", "ctrl+shift+Z", "mac+meta+shift+Z"], AnnotationEditorUIManager.prototype.redo], [["Backspace", "alt+Backspace", "ctrl+Backspace", "shift+Backspace", "mac+Backspace", "mac+alt+Backspace", "mac+ctrl+Backspace", "Delete", "ctrl+Delete", "shift+Delete"], AnnotationEditorUIManager.prototype.delete], [["Escape", "mac+Escape"], AnnotationEditorUIManager.prototype.unselectAll]]);
  3402. constructor(container, eventBus, annotationStorage) {
  3403. this.#container = container;
  3404. this.#eventBus = eventBus;
  3405. this.#eventBus._on("editingaction", this.#boundOnEditingAction);
  3406. this.#eventBus._on("pagechanging", this.#boundOnPageChanging);
  3407. this.#eventBus._on("scalechanging", this.#boundOnScaleChanging);
  3408. this.#eventBus._on("rotationchanging", this.#boundOnRotationChanging);
  3409. this.#annotationStorage = annotationStorage;
  3410. this.viewParameters = {
  3411. realScale: _display_utils.PixelsPerInch.PDF_TO_CSS_UNITS,
  3412. rotation: 0
  3413. };
  3414. }
  3415. destroy() {
  3416. this.#removeKeyboardManager();
  3417. this.#eventBus._off("editingaction", this.#boundOnEditingAction);
  3418. this.#eventBus._off("pagechanging", this.#boundOnPageChanging);
  3419. this.#eventBus._off("scalechanging", this.#boundOnScaleChanging);
  3420. this.#eventBus._off("rotationchanging", this.#boundOnRotationChanging);
  3421. for (const layer of this.#allLayers.values()) {
  3422. layer.destroy();
  3423. }
  3424. this.#allLayers.clear();
  3425. this.#allEditors.clear();
  3426. this.#editorsToRescale.clear();
  3427. this.#activeEditor = null;
  3428. this.#selectedEditors.clear();
  3429. this.#commandManager.destroy();
  3430. }
  3431. onPageChanging({
  3432. pageNumber
  3433. }) {
  3434. this.#currentPageIndex = pageNumber - 1;
  3435. }
  3436. focusMainContainer() {
  3437. this.#container.focus();
  3438. }
  3439. addShouldRescale(editor) {
  3440. this.#editorsToRescale.add(editor);
  3441. }
  3442. removeShouldRescale(editor) {
  3443. this.#editorsToRescale.delete(editor);
  3444. }
  3445. onScaleChanging({
  3446. scale
  3447. }) {
  3448. this.commitOrRemove();
  3449. this.viewParameters.realScale = scale * _display_utils.PixelsPerInch.PDF_TO_CSS_UNITS;
  3450. for (const editor of this.#editorsToRescale) {
  3451. editor.onScaleChanging();
  3452. }
  3453. }
  3454. onRotationChanging({
  3455. pagesRotation
  3456. }) {
  3457. this.commitOrRemove();
  3458. this.viewParameters.rotation = pagesRotation;
  3459. }
  3460. addToAnnotationStorage(editor) {
  3461. if (!editor.isEmpty() && this.#annotationStorage && !this.#annotationStorage.has(editor.id)) {
  3462. this.#annotationStorage.setValue(editor.id, editor);
  3463. }
  3464. }
  3465. #addKeyboardManager() {
  3466. this.#container.addEventListener("keydown", this.#boundKeydown);
  3467. }
  3468. #removeKeyboardManager() {
  3469. this.#container.removeEventListener("keydown", this.#boundKeydown);
  3470. }
  3471. #addCopyPasteListeners() {
  3472. document.addEventListener("copy", this.#boundCopy);
  3473. document.addEventListener("cut", this.#boundCut);
  3474. document.addEventListener("paste", this.#boundPaste);
  3475. }
  3476. #removeCopyPasteListeners() {
  3477. document.removeEventListener("copy", this.#boundCopy);
  3478. document.removeEventListener("cut", this.#boundCut);
  3479. document.removeEventListener("paste", this.#boundPaste);
  3480. }
  3481. copy(event) {
  3482. event.preventDefault();
  3483. if (this.#activeEditor) {
  3484. this.#activeEditor.commitOrRemove();
  3485. }
  3486. if (!this.hasSelection) {
  3487. return;
  3488. }
  3489. const editors = [];
  3490. for (const editor of this.#selectedEditors) {
  3491. if (!editor.isEmpty()) {
  3492. editors.push(editor.serialize());
  3493. }
  3494. }
  3495. if (editors.length === 0) {
  3496. return;
  3497. }
  3498. event.clipboardData.setData("application/pdfjs", JSON.stringify(editors));
  3499. }
  3500. cut(event) {
  3501. this.copy(event);
  3502. this.delete();
  3503. }
  3504. paste(event) {
  3505. event.preventDefault();
  3506. let data = event.clipboardData.getData("application/pdfjs");
  3507. if (!data) {
  3508. return;
  3509. }
  3510. try {
  3511. data = JSON.parse(data);
  3512. } catch (ex) {
  3513. (0, _util.warn)(`paste: "${ex.message}".`);
  3514. return;
  3515. }
  3516. if (!Array.isArray(data)) {
  3517. return;
  3518. }
  3519. this.unselectAll();
  3520. const layer = this.#allLayers.get(this.#currentPageIndex);
  3521. try {
  3522. const newEditors = [];
  3523. for (const editor of data) {
  3524. const deserializedEditor = layer.deserialize(editor);
  3525. if (!deserializedEditor) {
  3526. return;
  3527. }
  3528. newEditors.push(deserializedEditor);
  3529. }
  3530. const cmd = () => {
  3531. for (const editor of newEditors) {
  3532. this.#addEditorToLayer(editor);
  3533. }
  3534. this.#selectEditors(newEditors);
  3535. };
  3536. const undo = () => {
  3537. for (const editor of newEditors) {
  3538. editor.remove();
  3539. }
  3540. };
  3541. this.addCommands({
  3542. cmd,
  3543. undo,
  3544. mustExec: true
  3545. });
  3546. } catch (ex) {
  3547. (0, _util.warn)(`paste: "${ex.message}".`);
  3548. }
  3549. }
  3550. keydown(event) {
  3551. if (!this.getActive()?.shouldGetKeyboardEvents()) {
  3552. AnnotationEditorUIManager._keyboardManager.exec(this, event);
  3553. }
  3554. }
  3555. onEditingAction(details) {
  3556. if (["undo", "redo", "delete", "selectAll"].includes(details.name)) {
  3557. this[details.name]();
  3558. }
  3559. }
  3560. #dispatchUpdateStates(details) {
  3561. const hasChanged = Object.entries(details).some(([key, value]) => this.#previousStates[key] !== value);
  3562. if (hasChanged) {
  3563. this.#eventBus.dispatch("annotationeditorstateschanged", {
  3564. source: this,
  3565. details: Object.assign(this.#previousStates, details)
  3566. });
  3567. }
  3568. }
  3569. #dispatchUpdateUI(details) {
  3570. this.#eventBus.dispatch("annotationeditorparamschanged", {
  3571. source: this,
  3572. details
  3573. });
  3574. }
  3575. setEditingState(isEditing) {
  3576. if (isEditing) {
  3577. this.#addKeyboardManager();
  3578. this.#addCopyPasteListeners();
  3579. this.#dispatchUpdateStates({
  3580. isEditing: this.#mode !== _util.AnnotationEditorType.NONE,
  3581. isEmpty: this.#isEmpty(),
  3582. hasSomethingToUndo: this.#commandManager.hasSomethingToUndo(),
  3583. hasSomethingToRedo: this.#commandManager.hasSomethingToRedo(),
  3584. hasSelectedEditor: false
  3585. });
  3586. } else {
  3587. this.#removeKeyboardManager();
  3588. this.#removeCopyPasteListeners();
  3589. this.#dispatchUpdateStates({
  3590. isEditing: false
  3591. });
  3592. }
  3593. }
  3594. registerEditorTypes(types) {
  3595. if (this.#editorTypes) {
  3596. return;
  3597. }
  3598. this.#editorTypes = types;
  3599. for (const editorType of this.#editorTypes) {
  3600. this.#dispatchUpdateUI(editorType.defaultPropertiesToUpdate);
  3601. }
  3602. }
  3603. getId() {
  3604. return this.#idManager.getId();
  3605. }
  3606. get currentLayer() {
  3607. return this.#allLayers.get(this.#currentPageIndex);
  3608. }
  3609. get currentPageIndex() {
  3610. return this.#currentPageIndex;
  3611. }
  3612. addLayer(layer) {
  3613. this.#allLayers.set(layer.pageIndex, layer);
  3614. if (this.#isEnabled) {
  3615. layer.enable();
  3616. } else {
  3617. layer.disable();
  3618. }
  3619. }
  3620. removeLayer(layer) {
  3621. this.#allLayers.delete(layer.pageIndex);
  3622. }
  3623. updateMode(mode) {
  3624. this.#mode = mode;
  3625. if (mode === _util.AnnotationEditorType.NONE) {
  3626. this.setEditingState(false);
  3627. this.#disableAll();
  3628. } else {
  3629. this.setEditingState(true);
  3630. this.#enableAll();
  3631. for (const layer of this.#allLayers.values()) {
  3632. layer.updateMode(mode);
  3633. }
  3634. }
  3635. }
  3636. updateToolbar(mode) {
  3637. if (mode === this.#mode) {
  3638. return;
  3639. }
  3640. this.#eventBus.dispatch("switchannotationeditormode", {
  3641. source: this,
  3642. mode
  3643. });
  3644. }
  3645. updateParams(type, value) {
  3646. if (!this.#editorTypes) {
  3647. return;
  3648. }
  3649. for (const editor of this.#selectedEditors) {
  3650. editor.updateParams(type, value);
  3651. }
  3652. for (const editorType of this.#editorTypes) {
  3653. editorType.updateDefaultParams(type, value);
  3654. }
  3655. }
  3656. #enableAll() {
  3657. if (!this.#isEnabled) {
  3658. this.#isEnabled = true;
  3659. for (const layer of this.#allLayers.values()) {
  3660. layer.enable();
  3661. }
  3662. }
  3663. }
  3664. #disableAll() {
  3665. this.unselectAll();
  3666. if (this.#isEnabled) {
  3667. this.#isEnabled = false;
  3668. for (const layer of this.#allLayers.values()) {
  3669. layer.disable();
  3670. }
  3671. }
  3672. }
  3673. getEditors(pageIndex) {
  3674. const editors = [];
  3675. for (const editor of this.#allEditors.values()) {
  3676. if (editor.pageIndex === pageIndex) {
  3677. editors.push(editor);
  3678. }
  3679. }
  3680. return editors;
  3681. }
  3682. getEditor(id) {
  3683. return this.#allEditors.get(id);
  3684. }
  3685. addEditor(editor) {
  3686. this.#allEditors.set(editor.id, editor);
  3687. }
  3688. removeEditor(editor) {
  3689. this.#allEditors.delete(editor.id);
  3690. this.unselect(editor);
  3691. this.#annotationStorage?.remove(editor.id);
  3692. }
  3693. #addEditorToLayer(editor) {
  3694. const layer = this.#allLayers.get(editor.pageIndex);
  3695. if (layer) {
  3696. layer.addOrRebuild(editor);
  3697. } else {
  3698. this.addEditor(editor);
  3699. }
  3700. }
  3701. setActiveEditor(editor) {
  3702. if (this.#activeEditor === editor) {
  3703. return;
  3704. }
  3705. this.#activeEditor = editor;
  3706. if (editor) {
  3707. this.#dispatchUpdateUI(editor.propertiesToUpdate);
  3708. }
  3709. }
  3710. toggleSelected(editor) {
  3711. if (this.#selectedEditors.has(editor)) {
  3712. this.#selectedEditors.delete(editor);
  3713. editor.unselect();
  3714. this.#dispatchUpdateStates({
  3715. hasSelectedEditor: this.hasSelection
  3716. });
  3717. return;
  3718. }
  3719. this.#selectedEditors.add(editor);
  3720. editor.select();
  3721. this.#dispatchUpdateUI(editor.propertiesToUpdate);
  3722. this.#dispatchUpdateStates({
  3723. hasSelectedEditor: true
  3724. });
  3725. }
  3726. setSelected(editor) {
  3727. for (const ed of this.#selectedEditors) {
  3728. if (ed !== editor) {
  3729. ed.unselect();
  3730. }
  3731. }
  3732. this.#selectedEditors.clear();
  3733. this.#selectedEditors.add(editor);
  3734. editor.select();
  3735. this.#dispatchUpdateUI(editor.propertiesToUpdate);
  3736. this.#dispatchUpdateStates({
  3737. hasSelectedEditor: true
  3738. });
  3739. }
  3740. isSelected(editor) {
  3741. return this.#selectedEditors.has(editor);
  3742. }
  3743. unselect(editor) {
  3744. editor.unselect();
  3745. this.#selectedEditors.delete(editor);
  3746. this.#dispatchUpdateStates({
  3747. hasSelectedEditor: this.hasSelection
  3748. });
  3749. }
  3750. get hasSelection() {
  3751. return this.#selectedEditors.size !== 0;
  3752. }
  3753. undo() {
  3754. this.#commandManager.undo();
  3755. this.#dispatchUpdateStates({
  3756. hasSomethingToUndo: this.#commandManager.hasSomethingToUndo(),
  3757. hasSomethingToRedo: true,
  3758. isEmpty: this.#isEmpty()
  3759. });
  3760. }
  3761. redo() {
  3762. this.#commandManager.redo();
  3763. this.#dispatchUpdateStates({
  3764. hasSomethingToUndo: true,
  3765. hasSomethingToRedo: this.#commandManager.hasSomethingToRedo(),
  3766. isEmpty: this.#isEmpty()
  3767. });
  3768. }
  3769. addCommands(params) {
  3770. this.#commandManager.add(params);
  3771. this.#dispatchUpdateStates({
  3772. hasSomethingToUndo: true,
  3773. hasSomethingToRedo: false,
  3774. isEmpty: this.#isEmpty()
  3775. });
  3776. }
  3777. #isEmpty() {
  3778. if (this.#allEditors.size === 0) {
  3779. return true;
  3780. }
  3781. if (this.#allEditors.size === 1) {
  3782. for (const editor of this.#allEditors.values()) {
  3783. return editor.isEmpty();
  3784. }
  3785. }
  3786. return false;
  3787. }
  3788. delete() {
  3789. this.commitOrRemove();
  3790. if (!this.hasSelection) {
  3791. return;
  3792. }
  3793. const editors = [...this.#selectedEditors];
  3794. const cmd = () => {
  3795. for (const editor of editors) {
  3796. editor.remove();
  3797. }
  3798. };
  3799. const undo = () => {
  3800. for (const editor of editors) {
  3801. this.#addEditorToLayer(editor);
  3802. }
  3803. };
  3804. this.addCommands({
  3805. cmd,
  3806. undo,
  3807. mustExec: true
  3808. });
  3809. }
  3810. commitOrRemove() {
  3811. this.#activeEditor?.commitOrRemove();
  3812. }
  3813. #selectEditors(editors) {
  3814. this.#selectedEditors.clear();
  3815. for (const editor of editors) {
  3816. if (editor.isEmpty()) {
  3817. continue;
  3818. }
  3819. this.#selectedEditors.add(editor);
  3820. editor.select();
  3821. }
  3822. this.#dispatchUpdateStates({
  3823. hasSelectedEditor: true
  3824. });
  3825. }
  3826. selectAll() {
  3827. for (const editor of this.#selectedEditors) {
  3828. editor.commit();
  3829. }
  3830. this.#selectEditors(this.#allEditors.values());
  3831. }
  3832. unselectAll() {
  3833. if (this.#activeEditor) {
  3834. this.#activeEditor.commitOrRemove();
  3835. return;
  3836. }
  3837. if (this.#selectedEditors.size === 0) {
  3838. return;
  3839. }
  3840. for (const editor of this.#selectedEditors) {
  3841. editor.unselect();
  3842. }
  3843. this.#selectedEditors.clear();
  3844. this.#dispatchUpdateStates({
  3845. hasSelectedEditor: false
  3846. });
  3847. }
  3848. isActive(editor) {
  3849. return this.#activeEditor === editor;
  3850. }
  3851. getActive() {
  3852. return this.#activeEditor;
  3853. }
  3854. getMode() {
  3855. return this.#mode;
  3856. }
  3857. }
  3858. exports.AnnotationEditorUIManager = AnnotationEditorUIManager;
  3859. /***/ }),
  3860. /* 6 */
  3861. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3862. Object.defineProperty(exports, "__esModule", ({
  3863. value: true
  3864. }));
  3865. exports.StatTimer = exports.RenderingCancelledException = exports.PixelsPerInch = exports.PageViewport = exports.PDFDateString = exports.DOMStandardFontDataFactory = exports.DOMSVGFactory = exports.DOMFilterFactory = exports.DOMCanvasFactory = exports.DOMCMapReaderFactory = exports.AnnotationPrefix = void 0;
  3866. exports.deprecated = deprecated;
  3867. exports.getColorValues = getColorValues;
  3868. exports.getCurrentTransform = getCurrentTransform;
  3869. exports.getCurrentTransformInverse = getCurrentTransformInverse;
  3870. exports.getFilenameFromUrl = getFilenameFromUrl;
  3871. exports.getPdfFilenameFromUrl = getPdfFilenameFromUrl;
  3872. exports.getRGB = getRGB;
  3873. exports.getXfaPageViewport = getXfaPageViewport;
  3874. exports.isDataScheme = isDataScheme;
  3875. exports.isPdfFile = isPdfFile;
  3876. exports.isValidFetchUrl = isValidFetchUrl;
  3877. exports.loadScript = loadScript;
  3878. exports.setLayerDimensions = setLayerDimensions;
  3879. var _base_factory = __w_pdfjs_require__(7);
  3880. var _util = __w_pdfjs_require__(1);
  3881. const SVG_NS = "http://www.w3.org/2000/svg";
  3882. const AnnotationPrefix = "pdfjs_internal_id_";
  3883. exports.AnnotationPrefix = AnnotationPrefix;
  3884. class PixelsPerInch {
  3885. static CSS = 96.0;
  3886. static PDF = 72.0;
  3887. static PDF_TO_CSS_UNITS = this.CSS / this.PDF;
  3888. }
  3889. exports.PixelsPerInch = PixelsPerInch;
  3890. class DOMFilterFactory extends _base_factory.BaseFilterFactory {
  3891. #_cache;
  3892. #_defs;
  3893. #docId;
  3894. #document;
  3895. #hcmFilter;
  3896. #hcmKey;
  3897. #hcmUrl;
  3898. #id = 0;
  3899. constructor({
  3900. docId,
  3901. ownerDocument = globalThis.document
  3902. } = {}) {
  3903. super();
  3904. this.#docId = docId;
  3905. this.#document = ownerDocument;
  3906. }
  3907. get #cache() {
  3908. return this.#_cache ||= new Map();
  3909. }
  3910. get #defs() {
  3911. if (!this.#_defs) {
  3912. const div = this.#document.createElement("div");
  3913. const {
  3914. style
  3915. } = div;
  3916. style.visibility = "hidden";
  3917. style.contain = "strict";
  3918. style.width = style.height = 0;
  3919. style.position = "absolute";
  3920. style.top = style.left = 0;
  3921. style.zIndex = -1;
  3922. const svg = this.#document.createElementNS(SVG_NS, "svg");
  3923. svg.setAttribute("width", 0);
  3924. svg.setAttribute("height", 0);
  3925. this.#_defs = this.#document.createElementNS(SVG_NS, "defs");
  3926. div.append(svg);
  3927. svg.append(this.#_defs);
  3928. this.#document.body.append(div);
  3929. }
  3930. return this.#_defs;
  3931. }
  3932. #appendFeFunc(feComponentTransfer, func, table) {
  3933. const feFunc = this.#document.createElementNS(SVG_NS, func);
  3934. feFunc.setAttribute("type", "discrete");
  3935. feFunc.setAttribute("tableValues", table);
  3936. feComponentTransfer.append(feFunc);
  3937. }
  3938. addFilter(maps) {
  3939. if (!maps) {
  3940. return "none";
  3941. }
  3942. let value = this.#cache.get(maps);
  3943. if (value) {
  3944. return value;
  3945. }
  3946. let tableR, tableG, tableB, key;
  3947. if (maps.length === 1) {
  3948. const mapR = maps[0];
  3949. const buffer = new Array(256);
  3950. for (let i = 0; i < 256; i++) {
  3951. buffer[i] = mapR[i] / 255;
  3952. }
  3953. key = tableR = tableG = tableB = buffer.join(",");
  3954. } else {
  3955. const [mapR, mapG, mapB] = maps;
  3956. const bufferR = new Array(256);
  3957. const bufferG = new Array(256);
  3958. const bufferB = new Array(256);
  3959. for (let i = 0; i < 256; i++) {
  3960. bufferR[i] = mapR[i] / 255;
  3961. bufferG[i] = mapG[i] / 255;
  3962. bufferB[i] = mapB[i] / 255;
  3963. }
  3964. tableR = bufferR.join(",");
  3965. tableG = bufferG.join(",");
  3966. tableB = bufferB.join(",");
  3967. key = `${tableR}${tableG}${tableB}`;
  3968. }
  3969. value = this.#cache.get(key);
  3970. if (value) {
  3971. this.#cache.set(maps, value);
  3972. return value;
  3973. }
  3974. const id = `g_${this.#docId}_transfer_map_${this.#id++}`;
  3975. const url = `url(#${id})`;
  3976. this.#cache.set(maps, url);
  3977. this.#cache.set(key, url);
  3978. const filter = this.#document.createElementNS(SVG_NS, "filter", SVG_NS);
  3979. filter.setAttribute("id", id);
  3980. filter.setAttribute("color-interpolation-filters", "sRGB");
  3981. const feComponentTransfer = this.#document.createElementNS(SVG_NS, "feComponentTransfer");
  3982. filter.append(feComponentTransfer);
  3983. this.#appendFeFunc(feComponentTransfer, "feFuncR", tableR);
  3984. this.#appendFeFunc(feComponentTransfer, "feFuncG", tableG);
  3985. this.#appendFeFunc(feComponentTransfer, "feFuncB", tableB);
  3986. this.#defs.append(filter);
  3987. return url;
  3988. }
  3989. addHCMFilter(fgColor, bgColor) {
  3990. const key = `${fgColor}-${bgColor}`;
  3991. if (this.#hcmKey === key) {
  3992. return this.#hcmUrl;
  3993. }
  3994. this.#hcmKey = key;
  3995. this.#hcmUrl = "none";
  3996. this.#hcmFilter?.remove();
  3997. if (!fgColor || !bgColor) {
  3998. return this.#hcmUrl;
  3999. }
  4000. this.#defs.style.color = fgColor;
  4001. fgColor = getComputedStyle(this.#defs).getPropertyValue("color");
  4002. const fgRGB = getRGB(fgColor);
  4003. fgColor = _util.Util.makeHexColor(...fgRGB);
  4004. this.#defs.style.color = bgColor;
  4005. bgColor = getComputedStyle(this.#defs).getPropertyValue("color");
  4006. const bgRGB = getRGB(bgColor);
  4007. bgColor = _util.Util.makeHexColor(...bgRGB);
  4008. this.#defs.style.color = "";
  4009. if (fgColor === "#000000" && bgColor === "#ffffff" || fgColor === bgColor) {
  4010. return this.#hcmUrl;
  4011. }
  4012. const map = new Array(256);
  4013. for (let i = 0; i <= 255; i++) {
  4014. const x = i / 255;
  4015. map[i] = x <= 0.03928 ? x / 12.92 : ((x + 0.055) / 1.055) ** 2.4;
  4016. }
  4017. const table = map.join(",");
  4018. const id = `g_${this.#docId}_hcm_filter`;
  4019. const filter = this.#hcmFilter = this.#document.createElementNS(SVG_NS, "filter", SVG_NS);
  4020. filter.setAttribute("id", id);
  4021. filter.setAttribute("color-interpolation-filters", "sRGB");
  4022. let feComponentTransfer = this.#document.createElementNS(SVG_NS, "feComponentTransfer");
  4023. filter.append(feComponentTransfer);
  4024. this.#appendFeFunc(feComponentTransfer, "feFuncR", table);
  4025. this.#appendFeFunc(feComponentTransfer, "feFuncG", table);
  4026. this.#appendFeFunc(feComponentTransfer, "feFuncB", table);
  4027. const feColorMatrix = this.#document.createElementNS(SVG_NS, "feColorMatrix");
  4028. feColorMatrix.setAttribute("type", "matrix");
  4029. feColorMatrix.setAttribute("values", "0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0 0 0 1 0");
  4030. filter.append(feColorMatrix);
  4031. feComponentTransfer = this.#document.createElementNS(SVG_NS, "feComponentTransfer");
  4032. filter.append(feComponentTransfer);
  4033. const getSteps = (c, n) => {
  4034. const start = fgRGB[c] / 255;
  4035. const end = bgRGB[c] / 255;
  4036. const arr = new Array(n + 1);
  4037. for (let i = 0; i <= n; i++) {
  4038. arr[i] = start + i / n * (end - start);
  4039. }
  4040. return arr.join(",");
  4041. };
  4042. this.#appendFeFunc(feComponentTransfer, "feFuncR", getSteps(0, 5));
  4043. this.#appendFeFunc(feComponentTransfer, "feFuncG", getSteps(1, 5));
  4044. this.#appendFeFunc(feComponentTransfer, "feFuncB", getSteps(2, 5));
  4045. this.#defs.append(filter);
  4046. this.#hcmUrl = `url(#${id})`;
  4047. return this.#hcmUrl;
  4048. }
  4049. destroy(keepHCM = false) {
  4050. if (keepHCM && this.#hcmUrl) {
  4051. return;
  4052. }
  4053. if (this.#_defs) {
  4054. this.#_defs.parentNode.parentNode.remove();
  4055. this.#_defs = null;
  4056. }
  4057. if (this.#_cache) {
  4058. this.#_cache.clear();
  4059. this.#_cache = null;
  4060. }
  4061. this.#id = 0;
  4062. }
  4063. }
  4064. exports.DOMFilterFactory = DOMFilterFactory;
  4065. class DOMCanvasFactory extends _base_factory.BaseCanvasFactory {
  4066. constructor({
  4067. ownerDocument = globalThis.document
  4068. } = {}) {
  4069. super();
  4070. this._document = ownerDocument;
  4071. }
  4072. _createCanvas(width, height) {
  4073. const canvas = this._document.createElement("canvas");
  4074. canvas.width = width;
  4075. canvas.height = height;
  4076. return canvas;
  4077. }
  4078. }
  4079. exports.DOMCanvasFactory = DOMCanvasFactory;
  4080. async function fetchData(url, asTypedArray = false) {
  4081. if (isValidFetchUrl(url, document.baseURI)) {
  4082. const response = await fetch(url);
  4083. if (!response.ok) {
  4084. throw new Error(response.statusText);
  4085. }
  4086. return asTypedArray ? new Uint8Array(await response.arrayBuffer()) : (0, _util.stringToBytes)(await response.text());
  4087. }
  4088. return new Promise((resolve, reject) => {
  4089. const request = new XMLHttpRequest();
  4090. request.open("GET", url, true);
  4091. if (asTypedArray) {
  4092. request.responseType = "arraybuffer";
  4093. }
  4094. request.onreadystatechange = () => {
  4095. if (request.readyState !== XMLHttpRequest.DONE) {
  4096. return;
  4097. }
  4098. if (request.status === 200 || request.status === 0) {
  4099. let data;
  4100. if (asTypedArray && request.response) {
  4101. data = new Uint8Array(request.response);
  4102. } else if (!asTypedArray && request.responseText) {
  4103. data = (0, _util.stringToBytes)(request.responseText);
  4104. }
  4105. if (data) {
  4106. resolve(data);
  4107. return;
  4108. }
  4109. }
  4110. reject(new Error(request.statusText));
  4111. };
  4112. request.send(null);
  4113. });
  4114. }
  4115. class DOMCMapReaderFactory extends _base_factory.BaseCMapReaderFactory {
  4116. _fetchData(url, compressionType) {
  4117. return fetchData(url, this.isCompressed).then(data => {
  4118. return {
  4119. cMapData: data,
  4120. compressionType
  4121. };
  4122. });
  4123. }
  4124. }
  4125. exports.DOMCMapReaderFactory = DOMCMapReaderFactory;
  4126. class DOMStandardFontDataFactory extends _base_factory.BaseStandardFontDataFactory {
  4127. _fetchData(url) {
  4128. return fetchData(url, true);
  4129. }
  4130. }
  4131. exports.DOMStandardFontDataFactory = DOMStandardFontDataFactory;
  4132. class DOMSVGFactory extends _base_factory.BaseSVGFactory {
  4133. _createSVG(type) {
  4134. return document.createElementNS(SVG_NS, type);
  4135. }
  4136. }
  4137. exports.DOMSVGFactory = DOMSVGFactory;
  4138. class PageViewport {
  4139. constructor({
  4140. viewBox,
  4141. scale,
  4142. rotation,
  4143. offsetX = 0,
  4144. offsetY = 0,
  4145. dontFlip = false
  4146. }) {
  4147. this.viewBox = viewBox;
  4148. this.scale = scale;
  4149. this.rotation = rotation;
  4150. this.offsetX = offsetX;
  4151. this.offsetY = offsetY;
  4152. const centerX = (viewBox[2] + viewBox[0]) / 2;
  4153. const centerY = (viewBox[3] + viewBox[1]) / 2;
  4154. let rotateA, rotateB, rotateC, rotateD;
  4155. rotation %= 360;
  4156. if (rotation < 0) {
  4157. rotation += 360;
  4158. }
  4159. switch (rotation) {
  4160. case 180:
  4161. rotateA = -1;
  4162. rotateB = 0;
  4163. rotateC = 0;
  4164. rotateD = 1;
  4165. break;
  4166. case 90:
  4167. rotateA = 0;
  4168. rotateB = 1;
  4169. rotateC = 1;
  4170. rotateD = 0;
  4171. break;
  4172. case 270:
  4173. rotateA = 0;
  4174. rotateB = -1;
  4175. rotateC = -1;
  4176. rotateD = 0;
  4177. break;
  4178. case 0:
  4179. rotateA = 1;
  4180. rotateB = 0;
  4181. rotateC = 0;
  4182. rotateD = -1;
  4183. break;
  4184. default:
  4185. throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.");
  4186. }
  4187. if (dontFlip) {
  4188. rotateC = -rotateC;
  4189. rotateD = -rotateD;
  4190. }
  4191. let offsetCanvasX, offsetCanvasY;
  4192. let width, height;
  4193. if (rotateA === 0) {
  4194. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  4195. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  4196. width = (viewBox[3] - viewBox[1]) * scale;
  4197. height = (viewBox[2] - viewBox[0]) * scale;
  4198. } else {
  4199. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  4200. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  4201. width = (viewBox[2] - viewBox[0]) * scale;
  4202. height = (viewBox[3] - viewBox[1]) * scale;
  4203. }
  4204. this.transform = [rotateA * scale, rotateB * scale, rotateC * scale, rotateD * scale, offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY, offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY];
  4205. this.width = width;
  4206. this.height = height;
  4207. }
  4208. get rawDims() {
  4209. const {
  4210. viewBox
  4211. } = this;
  4212. return (0, _util.shadow)(this, "rawDims", {
  4213. pageWidth: viewBox[2] - viewBox[0],
  4214. pageHeight: viewBox[3] - viewBox[1],
  4215. pageX: viewBox[0],
  4216. pageY: viewBox[1]
  4217. });
  4218. }
  4219. clone({
  4220. scale = this.scale,
  4221. rotation = this.rotation,
  4222. offsetX = this.offsetX,
  4223. offsetY = this.offsetY,
  4224. dontFlip = false
  4225. } = {}) {
  4226. return new PageViewport({
  4227. viewBox: this.viewBox.slice(),
  4228. scale,
  4229. rotation,
  4230. offsetX,
  4231. offsetY,
  4232. dontFlip
  4233. });
  4234. }
  4235. convertToViewportPoint(x, y) {
  4236. return _util.Util.applyTransform([x, y], this.transform);
  4237. }
  4238. convertToViewportRectangle(rect) {
  4239. const topLeft = _util.Util.applyTransform([rect[0], rect[1]], this.transform);
  4240. const bottomRight = _util.Util.applyTransform([rect[2], rect[3]], this.transform);
  4241. return [topLeft[0], topLeft[1], bottomRight[0], bottomRight[1]];
  4242. }
  4243. convertToPdfPoint(x, y) {
  4244. return _util.Util.applyInverseTransform([x, y], this.transform);
  4245. }
  4246. }
  4247. exports.PageViewport = PageViewport;
  4248. class RenderingCancelledException extends _util.BaseException {
  4249. constructor(msg, type, extraDelay = 0) {
  4250. super(msg, "RenderingCancelledException");
  4251. this.type = type;
  4252. this.extraDelay = extraDelay;
  4253. }
  4254. }
  4255. exports.RenderingCancelledException = RenderingCancelledException;
  4256. function isDataScheme(url) {
  4257. const ii = url.length;
  4258. let i = 0;
  4259. while (i < ii && url[i].trim() === "") {
  4260. i++;
  4261. }
  4262. return url.substring(i, i + 5).toLowerCase() === "data:";
  4263. }
  4264. function isPdfFile(filename) {
  4265. return typeof filename === "string" && /\.pdf$/i.test(filename);
  4266. }
  4267. function getFilenameFromUrl(url, onlyStripPath = false) {
  4268. if (!onlyStripPath) {
  4269. [url] = url.split(/[#?]/, 1);
  4270. }
  4271. return url.substring(url.lastIndexOf("/") + 1);
  4272. }
  4273. function getPdfFilenameFromUrl(url, defaultFilename = "document.pdf") {
  4274. if (typeof url !== "string") {
  4275. return defaultFilename;
  4276. }
  4277. if (isDataScheme(url)) {
  4278. (0, _util.warn)('getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.');
  4279. return defaultFilename;
  4280. }
  4281. const reURI = /^(?:(?:[^:]+:)?\/\/[^/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
  4282. const reFilename = /[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
  4283. const splitURI = reURI.exec(url);
  4284. let suggestedFilename = reFilename.exec(splitURI[1]) || reFilename.exec(splitURI[2]) || reFilename.exec(splitURI[3]);
  4285. if (suggestedFilename) {
  4286. suggestedFilename = suggestedFilename[0];
  4287. if (suggestedFilename.includes("%")) {
  4288. try {
  4289. suggestedFilename = reFilename.exec(decodeURIComponent(suggestedFilename))[0];
  4290. } catch (ex) {}
  4291. }
  4292. }
  4293. return suggestedFilename || defaultFilename;
  4294. }
  4295. class StatTimer {
  4296. started = Object.create(null);
  4297. times = [];
  4298. time(name) {
  4299. if (name in this.started) {
  4300. (0, _util.warn)(`Timer is already running for ${name}`);
  4301. }
  4302. this.started[name] = Date.now();
  4303. }
  4304. timeEnd(name) {
  4305. if (!(name in this.started)) {
  4306. (0, _util.warn)(`Timer has not been started for ${name}`);
  4307. }
  4308. this.times.push({
  4309. name,
  4310. start: this.started[name],
  4311. end: Date.now()
  4312. });
  4313. delete this.started[name];
  4314. }
  4315. toString() {
  4316. const outBuf = [];
  4317. let longest = 0;
  4318. for (const {
  4319. name
  4320. } of this.times) {
  4321. longest = Math.max(name.length, longest);
  4322. }
  4323. for (const {
  4324. name,
  4325. start,
  4326. end
  4327. } of this.times) {
  4328. outBuf.push(`${name.padEnd(longest)} ${end - start}ms\n`);
  4329. }
  4330. return outBuf.join("");
  4331. }
  4332. }
  4333. exports.StatTimer = StatTimer;
  4334. function isValidFetchUrl(url, baseUrl) {
  4335. try {
  4336. const {
  4337. protocol
  4338. } = baseUrl ? new URL(url, baseUrl) : new URL(url);
  4339. return protocol === "http:" || protocol === "https:";
  4340. } catch (ex) {
  4341. return false;
  4342. }
  4343. }
  4344. function loadScript(src, removeScriptElement = false) {
  4345. return new Promise((resolve, reject) => {
  4346. const script = document.createElement("script");
  4347. script.src = src;
  4348. script.onload = function (evt) {
  4349. if (removeScriptElement) {
  4350. script.remove();
  4351. }
  4352. resolve(evt);
  4353. };
  4354. script.onerror = function () {
  4355. reject(new Error(`Cannot load script at: ${script.src}`));
  4356. };
  4357. (document.head || document.documentElement).append(script);
  4358. });
  4359. }
  4360. function deprecated(details) {
  4361. console.log("Deprecated API usage: " + details);
  4362. }
  4363. let pdfDateStringRegex;
  4364. class PDFDateString {
  4365. static toDateObject(input) {
  4366. if (!input || typeof input !== "string") {
  4367. return null;
  4368. }
  4369. pdfDateStringRegex ||= new RegExp("^D:" + "(\\d{4})" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "([Z|+|-])?" + "(\\d{2})?" + "'?" + "(\\d{2})?" + "'?");
  4370. const matches = pdfDateStringRegex.exec(input);
  4371. if (!matches) {
  4372. return null;
  4373. }
  4374. const year = parseInt(matches[1], 10);
  4375. let month = parseInt(matches[2], 10);
  4376. month = month >= 1 && month <= 12 ? month - 1 : 0;
  4377. let day = parseInt(matches[3], 10);
  4378. day = day >= 1 && day <= 31 ? day : 1;
  4379. let hour = parseInt(matches[4], 10);
  4380. hour = hour >= 0 && hour <= 23 ? hour : 0;
  4381. let minute = parseInt(matches[5], 10);
  4382. minute = minute >= 0 && minute <= 59 ? minute : 0;
  4383. let second = parseInt(matches[6], 10);
  4384. second = second >= 0 && second <= 59 ? second : 0;
  4385. const universalTimeRelation = matches[7] || "Z";
  4386. let offsetHour = parseInt(matches[8], 10);
  4387. offsetHour = offsetHour >= 0 && offsetHour <= 23 ? offsetHour : 0;
  4388. let offsetMinute = parseInt(matches[9], 10) || 0;
  4389. offsetMinute = offsetMinute >= 0 && offsetMinute <= 59 ? offsetMinute : 0;
  4390. if (universalTimeRelation === "-") {
  4391. hour += offsetHour;
  4392. minute += offsetMinute;
  4393. } else if (universalTimeRelation === "+") {
  4394. hour -= offsetHour;
  4395. minute -= offsetMinute;
  4396. }
  4397. return new Date(Date.UTC(year, month, day, hour, minute, second));
  4398. }
  4399. }
  4400. exports.PDFDateString = PDFDateString;
  4401. function getXfaPageViewport(xfaPage, {
  4402. scale = 1,
  4403. rotation = 0
  4404. }) {
  4405. const {
  4406. width,
  4407. height
  4408. } = xfaPage.attributes.style;
  4409. const viewBox = [0, 0, parseInt(width), parseInt(height)];
  4410. return new PageViewport({
  4411. viewBox,
  4412. scale,
  4413. rotation
  4414. });
  4415. }
  4416. function getRGB(color) {
  4417. if (color.startsWith("#")) {
  4418. const colorRGB = parseInt(color.slice(1), 16);
  4419. return [(colorRGB & 0xff0000) >> 16, (colorRGB & 0x00ff00) >> 8, colorRGB & 0x0000ff];
  4420. }
  4421. if (color.startsWith("rgb(")) {
  4422. return color.slice(4, -1).split(",").map(x => parseInt(x));
  4423. }
  4424. if (color.startsWith("rgba(")) {
  4425. return color.slice(5, -1).split(",").map(x => parseInt(x)).slice(0, 3);
  4426. }
  4427. (0, _util.warn)(`Not a valid color format: "${color}"`);
  4428. return [0, 0, 0];
  4429. }
  4430. function getColorValues(colors) {
  4431. const span = document.createElement("span");
  4432. span.style.visibility = "hidden";
  4433. document.body.append(span);
  4434. for (const name of colors.keys()) {
  4435. span.style.color = name;
  4436. const computedColor = window.getComputedStyle(span).color;
  4437. colors.set(name, getRGB(computedColor));
  4438. }
  4439. span.remove();
  4440. }
  4441. function getCurrentTransform(ctx) {
  4442. const {
  4443. a,
  4444. b,
  4445. c,
  4446. d,
  4447. e,
  4448. f
  4449. } = ctx.getTransform();
  4450. return [a, b, c, d, e, f];
  4451. }
  4452. function getCurrentTransformInverse(ctx) {
  4453. const {
  4454. a,
  4455. b,
  4456. c,
  4457. d,
  4458. e,
  4459. f
  4460. } = ctx.getTransform().invertSelf();
  4461. return [a, b, c, d, e, f];
  4462. }
  4463. function setLayerDimensions(div, viewport, mustFlip = false, mustRotate = true) {
  4464. if (viewport instanceof PageViewport) {
  4465. const {
  4466. pageWidth,
  4467. pageHeight
  4468. } = viewport.rawDims;
  4469. const {
  4470. style
  4471. } = div;
  4472. const widthStr = `calc(var(--scale-factor) * ${pageWidth}px)`;
  4473. const heightStr = `calc(var(--scale-factor) * ${pageHeight}px)`;
  4474. if (!mustFlip || viewport.rotation % 180 === 0) {
  4475. style.width = widthStr;
  4476. style.height = heightStr;
  4477. } else {
  4478. style.width = heightStr;
  4479. style.height = widthStr;
  4480. }
  4481. }
  4482. if (mustRotate) {
  4483. div.setAttribute("data-main-rotation", viewport.rotation);
  4484. }
  4485. }
  4486. /***/ }),
  4487. /* 7 */
  4488. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  4489. Object.defineProperty(exports, "__esModule", ({
  4490. value: true
  4491. }));
  4492. exports.BaseStandardFontDataFactory = exports.BaseSVGFactory = exports.BaseFilterFactory = exports.BaseCanvasFactory = exports.BaseCMapReaderFactory = void 0;
  4493. var _util = __w_pdfjs_require__(1);
  4494. class BaseFilterFactory {
  4495. constructor() {
  4496. if (this.constructor === BaseFilterFactory) {
  4497. (0, _util.unreachable)("Cannot initialize BaseFilterFactory.");
  4498. }
  4499. }
  4500. addFilter(maps) {
  4501. return "none";
  4502. }
  4503. addHCMFilter(fgColor, bgColor) {
  4504. return "none";
  4505. }
  4506. destroy(keepHCM = false) {}
  4507. }
  4508. exports.BaseFilterFactory = BaseFilterFactory;
  4509. class BaseCanvasFactory {
  4510. constructor() {
  4511. if (this.constructor === BaseCanvasFactory) {
  4512. (0, _util.unreachable)("Cannot initialize BaseCanvasFactory.");
  4513. }
  4514. }
  4515. create(width, height) {
  4516. if (width <= 0 || height <= 0) {
  4517. throw new Error("Invalid canvas size");
  4518. }
  4519. const canvas = this._createCanvas(width, height);
  4520. return {
  4521. canvas,
  4522. context: canvas.getContext("2d")
  4523. };
  4524. }
  4525. reset(canvasAndContext, width, height) {
  4526. if (!canvasAndContext.canvas) {
  4527. throw new Error("Canvas is not specified");
  4528. }
  4529. if (width <= 0 || height <= 0) {
  4530. throw new Error("Invalid canvas size");
  4531. }
  4532. canvasAndContext.canvas.width = width;
  4533. canvasAndContext.canvas.height = height;
  4534. }
  4535. destroy(canvasAndContext) {
  4536. if (!canvasAndContext.canvas) {
  4537. throw new Error("Canvas is not specified");
  4538. }
  4539. canvasAndContext.canvas.width = 0;
  4540. canvasAndContext.canvas.height = 0;
  4541. canvasAndContext.canvas = null;
  4542. canvasAndContext.context = null;
  4543. }
  4544. _createCanvas(width, height) {
  4545. (0, _util.unreachable)("Abstract method `_createCanvas` called.");
  4546. }
  4547. }
  4548. exports.BaseCanvasFactory = BaseCanvasFactory;
  4549. class BaseCMapReaderFactory {
  4550. constructor({
  4551. baseUrl = null,
  4552. isCompressed = true
  4553. }) {
  4554. if (this.constructor === BaseCMapReaderFactory) {
  4555. (0, _util.unreachable)("Cannot initialize BaseCMapReaderFactory.");
  4556. }
  4557. this.baseUrl = baseUrl;
  4558. this.isCompressed = isCompressed;
  4559. }
  4560. async fetch({
  4561. name
  4562. }) {
  4563. if (!this.baseUrl) {
  4564. throw new Error('The CMap "baseUrl" parameter must be specified, ensure that ' + 'the "cMapUrl" and "cMapPacked" API parameters are provided.');
  4565. }
  4566. if (!name) {
  4567. throw new Error("CMap name must be specified.");
  4568. }
  4569. const url = this.baseUrl + name + (this.isCompressed ? ".bcmap" : "");
  4570. const compressionType = this.isCompressed ? _util.CMapCompressionType.BINARY : _util.CMapCompressionType.NONE;
  4571. return this._fetchData(url, compressionType).catch(reason => {
  4572. throw new Error(`Unable to load ${this.isCompressed ? "binary " : ""}CMap at: ${url}`);
  4573. });
  4574. }
  4575. _fetchData(url, compressionType) {
  4576. (0, _util.unreachable)("Abstract method `_fetchData` called.");
  4577. }
  4578. }
  4579. exports.BaseCMapReaderFactory = BaseCMapReaderFactory;
  4580. class BaseStandardFontDataFactory {
  4581. constructor({
  4582. baseUrl = null
  4583. }) {
  4584. if (this.constructor === BaseStandardFontDataFactory) {
  4585. (0, _util.unreachable)("Cannot initialize BaseStandardFontDataFactory.");
  4586. }
  4587. this.baseUrl = baseUrl;
  4588. }
  4589. async fetch({
  4590. filename
  4591. }) {
  4592. if (!this.baseUrl) {
  4593. throw new Error('The standard font "baseUrl" parameter must be specified, ensure that ' + 'the "standardFontDataUrl" API parameter is provided.');
  4594. }
  4595. if (!filename) {
  4596. throw new Error("Font filename must be specified.");
  4597. }
  4598. const url = `${this.baseUrl}${filename}`;
  4599. return this._fetchData(url).catch(reason => {
  4600. throw new Error(`Unable to load font data at: ${url}`);
  4601. });
  4602. }
  4603. _fetchData(url) {
  4604. (0, _util.unreachable)("Abstract method `_fetchData` called.");
  4605. }
  4606. }
  4607. exports.BaseStandardFontDataFactory = BaseStandardFontDataFactory;
  4608. class BaseSVGFactory {
  4609. constructor() {
  4610. if (this.constructor === BaseSVGFactory) {
  4611. (0, _util.unreachable)("Cannot initialize BaseSVGFactory.");
  4612. }
  4613. }
  4614. create(width, height, skipDimensions = false) {
  4615. if (width <= 0 || height <= 0) {
  4616. throw new Error("Invalid SVG dimensions");
  4617. }
  4618. const svg = this._createSVG("svg:svg");
  4619. svg.setAttribute("version", "1.1");
  4620. if (!skipDimensions) {
  4621. svg.setAttribute("width", `${width}px`);
  4622. svg.setAttribute("height", `${height}px`);
  4623. }
  4624. svg.setAttribute("preserveAspectRatio", "none");
  4625. svg.setAttribute("viewBox", `0 0 ${width} ${height}`);
  4626. return svg;
  4627. }
  4628. createElement(type) {
  4629. if (typeof type !== "string") {
  4630. throw new Error("Invalid SVG element type");
  4631. }
  4632. return this._createSVG(type);
  4633. }
  4634. _createSVG(type) {
  4635. (0, _util.unreachable)("Abstract method `_createSVG` called.");
  4636. }
  4637. }
  4638. exports.BaseSVGFactory = BaseSVGFactory;
  4639. /***/ }),
  4640. /* 8 */
  4641. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  4642. Object.defineProperty(exports, "__esModule", ({
  4643. value: true
  4644. }));
  4645. exports.MurmurHash3_64 = void 0;
  4646. var _util = __w_pdfjs_require__(1);
  4647. const SEED = 0xc3d2e1f0;
  4648. const MASK_HIGH = 0xffff0000;
  4649. const MASK_LOW = 0xffff;
  4650. class MurmurHash3_64 {
  4651. constructor(seed) {
  4652. this.h1 = seed ? seed & 0xffffffff : SEED;
  4653. this.h2 = seed ? seed & 0xffffffff : SEED;
  4654. }
  4655. update(input) {
  4656. let data, length;
  4657. if (typeof input === "string") {
  4658. data = new Uint8Array(input.length * 2);
  4659. length = 0;
  4660. for (let i = 0, ii = input.length; i < ii; i++) {
  4661. const code = input.charCodeAt(i);
  4662. if (code <= 0xff) {
  4663. data[length++] = code;
  4664. } else {
  4665. data[length++] = code >>> 8;
  4666. data[length++] = code & 0xff;
  4667. }
  4668. }
  4669. } else if ((0, _util.isArrayBuffer)(input)) {
  4670. data = input.slice();
  4671. length = data.byteLength;
  4672. } else {
  4673. throw new Error("Wrong data format in MurmurHash3_64_update. " + "Input must be a string or array.");
  4674. }
  4675. const blockCounts = length >> 2;
  4676. const tailLength = length - blockCounts * 4;
  4677. const dataUint32 = new Uint32Array(data.buffer, 0, blockCounts);
  4678. let k1 = 0,
  4679. k2 = 0;
  4680. let h1 = this.h1,
  4681. h2 = this.h2;
  4682. const C1 = 0xcc9e2d51,
  4683. C2 = 0x1b873593;
  4684. const C1_LOW = C1 & MASK_LOW,
  4685. C2_LOW = C2 & MASK_LOW;
  4686. for (let i = 0; i < blockCounts; i++) {
  4687. if (i & 1) {
  4688. k1 = dataUint32[i];
  4689. k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
  4690. k1 = k1 << 15 | k1 >>> 17;
  4691. k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
  4692. h1 ^= k1;
  4693. h1 = h1 << 13 | h1 >>> 19;
  4694. h1 = h1 * 5 + 0xe6546b64;
  4695. } else {
  4696. k2 = dataUint32[i];
  4697. k2 = k2 * C1 & MASK_HIGH | k2 * C1_LOW & MASK_LOW;
  4698. k2 = k2 << 15 | k2 >>> 17;
  4699. k2 = k2 * C2 & MASK_HIGH | k2 * C2_LOW & MASK_LOW;
  4700. h2 ^= k2;
  4701. h2 = h2 << 13 | h2 >>> 19;
  4702. h2 = h2 * 5 + 0xe6546b64;
  4703. }
  4704. }
  4705. k1 = 0;
  4706. switch (tailLength) {
  4707. case 3:
  4708. k1 ^= data[blockCounts * 4 + 2] << 16;
  4709. case 2:
  4710. k1 ^= data[blockCounts * 4 + 1] << 8;
  4711. case 1:
  4712. k1 ^= data[blockCounts * 4];
  4713. k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
  4714. k1 = k1 << 15 | k1 >>> 17;
  4715. k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
  4716. if (blockCounts & 1) {
  4717. h1 ^= k1;
  4718. } else {
  4719. h2 ^= k1;
  4720. }
  4721. }
  4722. this.h1 = h1;
  4723. this.h2 = h2;
  4724. }
  4725. hexdigest() {
  4726. let h1 = this.h1,
  4727. h2 = this.h2;
  4728. h1 ^= h2 >>> 1;
  4729. h1 = h1 * 0xed558ccd & MASK_HIGH | h1 * 0x8ccd & MASK_LOW;
  4730. h2 = h2 * 0xff51afd7 & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16;
  4731. h1 ^= h2 >>> 1;
  4732. h1 = h1 * 0x1a85ec53 & MASK_HIGH | h1 * 0xec53 & MASK_LOW;
  4733. h2 = h2 * 0xc4ceb9fe & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16;
  4734. h1 ^= h2 >>> 1;
  4735. return (h1 >>> 0).toString(16).padStart(8, "0") + (h2 >>> 0).toString(16).padStart(8, "0");
  4736. }
  4737. }
  4738. exports.MurmurHash3_64 = MurmurHash3_64;
  4739. /***/ }),
  4740. /* 9 */
  4741. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  4742. Object.defineProperty(exports, "__esModule", ({
  4743. value: true
  4744. }));
  4745. exports.FontLoader = exports.FontFaceObject = void 0;
  4746. var _util = __w_pdfjs_require__(1);
  4747. var _is_node = __w_pdfjs_require__(10);
  4748. class FontLoader {
  4749. #systemFonts = new Set();
  4750. constructor({
  4751. ownerDocument = globalThis.document,
  4752. styleElement = null
  4753. }) {
  4754. this._document = ownerDocument;
  4755. this.nativeFontFaces = new Set();
  4756. this.styleElement = null;
  4757. this.loadingRequests = [];
  4758. this.loadTestFontId = 0;
  4759. }
  4760. addNativeFontFace(nativeFontFace) {
  4761. this.nativeFontFaces.add(nativeFontFace);
  4762. this._document.fonts.add(nativeFontFace);
  4763. }
  4764. removeNativeFontFace(nativeFontFace) {
  4765. this.nativeFontFaces.delete(nativeFontFace);
  4766. this._document.fonts.delete(nativeFontFace);
  4767. }
  4768. insertRule(rule) {
  4769. if (!this.styleElement) {
  4770. this.styleElement = this._document.createElement("style");
  4771. this._document.documentElement.getElementsByTagName("head")[0].append(this.styleElement);
  4772. }
  4773. const styleSheet = this.styleElement.sheet;
  4774. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  4775. }
  4776. clear() {
  4777. for (const nativeFontFace of this.nativeFontFaces) {
  4778. this._document.fonts.delete(nativeFontFace);
  4779. }
  4780. this.nativeFontFaces.clear();
  4781. this.#systemFonts.clear();
  4782. if (this.styleElement) {
  4783. this.styleElement.remove();
  4784. this.styleElement = null;
  4785. }
  4786. }
  4787. async loadSystemFont(info) {
  4788. if (!info || this.#systemFonts.has(info.loadedName)) {
  4789. return;
  4790. }
  4791. (0, _util.assert)(!this.disableFontFace, "loadSystemFont shouldn't be called when `disableFontFace` is set.");
  4792. if (this.isFontLoadingAPISupported) {
  4793. const {
  4794. loadedName,
  4795. src,
  4796. style
  4797. } = info;
  4798. const fontFace = new FontFace(loadedName, src, style);
  4799. this.addNativeFontFace(fontFace);
  4800. try {
  4801. await fontFace.load();
  4802. this.#systemFonts.add(loadedName);
  4803. } catch {
  4804. (0, _util.warn)(`Cannot load system font: ${info.baseFontName}, installing it could help to improve PDF rendering.`);
  4805. this.removeNativeFontFace(fontFace);
  4806. }
  4807. return;
  4808. }
  4809. (0, _util.unreachable)("Not implemented: loadSystemFont without the Font Loading API.");
  4810. }
  4811. async bind(font) {
  4812. if (font.attached || font.missingFile && !font.systemFontInfo) {
  4813. return;
  4814. }
  4815. font.attached = true;
  4816. if (font.systemFontInfo) {
  4817. await this.loadSystemFont(font.systemFontInfo);
  4818. return;
  4819. }
  4820. if (this.isFontLoadingAPISupported) {
  4821. const nativeFontFace = font.createNativeFontFace();
  4822. if (nativeFontFace) {
  4823. this.addNativeFontFace(nativeFontFace);
  4824. try {
  4825. await nativeFontFace.loaded;
  4826. } catch (ex) {
  4827. (0, _util.warn)(`Failed to load font '${nativeFontFace.family}': '${ex}'.`);
  4828. font.disableFontFace = true;
  4829. throw ex;
  4830. }
  4831. }
  4832. return;
  4833. }
  4834. const rule = font.createFontFaceRule();
  4835. if (rule) {
  4836. this.insertRule(rule);
  4837. if (this.isSyncFontLoadingSupported) {
  4838. return;
  4839. }
  4840. await new Promise(resolve => {
  4841. const request = this._queueLoadingCallback(resolve);
  4842. this._prepareFontLoadEvent(font, request);
  4843. });
  4844. }
  4845. }
  4846. get isFontLoadingAPISupported() {
  4847. const hasFonts = !!this._document?.fonts;
  4848. return (0, _util.shadow)(this, "isFontLoadingAPISupported", hasFonts);
  4849. }
  4850. get isSyncFontLoadingSupported() {
  4851. let supported = false;
  4852. if (_is_node.isNodeJS) {
  4853. supported = true;
  4854. } else if (typeof navigator !== "undefined" && /Mozilla\/5.0.*?rv:\d+.*? Gecko/.test(navigator.userAgent)) {
  4855. supported = true;
  4856. }
  4857. return (0, _util.shadow)(this, "isSyncFontLoadingSupported", supported);
  4858. }
  4859. _queueLoadingCallback(callback) {
  4860. function completeRequest() {
  4861. (0, _util.assert)(!request.done, "completeRequest() cannot be called twice.");
  4862. request.done = true;
  4863. while (loadingRequests.length > 0 && loadingRequests[0].done) {
  4864. const otherRequest = loadingRequests.shift();
  4865. setTimeout(otherRequest.callback, 0);
  4866. }
  4867. }
  4868. const {
  4869. loadingRequests
  4870. } = this;
  4871. const request = {
  4872. done: false,
  4873. complete: completeRequest,
  4874. callback
  4875. };
  4876. loadingRequests.push(request);
  4877. return request;
  4878. }
  4879. get _loadTestFont() {
  4880. const testFont = atob("T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQA" + "FQAABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAA" + "ALwAAAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgA" + "AAAGbmFtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1" + "AAsD6AAAAADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD" + "6AAAAAAD6AABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACM" + "AooCvAAAAeAAMQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4D" + "IP84AFoDIQAAAAAAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAA" + "AAEAAQAAAAEAAAAAAAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUA" + "AQAAAAEAAAAAAAYAAQAAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgAB" + "AAMAAQQJAAMAAgABAAMAAQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABY" + "AAAAAAAAAwAAAAMAAAAcAAEAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAA" + "AC7////TAAEAAAAAAAABBgAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAA" + "AAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgcA/gXBIwMAYuL+nz5tQXkD5j3CBLnEQAC" + "AQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYAAABAQAADwACAQEEE/t3" + "Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQAAAAAAAABAAAAAMmJbzEAAAAAzgTj" + "FQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAgABAAAAAAAAAAAD6AAAAAAAAA==");
  4881. return (0, _util.shadow)(this, "_loadTestFont", testFont);
  4882. }
  4883. _prepareFontLoadEvent(font, request) {
  4884. function int32(data, offset) {
  4885. return data.charCodeAt(offset) << 24 | data.charCodeAt(offset + 1) << 16 | data.charCodeAt(offset + 2) << 8 | data.charCodeAt(offset + 3) & 0xff;
  4886. }
  4887. function spliceString(s, offset, remove, insert) {
  4888. const chunk1 = s.substring(0, offset);
  4889. const chunk2 = s.substring(offset + remove);
  4890. return chunk1 + insert + chunk2;
  4891. }
  4892. let i, ii;
  4893. const canvas = this._document.createElement("canvas");
  4894. canvas.width = 1;
  4895. canvas.height = 1;
  4896. const ctx = canvas.getContext("2d");
  4897. let called = 0;
  4898. function isFontReady(name, callback) {
  4899. if (++called > 30) {
  4900. (0, _util.warn)("Load test font never loaded.");
  4901. callback();
  4902. return;
  4903. }
  4904. ctx.font = "30px " + name;
  4905. ctx.fillText(".", 0, 20);
  4906. const imageData = ctx.getImageData(0, 0, 1, 1);
  4907. if (imageData.data[3] > 0) {
  4908. callback();
  4909. return;
  4910. }
  4911. setTimeout(isFontReady.bind(null, name, callback));
  4912. }
  4913. const loadTestFontId = `lt${Date.now()}${this.loadTestFontId++}`;
  4914. let data = this._loadTestFont;
  4915. const COMMENT_OFFSET = 976;
  4916. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length, loadTestFontId);
  4917. const CFF_CHECKSUM_OFFSET = 16;
  4918. const XXXX_VALUE = 0x58585858;
  4919. let checksum = int32(data, CFF_CHECKSUM_OFFSET);
  4920. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  4921. checksum = checksum - XXXX_VALUE + int32(loadTestFontId, i) | 0;
  4922. }
  4923. if (i < loadTestFontId.length) {
  4924. checksum = checksum - XXXX_VALUE + int32(loadTestFontId + "XXX", i) | 0;
  4925. }
  4926. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, (0, _util.string32)(checksum));
  4927. const url = `url(data:font/opentype;base64,${btoa(data)});`;
  4928. const rule = `@font-face {font-family:"${loadTestFontId}";src:${url}}`;
  4929. this.insertRule(rule);
  4930. const div = this._document.createElement("div");
  4931. div.style.visibility = "hidden";
  4932. div.style.width = div.style.height = "10px";
  4933. div.style.position = "absolute";
  4934. div.style.top = div.style.left = "0px";
  4935. for (const name of [font.loadedName, loadTestFontId]) {
  4936. const span = this._document.createElement("span");
  4937. span.textContent = "Hi";
  4938. span.style.fontFamily = name;
  4939. div.append(span);
  4940. }
  4941. this._document.body.append(div);
  4942. isFontReady(loadTestFontId, () => {
  4943. div.remove();
  4944. request.complete();
  4945. });
  4946. }
  4947. }
  4948. exports.FontLoader = FontLoader;
  4949. class FontFaceObject {
  4950. constructor(translatedData, {
  4951. isEvalSupported = true,
  4952. disableFontFace = false,
  4953. ignoreErrors = false,
  4954. inspectFont = null
  4955. }) {
  4956. this.compiledGlyphs = Object.create(null);
  4957. for (const i in translatedData) {
  4958. this[i] = translatedData[i];
  4959. }
  4960. this.isEvalSupported = isEvalSupported !== false;
  4961. this.disableFontFace = disableFontFace === true;
  4962. this.ignoreErrors = ignoreErrors === true;
  4963. this._inspectFont = inspectFont;
  4964. }
  4965. createNativeFontFace() {
  4966. if (!this.data || this.disableFontFace) {
  4967. return null;
  4968. }
  4969. let nativeFontFace;
  4970. if (!this.cssFontInfo) {
  4971. nativeFontFace = new FontFace(this.loadedName, this.data, {});
  4972. } else {
  4973. const css = {
  4974. weight: this.cssFontInfo.fontWeight
  4975. };
  4976. if (this.cssFontInfo.italicAngle) {
  4977. css.style = `oblique ${this.cssFontInfo.italicAngle}deg`;
  4978. }
  4979. nativeFontFace = new FontFace(this.cssFontInfo.fontFamily, this.data, css);
  4980. }
  4981. this._inspectFont?.(this);
  4982. return nativeFontFace;
  4983. }
  4984. createFontFaceRule() {
  4985. if (!this.data || this.disableFontFace) {
  4986. return null;
  4987. }
  4988. const data = (0, _util.bytesToString)(this.data);
  4989. const url = `url(data:${this.mimetype};base64,${btoa(data)});`;
  4990. let rule;
  4991. if (!this.cssFontInfo) {
  4992. rule = `@font-face {font-family:"${this.loadedName}";src:${url}}`;
  4993. } else {
  4994. let css = `font-weight: ${this.cssFontInfo.fontWeight};`;
  4995. if (this.cssFontInfo.italicAngle) {
  4996. css += `font-style: oblique ${this.cssFontInfo.italicAngle}deg;`;
  4997. }
  4998. rule = `@font-face {font-family:"${this.cssFontInfo.fontFamily}";${css}src:${url}}`;
  4999. }
  5000. this._inspectFont?.(this, url);
  5001. return rule;
  5002. }
  5003. getPathGenerator(objs, character) {
  5004. if (this.compiledGlyphs[character] !== undefined) {
  5005. return this.compiledGlyphs[character];
  5006. }
  5007. let cmds;
  5008. try {
  5009. cmds = objs.get(this.loadedName + "_path_" + character);
  5010. } catch (ex) {
  5011. if (!this.ignoreErrors) {
  5012. throw ex;
  5013. }
  5014. (0, _util.warn)(`getPathGenerator - ignoring character: "${ex}".`);
  5015. return this.compiledGlyphs[character] = function (c, size) {};
  5016. }
  5017. if (this.isEvalSupported && _util.FeatureTest.isEvalSupported) {
  5018. const jsBuf = [];
  5019. for (const current of cmds) {
  5020. const args = current.args !== undefined ? current.args.join(",") : "";
  5021. jsBuf.push("c.", current.cmd, "(", args, ");\n");
  5022. }
  5023. return this.compiledGlyphs[character] = new Function("c", "size", jsBuf.join(""));
  5024. }
  5025. return this.compiledGlyphs[character] = function (c, size) {
  5026. for (const current of cmds) {
  5027. if (current.cmd === "scale") {
  5028. current.args = [size, -size];
  5029. }
  5030. c[current.cmd].apply(c, current.args);
  5031. }
  5032. };
  5033. }
  5034. }
  5035. exports.FontFaceObject = FontFaceObject;
  5036. /***/ }),
  5037. /* 10 */
  5038. /***/ ((__unused_webpack_module, exports) => {
  5039. Object.defineProperty(exports, "__esModule", ({
  5040. value: true
  5041. }));
  5042. exports.isNodeJS = void 0;
  5043. const isNodeJS = typeof process === "object" && process + "" === "[object process]" && !process.versions.nw && !(process.versions.electron && process.type && process.type !== "browser");
  5044. exports.isNodeJS = isNodeJS;
  5045. /***/ }),
  5046. /* 11 */
  5047. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  5048. Object.defineProperty(exports, "__esModule", ({
  5049. value: true
  5050. }));
  5051. exports.CanvasGraphics = void 0;
  5052. var _util = __w_pdfjs_require__(1);
  5053. var _display_utils = __w_pdfjs_require__(6);
  5054. var _pattern_helper = __w_pdfjs_require__(12);
  5055. var _image_utils = __w_pdfjs_require__(13);
  5056. var _is_node = __w_pdfjs_require__(10);
  5057. const MIN_FONT_SIZE = 16;
  5058. const MAX_FONT_SIZE = 100;
  5059. const MAX_GROUP_SIZE = 4096;
  5060. const EXECUTION_TIME = 15;
  5061. const EXECUTION_STEPS = 10;
  5062. const MAX_SIZE_TO_COMPILE = 1000;
  5063. const FULL_CHUNK_HEIGHT = 16;
  5064. function mirrorContextOperations(ctx, destCtx) {
  5065. if (ctx._removeMirroring) {
  5066. throw new Error("Context is already forwarding operations.");
  5067. }
  5068. ctx.__originalSave = ctx.save;
  5069. ctx.__originalRestore = ctx.restore;
  5070. ctx.__originalRotate = ctx.rotate;
  5071. ctx.__originalScale = ctx.scale;
  5072. ctx.__originalTranslate = ctx.translate;
  5073. ctx.__originalTransform = ctx.transform;
  5074. ctx.__originalSetTransform = ctx.setTransform;
  5075. ctx.__originalResetTransform = ctx.resetTransform;
  5076. ctx.__originalClip = ctx.clip;
  5077. ctx.__originalMoveTo = ctx.moveTo;
  5078. ctx.__originalLineTo = ctx.lineTo;
  5079. ctx.__originalBezierCurveTo = ctx.bezierCurveTo;
  5080. ctx.__originalRect = ctx.rect;
  5081. ctx.__originalClosePath = ctx.closePath;
  5082. ctx.__originalBeginPath = ctx.beginPath;
  5083. ctx._removeMirroring = () => {
  5084. ctx.save = ctx.__originalSave;
  5085. ctx.restore = ctx.__originalRestore;
  5086. ctx.rotate = ctx.__originalRotate;
  5087. ctx.scale = ctx.__originalScale;
  5088. ctx.translate = ctx.__originalTranslate;
  5089. ctx.transform = ctx.__originalTransform;
  5090. ctx.setTransform = ctx.__originalSetTransform;
  5091. ctx.resetTransform = ctx.__originalResetTransform;
  5092. ctx.clip = ctx.__originalClip;
  5093. ctx.moveTo = ctx.__originalMoveTo;
  5094. ctx.lineTo = ctx.__originalLineTo;
  5095. ctx.bezierCurveTo = ctx.__originalBezierCurveTo;
  5096. ctx.rect = ctx.__originalRect;
  5097. ctx.closePath = ctx.__originalClosePath;
  5098. ctx.beginPath = ctx.__originalBeginPath;
  5099. delete ctx._removeMirroring;
  5100. };
  5101. ctx.save = function ctxSave() {
  5102. destCtx.save();
  5103. this.__originalSave();
  5104. };
  5105. ctx.restore = function ctxRestore() {
  5106. destCtx.restore();
  5107. this.__originalRestore();
  5108. };
  5109. ctx.translate = function ctxTranslate(x, y) {
  5110. destCtx.translate(x, y);
  5111. this.__originalTranslate(x, y);
  5112. };
  5113. ctx.scale = function ctxScale(x, y) {
  5114. destCtx.scale(x, y);
  5115. this.__originalScale(x, y);
  5116. };
  5117. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  5118. destCtx.transform(a, b, c, d, e, f);
  5119. this.__originalTransform(a, b, c, d, e, f);
  5120. };
  5121. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  5122. destCtx.setTransform(a, b, c, d, e, f);
  5123. this.__originalSetTransform(a, b, c, d, e, f);
  5124. };
  5125. ctx.resetTransform = function ctxResetTransform() {
  5126. destCtx.resetTransform();
  5127. this.__originalResetTransform();
  5128. };
  5129. ctx.rotate = function ctxRotate(angle) {
  5130. destCtx.rotate(angle);
  5131. this.__originalRotate(angle);
  5132. };
  5133. ctx.clip = function ctxRotate(rule) {
  5134. destCtx.clip(rule);
  5135. this.__originalClip(rule);
  5136. };
  5137. ctx.moveTo = function (x, y) {
  5138. destCtx.moveTo(x, y);
  5139. this.__originalMoveTo(x, y);
  5140. };
  5141. ctx.lineTo = function (x, y) {
  5142. destCtx.lineTo(x, y);
  5143. this.__originalLineTo(x, y);
  5144. };
  5145. ctx.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
  5146. destCtx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
  5147. this.__originalBezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
  5148. };
  5149. ctx.rect = function (x, y, width, height) {
  5150. destCtx.rect(x, y, width, height);
  5151. this.__originalRect(x, y, width, height);
  5152. };
  5153. ctx.closePath = function () {
  5154. destCtx.closePath();
  5155. this.__originalClosePath();
  5156. };
  5157. ctx.beginPath = function () {
  5158. destCtx.beginPath();
  5159. this.__originalBeginPath();
  5160. };
  5161. }
  5162. class CachedCanvases {
  5163. constructor(canvasFactory) {
  5164. this.canvasFactory = canvasFactory;
  5165. this.cache = Object.create(null);
  5166. }
  5167. getCanvas(id, width, height) {
  5168. let canvasEntry;
  5169. if (this.cache[id] !== undefined) {
  5170. canvasEntry = this.cache[id];
  5171. this.canvasFactory.reset(canvasEntry, width, height);
  5172. } else {
  5173. canvasEntry = this.canvasFactory.create(width, height);
  5174. this.cache[id] = canvasEntry;
  5175. }
  5176. return canvasEntry;
  5177. }
  5178. delete(id) {
  5179. delete this.cache[id];
  5180. }
  5181. clear() {
  5182. for (const id in this.cache) {
  5183. const canvasEntry = this.cache[id];
  5184. this.canvasFactory.destroy(canvasEntry);
  5185. delete this.cache[id];
  5186. }
  5187. }
  5188. }
  5189. function drawImageAtIntegerCoords(ctx, srcImg, srcX, srcY, srcW, srcH, destX, destY, destW, destH) {
  5190. const [a, b, c, d, tx, ty] = (0, _display_utils.getCurrentTransform)(ctx);
  5191. if (b === 0 && c === 0) {
  5192. const tlX = destX * a + tx;
  5193. const rTlX = Math.round(tlX);
  5194. const tlY = destY * d + ty;
  5195. const rTlY = Math.round(tlY);
  5196. const brX = (destX + destW) * a + tx;
  5197. const rWidth = Math.abs(Math.round(brX) - rTlX) || 1;
  5198. const brY = (destY + destH) * d + ty;
  5199. const rHeight = Math.abs(Math.round(brY) - rTlY) || 1;
  5200. ctx.setTransform(Math.sign(a), 0, 0, Math.sign(d), rTlX, rTlY);
  5201. ctx.drawImage(srcImg, srcX, srcY, srcW, srcH, 0, 0, rWidth, rHeight);
  5202. ctx.setTransform(a, b, c, d, tx, ty);
  5203. return [rWidth, rHeight];
  5204. }
  5205. if (a === 0 && d === 0) {
  5206. const tlX = destY * c + tx;
  5207. const rTlX = Math.round(tlX);
  5208. const tlY = destX * b + ty;
  5209. const rTlY = Math.round(tlY);
  5210. const brX = (destY + destH) * c + tx;
  5211. const rWidth = Math.abs(Math.round(brX) - rTlX) || 1;
  5212. const brY = (destX + destW) * b + ty;
  5213. const rHeight = Math.abs(Math.round(brY) - rTlY) || 1;
  5214. ctx.setTransform(0, Math.sign(b), Math.sign(c), 0, rTlX, rTlY);
  5215. ctx.drawImage(srcImg, srcX, srcY, srcW, srcH, 0, 0, rHeight, rWidth);
  5216. ctx.setTransform(a, b, c, d, tx, ty);
  5217. return [rHeight, rWidth];
  5218. }
  5219. ctx.drawImage(srcImg, srcX, srcY, srcW, srcH, destX, destY, destW, destH);
  5220. const scaleX = Math.hypot(a, b);
  5221. const scaleY = Math.hypot(c, d);
  5222. return [scaleX * destW, scaleY * destH];
  5223. }
  5224. function compileType3Glyph(imgData) {
  5225. const {
  5226. width,
  5227. height
  5228. } = imgData;
  5229. if (width > MAX_SIZE_TO_COMPILE || height > MAX_SIZE_TO_COMPILE) {
  5230. return null;
  5231. }
  5232. const POINT_TO_PROCESS_LIMIT = 1000;
  5233. const POINT_TYPES = new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  5234. const width1 = width + 1;
  5235. let points = new Uint8Array(width1 * (height + 1));
  5236. let i, j, j0;
  5237. const lineSize = width + 7 & ~7;
  5238. let data = new Uint8Array(lineSize * height),
  5239. pos = 0;
  5240. for (const elem of imgData.data) {
  5241. let mask = 128;
  5242. while (mask > 0) {
  5243. data[pos++] = elem & mask ? 0 : 255;
  5244. mask >>= 1;
  5245. }
  5246. }
  5247. let count = 0;
  5248. pos = 0;
  5249. if (data[pos] !== 0) {
  5250. points[0] = 1;
  5251. ++count;
  5252. }
  5253. for (j = 1; j < width; j++) {
  5254. if (data[pos] !== data[pos + 1]) {
  5255. points[j] = data[pos] ? 2 : 1;
  5256. ++count;
  5257. }
  5258. pos++;
  5259. }
  5260. if (data[pos] !== 0) {
  5261. points[j] = 2;
  5262. ++count;
  5263. }
  5264. for (i = 1; i < height; i++) {
  5265. pos = i * lineSize;
  5266. j0 = i * width1;
  5267. if (data[pos - lineSize] !== data[pos]) {
  5268. points[j0] = data[pos] ? 1 : 8;
  5269. ++count;
  5270. }
  5271. let sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  5272. for (j = 1; j < width; j++) {
  5273. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) + (data[pos - lineSize + 1] ? 8 : 0);
  5274. if (POINT_TYPES[sum]) {
  5275. points[j0 + j] = POINT_TYPES[sum];
  5276. ++count;
  5277. }
  5278. pos++;
  5279. }
  5280. if (data[pos - lineSize] !== data[pos]) {
  5281. points[j0 + j] = data[pos] ? 2 : 4;
  5282. ++count;
  5283. }
  5284. if (count > POINT_TO_PROCESS_LIMIT) {
  5285. return null;
  5286. }
  5287. }
  5288. pos = lineSize * (height - 1);
  5289. j0 = i * width1;
  5290. if (data[pos] !== 0) {
  5291. points[j0] = 8;
  5292. ++count;
  5293. }
  5294. for (j = 1; j < width; j++) {
  5295. if (data[pos] !== data[pos + 1]) {
  5296. points[j0 + j] = data[pos] ? 4 : 8;
  5297. ++count;
  5298. }
  5299. pos++;
  5300. }
  5301. if (data[pos] !== 0) {
  5302. points[j0 + j] = 4;
  5303. ++count;
  5304. }
  5305. if (count > POINT_TO_PROCESS_LIMIT) {
  5306. return null;
  5307. }
  5308. const steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  5309. const path = new Path2D();
  5310. for (i = 0; count && i <= height; i++) {
  5311. let p = i * width1;
  5312. const end = p + width;
  5313. while (p < end && !points[p]) {
  5314. p++;
  5315. }
  5316. if (p === end) {
  5317. continue;
  5318. }
  5319. path.moveTo(p % width1, i);
  5320. const p0 = p;
  5321. let type = points[p];
  5322. do {
  5323. const step = steps[type];
  5324. do {
  5325. p += step;
  5326. } while (!points[p]);
  5327. const pp = points[p];
  5328. if (pp !== 5 && pp !== 10) {
  5329. type = pp;
  5330. points[p] = 0;
  5331. } else {
  5332. type = pp & 0x33 * type >> 4;
  5333. points[p] &= type >> 2 | type << 2;
  5334. }
  5335. path.lineTo(p % width1, p / width1 | 0);
  5336. if (!points[p]) {
  5337. --count;
  5338. }
  5339. } while (p0 !== p);
  5340. --i;
  5341. }
  5342. data = null;
  5343. points = null;
  5344. const drawOutline = function (c) {
  5345. c.save();
  5346. c.scale(1 / width, -1 / height);
  5347. c.translate(0, -height);
  5348. c.fill(path);
  5349. c.beginPath();
  5350. c.restore();
  5351. };
  5352. return drawOutline;
  5353. }
  5354. class CanvasExtraState {
  5355. constructor(width, height) {
  5356. this.alphaIsShape = false;
  5357. this.fontSize = 0;
  5358. this.fontSizeScale = 1;
  5359. this.textMatrix = _util.IDENTITY_MATRIX;
  5360. this.textMatrixScale = 1;
  5361. this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
  5362. this.leading = 0;
  5363. this.x = 0;
  5364. this.y = 0;
  5365. this.lineX = 0;
  5366. this.lineY = 0;
  5367. this.charSpacing = 0;
  5368. this.wordSpacing = 0;
  5369. this.textHScale = 1;
  5370. this.textRenderingMode = _util.TextRenderingMode.FILL;
  5371. this.textRise = 0;
  5372. this.fillColor = "#000000";
  5373. this.strokeColor = "#000000";
  5374. this.patternFill = false;
  5375. this.fillAlpha = 1;
  5376. this.strokeAlpha = 1;
  5377. this.lineWidth = 1;
  5378. this.activeSMask = null;
  5379. this.transferMaps = "none";
  5380. this.startNewPathAndClipBox([0, 0, width, height]);
  5381. }
  5382. clone() {
  5383. const clone = Object.create(this);
  5384. clone.clipBox = this.clipBox.slice();
  5385. return clone;
  5386. }
  5387. setCurrentPoint(x, y) {
  5388. this.x = x;
  5389. this.y = y;
  5390. }
  5391. updatePathMinMax(transform, x, y) {
  5392. [x, y] = _util.Util.applyTransform([x, y], transform);
  5393. this.minX = Math.min(this.minX, x);
  5394. this.minY = Math.min(this.minY, y);
  5395. this.maxX = Math.max(this.maxX, x);
  5396. this.maxY = Math.max(this.maxY, y);
  5397. }
  5398. updateRectMinMax(transform, rect) {
  5399. const p1 = _util.Util.applyTransform(rect, transform);
  5400. const p2 = _util.Util.applyTransform(rect.slice(2), transform);
  5401. this.minX = Math.min(this.minX, p1[0], p2[0]);
  5402. this.minY = Math.min(this.minY, p1[1], p2[1]);
  5403. this.maxX = Math.max(this.maxX, p1[0], p2[0]);
  5404. this.maxY = Math.max(this.maxY, p1[1], p2[1]);
  5405. }
  5406. updateScalingPathMinMax(transform, minMax) {
  5407. _util.Util.scaleMinMax(transform, minMax);
  5408. this.minX = Math.min(this.minX, minMax[0]);
  5409. this.maxX = Math.max(this.maxX, minMax[1]);
  5410. this.minY = Math.min(this.minY, minMax[2]);
  5411. this.maxY = Math.max(this.maxY, minMax[3]);
  5412. }
  5413. updateCurvePathMinMax(transform, x0, y0, x1, y1, x2, y2, x3, y3, minMax) {
  5414. const box = _util.Util.bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3);
  5415. if (minMax) {
  5416. minMax[0] = Math.min(minMax[0], box[0], box[2]);
  5417. minMax[1] = Math.max(minMax[1], box[0], box[2]);
  5418. minMax[2] = Math.min(minMax[2], box[1], box[3]);
  5419. minMax[3] = Math.max(minMax[3], box[1], box[3]);
  5420. return;
  5421. }
  5422. this.updateRectMinMax(transform, box);
  5423. }
  5424. getPathBoundingBox(pathType = _pattern_helper.PathType.FILL, transform = null) {
  5425. const box = [this.minX, this.minY, this.maxX, this.maxY];
  5426. if (pathType === _pattern_helper.PathType.STROKE) {
  5427. if (!transform) {
  5428. (0, _util.unreachable)("Stroke bounding box must include transform.");
  5429. }
  5430. const scale = _util.Util.singularValueDecompose2dScale(transform);
  5431. const xStrokePad = scale[0] * this.lineWidth / 2;
  5432. const yStrokePad = scale[1] * this.lineWidth / 2;
  5433. box[0] -= xStrokePad;
  5434. box[1] -= yStrokePad;
  5435. box[2] += xStrokePad;
  5436. box[3] += yStrokePad;
  5437. }
  5438. return box;
  5439. }
  5440. updateClipFromPath() {
  5441. const intersect = _util.Util.intersect(this.clipBox, this.getPathBoundingBox());
  5442. this.startNewPathAndClipBox(intersect || [0, 0, 0, 0]);
  5443. }
  5444. isEmptyClip() {
  5445. return this.minX === Infinity;
  5446. }
  5447. startNewPathAndClipBox(box) {
  5448. this.clipBox = box;
  5449. this.minX = Infinity;
  5450. this.minY = Infinity;
  5451. this.maxX = 0;
  5452. this.maxY = 0;
  5453. }
  5454. getClippedPathBoundingBox(pathType = _pattern_helper.PathType.FILL, transform = null) {
  5455. return _util.Util.intersect(this.clipBox, this.getPathBoundingBox(pathType, transform));
  5456. }
  5457. }
  5458. function putBinaryImageData(ctx, imgData) {
  5459. if (typeof ImageData !== "undefined" && imgData instanceof ImageData) {
  5460. ctx.putImageData(imgData, 0, 0);
  5461. return;
  5462. }
  5463. const height = imgData.height,
  5464. width = imgData.width;
  5465. const partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  5466. const fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  5467. const totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  5468. const chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  5469. let srcPos = 0,
  5470. destPos;
  5471. const src = imgData.data;
  5472. const dest = chunkImgData.data;
  5473. let i, j, thisChunkHeight, elemsInThisChunk;
  5474. if (imgData.kind === _util.ImageKind.GRAYSCALE_1BPP) {
  5475. const srcLength = src.byteLength;
  5476. const dest32 = new Uint32Array(dest.buffer, 0, dest.byteLength >> 2);
  5477. const dest32DataLength = dest32.length;
  5478. const fullSrcDiff = width + 7 >> 3;
  5479. const white = 0xffffffff;
  5480. const black = _util.FeatureTest.isLittleEndian ? 0xff000000 : 0x000000ff;
  5481. for (i = 0; i < totalChunks; i++) {
  5482. thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  5483. destPos = 0;
  5484. for (j = 0; j < thisChunkHeight; j++) {
  5485. const srcDiff = srcLength - srcPos;
  5486. let k = 0;
  5487. const kEnd = srcDiff > fullSrcDiff ? width : srcDiff * 8 - 7;
  5488. const kEndUnrolled = kEnd & ~7;
  5489. let mask = 0;
  5490. let srcByte = 0;
  5491. for (; k < kEndUnrolled; k += 8) {
  5492. srcByte = src[srcPos++];
  5493. dest32[destPos++] = srcByte & 128 ? white : black;
  5494. dest32[destPos++] = srcByte & 64 ? white : black;
  5495. dest32[destPos++] = srcByte & 32 ? white : black;
  5496. dest32[destPos++] = srcByte & 16 ? white : black;
  5497. dest32[destPos++] = srcByte & 8 ? white : black;
  5498. dest32[destPos++] = srcByte & 4 ? white : black;
  5499. dest32[destPos++] = srcByte & 2 ? white : black;
  5500. dest32[destPos++] = srcByte & 1 ? white : black;
  5501. }
  5502. for (; k < kEnd; k++) {
  5503. if (mask === 0) {
  5504. srcByte = src[srcPos++];
  5505. mask = 128;
  5506. }
  5507. dest32[destPos++] = srcByte & mask ? white : black;
  5508. mask >>= 1;
  5509. }
  5510. }
  5511. while (destPos < dest32DataLength) {
  5512. dest32[destPos++] = 0;
  5513. }
  5514. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  5515. }
  5516. } else if (imgData.kind === _util.ImageKind.RGBA_32BPP) {
  5517. j = 0;
  5518. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  5519. for (i = 0; i < fullChunks; i++) {
  5520. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  5521. srcPos += elemsInThisChunk;
  5522. ctx.putImageData(chunkImgData, 0, j);
  5523. j += FULL_CHUNK_HEIGHT;
  5524. }
  5525. if (i < totalChunks) {
  5526. elemsInThisChunk = width * partialChunkHeight * 4;
  5527. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  5528. ctx.putImageData(chunkImgData, 0, j);
  5529. }
  5530. } else if (imgData.kind === _util.ImageKind.RGB_24BPP) {
  5531. thisChunkHeight = FULL_CHUNK_HEIGHT;
  5532. elemsInThisChunk = width * thisChunkHeight;
  5533. for (i = 0; i < totalChunks; i++) {
  5534. if (i >= fullChunks) {
  5535. thisChunkHeight = partialChunkHeight;
  5536. elemsInThisChunk = width * thisChunkHeight;
  5537. }
  5538. destPos = 0;
  5539. for (j = elemsInThisChunk; j--;) {
  5540. dest[destPos++] = src[srcPos++];
  5541. dest[destPos++] = src[srcPos++];
  5542. dest[destPos++] = src[srcPos++];
  5543. dest[destPos++] = 255;
  5544. }
  5545. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  5546. }
  5547. } else {
  5548. throw new Error(`bad image kind: ${imgData.kind}`);
  5549. }
  5550. }
  5551. function putBinaryImageMask(ctx, imgData) {
  5552. if (imgData.bitmap) {
  5553. ctx.drawImage(imgData.bitmap, 0, 0);
  5554. return;
  5555. }
  5556. const height = imgData.height,
  5557. width = imgData.width;
  5558. const partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  5559. const fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  5560. const totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  5561. const chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  5562. let srcPos = 0;
  5563. const src = imgData.data;
  5564. const dest = chunkImgData.data;
  5565. for (let i = 0; i < totalChunks; i++) {
  5566. const thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  5567. ({
  5568. srcPos
  5569. } = (0, _image_utils.convertBlackAndWhiteToRGBA)({
  5570. src,
  5571. srcPos,
  5572. dest,
  5573. width,
  5574. height: thisChunkHeight,
  5575. nonBlackColor: 0
  5576. }));
  5577. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  5578. }
  5579. }
  5580. function copyCtxState(sourceCtx, destCtx) {
  5581. const properties = ["strokeStyle", "fillStyle", "fillRule", "globalAlpha", "lineWidth", "lineCap", "lineJoin", "miterLimit", "globalCompositeOperation", "font", "filter"];
  5582. for (const property of properties) {
  5583. if (sourceCtx[property] !== undefined) {
  5584. destCtx[property] = sourceCtx[property];
  5585. }
  5586. }
  5587. if (sourceCtx.setLineDash !== undefined) {
  5588. destCtx.setLineDash(sourceCtx.getLineDash());
  5589. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  5590. }
  5591. }
  5592. function resetCtxToDefault(ctx) {
  5593. ctx.strokeStyle = ctx.fillStyle = "#000000";
  5594. ctx.fillRule = "nonzero";
  5595. ctx.globalAlpha = 1;
  5596. ctx.lineWidth = 1;
  5597. ctx.lineCap = "butt";
  5598. ctx.lineJoin = "miter";
  5599. ctx.miterLimit = 10;
  5600. ctx.globalCompositeOperation = "source-over";
  5601. ctx.font = "10px sans-serif";
  5602. if (ctx.setLineDash !== undefined) {
  5603. ctx.setLineDash([]);
  5604. ctx.lineDashOffset = 0;
  5605. }
  5606. if (!_is_node.isNodeJS) {
  5607. ctx.filter = "none";
  5608. }
  5609. }
  5610. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  5611. const length = bytes.length;
  5612. for (let i = 3; i < length; i += 4) {
  5613. const alpha = bytes[i];
  5614. if (alpha === 0) {
  5615. bytes[i - 3] = r0;
  5616. bytes[i - 2] = g0;
  5617. bytes[i - 1] = b0;
  5618. } else if (alpha < 255) {
  5619. const alpha_ = 255 - alpha;
  5620. bytes[i - 3] = bytes[i - 3] * alpha + r0 * alpha_ >> 8;
  5621. bytes[i - 2] = bytes[i - 2] * alpha + g0 * alpha_ >> 8;
  5622. bytes[i - 1] = bytes[i - 1] * alpha + b0 * alpha_ >> 8;
  5623. }
  5624. }
  5625. }
  5626. function composeSMaskAlpha(maskData, layerData, transferMap) {
  5627. const length = maskData.length;
  5628. const scale = 1 / 255;
  5629. for (let i = 3; i < length; i += 4) {
  5630. const alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
  5631. layerData[i] = layerData[i] * alpha * scale | 0;
  5632. }
  5633. }
  5634. function composeSMaskLuminosity(maskData, layerData, transferMap) {
  5635. const length = maskData.length;
  5636. for (let i = 3; i < length; i += 4) {
  5637. const y = maskData[i - 3] * 77 + maskData[i - 2] * 152 + maskData[i - 1] * 28;
  5638. layerData[i] = transferMap ? layerData[i] * transferMap[y >> 8] >> 8 : layerData[i] * y >> 16;
  5639. }
  5640. }
  5641. function genericComposeSMask(maskCtx, layerCtx, width, height, subtype, backdrop, transferMap, layerOffsetX, layerOffsetY, maskOffsetX, maskOffsetY) {
  5642. const hasBackdrop = !!backdrop;
  5643. const r0 = hasBackdrop ? backdrop[0] : 0;
  5644. const g0 = hasBackdrop ? backdrop[1] : 0;
  5645. const b0 = hasBackdrop ? backdrop[2] : 0;
  5646. let composeFn;
  5647. if (subtype === "Luminosity") {
  5648. composeFn = composeSMaskLuminosity;
  5649. } else {
  5650. composeFn = composeSMaskAlpha;
  5651. }
  5652. const PIXELS_TO_PROCESS = 1048576;
  5653. const chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  5654. for (let row = 0; row < height; row += chunkSize) {
  5655. const chunkHeight = Math.min(chunkSize, height - row);
  5656. const maskData = maskCtx.getImageData(layerOffsetX - maskOffsetX, row + (layerOffsetY - maskOffsetY), width, chunkHeight);
  5657. const layerData = layerCtx.getImageData(layerOffsetX, row + layerOffsetY, width, chunkHeight);
  5658. if (hasBackdrop) {
  5659. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  5660. }
  5661. composeFn(maskData.data, layerData.data, transferMap);
  5662. layerCtx.putImageData(layerData, layerOffsetX, row + layerOffsetY);
  5663. }
  5664. }
  5665. function composeSMask(ctx, smask, layerCtx, layerBox) {
  5666. const layerOffsetX = layerBox[0];
  5667. const layerOffsetY = layerBox[1];
  5668. const layerWidth = layerBox[2] - layerOffsetX;
  5669. const layerHeight = layerBox[3] - layerOffsetY;
  5670. if (layerWidth === 0 || layerHeight === 0) {
  5671. return;
  5672. }
  5673. genericComposeSMask(smask.context, layerCtx, layerWidth, layerHeight, smask.subtype, smask.backdrop, smask.transferMap, layerOffsetX, layerOffsetY, smask.offsetX, smask.offsetY);
  5674. ctx.save();
  5675. ctx.globalAlpha = 1;
  5676. ctx.globalCompositeOperation = "source-over";
  5677. ctx.setTransform(1, 0, 0, 1, 0, 0);
  5678. ctx.drawImage(layerCtx.canvas, 0, 0);
  5679. ctx.restore();
  5680. }
  5681. function getImageSmoothingEnabled(transform, interpolate) {
  5682. const scale = _util.Util.singularValueDecompose2dScale(transform);
  5683. scale[0] = Math.fround(scale[0]);
  5684. scale[1] = Math.fround(scale[1]);
  5685. const actualScale = Math.fround((globalThis.devicePixelRatio || 1) * _display_utils.PixelsPerInch.PDF_TO_CSS_UNITS);
  5686. if (interpolate !== undefined) {
  5687. return interpolate;
  5688. } else if (scale[0] <= actualScale || scale[1] <= actualScale) {
  5689. return true;
  5690. }
  5691. return false;
  5692. }
  5693. const LINE_CAP_STYLES = ["butt", "round", "square"];
  5694. const LINE_JOIN_STYLES = ["miter", "round", "bevel"];
  5695. const NORMAL_CLIP = {};
  5696. const EO_CLIP = {};
  5697. class CanvasGraphics {
  5698. constructor(canvasCtx, commonObjs, objs, canvasFactory, filterFactory, {
  5699. optionalContentConfig,
  5700. markedContentStack = null
  5701. }, annotationCanvasMap, pageColors) {
  5702. this.ctx = canvasCtx;
  5703. this.current = new CanvasExtraState(this.ctx.canvas.width, this.ctx.canvas.height);
  5704. this.stateStack = [];
  5705. this.pendingClip = null;
  5706. this.pendingEOFill = false;
  5707. this.res = null;
  5708. this.xobjs = null;
  5709. this.commonObjs = commonObjs;
  5710. this.objs = objs;
  5711. this.canvasFactory = canvasFactory;
  5712. this.filterFactory = filterFactory;
  5713. this.groupStack = [];
  5714. this.processingType3 = null;
  5715. this.baseTransform = null;
  5716. this.baseTransformStack = [];
  5717. this.groupLevel = 0;
  5718. this.smaskStack = [];
  5719. this.smaskCounter = 0;
  5720. this.tempSMask = null;
  5721. this.suspendedCtx = null;
  5722. this.contentVisible = true;
  5723. this.markedContentStack = markedContentStack || [];
  5724. this.optionalContentConfig = optionalContentConfig;
  5725. this.cachedCanvases = new CachedCanvases(this.canvasFactory);
  5726. this.cachedPatterns = new Map();
  5727. this.annotationCanvasMap = annotationCanvasMap;
  5728. this.viewportScale = 1;
  5729. this.outputScaleX = 1;
  5730. this.outputScaleY = 1;
  5731. this.pageColors = pageColors;
  5732. this._cachedScaleForStroking = [-1, 0];
  5733. this._cachedGetSinglePixelWidth = null;
  5734. this._cachedBitmapsMap = new Map();
  5735. }
  5736. getObject(data, fallback = null) {
  5737. if (typeof data === "string") {
  5738. return data.startsWith("g_") ? this.commonObjs.get(data) : this.objs.get(data);
  5739. }
  5740. return fallback;
  5741. }
  5742. beginDrawing({
  5743. transform,
  5744. viewport,
  5745. transparency = false,
  5746. background = null
  5747. }) {
  5748. const width = this.ctx.canvas.width;
  5749. const height = this.ctx.canvas.height;
  5750. const savedFillStyle = this.ctx.fillStyle;
  5751. this.ctx.fillStyle = background || "#ffffff";
  5752. this.ctx.fillRect(0, 0, width, height);
  5753. this.ctx.fillStyle = savedFillStyle;
  5754. if (transparency) {
  5755. const transparentCanvas = this.cachedCanvases.getCanvas("transparent", width, height);
  5756. this.compositeCtx = this.ctx;
  5757. this.transparentCanvas = transparentCanvas.canvas;
  5758. this.ctx = transparentCanvas.context;
  5759. this.ctx.save();
  5760. this.ctx.transform(...(0, _display_utils.getCurrentTransform)(this.compositeCtx));
  5761. }
  5762. this.ctx.save();
  5763. resetCtxToDefault(this.ctx);
  5764. if (transform) {
  5765. this.ctx.transform(...transform);
  5766. this.outputScaleX = transform[0];
  5767. this.outputScaleY = transform[0];
  5768. }
  5769. this.ctx.transform(...viewport.transform);
  5770. this.viewportScale = viewport.scale;
  5771. this.baseTransform = (0, _display_utils.getCurrentTransform)(this.ctx);
  5772. }
  5773. executeOperatorList(operatorList, executionStartIdx, continueCallback, stepper) {
  5774. const argsArray = operatorList.argsArray;
  5775. const fnArray = operatorList.fnArray;
  5776. let i = executionStartIdx || 0;
  5777. const argsArrayLen = argsArray.length;
  5778. if (argsArrayLen === i) {
  5779. return i;
  5780. }
  5781. const chunkOperations = argsArrayLen - i > EXECUTION_STEPS && typeof continueCallback === "function";
  5782. const endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  5783. let steps = 0;
  5784. const commonObjs = this.commonObjs;
  5785. const objs = this.objs;
  5786. let fnId;
  5787. while (true) {
  5788. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  5789. stepper.breakIt(i, continueCallback);
  5790. return i;
  5791. }
  5792. fnId = fnArray[i];
  5793. if (fnId !== _util.OPS.dependency) {
  5794. this[fnId].apply(this, argsArray[i]);
  5795. } else {
  5796. for (const depObjId of argsArray[i]) {
  5797. const objsPool = depObjId.startsWith("g_") ? commonObjs : objs;
  5798. if (!objsPool.has(depObjId)) {
  5799. objsPool.get(depObjId, continueCallback);
  5800. return i;
  5801. }
  5802. }
  5803. }
  5804. i++;
  5805. if (i === argsArrayLen) {
  5806. return i;
  5807. }
  5808. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  5809. if (Date.now() > endTime) {
  5810. continueCallback();
  5811. return i;
  5812. }
  5813. steps = 0;
  5814. }
  5815. }
  5816. }
  5817. #restoreInitialState() {
  5818. while (this.stateStack.length || this.inSMaskMode) {
  5819. this.restore();
  5820. }
  5821. this.ctx.restore();
  5822. if (this.transparentCanvas) {
  5823. this.ctx = this.compositeCtx;
  5824. this.ctx.save();
  5825. this.ctx.setTransform(1, 0, 0, 1, 0, 0);
  5826. this.ctx.drawImage(this.transparentCanvas, 0, 0);
  5827. this.ctx.restore();
  5828. this.transparentCanvas = null;
  5829. }
  5830. }
  5831. endDrawing() {
  5832. this.#restoreInitialState();
  5833. this.cachedCanvases.clear();
  5834. this.cachedPatterns.clear();
  5835. for (const cache of this._cachedBitmapsMap.values()) {
  5836. for (const canvas of cache.values()) {
  5837. if (typeof HTMLCanvasElement !== "undefined" && canvas instanceof HTMLCanvasElement) {
  5838. canvas.width = canvas.height = 0;
  5839. }
  5840. }
  5841. cache.clear();
  5842. }
  5843. this._cachedBitmapsMap.clear();
  5844. this.#drawFilter();
  5845. }
  5846. #drawFilter() {
  5847. if (this.pageColors) {
  5848. const hcmFilterId = this.filterFactory.addHCMFilter(this.pageColors.foreground, this.pageColors.background);
  5849. if (hcmFilterId !== "none") {
  5850. const savedFilter = this.ctx.filter;
  5851. this.ctx.filter = hcmFilterId;
  5852. this.ctx.drawImage(this.ctx.canvas, 0, 0);
  5853. this.ctx.filter = savedFilter;
  5854. }
  5855. }
  5856. }
  5857. _scaleImage(img, inverseTransform) {
  5858. const width = img.width;
  5859. const height = img.height;
  5860. let widthScale = Math.max(Math.hypot(inverseTransform[0], inverseTransform[1]), 1);
  5861. let heightScale = Math.max(Math.hypot(inverseTransform[2], inverseTransform[3]), 1);
  5862. let paintWidth = width,
  5863. paintHeight = height;
  5864. let tmpCanvasId = "prescale1";
  5865. let tmpCanvas, tmpCtx;
  5866. while (widthScale > 2 && paintWidth > 1 || heightScale > 2 && paintHeight > 1) {
  5867. let newWidth = paintWidth,
  5868. newHeight = paintHeight;
  5869. if (widthScale > 2 && paintWidth > 1) {
  5870. newWidth = paintWidth >= 16384 ? Math.floor(paintWidth / 2) - 1 || 1 : Math.ceil(paintWidth / 2);
  5871. widthScale /= paintWidth / newWidth;
  5872. }
  5873. if (heightScale > 2 && paintHeight > 1) {
  5874. newHeight = paintHeight >= 16384 ? Math.floor(paintHeight / 2) - 1 || 1 : Math.ceil(paintHeight) / 2;
  5875. heightScale /= paintHeight / newHeight;
  5876. }
  5877. tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
  5878. tmpCtx = tmpCanvas.context;
  5879. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  5880. tmpCtx.drawImage(img, 0, 0, paintWidth, paintHeight, 0, 0, newWidth, newHeight);
  5881. img = tmpCanvas.canvas;
  5882. paintWidth = newWidth;
  5883. paintHeight = newHeight;
  5884. tmpCanvasId = tmpCanvasId === "prescale1" ? "prescale2" : "prescale1";
  5885. }
  5886. return {
  5887. img,
  5888. paintWidth,
  5889. paintHeight
  5890. };
  5891. }
  5892. _createMaskCanvas(img) {
  5893. const ctx = this.ctx;
  5894. const {
  5895. width,
  5896. height
  5897. } = img;
  5898. const fillColor = this.current.fillColor;
  5899. const isPatternFill = this.current.patternFill;
  5900. const currentTransform = (0, _display_utils.getCurrentTransform)(ctx);
  5901. let cache, cacheKey, scaled, maskCanvas;
  5902. if ((img.bitmap || img.data) && img.count > 1) {
  5903. const mainKey = img.bitmap || img.data.buffer;
  5904. cacheKey = JSON.stringify(isPatternFill ? currentTransform : [currentTransform.slice(0, 4), fillColor]);
  5905. cache = this._cachedBitmapsMap.get(mainKey);
  5906. if (!cache) {
  5907. cache = new Map();
  5908. this._cachedBitmapsMap.set(mainKey, cache);
  5909. }
  5910. const cachedImage = cache.get(cacheKey);
  5911. if (cachedImage && !isPatternFill) {
  5912. const offsetX = Math.round(Math.min(currentTransform[0], currentTransform[2]) + currentTransform[4]);
  5913. const offsetY = Math.round(Math.min(currentTransform[1], currentTransform[3]) + currentTransform[5]);
  5914. return {
  5915. canvas: cachedImage,
  5916. offsetX,
  5917. offsetY
  5918. };
  5919. }
  5920. scaled = cachedImage;
  5921. }
  5922. if (!scaled) {
  5923. maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
  5924. putBinaryImageMask(maskCanvas.context, img);
  5925. }
  5926. let maskToCanvas = _util.Util.transform(currentTransform, [1 / width, 0, 0, -1 / height, 0, 0]);
  5927. maskToCanvas = _util.Util.transform(maskToCanvas, [1, 0, 0, 1, 0, -height]);
  5928. const cord1 = _util.Util.applyTransform([0, 0], maskToCanvas);
  5929. const cord2 = _util.Util.applyTransform([width, height], maskToCanvas);
  5930. const rect = _util.Util.normalizeRect([cord1[0], cord1[1], cord2[0], cord2[1]]);
  5931. const drawnWidth = Math.round(rect[2] - rect[0]) || 1;
  5932. const drawnHeight = Math.round(rect[3] - rect[1]) || 1;
  5933. const fillCanvas = this.cachedCanvases.getCanvas("fillCanvas", drawnWidth, drawnHeight);
  5934. const fillCtx = fillCanvas.context;
  5935. const offsetX = Math.min(cord1[0], cord2[0]);
  5936. const offsetY = Math.min(cord1[1], cord2[1]);
  5937. fillCtx.translate(-offsetX, -offsetY);
  5938. fillCtx.transform(...maskToCanvas);
  5939. if (!scaled) {
  5940. scaled = this._scaleImage(maskCanvas.canvas, (0, _display_utils.getCurrentTransformInverse)(fillCtx));
  5941. scaled = scaled.img;
  5942. if (cache && isPatternFill) {
  5943. cache.set(cacheKey, scaled);
  5944. }
  5945. }
  5946. fillCtx.imageSmoothingEnabled = getImageSmoothingEnabled((0, _display_utils.getCurrentTransform)(fillCtx), img.interpolate);
  5947. drawImageAtIntegerCoords(fillCtx, scaled, 0, 0, scaled.width, scaled.height, 0, 0, width, height);
  5948. fillCtx.globalCompositeOperation = "source-in";
  5949. const inverse = _util.Util.transform((0, _display_utils.getCurrentTransformInverse)(fillCtx), [1, 0, 0, 1, -offsetX, -offsetY]);
  5950. fillCtx.fillStyle = isPatternFill ? fillColor.getPattern(ctx, this, inverse, _pattern_helper.PathType.FILL) : fillColor;
  5951. fillCtx.fillRect(0, 0, width, height);
  5952. if (cache && !isPatternFill) {
  5953. this.cachedCanvases.delete("fillCanvas");
  5954. cache.set(cacheKey, fillCanvas.canvas);
  5955. }
  5956. return {
  5957. canvas: fillCanvas.canvas,
  5958. offsetX: Math.round(offsetX),
  5959. offsetY: Math.round(offsetY)
  5960. };
  5961. }
  5962. setLineWidth(width) {
  5963. if (width !== this.current.lineWidth) {
  5964. this._cachedScaleForStroking[0] = -1;
  5965. }
  5966. this.current.lineWidth = width;
  5967. this.ctx.lineWidth = width;
  5968. }
  5969. setLineCap(style) {
  5970. this.ctx.lineCap = LINE_CAP_STYLES[style];
  5971. }
  5972. setLineJoin(style) {
  5973. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  5974. }
  5975. setMiterLimit(limit) {
  5976. this.ctx.miterLimit = limit;
  5977. }
  5978. setDash(dashArray, dashPhase) {
  5979. const ctx = this.ctx;
  5980. if (ctx.setLineDash !== undefined) {
  5981. ctx.setLineDash(dashArray);
  5982. ctx.lineDashOffset = dashPhase;
  5983. }
  5984. }
  5985. setRenderingIntent(intent) {}
  5986. setFlatness(flatness) {}
  5987. setGState(states) {
  5988. for (const [key, value] of states) {
  5989. switch (key) {
  5990. case "LW":
  5991. this.setLineWidth(value);
  5992. break;
  5993. case "LC":
  5994. this.setLineCap(value);
  5995. break;
  5996. case "LJ":
  5997. this.setLineJoin(value);
  5998. break;
  5999. case "ML":
  6000. this.setMiterLimit(value);
  6001. break;
  6002. case "D":
  6003. this.setDash(value[0], value[1]);
  6004. break;
  6005. case "RI":
  6006. this.setRenderingIntent(value);
  6007. break;
  6008. case "FL":
  6009. this.setFlatness(value);
  6010. break;
  6011. case "Font":
  6012. this.setFont(value[0], value[1]);
  6013. break;
  6014. case "CA":
  6015. this.current.strokeAlpha = value;
  6016. break;
  6017. case "ca":
  6018. this.current.fillAlpha = value;
  6019. this.ctx.globalAlpha = value;
  6020. break;
  6021. case "BM":
  6022. this.ctx.globalCompositeOperation = value;
  6023. break;
  6024. case "SMask":
  6025. this.current.activeSMask = value ? this.tempSMask : null;
  6026. this.tempSMask = null;
  6027. this.checkSMaskState();
  6028. break;
  6029. case "TR":
  6030. this.ctx.filter = this.current.transferMaps = this.filterFactory.addFilter(value);
  6031. break;
  6032. }
  6033. }
  6034. }
  6035. get inSMaskMode() {
  6036. return !!this.suspendedCtx;
  6037. }
  6038. checkSMaskState() {
  6039. const inSMaskMode = this.inSMaskMode;
  6040. if (this.current.activeSMask && !inSMaskMode) {
  6041. this.beginSMaskMode();
  6042. } else if (!this.current.activeSMask && inSMaskMode) {
  6043. this.endSMaskMode();
  6044. }
  6045. }
  6046. beginSMaskMode() {
  6047. if (this.inSMaskMode) {
  6048. throw new Error("beginSMaskMode called while already in smask mode");
  6049. }
  6050. const drawnWidth = this.ctx.canvas.width;
  6051. const drawnHeight = this.ctx.canvas.height;
  6052. const cacheId = "smaskGroupAt" + this.groupLevel;
  6053. const scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight);
  6054. this.suspendedCtx = this.ctx;
  6055. this.ctx = scratchCanvas.context;
  6056. const ctx = this.ctx;
  6057. ctx.setTransform(...(0, _display_utils.getCurrentTransform)(this.suspendedCtx));
  6058. copyCtxState(this.suspendedCtx, ctx);
  6059. mirrorContextOperations(ctx, this.suspendedCtx);
  6060. this.setGState([["BM", "source-over"], ["ca", 1], ["CA", 1]]);
  6061. }
  6062. endSMaskMode() {
  6063. if (!this.inSMaskMode) {
  6064. throw new Error("endSMaskMode called while not in smask mode");
  6065. }
  6066. this.ctx._removeMirroring();
  6067. copyCtxState(this.ctx, this.suspendedCtx);
  6068. this.ctx = this.suspendedCtx;
  6069. this.suspendedCtx = null;
  6070. }
  6071. compose(dirtyBox) {
  6072. if (!this.current.activeSMask) {
  6073. return;
  6074. }
  6075. if (!dirtyBox) {
  6076. dirtyBox = [0, 0, this.ctx.canvas.width, this.ctx.canvas.height];
  6077. } else {
  6078. dirtyBox[0] = Math.floor(dirtyBox[0]);
  6079. dirtyBox[1] = Math.floor(dirtyBox[1]);
  6080. dirtyBox[2] = Math.ceil(dirtyBox[2]);
  6081. dirtyBox[3] = Math.ceil(dirtyBox[3]);
  6082. }
  6083. const smask = this.current.activeSMask;
  6084. const suspendedCtx = this.suspendedCtx;
  6085. composeSMask(suspendedCtx, smask, this.ctx, dirtyBox);
  6086. this.ctx.save();
  6087. this.ctx.setTransform(1, 0, 0, 1, 0, 0);
  6088. this.ctx.clearRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height);
  6089. this.ctx.restore();
  6090. }
  6091. save() {
  6092. if (this.inSMaskMode) {
  6093. copyCtxState(this.ctx, this.suspendedCtx);
  6094. this.suspendedCtx.save();
  6095. } else {
  6096. this.ctx.save();
  6097. }
  6098. const old = this.current;
  6099. this.stateStack.push(old);
  6100. this.current = old.clone();
  6101. }
  6102. restore() {
  6103. if (this.stateStack.length === 0 && this.inSMaskMode) {
  6104. this.endSMaskMode();
  6105. }
  6106. if (this.stateStack.length !== 0) {
  6107. this.current = this.stateStack.pop();
  6108. if (this.inSMaskMode) {
  6109. this.suspendedCtx.restore();
  6110. copyCtxState(this.suspendedCtx, this.ctx);
  6111. } else {
  6112. this.ctx.restore();
  6113. }
  6114. this.checkSMaskState();
  6115. this.pendingClip = null;
  6116. this._cachedScaleForStroking[0] = -1;
  6117. this._cachedGetSinglePixelWidth = null;
  6118. }
  6119. }
  6120. transform(a, b, c, d, e, f) {
  6121. this.ctx.transform(a, b, c, d, e, f);
  6122. this._cachedScaleForStroking[0] = -1;
  6123. this._cachedGetSinglePixelWidth = null;
  6124. }
  6125. constructPath(ops, args, minMax) {
  6126. const ctx = this.ctx;
  6127. const current = this.current;
  6128. let x = current.x,
  6129. y = current.y;
  6130. let startX, startY;
  6131. const currentTransform = (0, _display_utils.getCurrentTransform)(ctx);
  6132. const isScalingMatrix = currentTransform[0] === 0 && currentTransform[3] === 0 || currentTransform[1] === 0 && currentTransform[2] === 0;
  6133. const minMaxForBezier = isScalingMatrix ? minMax.slice(0) : null;
  6134. for (let i = 0, j = 0, ii = ops.length; i < ii; i++) {
  6135. switch (ops[i] | 0) {
  6136. case _util.OPS.rectangle:
  6137. x = args[j++];
  6138. y = args[j++];
  6139. const width = args[j++];
  6140. const height = args[j++];
  6141. const xw = x + width;
  6142. const yh = y + height;
  6143. ctx.moveTo(x, y);
  6144. if (width === 0 || height === 0) {
  6145. ctx.lineTo(xw, yh);
  6146. } else {
  6147. ctx.lineTo(xw, y);
  6148. ctx.lineTo(xw, yh);
  6149. ctx.lineTo(x, yh);
  6150. }
  6151. if (!isScalingMatrix) {
  6152. current.updateRectMinMax(currentTransform, [x, y, xw, yh]);
  6153. }
  6154. ctx.closePath();
  6155. break;
  6156. case _util.OPS.moveTo:
  6157. x = args[j++];
  6158. y = args[j++];
  6159. ctx.moveTo(x, y);
  6160. if (!isScalingMatrix) {
  6161. current.updatePathMinMax(currentTransform, x, y);
  6162. }
  6163. break;
  6164. case _util.OPS.lineTo:
  6165. x = args[j++];
  6166. y = args[j++];
  6167. ctx.lineTo(x, y);
  6168. if (!isScalingMatrix) {
  6169. current.updatePathMinMax(currentTransform, x, y);
  6170. }
  6171. break;
  6172. case _util.OPS.curveTo:
  6173. startX = x;
  6174. startY = y;
  6175. x = args[j + 4];
  6176. y = args[j + 5];
  6177. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3], x, y);
  6178. current.updateCurvePathMinMax(currentTransform, startX, startY, args[j], args[j + 1], args[j + 2], args[j + 3], x, y, minMaxForBezier);
  6179. j += 6;
  6180. break;
  6181. case _util.OPS.curveTo2:
  6182. startX = x;
  6183. startY = y;
  6184. ctx.bezierCurveTo(x, y, args[j], args[j + 1], args[j + 2], args[j + 3]);
  6185. current.updateCurvePathMinMax(currentTransform, startX, startY, x, y, args[j], args[j + 1], args[j + 2], args[j + 3], minMaxForBezier);
  6186. x = args[j + 2];
  6187. y = args[j + 3];
  6188. j += 4;
  6189. break;
  6190. case _util.OPS.curveTo3:
  6191. startX = x;
  6192. startY = y;
  6193. x = args[j + 2];
  6194. y = args[j + 3];
  6195. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  6196. current.updateCurvePathMinMax(currentTransform, startX, startY, args[j], args[j + 1], x, y, x, y, minMaxForBezier);
  6197. j += 4;
  6198. break;
  6199. case _util.OPS.closePath:
  6200. ctx.closePath();
  6201. break;
  6202. }
  6203. }
  6204. if (isScalingMatrix) {
  6205. current.updateScalingPathMinMax(currentTransform, minMaxForBezier);
  6206. }
  6207. current.setCurrentPoint(x, y);
  6208. }
  6209. closePath() {
  6210. this.ctx.closePath();
  6211. }
  6212. stroke(consumePath = true) {
  6213. const ctx = this.ctx;
  6214. const strokeColor = this.current.strokeColor;
  6215. ctx.globalAlpha = this.current.strokeAlpha;
  6216. if (this.contentVisible) {
  6217. if (typeof strokeColor === "object" && strokeColor?.getPattern) {
  6218. ctx.save();
  6219. ctx.strokeStyle = strokeColor.getPattern(ctx, this, (0, _display_utils.getCurrentTransformInverse)(ctx), _pattern_helper.PathType.STROKE);
  6220. this.rescaleAndStroke(false);
  6221. ctx.restore();
  6222. } else {
  6223. this.rescaleAndStroke(true);
  6224. }
  6225. }
  6226. if (consumePath) {
  6227. this.consumePath(this.current.getClippedPathBoundingBox());
  6228. }
  6229. ctx.globalAlpha = this.current.fillAlpha;
  6230. }
  6231. closeStroke() {
  6232. this.closePath();
  6233. this.stroke();
  6234. }
  6235. fill(consumePath = true) {
  6236. const ctx = this.ctx;
  6237. const fillColor = this.current.fillColor;
  6238. const isPatternFill = this.current.patternFill;
  6239. let needRestore = false;
  6240. if (isPatternFill) {
  6241. ctx.save();
  6242. ctx.fillStyle = fillColor.getPattern(ctx, this, (0, _display_utils.getCurrentTransformInverse)(ctx), _pattern_helper.PathType.FILL);
  6243. needRestore = true;
  6244. }
  6245. const intersect = this.current.getClippedPathBoundingBox();
  6246. if (this.contentVisible && intersect !== null) {
  6247. if (this.pendingEOFill) {
  6248. ctx.fill("evenodd");
  6249. this.pendingEOFill = false;
  6250. } else {
  6251. ctx.fill();
  6252. }
  6253. }
  6254. if (needRestore) {
  6255. ctx.restore();
  6256. }
  6257. if (consumePath) {
  6258. this.consumePath(intersect);
  6259. }
  6260. }
  6261. eoFill() {
  6262. this.pendingEOFill = true;
  6263. this.fill();
  6264. }
  6265. fillStroke() {
  6266. this.fill(false);
  6267. this.stroke(false);
  6268. this.consumePath();
  6269. }
  6270. eoFillStroke() {
  6271. this.pendingEOFill = true;
  6272. this.fillStroke();
  6273. }
  6274. closeFillStroke() {
  6275. this.closePath();
  6276. this.fillStroke();
  6277. }
  6278. closeEOFillStroke() {
  6279. this.pendingEOFill = true;
  6280. this.closePath();
  6281. this.fillStroke();
  6282. }
  6283. endPath() {
  6284. this.consumePath();
  6285. }
  6286. clip() {
  6287. this.pendingClip = NORMAL_CLIP;
  6288. }
  6289. eoClip() {
  6290. this.pendingClip = EO_CLIP;
  6291. }
  6292. beginText() {
  6293. this.current.textMatrix = _util.IDENTITY_MATRIX;
  6294. this.current.textMatrixScale = 1;
  6295. this.current.x = this.current.lineX = 0;
  6296. this.current.y = this.current.lineY = 0;
  6297. }
  6298. endText() {
  6299. const paths = this.pendingTextPaths;
  6300. const ctx = this.ctx;
  6301. if (paths === undefined) {
  6302. ctx.beginPath();
  6303. return;
  6304. }
  6305. ctx.save();
  6306. ctx.beginPath();
  6307. for (const path of paths) {
  6308. ctx.setTransform(...path.transform);
  6309. ctx.translate(path.x, path.y);
  6310. path.addToPath(ctx, path.fontSize);
  6311. }
  6312. ctx.restore();
  6313. ctx.clip();
  6314. ctx.beginPath();
  6315. delete this.pendingTextPaths;
  6316. }
  6317. setCharSpacing(spacing) {
  6318. this.current.charSpacing = spacing;
  6319. }
  6320. setWordSpacing(spacing) {
  6321. this.current.wordSpacing = spacing;
  6322. }
  6323. setHScale(scale) {
  6324. this.current.textHScale = scale / 100;
  6325. }
  6326. setLeading(leading) {
  6327. this.current.leading = -leading;
  6328. }
  6329. setFont(fontRefName, size) {
  6330. const fontObj = this.commonObjs.get(fontRefName);
  6331. const current = this.current;
  6332. if (!fontObj) {
  6333. throw new Error(`Can't find font for ${fontRefName}`);
  6334. }
  6335. current.fontMatrix = fontObj.fontMatrix || _util.FONT_IDENTITY_MATRIX;
  6336. if (current.fontMatrix[0] === 0 || current.fontMatrix[3] === 0) {
  6337. (0, _util.warn)("Invalid font matrix for font " + fontRefName);
  6338. }
  6339. if (size < 0) {
  6340. size = -size;
  6341. current.fontDirection = -1;
  6342. } else {
  6343. current.fontDirection = 1;
  6344. }
  6345. this.current.font = fontObj;
  6346. this.current.fontSize = size;
  6347. if (fontObj.isType3Font) {
  6348. return;
  6349. }
  6350. const name = fontObj.loadedName || "sans-serif";
  6351. const typeface = fontObj.systemFontInfo?.css || `"${name}", ${fontObj.fallbackName}`;
  6352. let bold = "normal";
  6353. if (fontObj.black) {
  6354. bold = "900";
  6355. } else if (fontObj.bold) {
  6356. bold = "bold";
  6357. }
  6358. const italic = fontObj.italic ? "italic" : "normal";
  6359. let browserFontSize = size;
  6360. if (size < MIN_FONT_SIZE) {
  6361. browserFontSize = MIN_FONT_SIZE;
  6362. } else if (size > MAX_FONT_SIZE) {
  6363. browserFontSize = MAX_FONT_SIZE;
  6364. }
  6365. this.current.fontSizeScale = size / browserFontSize;
  6366. this.ctx.font = `${italic} ${bold} ${browserFontSize}px ${typeface}`;
  6367. }
  6368. setTextRenderingMode(mode) {
  6369. this.current.textRenderingMode = mode;
  6370. }
  6371. setTextRise(rise) {
  6372. this.current.textRise = rise;
  6373. }
  6374. moveText(x, y) {
  6375. this.current.x = this.current.lineX += x;
  6376. this.current.y = this.current.lineY += y;
  6377. }
  6378. setLeadingMoveText(x, y) {
  6379. this.setLeading(-y);
  6380. this.moveText(x, y);
  6381. }
  6382. setTextMatrix(a, b, c, d, e, f) {
  6383. this.current.textMatrix = [a, b, c, d, e, f];
  6384. this.current.textMatrixScale = Math.hypot(a, b);
  6385. this.current.x = this.current.lineX = 0;
  6386. this.current.y = this.current.lineY = 0;
  6387. }
  6388. nextLine() {
  6389. this.moveText(0, this.current.leading);
  6390. }
  6391. paintChar(character, x, y, patternTransform) {
  6392. const ctx = this.ctx;
  6393. const current = this.current;
  6394. const font = current.font;
  6395. const textRenderingMode = current.textRenderingMode;
  6396. const fontSize = current.fontSize / current.fontSizeScale;
  6397. const fillStrokeMode = textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  6398. const isAddToPathSet = !!(textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG);
  6399. const patternFill = current.patternFill && !font.missingFile;
  6400. let addToPath;
  6401. if (font.disableFontFace || isAddToPathSet || patternFill) {
  6402. addToPath = font.getPathGenerator(this.commonObjs, character);
  6403. }
  6404. if (font.disableFontFace || patternFill) {
  6405. ctx.save();
  6406. ctx.translate(x, y);
  6407. ctx.beginPath();
  6408. addToPath(ctx, fontSize);
  6409. if (patternTransform) {
  6410. ctx.setTransform(...patternTransform);
  6411. }
  6412. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  6413. ctx.fill();
  6414. }
  6415. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  6416. ctx.stroke();
  6417. }
  6418. ctx.restore();
  6419. } else {
  6420. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  6421. ctx.fillText(character, x, y);
  6422. }
  6423. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  6424. ctx.strokeText(character, x, y);
  6425. }
  6426. }
  6427. if (isAddToPathSet) {
  6428. const paths = this.pendingTextPaths ||= [];
  6429. paths.push({
  6430. transform: (0, _display_utils.getCurrentTransform)(ctx),
  6431. x,
  6432. y,
  6433. fontSize,
  6434. addToPath
  6435. });
  6436. }
  6437. }
  6438. get isFontSubpixelAAEnabled() {
  6439. const {
  6440. context: ctx
  6441. } = this.cachedCanvases.getCanvas("isFontSubpixelAAEnabled", 10, 10);
  6442. ctx.scale(1.5, 1);
  6443. ctx.fillText("I", 0, 10);
  6444. const data = ctx.getImageData(0, 0, 10, 10).data;
  6445. let enabled = false;
  6446. for (let i = 3; i < data.length; i += 4) {
  6447. if (data[i] > 0 && data[i] < 255) {
  6448. enabled = true;
  6449. break;
  6450. }
  6451. }
  6452. return (0, _util.shadow)(this, "isFontSubpixelAAEnabled", enabled);
  6453. }
  6454. showText(glyphs) {
  6455. const current = this.current;
  6456. const font = current.font;
  6457. if (font.isType3Font) {
  6458. return this.showType3Text(glyphs);
  6459. }
  6460. const fontSize = current.fontSize;
  6461. if (fontSize === 0) {
  6462. return undefined;
  6463. }
  6464. const ctx = this.ctx;
  6465. const fontSizeScale = current.fontSizeScale;
  6466. const charSpacing = current.charSpacing;
  6467. const wordSpacing = current.wordSpacing;
  6468. const fontDirection = current.fontDirection;
  6469. const textHScale = current.textHScale * fontDirection;
  6470. const glyphsLength = glyphs.length;
  6471. const vertical = font.vertical;
  6472. const spacingDir = vertical ? 1 : -1;
  6473. const defaultVMetrics = font.defaultVMetrics;
  6474. const widthAdvanceScale = fontSize * current.fontMatrix[0];
  6475. const simpleFillText = current.textRenderingMode === _util.TextRenderingMode.FILL && !font.disableFontFace && !current.patternFill;
  6476. ctx.save();
  6477. ctx.transform(...current.textMatrix);
  6478. ctx.translate(current.x, current.y + current.textRise);
  6479. if (fontDirection > 0) {
  6480. ctx.scale(textHScale, -1);
  6481. } else {
  6482. ctx.scale(textHScale, 1);
  6483. }
  6484. let patternTransform;
  6485. if (current.patternFill) {
  6486. ctx.save();
  6487. const pattern = current.fillColor.getPattern(ctx, this, (0, _display_utils.getCurrentTransformInverse)(ctx), _pattern_helper.PathType.FILL);
  6488. patternTransform = (0, _display_utils.getCurrentTransform)(ctx);
  6489. ctx.restore();
  6490. ctx.fillStyle = pattern;
  6491. }
  6492. let lineWidth = current.lineWidth;
  6493. const scale = current.textMatrixScale;
  6494. if (scale === 0 || lineWidth === 0) {
  6495. const fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  6496. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  6497. lineWidth = this.getSinglePixelWidth();
  6498. }
  6499. } else {
  6500. lineWidth /= scale;
  6501. }
  6502. if (fontSizeScale !== 1.0) {
  6503. ctx.scale(fontSizeScale, fontSizeScale);
  6504. lineWidth /= fontSizeScale;
  6505. }
  6506. ctx.lineWidth = lineWidth;
  6507. if (font.isInvalidPDFjsFont) {
  6508. const chars = [];
  6509. let width = 0;
  6510. for (const glyph of glyphs) {
  6511. chars.push(glyph.unicode);
  6512. width += glyph.width;
  6513. }
  6514. ctx.fillText(chars.join(""), 0, 0);
  6515. current.x += width * widthAdvanceScale * textHScale;
  6516. ctx.restore();
  6517. this.compose();
  6518. return undefined;
  6519. }
  6520. let x = 0,
  6521. i;
  6522. for (i = 0; i < glyphsLength; ++i) {
  6523. const glyph = glyphs[i];
  6524. if (typeof glyph === "number") {
  6525. x += spacingDir * glyph * fontSize / 1000;
  6526. continue;
  6527. }
  6528. let restoreNeeded = false;
  6529. const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  6530. const character = glyph.fontChar;
  6531. const accent = glyph.accent;
  6532. let scaledX, scaledY;
  6533. let width = glyph.width;
  6534. if (vertical) {
  6535. const vmetric = glyph.vmetric || defaultVMetrics;
  6536. const vx = -(glyph.vmetric ? vmetric[1] : width * 0.5) * widthAdvanceScale;
  6537. const vy = vmetric[2] * widthAdvanceScale;
  6538. width = vmetric ? -vmetric[0] : width;
  6539. scaledX = vx / fontSizeScale;
  6540. scaledY = (x + vy) / fontSizeScale;
  6541. } else {
  6542. scaledX = x / fontSizeScale;
  6543. scaledY = 0;
  6544. }
  6545. if (font.remeasure && width > 0) {
  6546. const measuredWidth = ctx.measureText(character).width * 1000 / fontSize * fontSizeScale;
  6547. if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
  6548. const characterScaleX = width / measuredWidth;
  6549. restoreNeeded = true;
  6550. ctx.save();
  6551. ctx.scale(characterScaleX, 1);
  6552. scaledX /= characterScaleX;
  6553. } else if (width !== measuredWidth) {
  6554. scaledX += (width - measuredWidth) / 2000 * fontSize / fontSizeScale;
  6555. }
  6556. }
  6557. if (this.contentVisible && (glyph.isInFont || font.missingFile)) {
  6558. if (simpleFillText && !accent) {
  6559. ctx.fillText(character, scaledX, scaledY);
  6560. } else {
  6561. this.paintChar(character, scaledX, scaledY, patternTransform);
  6562. if (accent) {
  6563. const scaledAccentX = scaledX + fontSize * accent.offset.x / fontSizeScale;
  6564. const scaledAccentY = scaledY - fontSize * accent.offset.y / fontSizeScale;
  6565. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY, patternTransform);
  6566. }
  6567. }
  6568. }
  6569. let charWidth;
  6570. if (vertical) {
  6571. charWidth = width * widthAdvanceScale - spacing * fontDirection;
  6572. } else {
  6573. charWidth = width * widthAdvanceScale + spacing * fontDirection;
  6574. }
  6575. x += charWidth;
  6576. if (restoreNeeded) {
  6577. ctx.restore();
  6578. }
  6579. }
  6580. if (vertical) {
  6581. current.y -= x;
  6582. } else {
  6583. current.x += x * textHScale;
  6584. }
  6585. ctx.restore();
  6586. this.compose();
  6587. return undefined;
  6588. }
  6589. showType3Text(glyphs) {
  6590. const ctx = this.ctx;
  6591. const current = this.current;
  6592. const font = current.font;
  6593. const fontSize = current.fontSize;
  6594. const fontDirection = current.fontDirection;
  6595. const spacingDir = font.vertical ? 1 : -1;
  6596. const charSpacing = current.charSpacing;
  6597. const wordSpacing = current.wordSpacing;
  6598. const textHScale = current.textHScale * fontDirection;
  6599. const fontMatrix = current.fontMatrix || _util.FONT_IDENTITY_MATRIX;
  6600. const glyphsLength = glyphs.length;
  6601. const isTextInvisible = current.textRenderingMode === _util.TextRenderingMode.INVISIBLE;
  6602. let i, glyph, width, spacingLength;
  6603. if (isTextInvisible || fontSize === 0) {
  6604. return;
  6605. }
  6606. this._cachedScaleForStroking[0] = -1;
  6607. this._cachedGetSinglePixelWidth = null;
  6608. ctx.save();
  6609. ctx.transform(...current.textMatrix);
  6610. ctx.translate(current.x, current.y);
  6611. ctx.scale(textHScale, fontDirection);
  6612. for (i = 0; i < glyphsLength; ++i) {
  6613. glyph = glyphs[i];
  6614. if (typeof glyph === "number") {
  6615. spacingLength = spacingDir * glyph * fontSize / 1000;
  6616. this.ctx.translate(spacingLength, 0);
  6617. current.x += spacingLength * textHScale;
  6618. continue;
  6619. }
  6620. const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  6621. const operatorList = font.charProcOperatorList[glyph.operatorListId];
  6622. if (!operatorList) {
  6623. (0, _util.warn)(`Type3 character "${glyph.operatorListId}" is not available.`);
  6624. continue;
  6625. }
  6626. if (this.contentVisible) {
  6627. this.processingType3 = glyph;
  6628. this.save();
  6629. ctx.scale(fontSize, fontSize);
  6630. ctx.transform(...fontMatrix);
  6631. this.executeOperatorList(operatorList);
  6632. this.restore();
  6633. }
  6634. const transformed = _util.Util.applyTransform([glyph.width, 0], fontMatrix);
  6635. width = transformed[0] * fontSize + spacing;
  6636. ctx.translate(width, 0);
  6637. current.x += width * textHScale;
  6638. }
  6639. ctx.restore();
  6640. this.processingType3 = null;
  6641. }
  6642. setCharWidth(xWidth, yWidth) {}
  6643. setCharWidthAndBounds(xWidth, yWidth, llx, lly, urx, ury) {
  6644. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  6645. this.ctx.clip();
  6646. this.endPath();
  6647. }
  6648. getColorN_Pattern(IR) {
  6649. let pattern;
  6650. if (IR[0] === "TilingPattern") {
  6651. const color = IR[1];
  6652. const baseTransform = this.baseTransform || (0, _display_utils.getCurrentTransform)(this.ctx);
  6653. const canvasGraphicsFactory = {
  6654. createCanvasGraphics: ctx => {
  6655. return new CanvasGraphics(ctx, this.commonObjs, this.objs, this.canvasFactory, this.filterFactory, {
  6656. optionalContentConfig: this.optionalContentConfig,
  6657. markedContentStack: this.markedContentStack
  6658. });
  6659. }
  6660. };
  6661. pattern = new _pattern_helper.TilingPattern(IR, color, this.ctx, canvasGraphicsFactory, baseTransform);
  6662. } else {
  6663. pattern = this._getPattern(IR[1], IR[2]);
  6664. }
  6665. return pattern;
  6666. }
  6667. setStrokeColorN() {
  6668. this.current.strokeColor = this.getColorN_Pattern(arguments);
  6669. }
  6670. setFillColorN() {
  6671. this.current.fillColor = this.getColorN_Pattern(arguments);
  6672. this.current.patternFill = true;
  6673. }
  6674. setStrokeRGBColor(r, g, b) {
  6675. const color = _util.Util.makeHexColor(r, g, b);
  6676. this.ctx.strokeStyle = color;
  6677. this.current.strokeColor = color;
  6678. }
  6679. setFillRGBColor(r, g, b) {
  6680. const color = _util.Util.makeHexColor(r, g, b);
  6681. this.ctx.fillStyle = color;
  6682. this.current.fillColor = color;
  6683. this.current.patternFill = false;
  6684. }
  6685. _getPattern(objId, matrix = null) {
  6686. let pattern;
  6687. if (this.cachedPatterns.has(objId)) {
  6688. pattern = this.cachedPatterns.get(objId);
  6689. } else {
  6690. pattern = (0, _pattern_helper.getShadingPattern)(this.getObject(objId));
  6691. this.cachedPatterns.set(objId, pattern);
  6692. }
  6693. if (matrix) {
  6694. pattern.matrix = matrix;
  6695. }
  6696. return pattern;
  6697. }
  6698. shadingFill(objId) {
  6699. if (!this.contentVisible) {
  6700. return;
  6701. }
  6702. const ctx = this.ctx;
  6703. this.save();
  6704. const pattern = this._getPattern(objId);
  6705. ctx.fillStyle = pattern.getPattern(ctx, this, (0, _display_utils.getCurrentTransformInverse)(ctx), _pattern_helper.PathType.SHADING);
  6706. const inv = (0, _display_utils.getCurrentTransformInverse)(ctx);
  6707. if (inv) {
  6708. const canvas = ctx.canvas;
  6709. const width = canvas.width;
  6710. const height = canvas.height;
  6711. const bl = _util.Util.applyTransform([0, 0], inv);
  6712. const br = _util.Util.applyTransform([0, height], inv);
  6713. const ul = _util.Util.applyTransform([width, 0], inv);
  6714. const ur = _util.Util.applyTransform([width, height], inv);
  6715. const x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  6716. const y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  6717. const x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  6718. const y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  6719. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  6720. } else {
  6721. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  6722. }
  6723. this.compose(this.current.getClippedPathBoundingBox());
  6724. this.restore();
  6725. }
  6726. beginInlineImage() {
  6727. (0, _util.unreachable)("Should not call beginInlineImage");
  6728. }
  6729. beginImageData() {
  6730. (0, _util.unreachable)("Should not call beginImageData");
  6731. }
  6732. paintFormXObjectBegin(matrix, bbox) {
  6733. if (!this.contentVisible) {
  6734. return;
  6735. }
  6736. this.save();
  6737. this.baseTransformStack.push(this.baseTransform);
  6738. if (Array.isArray(matrix) && matrix.length === 6) {
  6739. this.transform(...matrix);
  6740. }
  6741. this.baseTransform = (0, _display_utils.getCurrentTransform)(this.ctx);
  6742. if (bbox) {
  6743. const width = bbox[2] - bbox[0];
  6744. const height = bbox[3] - bbox[1];
  6745. this.ctx.rect(bbox[0], bbox[1], width, height);
  6746. this.current.updateRectMinMax((0, _display_utils.getCurrentTransform)(this.ctx), bbox);
  6747. this.clip();
  6748. this.endPath();
  6749. }
  6750. }
  6751. paintFormXObjectEnd() {
  6752. if (!this.contentVisible) {
  6753. return;
  6754. }
  6755. this.restore();
  6756. this.baseTransform = this.baseTransformStack.pop();
  6757. }
  6758. beginGroup(group) {
  6759. if (!this.contentVisible) {
  6760. return;
  6761. }
  6762. this.save();
  6763. if (this.inSMaskMode) {
  6764. this.endSMaskMode();
  6765. this.current.activeSMask = null;
  6766. }
  6767. const currentCtx = this.ctx;
  6768. if (!group.isolated) {
  6769. (0, _util.info)("TODO: Support non-isolated groups.");
  6770. }
  6771. if (group.knockout) {
  6772. (0, _util.warn)("Knockout groups not supported.");
  6773. }
  6774. const currentTransform = (0, _display_utils.getCurrentTransform)(currentCtx);
  6775. if (group.matrix) {
  6776. currentCtx.transform(...group.matrix);
  6777. }
  6778. if (!group.bbox) {
  6779. throw new Error("Bounding box is required.");
  6780. }
  6781. let bounds = _util.Util.getAxialAlignedBoundingBox(group.bbox, (0, _display_utils.getCurrentTransform)(currentCtx));
  6782. const canvasBounds = [0, 0, currentCtx.canvas.width, currentCtx.canvas.height];
  6783. bounds = _util.Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  6784. const offsetX = Math.floor(bounds[0]);
  6785. const offsetY = Math.floor(bounds[1]);
  6786. let drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  6787. let drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  6788. let scaleX = 1,
  6789. scaleY = 1;
  6790. if (drawnWidth > MAX_GROUP_SIZE) {
  6791. scaleX = drawnWidth / MAX_GROUP_SIZE;
  6792. drawnWidth = MAX_GROUP_SIZE;
  6793. }
  6794. if (drawnHeight > MAX_GROUP_SIZE) {
  6795. scaleY = drawnHeight / MAX_GROUP_SIZE;
  6796. drawnHeight = MAX_GROUP_SIZE;
  6797. }
  6798. this.current.startNewPathAndClipBox([0, 0, drawnWidth, drawnHeight]);
  6799. let cacheId = "groupAt" + this.groupLevel;
  6800. if (group.smask) {
  6801. cacheId += "_smask_" + this.smaskCounter++ % 2;
  6802. }
  6803. const scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight);
  6804. const groupCtx = scratchCanvas.context;
  6805. groupCtx.scale(1 / scaleX, 1 / scaleY);
  6806. groupCtx.translate(-offsetX, -offsetY);
  6807. groupCtx.transform(...currentTransform);
  6808. if (group.smask) {
  6809. this.smaskStack.push({
  6810. canvas: scratchCanvas.canvas,
  6811. context: groupCtx,
  6812. offsetX,
  6813. offsetY,
  6814. scaleX,
  6815. scaleY,
  6816. subtype: group.smask.subtype,
  6817. backdrop: group.smask.backdrop,
  6818. transferMap: group.smask.transferMap || null,
  6819. startTransformInverse: null
  6820. });
  6821. } else {
  6822. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  6823. currentCtx.translate(offsetX, offsetY);
  6824. currentCtx.scale(scaleX, scaleY);
  6825. currentCtx.save();
  6826. }
  6827. copyCtxState(currentCtx, groupCtx);
  6828. this.ctx = groupCtx;
  6829. this.setGState([["BM", "source-over"], ["ca", 1], ["CA", 1]]);
  6830. this.groupStack.push(currentCtx);
  6831. this.groupLevel++;
  6832. }
  6833. endGroup(group) {
  6834. if (!this.contentVisible) {
  6835. return;
  6836. }
  6837. this.groupLevel--;
  6838. const groupCtx = this.ctx;
  6839. const ctx = this.groupStack.pop();
  6840. this.ctx = ctx;
  6841. this.ctx.imageSmoothingEnabled = false;
  6842. if (group.smask) {
  6843. this.tempSMask = this.smaskStack.pop();
  6844. this.restore();
  6845. } else {
  6846. this.ctx.restore();
  6847. const currentMtx = (0, _display_utils.getCurrentTransform)(this.ctx);
  6848. this.restore();
  6849. this.ctx.save();
  6850. this.ctx.setTransform(...currentMtx);
  6851. const dirtyBox = _util.Util.getAxialAlignedBoundingBox([0, 0, groupCtx.canvas.width, groupCtx.canvas.height], currentMtx);
  6852. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  6853. this.ctx.restore();
  6854. this.compose(dirtyBox);
  6855. }
  6856. }
  6857. beginAnnotation(id, rect, transform, matrix, hasOwnCanvas) {
  6858. this.#restoreInitialState();
  6859. resetCtxToDefault(this.ctx);
  6860. this.ctx.save();
  6861. this.save();
  6862. if (this.baseTransform) {
  6863. this.ctx.setTransform(...this.baseTransform);
  6864. }
  6865. if (Array.isArray(rect) && rect.length === 4) {
  6866. const width = rect[2] - rect[0];
  6867. const height = rect[3] - rect[1];
  6868. if (hasOwnCanvas && this.annotationCanvasMap) {
  6869. transform = transform.slice();
  6870. transform[4] -= rect[0];
  6871. transform[5] -= rect[1];
  6872. rect = rect.slice();
  6873. rect[0] = rect[1] = 0;
  6874. rect[2] = width;
  6875. rect[3] = height;
  6876. const [scaleX, scaleY] = _util.Util.singularValueDecompose2dScale((0, _display_utils.getCurrentTransform)(this.ctx));
  6877. const {
  6878. viewportScale
  6879. } = this;
  6880. const canvasWidth = Math.ceil(width * this.outputScaleX * viewportScale);
  6881. const canvasHeight = Math.ceil(height * this.outputScaleY * viewportScale);
  6882. this.annotationCanvas = this.canvasFactory.create(canvasWidth, canvasHeight);
  6883. const {
  6884. canvas,
  6885. context
  6886. } = this.annotationCanvas;
  6887. this.annotationCanvasMap.set(id, canvas);
  6888. this.annotationCanvas.savedCtx = this.ctx;
  6889. this.ctx = context;
  6890. this.ctx.save();
  6891. this.ctx.setTransform(scaleX, 0, 0, -scaleY, 0, height * scaleY);
  6892. resetCtxToDefault(this.ctx);
  6893. } else {
  6894. resetCtxToDefault(this.ctx);
  6895. this.ctx.rect(rect[0], rect[1], width, height);
  6896. this.ctx.clip();
  6897. this.endPath();
  6898. }
  6899. }
  6900. this.current = new CanvasExtraState(this.ctx.canvas.width, this.ctx.canvas.height);
  6901. this.transform(...transform);
  6902. this.transform(...matrix);
  6903. }
  6904. endAnnotation() {
  6905. if (this.annotationCanvas) {
  6906. this.ctx.restore();
  6907. this.#drawFilter();
  6908. this.ctx = this.annotationCanvas.savedCtx;
  6909. delete this.annotationCanvas.savedCtx;
  6910. delete this.annotationCanvas;
  6911. }
  6912. }
  6913. paintImageMaskXObject(img) {
  6914. if (!this.contentVisible) {
  6915. return;
  6916. }
  6917. const count = img.count;
  6918. img = this.getObject(img.data, img);
  6919. img.count = count;
  6920. const ctx = this.ctx;
  6921. const glyph = this.processingType3;
  6922. if (glyph) {
  6923. if (glyph.compiled === undefined) {
  6924. glyph.compiled = compileType3Glyph(img);
  6925. }
  6926. if (glyph.compiled) {
  6927. glyph.compiled(ctx);
  6928. return;
  6929. }
  6930. }
  6931. const mask = this._createMaskCanvas(img);
  6932. const maskCanvas = mask.canvas;
  6933. ctx.save();
  6934. ctx.setTransform(1, 0, 0, 1, 0, 0);
  6935. ctx.drawImage(maskCanvas, mask.offsetX, mask.offsetY);
  6936. ctx.restore();
  6937. this.compose();
  6938. }
  6939. paintImageMaskXObjectRepeat(img, scaleX, skewX = 0, skewY = 0, scaleY, positions) {
  6940. if (!this.contentVisible) {
  6941. return;
  6942. }
  6943. img = this.getObject(img.data, img);
  6944. const ctx = this.ctx;
  6945. ctx.save();
  6946. const currentTransform = (0, _display_utils.getCurrentTransform)(ctx);
  6947. ctx.transform(scaleX, skewX, skewY, scaleY, 0, 0);
  6948. const mask = this._createMaskCanvas(img);
  6949. ctx.setTransform(1, 0, 0, 1, mask.offsetX - currentTransform[4], mask.offsetY - currentTransform[5]);
  6950. for (let i = 0, ii = positions.length; i < ii; i += 2) {
  6951. const trans = _util.Util.transform(currentTransform, [scaleX, skewX, skewY, scaleY, positions[i], positions[i + 1]]);
  6952. const [x, y] = _util.Util.applyTransform([0, 0], trans);
  6953. ctx.drawImage(mask.canvas, x, y);
  6954. }
  6955. ctx.restore();
  6956. this.compose();
  6957. }
  6958. paintImageMaskXObjectGroup(images) {
  6959. if (!this.contentVisible) {
  6960. return;
  6961. }
  6962. const ctx = this.ctx;
  6963. const fillColor = this.current.fillColor;
  6964. const isPatternFill = this.current.patternFill;
  6965. for (const image of images) {
  6966. const {
  6967. data,
  6968. width,
  6969. height,
  6970. transform
  6971. } = image;
  6972. const maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
  6973. const maskCtx = maskCanvas.context;
  6974. maskCtx.save();
  6975. const img = this.getObject(data, image);
  6976. putBinaryImageMask(maskCtx, img);
  6977. maskCtx.globalCompositeOperation = "source-in";
  6978. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this, (0, _display_utils.getCurrentTransformInverse)(ctx), _pattern_helper.PathType.FILL) : fillColor;
  6979. maskCtx.fillRect(0, 0, width, height);
  6980. maskCtx.restore();
  6981. ctx.save();
  6982. ctx.transform(...transform);
  6983. ctx.scale(1, -1);
  6984. drawImageAtIntegerCoords(ctx, maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1);
  6985. ctx.restore();
  6986. }
  6987. this.compose();
  6988. }
  6989. paintImageXObject(objId) {
  6990. if (!this.contentVisible) {
  6991. return;
  6992. }
  6993. const imgData = this.getObject(objId);
  6994. if (!imgData) {
  6995. (0, _util.warn)("Dependent image isn't ready yet");
  6996. return;
  6997. }
  6998. this.paintInlineImageXObject(imgData);
  6999. }
  7000. paintImageXObjectRepeat(objId, scaleX, scaleY, positions) {
  7001. if (!this.contentVisible) {
  7002. return;
  7003. }
  7004. const imgData = this.getObject(objId);
  7005. if (!imgData) {
  7006. (0, _util.warn)("Dependent image isn't ready yet");
  7007. return;
  7008. }
  7009. const width = imgData.width;
  7010. const height = imgData.height;
  7011. const map = [];
  7012. for (let i = 0, ii = positions.length; i < ii; i += 2) {
  7013. map.push({
  7014. transform: [scaleX, 0, 0, scaleY, positions[i], positions[i + 1]],
  7015. x: 0,
  7016. y: 0,
  7017. w: width,
  7018. h: height
  7019. });
  7020. }
  7021. this.paintInlineImageXObjectGroup(imgData, map);
  7022. }
  7023. applyTransferMapsToCanvas(ctx) {
  7024. if (this.current.transferMaps !== "none") {
  7025. ctx.filter = this.current.transferMaps;
  7026. ctx.drawImage(ctx.canvas, 0, 0);
  7027. ctx.filter = "none";
  7028. }
  7029. return ctx.canvas;
  7030. }
  7031. applyTransferMapsToBitmap(imgData) {
  7032. if (this.current.transferMaps === "none") {
  7033. return imgData.bitmap;
  7034. }
  7035. const {
  7036. bitmap,
  7037. width,
  7038. height
  7039. } = imgData;
  7040. const tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", width, height);
  7041. const tmpCtx = tmpCanvas.context;
  7042. tmpCtx.filter = this.current.transferMaps;
  7043. tmpCtx.drawImage(bitmap, 0, 0);
  7044. tmpCtx.filter = "none";
  7045. return tmpCanvas.canvas;
  7046. }
  7047. paintInlineImageXObject(imgData) {
  7048. if (!this.contentVisible) {
  7049. return;
  7050. }
  7051. const width = imgData.width;
  7052. const height = imgData.height;
  7053. const ctx = this.ctx;
  7054. this.save();
  7055. if (!_is_node.isNodeJS) {
  7056. ctx.filter = "none";
  7057. }
  7058. ctx.scale(1 / width, -1 / height);
  7059. let imgToPaint;
  7060. if (imgData.bitmap) {
  7061. imgToPaint = this.applyTransferMapsToBitmap(imgData);
  7062. } else if (typeof HTMLElement === "function" && imgData instanceof HTMLElement || !imgData.data) {
  7063. imgToPaint = imgData;
  7064. } else {
  7065. const tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", width, height);
  7066. const tmpCtx = tmpCanvas.context;
  7067. putBinaryImageData(tmpCtx, imgData);
  7068. imgToPaint = this.applyTransferMapsToCanvas(tmpCtx);
  7069. }
  7070. const scaled = this._scaleImage(imgToPaint, (0, _display_utils.getCurrentTransformInverse)(ctx));
  7071. ctx.imageSmoothingEnabled = getImageSmoothingEnabled((0, _display_utils.getCurrentTransform)(ctx), imgData.interpolate);
  7072. drawImageAtIntegerCoords(ctx, scaled.img, 0, 0, scaled.paintWidth, scaled.paintHeight, 0, -height, width, height);
  7073. this.compose();
  7074. this.restore();
  7075. }
  7076. paintInlineImageXObjectGroup(imgData, map) {
  7077. if (!this.contentVisible) {
  7078. return;
  7079. }
  7080. const ctx = this.ctx;
  7081. let imgToPaint;
  7082. if (imgData.bitmap) {
  7083. imgToPaint = imgData.bitmap;
  7084. } else {
  7085. const w = imgData.width;
  7086. const h = imgData.height;
  7087. const tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", w, h);
  7088. const tmpCtx = tmpCanvas.context;
  7089. putBinaryImageData(tmpCtx, imgData);
  7090. imgToPaint = this.applyTransferMapsToCanvas(tmpCtx);
  7091. }
  7092. for (const entry of map) {
  7093. ctx.save();
  7094. ctx.transform(...entry.transform);
  7095. ctx.scale(1, -1);
  7096. drawImageAtIntegerCoords(ctx, imgToPaint, entry.x, entry.y, entry.w, entry.h, 0, -1, 1, 1);
  7097. ctx.restore();
  7098. }
  7099. this.compose();
  7100. }
  7101. paintSolidColorImageMask() {
  7102. if (!this.contentVisible) {
  7103. return;
  7104. }
  7105. this.ctx.fillRect(0, 0, 1, 1);
  7106. this.compose();
  7107. }
  7108. markPoint(tag) {}
  7109. markPointProps(tag, properties) {}
  7110. beginMarkedContent(tag) {
  7111. this.markedContentStack.push({
  7112. visible: true
  7113. });
  7114. }
  7115. beginMarkedContentProps(tag, properties) {
  7116. if (tag === "OC") {
  7117. this.markedContentStack.push({
  7118. visible: this.optionalContentConfig.isVisible(properties)
  7119. });
  7120. } else {
  7121. this.markedContentStack.push({
  7122. visible: true
  7123. });
  7124. }
  7125. this.contentVisible = this.isContentVisible();
  7126. }
  7127. endMarkedContent() {
  7128. this.markedContentStack.pop();
  7129. this.contentVisible = this.isContentVisible();
  7130. }
  7131. beginCompat() {}
  7132. endCompat() {}
  7133. consumePath(clipBox) {
  7134. const isEmpty = this.current.isEmptyClip();
  7135. if (this.pendingClip) {
  7136. this.current.updateClipFromPath();
  7137. }
  7138. if (!this.pendingClip) {
  7139. this.compose(clipBox);
  7140. }
  7141. const ctx = this.ctx;
  7142. if (this.pendingClip) {
  7143. if (!isEmpty) {
  7144. if (this.pendingClip === EO_CLIP) {
  7145. ctx.clip("evenodd");
  7146. } else {
  7147. ctx.clip();
  7148. }
  7149. }
  7150. this.pendingClip = null;
  7151. }
  7152. this.current.startNewPathAndClipBox(this.current.clipBox);
  7153. ctx.beginPath();
  7154. }
  7155. getSinglePixelWidth() {
  7156. if (!this._cachedGetSinglePixelWidth) {
  7157. const m = (0, _display_utils.getCurrentTransform)(this.ctx);
  7158. if (m[1] === 0 && m[2] === 0) {
  7159. this._cachedGetSinglePixelWidth = 1 / Math.min(Math.abs(m[0]), Math.abs(m[3]));
  7160. } else {
  7161. const absDet = Math.abs(m[0] * m[3] - m[2] * m[1]);
  7162. const normX = Math.hypot(m[0], m[2]);
  7163. const normY = Math.hypot(m[1], m[3]);
  7164. this._cachedGetSinglePixelWidth = Math.max(normX, normY) / absDet;
  7165. }
  7166. }
  7167. return this._cachedGetSinglePixelWidth;
  7168. }
  7169. getScaleForStroking() {
  7170. if (this._cachedScaleForStroking[0] === -1) {
  7171. const {
  7172. lineWidth
  7173. } = this.current;
  7174. const {
  7175. a,
  7176. b,
  7177. c,
  7178. d
  7179. } = this.ctx.getTransform();
  7180. let scaleX, scaleY;
  7181. if (b === 0 && c === 0) {
  7182. const normX = Math.abs(a);
  7183. const normY = Math.abs(d);
  7184. if (normX === normY) {
  7185. if (lineWidth === 0) {
  7186. scaleX = scaleY = 1 / normX;
  7187. } else {
  7188. const scaledLineWidth = normX * lineWidth;
  7189. scaleX = scaleY = scaledLineWidth < 1 ? 1 / scaledLineWidth : 1;
  7190. }
  7191. } else if (lineWidth === 0) {
  7192. scaleX = 1 / normX;
  7193. scaleY = 1 / normY;
  7194. } else {
  7195. const scaledXLineWidth = normX * lineWidth;
  7196. const scaledYLineWidth = normY * lineWidth;
  7197. scaleX = scaledXLineWidth < 1 ? 1 / scaledXLineWidth : 1;
  7198. scaleY = scaledYLineWidth < 1 ? 1 / scaledYLineWidth : 1;
  7199. }
  7200. } else {
  7201. const absDet = Math.abs(a * d - b * c);
  7202. const normX = Math.hypot(a, b);
  7203. const normY = Math.hypot(c, d);
  7204. if (lineWidth === 0) {
  7205. scaleX = normY / absDet;
  7206. scaleY = normX / absDet;
  7207. } else {
  7208. const baseArea = lineWidth * absDet;
  7209. scaleX = normY > baseArea ? normY / baseArea : 1;
  7210. scaleY = normX > baseArea ? normX / baseArea : 1;
  7211. }
  7212. }
  7213. this._cachedScaleForStroking[0] = scaleX;
  7214. this._cachedScaleForStroking[1] = scaleY;
  7215. }
  7216. return this._cachedScaleForStroking;
  7217. }
  7218. rescaleAndStroke(saveRestore) {
  7219. const {
  7220. ctx
  7221. } = this;
  7222. const {
  7223. lineWidth
  7224. } = this.current;
  7225. const [scaleX, scaleY] = this.getScaleForStroking();
  7226. ctx.lineWidth = lineWidth || 1;
  7227. if (scaleX === 1 && scaleY === 1) {
  7228. ctx.stroke();
  7229. return;
  7230. }
  7231. const dashes = ctx.getLineDash();
  7232. if (saveRestore) {
  7233. ctx.save();
  7234. }
  7235. ctx.scale(scaleX, scaleY);
  7236. if (dashes.length > 0) {
  7237. const scale = Math.max(scaleX, scaleY);
  7238. ctx.setLineDash(dashes.map(x => x / scale));
  7239. ctx.lineDashOffset /= scale;
  7240. }
  7241. ctx.stroke();
  7242. if (saveRestore) {
  7243. ctx.restore();
  7244. }
  7245. }
  7246. isContentVisible() {
  7247. for (let i = this.markedContentStack.length - 1; i >= 0; i--) {
  7248. if (!this.markedContentStack[i].visible) {
  7249. return false;
  7250. }
  7251. }
  7252. return true;
  7253. }
  7254. }
  7255. exports.CanvasGraphics = CanvasGraphics;
  7256. for (const op in _util.OPS) {
  7257. if (CanvasGraphics.prototype[op] !== undefined) {
  7258. CanvasGraphics.prototype[_util.OPS[op]] = CanvasGraphics.prototype[op];
  7259. }
  7260. }
  7261. /***/ }),
  7262. /* 12 */
  7263. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  7264. Object.defineProperty(exports, "__esModule", ({
  7265. value: true
  7266. }));
  7267. exports.TilingPattern = exports.PathType = void 0;
  7268. exports.getShadingPattern = getShadingPattern;
  7269. var _util = __w_pdfjs_require__(1);
  7270. var _display_utils = __w_pdfjs_require__(6);
  7271. const PathType = {
  7272. FILL: "Fill",
  7273. STROKE: "Stroke",
  7274. SHADING: "Shading"
  7275. };
  7276. exports.PathType = PathType;
  7277. function applyBoundingBox(ctx, bbox) {
  7278. if (!bbox) {
  7279. return;
  7280. }
  7281. const width = bbox[2] - bbox[0];
  7282. const height = bbox[3] - bbox[1];
  7283. const region = new Path2D();
  7284. region.rect(bbox[0], bbox[1], width, height);
  7285. ctx.clip(region);
  7286. }
  7287. class BaseShadingPattern {
  7288. constructor() {
  7289. if (this.constructor === BaseShadingPattern) {
  7290. (0, _util.unreachable)("Cannot initialize BaseShadingPattern.");
  7291. }
  7292. }
  7293. getPattern() {
  7294. (0, _util.unreachable)("Abstract method `getPattern` called.");
  7295. }
  7296. }
  7297. class RadialAxialShadingPattern extends BaseShadingPattern {
  7298. constructor(IR) {
  7299. super();
  7300. this._type = IR[1];
  7301. this._bbox = IR[2];
  7302. this._colorStops = IR[3];
  7303. this._p0 = IR[4];
  7304. this._p1 = IR[5];
  7305. this._r0 = IR[6];
  7306. this._r1 = IR[7];
  7307. this.matrix = null;
  7308. }
  7309. _createGradient(ctx) {
  7310. let grad;
  7311. if (this._type === "axial") {
  7312. grad = ctx.createLinearGradient(this._p0[0], this._p0[1], this._p1[0], this._p1[1]);
  7313. } else if (this._type === "radial") {
  7314. grad = ctx.createRadialGradient(this._p0[0], this._p0[1], this._r0, this._p1[0], this._p1[1], this._r1);
  7315. }
  7316. for (const colorStop of this._colorStops) {
  7317. grad.addColorStop(colorStop[0], colorStop[1]);
  7318. }
  7319. return grad;
  7320. }
  7321. getPattern(ctx, owner, inverse, pathType) {
  7322. let pattern;
  7323. if (pathType === PathType.STROKE || pathType === PathType.FILL) {
  7324. const ownerBBox = owner.current.getClippedPathBoundingBox(pathType, (0, _display_utils.getCurrentTransform)(ctx)) || [0, 0, 0, 0];
  7325. const width = Math.ceil(ownerBBox[2] - ownerBBox[0]) || 1;
  7326. const height = Math.ceil(ownerBBox[3] - ownerBBox[1]) || 1;
  7327. const tmpCanvas = owner.cachedCanvases.getCanvas("pattern", width, height, true);
  7328. const tmpCtx = tmpCanvas.context;
  7329. tmpCtx.clearRect(0, 0, tmpCtx.canvas.width, tmpCtx.canvas.height);
  7330. tmpCtx.beginPath();
  7331. tmpCtx.rect(0, 0, tmpCtx.canvas.width, tmpCtx.canvas.height);
  7332. tmpCtx.translate(-ownerBBox[0], -ownerBBox[1]);
  7333. inverse = _util.Util.transform(inverse, [1, 0, 0, 1, ownerBBox[0], ownerBBox[1]]);
  7334. tmpCtx.transform(...owner.baseTransform);
  7335. if (this.matrix) {
  7336. tmpCtx.transform(...this.matrix);
  7337. }
  7338. applyBoundingBox(tmpCtx, this._bbox);
  7339. tmpCtx.fillStyle = this._createGradient(tmpCtx);
  7340. tmpCtx.fill();
  7341. pattern = ctx.createPattern(tmpCanvas.canvas, "no-repeat");
  7342. const domMatrix = new DOMMatrix(inverse);
  7343. pattern.setTransform(domMatrix);
  7344. } else {
  7345. applyBoundingBox(ctx, this._bbox);
  7346. pattern = this._createGradient(ctx);
  7347. }
  7348. return pattern;
  7349. }
  7350. }
  7351. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  7352. const coords = context.coords,
  7353. colors = context.colors;
  7354. const bytes = data.data,
  7355. rowSize = data.width * 4;
  7356. let tmp;
  7357. if (coords[p1 + 1] > coords[p2 + 1]) {
  7358. tmp = p1;
  7359. p1 = p2;
  7360. p2 = tmp;
  7361. tmp = c1;
  7362. c1 = c2;
  7363. c2 = tmp;
  7364. }
  7365. if (coords[p2 + 1] > coords[p3 + 1]) {
  7366. tmp = p2;
  7367. p2 = p3;
  7368. p3 = tmp;
  7369. tmp = c2;
  7370. c2 = c3;
  7371. c3 = tmp;
  7372. }
  7373. if (coords[p1 + 1] > coords[p2 + 1]) {
  7374. tmp = p1;
  7375. p1 = p2;
  7376. p2 = tmp;
  7377. tmp = c1;
  7378. c1 = c2;
  7379. c2 = tmp;
  7380. }
  7381. const x1 = (coords[p1] + context.offsetX) * context.scaleX;
  7382. const y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  7383. const x2 = (coords[p2] + context.offsetX) * context.scaleX;
  7384. const y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  7385. const x3 = (coords[p3] + context.offsetX) * context.scaleX;
  7386. const y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  7387. if (y1 >= y3) {
  7388. return;
  7389. }
  7390. const c1r = colors[c1],
  7391. c1g = colors[c1 + 1],
  7392. c1b = colors[c1 + 2];
  7393. const c2r = colors[c2],
  7394. c2g = colors[c2 + 1],
  7395. c2b = colors[c2 + 2];
  7396. const c3r = colors[c3],
  7397. c3g = colors[c3 + 1],
  7398. c3b = colors[c3 + 2];
  7399. const minY = Math.round(y1),
  7400. maxY = Math.round(y3);
  7401. let xa, car, cag, cab;
  7402. let xb, cbr, cbg, cbb;
  7403. for (let y = minY; y <= maxY; y++) {
  7404. if (y < y2) {
  7405. let k;
  7406. if (y < y1) {
  7407. k = 0;
  7408. } else {
  7409. k = (y1 - y) / (y1 - y2);
  7410. }
  7411. xa = x1 - (x1 - x2) * k;
  7412. car = c1r - (c1r - c2r) * k;
  7413. cag = c1g - (c1g - c2g) * k;
  7414. cab = c1b - (c1b - c2b) * k;
  7415. } else {
  7416. let k;
  7417. if (y > y3) {
  7418. k = 1;
  7419. } else if (y2 === y3) {
  7420. k = 0;
  7421. } else {
  7422. k = (y2 - y) / (y2 - y3);
  7423. }
  7424. xa = x2 - (x2 - x3) * k;
  7425. car = c2r - (c2r - c3r) * k;
  7426. cag = c2g - (c2g - c3g) * k;
  7427. cab = c2b - (c2b - c3b) * k;
  7428. }
  7429. let k;
  7430. if (y < y1) {
  7431. k = 0;
  7432. } else if (y > y3) {
  7433. k = 1;
  7434. } else {
  7435. k = (y1 - y) / (y1 - y3);
  7436. }
  7437. xb = x1 - (x1 - x3) * k;
  7438. cbr = c1r - (c1r - c3r) * k;
  7439. cbg = c1g - (c1g - c3g) * k;
  7440. cbb = c1b - (c1b - c3b) * k;
  7441. const x1_ = Math.round(Math.min(xa, xb));
  7442. const x2_ = Math.round(Math.max(xa, xb));
  7443. let j = rowSize * y + x1_ * 4;
  7444. for (let x = x1_; x <= x2_; x++) {
  7445. k = (xa - x) / (xa - xb);
  7446. if (k < 0) {
  7447. k = 0;
  7448. } else if (k > 1) {
  7449. k = 1;
  7450. }
  7451. bytes[j++] = car - (car - cbr) * k | 0;
  7452. bytes[j++] = cag - (cag - cbg) * k | 0;
  7453. bytes[j++] = cab - (cab - cbb) * k | 0;
  7454. bytes[j++] = 255;
  7455. }
  7456. }
  7457. }
  7458. function drawFigure(data, figure, context) {
  7459. const ps = figure.coords;
  7460. const cs = figure.colors;
  7461. let i, ii;
  7462. switch (figure.type) {
  7463. case "lattice":
  7464. const verticesPerRow = figure.verticesPerRow;
  7465. const rows = Math.floor(ps.length / verticesPerRow) - 1;
  7466. const cols = verticesPerRow - 1;
  7467. for (i = 0; i < rows; i++) {
  7468. let q = i * verticesPerRow;
  7469. for (let j = 0; j < cols; j++, q++) {
  7470. drawTriangle(data, context, ps[q], ps[q + 1], ps[q + verticesPerRow], cs[q], cs[q + 1], cs[q + verticesPerRow]);
  7471. drawTriangle(data, context, ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow], cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  7472. }
  7473. }
  7474. break;
  7475. case "triangles":
  7476. for (i = 0, ii = ps.length; i < ii; i += 3) {
  7477. drawTriangle(data, context, ps[i], ps[i + 1], ps[i + 2], cs[i], cs[i + 1], cs[i + 2]);
  7478. }
  7479. break;
  7480. default:
  7481. throw new Error("illegal figure");
  7482. }
  7483. }
  7484. class MeshShadingPattern extends BaseShadingPattern {
  7485. constructor(IR) {
  7486. super();
  7487. this._coords = IR[2];
  7488. this._colors = IR[3];
  7489. this._figures = IR[4];
  7490. this._bounds = IR[5];
  7491. this._bbox = IR[7];
  7492. this._background = IR[8];
  7493. this.matrix = null;
  7494. }
  7495. _createMeshCanvas(combinedScale, backgroundColor, cachedCanvases) {
  7496. const EXPECTED_SCALE = 1.1;
  7497. const MAX_PATTERN_SIZE = 3000;
  7498. const BORDER_SIZE = 2;
  7499. const offsetX = Math.floor(this._bounds[0]);
  7500. const offsetY = Math.floor(this._bounds[1]);
  7501. const boundsWidth = Math.ceil(this._bounds[2]) - offsetX;
  7502. const boundsHeight = Math.ceil(this._bounds[3]) - offsetY;
  7503. const width = Math.min(Math.ceil(Math.abs(boundsWidth * combinedScale[0] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  7504. const height = Math.min(Math.ceil(Math.abs(boundsHeight * combinedScale[1] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  7505. const scaleX = boundsWidth / width;
  7506. const scaleY = boundsHeight / height;
  7507. const context = {
  7508. coords: this._coords,
  7509. colors: this._colors,
  7510. offsetX: -offsetX,
  7511. offsetY: -offsetY,
  7512. scaleX: 1 / scaleX,
  7513. scaleY: 1 / scaleY
  7514. };
  7515. const paddedWidth = width + BORDER_SIZE * 2;
  7516. const paddedHeight = height + BORDER_SIZE * 2;
  7517. const tmpCanvas = cachedCanvases.getCanvas("mesh", paddedWidth, paddedHeight, false);
  7518. const tmpCtx = tmpCanvas.context;
  7519. const data = tmpCtx.createImageData(width, height);
  7520. if (backgroundColor) {
  7521. const bytes = data.data;
  7522. for (let i = 0, ii = bytes.length; i < ii; i += 4) {
  7523. bytes[i] = backgroundColor[0];
  7524. bytes[i + 1] = backgroundColor[1];
  7525. bytes[i + 2] = backgroundColor[2];
  7526. bytes[i + 3] = 255;
  7527. }
  7528. }
  7529. for (const figure of this._figures) {
  7530. drawFigure(data, figure, context);
  7531. }
  7532. tmpCtx.putImageData(data, BORDER_SIZE, BORDER_SIZE);
  7533. const canvas = tmpCanvas.canvas;
  7534. return {
  7535. canvas,
  7536. offsetX: offsetX - BORDER_SIZE * scaleX,
  7537. offsetY: offsetY - BORDER_SIZE * scaleY,
  7538. scaleX,
  7539. scaleY
  7540. };
  7541. }
  7542. getPattern(ctx, owner, inverse, pathType) {
  7543. applyBoundingBox(ctx, this._bbox);
  7544. let scale;
  7545. if (pathType === PathType.SHADING) {
  7546. scale = _util.Util.singularValueDecompose2dScale((0, _display_utils.getCurrentTransform)(ctx));
  7547. } else {
  7548. scale = _util.Util.singularValueDecompose2dScale(owner.baseTransform);
  7549. if (this.matrix) {
  7550. const matrixScale = _util.Util.singularValueDecompose2dScale(this.matrix);
  7551. scale = [scale[0] * matrixScale[0], scale[1] * matrixScale[1]];
  7552. }
  7553. }
  7554. const temporaryPatternCanvas = this._createMeshCanvas(scale, pathType === PathType.SHADING ? null : this._background, owner.cachedCanvases);
  7555. if (pathType !== PathType.SHADING) {
  7556. ctx.setTransform(...owner.baseTransform);
  7557. if (this.matrix) {
  7558. ctx.transform(...this.matrix);
  7559. }
  7560. }
  7561. ctx.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY);
  7562. ctx.scale(temporaryPatternCanvas.scaleX, temporaryPatternCanvas.scaleY);
  7563. return ctx.createPattern(temporaryPatternCanvas.canvas, "no-repeat");
  7564. }
  7565. }
  7566. class DummyShadingPattern extends BaseShadingPattern {
  7567. getPattern() {
  7568. return "hotpink";
  7569. }
  7570. }
  7571. function getShadingPattern(IR) {
  7572. switch (IR[0]) {
  7573. case "RadialAxial":
  7574. return new RadialAxialShadingPattern(IR);
  7575. case "Mesh":
  7576. return new MeshShadingPattern(IR);
  7577. case "Dummy":
  7578. return new DummyShadingPattern();
  7579. }
  7580. throw new Error(`Unknown IR type: ${IR[0]}`);
  7581. }
  7582. const PaintType = {
  7583. COLORED: 1,
  7584. UNCOLORED: 2
  7585. };
  7586. class TilingPattern {
  7587. static MAX_PATTERN_SIZE = 3000;
  7588. constructor(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
  7589. this.operatorList = IR[2];
  7590. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  7591. this.bbox = IR[4];
  7592. this.xstep = IR[5];
  7593. this.ystep = IR[6];
  7594. this.paintType = IR[7];
  7595. this.tilingType = IR[8];
  7596. this.color = color;
  7597. this.ctx = ctx;
  7598. this.canvasGraphicsFactory = canvasGraphicsFactory;
  7599. this.baseTransform = baseTransform;
  7600. }
  7601. createPatternCanvas(owner) {
  7602. const operatorList = this.operatorList;
  7603. const bbox = this.bbox;
  7604. const xstep = this.xstep;
  7605. const ystep = this.ystep;
  7606. const paintType = this.paintType;
  7607. const tilingType = this.tilingType;
  7608. const color = this.color;
  7609. const canvasGraphicsFactory = this.canvasGraphicsFactory;
  7610. (0, _util.info)("TilingType: " + tilingType);
  7611. const x0 = bbox[0],
  7612. y0 = bbox[1],
  7613. x1 = bbox[2],
  7614. y1 = bbox[3];
  7615. const matrixScale = _util.Util.singularValueDecompose2dScale(this.matrix);
  7616. const curMatrixScale = _util.Util.singularValueDecompose2dScale(this.baseTransform);
  7617. const combinedScale = [matrixScale[0] * curMatrixScale[0], matrixScale[1] * curMatrixScale[1]];
  7618. const dimx = this.getSizeAndScale(xstep, this.ctx.canvas.width, combinedScale[0]);
  7619. const dimy = this.getSizeAndScale(ystep, this.ctx.canvas.height, combinedScale[1]);
  7620. const tmpCanvas = owner.cachedCanvases.getCanvas("pattern", dimx.size, dimy.size, true);
  7621. const tmpCtx = tmpCanvas.context;
  7622. const graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
  7623. graphics.groupLevel = owner.groupLevel;
  7624. this.setFillAndStrokeStyleToContext(graphics, paintType, color);
  7625. let adjustedX0 = x0;
  7626. let adjustedY0 = y0;
  7627. let adjustedX1 = x1;
  7628. let adjustedY1 = y1;
  7629. if (x0 < 0) {
  7630. adjustedX0 = 0;
  7631. adjustedX1 += Math.abs(x0);
  7632. }
  7633. if (y0 < 0) {
  7634. adjustedY0 = 0;
  7635. adjustedY1 += Math.abs(y0);
  7636. }
  7637. tmpCtx.translate(-(dimx.scale * adjustedX0), -(dimy.scale * adjustedY0));
  7638. graphics.transform(dimx.scale, 0, 0, dimy.scale, 0, 0);
  7639. tmpCtx.save();
  7640. this.clipBbox(graphics, adjustedX0, adjustedY0, adjustedX1, adjustedY1);
  7641. graphics.baseTransform = (0, _display_utils.getCurrentTransform)(graphics.ctx);
  7642. graphics.executeOperatorList(operatorList);
  7643. graphics.endDrawing();
  7644. return {
  7645. canvas: tmpCanvas.canvas,
  7646. scaleX: dimx.scale,
  7647. scaleY: dimy.scale,
  7648. offsetX: adjustedX0,
  7649. offsetY: adjustedY0
  7650. };
  7651. }
  7652. getSizeAndScale(step, realOutputSize, scale) {
  7653. step = Math.abs(step);
  7654. const maxSize = Math.max(TilingPattern.MAX_PATTERN_SIZE, realOutputSize);
  7655. let size = Math.ceil(step * scale);
  7656. if (size >= maxSize) {
  7657. size = maxSize;
  7658. } else {
  7659. scale = size / step;
  7660. }
  7661. return {
  7662. scale,
  7663. size
  7664. };
  7665. }
  7666. clipBbox(graphics, x0, y0, x1, y1) {
  7667. const bboxWidth = x1 - x0;
  7668. const bboxHeight = y1 - y0;
  7669. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  7670. graphics.current.updateRectMinMax((0, _display_utils.getCurrentTransform)(graphics.ctx), [x0, y0, x1, y1]);
  7671. graphics.clip();
  7672. graphics.endPath();
  7673. }
  7674. setFillAndStrokeStyleToContext(graphics, paintType, color) {
  7675. const context = graphics.ctx,
  7676. current = graphics.current;
  7677. switch (paintType) {
  7678. case PaintType.COLORED:
  7679. const ctx = this.ctx;
  7680. context.fillStyle = ctx.fillStyle;
  7681. context.strokeStyle = ctx.strokeStyle;
  7682. current.fillColor = ctx.fillStyle;
  7683. current.strokeColor = ctx.strokeStyle;
  7684. break;
  7685. case PaintType.UNCOLORED:
  7686. const cssColor = _util.Util.makeHexColor(color[0], color[1], color[2]);
  7687. context.fillStyle = cssColor;
  7688. context.strokeStyle = cssColor;
  7689. current.fillColor = cssColor;
  7690. current.strokeColor = cssColor;
  7691. break;
  7692. default:
  7693. throw new _util.FormatError(`Unsupported paint type: ${paintType}`);
  7694. }
  7695. }
  7696. getPattern(ctx, owner, inverse, pathType) {
  7697. let matrix = inverse;
  7698. if (pathType !== PathType.SHADING) {
  7699. matrix = _util.Util.transform(matrix, owner.baseTransform);
  7700. if (this.matrix) {
  7701. matrix = _util.Util.transform(matrix, this.matrix);
  7702. }
  7703. }
  7704. const temporaryPatternCanvas = this.createPatternCanvas(owner);
  7705. let domMatrix = new DOMMatrix(matrix);
  7706. domMatrix = domMatrix.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY);
  7707. domMatrix = domMatrix.scale(1 / temporaryPatternCanvas.scaleX, 1 / temporaryPatternCanvas.scaleY);
  7708. const pattern = ctx.createPattern(temporaryPatternCanvas.canvas, "repeat");
  7709. pattern.setTransform(domMatrix);
  7710. return pattern;
  7711. }
  7712. }
  7713. exports.TilingPattern = TilingPattern;
  7714. /***/ }),
  7715. /* 13 */
  7716. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  7717. Object.defineProperty(exports, "__esModule", ({
  7718. value: true
  7719. }));
  7720. exports.convertBlackAndWhiteToRGBA = convertBlackAndWhiteToRGBA;
  7721. exports.convertToRGBA = convertToRGBA;
  7722. exports.grayToRGBA = grayToRGBA;
  7723. var _util = __w_pdfjs_require__(1);
  7724. function convertToRGBA(params) {
  7725. switch (params.kind) {
  7726. case _util.ImageKind.GRAYSCALE_1BPP:
  7727. return convertBlackAndWhiteToRGBA(params);
  7728. case _util.ImageKind.RGB_24BPP:
  7729. return convertRGBToRGBA(params);
  7730. }
  7731. return null;
  7732. }
  7733. function convertBlackAndWhiteToRGBA({
  7734. src,
  7735. srcPos = 0,
  7736. dest,
  7737. width,
  7738. height,
  7739. nonBlackColor = 0xffffffff,
  7740. inverseDecode = false
  7741. }) {
  7742. const black = _util.FeatureTest.isLittleEndian ? 0xff000000 : 0x000000ff;
  7743. const [zeroMapping, oneMapping] = inverseDecode ? [nonBlackColor, black] : [black, nonBlackColor];
  7744. const widthInSource = width >> 3;
  7745. const widthRemainder = width & 7;
  7746. const srcLength = src.length;
  7747. dest = new Uint32Array(dest.buffer);
  7748. let destPos = 0;
  7749. for (let i = 0; i < height; i++) {
  7750. for (const max = srcPos + widthInSource; srcPos < max; srcPos++) {
  7751. const elem = srcPos < srcLength ? src[srcPos] : 255;
  7752. dest[destPos++] = elem & 0b10000000 ? oneMapping : zeroMapping;
  7753. dest[destPos++] = elem & 0b1000000 ? oneMapping : zeroMapping;
  7754. dest[destPos++] = elem & 0b100000 ? oneMapping : zeroMapping;
  7755. dest[destPos++] = elem & 0b10000 ? oneMapping : zeroMapping;
  7756. dest[destPos++] = elem & 0b1000 ? oneMapping : zeroMapping;
  7757. dest[destPos++] = elem & 0b100 ? oneMapping : zeroMapping;
  7758. dest[destPos++] = elem & 0b10 ? oneMapping : zeroMapping;
  7759. dest[destPos++] = elem & 0b1 ? oneMapping : zeroMapping;
  7760. }
  7761. if (widthRemainder === 0) {
  7762. continue;
  7763. }
  7764. const elem = srcPos < srcLength ? src[srcPos++] : 255;
  7765. for (let j = 0; j < widthRemainder; j++) {
  7766. dest[destPos++] = elem & 1 << 7 - j ? oneMapping : zeroMapping;
  7767. }
  7768. }
  7769. return {
  7770. srcPos,
  7771. destPos
  7772. };
  7773. }
  7774. function convertRGBToRGBA({
  7775. src,
  7776. srcPos = 0,
  7777. dest,
  7778. destPos = 0,
  7779. width,
  7780. height
  7781. }) {
  7782. let i = 0;
  7783. const len32 = src.length >> 2;
  7784. const src32 = new Uint32Array(src.buffer, srcPos, len32);
  7785. if (_util.FeatureTest.isLittleEndian) {
  7786. for (; i < len32 - 2; i += 3, destPos += 4) {
  7787. const s1 = src32[i];
  7788. const s2 = src32[i + 1];
  7789. const s3 = src32[i + 2];
  7790. dest[destPos] = s1 | 0xff000000;
  7791. dest[destPos + 1] = s1 >>> 24 | s2 << 8 | 0xff000000;
  7792. dest[destPos + 2] = s2 >>> 16 | s3 << 16 | 0xff000000;
  7793. dest[destPos + 3] = s3 >>> 8 | 0xff000000;
  7794. }
  7795. for (let j = i * 4, jj = src.length; j < jj; j += 3) {
  7796. dest[destPos++] = src[j] | src[j + 1] << 8 | src[j + 2] << 16 | 0xff000000;
  7797. }
  7798. } else {
  7799. for (; i < len32 - 2; i += 3, destPos += 4) {
  7800. const s1 = src32[i];
  7801. const s2 = src32[i + 1];
  7802. const s3 = src32[i + 2];
  7803. dest[destPos] = s1 | 0xff;
  7804. dest[destPos + 1] = s1 << 24 | s2 >>> 8 | 0xff;
  7805. dest[destPos + 2] = s2 << 16 | s3 >>> 16 | 0xff;
  7806. dest[destPos + 3] = s3 << 8 | 0xff;
  7807. }
  7808. for (let j = i * 4, jj = src.length; j < jj; j += 3) {
  7809. dest[destPos++] = src[j] << 24 | src[j + 1] << 16 | src[j + 2] << 8 | 0xff;
  7810. }
  7811. }
  7812. return {
  7813. srcPos,
  7814. destPos
  7815. };
  7816. }
  7817. function grayToRGBA(src, dest) {
  7818. if (_util.FeatureTest.isLittleEndian) {
  7819. for (let i = 0, ii = src.length; i < ii; i++) {
  7820. dest[i] = src[i] * 0x10101 | 0xff000000;
  7821. }
  7822. } else {
  7823. for (let i = 0, ii = src.length; i < ii; i++) {
  7824. dest[i] = src[i] * 0x1010100 | 0x000000ff;
  7825. }
  7826. }
  7827. }
  7828. /***/ }),
  7829. /* 14 */
  7830. /***/ ((__unused_webpack_module, exports) => {
  7831. Object.defineProperty(exports, "__esModule", ({
  7832. value: true
  7833. }));
  7834. exports.GlobalWorkerOptions = void 0;
  7835. const GlobalWorkerOptions = Object.create(null);
  7836. exports.GlobalWorkerOptions = GlobalWorkerOptions;
  7837. GlobalWorkerOptions.workerPort = null;
  7838. GlobalWorkerOptions.workerSrc = "";
  7839. /***/ }),
  7840. /* 15 */
  7841. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  7842. Object.defineProperty(exports, "__esModule", ({
  7843. value: true
  7844. }));
  7845. exports.MessageHandler = void 0;
  7846. var _util = __w_pdfjs_require__(1);
  7847. const CallbackKind = {
  7848. UNKNOWN: 0,
  7849. DATA: 1,
  7850. ERROR: 2
  7851. };
  7852. const StreamKind = {
  7853. UNKNOWN: 0,
  7854. CANCEL: 1,
  7855. CANCEL_COMPLETE: 2,
  7856. CLOSE: 3,
  7857. ENQUEUE: 4,
  7858. ERROR: 5,
  7859. PULL: 6,
  7860. PULL_COMPLETE: 7,
  7861. START_COMPLETE: 8
  7862. };
  7863. function wrapReason(reason) {
  7864. if (!(reason instanceof Error || typeof reason === "object" && reason !== null)) {
  7865. (0, _util.unreachable)('wrapReason: Expected "reason" to be a (possibly cloned) Error.');
  7866. }
  7867. switch (reason.name) {
  7868. case "AbortException":
  7869. return new _util.AbortException(reason.message);
  7870. case "MissingPDFException":
  7871. return new _util.MissingPDFException(reason.message);
  7872. case "PasswordException":
  7873. return new _util.PasswordException(reason.message, reason.code);
  7874. case "UnexpectedResponseException":
  7875. return new _util.UnexpectedResponseException(reason.message, reason.status);
  7876. case "UnknownErrorException":
  7877. return new _util.UnknownErrorException(reason.message, reason.details);
  7878. default:
  7879. return new _util.UnknownErrorException(reason.message, reason.toString());
  7880. }
  7881. }
  7882. class MessageHandler {
  7883. constructor(sourceName, targetName, comObj) {
  7884. this.sourceName = sourceName;
  7885. this.targetName = targetName;
  7886. this.comObj = comObj;
  7887. this.callbackId = 1;
  7888. this.streamId = 1;
  7889. this.streamSinks = Object.create(null);
  7890. this.streamControllers = Object.create(null);
  7891. this.callbackCapabilities = Object.create(null);
  7892. this.actionHandler = Object.create(null);
  7893. this._onComObjOnMessage = event => {
  7894. const data = event.data;
  7895. if (data.targetName !== this.sourceName) {
  7896. return;
  7897. }
  7898. if (data.stream) {
  7899. this.#processStreamMessage(data);
  7900. return;
  7901. }
  7902. if (data.callback) {
  7903. const callbackId = data.callbackId;
  7904. const capability = this.callbackCapabilities[callbackId];
  7905. if (!capability) {
  7906. throw new Error(`Cannot resolve callback ${callbackId}`);
  7907. }
  7908. delete this.callbackCapabilities[callbackId];
  7909. if (data.callback === CallbackKind.DATA) {
  7910. capability.resolve(data.data);
  7911. } else if (data.callback === CallbackKind.ERROR) {
  7912. capability.reject(wrapReason(data.reason));
  7913. } else {
  7914. throw new Error("Unexpected callback case");
  7915. }
  7916. return;
  7917. }
  7918. const action = this.actionHandler[data.action];
  7919. if (!action) {
  7920. throw new Error(`Unknown action from worker: ${data.action}`);
  7921. }
  7922. if (data.callbackId) {
  7923. const cbSourceName = this.sourceName;
  7924. const cbTargetName = data.sourceName;
  7925. new Promise(function (resolve) {
  7926. resolve(action(data.data));
  7927. }).then(function (result) {
  7928. comObj.postMessage({
  7929. sourceName: cbSourceName,
  7930. targetName: cbTargetName,
  7931. callback: CallbackKind.DATA,
  7932. callbackId: data.callbackId,
  7933. data: result
  7934. });
  7935. }, function (reason) {
  7936. comObj.postMessage({
  7937. sourceName: cbSourceName,
  7938. targetName: cbTargetName,
  7939. callback: CallbackKind.ERROR,
  7940. callbackId: data.callbackId,
  7941. reason: wrapReason(reason)
  7942. });
  7943. });
  7944. return;
  7945. }
  7946. if (data.streamId) {
  7947. this.#createStreamSink(data);
  7948. return;
  7949. }
  7950. action(data.data);
  7951. };
  7952. comObj.addEventListener("message", this._onComObjOnMessage);
  7953. }
  7954. on(actionName, handler) {
  7955. const ah = this.actionHandler;
  7956. if (ah[actionName]) {
  7957. throw new Error(`There is already an actionName called "${actionName}"`);
  7958. }
  7959. ah[actionName] = handler;
  7960. }
  7961. send(actionName, data, transfers) {
  7962. this.comObj.postMessage({
  7963. sourceName: this.sourceName,
  7964. targetName: this.targetName,
  7965. action: actionName,
  7966. data
  7967. }, transfers);
  7968. }
  7969. sendWithPromise(actionName, data, transfers) {
  7970. const callbackId = this.callbackId++;
  7971. const capability = new _util.PromiseCapability();
  7972. this.callbackCapabilities[callbackId] = capability;
  7973. try {
  7974. this.comObj.postMessage({
  7975. sourceName: this.sourceName,
  7976. targetName: this.targetName,
  7977. action: actionName,
  7978. callbackId,
  7979. data
  7980. }, transfers);
  7981. } catch (ex) {
  7982. capability.reject(ex);
  7983. }
  7984. return capability.promise;
  7985. }
  7986. sendWithStream(actionName, data, queueingStrategy, transfers) {
  7987. const streamId = this.streamId++,
  7988. sourceName = this.sourceName,
  7989. targetName = this.targetName,
  7990. comObj = this.comObj;
  7991. return new ReadableStream({
  7992. start: controller => {
  7993. const startCapability = new _util.PromiseCapability();
  7994. this.streamControllers[streamId] = {
  7995. controller,
  7996. startCall: startCapability,
  7997. pullCall: null,
  7998. cancelCall: null,
  7999. isClosed: false
  8000. };
  8001. comObj.postMessage({
  8002. sourceName,
  8003. targetName,
  8004. action: actionName,
  8005. streamId,
  8006. data,
  8007. desiredSize: controller.desiredSize
  8008. }, transfers);
  8009. return startCapability.promise;
  8010. },
  8011. pull: controller => {
  8012. const pullCapability = new _util.PromiseCapability();
  8013. this.streamControllers[streamId].pullCall = pullCapability;
  8014. comObj.postMessage({
  8015. sourceName,
  8016. targetName,
  8017. stream: StreamKind.PULL,
  8018. streamId,
  8019. desiredSize: controller.desiredSize
  8020. });
  8021. return pullCapability.promise;
  8022. },
  8023. cancel: reason => {
  8024. (0, _util.assert)(reason instanceof Error, "cancel must have a valid reason");
  8025. const cancelCapability = new _util.PromiseCapability();
  8026. this.streamControllers[streamId].cancelCall = cancelCapability;
  8027. this.streamControllers[streamId].isClosed = true;
  8028. comObj.postMessage({
  8029. sourceName,
  8030. targetName,
  8031. stream: StreamKind.CANCEL,
  8032. streamId,
  8033. reason: wrapReason(reason)
  8034. });
  8035. return cancelCapability.promise;
  8036. }
  8037. }, queueingStrategy);
  8038. }
  8039. #createStreamSink(data) {
  8040. const streamId = data.streamId,
  8041. sourceName = this.sourceName,
  8042. targetName = data.sourceName,
  8043. comObj = this.comObj;
  8044. const self = this,
  8045. action = this.actionHandler[data.action];
  8046. const streamSink = {
  8047. enqueue(chunk, size = 1, transfers) {
  8048. if (this.isCancelled) {
  8049. return;
  8050. }
  8051. const lastDesiredSize = this.desiredSize;
  8052. this.desiredSize -= size;
  8053. if (lastDesiredSize > 0 && this.desiredSize <= 0) {
  8054. this.sinkCapability = new _util.PromiseCapability();
  8055. this.ready = this.sinkCapability.promise;
  8056. }
  8057. comObj.postMessage({
  8058. sourceName,
  8059. targetName,
  8060. stream: StreamKind.ENQUEUE,
  8061. streamId,
  8062. chunk
  8063. }, transfers);
  8064. },
  8065. close() {
  8066. if (this.isCancelled) {
  8067. return;
  8068. }
  8069. this.isCancelled = true;
  8070. comObj.postMessage({
  8071. sourceName,
  8072. targetName,
  8073. stream: StreamKind.CLOSE,
  8074. streamId
  8075. });
  8076. delete self.streamSinks[streamId];
  8077. },
  8078. error(reason) {
  8079. (0, _util.assert)(reason instanceof Error, "error must have a valid reason");
  8080. if (this.isCancelled) {
  8081. return;
  8082. }
  8083. this.isCancelled = true;
  8084. comObj.postMessage({
  8085. sourceName,
  8086. targetName,
  8087. stream: StreamKind.ERROR,
  8088. streamId,
  8089. reason: wrapReason(reason)
  8090. });
  8091. },
  8092. sinkCapability: new _util.PromiseCapability(),
  8093. onPull: null,
  8094. onCancel: null,
  8095. isCancelled: false,
  8096. desiredSize: data.desiredSize,
  8097. ready: null
  8098. };
  8099. streamSink.sinkCapability.resolve();
  8100. streamSink.ready = streamSink.sinkCapability.promise;
  8101. this.streamSinks[streamId] = streamSink;
  8102. new Promise(function (resolve) {
  8103. resolve(action(data.data, streamSink));
  8104. }).then(function () {
  8105. comObj.postMessage({
  8106. sourceName,
  8107. targetName,
  8108. stream: StreamKind.START_COMPLETE,
  8109. streamId,
  8110. success: true
  8111. });
  8112. }, function (reason) {
  8113. comObj.postMessage({
  8114. sourceName,
  8115. targetName,
  8116. stream: StreamKind.START_COMPLETE,
  8117. streamId,
  8118. reason: wrapReason(reason)
  8119. });
  8120. });
  8121. }
  8122. #processStreamMessage(data) {
  8123. const streamId = data.streamId,
  8124. sourceName = this.sourceName,
  8125. targetName = data.sourceName,
  8126. comObj = this.comObj;
  8127. const streamController = this.streamControllers[streamId],
  8128. streamSink = this.streamSinks[streamId];
  8129. switch (data.stream) {
  8130. case StreamKind.START_COMPLETE:
  8131. if (data.success) {
  8132. streamController.startCall.resolve();
  8133. } else {
  8134. streamController.startCall.reject(wrapReason(data.reason));
  8135. }
  8136. break;
  8137. case StreamKind.PULL_COMPLETE:
  8138. if (data.success) {
  8139. streamController.pullCall.resolve();
  8140. } else {
  8141. streamController.pullCall.reject(wrapReason(data.reason));
  8142. }
  8143. break;
  8144. case StreamKind.PULL:
  8145. if (!streamSink) {
  8146. comObj.postMessage({
  8147. sourceName,
  8148. targetName,
  8149. stream: StreamKind.PULL_COMPLETE,
  8150. streamId,
  8151. success: true
  8152. });
  8153. break;
  8154. }
  8155. if (streamSink.desiredSize <= 0 && data.desiredSize > 0) {
  8156. streamSink.sinkCapability.resolve();
  8157. }
  8158. streamSink.desiredSize = data.desiredSize;
  8159. new Promise(function (resolve) {
  8160. resolve(streamSink.onPull?.());
  8161. }).then(function () {
  8162. comObj.postMessage({
  8163. sourceName,
  8164. targetName,
  8165. stream: StreamKind.PULL_COMPLETE,
  8166. streamId,
  8167. success: true
  8168. });
  8169. }, function (reason) {
  8170. comObj.postMessage({
  8171. sourceName,
  8172. targetName,
  8173. stream: StreamKind.PULL_COMPLETE,
  8174. streamId,
  8175. reason: wrapReason(reason)
  8176. });
  8177. });
  8178. break;
  8179. case StreamKind.ENQUEUE:
  8180. (0, _util.assert)(streamController, "enqueue should have stream controller");
  8181. if (streamController.isClosed) {
  8182. break;
  8183. }
  8184. streamController.controller.enqueue(data.chunk);
  8185. break;
  8186. case StreamKind.CLOSE:
  8187. (0, _util.assert)(streamController, "close should have stream controller");
  8188. if (streamController.isClosed) {
  8189. break;
  8190. }
  8191. streamController.isClosed = true;
  8192. streamController.controller.close();
  8193. this.#deleteStreamController(streamController, streamId);
  8194. break;
  8195. case StreamKind.ERROR:
  8196. (0, _util.assert)(streamController, "error should have stream controller");
  8197. streamController.controller.error(wrapReason(data.reason));
  8198. this.#deleteStreamController(streamController, streamId);
  8199. break;
  8200. case StreamKind.CANCEL_COMPLETE:
  8201. if (data.success) {
  8202. streamController.cancelCall.resolve();
  8203. } else {
  8204. streamController.cancelCall.reject(wrapReason(data.reason));
  8205. }
  8206. this.#deleteStreamController(streamController, streamId);
  8207. break;
  8208. case StreamKind.CANCEL:
  8209. if (!streamSink) {
  8210. break;
  8211. }
  8212. new Promise(function (resolve) {
  8213. resolve(streamSink.onCancel?.(wrapReason(data.reason)));
  8214. }).then(function () {
  8215. comObj.postMessage({
  8216. sourceName,
  8217. targetName,
  8218. stream: StreamKind.CANCEL_COMPLETE,
  8219. streamId,
  8220. success: true
  8221. });
  8222. }, function (reason) {
  8223. comObj.postMessage({
  8224. sourceName,
  8225. targetName,
  8226. stream: StreamKind.CANCEL_COMPLETE,
  8227. streamId,
  8228. reason: wrapReason(reason)
  8229. });
  8230. });
  8231. streamSink.sinkCapability.reject(wrapReason(data.reason));
  8232. streamSink.isCancelled = true;
  8233. delete this.streamSinks[streamId];
  8234. break;
  8235. default:
  8236. throw new Error("Unexpected stream case");
  8237. }
  8238. }
  8239. async #deleteStreamController(streamController, streamId) {
  8240. await Promise.allSettled([streamController.startCall?.promise, streamController.pullCall?.promise, streamController.cancelCall?.promise]);
  8241. delete this.streamControllers[streamId];
  8242. }
  8243. destroy() {
  8244. this.comObj.removeEventListener("message", this._onComObjOnMessage);
  8245. }
  8246. }
  8247. exports.MessageHandler = MessageHandler;
  8248. /***/ }),
  8249. /* 16 */
  8250. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  8251. Object.defineProperty(exports, "__esModule", ({
  8252. value: true
  8253. }));
  8254. exports.Metadata = void 0;
  8255. var _util = __w_pdfjs_require__(1);
  8256. class Metadata {
  8257. #metadataMap;
  8258. #data;
  8259. constructor({
  8260. parsedData,
  8261. rawData
  8262. }) {
  8263. this.#metadataMap = parsedData;
  8264. this.#data = rawData;
  8265. }
  8266. getRaw() {
  8267. return this.#data;
  8268. }
  8269. get(name) {
  8270. return this.#metadataMap.get(name) ?? null;
  8271. }
  8272. getAll() {
  8273. return (0, _util.objectFromMap)(this.#metadataMap);
  8274. }
  8275. has(name) {
  8276. return this.#metadataMap.has(name);
  8277. }
  8278. }
  8279. exports.Metadata = Metadata;
  8280. /***/ }),
  8281. /* 17 */
  8282. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  8283. Object.defineProperty(exports, "__esModule", ({
  8284. value: true
  8285. }));
  8286. exports.OptionalContentConfig = void 0;
  8287. var _util = __w_pdfjs_require__(1);
  8288. var _murmurhash = __w_pdfjs_require__(8);
  8289. const INTERNAL = Symbol("INTERNAL");
  8290. class OptionalContentGroup {
  8291. #visible = true;
  8292. constructor(name, intent) {
  8293. this.name = name;
  8294. this.intent = intent;
  8295. }
  8296. get visible() {
  8297. return this.#visible;
  8298. }
  8299. _setVisible(internal, visible) {
  8300. if (internal !== INTERNAL) {
  8301. (0, _util.unreachable)("Internal method `_setVisible` called.");
  8302. }
  8303. this.#visible = visible;
  8304. }
  8305. }
  8306. class OptionalContentConfig {
  8307. #cachedGetHash = null;
  8308. #groups = new Map();
  8309. #initialHash = null;
  8310. #order = null;
  8311. constructor(data) {
  8312. this.name = null;
  8313. this.creator = null;
  8314. if (data === null) {
  8315. return;
  8316. }
  8317. this.name = data.name;
  8318. this.creator = data.creator;
  8319. this.#order = data.order;
  8320. for (const group of data.groups) {
  8321. this.#groups.set(group.id, new OptionalContentGroup(group.name, group.intent));
  8322. }
  8323. if (data.baseState === "OFF") {
  8324. for (const group of this.#groups.values()) {
  8325. group._setVisible(INTERNAL, false);
  8326. }
  8327. }
  8328. for (const on of data.on) {
  8329. this.#groups.get(on)._setVisible(INTERNAL, true);
  8330. }
  8331. for (const off of data.off) {
  8332. this.#groups.get(off)._setVisible(INTERNAL, false);
  8333. }
  8334. this.#initialHash = this.getHash();
  8335. }
  8336. #evaluateVisibilityExpression(array) {
  8337. const length = array.length;
  8338. if (length < 2) {
  8339. return true;
  8340. }
  8341. const operator = array[0];
  8342. for (let i = 1; i < length; i++) {
  8343. const element = array[i];
  8344. let state;
  8345. if (Array.isArray(element)) {
  8346. state = this.#evaluateVisibilityExpression(element);
  8347. } else if (this.#groups.has(element)) {
  8348. state = this.#groups.get(element).visible;
  8349. } else {
  8350. (0, _util.warn)(`Optional content group not found: ${element}`);
  8351. return true;
  8352. }
  8353. switch (operator) {
  8354. case "And":
  8355. if (!state) {
  8356. return false;
  8357. }
  8358. break;
  8359. case "Or":
  8360. if (state) {
  8361. return true;
  8362. }
  8363. break;
  8364. case "Not":
  8365. return !state;
  8366. default:
  8367. return true;
  8368. }
  8369. }
  8370. return operator === "And";
  8371. }
  8372. isVisible(group) {
  8373. if (this.#groups.size === 0) {
  8374. return true;
  8375. }
  8376. if (!group) {
  8377. (0, _util.warn)("Optional content group not defined.");
  8378. return true;
  8379. }
  8380. if (group.type === "OCG") {
  8381. if (!this.#groups.has(group.id)) {
  8382. (0, _util.warn)(`Optional content group not found: ${group.id}`);
  8383. return true;
  8384. }
  8385. return this.#groups.get(group.id).visible;
  8386. } else if (group.type === "OCMD") {
  8387. if (group.expression) {
  8388. return this.#evaluateVisibilityExpression(group.expression);
  8389. }
  8390. if (!group.policy || group.policy === "AnyOn") {
  8391. for (const id of group.ids) {
  8392. if (!this.#groups.has(id)) {
  8393. (0, _util.warn)(`Optional content group not found: ${id}`);
  8394. return true;
  8395. }
  8396. if (this.#groups.get(id).visible) {
  8397. return true;
  8398. }
  8399. }
  8400. return false;
  8401. } else if (group.policy === "AllOn") {
  8402. for (const id of group.ids) {
  8403. if (!this.#groups.has(id)) {
  8404. (0, _util.warn)(`Optional content group not found: ${id}`);
  8405. return true;
  8406. }
  8407. if (!this.#groups.get(id).visible) {
  8408. return false;
  8409. }
  8410. }
  8411. return true;
  8412. } else if (group.policy === "AnyOff") {
  8413. for (const id of group.ids) {
  8414. if (!this.#groups.has(id)) {
  8415. (0, _util.warn)(`Optional content group not found: ${id}`);
  8416. return true;
  8417. }
  8418. if (!this.#groups.get(id).visible) {
  8419. return true;
  8420. }
  8421. }
  8422. return false;
  8423. } else if (group.policy === "AllOff") {
  8424. for (const id of group.ids) {
  8425. if (!this.#groups.has(id)) {
  8426. (0, _util.warn)(`Optional content group not found: ${id}`);
  8427. return true;
  8428. }
  8429. if (this.#groups.get(id).visible) {
  8430. return false;
  8431. }
  8432. }
  8433. return true;
  8434. }
  8435. (0, _util.warn)(`Unknown optional content policy ${group.policy}.`);
  8436. return true;
  8437. }
  8438. (0, _util.warn)(`Unknown group type ${group.type}.`);
  8439. return true;
  8440. }
  8441. setVisibility(id, visible = true) {
  8442. if (!this.#groups.has(id)) {
  8443. (0, _util.warn)(`Optional content group not found: ${id}`);
  8444. return;
  8445. }
  8446. this.#groups.get(id)._setVisible(INTERNAL, !!visible);
  8447. this.#cachedGetHash = null;
  8448. }
  8449. get hasInitialVisibility() {
  8450. return this.getHash() === this.#initialHash;
  8451. }
  8452. getOrder() {
  8453. if (!this.#groups.size) {
  8454. return null;
  8455. }
  8456. if (this.#order) {
  8457. return this.#order.slice();
  8458. }
  8459. return [...this.#groups.keys()];
  8460. }
  8461. getGroups() {
  8462. return this.#groups.size > 0 ? (0, _util.objectFromMap)(this.#groups) : null;
  8463. }
  8464. getGroup(id) {
  8465. return this.#groups.get(id) || null;
  8466. }
  8467. getHash() {
  8468. if (this.#cachedGetHash !== null) {
  8469. return this.#cachedGetHash;
  8470. }
  8471. const hash = new _murmurhash.MurmurHash3_64();
  8472. for (const [id, group] of this.#groups) {
  8473. hash.update(`${id}:${group.visible}`);
  8474. }
  8475. return this.#cachedGetHash = hash.hexdigest();
  8476. }
  8477. }
  8478. exports.OptionalContentConfig = OptionalContentConfig;
  8479. /***/ }),
  8480. /* 18 */
  8481. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  8482. Object.defineProperty(exports, "__esModule", ({
  8483. value: true
  8484. }));
  8485. exports.PDFDataTransportStream = void 0;
  8486. var _util = __w_pdfjs_require__(1);
  8487. var _display_utils = __w_pdfjs_require__(6);
  8488. class PDFDataTransportStream {
  8489. constructor({
  8490. length,
  8491. initialData,
  8492. progressiveDone = false,
  8493. contentDispositionFilename = null,
  8494. disableRange = false,
  8495. disableStream = false
  8496. }, pdfDataRangeTransport) {
  8497. (0, _util.assert)(pdfDataRangeTransport, 'PDFDataTransportStream - missing required "pdfDataRangeTransport" argument.');
  8498. this._queuedChunks = [];
  8499. this._progressiveDone = progressiveDone;
  8500. this._contentDispositionFilename = contentDispositionFilename;
  8501. if (initialData?.length > 0) {
  8502. const buffer = initialData instanceof Uint8Array && initialData.byteLength === initialData.buffer.byteLength ? initialData.buffer : new Uint8Array(initialData).buffer;
  8503. this._queuedChunks.push(buffer);
  8504. }
  8505. this._pdfDataRangeTransport = pdfDataRangeTransport;
  8506. this._isStreamingSupported = !disableStream;
  8507. this._isRangeSupported = !disableRange;
  8508. this._contentLength = length;
  8509. this._fullRequestReader = null;
  8510. this._rangeReaders = [];
  8511. this._pdfDataRangeTransport.addRangeListener((begin, chunk) => {
  8512. this._onReceiveData({
  8513. begin,
  8514. chunk
  8515. });
  8516. });
  8517. this._pdfDataRangeTransport.addProgressListener((loaded, total) => {
  8518. this._onProgress({
  8519. loaded,
  8520. total
  8521. });
  8522. });
  8523. this._pdfDataRangeTransport.addProgressiveReadListener(chunk => {
  8524. this._onReceiveData({
  8525. chunk
  8526. });
  8527. });
  8528. this._pdfDataRangeTransport.addProgressiveDoneListener(() => {
  8529. this._onProgressiveDone();
  8530. });
  8531. this._pdfDataRangeTransport.transportReady();
  8532. }
  8533. _onReceiveData({
  8534. begin,
  8535. chunk
  8536. }) {
  8537. const buffer = chunk instanceof Uint8Array && chunk.byteLength === chunk.buffer.byteLength ? chunk.buffer : new Uint8Array(chunk).buffer;
  8538. if (begin === undefined) {
  8539. if (this._fullRequestReader) {
  8540. this._fullRequestReader._enqueue(buffer);
  8541. } else {
  8542. this._queuedChunks.push(buffer);
  8543. }
  8544. } else {
  8545. const found = this._rangeReaders.some(function (rangeReader) {
  8546. if (rangeReader._begin !== begin) {
  8547. return false;
  8548. }
  8549. rangeReader._enqueue(buffer);
  8550. return true;
  8551. });
  8552. (0, _util.assert)(found, "_onReceiveData - no `PDFDataTransportStreamRangeReader` instance found.");
  8553. }
  8554. }
  8555. get _progressiveDataLength() {
  8556. return this._fullRequestReader?._loaded ?? 0;
  8557. }
  8558. _onProgress(evt) {
  8559. if (evt.total === undefined) {
  8560. this._rangeReaders[0]?.onProgress?.({
  8561. loaded: evt.loaded
  8562. });
  8563. } else {
  8564. this._fullRequestReader?.onProgress?.({
  8565. loaded: evt.loaded,
  8566. total: evt.total
  8567. });
  8568. }
  8569. }
  8570. _onProgressiveDone() {
  8571. this._fullRequestReader?.progressiveDone();
  8572. this._progressiveDone = true;
  8573. }
  8574. _removeRangeReader(reader) {
  8575. const i = this._rangeReaders.indexOf(reader);
  8576. if (i >= 0) {
  8577. this._rangeReaders.splice(i, 1);
  8578. }
  8579. }
  8580. getFullReader() {
  8581. (0, _util.assert)(!this._fullRequestReader, "PDFDataTransportStream.getFullReader can only be called once.");
  8582. const queuedChunks = this._queuedChunks;
  8583. this._queuedChunks = null;
  8584. return new PDFDataTransportStreamReader(this, queuedChunks, this._progressiveDone, this._contentDispositionFilename);
  8585. }
  8586. getRangeReader(begin, end) {
  8587. if (end <= this._progressiveDataLength) {
  8588. return null;
  8589. }
  8590. const reader = new PDFDataTransportStreamRangeReader(this, begin, end);
  8591. this._pdfDataRangeTransport.requestDataRange(begin, end);
  8592. this._rangeReaders.push(reader);
  8593. return reader;
  8594. }
  8595. cancelAllRequests(reason) {
  8596. this._fullRequestReader?.cancel(reason);
  8597. for (const reader of this._rangeReaders.slice(0)) {
  8598. reader.cancel(reason);
  8599. }
  8600. this._pdfDataRangeTransport.abort();
  8601. }
  8602. }
  8603. exports.PDFDataTransportStream = PDFDataTransportStream;
  8604. class PDFDataTransportStreamReader {
  8605. constructor(stream, queuedChunks, progressiveDone = false, contentDispositionFilename = null) {
  8606. this._stream = stream;
  8607. this._done = progressiveDone || false;
  8608. this._filename = (0, _display_utils.isPdfFile)(contentDispositionFilename) ? contentDispositionFilename : null;
  8609. this._queuedChunks = queuedChunks || [];
  8610. this._loaded = 0;
  8611. for (const chunk of this._queuedChunks) {
  8612. this._loaded += chunk.byteLength;
  8613. }
  8614. this._requests = [];
  8615. this._headersReady = Promise.resolve();
  8616. stream._fullRequestReader = this;
  8617. this.onProgress = null;
  8618. }
  8619. _enqueue(chunk) {
  8620. if (this._done) {
  8621. return;
  8622. }
  8623. if (this._requests.length > 0) {
  8624. const requestCapability = this._requests.shift();
  8625. requestCapability.resolve({
  8626. value: chunk,
  8627. done: false
  8628. });
  8629. } else {
  8630. this._queuedChunks.push(chunk);
  8631. }
  8632. this._loaded += chunk.byteLength;
  8633. }
  8634. get headersReady() {
  8635. return this._headersReady;
  8636. }
  8637. get filename() {
  8638. return this._filename;
  8639. }
  8640. get isRangeSupported() {
  8641. return this._stream._isRangeSupported;
  8642. }
  8643. get isStreamingSupported() {
  8644. return this._stream._isStreamingSupported;
  8645. }
  8646. get contentLength() {
  8647. return this._stream._contentLength;
  8648. }
  8649. async read() {
  8650. if (this._queuedChunks.length > 0) {
  8651. const chunk = this._queuedChunks.shift();
  8652. return {
  8653. value: chunk,
  8654. done: false
  8655. };
  8656. }
  8657. if (this._done) {
  8658. return {
  8659. value: undefined,
  8660. done: true
  8661. };
  8662. }
  8663. const requestCapability = new _util.PromiseCapability();
  8664. this._requests.push(requestCapability);
  8665. return requestCapability.promise;
  8666. }
  8667. cancel(reason) {
  8668. this._done = true;
  8669. for (const requestCapability of this._requests) {
  8670. requestCapability.resolve({
  8671. value: undefined,
  8672. done: true
  8673. });
  8674. }
  8675. this._requests.length = 0;
  8676. }
  8677. progressiveDone() {
  8678. if (this._done) {
  8679. return;
  8680. }
  8681. this._done = true;
  8682. }
  8683. }
  8684. class PDFDataTransportStreamRangeReader {
  8685. constructor(stream, begin, end) {
  8686. this._stream = stream;
  8687. this._begin = begin;
  8688. this._end = end;
  8689. this._queuedChunk = null;
  8690. this._requests = [];
  8691. this._done = false;
  8692. this.onProgress = null;
  8693. }
  8694. _enqueue(chunk) {
  8695. if (this._done) {
  8696. return;
  8697. }
  8698. if (this._requests.length === 0) {
  8699. this._queuedChunk = chunk;
  8700. } else {
  8701. const requestsCapability = this._requests.shift();
  8702. requestsCapability.resolve({
  8703. value: chunk,
  8704. done: false
  8705. });
  8706. for (const requestCapability of this._requests) {
  8707. requestCapability.resolve({
  8708. value: undefined,
  8709. done: true
  8710. });
  8711. }
  8712. this._requests.length = 0;
  8713. }
  8714. this._done = true;
  8715. this._stream._removeRangeReader(this);
  8716. }
  8717. get isStreamingSupported() {
  8718. return false;
  8719. }
  8720. async read() {
  8721. if (this._queuedChunk) {
  8722. const chunk = this._queuedChunk;
  8723. this._queuedChunk = null;
  8724. return {
  8725. value: chunk,
  8726. done: false
  8727. };
  8728. }
  8729. if (this._done) {
  8730. return {
  8731. value: undefined,
  8732. done: true
  8733. };
  8734. }
  8735. const requestCapability = new _util.PromiseCapability();
  8736. this._requests.push(requestCapability);
  8737. return requestCapability.promise;
  8738. }
  8739. cancel(reason) {
  8740. this._done = true;
  8741. for (const requestCapability of this._requests) {
  8742. requestCapability.resolve({
  8743. value: undefined,
  8744. done: true
  8745. });
  8746. }
  8747. this._requests.length = 0;
  8748. this._stream._removeRangeReader(this);
  8749. }
  8750. }
  8751. /***/ }),
  8752. /* 19 */
  8753. /***/ ((__unused_webpack_module, exports) => {
  8754. Object.defineProperty(exports, "__esModule", ({
  8755. value: true
  8756. }));
  8757. exports.XfaText = void 0;
  8758. class XfaText {
  8759. static textContent(xfa) {
  8760. const items = [];
  8761. const output = {
  8762. items,
  8763. styles: Object.create(null)
  8764. };
  8765. function walk(node) {
  8766. if (!node) {
  8767. return;
  8768. }
  8769. let str = null;
  8770. const name = node.name;
  8771. if (name === "#text") {
  8772. str = node.value;
  8773. } else if (!XfaText.shouldBuildText(name)) {
  8774. return;
  8775. } else if (node?.attributes?.textContent) {
  8776. str = node.attributes.textContent;
  8777. } else if (node.value) {
  8778. str = node.value;
  8779. }
  8780. if (str !== null) {
  8781. items.push({
  8782. str
  8783. });
  8784. }
  8785. if (!node.children) {
  8786. return;
  8787. }
  8788. for (const child of node.children) {
  8789. walk(child);
  8790. }
  8791. }
  8792. walk(xfa);
  8793. return output;
  8794. }
  8795. static shouldBuildText(name) {
  8796. return !(name === "textarea" || name === "input" || name === "option" || name === "select");
  8797. }
  8798. }
  8799. exports.XfaText = XfaText;
  8800. /***/ }),
  8801. /* 20 */
  8802. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  8803. Object.defineProperty(exports, "__esModule", ({
  8804. value: true
  8805. }));
  8806. exports.NodeStandardFontDataFactory = exports.NodeFilterFactory = exports.NodeCanvasFactory = exports.NodeCMapReaderFactory = void 0;
  8807. var _base_factory = __w_pdfjs_require__(7);
  8808. ;
  8809. const fetchData = function (url) {
  8810. return new Promise((resolve, reject) => {
  8811. const fs = require("fs");
  8812. fs.readFile(url, (error, data) => {
  8813. if (error || !data) {
  8814. reject(new Error(error));
  8815. return;
  8816. }
  8817. resolve(new Uint8Array(data));
  8818. });
  8819. });
  8820. };
  8821. class NodeFilterFactory extends _base_factory.BaseFilterFactory {}
  8822. exports.NodeFilterFactory = NodeFilterFactory;
  8823. class NodeCanvasFactory extends _base_factory.BaseCanvasFactory {
  8824. _createCanvas(width, height) {
  8825. const Canvas = require("canvas");
  8826. return Canvas.createCanvas(width, height);
  8827. }
  8828. }
  8829. exports.NodeCanvasFactory = NodeCanvasFactory;
  8830. class NodeCMapReaderFactory extends _base_factory.BaseCMapReaderFactory {
  8831. _fetchData(url, compressionType) {
  8832. return fetchData(url).then(data => {
  8833. return {
  8834. cMapData: data,
  8835. compressionType
  8836. };
  8837. });
  8838. }
  8839. }
  8840. exports.NodeCMapReaderFactory = NodeCMapReaderFactory;
  8841. class NodeStandardFontDataFactory extends _base_factory.BaseStandardFontDataFactory {
  8842. _fetchData(url) {
  8843. return fetchData(url);
  8844. }
  8845. }
  8846. exports.NodeStandardFontDataFactory = NodeStandardFontDataFactory;
  8847. /***/ }),
  8848. /* 21 */
  8849. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  8850. Object.defineProperty(exports, "__esModule", ({
  8851. value: true
  8852. }));
  8853. exports.PDFNodeStream = void 0;
  8854. var _util = __w_pdfjs_require__(1);
  8855. var _network_utils = __w_pdfjs_require__(22);
  8856. ;
  8857. const fs = require("fs");
  8858. const http = require("http");
  8859. const https = require("https");
  8860. const url = require("url");
  8861. const fileUriRegex = /^file:\/\/\/[a-zA-Z]:\//;
  8862. function parseUrl(sourceUrl) {
  8863. const parsedUrl = url.parse(sourceUrl);
  8864. if (parsedUrl.protocol === "file:" || parsedUrl.host) {
  8865. return parsedUrl;
  8866. }
  8867. if (/^[a-z]:[/\\]/i.test(sourceUrl)) {
  8868. return url.parse(`file:///${sourceUrl}`);
  8869. }
  8870. if (!parsedUrl.host) {
  8871. parsedUrl.protocol = "file:";
  8872. }
  8873. return parsedUrl;
  8874. }
  8875. class PDFNodeStream {
  8876. constructor(source) {
  8877. this.source = source;
  8878. this.url = parseUrl(source.url);
  8879. this.isHttp = this.url.protocol === "http:" || this.url.protocol === "https:";
  8880. this.isFsUrl = this.url.protocol === "file:";
  8881. this.httpHeaders = this.isHttp && source.httpHeaders || {};
  8882. this._fullRequestReader = null;
  8883. this._rangeRequestReaders = [];
  8884. }
  8885. get _progressiveDataLength() {
  8886. return this._fullRequestReader?._loaded ?? 0;
  8887. }
  8888. getFullReader() {
  8889. (0, _util.assert)(!this._fullRequestReader, "PDFNodeStream.getFullReader can only be called once.");
  8890. this._fullRequestReader = this.isFsUrl ? new PDFNodeStreamFsFullReader(this) : new PDFNodeStreamFullReader(this);
  8891. return this._fullRequestReader;
  8892. }
  8893. getRangeReader(start, end) {
  8894. if (end <= this._progressiveDataLength) {
  8895. return null;
  8896. }
  8897. const rangeReader = this.isFsUrl ? new PDFNodeStreamFsRangeReader(this, start, end) : new PDFNodeStreamRangeReader(this, start, end);
  8898. this._rangeRequestReaders.push(rangeReader);
  8899. return rangeReader;
  8900. }
  8901. cancelAllRequests(reason) {
  8902. this._fullRequestReader?.cancel(reason);
  8903. for (const reader of this._rangeRequestReaders.slice(0)) {
  8904. reader.cancel(reason);
  8905. }
  8906. }
  8907. }
  8908. exports.PDFNodeStream = PDFNodeStream;
  8909. class BaseFullReader {
  8910. constructor(stream) {
  8911. this._url = stream.url;
  8912. this._done = false;
  8913. this._storedError = null;
  8914. this.onProgress = null;
  8915. const source = stream.source;
  8916. this._contentLength = source.length;
  8917. this._loaded = 0;
  8918. this._filename = null;
  8919. this._disableRange = source.disableRange || false;
  8920. this._rangeChunkSize = source.rangeChunkSize;
  8921. if (!this._rangeChunkSize && !this._disableRange) {
  8922. this._disableRange = true;
  8923. }
  8924. this._isStreamingSupported = !source.disableStream;
  8925. this._isRangeSupported = !source.disableRange;
  8926. this._readableStream = null;
  8927. this._readCapability = new _util.PromiseCapability();
  8928. this._headersCapability = new _util.PromiseCapability();
  8929. }
  8930. get headersReady() {
  8931. return this._headersCapability.promise;
  8932. }
  8933. get filename() {
  8934. return this._filename;
  8935. }
  8936. get contentLength() {
  8937. return this._contentLength;
  8938. }
  8939. get isRangeSupported() {
  8940. return this._isRangeSupported;
  8941. }
  8942. get isStreamingSupported() {
  8943. return this._isStreamingSupported;
  8944. }
  8945. async read() {
  8946. await this._readCapability.promise;
  8947. if (this._done) {
  8948. return {
  8949. value: undefined,
  8950. done: true
  8951. };
  8952. }
  8953. if (this._storedError) {
  8954. throw this._storedError;
  8955. }
  8956. const chunk = this._readableStream.read();
  8957. if (chunk === null) {
  8958. this._readCapability = new _util.PromiseCapability();
  8959. return this.read();
  8960. }
  8961. this._loaded += chunk.length;
  8962. this.onProgress?.({
  8963. loaded: this._loaded,
  8964. total: this._contentLength
  8965. });
  8966. const buffer = new Uint8Array(chunk).buffer;
  8967. return {
  8968. value: buffer,
  8969. done: false
  8970. };
  8971. }
  8972. cancel(reason) {
  8973. if (!this._readableStream) {
  8974. this._error(reason);
  8975. return;
  8976. }
  8977. this._readableStream.destroy(reason);
  8978. }
  8979. _error(reason) {
  8980. this._storedError = reason;
  8981. this._readCapability.resolve();
  8982. }
  8983. _setReadableStream(readableStream) {
  8984. this._readableStream = readableStream;
  8985. readableStream.on("readable", () => {
  8986. this._readCapability.resolve();
  8987. });
  8988. readableStream.on("end", () => {
  8989. readableStream.destroy();
  8990. this._done = true;
  8991. this._readCapability.resolve();
  8992. });
  8993. readableStream.on("error", reason => {
  8994. this._error(reason);
  8995. });
  8996. if (!this._isStreamingSupported && this._isRangeSupported) {
  8997. this._error(new _util.AbortException("streaming is disabled"));
  8998. }
  8999. if (this._storedError) {
  9000. this._readableStream.destroy(this._storedError);
  9001. }
  9002. }
  9003. }
  9004. class BaseRangeReader {
  9005. constructor(stream) {
  9006. this._url = stream.url;
  9007. this._done = false;
  9008. this._storedError = null;
  9009. this.onProgress = null;
  9010. this._loaded = 0;
  9011. this._readableStream = null;
  9012. this._readCapability = new _util.PromiseCapability();
  9013. const source = stream.source;
  9014. this._isStreamingSupported = !source.disableStream;
  9015. }
  9016. get isStreamingSupported() {
  9017. return this._isStreamingSupported;
  9018. }
  9019. async read() {
  9020. await this._readCapability.promise;
  9021. if (this._done) {
  9022. return {
  9023. value: undefined,
  9024. done: true
  9025. };
  9026. }
  9027. if (this._storedError) {
  9028. throw this._storedError;
  9029. }
  9030. const chunk = this._readableStream.read();
  9031. if (chunk === null) {
  9032. this._readCapability = new _util.PromiseCapability();
  9033. return this.read();
  9034. }
  9035. this._loaded += chunk.length;
  9036. this.onProgress?.({
  9037. loaded: this._loaded
  9038. });
  9039. const buffer = new Uint8Array(chunk).buffer;
  9040. return {
  9041. value: buffer,
  9042. done: false
  9043. };
  9044. }
  9045. cancel(reason) {
  9046. if (!this._readableStream) {
  9047. this._error(reason);
  9048. return;
  9049. }
  9050. this._readableStream.destroy(reason);
  9051. }
  9052. _error(reason) {
  9053. this._storedError = reason;
  9054. this._readCapability.resolve();
  9055. }
  9056. _setReadableStream(readableStream) {
  9057. this._readableStream = readableStream;
  9058. readableStream.on("readable", () => {
  9059. this._readCapability.resolve();
  9060. });
  9061. readableStream.on("end", () => {
  9062. readableStream.destroy();
  9063. this._done = true;
  9064. this._readCapability.resolve();
  9065. });
  9066. readableStream.on("error", reason => {
  9067. this._error(reason);
  9068. });
  9069. if (this._storedError) {
  9070. this._readableStream.destroy(this._storedError);
  9071. }
  9072. }
  9073. }
  9074. function createRequestOptions(parsedUrl, headers) {
  9075. return {
  9076. protocol: parsedUrl.protocol,
  9077. auth: parsedUrl.auth,
  9078. host: parsedUrl.hostname,
  9079. port: parsedUrl.port,
  9080. path: parsedUrl.path,
  9081. method: "GET",
  9082. headers
  9083. };
  9084. }
  9085. class PDFNodeStreamFullReader extends BaseFullReader {
  9086. constructor(stream) {
  9087. super(stream);
  9088. const handleResponse = response => {
  9089. if (response.statusCode === 404) {
  9090. const error = new _util.MissingPDFException(`Missing PDF "${this._url}".`);
  9091. this._storedError = error;
  9092. this._headersCapability.reject(error);
  9093. return;
  9094. }
  9095. this._headersCapability.resolve();
  9096. this._setReadableStream(response);
  9097. const getResponseHeader = name => {
  9098. return this._readableStream.headers[name.toLowerCase()];
  9099. };
  9100. const {
  9101. allowRangeRequests,
  9102. suggestedLength
  9103. } = (0, _network_utils.validateRangeRequestCapabilities)({
  9104. getResponseHeader,
  9105. isHttp: stream.isHttp,
  9106. rangeChunkSize: this._rangeChunkSize,
  9107. disableRange: this._disableRange
  9108. });
  9109. this._isRangeSupported = allowRangeRequests;
  9110. this._contentLength = suggestedLength || this._contentLength;
  9111. this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
  9112. };
  9113. this._request = null;
  9114. if (this._url.protocol === "http:") {
  9115. this._request = http.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
  9116. } else {
  9117. this._request = https.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
  9118. }
  9119. this._request.on("error", reason => {
  9120. this._storedError = reason;
  9121. this._headersCapability.reject(reason);
  9122. });
  9123. this._request.end();
  9124. }
  9125. }
  9126. class PDFNodeStreamRangeReader extends BaseRangeReader {
  9127. constructor(stream, start, end) {
  9128. super(stream);
  9129. this._httpHeaders = {};
  9130. for (const property in stream.httpHeaders) {
  9131. const value = stream.httpHeaders[property];
  9132. if (value === undefined) {
  9133. continue;
  9134. }
  9135. this._httpHeaders[property] = value;
  9136. }
  9137. this._httpHeaders.Range = `bytes=${start}-${end - 1}`;
  9138. const handleResponse = response => {
  9139. if (response.statusCode === 404) {
  9140. const error = new _util.MissingPDFException(`Missing PDF "${this._url}".`);
  9141. this._storedError = error;
  9142. return;
  9143. }
  9144. this._setReadableStream(response);
  9145. };
  9146. this._request = null;
  9147. if (this._url.protocol === "http:") {
  9148. this._request = http.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
  9149. } else {
  9150. this._request = https.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
  9151. }
  9152. this._request.on("error", reason => {
  9153. this._storedError = reason;
  9154. });
  9155. this._request.end();
  9156. }
  9157. }
  9158. class PDFNodeStreamFsFullReader extends BaseFullReader {
  9159. constructor(stream) {
  9160. super(stream);
  9161. let path = decodeURIComponent(this._url.path);
  9162. if (fileUriRegex.test(this._url.href)) {
  9163. path = path.replace(/^\//, "");
  9164. }
  9165. fs.lstat(path, (error, stat) => {
  9166. if (error) {
  9167. if (error.code === "ENOENT") {
  9168. error = new _util.MissingPDFException(`Missing PDF "${path}".`);
  9169. }
  9170. this._storedError = error;
  9171. this._headersCapability.reject(error);
  9172. return;
  9173. }
  9174. this._contentLength = stat.size;
  9175. this._setReadableStream(fs.createReadStream(path));
  9176. this._headersCapability.resolve();
  9177. });
  9178. }
  9179. }
  9180. class PDFNodeStreamFsRangeReader extends BaseRangeReader {
  9181. constructor(stream, start, end) {
  9182. super(stream);
  9183. let path = decodeURIComponent(this._url.path);
  9184. if (fileUriRegex.test(this._url.href)) {
  9185. path = path.replace(/^\//, "");
  9186. }
  9187. this._setReadableStream(fs.createReadStream(path, {
  9188. start,
  9189. end: end - 1
  9190. }));
  9191. }
  9192. }
  9193. /***/ }),
  9194. /* 22 */
  9195. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  9196. Object.defineProperty(exports, "__esModule", ({
  9197. value: true
  9198. }));
  9199. exports.createResponseStatusError = createResponseStatusError;
  9200. exports.extractFilenameFromHeader = extractFilenameFromHeader;
  9201. exports.validateRangeRequestCapabilities = validateRangeRequestCapabilities;
  9202. exports.validateResponseStatus = validateResponseStatus;
  9203. var _util = __w_pdfjs_require__(1);
  9204. var _content_disposition = __w_pdfjs_require__(23);
  9205. var _display_utils = __w_pdfjs_require__(6);
  9206. function validateRangeRequestCapabilities({
  9207. getResponseHeader,
  9208. isHttp,
  9209. rangeChunkSize,
  9210. disableRange
  9211. }) {
  9212. const returnValues = {
  9213. allowRangeRequests: false,
  9214. suggestedLength: undefined
  9215. };
  9216. const length = parseInt(getResponseHeader("Content-Length"), 10);
  9217. if (!Number.isInteger(length)) {
  9218. return returnValues;
  9219. }
  9220. returnValues.suggestedLength = length;
  9221. if (length <= 2 * rangeChunkSize) {
  9222. return returnValues;
  9223. }
  9224. if (disableRange || !isHttp) {
  9225. return returnValues;
  9226. }
  9227. if (getResponseHeader("Accept-Ranges") !== "bytes") {
  9228. return returnValues;
  9229. }
  9230. const contentEncoding = getResponseHeader("Content-Encoding") || "identity";
  9231. if (contentEncoding !== "identity") {
  9232. return returnValues;
  9233. }
  9234. returnValues.allowRangeRequests = true;
  9235. return returnValues;
  9236. }
  9237. function extractFilenameFromHeader(getResponseHeader) {
  9238. const contentDisposition = getResponseHeader("Content-Disposition");
  9239. if (contentDisposition) {
  9240. let filename = (0, _content_disposition.getFilenameFromContentDispositionHeader)(contentDisposition);
  9241. if (filename.includes("%")) {
  9242. try {
  9243. filename = decodeURIComponent(filename);
  9244. } catch (ex) {}
  9245. }
  9246. if ((0, _display_utils.isPdfFile)(filename)) {
  9247. return filename;
  9248. }
  9249. }
  9250. return null;
  9251. }
  9252. function createResponseStatusError(status, url) {
  9253. if (status === 404 || status === 0 && url.startsWith("file:")) {
  9254. return new _util.MissingPDFException('Missing PDF "' + url + '".');
  9255. }
  9256. return new _util.UnexpectedResponseException(`Unexpected server response (${status}) while retrieving PDF "${url}".`, status);
  9257. }
  9258. function validateResponseStatus(status) {
  9259. return status === 200 || status === 206;
  9260. }
  9261. /***/ }),
  9262. /* 23 */
  9263. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  9264. Object.defineProperty(exports, "__esModule", ({
  9265. value: true
  9266. }));
  9267. exports.getFilenameFromContentDispositionHeader = getFilenameFromContentDispositionHeader;
  9268. var _util = __w_pdfjs_require__(1);
  9269. function getFilenameFromContentDispositionHeader(contentDisposition) {
  9270. let needsEncodingFixup = true;
  9271. let tmp = toParamRegExp("filename\\*", "i").exec(contentDisposition);
  9272. if (tmp) {
  9273. tmp = tmp[1];
  9274. let filename = rfc2616unquote(tmp);
  9275. filename = unescape(filename);
  9276. filename = rfc5987decode(filename);
  9277. filename = rfc2047decode(filename);
  9278. return fixupEncoding(filename);
  9279. }
  9280. tmp = rfc2231getparam(contentDisposition);
  9281. if (tmp) {
  9282. const filename = rfc2047decode(tmp);
  9283. return fixupEncoding(filename);
  9284. }
  9285. tmp = toParamRegExp("filename", "i").exec(contentDisposition);
  9286. if (tmp) {
  9287. tmp = tmp[1];
  9288. let filename = rfc2616unquote(tmp);
  9289. filename = rfc2047decode(filename);
  9290. return fixupEncoding(filename);
  9291. }
  9292. function toParamRegExp(attributePattern, flags) {
  9293. return new RegExp("(?:^|;)\\s*" + attributePattern + "\\s*=\\s*" + "(" + '[^";\\s][^;\\s]*' + "|" + '"(?:[^"\\\\]|\\\\"?)+"?' + ")", flags);
  9294. }
  9295. function textdecode(encoding, value) {
  9296. if (encoding) {
  9297. if (!/^[\x00-\xFF]+$/.test(value)) {
  9298. return value;
  9299. }
  9300. try {
  9301. const decoder = new TextDecoder(encoding, {
  9302. fatal: true
  9303. });
  9304. const buffer = (0, _util.stringToBytes)(value);
  9305. value = decoder.decode(buffer);
  9306. needsEncodingFixup = false;
  9307. } catch (e) {}
  9308. }
  9309. return value;
  9310. }
  9311. function fixupEncoding(value) {
  9312. if (needsEncodingFixup && /[\x80-\xff]/.test(value)) {
  9313. value = textdecode("utf-8", value);
  9314. if (needsEncodingFixup) {
  9315. value = textdecode("iso-8859-1", value);
  9316. }
  9317. }
  9318. return value;
  9319. }
  9320. function rfc2231getparam(contentDispositionStr) {
  9321. const matches = [];
  9322. let match;
  9323. const iter = toParamRegExp("filename\\*((?!0\\d)\\d+)(\\*?)", "ig");
  9324. while ((match = iter.exec(contentDispositionStr)) !== null) {
  9325. let [, n, quot, part] = match;
  9326. n = parseInt(n, 10);
  9327. if (n in matches) {
  9328. if (n === 0) {
  9329. break;
  9330. }
  9331. continue;
  9332. }
  9333. matches[n] = [quot, part];
  9334. }
  9335. const parts = [];
  9336. for (let n = 0; n < matches.length; ++n) {
  9337. if (!(n in matches)) {
  9338. break;
  9339. }
  9340. let [quot, part] = matches[n];
  9341. part = rfc2616unquote(part);
  9342. if (quot) {
  9343. part = unescape(part);
  9344. if (n === 0) {
  9345. part = rfc5987decode(part);
  9346. }
  9347. }
  9348. parts.push(part);
  9349. }
  9350. return parts.join("");
  9351. }
  9352. function rfc2616unquote(value) {
  9353. if (value.startsWith('"')) {
  9354. const parts = value.slice(1).split('\\"');
  9355. for (let i = 0; i < parts.length; ++i) {
  9356. const quotindex = parts[i].indexOf('"');
  9357. if (quotindex !== -1) {
  9358. parts[i] = parts[i].slice(0, quotindex);
  9359. parts.length = i + 1;
  9360. }
  9361. parts[i] = parts[i].replaceAll(/\\(.)/g, "$1");
  9362. }
  9363. value = parts.join('"');
  9364. }
  9365. return value;
  9366. }
  9367. function rfc5987decode(extvalue) {
  9368. const encodingend = extvalue.indexOf("'");
  9369. if (encodingend === -1) {
  9370. return extvalue;
  9371. }
  9372. const encoding = extvalue.slice(0, encodingend);
  9373. const langvalue = extvalue.slice(encodingend + 1);
  9374. const value = langvalue.replace(/^[^']*'/, "");
  9375. return textdecode(encoding, value);
  9376. }
  9377. function rfc2047decode(value) {
  9378. if (!value.startsWith("=?") || /[\x00-\x19\x80-\xff]/.test(value)) {
  9379. return value;
  9380. }
  9381. return value.replaceAll(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g, function (matches, charset, encoding, text) {
  9382. if (encoding === "q" || encoding === "Q") {
  9383. text = text.replaceAll("_", " ");
  9384. text = text.replaceAll(/=([0-9a-fA-F]{2})/g, function (match, hex) {
  9385. return String.fromCharCode(parseInt(hex, 16));
  9386. });
  9387. return textdecode(charset, text);
  9388. }
  9389. try {
  9390. text = atob(text);
  9391. } catch (e) {}
  9392. return textdecode(charset, text);
  9393. });
  9394. }
  9395. return "";
  9396. }
  9397. /***/ }),
  9398. /* 24 */
  9399. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  9400. Object.defineProperty(exports, "__esModule", ({
  9401. value: true
  9402. }));
  9403. exports.PDFNetworkStream = void 0;
  9404. var _util = __w_pdfjs_require__(1);
  9405. var _network_utils = __w_pdfjs_require__(22);
  9406. ;
  9407. const OK_RESPONSE = 200;
  9408. const PARTIAL_CONTENT_RESPONSE = 206;
  9409. function getArrayBuffer(xhr) {
  9410. const data = xhr.response;
  9411. if (typeof data !== "string") {
  9412. return data;
  9413. }
  9414. return (0, _util.stringToBytes)(data).buffer;
  9415. }
  9416. class NetworkManager {
  9417. constructor(url, args = {}) {
  9418. this.url = url;
  9419. this.isHttp = /^https?:/i.test(url);
  9420. this.httpHeaders = this.isHttp && args.httpHeaders || Object.create(null);
  9421. this.withCredentials = args.withCredentials || false;
  9422. this.currXhrId = 0;
  9423. this.pendingRequests = Object.create(null);
  9424. }
  9425. requestRange(begin, end, listeners) {
  9426. const args = {
  9427. begin,
  9428. end
  9429. };
  9430. for (const prop in listeners) {
  9431. args[prop] = listeners[prop];
  9432. }
  9433. return this.request(args);
  9434. }
  9435. requestFull(listeners) {
  9436. return this.request(listeners);
  9437. }
  9438. request(args) {
  9439. const xhr = new XMLHttpRequest();
  9440. const xhrId = this.currXhrId++;
  9441. const pendingRequest = this.pendingRequests[xhrId] = {
  9442. xhr
  9443. };
  9444. xhr.open("GET", this.url);
  9445. xhr.withCredentials = this.withCredentials;
  9446. for (const property in this.httpHeaders) {
  9447. const value = this.httpHeaders[property];
  9448. if (value === undefined) {
  9449. continue;
  9450. }
  9451. xhr.setRequestHeader(property, value);
  9452. }
  9453. if (this.isHttp && "begin" in args && "end" in args) {
  9454. xhr.setRequestHeader("Range", `bytes=${args.begin}-${args.end - 1}`);
  9455. pendingRequest.expectedStatus = PARTIAL_CONTENT_RESPONSE;
  9456. } else {
  9457. pendingRequest.expectedStatus = OK_RESPONSE;
  9458. }
  9459. xhr.responseType = "arraybuffer";
  9460. if (args.onError) {
  9461. xhr.onerror = function (evt) {
  9462. args.onError(xhr.status);
  9463. };
  9464. }
  9465. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  9466. xhr.onprogress = this.onProgress.bind(this, xhrId);
  9467. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  9468. pendingRequest.onDone = args.onDone;
  9469. pendingRequest.onError = args.onError;
  9470. pendingRequest.onProgress = args.onProgress;
  9471. xhr.send(null);
  9472. return xhrId;
  9473. }
  9474. onProgress(xhrId, evt) {
  9475. const pendingRequest = this.pendingRequests[xhrId];
  9476. if (!pendingRequest) {
  9477. return;
  9478. }
  9479. pendingRequest.onProgress?.(evt);
  9480. }
  9481. onStateChange(xhrId, evt) {
  9482. const pendingRequest = this.pendingRequests[xhrId];
  9483. if (!pendingRequest) {
  9484. return;
  9485. }
  9486. const xhr = pendingRequest.xhr;
  9487. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  9488. pendingRequest.onHeadersReceived();
  9489. delete pendingRequest.onHeadersReceived;
  9490. }
  9491. if (xhr.readyState !== 4) {
  9492. return;
  9493. }
  9494. if (!(xhrId in this.pendingRequests)) {
  9495. return;
  9496. }
  9497. delete this.pendingRequests[xhrId];
  9498. if (xhr.status === 0 && this.isHttp) {
  9499. pendingRequest.onError?.(xhr.status);
  9500. return;
  9501. }
  9502. const xhrStatus = xhr.status || OK_RESPONSE;
  9503. const ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  9504. if (!ok_response_on_range_request && xhrStatus !== pendingRequest.expectedStatus) {
  9505. pendingRequest.onError?.(xhr.status);
  9506. return;
  9507. }
  9508. const chunk = getArrayBuffer(xhr);
  9509. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  9510. const rangeHeader = xhr.getResponseHeader("Content-Range");
  9511. const matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  9512. pendingRequest.onDone({
  9513. begin: parseInt(matches[1], 10),
  9514. chunk
  9515. });
  9516. } else if (chunk) {
  9517. pendingRequest.onDone({
  9518. begin: 0,
  9519. chunk
  9520. });
  9521. } else {
  9522. pendingRequest.onError?.(xhr.status);
  9523. }
  9524. }
  9525. getRequestXhr(xhrId) {
  9526. return this.pendingRequests[xhrId].xhr;
  9527. }
  9528. isPendingRequest(xhrId) {
  9529. return xhrId in this.pendingRequests;
  9530. }
  9531. abortRequest(xhrId) {
  9532. const xhr = this.pendingRequests[xhrId].xhr;
  9533. delete this.pendingRequests[xhrId];
  9534. xhr.abort();
  9535. }
  9536. }
  9537. class PDFNetworkStream {
  9538. constructor(source) {
  9539. this._source = source;
  9540. this._manager = new NetworkManager(source.url, {
  9541. httpHeaders: source.httpHeaders,
  9542. withCredentials: source.withCredentials
  9543. });
  9544. this._rangeChunkSize = source.rangeChunkSize;
  9545. this._fullRequestReader = null;
  9546. this._rangeRequestReaders = [];
  9547. }
  9548. _onRangeRequestReaderClosed(reader) {
  9549. const i = this._rangeRequestReaders.indexOf(reader);
  9550. if (i >= 0) {
  9551. this._rangeRequestReaders.splice(i, 1);
  9552. }
  9553. }
  9554. getFullReader() {
  9555. (0, _util.assert)(!this._fullRequestReader, "PDFNetworkStream.getFullReader can only be called once.");
  9556. this._fullRequestReader = new PDFNetworkStreamFullRequestReader(this._manager, this._source);
  9557. return this._fullRequestReader;
  9558. }
  9559. getRangeReader(begin, end) {
  9560. const reader = new PDFNetworkStreamRangeRequestReader(this._manager, begin, end);
  9561. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  9562. this._rangeRequestReaders.push(reader);
  9563. return reader;
  9564. }
  9565. cancelAllRequests(reason) {
  9566. this._fullRequestReader?.cancel(reason);
  9567. for (const reader of this._rangeRequestReaders.slice(0)) {
  9568. reader.cancel(reason);
  9569. }
  9570. }
  9571. }
  9572. exports.PDFNetworkStream = PDFNetworkStream;
  9573. class PDFNetworkStreamFullRequestReader {
  9574. constructor(manager, source) {
  9575. this._manager = manager;
  9576. const args = {
  9577. onHeadersReceived: this._onHeadersReceived.bind(this),
  9578. onDone: this._onDone.bind(this),
  9579. onError: this._onError.bind(this),
  9580. onProgress: this._onProgress.bind(this)
  9581. };
  9582. this._url = source.url;
  9583. this._fullRequestId = manager.requestFull(args);
  9584. this._headersReceivedCapability = new _util.PromiseCapability();
  9585. this._disableRange = source.disableRange || false;
  9586. this._contentLength = source.length;
  9587. this._rangeChunkSize = source.rangeChunkSize;
  9588. if (!this._rangeChunkSize && !this._disableRange) {
  9589. this._disableRange = true;
  9590. }
  9591. this._isStreamingSupported = false;
  9592. this._isRangeSupported = false;
  9593. this._cachedChunks = [];
  9594. this._requests = [];
  9595. this._done = false;
  9596. this._storedError = undefined;
  9597. this._filename = null;
  9598. this.onProgress = null;
  9599. }
  9600. _onHeadersReceived() {
  9601. const fullRequestXhrId = this._fullRequestId;
  9602. const fullRequestXhr = this._manager.getRequestXhr(fullRequestXhrId);
  9603. const getResponseHeader = name => {
  9604. return fullRequestXhr.getResponseHeader(name);
  9605. };
  9606. const {
  9607. allowRangeRequests,
  9608. suggestedLength
  9609. } = (0, _network_utils.validateRangeRequestCapabilities)({
  9610. getResponseHeader,
  9611. isHttp: this._manager.isHttp,
  9612. rangeChunkSize: this._rangeChunkSize,
  9613. disableRange: this._disableRange
  9614. });
  9615. if (allowRangeRequests) {
  9616. this._isRangeSupported = true;
  9617. }
  9618. this._contentLength = suggestedLength || this._contentLength;
  9619. this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
  9620. if (this._isRangeSupported) {
  9621. this._manager.abortRequest(fullRequestXhrId);
  9622. }
  9623. this._headersReceivedCapability.resolve();
  9624. }
  9625. _onDone(data) {
  9626. if (data) {
  9627. if (this._requests.length > 0) {
  9628. const requestCapability = this._requests.shift();
  9629. requestCapability.resolve({
  9630. value: data.chunk,
  9631. done: false
  9632. });
  9633. } else {
  9634. this._cachedChunks.push(data.chunk);
  9635. }
  9636. }
  9637. this._done = true;
  9638. if (this._cachedChunks.length > 0) {
  9639. return;
  9640. }
  9641. for (const requestCapability of this._requests) {
  9642. requestCapability.resolve({
  9643. value: undefined,
  9644. done: true
  9645. });
  9646. }
  9647. this._requests.length = 0;
  9648. }
  9649. _onError(status) {
  9650. this._storedError = (0, _network_utils.createResponseStatusError)(status, this._url);
  9651. this._headersReceivedCapability.reject(this._storedError);
  9652. for (const requestCapability of this._requests) {
  9653. requestCapability.reject(this._storedError);
  9654. }
  9655. this._requests.length = 0;
  9656. this._cachedChunks.length = 0;
  9657. }
  9658. _onProgress(evt) {
  9659. this.onProgress?.({
  9660. loaded: evt.loaded,
  9661. total: evt.lengthComputable ? evt.total : this._contentLength
  9662. });
  9663. }
  9664. get filename() {
  9665. return this._filename;
  9666. }
  9667. get isRangeSupported() {
  9668. return this._isRangeSupported;
  9669. }
  9670. get isStreamingSupported() {
  9671. return this._isStreamingSupported;
  9672. }
  9673. get contentLength() {
  9674. return this._contentLength;
  9675. }
  9676. get headersReady() {
  9677. return this._headersReceivedCapability.promise;
  9678. }
  9679. async read() {
  9680. if (this._storedError) {
  9681. throw this._storedError;
  9682. }
  9683. if (this._cachedChunks.length > 0) {
  9684. const chunk = this._cachedChunks.shift();
  9685. return {
  9686. value: chunk,
  9687. done: false
  9688. };
  9689. }
  9690. if (this._done) {
  9691. return {
  9692. value: undefined,
  9693. done: true
  9694. };
  9695. }
  9696. const requestCapability = new _util.PromiseCapability();
  9697. this._requests.push(requestCapability);
  9698. return requestCapability.promise;
  9699. }
  9700. cancel(reason) {
  9701. this._done = true;
  9702. this._headersReceivedCapability.reject(reason);
  9703. for (const requestCapability of this._requests) {
  9704. requestCapability.resolve({
  9705. value: undefined,
  9706. done: true
  9707. });
  9708. }
  9709. this._requests.length = 0;
  9710. if (this._manager.isPendingRequest(this._fullRequestId)) {
  9711. this._manager.abortRequest(this._fullRequestId);
  9712. }
  9713. this._fullRequestReader = null;
  9714. }
  9715. }
  9716. class PDFNetworkStreamRangeRequestReader {
  9717. constructor(manager, begin, end) {
  9718. this._manager = manager;
  9719. const args = {
  9720. onDone: this._onDone.bind(this),
  9721. onError: this._onError.bind(this),
  9722. onProgress: this._onProgress.bind(this)
  9723. };
  9724. this._url = manager.url;
  9725. this._requestId = manager.requestRange(begin, end, args);
  9726. this._requests = [];
  9727. this._queuedChunk = null;
  9728. this._done = false;
  9729. this._storedError = undefined;
  9730. this.onProgress = null;
  9731. this.onClosed = null;
  9732. }
  9733. _close() {
  9734. this.onClosed?.(this);
  9735. }
  9736. _onDone(data) {
  9737. const chunk = data.chunk;
  9738. if (this._requests.length > 0) {
  9739. const requestCapability = this._requests.shift();
  9740. requestCapability.resolve({
  9741. value: chunk,
  9742. done: false
  9743. });
  9744. } else {
  9745. this._queuedChunk = chunk;
  9746. }
  9747. this._done = true;
  9748. for (const requestCapability of this._requests) {
  9749. requestCapability.resolve({
  9750. value: undefined,
  9751. done: true
  9752. });
  9753. }
  9754. this._requests.length = 0;
  9755. this._close();
  9756. }
  9757. _onError(status) {
  9758. this._storedError = (0, _network_utils.createResponseStatusError)(status, this._url);
  9759. for (const requestCapability of this._requests) {
  9760. requestCapability.reject(this._storedError);
  9761. }
  9762. this._requests.length = 0;
  9763. this._queuedChunk = null;
  9764. }
  9765. _onProgress(evt) {
  9766. if (!this.isStreamingSupported) {
  9767. this.onProgress?.({
  9768. loaded: evt.loaded
  9769. });
  9770. }
  9771. }
  9772. get isStreamingSupported() {
  9773. return false;
  9774. }
  9775. async read() {
  9776. if (this._storedError) {
  9777. throw this._storedError;
  9778. }
  9779. if (this._queuedChunk !== null) {
  9780. const chunk = this._queuedChunk;
  9781. this._queuedChunk = null;
  9782. return {
  9783. value: chunk,
  9784. done: false
  9785. };
  9786. }
  9787. if (this._done) {
  9788. return {
  9789. value: undefined,
  9790. done: true
  9791. };
  9792. }
  9793. const requestCapability = new _util.PromiseCapability();
  9794. this._requests.push(requestCapability);
  9795. return requestCapability.promise;
  9796. }
  9797. cancel(reason) {
  9798. this._done = true;
  9799. for (const requestCapability of this._requests) {
  9800. requestCapability.resolve({
  9801. value: undefined,
  9802. done: true
  9803. });
  9804. }
  9805. this._requests.length = 0;
  9806. if (this._manager.isPendingRequest(this._requestId)) {
  9807. this._manager.abortRequest(this._requestId);
  9808. }
  9809. this._close();
  9810. }
  9811. }
  9812. /***/ }),
  9813. /* 25 */
  9814. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  9815. Object.defineProperty(exports, "__esModule", ({
  9816. value: true
  9817. }));
  9818. exports.PDFFetchStream = void 0;
  9819. var _util = __w_pdfjs_require__(1);
  9820. var _network_utils = __w_pdfjs_require__(22);
  9821. ;
  9822. function createFetchOptions(headers, withCredentials, abortController) {
  9823. return {
  9824. method: "GET",
  9825. headers,
  9826. signal: abortController.signal,
  9827. mode: "cors",
  9828. credentials: withCredentials ? "include" : "same-origin",
  9829. redirect: "follow"
  9830. };
  9831. }
  9832. function createHeaders(httpHeaders) {
  9833. const headers = new Headers();
  9834. for (const property in httpHeaders) {
  9835. const value = httpHeaders[property];
  9836. if (value === undefined) {
  9837. continue;
  9838. }
  9839. headers.append(property, value);
  9840. }
  9841. return headers;
  9842. }
  9843. function getArrayBuffer(val) {
  9844. if (val instanceof Uint8Array) {
  9845. return val.buffer;
  9846. }
  9847. if (val instanceof ArrayBuffer) {
  9848. return val;
  9849. }
  9850. (0, _util.warn)(`getArrayBuffer - unexpected data format: ${val}`);
  9851. return new Uint8Array(val).buffer;
  9852. }
  9853. class PDFFetchStream {
  9854. constructor(source) {
  9855. this.source = source;
  9856. this.isHttp = /^https?:/i.test(source.url);
  9857. this.httpHeaders = this.isHttp && source.httpHeaders || {};
  9858. this._fullRequestReader = null;
  9859. this._rangeRequestReaders = [];
  9860. }
  9861. get _progressiveDataLength() {
  9862. return this._fullRequestReader?._loaded ?? 0;
  9863. }
  9864. getFullReader() {
  9865. (0, _util.assert)(!this._fullRequestReader, "PDFFetchStream.getFullReader can only be called once.");
  9866. this._fullRequestReader = new PDFFetchStreamReader(this);
  9867. return this._fullRequestReader;
  9868. }
  9869. getRangeReader(begin, end) {
  9870. if (end <= this._progressiveDataLength) {
  9871. return null;
  9872. }
  9873. const reader = new PDFFetchStreamRangeReader(this, begin, end);
  9874. this._rangeRequestReaders.push(reader);
  9875. return reader;
  9876. }
  9877. cancelAllRequests(reason) {
  9878. this._fullRequestReader?.cancel(reason);
  9879. for (const reader of this._rangeRequestReaders.slice(0)) {
  9880. reader.cancel(reason);
  9881. }
  9882. }
  9883. }
  9884. exports.PDFFetchStream = PDFFetchStream;
  9885. class PDFFetchStreamReader {
  9886. constructor(stream) {
  9887. this._stream = stream;
  9888. this._reader = null;
  9889. this._loaded = 0;
  9890. this._filename = null;
  9891. const source = stream.source;
  9892. this._withCredentials = source.withCredentials || false;
  9893. this._contentLength = source.length;
  9894. this._headersCapability = new _util.PromiseCapability();
  9895. this._disableRange = source.disableRange || false;
  9896. this._rangeChunkSize = source.rangeChunkSize;
  9897. if (!this._rangeChunkSize && !this._disableRange) {
  9898. this._disableRange = true;
  9899. }
  9900. this._abortController = new AbortController();
  9901. this._isStreamingSupported = !source.disableStream;
  9902. this._isRangeSupported = !source.disableRange;
  9903. this._headers = createHeaders(this._stream.httpHeaders);
  9904. const url = source.url;
  9905. fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(response => {
  9906. if (!(0, _network_utils.validateResponseStatus)(response.status)) {
  9907. throw (0, _network_utils.createResponseStatusError)(response.status, url);
  9908. }
  9909. this._reader = response.body.getReader();
  9910. this._headersCapability.resolve();
  9911. const getResponseHeader = name => {
  9912. return response.headers.get(name);
  9913. };
  9914. const {
  9915. allowRangeRequests,
  9916. suggestedLength
  9917. } = (0, _network_utils.validateRangeRequestCapabilities)({
  9918. getResponseHeader,
  9919. isHttp: this._stream.isHttp,
  9920. rangeChunkSize: this._rangeChunkSize,
  9921. disableRange: this._disableRange
  9922. });
  9923. this._isRangeSupported = allowRangeRequests;
  9924. this._contentLength = suggestedLength || this._contentLength;
  9925. this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
  9926. if (!this._isStreamingSupported && this._isRangeSupported) {
  9927. this.cancel(new _util.AbortException("Streaming is disabled."));
  9928. }
  9929. }).catch(this._headersCapability.reject);
  9930. this.onProgress = null;
  9931. }
  9932. get headersReady() {
  9933. return this._headersCapability.promise;
  9934. }
  9935. get filename() {
  9936. return this._filename;
  9937. }
  9938. get contentLength() {
  9939. return this._contentLength;
  9940. }
  9941. get isRangeSupported() {
  9942. return this._isRangeSupported;
  9943. }
  9944. get isStreamingSupported() {
  9945. return this._isStreamingSupported;
  9946. }
  9947. async read() {
  9948. await this._headersCapability.promise;
  9949. const {
  9950. value,
  9951. done
  9952. } = await this._reader.read();
  9953. if (done) {
  9954. return {
  9955. value,
  9956. done
  9957. };
  9958. }
  9959. this._loaded += value.byteLength;
  9960. this.onProgress?.({
  9961. loaded: this._loaded,
  9962. total: this._contentLength
  9963. });
  9964. return {
  9965. value: getArrayBuffer(value),
  9966. done: false
  9967. };
  9968. }
  9969. cancel(reason) {
  9970. this._reader?.cancel(reason);
  9971. this._abortController.abort();
  9972. }
  9973. }
  9974. class PDFFetchStreamRangeReader {
  9975. constructor(stream, begin, end) {
  9976. this._stream = stream;
  9977. this._reader = null;
  9978. this._loaded = 0;
  9979. const source = stream.source;
  9980. this._withCredentials = source.withCredentials || false;
  9981. this._readCapability = new _util.PromiseCapability();
  9982. this._isStreamingSupported = !source.disableStream;
  9983. this._abortController = new AbortController();
  9984. this._headers = createHeaders(this._stream.httpHeaders);
  9985. this._headers.append("Range", `bytes=${begin}-${end - 1}`);
  9986. const url = source.url;
  9987. fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(response => {
  9988. if (!(0, _network_utils.validateResponseStatus)(response.status)) {
  9989. throw (0, _network_utils.createResponseStatusError)(response.status, url);
  9990. }
  9991. this._readCapability.resolve();
  9992. this._reader = response.body.getReader();
  9993. }).catch(this._readCapability.reject);
  9994. this.onProgress = null;
  9995. }
  9996. get isStreamingSupported() {
  9997. return this._isStreamingSupported;
  9998. }
  9999. async read() {
  10000. await this._readCapability.promise;
  10001. const {
  10002. value,
  10003. done
  10004. } = await this._reader.read();
  10005. if (done) {
  10006. return {
  10007. value,
  10008. done
  10009. };
  10010. }
  10011. this._loaded += value.byteLength;
  10012. this.onProgress?.({
  10013. loaded: this._loaded
  10014. });
  10015. return {
  10016. value: getArrayBuffer(value),
  10017. done: false
  10018. };
  10019. }
  10020. cancel(reason) {
  10021. this._reader?.cancel(reason);
  10022. this._abortController.abort();
  10023. }
  10024. }
  10025. /***/ }),
  10026. /* 26 */
  10027. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  10028. Object.defineProperty(exports, "__esModule", ({
  10029. value: true
  10030. }));
  10031. exports.TextLayerRenderTask = void 0;
  10032. exports.renderTextLayer = renderTextLayer;
  10033. exports.updateTextLayer = updateTextLayer;
  10034. var _util = __w_pdfjs_require__(1);
  10035. var _display_utils = __w_pdfjs_require__(6);
  10036. const MAX_TEXT_DIVS_TO_RENDER = 100000;
  10037. const DEFAULT_FONT_SIZE = 30;
  10038. const DEFAULT_FONT_ASCENT = 0.8;
  10039. const ascentCache = new Map();
  10040. function getCtx(size, isOffscreenCanvasSupported) {
  10041. let ctx;
  10042. if (isOffscreenCanvasSupported && _util.FeatureTest.isOffscreenCanvasSupported) {
  10043. ctx = new OffscreenCanvas(size, size).getContext("2d", {
  10044. alpha: false
  10045. });
  10046. } else {
  10047. const canvas = document.createElement("canvas");
  10048. canvas.width = canvas.height = size;
  10049. ctx = canvas.getContext("2d", {
  10050. alpha: false
  10051. });
  10052. }
  10053. return ctx;
  10054. }
  10055. function getAscent(fontFamily, isOffscreenCanvasSupported) {
  10056. const cachedAscent = ascentCache.get(fontFamily);
  10057. if (cachedAscent) {
  10058. return cachedAscent;
  10059. }
  10060. const ctx = getCtx(DEFAULT_FONT_SIZE, isOffscreenCanvasSupported);
  10061. ctx.font = `${DEFAULT_FONT_SIZE}px ${fontFamily}`;
  10062. const metrics = ctx.measureText("");
  10063. let ascent = metrics.fontBoundingBoxAscent;
  10064. let descent = Math.abs(metrics.fontBoundingBoxDescent);
  10065. if (ascent) {
  10066. const ratio = ascent / (ascent + descent);
  10067. ascentCache.set(fontFamily, ratio);
  10068. ctx.canvas.width = ctx.canvas.height = 0;
  10069. return ratio;
  10070. }
  10071. ctx.strokeStyle = "red";
  10072. ctx.clearRect(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE);
  10073. ctx.strokeText("g", 0, 0);
  10074. let pixels = ctx.getImageData(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE).data;
  10075. descent = 0;
  10076. for (let i = pixels.length - 1 - 3; i >= 0; i -= 4) {
  10077. if (pixels[i] > 0) {
  10078. descent = Math.ceil(i / 4 / DEFAULT_FONT_SIZE);
  10079. break;
  10080. }
  10081. }
  10082. ctx.clearRect(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE);
  10083. ctx.strokeText("A", 0, DEFAULT_FONT_SIZE);
  10084. pixels = ctx.getImageData(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE).data;
  10085. ascent = 0;
  10086. for (let i = 0, ii = pixels.length; i < ii; i += 4) {
  10087. if (pixels[i] > 0) {
  10088. ascent = DEFAULT_FONT_SIZE - Math.floor(i / 4 / DEFAULT_FONT_SIZE);
  10089. break;
  10090. }
  10091. }
  10092. ctx.canvas.width = ctx.canvas.height = 0;
  10093. if (ascent) {
  10094. const ratio = ascent / (ascent + descent);
  10095. ascentCache.set(fontFamily, ratio);
  10096. return ratio;
  10097. }
  10098. ascentCache.set(fontFamily, DEFAULT_FONT_ASCENT);
  10099. return DEFAULT_FONT_ASCENT;
  10100. }
  10101. function appendText(task, geom, styles) {
  10102. const textDiv = document.createElement("span");
  10103. const textDivProperties = {
  10104. angle: 0,
  10105. canvasWidth: 0,
  10106. hasText: geom.str !== "",
  10107. hasEOL: geom.hasEOL,
  10108. fontSize: 0
  10109. };
  10110. task._textDivs.push(textDiv);
  10111. const tx = _util.Util.transform(task._transform, geom.transform);
  10112. let angle = Math.atan2(tx[1], tx[0]);
  10113. const style = styles[geom.fontName];
  10114. if (style.vertical) {
  10115. angle += Math.PI / 2;
  10116. }
  10117. const fontHeight = Math.hypot(tx[2], tx[3]);
  10118. const fontAscent = fontHeight * getAscent(style.fontFamily, task._isOffscreenCanvasSupported);
  10119. let left, top;
  10120. if (angle === 0) {
  10121. left = tx[4];
  10122. top = tx[5] - fontAscent;
  10123. } else {
  10124. left = tx[4] + fontAscent * Math.sin(angle);
  10125. top = tx[5] - fontAscent * Math.cos(angle);
  10126. }
  10127. const scaleFactorStr = "calc(var(--scale-factor)*";
  10128. const divStyle = textDiv.style;
  10129. if (task._container === task._rootContainer) {
  10130. divStyle.left = `${(100 * left / task._pageWidth).toFixed(2)}%`;
  10131. divStyle.top = `${(100 * top / task._pageHeight).toFixed(2)}%`;
  10132. } else {
  10133. divStyle.left = `${scaleFactorStr}${left.toFixed(2)}px)`;
  10134. divStyle.top = `${scaleFactorStr}${top.toFixed(2)}px)`;
  10135. }
  10136. divStyle.fontSize = `${scaleFactorStr}${fontHeight.toFixed(2)}px)`;
  10137. divStyle.fontFamily = style.fontFamily;
  10138. textDivProperties.fontSize = fontHeight;
  10139. textDiv.setAttribute("role", "presentation");
  10140. textDiv.textContent = geom.str;
  10141. textDiv.dir = geom.dir;
  10142. if (task._fontInspectorEnabled) {
  10143. textDiv.dataset.fontName = geom.fontName;
  10144. }
  10145. if (angle !== 0) {
  10146. textDivProperties.angle = angle * (180 / Math.PI);
  10147. }
  10148. let shouldScaleText = false;
  10149. if (geom.str.length > 1) {
  10150. shouldScaleText = true;
  10151. } else if (geom.str !== " " && geom.transform[0] !== geom.transform[3]) {
  10152. const absScaleX = Math.abs(geom.transform[0]),
  10153. absScaleY = Math.abs(geom.transform[3]);
  10154. if (absScaleX !== absScaleY && Math.max(absScaleX, absScaleY) / Math.min(absScaleX, absScaleY) > 1.5) {
  10155. shouldScaleText = true;
  10156. }
  10157. }
  10158. if (shouldScaleText) {
  10159. textDivProperties.canvasWidth = style.vertical ? geom.height : geom.width;
  10160. }
  10161. task._textDivProperties.set(textDiv, textDivProperties);
  10162. if (task._isReadableStream) {
  10163. task._layoutText(textDiv);
  10164. }
  10165. }
  10166. function layout(params) {
  10167. const {
  10168. div,
  10169. scale,
  10170. properties,
  10171. ctx,
  10172. prevFontSize,
  10173. prevFontFamily
  10174. } = params;
  10175. const {
  10176. style
  10177. } = div;
  10178. let transform = "";
  10179. if (properties.canvasWidth !== 0 && properties.hasText) {
  10180. const {
  10181. fontFamily
  10182. } = style;
  10183. const {
  10184. canvasWidth,
  10185. fontSize
  10186. } = properties;
  10187. if (prevFontSize !== fontSize || prevFontFamily !== fontFamily) {
  10188. ctx.font = `${fontSize * scale}px ${fontFamily}`;
  10189. params.prevFontSize = fontSize;
  10190. params.prevFontFamily = fontFamily;
  10191. }
  10192. const {
  10193. width
  10194. } = ctx.measureText(div.textContent);
  10195. if (width > 0) {
  10196. transform = `scaleX(${canvasWidth * scale / width})`;
  10197. }
  10198. }
  10199. if (properties.angle !== 0) {
  10200. transform = `rotate(${properties.angle}deg) ${transform}`;
  10201. }
  10202. if (transform.length > 0) {
  10203. style.transform = transform;
  10204. }
  10205. }
  10206. function render(task) {
  10207. if (task._canceled) {
  10208. return;
  10209. }
  10210. const textDivs = task._textDivs;
  10211. const capability = task._capability;
  10212. const textDivsLength = textDivs.length;
  10213. if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
  10214. capability.resolve();
  10215. return;
  10216. }
  10217. if (!task._isReadableStream) {
  10218. for (const textDiv of textDivs) {
  10219. task._layoutText(textDiv);
  10220. }
  10221. }
  10222. capability.resolve();
  10223. }
  10224. class TextLayerRenderTask {
  10225. constructor({
  10226. textContentSource,
  10227. container,
  10228. viewport,
  10229. textDivs,
  10230. textDivProperties,
  10231. textContentItemsStr,
  10232. isOffscreenCanvasSupported
  10233. }) {
  10234. this._textContentSource = textContentSource;
  10235. this._isReadableStream = textContentSource instanceof ReadableStream;
  10236. this._container = this._rootContainer = container;
  10237. this._textDivs = textDivs || [];
  10238. this._textContentItemsStr = textContentItemsStr || [];
  10239. this._isOffscreenCanvasSupported = isOffscreenCanvasSupported;
  10240. this._fontInspectorEnabled = !!globalThis.FontInspector?.enabled;
  10241. this._reader = null;
  10242. this._textDivProperties = textDivProperties || new WeakMap();
  10243. this._canceled = false;
  10244. this._capability = new _util.PromiseCapability();
  10245. this._layoutTextParams = {
  10246. prevFontSize: null,
  10247. prevFontFamily: null,
  10248. div: null,
  10249. scale: viewport.scale * (globalThis.devicePixelRatio || 1),
  10250. properties: null,
  10251. ctx: getCtx(0, isOffscreenCanvasSupported)
  10252. };
  10253. const {
  10254. pageWidth,
  10255. pageHeight,
  10256. pageX,
  10257. pageY
  10258. } = viewport.rawDims;
  10259. this._transform = [1, 0, 0, -1, -pageX, pageY + pageHeight];
  10260. this._pageWidth = pageWidth;
  10261. this._pageHeight = pageHeight;
  10262. (0, _display_utils.setLayerDimensions)(container, viewport);
  10263. this._capability.promise.finally(() => {
  10264. this._layoutTextParams = null;
  10265. }).catch(() => {});
  10266. }
  10267. get promise() {
  10268. return this._capability.promise;
  10269. }
  10270. cancel() {
  10271. this._canceled = true;
  10272. if (this._reader) {
  10273. this._reader.cancel(new _util.AbortException("TextLayer task cancelled.")).catch(() => {});
  10274. this._reader = null;
  10275. }
  10276. this._capability.reject(new _util.AbortException("TextLayer task cancelled."));
  10277. }
  10278. _processItems(items, styleCache) {
  10279. for (const item of items) {
  10280. if (item.str === undefined) {
  10281. if (item.type === "beginMarkedContentProps" || item.type === "beginMarkedContent") {
  10282. const parent = this._container;
  10283. this._container = document.createElement("span");
  10284. this._container.classList.add("markedContent");
  10285. if (item.id !== null) {
  10286. this._container.setAttribute("id", `${item.id}`);
  10287. }
  10288. parent.append(this._container);
  10289. } else if (item.type === "endMarkedContent") {
  10290. this._container = this._container.parentNode;
  10291. }
  10292. continue;
  10293. }
  10294. this._textContentItemsStr.push(item.str);
  10295. appendText(this, item, styleCache);
  10296. }
  10297. }
  10298. _layoutText(textDiv) {
  10299. const textDivProperties = this._layoutTextParams.properties = this._textDivProperties.get(textDiv);
  10300. this._layoutTextParams.div = textDiv;
  10301. layout(this._layoutTextParams);
  10302. if (textDivProperties.hasText) {
  10303. this._container.append(textDiv);
  10304. }
  10305. if (textDivProperties.hasEOL) {
  10306. const br = document.createElement("br");
  10307. br.setAttribute("role", "presentation");
  10308. this._container.append(br);
  10309. }
  10310. }
  10311. _render() {
  10312. const capability = new _util.PromiseCapability();
  10313. let styleCache = Object.create(null);
  10314. if (this._isReadableStream) {
  10315. const pump = () => {
  10316. this._reader.read().then(({
  10317. value,
  10318. done
  10319. }) => {
  10320. if (done) {
  10321. capability.resolve();
  10322. return;
  10323. }
  10324. Object.assign(styleCache, value.styles);
  10325. this._processItems(value.items, styleCache);
  10326. pump();
  10327. }, capability.reject);
  10328. };
  10329. this._reader = this._textContentSource.getReader();
  10330. pump();
  10331. } else if (this._textContentSource) {
  10332. const {
  10333. items,
  10334. styles
  10335. } = this._textContentSource;
  10336. this._processItems(items, styles);
  10337. capability.resolve();
  10338. } else {
  10339. throw new Error('No "textContentSource" parameter specified.');
  10340. }
  10341. capability.promise.then(() => {
  10342. styleCache = null;
  10343. render(this);
  10344. }, this._capability.reject);
  10345. }
  10346. }
  10347. exports.TextLayerRenderTask = TextLayerRenderTask;
  10348. function renderTextLayer(params) {
  10349. if (!params.textContentSource && (params.textContent || params.textContentStream)) {
  10350. (0, _display_utils.deprecated)("The TextLayerRender `textContent`/`textContentStream` parameters " + "will be removed in the future, please use `textContentSource` instead.");
  10351. params.textContentSource = params.textContent || params.textContentStream;
  10352. }
  10353. const {
  10354. container,
  10355. viewport
  10356. } = params;
  10357. const style = getComputedStyle(container);
  10358. const visibility = style.getPropertyValue("visibility");
  10359. const scaleFactor = parseFloat(style.getPropertyValue("--scale-factor"));
  10360. if (visibility === "visible" && (!scaleFactor || Math.abs(scaleFactor - viewport.scale) > 1e-5)) {
  10361. console.error("The `--scale-factor` CSS-variable must be set, " + "to the same value as `viewport.scale`, " + "either on the `container`-element itself or higher up in the DOM.");
  10362. }
  10363. const task = new TextLayerRenderTask(params);
  10364. task._render();
  10365. return task;
  10366. }
  10367. function updateTextLayer({
  10368. container,
  10369. viewport,
  10370. textDivs,
  10371. textDivProperties,
  10372. isOffscreenCanvasSupported,
  10373. mustRotate = true,
  10374. mustRescale = true
  10375. }) {
  10376. if (mustRotate) {
  10377. (0, _display_utils.setLayerDimensions)(container, {
  10378. rotation: viewport.rotation
  10379. });
  10380. }
  10381. if (mustRescale) {
  10382. const ctx = getCtx(0, isOffscreenCanvasSupported);
  10383. const scale = viewport.scale * (globalThis.devicePixelRatio || 1);
  10384. const params = {
  10385. prevFontSize: null,
  10386. prevFontFamily: null,
  10387. div: null,
  10388. scale,
  10389. properties: null,
  10390. ctx
  10391. };
  10392. for (const div of textDivs) {
  10393. params.properties = textDivProperties.get(div);
  10394. params.div = div;
  10395. layout(params);
  10396. }
  10397. }
  10398. }
  10399. /***/ }),
  10400. /* 27 */
  10401. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  10402. Object.defineProperty(exports, "__esModule", ({
  10403. value: true
  10404. }));
  10405. exports.AnnotationEditorLayer = void 0;
  10406. var _util = __w_pdfjs_require__(1);
  10407. var _tools = __w_pdfjs_require__(5);
  10408. var _freetext = __w_pdfjs_require__(28);
  10409. var _ink = __w_pdfjs_require__(29);
  10410. var _display_utils = __w_pdfjs_require__(6);
  10411. class AnnotationEditorLayer {
  10412. #accessibilityManager;
  10413. #allowClick = false;
  10414. #boundPointerup = this.pointerup.bind(this);
  10415. #boundPointerdown = this.pointerdown.bind(this);
  10416. #editors = new Map();
  10417. #hadPointerDown = false;
  10418. #isCleaningUp = false;
  10419. #uiManager;
  10420. static _initialized = false;
  10421. constructor(options) {
  10422. if (!AnnotationEditorLayer._initialized) {
  10423. AnnotationEditorLayer._initialized = true;
  10424. _freetext.FreeTextEditor.initialize(options.l10n);
  10425. _ink.InkEditor.initialize(options.l10n);
  10426. }
  10427. options.uiManager.registerEditorTypes([_freetext.FreeTextEditor, _ink.InkEditor]);
  10428. this.#uiManager = options.uiManager;
  10429. this.pageIndex = options.pageIndex;
  10430. this.div = options.div;
  10431. this.#accessibilityManager = options.accessibilityManager;
  10432. this.#uiManager.addLayer(this);
  10433. }
  10434. get isEmpty() {
  10435. return this.#editors.size === 0;
  10436. }
  10437. updateToolbar(mode) {
  10438. this.#uiManager.updateToolbar(mode);
  10439. }
  10440. updateMode(mode = this.#uiManager.getMode()) {
  10441. this.#cleanup();
  10442. if (mode === _util.AnnotationEditorType.INK) {
  10443. this.addInkEditorIfNeeded(false);
  10444. this.disableClick();
  10445. } else {
  10446. this.enableClick();
  10447. }
  10448. this.#uiManager.unselectAll();
  10449. if (mode !== _util.AnnotationEditorType.NONE) {
  10450. this.div.classList.toggle("freeTextEditing", mode === _util.AnnotationEditorType.FREETEXT);
  10451. this.div.classList.toggle("inkEditing", mode === _util.AnnotationEditorType.INK);
  10452. this.div.hidden = false;
  10453. }
  10454. }
  10455. addInkEditorIfNeeded(isCommitting) {
  10456. if (!isCommitting && this.#uiManager.getMode() !== _util.AnnotationEditorType.INK) {
  10457. return;
  10458. }
  10459. if (!isCommitting) {
  10460. for (const editor of this.#editors.values()) {
  10461. if (editor.isEmpty()) {
  10462. editor.setInBackground();
  10463. return;
  10464. }
  10465. }
  10466. }
  10467. const editor = this.#createAndAddNewEditor({
  10468. offsetX: 0,
  10469. offsetY: 0
  10470. });
  10471. editor.setInBackground();
  10472. }
  10473. setEditingState(isEditing) {
  10474. this.#uiManager.setEditingState(isEditing);
  10475. }
  10476. addCommands(params) {
  10477. this.#uiManager.addCommands(params);
  10478. }
  10479. enable() {
  10480. this.div.style.pointerEvents = "auto";
  10481. for (const editor of this.#editors.values()) {
  10482. editor.enableEditing();
  10483. }
  10484. }
  10485. disable() {
  10486. this.div.style.pointerEvents = "none";
  10487. for (const editor of this.#editors.values()) {
  10488. editor.disableEditing();
  10489. }
  10490. this.#cleanup();
  10491. if (this.isEmpty) {
  10492. this.div.hidden = true;
  10493. }
  10494. }
  10495. setActiveEditor(editor) {
  10496. const currentActive = this.#uiManager.getActive();
  10497. if (currentActive === editor) {
  10498. return;
  10499. }
  10500. this.#uiManager.setActiveEditor(editor);
  10501. }
  10502. enableClick() {
  10503. this.div.addEventListener("pointerdown", this.#boundPointerdown);
  10504. this.div.addEventListener("pointerup", this.#boundPointerup);
  10505. }
  10506. disableClick() {
  10507. this.div.removeEventListener("pointerdown", this.#boundPointerdown);
  10508. this.div.removeEventListener("pointerup", this.#boundPointerup);
  10509. }
  10510. attach(editor) {
  10511. this.#editors.set(editor.id, editor);
  10512. }
  10513. detach(editor) {
  10514. this.#editors.delete(editor.id);
  10515. this.#accessibilityManager?.removePointerInTextLayer(editor.contentDiv);
  10516. }
  10517. remove(editor) {
  10518. this.#uiManager.removeEditor(editor);
  10519. this.detach(editor);
  10520. editor.div.style.display = "none";
  10521. setTimeout(() => {
  10522. editor.div.style.display = "";
  10523. editor.div.remove();
  10524. editor.isAttachedToDOM = false;
  10525. if (document.activeElement === document.body) {
  10526. this.#uiManager.focusMainContainer();
  10527. }
  10528. }, 0);
  10529. if (!this.#isCleaningUp) {
  10530. this.addInkEditorIfNeeded(false);
  10531. }
  10532. }
  10533. #changeParent(editor) {
  10534. if (editor.parent === this) {
  10535. return;
  10536. }
  10537. this.attach(editor);
  10538. editor.parent?.detach(editor);
  10539. editor.setParent(this);
  10540. if (editor.div && editor.isAttachedToDOM) {
  10541. editor.div.remove();
  10542. this.div.append(editor.div);
  10543. }
  10544. }
  10545. add(editor) {
  10546. this.#changeParent(editor);
  10547. this.#uiManager.addEditor(editor);
  10548. this.attach(editor);
  10549. if (!editor.isAttachedToDOM) {
  10550. const div = editor.render();
  10551. this.div.append(div);
  10552. editor.isAttachedToDOM = true;
  10553. }
  10554. this.moveEditorInDOM(editor);
  10555. editor.onceAdded();
  10556. this.#uiManager.addToAnnotationStorage(editor);
  10557. }
  10558. moveEditorInDOM(editor) {
  10559. this.#accessibilityManager?.moveElementInDOM(this.div, editor.div, editor.contentDiv, true);
  10560. }
  10561. addOrRebuild(editor) {
  10562. if (editor.needsToBeRebuilt()) {
  10563. editor.rebuild();
  10564. } else {
  10565. this.add(editor);
  10566. }
  10567. }
  10568. addANewEditor(editor) {
  10569. const cmd = () => {
  10570. this.addOrRebuild(editor);
  10571. };
  10572. const undo = () => {
  10573. editor.remove();
  10574. };
  10575. this.addCommands({
  10576. cmd,
  10577. undo,
  10578. mustExec: true
  10579. });
  10580. }
  10581. addUndoableEditor(editor) {
  10582. const cmd = () => {
  10583. this.addOrRebuild(editor);
  10584. };
  10585. const undo = () => {
  10586. editor.remove();
  10587. };
  10588. this.addCommands({
  10589. cmd,
  10590. undo,
  10591. mustExec: false
  10592. });
  10593. }
  10594. getNextId() {
  10595. return this.#uiManager.getId();
  10596. }
  10597. #createNewEditor(params) {
  10598. switch (this.#uiManager.getMode()) {
  10599. case _util.AnnotationEditorType.FREETEXT:
  10600. return new _freetext.FreeTextEditor(params);
  10601. case _util.AnnotationEditorType.INK:
  10602. return new _ink.InkEditor(params);
  10603. }
  10604. return null;
  10605. }
  10606. deserialize(data) {
  10607. switch (data.annotationType) {
  10608. case _util.AnnotationEditorType.FREETEXT:
  10609. return _freetext.FreeTextEditor.deserialize(data, this, this.#uiManager);
  10610. case _util.AnnotationEditorType.INK:
  10611. return _ink.InkEditor.deserialize(data, this, this.#uiManager);
  10612. }
  10613. return null;
  10614. }
  10615. #createAndAddNewEditor(event) {
  10616. const id = this.getNextId();
  10617. const editor = this.#createNewEditor({
  10618. parent: this,
  10619. id,
  10620. x: event.offsetX,
  10621. y: event.offsetY,
  10622. uiManager: this.#uiManager
  10623. });
  10624. if (editor) {
  10625. this.add(editor);
  10626. }
  10627. return editor;
  10628. }
  10629. setSelected(editor) {
  10630. this.#uiManager.setSelected(editor);
  10631. }
  10632. toggleSelected(editor) {
  10633. this.#uiManager.toggleSelected(editor);
  10634. }
  10635. isSelected(editor) {
  10636. return this.#uiManager.isSelected(editor);
  10637. }
  10638. unselect(editor) {
  10639. this.#uiManager.unselect(editor);
  10640. }
  10641. pointerup(event) {
  10642. const {
  10643. isMac
  10644. } = _util.FeatureTest.platform;
  10645. if (event.button !== 0 || event.ctrlKey && isMac) {
  10646. return;
  10647. }
  10648. if (event.target !== this.div) {
  10649. return;
  10650. }
  10651. if (!this.#hadPointerDown) {
  10652. return;
  10653. }
  10654. this.#hadPointerDown = false;
  10655. if (!this.#allowClick) {
  10656. this.#allowClick = true;
  10657. return;
  10658. }
  10659. this.#createAndAddNewEditor(event);
  10660. }
  10661. pointerdown(event) {
  10662. const {
  10663. isMac
  10664. } = _util.FeatureTest.platform;
  10665. if (event.button !== 0 || event.ctrlKey && isMac) {
  10666. return;
  10667. }
  10668. if (event.target !== this.div) {
  10669. return;
  10670. }
  10671. this.#hadPointerDown = true;
  10672. const editor = this.#uiManager.getActive();
  10673. this.#allowClick = !editor || editor.isEmpty();
  10674. }
  10675. drop(event) {
  10676. const id = event.dataTransfer.getData("text/plain");
  10677. const editor = this.#uiManager.getEditor(id);
  10678. if (!editor) {
  10679. return;
  10680. }
  10681. event.preventDefault();
  10682. event.dataTransfer.dropEffect = "move";
  10683. this.#changeParent(editor);
  10684. const rect = this.div.getBoundingClientRect();
  10685. const endX = event.clientX - rect.x;
  10686. const endY = event.clientY - rect.y;
  10687. editor.translate(endX - editor.startX, endY - editor.startY);
  10688. this.moveEditorInDOM(editor);
  10689. editor.div.focus();
  10690. }
  10691. dragover(event) {
  10692. event.preventDefault();
  10693. }
  10694. destroy() {
  10695. if (this.#uiManager.getActive()?.parent === this) {
  10696. this.#uiManager.setActiveEditor(null);
  10697. }
  10698. for (const editor of this.#editors.values()) {
  10699. this.#accessibilityManager?.removePointerInTextLayer(editor.contentDiv);
  10700. editor.setParent(null);
  10701. editor.isAttachedToDOM = false;
  10702. editor.div.remove();
  10703. }
  10704. this.div = null;
  10705. this.#editors.clear();
  10706. this.#uiManager.removeLayer(this);
  10707. }
  10708. #cleanup() {
  10709. this.#isCleaningUp = true;
  10710. for (const editor of this.#editors.values()) {
  10711. if (editor.isEmpty()) {
  10712. editor.remove();
  10713. }
  10714. }
  10715. this.#isCleaningUp = false;
  10716. }
  10717. render({
  10718. viewport
  10719. }) {
  10720. this.viewport = viewport;
  10721. (0, _display_utils.setLayerDimensions)(this.div, viewport);
  10722. (0, _tools.bindEvents)(this, this.div, ["dragover", "drop"]);
  10723. for (const editor of this.#uiManager.getEditors(this.pageIndex)) {
  10724. this.add(editor);
  10725. }
  10726. this.updateMode();
  10727. }
  10728. update({
  10729. viewport
  10730. }) {
  10731. this.#uiManager.commitOrRemove();
  10732. this.viewport = viewport;
  10733. (0, _display_utils.setLayerDimensions)(this.div, {
  10734. rotation: viewport.rotation
  10735. });
  10736. this.updateMode();
  10737. }
  10738. get pageDimensions() {
  10739. const {
  10740. pageWidth,
  10741. pageHeight
  10742. } = this.viewport.rawDims;
  10743. return [pageWidth, pageHeight];
  10744. }
  10745. }
  10746. exports.AnnotationEditorLayer = AnnotationEditorLayer;
  10747. /***/ }),
  10748. /* 28 */
  10749. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  10750. Object.defineProperty(exports, "__esModule", ({
  10751. value: true
  10752. }));
  10753. exports.FreeTextEditor = void 0;
  10754. var _util = __w_pdfjs_require__(1);
  10755. var _tools = __w_pdfjs_require__(5);
  10756. var _editor = __w_pdfjs_require__(4);
  10757. class FreeTextEditor extends _editor.AnnotationEditor {
  10758. #boundEditorDivBlur = this.editorDivBlur.bind(this);
  10759. #boundEditorDivFocus = this.editorDivFocus.bind(this);
  10760. #boundEditorDivInput = this.editorDivInput.bind(this);
  10761. #boundEditorDivKeydown = this.editorDivKeydown.bind(this);
  10762. #color;
  10763. #content = "";
  10764. #editorDivId = `${this.id}-editor`;
  10765. #hasAlreadyBeenCommitted = false;
  10766. #fontSize;
  10767. static _freeTextDefaultContent = "";
  10768. static _l10nPromise;
  10769. static _internalPadding = 0;
  10770. static _defaultColor = null;
  10771. static _defaultFontSize = 10;
  10772. static _keyboardManager = new _tools.KeyboardManager([[["ctrl+Enter", "mac+meta+Enter", "Escape", "mac+Escape"], FreeTextEditor.prototype.commitOrRemove]]);
  10773. static _type = "freetext";
  10774. constructor(params) {
  10775. super({
  10776. ...params,
  10777. name: "freeTextEditor"
  10778. });
  10779. this.#color = params.color || FreeTextEditor._defaultColor || _editor.AnnotationEditor._defaultLineColor;
  10780. this.#fontSize = params.fontSize || FreeTextEditor._defaultFontSize;
  10781. }
  10782. static initialize(l10n) {
  10783. this._l10nPromise = new Map(["free_text2_default_content", "editor_free_text2_aria_label"].map(str => [str, l10n.get(str)]));
  10784. const style = getComputedStyle(document.documentElement);
  10785. this._internalPadding = parseFloat(style.getPropertyValue("--freetext-padding"));
  10786. }
  10787. static updateDefaultParams(type, value) {
  10788. switch (type) {
  10789. case _util.AnnotationEditorParamsType.FREETEXT_SIZE:
  10790. FreeTextEditor._defaultFontSize = value;
  10791. break;
  10792. case _util.AnnotationEditorParamsType.FREETEXT_COLOR:
  10793. FreeTextEditor._defaultColor = value;
  10794. break;
  10795. }
  10796. }
  10797. updateParams(type, value) {
  10798. switch (type) {
  10799. case _util.AnnotationEditorParamsType.FREETEXT_SIZE:
  10800. this.#updateFontSize(value);
  10801. break;
  10802. case _util.AnnotationEditorParamsType.FREETEXT_COLOR:
  10803. this.#updateColor(value);
  10804. break;
  10805. }
  10806. }
  10807. static get defaultPropertiesToUpdate() {
  10808. return [[_util.AnnotationEditorParamsType.FREETEXT_SIZE, FreeTextEditor._defaultFontSize], [_util.AnnotationEditorParamsType.FREETEXT_COLOR, FreeTextEditor._defaultColor || _editor.AnnotationEditor._defaultLineColor]];
  10809. }
  10810. get propertiesToUpdate() {
  10811. return [[_util.AnnotationEditorParamsType.FREETEXT_SIZE, this.#fontSize], [_util.AnnotationEditorParamsType.FREETEXT_COLOR, this.#color]];
  10812. }
  10813. #updateFontSize(fontSize) {
  10814. const setFontsize = size => {
  10815. this.editorDiv.style.fontSize = `calc(${size}px * var(--scale-factor))`;
  10816. this.translate(0, -(size - this.#fontSize) * this.parentScale);
  10817. this.#fontSize = size;
  10818. this.#setEditorDimensions();
  10819. };
  10820. const savedFontsize = this.#fontSize;
  10821. this.addCommands({
  10822. cmd: () => {
  10823. setFontsize(fontSize);
  10824. },
  10825. undo: () => {
  10826. setFontsize(savedFontsize);
  10827. },
  10828. mustExec: true,
  10829. type: _util.AnnotationEditorParamsType.FREETEXT_SIZE,
  10830. overwriteIfSameType: true,
  10831. keepUndo: true
  10832. });
  10833. }
  10834. #updateColor(color) {
  10835. const savedColor = this.#color;
  10836. this.addCommands({
  10837. cmd: () => {
  10838. this.#color = this.editorDiv.style.color = color;
  10839. },
  10840. undo: () => {
  10841. this.#color = this.editorDiv.style.color = savedColor;
  10842. },
  10843. mustExec: true,
  10844. type: _util.AnnotationEditorParamsType.FREETEXT_COLOR,
  10845. overwriteIfSameType: true,
  10846. keepUndo: true
  10847. });
  10848. }
  10849. getInitialTranslation() {
  10850. const scale = this.parentScale;
  10851. return [-FreeTextEditor._internalPadding * scale, -(FreeTextEditor._internalPadding + this.#fontSize) * scale];
  10852. }
  10853. rebuild() {
  10854. super.rebuild();
  10855. if (this.div === null) {
  10856. return;
  10857. }
  10858. if (!this.isAttachedToDOM) {
  10859. this.parent.add(this);
  10860. }
  10861. }
  10862. enableEditMode() {
  10863. if (this.isInEditMode()) {
  10864. return;
  10865. }
  10866. this.parent.setEditingState(false);
  10867. this.parent.updateToolbar(_util.AnnotationEditorType.FREETEXT);
  10868. super.enableEditMode();
  10869. this.overlayDiv.classList.remove("enabled");
  10870. this.editorDiv.contentEditable = true;
  10871. this.div.draggable = false;
  10872. this.div.removeAttribute("aria-activedescendant");
  10873. this.editorDiv.addEventListener("keydown", this.#boundEditorDivKeydown);
  10874. this.editorDiv.addEventListener("focus", this.#boundEditorDivFocus);
  10875. this.editorDiv.addEventListener("blur", this.#boundEditorDivBlur);
  10876. this.editorDiv.addEventListener("input", this.#boundEditorDivInput);
  10877. }
  10878. disableEditMode() {
  10879. if (!this.isInEditMode()) {
  10880. return;
  10881. }
  10882. this.parent.setEditingState(true);
  10883. super.disableEditMode();
  10884. this.overlayDiv.classList.add("enabled");
  10885. this.editorDiv.contentEditable = false;
  10886. this.div.setAttribute("aria-activedescendant", this.#editorDivId);
  10887. this.div.draggable = true;
  10888. this.editorDiv.removeEventListener("keydown", this.#boundEditorDivKeydown);
  10889. this.editorDiv.removeEventListener("focus", this.#boundEditorDivFocus);
  10890. this.editorDiv.removeEventListener("blur", this.#boundEditorDivBlur);
  10891. this.editorDiv.removeEventListener("input", this.#boundEditorDivInput);
  10892. this.div.focus({
  10893. preventScroll: true
  10894. });
  10895. this.isEditing = false;
  10896. this.parent.div.classList.add("freeTextEditing");
  10897. }
  10898. focusin(event) {
  10899. super.focusin(event);
  10900. if (event.target !== this.editorDiv) {
  10901. this.editorDiv.focus();
  10902. }
  10903. }
  10904. onceAdded() {
  10905. if (this.width) {
  10906. return;
  10907. }
  10908. this.enableEditMode();
  10909. this.editorDiv.focus();
  10910. }
  10911. isEmpty() {
  10912. return !this.editorDiv || this.editorDiv.innerText.trim() === "";
  10913. }
  10914. remove() {
  10915. this.isEditing = false;
  10916. this.parent.setEditingState(true);
  10917. this.parent.div.classList.add("freeTextEditing");
  10918. super.remove();
  10919. }
  10920. #extractText() {
  10921. const divs = this.editorDiv.getElementsByTagName("div");
  10922. if (divs.length === 0) {
  10923. return this.editorDiv.innerText;
  10924. }
  10925. const buffer = [];
  10926. for (const div of divs) {
  10927. buffer.push(div.innerText.replace(/\r\n?|\n/, ""));
  10928. }
  10929. return buffer.join("\n");
  10930. }
  10931. #setEditorDimensions() {
  10932. const [parentWidth, parentHeight] = this.parentDimensions;
  10933. let rect;
  10934. if (this.isAttachedToDOM) {
  10935. rect = this.div.getBoundingClientRect();
  10936. } else {
  10937. const {
  10938. currentLayer,
  10939. div
  10940. } = this;
  10941. const savedDisplay = div.style.display;
  10942. div.style.display = "hidden";
  10943. currentLayer.div.append(this.div);
  10944. rect = div.getBoundingClientRect();
  10945. div.remove();
  10946. div.style.display = savedDisplay;
  10947. }
  10948. this.width = rect.width / parentWidth;
  10949. this.height = rect.height / parentHeight;
  10950. }
  10951. commit() {
  10952. if (!this.isInEditMode()) {
  10953. return;
  10954. }
  10955. super.commit();
  10956. if (!this.#hasAlreadyBeenCommitted) {
  10957. this.#hasAlreadyBeenCommitted = true;
  10958. this.parent.addUndoableEditor(this);
  10959. }
  10960. this.disableEditMode();
  10961. this.#content = this.#extractText().trimEnd();
  10962. this.#setEditorDimensions();
  10963. }
  10964. shouldGetKeyboardEvents() {
  10965. return this.isInEditMode();
  10966. }
  10967. dblclick(event) {
  10968. this.enableEditMode();
  10969. this.editorDiv.focus();
  10970. }
  10971. keydown(event) {
  10972. if (event.target === this.div && event.key === "Enter") {
  10973. this.enableEditMode();
  10974. this.editorDiv.focus();
  10975. }
  10976. }
  10977. editorDivKeydown(event) {
  10978. FreeTextEditor._keyboardManager.exec(this, event);
  10979. }
  10980. editorDivFocus(event) {
  10981. this.isEditing = true;
  10982. }
  10983. editorDivBlur(event) {
  10984. this.isEditing = false;
  10985. }
  10986. editorDivInput(event) {
  10987. this.parent.div.classList.toggle("freeTextEditing", this.isEmpty());
  10988. }
  10989. disableEditing() {
  10990. this.editorDiv.setAttribute("role", "comment");
  10991. this.editorDiv.removeAttribute("aria-multiline");
  10992. }
  10993. enableEditing() {
  10994. this.editorDiv.setAttribute("role", "textbox");
  10995. this.editorDiv.setAttribute("aria-multiline", true);
  10996. }
  10997. render() {
  10998. if (this.div) {
  10999. return this.div;
  11000. }
  11001. let baseX, baseY;
  11002. if (this.width) {
  11003. baseX = this.x;
  11004. baseY = this.y;
  11005. }
  11006. super.render();
  11007. this.editorDiv = document.createElement("div");
  11008. this.editorDiv.className = "internal";
  11009. this.editorDiv.setAttribute("id", this.#editorDivId);
  11010. this.enableEditing();
  11011. FreeTextEditor._l10nPromise.get("editor_free_text2_aria_label").then(msg => this.editorDiv?.setAttribute("aria-label", msg));
  11012. FreeTextEditor._l10nPromise.get("free_text2_default_content").then(msg => this.editorDiv?.setAttribute("default-content", msg));
  11013. this.editorDiv.contentEditable = true;
  11014. const {
  11015. style
  11016. } = this.editorDiv;
  11017. style.fontSize = `calc(${this.#fontSize}px * var(--scale-factor))`;
  11018. style.color = this.#color;
  11019. this.div.append(this.editorDiv);
  11020. this.overlayDiv = document.createElement("div");
  11021. this.overlayDiv.classList.add("overlay", "enabled");
  11022. this.div.append(this.overlayDiv);
  11023. (0, _tools.bindEvents)(this, this.div, ["dblclick", "keydown"]);
  11024. if (this.width) {
  11025. const [parentWidth, parentHeight] = this.parentDimensions;
  11026. this.setAt(baseX * parentWidth, baseY * parentHeight, this.width * parentWidth, this.height * parentHeight);
  11027. for (const line of this.#content.split("\n")) {
  11028. const div = document.createElement("div");
  11029. div.append(line ? document.createTextNode(line) : document.createElement("br"));
  11030. this.editorDiv.append(div);
  11031. }
  11032. this.div.draggable = true;
  11033. this.editorDiv.contentEditable = false;
  11034. } else {
  11035. this.div.draggable = false;
  11036. this.editorDiv.contentEditable = true;
  11037. }
  11038. return this.div;
  11039. }
  11040. get contentDiv() {
  11041. return this.editorDiv;
  11042. }
  11043. static deserialize(data, parent, uiManager) {
  11044. const editor = super.deserialize(data, parent, uiManager);
  11045. editor.#fontSize = data.fontSize;
  11046. editor.#color = _util.Util.makeHexColor(...data.color);
  11047. editor.#content = data.value;
  11048. return editor;
  11049. }
  11050. serialize() {
  11051. if (this.isEmpty()) {
  11052. return null;
  11053. }
  11054. const padding = FreeTextEditor._internalPadding * this.parentScale;
  11055. const rect = this.getRect(padding, padding);
  11056. const color = _editor.AnnotationEditor._colorManager.convert(this.isAttachedToDOM ? getComputedStyle(this.editorDiv).color : this.#color);
  11057. return {
  11058. annotationType: _util.AnnotationEditorType.FREETEXT,
  11059. color,
  11060. fontSize: this.#fontSize,
  11061. value: this.#content,
  11062. pageIndex: this.pageIndex,
  11063. rect,
  11064. rotation: this.rotation
  11065. };
  11066. }
  11067. }
  11068. exports.FreeTextEditor = FreeTextEditor;
  11069. /***/ }),
  11070. /* 29 */
  11071. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  11072. Object.defineProperty(exports, "__esModule", ({
  11073. value: true
  11074. }));
  11075. exports.InkEditor = void 0;
  11076. var _util = __w_pdfjs_require__(1);
  11077. var _editor = __w_pdfjs_require__(4);
  11078. var _tools = __w_pdfjs_require__(5);
  11079. const RESIZER_SIZE = 16;
  11080. class InkEditor extends _editor.AnnotationEditor {
  11081. #aspectRatio = 0;
  11082. #baseHeight = 0;
  11083. #baseWidth = 0;
  11084. #boundCanvasContextMenu = this.canvasContextMenu.bind(this);
  11085. #boundCanvasPointermove = this.canvasPointermove.bind(this);
  11086. #boundCanvasPointerleave = this.canvasPointerleave.bind(this);
  11087. #boundCanvasPointerup = this.canvasPointerup.bind(this);
  11088. #boundCanvasPointerdown = this.canvasPointerdown.bind(this);
  11089. #currentPath2D = new Path2D();
  11090. #disableEditing = false;
  11091. #hasSomethingToDraw = false;
  11092. #isCanvasInitialized = false;
  11093. #observer = null;
  11094. #realWidth = 0;
  11095. #realHeight = 0;
  11096. #requestFrameCallback = null;
  11097. static _defaultColor = null;
  11098. static _defaultOpacity = 1;
  11099. static _defaultThickness = 1;
  11100. static _l10nPromise;
  11101. static _type = "ink";
  11102. constructor(params) {
  11103. super({
  11104. ...params,
  11105. name: "inkEditor"
  11106. });
  11107. this.color = params.color || null;
  11108. this.thickness = params.thickness || null;
  11109. this.opacity = params.opacity || null;
  11110. this.paths = [];
  11111. this.bezierPath2D = [];
  11112. this.allRawPaths = [];
  11113. this.currentPath = [];
  11114. this.scaleFactor = 1;
  11115. this.translationX = this.translationY = 0;
  11116. this.x = 0;
  11117. this.y = 0;
  11118. }
  11119. static initialize(l10n) {
  11120. this._l10nPromise = new Map(["editor_ink_canvas_aria_label", "editor_ink2_aria_label"].map(str => [str, l10n.get(str)]));
  11121. }
  11122. static updateDefaultParams(type, value) {
  11123. switch (type) {
  11124. case _util.AnnotationEditorParamsType.INK_THICKNESS:
  11125. InkEditor._defaultThickness = value;
  11126. break;
  11127. case _util.AnnotationEditorParamsType.INK_COLOR:
  11128. InkEditor._defaultColor = value;
  11129. break;
  11130. case _util.AnnotationEditorParamsType.INK_OPACITY:
  11131. InkEditor._defaultOpacity = value / 100;
  11132. break;
  11133. }
  11134. }
  11135. updateParams(type, value) {
  11136. switch (type) {
  11137. case _util.AnnotationEditorParamsType.INK_THICKNESS:
  11138. this.#updateThickness(value);
  11139. break;
  11140. case _util.AnnotationEditorParamsType.INK_COLOR:
  11141. this.#updateColor(value);
  11142. break;
  11143. case _util.AnnotationEditorParamsType.INK_OPACITY:
  11144. this.#updateOpacity(value);
  11145. break;
  11146. }
  11147. }
  11148. static get defaultPropertiesToUpdate() {
  11149. return [[_util.AnnotationEditorParamsType.INK_THICKNESS, InkEditor._defaultThickness], [_util.AnnotationEditorParamsType.INK_COLOR, InkEditor._defaultColor || _editor.AnnotationEditor._defaultLineColor], [_util.AnnotationEditorParamsType.INK_OPACITY, Math.round(InkEditor._defaultOpacity * 100)]];
  11150. }
  11151. get propertiesToUpdate() {
  11152. return [[_util.AnnotationEditorParamsType.INK_THICKNESS, this.thickness || InkEditor._defaultThickness], [_util.AnnotationEditorParamsType.INK_COLOR, this.color || InkEditor._defaultColor || _editor.AnnotationEditor._defaultLineColor], [_util.AnnotationEditorParamsType.INK_OPACITY, Math.round(100 * (this.opacity ?? InkEditor._defaultOpacity))]];
  11153. }
  11154. #updateThickness(thickness) {
  11155. const savedThickness = this.thickness;
  11156. this.addCommands({
  11157. cmd: () => {
  11158. this.thickness = thickness;
  11159. this.#fitToContent();
  11160. },
  11161. undo: () => {
  11162. this.thickness = savedThickness;
  11163. this.#fitToContent();
  11164. },
  11165. mustExec: true,
  11166. type: _util.AnnotationEditorParamsType.INK_THICKNESS,
  11167. overwriteIfSameType: true,
  11168. keepUndo: true
  11169. });
  11170. }
  11171. #updateColor(color) {
  11172. const savedColor = this.color;
  11173. this.addCommands({
  11174. cmd: () => {
  11175. this.color = color;
  11176. this.#redraw();
  11177. },
  11178. undo: () => {
  11179. this.color = savedColor;
  11180. this.#redraw();
  11181. },
  11182. mustExec: true,
  11183. type: _util.AnnotationEditorParamsType.INK_COLOR,
  11184. overwriteIfSameType: true,
  11185. keepUndo: true
  11186. });
  11187. }
  11188. #updateOpacity(opacity) {
  11189. opacity /= 100;
  11190. const savedOpacity = this.opacity;
  11191. this.addCommands({
  11192. cmd: () => {
  11193. this.opacity = opacity;
  11194. this.#redraw();
  11195. },
  11196. undo: () => {
  11197. this.opacity = savedOpacity;
  11198. this.#redraw();
  11199. },
  11200. mustExec: true,
  11201. type: _util.AnnotationEditorParamsType.INK_OPACITY,
  11202. overwriteIfSameType: true,
  11203. keepUndo: true
  11204. });
  11205. }
  11206. rebuild() {
  11207. super.rebuild();
  11208. if (this.div === null) {
  11209. return;
  11210. }
  11211. if (!this.canvas) {
  11212. this.#createCanvas();
  11213. this.#createObserver();
  11214. }
  11215. if (!this.isAttachedToDOM) {
  11216. this.parent.add(this);
  11217. this.#setCanvasDims();
  11218. }
  11219. this.#fitToContent();
  11220. }
  11221. remove() {
  11222. if (this.canvas === null) {
  11223. return;
  11224. }
  11225. if (!this.isEmpty()) {
  11226. this.commit();
  11227. }
  11228. this.canvas.width = this.canvas.height = 0;
  11229. this.canvas.remove();
  11230. this.canvas = null;
  11231. this.#observer.disconnect();
  11232. this.#observer = null;
  11233. super.remove();
  11234. }
  11235. setParent(parent) {
  11236. if (!this.parent && parent) {
  11237. this._uiManager.removeShouldRescale(this);
  11238. } else if (this.parent && parent === null) {
  11239. this._uiManager.addShouldRescale(this);
  11240. }
  11241. super.setParent(parent);
  11242. }
  11243. onScaleChanging() {
  11244. const [parentWidth, parentHeight] = this.parentDimensions;
  11245. const width = this.width * parentWidth;
  11246. const height = this.height * parentHeight;
  11247. this.setDimensions(width, height);
  11248. }
  11249. enableEditMode() {
  11250. if (this.#disableEditing || this.canvas === null) {
  11251. return;
  11252. }
  11253. super.enableEditMode();
  11254. this.div.draggable = false;
  11255. this.canvas.addEventListener("pointerdown", this.#boundCanvasPointerdown);
  11256. }
  11257. disableEditMode() {
  11258. if (!this.isInEditMode() || this.canvas === null) {
  11259. return;
  11260. }
  11261. super.disableEditMode();
  11262. this.div.draggable = !this.isEmpty();
  11263. this.div.classList.remove("editing");
  11264. this.canvas.removeEventListener("pointerdown", this.#boundCanvasPointerdown);
  11265. }
  11266. onceAdded() {
  11267. this.div.draggable = !this.isEmpty();
  11268. }
  11269. isEmpty() {
  11270. return this.paths.length === 0 || this.paths.length === 1 && this.paths[0].length === 0;
  11271. }
  11272. #getInitialBBox() {
  11273. const {
  11274. parentRotation,
  11275. parentDimensions: [width, height]
  11276. } = this;
  11277. switch (parentRotation) {
  11278. case 90:
  11279. return [0, height, height, width];
  11280. case 180:
  11281. return [width, height, width, height];
  11282. case 270:
  11283. return [width, 0, height, width];
  11284. default:
  11285. return [0, 0, width, height];
  11286. }
  11287. }
  11288. #setStroke() {
  11289. const {
  11290. ctx,
  11291. color,
  11292. opacity,
  11293. thickness,
  11294. parentScale,
  11295. scaleFactor
  11296. } = this;
  11297. ctx.lineWidth = thickness * parentScale / scaleFactor;
  11298. ctx.lineCap = "round";
  11299. ctx.lineJoin = "round";
  11300. ctx.miterLimit = 10;
  11301. ctx.strokeStyle = `${color}${(0, _tools.opacityToHex)(opacity)}`;
  11302. }
  11303. #startDrawing(x, y) {
  11304. this.canvas.addEventListener("contextmenu", this.#boundCanvasContextMenu);
  11305. this.canvas.addEventListener("pointerleave", this.#boundCanvasPointerleave);
  11306. this.canvas.addEventListener("pointermove", this.#boundCanvasPointermove);
  11307. this.canvas.addEventListener("pointerup", this.#boundCanvasPointerup);
  11308. this.canvas.removeEventListener("pointerdown", this.#boundCanvasPointerdown);
  11309. this.isEditing = true;
  11310. if (!this.#isCanvasInitialized) {
  11311. this.#isCanvasInitialized = true;
  11312. this.#setCanvasDims();
  11313. this.thickness ||= InkEditor._defaultThickness;
  11314. this.color ||= InkEditor._defaultColor || _editor.AnnotationEditor._defaultLineColor;
  11315. this.opacity ??= InkEditor._defaultOpacity;
  11316. }
  11317. this.currentPath.push([x, y]);
  11318. this.#hasSomethingToDraw = false;
  11319. this.#setStroke();
  11320. this.#requestFrameCallback = () => {
  11321. this.#drawPoints();
  11322. if (this.#requestFrameCallback) {
  11323. window.requestAnimationFrame(this.#requestFrameCallback);
  11324. }
  11325. };
  11326. window.requestAnimationFrame(this.#requestFrameCallback);
  11327. }
  11328. #draw(x, y) {
  11329. const [lastX, lastY] = this.currentPath.at(-1);
  11330. if (this.currentPath.length > 1 && x === lastX && y === lastY) {
  11331. return;
  11332. }
  11333. const currentPath = this.currentPath;
  11334. let path2D = this.#currentPath2D;
  11335. currentPath.push([x, y]);
  11336. this.#hasSomethingToDraw = true;
  11337. if (currentPath.length <= 2) {
  11338. path2D.moveTo(...currentPath[0]);
  11339. path2D.lineTo(x, y);
  11340. return;
  11341. }
  11342. if (currentPath.length === 3) {
  11343. this.#currentPath2D = path2D = new Path2D();
  11344. path2D.moveTo(...currentPath[0]);
  11345. }
  11346. this.#makeBezierCurve(path2D, ...currentPath.at(-3), ...currentPath.at(-2), x, y);
  11347. }
  11348. #endPath() {
  11349. if (this.currentPath.length === 0) {
  11350. return;
  11351. }
  11352. const lastPoint = this.currentPath.at(-1);
  11353. this.#currentPath2D.lineTo(...lastPoint);
  11354. }
  11355. #stopDrawing(x, y) {
  11356. this.#requestFrameCallback = null;
  11357. x = Math.min(Math.max(x, 0), this.canvas.width);
  11358. y = Math.min(Math.max(y, 0), this.canvas.height);
  11359. this.#draw(x, y);
  11360. this.#endPath();
  11361. let bezier;
  11362. if (this.currentPath.length !== 1) {
  11363. bezier = this.#generateBezierPoints();
  11364. } else {
  11365. const xy = [x, y];
  11366. bezier = [[xy, xy.slice(), xy.slice(), xy]];
  11367. }
  11368. const path2D = this.#currentPath2D;
  11369. const currentPath = this.currentPath;
  11370. this.currentPath = [];
  11371. this.#currentPath2D = new Path2D();
  11372. const cmd = () => {
  11373. this.allRawPaths.push(currentPath);
  11374. this.paths.push(bezier);
  11375. this.bezierPath2D.push(path2D);
  11376. this.rebuild();
  11377. };
  11378. const undo = () => {
  11379. this.allRawPaths.pop();
  11380. this.paths.pop();
  11381. this.bezierPath2D.pop();
  11382. if (this.paths.length === 0) {
  11383. this.remove();
  11384. } else {
  11385. if (!this.canvas) {
  11386. this.#createCanvas();
  11387. this.#createObserver();
  11388. }
  11389. this.#fitToContent();
  11390. }
  11391. };
  11392. this.addCommands({
  11393. cmd,
  11394. undo,
  11395. mustExec: true
  11396. });
  11397. }
  11398. #drawPoints() {
  11399. if (!this.#hasSomethingToDraw) {
  11400. return;
  11401. }
  11402. this.#hasSomethingToDraw = false;
  11403. const thickness = Math.ceil(this.thickness * this.parentScale);
  11404. const lastPoints = this.currentPath.slice(-3);
  11405. const x = lastPoints.map(xy => xy[0]);
  11406. const y = lastPoints.map(xy => xy[1]);
  11407. const xMin = Math.min(...x) - thickness;
  11408. const xMax = Math.max(...x) + thickness;
  11409. const yMin = Math.min(...y) - thickness;
  11410. const yMax = Math.max(...y) + thickness;
  11411. const {
  11412. ctx
  11413. } = this;
  11414. ctx.save();
  11415. ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
  11416. for (const path of this.bezierPath2D) {
  11417. ctx.stroke(path);
  11418. }
  11419. ctx.stroke(this.#currentPath2D);
  11420. ctx.restore();
  11421. }
  11422. #makeBezierCurve(path2D, x0, y0, x1, y1, x2, y2) {
  11423. const prevX = (x0 + x1) / 2;
  11424. const prevY = (y0 + y1) / 2;
  11425. const x3 = (x1 + x2) / 2;
  11426. const y3 = (y1 + y2) / 2;
  11427. path2D.bezierCurveTo(prevX + 2 * (x1 - prevX) / 3, prevY + 2 * (y1 - prevY) / 3, x3 + 2 * (x1 - x3) / 3, y3 + 2 * (y1 - y3) / 3, x3, y3);
  11428. }
  11429. #generateBezierPoints() {
  11430. const path = this.currentPath;
  11431. if (path.length <= 2) {
  11432. return [[path[0], path[0], path.at(-1), path.at(-1)]];
  11433. }
  11434. const bezierPoints = [];
  11435. let i;
  11436. let [x0, y0] = path[0];
  11437. for (i = 1; i < path.length - 2; i++) {
  11438. const [x1, y1] = path[i];
  11439. const [x2, y2] = path[i + 1];
  11440. const x3 = (x1 + x2) / 2;
  11441. const y3 = (y1 + y2) / 2;
  11442. const control1 = [x0 + 2 * (x1 - x0) / 3, y0 + 2 * (y1 - y0) / 3];
  11443. const control2 = [x3 + 2 * (x1 - x3) / 3, y3 + 2 * (y1 - y3) / 3];
  11444. bezierPoints.push([[x0, y0], control1, control2, [x3, y3]]);
  11445. [x0, y0] = [x3, y3];
  11446. }
  11447. const [x1, y1] = path[i];
  11448. const [x2, y2] = path[i + 1];
  11449. const control1 = [x0 + 2 * (x1 - x0) / 3, y0 + 2 * (y1 - y0) / 3];
  11450. const control2 = [x2 + 2 * (x1 - x2) / 3, y2 + 2 * (y1 - y2) / 3];
  11451. bezierPoints.push([[x0, y0], control1, control2, [x2, y2]]);
  11452. return bezierPoints;
  11453. }
  11454. #redraw() {
  11455. if (this.isEmpty()) {
  11456. this.#updateTransform();
  11457. return;
  11458. }
  11459. this.#setStroke();
  11460. const {
  11461. canvas,
  11462. ctx
  11463. } = this;
  11464. ctx.setTransform(1, 0, 0, 1, 0, 0);
  11465. ctx.clearRect(0, 0, canvas.width, canvas.height);
  11466. this.#updateTransform();
  11467. for (const path of this.bezierPath2D) {
  11468. ctx.stroke(path);
  11469. }
  11470. }
  11471. commit() {
  11472. if (this.#disableEditing) {
  11473. return;
  11474. }
  11475. super.commit();
  11476. this.isEditing = false;
  11477. this.disableEditMode();
  11478. this.setInForeground();
  11479. this.#disableEditing = true;
  11480. this.div.classList.add("disabled");
  11481. this.#fitToContent(true);
  11482. this.parent.addInkEditorIfNeeded(true);
  11483. this.parent.moveEditorInDOM(this);
  11484. this.div.focus({
  11485. preventScroll: true
  11486. });
  11487. }
  11488. focusin(event) {
  11489. super.focusin(event);
  11490. this.enableEditMode();
  11491. }
  11492. canvasPointerdown(event) {
  11493. if (event.button !== 0 || !this.isInEditMode() || this.#disableEditing) {
  11494. return;
  11495. }
  11496. this.setInForeground();
  11497. event.preventDefault();
  11498. if (event.type !== "mouse") {
  11499. this.div.focus();
  11500. }
  11501. this.#startDrawing(event.offsetX, event.offsetY);
  11502. }
  11503. canvasContextMenu(event) {
  11504. event.preventDefault();
  11505. }
  11506. canvasPointermove(event) {
  11507. event.preventDefault();
  11508. this.#draw(event.offsetX, event.offsetY);
  11509. }
  11510. canvasPointerup(event) {
  11511. event.preventDefault();
  11512. this.#endDrawing(event);
  11513. }
  11514. canvasPointerleave(event) {
  11515. this.#endDrawing(event);
  11516. }
  11517. #endDrawing(event) {
  11518. this.canvas.removeEventListener("pointerleave", this.#boundCanvasPointerleave);
  11519. this.canvas.removeEventListener("pointermove", this.#boundCanvasPointermove);
  11520. this.canvas.removeEventListener("pointerup", this.#boundCanvasPointerup);
  11521. this.canvas.addEventListener("pointerdown", this.#boundCanvasPointerdown);
  11522. setTimeout(() => {
  11523. this.canvas.removeEventListener("contextmenu", this.#boundCanvasContextMenu);
  11524. }, 10);
  11525. this.#stopDrawing(event.offsetX, event.offsetY);
  11526. this.addToAnnotationStorage();
  11527. this.setInBackground();
  11528. }
  11529. #createCanvas() {
  11530. this.canvas = document.createElement("canvas");
  11531. this.canvas.width = this.canvas.height = 0;
  11532. this.canvas.className = "inkEditorCanvas";
  11533. InkEditor._l10nPromise.get("editor_ink_canvas_aria_label").then(msg => this.canvas?.setAttribute("aria-label", msg));
  11534. this.div.append(this.canvas);
  11535. this.ctx = this.canvas.getContext("2d");
  11536. }
  11537. #createObserver() {
  11538. this.#observer = new ResizeObserver(entries => {
  11539. const rect = entries[0].contentRect;
  11540. if (rect.width && rect.height) {
  11541. this.setDimensions(rect.width, rect.height);
  11542. }
  11543. });
  11544. this.#observer.observe(this.div);
  11545. }
  11546. render() {
  11547. if (this.div) {
  11548. return this.div;
  11549. }
  11550. let baseX, baseY;
  11551. if (this.width) {
  11552. baseX = this.x;
  11553. baseY = this.y;
  11554. }
  11555. super.render();
  11556. InkEditor._l10nPromise.get("editor_ink2_aria_label").then(msg => this.div?.setAttribute("aria-label", msg));
  11557. const [x, y, w, h] = this.#getInitialBBox();
  11558. this.setAt(x, y, 0, 0);
  11559. this.setDims(w, h);
  11560. this.#createCanvas();
  11561. if (this.width) {
  11562. const [parentWidth, parentHeight] = this.parentDimensions;
  11563. this.setAt(baseX * parentWidth, baseY * parentHeight, this.width * parentWidth, this.height * parentHeight);
  11564. this.#isCanvasInitialized = true;
  11565. this.#setCanvasDims();
  11566. this.setDims(this.width * parentWidth, this.height * parentHeight);
  11567. this.#redraw();
  11568. this.#setMinDims();
  11569. this.div.classList.add("disabled");
  11570. } else {
  11571. this.div.classList.add("editing");
  11572. this.enableEditMode();
  11573. }
  11574. this.#createObserver();
  11575. return this.div;
  11576. }
  11577. #setCanvasDims() {
  11578. if (!this.#isCanvasInitialized) {
  11579. return;
  11580. }
  11581. const [parentWidth, parentHeight] = this.parentDimensions;
  11582. this.canvas.width = Math.ceil(this.width * parentWidth);
  11583. this.canvas.height = Math.ceil(this.height * parentHeight);
  11584. this.#updateTransform();
  11585. }
  11586. setDimensions(width, height) {
  11587. const roundedWidth = Math.round(width);
  11588. const roundedHeight = Math.round(height);
  11589. if (this.#realWidth === roundedWidth && this.#realHeight === roundedHeight) {
  11590. return;
  11591. }
  11592. this.#realWidth = roundedWidth;
  11593. this.#realHeight = roundedHeight;
  11594. this.canvas.style.visibility = "hidden";
  11595. if (this.#aspectRatio && Math.abs(this.#aspectRatio - width / height) > 1e-2) {
  11596. height = Math.ceil(width / this.#aspectRatio);
  11597. this.setDims(width, height);
  11598. }
  11599. const [parentWidth, parentHeight] = this.parentDimensions;
  11600. this.width = width / parentWidth;
  11601. this.height = height / parentHeight;
  11602. if (this.#disableEditing) {
  11603. this.#setScaleFactor(width, height);
  11604. }
  11605. this.#setCanvasDims();
  11606. this.#redraw();
  11607. this.canvas.style.visibility = "visible";
  11608. this.fixDims();
  11609. }
  11610. #setScaleFactor(width, height) {
  11611. const padding = this.#getPadding();
  11612. const scaleFactorW = (width - padding) / this.#baseWidth;
  11613. const scaleFactorH = (height - padding) / this.#baseHeight;
  11614. this.scaleFactor = Math.min(scaleFactorW, scaleFactorH);
  11615. }
  11616. #updateTransform() {
  11617. const padding = this.#getPadding() / 2;
  11618. this.ctx.setTransform(this.scaleFactor, 0, 0, this.scaleFactor, this.translationX * this.scaleFactor + padding, this.translationY * this.scaleFactor + padding);
  11619. }
  11620. static #buildPath2D(bezier) {
  11621. const path2D = new Path2D();
  11622. for (let i = 0, ii = bezier.length; i < ii; i++) {
  11623. const [first, control1, control2, second] = bezier[i];
  11624. if (i === 0) {
  11625. path2D.moveTo(...first);
  11626. }
  11627. path2D.bezierCurveTo(control1[0], control1[1], control2[0], control2[1], second[0], second[1]);
  11628. }
  11629. return path2D;
  11630. }
  11631. #serializePaths(s, tx, ty, h) {
  11632. const NUMBER_OF_POINTS_ON_BEZIER_CURVE = 4;
  11633. const paths = [];
  11634. const padding = this.thickness / 2;
  11635. let buffer, points;
  11636. for (const bezier of this.paths) {
  11637. buffer = [];
  11638. points = [];
  11639. for (let i = 0, ii = bezier.length; i < ii; i++) {
  11640. const [first, control1, control2, second] = bezier[i];
  11641. const p10 = s * (first[0] + tx) + padding;
  11642. const p11 = h - s * (first[1] + ty) - padding;
  11643. const p20 = s * (control1[0] + tx) + padding;
  11644. const p21 = h - s * (control1[1] + ty) - padding;
  11645. const p30 = s * (control2[0] + tx) + padding;
  11646. const p31 = h - s * (control2[1] + ty) - padding;
  11647. const p40 = s * (second[0] + tx) + padding;
  11648. const p41 = h - s * (second[1] + ty) - padding;
  11649. if (i === 0) {
  11650. buffer.push(p10, p11);
  11651. points.push(p10, p11);
  11652. }
  11653. buffer.push(p20, p21, p30, p31, p40, p41);
  11654. this.#extractPointsOnBezier(p10, p11, p20, p21, p30, p31, p40, p41, NUMBER_OF_POINTS_ON_BEZIER_CURVE, points);
  11655. }
  11656. paths.push({
  11657. bezier: buffer,
  11658. points
  11659. });
  11660. }
  11661. return paths;
  11662. }
  11663. #extractPointsOnBezier(p10, p11, p20, p21, p30, p31, p40, p41, n, points) {
  11664. if (this.#isAlmostFlat(p10, p11, p20, p21, p30, p31, p40, p41)) {
  11665. points.push(p40, p41);
  11666. return;
  11667. }
  11668. for (let i = 1; i < n - 1; i++) {
  11669. const t = i / n;
  11670. const mt = 1 - t;
  11671. let q10 = t * p10 + mt * p20;
  11672. let q11 = t * p11 + mt * p21;
  11673. let q20 = t * p20 + mt * p30;
  11674. let q21 = t * p21 + mt * p31;
  11675. const q30 = t * p30 + mt * p40;
  11676. const q31 = t * p31 + mt * p41;
  11677. q10 = t * q10 + mt * q20;
  11678. q11 = t * q11 + mt * q21;
  11679. q20 = t * q20 + mt * q30;
  11680. q21 = t * q21 + mt * q31;
  11681. q10 = t * q10 + mt * q20;
  11682. q11 = t * q11 + mt * q21;
  11683. points.push(q10, q11);
  11684. }
  11685. points.push(p40, p41);
  11686. }
  11687. #isAlmostFlat(p10, p11, p20, p21, p30, p31, p40, p41) {
  11688. const tol = 10;
  11689. const ax = (3 * p20 - 2 * p10 - p40) ** 2;
  11690. const ay = (3 * p21 - 2 * p11 - p41) ** 2;
  11691. const bx = (3 * p30 - p10 - 2 * p40) ** 2;
  11692. const by = (3 * p31 - p11 - 2 * p41) ** 2;
  11693. return Math.max(ax, bx) + Math.max(ay, by) <= tol;
  11694. }
  11695. #getBbox() {
  11696. let xMin = Infinity;
  11697. let xMax = -Infinity;
  11698. let yMin = Infinity;
  11699. let yMax = -Infinity;
  11700. for (const path of this.paths) {
  11701. for (const [first, control1, control2, second] of path) {
  11702. const bbox = _util.Util.bezierBoundingBox(...first, ...control1, ...control2, ...second);
  11703. xMin = Math.min(xMin, bbox[0]);
  11704. yMin = Math.min(yMin, bbox[1]);
  11705. xMax = Math.max(xMax, bbox[2]);
  11706. yMax = Math.max(yMax, bbox[3]);
  11707. }
  11708. }
  11709. return [xMin, yMin, xMax, yMax];
  11710. }
  11711. #getPadding() {
  11712. return this.#disableEditing ? Math.ceil(this.thickness * this.parentScale) : 0;
  11713. }
  11714. #fitToContent(firstTime = false) {
  11715. if (this.isEmpty()) {
  11716. return;
  11717. }
  11718. if (!this.#disableEditing) {
  11719. this.#redraw();
  11720. return;
  11721. }
  11722. const bbox = this.#getBbox();
  11723. const padding = this.#getPadding();
  11724. this.#baseWidth = Math.max(RESIZER_SIZE, bbox[2] - bbox[0]);
  11725. this.#baseHeight = Math.max(RESIZER_SIZE, bbox[3] - bbox[1]);
  11726. const width = Math.ceil(padding + this.#baseWidth * this.scaleFactor);
  11727. const height = Math.ceil(padding + this.#baseHeight * this.scaleFactor);
  11728. const [parentWidth, parentHeight] = this.parentDimensions;
  11729. this.width = width / parentWidth;
  11730. this.height = height / parentHeight;
  11731. this.#aspectRatio = width / height;
  11732. this.#setMinDims();
  11733. const prevTranslationX = this.translationX;
  11734. const prevTranslationY = this.translationY;
  11735. this.translationX = -bbox[0];
  11736. this.translationY = -bbox[1];
  11737. this.#setCanvasDims();
  11738. this.#redraw();
  11739. this.#realWidth = width;
  11740. this.#realHeight = height;
  11741. this.setDims(width, height);
  11742. const unscaledPadding = firstTime ? padding / this.scaleFactor / 2 : 0;
  11743. this.translate(prevTranslationX - this.translationX - unscaledPadding, prevTranslationY - this.translationY - unscaledPadding);
  11744. }
  11745. #setMinDims() {
  11746. const {
  11747. style
  11748. } = this.div;
  11749. if (this.#aspectRatio >= 1) {
  11750. style.minHeight = `${RESIZER_SIZE}px`;
  11751. style.minWidth = `${Math.round(this.#aspectRatio * RESIZER_SIZE)}px`;
  11752. } else {
  11753. style.minWidth = `${RESIZER_SIZE}px`;
  11754. style.minHeight = `${Math.round(RESIZER_SIZE / this.#aspectRatio)}px`;
  11755. }
  11756. }
  11757. static deserialize(data, parent, uiManager) {
  11758. const editor = super.deserialize(data, parent, uiManager);
  11759. editor.thickness = data.thickness;
  11760. editor.color = _util.Util.makeHexColor(...data.color);
  11761. editor.opacity = data.opacity;
  11762. const [pageWidth, pageHeight] = editor.pageDimensions;
  11763. const width = editor.width * pageWidth;
  11764. const height = editor.height * pageHeight;
  11765. const scaleFactor = editor.parentScale;
  11766. const padding = data.thickness / 2;
  11767. editor.#aspectRatio = width / height;
  11768. editor.#disableEditing = true;
  11769. editor.#realWidth = Math.round(width);
  11770. editor.#realHeight = Math.round(height);
  11771. for (const {
  11772. bezier
  11773. } of data.paths) {
  11774. const path = [];
  11775. editor.paths.push(path);
  11776. let p0 = scaleFactor * (bezier[0] - padding);
  11777. let p1 = scaleFactor * (height - bezier[1] - padding);
  11778. for (let i = 2, ii = bezier.length; i < ii; i += 6) {
  11779. const p10 = scaleFactor * (bezier[i] - padding);
  11780. const p11 = scaleFactor * (height - bezier[i + 1] - padding);
  11781. const p20 = scaleFactor * (bezier[i + 2] - padding);
  11782. const p21 = scaleFactor * (height - bezier[i + 3] - padding);
  11783. const p30 = scaleFactor * (bezier[i + 4] - padding);
  11784. const p31 = scaleFactor * (height - bezier[i + 5] - padding);
  11785. path.push([[p0, p1], [p10, p11], [p20, p21], [p30, p31]]);
  11786. p0 = p30;
  11787. p1 = p31;
  11788. }
  11789. const path2D = this.#buildPath2D(path);
  11790. editor.bezierPath2D.push(path2D);
  11791. }
  11792. const bbox = editor.#getBbox();
  11793. editor.#baseWidth = Math.max(RESIZER_SIZE, bbox[2] - bbox[0]);
  11794. editor.#baseHeight = Math.max(RESIZER_SIZE, bbox[3] - bbox[1]);
  11795. editor.#setScaleFactor(width, height);
  11796. return editor;
  11797. }
  11798. serialize() {
  11799. if (this.isEmpty()) {
  11800. return null;
  11801. }
  11802. const rect = this.getRect(0, 0);
  11803. const height = this.rotation % 180 === 0 ? rect[3] - rect[1] : rect[2] - rect[0];
  11804. const color = _editor.AnnotationEditor._colorManager.convert(this.ctx.strokeStyle);
  11805. return {
  11806. annotationType: _util.AnnotationEditorType.INK,
  11807. color,
  11808. thickness: this.thickness,
  11809. opacity: this.opacity,
  11810. paths: this.#serializePaths(this.scaleFactor / this.parentScale, this.translationX, this.translationY, height),
  11811. pageIndex: this.pageIndex,
  11812. rect,
  11813. rotation: this.rotation
  11814. };
  11815. }
  11816. }
  11817. exports.InkEditor = InkEditor;
  11818. /***/ }),
  11819. /* 30 */
  11820. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  11821. Object.defineProperty(exports, "__esModule", ({
  11822. value: true
  11823. }));
  11824. exports.AnnotationLayer = void 0;
  11825. var _util = __w_pdfjs_require__(1);
  11826. var _display_utils = __w_pdfjs_require__(6);
  11827. var _annotation_storage = __w_pdfjs_require__(3);
  11828. var _scripting_utils = __w_pdfjs_require__(31);
  11829. var _xfa_layer = __w_pdfjs_require__(32);
  11830. const DEFAULT_TAB_INDEX = 1000;
  11831. const DEFAULT_FONT_SIZE = 9;
  11832. const GetElementsByNameSet = new WeakSet();
  11833. function getRectDims(rect) {
  11834. return {
  11835. width: rect[2] - rect[0],
  11836. height: rect[3] - rect[1]
  11837. };
  11838. }
  11839. class AnnotationElementFactory {
  11840. static create(parameters) {
  11841. const subtype = parameters.data.annotationType;
  11842. switch (subtype) {
  11843. case _util.AnnotationType.LINK:
  11844. return new LinkAnnotationElement(parameters);
  11845. case _util.AnnotationType.TEXT:
  11846. return new TextAnnotationElement(parameters);
  11847. case _util.AnnotationType.WIDGET:
  11848. const fieldType = parameters.data.fieldType;
  11849. switch (fieldType) {
  11850. case "Tx":
  11851. return new TextWidgetAnnotationElement(parameters);
  11852. case "Btn":
  11853. if (parameters.data.radioButton) {
  11854. return new RadioButtonWidgetAnnotationElement(parameters);
  11855. } else if (parameters.data.checkBox) {
  11856. return new CheckboxWidgetAnnotationElement(parameters);
  11857. }
  11858. return new PushButtonWidgetAnnotationElement(parameters);
  11859. case "Ch":
  11860. return new ChoiceWidgetAnnotationElement(parameters);
  11861. }
  11862. return new WidgetAnnotationElement(parameters);
  11863. case _util.AnnotationType.POPUP:
  11864. return new PopupAnnotationElement(parameters);
  11865. case _util.AnnotationType.FREETEXT:
  11866. return new FreeTextAnnotationElement(parameters);
  11867. case _util.AnnotationType.LINE:
  11868. return new LineAnnotationElement(parameters);
  11869. case _util.AnnotationType.SQUARE:
  11870. return new SquareAnnotationElement(parameters);
  11871. case _util.AnnotationType.CIRCLE:
  11872. return new CircleAnnotationElement(parameters);
  11873. case _util.AnnotationType.POLYLINE:
  11874. return new PolylineAnnotationElement(parameters);
  11875. case _util.AnnotationType.CARET:
  11876. return new CaretAnnotationElement(parameters);
  11877. case _util.AnnotationType.INK:
  11878. return new InkAnnotationElement(parameters);
  11879. case _util.AnnotationType.POLYGON:
  11880. return new PolygonAnnotationElement(parameters);
  11881. case _util.AnnotationType.HIGHLIGHT:
  11882. return new HighlightAnnotationElement(parameters);
  11883. case _util.AnnotationType.UNDERLINE:
  11884. return new UnderlineAnnotationElement(parameters);
  11885. case _util.AnnotationType.SQUIGGLY:
  11886. return new SquigglyAnnotationElement(parameters);
  11887. case _util.AnnotationType.STRIKEOUT:
  11888. return new StrikeOutAnnotationElement(parameters);
  11889. case _util.AnnotationType.STAMP:
  11890. return new StampAnnotationElement(parameters);
  11891. case _util.AnnotationType.FILEATTACHMENT:
  11892. return new FileAttachmentAnnotationElement(parameters);
  11893. default:
  11894. return new AnnotationElement(parameters);
  11895. }
  11896. }
  11897. }
  11898. class AnnotationElement {
  11899. constructor(parameters, {
  11900. isRenderable = false,
  11901. ignoreBorder = false,
  11902. createQuadrilaterals = false
  11903. } = {}) {
  11904. this.isRenderable = isRenderable;
  11905. this.data = parameters.data;
  11906. this.layer = parameters.layer;
  11907. this.page = parameters.page;
  11908. this.viewport = parameters.viewport;
  11909. this.linkService = parameters.linkService;
  11910. this.downloadManager = parameters.downloadManager;
  11911. this.imageResourcesPath = parameters.imageResourcesPath;
  11912. this.renderForms = parameters.renderForms;
  11913. this.svgFactory = parameters.svgFactory;
  11914. this.annotationStorage = parameters.annotationStorage;
  11915. this.enableScripting = parameters.enableScripting;
  11916. this.hasJSActions = parameters.hasJSActions;
  11917. this._fieldObjects = parameters.fieldObjects;
  11918. if (isRenderable) {
  11919. this.container = this._createContainer(ignoreBorder);
  11920. }
  11921. if (createQuadrilaterals) {
  11922. this.quadrilaterals = this._createQuadrilaterals(ignoreBorder);
  11923. }
  11924. }
  11925. _createContainer(ignoreBorder = false) {
  11926. const {
  11927. data,
  11928. page,
  11929. viewport
  11930. } = this;
  11931. const container = document.createElement("section");
  11932. container.setAttribute("data-annotation-id", data.id);
  11933. if (data.noRotate) {
  11934. container.classList.add("norotate");
  11935. }
  11936. const {
  11937. pageWidth,
  11938. pageHeight,
  11939. pageX,
  11940. pageY
  11941. } = viewport.rawDims;
  11942. const {
  11943. width,
  11944. height
  11945. } = getRectDims(data.rect);
  11946. 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]]);
  11947. if (!ignoreBorder && data.borderStyle.width > 0) {
  11948. container.style.borderWidth = `${data.borderStyle.width}px`;
  11949. const horizontalRadius = data.borderStyle.horizontalCornerRadius;
  11950. const verticalRadius = data.borderStyle.verticalCornerRadius;
  11951. if (horizontalRadius > 0 || verticalRadius > 0) {
  11952. const radius = `calc(${horizontalRadius}px * var(--scale-factor)) / calc(${verticalRadius}px * var(--scale-factor))`;
  11953. container.style.borderRadius = radius;
  11954. } else if (this instanceof RadioButtonWidgetAnnotationElement) {
  11955. const radius = `calc(${width}px * var(--scale-factor)) / calc(${height}px * var(--scale-factor))`;
  11956. container.style.borderRadius = radius;
  11957. }
  11958. switch (data.borderStyle.style) {
  11959. case _util.AnnotationBorderStyleType.SOLID:
  11960. container.style.borderStyle = "solid";
  11961. break;
  11962. case _util.AnnotationBorderStyleType.DASHED:
  11963. container.style.borderStyle = "dashed";
  11964. break;
  11965. case _util.AnnotationBorderStyleType.BEVELED:
  11966. (0, _util.warn)("Unimplemented border style: beveled");
  11967. break;
  11968. case _util.AnnotationBorderStyleType.INSET:
  11969. (0, _util.warn)("Unimplemented border style: inset");
  11970. break;
  11971. case _util.AnnotationBorderStyleType.UNDERLINE:
  11972. container.style.borderBottomStyle = "solid";
  11973. break;
  11974. default:
  11975. break;
  11976. }
  11977. const borderColor = data.borderColor || null;
  11978. if (borderColor) {
  11979. container.style.borderColor = _util.Util.makeHexColor(borderColor[0] | 0, borderColor[1] | 0, borderColor[2] | 0);
  11980. } else {
  11981. container.style.borderWidth = 0;
  11982. }
  11983. }
  11984. container.style.left = `${100 * (rect[0] - pageX) / pageWidth}%`;
  11985. container.style.top = `${100 * (rect[1] - pageY) / pageHeight}%`;
  11986. const {
  11987. rotation
  11988. } = data;
  11989. if (data.hasOwnCanvas || rotation === 0) {
  11990. container.style.width = `${100 * width / pageWidth}%`;
  11991. container.style.height = `${100 * height / pageHeight}%`;
  11992. } else {
  11993. this.setRotation(rotation, container);
  11994. }
  11995. return container;
  11996. }
  11997. setRotation(angle, container = this.container) {
  11998. const {
  11999. pageWidth,
  12000. pageHeight
  12001. } = this.viewport.rawDims;
  12002. const {
  12003. width,
  12004. height
  12005. } = getRectDims(this.data.rect);
  12006. let elementWidth, elementHeight;
  12007. if (angle % 180 === 0) {
  12008. elementWidth = 100 * width / pageWidth;
  12009. elementHeight = 100 * height / pageHeight;
  12010. } else {
  12011. elementWidth = 100 * height / pageWidth;
  12012. elementHeight = 100 * width / pageHeight;
  12013. }
  12014. container.style.width = `${elementWidth}%`;
  12015. container.style.height = `${elementHeight}%`;
  12016. container.setAttribute("data-main-rotation", (360 - angle) % 360);
  12017. }
  12018. get _commonActions() {
  12019. const setColor = (jsName, styleName, event) => {
  12020. const color = event.detail[jsName];
  12021. event.target.style[styleName] = _scripting_utils.ColorConverters[`${color[0]}_HTML`](color.slice(1));
  12022. };
  12023. return (0, _util.shadow)(this, "_commonActions", {
  12024. display: event => {
  12025. const hidden = event.detail.display % 2 === 1;
  12026. this.container.style.visibility = hidden ? "hidden" : "visible";
  12027. this.annotationStorage.setValue(this.data.id, {
  12028. hidden,
  12029. print: event.detail.display === 0 || event.detail.display === 3
  12030. });
  12031. },
  12032. print: event => {
  12033. this.annotationStorage.setValue(this.data.id, {
  12034. print: event.detail.print
  12035. });
  12036. },
  12037. hidden: event => {
  12038. this.container.style.visibility = event.detail.hidden ? "hidden" : "visible";
  12039. this.annotationStorage.setValue(this.data.id, {
  12040. hidden: event.detail.hidden
  12041. });
  12042. },
  12043. focus: event => {
  12044. setTimeout(() => event.target.focus({
  12045. preventScroll: false
  12046. }), 0);
  12047. },
  12048. userName: event => {
  12049. event.target.title = event.detail.userName;
  12050. },
  12051. readonly: event => {
  12052. if (event.detail.readonly) {
  12053. event.target.setAttribute("readonly", "");
  12054. } else {
  12055. event.target.removeAttribute("readonly");
  12056. }
  12057. },
  12058. required: event => {
  12059. this._setRequired(event.target, event.detail.required);
  12060. },
  12061. bgColor: event => {
  12062. setColor("bgColor", "backgroundColor", event);
  12063. },
  12064. fillColor: event => {
  12065. setColor("fillColor", "backgroundColor", event);
  12066. },
  12067. fgColor: event => {
  12068. setColor("fgColor", "color", event);
  12069. },
  12070. textColor: event => {
  12071. setColor("textColor", "color", event);
  12072. },
  12073. borderColor: event => {
  12074. setColor("borderColor", "borderColor", event);
  12075. },
  12076. strokeColor: event => {
  12077. setColor("strokeColor", "borderColor", event);
  12078. },
  12079. rotation: event => {
  12080. const angle = event.detail.rotation;
  12081. this.setRotation(angle);
  12082. this.annotationStorage.setValue(this.data.id, {
  12083. rotation: angle
  12084. });
  12085. }
  12086. });
  12087. }
  12088. _dispatchEventFromSandbox(actions, jsEvent) {
  12089. const commonActions = this._commonActions;
  12090. for (const name of Object.keys(jsEvent.detail)) {
  12091. const action = actions[name] || commonActions[name];
  12092. action?.(jsEvent);
  12093. }
  12094. }
  12095. _setDefaultPropertiesFromJS(element) {
  12096. if (!this.enableScripting) {
  12097. return;
  12098. }
  12099. const storedData = this.annotationStorage.getRawValue(this.data.id);
  12100. if (!storedData) {
  12101. return;
  12102. }
  12103. const commonActions = this._commonActions;
  12104. for (const [actionName, detail] of Object.entries(storedData)) {
  12105. const action = commonActions[actionName];
  12106. if (action) {
  12107. const eventProxy = {
  12108. detail: {
  12109. [actionName]: detail
  12110. },
  12111. target: element
  12112. };
  12113. action(eventProxy);
  12114. delete storedData[actionName];
  12115. }
  12116. }
  12117. }
  12118. _createQuadrilaterals(ignoreBorder = false) {
  12119. if (!this.data.quadPoints) {
  12120. return null;
  12121. }
  12122. const quadrilaterals = [];
  12123. const savedRect = this.data.rect;
  12124. for (const quadPoint of this.data.quadPoints) {
  12125. this.data.rect = [quadPoint[2].x, quadPoint[2].y, quadPoint[1].x, quadPoint[1].y];
  12126. quadrilaterals.push(this._createContainer(ignoreBorder));
  12127. }
  12128. this.data.rect = savedRect;
  12129. return quadrilaterals;
  12130. }
  12131. _createPopup(trigger, data) {
  12132. let container = this.container;
  12133. if (this.quadrilaterals) {
  12134. trigger ||= this.quadrilaterals;
  12135. container = this.quadrilaterals[0];
  12136. }
  12137. if (!trigger) {
  12138. trigger = document.createElement("div");
  12139. trigger.classList.add("popupTriggerArea");
  12140. container.append(trigger);
  12141. }
  12142. const popupElement = new PopupElement({
  12143. container,
  12144. trigger,
  12145. color: data.color,
  12146. titleObj: data.titleObj,
  12147. modificationDate: data.modificationDate,
  12148. contentsObj: data.contentsObj,
  12149. richText: data.richText,
  12150. hideWrapper: true
  12151. });
  12152. const popup = popupElement.render();
  12153. popup.style.left = "100%";
  12154. container.append(popup);
  12155. }
  12156. _renderQuadrilaterals(className) {
  12157. for (const quadrilateral of this.quadrilaterals) {
  12158. quadrilateral.classList.add(className);
  12159. }
  12160. return this.quadrilaterals;
  12161. }
  12162. render() {
  12163. (0, _util.unreachable)("Abstract method `AnnotationElement.render` called");
  12164. }
  12165. _getElementsByName(name, skipId = null) {
  12166. const fields = [];
  12167. if (this._fieldObjects) {
  12168. const fieldObj = this._fieldObjects[name];
  12169. if (fieldObj) {
  12170. for (const {
  12171. page,
  12172. id,
  12173. exportValues
  12174. } of fieldObj) {
  12175. if (page === -1) {
  12176. continue;
  12177. }
  12178. if (id === skipId) {
  12179. continue;
  12180. }
  12181. const exportValue = typeof exportValues === "string" ? exportValues : null;
  12182. const domElement = document.querySelector(`[data-element-id="${id}"]`);
  12183. if (domElement && !GetElementsByNameSet.has(domElement)) {
  12184. (0, _util.warn)(`_getElementsByName - element not allowed: ${id}`);
  12185. continue;
  12186. }
  12187. fields.push({
  12188. id,
  12189. exportValue,
  12190. domElement
  12191. });
  12192. }
  12193. }
  12194. return fields;
  12195. }
  12196. for (const domElement of document.getElementsByName(name)) {
  12197. const {
  12198. exportValue
  12199. } = domElement;
  12200. const id = domElement.getAttribute("data-element-id");
  12201. if (id === skipId) {
  12202. continue;
  12203. }
  12204. if (!GetElementsByNameSet.has(domElement)) {
  12205. continue;
  12206. }
  12207. fields.push({
  12208. id,
  12209. exportValue,
  12210. domElement
  12211. });
  12212. }
  12213. return fields;
  12214. }
  12215. }
  12216. class LinkAnnotationElement extends AnnotationElement {
  12217. constructor(parameters, options = null) {
  12218. super(parameters, {
  12219. isRenderable: true,
  12220. ignoreBorder: !!options?.ignoreBorder,
  12221. createQuadrilaterals: true
  12222. });
  12223. this.isTooltipOnly = parameters.data.isTooltipOnly;
  12224. }
  12225. render() {
  12226. const {
  12227. data,
  12228. linkService
  12229. } = this;
  12230. const link = document.createElement("a");
  12231. link.setAttribute("data-element-id", data.id);
  12232. let isBound = false;
  12233. if (data.url) {
  12234. linkService.addLinkAttributes(link, data.url, data.newWindow);
  12235. isBound = true;
  12236. } else if (data.action) {
  12237. this._bindNamedAction(link, data.action);
  12238. isBound = true;
  12239. } else if (data.attachment) {
  12240. this._bindAttachment(link, data.attachment);
  12241. isBound = true;
  12242. } else if (data.setOCGState) {
  12243. this.#bindSetOCGState(link, data.setOCGState);
  12244. isBound = true;
  12245. } else if (data.dest) {
  12246. this._bindLink(link, data.dest);
  12247. isBound = true;
  12248. } else {
  12249. if (data.actions && (data.actions.Action || data.actions["Mouse Up"] || data.actions["Mouse Down"]) && this.enableScripting && this.hasJSActions) {
  12250. this._bindJSAction(link, data);
  12251. isBound = true;
  12252. }
  12253. if (data.resetForm) {
  12254. this._bindResetFormAction(link, data.resetForm);
  12255. isBound = true;
  12256. } else if (this.isTooltipOnly && !isBound) {
  12257. this._bindLink(link, "");
  12258. isBound = true;
  12259. }
  12260. }
  12261. if (this.quadrilaterals) {
  12262. return this._renderQuadrilaterals("linkAnnotation").map((quadrilateral, index) => {
  12263. const linkElement = index === 0 ? link : link.cloneNode();
  12264. quadrilateral.append(linkElement);
  12265. return quadrilateral;
  12266. });
  12267. }
  12268. this.container.classList.add("linkAnnotation");
  12269. if (isBound) {
  12270. this.container.append(link);
  12271. }
  12272. return this.container;
  12273. }
  12274. #setInternalLink() {
  12275. this.container.setAttribute("data-internal-link", "");
  12276. }
  12277. _bindLink(link, destination) {
  12278. link.href = this.linkService.getDestinationHash(destination);
  12279. link.onclick = () => {
  12280. if (destination) {
  12281. this.linkService.goToDestination(destination);
  12282. }
  12283. return false;
  12284. };
  12285. if (destination || destination === "") {
  12286. this.#setInternalLink();
  12287. }
  12288. }
  12289. _bindNamedAction(link, action) {
  12290. link.href = this.linkService.getAnchorUrl("");
  12291. link.onclick = () => {
  12292. this.linkService.executeNamedAction(action);
  12293. return false;
  12294. };
  12295. this.#setInternalLink();
  12296. }
  12297. _bindAttachment(link, attachment) {
  12298. link.href = this.linkService.getAnchorUrl("");
  12299. link.onclick = () => {
  12300. this.downloadManager?.openOrDownloadData(this.container, attachment.content, attachment.filename);
  12301. return false;
  12302. };
  12303. this.#setInternalLink();
  12304. }
  12305. #bindSetOCGState(link, action) {
  12306. link.href = this.linkService.getAnchorUrl("");
  12307. link.onclick = () => {
  12308. this.linkService.executeSetOCGState(action);
  12309. return false;
  12310. };
  12311. this.#setInternalLink();
  12312. }
  12313. _bindJSAction(link, data) {
  12314. link.href = this.linkService.getAnchorUrl("");
  12315. const map = new Map([["Action", "onclick"], ["Mouse Up", "onmouseup"], ["Mouse Down", "onmousedown"]]);
  12316. for (const name of Object.keys(data.actions)) {
  12317. const jsName = map.get(name);
  12318. if (!jsName) {
  12319. continue;
  12320. }
  12321. link[jsName] = () => {
  12322. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  12323. source: this,
  12324. detail: {
  12325. id: data.id,
  12326. name
  12327. }
  12328. });
  12329. return false;
  12330. };
  12331. }
  12332. if (!link.onclick) {
  12333. link.onclick = () => false;
  12334. }
  12335. this.#setInternalLink();
  12336. }
  12337. _bindResetFormAction(link, resetForm) {
  12338. const otherClickAction = link.onclick;
  12339. if (!otherClickAction) {
  12340. link.href = this.linkService.getAnchorUrl("");
  12341. }
  12342. this.#setInternalLink();
  12343. if (!this._fieldObjects) {
  12344. (0, _util.warn)(`_bindResetFormAction - "resetForm" action not supported, ` + "ensure that the `fieldObjects` parameter is provided.");
  12345. if (!otherClickAction) {
  12346. link.onclick = () => false;
  12347. }
  12348. return;
  12349. }
  12350. link.onclick = () => {
  12351. otherClickAction?.();
  12352. const {
  12353. fields: resetFormFields,
  12354. refs: resetFormRefs,
  12355. include
  12356. } = resetForm;
  12357. const allFields = [];
  12358. if (resetFormFields.length !== 0 || resetFormRefs.length !== 0) {
  12359. const fieldIds = new Set(resetFormRefs);
  12360. for (const fieldName of resetFormFields) {
  12361. const fields = this._fieldObjects[fieldName] || [];
  12362. for (const {
  12363. id
  12364. } of fields) {
  12365. fieldIds.add(id);
  12366. }
  12367. }
  12368. for (const fields of Object.values(this._fieldObjects)) {
  12369. for (const field of fields) {
  12370. if (fieldIds.has(field.id) === include) {
  12371. allFields.push(field);
  12372. }
  12373. }
  12374. }
  12375. } else {
  12376. for (const fields of Object.values(this._fieldObjects)) {
  12377. allFields.push(...fields);
  12378. }
  12379. }
  12380. const storage = this.annotationStorage;
  12381. const allIds = [];
  12382. for (const field of allFields) {
  12383. const {
  12384. id
  12385. } = field;
  12386. allIds.push(id);
  12387. switch (field.type) {
  12388. case "text":
  12389. {
  12390. const value = field.defaultValue || "";
  12391. storage.setValue(id, {
  12392. value
  12393. });
  12394. break;
  12395. }
  12396. case "checkbox":
  12397. case "radiobutton":
  12398. {
  12399. const value = field.defaultValue === field.exportValues;
  12400. storage.setValue(id, {
  12401. value
  12402. });
  12403. break;
  12404. }
  12405. case "combobox":
  12406. case "listbox":
  12407. {
  12408. const value = field.defaultValue || "";
  12409. storage.setValue(id, {
  12410. value
  12411. });
  12412. break;
  12413. }
  12414. default:
  12415. continue;
  12416. }
  12417. const domElement = document.querySelector(`[data-element-id="${id}"]`);
  12418. if (!domElement) {
  12419. continue;
  12420. } else if (!GetElementsByNameSet.has(domElement)) {
  12421. (0, _util.warn)(`_bindResetFormAction - element not allowed: ${id}`);
  12422. continue;
  12423. }
  12424. domElement.dispatchEvent(new Event("resetform"));
  12425. }
  12426. if (this.enableScripting) {
  12427. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  12428. source: this,
  12429. detail: {
  12430. id: "app",
  12431. ids: allIds,
  12432. name: "ResetForm"
  12433. }
  12434. });
  12435. }
  12436. return false;
  12437. };
  12438. }
  12439. }
  12440. class TextAnnotationElement extends AnnotationElement {
  12441. constructor(parameters) {
  12442. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  12443. super(parameters, {
  12444. isRenderable
  12445. });
  12446. }
  12447. render() {
  12448. this.container.classList.add("textAnnotation");
  12449. const image = document.createElement("img");
  12450. image.src = this.imageResourcesPath + "annotation-" + this.data.name.toLowerCase() + ".svg";
  12451. image.alt = "[{{type}} Annotation]";
  12452. image.dataset.l10nId = "text_annotation_type";
  12453. image.dataset.l10nArgs = JSON.stringify({
  12454. type: this.data.name
  12455. });
  12456. if (!this.data.hasPopup) {
  12457. this._createPopup(image, this.data);
  12458. }
  12459. this.container.append(image);
  12460. return this.container;
  12461. }
  12462. }
  12463. class WidgetAnnotationElement extends AnnotationElement {
  12464. render() {
  12465. if (this.data.alternativeText) {
  12466. this.container.title = this.data.alternativeText;
  12467. }
  12468. return this.container;
  12469. }
  12470. showElementAndHideCanvas(element) {
  12471. if (this.data.hasOwnCanvas) {
  12472. if (element.previousSibling?.nodeName === "CANVAS") {
  12473. element.previousSibling.hidden = true;
  12474. }
  12475. element.hidden = false;
  12476. }
  12477. }
  12478. _getKeyModifier(event) {
  12479. const {
  12480. isWin,
  12481. isMac
  12482. } = _util.FeatureTest.platform;
  12483. return isWin && event.ctrlKey || isMac && event.metaKey;
  12484. }
  12485. _setEventListener(element, baseName, eventName, valueGetter) {
  12486. if (baseName.includes("mouse")) {
  12487. element.addEventListener(baseName, event => {
  12488. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  12489. source: this,
  12490. detail: {
  12491. id: this.data.id,
  12492. name: eventName,
  12493. value: valueGetter(event),
  12494. shift: event.shiftKey,
  12495. modifier: this._getKeyModifier(event)
  12496. }
  12497. });
  12498. });
  12499. } else {
  12500. element.addEventListener(baseName, event => {
  12501. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  12502. source: this,
  12503. detail: {
  12504. id: this.data.id,
  12505. name: eventName,
  12506. value: valueGetter(event)
  12507. }
  12508. });
  12509. });
  12510. }
  12511. }
  12512. _setEventListeners(element, names, getter) {
  12513. for (const [baseName, eventName] of names) {
  12514. if (eventName === "Action" || this.data.actions?.[eventName]) {
  12515. this._setEventListener(element, baseName, eventName, getter);
  12516. }
  12517. }
  12518. }
  12519. _setBackgroundColor(element) {
  12520. const color = this.data.backgroundColor || null;
  12521. element.style.backgroundColor = color === null ? "transparent" : _util.Util.makeHexColor(color[0], color[1], color[2]);
  12522. }
  12523. _setTextStyle(element) {
  12524. const TEXT_ALIGNMENT = ["left", "center", "right"];
  12525. const {
  12526. fontColor
  12527. } = this.data.defaultAppearanceData;
  12528. const fontSize = this.data.defaultAppearanceData.fontSize || DEFAULT_FONT_SIZE;
  12529. const style = element.style;
  12530. let computedFontSize;
  12531. const BORDER_SIZE = 2;
  12532. const roundToOneDecimal = x => Math.round(10 * x) / 10;
  12533. if (this.data.multiLine) {
  12534. const height = Math.abs(this.data.rect[3] - this.data.rect[1] - BORDER_SIZE);
  12535. const numberOfLines = Math.round(height / (_util.LINE_FACTOR * fontSize)) || 1;
  12536. const lineHeight = height / numberOfLines;
  12537. computedFontSize = Math.min(fontSize, roundToOneDecimal(lineHeight / _util.LINE_FACTOR));
  12538. } else {
  12539. const height = Math.abs(this.data.rect[3] - this.data.rect[1] - BORDER_SIZE);
  12540. computedFontSize = Math.min(fontSize, roundToOneDecimal(height / _util.LINE_FACTOR));
  12541. }
  12542. style.fontSize = `calc(${computedFontSize}px * var(--scale-factor))`;
  12543. style.color = _util.Util.makeHexColor(fontColor[0], fontColor[1], fontColor[2]);
  12544. if (this.data.textAlignment !== null) {
  12545. style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
  12546. }
  12547. }
  12548. _setRequired(element, isRequired) {
  12549. if (isRequired) {
  12550. element.setAttribute("required", true);
  12551. } else {
  12552. element.removeAttribute("required");
  12553. }
  12554. element.setAttribute("aria-required", isRequired);
  12555. }
  12556. }
  12557. class TextWidgetAnnotationElement extends WidgetAnnotationElement {
  12558. constructor(parameters) {
  12559. const isRenderable = parameters.renderForms || !parameters.data.hasAppearance && !!parameters.data.fieldValue;
  12560. super(parameters, {
  12561. isRenderable
  12562. });
  12563. }
  12564. setPropertyOnSiblings(base, key, value, keyInStorage) {
  12565. const storage = this.annotationStorage;
  12566. for (const element of this._getElementsByName(base.name, base.id)) {
  12567. if (element.domElement) {
  12568. element.domElement[key] = value;
  12569. }
  12570. storage.setValue(element.id, {
  12571. [keyInStorage]: value
  12572. });
  12573. }
  12574. }
  12575. render() {
  12576. const storage = this.annotationStorage;
  12577. const id = this.data.id;
  12578. this.container.classList.add("textWidgetAnnotation");
  12579. let element = null;
  12580. if (this.renderForms) {
  12581. const storedData = storage.getValue(id, {
  12582. value: this.data.fieldValue
  12583. });
  12584. let textContent = storedData.value || "";
  12585. const maxLen = storage.getValue(id, {
  12586. charLimit: this.data.maxLen
  12587. }).charLimit;
  12588. if (maxLen && textContent.length > maxLen) {
  12589. textContent = textContent.slice(0, maxLen);
  12590. }
  12591. let fieldFormattedValues = storedData.formattedValue || this.data.textContent?.join("\n") || null;
  12592. if (fieldFormattedValues && this.data.comb) {
  12593. fieldFormattedValues = fieldFormattedValues.replaceAll(/\s+/g, "");
  12594. }
  12595. const elementData = {
  12596. userValue: textContent,
  12597. formattedValue: fieldFormattedValues,
  12598. lastCommittedValue: null,
  12599. commitKey: 1
  12600. };
  12601. if (this.data.multiLine) {
  12602. element = document.createElement("textarea");
  12603. element.textContent = fieldFormattedValues ?? textContent;
  12604. if (this.data.doNotScroll) {
  12605. element.style.overflowY = "hidden";
  12606. }
  12607. } else {
  12608. element = document.createElement("input");
  12609. element.type = "text";
  12610. element.setAttribute("value", fieldFormattedValues ?? textContent);
  12611. if (this.data.doNotScroll) {
  12612. element.style.overflowX = "hidden";
  12613. }
  12614. }
  12615. if (this.data.hasOwnCanvas) {
  12616. element.hidden = true;
  12617. }
  12618. GetElementsByNameSet.add(element);
  12619. element.setAttribute("data-element-id", id);
  12620. element.disabled = this.data.readOnly;
  12621. element.name = this.data.fieldName;
  12622. element.tabIndex = DEFAULT_TAB_INDEX;
  12623. this._setRequired(element, this.data.required);
  12624. if (maxLen) {
  12625. element.maxLength = maxLen;
  12626. }
  12627. element.addEventListener("input", event => {
  12628. storage.setValue(id, {
  12629. value: event.target.value
  12630. });
  12631. this.setPropertyOnSiblings(element, "value", event.target.value, "value");
  12632. elementData.formattedValue = null;
  12633. });
  12634. element.addEventListener("resetform", event => {
  12635. const defaultValue = this.data.defaultFieldValue ?? "";
  12636. element.value = elementData.userValue = defaultValue;
  12637. elementData.formattedValue = null;
  12638. });
  12639. let blurListener = event => {
  12640. const {
  12641. formattedValue
  12642. } = elementData;
  12643. if (formattedValue !== null && formattedValue !== undefined) {
  12644. event.target.value = formattedValue;
  12645. }
  12646. event.target.scrollLeft = 0;
  12647. };
  12648. if (this.enableScripting && this.hasJSActions) {
  12649. element.addEventListener("focus", event => {
  12650. const {
  12651. target
  12652. } = event;
  12653. if (elementData.userValue) {
  12654. target.value = elementData.userValue;
  12655. }
  12656. elementData.lastCommittedValue = target.value;
  12657. elementData.commitKey = 1;
  12658. });
  12659. element.addEventListener("updatefromsandbox", jsEvent => {
  12660. this.showElementAndHideCanvas(jsEvent.target);
  12661. const actions = {
  12662. value(event) {
  12663. elementData.userValue = event.detail.value ?? "";
  12664. storage.setValue(id, {
  12665. value: elementData.userValue.toString()
  12666. });
  12667. event.target.value = elementData.userValue;
  12668. },
  12669. formattedValue(event) {
  12670. const {
  12671. formattedValue
  12672. } = event.detail;
  12673. elementData.formattedValue = formattedValue;
  12674. if (formattedValue !== null && formattedValue !== undefined && event.target !== document.activeElement) {
  12675. event.target.value = formattedValue;
  12676. }
  12677. storage.setValue(id, {
  12678. formattedValue
  12679. });
  12680. },
  12681. selRange(event) {
  12682. event.target.setSelectionRange(...event.detail.selRange);
  12683. },
  12684. charLimit: event => {
  12685. const {
  12686. charLimit
  12687. } = event.detail;
  12688. const {
  12689. target
  12690. } = event;
  12691. if (charLimit === 0) {
  12692. target.removeAttribute("maxLength");
  12693. return;
  12694. }
  12695. target.setAttribute("maxLength", charLimit);
  12696. let value = elementData.userValue;
  12697. if (!value || value.length <= charLimit) {
  12698. return;
  12699. }
  12700. value = value.slice(0, charLimit);
  12701. target.value = elementData.userValue = value;
  12702. storage.setValue(id, {
  12703. value
  12704. });
  12705. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  12706. source: this,
  12707. detail: {
  12708. id,
  12709. name: "Keystroke",
  12710. value,
  12711. willCommit: true,
  12712. commitKey: 1,
  12713. selStart: target.selectionStart,
  12714. selEnd: target.selectionEnd
  12715. }
  12716. });
  12717. }
  12718. };
  12719. this._dispatchEventFromSandbox(actions, jsEvent);
  12720. });
  12721. element.addEventListener("keydown", event => {
  12722. elementData.commitKey = 1;
  12723. let commitKey = -1;
  12724. if (event.key === "Escape") {
  12725. commitKey = 0;
  12726. } else if (event.key === "Enter" && !this.data.multiLine) {
  12727. commitKey = 2;
  12728. } else if (event.key === "Tab") {
  12729. elementData.commitKey = 3;
  12730. }
  12731. if (commitKey === -1) {
  12732. return;
  12733. }
  12734. const {
  12735. value
  12736. } = event.target;
  12737. if (elementData.lastCommittedValue === value) {
  12738. return;
  12739. }
  12740. elementData.lastCommittedValue = value;
  12741. elementData.userValue = value;
  12742. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  12743. source: this,
  12744. detail: {
  12745. id,
  12746. name: "Keystroke",
  12747. value,
  12748. willCommit: true,
  12749. commitKey,
  12750. selStart: event.target.selectionStart,
  12751. selEnd: event.target.selectionEnd
  12752. }
  12753. });
  12754. });
  12755. const _blurListener = blurListener;
  12756. blurListener = null;
  12757. element.addEventListener("blur", event => {
  12758. if (!event.relatedTarget) {
  12759. return;
  12760. }
  12761. const {
  12762. value
  12763. } = event.target;
  12764. elementData.userValue = value;
  12765. if (elementData.lastCommittedValue !== value) {
  12766. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  12767. source: this,
  12768. detail: {
  12769. id,
  12770. name: "Keystroke",
  12771. value,
  12772. willCommit: true,
  12773. commitKey: elementData.commitKey,
  12774. selStart: event.target.selectionStart,
  12775. selEnd: event.target.selectionEnd
  12776. }
  12777. });
  12778. }
  12779. _blurListener(event);
  12780. });
  12781. if (this.data.actions?.Keystroke) {
  12782. element.addEventListener("beforeinput", event => {
  12783. elementData.lastCommittedValue = null;
  12784. const {
  12785. data,
  12786. target
  12787. } = event;
  12788. const {
  12789. value,
  12790. selectionStart,
  12791. selectionEnd
  12792. } = target;
  12793. let selStart = selectionStart,
  12794. selEnd = selectionEnd;
  12795. switch (event.inputType) {
  12796. case "deleteWordBackward":
  12797. {
  12798. const match = value.substring(0, selectionStart).match(/\w*[^\w]*$/);
  12799. if (match) {
  12800. selStart -= match[0].length;
  12801. }
  12802. break;
  12803. }
  12804. case "deleteWordForward":
  12805. {
  12806. const match = value.substring(selectionStart).match(/^[^\w]*\w*/);
  12807. if (match) {
  12808. selEnd += match[0].length;
  12809. }
  12810. break;
  12811. }
  12812. case "deleteContentBackward":
  12813. if (selectionStart === selectionEnd) {
  12814. selStart -= 1;
  12815. }
  12816. break;
  12817. case "deleteContentForward":
  12818. if (selectionStart === selectionEnd) {
  12819. selEnd += 1;
  12820. }
  12821. break;
  12822. }
  12823. event.preventDefault();
  12824. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  12825. source: this,
  12826. detail: {
  12827. id,
  12828. name: "Keystroke",
  12829. value,
  12830. change: data || "",
  12831. willCommit: false,
  12832. selStart,
  12833. selEnd
  12834. }
  12835. });
  12836. });
  12837. }
  12838. this._setEventListeners(element, [["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"]], event => event.target.value);
  12839. }
  12840. if (blurListener) {
  12841. element.addEventListener("blur", blurListener);
  12842. }
  12843. if (this.data.comb) {
  12844. const fieldWidth = this.data.rect[2] - this.data.rect[0];
  12845. const combWidth = fieldWidth / maxLen;
  12846. element.classList.add("comb");
  12847. element.style.letterSpacing = `calc(${combWidth}px * var(--scale-factor) - 1ch)`;
  12848. }
  12849. } else {
  12850. element = document.createElement("div");
  12851. element.textContent = this.data.fieldValue;
  12852. element.style.verticalAlign = "middle";
  12853. element.style.display = "table-cell";
  12854. }
  12855. this._setTextStyle(element);
  12856. this._setBackgroundColor(element);
  12857. this._setDefaultPropertiesFromJS(element);
  12858. this.container.append(element);
  12859. return this.container;
  12860. }
  12861. }
  12862. class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement {
  12863. constructor(parameters) {
  12864. super(parameters, {
  12865. isRenderable: parameters.renderForms
  12866. });
  12867. }
  12868. render() {
  12869. const storage = this.annotationStorage;
  12870. const data = this.data;
  12871. const id = data.id;
  12872. let value = storage.getValue(id, {
  12873. value: data.exportValue === data.fieldValue
  12874. }).value;
  12875. if (typeof value === "string") {
  12876. value = value !== "Off";
  12877. storage.setValue(id, {
  12878. value
  12879. });
  12880. }
  12881. this.container.classList.add("buttonWidgetAnnotation", "checkBox");
  12882. const element = document.createElement("input");
  12883. GetElementsByNameSet.add(element);
  12884. element.setAttribute("data-element-id", id);
  12885. element.disabled = data.readOnly;
  12886. this._setRequired(element, this.data.required);
  12887. element.type = "checkbox";
  12888. element.name = data.fieldName;
  12889. if (value) {
  12890. element.setAttribute("checked", true);
  12891. }
  12892. element.setAttribute("exportValue", data.exportValue);
  12893. element.tabIndex = DEFAULT_TAB_INDEX;
  12894. element.addEventListener("change", event => {
  12895. const {
  12896. name,
  12897. checked
  12898. } = event.target;
  12899. for (const checkbox of this._getElementsByName(name, id)) {
  12900. const curChecked = checked && checkbox.exportValue === data.exportValue;
  12901. if (checkbox.domElement) {
  12902. checkbox.domElement.checked = curChecked;
  12903. }
  12904. storage.setValue(checkbox.id, {
  12905. value: curChecked
  12906. });
  12907. }
  12908. storage.setValue(id, {
  12909. value: checked
  12910. });
  12911. });
  12912. element.addEventListener("resetform", event => {
  12913. const defaultValue = data.defaultFieldValue || "Off";
  12914. event.target.checked = defaultValue === data.exportValue;
  12915. });
  12916. if (this.enableScripting && this.hasJSActions) {
  12917. element.addEventListener("updatefromsandbox", jsEvent => {
  12918. const actions = {
  12919. value(event) {
  12920. event.target.checked = event.detail.value !== "Off";
  12921. storage.setValue(id, {
  12922. value: event.target.checked
  12923. });
  12924. }
  12925. };
  12926. this._dispatchEventFromSandbox(actions, jsEvent);
  12927. });
  12928. 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);
  12929. }
  12930. this._setBackgroundColor(element);
  12931. this._setDefaultPropertiesFromJS(element);
  12932. this.container.append(element);
  12933. return this.container;
  12934. }
  12935. }
  12936. class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
  12937. constructor(parameters) {
  12938. super(parameters, {
  12939. isRenderable: parameters.renderForms
  12940. });
  12941. }
  12942. render() {
  12943. this.container.classList.add("buttonWidgetAnnotation", "radioButton");
  12944. const storage = this.annotationStorage;
  12945. const data = this.data;
  12946. const id = data.id;
  12947. let value = storage.getValue(id, {
  12948. value: data.fieldValue === data.buttonValue
  12949. }).value;
  12950. if (typeof value === "string") {
  12951. value = value !== data.buttonValue;
  12952. storage.setValue(id, {
  12953. value
  12954. });
  12955. }
  12956. const element = document.createElement("input");
  12957. GetElementsByNameSet.add(element);
  12958. element.setAttribute("data-element-id", id);
  12959. element.disabled = data.readOnly;
  12960. this._setRequired(element, this.data.required);
  12961. element.type = "radio";
  12962. element.name = data.fieldName;
  12963. if (value) {
  12964. element.setAttribute("checked", true);
  12965. }
  12966. element.tabIndex = DEFAULT_TAB_INDEX;
  12967. element.addEventListener("change", event => {
  12968. const {
  12969. name,
  12970. checked
  12971. } = event.target;
  12972. for (const radio of this._getElementsByName(name, id)) {
  12973. storage.setValue(radio.id, {
  12974. value: false
  12975. });
  12976. }
  12977. storage.setValue(id, {
  12978. value: checked
  12979. });
  12980. });
  12981. element.addEventListener("resetform", event => {
  12982. const defaultValue = data.defaultFieldValue;
  12983. event.target.checked = defaultValue !== null && defaultValue !== undefined && defaultValue === data.buttonValue;
  12984. });
  12985. if (this.enableScripting && this.hasJSActions) {
  12986. const pdfButtonValue = data.buttonValue;
  12987. element.addEventListener("updatefromsandbox", jsEvent => {
  12988. const actions = {
  12989. value: event => {
  12990. const checked = pdfButtonValue === event.detail.value;
  12991. for (const radio of this._getElementsByName(event.target.name)) {
  12992. const curChecked = checked && radio.id === id;
  12993. if (radio.domElement) {
  12994. radio.domElement.checked = curChecked;
  12995. }
  12996. storage.setValue(radio.id, {
  12997. value: curChecked
  12998. });
  12999. }
  13000. }
  13001. };
  13002. this._dispatchEventFromSandbox(actions, jsEvent);
  13003. });
  13004. 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);
  13005. }
  13006. this._setBackgroundColor(element);
  13007. this._setDefaultPropertiesFromJS(element);
  13008. this.container.append(element);
  13009. return this.container;
  13010. }
  13011. }
  13012. class PushButtonWidgetAnnotationElement extends LinkAnnotationElement {
  13013. constructor(parameters) {
  13014. super(parameters, {
  13015. ignoreBorder: parameters.data.hasAppearance
  13016. });
  13017. }
  13018. render() {
  13019. const container = super.render();
  13020. container.classList.add("buttonWidgetAnnotation", "pushButton");
  13021. if (this.data.alternativeText) {
  13022. container.title = this.data.alternativeText;
  13023. }
  13024. const linkElement = container.lastChild;
  13025. if (this.enableScripting && this.hasJSActions && linkElement) {
  13026. this._setDefaultPropertiesFromJS(linkElement);
  13027. linkElement.addEventListener("updatefromsandbox", jsEvent => {
  13028. this._dispatchEventFromSandbox({}, jsEvent);
  13029. });
  13030. }
  13031. return container;
  13032. }
  13033. }
  13034. class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
  13035. constructor(parameters) {
  13036. super(parameters, {
  13037. isRenderable: parameters.renderForms
  13038. });
  13039. }
  13040. render() {
  13041. this.container.classList.add("choiceWidgetAnnotation");
  13042. const storage = this.annotationStorage;
  13043. const id = this.data.id;
  13044. const storedData = storage.getValue(id, {
  13045. value: this.data.fieldValue
  13046. });
  13047. const selectElement = document.createElement("select");
  13048. GetElementsByNameSet.add(selectElement);
  13049. selectElement.setAttribute("data-element-id", id);
  13050. selectElement.disabled = this.data.readOnly;
  13051. this._setRequired(selectElement, this.data.required);
  13052. selectElement.name = this.data.fieldName;
  13053. selectElement.tabIndex = DEFAULT_TAB_INDEX;
  13054. let addAnEmptyEntry = this.data.combo && this.data.options.length > 0;
  13055. if (!this.data.combo) {
  13056. selectElement.size = this.data.options.length;
  13057. if (this.data.multiSelect) {
  13058. selectElement.multiple = true;
  13059. }
  13060. }
  13061. selectElement.addEventListener("resetform", event => {
  13062. const defaultValue = this.data.defaultFieldValue;
  13063. for (const option of selectElement.options) {
  13064. option.selected = option.value === defaultValue;
  13065. }
  13066. });
  13067. for (const option of this.data.options) {
  13068. const optionElement = document.createElement("option");
  13069. optionElement.textContent = option.displayValue;
  13070. optionElement.value = option.exportValue;
  13071. if (storedData.value.includes(option.exportValue)) {
  13072. optionElement.setAttribute("selected", true);
  13073. addAnEmptyEntry = false;
  13074. }
  13075. selectElement.append(optionElement);
  13076. }
  13077. let removeEmptyEntry = null;
  13078. if (addAnEmptyEntry) {
  13079. const noneOptionElement = document.createElement("option");
  13080. noneOptionElement.value = " ";
  13081. noneOptionElement.setAttribute("hidden", true);
  13082. noneOptionElement.setAttribute("selected", true);
  13083. selectElement.prepend(noneOptionElement);
  13084. removeEmptyEntry = () => {
  13085. noneOptionElement.remove();
  13086. selectElement.removeEventListener("input", removeEmptyEntry);
  13087. removeEmptyEntry = null;
  13088. };
  13089. selectElement.addEventListener("input", removeEmptyEntry);
  13090. }
  13091. const getValue = isExport => {
  13092. const name = isExport ? "value" : "textContent";
  13093. const {
  13094. options,
  13095. multiple
  13096. } = selectElement;
  13097. if (!multiple) {
  13098. return options.selectedIndex === -1 ? null : options[options.selectedIndex][name];
  13099. }
  13100. return Array.prototype.filter.call(options, option => option.selected).map(option => option[name]);
  13101. };
  13102. let selectedValues = getValue(false);
  13103. const getItems = event => {
  13104. const options = event.target.options;
  13105. return Array.prototype.map.call(options, option => {
  13106. return {
  13107. displayValue: option.textContent,
  13108. exportValue: option.value
  13109. };
  13110. });
  13111. };
  13112. if (this.enableScripting && this.hasJSActions) {
  13113. selectElement.addEventListener("updatefromsandbox", jsEvent => {
  13114. const actions = {
  13115. value(event) {
  13116. removeEmptyEntry?.();
  13117. const value = event.detail.value;
  13118. const values = new Set(Array.isArray(value) ? value : [value]);
  13119. for (const option of selectElement.options) {
  13120. option.selected = values.has(option.value);
  13121. }
  13122. storage.setValue(id, {
  13123. value: getValue(true)
  13124. });
  13125. selectedValues = getValue(false);
  13126. },
  13127. multipleSelection(event) {
  13128. selectElement.multiple = true;
  13129. },
  13130. remove(event) {
  13131. const options = selectElement.options;
  13132. const index = event.detail.remove;
  13133. options[index].selected = false;
  13134. selectElement.remove(index);
  13135. if (options.length > 0) {
  13136. const i = Array.prototype.findIndex.call(options, option => option.selected);
  13137. if (i === -1) {
  13138. options[0].selected = true;
  13139. }
  13140. }
  13141. storage.setValue(id, {
  13142. value: getValue(true),
  13143. items: getItems(event)
  13144. });
  13145. selectedValues = getValue(false);
  13146. },
  13147. clear(event) {
  13148. while (selectElement.length !== 0) {
  13149. selectElement.remove(0);
  13150. }
  13151. storage.setValue(id, {
  13152. value: null,
  13153. items: []
  13154. });
  13155. selectedValues = getValue(false);
  13156. },
  13157. insert(event) {
  13158. const {
  13159. index,
  13160. displayValue,
  13161. exportValue
  13162. } = event.detail.insert;
  13163. const selectChild = selectElement.children[index];
  13164. const optionElement = document.createElement("option");
  13165. optionElement.textContent = displayValue;
  13166. optionElement.value = exportValue;
  13167. if (selectChild) {
  13168. selectChild.before(optionElement);
  13169. } else {
  13170. selectElement.append(optionElement);
  13171. }
  13172. storage.setValue(id, {
  13173. value: getValue(true),
  13174. items: getItems(event)
  13175. });
  13176. selectedValues = getValue(false);
  13177. },
  13178. items(event) {
  13179. const {
  13180. items
  13181. } = event.detail;
  13182. while (selectElement.length !== 0) {
  13183. selectElement.remove(0);
  13184. }
  13185. for (const item of items) {
  13186. const {
  13187. displayValue,
  13188. exportValue
  13189. } = item;
  13190. const optionElement = document.createElement("option");
  13191. optionElement.textContent = displayValue;
  13192. optionElement.value = exportValue;
  13193. selectElement.append(optionElement);
  13194. }
  13195. if (selectElement.options.length > 0) {
  13196. selectElement.options[0].selected = true;
  13197. }
  13198. storage.setValue(id, {
  13199. value: getValue(true),
  13200. items: getItems(event)
  13201. });
  13202. selectedValues = getValue(false);
  13203. },
  13204. indices(event) {
  13205. const indices = new Set(event.detail.indices);
  13206. for (const option of event.target.options) {
  13207. option.selected = indices.has(option.index);
  13208. }
  13209. storage.setValue(id, {
  13210. value: getValue(true)
  13211. });
  13212. selectedValues = getValue(false);
  13213. },
  13214. editable(event) {
  13215. event.target.disabled = !event.detail.editable;
  13216. }
  13217. };
  13218. this._dispatchEventFromSandbox(actions, jsEvent);
  13219. });
  13220. selectElement.addEventListener("input", event => {
  13221. const exportValue = getValue(true);
  13222. storage.setValue(id, {
  13223. value: exportValue
  13224. });
  13225. event.preventDefault();
  13226. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  13227. source: this,
  13228. detail: {
  13229. id,
  13230. name: "Keystroke",
  13231. value: selectedValues,
  13232. changeEx: exportValue,
  13233. willCommit: false,
  13234. commitKey: 1,
  13235. keyDown: false
  13236. }
  13237. });
  13238. });
  13239. this._setEventListeners(selectElement, [["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"], ["input", "Action"], ["input", "Validate"]], event => event.target.value);
  13240. } else {
  13241. selectElement.addEventListener("input", function (event) {
  13242. storage.setValue(id, {
  13243. value: getValue(true)
  13244. });
  13245. });
  13246. }
  13247. if (this.data.combo) {
  13248. this._setTextStyle(selectElement);
  13249. } else {}
  13250. this._setBackgroundColor(selectElement);
  13251. this._setDefaultPropertiesFromJS(selectElement);
  13252. this.container.append(selectElement);
  13253. return this.container;
  13254. }
  13255. }
  13256. class PopupAnnotationElement extends AnnotationElement {
  13257. static IGNORE_TYPES = new Set(["Line", "Square", "Circle", "PolyLine", "Polygon", "Ink"]);
  13258. constructor(parameters) {
  13259. const {
  13260. data
  13261. } = parameters;
  13262. const isRenderable = !PopupAnnotationElement.IGNORE_TYPES.has(data.parentType) && !!(data.titleObj?.str || data.contentsObj?.str || data.richText?.str);
  13263. super(parameters, {
  13264. isRenderable
  13265. });
  13266. }
  13267. render() {
  13268. this.container.classList.add("popupAnnotation");
  13269. const parentElements = this.layer.querySelectorAll(`[data-annotation-id="${this.data.parentId}"]`);
  13270. if (parentElements.length === 0) {
  13271. return this.container;
  13272. }
  13273. const popup = new PopupElement({
  13274. container: this.container,
  13275. trigger: Array.from(parentElements),
  13276. color: this.data.color,
  13277. titleObj: this.data.titleObj,
  13278. modificationDate: this.data.modificationDate,
  13279. contentsObj: this.data.contentsObj,
  13280. richText: this.data.richText
  13281. });
  13282. const page = this.page;
  13283. 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]]);
  13284. const popupLeft = rect[0] + this.data.parentRect[2] - this.data.parentRect[0];
  13285. const popupTop = rect[1];
  13286. const {
  13287. pageWidth,
  13288. pageHeight,
  13289. pageX,
  13290. pageY
  13291. } = this.viewport.rawDims;
  13292. this.container.style.left = `${100 * (popupLeft - pageX) / pageWidth}%`;
  13293. this.container.style.top = `${100 * (popupTop - pageY) / pageHeight}%`;
  13294. this.container.append(popup.render());
  13295. return this.container;
  13296. }
  13297. }
  13298. class PopupElement {
  13299. constructor(parameters) {
  13300. this.container = parameters.container;
  13301. this.trigger = parameters.trigger;
  13302. this.color = parameters.color;
  13303. this.titleObj = parameters.titleObj;
  13304. this.modificationDate = parameters.modificationDate;
  13305. this.contentsObj = parameters.contentsObj;
  13306. this.richText = parameters.richText;
  13307. this.hideWrapper = parameters.hideWrapper || false;
  13308. this.pinned = false;
  13309. }
  13310. render() {
  13311. const BACKGROUND_ENLIGHT = 0.7;
  13312. const wrapper = document.createElement("div");
  13313. wrapper.classList.add("popupWrapper");
  13314. this.hideElement = this.hideWrapper ? wrapper : this.container;
  13315. this.hideElement.hidden = true;
  13316. const popup = document.createElement("div");
  13317. popup.classList.add("popup");
  13318. const color = this.color;
  13319. if (color) {
  13320. const r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  13321. const g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  13322. const b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  13323. popup.style.backgroundColor = _util.Util.makeHexColor(r | 0, g | 0, b | 0);
  13324. }
  13325. const title = document.createElement("h1");
  13326. title.dir = this.titleObj.dir;
  13327. title.textContent = this.titleObj.str;
  13328. popup.append(title);
  13329. const dateObject = _display_utils.PDFDateString.toDateObject(this.modificationDate);
  13330. if (dateObject) {
  13331. const modificationDate = document.createElement("span");
  13332. modificationDate.classList.add("popupDate");
  13333. modificationDate.textContent = "{{date}}, {{time}}";
  13334. modificationDate.dataset.l10nId = "annotation_date_string";
  13335. modificationDate.dataset.l10nArgs = JSON.stringify({
  13336. date: dateObject.toLocaleDateString(),
  13337. time: dateObject.toLocaleTimeString()
  13338. });
  13339. popup.append(modificationDate);
  13340. }
  13341. if (this.richText?.str && (!this.contentsObj?.str || this.contentsObj.str === this.richText.str)) {
  13342. _xfa_layer.XfaLayer.render({
  13343. xfaHtml: this.richText.html,
  13344. intent: "richText",
  13345. div: popup
  13346. });
  13347. popup.lastChild.classList.add("richText", "popupContent");
  13348. } else {
  13349. const contents = this._formatContents(this.contentsObj);
  13350. popup.append(contents);
  13351. }
  13352. if (!Array.isArray(this.trigger)) {
  13353. this.trigger = [this.trigger];
  13354. }
  13355. for (const element of this.trigger) {
  13356. element.addEventListener("click", this._toggle.bind(this));
  13357. element.addEventListener("mouseover", this._show.bind(this, false));
  13358. element.addEventListener("mouseout", this._hide.bind(this, false));
  13359. }
  13360. popup.addEventListener("click", this._hide.bind(this, true));
  13361. wrapper.append(popup);
  13362. return wrapper;
  13363. }
  13364. _formatContents({
  13365. str,
  13366. dir
  13367. }) {
  13368. const p = document.createElement("p");
  13369. p.classList.add("popupContent");
  13370. p.dir = dir;
  13371. const lines = str.split(/(?:\r\n?|\n)/);
  13372. for (let i = 0, ii = lines.length; i < ii; ++i) {
  13373. const line = lines[i];
  13374. p.append(document.createTextNode(line));
  13375. if (i < ii - 1) {
  13376. p.append(document.createElement("br"));
  13377. }
  13378. }
  13379. return p;
  13380. }
  13381. _toggle() {
  13382. if (this.pinned) {
  13383. this._hide(true);
  13384. } else {
  13385. this._show(true);
  13386. }
  13387. }
  13388. _show(pin = false) {
  13389. if (pin) {
  13390. this.pinned = true;
  13391. }
  13392. if (this.hideElement.hidden) {
  13393. this.hideElement.hidden = false;
  13394. this.container.style.zIndex = parseInt(this.container.style.zIndex) + 1000;
  13395. }
  13396. }
  13397. _hide(unpin = true) {
  13398. if (unpin) {
  13399. this.pinned = false;
  13400. }
  13401. if (!this.hideElement.hidden && !this.pinned) {
  13402. this.hideElement.hidden = true;
  13403. this.container.style.zIndex = parseInt(this.container.style.zIndex) - 1000;
  13404. }
  13405. }
  13406. }
  13407. class FreeTextAnnotationElement extends AnnotationElement {
  13408. constructor(parameters) {
  13409. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  13410. super(parameters, {
  13411. isRenderable,
  13412. ignoreBorder: true
  13413. });
  13414. this.textContent = parameters.data.textContent;
  13415. }
  13416. render() {
  13417. this.container.classList.add("freeTextAnnotation");
  13418. if (this.textContent) {
  13419. const content = document.createElement("div");
  13420. content.classList.add("annotationTextContent");
  13421. content.setAttribute("role", "comment");
  13422. for (const line of this.textContent) {
  13423. const lineSpan = document.createElement("span");
  13424. lineSpan.textContent = line;
  13425. content.append(lineSpan);
  13426. }
  13427. this.container.append(content);
  13428. }
  13429. if (!this.data.hasPopup) {
  13430. this._createPopup(null, this.data);
  13431. }
  13432. return this.container;
  13433. }
  13434. }
  13435. class LineAnnotationElement extends AnnotationElement {
  13436. constructor(parameters) {
  13437. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  13438. super(parameters, {
  13439. isRenderable,
  13440. ignoreBorder: true
  13441. });
  13442. }
  13443. render() {
  13444. this.container.classList.add("lineAnnotation");
  13445. const data = this.data;
  13446. const {
  13447. width,
  13448. height
  13449. } = getRectDims(data.rect);
  13450. const svg = this.svgFactory.create(width, height, true);
  13451. const line = this.svgFactory.createElement("svg:line");
  13452. line.setAttribute("x1", data.rect[2] - data.lineCoordinates[0]);
  13453. line.setAttribute("y1", data.rect[3] - data.lineCoordinates[1]);
  13454. line.setAttribute("x2", data.rect[2] - data.lineCoordinates[2]);
  13455. line.setAttribute("y2", data.rect[3] - data.lineCoordinates[3]);
  13456. line.setAttribute("stroke-width", data.borderStyle.width || 1);
  13457. line.setAttribute("stroke", "transparent");
  13458. line.setAttribute("fill", "transparent");
  13459. svg.append(line);
  13460. this.container.append(svg);
  13461. this._createPopup(line, data);
  13462. return this.container;
  13463. }
  13464. }
  13465. class SquareAnnotationElement extends AnnotationElement {
  13466. constructor(parameters) {
  13467. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  13468. super(parameters, {
  13469. isRenderable,
  13470. ignoreBorder: true
  13471. });
  13472. }
  13473. render() {
  13474. this.container.classList.add("squareAnnotation");
  13475. const data = this.data;
  13476. const {
  13477. width,
  13478. height
  13479. } = getRectDims(data.rect);
  13480. const svg = this.svgFactory.create(width, height, true);
  13481. const borderWidth = data.borderStyle.width;
  13482. const square = this.svgFactory.createElement("svg:rect");
  13483. square.setAttribute("x", borderWidth / 2);
  13484. square.setAttribute("y", borderWidth / 2);
  13485. square.setAttribute("width", width - borderWidth);
  13486. square.setAttribute("height", height - borderWidth);
  13487. square.setAttribute("stroke-width", borderWidth || 1);
  13488. square.setAttribute("stroke", "transparent");
  13489. square.setAttribute("fill", "transparent");
  13490. svg.append(square);
  13491. this.container.append(svg);
  13492. this._createPopup(square, data);
  13493. return this.container;
  13494. }
  13495. }
  13496. class CircleAnnotationElement extends AnnotationElement {
  13497. constructor(parameters) {
  13498. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  13499. super(parameters, {
  13500. isRenderable,
  13501. ignoreBorder: true
  13502. });
  13503. }
  13504. render() {
  13505. this.container.classList.add("circleAnnotation");
  13506. const data = this.data;
  13507. const {
  13508. width,
  13509. height
  13510. } = getRectDims(data.rect);
  13511. const svg = this.svgFactory.create(width, height, true);
  13512. const borderWidth = data.borderStyle.width;
  13513. const circle = this.svgFactory.createElement("svg:ellipse");
  13514. circle.setAttribute("cx", width / 2);
  13515. circle.setAttribute("cy", height / 2);
  13516. circle.setAttribute("rx", width / 2 - borderWidth / 2);
  13517. circle.setAttribute("ry", height / 2 - borderWidth / 2);
  13518. circle.setAttribute("stroke-width", borderWidth || 1);
  13519. circle.setAttribute("stroke", "transparent");
  13520. circle.setAttribute("fill", "transparent");
  13521. svg.append(circle);
  13522. this.container.append(svg);
  13523. this._createPopup(circle, data);
  13524. return this.container;
  13525. }
  13526. }
  13527. class PolylineAnnotationElement extends AnnotationElement {
  13528. constructor(parameters) {
  13529. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  13530. super(parameters, {
  13531. isRenderable,
  13532. ignoreBorder: true
  13533. });
  13534. this.containerClassName = "polylineAnnotation";
  13535. this.svgElementName = "svg:polyline";
  13536. }
  13537. render() {
  13538. this.container.classList.add(this.containerClassName);
  13539. const data = this.data;
  13540. const {
  13541. width,
  13542. height
  13543. } = getRectDims(data.rect);
  13544. const svg = this.svgFactory.create(width, height, true);
  13545. let points = [];
  13546. for (const coordinate of data.vertices) {
  13547. const x = coordinate.x - data.rect[0];
  13548. const y = data.rect[3] - coordinate.y;
  13549. points.push(x + "," + y);
  13550. }
  13551. points = points.join(" ");
  13552. const polyline = this.svgFactory.createElement(this.svgElementName);
  13553. polyline.setAttribute("points", points);
  13554. polyline.setAttribute("stroke-width", data.borderStyle.width || 1);
  13555. polyline.setAttribute("stroke", "transparent");
  13556. polyline.setAttribute("fill", "transparent");
  13557. svg.append(polyline);
  13558. this.container.append(svg);
  13559. this._createPopup(polyline, data);
  13560. return this.container;
  13561. }
  13562. }
  13563. class PolygonAnnotationElement extends PolylineAnnotationElement {
  13564. constructor(parameters) {
  13565. super(parameters);
  13566. this.containerClassName = "polygonAnnotation";
  13567. this.svgElementName = "svg:polygon";
  13568. }
  13569. }
  13570. class CaretAnnotationElement extends AnnotationElement {
  13571. constructor(parameters) {
  13572. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  13573. super(parameters, {
  13574. isRenderable,
  13575. ignoreBorder: true
  13576. });
  13577. }
  13578. render() {
  13579. this.container.classList.add("caretAnnotation");
  13580. if (!this.data.hasPopup) {
  13581. this._createPopup(null, this.data);
  13582. }
  13583. return this.container;
  13584. }
  13585. }
  13586. class InkAnnotationElement extends AnnotationElement {
  13587. constructor(parameters) {
  13588. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  13589. super(parameters, {
  13590. isRenderable,
  13591. ignoreBorder: true
  13592. });
  13593. this.containerClassName = "inkAnnotation";
  13594. this.svgElementName = "svg:polyline";
  13595. }
  13596. render() {
  13597. this.container.classList.add(this.containerClassName);
  13598. const data = this.data;
  13599. const {
  13600. width,
  13601. height
  13602. } = getRectDims(data.rect);
  13603. const svg = this.svgFactory.create(width, height, true);
  13604. for (const inkList of data.inkLists) {
  13605. let points = [];
  13606. for (const coordinate of inkList) {
  13607. const x = coordinate.x - data.rect[0];
  13608. const y = data.rect[3] - coordinate.y;
  13609. points.push(`${x},${y}`);
  13610. }
  13611. points = points.join(" ");
  13612. const polyline = this.svgFactory.createElement(this.svgElementName);
  13613. polyline.setAttribute("points", points);
  13614. polyline.setAttribute("stroke-width", data.borderStyle.width || 1);
  13615. polyline.setAttribute("stroke", "transparent");
  13616. polyline.setAttribute("fill", "transparent");
  13617. this._createPopup(polyline, data);
  13618. svg.append(polyline);
  13619. }
  13620. this.container.append(svg);
  13621. return this.container;
  13622. }
  13623. }
  13624. class HighlightAnnotationElement extends AnnotationElement {
  13625. constructor(parameters) {
  13626. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  13627. super(parameters, {
  13628. isRenderable,
  13629. ignoreBorder: true,
  13630. createQuadrilaterals: true
  13631. });
  13632. }
  13633. render() {
  13634. if (!this.data.hasPopup) {
  13635. this._createPopup(null, this.data);
  13636. }
  13637. if (this.quadrilaterals) {
  13638. return this._renderQuadrilaterals("highlightAnnotation");
  13639. }
  13640. this.container.classList.add("highlightAnnotation");
  13641. return this.container;
  13642. }
  13643. }
  13644. class UnderlineAnnotationElement extends AnnotationElement {
  13645. constructor(parameters) {
  13646. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  13647. super(parameters, {
  13648. isRenderable,
  13649. ignoreBorder: true,
  13650. createQuadrilaterals: true
  13651. });
  13652. }
  13653. render() {
  13654. if (!this.data.hasPopup) {
  13655. this._createPopup(null, this.data);
  13656. }
  13657. if (this.quadrilaterals) {
  13658. return this._renderQuadrilaterals("underlineAnnotation");
  13659. }
  13660. this.container.classList.add("underlineAnnotation");
  13661. return this.container;
  13662. }
  13663. }
  13664. class SquigglyAnnotationElement extends AnnotationElement {
  13665. constructor(parameters) {
  13666. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  13667. super(parameters, {
  13668. isRenderable,
  13669. ignoreBorder: true,
  13670. createQuadrilaterals: true
  13671. });
  13672. }
  13673. render() {
  13674. if (!this.data.hasPopup) {
  13675. this._createPopup(null, this.data);
  13676. }
  13677. if (this.quadrilaterals) {
  13678. return this._renderQuadrilaterals("squigglyAnnotation");
  13679. }
  13680. this.container.classList.add("squigglyAnnotation");
  13681. return this.container;
  13682. }
  13683. }
  13684. class StrikeOutAnnotationElement extends AnnotationElement {
  13685. constructor(parameters) {
  13686. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  13687. super(parameters, {
  13688. isRenderable,
  13689. ignoreBorder: true,
  13690. createQuadrilaterals: true
  13691. });
  13692. }
  13693. render() {
  13694. if (!this.data.hasPopup) {
  13695. this._createPopup(null, this.data);
  13696. }
  13697. if (this.quadrilaterals) {
  13698. return this._renderQuadrilaterals("strikeoutAnnotation");
  13699. }
  13700. this.container.classList.add("strikeoutAnnotation");
  13701. return this.container;
  13702. }
  13703. }
  13704. class StampAnnotationElement extends AnnotationElement {
  13705. constructor(parameters) {
  13706. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  13707. super(parameters, {
  13708. isRenderable,
  13709. ignoreBorder: true
  13710. });
  13711. }
  13712. render() {
  13713. this.container.classList.add("stampAnnotation");
  13714. if (!this.data.hasPopup) {
  13715. this._createPopup(null, this.data);
  13716. }
  13717. return this.container;
  13718. }
  13719. }
  13720. class FileAttachmentAnnotationElement extends AnnotationElement {
  13721. constructor(parameters) {
  13722. super(parameters, {
  13723. isRenderable: true
  13724. });
  13725. const {
  13726. filename,
  13727. content
  13728. } = this.data.file;
  13729. this.filename = (0, _display_utils.getFilenameFromUrl)(filename, true);
  13730. this.content = content;
  13731. this.linkService.eventBus?.dispatch("fileattachmentannotation", {
  13732. source: this,
  13733. filename,
  13734. content
  13735. });
  13736. }
  13737. render() {
  13738. this.container.classList.add("fileAttachmentAnnotation");
  13739. let trigger;
  13740. if (this.data.hasAppearance) {
  13741. trigger = document.createElement("div");
  13742. } else {
  13743. trigger = document.createElement("img");
  13744. trigger.src = `${this.imageResourcesPath}annotation-${/paperclip/i.test(this.data.name) ? "paperclip" : "pushpin"}.svg`;
  13745. }
  13746. trigger.classList.add("popupTriggerArea");
  13747. trigger.addEventListener("dblclick", this._download.bind(this));
  13748. if (!this.data.hasPopup && (this.data.titleObj?.str || this.data.contentsObj?.str || this.data.richText)) {
  13749. this._createPopup(trigger, this.data);
  13750. }
  13751. this.container.append(trigger);
  13752. return this.container;
  13753. }
  13754. _download() {
  13755. this.downloadManager?.openOrDownloadData(this.container, this.content, this.filename);
  13756. }
  13757. }
  13758. class AnnotationLayer {
  13759. static #appendElement(element, id, div, accessibilityManager) {
  13760. const contentElement = element.firstChild || element;
  13761. contentElement.id = `${_display_utils.AnnotationPrefix}${id}`;
  13762. div.append(element);
  13763. accessibilityManager?.moveElementInDOM(div, element, contentElement, false);
  13764. }
  13765. static render(params) {
  13766. const {
  13767. annotations,
  13768. div,
  13769. viewport,
  13770. accessibilityManager
  13771. } = params;
  13772. (0, _display_utils.setLayerDimensions)(div, viewport);
  13773. const elementParams = {
  13774. data: null,
  13775. layer: div,
  13776. page: params.page,
  13777. viewport,
  13778. linkService: params.linkService,
  13779. downloadManager: params.downloadManager,
  13780. imageResourcesPath: params.imageResourcesPath || "",
  13781. renderForms: params.renderForms !== false,
  13782. svgFactory: new _display_utils.DOMSVGFactory(),
  13783. annotationStorage: params.annotationStorage || new _annotation_storage.AnnotationStorage(),
  13784. enableScripting: params.enableScripting === true,
  13785. hasJSActions: params.hasJSActions,
  13786. fieldObjects: params.fieldObjects
  13787. };
  13788. let zIndex = 0;
  13789. for (const data of annotations) {
  13790. if (data.noHTML) {
  13791. continue;
  13792. }
  13793. if (data.annotationType !== _util.AnnotationType.POPUP) {
  13794. const {
  13795. width,
  13796. height
  13797. } = getRectDims(data.rect);
  13798. if (width <= 0 || height <= 0) {
  13799. continue;
  13800. }
  13801. }
  13802. elementParams.data = data;
  13803. const element = AnnotationElementFactory.create(elementParams);
  13804. if (!element.isRenderable) {
  13805. continue;
  13806. }
  13807. const rendered = element.render();
  13808. if (data.hidden) {
  13809. rendered.style.visibility = "hidden";
  13810. }
  13811. if (Array.isArray(rendered)) {
  13812. for (const renderedElement of rendered) {
  13813. renderedElement.style.zIndex = zIndex++;
  13814. AnnotationLayer.#appendElement(renderedElement, data.id, div, accessibilityManager);
  13815. }
  13816. } else {
  13817. rendered.style.zIndex = zIndex++;
  13818. if (element instanceof PopupAnnotationElement) {
  13819. div.prepend(rendered);
  13820. } else {
  13821. AnnotationLayer.#appendElement(rendered, data.id, div, accessibilityManager);
  13822. }
  13823. }
  13824. }
  13825. this.#setAnnotationCanvasMap(div, params.annotationCanvasMap);
  13826. }
  13827. static update(params) {
  13828. const {
  13829. annotationCanvasMap,
  13830. div,
  13831. viewport
  13832. } = params;
  13833. (0, _display_utils.setLayerDimensions)(div, {
  13834. rotation: viewport.rotation
  13835. });
  13836. this.#setAnnotationCanvasMap(div, annotationCanvasMap);
  13837. div.hidden = false;
  13838. }
  13839. static #setAnnotationCanvasMap(div, annotationCanvasMap) {
  13840. if (!annotationCanvasMap) {
  13841. return;
  13842. }
  13843. for (const [id, canvas] of annotationCanvasMap) {
  13844. const element = div.querySelector(`[data-annotation-id="${id}"]`);
  13845. if (!element) {
  13846. continue;
  13847. }
  13848. const {
  13849. firstChild
  13850. } = element;
  13851. if (!firstChild) {
  13852. element.append(canvas);
  13853. } else if (firstChild.nodeName === "CANVAS") {
  13854. firstChild.replaceWith(canvas);
  13855. } else {
  13856. firstChild.before(canvas);
  13857. }
  13858. }
  13859. annotationCanvasMap.clear();
  13860. }
  13861. }
  13862. exports.AnnotationLayer = AnnotationLayer;
  13863. /***/ }),
  13864. /* 31 */
  13865. /***/ ((__unused_webpack_module, exports) => {
  13866. Object.defineProperty(exports, "__esModule", ({
  13867. value: true
  13868. }));
  13869. exports.ColorConverters = void 0;
  13870. function makeColorComp(n) {
  13871. return Math.floor(Math.max(0, Math.min(1, n)) * 255).toString(16).padStart(2, "0");
  13872. }
  13873. class ColorConverters {
  13874. static CMYK_G([c, y, m, k]) {
  13875. return ["G", 1 - Math.min(1, 0.3 * c + 0.59 * m + 0.11 * y + k)];
  13876. }
  13877. static G_CMYK([g]) {
  13878. return ["CMYK", 0, 0, 0, 1 - g];
  13879. }
  13880. static G_RGB([g]) {
  13881. return ["RGB", g, g, g];
  13882. }
  13883. static G_HTML([g]) {
  13884. const G = makeColorComp(g);
  13885. return `#${G}${G}${G}`;
  13886. }
  13887. static RGB_G([r, g, b]) {
  13888. return ["G", 0.3 * r + 0.59 * g + 0.11 * b];
  13889. }
  13890. static RGB_HTML([r, g, b]) {
  13891. const R = makeColorComp(r);
  13892. const G = makeColorComp(g);
  13893. const B = makeColorComp(b);
  13894. return `#${R}${G}${B}`;
  13895. }
  13896. static T_HTML() {
  13897. return "#00000000";
  13898. }
  13899. static CMYK_RGB([c, y, m, k]) {
  13900. return ["RGB", 1 - Math.min(1, c + k), 1 - Math.min(1, m + k), 1 - Math.min(1, y + k)];
  13901. }
  13902. static CMYK_HTML(components) {
  13903. const rgb = this.CMYK_RGB(components).slice(1);
  13904. return this.RGB_HTML(rgb);
  13905. }
  13906. static RGB_CMYK([r, g, b]) {
  13907. const c = 1 - r;
  13908. const m = 1 - g;
  13909. const y = 1 - b;
  13910. const k = Math.min(c, m, y);
  13911. return ["CMYK", c, m, y, k];
  13912. }
  13913. }
  13914. exports.ColorConverters = ColorConverters;
  13915. /***/ }),
  13916. /* 32 */
  13917. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  13918. Object.defineProperty(exports, "__esModule", ({
  13919. value: true
  13920. }));
  13921. exports.XfaLayer = void 0;
  13922. var _xfa_text = __w_pdfjs_require__(19);
  13923. class XfaLayer {
  13924. static setupStorage(html, id, element, storage, intent) {
  13925. const storedData = storage.getValue(id, {
  13926. value: null
  13927. });
  13928. switch (element.name) {
  13929. case "textarea":
  13930. if (storedData.value !== null) {
  13931. html.textContent = storedData.value;
  13932. }
  13933. if (intent === "print") {
  13934. break;
  13935. }
  13936. html.addEventListener("input", event => {
  13937. storage.setValue(id, {
  13938. value: event.target.value
  13939. });
  13940. });
  13941. break;
  13942. case "input":
  13943. if (element.attributes.type === "radio" || element.attributes.type === "checkbox") {
  13944. if (storedData.value === element.attributes.xfaOn) {
  13945. html.setAttribute("checked", true);
  13946. } else if (storedData.value === element.attributes.xfaOff) {
  13947. html.removeAttribute("checked");
  13948. }
  13949. if (intent === "print") {
  13950. break;
  13951. }
  13952. html.addEventListener("change", event => {
  13953. storage.setValue(id, {
  13954. value: event.target.checked ? event.target.getAttribute("xfaOn") : event.target.getAttribute("xfaOff")
  13955. });
  13956. });
  13957. } else {
  13958. if (storedData.value !== null) {
  13959. html.setAttribute("value", storedData.value);
  13960. }
  13961. if (intent === "print") {
  13962. break;
  13963. }
  13964. html.addEventListener("input", event => {
  13965. storage.setValue(id, {
  13966. value: event.target.value
  13967. });
  13968. });
  13969. }
  13970. break;
  13971. case "select":
  13972. if (storedData.value !== null) {
  13973. for (const option of element.children) {
  13974. if (option.attributes.value === storedData.value) {
  13975. option.attributes.selected = true;
  13976. }
  13977. }
  13978. }
  13979. html.addEventListener("input", event => {
  13980. const options = event.target.options;
  13981. const value = options.selectedIndex === -1 ? "" : options[options.selectedIndex].value;
  13982. storage.setValue(id, {
  13983. value
  13984. });
  13985. });
  13986. break;
  13987. }
  13988. }
  13989. static setAttributes({
  13990. html,
  13991. element,
  13992. storage = null,
  13993. intent,
  13994. linkService
  13995. }) {
  13996. const {
  13997. attributes
  13998. } = element;
  13999. const isHTMLAnchorElement = html instanceof HTMLAnchorElement;
  14000. if (attributes.type === "radio") {
  14001. attributes.name = `${attributes.name}-${intent}`;
  14002. }
  14003. for (const [key, value] of Object.entries(attributes)) {
  14004. if (value === null || value === undefined) {
  14005. continue;
  14006. }
  14007. switch (key) {
  14008. case "class":
  14009. if (value.length) {
  14010. html.setAttribute(key, value.join(" "));
  14011. }
  14012. break;
  14013. case "dataId":
  14014. break;
  14015. case "id":
  14016. html.setAttribute("data-element-id", value);
  14017. break;
  14018. case "style":
  14019. Object.assign(html.style, value);
  14020. break;
  14021. case "textContent":
  14022. html.textContent = value;
  14023. break;
  14024. default:
  14025. if (!isHTMLAnchorElement || key !== "href" && key !== "newWindow") {
  14026. html.setAttribute(key, value);
  14027. }
  14028. }
  14029. }
  14030. if (isHTMLAnchorElement) {
  14031. linkService.addLinkAttributes(html, attributes.href, attributes.newWindow);
  14032. }
  14033. if (storage && attributes.dataId) {
  14034. this.setupStorage(html, attributes.dataId, element, storage);
  14035. }
  14036. }
  14037. static render(parameters) {
  14038. const storage = parameters.annotationStorage;
  14039. const linkService = parameters.linkService;
  14040. const root = parameters.xfaHtml;
  14041. const intent = parameters.intent || "display";
  14042. const rootHtml = document.createElement(root.name);
  14043. if (root.attributes) {
  14044. this.setAttributes({
  14045. html: rootHtml,
  14046. element: root,
  14047. intent,
  14048. linkService
  14049. });
  14050. }
  14051. const stack = [[root, -1, rootHtml]];
  14052. const rootDiv = parameters.div;
  14053. rootDiv.append(rootHtml);
  14054. if (parameters.viewport) {
  14055. const transform = `matrix(${parameters.viewport.transform.join(",")})`;
  14056. rootDiv.style.transform = transform;
  14057. }
  14058. if (intent !== "richText") {
  14059. rootDiv.setAttribute("class", "xfaLayer xfaFont");
  14060. }
  14061. const textDivs = [];
  14062. while (stack.length > 0) {
  14063. const [parent, i, html] = stack.at(-1);
  14064. if (i + 1 === parent.children.length) {
  14065. stack.pop();
  14066. continue;
  14067. }
  14068. const child = parent.children[++stack.at(-1)[1]];
  14069. if (child === null) {
  14070. continue;
  14071. }
  14072. const {
  14073. name
  14074. } = child;
  14075. if (name === "#text") {
  14076. const node = document.createTextNode(child.value);
  14077. textDivs.push(node);
  14078. html.append(node);
  14079. continue;
  14080. }
  14081. let childHtml;
  14082. if (child?.attributes?.xmlns) {
  14083. childHtml = document.createElementNS(child.attributes.xmlns, name);
  14084. } else {
  14085. childHtml = document.createElement(name);
  14086. }
  14087. html.append(childHtml);
  14088. if (child.attributes) {
  14089. this.setAttributes({
  14090. html: childHtml,
  14091. element: child,
  14092. storage,
  14093. intent,
  14094. linkService
  14095. });
  14096. }
  14097. if (child.children && child.children.length > 0) {
  14098. stack.push([child, -1, childHtml]);
  14099. } else if (child.value) {
  14100. const node = document.createTextNode(child.value);
  14101. if (_xfa_text.XfaText.shouldBuildText(name)) {
  14102. textDivs.push(node);
  14103. }
  14104. childHtml.append(node);
  14105. }
  14106. }
  14107. for (const el of rootDiv.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea")) {
  14108. el.setAttribute("readOnly", true);
  14109. }
  14110. return {
  14111. textDivs
  14112. };
  14113. }
  14114. static update(parameters) {
  14115. const transform = `matrix(${parameters.viewport.transform.join(",")})`;
  14116. parameters.div.style.transform = transform;
  14117. parameters.div.hidden = false;
  14118. }
  14119. }
  14120. exports.XfaLayer = XfaLayer;
  14121. /***/ }),
  14122. /* 33 */
  14123. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  14124. Object.defineProperty(exports, "__esModule", ({
  14125. value: true
  14126. }));
  14127. exports.SVGGraphics = void 0;
  14128. var _display_utils = __w_pdfjs_require__(6);
  14129. var _util = __w_pdfjs_require__(1);
  14130. var _is_node = __w_pdfjs_require__(10);
  14131. let SVGGraphics = class {
  14132. constructor() {
  14133. (0, _util.unreachable)("Not implemented: SVGGraphics");
  14134. }
  14135. };
  14136. exports.SVGGraphics = SVGGraphics;
  14137. {
  14138. const SVG_DEFAULTS = {
  14139. fontStyle: "normal",
  14140. fontWeight: "normal",
  14141. fillColor: "#000000"
  14142. };
  14143. const XML_NS = "http://www.w3.org/XML/1998/namespace";
  14144. const XLINK_NS = "http://www.w3.org/1999/xlink";
  14145. const LINE_CAP_STYLES = ["butt", "round", "square"];
  14146. const LINE_JOIN_STYLES = ["miter", "round", "bevel"];
  14147. const createObjectURL = function (data, contentType = "", forceDataSchema = false) {
  14148. if (URL.createObjectURL && typeof Blob !== "undefined" && !forceDataSchema) {
  14149. return URL.createObjectURL(new Blob([data], {
  14150. type: contentType
  14151. }));
  14152. }
  14153. const digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  14154. let buffer = `data:${contentType};base64,`;
  14155. for (let i = 0, ii = data.length; i < ii; i += 3) {
  14156. const b1 = data[i] & 0xff;
  14157. const b2 = data[i + 1] & 0xff;
  14158. const b3 = data[i + 2] & 0xff;
  14159. const d1 = b1 >> 2,
  14160. d2 = (b1 & 3) << 4 | b2 >> 4;
  14161. const d3 = i + 1 < ii ? (b2 & 0xf) << 2 | b3 >> 6 : 64;
  14162. const d4 = i + 2 < ii ? b3 & 0x3f : 64;
  14163. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  14164. }
  14165. return buffer;
  14166. };
  14167. const convertImgDataToPng = function () {
  14168. const PNG_HEADER = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  14169. const CHUNK_WRAPPER_SIZE = 12;
  14170. const crcTable = new Int32Array(256);
  14171. for (let i = 0; i < 256; i++) {
  14172. let c = i;
  14173. for (let h = 0; h < 8; h++) {
  14174. if (c & 1) {
  14175. c = 0xedb88320 ^ c >> 1 & 0x7fffffff;
  14176. } else {
  14177. c = c >> 1 & 0x7fffffff;
  14178. }
  14179. }
  14180. crcTable[i] = c;
  14181. }
  14182. function crc32(data, start, end) {
  14183. let crc = -1;
  14184. for (let i = start; i < end; i++) {
  14185. const a = (crc ^ data[i]) & 0xff;
  14186. const b = crcTable[a];
  14187. crc = crc >>> 8 ^ b;
  14188. }
  14189. return crc ^ -1;
  14190. }
  14191. function writePngChunk(type, body, data, offset) {
  14192. let p = offset;
  14193. const len = body.length;
  14194. data[p] = len >> 24 & 0xff;
  14195. data[p + 1] = len >> 16 & 0xff;
  14196. data[p + 2] = len >> 8 & 0xff;
  14197. data[p + 3] = len & 0xff;
  14198. p += 4;
  14199. data[p] = type.charCodeAt(0) & 0xff;
  14200. data[p + 1] = type.charCodeAt(1) & 0xff;
  14201. data[p + 2] = type.charCodeAt(2) & 0xff;
  14202. data[p + 3] = type.charCodeAt(3) & 0xff;
  14203. p += 4;
  14204. data.set(body, p);
  14205. p += body.length;
  14206. const crc = crc32(data, offset + 4, p);
  14207. data[p] = crc >> 24 & 0xff;
  14208. data[p + 1] = crc >> 16 & 0xff;
  14209. data[p + 2] = crc >> 8 & 0xff;
  14210. data[p + 3] = crc & 0xff;
  14211. }
  14212. function adler32(data, start, end) {
  14213. let a = 1;
  14214. let b = 0;
  14215. for (let i = start; i < end; ++i) {
  14216. a = (a + (data[i] & 0xff)) % 65521;
  14217. b = (b + a) % 65521;
  14218. }
  14219. return b << 16 | a;
  14220. }
  14221. function deflateSync(literals) {
  14222. if (!_is_node.isNodeJS) {
  14223. return deflateSyncUncompressed(literals);
  14224. }
  14225. try {
  14226. let input;
  14227. if (parseInt(process.versions.node) >= 8) {
  14228. input = literals;
  14229. } else {
  14230. input = Buffer.from(literals);
  14231. }
  14232. const output = require("zlib").deflateSync(input, {
  14233. level: 9
  14234. });
  14235. return output instanceof Uint8Array ? output : new Uint8Array(output);
  14236. } catch (e) {
  14237. (0, _util.warn)("Not compressing PNG because zlib.deflateSync is unavailable: " + e);
  14238. }
  14239. return deflateSyncUncompressed(literals);
  14240. }
  14241. function deflateSyncUncompressed(literals) {
  14242. let len = literals.length;
  14243. const maxBlockLength = 0xffff;
  14244. const deflateBlocks = Math.ceil(len / maxBlockLength);
  14245. const idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  14246. let pi = 0;
  14247. idat[pi++] = 0x78;
  14248. idat[pi++] = 0x9c;
  14249. let pos = 0;
  14250. while (len > maxBlockLength) {
  14251. idat[pi++] = 0x00;
  14252. idat[pi++] = 0xff;
  14253. idat[pi++] = 0xff;
  14254. idat[pi++] = 0x00;
  14255. idat[pi++] = 0x00;
  14256. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  14257. pi += maxBlockLength;
  14258. pos += maxBlockLength;
  14259. len -= maxBlockLength;
  14260. }
  14261. idat[pi++] = 0x01;
  14262. idat[pi++] = len & 0xff;
  14263. idat[pi++] = len >> 8 & 0xff;
  14264. idat[pi++] = ~len & 0xffff & 0xff;
  14265. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  14266. idat.set(literals.subarray(pos), pi);
  14267. pi += literals.length - pos;
  14268. const adler = adler32(literals, 0, literals.length);
  14269. idat[pi++] = adler >> 24 & 0xff;
  14270. idat[pi++] = adler >> 16 & 0xff;
  14271. idat[pi++] = adler >> 8 & 0xff;
  14272. idat[pi++] = adler & 0xff;
  14273. return idat;
  14274. }
  14275. function encode(imgData, kind, forceDataSchema, isMask) {
  14276. const width = imgData.width;
  14277. const height = imgData.height;
  14278. let bitDepth, colorType, lineSize;
  14279. const bytes = imgData.data;
  14280. switch (kind) {
  14281. case _util.ImageKind.GRAYSCALE_1BPP:
  14282. colorType = 0;
  14283. bitDepth = 1;
  14284. lineSize = width + 7 >> 3;
  14285. break;
  14286. case _util.ImageKind.RGB_24BPP:
  14287. colorType = 2;
  14288. bitDepth = 8;
  14289. lineSize = width * 3;
  14290. break;
  14291. case _util.ImageKind.RGBA_32BPP:
  14292. colorType = 6;
  14293. bitDepth = 8;
  14294. lineSize = width * 4;
  14295. break;
  14296. default:
  14297. throw new Error("invalid format");
  14298. }
  14299. const literals = new Uint8Array((1 + lineSize) * height);
  14300. let offsetLiterals = 0,
  14301. offsetBytes = 0;
  14302. for (let y = 0; y < height; ++y) {
  14303. literals[offsetLiterals++] = 0;
  14304. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize), offsetLiterals);
  14305. offsetBytes += lineSize;
  14306. offsetLiterals += lineSize;
  14307. }
  14308. if (kind === _util.ImageKind.GRAYSCALE_1BPP && isMask) {
  14309. offsetLiterals = 0;
  14310. for (let y = 0; y < height; y++) {
  14311. offsetLiterals++;
  14312. for (let i = 0; i < lineSize; i++) {
  14313. literals[offsetLiterals++] ^= 0xff;
  14314. }
  14315. }
  14316. }
  14317. 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]);
  14318. const idat = deflateSync(literals);
  14319. const pngLength = PNG_HEADER.length + CHUNK_WRAPPER_SIZE * 3 + ihdr.length + idat.length;
  14320. const data = new Uint8Array(pngLength);
  14321. let offset = 0;
  14322. data.set(PNG_HEADER, offset);
  14323. offset += PNG_HEADER.length;
  14324. writePngChunk("IHDR", ihdr, data, offset);
  14325. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  14326. writePngChunk("IDATA", idat, data, offset);
  14327. offset += CHUNK_WRAPPER_SIZE + idat.length;
  14328. writePngChunk("IEND", new Uint8Array(0), data, offset);
  14329. return createObjectURL(data, "image/png", forceDataSchema);
  14330. }
  14331. return function convertImgDataToPng(imgData, forceDataSchema, isMask) {
  14332. const kind = imgData.kind === undefined ? _util.ImageKind.GRAYSCALE_1BPP : imgData.kind;
  14333. return encode(imgData, kind, forceDataSchema, isMask);
  14334. };
  14335. }();
  14336. class SVGExtraState {
  14337. constructor() {
  14338. this.fontSizeScale = 1;
  14339. this.fontWeight = SVG_DEFAULTS.fontWeight;
  14340. this.fontSize = 0;
  14341. this.textMatrix = _util.IDENTITY_MATRIX;
  14342. this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
  14343. this.leading = 0;
  14344. this.textRenderingMode = _util.TextRenderingMode.FILL;
  14345. this.textMatrixScale = 1;
  14346. this.x = 0;
  14347. this.y = 0;
  14348. this.lineX = 0;
  14349. this.lineY = 0;
  14350. this.charSpacing = 0;
  14351. this.wordSpacing = 0;
  14352. this.textHScale = 1;
  14353. this.textRise = 0;
  14354. this.fillColor = SVG_DEFAULTS.fillColor;
  14355. this.strokeColor = "#000000";
  14356. this.fillAlpha = 1;
  14357. this.strokeAlpha = 1;
  14358. this.lineWidth = 1;
  14359. this.lineJoin = "";
  14360. this.lineCap = "";
  14361. this.miterLimit = 0;
  14362. this.dashArray = [];
  14363. this.dashPhase = 0;
  14364. this.dependencies = [];
  14365. this.activeClipUrl = null;
  14366. this.clipGroup = null;
  14367. this.maskId = "";
  14368. }
  14369. clone() {
  14370. return Object.create(this);
  14371. }
  14372. setCurrentPoint(x, y) {
  14373. this.x = x;
  14374. this.y = y;
  14375. }
  14376. }
  14377. function opListToTree(opList) {
  14378. let opTree = [];
  14379. const tmp = [];
  14380. for (const opListElement of opList) {
  14381. if (opListElement.fn === "save") {
  14382. opTree.push({
  14383. fnId: 92,
  14384. fn: "group",
  14385. items: []
  14386. });
  14387. tmp.push(opTree);
  14388. opTree = opTree.at(-1).items;
  14389. continue;
  14390. }
  14391. if (opListElement.fn === "restore") {
  14392. opTree = tmp.pop();
  14393. } else {
  14394. opTree.push(opListElement);
  14395. }
  14396. }
  14397. return opTree;
  14398. }
  14399. function pf(value) {
  14400. if (Number.isInteger(value)) {
  14401. return value.toString();
  14402. }
  14403. const s = value.toFixed(10);
  14404. let i = s.length - 1;
  14405. if (s[i] !== "0") {
  14406. return s;
  14407. }
  14408. do {
  14409. i--;
  14410. } while (s[i] === "0");
  14411. return s.substring(0, s[i] === "." ? i : i + 1);
  14412. }
  14413. function pm(m) {
  14414. if (m[4] === 0 && m[5] === 0) {
  14415. if (m[1] === 0 && m[2] === 0) {
  14416. if (m[0] === 1 && m[3] === 1) {
  14417. return "";
  14418. }
  14419. return `scale(${pf(m[0])} ${pf(m[3])})`;
  14420. }
  14421. if (m[0] === m[3] && m[1] === -m[2]) {
  14422. const a = Math.acos(m[0]) * 180 / Math.PI;
  14423. return `rotate(${pf(a)})`;
  14424. }
  14425. } else {
  14426. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  14427. return `translate(${pf(m[4])} ${pf(m[5])})`;
  14428. }
  14429. }
  14430. return `matrix(${pf(m[0])} ${pf(m[1])} ${pf(m[2])} ${pf(m[3])} ${pf(m[4])} ` + `${pf(m[5])})`;
  14431. }
  14432. let clipCount = 0;
  14433. let maskCount = 0;
  14434. let shadingCount = 0;
  14435. exports.SVGGraphics = SVGGraphics = class {
  14436. constructor(commonObjs, objs, forceDataSchema = false) {
  14437. (0, _display_utils.deprecated)("The SVG back-end is no longer maintained and *may* be removed in the future.");
  14438. this.svgFactory = new _display_utils.DOMSVGFactory();
  14439. this.current = new SVGExtraState();
  14440. this.transformMatrix = _util.IDENTITY_MATRIX;
  14441. this.transformStack = [];
  14442. this.extraStack = [];
  14443. this.commonObjs = commonObjs;
  14444. this.objs = objs;
  14445. this.pendingClip = null;
  14446. this.pendingEOFill = false;
  14447. this.embedFonts = false;
  14448. this.embeddedFonts = Object.create(null);
  14449. this.cssStyle = null;
  14450. this.forceDataSchema = !!forceDataSchema;
  14451. this._operatorIdMapping = [];
  14452. for (const op in _util.OPS) {
  14453. this._operatorIdMapping[_util.OPS[op]] = op;
  14454. }
  14455. }
  14456. getObject(data, fallback = null) {
  14457. if (typeof data === "string") {
  14458. return data.startsWith("g_") ? this.commonObjs.get(data) : this.objs.get(data);
  14459. }
  14460. return fallback;
  14461. }
  14462. save() {
  14463. this.transformStack.push(this.transformMatrix);
  14464. const old = this.current;
  14465. this.extraStack.push(old);
  14466. this.current = old.clone();
  14467. }
  14468. restore() {
  14469. this.transformMatrix = this.transformStack.pop();
  14470. this.current = this.extraStack.pop();
  14471. this.pendingClip = null;
  14472. this.tgrp = null;
  14473. }
  14474. group(items) {
  14475. this.save();
  14476. this.executeOpTree(items);
  14477. this.restore();
  14478. }
  14479. loadDependencies(operatorList) {
  14480. const fnArray = operatorList.fnArray;
  14481. const argsArray = operatorList.argsArray;
  14482. for (let i = 0, ii = fnArray.length; i < ii; i++) {
  14483. if (fnArray[i] !== _util.OPS.dependency) {
  14484. continue;
  14485. }
  14486. for (const obj of argsArray[i]) {
  14487. const objsPool = obj.startsWith("g_") ? this.commonObjs : this.objs;
  14488. const promise = new Promise(resolve => {
  14489. objsPool.get(obj, resolve);
  14490. });
  14491. this.current.dependencies.push(promise);
  14492. }
  14493. }
  14494. return Promise.all(this.current.dependencies);
  14495. }
  14496. transform(a, b, c, d, e, f) {
  14497. const transformMatrix = [a, b, c, d, e, f];
  14498. this.transformMatrix = _util.Util.transform(this.transformMatrix, transformMatrix);
  14499. this.tgrp = null;
  14500. }
  14501. getSVG(operatorList, viewport) {
  14502. this.viewport = viewport;
  14503. const svgElement = this._initialize(viewport);
  14504. return this.loadDependencies(operatorList).then(() => {
  14505. this.transformMatrix = _util.IDENTITY_MATRIX;
  14506. this.executeOpTree(this.convertOpList(operatorList));
  14507. return svgElement;
  14508. });
  14509. }
  14510. convertOpList(operatorList) {
  14511. const operatorIdMapping = this._operatorIdMapping;
  14512. const argsArray = operatorList.argsArray;
  14513. const fnArray = operatorList.fnArray;
  14514. const opList = [];
  14515. for (let i = 0, ii = fnArray.length; i < ii; i++) {
  14516. const fnId = fnArray[i];
  14517. opList.push({
  14518. fnId,
  14519. fn: operatorIdMapping[fnId],
  14520. args: argsArray[i]
  14521. });
  14522. }
  14523. return opListToTree(opList);
  14524. }
  14525. executeOpTree(opTree) {
  14526. for (const opTreeElement of opTree) {
  14527. const fn = opTreeElement.fn;
  14528. const fnId = opTreeElement.fnId;
  14529. const args = opTreeElement.args;
  14530. switch (fnId | 0) {
  14531. case _util.OPS.beginText:
  14532. this.beginText();
  14533. break;
  14534. case _util.OPS.dependency:
  14535. break;
  14536. case _util.OPS.setLeading:
  14537. this.setLeading(args);
  14538. break;
  14539. case _util.OPS.setLeadingMoveText:
  14540. this.setLeadingMoveText(args[0], args[1]);
  14541. break;
  14542. case _util.OPS.setFont:
  14543. this.setFont(args);
  14544. break;
  14545. case _util.OPS.showText:
  14546. this.showText(args[0]);
  14547. break;
  14548. case _util.OPS.showSpacedText:
  14549. this.showText(args[0]);
  14550. break;
  14551. case _util.OPS.endText:
  14552. this.endText();
  14553. break;
  14554. case _util.OPS.moveText:
  14555. this.moveText(args[0], args[1]);
  14556. break;
  14557. case _util.OPS.setCharSpacing:
  14558. this.setCharSpacing(args[0]);
  14559. break;
  14560. case _util.OPS.setWordSpacing:
  14561. this.setWordSpacing(args[0]);
  14562. break;
  14563. case _util.OPS.setHScale:
  14564. this.setHScale(args[0]);
  14565. break;
  14566. case _util.OPS.setTextMatrix:
  14567. this.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
  14568. break;
  14569. case _util.OPS.setTextRise:
  14570. this.setTextRise(args[0]);
  14571. break;
  14572. case _util.OPS.setTextRenderingMode:
  14573. this.setTextRenderingMode(args[0]);
  14574. break;
  14575. case _util.OPS.setLineWidth:
  14576. this.setLineWidth(args[0]);
  14577. break;
  14578. case _util.OPS.setLineJoin:
  14579. this.setLineJoin(args[0]);
  14580. break;
  14581. case _util.OPS.setLineCap:
  14582. this.setLineCap(args[0]);
  14583. break;
  14584. case _util.OPS.setMiterLimit:
  14585. this.setMiterLimit(args[0]);
  14586. break;
  14587. case _util.OPS.setFillRGBColor:
  14588. this.setFillRGBColor(args[0], args[1], args[2]);
  14589. break;
  14590. case _util.OPS.setStrokeRGBColor:
  14591. this.setStrokeRGBColor(args[0], args[1], args[2]);
  14592. break;
  14593. case _util.OPS.setStrokeColorN:
  14594. this.setStrokeColorN(args);
  14595. break;
  14596. case _util.OPS.setFillColorN:
  14597. this.setFillColorN(args);
  14598. break;
  14599. case _util.OPS.shadingFill:
  14600. this.shadingFill(args[0]);
  14601. break;
  14602. case _util.OPS.setDash:
  14603. this.setDash(args[0], args[1]);
  14604. break;
  14605. case _util.OPS.setRenderingIntent:
  14606. this.setRenderingIntent(args[0]);
  14607. break;
  14608. case _util.OPS.setFlatness:
  14609. this.setFlatness(args[0]);
  14610. break;
  14611. case _util.OPS.setGState:
  14612. this.setGState(args[0]);
  14613. break;
  14614. case _util.OPS.fill:
  14615. this.fill();
  14616. break;
  14617. case _util.OPS.eoFill:
  14618. this.eoFill();
  14619. break;
  14620. case _util.OPS.stroke:
  14621. this.stroke();
  14622. break;
  14623. case _util.OPS.fillStroke:
  14624. this.fillStroke();
  14625. break;
  14626. case _util.OPS.eoFillStroke:
  14627. this.eoFillStroke();
  14628. break;
  14629. case _util.OPS.clip:
  14630. this.clip("nonzero");
  14631. break;
  14632. case _util.OPS.eoClip:
  14633. this.clip("evenodd");
  14634. break;
  14635. case _util.OPS.paintSolidColorImageMask:
  14636. this.paintSolidColorImageMask();
  14637. break;
  14638. case _util.OPS.paintImageXObject:
  14639. this.paintImageXObject(args[0]);
  14640. break;
  14641. case _util.OPS.paintInlineImageXObject:
  14642. this.paintInlineImageXObject(args[0]);
  14643. break;
  14644. case _util.OPS.paintImageMaskXObject:
  14645. this.paintImageMaskXObject(args[0]);
  14646. break;
  14647. case _util.OPS.paintFormXObjectBegin:
  14648. this.paintFormXObjectBegin(args[0], args[1]);
  14649. break;
  14650. case _util.OPS.paintFormXObjectEnd:
  14651. this.paintFormXObjectEnd();
  14652. break;
  14653. case _util.OPS.closePath:
  14654. this.closePath();
  14655. break;
  14656. case _util.OPS.closeStroke:
  14657. this.closeStroke();
  14658. break;
  14659. case _util.OPS.closeFillStroke:
  14660. this.closeFillStroke();
  14661. break;
  14662. case _util.OPS.closeEOFillStroke:
  14663. this.closeEOFillStroke();
  14664. break;
  14665. case _util.OPS.nextLine:
  14666. this.nextLine();
  14667. break;
  14668. case _util.OPS.transform:
  14669. this.transform(args[0], args[1], args[2], args[3], args[4], args[5]);
  14670. break;
  14671. case _util.OPS.constructPath:
  14672. this.constructPath(args[0], args[1]);
  14673. break;
  14674. case _util.OPS.endPath:
  14675. this.endPath();
  14676. break;
  14677. case 92:
  14678. this.group(opTreeElement.items);
  14679. break;
  14680. default:
  14681. (0, _util.warn)(`Unimplemented operator ${fn}`);
  14682. break;
  14683. }
  14684. }
  14685. }
  14686. setWordSpacing(wordSpacing) {
  14687. this.current.wordSpacing = wordSpacing;
  14688. }
  14689. setCharSpacing(charSpacing) {
  14690. this.current.charSpacing = charSpacing;
  14691. }
  14692. nextLine() {
  14693. this.moveText(0, this.current.leading);
  14694. }
  14695. setTextMatrix(a, b, c, d, e, f) {
  14696. const current = this.current;
  14697. current.textMatrix = current.lineMatrix = [a, b, c, d, e, f];
  14698. current.textMatrixScale = Math.hypot(a, b);
  14699. current.x = current.lineX = 0;
  14700. current.y = current.lineY = 0;
  14701. current.xcoords = [];
  14702. current.ycoords = [];
  14703. current.tspan = this.svgFactory.createElement("svg:tspan");
  14704. current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
  14705. current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
  14706. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  14707. current.txtElement = this.svgFactory.createElement("svg:text");
  14708. current.txtElement.append(current.tspan);
  14709. }
  14710. beginText() {
  14711. const current = this.current;
  14712. current.x = current.lineX = 0;
  14713. current.y = current.lineY = 0;
  14714. current.textMatrix = _util.IDENTITY_MATRIX;
  14715. current.lineMatrix = _util.IDENTITY_MATRIX;
  14716. current.textMatrixScale = 1;
  14717. current.tspan = this.svgFactory.createElement("svg:tspan");
  14718. current.txtElement = this.svgFactory.createElement("svg:text");
  14719. current.txtgrp = this.svgFactory.createElement("svg:g");
  14720. current.xcoords = [];
  14721. current.ycoords = [];
  14722. }
  14723. moveText(x, y) {
  14724. const current = this.current;
  14725. current.x = current.lineX += x;
  14726. current.y = current.lineY += y;
  14727. current.xcoords = [];
  14728. current.ycoords = [];
  14729. current.tspan = this.svgFactory.createElement("svg:tspan");
  14730. current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
  14731. current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
  14732. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  14733. }
  14734. showText(glyphs) {
  14735. const current = this.current;
  14736. const font = current.font;
  14737. const fontSize = current.fontSize;
  14738. if (fontSize === 0) {
  14739. return;
  14740. }
  14741. const fontSizeScale = current.fontSizeScale;
  14742. const charSpacing = current.charSpacing;
  14743. const wordSpacing = current.wordSpacing;
  14744. const fontDirection = current.fontDirection;
  14745. const textHScale = current.textHScale * fontDirection;
  14746. const vertical = font.vertical;
  14747. const spacingDir = vertical ? 1 : -1;
  14748. const defaultVMetrics = font.defaultVMetrics;
  14749. const widthAdvanceScale = fontSize * current.fontMatrix[0];
  14750. let x = 0;
  14751. for (const glyph of glyphs) {
  14752. if (glyph === null) {
  14753. x += fontDirection * wordSpacing;
  14754. continue;
  14755. } else if (typeof glyph === "number") {
  14756. x += spacingDir * glyph * fontSize / 1000;
  14757. continue;
  14758. }
  14759. const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  14760. const character = glyph.fontChar;
  14761. let scaledX, scaledY;
  14762. let width = glyph.width;
  14763. if (vertical) {
  14764. let vx;
  14765. const vmetric = glyph.vmetric || defaultVMetrics;
  14766. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  14767. vx = -vx * widthAdvanceScale;
  14768. const vy = vmetric[2] * widthAdvanceScale;
  14769. width = vmetric ? -vmetric[0] : width;
  14770. scaledX = vx / fontSizeScale;
  14771. scaledY = (x + vy) / fontSizeScale;
  14772. } else {
  14773. scaledX = x / fontSizeScale;
  14774. scaledY = 0;
  14775. }
  14776. if (glyph.isInFont || font.missingFile) {
  14777. current.xcoords.push(current.x + scaledX);
  14778. if (vertical) {
  14779. current.ycoords.push(-current.y + scaledY);
  14780. }
  14781. current.tspan.textContent += character;
  14782. } else {}
  14783. let charWidth;
  14784. if (vertical) {
  14785. charWidth = width * widthAdvanceScale - spacing * fontDirection;
  14786. } else {
  14787. charWidth = width * widthAdvanceScale + spacing * fontDirection;
  14788. }
  14789. x += charWidth;
  14790. }
  14791. current.tspan.setAttributeNS(null, "x", current.xcoords.map(pf).join(" "));
  14792. if (vertical) {
  14793. current.tspan.setAttributeNS(null, "y", current.ycoords.map(pf).join(" "));
  14794. } else {
  14795. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  14796. }
  14797. if (vertical) {
  14798. current.y -= x;
  14799. } else {
  14800. current.x += x * textHScale;
  14801. }
  14802. current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
  14803. current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
  14804. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  14805. current.tspan.setAttributeNS(null, "font-style", current.fontStyle);
  14806. }
  14807. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  14808. current.tspan.setAttributeNS(null, "font-weight", current.fontWeight);
  14809. }
  14810. const fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  14811. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  14812. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  14813. current.tspan.setAttributeNS(null, "fill", current.fillColor);
  14814. }
  14815. if (current.fillAlpha < 1) {
  14816. current.tspan.setAttributeNS(null, "fill-opacity", current.fillAlpha);
  14817. }
  14818. } else if (current.textRenderingMode === _util.TextRenderingMode.ADD_TO_PATH) {
  14819. current.tspan.setAttributeNS(null, "fill", "transparent");
  14820. } else {
  14821. current.tspan.setAttributeNS(null, "fill", "none");
  14822. }
  14823. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  14824. const lineWidthScale = 1 / (current.textMatrixScale || 1);
  14825. this._setStrokeAttributes(current.tspan, lineWidthScale);
  14826. }
  14827. let textMatrix = current.textMatrix;
  14828. if (current.textRise !== 0) {
  14829. textMatrix = textMatrix.slice();
  14830. textMatrix[5] += current.textRise;
  14831. }
  14832. current.txtElement.setAttributeNS(null, "transform", `${pm(textMatrix)} scale(${pf(textHScale)}, -1)`);
  14833. current.txtElement.setAttributeNS(XML_NS, "xml:space", "preserve");
  14834. current.txtElement.append(current.tspan);
  14835. current.txtgrp.append(current.txtElement);
  14836. this._ensureTransformGroup().append(current.txtElement);
  14837. }
  14838. setLeadingMoveText(x, y) {
  14839. this.setLeading(-y);
  14840. this.moveText(x, y);
  14841. }
  14842. addFontStyle(fontObj) {
  14843. if (!fontObj.data) {
  14844. throw new Error("addFontStyle: No font data available, " + 'ensure that the "fontExtraProperties" API parameter is set.');
  14845. }
  14846. if (!this.cssStyle) {
  14847. this.cssStyle = this.svgFactory.createElement("svg:style");
  14848. this.cssStyle.setAttributeNS(null, "type", "text/css");
  14849. this.defs.append(this.cssStyle);
  14850. }
  14851. const url = createObjectURL(fontObj.data, fontObj.mimetype, this.forceDataSchema);
  14852. this.cssStyle.textContent += `@font-face { font-family: "${fontObj.loadedName}";` + ` src: url(${url}); }\n`;
  14853. }
  14854. setFont(details) {
  14855. const current = this.current;
  14856. const fontObj = this.commonObjs.get(details[0]);
  14857. let size = details[1];
  14858. current.font = fontObj;
  14859. if (this.embedFonts && !fontObj.missingFile && !this.embeddedFonts[fontObj.loadedName]) {
  14860. this.addFontStyle(fontObj);
  14861. this.embeddedFonts[fontObj.loadedName] = fontObj;
  14862. }
  14863. current.fontMatrix = fontObj.fontMatrix || _util.FONT_IDENTITY_MATRIX;
  14864. let bold = "normal";
  14865. if (fontObj.black) {
  14866. bold = "900";
  14867. } else if (fontObj.bold) {
  14868. bold = "bold";
  14869. }
  14870. const italic = fontObj.italic ? "italic" : "normal";
  14871. if (size < 0) {
  14872. size = -size;
  14873. current.fontDirection = -1;
  14874. } else {
  14875. current.fontDirection = 1;
  14876. }
  14877. current.fontSize = size;
  14878. current.fontFamily = fontObj.loadedName;
  14879. current.fontWeight = bold;
  14880. current.fontStyle = italic;
  14881. current.tspan = this.svgFactory.createElement("svg:tspan");
  14882. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  14883. current.xcoords = [];
  14884. current.ycoords = [];
  14885. }
  14886. endText() {
  14887. const current = this.current;
  14888. if (current.textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG && current.txtElement?.hasChildNodes()) {
  14889. current.element = current.txtElement;
  14890. this.clip("nonzero");
  14891. this.endPath();
  14892. }
  14893. }
  14894. setLineWidth(width) {
  14895. if (width > 0) {
  14896. this.current.lineWidth = width;
  14897. }
  14898. }
  14899. setLineCap(style) {
  14900. this.current.lineCap = LINE_CAP_STYLES[style];
  14901. }
  14902. setLineJoin(style) {
  14903. this.current.lineJoin = LINE_JOIN_STYLES[style];
  14904. }
  14905. setMiterLimit(limit) {
  14906. this.current.miterLimit = limit;
  14907. }
  14908. setStrokeAlpha(strokeAlpha) {
  14909. this.current.strokeAlpha = strokeAlpha;
  14910. }
  14911. setStrokeRGBColor(r, g, b) {
  14912. this.current.strokeColor = _util.Util.makeHexColor(r, g, b);
  14913. }
  14914. setFillAlpha(fillAlpha) {
  14915. this.current.fillAlpha = fillAlpha;
  14916. }
  14917. setFillRGBColor(r, g, b) {
  14918. this.current.fillColor = _util.Util.makeHexColor(r, g, b);
  14919. this.current.tspan = this.svgFactory.createElement("svg:tspan");
  14920. this.current.xcoords = [];
  14921. this.current.ycoords = [];
  14922. }
  14923. setStrokeColorN(args) {
  14924. this.current.strokeColor = this._makeColorN_Pattern(args);
  14925. }
  14926. setFillColorN(args) {
  14927. this.current.fillColor = this._makeColorN_Pattern(args);
  14928. }
  14929. shadingFill(args) {
  14930. const width = this.viewport.width;
  14931. const height = this.viewport.height;
  14932. const inv = _util.Util.inverseTransform(this.transformMatrix);
  14933. const bl = _util.Util.applyTransform([0, 0], inv);
  14934. const br = _util.Util.applyTransform([0, height], inv);
  14935. const ul = _util.Util.applyTransform([width, 0], inv);
  14936. const ur = _util.Util.applyTransform([width, height], inv);
  14937. const x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  14938. const y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  14939. const x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  14940. const y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  14941. const rect = this.svgFactory.createElement("svg:rect");
  14942. rect.setAttributeNS(null, "x", x0);
  14943. rect.setAttributeNS(null, "y", y0);
  14944. rect.setAttributeNS(null, "width", x1 - x0);
  14945. rect.setAttributeNS(null, "height", y1 - y0);
  14946. rect.setAttributeNS(null, "fill", this._makeShadingPattern(args));
  14947. if (this.current.fillAlpha < 1) {
  14948. rect.setAttributeNS(null, "fill-opacity", this.current.fillAlpha);
  14949. }
  14950. this._ensureTransformGroup().append(rect);
  14951. }
  14952. _makeColorN_Pattern(args) {
  14953. if (args[0] === "TilingPattern") {
  14954. return this._makeTilingPattern(args);
  14955. }
  14956. return this._makeShadingPattern(args);
  14957. }
  14958. _makeTilingPattern(args) {
  14959. const color = args[1];
  14960. const operatorList = args[2];
  14961. const matrix = args[3] || _util.IDENTITY_MATRIX;
  14962. const [x0, y0, x1, y1] = args[4];
  14963. const xstep = args[5];
  14964. const ystep = args[6];
  14965. const paintType = args[7];
  14966. const tilingId = `shading${shadingCount++}`;
  14967. const [tx0, ty0, tx1, ty1] = _util.Util.normalizeRect([..._util.Util.applyTransform([x0, y0], matrix), ..._util.Util.applyTransform([x1, y1], matrix)]);
  14968. const [xscale, yscale] = _util.Util.singularValueDecompose2dScale(matrix);
  14969. const txstep = xstep * xscale;
  14970. const tystep = ystep * yscale;
  14971. const tiling = this.svgFactory.createElement("svg:pattern");
  14972. tiling.setAttributeNS(null, "id", tilingId);
  14973. tiling.setAttributeNS(null, "patternUnits", "userSpaceOnUse");
  14974. tiling.setAttributeNS(null, "width", txstep);
  14975. tiling.setAttributeNS(null, "height", tystep);
  14976. tiling.setAttributeNS(null, "x", `${tx0}`);
  14977. tiling.setAttributeNS(null, "y", `${ty0}`);
  14978. const svg = this.svg;
  14979. const transformMatrix = this.transformMatrix;
  14980. const fillColor = this.current.fillColor;
  14981. const strokeColor = this.current.strokeColor;
  14982. const bbox = this.svgFactory.create(tx1 - tx0, ty1 - ty0);
  14983. this.svg = bbox;
  14984. this.transformMatrix = matrix;
  14985. if (paintType === 2) {
  14986. const cssColor = _util.Util.makeHexColor(...color);
  14987. this.current.fillColor = cssColor;
  14988. this.current.strokeColor = cssColor;
  14989. }
  14990. this.executeOpTree(this.convertOpList(operatorList));
  14991. this.svg = svg;
  14992. this.transformMatrix = transformMatrix;
  14993. this.current.fillColor = fillColor;
  14994. this.current.strokeColor = strokeColor;
  14995. tiling.append(bbox.childNodes[0]);
  14996. this.defs.append(tiling);
  14997. return `url(#${tilingId})`;
  14998. }
  14999. _makeShadingPattern(args) {
  15000. if (typeof args === "string") {
  15001. args = this.objs.get(args);
  15002. }
  15003. switch (args[0]) {
  15004. case "RadialAxial":
  15005. const shadingId = `shading${shadingCount++}`;
  15006. const colorStops = args[3];
  15007. let gradient;
  15008. switch (args[1]) {
  15009. case "axial":
  15010. const point0 = args[4];
  15011. const point1 = args[5];
  15012. gradient = this.svgFactory.createElement("svg:linearGradient");
  15013. gradient.setAttributeNS(null, "id", shadingId);
  15014. gradient.setAttributeNS(null, "gradientUnits", "userSpaceOnUse");
  15015. gradient.setAttributeNS(null, "x1", point0[0]);
  15016. gradient.setAttributeNS(null, "y1", point0[1]);
  15017. gradient.setAttributeNS(null, "x2", point1[0]);
  15018. gradient.setAttributeNS(null, "y2", point1[1]);
  15019. break;
  15020. case "radial":
  15021. const focalPoint = args[4];
  15022. const circlePoint = args[5];
  15023. const focalRadius = args[6];
  15024. const circleRadius = args[7];
  15025. gradient = this.svgFactory.createElement("svg:radialGradient");
  15026. gradient.setAttributeNS(null, "id", shadingId);
  15027. gradient.setAttributeNS(null, "gradientUnits", "userSpaceOnUse");
  15028. gradient.setAttributeNS(null, "cx", circlePoint[0]);
  15029. gradient.setAttributeNS(null, "cy", circlePoint[1]);
  15030. gradient.setAttributeNS(null, "r", circleRadius);
  15031. gradient.setAttributeNS(null, "fx", focalPoint[0]);
  15032. gradient.setAttributeNS(null, "fy", focalPoint[1]);
  15033. gradient.setAttributeNS(null, "fr", focalRadius);
  15034. break;
  15035. default:
  15036. throw new Error(`Unknown RadialAxial type: ${args[1]}`);
  15037. }
  15038. for (const colorStop of colorStops) {
  15039. const stop = this.svgFactory.createElement("svg:stop");
  15040. stop.setAttributeNS(null, "offset", colorStop[0]);
  15041. stop.setAttributeNS(null, "stop-color", colorStop[1]);
  15042. gradient.append(stop);
  15043. }
  15044. this.defs.append(gradient);
  15045. return `url(#${shadingId})`;
  15046. case "Mesh":
  15047. (0, _util.warn)("Unimplemented pattern Mesh");
  15048. return null;
  15049. case "Dummy":
  15050. return "hotpink";
  15051. default:
  15052. throw new Error(`Unknown IR type: ${args[0]}`);
  15053. }
  15054. }
  15055. setDash(dashArray, dashPhase) {
  15056. this.current.dashArray = dashArray;
  15057. this.current.dashPhase = dashPhase;
  15058. }
  15059. constructPath(ops, args) {
  15060. const current = this.current;
  15061. let x = current.x,
  15062. y = current.y;
  15063. let d = [];
  15064. let j = 0;
  15065. for (const op of ops) {
  15066. switch (op | 0) {
  15067. case _util.OPS.rectangle:
  15068. x = args[j++];
  15069. y = args[j++];
  15070. const width = args[j++];
  15071. const height = args[j++];
  15072. const xw = x + width;
  15073. const yh = y + height;
  15074. d.push("M", pf(x), pf(y), "L", pf(xw), pf(y), "L", pf(xw), pf(yh), "L", pf(x), pf(yh), "Z");
  15075. break;
  15076. case _util.OPS.moveTo:
  15077. x = args[j++];
  15078. y = args[j++];
  15079. d.push("M", pf(x), pf(y));
  15080. break;
  15081. case _util.OPS.lineTo:
  15082. x = args[j++];
  15083. y = args[j++];
  15084. d.push("L", pf(x), pf(y));
  15085. break;
  15086. case _util.OPS.curveTo:
  15087. x = args[j + 4];
  15088. y = args[j + 5];
  15089. d.push("C", pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]), pf(x), pf(y));
  15090. j += 6;
  15091. break;
  15092. case _util.OPS.curveTo2:
  15093. d.push("C", pf(x), pf(y), pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]));
  15094. x = args[j + 2];
  15095. y = args[j + 3];
  15096. j += 4;
  15097. break;
  15098. case _util.OPS.curveTo3:
  15099. x = args[j + 2];
  15100. y = args[j + 3];
  15101. d.push("C", pf(args[j]), pf(args[j + 1]), pf(x), pf(y), pf(x), pf(y));
  15102. j += 4;
  15103. break;
  15104. case _util.OPS.closePath:
  15105. d.push("Z");
  15106. break;
  15107. }
  15108. }
  15109. d = d.join(" ");
  15110. if (current.path && ops.length > 0 && ops[0] !== _util.OPS.rectangle && ops[0] !== _util.OPS.moveTo) {
  15111. d = current.path.getAttributeNS(null, "d") + d;
  15112. } else {
  15113. current.path = this.svgFactory.createElement("svg:path");
  15114. this._ensureTransformGroup().append(current.path);
  15115. }
  15116. current.path.setAttributeNS(null, "d", d);
  15117. current.path.setAttributeNS(null, "fill", "none");
  15118. current.element = current.path;
  15119. current.setCurrentPoint(x, y);
  15120. }
  15121. endPath() {
  15122. const current = this.current;
  15123. current.path = null;
  15124. if (!this.pendingClip) {
  15125. return;
  15126. }
  15127. if (!current.element) {
  15128. this.pendingClip = null;
  15129. return;
  15130. }
  15131. const clipId = `clippath${clipCount++}`;
  15132. const clipPath = this.svgFactory.createElement("svg:clipPath");
  15133. clipPath.setAttributeNS(null, "id", clipId);
  15134. clipPath.setAttributeNS(null, "transform", pm(this.transformMatrix));
  15135. const clipElement = current.element.cloneNode(true);
  15136. if (this.pendingClip === "evenodd") {
  15137. clipElement.setAttributeNS(null, "clip-rule", "evenodd");
  15138. } else {
  15139. clipElement.setAttributeNS(null, "clip-rule", "nonzero");
  15140. }
  15141. this.pendingClip = null;
  15142. clipPath.append(clipElement);
  15143. this.defs.append(clipPath);
  15144. if (current.activeClipUrl) {
  15145. current.clipGroup = null;
  15146. for (const prev of this.extraStack) {
  15147. prev.clipGroup = null;
  15148. }
  15149. clipPath.setAttributeNS(null, "clip-path", current.activeClipUrl);
  15150. }
  15151. current.activeClipUrl = `url(#${clipId})`;
  15152. this.tgrp = null;
  15153. }
  15154. clip(type) {
  15155. this.pendingClip = type;
  15156. }
  15157. closePath() {
  15158. const current = this.current;
  15159. if (current.path) {
  15160. const d = `${current.path.getAttributeNS(null, "d")}Z`;
  15161. current.path.setAttributeNS(null, "d", d);
  15162. }
  15163. }
  15164. setLeading(leading) {
  15165. this.current.leading = -leading;
  15166. }
  15167. setTextRise(textRise) {
  15168. this.current.textRise = textRise;
  15169. }
  15170. setTextRenderingMode(textRenderingMode) {
  15171. this.current.textRenderingMode = textRenderingMode;
  15172. }
  15173. setHScale(scale) {
  15174. this.current.textHScale = scale / 100;
  15175. }
  15176. setRenderingIntent(intent) {}
  15177. setFlatness(flatness) {}
  15178. setGState(states) {
  15179. for (const [key, value] of states) {
  15180. switch (key) {
  15181. case "LW":
  15182. this.setLineWidth(value);
  15183. break;
  15184. case "LC":
  15185. this.setLineCap(value);
  15186. break;
  15187. case "LJ":
  15188. this.setLineJoin(value);
  15189. break;
  15190. case "ML":
  15191. this.setMiterLimit(value);
  15192. break;
  15193. case "D":
  15194. this.setDash(value[0], value[1]);
  15195. break;
  15196. case "RI":
  15197. this.setRenderingIntent(value);
  15198. break;
  15199. case "FL":
  15200. this.setFlatness(value);
  15201. break;
  15202. case "Font":
  15203. this.setFont(value);
  15204. break;
  15205. case "CA":
  15206. this.setStrokeAlpha(value);
  15207. break;
  15208. case "ca":
  15209. this.setFillAlpha(value);
  15210. break;
  15211. default:
  15212. (0, _util.warn)(`Unimplemented graphic state operator ${key}`);
  15213. break;
  15214. }
  15215. }
  15216. }
  15217. fill() {
  15218. const current = this.current;
  15219. if (current.element) {
  15220. current.element.setAttributeNS(null, "fill", current.fillColor);
  15221. current.element.setAttributeNS(null, "fill-opacity", current.fillAlpha);
  15222. this.endPath();
  15223. }
  15224. }
  15225. stroke() {
  15226. const current = this.current;
  15227. if (current.element) {
  15228. this._setStrokeAttributes(current.element);
  15229. current.element.setAttributeNS(null, "fill", "none");
  15230. this.endPath();
  15231. }
  15232. }
  15233. _setStrokeAttributes(element, lineWidthScale = 1) {
  15234. const current = this.current;
  15235. let dashArray = current.dashArray;
  15236. if (lineWidthScale !== 1 && dashArray.length > 0) {
  15237. dashArray = dashArray.map(function (value) {
  15238. return lineWidthScale * value;
  15239. });
  15240. }
  15241. element.setAttributeNS(null, "stroke", current.strokeColor);
  15242. element.setAttributeNS(null, "stroke-opacity", current.strokeAlpha);
  15243. element.setAttributeNS(null, "stroke-miterlimit", pf(current.miterLimit));
  15244. element.setAttributeNS(null, "stroke-linecap", current.lineCap);
  15245. element.setAttributeNS(null, "stroke-linejoin", current.lineJoin);
  15246. element.setAttributeNS(null, "stroke-width", pf(lineWidthScale * current.lineWidth) + "px");
  15247. element.setAttributeNS(null, "stroke-dasharray", dashArray.map(pf).join(" "));
  15248. element.setAttributeNS(null, "stroke-dashoffset", pf(lineWidthScale * current.dashPhase) + "px");
  15249. }
  15250. eoFill() {
  15251. this.current.element?.setAttributeNS(null, "fill-rule", "evenodd");
  15252. this.fill();
  15253. }
  15254. fillStroke() {
  15255. this.stroke();
  15256. this.fill();
  15257. }
  15258. eoFillStroke() {
  15259. this.current.element?.setAttributeNS(null, "fill-rule", "evenodd");
  15260. this.fillStroke();
  15261. }
  15262. closeStroke() {
  15263. this.closePath();
  15264. this.stroke();
  15265. }
  15266. closeFillStroke() {
  15267. this.closePath();
  15268. this.fillStroke();
  15269. }
  15270. closeEOFillStroke() {
  15271. this.closePath();
  15272. this.eoFillStroke();
  15273. }
  15274. paintSolidColorImageMask() {
  15275. const rect = this.svgFactory.createElement("svg:rect");
  15276. rect.setAttributeNS(null, "x", "0");
  15277. rect.setAttributeNS(null, "y", "0");
  15278. rect.setAttributeNS(null, "width", "1px");
  15279. rect.setAttributeNS(null, "height", "1px");
  15280. rect.setAttributeNS(null, "fill", this.current.fillColor);
  15281. this._ensureTransformGroup().append(rect);
  15282. }
  15283. paintImageXObject(objId) {
  15284. const imgData = this.getObject(objId);
  15285. if (!imgData) {
  15286. (0, _util.warn)(`Dependent image with object ID ${objId} is not ready yet`);
  15287. return;
  15288. }
  15289. this.paintInlineImageXObject(imgData);
  15290. }
  15291. paintInlineImageXObject(imgData, mask) {
  15292. const width = imgData.width;
  15293. const height = imgData.height;
  15294. const imgSrc = convertImgDataToPng(imgData, this.forceDataSchema, !!mask);
  15295. const cliprect = this.svgFactory.createElement("svg:rect");
  15296. cliprect.setAttributeNS(null, "x", "0");
  15297. cliprect.setAttributeNS(null, "y", "0");
  15298. cliprect.setAttributeNS(null, "width", pf(width));
  15299. cliprect.setAttributeNS(null, "height", pf(height));
  15300. this.current.element = cliprect;
  15301. this.clip("nonzero");
  15302. const imgEl = this.svgFactory.createElement("svg:image");
  15303. imgEl.setAttributeNS(XLINK_NS, "xlink:href", imgSrc);
  15304. imgEl.setAttributeNS(null, "x", "0");
  15305. imgEl.setAttributeNS(null, "y", pf(-height));
  15306. imgEl.setAttributeNS(null, "width", pf(width) + "px");
  15307. imgEl.setAttributeNS(null, "height", pf(height) + "px");
  15308. imgEl.setAttributeNS(null, "transform", `scale(${pf(1 / width)} ${pf(-1 / height)})`);
  15309. if (mask) {
  15310. mask.append(imgEl);
  15311. } else {
  15312. this._ensureTransformGroup().append(imgEl);
  15313. }
  15314. }
  15315. paintImageMaskXObject(img) {
  15316. const imgData = this.getObject(img.data, img);
  15317. if (imgData.bitmap) {
  15318. (0, _util.warn)("paintImageMaskXObject: ImageBitmap support is not implemented, " + "ensure that the `isOffscreenCanvasSupported` API parameter is disabled.");
  15319. return;
  15320. }
  15321. const current = this.current;
  15322. const width = imgData.width;
  15323. const height = imgData.height;
  15324. const fillColor = current.fillColor;
  15325. current.maskId = `mask${maskCount++}`;
  15326. const mask = this.svgFactory.createElement("svg:mask");
  15327. mask.setAttributeNS(null, "id", current.maskId);
  15328. const rect = this.svgFactory.createElement("svg:rect");
  15329. rect.setAttributeNS(null, "x", "0");
  15330. rect.setAttributeNS(null, "y", "0");
  15331. rect.setAttributeNS(null, "width", pf(width));
  15332. rect.setAttributeNS(null, "height", pf(height));
  15333. rect.setAttributeNS(null, "fill", fillColor);
  15334. rect.setAttributeNS(null, "mask", `url(#${current.maskId})`);
  15335. this.defs.append(mask);
  15336. this._ensureTransformGroup().append(rect);
  15337. this.paintInlineImageXObject(imgData, mask);
  15338. }
  15339. paintFormXObjectBegin(matrix, bbox) {
  15340. if (Array.isArray(matrix) && matrix.length === 6) {
  15341. this.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
  15342. }
  15343. if (bbox) {
  15344. const width = bbox[2] - bbox[0];
  15345. const height = bbox[3] - bbox[1];
  15346. const cliprect = this.svgFactory.createElement("svg:rect");
  15347. cliprect.setAttributeNS(null, "x", bbox[0]);
  15348. cliprect.setAttributeNS(null, "y", bbox[1]);
  15349. cliprect.setAttributeNS(null, "width", pf(width));
  15350. cliprect.setAttributeNS(null, "height", pf(height));
  15351. this.current.element = cliprect;
  15352. this.clip("nonzero");
  15353. this.endPath();
  15354. }
  15355. }
  15356. paintFormXObjectEnd() {}
  15357. _initialize(viewport) {
  15358. const svg = this.svgFactory.create(viewport.width, viewport.height);
  15359. const definitions = this.svgFactory.createElement("svg:defs");
  15360. svg.append(definitions);
  15361. this.defs = definitions;
  15362. const rootGroup = this.svgFactory.createElement("svg:g");
  15363. rootGroup.setAttributeNS(null, "transform", pm(viewport.transform));
  15364. svg.append(rootGroup);
  15365. this.svg = rootGroup;
  15366. return svg;
  15367. }
  15368. _ensureClipGroup() {
  15369. if (!this.current.clipGroup) {
  15370. const clipGroup = this.svgFactory.createElement("svg:g");
  15371. clipGroup.setAttributeNS(null, "clip-path", this.current.activeClipUrl);
  15372. this.svg.append(clipGroup);
  15373. this.current.clipGroup = clipGroup;
  15374. }
  15375. return this.current.clipGroup;
  15376. }
  15377. _ensureTransformGroup() {
  15378. if (!this.tgrp) {
  15379. this.tgrp = this.svgFactory.createElement("svg:g");
  15380. this.tgrp.setAttributeNS(null, "transform", pm(this.transformMatrix));
  15381. if (this.current.activeClipUrl) {
  15382. this._ensureClipGroup().append(this.tgrp);
  15383. } else {
  15384. this.svg.append(this.tgrp);
  15385. }
  15386. }
  15387. return this.tgrp;
  15388. }
  15389. };
  15390. }
  15391. /***/ })
  15392. /******/ ]);
  15393. /************************************************************************/
  15394. /******/ // The module cache
  15395. /******/ var __webpack_module_cache__ = {};
  15396. /******/
  15397. /******/ // The require function
  15398. /******/ function __w_pdfjs_require__(moduleId) {
  15399. /******/ // Check if module is in cache
  15400. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  15401. /******/ if (cachedModule !== undefined) {
  15402. /******/ return cachedModule.exports;
  15403. /******/ }
  15404. /******/ // Create a new module (and put it into the cache)
  15405. /******/ var module = __webpack_module_cache__[moduleId] = {
  15406. /******/ // no module.id needed
  15407. /******/ // no module.loaded needed
  15408. /******/ exports: {}
  15409. /******/ };
  15410. /******/
  15411. /******/ // Execute the module function
  15412. /******/ __webpack_modules__[moduleId](module, module.exports, __w_pdfjs_require__);
  15413. /******/
  15414. /******/ // Return the exports of the module
  15415. /******/ return module.exports;
  15416. /******/ }
  15417. /******/
  15418. /************************************************************************/
  15419. var __webpack_exports__ = {};
  15420. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  15421. (() => {
  15422. var exports = __webpack_exports__;
  15423. Object.defineProperty(exports, "__esModule", ({
  15424. value: true
  15425. }));
  15426. Object.defineProperty(exports, "AbortException", ({
  15427. enumerable: true,
  15428. get: function () {
  15429. return _util.AbortException;
  15430. }
  15431. }));
  15432. Object.defineProperty(exports, "AnnotationEditorLayer", ({
  15433. enumerable: true,
  15434. get: function () {
  15435. return _annotation_editor_layer.AnnotationEditorLayer;
  15436. }
  15437. }));
  15438. Object.defineProperty(exports, "AnnotationEditorParamsType", ({
  15439. enumerable: true,
  15440. get: function () {
  15441. return _util.AnnotationEditorParamsType;
  15442. }
  15443. }));
  15444. Object.defineProperty(exports, "AnnotationEditorType", ({
  15445. enumerable: true,
  15446. get: function () {
  15447. return _util.AnnotationEditorType;
  15448. }
  15449. }));
  15450. Object.defineProperty(exports, "AnnotationEditorUIManager", ({
  15451. enumerable: true,
  15452. get: function () {
  15453. return _tools.AnnotationEditorUIManager;
  15454. }
  15455. }));
  15456. Object.defineProperty(exports, "AnnotationLayer", ({
  15457. enumerable: true,
  15458. get: function () {
  15459. return _annotation_layer.AnnotationLayer;
  15460. }
  15461. }));
  15462. Object.defineProperty(exports, "AnnotationMode", ({
  15463. enumerable: true,
  15464. get: function () {
  15465. return _util.AnnotationMode;
  15466. }
  15467. }));
  15468. Object.defineProperty(exports, "CMapCompressionType", ({
  15469. enumerable: true,
  15470. get: function () {
  15471. return _util.CMapCompressionType;
  15472. }
  15473. }));
  15474. Object.defineProperty(exports, "FeatureTest", ({
  15475. enumerable: true,
  15476. get: function () {
  15477. return _util.FeatureTest;
  15478. }
  15479. }));
  15480. Object.defineProperty(exports, "GlobalWorkerOptions", ({
  15481. enumerable: true,
  15482. get: function () {
  15483. return _worker_options.GlobalWorkerOptions;
  15484. }
  15485. }));
  15486. Object.defineProperty(exports, "InvalidPDFException", ({
  15487. enumerable: true,
  15488. get: function () {
  15489. return _util.InvalidPDFException;
  15490. }
  15491. }));
  15492. Object.defineProperty(exports, "MissingPDFException", ({
  15493. enumerable: true,
  15494. get: function () {
  15495. return _util.MissingPDFException;
  15496. }
  15497. }));
  15498. Object.defineProperty(exports, "OPS", ({
  15499. enumerable: true,
  15500. get: function () {
  15501. return _util.OPS;
  15502. }
  15503. }));
  15504. Object.defineProperty(exports, "PDFDataRangeTransport", ({
  15505. enumerable: true,
  15506. get: function () {
  15507. return _api.PDFDataRangeTransport;
  15508. }
  15509. }));
  15510. Object.defineProperty(exports, "PDFDateString", ({
  15511. enumerable: true,
  15512. get: function () {
  15513. return _display_utils.PDFDateString;
  15514. }
  15515. }));
  15516. Object.defineProperty(exports, "PDFWorker", ({
  15517. enumerable: true,
  15518. get: function () {
  15519. return _api.PDFWorker;
  15520. }
  15521. }));
  15522. Object.defineProperty(exports, "PasswordResponses", ({
  15523. enumerable: true,
  15524. get: function () {
  15525. return _util.PasswordResponses;
  15526. }
  15527. }));
  15528. Object.defineProperty(exports, "PermissionFlag", ({
  15529. enumerable: true,
  15530. get: function () {
  15531. return _util.PermissionFlag;
  15532. }
  15533. }));
  15534. Object.defineProperty(exports, "PixelsPerInch", ({
  15535. enumerable: true,
  15536. get: function () {
  15537. return _display_utils.PixelsPerInch;
  15538. }
  15539. }));
  15540. Object.defineProperty(exports, "PromiseCapability", ({
  15541. enumerable: true,
  15542. get: function () {
  15543. return _util.PromiseCapability;
  15544. }
  15545. }));
  15546. Object.defineProperty(exports, "RenderingCancelledException", ({
  15547. enumerable: true,
  15548. get: function () {
  15549. return _display_utils.RenderingCancelledException;
  15550. }
  15551. }));
  15552. Object.defineProperty(exports, "SVGGraphics", ({
  15553. enumerable: true,
  15554. get: function () {
  15555. return _svg.SVGGraphics;
  15556. }
  15557. }));
  15558. Object.defineProperty(exports, "UnexpectedResponseException", ({
  15559. enumerable: true,
  15560. get: function () {
  15561. return _util.UnexpectedResponseException;
  15562. }
  15563. }));
  15564. Object.defineProperty(exports, "Util", ({
  15565. enumerable: true,
  15566. get: function () {
  15567. return _util.Util;
  15568. }
  15569. }));
  15570. Object.defineProperty(exports, "VerbosityLevel", ({
  15571. enumerable: true,
  15572. get: function () {
  15573. return _util.VerbosityLevel;
  15574. }
  15575. }));
  15576. Object.defineProperty(exports, "XfaLayer", ({
  15577. enumerable: true,
  15578. get: function () {
  15579. return _xfa_layer.XfaLayer;
  15580. }
  15581. }));
  15582. Object.defineProperty(exports, "build", ({
  15583. enumerable: true,
  15584. get: function () {
  15585. return _api.build;
  15586. }
  15587. }));
  15588. Object.defineProperty(exports, "createValidAbsoluteUrl", ({
  15589. enumerable: true,
  15590. get: function () {
  15591. return _util.createValidAbsoluteUrl;
  15592. }
  15593. }));
  15594. Object.defineProperty(exports, "getDocument", ({
  15595. enumerable: true,
  15596. get: function () {
  15597. return _api.getDocument;
  15598. }
  15599. }));
  15600. Object.defineProperty(exports, "getFilenameFromUrl", ({
  15601. enumerable: true,
  15602. get: function () {
  15603. return _display_utils.getFilenameFromUrl;
  15604. }
  15605. }));
  15606. Object.defineProperty(exports, "getPdfFilenameFromUrl", ({
  15607. enumerable: true,
  15608. get: function () {
  15609. return _display_utils.getPdfFilenameFromUrl;
  15610. }
  15611. }));
  15612. Object.defineProperty(exports, "getXfaPageViewport", ({
  15613. enumerable: true,
  15614. get: function () {
  15615. return _display_utils.getXfaPageViewport;
  15616. }
  15617. }));
  15618. Object.defineProperty(exports, "isDataScheme", ({
  15619. enumerable: true,
  15620. get: function () {
  15621. return _display_utils.isDataScheme;
  15622. }
  15623. }));
  15624. Object.defineProperty(exports, "isPdfFile", ({
  15625. enumerable: true,
  15626. get: function () {
  15627. return _display_utils.isPdfFile;
  15628. }
  15629. }));
  15630. Object.defineProperty(exports, "loadScript", ({
  15631. enumerable: true,
  15632. get: function () {
  15633. return _display_utils.loadScript;
  15634. }
  15635. }));
  15636. Object.defineProperty(exports, "normalizeUnicode", ({
  15637. enumerable: true,
  15638. get: function () {
  15639. return _util.normalizeUnicode;
  15640. }
  15641. }));
  15642. Object.defineProperty(exports, "renderTextLayer", ({
  15643. enumerable: true,
  15644. get: function () {
  15645. return _text_layer.renderTextLayer;
  15646. }
  15647. }));
  15648. Object.defineProperty(exports, "setLayerDimensions", ({
  15649. enumerable: true,
  15650. get: function () {
  15651. return _display_utils.setLayerDimensions;
  15652. }
  15653. }));
  15654. Object.defineProperty(exports, "shadow", ({
  15655. enumerable: true,
  15656. get: function () {
  15657. return _util.shadow;
  15658. }
  15659. }));
  15660. Object.defineProperty(exports, "updateTextLayer", ({
  15661. enumerable: true,
  15662. get: function () {
  15663. return _text_layer.updateTextLayer;
  15664. }
  15665. }));
  15666. Object.defineProperty(exports, "version", ({
  15667. enumerable: true,
  15668. get: function () {
  15669. return _api.version;
  15670. }
  15671. }));
  15672. var _util = __w_pdfjs_require__(1);
  15673. var _api = __w_pdfjs_require__(2);
  15674. var _display_utils = __w_pdfjs_require__(6);
  15675. var _text_layer = __w_pdfjs_require__(26);
  15676. var _annotation_editor_layer = __w_pdfjs_require__(27);
  15677. var _tools = __w_pdfjs_require__(5);
  15678. var _annotation_layer = __w_pdfjs_require__(30);
  15679. var _worker_options = __w_pdfjs_require__(14);
  15680. var _svg = __w_pdfjs_require__(33);
  15681. var _xfa_layer = __w_pdfjs_require__(32);
  15682. const pdfjsVersion = '3.7.107';
  15683. const pdfjsBuild = '036f855dc';
  15684. })();
  15685. /******/ return __webpack_exports__;
  15686. /******/ })()
  15687. ;
  15688. });
  15689. //# sourceMappingURL=pdf.js.map