pdf.js 490 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821
  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.UNSUPPORTED_FEATURES = exports.TextRenderingMode = exports.RenderingIntentFlag = exports.PermissionFlag = exports.PasswordResponses = exports.PasswordException = exports.PageActionEventType = exports.OPS = exports.MissingPDFException = 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.arrayByteLength = arrayByteLength;
  43. exports.arraysToBytes = arraysToBytes;
  44. exports.assert = assert;
  45. exports.bytesToString = bytesToString;
  46. exports.createPromiseCapability = createPromiseCapability;
  47. exports.createValidAbsoluteUrl = createValidAbsoluteUrl;
  48. exports.getModificationDate = getModificationDate;
  49. exports.getVerbosityLevel = getVerbosityLevel;
  50. exports.info = info;
  51. exports.isArrayBuffer = isArrayBuffer;
  52. exports.isArrayEqual = isArrayEqual;
  53. exports.objectFromMap = objectFromMap;
  54. exports.objectSize = objectSize;
  55. exports.setVerbosityLevel = setVerbosityLevel;
  56. exports.shadow = shadow;
  57. exports.string32 = string32;
  58. exports.stringToBytes = stringToBytes;
  59. exports.stringToPDFString = stringToPDFString;
  60. exports.stringToUTF8String = stringToUTF8String;
  61. exports.unreachable = unreachable;
  62. exports.utf8StringToString = utf8StringToString;
  63. exports.warn = warn;
  64. ;
  65. const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  66. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  67. const FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  68. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  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 UNSUPPORTED_FEATURES = {
  369. forms: "forms",
  370. javaScript: "javaScript",
  371. signatures: "signatures",
  372. smask: "smask",
  373. shadingPattern: "shadingPattern",
  374. errorTilingPattern: "errorTilingPattern",
  375. errorExtGState: "errorExtGState",
  376. errorXObject: "errorXObject",
  377. errorFontLoadType3: "errorFontLoadType3",
  378. errorFontState: "errorFontState",
  379. errorFontMissing: "errorFontMissing",
  380. errorFontTranslate: "errorFontTranslate",
  381. errorColorSpace: "errorColorSpace",
  382. errorOperatorList: "errorOperatorList",
  383. errorFontToUnicode: "errorFontToUnicode",
  384. errorFontLoadNative: "errorFontLoadNative",
  385. errorFontBuildPath: "errorFontBuildPath",
  386. errorFontGetPath: "errorFontGetPath",
  387. errorMarkedContent: "errorMarkedContent",
  388. errorContentSubStream: "errorContentSubStream"
  389. };
  390. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  391. const PasswordResponses = {
  392. NEED_PASSWORD: 1,
  393. INCORRECT_PASSWORD: 2
  394. };
  395. exports.PasswordResponses = PasswordResponses;
  396. let verbosity = VerbosityLevel.WARNINGS;
  397. function setVerbosityLevel(level) {
  398. if (Number.isInteger(level)) {
  399. verbosity = level;
  400. }
  401. }
  402. function getVerbosityLevel() {
  403. return verbosity;
  404. }
  405. function info(msg) {
  406. if (verbosity >= VerbosityLevel.INFOS) {
  407. console.log(`Info: ${msg}`);
  408. }
  409. }
  410. function warn(msg) {
  411. if (verbosity >= VerbosityLevel.WARNINGS) {
  412. console.log(`Warning: ${msg}`);
  413. }
  414. }
  415. function unreachable(msg) {
  416. throw new Error(msg);
  417. }
  418. function assert(cond, msg) {
  419. if (!cond) {
  420. unreachable(msg);
  421. }
  422. }
  423. function _isValidProtocol(url) {
  424. if (!url) {
  425. return false;
  426. }
  427. switch (url.protocol) {
  428. case "http:":
  429. case "https:":
  430. case "ftp:":
  431. case "mailto:":
  432. case "tel:":
  433. return true;
  434. default:
  435. return false;
  436. }
  437. }
  438. function createValidAbsoluteUrl(url, baseUrl = null, options = null) {
  439. if (!url) {
  440. return null;
  441. }
  442. try {
  443. if (options && typeof url === "string") {
  444. if (options.addDefaultProtocol && url.startsWith("www.")) {
  445. const dots = url.match(/\./g);
  446. if (dots && dots.length >= 2) {
  447. url = `http://${url}`;
  448. }
  449. }
  450. if (options.tryConvertEncoding) {
  451. try {
  452. url = stringToUTF8String(url);
  453. } catch (ex) {}
  454. }
  455. }
  456. const absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url);
  457. if (_isValidProtocol(absoluteUrl)) {
  458. return absoluteUrl;
  459. }
  460. } catch (ex) {}
  461. return null;
  462. }
  463. function shadow(obj, prop, value, nonSerializable = false) {
  464. Object.defineProperty(obj, prop, {
  465. value,
  466. enumerable: !nonSerializable,
  467. configurable: true,
  468. writable: false
  469. });
  470. return value;
  471. }
  472. const BaseException = function BaseExceptionClosure() {
  473. function BaseException(message, name) {
  474. if (this.constructor === BaseException) {
  475. unreachable("Cannot initialize BaseException.");
  476. }
  477. this.message = message;
  478. this.name = name;
  479. }
  480. BaseException.prototype = new Error();
  481. BaseException.constructor = BaseException;
  482. return BaseException;
  483. }();
  484. exports.BaseException = BaseException;
  485. class PasswordException extends BaseException {
  486. constructor(msg, code) {
  487. super(msg, "PasswordException");
  488. this.code = code;
  489. }
  490. }
  491. exports.PasswordException = PasswordException;
  492. class UnknownErrorException extends BaseException {
  493. constructor(msg, details) {
  494. super(msg, "UnknownErrorException");
  495. this.details = details;
  496. }
  497. }
  498. exports.UnknownErrorException = UnknownErrorException;
  499. class InvalidPDFException extends BaseException {
  500. constructor(msg) {
  501. super(msg, "InvalidPDFException");
  502. }
  503. }
  504. exports.InvalidPDFException = InvalidPDFException;
  505. class MissingPDFException extends BaseException {
  506. constructor(msg) {
  507. super(msg, "MissingPDFException");
  508. }
  509. }
  510. exports.MissingPDFException = MissingPDFException;
  511. class UnexpectedResponseException extends BaseException {
  512. constructor(msg, status) {
  513. super(msg, "UnexpectedResponseException");
  514. this.status = status;
  515. }
  516. }
  517. exports.UnexpectedResponseException = UnexpectedResponseException;
  518. class FormatError extends BaseException {
  519. constructor(msg) {
  520. super(msg, "FormatError");
  521. }
  522. }
  523. exports.FormatError = FormatError;
  524. class AbortException extends BaseException {
  525. constructor(msg) {
  526. super(msg, "AbortException");
  527. }
  528. }
  529. exports.AbortException = AbortException;
  530. function bytesToString(bytes) {
  531. if (typeof bytes !== "object" || bytes === null || bytes.length === undefined) {
  532. unreachable("Invalid argument for bytesToString");
  533. }
  534. const length = bytes.length;
  535. const MAX_ARGUMENT_COUNT = 8192;
  536. if (length < MAX_ARGUMENT_COUNT) {
  537. return String.fromCharCode.apply(null, bytes);
  538. }
  539. const strBuf = [];
  540. for (let i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  541. const chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  542. const chunk = bytes.subarray(i, chunkEnd);
  543. strBuf.push(String.fromCharCode.apply(null, chunk));
  544. }
  545. return strBuf.join("");
  546. }
  547. function stringToBytes(str) {
  548. if (typeof str !== "string") {
  549. unreachable("Invalid argument for stringToBytes");
  550. }
  551. const length = str.length;
  552. const bytes = new Uint8Array(length);
  553. for (let i = 0; i < length; ++i) {
  554. bytes[i] = str.charCodeAt(i) & 0xff;
  555. }
  556. return bytes;
  557. }
  558. function arrayByteLength(arr) {
  559. if (arr.length !== undefined) {
  560. return arr.length;
  561. }
  562. if (arr.byteLength !== undefined) {
  563. return arr.byteLength;
  564. }
  565. unreachable("Invalid argument for arrayByteLength");
  566. }
  567. function arraysToBytes(arr) {
  568. const length = arr.length;
  569. if (length === 1 && arr[0] instanceof Uint8Array) {
  570. return arr[0];
  571. }
  572. let resultLength = 0;
  573. for (let i = 0; i < length; i++) {
  574. resultLength += arrayByteLength(arr[i]);
  575. }
  576. let pos = 0;
  577. const data = new Uint8Array(resultLength);
  578. for (let i = 0; i < length; i++) {
  579. let item = arr[i];
  580. if (!(item instanceof Uint8Array)) {
  581. if (typeof item === "string") {
  582. item = stringToBytes(item);
  583. } else {
  584. item = new Uint8Array(item);
  585. }
  586. }
  587. const itemLength = item.byteLength;
  588. data.set(item, pos);
  589. pos += itemLength;
  590. }
  591. return data;
  592. }
  593. function string32(value) {
  594. return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
  595. }
  596. function objectSize(obj) {
  597. return Object.keys(obj).length;
  598. }
  599. function objectFromMap(map) {
  600. const obj = Object.create(null);
  601. for (const [key, value] of map) {
  602. obj[key] = value;
  603. }
  604. return obj;
  605. }
  606. function isLittleEndian() {
  607. const buffer8 = new Uint8Array(4);
  608. buffer8[0] = 1;
  609. const view32 = new Uint32Array(buffer8.buffer, 0, 1);
  610. return view32[0] === 1;
  611. }
  612. function isEvalSupported() {
  613. try {
  614. new Function("");
  615. return true;
  616. } catch (e) {
  617. return false;
  618. }
  619. }
  620. class FeatureTest {
  621. static get isLittleEndian() {
  622. return shadow(this, "isLittleEndian", isLittleEndian());
  623. }
  624. static get isEvalSupported() {
  625. return shadow(this, "isEvalSupported", isEvalSupported());
  626. }
  627. static get isOffscreenCanvasSupported() {
  628. return shadow(this, "isOffscreenCanvasSupported", typeof OffscreenCanvas !== "undefined");
  629. }
  630. static get platform() {
  631. if (typeof navigator === "undefined") {
  632. return shadow(this, "platform", {
  633. isWin: false,
  634. isMac: false
  635. });
  636. }
  637. return shadow(this, "platform", {
  638. isWin: navigator.platform.includes("Win"),
  639. isMac: navigator.platform.includes("Mac")
  640. });
  641. }
  642. }
  643. exports.FeatureTest = FeatureTest;
  644. const hexNumbers = [...Array(256).keys()].map(n => n.toString(16).padStart(2, "0"));
  645. class Util {
  646. static makeHexColor(r, g, b) {
  647. return `#${hexNumbers[r]}${hexNumbers[g]}${hexNumbers[b]}`;
  648. }
  649. static scaleMinMax(transform, minMax) {
  650. let temp;
  651. if (transform[0]) {
  652. if (transform[0] < 0) {
  653. temp = minMax[0];
  654. minMax[0] = minMax[1];
  655. minMax[1] = temp;
  656. }
  657. minMax[0] *= transform[0];
  658. minMax[1] *= transform[0];
  659. if (transform[3] < 0) {
  660. temp = minMax[2];
  661. minMax[2] = minMax[3];
  662. minMax[3] = temp;
  663. }
  664. minMax[2] *= transform[3];
  665. minMax[3] *= transform[3];
  666. } else {
  667. temp = minMax[0];
  668. minMax[0] = minMax[2];
  669. minMax[2] = temp;
  670. temp = minMax[1];
  671. minMax[1] = minMax[3];
  672. minMax[3] = temp;
  673. if (transform[1] < 0) {
  674. temp = minMax[2];
  675. minMax[2] = minMax[3];
  676. minMax[3] = temp;
  677. }
  678. minMax[2] *= transform[1];
  679. minMax[3] *= transform[1];
  680. if (transform[2] < 0) {
  681. temp = minMax[0];
  682. minMax[0] = minMax[1];
  683. minMax[1] = temp;
  684. }
  685. minMax[0] *= transform[2];
  686. minMax[1] *= transform[2];
  687. }
  688. minMax[0] += transform[4];
  689. minMax[1] += transform[4];
  690. minMax[2] += transform[5];
  691. minMax[3] += transform[5];
  692. }
  693. static transform(m1, m2) {
  694. 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]];
  695. }
  696. static applyTransform(p, m) {
  697. const xt = p[0] * m[0] + p[1] * m[2] + m[4];
  698. const yt = p[0] * m[1] + p[1] * m[3] + m[5];
  699. return [xt, yt];
  700. }
  701. static applyInverseTransform(p, m) {
  702. const d = m[0] * m[3] - m[1] * m[2];
  703. const xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  704. const yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  705. return [xt, yt];
  706. }
  707. static getAxialAlignedBoundingBox(r, m) {
  708. const p1 = Util.applyTransform(r, m);
  709. const p2 = Util.applyTransform(r.slice(2, 4), m);
  710. const p3 = Util.applyTransform([r[0], r[3]], m);
  711. const p4 = Util.applyTransform([r[2], r[1]], m);
  712. 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])];
  713. }
  714. static inverseTransform(m) {
  715. const d = m[0] * m[3] - m[1] * m[2];
  716. 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];
  717. }
  718. static singularValueDecompose2dScale(m) {
  719. const transpose = [m[0], m[2], m[1], m[3]];
  720. const a = m[0] * transpose[0] + m[1] * transpose[2];
  721. const b = m[0] * transpose[1] + m[1] * transpose[3];
  722. const c = m[2] * transpose[0] + m[3] * transpose[2];
  723. const d = m[2] * transpose[1] + m[3] * transpose[3];
  724. const first = (a + d) / 2;
  725. const second = Math.sqrt((a + d) ** 2 - 4 * (a * d - c * b)) / 2;
  726. const sx = first + second || 1;
  727. const sy = first - second || 1;
  728. return [Math.sqrt(sx), Math.sqrt(sy)];
  729. }
  730. static normalizeRect(rect) {
  731. const r = rect.slice(0);
  732. if (rect[0] > rect[2]) {
  733. r[0] = rect[2];
  734. r[2] = rect[0];
  735. }
  736. if (rect[1] > rect[3]) {
  737. r[1] = rect[3];
  738. r[3] = rect[1];
  739. }
  740. return r;
  741. }
  742. static intersect(rect1, rect2) {
  743. const xLow = Math.max(Math.min(rect1[0], rect1[2]), Math.min(rect2[0], rect2[2]));
  744. const xHigh = Math.min(Math.max(rect1[0], rect1[2]), Math.max(rect2[0], rect2[2]));
  745. if (xLow > xHigh) {
  746. return null;
  747. }
  748. const yLow = Math.max(Math.min(rect1[1], rect1[3]), Math.min(rect2[1], rect2[3]));
  749. const yHigh = Math.min(Math.max(rect1[1], rect1[3]), Math.max(rect2[1], rect2[3]));
  750. if (yLow > yHigh) {
  751. return null;
  752. }
  753. return [xLow, yLow, xHigh, yHigh];
  754. }
  755. static bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3) {
  756. const tvalues = [],
  757. bounds = [[], []];
  758. let a, b, c, t, t1, t2, b2ac, sqrtb2ac;
  759. for (let i = 0; i < 2; ++i) {
  760. if (i === 0) {
  761. b = 6 * x0 - 12 * x1 + 6 * x2;
  762. a = -3 * x0 + 9 * x1 - 9 * x2 + 3 * x3;
  763. c = 3 * x1 - 3 * x0;
  764. } else {
  765. b = 6 * y0 - 12 * y1 + 6 * y2;
  766. a = -3 * y0 + 9 * y1 - 9 * y2 + 3 * y3;
  767. c = 3 * y1 - 3 * y0;
  768. }
  769. if (Math.abs(a) < 1e-12) {
  770. if (Math.abs(b) < 1e-12) {
  771. continue;
  772. }
  773. t = -c / b;
  774. if (0 < t && t < 1) {
  775. tvalues.push(t);
  776. }
  777. continue;
  778. }
  779. b2ac = b * b - 4 * c * a;
  780. sqrtb2ac = Math.sqrt(b2ac);
  781. if (b2ac < 0) {
  782. continue;
  783. }
  784. t1 = (-b + sqrtb2ac) / (2 * a);
  785. if (0 < t1 && t1 < 1) {
  786. tvalues.push(t1);
  787. }
  788. t2 = (-b - sqrtb2ac) / (2 * a);
  789. if (0 < t2 && t2 < 1) {
  790. tvalues.push(t2);
  791. }
  792. }
  793. let j = tvalues.length,
  794. mt;
  795. const jlen = j;
  796. while (j--) {
  797. t = tvalues[j];
  798. mt = 1 - t;
  799. bounds[0][j] = mt * mt * mt * x0 + 3 * mt * mt * t * x1 + 3 * mt * t * t * x2 + t * t * t * x3;
  800. bounds[1][j] = mt * mt * mt * y0 + 3 * mt * mt * t * y1 + 3 * mt * t * t * y2 + t * t * t * y3;
  801. }
  802. bounds[0][jlen] = x0;
  803. bounds[1][jlen] = y0;
  804. bounds[0][jlen + 1] = x3;
  805. bounds[1][jlen + 1] = y3;
  806. bounds[0].length = bounds[1].length = jlen + 2;
  807. return [Math.min(...bounds[0]), Math.min(...bounds[1]), Math.max(...bounds[0]), Math.max(...bounds[1])];
  808. }
  809. }
  810. exports.Util = Util;
  811. 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];
  812. function stringToPDFString(str) {
  813. if (str[0] >= "\xEF") {
  814. let encoding;
  815. if (str[0] === "\xFE" && str[1] === "\xFF") {
  816. encoding = "utf-16be";
  817. } else if (str[0] === "\xFF" && str[1] === "\xFE") {
  818. encoding = "utf-16le";
  819. } else if (str[0] === "\xEF" && str[1] === "\xBB" && str[2] === "\xBF") {
  820. encoding = "utf-8";
  821. }
  822. if (encoding) {
  823. try {
  824. const decoder = new TextDecoder(encoding, {
  825. fatal: true
  826. });
  827. const buffer = stringToBytes(str);
  828. return decoder.decode(buffer);
  829. } catch (ex) {
  830. warn(`stringToPDFString: "${ex}".`);
  831. }
  832. }
  833. }
  834. const strBuf = [];
  835. for (let i = 0, ii = str.length; i < ii; i++) {
  836. const code = PDFStringTranslateTable[str.charCodeAt(i)];
  837. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  838. }
  839. return strBuf.join("");
  840. }
  841. function stringToUTF8String(str) {
  842. return decodeURIComponent(escape(str));
  843. }
  844. function utf8StringToString(str) {
  845. return unescape(encodeURIComponent(str));
  846. }
  847. function isArrayBuffer(v) {
  848. return typeof v === "object" && v !== null && v.byteLength !== undefined;
  849. }
  850. function isArrayEqual(arr1, arr2) {
  851. if (arr1.length !== arr2.length) {
  852. return false;
  853. }
  854. for (let i = 0, ii = arr1.length; i < ii; i++) {
  855. if (arr1[i] !== arr2[i]) {
  856. return false;
  857. }
  858. }
  859. return true;
  860. }
  861. function getModificationDate(date = new Date()) {
  862. 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")];
  863. return buffer.join("");
  864. }
  865. function createPromiseCapability() {
  866. const capability = Object.create(null);
  867. let isSettled = false;
  868. Object.defineProperty(capability, "settled", {
  869. get() {
  870. return isSettled;
  871. }
  872. });
  873. capability.promise = new Promise(function (resolve, reject) {
  874. capability.resolve = function (data) {
  875. isSettled = true;
  876. resolve(data);
  877. };
  878. capability.reject = function (reason) {
  879. isSettled = true;
  880. reject(reason);
  881. };
  882. });
  883. return capability;
  884. }
  885. /***/ }),
  886. /* 2 */
  887. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  888. Object.defineProperty(exports, "__esModule", ({
  889. value: true
  890. }));
  891. exports.build = exports.RenderTask = exports.PDFWorkerUtil = exports.PDFWorker = exports.PDFPageProxy = exports.PDFDocumentProxy = exports.PDFDocumentLoadingTask = exports.PDFDataRangeTransport = exports.LoopbackPort = exports.DefaultStandardFontDataFactory = exports.DefaultCanvasFactory = exports.DefaultCMapReaderFactory = void 0;
  892. exports.getDocument = getDocument;
  893. exports.version = void 0;
  894. var _util = __w_pdfjs_require__(1);
  895. var _annotation_storage = __w_pdfjs_require__(3);
  896. var _display_utils = __w_pdfjs_require__(6);
  897. var _font_loader = __w_pdfjs_require__(9);
  898. var _canvas = __w_pdfjs_require__(11);
  899. var _worker_options = __w_pdfjs_require__(14);
  900. var _is_node = __w_pdfjs_require__(10);
  901. var _message_handler = __w_pdfjs_require__(15);
  902. var _metadata = __w_pdfjs_require__(16);
  903. var _optional_content_config = __w_pdfjs_require__(17);
  904. var _transport_stream = __w_pdfjs_require__(18);
  905. var _xfa_text = __w_pdfjs_require__(19);
  906. const DEFAULT_RANGE_CHUNK_SIZE = 65536;
  907. const RENDERING_CANCELLED_TIMEOUT = 100;
  908. let DefaultCanvasFactory = _display_utils.DOMCanvasFactory;
  909. exports.DefaultCanvasFactory = DefaultCanvasFactory;
  910. let DefaultCMapReaderFactory = _display_utils.DOMCMapReaderFactory;
  911. exports.DefaultCMapReaderFactory = DefaultCMapReaderFactory;
  912. let DefaultStandardFontDataFactory = _display_utils.DOMStandardFontDataFactory;
  913. exports.DefaultStandardFontDataFactory = DefaultStandardFontDataFactory;
  914. if (_is_node.isNodeJS) {
  915. const {
  916. NodeCanvasFactory,
  917. NodeCMapReaderFactory,
  918. NodeStandardFontDataFactory
  919. } = __w_pdfjs_require__(20);
  920. exports.DefaultCanvasFactory = DefaultCanvasFactory = NodeCanvasFactory;
  921. exports.DefaultCMapReaderFactory = DefaultCMapReaderFactory = NodeCMapReaderFactory;
  922. exports.DefaultStandardFontDataFactory = DefaultStandardFontDataFactory = NodeStandardFontDataFactory;
  923. }
  924. let createPDFNetworkStream;
  925. {
  926. if (_is_node.isNodeJS) {
  927. const {
  928. PDFNodeStream
  929. } = __w_pdfjs_require__(21);
  930. createPDFNetworkStream = params => {
  931. return new PDFNodeStream(params);
  932. };
  933. } else {
  934. const {
  935. PDFNetworkStream
  936. } = __w_pdfjs_require__(24);
  937. const {
  938. PDFFetchStream
  939. } = __w_pdfjs_require__(25);
  940. createPDFNetworkStream = params => {
  941. return (0, _display_utils.isValidFetchUrl)(params.url) ? new PDFFetchStream(params) : new PDFNetworkStream(params);
  942. };
  943. }
  944. }
  945. function getDocument(src) {
  946. if (typeof src === "string" || src instanceof URL) {
  947. src = {
  948. url: src
  949. };
  950. } else if ((0, _util.isArrayBuffer)(src)) {
  951. src = {
  952. data: src
  953. };
  954. } else if (src instanceof PDFDataRangeTransport) {
  955. (0, _display_utils.deprecated)("`PDFDataRangeTransport`-instance, " + "please use a parameter object with `range`-property instead.");
  956. src = {
  957. range: src
  958. };
  959. } else {
  960. if (typeof src !== "object") {
  961. throw new Error("Invalid parameter in getDocument, " + "need either string, URL, TypedArray, or parameter object.");
  962. }
  963. }
  964. if (!src.url && !src.data && !src.range) {
  965. throw new Error("Invalid parameter object: need either .data, .range or .url");
  966. }
  967. const task = new PDFDocumentLoadingTask();
  968. const params = Object.create(null);
  969. let rangeTransport = null,
  970. worker = null;
  971. for (const key in src) {
  972. const val = src[key];
  973. switch (key) {
  974. case "url":
  975. if (val instanceof URL) {
  976. params[key] = val.href;
  977. continue;
  978. }
  979. try {
  980. params[key] = new URL(val, window.location).href;
  981. continue;
  982. } catch (ex) {
  983. if (_is_node.isNodeJS && typeof val === "string") {
  984. break;
  985. }
  986. }
  987. throw new Error("Invalid PDF url data: " + "either string or URL-object is expected in the url property.");
  988. case "range":
  989. rangeTransport = val;
  990. continue;
  991. case "worker":
  992. worker = val;
  993. continue;
  994. case "data":
  995. if (_is_node.isNodeJS && typeof Buffer !== "undefined" && val instanceof Buffer) {
  996. params[key] = new Uint8Array(val);
  997. } else if (val instanceof Uint8Array && val.byteLength === val.buffer.byteLength) {
  998. break;
  999. } else if (typeof val === "string") {
  1000. params[key] = (0, _util.stringToBytes)(val);
  1001. } else if (typeof val === "object" && val !== null && !isNaN(val.length) || (0, _util.isArrayBuffer)(val)) {
  1002. params[key] = new Uint8Array(val);
  1003. } else {
  1004. throw new Error("Invalid PDF binary data: either TypedArray, " + "string, or array-like object is expected in the data property.");
  1005. }
  1006. continue;
  1007. }
  1008. params[key] = val;
  1009. }
  1010. params.CMapReaderFactory = params.CMapReaderFactory || DefaultCMapReaderFactory;
  1011. params.StandardFontDataFactory = params.StandardFontDataFactory || DefaultStandardFontDataFactory;
  1012. params.ignoreErrors = params.stopAtErrors !== true;
  1013. params.fontExtraProperties = params.fontExtraProperties === true;
  1014. params.pdfBug = params.pdfBug === true;
  1015. params.enableXfa = params.enableXfa === true;
  1016. if (!Number.isInteger(params.rangeChunkSize) || params.rangeChunkSize < 1) {
  1017. params.rangeChunkSize = DEFAULT_RANGE_CHUNK_SIZE;
  1018. }
  1019. if (typeof params.docBaseUrl !== "string" || (0, _display_utils.isDataScheme)(params.docBaseUrl)) {
  1020. params.docBaseUrl = null;
  1021. }
  1022. if (!Number.isInteger(params.maxImageSize) || params.maxImageSize < -1) {
  1023. params.maxImageSize = -1;
  1024. }
  1025. if (typeof params.cMapUrl !== "string") {
  1026. params.cMapUrl = null;
  1027. }
  1028. if (typeof params.standardFontDataUrl !== "string") {
  1029. params.standardFontDataUrl = null;
  1030. }
  1031. if (typeof params.useWorkerFetch !== "boolean") {
  1032. params.useWorkerFetch = params.CMapReaderFactory === _display_utils.DOMCMapReaderFactory && params.StandardFontDataFactory === _display_utils.DOMStandardFontDataFactory && (0, _display_utils.isValidFetchUrl)(params.cMapUrl, document.baseURI) && (0, _display_utils.isValidFetchUrl)(params.standardFontDataUrl, document.baseURI);
  1033. }
  1034. if (typeof params.isEvalSupported !== "boolean") {
  1035. params.isEvalSupported = true;
  1036. }
  1037. if (typeof params.isOffscreenCanvasSupported !== "boolean") {
  1038. params.isOffscreenCanvasSupported = !_is_node.isNodeJS;
  1039. }
  1040. if (typeof params.disableFontFace !== "boolean") {
  1041. params.disableFontFace = _is_node.isNodeJS;
  1042. }
  1043. if (typeof params.useSystemFonts !== "boolean") {
  1044. params.useSystemFonts = !_is_node.isNodeJS && !params.disableFontFace;
  1045. }
  1046. if (typeof params.ownerDocument !== "object" || params.ownerDocument === null) {
  1047. params.ownerDocument = globalThis.document;
  1048. }
  1049. if (typeof params.disableRange !== "boolean") {
  1050. params.disableRange = false;
  1051. }
  1052. if (typeof params.disableStream !== "boolean") {
  1053. params.disableStream = false;
  1054. }
  1055. if (typeof params.disableAutoFetch !== "boolean") {
  1056. params.disableAutoFetch = false;
  1057. }
  1058. (0, _util.setVerbosityLevel)(params.verbosity);
  1059. if (!worker) {
  1060. const workerParams = {
  1061. verbosity: params.verbosity,
  1062. port: _worker_options.GlobalWorkerOptions.workerPort
  1063. };
  1064. worker = workerParams.port ? PDFWorker.fromPort(workerParams) : new PDFWorker(workerParams);
  1065. task._worker = worker;
  1066. }
  1067. const docId = task.docId;
  1068. worker.promise.then(function () {
  1069. if (task.destroyed) {
  1070. throw new Error("Loading aborted");
  1071. }
  1072. const workerIdPromise = _fetchDocument(worker, params, rangeTransport, docId);
  1073. const networkStreamPromise = new Promise(function (resolve) {
  1074. let networkStream;
  1075. if (rangeTransport) {
  1076. networkStream = new _transport_stream.PDFDataTransportStream({
  1077. length: params.length,
  1078. initialData: params.initialData,
  1079. progressiveDone: params.progressiveDone,
  1080. contentDispositionFilename: params.contentDispositionFilename,
  1081. disableRange: params.disableRange,
  1082. disableStream: params.disableStream
  1083. }, rangeTransport);
  1084. } else if (!params.data) {
  1085. networkStream = createPDFNetworkStream({
  1086. url: params.url,
  1087. length: params.length,
  1088. httpHeaders: params.httpHeaders,
  1089. withCredentials: params.withCredentials,
  1090. rangeChunkSize: params.rangeChunkSize,
  1091. disableRange: params.disableRange,
  1092. disableStream: params.disableStream
  1093. });
  1094. }
  1095. resolve(networkStream);
  1096. });
  1097. return Promise.all([workerIdPromise, networkStreamPromise]).then(function ([workerId, networkStream]) {
  1098. if (task.destroyed) {
  1099. throw new Error("Loading aborted");
  1100. }
  1101. const messageHandler = new _message_handler.MessageHandler(docId, workerId, worker.port);
  1102. const transport = new WorkerTransport(messageHandler, task, networkStream, params);
  1103. task._transport = transport;
  1104. messageHandler.send("Ready", null);
  1105. });
  1106. }).catch(task._capability.reject);
  1107. return task;
  1108. }
  1109. async function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
  1110. if (worker.destroyed) {
  1111. throw new Error("Worker was destroyed");
  1112. }
  1113. if (pdfDataRangeTransport) {
  1114. source.length = pdfDataRangeTransport.length;
  1115. source.initialData = pdfDataRangeTransport.initialData;
  1116. source.progressiveDone = pdfDataRangeTransport.progressiveDone;
  1117. source.contentDispositionFilename = pdfDataRangeTransport.contentDispositionFilename;
  1118. }
  1119. const transfers = source.data ? [source.data.buffer] : null;
  1120. const workerId = await worker.messageHandler.sendWithPromise("GetDocRequest", {
  1121. docId,
  1122. apiVersion: '3.3.122',
  1123. data: source.data,
  1124. password: source.password,
  1125. disableAutoFetch: source.disableAutoFetch,
  1126. rangeChunkSize: source.rangeChunkSize,
  1127. length: source.length,
  1128. docBaseUrl: source.docBaseUrl,
  1129. enableXfa: source.enableXfa,
  1130. evaluatorOptions: {
  1131. maxImageSize: source.maxImageSize,
  1132. disableFontFace: source.disableFontFace,
  1133. ignoreErrors: source.ignoreErrors,
  1134. isEvalSupported: source.isEvalSupported,
  1135. isOffscreenCanvasSupported: source.isOffscreenCanvasSupported,
  1136. fontExtraProperties: source.fontExtraProperties,
  1137. useSystemFonts: source.useSystemFonts,
  1138. cMapUrl: source.useWorkerFetch ? source.cMapUrl : null,
  1139. standardFontDataUrl: source.useWorkerFetch ? source.standardFontDataUrl : null
  1140. }
  1141. }, transfers);
  1142. if (worker.destroyed) {
  1143. throw new Error("Worker was destroyed");
  1144. }
  1145. return workerId;
  1146. }
  1147. class PDFDocumentLoadingTask {
  1148. static #docId = 0;
  1149. #onUnsupportedFeature = null;
  1150. constructor() {
  1151. this._capability = (0, _util.createPromiseCapability)();
  1152. this._transport = null;
  1153. this._worker = null;
  1154. this.docId = `d${PDFDocumentLoadingTask.#docId++}`;
  1155. this.destroyed = false;
  1156. this.onPassword = null;
  1157. this.onProgress = null;
  1158. }
  1159. get onUnsupportedFeature() {
  1160. return this.#onUnsupportedFeature;
  1161. }
  1162. set onUnsupportedFeature(callback) {
  1163. (0, _display_utils.deprecated)("The PDFDocumentLoadingTask onUnsupportedFeature property will be removed in the future.");
  1164. this.#onUnsupportedFeature = callback;
  1165. }
  1166. get promise() {
  1167. return this._capability.promise;
  1168. }
  1169. async destroy() {
  1170. this.destroyed = true;
  1171. await this._transport?.destroy();
  1172. this._transport = null;
  1173. if (this._worker) {
  1174. this._worker.destroy();
  1175. this._worker = null;
  1176. }
  1177. }
  1178. }
  1179. exports.PDFDocumentLoadingTask = PDFDocumentLoadingTask;
  1180. class PDFDataRangeTransport {
  1181. constructor(length, initialData, progressiveDone = false, contentDispositionFilename = null) {
  1182. this.length = length;
  1183. this.initialData = initialData;
  1184. this.progressiveDone = progressiveDone;
  1185. this.contentDispositionFilename = contentDispositionFilename;
  1186. this._rangeListeners = [];
  1187. this._progressListeners = [];
  1188. this._progressiveReadListeners = [];
  1189. this._progressiveDoneListeners = [];
  1190. this._readyCapability = (0, _util.createPromiseCapability)();
  1191. }
  1192. addRangeListener(listener) {
  1193. this._rangeListeners.push(listener);
  1194. }
  1195. addProgressListener(listener) {
  1196. this._progressListeners.push(listener);
  1197. }
  1198. addProgressiveReadListener(listener) {
  1199. this._progressiveReadListeners.push(listener);
  1200. }
  1201. addProgressiveDoneListener(listener) {
  1202. this._progressiveDoneListeners.push(listener);
  1203. }
  1204. onDataRange(begin, chunk) {
  1205. for (const listener of this._rangeListeners) {
  1206. listener(begin, chunk);
  1207. }
  1208. }
  1209. onDataProgress(loaded, total) {
  1210. this._readyCapability.promise.then(() => {
  1211. for (const listener of this._progressListeners) {
  1212. listener(loaded, total);
  1213. }
  1214. });
  1215. }
  1216. onDataProgressiveRead(chunk) {
  1217. this._readyCapability.promise.then(() => {
  1218. for (const listener of this._progressiveReadListeners) {
  1219. listener(chunk);
  1220. }
  1221. });
  1222. }
  1223. onDataProgressiveDone() {
  1224. this._readyCapability.promise.then(() => {
  1225. for (const listener of this._progressiveDoneListeners) {
  1226. listener();
  1227. }
  1228. });
  1229. }
  1230. transportReady() {
  1231. this._readyCapability.resolve();
  1232. }
  1233. requestDataRange(begin, end) {
  1234. (0, _util.unreachable)("Abstract method PDFDataRangeTransport.requestDataRange");
  1235. }
  1236. abort() {}
  1237. }
  1238. exports.PDFDataRangeTransport = PDFDataRangeTransport;
  1239. class PDFDocumentProxy {
  1240. constructor(pdfInfo, transport) {
  1241. this._pdfInfo = pdfInfo;
  1242. this._transport = transport;
  1243. }
  1244. get annotationStorage() {
  1245. return this._transport.annotationStorage;
  1246. }
  1247. get numPages() {
  1248. return this._pdfInfo.numPages;
  1249. }
  1250. get fingerprints() {
  1251. return this._pdfInfo.fingerprints;
  1252. }
  1253. get isPureXfa() {
  1254. return (0, _util.shadow)(this, "isPureXfa", !!this._transport._htmlForXfa);
  1255. }
  1256. get allXfaHtml() {
  1257. return this._transport._htmlForXfa;
  1258. }
  1259. getPage(pageNumber) {
  1260. return this._transport.getPage(pageNumber);
  1261. }
  1262. getPageIndex(ref) {
  1263. return this._transport.getPageIndex(ref);
  1264. }
  1265. getDestinations() {
  1266. return this._transport.getDestinations();
  1267. }
  1268. getDestination(id) {
  1269. return this._transport.getDestination(id);
  1270. }
  1271. getPageLabels() {
  1272. return this._transport.getPageLabels();
  1273. }
  1274. getPageLayout() {
  1275. return this._transport.getPageLayout();
  1276. }
  1277. getPageMode() {
  1278. return this._transport.getPageMode();
  1279. }
  1280. getViewerPreferences() {
  1281. return this._transport.getViewerPreferences();
  1282. }
  1283. getOpenAction() {
  1284. return this._transport.getOpenAction();
  1285. }
  1286. getAttachments() {
  1287. return this._transport.getAttachments();
  1288. }
  1289. getJavaScript() {
  1290. return this._transport.getJavaScript();
  1291. }
  1292. getJSActions() {
  1293. return this._transport.getDocJSActions();
  1294. }
  1295. getOutline() {
  1296. return this._transport.getOutline();
  1297. }
  1298. getOptionalContentConfig() {
  1299. return this._transport.getOptionalContentConfig();
  1300. }
  1301. getPermissions() {
  1302. return this._transport.getPermissions();
  1303. }
  1304. getMetadata() {
  1305. return this._transport.getMetadata();
  1306. }
  1307. getMarkInfo() {
  1308. return this._transport.getMarkInfo();
  1309. }
  1310. getData() {
  1311. return this._transport.getData();
  1312. }
  1313. saveDocument() {
  1314. return this._transport.saveDocument();
  1315. }
  1316. getDownloadInfo() {
  1317. return this._transport.downloadInfoCapability.promise;
  1318. }
  1319. cleanup(keepLoadedFonts = false) {
  1320. return this._transport.startCleanup(keepLoadedFonts || this.isPureXfa);
  1321. }
  1322. destroy() {
  1323. return this.loadingTask.destroy();
  1324. }
  1325. get loadingParams() {
  1326. return this._transport.loadingParams;
  1327. }
  1328. get loadingTask() {
  1329. return this._transport.loadingTask;
  1330. }
  1331. getFieldObjects() {
  1332. return this._transport.getFieldObjects();
  1333. }
  1334. hasJSActions() {
  1335. return this._transport.hasJSActions();
  1336. }
  1337. getCalculationOrderIds() {
  1338. return this._transport.getCalculationOrderIds();
  1339. }
  1340. }
  1341. exports.PDFDocumentProxy = PDFDocumentProxy;
  1342. class PDFPageProxy {
  1343. constructor(pageIndex, pageInfo, transport, ownerDocument, pdfBug = false) {
  1344. this._pageIndex = pageIndex;
  1345. this._pageInfo = pageInfo;
  1346. this._ownerDocument = ownerDocument;
  1347. this._transport = transport;
  1348. this._stats = pdfBug ? new _display_utils.StatTimer() : null;
  1349. this._pdfBug = pdfBug;
  1350. this.commonObjs = transport.commonObjs;
  1351. this.objs = new PDFObjects();
  1352. this._bitmaps = new Set();
  1353. this.cleanupAfterRender = false;
  1354. this.pendingCleanup = false;
  1355. this._intentStates = new Map();
  1356. this.destroyed = false;
  1357. }
  1358. get pageNumber() {
  1359. return this._pageIndex + 1;
  1360. }
  1361. get rotate() {
  1362. return this._pageInfo.rotate;
  1363. }
  1364. get ref() {
  1365. return this._pageInfo.ref;
  1366. }
  1367. get userUnit() {
  1368. return this._pageInfo.userUnit;
  1369. }
  1370. get view() {
  1371. return this._pageInfo.view;
  1372. }
  1373. getViewport({
  1374. scale,
  1375. rotation = this.rotate,
  1376. offsetX = 0,
  1377. offsetY = 0,
  1378. dontFlip = false
  1379. } = {}) {
  1380. return new _display_utils.PageViewport({
  1381. viewBox: this.view,
  1382. scale,
  1383. rotation,
  1384. offsetX,
  1385. offsetY,
  1386. dontFlip
  1387. });
  1388. }
  1389. getAnnotations({
  1390. intent = "display"
  1391. } = {}) {
  1392. const intentArgs = this._transport.getRenderingIntent(intent);
  1393. return this._transport.getAnnotations(this._pageIndex, intentArgs.renderingIntent);
  1394. }
  1395. getJSActions() {
  1396. return this._transport.getPageJSActions(this._pageIndex);
  1397. }
  1398. get isPureXfa() {
  1399. return (0, _util.shadow)(this, "isPureXfa", !!this._transport._htmlForXfa);
  1400. }
  1401. async getXfa() {
  1402. return this._transport._htmlForXfa?.children[this._pageIndex] || null;
  1403. }
  1404. render({
  1405. canvasContext,
  1406. viewport,
  1407. intent = "display",
  1408. annotationMode = _util.AnnotationMode.ENABLE,
  1409. transform = null,
  1410. canvasFactory = null,
  1411. background = null,
  1412. optionalContentConfigPromise = null,
  1413. annotationCanvasMap = null,
  1414. pageColors = null,
  1415. printAnnotationStorage = null
  1416. }) {
  1417. this._stats?.time("Overall");
  1418. const intentArgs = this._transport.getRenderingIntent(intent, annotationMode, printAnnotationStorage);
  1419. this.pendingCleanup = false;
  1420. if (!optionalContentConfigPromise) {
  1421. optionalContentConfigPromise = this._transport.getOptionalContentConfig();
  1422. }
  1423. let intentState = this._intentStates.get(intentArgs.cacheKey);
  1424. if (!intentState) {
  1425. intentState = Object.create(null);
  1426. this._intentStates.set(intentArgs.cacheKey, intentState);
  1427. }
  1428. if (intentState.streamReaderCancelTimeout) {
  1429. clearTimeout(intentState.streamReaderCancelTimeout);
  1430. intentState.streamReaderCancelTimeout = null;
  1431. }
  1432. const canvasFactoryInstance = canvasFactory || new DefaultCanvasFactory({
  1433. ownerDocument: this._ownerDocument
  1434. });
  1435. const intentPrint = !!(intentArgs.renderingIntent & _util.RenderingIntentFlag.PRINT);
  1436. if (!intentState.displayReadyCapability) {
  1437. intentState.displayReadyCapability = (0, _util.createPromiseCapability)();
  1438. intentState.operatorList = {
  1439. fnArray: [],
  1440. argsArray: [],
  1441. lastChunk: false,
  1442. separateAnnots: null
  1443. };
  1444. this._stats?.time("Page Request");
  1445. this._pumpOperatorList(intentArgs);
  1446. }
  1447. const complete = error => {
  1448. intentState.renderTasks.delete(internalRenderTask);
  1449. if (this.cleanupAfterRender || intentPrint) {
  1450. this.pendingCleanup = true;
  1451. }
  1452. this._tryCleanup();
  1453. if (error) {
  1454. internalRenderTask.capability.reject(error);
  1455. this._abortOperatorList({
  1456. intentState,
  1457. reason: error instanceof Error ? error : new Error(error)
  1458. });
  1459. } else {
  1460. internalRenderTask.capability.resolve();
  1461. }
  1462. this._stats?.timeEnd("Rendering");
  1463. this._stats?.timeEnd("Overall");
  1464. };
  1465. const internalRenderTask = new InternalRenderTask({
  1466. callback: complete,
  1467. params: {
  1468. canvasContext,
  1469. viewport,
  1470. transform,
  1471. background
  1472. },
  1473. objs: this.objs,
  1474. commonObjs: this.commonObjs,
  1475. annotationCanvasMap,
  1476. operatorList: intentState.operatorList,
  1477. pageIndex: this._pageIndex,
  1478. canvasFactory: canvasFactoryInstance,
  1479. useRequestAnimationFrame: !intentPrint,
  1480. pdfBug: this._pdfBug,
  1481. pageColors
  1482. });
  1483. (intentState.renderTasks ||= new Set()).add(internalRenderTask);
  1484. const renderTask = internalRenderTask.task;
  1485. Promise.all([intentState.displayReadyCapability.promise, optionalContentConfigPromise]).then(([transparency, optionalContentConfig]) => {
  1486. if (this.pendingCleanup) {
  1487. complete();
  1488. return;
  1489. }
  1490. this._stats?.time("Rendering");
  1491. internalRenderTask.initializeGraphics({
  1492. transparency,
  1493. optionalContentConfig
  1494. });
  1495. internalRenderTask.operatorListChanged();
  1496. }).catch(complete);
  1497. return renderTask;
  1498. }
  1499. getOperatorList({
  1500. intent = "display",
  1501. annotationMode = _util.AnnotationMode.ENABLE,
  1502. printAnnotationStorage = null
  1503. } = {}) {
  1504. function operatorListChanged() {
  1505. if (intentState.operatorList.lastChunk) {
  1506. intentState.opListReadCapability.resolve(intentState.operatorList);
  1507. intentState.renderTasks.delete(opListTask);
  1508. }
  1509. }
  1510. const intentArgs = this._transport.getRenderingIntent(intent, annotationMode, printAnnotationStorage, true);
  1511. let intentState = this._intentStates.get(intentArgs.cacheKey);
  1512. if (!intentState) {
  1513. intentState = Object.create(null);
  1514. this._intentStates.set(intentArgs.cacheKey, intentState);
  1515. }
  1516. let opListTask;
  1517. if (!intentState.opListReadCapability) {
  1518. opListTask = Object.create(null);
  1519. opListTask.operatorListChanged = operatorListChanged;
  1520. intentState.opListReadCapability = (0, _util.createPromiseCapability)();
  1521. (intentState.renderTasks ||= new Set()).add(opListTask);
  1522. intentState.operatorList = {
  1523. fnArray: [],
  1524. argsArray: [],
  1525. lastChunk: false,
  1526. separateAnnots: null
  1527. };
  1528. this._stats?.time("Page Request");
  1529. this._pumpOperatorList(intentArgs);
  1530. }
  1531. return intentState.opListReadCapability.promise;
  1532. }
  1533. streamTextContent({
  1534. disableCombineTextItems = false,
  1535. includeMarkedContent = false
  1536. } = {}) {
  1537. const TEXT_CONTENT_CHUNK_SIZE = 100;
  1538. return this._transport.messageHandler.sendWithStream("GetTextContent", {
  1539. pageIndex: this._pageIndex,
  1540. combineTextItems: disableCombineTextItems !== true,
  1541. includeMarkedContent: includeMarkedContent === true
  1542. }, {
  1543. highWaterMark: TEXT_CONTENT_CHUNK_SIZE,
  1544. size(textContent) {
  1545. return textContent.items.length;
  1546. }
  1547. });
  1548. }
  1549. getTextContent(params = {}) {
  1550. if (this._transport._htmlForXfa) {
  1551. return this.getXfa().then(xfa => {
  1552. return _xfa_text.XfaText.textContent(xfa);
  1553. });
  1554. }
  1555. const readableStream = this.streamTextContent(params);
  1556. return new Promise(function (resolve, reject) {
  1557. function pump() {
  1558. reader.read().then(function ({
  1559. value,
  1560. done
  1561. }) {
  1562. if (done) {
  1563. resolve(textContent);
  1564. return;
  1565. }
  1566. Object.assign(textContent.styles, value.styles);
  1567. textContent.items.push(...value.items);
  1568. pump();
  1569. }, reject);
  1570. }
  1571. const reader = readableStream.getReader();
  1572. const textContent = {
  1573. items: [],
  1574. styles: Object.create(null)
  1575. };
  1576. pump();
  1577. });
  1578. }
  1579. getStructTree() {
  1580. return this._transport.getStructTree(this._pageIndex);
  1581. }
  1582. _destroy() {
  1583. this.destroyed = true;
  1584. const waitOn = [];
  1585. for (const intentState of this._intentStates.values()) {
  1586. this._abortOperatorList({
  1587. intentState,
  1588. reason: new Error("Page was destroyed."),
  1589. force: true
  1590. });
  1591. if (intentState.opListReadCapability) {
  1592. continue;
  1593. }
  1594. for (const internalRenderTask of intentState.renderTasks) {
  1595. waitOn.push(internalRenderTask.completed);
  1596. internalRenderTask.cancel();
  1597. }
  1598. }
  1599. this.objs.clear();
  1600. for (const bitmap of this._bitmaps) {
  1601. bitmap.close();
  1602. }
  1603. this._bitmaps.clear();
  1604. this.pendingCleanup = false;
  1605. return Promise.all(waitOn);
  1606. }
  1607. cleanup(resetStats = false) {
  1608. this.pendingCleanup = true;
  1609. return this._tryCleanup(resetStats);
  1610. }
  1611. _tryCleanup(resetStats = false) {
  1612. if (!this.pendingCleanup) {
  1613. return false;
  1614. }
  1615. for (const {
  1616. renderTasks,
  1617. operatorList
  1618. } of this._intentStates.values()) {
  1619. if (renderTasks.size > 0 || !operatorList.lastChunk) {
  1620. return false;
  1621. }
  1622. }
  1623. this._intentStates.clear();
  1624. this.objs.clear();
  1625. if (resetStats && this._stats) {
  1626. this._stats = new _display_utils.StatTimer();
  1627. }
  1628. for (const bitmap of this._bitmaps) {
  1629. bitmap.close();
  1630. }
  1631. this._bitmaps.clear();
  1632. this.pendingCleanup = false;
  1633. return true;
  1634. }
  1635. _startRenderPage(transparency, cacheKey) {
  1636. const intentState = this._intentStates.get(cacheKey);
  1637. if (!intentState) {
  1638. return;
  1639. }
  1640. this._stats?.timeEnd("Page Request");
  1641. intentState.displayReadyCapability?.resolve(transparency);
  1642. }
  1643. _renderPageChunk(operatorListChunk, intentState) {
  1644. for (let i = 0, ii = operatorListChunk.length; i < ii; i++) {
  1645. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  1646. intentState.operatorList.argsArray.push(operatorListChunk.argsArray[i]);
  1647. }
  1648. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  1649. intentState.operatorList.separateAnnots = operatorListChunk.separateAnnots;
  1650. for (const internalRenderTask of intentState.renderTasks) {
  1651. internalRenderTask.operatorListChanged();
  1652. }
  1653. if (operatorListChunk.lastChunk) {
  1654. this._tryCleanup();
  1655. }
  1656. }
  1657. _pumpOperatorList({
  1658. renderingIntent,
  1659. cacheKey,
  1660. annotationStorageMap
  1661. }) {
  1662. const readableStream = this._transport.messageHandler.sendWithStream("GetOperatorList", {
  1663. pageIndex: this._pageIndex,
  1664. intent: renderingIntent,
  1665. cacheKey,
  1666. annotationStorage: annotationStorageMap
  1667. });
  1668. const reader = readableStream.getReader();
  1669. const intentState = this._intentStates.get(cacheKey);
  1670. intentState.streamReader = reader;
  1671. const pump = () => {
  1672. reader.read().then(({
  1673. value,
  1674. done
  1675. }) => {
  1676. if (done) {
  1677. intentState.streamReader = null;
  1678. return;
  1679. }
  1680. if (this._transport.destroyed) {
  1681. return;
  1682. }
  1683. this._renderPageChunk(value, intentState);
  1684. pump();
  1685. }, reason => {
  1686. intentState.streamReader = null;
  1687. if (this._transport.destroyed) {
  1688. return;
  1689. }
  1690. if (intentState.operatorList) {
  1691. intentState.operatorList.lastChunk = true;
  1692. for (const internalRenderTask of intentState.renderTasks) {
  1693. internalRenderTask.operatorListChanged();
  1694. }
  1695. this._tryCleanup();
  1696. }
  1697. if (intentState.displayReadyCapability) {
  1698. intentState.displayReadyCapability.reject(reason);
  1699. } else if (intentState.opListReadCapability) {
  1700. intentState.opListReadCapability.reject(reason);
  1701. } else {
  1702. throw reason;
  1703. }
  1704. });
  1705. };
  1706. pump();
  1707. }
  1708. _abortOperatorList({
  1709. intentState,
  1710. reason,
  1711. force = false
  1712. }) {
  1713. if (!intentState.streamReader) {
  1714. return;
  1715. }
  1716. if (intentState.streamReaderCancelTimeout) {
  1717. clearTimeout(intentState.streamReaderCancelTimeout);
  1718. intentState.streamReaderCancelTimeout = null;
  1719. }
  1720. if (!force) {
  1721. if (intentState.renderTasks.size > 0) {
  1722. return;
  1723. }
  1724. if (reason instanceof _display_utils.RenderingCancelledException) {
  1725. let delay = RENDERING_CANCELLED_TIMEOUT;
  1726. if (reason.extraDelay > 0 && reason.extraDelay < 1000) {
  1727. delay += reason.extraDelay;
  1728. }
  1729. intentState.streamReaderCancelTimeout = setTimeout(() => {
  1730. intentState.streamReaderCancelTimeout = null;
  1731. this._abortOperatorList({
  1732. intentState,
  1733. reason,
  1734. force: true
  1735. });
  1736. }, delay);
  1737. return;
  1738. }
  1739. }
  1740. intentState.streamReader.cancel(new _util.AbortException(reason.message)).catch(() => {});
  1741. intentState.streamReader = null;
  1742. if (this._transport.destroyed) {
  1743. return;
  1744. }
  1745. for (const [curCacheKey, curIntentState] of this._intentStates) {
  1746. if (curIntentState === intentState) {
  1747. this._intentStates.delete(curCacheKey);
  1748. break;
  1749. }
  1750. }
  1751. this.cleanup();
  1752. }
  1753. get stats() {
  1754. return this._stats;
  1755. }
  1756. }
  1757. exports.PDFPageProxy = PDFPageProxy;
  1758. class LoopbackPort {
  1759. #listeners = [];
  1760. #deferred = Promise.resolve();
  1761. postMessage(obj, transfers) {
  1762. const event = {
  1763. data: structuredClone(obj, transfers)
  1764. };
  1765. this.#deferred.then(() => {
  1766. for (const listener of this.#listeners) {
  1767. listener.call(this, event);
  1768. }
  1769. });
  1770. }
  1771. addEventListener(name, listener) {
  1772. this.#listeners.push(listener);
  1773. }
  1774. removeEventListener(name, listener) {
  1775. const i = this.#listeners.indexOf(listener);
  1776. this.#listeners.splice(i, 1);
  1777. }
  1778. terminate() {
  1779. this.#listeners.length = 0;
  1780. }
  1781. }
  1782. exports.LoopbackPort = LoopbackPort;
  1783. const PDFWorkerUtil = {
  1784. isWorkerDisabled: false,
  1785. fallbackWorkerSrc: null,
  1786. fakeWorkerId: 0
  1787. };
  1788. exports.PDFWorkerUtil = PDFWorkerUtil;
  1789. {
  1790. if (_is_node.isNodeJS && typeof require === "function") {
  1791. PDFWorkerUtil.isWorkerDisabled = true;
  1792. PDFWorkerUtil.fallbackWorkerSrc = "./pdf.worker.js";
  1793. } else if (typeof document === "object") {
  1794. const pdfjsFilePath = document?.currentScript?.src;
  1795. if (pdfjsFilePath) {
  1796. PDFWorkerUtil.fallbackWorkerSrc = pdfjsFilePath.replace(/(\.(?:min\.)?js)(\?.*)?$/i, ".worker$1$2");
  1797. }
  1798. }
  1799. PDFWorkerUtil.isSameOrigin = function (baseUrl, otherUrl) {
  1800. let base;
  1801. try {
  1802. base = new URL(baseUrl);
  1803. if (!base.origin || base.origin === "null") {
  1804. return false;
  1805. }
  1806. } catch (e) {
  1807. return false;
  1808. }
  1809. const other = new URL(otherUrl, base);
  1810. return base.origin === other.origin;
  1811. };
  1812. PDFWorkerUtil.createCDNWrapper = function (url) {
  1813. const wrapper = `importScripts("${url}");`;
  1814. return URL.createObjectURL(new Blob([wrapper]));
  1815. };
  1816. }
  1817. class PDFWorker {
  1818. static #workerPorts = new WeakMap();
  1819. constructor({
  1820. name = null,
  1821. port = null,
  1822. verbosity = (0, _util.getVerbosityLevel)()
  1823. } = {}) {
  1824. if (port && PDFWorker.#workerPorts.has(port)) {
  1825. throw new Error("Cannot use more than one PDFWorker per port.");
  1826. }
  1827. this.name = name;
  1828. this.destroyed = false;
  1829. this.verbosity = verbosity;
  1830. this._readyCapability = (0, _util.createPromiseCapability)();
  1831. this._port = null;
  1832. this._webWorker = null;
  1833. this._messageHandler = null;
  1834. if (port) {
  1835. PDFWorker.#workerPorts.set(port, this);
  1836. this._initializeFromPort(port);
  1837. return;
  1838. }
  1839. this._initialize();
  1840. }
  1841. get promise() {
  1842. return this._readyCapability.promise;
  1843. }
  1844. get port() {
  1845. return this._port;
  1846. }
  1847. get messageHandler() {
  1848. return this._messageHandler;
  1849. }
  1850. _initializeFromPort(port) {
  1851. this._port = port;
  1852. this._messageHandler = new _message_handler.MessageHandler("main", "worker", port);
  1853. this._messageHandler.on("ready", function () {});
  1854. this._readyCapability.resolve();
  1855. this._messageHandler.send("configure", {
  1856. verbosity: this.verbosity
  1857. });
  1858. }
  1859. _initialize() {
  1860. if (!PDFWorkerUtil.isWorkerDisabled && !PDFWorker._mainThreadWorkerMessageHandler) {
  1861. let {
  1862. workerSrc
  1863. } = PDFWorker;
  1864. try {
  1865. if (!PDFWorkerUtil.isSameOrigin(window.location.href, workerSrc)) {
  1866. workerSrc = PDFWorkerUtil.createCDNWrapper(new URL(workerSrc, window.location).href);
  1867. }
  1868. const worker = new Worker(workerSrc);
  1869. const messageHandler = new _message_handler.MessageHandler("main", "worker", worker);
  1870. const terminateEarly = () => {
  1871. worker.removeEventListener("error", onWorkerError);
  1872. messageHandler.destroy();
  1873. worker.terminate();
  1874. if (this.destroyed) {
  1875. this._readyCapability.reject(new Error("Worker was destroyed"));
  1876. } else {
  1877. this._setupFakeWorker();
  1878. }
  1879. };
  1880. const onWorkerError = () => {
  1881. if (!this._webWorker) {
  1882. terminateEarly();
  1883. }
  1884. };
  1885. worker.addEventListener("error", onWorkerError);
  1886. messageHandler.on("test", data => {
  1887. worker.removeEventListener("error", onWorkerError);
  1888. if (this.destroyed) {
  1889. terminateEarly();
  1890. return;
  1891. }
  1892. if (data) {
  1893. this._messageHandler = messageHandler;
  1894. this._port = worker;
  1895. this._webWorker = worker;
  1896. this._readyCapability.resolve();
  1897. messageHandler.send("configure", {
  1898. verbosity: this.verbosity
  1899. });
  1900. } else {
  1901. this._setupFakeWorker();
  1902. messageHandler.destroy();
  1903. worker.terminate();
  1904. }
  1905. });
  1906. messageHandler.on("ready", data => {
  1907. worker.removeEventListener("error", onWorkerError);
  1908. if (this.destroyed) {
  1909. terminateEarly();
  1910. return;
  1911. }
  1912. try {
  1913. sendTest();
  1914. } catch (e) {
  1915. this._setupFakeWorker();
  1916. }
  1917. });
  1918. const sendTest = () => {
  1919. const testObj = new Uint8Array();
  1920. messageHandler.send("test", testObj, [testObj.buffer]);
  1921. };
  1922. sendTest();
  1923. return;
  1924. } catch (e) {
  1925. (0, _util.info)("The worker has been disabled.");
  1926. }
  1927. }
  1928. this._setupFakeWorker();
  1929. }
  1930. _setupFakeWorker() {
  1931. if (!PDFWorkerUtil.isWorkerDisabled) {
  1932. (0, _util.warn)("Setting up fake worker.");
  1933. PDFWorkerUtil.isWorkerDisabled = true;
  1934. }
  1935. PDFWorker._setupFakeWorkerGlobal.then(WorkerMessageHandler => {
  1936. if (this.destroyed) {
  1937. this._readyCapability.reject(new Error("Worker was destroyed"));
  1938. return;
  1939. }
  1940. const port = new LoopbackPort();
  1941. this._port = port;
  1942. const id = `fake${PDFWorkerUtil.fakeWorkerId++}`;
  1943. const workerHandler = new _message_handler.MessageHandler(id + "_worker", id, port);
  1944. WorkerMessageHandler.setup(workerHandler, port);
  1945. const messageHandler = new _message_handler.MessageHandler(id, id + "_worker", port);
  1946. this._messageHandler = messageHandler;
  1947. this._readyCapability.resolve();
  1948. messageHandler.send("configure", {
  1949. verbosity: this.verbosity
  1950. });
  1951. }).catch(reason => {
  1952. this._readyCapability.reject(new Error(`Setting up fake worker failed: "${reason.message}".`));
  1953. });
  1954. }
  1955. destroy() {
  1956. this.destroyed = true;
  1957. if (this._webWorker) {
  1958. this._webWorker.terminate();
  1959. this._webWorker = null;
  1960. }
  1961. PDFWorker.#workerPorts.delete(this._port);
  1962. this._port = null;
  1963. if (this._messageHandler) {
  1964. this._messageHandler.destroy();
  1965. this._messageHandler = null;
  1966. }
  1967. }
  1968. static fromPort(params) {
  1969. if (!params?.port) {
  1970. throw new Error("PDFWorker.fromPort - invalid method signature.");
  1971. }
  1972. if (this.#workerPorts.has(params.port)) {
  1973. return this.#workerPorts.get(params.port);
  1974. }
  1975. return new PDFWorker(params);
  1976. }
  1977. static get workerSrc() {
  1978. if (_worker_options.GlobalWorkerOptions.workerSrc) {
  1979. return _worker_options.GlobalWorkerOptions.workerSrc;
  1980. }
  1981. if (PDFWorkerUtil.fallbackWorkerSrc !== null) {
  1982. if (!_is_node.isNodeJS) {
  1983. (0, _display_utils.deprecated)('No "GlobalWorkerOptions.workerSrc" specified.');
  1984. }
  1985. return PDFWorkerUtil.fallbackWorkerSrc;
  1986. }
  1987. throw new Error('No "GlobalWorkerOptions.workerSrc" specified.');
  1988. }
  1989. static get _mainThreadWorkerMessageHandler() {
  1990. try {
  1991. return globalThis.pdfjsWorker?.WorkerMessageHandler || null;
  1992. } catch (ex) {
  1993. return null;
  1994. }
  1995. }
  1996. static get _setupFakeWorkerGlobal() {
  1997. const loader = async () => {
  1998. const mainWorkerMessageHandler = this._mainThreadWorkerMessageHandler;
  1999. if (mainWorkerMessageHandler) {
  2000. return mainWorkerMessageHandler;
  2001. }
  2002. if (_is_node.isNodeJS && typeof require === "function") {
  2003. const worker = eval("require")(this.workerSrc);
  2004. return worker.WorkerMessageHandler;
  2005. }
  2006. await (0, _display_utils.loadScript)(this.workerSrc);
  2007. return window.pdfjsWorker.WorkerMessageHandler;
  2008. };
  2009. return (0, _util.shadow)(this, "_setupFakeWorkerGlobal", loader());
  2010. }
  2011. }
  2012. exports.PDFWorker = PDFWorker;
  2013. class WorkerTransport {
  2014. #pageCache = new Map();
  2015. #pagePromises = new Map();
  2016. #metadataPromise = null;
  2017. constructor(messageHandler, loadingTask, networkStream, params) {
  2018. this.messageHandler = messageHandler;
  2019. this.loadingTask = loadingTask;
  2020. this.commonObjs = new PDFObjects();
  2021. this.fontLoader = new _font_loader.FontLoader({
  2022. onUnsupportedFeature: this._onUnsupportedFeature.bind(this),
  2023. ownerDocument: params.ownerDocument,
  2024. styleElement: params.styleElement
  2025. });
  2026. this._params = params;
  2027. if (!params.useWorkerFetch) {
  2028. this.CMapReaderFactory = new params.CMapReaderFactory({
  2029. baseUrl: params.cMapUrl,
  2030. isCompressed: params.cMapPacked
  2031. });
  2032. this.StandardFontDataFactory = new params.StandardFontDataFactory({
  2033. baseUrl: params.standardFontDataUrl
  2034. });
  2035. }
  2036. this.destroyed = false;
  2037. this.destroyCapability = null;
  2038. this._passwordCapability = null;
  2039. this._networkStream = networkStream;
  2040. this._fullReader = null;
  2041. this._lastProgress = null;
  2042. this.downloadInfoCapability = (0, _util.createPromiseCapability)();
  2043. this.setupMessageHandler();
  2044. }
  2045. get annotationStorage() {
  2046. return (0, _util.shadow)(this, "annotationStorage", new _annotation_storage.AnnotationStorage());
  2047. }
  2048. getRenderingIntent(intent, annotationMode = _util.AnnotationMode.ENABLE, printAnnotationStorage = null, isOpList = false) {
  2049. let renderingIntent = _util.RenderingIntentFlag.DISPLAY;
  2050. let annotationMap = null;
  2051. switch (intent) {
  2052. case "any":
  2053. renderingIntent = _util.RenderingIntentFlag.ANY;
  2054. break;
  2055. case "display":
  2056. break;
  2057. case "print":
  2058. renderingIntent = _util.RenderingIntentFlag.PRINT;
  2059. break;
  2060. default:
  2061. (0, _util.warn)(`getRenderingIntent - invalid intent: ${intent}`);
  2062. }
  2063. switch (annotationMode) {
  2064. case _util.AnnotationMode.DISABLE:
  2065. renderingIntent += _util.RenderingIntentFlag.ANNOTATIONS_DISABLE;
  2066. break;
  2067. case _util.AnnotationMode.ENABLE:
  2068. break;
  2069. case _util.AnnotationMode.ENABLE_FORMS:
  2070. renderingIntent += _util.RenderingIntentFlag.ANNOTATIONS_FORMS;
  2071. break;
  2072. case _util.AnnotationMode.ENABLE_STORAGE:
  2073. renderingIntent += _util.RenderingIntentFlag.ANNOTATIONS_STORAGE;
  2074. const annotationStorage = renderingIntent & _util.RenderingIntentFlag.PRINT && printAnnotationStorage instanceof _annotation_storage.PrintAnnotationStorage ? printAnnotationStorage : this.annotationStorage;
  2075. annotationMap = annotationStorage.serializable;
  2076. break;
  2077. default:
  2078. (0, _util.warn)(`getRenderingIntent - invalid annotationMode: ${annotationMode}`);
  2079. }
  2080. if (isOpList) {
  2081. renderingIntent += _util.RenderingIntentFlag.OPLIST;
  2082. }
  2083. return {
  2084. renderingIntent,
  2085. cacheKey: `${renderingIntent}_${_annotation_storage.AnnotationStorage.getHash(annotationMap)}`,
  2086. annotationStorageMap: annotationMap
  2087. };
  2088. }
  2089. destroy() {
  2090. if (this.destroyCapability) {
  2091. return this.destroyCapability.promise;
  2092. }
  2093. this.destroyed = true;
  2094. this.destroyCapability = (0, _util.createPromiseCapability)();
  2095. if (this._passwordCapability) {
  2096. this._passwordCapability.reject(new Error("Worker was destroyed during onPassword callback"));
  2097. }
  2098. const waitOn = [];
  2099. for (const page of this.#pageCache.values()) {
  2100. waitOn.push(page._destroy());
  2101. }
  2102. this.#pageCache.clear();
  2103. this.#pagePromises.clear();
  2104. if (this.hasOwnProperty("annotationStorage")) {
  2105. this.annotationStorage.resetModified();
  2106. }
  2107. const terminated = this.messageHandler.sendWithPromise("Terminate", null);
  2108. waitOn.push(terminated);
  2109. Promise.all(waitOn).then(() => {
  2110. this.commonObjs.clear();
  2111. this.fontLoader.clear();
  2112. this.#metadataPromise = null;
  2113. this._getFieldObjectsPromise = null;
  2114. this._hasJSActionsPromise = null;
  2115. if (this._networkStream) {
  2116. this._networkStream.cancelAllRequests(new _util.AbortException("Worker was terminated."));
  2117. }
  2118. if (this.messageHandler) {
  2119. this.messageHandler.destroy();
  2120. this.messageHandler = null;
  2121. }
  2122. this.destroyCapability.resolve();
  2123. }, this.destroyCapability.reject);
  2124. return this.destroyCapability.promise;
  2125. }
  2126. setupMessageHandler() {
  2127. const {
  2128. messageHandler,
  2129. loadingTask
  2130. } = this;
  2131. messageHandler.on("GetReader", (data, sink) => {
  2132. (0, _util.assert)(this._networkStream, "GetReader - no `IPDFStream` instance available.");
  2133. this._fullReader = this._networkStream.getFullReader();
  2134. this._fullReader.onProgress = evt => {
  2135. this._lastProgress = {
  2136. loaded: evt.loaded,
  2137. total: evt.total
  2138. };
  2139. };
  2140. sink.onPull = () => {
  2141. this._fullReader.read().then(function ({
  2142. value,
  2143. done
  2144. }) {
  2145. if (done) {
  2146. sink.close();
  2147. return;
  2148. }
  2149. (0, _util.assert)(value instanceof ArrayBuffer, "GetReader - expected an ArrayBuffer.");
  2150. sink.enqueue(new Uint8Array(value), 1, [value]);
  2151. }).catch(reason => {
  2152. sink.error(reason);
  2153. });
  2154. };
  2155. sink.onCancel = reason => {
  2156. this._fullReader.cancel(reason);
  2157. sink.ready.catch(readyReason => {
  2158. if (this.destroyed) {
  2159. return;
  2160. }
  2161. throw readyReason;
  2162. });
  2163. };
  2164. });
  2165. messageHandler.on("ReaderHeadersReady", data => {
  2166. const headersCapability = (0, _util.createPromiseCapability)();
  2167. const fullReader = this._fullReader;
  2168. fullReader.headersReady.then(() => {
  2169. if (!fullReader.isStreamingSupported || !fullReader.isRangeSupported) {
  2170. if (this._lastProgress) {
  2171. loadingTask.onProgress?.(this._lastProgress);
  2172. }
  2173. fullReader.onProgress = evt => {
  2174. loadingTask.onProgress?.({
  2175. loaded: evt.loaded,
  2176. total: evt.total
  2177. });
  2178. };
  2179. }
  2180. headersCapability.resolve({
  2181. isStreamingSupported: fullReader.isStreamingSupported,
  2182. isRangeSupported: fullReader.isRangeSupported,
  2183. contentLength: fullReader.contentLength
  2184. });
  2185. }, headersCapability.reject);
  2186. return headersCapability.promise;
  2187. });
  2188. messageHandler.on("GetRangeReader", (data, sink) => {
  2189. (0, _util.assert)(this._networkStream, "GetRangeReader - no `IPDFStream` instance available.");
  2190. const rangeReader = this._networkStream.getRangeReader(data.begin, data.end);
  2191. if (!rangeReader) {
  2192. sink.close();
  2193. return;
  2194. }
  2195. sink.onPull = () => {
  2196. rangeReader.read().then(function ({
  2197. value,
  2198. done
  2199. }) {
  2200. if (done) {
  2201. sink.close();
  2202. return;
  2203. }
  2204. (0, _util.assert)(value instanceof ArrayBuffer, "GetRangeReader - expected an ArrayBuffer.");
  2205. sink.enqueue(new Uint8Array(value), 1, [value]);
  2206. }).catch(reason => {
  2207. sink.error(reason);
  2208. });
  2209. };
  2210. sink.onCancel = reason => {
  2211. rangeReader.cancel(reason);
  2212. sink.ready.catch(readyReason => {
  2213. if (this.destroyed) {
  2214. return;
  2215. }
  2216. throw readyReason;
  2217. });
  2218. };
  2219. });
  2220. messageHandler.on("GetDoc", ({
  2221. pdfInfo
  2222. }) => {
  2223. this._numPages = pdfInfo.numPages;
  2224. this._htmlForXfa = pdfInfo.htmlForXfa;
  2225. delete pdfInfo.htmlForXfa;
  2226. loadingTask._capability.resolve(new PDFDocumentProxy(pdfInfo, this));
  2227. });
  2228. messageHandler.on("DocException", function (ex) {
  2229. let reason;
  2230. switch (ex.name) {
  2231. case "PasswordException":
  2232. reason = new _util.PasswordException(ex.message, ex.code);
  2233. break;
  2234. case "InvalidPDFException":
  2235. reason = new _util.InvalidPDFException(ex.message);
  2236. break;
  2237. case "MissingPDFException":
  2238. reason = new _util.MissingPDFException(ex.message);
  2239. break;
  2240. case "UnexpectedResponseException":
  2241. reason = new _util.UnexpectedResponseException(ex.message, ex.status);
  2242. break;
  2243. case "UnknownErrorException":
  2244. reason = new _util.UnknownErrorException(ex.message, ex.details);
  2245. break;
  2246. default:
  2247. (0, _util.unreachable)("DocException - expected a valid Error.");
  2248. }
  2249. loadingTask._capability.reject(reason);
  2250. });
  2251. messageHandler.on("PasswordRequest", exception => {
  2252. this._passwordCapability = (0, _util.createPromiseCapability)();
  2253. if (loadingTask.onPassword) {
  2254. const updatePassword = password => {
  2255. if (password instanceof Error) {
  2256. this._passwordCapability.reject(password);
  2257. } else {
  2258. this._passwordCapability.resolve({
  2259. password
  2260. });
  2261. }
  2262. };
  2263. try {
  2264. loadingTask.onPassword(updatePassword, exception.code);
  2265. } catch (ex) {
  2266. this._passwordCapability.reject(ex);
  2267. }
  2268. } else {
  2269. this._passwordCapability.reject(new _util.PasswordException(exception.message, exception.code));
  2270. }
  2271. return this._passwordCapability.promise;
  2272. });
  2273. messageHandler.on("DataLoaded", data => {
  2274. loadingTask.onProgress?.({
  2275. loaded: data.length,
  2276. total: data.length
  2277. });
  2278. this.downloadInfoCapability.resolve(data);
  2279. });
  2280. messageHandler.on("StartRenderPage", data => {
  2281. if (this.destroyed) {
  2282. return;
  2283. }
  2284. const page = this.#pageCache.get(data.pageIndex);
  2285. page._startRenderPage(data.transparency, data.cacheKey);
  2286. });
  2287. messageHandler.on("commonobj", ([id, type, exportedData]) => {
  2288. if (this.destroyed) {
  2289. return;
  2290. }
  2291. if (this.commonObjs.has(id)) {
  2292. return;
  2293. }
  2294. switch (type) {
  2295. case "Font":
  2296. const params = this._params;
  2297. if ("error" in exportedData) {
  2298. const exportedError = exportedData.error;
  2299. (0, _util.warn)(`Error during font loading: ${exportedError}`);
  2300. this.commonObjs.resolve(id, exportedError);
  2301. break;
  2302. }
  2303. let fontRegistry = null;
  2304. if (params.pdfBug && globalThis.FontInspector?.enabled) {
  2305. fontRegistry = {
  2306. registerFont(font, url) {
  2307. globalThis.FontInspector.fontAdded(font, url);
  2308. }
  2309. };
  2310. }
  2311. const font = new _font_loader.FontFaceObject(exportedData, {
  2312. isEvalSupported: params.isEvalSupported,
  2313. disableFontFace: params.disableFontFace,
  2314. ignoreErrors: params.ignoreErrors,
  2315. onUnsupportedFeature: this._onUnsupportedFeature.bind(this),
  2316. fontRegistry
  2317. });
  2318. this.fontLoader.bind(font).catch(reason => {
  2319. return messageHandler.sendWithPromise("FontFallback", {
  2320. id
  2321. });
  2322. }).finally(() => {
  2323. if (!params.fontExtraProperties && font.data) {
  2324. font.data = null;
  2325. }
  2326. this.commonObjs.resolve(id, font);
  2327. });
  2328. break;
  2329. case "FontPath":
  2330. case "Image":
  2331. this.commonObjs.resolve(id, exportedData);
  2332. break;
  2333. default:
  2334. throw new Error(`Got unknown common object type ${type}`);
  2335. }
  2336. });
  2337. messageHandler.on("obj", ([id, pageIndex, type, imageData]) => {
  2338. if (this.destroyed) {
  2339. return;
  2340. }
  2341. const pageProxy = this.#pageCache.get(pageIndex);
  2342. if (pageProxy.objs.has(id)) {
  2343. return;
  2344. }
  2345. switch (type) {
  2346. case "Image":
  2347. pageProxy.objs.resolve(id, imageData);
  2348. const MAX_IMAGE_SIZE_TO_STORE = 8000000;
  2349. if (imageData) {
  2350. let length;
  2351. if (imageData.bitmap) {
  2352. const {
  2353. bitmap,
  2354. width,
  2355. height
  2356. } = imageData;
  2357. length = width * height * 4;
  2358. pageProxy._bitmaps.add(bitmap);
  2359. } else {
  2360. length = imageData.data?.length || 0;
  2361. }
  2362. if (length > MAX_IMAGE_SIZE_TO_STORE) {
  2363. pageProxy.cleanupAfterRender = true;
  2364. }
  2365. }
  2366. break;
  2367. case "Pattern":
  2368. pageProxy.objs.resolve(id, imageData);
  2369. break;
  2370. default:
  2371. throw new Error(`Got unknown object type ${type}`);
  2372. }
  2373. });
  2374. messageHandler.on("DocProgress", data => {
  2375. if (this.destroyed) {
  2376. return;
  2377. }
  2378. loadingTask.onProgress?.({
  2379. loaded: data.loaded,
  2380. total: data.total
  2381. });
  2382. });
  2383. messageHandler.on("UnsupportedFeature", this._onUnsupportedFeature.bind(this));
  2384. messageHandler.on("FetchBuiltInCMap", data => {
  2385. if (this.destroyed) {
  2386. return Promise.reject(new Error("Worker was destroyed."));
  2387. }
  2388. if (!this.CMapReaderFactory) {
  2389. return Promise.reject(new Error("CMapReaderFactory not initialized, see the `useWorkerFetch` parameter."));
  2390. }
  2391. return this.CMapReaderFactory.fetch(data);
  2392. });
  2393. messageHandler.on("FetchStandardFontData", data => {
  2394. if (this.destroyed) {
  2395. return Promise.reject(new Error("Worker was destroyed."));
  2396. }
  2397. if (!this.StandardFontDataFactory) {
  2398. return Promise.reject(new Error("StandardFontDataFactory not initialized, see the `useWorkerFetch` parameter."));
  2399. }
  2400. return this.StandardFontDataFactory.fetch(data);
  2401. });
  2402. }
  2403. _onUnsupportedFeature({
  2404. featureId
  2405. }) {
  2406. if (this.destroyed) {
  2407. return;
  2408. }
  2409. this.loadingTask.onUnsupportedFeature?.(featureId);
  2410. }
  2411. getData() {
  2412. return this.messageHandler.sendWithPromise("GetData", null);
  2413. }
  2414. saveDocument() {
  2415. if (this.annotationStorage.size <= 0) {
  2416. (0, _util.warn)("saveDocument called while `annotationStorage` is empty, " + "please use the getData-method instead.");
  2417. }
  2418. return this.messageHandler.sendWithPromise("SaveDocument", {
  2419. isPureXfa: !!this._htmlForXfa,
  2420. numPages: this._numPages,
  2421. annotationStorage: this.annotationStorage.serializable,
  2422. filename: this._fullReader?.filename ?? null
  2423. }).finally(() => {
  2424. this.annotationStorage.resetModified();
  2425. });
  2426. }
  2427. getPage(pageNumber) {
  2428. if (!Number.isInteger(pageNumber) || pageNumber <= 0 || pageNumber > this._numPages) {
  2429. return Promise.reject(new Error("Invalid page request."));
  2430. }
  2431. const pageIndex = pageNumber - 1,
  2432. cachedPromise = this.#pagePromises.get(pageIndex);
  2433. if (cachedPromise) {
  2434. return cachedPromise;
  2435. }
  2436. const promise = this.messageHandler.sendWithPromise("GetPage", {
  2437. pageIndex
  2438. }).then(pageInfo => {
  2439. if (this.destroyed) {
  2440. throw new Error("Transport destroyed");
  2441. }
  2442. const page = new PDFPageProxy(pageIndex, pageInfo, this, this._params.ownerDocument, this._params.pdfBug);
  2443. this.#pageCache.set(pageIndex, page);
  2444. return page;
  2445. });
  2446. this.#pagePromises.set(pageIndex, promise);
  2447. return promise;
  2448. }
  2449. getPageIndex(ref) {
  2450. if (typeof ref !== "object" || ref === null || !Number.isInteger(ref.num) || ref.num < 0 || !Number.isInteger(ref.gen) || ref.gen < 0) {
  2451. return Promise.reject(new Error("Invalid pageIndex request."));
  2452. }
  2453. return this.messageHandler.sendWithPromise("GetPageIndex", {
  2454. num: ref.num,
  2455. gen: ref.gen
  2456. });
  2457. }
  2458. getAnnotations(pageIndex, intent) {
  2459. return this.messageHandler.sendWithPromise("GetAnnotations", {
  2460. pageIndex,
  2461. intent
  2462. });
  2463. }
  2464. getFieldObjects() {
  2465. return this._getFieldObjectsPromise ||= this.messageHandler.sendWithPromise("GetFieldObjects", null);
  2466. }
  2467. hasJSActions() {
  2468. return this._hasJSActionsPromise ||= this.messageHandler.sendWithPromise("HasJSActions", null);
  2469. }
  2470. getCalculationOrderIds() {
  2471. return this.messageHandler.sendWithPromise("GetCalculationOrderIds", null);
  2472. }
  2473. getDestinations() {
  2474. return this.messageHandler.sendWithPromise("GetDestinations", null);
  2475. }
  2476. getDestination(id) {
  2477. if (typeof id !== "string") {
  2478. return Promise.reject(new Error("Invalid destination request."));
  2479. }
  2480. return this.messageHandler.sendWithPromise("GetDestination", {
  2481. id
  2482. });
  2483. }
  2484. getPageLabels() {
  2485. return this.messageHandler.sendWithPromise("GetPageLabels", null);
  2486. }
  2487. getPageLayout() {
  2488. return this.messageHandler.sendWithPromise("GetPageLayout", null);
  2489. }
  2490. getPageMode() {
  2491. return this.messageHandler.sendWithPromise("GetPageMode", null);
  2492. }
  2493. getViewerPreferences() {
  2494. return this.messageHandler.sendWithPromise("GetViewerPreferences", null);
  2495. }
  2496. getOpenAction() {
  2497. return this.messageHandler.sendWithPromise("GetOpenAction", null);
  2498. }
  2499. getAttachments() {
  2500. return this.messageHandler.sendWithPromise("GetAttachments", null);
  2501. }
  2502. getJavaScript() {
  2503. return this.messageHandler.sendWithPromise("GetJavaScript", null);
  2504. }
  2505. getDocJSActions() {
  2506. return this.messageHandler.sendWithPromise("GetDocJSActions", null);
  2507. }
  2508. getPageJSActions(pageIndex) {
  2509. return this.messageHandler.sendWithPromise("GetPageJSActions", {
  2510. pageIndex
  2511. });
  2512. }
  2513. getStructTree(pageIndex) {
  2514. return this.messageHandler.sendWithPromise("GetStructTree", {
  2515. pageIndex
  2516. });
  2517. }
  2518. getOutline() {
  2519. return this.messageHandler.sendWithPromise("GetOutline", null);
  2520. }
  2521. getOptionalContentConfig() {
  2522. return this.messageHandler.sendWithPromise("GetOptionalContentConfig", null).then(results => {
  2523. return new _optional_content_config.OptionalContentConfig(results);
  2524. });
  2525. }
  2526. getPermissions() {
  2527. return this.messageHandler.sendWithPromise("GetPermissions", null);
  2528. }
  2529. getMetadata() {
  2530. return this.#metadataPromise ||= this.messageHandler.sendWithPromise("GetMetadata", null).then(results => {
  2531. return {
  2532. info: results[0],
  2533. metadata: results[1] ? new _metadata.Metadata(results[1]) : null,
  2534. contentDispositionFilename: this._fullReader?.filename ?? null,
  2535. contentLength: this._fullReader?.contentLength ?? null
  2536. };
  2537. });
  2538. }
  2539. getMarkInfo() {
  2540. return this.messageHandler.sendWithPromise("GetMarkInfo", null);
  2541. }
  2542. async startCleanup(keepLoadedFonts = false) {
  2543. if (this.destroyed) {
  2544. return;
  2545. }
  2546. await this.messageHandler.sendWithPromise("Cleanup", null);
  2547. for (const page of this.#pageCache.values()) {
  2548. const cleanupSuccessful = page.cleanup();
  2549. if (!cleanupSuccessful) {
  2550. throw new Error(`startCleanup: Page ${page.pageNumber} is currently rendering.`);
  2551. }
  2552. }
  2553. this.commonObjs.clear();
  2554. if (!keepLoadedFonts) {
  2555. this.fontLoader.clear();
  2556. }
  2557. this.#metadataPromise = null;
  2558. this._getFieldObjectsPromise = null;
  2559. this._hasJSActionsPromise = null;
  2560. }
  2561. get loadingParams() {
  2562. const params = this._params;
  2563. return (0, _util.shadow)(this, "loadingParams", {
  2564. disableAutoFetch: params.disableAutoFetch,
  2565. enableXfa: params.enableXfa
  2566. });
  2567. }
  2568. }
  2569. class PDFObjects {
  2570. #objs = Object.create(null);
  2571. #ensureObj(objId) {
  2572. const obj = this.#objs[objId];
  2573. if (obj) {
  2574. return obj;
  2575. }
  2576. return this.#objs[objId] = {
  2577. capability: (0, _util.createPromiseCapability)(),
  2578. data: null
  2579. };
  2580. }
  2581. get(objId, callback = null) {
  2582. if (callback) {
  2583. const obj = this.#ensureObj(objId);
  2584. obj.capability.promise.then(() => callback(obj.data));
  2585. return null;
  2586. }
  2587. const obj = this.#objs[objId];
  2588. if (!obj?.capability.settled) {
  2589. throw new Error(`Requesting object that isn't resolved yet ${objId}.`);
  2590. }
  2591. return obj.data;
  2592. }
  2593. has(objId) {
  2594. const obj = this.#objs[objId];
  2595. return obj?.capability.settled || false;
  2596. }
  2597. resolve(objId, data = null) {
  2598. const obj = this.#ensureObj(objId);
  2599. obj.data = data;
  2600. obj.capability.resolve();
  2601. }
  2602. clear() {
  2603. this.#objs = Object.create(null);
  2604. }
  2605. }
  2606. class RenderTask {
  2607. #internalRenderTask = null;
  2608. constructor(internalRenderTask) {
  2609. this.#internalRenderTask = internalRenderTask;
  2610. this.onContinue = null;
  2611. }
  2612. get promise() {
  2613. return this.#internalRenderTask.capability.promise;
  2614. }
  2615. cancel(extraDelay = 0) {
  2616. this.#internalRenderTask.cancel(null, extraDelay);
  2617. }
  2618. get separateAnnots() {
  2619. const {
  2620. separateAnnots
  2621. } = this.#internalRenderTask.operatorList;
  2622. if (!separateAnnots) {
  2623. return false;
  2624. }
  2625. const {
  2626. annotationCanvasMap
  2627. } = this.#internalRenderTask;
  2628. return separateAnnots.form || separateAnnots.canvas && annotationCanvasMap?.size > 0;
  2629. }
  2630. }
  2631. exports.RenderTask = RenderTask;
  2632. class InternalRenderTask {
  2633. static #canvasInUse = new WeakSet();
  2634. constructor({
  2635. callback,
  2636. params,
  2637. objs,
  2638. commonObjs,
  2639. annotationCanvasMap,
  2640. operatorList,
  2641. pageIndex,
  2642. canvasFactory,
  2643. useRequestAnimationFrame = false,
  2644. pdfBug = false,
  2645. pageColors = null
  2646. }) {
  2647. this.callback = callback;
  2648. this.params = params;
  2649. this.objs = objs;
  2650. this.commonObjs = commonObjs;
  2651. this.annotationCanvasMap = annotationCanvasMap;
  2652. this.operatorListIdx = null;
  2653. this.operatorList = operatorList;
  2654. this._pageIndex = pageIndex;
  2655. this.canvasFactory = canvasFactory;
  2656. this._pdfBug = pdfBug;
  2657. this.pageColors = pageColors;
  2658. this.running = false;
  2659. this.graphicsReadyCallback = null;
  2660. this.graphicsReady = false;
  2661. this._useRequestAnimationFrame = useRequestAnimationFrame === true && typeof window !== "undefined";
  2662. this.cancelled = false;
  2663. this.capability = (0, _util.createPromiseCapability)();
  2664. this.task = new RenderTask(this);
  2665. this._cancelBound = this.cancel.bind(this);
  2666. this._continueBound = this._continue.bind(this);
  2667. this._scheduleNextBound = this._scheduleNext.bind(this);
  2668. this._nextBound = this._next.bind(this);
  2669. this._canvas = params.canvasContext.canvas;
  2670. }
  2671. get completed() {
  2672. return this.capability.promise.catch(function () {});
  2673. }
  2674. initializeGraphics({
  2675. transparency = false,
  2676. optionalContentConfig
  2677. }) {
  2678. if (this.cancelled) {
  2679. return;
  2680. }
  2681. if (this._canvas) {
  2682. if (InternalRenderTask.#canvasInUse.has(this._canvas)) {
  2683. throw new Error("Cannot use the same canvas during multiple render() operations. " + "Use different canvas or ensure previous operations were " + "cancelled or completed.");
  2684. }
  2685. InternalRenderTask.#canvasInUse.add(this._canvas);
  2686. }
  2687. if (this._pdfBug && globalThis.StepperManager?.enabled) {
  2688. this.stepper = globalThis.StepperManager.create(this._pageIndex);
  2689. this.stepper.init(this.operatorList);
  2690. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  2691. }
  2692. const {
  2693. canvasContext,
  2694. viewport,
  2695. transform,
  2696. background
  2697. } = this.params;
  2698. this.gfx = new _canvas.CanvasGraphics(canvasContext, this.commonObjs, this.objs, this.canvasFactory, {
  2699. optionalContentConfig
  2700. }, this.annotationCanvasMap, this.pageColors);
  2701. this.gfx.beginDrawing({
  2702. transform,
  2703. viewport,
  2704. transparency,
  2705. background
  2706. });
  2707. this.operatorListIdx = 0;
  2708. this.graphicsReady = true;
  2709. this.graphicsReadyCallback?.();
  2710. }
  2711. cancel(error = null, extraDelay = 0) {
  2712. this.running = false;
  2713. this.cancelled = true;
  2714. this.gfx?.endDrawing();
  2715. if (this._canvas) {
  2716. InternalRenderTask.#canvasInUse.delete(this._canvas);
  2717. }
  2718. this.callback(error || new _display_utils.RenderingCancelledException(`Rendering cancelled, page ${this._pageIndex + 1}`, "canvas", extraDelay));
  2719. }
  2720. operatorListChanged() {
  2721. if (!this.graphicsReady) {
  2722. if (!this.graphicsReadyCallback) {
  2723. this.graphicsReadyCallback = this._continueBound;
  2724. }
  2725. return;
  2726. }
  2727. this.stepper?.updateOperatorList(this.operatorList);
  2728. if (this.running) {
  2729. return;
  2730. }
  2731. this._continue();
  2732. }
  2733. _continue() {
  2734. this.running = true;
  2735. if (this.cancelled) {
  2736. return;
  2737. }
  2738. if (this.task.onContinue) {
  2739. this.task.onContinue(this._scheduleNextBound);
  2740. } else {
  2741. this._scheduleNext();
  2742. }
  2743. }
  2744. _scheduleNext() {
  2745. if (this._useRequestAnimationFrame) {
  2746. window.requestAnimationFrame(() => {
  2747. this._nextBound().catch(this._cancelBound);
  2748. });
  2749. } else {
  2750. Promise.resolve().then(this._nextBound).catch(this._cancelBound);
  2751. }
  2752. }
  2753. async _next() {
  2754. if (this.cancelled) {
  2755. return;
  2756. }
  2757. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList, this.operatorListIdx, this._continueBound, this.stepper);
  2758. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  2759. this.running = false;
  2760. if (this.operatorList.lastChunk) {
  2761. this.gfx.endDrawing();
  2762. if (this._canvas) {
  2763. InternalRenderTask.#canvasInUse.delete(this._canvas);
  2764. }
  2765. this.callback();
  2766. }
  2767. }
  2768. }
  2769. }
  2770. const version = '3.3.122';
  2771. exports.version = version;
  2772. const build = '562045607';
  2773. exports.build = build;
  2774. /***/ }),
  2775. /* 3 */
  2776. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  2777. Object.defineProperty(exports, "__esModule", ({
  2778. value: true
  2779. }));
  2780. exports.PrintAnnotationStorage = exports.AnnotationStorage = void 0;
  2781. var _util = __w_pdfjs_require__(1);
  2782. var _editor = __w_pdfjs_require__(4);
  2783. var _murmurhash = __w_pdfjs_require__(8);
  2784. class AnnotationStorage {
  2785. #modified = false;
  2786. #storage = new Map();
  2787. constructor() {
  2788. this.onSetModified = null;
  2789. this.onResetModified = null;
  2790. this.onAnnotationEditor = null;
  2791. }
  2792. getValue(key, defaultValue) {
  2793. const value = this.#storage.get(key);
  2794. if (value === undefined) {
  2795. return defaultValue;
  2796. }
  2797. return Object.assign(defaultValue, value);
  2798. }
  2799. getRawValue(key) {
  2800. return this.#storage.get(key);
  2801. }
  2802. remove(key) {
  2803. this.#storage.delete(key);
  2804. if (this.#storage.size === 0) {
  2805. this.resetModified();
  2806. }
  2807. if (typeof this.onAnnotationEditor === "function") {
  2808. for (const value of this.#storage.values()) {
  2809. if (value instanceof _editor.AnnotationEditor) {
  2810. return;
  2811. }
  2812. }
  2813. this.onAnnotationEditor(null);
  2814. }
  2815. }
  2816. setValue(key, value) {
  2817. const obj = this.#storage.get(key);
  2818. let modified = false;
  2819. if (obj !== undefined) {
  2820. for (const [entry, val] of Object.entries(value)) {
  2821. if (obj[entry] !== val) {
  2822. modified = true;
  2823. obj[entry] = val;
  2824. }
  2825. }
  2826. } else {
  2827. modified = true;
  2828. this.#storage.set(key, value);
  2829. }
  2830. if (modified) {
  2831. this.#setModified();
  2832. }
  2833. if (value instanceof _editor.AnnotationEditor && typeof this.onAnnotationEditor === "function") {
  2834. this.onAnnotationEditor(value.constructor._type);
  2835. }
  2836. }
  2837. has(key) {
  2838. return this.#storage.has(key);
  2839. }
  2840. getAll() {
  2841. return this.#storage.size > 0 ? (0, _util.objectFromMap)(this.#storage) : null;
  2842. }
  2843. get size() {
  2844. return this.#storage.size;
  2845. }
  2846. #setModified() {
  2847. if (!this.#modified) {
  2848. this.#modified = true;
  2849. if (typeof this.onSetModified === "function") {
  2850. this.onSetModified();
  2851. }
  2852. }
  2853. }
  2854. resetModified() {
  2855. if (this.#modified) {
  2856. this.#modified = false;
  2857. if (typeof this.onResetModified === "function") {
  2858. this.onResetModified();
  2859. }
  2860. }
  2861. }
  2862. get print() {
  2863. return new PrintAnnotationStorage(this);
  2864. }
  2865. get serializable() {
  2866. if (this.#storage.size === 0) {
  2867. return null;
  2868. }
  2869. const clone = new Map();
  2870. for (const [key, val] of this.#storage) {
  2871. const serialized = val instanceof _editor.AnnotationEditor ? val.serialize() : val;
  2872. if (serialized) {
  2873. clone.set(key, serialized);
  2874. }
  2875. }
  2876. return clone;
  2877. }
  2878. static getHash(map) {
  2879. if (!map) {
  2880. return "";
  2881. }
  2882. const hash = new _murmurhash.MurmurHash3_64();
  2883. for (const [key, val] of map) {
  2884. hash.update(`${key}:${JSON.stringify(val)}`);
  2885. }
  2886. return hash.hexdigest();
  2887. }
  2888. }
  2889. exports.AnnotationStorage = AnnotationStorage;
  2890. class PrintAnnotationStorage extends AnnotationStorage {
  2891. #serializable = null;
  2892. constructor(parent) {
  2893. super();
  2894. this.#serializable = structuredClone(parent.serializable);
  2895. }
  2896. get print() {
  2897. (0, _util.unreachable)("Should not call PrintAnnotationStorage.print");
  2898. }
  2899. get serializable() {
  2900. return this.#serializable;
  2901. }
  2902. }
  2903. exports.PrintAnnotationStorage = PrintAnnotationStorage;
  2904. /***/ }),
  2905. /* 4 */
  2906. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  2907. Object.defineProperty(exports, "__esModule", ({
  2908. value: true
  2909. }));
  2910. exports.AnnotationEditor = void 0;
  2911. var _tools = __w_pdfjs_require__(5);
  2912. var _util = __w_pdfjs_require__(1);
  2913. class AnnotationEditor {
  2914. #boundFocusin = this.focusin.bind(this);
  2915. #boundFocusout = this.focusout.bind(this);
  2916. #hasBeenSelected = false;
  2917. #isEditing = false;
  2918. #isInEditMode = false;
  2919. _uiManager = null;
  2920. #zIndex = AnnotationEditor._zIndex++;
  2921. static _colorManager = new _tools.ColorManager();
  2922. static _zIndex = 1;
  2923. constructor(parameters) {
  2924. if (this.constructor === AnnotationEditor) {
  2925. (0, _util.unreachable)("Cannot initialize AnnotationEditor.");
  2926. }
  2927. this.parent = parameters.parent;
  2928. this.id = parameters.id;
  2929. this.width = this.height = null;
  2930. this.pageIndex = parameters.parent.pageIndex;
  2931. this.name = parameters.name;
  2932. this.div = null;
  2933. this._uiManager = parameters.uiManager;
  2934. const {
  2935. rotation,
  2936. rawDims: {
  2937. pageWidth,
  2938. pageHeight,
  2939. pageX,
  2940. pageY
  2941. }
  2942. } = this.parent.viewport;
  2943. this.rotation = rotation;
  2944. this.pageDimensions = [pageWidth, pageHeight];
  2945. this.pageTranslation = [pageX, pageY];
  2946. const [width, height] = this.parentDimensions;
  2947. this.x = parameters.x / width;
  2948. this.y = parameters.y / height;
  2949. this.isAttachedToDOM = false;
  2950. }
  2951. static get _defaultLineColor() {
  2952. return (0, _util.shadow)(this, "_defaultLineColor", this._colorManager.getHexCode("CanvasText"));
  2953. }
  2954. addCommands(params) {
  2955. this._uiManager.addCommands(params);
  2956. }
  2957. get currentLayer() {
  2958. return this._uiManager.currentLayer;
  2959. }
  2960. setInBackground() {
  2961. this.div.style.zIndex = 0;
  2962. }
  2963. setInForeground() {
  2964. this.div.style.zIndex = this.#zIndex;
  2965. }
  2966. setParent(parent) {
  2967. if (parent !== null) {
  2968. this.pageIndex = parent.pageIndex;
  2969. this.pageDimensions = parent.pageDimensions;
  2970. }
  2971. this.parent = parent;
  2972. }
  2973. focusin(event) {
  2974. if (!this.#hasBeenSelected) {
  2975. this.parent.setSelected(this);
  2976. } else {
  2977. this.#hasBeenSelected = false;
  2978. }
  2979. }
  2980. focusout(event) {
  2981. if (!this.isAttachedToDOM) {
  2982. return;
  2983. }
  2984. const target = event.relatedTarget;
  2985. if (target?.closest(`#${this.id}`)) {
  2986. return;
  2987. }
  2988. event.preventDefault();
  2989. if (!this.parent?.isMultipleSelection) {
  2990. this.commitOrRemove();
  2991. }
  2992. }
  2993. commitOrRemove() {
  2994. if (this.isEmpty()) {
  2995. this.remove();
  2996. } else {
  2997. this.commit();
  2998. }
  2999. }
  3000. commit() {
  3001. this.addToAnnotationStorage();
  3002. }
  3003. addToAnnotationStorage() {
  3004. this._uiManager.addToAnnotationStorage(this);
  3005. }
  3006. dragstart(event) {
  3007. const rect = this.parent.div.getBoundingClientRect();
  3008. this.startX = event.clientX - rect.x;
  3009. this.startY = event.clientY - rect.y;
  3010. event.dataTransfer.setData("text/plain", this.id);
  3011. event.dataTransfer.effectAllowed = "move";
  3012. }
  3013. setAt(x, y, tx, ty) {
  3014. const [width, height] = this.parentDimensions;
  3015. [tx, ty] = this.screenToPageTranslation(tx, ty);
  3016. this.x = (x + tx) / width;
  3017. this.y = (y + ty) / height;
  3018. this.div.style.left = `${100 * this.x}%`;
  3019. this.div.style.top = `${100 * this.y}%`;
  3020. }
  3021. translate(x, y) {
  3022. const [width, height] = this.parentDimensions;
  3023. [x, y] = this.screenToPageTranslation(x, y);
  3024. this.x += x / width;
  3025. this.y += y / height;
  3026. this.div.style.left = `${100 * this.x}%`;
  3027. this.div.style.top = `${100 * this.y}%`;
  3028. }
  3029. screenToPageTranslation(x, y) {
  3030. switch (this.parentRotation) {
  3031. case 90:
  3032. return [y, -x];
  3033. case 180:
  3034. return [-x, -y];
  3035. case 270:
  3036. return [-y, x];
  3037. default:
  3038. return [x, y];
  3039. }
  3040. }
  3041. get parentScale() {
  3042. return this._uiManager.viewParameters.realScale;
  3043. }
  3044. get parentRotation() {
  3045. return this._uiManager.viewParameters.rotation;
  3046. }
  3047. get parentDimensions() {
  3048. const {
  3049. realScale
  3050. } = this._uiManager.viewParameters;
  3051. const [pageWidth, pageHeight] = this.pageDimensions;
  3052. return [pageWidth * realScale, pageHeight * realScale];
  3053. }
  3054. setDims(width, height) {
  3055. const [parentWidth, parentHeight] = this.parentDimensions;
  3056. this.div.style.width = `${100 * width / parentWidth}%`;
  3057. this.div.style.height = `${100 * height / parentHeight}%`;
  3058. }
  3059. fixDims() {
  3060. const {
  3061. style
  3062. } = this.div;
  3063. const {
  3064. height,
  3065. width
  3066. } = style;
  3067. const widthPercent = width.endsWith("%");
  3068. const heightPercent = height.endsWith("%");
  3069. if (widthPercent && heightPercent) {
  3070. return;
  3071. }
  3072. const [parentWidth, parentHeight] = this.parentDimensions;
  3073. if (!widthPercent) {
  3074. style.width = `${100 * parseFloat(width) / parentWidth}%`;
  3075. }
  3076. if (!heightPercent) {
  3077. style.height = `${100 * parseFloat(height) / parentHeight}%`;
  3078. }
  3079. }
  3080. getInitialTranslation() {
  3081. return [0, 0];
  3082. }
  3083. render() {
  3084. this.div = document.createElement("div");
  3085. this.div.setAttribute("data-editor-rotation", (360 - this.rotation) % 360);
  3086. this.div.className = this.name;
  3087. this.div.setAttribute("id", this.id);
  3088. this.div.setAttribute("tabIndex", 0);
  3089. this.setInForeground();
  3090. this.div.addEventListener("focusin", this.#boundFocusin);
  3091. this.div.addEventListener("focusout", this.#boundFocusout);
  3092. const [tx, ty] = this.getInitialTranslation();
  3093. this.translate(tx, ty);
  3094. (0, _tools.bindEvents)(this, this.div, ["dragstart", "pointerdown"]);
  3095. return this.div;
  3096. }
  3097. pointerdown(event) {
  3098. const {
  3099. isMac
  3100. } = _util.FeatureTest.platform;
  3101. if (event.button !== 0 || event.ctrlKey && isMac) {
  3102. event.preventDefault();
  3103. return;
  3104. }
  3105. if (event.ctrlKey && !isMac || event.shiftKey || event.metaKey && isMac) {
  3106. this.parent.toggleSelected(this);
  3107. } else {
  3108. this.parent.setSelected(this);
  3109. }
  3110. this.#hasBeenSelected = true;
  3111. }
  3112. getRect(tx, ty) {
  3113. const scale = this.parentScale;
  3114. const [pageWidth, pageHeight] = this.pageDimensions;
  3115. const [pageX, pageY] = this.pageTranslation;
  3116. const shiftX = tx / scale;
  3117. const shiftY = ty / scale;
  3118. const x = this.x * pageWidth;
  3119. const y = this.y * pageHeight;
  3120. const width = this.width * pageWidth;
  3121. const height = this.height * pageHeight;
  3122. switch (this.rotation) {
  3123. case 0:
  3124. return [x + shiftX + pageX, pageHeight - y - shiftY - height + pageY, x + shiftX + width + pageX, pageHeight - y - shiftY + pageY];
  3125. case 90:
  3126. return [x + shiftY + pageX, pageHeight - y + shiftX + pageY, x + shiftY + height + pageX, pageHeight - y + shiftX + width + pageY];
  3127. case 180:
  3128. return [x - shiftX - width + pageX, pageHeight - y + shiftY + pageY, x - shiftX + pageX, pageHeight - y + shiftY + height + pageY];
  3129. case 270:
  3130. return [x - shiftY - height + pageX, pageHeight - y - shiftX - width + pageY, x - shiftY + pageX, pageHeight - y - shiftX + pageY];
  3131. default:
  3132. throw new Error("Invalid rotation");
  3133. }
  3134. }
  3135. getRectInCurrentCoords(rect, pageHeight) {
  3136. const [x1, y1, x2, y2] = rect;
  3137. const width = x2 - x1;
  3138. const height = y2 - y1;
  3139. switch (this.rotation) {
  3140. case 0:
  3141. return [x1, pageHeight - y2, width, height];
  3142. case 90:
  3143. return [x1, pageHeight - y1, height, width];
  3144. case 180:
  3145. return [x2, pageHeight - y1, width, height];
  3146. case 270:
  3147. return [x2, pageHeight - y2, height, width];
  3148. default:
  3149. throw new Error("Invalid rotation");
  3150. }
  3151. }
  3152. onceAdded() {}
  3153. isEmpty() {
  3154. return false;
  3155. }
  3156. enableEditMode() {
  3157. this.#isInEditMode = true;
  3158. }
  3159. disableEditMode() {
  3160. this.#isInEditMode = false;
  3161. }
  3162. isInEditMode() {
  3163. return this.#isInEditMode;
  3164. }
  3165. shouldGetKeyboardEvents() {
  3166. return false;
  3167. }
  3168. needsToBeRebuilt() {
  3169. return this.div && !this.isAttachedToDOM;
  3170. }
  3171. rebuild() {
  3172. this.div?.addEventListener("focusin", this.#boundFocusin);
  3173. }
  3174. serialize() {
  3175. (0, _util.unreachable)("An editor must be serializable");
  3176. }
  3177. static deserialize(data, parent, uiManager) {
  3178. const editor = new this.prototype.constructor({
  3179. parent,
  3180. id: parent.getNextId(),
  3181. uiManager
  3182. });
  3183. editor.rotation = data.rotation;
  3184. const [pageWidth, pageHeight] = editor.pageDimensions;
  3185. const [x, y, width, height] = editor.getRectInCurrentCoords(data.rect, pageHeight);
  3186. editor.x = x / pageWidth;
  3187. editor.y = y / pageHeight;
  3188. editor.width = width / pageWidth;
  3189. editor.height = height / pageHeight;
  3190. return editor;
  3191. }
  3192. remove() {
  3193. this.div.removeEventListener("focusin", this.#boundFocusin);
  3194. this.div.removeEventListener("focusout", this.#boundFocusout);
  3195. if (!this.isEmpty()) {
  3196. this.commit();
  3197. }
  3198. this.parent.remove(this);
  3199. }
  3200. select() {
  3201. this.div?.classList.add("selectedEditor");
  3202. }
  3203. unselect() {
  3204. this.div?.classList.remove("selectedEditor");
  3205. }
  3206. updateParams(type, value) {}
  3207. disableEditing() {}
  3208. enableEditing() {}
  3209. get propertiesToUpdate() {
  3210. return {};
  3211. }
  3212. get contentDiv() {
  3213. return this.div;
  3214. }
  3215. get isEditing() {
  3216. return this.#isEditing;
  3217. }
  3218. set isEditing(value) {
  3219. this.#isEditing = value;
  3220. if (value) {
  3221. this.parent.setSelected(this);
  3222. this.parent.setActiveEditor(this);
  3223. } else {
  3224. this.parent.setActiveEditor(null);
  3225. }
  3226. }
  3227. }
  3228. exports.AnnotationEditor = AnnotationEditor;
  3229. /***/ }),
  3230. /* 5 */
  3231. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3232. Object.defineProperty(exports, "__esModule", ({
  3233. value: true
  3234. }));
  3235. exports.KeyboardManager = exports.CommandManager = exports.ColorManager = exports.AnnotationEditorUIManager = void 0;
  3236. exports.bindEvents = bindEvents;
  3237. exports.opacityToHex = opacityToHex;
  3238. var _util = __w_pdfjs_require__(1);
  3239. var _display_utils = __w_pdfjs_require__(6);
  3240. function bindEvents(obj, element, names) {
  3241. for (const name of names) {
  3242. element.addEventListener(name, obj[name].bind(obj));
  3243. }
  3244. }
  3245. function opacityToHex(opacity) {
  3246. return Math.round(Math.min(255, Math.max(1, 255 * opacity))).toString(16).padStart(2, "0");
  3247. }
  3248. class IdManager {
  3249. #id = 0;
  3250. getId() {
  3251. return `${_util.AnnotationEditorPrefix}${this.#id++}`;
  3252. }
  3253. }
  3254. class CommandManager {
  3255. #commands = [];
  3256. #locked = false;
  3257. #maxSize;
  3258. #position = -1;
  3259. constructor(maxSize = 128) {
  3260. this.#maxSize = maxSize;
  3261. }
  3262. add({
  3263. cmd,
  3264. undo,
  3265. mustExec,
  3266. type = NaN,
  3267. overwriteIfSameType = false,
  3268. keepUndo = false
  3269. }) {
  3270. if (mustExec) {
  3271. cmd();
  3272. }
  3273. if (this.#locked) {
  3274. return;
  3275. }
  3276. const save = {
  3277. cmd,
  3278. undo,
  3279. type
  3280. };
  3281. if (this.#position === -1) {
  3282. if (this.#commands.length > 0) {
  3283. this.#commands.length = 0;
  3284. }
  3285. this.#position = 0;
  3286. this.#commands.push(save);
  3287. return;
  3288. }
  3289. if (overwriteIfSameType && this.#commands[this.#position].type === type) {
  3290. if (keepUndo) {
  3291. save.undo = this.#commands[this.#position].undo;
  3292. }
  3293. this.#commands[this.#position] = save;
  3294. return;
  3295. }
  3296. const next = this.#position + 1;
  3297. if (next === this.#maxSize) {
  3298. this.#commands.splice(0, 1);
  3299. } else {
  3300. this.#position = next;
  3301. if (next < this.#commands.length) {
  3302. this.#commands.splice(next);
  3303. }
  3304. }
  3305. this.#commands.push(save);
  3306. }
  3307. undo() {
  3308. if (this.#position === -1) {
  3309. return;
  3310. }
  3311. this.#locked = true;
  3312. this.#commands[this.#position].undo();
  3313. this.#locked = false;
  3314. this.#position -= 1;
  3315. }
  3316. redo() {
  3317. if (this.#position < this.#commands.length - 1) {
  3318. this.#position += 1;
  3319. this.#locked = true;
  3320. this.#commands[this.#position].cmd();
  3321. this.#locked = false;
  3322. }
  3323. }
  3324. hasSomethingToUndo() {
  3325. return this.#position !== -1;
  3326. }
  3327. hasSomethingToRedo() {
  3328. return this.#position < this.#commands.length - 1;
  3329. }
  3330. destroy() {
  3331. this.#commands = null;
  3332. }
  3333. }
  3334. exports.CommandManager = CommandManager;
  3335. class KeyboardManager {
  3336. constructor(callbacks) {
  3337. this.buffer = [];
  3338. this.callbacks = new Map();
  3339. this.allKeys = new Set();
  3340. const {
  3341. isMac
  3342. } = _util.FeatureTest.platform;
  3343. for (const [keys, callback] of callbacks) {
  3344. for (const key of keys) {
  3345. const isMacKey = key.startsWith("mac+");
  3346. if (isMac && isMacKey) {
  3347. this.callbacks.set(key.slice(4), callback);
  3348. this.allKeys.add(key.split("+").at(-1));
  3349. } else if (!isMac && !isMacKey) {
  3350. this.callbacks.set(key, callback);
  3351. this.allKeys.add(key.split("+").at(-1));
  3352. }
  3353. }
  3354. }
  3355. }
  3356. #serialize(event) {
  3357. if (event.altKey) {
  3358. this.buffer.push("alt");
  3359. }
  3360. if (event.ctrlKey) {
  3361. this.buffer.push("ctrl");
  3362. }
  3363. if (event.metaKey) {
  3364. this.buffer.push("meta");
  3365. }
  3366. if (event.shiftKey) {
  3367. this.buffer.push("shift");
  3368. }
  3369. this.buffer.push(event.key);
  3370. const str = this.buffer.join("+");
  3371. this.buffer.length = 0;
  3372. return str;
  3373. }
  3374. exec(self, event) {
  3375. if (!this.allKeys.has(event.key)) {
  3376. return;
  3377. }
  3378. const callback = this.callbacks.get(this.#serialize(event));
  3379. if (!callback) {
  3380. return;
  3381. }
  3382. callback.bind(self)();
  3383. event.stopPropagation();
  3384. event.preventDefault();
  3385. }
  3386. }
  3387. exports.KeyboardManager = KeyboardManager;
  3388. class ColorManager {
  3389. static _colorsMapping = new Map([["CanvasText", [0, 0, 0]], ["Canvas", [255, 255, 255]]]);
  3390. get _colors() {
  3391. const colors = new Map([["CanvasText", null], ["Canvas", null]]);
  3392. (0, _display_utils.getColorValues)(colors);
  3393. return (0, _util.shadow)(this, "_colors", colors);
  3394. }
  3395. convert(color) {
  3396. const rgb = (0, _display_utils.getRGB)(color);
  3397. if (!window.matchMedia("(forced-colors: active)").matches) {
  3398. return rgb;
  3399. }
  3400. for (const [name, RGB] of this._colors) {
  3401. if (RGB.every((x, i) => x === rgb[i])) {
  3402. return ColorManager._colorsMapping.get(name);
  3403. }
  3404. }
  3405. return rgb;
  3406. }
  3407. getHexCode(name) {
  3408. const rgb = this._colors.get(name);
  3409. if (!rgb) {
  3410. return name;
  3411. }
  3412. return _util.Util.makeHexColor(...rgb);
  3413. }
  3414. }
  3415. exports.ColorManager = ColorManager;
  3416. class AnnotationEditorUIManager {
  3417. #activeEditor = null;
  3418. #allEditors = new Map();
  3419. #allLayers = new Map();
  3420. #annotationStorage = null;
  3421. #commandManager = new CommandManager();
  3422. #currentPageIndex = 0;
  3423. #editorTypes = null;
  3424. #editorsToRescale = new Set();
  3425. #eventBus = null;
  3426. #idManager = new IdManager();
  3427. #isEnabled = false;
  3428. #mode = _util.AnnotationEditorType.NONE;
  3429. #selectedEditors = new Set();
  3430. #boundCopy = this.copy.bind(this);
  3431. #boundCut = this.cut.bind(this);
  3432. #boundPaste = this.paste.bind(this);
  3433. #boundKeydown = this.keydown.bind(this);
  3434. #boundOnEditingAction = this.onEditingAction.bind(this);
  3435. #boundOnPageChanging = this.onPageChanging.bind(this);
  3436. #boundOnScaleChanging = this.onScaleChanging.bind(this);
  3437. #boundOnRotationChanging = this.onRotationChanging.bind(this);
  3438. #previousStates = {
  3439. isEditing: false,
  3440. isEmpty: true,
  3441. hasSomethingToUndo: false,
  3442. hasSomethingToRedo: false,
  3443. hasSelectedEditor: false
  3444. };
  3445. #container = null;
  3446. 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]]);
  3447. constructor(container, eventBus, annotationStorage) {
  3448. this.#container = container;
  3449. this.#eventBus = eventBus;
  3450. this.#eventBus._on("editingaction", this.#boundOnEditingAction);
  3451. this.#eventBus._on("pagechanging", this.#boundOnPageChanging);
  3452. this.#eventBus._on("scalechanging", this.#boundOnScaleChanging);
  3453. this.#eventBus._on("rotationchanging", this.#boundOnRotationChanging);
  3454. this.#annotationStorage = annotationStorage;
  3455. this.viewParameters = {
  3456. realScale: _display_utils.PixelsPerInch.PDF_TO_CSS_UNITS,
  3457. rotation: 0
  3458. };
  3459. }
  3460. destroy() {
  3461. this.#removeKeyboardManager();
  3462. this.#eventBus._off("editingaction", this.#boundOnEditingAction);
  3463. this.#eventBus._off("pagechanging", this.#boundOnPageChanging);
  3464. this.#eventBus._off("scalechanging", this.#boundOnScaleChanging);
  3465. this.#eventBus._off("rotationchanging", this.#boundOnRotationChanging);
  3466. for (const layer of this.#allLayers.values()) {
  3467. layer.destroy();
  3468. }
  3469. this.#allLayers.clear();
  3470. this.#allEditors.clear();
  3471. this.#editorsToRescale.clear();
  3472. this.#activeEditor = null;
  3473. this.#selectedEditors.clear();
  3474. this.#commandManager.destroy();
  3475. }
  3476. onPageChanging({
  3477. pageNumber
  3478. }) {
  3479. this.#currentPageIndex = pageNumber - 1;
  3480. }
  3481. focusMainContainer() {
  3482. this.#container.focus();
  3483. }
  3484. addShouldRescale(editor) {
  3485. this.#editorsToRescale.add(editor);
  3486. }
  3487. removeShouldRescale(editor) {
  3488. this.#editorsToRescale.delete(editor);
  3489. }
  3490. onScaleChanging({
  3491. scale
  3492. }) {
  3493. this.commitOrRemove();
  3494. this.viewParameters.realScale = scale * _display_utils.PixelsPerInch.PDF_TO_CSS_UNITS;
  3495. for (const editor of this.#editorsToRescale) {
  3496. editor.onScaleChanging();
  3497. }
  3498. }
  3499. onRotationChanging({
  3500. pagesRotation
  3501. }) {
  3502. this.commitOrRemove();
  3503. this.viewParameters.rotation = pagesRotation;
  3504. }
  3505. addToAnnotationStorage(editor) {
  3506. if (!editor.isEmpty() && this.#annotationStorage && !this.#annotationStorage.has(editor.id)) {
  3507. this.#annotationStorage.setValue(editor.id, editor);
  3508. }
  3509. }
  3510. #addKeyboardManager() {
  3511. this.#container.addEventListener("keydown", this.#boundKeydown);
  3512. }
  3513. #removeKeyboardManager() {
  3514. this.#container.removeEventListener("keydown", this.#boundKeydown);
  3515. }
  3516. #addCopyPasteListeners() {
  3517. document.addEventListener("copy", this.#boundCopy);
  3518. document.addEventListener("cut", this.#boundCut);
  3519. document.addEventListener("paste", this.#boundPaste);
  3520. }
  3521. #removeCopyPasteListeners() {
  3522. document.removeEventListener("copy", this.#boundCopy);
  3523. document.removeEventListener("cut", this.#boundCut);
  3524. document.removeEventListener("paste", this.#boundPaste);
  3525. }
  3526. copy(event) {
  3527. event.preventDefault();
  3528. if (this.#activeEditor) {
  3529. this.#activeEditor.commitOrRemove();
  3530. }
  3531. if (!this.hasSelection) {
  3532. return;
  3533. }
  3534. const editors = [];
  3535. for (const editor of this.#selectedEditors) {
  3536. if (!editor.isEmpty()) {
  3537. editors.push(editor.serialize());
  3538. }
  3539. }
  3540. if (editors.length === 0) {
  3541. return;
  3542. }
  3543. event.clipboardData.setData("application/pdfjs", JSON.stringify(editors));
  3544. }
  3545. cut(event) {
  3546. this.copy(event);
  3547. this.delete();
  3548. }
  3549. paste(event) {
  3550. event.preventDefault();
  3551. let data = event.clipboardData.getData("application/pdfjs");
  3552. if (!data) {
  3553. return;
  3554. }
  3555. try {
  3556. data = JSON.parse(data);
  3557. } catch (ex) {
  3558. (0, _util.warn)(`paste: "${ex.message}".`);
  3559. return;
  3560. }
  3561. if (!Array.isArray(data)) {
  3562. return;
  3563. }
  3564. this.unselectAll();
  3565. const layer = this.#allLayers.get(this.#currentPageIndex);
  3566. try {
  3567. const newEditors = [];
  3568. for (const editor of data) {
  3569. const deserializedEditor = layer.deserialize(editor);
  3570. if (!deserializedEditor) {
  3571. return;
  3572. }
  3573. newEditors.push(deserializedEditor);
  3574. }
  3575. const cmd = () => {
  3576. for (const editor of newEditors) {
  3577. this.#addEditorToLayer(editor);
  3578. }
  3579. this.#selectEditors(newEditors);
  3580. };
  3581. const undo = () => {
  3582. for (const editor of newEditors) {
  3583. editor.remove();
  3584. }
  3585. };
  3586. this.addCommands({
  3587. cmd,
  3588. undo,
  3589. mustExec: true
  3590. });
  3591. } catch (ex) {
  3592. (0, _util.warn)(`paste: "${ex.message}".`);
  3593. }
  3594. }
  3595. keydown(event) {
  3596. if (!this.getActive()?.shouldGetKeyboardEvents()) {
  3597. AnnotationEditorUIManager._keyboardManager.exec(this, event);
  3598. }
  3599. }
  3600. onEditingAction(details) {
  3601. if (["undo", "redo", "delete", "selectAll"].includes(details.name)) {
  3602. this[details.name]();
  3603. }
  3604. }
  3605. #dispatchUpdateStates(details) {
  3606. const hasChanged = Object.entries(details).some(([key, value]) => this.#previousStates[key] !== value);
  3607. if (hasChanged) {
  3608. this.#eventBus.dispatch("annotationeditorstateschanged", {
  3609. source: this,
  3610. details: Object.assign(this.#previousStates, details)
  3611. });
  3612. }
  3613. }
  3614. #dispatchUpdateUI(details) {
  3615. this.#eventBus.dispatch("annotationeditorparamschanged", {
  3616. source: this,
  3617. details
  3618. });
  3619. }
  3620. setEditingState(isEditing) {
  3621. if (isEditing) {
  3622. this.#addKeyboardManager();
  3623. this.#addCopyPasteListeners();
  3624. this.#dispatchUpdateStates({
  3625. isEditing: this.#mode !== _util.AnnotationEditorType.NONE,
  3626. isEmpty: this.#isEmpty(),
  3627. hasSomethingToUndo: this.#commandManager.hasSomethingToUndo(),
  3628. hasSomethingToRedo: this.#commandManager.hasSomethingToRedo(),
  3629. hasSelectedEditor: false
  3630. });
  3631. } else {
  3632. this.#removeKeyboardManager();
  3633. this.#removeCopyPasteListeners();
  3634. this.#dispatchUpdateStates({
  3635. isEditing: false
  3636. });
  3637. }
  3638. }
  3639. registerEditorTypes(types) {
  3640. if (this.#editorTypes) {
  3641. return;
  3642. }
  3643. this.#editorTypes = types;
  3644. for (const editorType of this.#editorTypes) {
  3645. this.#dispatchUpdateUI(editorType.defaultPropertiesToUpdate);
  3646. }
  3647. }
  3648. getId() {
  3649. return this.#idManager.getId();
  3650. }
  3651. get currentLayer() {
  3652. return this.#allLayers.get(this.#currentPageIndex);
  3653. }
  3654. get currentPageIndex() {
  3655. return this.#currentPageIndex;
  3656. }
  3657. addLayer(layer) {
  3658. this.#allLayers.set(layer.pageIndex, layer);
  3659. if (this.#isEnabled) {
  3660. layer.enable();
  3661. } else {
  3662. layer.disable();
  3663. }
  3664. }
  3665. removeLayer(layer) {
  3666. this.#allLayers.delete(layer.pageIndex);
  3667. }
  3668. updateMode(mode) {
  3669. this.#mode = mode;
  3670. if (mode === _util.AnnotationEditorType.NONE) {
  3671. this.setEditingState(false);
  3672. this.#disableAll();
  3673. } else {
  3674. this.setEditingState(true);
  3675. this.#enableAll();
  3676. for (const layer of this.#allLayers.values()) {
  3677. layer.updateMode(mode);
  3678. }
  3679. }
  3680. }
  3681. updateToolbar(mode) {
  3682. if (mode === this.#mode) {
  3683. return;
  3684. }
  3685. this.#eventBus.dispatch("switchannotationeditormode", {
  3686. source: this,
  3687. mode
  3688. });
  3689. }
  3690. updateParams(type, value) {
  3691. if (!this.#editorTypes) {
  3692. return;
  3693. }
  3694. for (const editor of this.#selectedEditors) {
  3695. editor.updateParams(type, value);
  3696. }
  3697. for (const editorType of this.#editorTypes) {
  3698. editorType.updateDefaultParams(type, value);
  3699. }
  3700. }
  3701. #enableAll() {
  3702. if (!this.#isEnabled) {
  3703. this.#isEnabled = true;
  3704. for (const layer of this.#allLayers.values()) {
  3705. layer.enable();
  3706. }
  3707. }
  3708. }
  3709. #disableAll() {
  3710. this.unselectAll();
  3711. if (this.#isEnabled) {
  3712. this.#isEnabled = false;
  3713. for (const layer of this.#allLayers.values()) {
  3714. layer.disable();
  3715. }
  3716. }
  3717. }
  3718. getEditors(pageIndex) {
  3719. const editors = [];
  3720. for (const editor of this.#allEditors.values()) {
  3721. if (editor.pageIndex === pageIndex) {
  3722. editors.push(editor);
  3723. }
  3724. }
  3725. return editors;
  3726. }
  3727. getEditor(id) {
  3728. return this.#allEditors.get(id);
  3729. }
  3730. addEditor(editor) {
  3731. this.#allEditors.set(editor.id, editor);
  3732. }
  3733. removeEditor(editor) {
  3734. this.#allEditors.delete(editor.id);
  3735. this.unselect(editor);
  3736. this.#annotationStorage?.remove(editor.id);
  3737. }
  3738. #addEditorToLayer(editor) {
  3739. const layer = this.#allLayers.get(editor.pageIndex);
  3740. if (layer) {
  3741. layer.addOrRebuild(editor);
  3742. } else {
  3743. this.addEditor(editor);
  3744. }
  3745. }
  3746. setActiveEditor(editor) {
  3747. if (this.#activeEditor === editor) {
  3748. return;
  3749. }
  3750. this.#activeEditor = editor;
  3751. if (editor) {
  3752. this.#dispatchUpdateUI(editor.propertiesToUpdate);
  3753. }
  3754. }
  3755. toggleSelected(editor) {
  3756. if (this.#selectedEditors.has(editor)) {
  3757. this.#selectedEditors.delete(editor);
  3758. editor.unselect();
  3759. this.#dispatchUpdateStates({
  3760. hasSelectedEditor: this.hasSelection
  3761. });
  3762. return;
  3763. }
  3764. this.#selectedEditors.add(editor);
  3765. editor.select();
  3766. this.#dispatchUpdateUI(editor.propertiesToUpdate);
  3767. this.#dispatchUpdateStates({
  3768. hasSelectedEditor: true
  3769. });
  3770. }
  3771. setSelected(editor) {
  3772. for (const ed of this.#selectedEditors) {
  3773. if (ed !== editor) {
  3774. ed.unselect();
  3775. }
  3776. }
  3777. this.#selectedEditors.clear();
  3778. this.#selectedEditors.add(editor);
  3779. editor.select();
  3780. this.#dispatchUpdateUI(editor.propertiesToUpdate);
  3781. this.#dispatchUpdateStates({
  3782. hasSelectedEditor: true
  3783. });
  3784. }
  3785. isSelected(editor) {
  3786. return this.#selectedEditors.has(editor);
  3787. }
  3788. unselect(editor) {
  3789. editor.unselect();
  3790. this.#selectedEditors.delete(editor);
  3791. this.#dispatchUpdateStates({
  3792. hasSelectedEditor: this.hasSelection
  3793. });
  3794. }
  3795. get hasSelection() {
  3796. return this.#selectedEditors.size !== 0;
  3797. }
  3798. undo() {
  3799. this.#commandManager.undo();
  3800. this.#dispatchUpdateStates({
  3801. hasSomethingToUndo: this.#commandManager.hasSomethingToUndo(),
  3802. hasSomethingToRedo: true,
  3803. isEmpty: this.#isEmpty()
  3804. });
  3805. }
  3806. redo() {
  3807. this.#commandManager.redo();
  3808. this.#dispatchUpdateStates({
  3809. hasSomethingToUndo: true,
  3810. hasSomethingToRedo: this.#commandManager.hasSomethingToRedo(),
  3811. isEmpty: this.#isEmpty()
  3812. });
  3813. }
  3814. addCommands(params) {
  3815. this.#commandManager.add(params);
  3816. this.#dispatchUpdateStates({
  3817. hasSomethingToUndo: true,
  3818. hasSomethingToRedo: false,
  3819. isEmpty: this.#isEmpty()
  3820. });
  3821. }
  3822. #isEmpty() {
  3823. if (this.#allEditors.size === 0) {
  3824. return true;
  3825. }
  3826. if (this.#allEditors.size === 1) {
  3827. for (const editor of this.#allEditors.values()) {
  3828. return editor.isEmpty();
  3829. }
  3830. }
  3831. return false;
  3832. }
  3833. delete() {
  3834. this.commitOrRemove();
  3835. if (!this.hasSelection) {
  3836. return;
  3837. }
  3838. const editors = [...this.#selectedEditors];
  3839. const cmd = () => {
  3840. for (const editor of editors) {
  3841. editor.remove();
  3842. }
  3843. };
  3844. const undo = () => {
  3845. for (const editor of editors) {
  3846. this.#addEditorToLayer(editor);
  3847. }
  3848. };
  3849. this.addCommands({
  3850. cmd,
  3851. undo,
  3852. mustExec: true
  3853. });
  3854. }
  3855. commitOrRemove() {
  3856. this.#activeEditor?.commitOrRemove();
  3857. }
  3858. #selectEditors(editors) {
  3859. this.#selectedEditors.clear();
  3860. for (const editor of editors) {
  3861. if (editor.isEmpty()) {
  3862. continue;
  3863. }
  3864. this.#selectedEditors.add(editor);
  3865. editor.select();
  3866. }
  3867. this.#dispatchUpdateStates({
  3868. hasSelectedEditor: true
  3869. });
  3870. }
  3871. selectAll() {
  3872. for (const editor of this.#selectedEditors) {
  3873. editor.commit();
  3874. }
  3875. this.#selectEditors(this.#allEditors.values());
  3876. }
  3877. unselectAll() {
  3878. if (this.#activeEditor) {
  3879. this.#activeEditor.commitOrRemove();
  3880. return;
  3881. }
  3882. if (this.#selectedEditors.size === 0) {
  3883. return;
  3884. }
  3885. for (const editor of this.#selectedEditors) {
  3886. editor.unselect();
  3887. }
  3888. this.#selectedEditors.clear();
  3889. this.#dispatchUpdateStates({
  3890. hasSelectedEditor: false
  3891. });
  3892. }
  3893. isActive(editor) {
  3894. return this.#activeEditor === editor;
  3895. }
  3896. getActive() {
  3897. return this.#activeEditor;
  3898. }
  3899. getMode() {
  3900. return this.#mode;
  3901. }
  3902. }
  3903. exports.AnnotationEditorUIManager = AnnotationEditorUIManager;
  3904. /***/ }),
  3905. /* 6 */
  3906. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3907. Object.defineProperty(exports, "__esModule", ({
  3908. value: true
  3909. }));
  3910. exports.StatTimer = exports.RenderingCancelledException = exports.PixelsPerInch = exports.PageViewport = exports.PDFDateString = exports.DOMStandardFontDataFactory = exports.DOMSVGFactory = exports.DOMCanvasFactory = exports.DOMCMapReaderFactory = exports.AnnotationPrefix = void 0;
  3911. exports.deprecated = deprecated;
  3912. exports.getColorValues = getColorValues;
  3913. exports.getCurrentTransform = getCurrentTransform;
  3914. exports.getCurrentTransformInverse = getCurrentTransformInverse;
  3915. exports.getFilenameFromUrl = getFilenameFromUrl;
  3916. exports.getPdfFilenameFromUrl = getPdfFilenameFromUrl;
  3917. exports.getRGB = getRGB;
  3918. exports.getXfaPageViewport = getXfaPageViewport;
  3919. exports.isDataScheme = isDataScheme;
  3920. exports.isPdfFile = isPdfFile;
  3921. exports.isValidFetchUrl = isValidFetchUrl;
  3922. exports.loadScript = loadScript;
  3923. exports.setLayerDimensions = setLayerDimensions;
  3924. var _base_factory = __w_pdfjs_require__(7);
  3925. var _util = __w_pdfjs_require__(1);
  3926. const SVG_NS = "http://www.w3.org/2000/svg";
  3927. const AnnotationPrefix = "pdfjs_internal_id_";
  3928. exports.AnnotationPrefix = AnnotationPrefix;
  3929. class PixelsPerInch {
  3930. static CSS = 96.0;
  3931. static PDF = 72.0;
  3932. static PDF_TO_CSS_UNITS = this.CSS / this.PDF;
  3933. }
  3934. exports.PixelsPerInch = PixelsPerInch;
  3935. class DOMCanvasFactory extends _base_factory.BaseCanvasFactory {
  3936. constructor({
  3937. ownerDocument = globalThis.document
  3938. } = {}) {
  3939. super();
  3940. this._document = ownerDocument;
  3941. }
  3942. _createCanvas(width, height) {
  3943. const canvas = this._document.createElement("canvas");
  3944. canvas.width = width;
  3945. canvas.height = height;
  3946. return canvas;
  3947. }
  3948. }
  3949. exports.DOMCanvasFactory = DOMCanvasFactory;
  3950. async function fetchData(url, asTypedArray = false) {
  3951. if (isValidFetchUrl(url, document.baseURI)) {
  3952. const response = await fetch(url);
  3953. if (!response.ok) {
  3954. throw new Error(response.statusText);
  3955. }
  3956. return asTypedArray ? new Uint8Array(await response.arrayBuffer()) : (0, _util.stringToBytes)(await response.text());
  3957. }
  3958. return new Promise((resolve, reject) => {
  3959. const request = new XMLHttpRequest();
  3960. request.open("GET", url, true);
  3961. if (asTypedArray) {
  3962. request.responseType = "arraybuffer";
  3963. }
  3964. request.onreadystatechange = () => {
  3965. if (request.readyState !== XMLHttpRequest.DONE) {
  3966. return;
  3967. }
  3968. if (request.status === 200 || request.status === 0) {
  3969. let data;
  3970. if (asTypedArray && request.response) {
  3971. data = new Uint8Array(request.response);
  3972. } else if (!asTypedArray && request.responseText) {
  3973. data = (0, _util.stringToBytes)(request.responseText);
  3974. }
  3975. if (data) {
  3976. resolve(data);
  3977. return;
  3978. }
  3979. }
  3980. reject(new Error(request.statusText));
  3981. };
  3982. request.send(null);
  3983. });
  3984. }
  3985. class DOMCMapReaderFactory extends _base_factory.BaseCMapReaderFactory {
  3986. _fetchData(url, compressionType) {
  3987. return fetchData(url, this.isCompressed).then(data => {
  3988. return {
  3989. cMapData: data,
  3990. compressionType
  3991. };
  3992. });
  3993. }
  3994. }
  3995. exports.DOMCMapReaderFactory = DOMCMapReaderFactory;
  3996. class DOMStandardFontDataFactory extends _base_factory.BaseStandardFontDataFactory {
  3997. _fetchData(url) {
  3998. return fetchData(url, true);
  3999. }
  4000. }
  4001. exports.DOMStandardFontDataFactory = DOMStandardFontDataFactory;
  4002. class DOMSVGFactory extends _base_factory.BaseSVGFactory {
  4003. _createSVG(type) {
  4004. return document.createElementNS(SVG_NS, type);
  4005. }
  4006. }
  4007. exports.DOMSVGFactory = DOMSVGFactory;
  4008. class PageViewport {
  4009. constructor({
  4010. viewBox,
  4011. scale,
  4012. rotation,
  4013. offsetX = 0,
  4014. offsetY = 0,
  4015. dontFlip = false
  4016. }) {
  4017. this.viewBox = viewBox;
  4018. this.scale = scale;
  4019. this.rotation = rotation;
  4020. this.offsetX = offsetX;
  4021. this.offsetY = offsetY;
  4022. const centerX = (viewBox[2] + viewBox[0]) / 2;
  4023. const centerY = (viewBox[3] + viewBox[1]) / 2;
  4024. let rotateA, rotateB, rotateC, rotateD;
  4025. rotation %= 360;
  4026. if (rotation < 0) {
  4027. rotation += 360;
  4028. }
  4029. switch (rotation) {
  4030. case 180:
  4031. rotateA = -1;
  4032. rotateB = 0;
  4033. rotateC = 0;
  4034. rotateD = 1;
  4035. break;
  4036. case 90:
  4037. rotateA = 0;
  4038. rotateB = 1;
  4039. rotateC = 1;
  4040. rotateD = 0;
  4041. break;
  4042. case 270:
  4043. rotateA = 0;
  4044. rotateB = -1;
  4045. rotateC = -1;
  4046. rotateD = 0;
  4047. break;
  4048. case 0:
  4049. rotateA = 1;
  4050. rotateB = 0;
  4051. rotateC = 0;
  4052. rotateD = -1;
  4053. break;
  4054. default:
  4055. throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.");
  4056. }
  4057. if (dontFlip) {
  4058. rotateC = -rotateC;
  4059. rotateD = -rotateD;
  4060. }
  4061. let offsetCanvasX, offsetCanvasY;
  4062. let width, height;
  4063. if (rotateA === 0) {
  4064. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  4065. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  4066. width = (viewBox[3] - viewBox[1]) * scale;
  4067. height = (viewBox[2] - viewBox[0]) * scale;
  4068. } else {
  4069. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  4070. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  4071. width = (viewBox[2] - viewBox[0]) * scale;
  4072. height = (viewBox[3] - viewBox[1]) * scale;
  4073. }
  4074. this.transform = [rotateA * scale, rotateB * scale, rotateC * scale, rotateD * scale, offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY, offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY];
  4075. this.width = width;
  4076. this.height = height;
  4077. }
  4078. get rawDims() {
  4079. const {
  4080. viewBox
  4081. } = this;
  4082. return (0, _util.shadow)(this, "rawDims", {
  4083. pageWidth: viewBox[2] - viewBox[0],
  4084. pageHeight: viewBox[3] - viewBox[1],
  4085. pageX: viewBox[0],
  4086. pageY: viewBox[1]
  4087. });
  4088. }
  4089. clone({
  4090. scale = this.scale,
  4091. rotation = this.rotation,
  4092. offsetX = this.offsetX,
  4093. offsetY = this.offsetY,
  4094. dontFlip = false
  4095. } = {}) {
  4096. return new PageViewport({
  4097. viewBox: this.viewBox.slice(),
  4098. scale,
  4099. rotation,
  4100. offsetX,
  4101. offsetY,
  4102. dontFlip
  4103. });
  4104. }
  4105. convertToViewportPoint(x, y) {
  4106. return _util.Util.applyTransform([x, y], this.transform);
  4107. }
  4108. convertToViewportRectangle(rect) {
  4109. const topLeft = _util.Util.applyTransform([rect[0], rect[1]], this.transform);
  4110. const bottomRight = _util.Util.applyTransform([rect[2], rect[3]], this.transform);
  4111. return [topLeft[0], topLeft[1], bottomRight[0], bottomRight[1]];
  4112. }
  4113. convertToPdfPoint(x, y) {
  4114. return _util.Util.applyInverseTransform([x, y], this.transform);
  4115. }
  4116. }
  4117. exports.PageViewport = PageViewport;
  4118. class RenderingCancelledException extends _util.BaseException {
  4119. constructor(msg, type, extraDelay = 0) {
  4120. super(msg, "RenderingCancelledException");
  4121. this.type = type;
  4122. this.extraDelay = extraDelay;
  4123. }
  4124. }
  4125. exports.RenderingCancelledException = RenderingCancelledException;
  4126. function isDataScheme(url) {
  4127. const ii = url.length;
  4128. let i = 0;
  4129. while (i < ii && url[i].trim() === "") {
  4130. i++;
  4131. }
  4132. return url.substring(i, i + 5).toLowerCase() === "data:";
  4133. }
  4134. function isPdfFile(filename) {
  4135. return typeof filename === "string" && /\.pdf$/i.test(filename);
  4136. }
  4137. function getFilenameFromUrl(url, onlyStripPath = false) {
  4138. if (!onlyStripPath) {
  4139. [url] = url.split(/[#?]/, 1);
  4140. }
  4141. return url.substring(url.lastIndexOf("/") + 1);
  4142. }
  4143. function getPdfFilenameFromUrl(url, defaultFilename = "document.pdf") {
  4144. if (typeof url !== "string") {
  4145. return defaultFilename;
  4146. }
  4147. if (isDataScheme(url)) {
  4148. (0, _util.warn)('getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.');
  4149. return defaultFilename;
  4150. }
  4151. const reURI = /^(?:(?:[^:]+:)?\/\/[^/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
  4152. const reFilename = /[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
  4153. const splitURI = reURI.exec(url);
  4154. let suggestedFilename = reFilename.exec(splitURI[1]) || reFilename.exec(splitURI[2]) || reFilename.exec(splitURI[3]);
  4155. if (suggestedFilename) {
  4156. suggestedFilename = suggestedFilename[0];
  4157. if (suggestedFilename.includes("%")) {
  4158. try {
  4159. suggestedFilename = reFilename.exec(decodeURIComponent(suggestedFilename))[0];
  4160. } catch (ex) {}
  4161. }
  4162. }
  4163. return suggestedFilename || defaultFilename;
  4164. }
  4165. class StatTimer {
  4166. started = Object.create(null);
  4167. times = [];
  4168. time(name) {
  4169. if (name in this.started) {
  4170. (0, _util.warn)(`Timer is already running for ${name}`);
  4171. }
  4172. this.started[name] = Date.now();
  4173. }
  4174. timeEnd(name) {
  4175. if (!(name in this.started)) {
  4176. (0, _util.warn)(`Timer has not been started for ${name}`);
  4177. }
  4178. this.times.push({
  4179. name,
  4180. start: this.started[name],
  4181. end: Date.now()
  4182. });
  4183. delete this.started[name];
  4184. }
  4185. toString() {
  4186. const outBuf = [];
  4187. let longest = 0;
  4188. for (const {
  4189. name
  4190. } of this.times) {
  4191. longest = Math.max(name.length, longest);
  4192. }
  4193. for (const {
  4194. name,
  4195. start,
  4196. end
  4197. } of this.times) {
  4198. outBuf.push(`${name.padEnd(longest)} ${end - start}ms\n`);
  4199. }
  4200. return outBuf.join("");
  4201. }
  4202. }
  4203. exports.StatTimer = StatTimer;
  4204. function isValidFetchUrl(url, baseUrl) {
  4205. try {
  4206. const {
  4207. protocol
  4208. } = baseUrl ? new URL(url, baseUrl) : new URL(url);
  4209. return protocol === "http:" || protocol === "https:";
  4210. } catch (ex) {
  4211. return false;
  4212. }
  4213. }
  4214. function loadScript(src, removeScriptElement = false) {
  4215. return new Promise((resolve, reject) => {
  4216. const script = document.createElement("script");
  4217. script.src = src;
  4218. script.onload = function (evt) {
  4219. if (removeScriptElement) {
  4220. script.remove();
  4221. }
  4222. resolve(evt);
  4223. };
  4224. script.onerror = function () {
  4225. reject(new Error(`Cannot load script at: ${script.src}`));
  4226. };
  4227. (document.head || document.documentElement).append(script);
  4228. });
  4229. }
  4230. function deprecated(details) {
  4231. console.log("Deprecated API usage: " + details);
  4232. }
  4233. let pdfDateStringRegex;
  4234. class PDFDateString {
  4235. static toDateObject(input) {
  4236. if (!input || typeof input !== "string") {
  4237. return null;
  4238. }
  4239. if (!pdfDateStringRegex) {
  4240. pdfDateStringRegex = new RegExp("^D:" + "(\\d{4})" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "([Z|+|-])?" + "(\\d{2})?" + "'?" + "(\\d{2})?" + "'?");
  4241. }
  4242. const matches = pdfDateStringRegex.exec(input);
  4243. if (!matches) {
  4244. return null;
  4245. }
  4246. const year = parseInt(matches[1], 10);
  4247. let month = parseInt(matches[2], 10);
  4248. month = month >= 1 && month <= 12 ? month - 1 : 0;
  4249. let day = parseInt(matches[3], 10);
  4250. day = day >= 1 && day <= 31 ? day : 1;
  4251. let hour = parseInt(matches[4], 10);
  4252. hour = hour >= 0 && hour <= 23 ? hour : 0;
  4253. let minute = parseInt(matches[5], 10);
  4254. minute = minute >= 0 && minute <= 59 ? minute : 0;
  4255. let second = parseInt(matches[6], 10);
  4256. second = second >= 0 && second <= 59 ? second : 0;
  4257. const universalTimeRelation = matches[7] || "Z";
  4258. let offsetHour = parseInt(matches[8], 10);
  4259. offsetHour = offsetHour >= 0 && offsetHour <= 23 ? offsetHour : 0;
  4260. let offsetMinute = parseInt(matches[9], 10) || 0;
  4261. offsetMinute = offsetMinute >= 0 && offsetMinute <= 59 ? offsetMinute : 0;
  4262. if (universalTimeRelation === "-") {
  4263. hour += offsetHour;
  4264. minute += offsetMinute;
  4265. } else if (universalTimeRelation === "+") {
  4266. hour -= offsetHour;
  4267. minute -= offsetMinute;
  4268. }
  4269. return new Date(Date.UTC(year, month, day, hour, minute, second));
  4270. }
  4271. }
  4272. exports.PDFDateString = PDFDateString;
  4273. function getXfaPageViewport(xfaPage, {
  4274. scale = 1,
  4275. rotation = 0
  4276. }) {
  4277. const {
  4278. width,
  4279. height
  4280. } = xfaPage.attributes.style;
  4281. const viewBox = [0, 0, parseInt(width), parseInt(height)];
  4282. return new PageViewport({
  4283. viewBox,
  4284. scale,
  4285. rotation
  4286. });
  4287. }
  4288. function getRGB(color) {
  4289. if (color.startsWith("#")) {
  4290. const colorRGB = parseInt(color.slice(1), 16);
  4291. return [(colorRGB & 0xff0000) >> 16, (colorRGB & 0x00ff00) >> 8, colorRGB & 0x0000ff];
  4292. }
  4293. if (color.startsWith("rgb(")) {
  4294. return color.slice(4, -1).split(",").map(x => parseInt(x));
  4295. }
  4296. if (color.startsWith("rgba(")) {
  4297. return color.slice(5, -1).split(",").map(x => parseInt(x)).slice(0, 3);
  4298. }
  4299. (0, _util.warn)(`Not a valid color format: "${color}"`);
  4300. return [0, 0, 0];
  4301. }
  4302. function getColorValues(colors) {
  4303. const span = document.createElement("span");
  4304. span.style.visibility = "hidden";
  4305. document.body.append(span);
  4306. for (const name of colors.keys()) {
  4307. span.style.color = name;
  4308. const computedColor = window.getComputedStyle(span).color;
  4309. colors.set(name, getRGB(computedColor));
  4310. }
  4311. span.remove();
  4312. }
  4313. function getCurrentTransform(ctx) {
  4314. const {
  4315. a,
  4316. b,
  4317. c,
  4318. d,
  4319. e,
  4320. f
  4321. } = ctx.getTransform();
  4322. return [a, b, c, d, e, f];
  4323. }
  4324. function getCurrentTransformInverse(ctx) {
  4325. const {
  4326. a,
  4327. b,
  4328. c,
  4329. d,
  4330. e,
  4331. f
  4332. } = ctx.getTransform().invertSelf();
  4333. return [a, b, c, d, e, f];
  4334. }
  4335. function setLayerDimensions(div, viewport, mustFlip = false, mustRotate = true) {
  4336. if (viewport instanceof PageViewport) {
  4337. const {
  4338. pageWidth,
  4339. pageHeight
  4340. } = viewport.rawDims;
  4341. const {
  4342. style
  4343. } = div;
  4344. const widthStr = `calc(var(--scale-factor) * ${pageWidth}px)`;
  4345. const heightStr = `calc(var(--scale-factor) * ${pageHeight}px)`;
  4346. if (!mustFlip || viewport.rotation % 180 === 0) {
  4347. style.width = widthStr;
  4348. style.height = heightStr;
  4349. } else {
  4350. style.width = heightStr;
  4351. style.height = widthStr;
  4352. }
  4353. }
  4354. if (mustRotate) {
  4355. div.setAttribute("data-main-rotation", viewport.rotation);
  4356. }
  4357. }
  4358. /***/ }),
  4359. /* 7 */
  4360. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  4361. Object.defineProperty(exports, "__esModule", ({
  4362. value: true
  4363. }));
  4364. exports.BaseStandardFontDataFactory = exports.BaseSVGFactory = exports.BaseCanvasFactory = exports.BaseCMapReaderFactory = void 0;
  4365. var _util = __w_pdfjs_require__(1);
  4366. class BaseCanvasFactory {
  4367. constructor() {
  4368. if (this.constructor === BaseCanvasFactory) {
  4369. (0, _util.unreachable)("Cannot initialize BaseCanvasFactory.");
  4370. }
  4371. }
  4372. create(width, height) {
  4373. if (width <= 0 || height <= 0) {
  4374. throw new Error("Invalid canvas size");
  4375. }
  4376. const canvas = this._createCanvas(width, height);
  4377. return {
  4378. canvas,
  4379. context: canvas.getContext("2d")
  4380. };
  4381. }
  4382. reset(canvasAndContext, width, height) {
  4383. if (!canvasAndContext.canvas) {
  4384. throw new Error("Canvas is not specified");
  4385. }
  4386. if (width <= 0 || height <= 0) {
  4387. throw new Error("Invalid canvas size");
  4388. }
  4389. canvasAndContext.canvas.width = width;
  4390. canvasAndContext.canvas.height = height;
  4391. }
  4392. destroy(canvasAndContext) {
  4393. if (!canvasAndContext.canvas) {
  4394. throw new Error("Canvas is not specified");
  4395. }
  4396. canvasAndContext.canvas.width = 0;
  4397. canvasAndContext.canvas.height = 0;
  4398. canvasAndContext.canvas = null;
  4399. canvasAndContext.context = null;
  4400. }
  4401. _createCanvas(width, height) {
  4402. (0, _util.unreachable)("Abstract method `_createCanvas` called.");
  4403. }
  4404. }
  4405. exports.BaseCanvasFactory = BaseCanvasFactory;
  4406. class BaseCMapReaderFactory {
  4407. constructor({
  4408. baseUrl = null,
  4409. isCompressed = false
  4410. }) {
  4411. if (this.constructor === BaseCMapReaderFactory) {
  4412. (0, _util.unreachable)("Cannot initialize BaseCMapReaderFactory.");
  4413. }
  4414. this.baseUrl = baseUrl;
  4415. this.isCompressed = isCompressed;
  4416. }
  4417. async fetch({
  4418. name
  4419. }) {
  4420. if (!this.baseUrl) {
  4421. throw new Error('The CMap "baseUrl" parameter must be specified, ensure that ' + 'the "cMapUrl" and "cMapPacked" API parameters are provided.');
  4422. }
  4423. if (!name) {
  4424. throw new Error("CMap name must be specified.");
  4425. }
  4426. const url = this.baseUrl + name + (this.isCompressed ? ".bcmap" : "");
  4427. const compressionType = this.isCompressed ? _util.CMapCompressionType.BINARY : _util.CMapCompressionType.NONE;
  4428. return this._fetchData(url, compressionType).catch(reason => {
  4429. throw new Error(`Unable to load ${this.isCompressed ? "binary " : ""}CMap at: ${url}`);
  4430. });
  4431. }
  4432. _fetchData(url, compressionType) {
  4433. (0, _util.unreachable)("Abstract method `_fetchData` called.");
  4434. }
  4435. }
  4436. exports.BaseCMapReaderFactory = BaseCMapReaderFactory;
  4437. class BaseStandardFontDataFactory {
  4438. constructor({
  4439. baseUrl = null
  4440. }) {
  4441. if (this.constructor === BaseStandardFontDataFactory) {
  4442. (0, _util.unreachable)("Cannot initialize BaseStandardFontDataFactory.");
  4443. }
  4444. this.baseUrl = baseUrl;
  4445. }
  4446. async fetch({
  4447. filename
  4448. }) {
  4449. if (!this.baseUrl) {
  4450. throw new Error('The standard font "baseUrl" parameter must be specified, ensure that ' + 'the "standardFontDataUrl" API parameter is provided.');
  4451. }
  4452. if (!filename) {
  4453. throw new Error("Font filename must be specified.");
  4454. }
  4455. const url = `${this.baseUrl}${filename}`;
  4456. return this._fetchData(url).catch(reason => {
  4457. throw new Error(`Unable to load font data at: ${url}`);
  4458. });
  4459. }
  4460. _fetchData(url) {
  4461. (0, _util.unreachable)("Abstract method `_fetchData` called.");
  4462. }
  4463. }
  4464. exports.BaseStandardFontDataFactory = BaseStandardFontDataFactory;
  4465. class BaseSVGFactory {
  4466. constructor() {
  4467. if (this.constructor === BaseSVGFactory) {
  4468. (0, _util.unreachable)("Cannot initialize BaseSVGFactory.");
  4469. }
  4470. }
  4471. create(width, height, skipDimensions = false) {
  4472. if (width <= 0 || height <= 0) {
  4473. throw new Error("Invalid SVG dimensions");
  4474. }
  4475. const svg = this._createSVG("svg:svg");
  4476. svg.setAttribute("version", "1.1");
  4477. if (!skipDimensions) {
  4478. svg.setAttribute("width", `${width}px`);
  4479. svg.setAttribute("height", `${height}px`);
  4480. }
  4481. svg.setAttribute("preserveAspectRatio", "none");
  4482. svg.setAttribute("viewBox", `0 0 ${width} ${height}`);
  4483. return svg;
  4484. }
  4485. createElement(type) {
  4486. if (typeof type !== "string") {
  4487. throw new Error("Invalid SVG element type");
  4488. }
  4489. return this._createSVG(type);
  4490. }
  4491. _createSVG(type) {
  4492. (0, _util.unreachable)("Abstract method `_createSVG` called.");
  4493. }
  4494. }
  4495. exports.BaseSVGFactory = BaseSVGFactory;
  4496. /***/ }),
  4497. /* 8 */
  4498. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  4499. Object.defineProperty(exports, "__esModule", ({
  4500. value: true
  4501. }));
  4502. exports.MurmurHash3_64 = void 0;
  4503. var _util = __w_pdfjs_require__(1);
  4504. const SEED = 0xc3d2e1f0;
  4505. const MASK_HIGH = 0xffff0000;
  4506. const MASK_LOW = 0xffff;
  4507. class MurmurHash3_64 {
  4508. constructor(seed) {
  4509. this.h1 = seed ? seed & 0xffffffff : SEED;
  4510. this.h2 = seed ? seed & 0xffffffff : SEED;
  4511. }
  4512. update(input) {
  4513. let data, length;
  4514. if (typeof input === "string") {
  4515. data = new Uint8Array(input.length * 2);
  4516. length = 0;
  4517. for (let i = 0, ii = input.length; i < ii; i++) {
  4518. const code = input.charCodeAt(i);
  4519. if (code <= 0xff) {
  4520. data[length++] = code;
  4521. } else {
  4522. data[length++] = code >>> 8;
  4523. data[length++] = code & 0xff;
  4524. }
  4525. }
  4526. } else if ((0, _util.isArrayBuffer)(input)) {
  4527. data = input.slice();
  4528. length = data.byteLength;
  4529. } else {
  4530. throw new Error("Wrong data format in MurmurHash3_64_update. " + "Input must be a string or array.");
  4531. }
  4532. const blockCounts = length >> 2;
  4533. const tailLength = length - blockCounts * 4;
  4534. const dataUint32 = new Uint32Array(data.buffer, 0, blockCounts);
  4535. let k1 = 0,
  4536. k2 = 0;
  4537. let h1 = this.h1,
  4538. h2 = this.h2;
  4539. const C1 = 0xcc9e2d51,
  4540. C2 = 0x1b873593;
  4541. const C1_LOW = C1 & MASK_LOW,
  4542. C2_LOW = C2 & MASK_LOW;
  4543. for (let i = 0; i < blockCounts; i++) {
  4544. if (i & 1) {
  4545. k1 = dataUint32[i];
  4546. k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
  4547. k1 = k1 << 15 | k1 >>> 17;
  4548. k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
  4549. h1 ^= k1;
  4550. h1 = h1 << 13 | h1 >>> 19;
  4551. h1 = h1 * 5 + 0xe6546b64;
  4552. } else {
  4553. k2 = dataUint32[i];
  4554. k2 = k2 * C1 & MASK_HIGH | k2 * C1_LOW & MASK_LOW;
  4555. k2 = k2 << 15 | k2 >>> 17;
  4556. k2 = k2 * C2 & MASK_HIGH | k2 * C2_LOW & MASK_LOW;
  4557. h2 ^= k2;
  4558. h2 = h2 << 13 | h2 >>> 19;
  4559. h2 = h2 * 5 + 0xe6546b64;
  4560. }
  4561. }
  4562. k1 = 0;
  4563. switch (tailLength) {
  4564. case 3:
  4565. k1 ^= data[blockCounts * 4 + 2] << 16;
  4566. case 2:
  4567. k1 ^= data[blockCounts * 4 + 1] << 8;
  4568. case 1:
  4569. k1 ^= data[blockCounts * 4];
  4570. k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
  4571. k1 = k1 << 15 | k1 >>> 17;
  4572. k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
  4573. if (blockCounts & 1) {
  4574. h1 ^= k1;
  4575. } else {
  4576. h2 ^= k1;
  4577. }
  4578. }
  4579. this.h1 = h1;
  4580. this.h2 = h2;
  4581. }
  4582. hexdigest() {
  4583. let h1 = this.h1,
  4584. h2 = this.h2;
  4585. h1 ^= h2 >>> 1;
  4586. h1 = h1 * 0xed558ccd & MASK_HIGH | h1 * 0x8ccd & MASK_LOW;
  4587. h2 = h2 * 0xff51afd7 & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16;
  4588. h1 ^= h2 >>> 1;
  4589. h1 = h1 * 0x1a85ec53 & MASK_HIGH | h1 * 0xec53 & MASK_LOW;
  4590. h2 = h2 * 0xc4ceb9fe & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16;
  4591. h1 ^= h2 >>> 1;
  4592. return (h1 >>> 0).toString(16).padStart(8, "0") + (h2 >>> 0).toString(16).padStart(8, "0");
  4593. }
  4594. }
  4595. exports.MurmurHash3_64 = MurmurHash3_64;
  4596. /***/ }),
  4597. /* 9 */
  4598. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  4599. Object.defineProperty(exports, "__esModule", ({
  4600. value: true
  4601. }));
  4602. exports.FontLoader = exports.FontFaceObject = void 0;
  4603. var _util = __w_pdfjs_require__(1);
  4604. var _is_node = __w_pdfjs_require__(10);
  4605. class FontLoader {
  4606. constructor({
  4607. onUnsupportedFeature,
  4608. ownerDocument = globalThis.document,
  4609. styleElement = null
  4610. }) {
  4611. this._onUnsupportedFeature = onUnsupportedFeature;
  4612. this._document = ownerDocument;
  4613. this.nativeFontFaces = [];
  4614. this.styleElement = null;
  4615. this.loadingRequests = [];
  4616. this.loadTestFontId = 0;
  4617. }
  4618. addNativeFontFace(nativeFontFace) {
  4619. this.nativeFontFaces.push(nativeFontFace);
  4620. this._document.fonts.add(nativeFontFace);
  4621. }
  4622. insertRule(rule) {
  4623. if (!this.styleElement) {
  4624. this.styleElement = this._document.createElement("style");
  4625. this._document.documentElement.getElementsByTagName("head")[0].append(this.styleElement);
  4626. }
  4627. const styleSheet = this.styleElement.sheet;
  4628. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  4629. }
  4630. clear() {
  4631. for (const nativeFontFace of this.nativeFontFaces) {
  4632. this._document.fonts.delete(nativeFontFace);
  4633. }
  4634. this.nativeFontFaces.length = 0;
  4635. if (this.styleElement) {
  4636. this.styleElement.remove();
  4637. this.styleElement = null;
  4638. }
  4639. }
  4640. async bind(font) {
  4641. if (font.attached || font.missingFile) {
  4642. return;
  4643. }
  4644. font.attached = true;
  4645. if (this.isFontLoadingAPISupported) {
  4646. const nativeFontFace = font.createNativeFontFace();
  4647. if (nativeFontFace) {
  4648. this.addNativeFontFace(nativeFontFace);
  4649. try {
  4650. await nativeFontFace.loaded;
  4651. } catch (ex) {
  4652. this._onUnsupportedFeature({
  4653. featureId: _util.UNSUPPORTED_FEATURES.errorFontLoadNative
  4654. });
  4655. (0, _util.warn)(`Failed to load font '${nativeFontFace.family}': '${ex}'.`);
  4656. font.disableFontFace = true;
  4657. throw ex;
  4658. }
  4659. }
  4660. return;
  4661. }
  4662. const rule = font.createFontFaceRule();
  4663. if (rule) {
  4664. this.insertRule(rule);
  4665. if (this.isSyncFontLoadingSupported) {
  4666. return;
  4667. }
  4668. await new Promise(resolve => {
  4669. const request = this._queueLoadingCallback(resolve);
  4670. this._prepareFontLoadEvent(font, request);
  4671. });
  4672. }
  4673. }
  4674. get isFontLoadingAPISupported() {
  4675. const hasFonts = !!this._document?.fonts;
  4676. return (0, _util.shadow)(this, "isFontLoadingAPISupported", hasFonts);
  4677. }
  4678. get isSyncFontLoadingSupported() {
  4679. let supported = false;
  4680. if (_is_node.isNodeJS) {
  4681. supported = true;
  4682. } else if (typeof navigator !== "undefined" && /Mozilla\/5.0.*?rv:\d+.*? Gecko/.test(navigator.userAgent)) {
  4683. supported = true;
  4684. }
  4685. return (0, _util.shadow)(this, "isSyncFontLoadingSupported", supported);
  4686. }
  4687. _queueLoadingCallback(callback) {
  4688. function completeRequest() {
  4689. (0, _util.assert)(!request.done, "completeRequest() cannot be called twice.");
  4690. request.done = true;
  4691. while (loadingRequests.length > 0 && loadingRequests[0].done) {
  4692. const otherRequest = loadingRequests.shift();
  4693. setTimeout(otherRequest.callback, 0);
  4694. }
  4695. }
  4696. const {
  4697. loadingRequests
  4698. } = this;
  4699. const request = {
  4700. done: false,
  4701. complete: completeRequest,
  4702. callback
  4703. };
  4704. loadingRequests.push(request);
  4705. return request;
  4706. }
  4707. get _loadTestFont() {
  4708. 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==");
  4709. return (0, _util.shadow)(this, "_loadTestFont", testFont);
  4710. }
  4711. _prepareFontLoadEvent(font, request) {
  4712. function int32(data, offset) {
  4713. return data.charCodeAt(offset) << 24 | data.charCodeAt(offset + 1) << 16 | data.charCodeAt(offset + 2) << 8 | data.charCodeAt(offset + 3) & 0xff;
  4714. }
  4715. function spliceString(s, offset, remove, insert) {
  4716. const chunk1 = s.substring(0, offset);
  4717. const chunk2 = s.substring(offset + remove);
  4718. return chunk1 + insert + chunk2;
  4719. }
  4720. let i, ii;
  4721. const canvas = this._document.createElement("canvas");
  4722. canvas.width = 1;
  4723. canvas.height = 1;
  4724. const ctx = canvas.getContext("2d");
  4725. let called = 0;
  4726. function isFontReady(name, callback) {
  4727. if (++called > 30) {
  4728. (0, _util.warn)("Load test font never loaded.");
  4729. callback();
  4730. return;
  4731. }
  4732. ctx.font = "30px " + name;
  4733. ctx.fillText(".", 0, 20);
  4734. const imageData = ctx.getImageData(0, 0, 1, 1);
  4735. if (imageData.data[3] > 0) {
  4736. callback();
  4737. return;
  4738. }
  4739. setTimeout(isFontReady.bind(null, name, callback));
  4740. }
  4741. const loadTestFontId = `lt${Date.now()}${this.loadTestFontId++}`;
  4742. let data = this._loadTestFont;
  4743. const COMMENT_OFFSET = 976;
  4744. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length, loadTestFontId);
  4745. const CFF_CHECKSUM_OFFSET = 16;
  4746. const XXXX_VALUE = 0x58585858;
  4747. let checksum = int32(data, CFF_CHECKSUM_OFFSET);
  4748. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  4749. checksum = checksum - XXXX_VALUE + int32(loadTestFontId, i) | 0;
  4750. }
  4751. if (i < loadTestFontId.length) {
  4752. checksum = checksum - XXXX_VALUE + int32(loadTestFontId + "XXX", i) | 0;
  4753. }
  4754. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, (0, _util.string32)(checksum));
  4755. const url = `url(data:font/opentype;base64,${btoa(data)});`;
  4756. const rule = `@font-face {font-family:"${loadTestFontId}";src:${url}}`;
  4757. this.insertRule(rule);
  4758. const div = this._document.createElement("div");
  4759. div.style.visibility = "hidden";
  4760. div.style.width = div.style.height = "10px";
  4761. div.style.position = "absolute";
  4762. div.style.top = div.style.left = "0px";
  4763. for (const name of [font.loadedName, loadTestFontId]) {
  4764. const span = this._document.createElement("span");
  4765. span.textContent = "Hi";
  4766. span.style.fontFamily = name;
  4767. div.append(span);
  4768. }
  4769. this._document.body.append(div);
  4770. isFontReady(loadTestFontId, () => {
  4771. div.remove();
  4772. request.complete();
  4773. });
  4774. }
  4775. }
  4776. exports.FontLoader = FontLoader;
  4777. class FontFaceObject {
  4778. constructor(translatedData, {
  4779. isEvalSupported = true,
  4780. disableFontFace = false,
  4781. ignoreErrors = false,
  4782. onUnsupportedFeature,
  4783. fontRegistry = null
  4784. }) {
  4785. this.compiledGlyphs = Object.create(null);
  4786. for (const i in translatedData) {
  4787. this[i] = translatedData[i];
  4788. }
  4789. this.isEvalSupported = isEvalSupported !== false;
  4790. this.disableFontFace = disableFontFace === true;
  4791. this.ignoreErrors = ignoreErrors === true;
  4792. this._onUnsupportedFeature = onUnsupportedFeature;
  4793. this.fontRegistry = fontRegistry;
  4794. }
  4795. createNativeFontFace() {
  4796. if (!this.data || this.disableFontFace) {
  4797. return null;
  4798. }
  4799. let nativeFontFace;
  4800. if (!this.cssFontInfo) {
  4801. nativeFontFace = new FontFace(this.loadedName, this.data, {});
  4802. } else {
  4803. const css = {
  4804. weight: this.cssFontInfo.fontWeight
  4805. };
  4806. if (this.cssFontInfo.italicAngle) {
  4807. css.style = `oblique ${this.cssFontInfo.italicAngle}deg`;
  4808. }
  4809. nativeFontFace = new FontFace(this.cssFontInfo.fontFamily, this.data, css);
  4810. }
  4811. this.fontRegistry?.registerFont(this);
  4812. return nativeFontFace;
  4813. }
  4814. createFontFaceRule() {
  4815. if (!this.data || this.disableFontFace) {
  4816. return null;
  4817. }
  4818. const data = (0, _util.bytesToString)(this.data);
  4819. const url = `url(data:${this.mimetype};base64,${btoa(data)});`;
  4820. let rule;
  4821. if (!this.cssFontInfo) {
  4822. rule = `@font-face {font-family:"${this.loadedName}";src:${url}}`;
  4823. } else {
  4824. let css = `font-weight: ${this.cssFontInfo.fontWeight};`;
  4825. if (this.cssFontInfo.italicAngle) {
  4826. css += `font-style: oblique ${this.cssFontInfo.italicAngle}deg;`;
  4827. }
  4828. rule = `@font-face {font-family:"${this.cssFontInfo.fontFamily}";${css}src:${url}}`;
  4829. }
  4830. this.fontRegistry?.registerFont(this, url);
  4831. return rule;
  4832. }
  4833. getPathGenerator(objs, character) {
  4834. if (this.compiledGlyphs[character] !== undefined) {
  4835. return this.compiledGlyphs[character];
  4836. }
  4837. let cmds;
  4838. try {
  4839. cmds = objs.get(this.loadedName + "_path_" + character);
  4840. } catch (ex) {
  4841. if (!this.ignoreErrors) {
  4842. throw ex;
  4843. }
  4844. this._onUnsupportedFeature({
  4845. featureId: _util.UNSUPPORTED_FEATURES.errorFontGetPath
  4846. });
  4847. (0, _util.warn)(`getPathGenerator - ignoring character: "${ex}".`);
  4848. return this.compiledGlyphs[character] = function (c, size) {};
  4849. }
  4850. if (this.isEvalSupported && _util.FeatureTest.isEvalSupported) {
  4851. const jsBuf = [];
  4852. for (const current of cmds) {
  4853. const args = current.args !== undefined ? current.args.join(",") : "";
  4854. jsBuf.push("c.", current.cmd, "(", args, ");\n");
  4855. }
  4856. return this.compiledGlyphs[character] = new Function("c", "size", jsBuf.join(""));
  4857. }
  4858. return this.compiledGlyphs[character] = function (c, size) {
  4859. for (const current of cmds) {
  4860. if (current.cmd === "scale") {
  4861. current.args = [size, -size];
  4862. }
  4863. c[current.cmd].apply(c, current.args);
  4864. }
  4865. };
  4866. }
  4867. }
  4868. exports.FontFaceObject = FontFaceObject;
  4869. /***/ }),
  4870. /* 10 */
  4871. /***/ ((__unused_webpack_module, exports) => {
  4872. Object.defineProperty(exports, "__esModule", ({
  4873. value: true
  4874. }));
  4875. exports.isNodeJS = void 0;
  4876. const isNodeJS = typeof process === "object" && process + "" === "[object process]" && !process.versions.nw && !(process.versions.electron && process.type && process.type !== "browser");
  4877. exports.isNodeJS = isNodeJS;
  4878. /***/ }),
  4879. /* 11 */
  4880. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  4881. Object.defineProperty(exports, "__esModule", ({
  4882. value: true
  4883. }));
  4884. exports.CanvasGraphics = void 0;
  4885. var _util = __w_pdfjs_require__(1);
  4886. var _display_utils = __w_pdfjs_require__(6);
  4887. var _pattern_helper = __w_pdfjs_require__(12);
  4888. var _image_utils = __w_pdfjs_require__(13);
  4889. const MIN_FONT_SIZE = 16;
  4890. const MAX_FONT_SIZE = 100;
  4891. const MAX_GROUP_SIZE = 4096;
  4892. const EXECUTION_TIME = 15;
  4893. const EXECUTION_STEPS = 10;
  4894. const MAX_SIZE_TO_COMPILE = 1000;
  4895. const FULL_CHUNK_HEIGHT = 16;
  4896. function mirrorContextOperations(ctx, destCtx) {
  4897. if (ctx._removeMirroring) {
  4898. throw new Error("Context is already forwarding operations.");
  4899. }
  4900. ctx.__originalSave = ctx.save;
  4901. ctx.__originalRestore = ctx.restore;
  4902. ctx.__originalRotate = ctx.rotate;
  4903. ctx.__originalScale = ctx.scale;
  4904. ctx.__originalTranslate = ctx.translate;
  4905. ctx.__originalTransform = ctx.transform;
  4906. ctx.__originalSetTransform = ctx.setTransform;
  4907. ctx.__originalResetTransform = ctx.resetTransform;
  4908. ctx.__originalClip = ctx.clip;
  4909. ctx.__originalMoveTo = ctx.moveTo;
  4910. ctx.__originalLineTo = ctx.lineTo;
  4911. ctx.__originalBezierCurveTo = ctx.bezierCurveTo;
  4912. ctx.__originalRect = ctx.rect;
  4913. ctx.__originalClosePath = ctx.closePath;
  4914. ctx.__originalBeginPath = ctx.beginPath;
  4915. ctx._removeMirroring = () => {
  4916. ctx.save = ctx.__originalSave;
  4917. ctx.restore = ctx.__originalRestore;
  4918. ctx.rotate = ctx.__originalRotate;
  4919. ctx.scale = ctx.__originalScale;
  4920. ctx.translate = ctx.__originalTranslate;
  4921. ctx.transform = ctx.__originalTransform;
  4922. ctx.setTransform = ctx.__originalSetTransform;
  4923. ctx.resetTransform = ctx.__originalResetTransform;
  4924. ctx.clip = ctx.__originalClip;
  4925. ctx.moveTo = ctx.__originalMoveTo;
  4926. ctx.lineTo = ctx.__originalLineTo;
  4927. ctx.bezierCurveTo = ctx.__originalBezierCurveTo;
  4928. ctx.rect = ctx.__originalRect;
  4929. ctx.closePath = ctx.__originalClosePath;
  4930. ctx.beginPath = ctx.__originalBeginPath;
  4931. delete ctx._removeMirroring;
  4932. };
  4933. ctx.save = function ctxSave() {
  4934. destCtx.save();
  4935. this.__originalSave();
  4936. };
  4937. ctx.restore = function ctxRestore() {
  4938. destCtx.restore();
  4939. this.__originalRestore();
  4940. };
  4941. ctx.translate = function ctxTranslate(x, y) {
  4942. destCtx.translate(x, y);
  4943. this.__originalTranslate(x, y);
  4944. };
  4945. ctx.scale = function ctxScale(x, y) {
  4946. destCtx.scale(x, y);
  4947. this.__originalScale(x, y);
  4948. };
  4949. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  4950. destCtx.transform(a, b, c, d, e, f);
  4951. this.__originalTransform(a, b, c, d, e, f);
  4952. };
  4953. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  4954. destCtx.setTransform(a, b, c, d, e, f);
  4955. this.__originalSetTransform(a, b, c, d, e, f);
  4956. };
  4957. ctx.resetTransform = function ctxResetTransform() {
  4958. destCtx.resetTransform();
  4959. this.__originalResetTransform();
  4960. };
  4961. ctx.rotate = function ctxRotate(angle) {
  4962. destCtx.rotate(angle);
  4963. this.__originalRotate(angle);
  4964. };
  4965. ctx.clip = function ctxRotate(rule) {
  4966. destCtx.clip(rule);
  4967. this.__originalClip(rule);
  4968. };
  4969. ctx.moveTo = function (x, y) {
  4970. destCtx.moveTo(x, y);
  4971. this.__originalMoveTo(x, y);
  4972. };
  4973. ctx.lineTo = function (x, y) {
  4974. destCtx.lineTo(x, y);
  4975. this.__originalLineTo(x, y);
  4976. };
  4977. ctx.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
  4978. destCtx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
  4979. this.__originalBezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
  4980. };
  4981. ctx.rect = function (x, y, width, height) {
  4982. destCtx.rect(x, y, width, height);
  4983. this.__originalRect(x, y, width, height);
  4984. };
  4985. ctx.closePath = function () {
  4986. destCtx.closePath();
  4987. this.__originalClosePath();
  4988. };
  4989. ctx.beginPath = function () {
  4990. destCtx.beginPath();
  4991. this.__originalBeginPath();
  4992. };
  4993. }
  4994. class CachedCanvases {
  4995. constructor(canvasFactory) {
  4996. this.canvasFactory = canvasFactory;
  4997. this.cache = Object.create(null);
  4998. }
  4999. getCanvas(id, width, height) {
  5000. let canvasEntry;
  5001. if (this.cache[id] !== undefined) {
  5002. canvasEntry = this.cache[id];
  5003. this.canvasFactory.reset(canvasEntry, width, height);
  5004. } else {
  5005. canvasEntry = this.canvasFactory.create(width, height);
  5006. this.cache[id] = canvasEntry;
  5007. }
  5008. return canvasEntry;
  5009. }
  5010. delete(id) {
  5011. delete this.cache[id];
  5012. }
  5013. clear() {
  5014. for (const id in this.cache) {
  5015. const canvasEntry = this.cache[id];
  5016. this.canvasFactory.destroy(canvasEntry);
  5017. delete this.cache[id];
  5018. }
  5019. }
  5020. }
  5021. function drawImageAtIntegerCoords(ctx, srcImg, srcX, srcY, srcW, srcH, destX, destY, destW, destH) {
  5022. const [a, b, c, d, tx, ty] = (0, _display_utils.getCurrentTransform)(ctx);
  5023. if (b === 0 && c === 0) {
  5024. const tlX = destX * a + tx;
  5025. const rTlX = Math.round(tlX);
  5026. const tlY = destY * d + ty;
  5027. const rTlY = Math.round(tlY);
  5028. const brX = (destX + destW) * a + tx;
  5029. const rWidth = Math.abs(Math.round(brX) - rTlX) || 1;
  5030. const brY = (destY + destH) * d + ty;
  5031. const rHeight = Math.abs(Math.round(brY) - rTlY) || 1;
  5032. ctx.setTransform(Math.sign(a), 0, 0, Math.sign(d), rTlX, rTlY);
  5033. ctx.drawImage(srcImg, srcX, srcY, srcW, srcH, 0, 0, rWidth, rHeight);
  5034. ctx.setTransform(a, b, c, d, tx, ty);
  5035. return [rWidth, rHeight];
  5036. }
  5037. if (a === 0 && d === 0) {
  5038. const tlX = destY * c + tx;
  5039. const rTlX = Math.round(tlX);
  5040. const tlY = destX * b + ty;
  5041. const rTlY = Math.round(tlY);
  5042. const brX = (destY + destH) * c + tx;
  5043. const rWidth = Math.abs(Math.round(brX) - rTlX) || 1;
  5044. const brY = (destX + destW) * b + ty;
  5045. const rHeight = Math.abs(Math.round(brY) - rTlY) || 1;
  5046. ctx.setTransform(0, Math.sign(b), Math.sign(c), 0, rTlX, rTlY);
  5047. ctx.drawImage(srcImg, srcX, srcY, srcW, srcH, 0, 0, rHeight, rWidth);
  5048. ctx.setTransform(a, b, c, d, tx, ty);
  5049. return [rHeight, rWidth];
  5050. }
  5051. ctx.drawImage(srcImg, srcX, srcY, srcW, srcH, destX, destY, destW, destH);
  5052. const scaleX = Math.hypot(a, b);
  5053. const scaleY = Math.hypot(c, d);
  5054. return [scaleX * destW, scaleY * destH];
  5055. }
  5056. function compileType3Glyph(imgData) {
  5057. const {
  5058. width,
  5059. height
  5060. } = imgData;
  5061. if (width > MAX_SIZE_TO_COMPILE || height > MAX_SIZE_TO_COMPILE) {
  5062. return null;
  5063. }
  5064. const POINT_TO_PROCESS_LIMIT = 1000;
  5065. const POINT_TYPES = new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  5066. const width1 = width + 1;
  5067. let points = new Uint8Array(width1 * (height + 1));
  5068. let i, j, j0;
  5069. const lineSize = width + 7 & ~7;
  5070. let data = new Uint8Array(lineSize * height),
  5071. pos = 0;
  5072. for (const elem of imgData.data) {
  5073. let mask = 128;
  5074. while (mask > 0) {
  5075. data[pos++] = elem & mask ? 0 : 255;
  5076. mask >>= 1;
  5077. }
  5078. }
  5079. let count = 0;
  5080. pos = 0;
  5081. if (data[pos] !== 0) {
  5082. points[0] = 1;
  5083. ++count;
  5084. }
  5085. for (j = 1; j < width; j++) {
  5086. if (data[pos] !== data[pos + 1]) {
  5087. points[j] = data[pos] ? 2 : 1;
  5088. ++count;
  5089. }
  5090. pos++;
  5091. }
  5092. if (data[pos] !== 0) {
  5093. points[j] = 2;
  5094. ++count;
  5095. }
  5096. for (i = 1; i < height; i++) {
  5097. pos = i * lineSize;
  5098. j0 = i * width1;
  5099. if (data[pos - lineSize] !== data[pos]) {
  5100. points[j0] = data[pos] ? 1 : 8;
  5101. ++count;
  5102. }
  5103. let sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  5104. for (j = 1; j < width; j++) {
  5105. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) + (data[pos - lineSize + 1] ? 8 : 0);
  5106. if (POINT_TYPES[sum]) {
  5107. points[j0 + j] = POINT_TYPES[sum];
  5108. ++count;
  5109. }
  5110. pos++;
  5111. }
  5112. if (data[pos - lineSize] !== data[pos]) {
  5113. points[j0 + j] = data[pos] ? 2 : 4;
  5114. ++count;
  5115. }
  5116. if (count > POINT_TO_PROCESS_LIMIT) {
  5117. return null;
  5118. }
  5119. }
  5120. pos = lineSize * (height - 1);
  5121. j0 = i * width1;
  5122. if (data[pos] !== 0) {
  5123. points[j0] = 8;
  5124. ++count;
  5125. }
  5126. for (j = 1; j < width; j++) {
  5127. if (data[pos] !== data[pos + 1]) {
  5128. points[j0 + j] = data[pos] ? 4 : 8;
  5129. ++count;
  5130. }
  5131. pos++;
  5132. }
  5133. if (data[pos] !== 0) {
  5134. points[j0 + j] = 4;
  5135. ++count;
  5136. }
  5137. if (count > POINT_TO_PROCESS_LIMIT) {
  5138. return null;
  5139. }
  5140. const steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  5141. const path = new Path2D();
  5142. for (i = 0; count && i <= height; i++) {
  5143. let p = i * width1;
  5144. const end = p + width;
  5145. while (p < end && !points[p]) {
  5146. p++;
  5147. }
  5148. if (p === end) {
  5149. continue;
  5150. }
  5151. path.moveTo(p % width1, i);
  5152. const p0 = p;
  5153. let type = points[p];
  5154. do {
  5155. const step = steps[type];
  5156. do {
  5157. p += step;
  5158. } while (!points[p]);
  5159. const pp = points[p];
  5160. if (pp !== 5 && pp !== 10) {
  5161. type = pp;
  5162. points[p] = 0;
  5163. } else {
  5164. type = pp & 0x33 * type >> 4;
  5165. points[p] &= type >> 2 | type << 2;
  5166. }
  5167. path.lineTo(p % width1, p / width1 | 0);
  5168. if (!points[p]) {
  5169. --count;
  5170. }
  5171. } while (p0 !== p);
  5172. --i;
  5173. }
  5174. data = null;
  5175. points = null;
  5176. const drawOutline = function (c) {
  5177. c.save();
  5178. c.scale(1 / width, -1 / height);
  5179. c.translate(0, -height);
  5180. c.fill(path);
  5181. c.beginPath();
  5182. c.restore();
  5183. };
  5184. return drawOutline;
  5185. }
  5186. class CanvasExtraState {
  5187. constructor(width, height) {
  5188. this.alphaIsShape = false;
  5189. this.fontSize = 0;
  5190. this.fontSizeScale = 1;
  5191. this.textMatrix = _util.IDENTITY_MATRIX;
  5192. this.textMatrixScale = 1;
  5193. this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
  5194. this.leading = 0;
  5195. this.x = 0;
  5196. this.y = 0;
  5197. this.lineX = 0;
  5198. this.lineY = 0;
  5199. this.charSpacing = 0;
  5200. this.wordSpacing = 0;
  5201. this.textHScale = 1;
  5202. this.textRenderingMode = _util.TextRenderingMode.FILL;
  5203. this.textRise = 0;
  5204. this.fillColor = "#000000";
  5205. this.strokeColor = "#000000";
  5206. this.patternFill = false;
  5207. this.fillAlpha = 1;
  5208. this.strokeAlpha = 1;
  5209. this.lineWidth = 1;
  5210. this.activeSMask = null;
  5211. this.transferMaps = null;
  5212. this.startNewPathAndClipBox([0, 0, width, height]);
  5213. }
  5214. clone() {
  5215. const clone = Object.create(this);
  5216. clone.clipBox = this.clipBox.slice();
  5217. return clone;
  5218. }
  5219. setCurrentPoint(x, y) {
  5220. this.x = x;
  5221. this.y = y;
  5222. }
  5223. updatePathMinMax(transform, x, y) {
  5224. [x, y] = _util.Util.applyTransform([x, y], transform);
  5225. this.minX = Math.min(this.minX, x);
  5226. this.minY = Math.min(this.minY, y);
  5227. this.maxX = Math.max(this.maxX, x);
  5228. this.maxY = Math.max(this.maxY, y);
  5229. }
  5230. updateRectMinMax(transform, rect) {
  5231. const p1 = _util.Util.applyTransform(rect, transform);
  5232. const p2 = _util.Util.applyTransform(rect.slice(2), transform);
  5233. this.minX = Math.min(this.minX, p1[0], p2[0]);
  5234. this.minY = Math.min(this.minY, p1[1], p2[1]);
  5235. this.maxX = Math.max(this.maxX, p1[0], p2[0]);
  5236. this.maxY = Math.max(this.maxY, p1[1], p2[1]);
  5237. }
  5238. updateScalingPathMinMax(transform, minMax) {
  5239. _util.Util.scaleMinMax(transform, minMax);
  5240. this.minX = Math.min(this.minX, minMax[0]);
  5241. this.maxX = Math.max(this.maxX, minMax[1]);
  5242. this.minY = Math.min(this.minY, minMax[2]);
  5243. this.maxY = Math.max(this.maxY, minMax[3]);
  5244. }
  5245. updateCurvePathMinMax(transform, x0, y0, x1, y1, x2, y2, x3, y3, minMax) {
  5246. const box = _util.Util.bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3);
  5247. if (minMax) {
  5248. minMax[0] = Math.min(minMax[0], box[0], box[2]);
  5249. minMax[1] = Math.max(minMax[1], box[0], box[2]);
  5250. minMax[2] = Math.min(minMax[2], box[1], box[3]);
  5251. minMax[3] = Math.max(minMax[3], box[1], box[3]);
  5252. return;
  5253. }
  5254. this.updateRectMinMax(transform, box);
  5255. }
  5256. getPathBoundingBox(pathType = _pattern_helper.PathType.FILL, transform = null) {
  5257. const box = [this.minX, this.minY, this.maxX, this.maxY];
  5258. if (pathType === _pattern_helper.PathType.STROKE) {
  5259. if (!transform) {
  5260. (0, _util.unreachable)("Stroke bounding box must include transform.");
  5261. }
  5262. const scale = _util.Util.singularValueDecompose2dScale(transform);
  5263. const xStrokePad = scale[0] * this.lineWidth / 2;
  5264. const yStrokePad = scale[1] * this.lineWidth / 2;
  5265. box[0] -= xStrokePad;
  5266. box[1] -= yStrokePad;
  5267. box[2] += xStrokePad;
  5268. box[3] += yStrokePad;
  5269. }
  5270. return box;
  5271. }
  5272. updateClipFromPath() {
  5273. const intersect = _util.Util.intersect(this.clipBox, this.getPathBoundingBox());
  5274. this.startNewPathAndClipBox(intersect || [0, 0, 0, 0]);
  5275. }
  5276. isEmptyClip() {
  5277. return this.minX === Infinity;
  5278. }
  5279. startNewPathAndClipBox(box) {
  5280. this.clipBox = box;
  5281. this.minX = Infinity;
  5282. this.minY = Infinity;
  5283. this.maxX = 0;
  5284. this.maxY = 0;
  5285. }
  5286. getClippedPathBoundingBox(pathType = _pattern_helper.PathType.FILL, transform = null) {
  5287. return _util.Util.intersect(this.clipBox, this.getPathBoundingBox(pathType, transform));
  5288. }
  5289. }
  5290. function putBinaryImageData(ctx, imgData, transferMaps = null) {
  5291. if (typeof ImageData !== "undefined" && imgData instanceof ImageData) {
  5292. ctx.putImageData(imgData, 0, 0);
  5293. return;
  5294. }
  5295. const height = imgData.height,
  5296. width = imgData.width;
  5297. const partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  5298. const fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  5299. const totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  5300. const chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  5301. let srcPos = 0,
  5302. destPos;
  5303. const src = imgData.data;
  5304. const dest = chunkImgData.data;
  5305. let i, j, thisChunkHeight, elemsInThisChunk;
  5306. let transferMapRed, transferMapGreen, transferMapBlue, transferMapGray;
  5307. if (transferMaps) {
  5308. switch (transferMaps.length) {
  5309. case 1:
  5310. transferMapRed = transferMaps[0];
  5311. transferMapGreen = transferMaps[0];
  5312. transferMapBlue = transferMaps[0];
  5313. transferMapGray = transferMaps[0];
  5314. break;
  5315. case 4:
  5316. transferMapRed = transferMaps[0];
  5317. transferMapGreen = transferMaps[1];
  5318. transferMapBlue = transferMaps[2];
  5319. transferMapGray = transferMaps[3];
  5320. break;
  5321. }
  5322. }
  5323. if (imgData.kind === _util.ImageKind.GRAYSCALE_1BPP) {
  5324. const srcLength = src.byteLength;
  5325. const dest32 = new Uint32Array(dest.buffer, 0, dest.byteLength >> 2);
  5326. const dest32DataLength = dest32.length;
  5327. const fullSrcDiff = width + 7 >> 3;
  5328. let white = 0xffffffff;
  5329. let black = _util.FeatureTest.isLittleEndian ? 0xff000000 : 0x000000ff;
  5330. if (transferMapGray) {
  5331. if (transferMapGray[0] === 0xff && transferMapGray[0xff] === 0) {
  5332. [white, black] = [black, white];
  5333. }
  5334. }
  5335. for (i = 0; i < totalChunks; i++) {
  5336. thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  5337. destPos = 0;
  5338. for (j = 0; j < thisChunkHeight; j++) {
  5339. const srcDiff = srcLength - srcPos;
  5340. let k = 0;
  5341. const kEnd = srcDiff > fullSrcDiff ? width : srcDiff * 8 - 7;
  5342. const kEndUnrolled = kEnd & ~7;
  5343. let mask = 0;
  5344. let srcByte = 0;
  5345. for (; k < kEndUnrolled; k += 8) {
  5346. srcByte = src[srcPos++];
  5347. dest32[destPos++] = srcByte & 128 ? white : black;
  5348. dest32[destPos++] = srcByte & 64 ? white : black;
  5349. dest32[destPos++] = srcByte & 32 ? white : black;
  5350. dest32[destPos++] = srcByte & 16 ? white : black;
  5351. dest32[destPos++] = srcByte & 8 ? white : black;
  5352. dest32[destPos++] = srcByte & 4 ? white : black;
  5353. dest32[destPos++] = srcByte & 2 ? white : black;
  5354. dest32[destPos++] = srcByte & 1 ? white : black;
  5355. }
  5356. for (; k < kEnd; k++) {
  5357. if (mask === 0) {
  5358. srcByte = src[srcPos++];
  5359. mask = 128;
  5360. }
  5361. dest32[destPos++] = srcByte & mask ? white : black;
  5362. mask >>= 1;
  5363. }
  5364. }
  5365. while (destPos < dest32DataLength) {
  5366. dest32[destPos++] = 0;
  5367. }
  5368. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  5369. }
  5370. } else if (imgData.kind === _util.ImageKind.RGBA_32BPP) {
  5371. const hasTransferMaps = !!(transferMapRed || transferMapGreen || transferMapBlue);
  5372. j = 0;
  5373. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  5374. for (i = 0; i < fullChunks; i++) {
  5375. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  5376. srcPos += elemsInThisChunk;
  5377. if (hasTransferMaps) {
  5378. for (let k = 0; k < elemsInThisChunk; k += 4) {
  5379. if (transferMapRed) {
  5380. dest[k + 0] = transferMapRed[dest[k + 0]];
  5381. }
  5382. if (transferMapGreen) {
  5383. dest[k + 1] = transferMapGreen[dest[k + 1]];
  5384. }
  5385. if (transferMapBlue) {
  5386. dest[k + 2] = transferMapBlue[dest[k + 2]];
  5387. }
  5388. }
  5389. }
  5390. ctx.putImageData(chunkImgData, 0, j);
  5391. j += FULL_CHUNK_HEIGHT;
  5392. }
  5393. if (i < totalChunks) {
  5394. elemsInThisChunk = width * partialChunkHeight * 4;
  5395. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  5396. if (hasTransferMaps) {
  5397. for (let k = 0; k < elemsInThisChunk; k += 4) {
  5398. if (transferMapRed) {
  5399. dest[k + 0] = transferMapRed[dest[k + 0]];
  5400. }
  5401. if (transferMapGreen) {
  5402. dest[k + 1] = transferMapGreen[dest[k + 1]];
  5403. }
  5404. if (transferMapBlue) {
  5405. dest[k + 2] = transferMapBlue[dest[k + 2]];
  5406. }
  5407. }
  5408. }
  5409. ctx.putImageData(chunkImgData, 0, j);
  5410. }
  5411. } else if (imgData.kind === _util.ImageKind.RGB_24BPP) {
  5412. const hasTransferMaps = !!(transferMapRed || transferMapGreen || transferMapBlue);
  5413. thisChunkHeight = FULL_CHUNK_HEIGHT;
  5414. elemsInThisChunk = width * thisChunkHeight;
  5415. for (i = 0; i < totalChunks; i++) {
  5416. if (i >= fullChunks) {
  5417. thisChunkHeight = partialChunkHeight;
  5418. elemsInThisChunk = width * thisChunkHeight;
  5419. }
  5420. destPos = 0;
  5421. for (j = elemsInThisChunk; j--;) {
  5422. dest[destPos++] = src[srcPos++];
  5423. dest[destPos++] = src[srcPos++];
  5424. dest[destPos++] = src[srcPos++];
  5425. dest[destPos++] = 255;
  5426. }
  5427. if (hasTransferMaps) {
  5428. for (let k = 0; k < destPos; k += 4) {
  5429. if (transferMapRed) {
  5430. dest[k + 0] = transferMapRed[dest[k + 0]];
  5431. }
  5432. if (transferMapGreen) {
  5433. dest[k + 1] = transferMapGreen[dest[k + 1]];
  5434. }
  5435. if (transferMapBlue) {
  5436. dest[k + 2] = transferMapBlue[dest[k + 2]];
  5437. }
  5438. }
  5439. }
  5440. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  5441. }
  5442. } else {
  5443. throw new Error(`bad image kind: ${imgData.kind}`);
  5444. }
  5445. }
  5446. function putBinaryImageMask(ctx, imgData) {
  5447. if (imgData.bitmap) {
  5448. ctx.drawImage(imgData.bitmap, 0, 0);
  5449. return;
  5450. }
  5451. const height = imgData.height,
  5452. width = imgData.width;
  5453. const partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  5454. const fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  5455. const totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  5456. const chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  5457. let srcPos = 0;
  5458. const src = imgData.data;
  5459. const dest = chunkImgData.data;
  5460. for (let i = 0; i < totalChunks; i++) {
  5461. const thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  5462. ({
  5463. srcPos
  5464. } = (0, _image_utils.applyMaskImageData)({
  5465. src,
  5466. srcPos,
  5467. dest,
  5468. width,
  5469. height: thisChunkHeight
  5470. }));
  5471. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  5472. }
  5473. }
  5474. function copyCtxState(sourceCtx, destCtx) {
  5475. const properties = ["strokeStyle", "fillStyle", "fillRule", "globalAlpha", "lineWidth", "lineCap", "lineJoin", "miterLimit", "globalCompositeOperation", "font"];
  5476. for (const property of properties) {
  5477. if (sourceCtx[property] !== undefined) {
  5478. destCtx[property] = sourceCtx[property];
  5479. }
  5480. }
  5481. if (sourceCtx.setLineDash !== undefined) {
  5482. destCtx.setLineDash(sourceCtx.getLineDash());
  5483. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  5484. }
  5485. }
  5486. function resetCtxToDefault(ctx, foregroundColor) {
  5487. ctx.strokeStyle = ctx.fillStyle = foregroundColor || "#000000";
  5488. ctx.fillRule = "nonzero";
  5489. ctx.globalAlpha = 1;
  5490. ctx.lineWidth = 1;
  5491. ctx.lineCap = "butt";
  5492. ctx.lineJoin = "miter";
  5493. ctx.miterLimit = 10;
  5494. ctx.globalCompositeOperation = "source-over";
  5495. ctx.font = "10px sans-serif";
  5496. if (ctx.setLineDash !== undefined) {
  5497. ctx.setLineDash([]);
  5498. ctx.lineDashOffset = 0;
  5499. }
  5500. }
  5501. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  5502. const length = bytes.length;
  5503. for (let i = 3; i < length; i += 4) {
  5504. const alpha = bytes[i];
  5505. if (alpha === 0) {
  5506. bytes[i - 3] = r0;
  5507. bytes[i - 2] = g0;
  5508. bytes[i - 1] = b0;
  5509. } else if (alpha < 255) {
  5510. const alpha_ = 255 - alpha;
  5511. bytes[i - 3] = bytes[i - 3] * alpha + r0 * alpha_ >> 8;
  5512. bytes[i - 2] = bytes[i - 2] * alpha + g0 * alpha_ >> 8;
  5513. bytes[i - 1] = bytes[i - 1] * alpha + b0 * alpha_ >> 8;
  5514. }
  5515. }
  5516. }
  5517. function composeSMaskAlpha(maskData, layerData, transferMap) {
  5518. const length = maskData.length;
  5519. const scale = 1 / 255;
  5520. for (let i = 3; i < length; i += 4) {
  5521. const alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
  5522. layerData[i] = layerData[i] * alpha * scale | 0;
  5523. }
  5524. }
  5525. function composeSMaskLuminosity(maskData, layerData, transferMap) {
  5526. const length = maskData.length;
  5527. for (let i = 3; i < length; i += 4) {
  5528. const y = maskData[i - 3] * 77 + maskData[i - 2] * 152 + maskData[i - 1] * 28;
  5529. layerData[i] = transferMap ? layerData[i] * transferMap[y >> 8] >> 8 : layerData[i] * y >> 16;
  5530. }
  5531. }
  5532. function genericComposeSMask(maskCtx, layerCtx, width, height, subtype, backdrop, transferMap, layerOffsetX, layerOffsetY, maskOffsetX, maskOffsetY) {
  5533. const hasBackdrop = !!backdrop;
  5534. const r0 = hasBackdrop ? backdrop[0] : 0;
  5535. const g0 = hasBackdrop ? backdrop[1] : 0;
  5536. const b0 = hasBackdrop ? backdrop[2] : 0;
  5537. let composeFn;
  5538. if (subtype === "Luminosity") {
  5539. composeFn = composeSMaskLuminosity;
  5540. } else {
  5541. composeFn = composeSMaskAlpha;
  5542. }
  5543. const PIXELS_TO_PROCESS = 1048576;
  5544. const chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  5545. for (let row = 0; row < height; row += chunkSize) {
  5546. const chunkHeight = Math.min(chunkSize, height - row);
  5547. const maskData = maskCtx.getImageData(layerOffsetX - maskOffsetX, row + (layerOffsetY - maskOffsetY), width, chunkHeight);
  5548. const layerData = layerCtx.getImageData(layerOffsetX, row + layerOffsetY, width, chunkHeight);
  5549. if (hasBackdrop) {
  5550. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  5551. }
  5552. composeFn(maskData.data, layerData.data, transferMap);
  5553. layerCtx.putImageData(layerData, layerOffsetX, row + layerOffsetY);
  5554. }
  5555. }
  5556. function composeSMask(ctx, smask, layerCtx, layerBox) {
  5557. const layerOffsetX = layerBox[0];
  5558. const layerOffsetY = layerBox[1];
  5559. const layerWidth = layerBox[2] - layerOffsetX;
  5560. const layerHeight = layerBox[3] - layerOffsetY;
  5561. if (layerWidth === 0 || layerHeight === 0) {
  5562. return;
  5563. }
  5564. genericComposeSMask(smask.context, layerCtx, layerWidth, layerHeight, smask.subtype, smask.backdrop, smask.transferMap, layerOffsetX, layerOffsetY, smask.offsetX, smask.offsetY);
  5565. ctx.save();
  5566. ctx.globalAlpha = 1;
  5567. ctx.globalCompositeOperation = "source-over";
  5568. ctx.setTransform(1, 0, 0, 1, 0, 0);
  5569. ctx.drawImage(layerCtx.canvas, 0, 0);
  5570. ctx.restore();
  5571. }
  5572. function getImageSmoothingEnabled(transform, interpolate) {
  5573. const scale = _util.Util.singularValueDecompose2dScale(transform);
  5574. scale[0] = Math.fround(scale[0]);
  5575. scale[1] = Math.fround(scale[1]);
  5576. const actualScale = Math.fround((globalThis.devicePixelRatio || 1) * _display_utils.PixelsPerInch.PDF_TO_CSS_UNITS);
  5577. if (interpolate !== undefined) {
  5578. return interpolate;
  5579. } else if (scale[0] <= actualScale || scale[1] <= actualScale) {
  5580. return true;
  5581. }
  5582. return false;
  5583. }
  5584. const LINE_CAP_STYLES = ["butt", "round", "square"];
  5585. const LINE_JOIN_STYLES = ["miter", "round", "bevel"];
  5586. const NORMAL_CLIP = {};
  5587. const EO_CLIP = {};
  5588. class CanvasGraphics {
  5589. constructor(canvasCtx, commonObjs, objs, canvasFactory, {
  5590. optionalContentConfig,
  5591. markedContentStack = null
  5592. }, annotationCanvasMap, pageColors) {
  5593. this.ctx = canvasCtx;
  5594. this.current = new CanvasExtraState(this.ctx.canvas.width, this.ctx.canvas.height);
  5595. this.stateStack = [];
  5596. this.pendingClip = null;
  5597. this.pendingEOFill = false;
  5598. this.res = null;
  5599. this.xobjs = null;
  5600. this.commonObjs = commonObjs;
  5601. this.objs = objs;
  5602. this.canvasFactory = canvasFactory;
  5603. this.groupStack = [];
  5604. this.processingType3 = null;
  5605. this.baseTransform = null;
  5606. this.baseTransformStack = [];
  5607. this.groupLevel = 0;
  5608. this.smaskStack = [];
  5609. this.smaskCounter = 0;
  5610. this.tempSMask = null;
  5611. this.suspendedCtx = null;
  5612. this.contentVisible = true;
  5613. this.markedContentStack = markedContentStack || [];
  5614. this.optionalContentConfig = optionalContentConfig;
  5615. this.cachedCanvases = new CachedCanvases(this.canvasFactory);
  5616. this.cachedPatterns = new Map();
  5617. this.annotationCanvasMap = annotationCanvasMap;
  5618. this.viewportScale = 1;
  5619. this.outputScaleX = 1;
  5620. this.outputScaleY = 1;
  5621. this.backgroundColor = pageColors?.background || null;
  5622. this.foregroundColor = pageColors?.foreground || null;
  5623. this._cachedScaleForStroking = null;
  5624. this._cachedGetSinglePixelWidth = null;
  5625. this._cachedBitmapsMap = new Map();
  5626. }
  5627. getObject(data, fallback = null) {
  5628. if (typeof data === "string") {
  5629. return data.startsWith("g_") ? this.commonObjs.get(data) : this.objs.get(data);
  5630. }
  5631. return fallback;
  5632. }
  5633. beginDrawing({
  5634. transform,
  5635. viewport,
  5636. transparency = false,
  5637. background = null
  5638. }) {
  5639. const width = this.ctx.canvas.width;
  5640. const height = this.ctx.canvas.height;
  5641. const defaultBackgroundColor = background || "#ffffff";
  5642. this.ctx.save();
  5643. if (this.foregroundColor && this.backgroundColor) {
  5644. this.ctx.fillStyle = this.foregroundColor;
  5645. const fg = this.foregroundColor = this.ctx.fillStyle;
  5646. this.ctx.fillStyle = this.backgroundColor;
  5647. const bg = this.backgroundColor = this.ctx.fillStyle;
  5648. let isValidDefaultBg = true;
  5649. let defaultBg = defaultBackgroundColor;
  5650. this.ctx.fillStyle = defaultBackgroundColor;
  5651. defaultBg = this.ctx.fillStyle;
  5652. isValidDefaultBg = typeof defaultBg === "string" && /^#[0-9A-Fa-f]{6}$/.test(defaultBg);
  5653. if (fg === "#000000" && bg === "#ffffff" || fg === bg || !isValidDefaultBg) {
  5654. this.foregroundColor = this.backgroundColor = null;
  5655. } else {
  5656. const [rB, gB, bB] = (0, _display_utils.getRGB)(defaultBg);
  5657. const newComp = x => {
  5658. x /= 255;
  5659. return x <= 0.03928 ? x / 12.92 : ((x + 0.055) / 1.055) ** 2.4;
  5660. };
  5661. const lumB = Math.round(0.2126 * newComp(rB) + 0.7152 * newComp(gB) + 0.0722 * newComp(bB));
  5662. this.selectColor = (r, g, b) => {
  5663. const lumC = 0.2126 * newComp(r) + 0.7152 * newComp(g) + 0.0722 * newComp(b);
  5664. return Math.round(lumC) === lumB ? bg : fg;
  5665. };
  5666. }
  5667. }
  5668. this.ctx.fillStyle = this.backgroundColor || defaultBackgroundColor;
  5669. this.ctx.fillRect(0, 0, width, height);
  5670. this.ctx.restore();
  5671. if (transparency) {
  5672. const transparentCanvas = this.cachedCanvases.getCanvas("transparent", width, height);
  5673. this.compositeCtx = this.ctx;
  5674. this.transparentCanvas = transparentCanvas.canvas;
  5675. this.ctx = transparentCanvas.context;
  5676. this.ctx.save();
  5677. this.ctx.transform(...(0, _display_utils.getCurrentTransform)(this.compositeCtx));
  5678. }
  5679. this.ctx.save();
  5680. resetCtxToDefault(this.ctx, this.foregroundColor);
  5681. if (transform) {
  5682. this.ctx.transform(...transform);
  5683. this.outputScaleX = transform[0];
  5684. this.outputScaleY = transform[0];
  5685. }
  5686. this.ctx.transform(...viewport.transform);
  5687. this.viewportScale = viewport.scale;
  5688. this.baseTransform = (0, _display_utils.getCurrentTransform)(this.ctx);
  5689. }
  5690. executeOperatorList(operatorList, executionStartIdx, continueCallback, stepper) {
  5691. const argsArray = operatorList.argsArray;
  5692. const fnArray = operatorList.fnArray;
  5693. let i = executionStartIdx || 0;
  5694. const argsArrayLen = argsArray.length;
  5695. if (argsArrayLen === i) {
  5696. return i;
  5697. }
  5698. const chunkOperations = argsArrayLen - i > EXECUTION_STEPS && typeof continueCallback === "function";
  5699. const endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  5700. let steps = 0;
  5701. const commonObjs = this.commonObjs;
  5702. const objs = this.objs;
  5703. let fnId;
  5704. while (true) {
  5705. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  5706. stepper.breakIt(i, continueCallback);
  5707. return i;
  5708. }
  5709. fnId = fnArray[i];
  5710. if (fnId !== _util.OPS.dependency) {
  5711. this[fnId].apply(this, argsArray[i]);
  5712. } else {
  5713. for (const depObjId of argsArray[i]) {
  5714. const objsPool = depObjId.startsWith("g_") ? commonObjs : objs;
  5715. if (!objsPool.has(depObjId)) {
  5716. objsPool.get(depObjId, continueCallback);
  5717. return i;
  5718. }
  5719. }
  5720. }
  5721. i++;
  5722. if (i === argsArrayLen) {
  5723. return i;
  5724. }
  5725. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  5726. if (Date.now() > endTime) {
  5727. continueCallback();
  5728. return i;
  5729. }
  5730. steps = 0;
  5731. }
  5732. }
  5733. }
  5734. #restoreInitialState() {
  5735. while (this.stateStack.length || this.inSMaskMode) {
  5736. this.restore();
  5737. }
  5738. this.ctx.restore();
  5739. if (this.transparentCanvas) {
  5740. this.ctx = this.compositeCtx;
  5741. this.ctx.save();
  5742. this.ctx.setTransform(1, 0, 0, 1, 0, 0);
  5743. this.ctx.drawImage(this.transparentCanvas, 0, 0);
  5744. this.ctx.restore();
  5745. this.transparentCanvas = null;
  5746. }
  5747. }
  5748. endDrawing() {
  5749. this.#restoreInitialState();
  5750. this.cachedCanvases.clear();
  5751. this.cachedPatterns.clear();
  5752. for (const cache of this._cachedBitmapsMap.values()) {
  5753. for (const canvas of cache.values()) {
  5754. if (typeof HTMLCanvasElement !== "undefined" && canvas instanceof HTMLCanvasElement) {
  5755. canvas.width = canvas.height = 0;
  5756. }
  5757. }
  5758. cache.clear();
  5759. }
  5760. this._cachedBitmapsMap.clear();
  5761. }
  5762. _scaleImage(img, inverseTransform) {
  5763. const width = img.width;
  5764. const height = img.height;
  5765. let widthScale = Math.max(Math.hypot(inverseTransform[0], inverseTransform[1]), 1);
  5766. let heightScale = Math.max(Math.hypot(inverseTransform[2], inverseTransform[3]), 1);
  5767. let paintWidth = width,
  5768. paintHeight = height;
  5769. let tmpCanvasId = "prescale1";
  5770. let tmpCanvas, tmpCtx;
  5771. while (widthScale > 2 && paintWidth > 1 || heightScale > 2 && paintHeight > 1) {
  5772. let newWidth = paintWidth,
  5773. newHeight = paintHeight;
  5774. if (widthScale > 2 && paintWidth > 1) {
  5775. newWidth = Math.ceil(paintWidth / 2);
  5776. widthScale /= paintWidth / newWidth;
  5777. }
  5778. if (heightScale > 2 && paintHeight > 1) {
  5779. newHeight = Math.ceil(paintHeight / 2);
  5780. heightScale /= paintHeight / newHeight;
  5781. }
  5782. tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
  5783. tmpCtx = tmpCanvas.context;
  5784. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  5785. tmpCtx.drawImage(img, 0, 0, paintWidth, paintHeight, 0, 0, newWidth, newHeight);
  5786. img = tmpCanvas.canvas;
  5787. paintWidth = newWidth;
  5788. paintHeight = newHeight;
  5789. tmpCanvasId = tmpCanvasId === "prescale1" ? "prescale2" : "prescale1";
  5790. }
  5791. return {
  5792. img,
  5793. paintWidth,
  5794. paintHeight
  5795. };
  5796. }
  5797. _createMaskCanvas(img) {
  5798. const ctx = this.ctx;
  5799. const {
  5800. width,
  5801. height
  5802. } = img;
  5803. const fillColor = this.current.fillColor;
  5804. const isPatternFill = this.current.patternFill;
  5805. const currentTransform = (0, _display_utils.getCurrentTransform)(ctx);
  5806. let cache, cacheKey, scaled, maskCanvas;
  5807. if ((img.bitmap || img.data) && img.count > 1) {
  5808. const mainKey = img.bitmap || img.data.buffer;
  5809. cacheKey = JSON.stringify(isPatternFill ? currentTransform : [currentTransform.slice(0, 4), fillColor]);
  5810. cache = this._cachedBitmapsMap.get(mainKey);
  5811. if (!cache) {
  5812. cache = new Map();
  5813. this._cachedBitmapsMap.set(mainKey, cache);
  5814. }
  5815. const cachedImage = cache.get(cacheKey);
  5816. if (cachedImage && !isPatternFill) {
  5817. const offsetX = Math.round(Math.min(currentTransform[0], currentTransform[2]) + currentTransform[4]);
  5818. const offsetY = Math.round(Math.min(currentTransform[1], currentTransform[3]) + currentTransform[5]);
  5819. return {
  5820. canvas: cachedImage,
  5821. offsetX,
  5822. offsetY
  5823. };
  5824. }
  5825. scaled = cachedImage;
  5826. }
  5827. if (!scaled) {
  5828. maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
  5829. putBinaryImageMask(maskCanvas.context, img);
  5830. }
  5831. let maskToCanvas = _util.Util.transform(currentTransform, [1 / width, 0, 0, -1 / height, 0, 0]);
  5832. maskToCanvas = _util.Util.transform(maskToCanvas, [1, 0, 0, 1, 0, -height]);
  5833. const cord1 = _util.Util.applyTransform([0, 0], maskToCanvas);
  5834. const cord2 = _util.Util.applyTransform([width, height], maskToCanvas);
  5835. const rect = _util.Util.normalizeRect([cord1[0], cord1[1], cord2[0], cord2[1]]);
  5836. const drawnWidth = Math.round(rect[2] - rect[0]) || 1;
  5837. const drawnHeight = Math.round(rect[3] - rect[1]) || 1;
  5838. const fillCanvas = this.cachedCanvases.getCanvas("fillCanvas", drawnWidth, drawnHeight);
  5839. const fillCtx = fillCanvas.context;
  5840. const offsetX = Math.min(cord1[0], cord2[0]);
  5841. const offsetY = Math.min(cord1[1], cord2[1]);
  5842. fillCtx.translate(-offsetX, -offsetY);
  5843. fillCtx.transform(...maskToCanvas);
  5844. if (!scaled) {
  5845. scaled = this._scaleImage(maskCanvas.canvas, (0, _display_utils.getCurrentTransformInverse)(fillCtx));
  5846. scaled = scaled.img;
  5847. if (cache && isPatternFill) {
  5848. cache.set(cacheKey, scaled);
  5849. }
  5850. }
  5851. fillCtx.imageSmoothingEnabled = getImageSmoothingEnabled((0, _display_utils.getCurrentTransform)(fillCtx), img.interpolate);
  5852. drawImageAtIntegerCoords(fillCtx, scaled, 0, 0, scaled.width, scaled.height, 0, 0, width, height);
  5853. fillCtx.globalCompositeOperation = "source-in";
  5854. const inverse = _util.Util.transform((0, _display_utils.getCurrentTransformInverse)(fillCtx), [1, 0, 0, 1, -offsetX, -offsetY]);
  5855. fillCtx.fillStyle = isPatternFill ? fillColor.getPattern(ctx, this, inverse, _pattern_helper.PathType.FILL) : fillColor;
  5856. fillCtx.fillRect(0, 0, width, height);
  5857. if (cache && !isPatternFill) {
  5858. this.cachedCanvases.delete("fillCanvas");
  5859. cache.set(cacheKey, fillCanvas.canvas);
  5860. }
  5861. return {
  5862. canvas: fillCanvas.canvas,
  5863. offsetX: Math.round(offsetX),
  5864. offsetY: Math.round(offsetY)
  5865. };
  5866. }
  5867. setLineWidth(width) {
  5868. if (width !== this.current.lineWidth) {
  5869. this._cachedScaleForStroking = null;
  5870. }
  5871. this.current.lineWidth = width;
  5872. this.ctx.lineWidth = width;
  5873. }
  5874. setLineCap(style) {
  5875. this.ctx.lineCap = LINE_CAP_STYLES[style];
  5876. }
  5877. setLineJoin(style) {
  5878. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  5879. }
  5880. setMiterLimit(limit) {
  5881. this.ctx.miterLimit = limit;
  5882. }
  5883. setDash(dashArray, dashPhase) {
  5884. const ctx = this.ctx;
  5885. if (ctx.setLineDash !== undefined) {
  5886. ctx.setLineDash(dashArray);
  5887. ctx.lineDashOffset = dashPhase;
  5888. }
  5889. }
  5890. setRenderingIntent(intent) {}
  5891. setFlatness(flatness) {}
  5892. setGState(states) {
  5893. for (const [key, value] of states) {
  5894. switch (key) {
  5895. case "LW":
  5896. this.setLineWidth(value);
  5897. break;
  5898. case "LC":
  5899. this.setLineCap(value);
  5900. break;
  5901. case "LJ":
  5902. this.setLineJoin(value);
  5903. break;
  5904. case "ML":
  5905. this.setMiterLimit(value);
  5906. break;
  5907. case "D":
  5908. this.setDash(value[0], value[1]);
  5909. break;
  5910. case "RI":
  5911. this.setRenderingIntent(value);
  5912. break;
  5913. case "FL":
  5914. this.setFlatness(value);
  5915. break;
  5916. case "Font":
  5917. this.setFont(value[0], value[1]);
  5918. break;
  5919. case "CA":
  5920. this.current.strokeAlpha = value;
  5921. break;
  5922. case "ca":
  5923. this.current.fillAlpha = value;
  5924. this.ctx.globalAlpha = value;
  5925. break;
  5926. case "BM":
  5927. this.ctx.globalCompositeOperation = value;
  5928. break;
  5929. case "SMask":
  5930. this.current.activeSMask = value ? this.tempSMask : null;
  5931. this.tempSMask = null;
  5932. this.checkSMaskState();
  5933. break;
  5934. case "TR":
  5935. this.current.transferMaps = value;
  5936. }
  5937. }
  5938. }
  5939. get inSMaskMode() {
  5940. return !!this.suspendedCtx;
  5941. }
  5942. checkSMaskState() {
  5943. const inSMaskMode = this.inSMaskMode;
  5944. if (this.current.activeSMask && !inSMaskMode) {
  5945. this.beginSMaskMode();
  5946. } else if (!this.current.activeSMask && inSMaskMode) {
  5947. this.endSMaskMode();
  5948. }
  5949. }
  5950. beginSMaskMode() {
  5951. if (this.inSMaskMode) {
  5952. throw new Error("beginSMaskMode called while already in smask mode");
  5953. }
  5954. const drawnWidth = this.ctx.canvas.width;
  5955. const drawnHeight = this.ctx.canvas.height;
  5956. const cacheId = "smaskGroupAt" + this.groupLevel;
  5957. const scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight);
  5958. this.suspendedCtx = this.ctx;
  5959. this.ctx = scratchCanvas.context;
  5960. const ctx = this.ctx;
  5961. ctx.setTransform(...(0, _display_utils.getCurrentTransform)(this.suspendedCtx));
  5962. copyCtxState(this.suspendedCtx, ctx);
  5963. mirrorContextOperations(ctx, this.suspendedCtx);
  5964. this.setGState([["BM", "source-over"], ["ca", 1], ["CA", 1]]);
  5965. }
  5966. endSMaskMode() {
  5967. if (!this.inSMaskMode) {
  5968. throw new Error("endSMaskMode called while not in smask mode");
  5969. }
  5970. this.ctx._removeMirroring();
  5971. copyCtxState(this.ctx, this.suspendedCtx);
  5972. this.ctx = this.suspendedCtx;
  5973. this.suspendedCtx = null;
  5974. }
  5975. compose(dirtyBox) {
  5976. if (!this.current.activeSMask) {
  5977. return;
  5978. }
  5979. if (!dirtyBox) {
  5980. dirtyBox = [0, 0, this.ctx.canvas.width, this.ctx.canvas.height];
  5981. } else {
  5982. dirtyBox[0] = Math.floor(dirtyBox[0]);
  5983. dirtyBox[1] = Math.floor(dirtyBox[1]);
  5984. dirtyBox[2] = Math.ceil(dirtyBox[2]);
  5985. dirtyBox[3] = Math.ceil(dirtyBox[3]);
  5986. }
  5987. const smask = this.current.activeSMask;
  5988. const suspendedCtx = this.suspendedCtx;
  5989. composeSMask(suspendedCtx, smask, this.ctx, dirtyBox);
  5990. this.ctx.save();
  5991. this.ctx.setTransform(1, 0, 0, 1, 0, 0);
  5992. this.ctx.clearRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height);
  5993. this.ctx.restore();
  5994. }
  5995. save() {
  5996. if (this.inSMaskMode) {
  5997. copyCtxState(this.ctx, this.suspendedCtx);
  5998. this.suspendedCtx.save();
  5999. } else {
  6000. this.ctx.save();
  6001. }
  6002. const old = this.current;
  6003. this.stateStack.push(old);
  6004. this.current = old.clone();
  6005. }
  6006. restore() {
  6007. if (this.stateStack.length === 0 && this.inSMaskMode) {
  6008. this.endSMaskMode();
  6009. }
  6010. if (this.stateStack.length !== 0) {
  6011. this.current = this.stateStack.pop();
  6012. if (this.inSMaskMode) {
  6013. this.suspendedCtx.restore();
  6014. copyCtxState(this.suspendedCtx, this.ctx);
  6015. } else {
  6016. this.ctx.restore();
  6017. }
  6018. this.checkSMaskState();
  6019. this.pendingClip = null;
  6020. this._cachedScaleForStroking = null;
  6021. this._cachedGetSinglePixelWidth = null;
  6022. }
  6023. }
  6024. transform(a, b, c, d, e, f) {
  6025. this.ctx.transform(a, b, c, d, e, f);
  6026. this._cachedScaleForStroking = null;
  6027. this._cachedGetSinglePixelWidth = null;
  6028. }
  6029. constructPath(ops, args, minMax) {
  6030. const ctx = this.ctx;
  6031. const current = this.current;
  6032. let x = current.x,
  6033. y = current.y;
  6034. let startX, startY;
  6035. const currentTransform = (0, _display_utils.getCurrentTransform)(ctx);
  6036. const isScalingMatrix = currentTransform[0] === 0 && currentTransform[3] === 0 || currentTransform[1] === 0 && currentTransform[2] === 0;
  6037. const minMaxForBezier = isScalingMatrix ? minMax.slice(0) : null;
  6038. for (let i = 0, j = 0, ii = ops.length; i < ii; i++) {
  6039. switch (ops[i] | 0) {
  6040. case _util.OPS.rectangle:
  6041. x = args[j++];
  6042. y = args[j++];
  6043. const width = args[j++];
  6044. const height = args[j++];
  6045. const xw = x + width;
  6046. const yh = y + height;
  6047. ctx.moveTo(x, y);
  6048. if (width === 0 || height === 0) {
  6049. ctx.lineTo(xw, yh);
  6050. } else {
  6051. ctx.lineTo(xw, y);
  6052. ctx.lineTo(xw, yh);
  6053. ctx.lineTo(x, yh);
  6054. }
  6055. if (!isScalingMatrix) {
  6056. current.updateRectMinMax(currentTransform, [x, y, xw, yh]);
  6057. }
  6058. ctx.closePath();
  6059. break;
  6060. case _util.OPS.moveTo:
  6061. x = args[j++];
  6062. y = args[j++];
  6063. ctx.moveTo(x, y);
  6064. if (!isScalingMatrix) {
  6065. current.updatePathMinMax(currentTransform, x, y);
  6066. }
  6067. break;
  6068. case _util.OPS.lineTo:
  6069. x = args[j++];
  6070. y = args[j++];
  6071. ctx.lineTo(x, y);
  6072. if (!isScalingMatrix) {
  6073. current.updatePathMinMax(currentTransform, x, y);
  6074. }
  6075. break;
  6076. case _util.OPS.curveTo:
  6077. startX = x;
  6078. startY = y;
  6079. x = args[j + 4];
  6080. y = args[j + 5];
  6081. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3], x, y);
  6082. current.updateCurvePathMinMax(currentTransform, startX, startY, args[j], args[j + 1], args[j + 2], args[j + 3], x, y, minMaxForBezier);
  6083. j += 6;
  6084. break;
  6085. case _util.OPS.curveTo2:
  6086. startX = x;
  6087. startY = y;
  6088. ctx.bezierCurveTo(x, y, args[j], args[j + 1], args[j + 2], args[j + 3]);
  6089. current.updateCurvePathMinMax(currentTransform, startX, startY, x, y, args[j], args[j + 1], args[j + 2], args[j + 3], minMaxForBezier);
  6090. x = args[j + 2];
  6091. y = args[j + 3];
  6092. j += 4;
  6093. break;
  6094. case _util.OPS.curveTo3:
  6095. startX = x;
  6096. startY = y;
  6097. x = args[j + 2];
  6098. y = args[j + 3];
  6099. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  6100. current.updateCurvePathMinMax(currentTransform, startX, startY, args[j], args[j + 1], x, y, x, y, minMaxForBezier);
  6101. j += 4;
  6102. break;
  6103. case _util.OPS.closePath:
  6104. ctx.closePath();
  6105. break;
  6106. }
  6107. }
  6108. if (isScalingMatrix) {
  6109. current.updateScalingPathMinMax(currentTransform, minMaxForBezier);
  6110. }
  6111. current.setCurrentPoint(x, y);
  6112. }
  6113. closePath() {
  6114. this.ctx.closePath();
  6115. }
  6116. stroke(consumePath = true) {
  6117. const ctx = this.ctx;
  6118. const strokeColor = this.current.strokeColor;
  6119. ctx.globalAlpha = this.current.strokeAlpha;
  6120. if (this.contentVisible) {
  6121. if (typeof strokeColor === "object" && strokeColor?.getPattern) {
  6122. ctx.save();
  6123. ctx.strokeStyle = strokeColor.getPattern(ctx, this, (0, _display_utils.getCurrentTransformInverse)(ctx), _pattern_helper.PathType.STROKE);
  6124. this.rescaleAndStroke(false);
  6125. ctx.restore();
  6126. } else {
  6127. this.rescaleAndStroke(true);
  6128. }
  6129. }
  6130. if (consumePath) {
  6131. this.consumePath(this.current.getClippedPathBoundingBox());
  6132. }
  6133. ctx.globalAlpha = this.current.fillAlpha;
  6134. }
  6135. closeStroke() {
  6136. this.closePath();
  6137. this.stroke();
  6138. }
  6139. fill(consumePath = true) {
  6140. const ctx = this.ctx;
  6141. const fillColor = this.current.fillColor;
  6142. const isPatternFill = this.current.patternFill;
  6143. let needRestore = false;
  6144. if (isPatternFill) {
  6145. ctx.save();
  6146. ctx.fillStyle = fillColor.getPattern(ctx, this, (0, _display_utils.getCurrentTransformInverse)(ctx), _pattern_helper.PathType.FILL);
  6147. needRestore = true;
  6148. }
  6149. const intersect = this.current.getClippedPathBoundingBox();
  6150. if (this.contentVisible && intersect !== null) {
  6151. if (this.pendingEOFill) {
  6152. ctx.fill("evenodd");
  6153. this.pendingEOFill = false;
  6154. } else {
  6155. ctx.fill();
  6156. }
  6157. }
  6158. if (needRestore) {
  6159. ctx.restore();
  6160. }
  6161. if (consumePath) {
  6162. this.consumePath(intersect);
  6163. }
  6164. }
  6165. eoFill() {
  6166. this.pendingEOFill = true;
  6167. this.fill();
  6168. }
  6169. fillStroke() {
  6170. this.fill(false);
  6171. this.stroke(false);
  6172. this.consumePath();
  6173. }
  6174. eoFillStroke() {
  6175. this.pendingEOFill = true;
  6176. this.fillStroke();
  6177. }
  6178. closeFillStroke() {
  6179. this.closePath();
  6180. this.fillStroke();
  6181. }
  6182. closeEOFillStroke() {
  6183. this.pendingEOFill = true;
  6184. this.closePath();
  6185. this.fillStroke();
  6186. }
  6187. endPath() {
  6188. this.consumePath();
  6189. }
  6190. clip() {
  6191. this.pendingClip = NORMAL_CLIP;
  6192. }
  6193. eoClip() {
  6194. this.pendingClip = EO_CLIP;
  6195. }
  6196. beginText() {
  6197. this.current.textMatrix = _util.IDENTITY_MATRIX;
  6198. this.current.textMatrixScale = 1;
  6199. this.current.x = this.current.lineX = 0;
  6200. this.current.y = this.current.lineY = 0;
  6201. }
  6202. endText() {
  6203. const paths = this.pendingTextPaths;
  6204. const ctx = this.ctx;
  6205. if (paths === undefined) {
  6206. ctx.beginPath();
  6207. return;
  6208. }
  6209. ctx.save();
  6210. ctx.beginPath();
  6211. for (const path of paths) {
  6212. ctx.setTransform(...path.transform);
  6213. ctx.translate(path.x, path.y);
  6214. path.addToPath(ctx, path.fontSize);
  6215. }
  6216. ctx.restore();
  6217. ctx.clip();
  6218. ctx.beginPath();
  6219. delete this.pendingTextPaths;
  6220. }
  6221. setCharSpacing(spacing) {
  6222. this.current.charSpacing = spacing;
  6223. }
  6224. setWordSpacing(spacing) {
  6225. this.current.wordSpacing = spacing;
  6226. }
  6227. setHScale(scale) {
  6228. this.current.textHScale = scale / 100;
  6229. }
  6230. setLeading(leading) {
  6231. this.current.leading = -leading;
  6232. }
  6233. setFont(fontRefName, size) {
  6234. const fontObj = this.commonObjs.get(fontRefName);
  6235. const current = this.current;
  6236. if (!fontObj) {
  6237. throw new Error(`Can't find font for ${fontRefName}`);
  6238. }
  6239. current.fontMatrix = fontObj.fontMatrix || _util.FONT_IDENTITY_MATRIX;
  6240. if (current.fontMatrix[0] === 0 || current.fontMatrix[3] === 0) {
  6241. (0, _util.warn)("Invalid font matrix for font " + fontRefName);
  6242. }
  6243. if (size < 0) {
  6244. size = -size;
  6245. current.fontDirection = -1;
  6246. } else {
  6247. current.fontDirection = 1;
  6248. }
  6249. this.current.font = fontObj;
  6250. this.current.fontSize = size;
  6251. if (fontObj.isType3Font) {
  6252. return;
  6253. }
  6254. const name = fontObj.loadedName || "sans-serif";
  6255. let bold = "normal";
  6256. if (fontObj.black) {
  6257. bold = "900";
  6258. } else if (fontObj.bold) {
  6259. bold = "bold";
  6260. }
  6261. const italic = fontObj.italic ? "italic" : "normal";
  6262. const typeface = `"${name}", ${fontObj.fallbackName}`;
  6263. let browserFontSize = size;
  6264. if (size < MIN_FONT_SIZE) {
  6265. browserFontSize = MIN_FONT_SIZE;
  6266. } else if (size > MAX_FONT_SIZE) {
  6267. browserFontSize = MAX_FONT_SIZE;
  6268. }
  6269. this.current.fontSizeScale = size / browserFontSize;
  6270. this.ctx.font = `${italic} ${bold} ${browserFontSize}px ${typeface}`;
  6271. }
  6272. setTextRenderingMode(mode) {
  6273. this.current.textRenderingMode = mode;
  6274. }
  6275. setTextRise(rise) {
  6276. this.current.textRise = rise;
  6277. }
  6278. moveText(x, y) {
  6279. this.current.x = this.current.lineX += x;
  6280. this.current.y = this.current.lineY += y;
  6281. }
  6282. setLeadingMoveText(x, y) {
  6283. this.setLeading(-y);
  6284. this.moveText(x, y);
  6285. }
  6286. setTextMatrix(a, b, c, d, e, f) {
  6287. this.current.textMatrix = [a, b, c, d, e, f];
  6288. this.current.textMatrixScale = Math.hypot(a, b);
  6289. this.current.x = this.current.lineX = 0;
  6290. this.current.y = this.current.lineY = 0;
  6291. }
  6292. nextLine() {
  6293. this.moveText(0, this.current.leading);
  6294. }
  6295. paintChar(character, x, y, patternTransform) {
  6296. const ctx = this.ctx;
  6297. const current = this.current;
  6298. const font = current.font;
  6299. const textRenderingMode = current.textRenderingMode;
  6300. const fontSize = current.fontSize / current.fontSizeScale;
  6301. const fillStrokeMode = textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  6302. const isAddToPathSet = !!(textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG);
  6303. const patternFill = current.patternFill && !font.missingFile;
  6304. let addToPath;
  6305. if (font.disableFontFace || isAddToPathSet || patternFill) {
  6306. addToPath = font.getPathGenerator(this.commonObjs, character);
  6307. }
  6308. if (font.disableFontFace || patternFill) {
  6309. ctx.save();
  6310. ctx.translate(x, y);
  6311. ctx.beginPath();
  6312. addToPath(ctx, fontSize);
  6313. if (patternTransform) {
  6314. ctx.setTransform(...patternTransform);
  6315. }
  6316. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  6317. ctx.fill();
  6318. }
  6319. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  6320. ctx.stroke();
  6321. }
  6322. ctx.restore();
  6323. } else {
  6324. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  6325. ctx.fillText(character, x, y);
  6326. }
  6327. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  6328. ctx.strokeText(character, x, y);
  6329. }
  6330. }
  6331. if (isAddToPathSet) {
  6332. const paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  6333. paths.push({
  6334. transform: (0, _display_utils.getCurrentTransform)(ctx),
  6335. x,
  6336. y,
  6337. fontSize,
  6338. addToPath
  6339. });
  6340. }
  6341. }
  6342. get isFontSubpixelAAEnabled() {
  6343. const {
  6344. context: ctx
  6345. } = this.cachedCanvases.getCanvas("isFontSubpixelAAEnabled", 10, 10);
  6346. ctx.scale(1.5, 1);
  6347. ctx.fillText("I", 0, 10);
  6348. const data = ctx.getImageData(0, 0, 10, 10).data;
  6349. let enabled = false;
  6350. for (let i = 3; i < data.length; i += 4) {
  6351. if (data[i] > 0 && data[i] < 255) {
  6352. enabled = true;
  6353. break;
  6354. }
  6355. }
  6356. return (0, _util.shadow)(this, "isFontSubpixelAAEnabled", enabled);
  6357. }
  6358. showText(glyphs) {
  6359. const current = this.current;
  6360. const font = current.font;
  6361. if (font.isType3Font) {
  6362. return this.showType3Text(glyphs);
  6363. }
  6364. const fontSize = current.fontSize;
  6365. if (fontSize === 0) {
  6366. return undefined;
  6367. }
  6368. const ctx = this.ctx;
  6369. const fontSizeScale = current.fontSizeScale;
  6370. const charSpacing = current.charSpacing;
  6371. const wordSpacing = current.wordSpacing;
  6372. const fontDirection = current.fontDirection;
  6373. const textHScale = current.textHScale * fontDirection;
  6374. const glyphsLength = glyphs.length;
  6375. const vertical = font.vertical;
  6376. const spacingDir = vertical ? 1 : -1;
  6377. const defaultVMetrics = font.defaultVMetrics;
  6378. const widthAdvanceScale = fontSize * current.fontMatrix[0];
  6379. const simpleFillText = current.textRenderingMode === _util.TextRenderingMode.FILL && !font.disableFontFace && !current.patternFill;
  6380. ctx.save();
  6381. ctx.transform(...current.textMatrix);
  6382. ctx.translate(current.x, current.y + current.textRise);
  6383. if (fontDirection > 0) {
  6384. ctx.scale(textHScale, -1);
  6385. } else {
  6386. ctx.scale(textHScale, 1);
  6387. }
  6388. let patternTransform;
  6389. if (current.patternFill) {
  6390. ctx.save();
  6391. const pattern = current.fillColor.getPattern(ctx, this, (0, _display_utils.getCurrentTransformInverse)(ctx), _pattern_helper.PathType.FILL);
  6392. patternTransform = (0, _display_utils.getCurrentTransform)(ctx);
  6393. ctx.restore();
  6394. ctx.fillStyle = pattern;
  6395. }
  6396. let lineWidth = current.lineWidth;
  6397. const scale = current.textMatrixScale;
  6398. if (scale === 0 || lineWidth === 0) {
  6399. const fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  6400. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  6401. lineWidth = this.getSinglePixelWidth();
  6402. }
  6403. } else {
  6404. lineWidth /= scale;
  6405. }
  6406. if (fontSizeScale !== 1.0) {
  6407. ctx.scale(fontSizeScale, fontSizeScale);
  6408. lineWidth /= fontSizeScale;
  6409. }
  6410. ctx.lineWidth = lineWidth;
  6411. if (font.isInvalidPDFjsFont) {
  6412. const chars = [];
  6413. let width = 0;
  6414. for (const glyph of glyphs) {
  6415. chars.push(glyph.unicode);
  6416. width += glyph.width;
  6417. }
  6418. ctx.fillText(chars.join(""), 0, 0);
  6419. current.x += width * widthAdvanceScale * textHScale;
  6420. ctx.restore();
  6421. this.compose();
  6422. return undefined;
  6423. }
  6424. let x = 0,
  6425. i;
  6426. for (i = 0; i < glyphsLength; ++i) {
  6427. const glyph = glyphs[i];
  6428. if (typeof glyph === "number") {
  6429. x += spacingDir * glyph * fontSize / 1000;
  6430. continue;
  6431. }
  6432. let restoreNeeded = false;
  6433. const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  6434. const character = glyph.fontChar;
  6435. const accent = glyph.accent;
  6436. let scaledX, scaledY;
  6437. let width = glyph.width;
  6438. if (vertical) {
  6439. const vmetric = glyph.vmetric || defaultVMetrics;
  6440. const vx = -(glyph.vmetric ? vmetric[1] : width * 0.5) * widthAdvanceScale;
  6441. const vy = vmetric[2] * widthAdvanceScale;
  6442. width = vmetric ? -vmetric[0] : width;
  6443. scaledX = vx / fontSizeScale;
  6444. scaledY = (x + vy) / fontSizeScale;
  6445. } else {
  6446. scaledX = x / fontSizeScale;
  6447. scaledY = 0;
  6448. }
  6449. if (font.remeasure && width > 0) {
  6450. const measuredWidth = ctx.measureText(character).width * 1000 / fontSize * fontSizeScale;
  6451. if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
  6452. const characterScaleX = width / measuredWidth;
  6453. restoreNeeded = true;
  6454. ctx.save();
  6455. ctx.scale(characterScaleX, 1);
  6456. scaledX /= characterScaleX;
  6457. } else if (width !== measuredWidth) {
  6458. scaledX += (width - measuredWidth) / 2000 * fontSize / fontSizeScale;
  6459. }
  6460. }
  6461. if (this.contentVisible && (glyph.isInFont || font.missingFile)) {
  6462. if (simpleFillText && !accent) {
  6463. ctx.fillText(character, scaledX, scaledY);
  6464. } else {
  6465. this.paintChar(character, scaledX, scaledY, patternTransform);
  6466. if (accent) {
  6467. const scaledAccentX = scaledX + fontSize * accent.offset.x / fontSizeScale;
  6468. const scaledAccentY = scaledY - fontSize * accent.offset.y / fontSizeScale;
  6469. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY, patternTransform);
  6470. }
  6471. }
  6472. }
  6473. let charWidth;
  6474. if (vertical) {
  6475. charWidth = width * widthAdvanceScale - spacing * fontDirection;
  6476. } else {
  6477. charWidth = width * widthAdvanceScale + spacing * fontDirection;
  6478. }
  6479. x += charWidth;
  6480. if (restoreNeeded) {
  6481. ctx.restore();
  6482. }
  6483. }
  6484. if (vertical) {
  6485. current.y -= x;
  6486. } else {
  6487. current.x += x * textHScale;
  6488. }
  6489. ctx.restore();
  6490. this.compose();
  6491. return undefined;
  6492. }
  6493. showType3Text(glyphs) {
  6494. const ctx = this.ctx;
  6495. const current = this.current;
  6496. const font = current.font;
  6497. const fontSize = current.fontSize;
  6498. const fontDirection = current.fontDirection;
  6499. const spacingDir = font.vertical ? 1 : -1;
  6500. const charSpacing = current.charSpacing;
  6501. const wordSpacing = current.wordSpacing;
  6502. const textHScale = current.textHScale * fontDirection;
  6503. const fontMatrix = current.fontMatrix || _util.FONT_IDENTITY_MATRIX;
  6504. const glyphsLength = glyphs.length;
  6505. const isTextInvisible = current.textRenderingMode === _util.TextRenderingMode.INVISIBLE;
  6506. let i, glyph, width, spacingLength;
  6507. if (isTextInvisible || fontSize === 0) {
  6508. return;
  6509. }
  6510. this._cachedScaleForStroking = null;
  6511. this._cachedGetSinglePixelWidth = null;
  6512. ctx.save();
  6513. ctx.transform(...current.textMatrix);
  6514. ctx.translate(current.x, current.y);
  6515. ctx.scale(textHScale, fontDirection);
  6516. for (i = 0; i < glyphsLength; ++i) {
  6517. glyph = glyphs[i];
  6518. if (typeof glyph === "number") {
  6519. spacingLength = spacingDir * glyph * fontSize / 1000;
  6520. this.ctx.translate(spacingLength, 0);
  6521. current.x += spacingLength * textHScale;
  6522. continue;
  6523. }
  6524. const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  6525. const operatorList = font.charProcOperatorList[glyph.operatorListId];
  6526. if (!operatorList) {
  6527. (0, _util.warn)(`Type3 character "${glyph.operatorListId}" is not available.`);
  6528. continue;
  6529. }
  6530. if (this.contentVisible) {
  6531. this.processingType3 = glyph;
  6532. this.save();
  6533. ctx.scale(fontSize, fontSize);
  6534. ctx.transform(...fontMatrix);
  6535. this.executeOperatorList(operatorList);
  6536. this.restore();
  6537. }
  6538. const transformed = _util.Util.applyTransform([glyph.width, 0], fontMatrix);
  6539. width = transformed[0] * fontSize + spacing;
  6540. ctx.translate(width, 0);
  6541. current.x += width * textHScale;
  6542. }
  6543. ctx.restore();
  6544. this.processingType3 = null;
  6545. }
  6546. setCharWidth(xWidth, yWidth) {}
  6547. setCharWidthAndBounds(xWidth, yWidth, llx, lly, urx, ury) {
  6548. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  6549. this.ctx.clip();
  6550. this.endPath();
  6551. }
  6552. getColorN_Pattern(IR) {
  6553. let pattern;
  6554. if (IR[0] === "TilingPattern") {
  6555. const color = IR[1];
  6556. const baseTransform = this.baseTransform || (0, _display_utils.getCurrentTransform)(this.ctx);
  6557. const canvasGraphicsFactory = {
  6558. createCanvasGraphics: ctx => {
  6559. return new CanvasGraphics(ctx, this.commonObjs, this.objs, this.canvasFactory, {
  6560. optionalContentConfig: this.optionalContentConfig,
  6561. markedContentStack: this.markedContentStack
  6562. });
  6563. }
  6564. };
  6565. pattern = new _pattern_helper.TilingPattern(IR, color, this.ctx, canvasGraphicsFactory, baseTransform);
  6566. } else {
  6567. pattern = this._getPattern(IR[1], IR[2]);
  6568. }
  6569. return pattern;
  6570. }
  6571. setStrokeColorN() {
  6572. this.current.strokeColor = this.getColorN_Pattern(arguments);
  6573. }
  6574. setFillColorN() {
  6575. this.current.fillColor = this.getColorN_Pattern(arguments);
  6576. this.current.patternFill = true;
  6577. }
  6578. setStrokeRGBColor(r, g, b) {
  6579. const color = this.selectColor?.(r, g, b) || _util.Util.makeHexColor(r, g, b);
  6580. this.ctx.strokeStyle = color;
  6581. this.current.strokeColor = color;
  6582. }
  6583. setFillRGBColor(r, g, b) {
  6584. const color = this.selectColor?.(r, g, b) || _util.Util.makeHexColor(r, g, b);
  6585. this.ctx.fillStyle = color;
  6586. this.current.fillColor = color;
  6587. this.current.patternFill = false;
  6588. }
  6589. _getPattern(objId, matrix = null) {
  6590. let pattern;
  6591. if (this.cachedPatterns.has(objId)) {
  6592. pattern = this.cachedPatterns.get(objId);
  6593. } else {
  6594. pattern = (0, _pattern_helper.getShadingPattern)(this.objs.get(objId));
  6595. this.cachedPatterns.set(objId, pattern);
  6596. }
  6597. if (matrix) {
  6598. pattern.matrix = matrix;
  6599. }
  6600. return pattern;
  6601. }
  6602. shadingFill(objId) {
  6603. if (!this.contentVisible) {
  6604. return;
  6605. }
  6606. const ctx = this.ctx;
  6607. this.save();
  6608. const pattern = this._getPattern(objId);
  6609. ctx.fillStyle = pattern.getPattern(ctx, this, (0, _display_utils.getCurrentTransformInverse)(ctx), _pattern_helper.PathType.SHADING);
  6610. const inv = (0, _display_utils.getCurrentTransformInverse)(ctx);
  6611. if (inv) {
  6612. const canvas = ctx.canvas;
  6613. const width = canvas.width;
  6614. const height = canvas.height;
  6615. const bl = _util.Util.applyTransform([0, 0], inv);
  6616. const br = _util.Util.applyTransform([0, height], inv);
  6617. const ul = _util.Util.applyTransform([width, 0], inv);
  6618. const ur = _util.Util.applyTransform([width, height], inv);
  6619. const x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  6620. const y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  6621. const x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  6622. const y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  6623. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  6624. } else {
  6625. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  6626. }
  6627. this.compose(this.current.getClippedPathBoundingBox());
  6628. this.restore();
  6629. }
  6630. beginInlineImage() {
  6631. (0, _util.unreachable)("Should not call beginInlineImage");
  6632. }
  6633. beginImageData() {
  6634. (0, _util.unreachable)("Should not call beginImageData");
  6635. }
  6636. paintFormXObjectBegin(matrix, bbox) {
  6637. if (!this.contentVisible) {
  6638. return;
  6639. }
  6640. this.save();
  6641. this.baseTransformStack.push(this.baseTransform);
  6642. if (Array.isArray(matrix) && matrix.length === 6) {
  6643. this.transform(...matrix);
  6644. }
  6645. this.baseTransform = (0, _display_utils.getCurrentTransform)(this.ctx);
  6646. if (bbox) {
  6647. const width = bbox[2] - bbox[0];
  6648. const height = bbox[3] - bbox[1];
  6649. this.ctx.rect(bbox[0], bbox[1], width, height);
  6650. this.current.updateRectMinMax((0, _display_utils.getCurrentTransform)(this.ctx), bbox);
  6651. this.clip();
  6652. this.endPath();
  6653. }
  6654. }
  6655. paintFormXObjectEnd() {
  6656. if (!this.contentVisible) {
  6657. return;
  6658. }
  6659. this.restore();
  6660. this.baseTransform = this.baseTransformStack.pop();
  6661. }
  6662. beginGroup(group) {
  6663. if (!this.contentVisible) {
  6664. return;
  6665. }
  6666. this.save();
  6667. if (this.inSMaskMode) {
  6668. this.endSMaskMode();
  6669. this.current.activeSMask = null;
  6670. }
  6671. const currentCtx = this.ctx;
  6672. if (!group.isolated) {
  6673. (0, _util.info)("TODO: Support non-isolated groups.");
  6674. }
  6675. if (group.knockout) {
  6676. (0, _util.warn)("Knockout groups not supported.");
  6677. }
  6678. const currentTransform = (0, _display_utils.getCurrentTransform)(currentCtx);
  6679. if (group.matrix) {
  6680. currentCtx.transform(...group.matrix);
  6681. }
  6682. if (!group.bbox) {
  6683. throw new Error("Bounding box is required.");
  6684. }
  6685. let bounds = _util.Util.getAxialAlignedBoundingBox(group.bbox, (0, _display_utils.getCurrentTransform)(currentCtx));
  6686. const canvasBounds = [0, 0, currentCtx.canvas.width, currentCtx.canvas.height];
  6687. bounds = _util.Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  6688. const offsetX = Math.floor(bounds[0]);
  6689. const offsetY = Math.floor(bounds[1]);
  6690. let drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  6691. let drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  6692. let scaleX = 1,
  6693. scaleY = 1;
  6694. if (drawnWidth > MAX_GROUP_SIZE) {
  6695. scaleX = drawnWidth / MAX_GROUP_SIZE;
  6696. drawnWidth = MAX_GROUP_SIZE;
  6697. }
  6698. if (drawnHeight > MAX_GROUP_SIZE) {
  6699. scaleY = drawnHeight / MAX_GROUP_SIZE;
  6700. drawnHeight = MAX_GROUP_SIZE;
  6701. }
  6702. this.current.startNewPathAndClipBox([0, 0, drawnWidth, drawnHeight]);
  6703. let cacheId = "groupAt" + this.groupLevel;
  6704. if (group.smask) {
  6705. cacheId += "_smask_" + this.smaskCounter++ % 2;
  6706. }
  6707. const scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight);
  6708. const groupCtx = scratchCanvas.context;
  6709. groupCtx.scale(1 / scaleX, 1 / scaleY);
  6710. groupCtx.translate(-offsetX, -offsetY);
  6711. groupCtx.transform(...currentTransform);
  6712. if (group.smask) {
  6713. this.smaskStack.push({
  6714. canvas: scratchCanvas.canvas,
  6715. context: groupCtx,
  6716. offsetX,
  6717. offsetY,
  6718. scaleX,
  6719. scaleY,
  6720. subtype: group.smask.subtype,
  6721. backdrop: group.smask.backdrop,
  6722. transferMap: group.smask.transferMap || null,
  6723. startTransformInverse: null
  6724. });
  6725. } else {
  6726. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  6727. currentCtx.translate(offsetX, offsetY);
  6728. currentCtx.scale(scaleX, scaleY);
  6729. currentCtx.save();
  6730. }
  6731. copyCtxState(currentCtx, groupCtx);
  6732. this.ctx = groupCtx;
  6733. this.setGState([["BM", "source-over"], ["ca", 1], ["CA", 1]]);
  6734. this.groupStack.push(currentCtx);
  6735. this.groupLevel++;
  6736. }
  6737. endGroup(group) {
  6738. if (!this.contentVisible) {
  6739. return;
  6740. }
  6741. this.groupLevel--;
  6742. const groupCtx = this.ctx;
  6743. const ctx = this.groupStack.pop();
  6744. this.ctx = ctx;
  6745. this.ctx.imageSmoothingEnabled = false;
  6746. if (group.smask) {
  6747. this.tempSMask = this.smaskStack.pop();
  6748. this.restore();
  6749. } else {
  6750. this.ctx.restore();
  6751. const currentMtx = (0, _display_utils.getCurrentTransform)(this.ctx);
  6752. this.restore();
  6753. this.ctx.save();
  6754. this.ctx.setTransform(...currentMtx);
  6755. const dirtyBox = _util.Util.getAxialAlignedBoundingBox([0, 0, groupCtx.canvas.width, groupCtx.canvas.height], currentMtx);
  6756. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  6757. this.ctx.restore();
  6758. this.compose(dirtyBox);
  6759. }
  6760. }
  6761. beginAnnotation(id, rect, transform, matrix, hasOwnCanvas) {
  6762. this.#restoreInitialState();
  6763. resetCtxToDefault(this.ctx, this.foregroundColor);
  6764. this.ctx.save();
  6765. this.save();
  6766. if (this.baseTransform) {
  6767. this.ctx.setTransform(...this.baseTransform);
  6768. }
  6769. if (Array.isArray(rect) && rect.length === 4) {
  6770. const width = rect[2] - rect[0];
  6771. const height = rect[3] - rect[1];
  6772. if (hasOwnCanvas && this.annotationCanvasMap) {
  6773. transform = transform.slice();
  6774. transform[4] -= rect[0];
  6775. transform[5] -= rect[1];
  6776. rect = rect.slice();
  6777. rect[0] = rect[1] = 0;
  6778. rect[2] = width;
  6779. rect[3] = height;
  6780. const [scaleX, scaleY] = _util.Util.singularValueDecompose2dScale((0, _display_utils.getCurrentTransform)(this.ctx));
  6781. const {
  6782. viewportScale
  6783. } = this;
  6784. const canvasWidth = Math.ceil(width * this.outputScaleX * viewportScale);
  6785. const canvasHeight = Math.ceil(height * this.outputScaleY * viewportScale);
  6786. this.annotationCanvas = this.canvasFactory.create(canvasWidth, canvasHeight);
  6787. const {
  6788. canvas,
  6789. context
  6790. } = this.annotationCanvas;
  6791. this.annotationCanvasMap.set(id, canvas);
  6792. this.annotationCanvas.savedCtx = this.ctx;
  6793. this.ctx = context;
  6794. this.ctx.setTransform(scaleX, 0, 0, -scaleY, 0, height * scaleY);
  6795. resetCtxToDefault(this.ctx, this.foregroundColor);
  6796. } else {
  6797. resetCtxToDefault(this.ctx, this.foregroundColor);
  6798. this.ctx.rect(rect[0], rect[1], width, height);
  6799. this.ctx.clip();
  6800. this.endPath();
  6801. }
  6802. }
  6803. this.current = new CanvasExtraState(this.ctx.canvas.width, this.ctx.canvas.height);
  6804. this.transform(...transform);
  6805. this.transform(...matrix);
  6806. }
  6807. endAnnotation() {
  6808. if (this.annotationCanvas) {
  6809. this.ctx = this.annotationCanvas.savedCtx;
  6810. delete this.annotationCanvas.savedCtx;
  6811. delete this.annotationCanvas;
  6812. }
  6813. }
  6814. paintImageMaskXObject(img) {
  6815. if (!this.contentVisible) {
  6816. return;
  6817. }
  6818. const count = img.count;
  6819. img = this.getObject(img.data, img);
  6820. img.count = count;
  6821. const ctx = this.ctx;
  6822. const glyph = this.processingType3;
  6823. if (glyph) {
  6824. if (glyph.compiled === undefined) {
  6825. glyph.compiled = compileType3Glyph(img);
  6826. }
  6827. if (glyph.compiled) {
  6828. glyph.compiled(ctx);
  6829. return;
  6830. }
  6831. }
  6832. const mask = this._createMaskCanvas(img);
  6833. const maskCanvas = mask.canvas;
  6834. ctx.save();
  6835. ctx.setTransform(1, 0, 0, 1, 0, 0);
  6836. ctx.drawImage(maskCanvas, mask.offsetX, mask.offsetY);
  6837. ctx.restore();
  6838. this.compose();
  6839. }
  6840. paintImageMaskXObjectRepeat(img, scaleX, skewX = 0, skewY = 0, scaleY, positions) {
  6841. if (!this.contentVisible) {
  6842. return;
  6843. }
  6844. img = this.getObject(img.data, img);
  6845. const ctx = this.ctx;
  6846. ctx.save();
  6847. const currentTransform = (0, _display_utils.getCurrentTransform)(ctx);
  6848. ctx.transform(scaleX, skewX, skewY, scaleY, 0, 0);
  6849. const mask = this._createMaskCanvas(img);
  6850. ctx.setTransform(1, 0, 0, 1, mask.offsetX - currentTransform[4], mask.offsetY - currentTransform[5]);
  6851. for (let i = 0, ii = positions.length; i < ii; i += 2) {
  6852. const trans = _util.Util.transform(currentTransform, [scaleX, skewX, skewY, scaleY, positions[i], positions[i + 1]]);
  6853. const [x, y] = _util.Util.applyTransform([0, 0], trans);
  6854. ctx.drawImage(mask.canvas, x, y);
  6855. }
  6856. ctx.restore();
  6857. this.compose();
  6858. }
  6859. paintImageMaskXObjectGroup(images) {
  6860. if (!this.contentVisible) {
  6861. return;
  6862. }
  6863. const ctx = this.ctx;
  6864. const fillColor = this.current.fillColor;
  6865. const isPatternFill = this.current.patternFill;
  6866. for (const image of images) {
  6867. const {
  6868. data,
  6869. width,
  6870. height,
  6871. transform
  6872. } = image;
  6873. const maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
  6874. const maskCtx = maskCanvas.context;
  6875. maskCtx.save();
  6876. const img = this.getObject(data, image);
  6877. putBinaryImageMask(maskCtx, img);
  6878. maskCtx.globalCompositeOperation = "source-in";
  6879. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this, (0, _display_utils.getCurrentTransformInverse)(ctx), _pattern_helper.PathType.FILL) : fillColor;
  6880. maskCtx.fillRect(0, 0, width, height);
  6881. maskCtx.restore();
  6882. ctx.save();
  6883. ctx.transform(...transform);
  6884. ctx.scale(1, -1);
  6885. drawImageAtIntegerCoords(ctx, maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1);
  6886. ctx.restore();
  6887. }
  6888. this.compose();
  6889. }
  6890. paintImageXObject(objId) {
  6891. if (!this.contentVisible) {
  6892. return;
  6893. }
  6894. const imgData = this.getObject(objId);
  6895. if (!imgData) {
  6896. (0, _util.warn)("Dependent image isn't ready yet");
  6897. return;
  6898. }
  6899. this.paintInlineImageXObject(imgData);
  6900. }
  6901. paintImageXObjectRepeat(objId, scaleX, scaleY, positions) {
  6902. if (!this.contentVisible) {
  6903. return;
  6904. }
  6905. const imgData = this.getObject(objId);
  6906. if (!imgData) {
  6907. (0, _util.warn)("Dependent image isn't ready yet");
  6908. return;
  6909. }
  6910. const width = imgData.width;
  6911. const height = imgData.height;
  6912. const map = [];
  6913. for (let i = 0, ii = positions.length; i < ii; i += 2) {
  6914. map.push({
  6915. transform: [scaleX, 0, 0, scaleY, positions[i], positions[i + 1]],
  6916. x: 0,
  6917. y: 0,
  6918. w: width,
  6919. h: height
  6920. });
  6921. }
  6922. this.paintInlineImageXObjectGroup(imgData, map);
  6923. }
  6924. paintInlineImageXObject(imgData) {
  6925. if (!this.contentVisible) {
  6926. return;
  6927. }
  6928. const width = imgData.width;
  6929. const height = imgData.height;
  6930. const ctx = this.ctx;
  6931. this.save();
  6932. ctx.scale(1 / width, -1 / height);
  6933. let imgToPaint;
  6934. if (typeof HTMLElement === "function" && imgData instanceof HTMLElement || !imgData.data) {
  6935. imgToPaint = imgData;
  6936. } else {
  6937. const tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", width, height);
  6938. const tmpCtx = tmpCanvas.context;
  6939. putBinaryImageData(tmpCtx, imgData, this.current.transferMaps);
  6940. imgToPaint = tmpCanvas.canvas;
  6941. }
  6942. const scaled = this._scaleImage(imgToPaint, (0, _display_utils.getCurrentTransformInverse)(ctx));
  6943. ctx.imageSmoothingEnabled = getImageSmoothingEnabled((0, _display_utils.getCurrentTransform)(ctx), imgData.interpolate);
  6944. drawImageAtIntegerCoords(ctx, scaled.img, 0, 0, scaled.paintWidth, scaled.paintHeight, 0, -height, width, height);
  6945. this.compose();
  6946. this.restore();
  6947. }
  6948. paintInlineImageXObjectGroup(imgData, map) {
  6949. if (!this.contentVisible) {
  6950. return;
  6951. }
  6952. const ctx = this.ctx;
  6953. const w = imgData.width;
  6954. const h = imgData.height;
  6955. const tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", w, h);
  6956. const tmpCtx = tmpCanvas.context;
  6957. putBinaryImageData(tmpCtx, imgData, this.current.transferMaps);
  6958. for (const entry of map) {
  6959. ctx.save();
  6960. ctx.transform(...entry.transform);
  6961. ctx.scale(1, -1);
  6962. drawImageAtIntegerCoords(ctx, tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h, 0, -1, 1, 1);
  6963. ctx.restore();
  6964. }
  6965. this.compose();
  6966. }
  6967. paintSolidColorImageMask() {
  6968. if (!this.contentVisible) {
  6969. return;
  6970. }
  6971. this.ctx.fillRect(0, 0, 1, 1);
  6972. this.compose();
  6973. }
  6974. markPoint(tag) {}
  6975. markPointProps(tag, properties) {}
  6976. beginMarkedContent(tag) {
  6977. this.markedContentStack.push({
  6978. visible: true
  6979. });
  6980. }
  6981. beginMarkedContentProps(tag, properties) {
  6982. if (tag === "OC") {
  6983. this.markedContentStack.push({
  6984. visible: this.optionalContentConfig.isVisible(properties)
  6985. });
  6986. } else {
  6987. this.markedContentStack.push({
  6988. visible: true
  6989. });
  6990. }
  6991. this.contentVisible = this.isContentVisible();
  6992. }
  6993. endMarkedContent() {
  6994. this.markedContentStack.pop();
  6995. this.contentVisible = this.isContentVisible();
  6996. }
  6997. beginCompat() {}
  6998. endCompat() {}
  6999. consumePath(clipBox) {
  7000. const isEmpty = this.current.isEmptyClip();
  7001. if (this.pendingClip) {
  7002. this.current.updateClipFromPath();
  7003. }
  7004. if (!this.pendingClip) {
  7005. this.compose(clipBox);
  7006. }
  7007. const ctx = this.ctx;
  7008. if (this.pendingClip) {
  7009. if (!isEmpty) {
  7010. if (this.pendingClip === EO_CLIP) {
  7011. ctx.clip("evenodd");
  7012. } else {
  7013. ctx.clip();
  7014. }
  7015. }
  7016. this.pendingClip = null;
  7017. }
  7018. this.current.startNewPathAndClipBox(this.current.clipBox);
  7019. ctx.beginPath();
  7020. }
  7021. getSinglePixelWidth() {
  7022. if (!this._cachedGetSinglePixelWidth) {
  7023. const m = (0, _display_utils.getCurrentTransform)(this.ctx);
  7024. if (m[1] === 0 && m[2] === 0) {
  7025. this._cachedGetSinglePixelWidth = 1 / Math.min(Math.abs(m[0]), Math.abs(m[3]));
  7026. } else {
  7027. const absDet = Math.abs(m[0] * m[3] - m[2] * m[1]);
  7028. const normX = Math.hypot(m[0], m[2]);
  7029. const normY = Math.hypot(m[1], m[3]);
  7030. this._cachedGetSinglePixelWidth = Math.max(normX, normY) / absDet;
  7031. }
  7032. }
  7033. return this._cachedGetSinglePixelWidth;
  7034. }
  7035. getScaleForStroking() {
  7036. if (!this._cachedScaleForStroking) {
  7037. const {
  7038. lineWidth
  7039. } = this.current;
  7040. const m = (0, _display_utils.getCurrentTransform)(this.ctx);
  7041. let scaleX, scaleY;
  7042. if (m[1] === 0 && m[2] === 0) {
  7043. const normX = Math.abs(m[0]);
  7044. const normY = Math.abs(m[3]);
  7045. if (lineWidth === 0) {
  7046. scaleX = 1 / normX;
  7047. scaleY = 1 / normY;
  7048. } else {
  7049. const scaledXLineWidth = normX * lineWidth;
  7050. const scaledYLineWidth = normY * lineWidth;
  7051. scaleX = scaledXLineWidth < 1 ? 1 / scaledXLineWidth : 1;
  7052. scaleY = scaledYLineWidth < 1 ? 1 / scaledYLineWidth : 1;
  7053. }
  7054. } else {
  7055. const absDet = Math.abs(m[0] * m[3] - m[2] * m[1]);
  7056. const normX = Math.hypot(m[0], m[1]);
  7057. const normY = Math.hypot(m[2], m[3]);
  7058. if (lineWidth === 0) {
  7059. scaleX = normY / absDet;
  7060. scaleY = normX / absDet;
  7061. } else {
  7062. const baseArea = lineWidth * absDet;
  7063. scaleX = normY > baseArea ? normY / baseArea : 1;
  7064. scaleY = normX > baseArea ? normX / baseArea : 1;
  7065. }
  7066. }
  7067. this._cachedScaleForStroking = [scaleX, scaleY];
  7068. }
  7069. return this._cachedScaleForStroking;
  7070. }
  7071. rescaleAndStroke(saveRestore) {
  7072. const {
  7073. ctx
  7074. } = this;
  7075. const {
  7076. lineWidth
  7077. } = this.current;
  7078. const [scaleX, scaleY] = this.getScaleForStroking();
  7079. ctx.lineWidth = lineWidth || 1;
  7080. if (scaleX === 1 && scaleY === 1) {
  7081. ctx.stroke();
  7082. return;
  7083. }
  7084. let savedMatrix, savedDashes, savedDashOffset;
  7085. if (saveRestore) {
  7086. savedMatrix = (0, _display_utils.getCurrentTransform)(ctx);
  7087. savedDashes = ctx.getLineDash().slice();
  7088. savedDashOffset = ctx.lineDashOffset;
  7089. }
  7090. ctx.scale(scaleX, scaleY);
  7091. const scale = Math.max(scaleX, scaleY);
  7092. ctx.setLineDash(ctx.getLineDash().map(x => x / scale));
  7093. ctx.lineDashOffset /= scale;
  7094. ctx.stroke();
  7095. if (saveRestore) {
  7096. ctx.setTransform(...savedMatrix);
  7097. ctx.setLineDash(savedDashes);
  7098. ctx.lineDashOffset = savedDashOffset;
  7099. }
  7100. }
  7101. isContentVisible() {
  7102. for (let i = this.markedContentStack.length - 1; i >= 0; i--) {
  7103. if (!this.markedContentStack[i].visible) {
  7104. return false;
  7105. }
  7106. }
  7107. return true;
  7108. }
  7109. }
  7110. exports.CanvasGraphics = CanvasGraphics;
  7111. for (const op in _util.OPS) {
  7112. if (CanvasGraphics.prototype[op] !== undefined) {
  7113. CanvasGraphics.prototype[_util.OPS[op]] = CanvasGraphics.prototype[op];
  7114. }
  7115. }
  7116. /***/ }),
  7117. /* 12 */
  7118. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  7119. Object.defineProperty(exports, "__esModule", ({
  7120. value: true
  7121. }));
  7122. exports.TilingPattern = exports.PathType = void 0;
  7123. exports.getShadingPattern = getShadingPattern;
  7124. var _util = __w_pdfjs_require__(1);
  7125. var _display_utils = __w_pdfjs_require__(6);
  7126. const PathType = {
  7127. FILL: "Fill",
  7128. STROKE: "Stroke",
  7129. SHADING: "Shading"
  7130. };
  7131. exports.PathType = PathType;
  7132. function applyBoundingBox(ctx, bbox) {
  7133. if (!bbox) {
  7134. return;
  7135. }
  7136. const width = bbox[2] - bbox[0];
  7137. const height = bbox[3] - bbox[1];
  7138. const region = new Path2D();
  7139. region.rect(bbox[0], bbox[1], width, height);
  7140. ctx.clip(region);
  7141. }
  7142. class BaseShadingPattern {
  7143. constructor() {
  7144. if (this.constructor === BaseShadingPattern) {
  7145. (0, _util.unreachable)("Cannot initialize BaseShadingPattern.");
  7146. }
  7147. }
  7148. getPattern() {
  7149. (0, _util.unreachable)("Abstract method `getPattern` called.");
  7150. }
  7151. }
  7152. class RadialAxialShadingPattern extends BaseShadingPattern {
  7153. constructor(IR) {
  7154. super();
  7155. this._type = IR[1];
  7156. this._bbox = IR[2];
  7157. this._colorStops = IR[3];
  7158. this._p0 = IR[4];
  7159. this._p1 = IR[5];
  7160. this._r0 = IR[6];
  7161. this._r1 = IR[7];
  7162. this.matrix = null;
  7163. }
  7164. _createGradient(ctx) {
  7165. let grad;
  7166. if (this._type === "axial") {
  7167. grad = ctx.createLinearGradient(this._p0[0], this._p0[1], this._p1[0], this._p1[1]);
  7168. } else if (this._type === "radial") {
  7169. grad = ctx.createRadialGradient(this._p0[0], this._p0[1], this._r0, this._p1[0], this._p1[1], this._r1);
  7170. }
  7171. for (const colorStop of this._colorStops) {
  7172. grad.addColorStop(colorStop[0], colorStop[1]);
  7173. }
  7174. return grad;
  7175. }
  7176. getPattern(ctx, owner, inverse, pathType) {
  7177. let pattern;
  7178. if (pathType === PathType.STROKE || pathType === PathType.FILL) {
  7179. const ownerBBox = owner.current.getClippedPathBoundingBox(pathType, (0, _display_utils.getCurrentTransform)(ctx)) || [0, 0, 0, 0];
  7180. const width = Math.ceil(ownerBBox[2] - ownerBBox[0]) || 1;
  7181. const height = Math.ceil(ownerBBox[3] - ownerBBox[1]) || 1;
  7182. const tmpCanvas = owner.cachedCanvases.getCanvas("pattern", width, height, true);
  7183. const tmpCtx = tmpCanvas.context;
  7184. tmpCtx.clearRect(0, 0, tmpCtx.canvas.width, tmpCtx.canvas.height);
  7185. tmpCtx.beginPath();
  7186. tmpCtx.rect(0, 0, tmpCtx.canvas.width, tmpCtx.canvas.height);
  7187. tmpCtx.translate(-ownerBBox[0], -ownerBBox[1]);
  7188. inverse = _util.Util.transform(inverse, [1, 0, 0, 1, ownerBBox[0], ownerBBox[1]]);
  7189. tmpCtx.transform(...owner.baseTransform);
  7190. if (this.matrix) {
  7191. tmpCtx.transform(...this.matrix);
  7192. }
  7193. applyBoundingBox(tmpCtx, this._bbox);
  7194. tmpCtx.fillStyle = this._createGradient(tmpCtx);
  7195. tmpCtx.fill();
  7196. pattern = ctx.createPattern(tmpCanvas.canvas, "no-repeat");
  7197. const domMatrix = new DOMMatrix(inverse);
  7198. pattern.setTransform(domMatrix);
  7199. } else {
  7200. applyBoundingBox(ctx, this._bbox);
  7201. pattern = this._createGradient(ctx);
  7202. }
  7203. return pattern;
  7204. }
  7205. }
  7206. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  7207. const coords = context.coords,
  7208. colors = context.colors;
  7209. const bytes = data.data,
  7210. rowSize = data.width * 4;
  7211. let tmp;
  7212. if (coords[p1 + 1] > coords[p2 + 1]) {
  7213. tmp = p1;
  7214. p1 = p2;
  7215. p2 = tmp;
  7216. tmp = c1;
  7217. c1 = c2;
  7218. c2 = tmp;
  7219. }
  7220. if (coords[p2 + 1] > coords[p3 + 1]) {
  7221. tmp = p2;
  7222. p2 = p3;
  7223. p3 = tmp;
  7224. tmp = c2;
  7225. c2 = c3;
  7226. c3 = tmp;
  7227. }
  7228. if (coords[p1 + 1] > coords[p2 + 1]) {
  7229. tmp = p1;
  7230. p1 = p2;
  7231. p2 = tmp;
  7232. tmp = c1;
  7233. c1 = c2;
  7234. c2 = tmp;
  7235. }
  7236. const x1 = (coords[p1] + context.offsetX) * context.scaleX;
  7237. const y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  7238. const x2 = (coords[p2] + context.offsetX) * context.scaleX;
  7239. const y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  7240. const x3 = (coords[p3] + context.offsetX) * context.scaleX;
  7241. const y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  7242. if (y1 >= y3) {
  7243. return;
  7244. }
  7245. const c1r = colors[c1],
  7246. c1g = colors[c1 + 1],
  7247. c1b = colors[c1 + 2];
  7248. const c2r = colors[c2],
  7249. c2g = colors[c2 + 1],
  7250. c2b = colors[c2 + 2];
  7251. const c3r = colors[c3],
  7252. c3g = colors[c3 + 1],
  7253. c3b = colors[c3 + 2];
  7254. const minY = Math.round(y1),
  7255. maxY = Math.round(y3);
  7256. let xa, car, cag, cab;
  7257. let xb, cbr, cbg, cbb;
  7258. for (let y = minY; y <= maxY; y++) {
  7259. if (y < y2) {
  7260. let k;
  7261. if (y < y1) {
  7262. k = 0;
  7263. } else {
  7264. k = (y1 - y) / (y1 - y2);
  7265. }
  7266. xa = x1 - (x1 - x2) * k;
  7267. car = c1r - (c1r - c2r) * k;
  7268. cag = c1g - (c1g - c2g) * k;
  7269. cab = c1b - (c1b - c2b) * k;
  7270. } else {
  7271. let k;
  7272. if (y > y3) {
  7273. k = 1;
  7274. } else if (y2 === y3) {
  7275. k = 0;
  7276. } else {
  7277. k = (y2 - y) / (y2 - y3);
  7278. }
  7279. xa = x2 - (x2 - x3) * k;
  7280. car = c2r - (c2r - c3r) * k;
  7281. cag = c2g - (c2g - c3g) * k;
  7282. cab = c2b - (c2b - c3b) * k;
  7283. }
  7284. let k;
  7285. if (y < y1) {
  7286. k = 0;
  7287. } else if (y > y3) {
  7288. k = 1;
  7289. } else {
  7290. k = (y1 - y) / (y1 - y3);
  7291. }
  7292. xb = x1 - (x1 - x3) * k;
  7293. cbr = c1r - (c1r - c3r) * k;
  7294. cbg = c1g - (c1g - c3g) * k;
  7295. cbb = c1b - (c1b - c3b) * k;
  7296. const x1_ = Math.round(Math.min(xa, xb));
  7297. const x2_ = Math.round(Math.max(xa, xb));
  7298. let j = rowSize * y + x1_ * 4;
  7299. for (let x = x1_; x <= x2_; x++) {
  7300. k = (xa - x) / (xa - xb);
  7301. if (k < 0) {
  7302. k = 0;
  7303. } else if (k > 1) {
  7304. k = 1;
  7305. }
  7306. bytes[j++] = car - (car - cbr) * k | 0;
  7307. bytes[j++] = cag - (cag - cbg) * k | 0;
  7308. bytes[j++] = cab - (cab - cbb) * k | 0;
  7309. bytes[j++] = 255;
  7310. }
  7311. }
  7312. }
  7313. function drawFigure(data, figure, context) {
  7314. const ps = figure.coords;
  7315. const cs = figure.colors;
  7316. let i, ii;
  7317. switch (figure.type) {
  7318. case "lattice":
  7319. const verticesPerRow = figure.verticesPerRow;
  7320. const rows = Math.floor(ps.length / verticesPerRow) - 1;
  7321. const cols = verticesPerRow - 1;
  7322. for (i = 0; i < rows; i++) {
  7323. let q = i * verticesPerRow;
  7324. for (let j = 0; j < cols; j++, q++) {
  7325. drawTriangle(data, context, ps[q], ps[q + 1], ps[q + verticesPerRow], cs[q], cs[q + 1], cs[q + verticesPerRow]);
  7326. drawTriangle(data, context, ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow], cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  7327. }
  7328. }
  7329. break;
  7330. case "triangles":
  7331. for (i = 0, ii = ps.length; i < ii; i += 3) {
  7332. drawTriangle(data, context, ps[i], ps[i + 1], ps[i + 2], cs[i], cs[i + 1], cs[i + 2]);
  7333. }
  7334. break;
  7335. default:
  7336. throw new Error("illegal figure");
  7337. }
  7338. }
  7339. class MeshShadingPattern extends BaseShadingPattern {
  7340. constructor(IR) {
  7341. super();
  7342. this._coords = IR[2];
  7343. this._colors = IR[3];
  7344. this._figures = IR[4];
  7345. this._bounds = IR[5];
  7346. this._bbox = IR[7];
  7347. this._background = IR[8];
  7348. this.matrix = null;
  7349. }
  7350. _createMeshCanvas(combinedScale, backgroundColor, cachedCanvases) {
  7351. const EXPECTED_SCALE = 1.1;
  7352. const MAX_PATTERN_SIZE = 3000;
  7353. const BORDER_SIZE = 2;
  7354. const offsetX = Math.floor(this._bounds[0]);
  7355. const offsetY = Math.floor(this._bounds[1]);
  7356. const boundsWidth = Math.ceil(this._bounds[2]) - offsetX;
  7357. const boundsHeight = Math.ceil(this._bounds[3]) - offsetY;
  7358. const width = Math.min(Math.ceil(Math.abs(boundsWidth * combinedScale[0] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  7359. const height = Math.min(Math.ceil(Math.abs(boundsHeight * combinedScale[1] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  7360. const scaleX = boundsWidth / width;
  7361. const scaleY = boundsHeight / height;
  7362. const context = {
  7363. coords: this._coords,
  7364. colors: this._colors,
  7365. offsetX: -offsetX,
  7366. offsetY: -offsetY,
  7367. scaleX: 1 / scaleX,
  7368. scaleY: 1 / scaleY
  7369. };
  7370. const paddedWidth = width + BORDER_SIZE * 2;
  7371. const paddedHeight = height + BORDER_SIZE * 2;
  7372. const tmpCanvas = cachedCanvases.getCanvas("mesh", paddedWidth, paddedHeight, false);
  7373. const tmpCtx = tmpCanvas.context;
  7374. const data = tmpCtx.createImageData(width, height);
  7375. if (backgroundColor) {
  7376. const bytes = data.data;
  7377. for (let i = 0, ii = bytes.length; i < ii; i += 4) {
  7378. bytes[i] = backgroundColor[0];
  7379. bytes[i + 1] = backgroundColor[1];
  7380. bytes[i + 2] = backgroundColor[2];
  7381. bytes[i + 3] = 255;
  7382. }
  7383. }
  7384. for (const figure of this._figures) {
  7385. drawFigure(data, figure, context);
  7386. }
  7387. tmpCtx.putImageData(data, BORDER_SIZE, BORDER_SIZE);
  7388. const canvas = tmpCanvas.canvas;
  7389. return {
  7390. canvas,
  7391. offsetX: offsetX - BORDER_SIZE * scaleX,
  7392. offsetY: offsetY - BORDER_SIZE * scaleY,
  7393. scaleX,
  7394. scaleY
  7395. };
  7396. }
  7397. getPattern(ctx, owner, inverse, pathType) {
  7398. applyBoundingBox(ctx, this._bbox);
  7399. let scale;
  7400. if (pathType === PathType.SHADING) {
  7401. scale = _util.Util.singularValueDecompose2dScale((0, _display_utils.getCurrentTransform)(ctx));
  7402. } else {
  7403. scale = _util.Util.singularValueDecompose2dScale(owner.baseTransform);
  7404. if (this.matrix) {
  7405. const matrixScale = _util.Util.singularValueDecompose2dScale(this.matrix);
  7406. scale = [scale[0] * matrixScale[0], scale[1] * matrixScale[1]];
  7407. }
  7408. }
  7409. const temporaryPatternCanvas = this._createMeshCanvas(scale, pathType === PathType.SHADING ? null : this._background, owner.cachedCanvases);
  7410. if (pathType !== PathType.SHADING) {
  7411. ctx.setTransform(...owner.baseTransform);
  7412. if (this.matrix) {
  7413. ctx.transform(...this.matrix);
  7414. }
  7415. }
  7416. ctx.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY);
  7417. ctx.scale(temporaryPatternCanvas.scaleX, temporaryPatternCanvas.scaleY);
  7418. return ctx.createPattern(temporaryPatternCanvas.canvas, "no-repeat");
  7419. }
  7420. }
  7421. class DummyShadingPattern extends BaseShadingPattern {
  7422. getPattern() {
  7423. return "hotpink";
  7424. }
  7425. }
  7426. function getShadingPattern(IR) {
  7427. switch (IR[0]) {
  7428. case "RadialAxial":
  7429. return new RadialAxialShadingPattern(IR);
  7430. case "Mesh":
  7431. return new MeshShadingPattern(IR);
  7432. case "Dummy":
  7433. return new DummyShadingPattern();
  7434. }
  7435. throw new Error(`Unknown IR type: ${IR[0]}`);
  7436. }
  7437. const PaintType = {
  7438. COLORED: 1,
  7439. UNCOLORED: 2
  7440. };
  7441. class TilingPattern {
  7442. static get MAX_PATTERN_SIZE() {
  7443. return (0, _util.shadow)(this, "MAX_PATTERN_SIZE", 3000);
  7444. }
  7445. constructor(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
  7446. this.operatorList = IR[2];
  7447. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  7448. this.bbox = IR[4];
  7449. this.xstep = IR[5];
  7450. this.ystep = IR[6];
  7451. this.paintType = IR[7];
  7452. this.tilingType = IR[8];
  7453. this.color = color;
  7454. this.ctx = ctx;
  7455. this.canvasGraphicsFactory = canvasGraphicsFactory;
  7456. this.baseTransform = baseTransform;
  7457. }
  7458. createPatternCanvas(owner) {
  7459. const operatorList = this.operatorList;
  7460. const bbox = this.bbox;
  7461. const xstep = this.xstep;
  7462. const ystep = this.ystep;
  7463. const paintType = this.paintType;
  7464. const tilingType = this.tilingType;
  7465. const color = this.color;
  7466. const canvasGraphicsFactory = this.canvasGraphicsFactory;
  7467. (0, _util.info)("TilingType: " + tilingType);
  7468. const x0 = bbox[0],
  7469. y0 = bbox[1],
  7470. x1 = bbox[2],
  7471. y1 = bbox[3];
  7472. const matrixScale = _util.Util.singularValueDecompose2dScale(this.matrix);
  7473. const curMatrixScale = _util.Util.singularValueDecompose2dScale(this.baseTransform);
  7474. const combinedScale = [matrixScale[0] * curMatrixScale[0], matrixScale[1] * curMatrixScale[1]];
  7475. const dimx = this.getSizeAndScale(xstep, this.ctx.canvas.width, combinedScale[0]);
  7476. const dimy = this.getSizeAndScale(ystep, this.ctx.canvas.height, combinedScale[1]);
  7477. const tmpCanvas = owner.cachedCanvases.getCanvas("pattern", dimx.size, dimy.size, true);
  7478. const tmpCtx = tmpCanvas.context;
  7479. const graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
  7480. graphics.groupLevel = owner.groupLevel;
  7481. this.setFillAndStrokeStyleToContext(graphics, paintType, color);
  7482. let adjustedX0 = x0;
  7483. let adjustedY0 = y0;
  7484. let adjustedX1 = x1;
  7485. let adjustedY1 = y1;
  7486. if (x0 < 0) {
  7487. adjustedX0 = 0;
  7488. adjustedX1 += Math.abs(x0);
  7489. }
  7490. if (y0 < 0) {
  7491. adjustedY0 = 0;
  7492. adjustedY1 += Math.abs(y0);
  7493. }
  7494. tmpCtx.translate(-(dimx.scale * adjustedX0), -(dimy.scale * adjustedY0));
  7495. graphics.transform(dimx.scale, 0, 0, dimy.scale, 0, 0);
  7496. tmpCtx.save();
  7497. this.clipBbox(graphics, adjustedX0, adjustedY0, adjustedX1, adjustedY1);
  7498. graphics.baseTransform = (0, _display_utils.getCurrentTransform)(graphics.ctx);
  7499. graphics.executeOperatorList(operatorList);
  7500. graphics.endDrawing();
  7501. return {
  7502. canvas: tmpCanvas.canvas,
  7503. scaleX: dimx.scale,
  7504. scaleY: dimy.scale,
  7505. offsetX: adjustedX0,
  7506. offsetY: adjustedY0
  7507. };
  7508. }
  7509. getSizeAndScale(step, realOutputSize, scale) {
  7510. step = Math.abs(step);
  7511. const maxSize = Math.max(TilingPattern.MAX_PATTERN_SIZE, realOutputSize);
  7512. let size = Math.ceil(step * scale);
  7513. if (size >= maxSize) {
  7514. size = maxSize;
  7515. } else {
  7516. scale = size / step;
  7517. }
  7518. return {
  7519. scale,
  7520. size
  7521. };
  7522. }
  7523. clipBbox(graphics, x0, y0, x1, y1) {
  7524. const bboxWidth = x1 - x0;
  7525. const bboxHeight = y1 - y0;
  7526. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  7527. graphics.current.updateRectMinMax((0, _display_utils.getCurrentTransform)(graphics.ctx), [x0, y0, x1, y1]);
  7528. graphics.clip();
  7529. graphics.endPath();
  7530. }
  7531. setFillAndStrokeStyleToContext(graphics, paintType, color) {
  7532. const context = graphics.ctx,
  7533. current = graphics.current;
  7534. switch (paintType) {
  7535. case PaintType.COLORED:
  7536. const ctx = this.ctx;
  7537. context.fillStyle = ctx.fillStyle;
  7538. context.strokeStyle = ctx.strokeStyle;
  7539. current.fillColor = ctx.fillStyle;
  7540. current.strokeColor = ctx.strokeStyle;
  7541. break;
  7542. case PaintType.UNCOLORED:
  7543. const cssColor = _util.Util.makeHexColor(color[0], color[1], color[2]);
  7544. context.fillStyle = cssColor;
  7545. context.strokeStyle = cssColor;
  7546. current.fillColor = cssColor;
  7547. current.strokeColor = cssColor;
  7548. break;
  7549. default:
  7550. throw new _util.FormatError(`Unsupported paint type: ${paintType}`);
  7551. }
  7552. }
  7553. getPattern(ctx, owner, inverse, pathType) {
  7554. let matrix = inverse;
  7555. if (pathType !== PathType.SHADING) {
  7556. matrix = _util.Util.transform(matrix, owner.baseTransform);
  7557. if (this.matrix) {
  7558. matrix = _util.Util.transform(matrix, this.matrix);
  7559. }
  7560. }
  7561. const temporaryPatternCanvas = this.createPatternCanvas(owner);
  7562. let domMatrix = new DOMMatrix(matrix);
  7563. domMatrix = domMatrix.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY);
  7564. domMatrix = domMatrix.scale(1 / temporaryPatternCanvas.scaleX, 1 / temporaryPatternCanvas.scaleY);
  7565. const pattern = ctx.createPattern(temporaryPatternCanvas.canvas, "repeat");
  7566. pattern.setTransform(domMatrix);
  7567. return pattern;
  7568. }
  7569. }
  7570. exports.TilingPattern = TilingPattern;
  7571. /***/ }),
  7572. /* 13 */
  7573. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  7574. Object.defineProperty(exports, "__esModule", ({
  7575. value: true
  7576. }));
  7577. exports.applyMaskImageData = applyMaskImageData;
  7578. var _util = __w_pdfjs_require__(1);
  7579. function applyMaskImageData({
  7580. src,
  7581. srcPos = 0,
  7582. dest,
  7583. destPos = 0,
  7584. width,
  7585. height,
  7586. inverseDecode = false
  7587. }) {
  7588. const opaque = _util.FeatureTest.isLittleEndian ? 0xff000000 : 0x000000ff;
  7589. const [zeroMapping, oneMapping] = !inverseDecode ? [opaque, 0] : [0, opaque];
  7590. const widthInSource = width >> 3;
  7591. const widthRemainder = width & 7;
  7592. const srcLength = src.length;
  7593. dest = new Uint32Array(dest.buffer);
  7594. for (let i = 0; i < height; i++) {
  7595. for (const max = srcPos + widthInSource; srcPos < max; srcPos++) {
  7596. const elem = srcPos < srcLength ? src[srcPos] : 255;
  7597. dest[destPos++] = elem & 0b10000000 ? oneMapping : zeroMapping;
  7598. dest[destPos++] = elem & 0b1000000 ? oneMapping : zeroMapping;
  7599. dest[destPos++] = elem & 0b100000 ? oneMapping : zeroMapping;
  7600. dest[destPos++] = elem & 0b10000 ? oneMapping : zeroMapping;
  7601. dest[destPos++] = elem & 0b1000 ? oneMapping : zeroMapping;
  7602. dest[destPos++] = elem & 0b100 ? oneMapping : zeroMapping;
  7603. dest[destPos++] = elem & 0b10 ? oneMapping : zeroMapping;
  7604. dest[destPos++] = elem & 0b1 ? oneMapping : zeroMapping;
  7605. }
  7606. if (widthRemainder === 0) {
  7607. continue;
  7608. }
  7609. const elem = srcPos < srcLength ? src[srcPos++] : 255;
  7610. for (let j = 0; j < widthRemainder; j++) {
  7611. dest[destPos++] = elem & 1 << 7 - j ? oneMapping : zeroMapping;
  7612. }
  7613. }
  7614. return {
  7615. srcPos,
  7616. destPos
  7617. };
  7618. }
  7619. /***/ }),
  7620. /* 14 */
  7621. /***/ ((__unused_webpack_module, exports) => {
  7622. Object.defineProperty(exports, "__esModule", ({
  7623. value: true
  7624. }));
  7625. exports.GlobalWorkerOptions = void 0;
  7626. const GlobalWorkerOptions = Object.create(null);
  7627. exports.GlobalWorkerOptions = GlobalWorkerOptions;
  7628. GlobalWorkerOptions.workerPort = null;
  7629. GlobalWorkerOptions.workerSrc = "";
  7630. /***/ }),
  7631. /* 15 */
  7632. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  7633. Object.defineProperty(exports, "__esModule", ({
  7634. value: true
  7635. }));
  7636. exports.MessageHandler = void 0;
  7637. var _util = __w_pdfjs_require__(1);
  7638. const CallbackKind = {
  7639. UNKNOWN: 0,
  7640. DATA: 1,
  7641. ERROR: 2
  7642. };
  7643. const StreamKind = {
  7644. UNKNOWN: 0,
  7645. CANCEL: 1,
  7646. CANCEL_COMPLETE: 2,
  7647. CLOSE: 3,
  7648. ENQUEUE: 4,
  7649. ERROR: 5,
  7650. PULL: 6,
  7651. PULL_COMPLETE: 7,
  7652. START_COMPLETE: 8
  7653. };
  7654. function wrapReason(reason) {
  7655. if (!(reason instanceof Error || typeof reason === "object" && reason !== null)) {
  7656. (0, _util.unreachable)('wrapReason: Expected "reason" to be a (possibly cloned) Error.');
  7657. }
  7658. switch (reason.name) {
  7659. case "AbortException":
  7660. return new _util.AbortException(reason.message);
  7661. case "MissingPDFException":
  7662. return new _util.MissingPDFException(reason.message);
  7663. case "PasswordException":
  7664. return new _util.PasswordException(reason.message, reason.code);
  7665. case "UnexpectedResponseException":
  7666. return new _util.UnexpectedResponseException(reason.message, reason.status);
  7667. case "UnknownErrorException":
  7668. return new _util.UnknownErrorException(reason.message, reason.details);
  7669. default:
  7670. return new _util.UnknownErrorException(reason.message, reason.toString());
  7671. }
  7672. }
  7673. class MessageHandler {
  7674. constructor(sourceName, targetName, comObj) {
  7675. this.sourceName = sourceName;
  7676. this.targetName = targetName;
  7677. this.comObj = comObj;
  7678. this.callbackId = 1;
  7679. this.streamId = 1;
  7680. this.streamSinks = Object.create(null);
  7681. this.streamControllers = Object.create(null);
  7682. this.callbackCapabilities = Object.create(null);
  7683. this.actionHandler = Object.create(null);
  7684. this._onComObjOnMessage = event => {
  7685. const data = event.data;
  7686. if (data.targetName !== this.sourceName) {
  7687. return;
  7688. }
  7689. if (data.stream) {
  7690. this._processStreamMessage(data);
  7691. return;
  7692. }
  7693. if (data.callback) {
  7694. const callbackId = data.callbackId;
  7695. const capability = this.callbackCapabilities[callbackId];
  7696. if (!capability) {
  7697. throw new Error(`Cannot resolve callback ${callbackId}`);
  7698. }
  7699. delete this.callbackCapabilities[callbackId];
  7700. if (data.callback === CallbackKind.DATA) {
  7701. capability.resolve(data.data);
  7702. } else if (data.callback === CallbackKind.ERROR) {
  7703. capability.reject(wrapReason(data.reason));
  7704. } else {
  7705. throw new Error("Unexpected callback case");
  7706. }
  7707. return;
  7708. }
  7709. const action = this.actionHandler[data.action];
  7710. if (!action) {
  7711. throw new Error(`Unknown action from worker: ${data.action}`);
  7712. }
  7713. if (data.callbackId) {
  7714. const cbSourceName = this.sourceName;
  7715. const cbTargetName = data.sourceName;
  7716. new Promise(function (resolve) {
  7717. resolve(action(data.data));
  7718. }).then(function (result) {
  7719. comObj.postMessage({
  7720. sourceName: cbSourceName,
  7721. targetName: cbTargetName,
  7722. callback: CallbackKind.DATA,
  7723. callbackId: data.callbackId,
  7724. data: result
  7725. });
  7726. }, function (reason) {
  7727. comObj.postMessage({
  7728. sourceName: cbSourceName,
  7729. targetName: cbTargetName,
  7730. callback: CallbackKind.ERROR,
  7731. callbackId: data.callbackId,
  7732. reason: wrapReason(reason)
  7733. });
  7734. });
  7735. return;
  7736. }
  7737. if (data.streamId) {
  7738. this._createStreamSink(data);
  7739. return;
  7740. }
  7741. action(data.data);
  7742. };
  7743. comObj.addEventListener("message", this._onComObjOnMessage);
  7744. }
  7745. on(actionName, handler) {
  7746. const ah = this.actionHandler;
  7747. if (ah[actionName]) {
  7748. throw new Error(`There is already an actionName called "${actionName}"`);
  7749. }
  7750. ah[actionName] = handler;
  7751. }
  7752. send(actionName, data, transfers) {
  7753. this.comObj.postMessage({
  7754. sourceName: this.sourceName,
  7755. targetName: this.targetName,
  7756. action: actionName,
  7757. data
  7758. }, transfers);
  7759. }
  7760. sendWithPromise(actionName, data, transfers) {
  7761. const callbackId = this.callbackId++;
  7762. const capability = (0, _util.createPromiseCapability)();
  7763. this.callbackCapabilities[callbackId] = capability;
  7764. try {
  7765. this.comObj.postMessage({
  7766. sourceName: this.sourceName,
  7767. targetName: this.targetName,
  7768. action: actionName,
  7769. callbackId,
  7770. data
  7771. }, transfers);
  7772. } catch (ex) {
  7773. capability.reject(ex);
  7774. }
  7775. return capability.promise;
  7776. }
  7777. sendWithStream(actionName, data, queueingStrategy, transfers) {
  7778. const streamId = this.streamId++,
  7779. sourceName = this.sourceName,
  7780. targetName = this.targetName,
  7781. comObj = this.comObj;
  7782. return new ReadableStream({
  7783. start: controller => {
  7784. const startCapability = (0, _util.createPromiseCapability)();
  7785. this.streamControllers[streamId] = {
  7786. controller,
  7787. startCall: startCapability,
  7788. pullCall: null,
  7789. cancelCall: null,
  7790. isClosed: false
  7791. };
  7792. comObj.postMessage({
  7793. sourceName,
  7794. targetName,
  7795. action: actionName,
  7796. streamId,
  7797. data,
  7798. desiredSize: controller.desiredSize
  7799. }, transfers);
  7800. return startCapability.promise;
  7801. },
  7802. pull: controller => {
  7803. const pullCapability = (0, _util.createPromiseCapability)();
  7804. this.streamControllers[streamId].pullCall = pullCapability;
  7805. comObj.postMessage({
  7806. sourceName,
  7807. targetName,
  7808. stream: StreamKind.PULL,
  7809. streamId,
  7810. desiredSize: controller.desiredSize
  7811. });
  7812. return pullCapability.promise;
  7813. },
  7814. cancel: reason => {
  7815. (0, _util.assert)(reason instanceof Error, "cancel must have a valid reason");
  7816. const cancelCapability = (0, _util.createPromiseCapability)();
  7817. this.streamControllers[streamId].cancelCall = cancelCapability;
  7818. this.streamControllers[streamId].isClosed = true;
  7819. comObj.postMessage({
  7820. sourceName,
  7821. targetName,
  7822. stream: StreamKind.CANCEL,
  7823. streamId,
  7824. reason: wrapReason(reason)
  7825. });
  7826. return cancelCapability.promise;
  7827. }
  7828. }, queueingStrategy);
  7829. }
  7830. _createStreamSink(data) {
  7831. const streamId = data.streamId,
  7832. sourceName = this.sourceName,
  7833. targetName = data.sourceName,
  7834. comObj = this.comObj;
  7835. const self = this,
  7836. action = this.actionHandler[data.action];
  7837. const streamSink = {
  7838. enqueue(chunk, size = 1, transfers) {
  7839. if (this.isCancelled) {
  7840. return;
  7841. }
  7842. const lastDesiredSize = this.desiredSize;
  7843. this.desiredSize -= size;
  7844. if (lastDesiredSize > 0 && this.desiredSize <= 0) {
  7845. this.sinkCapability = (0, _util.createPromiseCapability)();
  7846. this.ready = this.sinkCapability.promise;
  7847. }
  7848. comObj.postMessage({
  7849. sourceName,
  7850. targetName,
  7851. stream: StreamKind.ENQUEUE,
  7852. streamId,
  7853. chunk
  7854. }, transfers);
  7855. },
  7856. close() {
  7857. if (this.isCancelled) {
  7858. return;
  7859. }
  7860. this.isCancelled = true;
  7861. comObj.postMessage({
  7862. sourceName,
  7863. targetName,
  7864. stream: StreamKind.CLOSE,
  7865. streamId
  7866. });
  7867. delete self.streamSinks[streamId];
  7868. },
  7869. error(reason) {
  7870. (0, _util.assert)(reason instanceof Error, "error must have a valid reason");
  7871. if (this.isCancelled) {
  7872. return;
  7873. }
  7874. this.isCancelled = true;
  7875. comObj.postMessage({
  7876. sourceName,
  7877. targetName,
  7878. stream: StreamKind.ERROR,
  7879. streamId,
  7880. reason: wrapReason(reason)
  7881. });
  7882. },
  7883. sinkCapability: (0, _util.createPromiseCapability)(),
  7884. onPull: null,
  7885. onCancel: null,
  7886. isCancelled: false,
  7887. desiredSize: data.desiredSize,
  7888. ready: null
  7889. };
  7890. streamSink.sinkCapability.resolve();
  7891. streamSink.ready = streamSink.sinkCapability.promise;
  7892. this.streamSinks[streamId] = streamSink;
  7893. new Promise(function (resolve) {
  7894. resolve(action(data.data, streamSink));
  7895. }).then(function () {
  7896. comObj.postMessage({
  7897. sourceName,
  7898. targetName,
  7899. stream: StreamKind.START_COMPLETE,
  7900. streamId,
  7901. success: true
  7902. });
  7903. }, function (reason) {
  7904. comObj.postMessage({
  7905. sourceName,
  7906. targetName,
  7907. stream: StreamKind.START_COMPLETE,
  7908. streamId,
  7909. reason: wrapReason(reason)
  7910. });
  7911. });
  7912. }
  7913. _processStreamMessage(data) {
  7914. const streamId = data.streamId,
  7915. sourceName = this.sourceName,
  7916. targetName = data.sourceName,
  7917. comObj = this.comObj;
  7918. const streamController = this.streamControllers[streamId],
  7919. streamSink = this.streamSinks[streamId];
  7920. switch (data.stream) {
  7921. case StreamKind.START_COMPLETE:
  7922. if (data.success) {
  7923. streamController.startCall.resolve();
  7924. } else {
  7925. streamController.startCall.reject(wrapReason(data.reason));
  7926. }
  7927. break;
  7928. case StreamKind.PULL_COMPLETE:
  7929. if (data.success) {
  7930. streamController.pullCall.resolve();
  7931. } else {
  7932. streamController.pullCall.reject(wrapReason(data.reason));
  7933. }
  7934. break;
  7935. case StreamKind.PULL:
  7936. if (!streamSink) {
  7937. comObj.postMessage({
  7938. sourceName,
  7939. targetName,
  7940. stream: StreamKind.PULL_COMPLETE,
  7941. streamId,
  7942. success: true
  7943. });
  7944. break;
  7945. }
  7946. if (streamSink.desiredSize <= 0 && data.desiredSize > 0) {
  7947. streamSink.sinkCapability.resolve();
  7948. }
  7949. streamSink.desiredSize = data.desiredSize;
  7950. new Promise(function (resolve) {
  7951. resolve(streamSink.onPull && streamSink.onPull());
  7952. }).then(function () {
  7953. comObj.postMessage({
  7954. sourceName,
  7955. targetName,
  7956. stream: StreamKind.PULL_COMPLETE,
  7957. streamId,
  7958. success: true
  7959. });
  7960. }, function (reason) {
  7961. comObj.postMessage({
  7962. sourceName,
  7963. targetName,
  7964. stream: StreamKind.PULL_COMPLETE,
  7965. streamId,
  7966. reason: wrapReason(reason)
  7967. });
  7968. });
  7969. break;
  7970. case StreamKind.ENQUEUE:
  7971. (0, _util.assert)(streamController, "enqueue should have stream controller");
  7972. if (streamController.isClosed) {
  7973. break;
  7974. }
  7975. streamController.controller.enqueue(data.chunk);
  7976. break;
  7977. case StreamKind.CLOSE:
  7978. (0, _util.assert)(streamController, "close should have stream controller");
  7979. if (streamController.isClosed) {
  7980. break;
  7981. }
  7982. streamController.isClosed = true;
  7983. streamController.controller.close();
  7984. this._deleteStreamController(streamController, streamId);
  7985. break;
  7986. case StreamKind.ERROR:
  7987. (0, _util.assert)(streamController, "error should have stream controller");
  7988. streamController.controller.error(wrapReason(data.reason));
  7989. this._deleteStreamController(streamController, streamId);
  7990. break;
  7991. case StreamKind.CANCEL_COMPLETE:
  7992. if (data.success) {
  7993. streamController.cancelCall.resolve();
  7994. } else {
  7995. streamController.cancelCall.reject(wrapReason(data.reason));
  7996. }
  7997. this._deleteStreamController(streamController, streamId);
  7998. break;
  7999. case StreamKind.CANCEL:
  8000. if (!streamSink) {
  8001. break;
  8002. }
  8003. new Promise(function (resolve) {
  8004. resolve(streamSink.onCancel && streamSink.onCancel(wrapReason(data.reason)));
  8005. }).then(function () {
  8006. comObj.postMessage({
  8007. sourceName,
  8008. targetName,
  8009. stream: StreamKind.CANCEL_COMPLETE,
  8010. streamId,
  8011. success: true
  8012. });
  8013. }, function (reason) {
  8014. comObj.postMessage({
  8015. sourceName,
  8016. targetName,
  8017. stream: StreamKind.CANCEL_COMPLETE,
  8018. streamId,
  8019. reason: wrapReason(reason)
  8020. });
  8021. });
  8022. streamSink.sinkCapability.reject(wrapReason(data.reason));
  8023. streamSink.isCancelled = true;
  8024. delete this.streamSinks[streamId];
  8025. break;
  8026. default:
  8027. throw new Error("Unexpected stream case");
  8028. }
  8029. }
  8030. async _deleteStreamController(streamController, streamId) {
  8031. await Promise.allSettled([streamController.startCall && streamController.startCall.promise, streamController.pullCall && streamController.pullCall.promise, streamController.cancelCall && streamController.cancelCall.promise]);
  8032. delete this.streamControllers[streamId];
  8033. }
  8034. destroy() {
  8035. this.comObj.removeEventListener("message", this._onComObjOnMessage);
  8036. }
  8037. }
  8038. exports.MessageHandler = MessageHandler;
  8039. /***/ }),
  8040. /* 16 */
  8041. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  8042. Object.defineProperty(exports, "__esModule", ({
  8043. value: true
  8044. }));
  8045. exports.Metadata = void 0;
  8046. var _util = __w_pdfjs_require__(1);
  8047. class Metadata {
  8048. #metadataMap;
  8049. #data;
  8050. constructor({
  8051. parsedData,
  8052. rawData
  8053. }) {
  8054. this.#metadataMap = parsedData;
  8055. this.#data = rawData;
  8056. }
  8057. getRaw() {
  8058. return this.#data;
  8059. }
  8060. get(name) {
  8061. return this.#metadataMap.get(name) ?? null;
  8062. }
  8063. getAll() {
  8064. return (0, _util.objectFromMap)(this.#metadataMap);
  8065. }
  8066. has(name) {
  8067. return this.#metadataMap.has(name);
  8068. }
  8069. }
  8070. exports.Metadata = Metadata;
  8071. /***/ }),
  8072. /* 17 */
  8073. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  8074. Object.defineProperty(exports, "__esModule", ({
  8075. value: true
  8076. }));
  8077. exports.OptionalContentConfig = void 0;
  8078. var _util = __w_pdfjs_require__(1);
  8079. var _murmurhash = __w_pdfjs_require__(8);
  8080. const INTERNAL = Symbol("INTERNAL");
  8081. class OptionalContentGroup {
  8082. #visible = true;
  8083. constructor(name, intent) {
  8084. this.name = name;
  8085. this.intent = intent;
  8086. }
  8087. get visible() {
  8088. return this.#visible;
  8089. }
  8090. _setVisible(internal, visible) {
  8091. if (internal !== INTERNAL) {
  8092. (0, _util.unreachable)("Internal method `_setVisible` called.");
  8093. }
  8094. this.#visible = visible;
  8095. }
  8096. }
  8097. class OptionalContentConfig {
  8098. #cachedGetHash = null;
  8099. #groups = new Map();
  8100. #initialHash = null;
  8101. #order = null;
  8102. constructor(data) {
  8103. this.name = null;
  8104. this.creator = null;
  8105. if (data === null) {
  8106. return;
  8107. }
  8108. this.name = data.name;
  8109. this.creator = data.creator;
  8110. this.#order = data.order;
  8111. for (const group of data.groups) {
  8112. this.#groups.set(group.id, new OptionalContentGroup(group.name, group.intent));
  8113. }
  8114. if (data.baseState === "OFF") {
  8115. for (const group of this.#groups.values()) {
  8116. group._setVisible(INTERNAL, false);
  8117. }
  8118. }
  8119. for (const on of data.on) {
  8120. this.#groups.get(on)._setVisible(INTERNAL, true);
  8121. }
  8122. for (const off of data.off) {
  8123. this.#groups.get(off)._setVisible(INTERNAL, false);
  8124. }
  8125. this.#initialHash = this.getHash();
  8126. }
  8127. #evaluateVisibilityExpression(array) {
  8128. const length = array.length;
  8129. if (length < 2) {
  8130. return true;
  8131. }
  8132. const operator = array[0];
  8133. for (let i = 1; i < length; i++) {
  8134. const element = array[i];
  8135. let state;
  8136. if (Array.isArray(element)) {
  8137. state = this.#evaluateVisibilityExpression(element);
  8138. } else if (this.#groups.has(element)) {
  8139. state = this.#groups.get(element).visible;
  8140. } else {
  8141. (0, _util.warn)(`Optional content group not found: ${element}`);
  8142. return true;
  8143. }
  8144. switch (operator) {
  8145. case "And":
  8146. if (!state) {
  8147. return false;
  8148. }
  8149. break;
  8150. case "Or":
  8151. if (state) {
  8152. return true;
  8153. }
  8154. break;
  8155. case "Not":
  8156. return !state;
  8157. default:
  8158. return true;
  8159. }
  8160. }
  8161. return operator === "And";
  8162. }
  8163. isVisible(group) {
  8164. if (this.#groups.size === 0) {
  8165. return true;
  8166. }
  8167. if (!group) {
  8168. (0, _util.warn)("Optional content group not defined.");
  8169. return true;
  8170. }
  8171. if (group.type === "OCG") {
  8172. if (!this.#groups.has(group.id)) {
  8173. (0, _util.warn)(`Optional content group not found: ${group.id}`);
  8174. return true;
  8175. }
  8176. return this.#groups.get(group.id).visible;
  8177. } else if (group.type === "OCMD") {
  8178. if (group.expression) {
  8179. return this.#evaluateVisibilityExpression(group.expression);
  8180. }
  8181. if (!group.policy || group.policy === "AnyOn") {
  8182. for (const id of group.ids) {
  8183. if (!this.#groups.has(id)) {
  8184. (0, _util.warn)(`Optional content group not found: ${id}`);
  8185. return true;
  8186. }
  8187. if (this.#groups.get(id).visible) {
  8188. return true;
  8189. }
  8190. }
  8191. return false;
  8192. } else if (group.policy === "AllOn") {
  8193. for (const id of group.ids) {
  8194. if (!this.#groups.has(id)) {
  8195. (0, _util.warn)(`Optional content group not found: ${id}`);
  8196. return true;
  8197. }
  8198. if (!this.#groups.get(id).visible) {
  8199. return false;
  8200. }
  8201. }
  8202. return true;
  8203. } else if (group.policy === "AnyOff") {
  8204. for (const id of group.ids) {
  8205. if (!this.#groups.has(id)) {
  8206. (0, _util.warn)(`Optional content group not found: ${id}`);
  8207. return true;
  8208. }
  8209. if (!this.#groups.get(id).visible) {
  8210. return true;
  8211. }
  8212. }
  8213. return false;
  8214. } else if (group.policy === "AllOff") {
  8215. for (const id of group.ids) {
  8216. if (!this.#groups.has(id)) {
  8217. (0, _util.warn)(`Optional content group not found: ${id}`);
  8218. return true;
  8219. }
  8220. if (this.#groups.get(id).visible) {
  8221. return false;
  8222. }
  8223. }
  8224. return true;
  8225. }
  8226. (0, _util.warn)(`Unknown optional content policy ${group.policy}.`);
  8227. return true;
  8228. }
  8229. (0, _util.warn)(`Unknown group type ${group.type}.`);
  8230. return true;
  8231. }
  8232. setVisibility(id, visible = true) {
  8233. if (!this.#groups.has(id)) {
  8234. (0, _util.warn)(`Optional content group not found: ${id}`);
  8235. return;
  8236. }
  8237. this.#groups.get(id)._setVisible(INTERNAL, !!visible);
  8238. this.#cachedGetHash = null;
  8239. }
  8240. get hasInitialVisibility() {
  8241. return this.getHash() === this.#initialHash;
  8242. }
  8243. getOrder() {
  8244. if (!this.#groups.size) {
  8245. return null;
  8246. }
  8247. if (this.#order) {
  8248. return this.#order.slice();
  8249. }
  8250. return [...this.#groups.keys()];
  8251. }
  8252. getGroups() {
  8253. return this.#groups.size > 0 ? (0, _util.objectFromMap)(this.#groups) : null;
  8254. }
  8255. getGroup(id) {
  8256. return this.#groups.get(id) || null;
  8257. }
  8258. getHash() {
  8259. if (this.#cachedGetHash !== null) {
  8260. return this.#cachedGetHash;
  8261. }
  8262. const hash = new _murmurhash.MurmurHash3_64();
  8263. for (const [id, group] of this.#groups) {
  8264. hash.update(`${id}:${group.visible}`);
  8265. }
  8266. return this.#cachedGetHash = hash.hexdigest();
  8267. }
  8268. }
  8269. exports.OptionalContentConfig = OptionalContentConfig;
  8270. /***/ }),
  8271. /* 18 */
  8272. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  8273. Object.defineProperty(exports, "__esModule", ({
  8274. value: true
  8275. }));
  8276. exports.PDFDataTransportStream = void 0;
  8277. var _util = __w_pdfjs_require__(1);
  8278. var _display_utils = __w_pdfjs_require__(6);
  8279. class PDFDataTransportStream {
  8280. constructor({
  8281. length,
  8282. initialData,
  8283. progressiveDone = false,
  8284. contentDispositionFilename = null,
  8285. disableRange = false,
  8286. disableStream = false
  8287. }, pdfDataRangeTransport) {
  8288. (0, _util.assert)(pdfDataRangeTransport, 'PDFDataTransportStream - missing required "pdfDataRangeTransport" argument.');
  8289. this._queuedChunks = [];
  8290. this._progressiveDone = progressiveDone;
  8291. this._contentDispositionFilename = contentDispositionFilename;
  8292. if (initialData?.length > 0) {
  8293. const buffer = initialData instanceof Uint8Array && initialData.byteLength === initialData.buffer.byteLength ? initialData.buffer : new Uint8Array(initialData).buffer;
  8294. this._queuedChunks.push(buffer);
  8295. }
  8296. this._pdfDataRangeTransport = pdfDataRangeTransport;
  8297. this._isStreamingSupported = !disableStream;
  8298. this._isRangeSupported = !disableRange;
  8299. this._contentLength = length;
  8300. this._fullRequestReader = null;
  8301. this._rangeReaders = [];
  8302. this._pdfDataRangeTransport.addRangeListener((begin, chunk) => {
  8303. this._onReceiveData({
  8304. begin,
  8305. chunk
  8306. });
  8307. });
  8308. this._pdfDataRangeTransport.addProgressListener((loaded, total) => {
  8309. this._onProgress({
  8310. loaded,
  8311. total
  8312. });
  8313. });
  8314. this._pdfDataRangeTransport.addProgressiveReadListener(chunk => {
  8315. this._onReceiveData({
  8316. chunk
  8317. });
  8318. });
  8319. this._pdfDataRangeTransport.addProgressiveDoneListener(() => {
  8320. this._onProgressiveDone();
  8321. });
  8322. this._pdfDataRangeTransport.transportReady();
  8323. }
  8324. _onReceiveData({
  8325. begin,
  8326. chunk
  8327. }) {
  8328. const buffer = chunk instanceof Uint8Array && chunk.byteLength === chunk.buffer.byteLength ? chunk.buffer : new Uint8Array(chunk).buffer;
  8329. if (begin === undefined) {
  8330. if (this._fullRequestReader) {
  8331. this._fullRequestReader._enqueue(buffer);
  8332. } else {
  8333. this._queuedChunks.push(buffer);
  8334. }
  8335. } else {
  8336. const found = this._rangeReaders.some(function (rangeReader) {
  8337. if (rangeReader._begin !== begin) {
  8338. return false;
  8339. }
  8340. rangeReader._enqueue(buffer);
  8341. return true;
  8342. });
  8343. (0, _util.assert)(found, "_onReceiveData - no `PDFDataTransportStreamRangeReader` instance found.");
  8344. }
  8345. }
  8346. get _progressiveDataLength() {
  8347. return this._fullRequestReader?._loaded ?? 0;
  8348. }
  8349. _onProgress(evt) {
  8350. if (evt.total === undefined) {
  8351. this._rangeReaders[0]?.onProgress?.({
  8352. loaded: evt.loaded
  8353. });
  8354. } else {
  8355. this._fullRequestReader?.onProgress?.({
  8356. loaded: evt.loaded,
  8357. total: evt.total
  8358. });
  8359. }
  8360. }
  8361. _onProgressiveDone() {
  8362. this._fullRequestReader?.progressiveDone();
  8363. this._progressiveDone = true;
  8364. }
  8365. _removeRangeReader(reader) {
  8366. const i = this._rangeReaders.indexOf(reader);
  8367. if (i >= 0) {
  8368. this._rangeReaders.splice(i, 1);
  8369. }
  8370. }
  8371. getFullReader() {
  8372. (0, _util.assert)(!this._fullRequestReader, "PDFDataTransportStream.getFullReader can only be called once.");
  8373. const queuedChunks = this._queuedChunks;
  8374. this._queuedChunks = null;
  8375. return new PDFDataTransportStreamReader(this, queuedChunks, this._progressiveDone, this._contentDispositionFilename);
  8376. }
  8377. getRangeReader(begin, end) {
  8378. if (end <= this._progressiveDataLength) {
  8379. return null;
  8380. }
  8381. const reader = new PDFDataTransportStreamRangeReader(this, begin, end);
  8382. this._pdfDataRangeTransport.requestDataRange(begin, end);
  8383. this._rangeReaders.push(reader);
  8384. return reader;
  8385. }
  8386. cancelAllRequests(reason) {
  8387. this._fullRequestReader?.cancel(reason);
  8388. for (const reader of this._rangeReaders.slice(0)) {
  8389. reader.cancel(reason);
  8390. }
  8391. this._pdfDataRangeTransport.abort();
  8392. }
  8393. }
  8394. exports.PDFDataTransportStream = PDFDataTransportStream;
  8395. class PDFDataTransportStreamReader {
  8396. constructor(stream, queuedChunks, progressiveDone = false, contentDispositionFilename = null) {
  8397. this._stream = stream;
  8398. this._done = progressiveDone || false;
  8399. this._filename = (0, _display_utils.isPdfFile)(contentDispositionFilename) ? contentDispositionFilename : null;
  8400. this._queuedChunks = queuedChunks || [];
  8401. this._loaded = 0;
  8402. for (const chunk of this._queuedChunks) {
  8403. this._loaded += chunk.byteLength;
  8404. }
  8405. this._requests = [];
  8406. this._headersReady = Promise.resolve();
  8407. stream._fullRequestReader = this;
  8408. this.onProgress = null;
  8409. }
  8410. _enqueue(chunk) {
  8411. if (this._done) {
  8412. return;
  8413. }
  8414. if (this._requests.length > 0) {
  8415. const requestCapability = this._requests.shift();
  8416. requestCapability.resolve({
  8417. value: chunk,
  8418. done: false
  8419. });
  8420. } else {
  8421. this._queuedChunks.push(chunk);
  8422. }
  8423. this._loaded += chunk.byteLength;
  8424. }
  8425. get headersReady() {
  8426. return this._headersReady;
  8427. }
  8428. get filename() {
  8429. return this._filename;
  8430. }
  8431. get isRangeSupported() {
  8432. return this._stream._isRangeSupported;
  8433. }
  8434. get isStreamingSupported() {
  8435. return this._stream._isStreamingSupported;
  8436. }
  8437. get contentLength() {
  8438. return this._stream._contentLength;
  8439. }
  8440. async read() {
  8441. if (this._queuedChunks.length > 0) {
  8442. const chunk = this._queuedChunks.shift();
  8443. return {
  8444. value: chunk,
  8445. done: false
  8446. };
  8447. }
  8448. if (this._done) {
  8449. return {
  8450. value: undefined,
  8451. done: true
  8452. };
  8453. }
  8454. const requestCapability = (0, _util.createPromiseCapability)();
  8455. this._requests.push(requestCapability);
  8456. return requestCapability.promise;
  8457. }
  8458. cancel(reason) {
  8459. this._done = true;
  8460. for (const requestCapability of this._requests) {
  8461. requestCapability.resolve({
  8462. value: undefined,
  8463. done: true
  8464. });
  8465. }
  8466. this._requests.length = 0;
  8467. }
  8468. progressiveDone() {
  8469. if (this._done) {
  8470. return;
  8471. }
  8472. this._done = true;
  8473. }
  8474. }
  8475. class PDFDataTransportStreamRangeReader {
  8476. constructor(stream, begin, end) {
  8477. this._stream = stream;
  8478. this._begin = begin;
  8479. this._end = end;
  8480. this._queuedChunk = null;
  8481. this._requests = [];
  8482. this._done = false;
  8483. this.onProgress = null;
  8484. }
  8485. _enqueue(chunk) {
  8486. if (this._done) {
  8487. return;
  8488. }
  8489. if (this._requests.length === 0) {
  8490. this._queuedChunk = chunk;
  8491. } else {
  8492. const requestsCapability = this._requests.shift();
  8493. requestsCapability.resolve({
  8494. value: chunk,
  8495. done: false
  8496. });
  8497. for (const requestCapability of this._requests) {
  8498. requestCapability.resolve({
  8499. value: undefined,
  8500. done: true
  8501. });
  8502. }
  8503. this._requests.length = 0;
  8504. }
  8505. this._done = true;
  8506. this._stream._removeRangeReader(this);
  8507. }
  8508. get isStreamingSupported() {
  8509. return false;
  8510. }
  8511. async read() {
  8512. if (this._queuedChunk) {
  8513. const chunk = this._queuedChunk;
  8514. this._queuedChunk = null;
  8515. return {
  8516. value: chunk,
  8517. done: false
  8518. };
  8519. }
  8520. if (this._done) {
  8521. return {
  8522. value: undefined,
  8523. done: true
  8524. };
  8525. }
  8526. const requestCapability = (0, _util.createPromiseCapability)();
  8527. this._requests.push(requestCapability);
  8528. return requestCapability.promise;
  8529. }
  8530. cancel(reason) {
  8531. this._done = true;
  8532. for (const requestCapability of this._requests) {
  8533. requestCapability.resolve({
  8534. value: undefined,
  8535. done: true
  8536. });
  8537. }
  8538. this._requests.length = 0;
  8539. this._stream._removeRangeReader(this);
  8540. }
  8541. }
  8542. /***/ }),
  8543. /* 19 */
  8544. /***/ ((__unused_webpack_module, exports) => {
  8545. Object.defineProperty(exports, "__esModule", ({
  8546. value: true
  8547. }));
  8548. exports.XfaText = void 0;
  8549. class XfaText {
  8550. static textContent(xfa) {
  8551. const items = [];
  8552. const output = {
  8553. items,
  8554. styles: Object.create(null)
  8555. };
  8556. function walk(node) {
  8557. if (!node) {
  8558. return;
  8559. }
  8560. let str = null;
  8561. const name = node.name;
  8562. if (name === "#text") {
  8563. str = node.value;
  8564. } else if (!XfaText.shouldBuildText(name)) {
  8565. return;
  8566. } else if (node?.attributes?.textContent) {
  8567. str = node.attributes.textContent;
  8568. } else if (node.value) {
  8569. str = node.value;
  8570. }
  8571. if (str !== null) {
  8572. items.push({
  8573. str
  8574. });
  8575. }
  8576. if (!node.children) {
  8577. return;
  8578. }
  8579. for (const child of node.children) {
  8580. walk(child);
  8581. }
  8582. }
  8583. walk(xfa);
  8584. return output;
  8585. }
  8586. static shouldBuildText(name) {
  8587. return !(name === "textarea" || name === "input" || name === "option" || name === "select");
  8588. }
  8589. }
  8590. exports.XfaText = XfaText;
  8591. /***/ }),
  8592. /* 20 */
  8593. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  8594. Object.defineProperty(exports, "__esModule", ({
  8595. value: true
  8596. }));
  8597. exports.NodeStandardFontDataFactory = exports.NodeCanvasFactory = exports.NodeCMapReaderFactory = void 0;
  8598. var _base_factory = __w_pdfjs_require__(7);
  8599. ;
  8600. const fetchData = function (url) {
  8601. return new Promise((resolve, reject) => {
  8602. const fs = require("fs");
  8603. fs.readFile(url, (error, data) => {
  8604. if (error || !data) {
  8605. reject(new Error(error));
  8606. return;
  8607. }
  8608. resolve(new Uint8Array(data));
  8609. });
  8610. });
  8611. };
  8612. class NodeCanvasFactory extends _base_factory.BaseCanvasFactory {
  8613. _createCanvas(width, height) {
  8614. const Canvas = require("canvas");
  8615. return Canvas.createCanvas(width, height);
  8616. }
  8617. }
  8618. exports.NodeCanvasFactory = NodeCanvasFactory;
  8619. class NodeCMapReaderFactory extends _base_factory.BaseCMapReaderFactory {
  8620. _fetchData(url, compressionType) {
  8621. return fetchData(url).then(data => {
  8622. return {
  8623. cMapData: data,
  8624. compressionType
  8625. };
  8626. });
  8627. }
  8628. }
  8629. exports.NodeCMapReaderFactory = NodeCMapReaderFactory;
  8630. class NodeStandardFontDataFactory extends _base_factory.BaseStandardFontDataFactory {
  8631. _fetchData(url) {
  8632. return fetchData(url);
  8633. }
  8634. }
  8635. exports.NodeStandardFontDataFactory = NodeStandardFontDataFactory;
  8636. /***/ }),
  8637. /* 21 */
  8638. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  8639. Object.defineProperty(exports, "__esModule", ({
  8640. value: true
  8641. }));
  8642. exports.PDFNodeStream = void 0;
  8643. var _util = __w_pdfjs_require__(1);
  8644. var _network_utils = __w_pdfjs_require__(22);
  8645. ;
  8646. const fs = require("fs");
  8647. const http = require("http");
  8648. const https = require("https");
  8649. const url = require("url");
  8650. const fileUriRegex = /^file:\/\/\/[a-zA-Z]:\//;
  8651. function parseUrl(sourceUrl) {
  8652. const parsedUrl = url.parse(sourceUrl);
  8653. if (parsedUrl.protocol === "file:" || parsedUrl.host) {
  8654. return parsedUrl;
  8655. }
  8656. if (/^[a-z]:[/\\]/i.test(sourceUrl)) {
  8657. return url.parse(`file:///${sourceUrl}`);
  8658. }
  8659. if (!parsedUrl.host) {
  8660. parsedUrl.protocol = "file:";
  8661. }
  8662. return parsedUrl;
  8663. }
  8664. class PDFNodeStream {
  8665. constructor(source) {
  8666. this.source = source;
  8667. this.url = parseUrl(source.url);
  8668. this.isHttp = this.url.protocol === "http:" || this.url.protocol === "https:";
  8669. this.isFsUrl = this.url.protocol === "file:";
  8670. this.httpHeaders = this.isHttp && source.httpHeaders || {};
  8671. this._fullRequestReader = null;
  8672. this._rangeRequestReaders = [];
  8673. }
  8674. get _progressiveDataLength() {
  8675. return this._fullRequestReader?._loaded ?? 0;
  8676. }
  8677. getFullReader() {
  8678. (0, _util.assert)(!this._fullRequestReader, "PDFNodeStream.getFullReader can only be called once.");
  8679. this._fullRequestReader = this.isFsUrl ? new PDFNodeStreamFsFullReader(this) : new PDFNodeStreamFullReader(this);
  8680. return this._fullRequestReader;
  8681. }
  8682. getRangeReader(start, end) {
  8683. if (end <= this._progressiveDataLength) {
  8684. return null;
  8685. }
  8686. const rangeReader = this.isFsUrl ? new PDFNodeStreamFsRangeReader(this, start, end) : new PDFNodeStreamRangeReader(this, start, end);
  8687. this._rangeRequestReaders.push(rangeReader);
  8688. return rangeReader;
  8689. }
  8690. cancelAllRequests(reason) {
  8691. this._fullRequestReader?.cancel(reason);
  8692. for (const reader of this._rangeRequestReaders.slice(0)) {
  8693. reader.cancel(reason);
  8694. }
  8695. }
  8696. }
  8697. exports.PDFNodeStream = PDFNodeStream;
  8698. class BaseFullReader {
  8699. constructor(stream) {
  8700. this._url = stream.url;
  8701. this._done = false;
  8702. this._storedError = null;
  8703. this.onProgress = null;
  8704. const source = stream.source;
  8705. this._contentLength = source.length;
  8706. this._loaded = 0;
  8707. this._filename = null;
  8708. this._disableRange = source.disableRange || false;
  8709. this._rangeChunkSize = source.rangeChunkSize;
  8710. if (!this._rangeChunkSize && !this._disableRange) {
  8711. this._disableRange = true;
  8712. }
  8713. this._isStreamingSupported = !source.disableStream;
  8714. this._isRangeSupported = !source.disableRange;
  8715. this._readableStream = null;
  8716. this._readCapability = (0, _util.createPromiseCapability)();
  8717. this._headersCapability = (0, _util.createPromiseCapability)();
  8718. }
  8719. get headersReady() {
  8720. return this._headersCapability.promise;
  8721. }
  8722. get filename() {
  8723. return this._filename;
  8724. }
  8725. get contentLength() {
  8726. return this._contentLength;
  8727. }
  8728. get isRangeSupported() {
  8729. return this._isRangeSupported;
  8730. }
  8731. get isStreamingSupported() {
  8732. return this._isStreamingSupported;
  8733. }
  8734. async read() {
  8735. await this._readCapability.promise;
  8736. if (this._done) {
  8737. return {
  8738. value: undefined,
  8739. done: true
  8740. };
  8741. }
  8742. if (this._storedError) {
  8743. throw this._storedError;
  8744. }
  8745. const chunk = this._readableStream.read();
  8746. if (chunk === null) {
  8747. this._readCapability = (0, _util.createPromiseCapability)();
  8748. return this.read();
  8749. }
  8750. this._loaded += chunk.length;
  8751. this.onProgress?.({
  8752. loaded: this._loaded,
  8753. total: this._contentLength
  8754. });
  8755. const buffer = new Uint8Array(chunk).buffer;
  8756. return {
  8757. value: buffer,
  8758. done: false
  8759. };
  8760. }
  8761. cancel(reason) {
  8762. if (!this._readableStream) {
  8763. this._error(reason);
  8764. return;
  8765. }
  8766. this._readableStream.destroy(reason);
  8767. }
  8768. _error(reason) {
  8769. this._storedError = reason;
  8770. this._readCapability.resolve();
  8771. }
  8772. _setReadableStream(readableStream) {
  8773. this._readableStream = readableStream;
  8774. readableStream.on("readable", () => {
  8775. this._readCapability.resolve();
  8776. });
  8777. readableStream.on("end", () => {
  8778. readableStream.destroy();
  8779. this._done = true;
  8780. this._readCapability.resolve();
  8781. });
  8782. readableStream.on("error", reason => {
  8783. this._error(reason);
  8784. });
  8785. if (!this._isStreamingSupported && this._isRangeSupported) {
  8786. this._error(new _util.AbortException("streaming is disabled"));
  8787. }
  8788. if (this._storedError) {
  8789. this._readableStream.destroy(this._storedError);
  8790. }
  8791. }
  8792. }
  8793. class BaseRangeReader {
  8794. constructor(stream) {
  8795. this._url = stream.url;
  8796. this._done = false;
  8797. this._storedError = null;
  8798. this.onProgress = null;
  8799. this._loaded = 0;
  8800. this._readableStream = null;
  8801. this._readCapability = (0, _util.createPromiseCapability)();
  8802. const source = stream.source;
  8803. this._isStreamingSupported = !source.disableStream;
  8804. }
  8805. get isStreamingSupported() {
  8806. return this._isStreamingSupported;
  8807. }
  8808. async read() {
  8809. await this._readCapability.promise;
  8810. if (this._done) {
  8811. return {
  8812. value: undefined,
  8813. done: true
  8814. };
  8815. }
  8816. if (this._storedError) {
  8817. throw this._storedError;
  8818. }
  8819. const chunk = this._readableStream.read();
  8820. if (chunk === null) {
  8821. this._readCapability = (0, _util.createPromiseCapability)();
  8822. return this.read();
  8823. }
  8824. this._loaded += chunk.length;
  8825. this.onProgress?.({
  8826. loaded: this._loaded
  8827. });
  8828. const buffer = new Uint8Array(chunk).buffer;
  8829. return {
  8830. value: buffer,
  8831. done: false
  8832. };
  8833. }
  8834. cancel(reason) {
  8835. if (!this._readableStream) {
  8836. this._error(reason);
  8837. return;
  8838. }
  8839. this._readableStream.destroy(reason);
  8840. }
  8841. _error(reason) {
  8842. this._storedError = reason;
  8843. this._readCapability.resolve();
  8844. }
  8845. _setReadableStream(readableStream) {
  8846. this._readableStream = readableStream;
  8847. readableStream.on("readable", () => {
  8848. this._readCapability.resolve();
  8849. });
  8850. readableStream.on("end", () => {
  8851. readableStream.destroy();
  8852. this._done = true;
  8853. this._readCapability.resolve();
  8854. });
  8855. readableStream.on("error", reason => {
  8856. this._error(reason);
  8857. });
  8858. if (this._storedError) {
  8859. this._readableStream.destroy(this._storedError);
  8860. }
  8861. }
  8862. }
  8863. function createRequestOptions(parsedUrl, headers) {
  8864. return {
  8865. protocol: parsedUrl.protocol,
  8866. auth: parsedUrl.auth,
  8867. host: parsedUrl.hostname,
  8868. port: parsedUrl.port,
  8869. path: parsedUrl.path,
  8870. method: "GET",
  8871. headers
  8872. };
  8873. }
  8874. class PDFNodeStreamFullReader extends BaseFullReader {
  8875. constructor(stream) {
  8876. super(stream);
  8877. const handleResponse = response => {
  8878. if (response.statusCode === 404) {
  8879. const error = new _util.MissingPDFException(`Missing PDF "${this._url}".`);
  8880. this._storedError = error;
  8881. this._headersCapability.reject(error);
  8882. return;
  8883. }
  8884. this._headersCapability.resolve();
  8885. this._setReadableStream(response);
  8886. const getResponseHeader = name => {
  8887. return this._readableStream.headers[name.toLowerCase()];
  8888. };
  8889. const {
  8890. allowRangeRequests,
  8891. suggestedLength
  8892. } = (0, _network_utils.validateRangeRequestCapabilities)({
  8893. getResponseHeader,
  8894. isHttp: stream.isHttp,
  8895. rangeChunkSize: this._rangeChunkSize,
  8896. disableRange: this._disableRange
  8897. });
  8898. this._isRangeSupported = allowRangeRequests;
  8899. this._contentLength = suggestedLength || this._contentLength;
  8900. this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
  8901. };
  8902. this._request = null;
  8903. if (this._url.protocol === "http:") {
  8904. this._request = http.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
  8905. } else {
  8906. this._request = https.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
  8907. }
  8908. this._request.on("error", reason => {
  8909. this._storedError = reason;
  8910. this._headersCapability.reject(reason);
  8911. });
  8912. this._request.end();
  8913. }
  8914. }
  8915. class PDFNodeStreamRangeReader extends BaseRangeReader {
  8916. constructor(stream, start, end) {
  8917. super(stream);
  8918. this._httpHeaders = {};
  8919. for (const property in stream.httpHeaders) {
  8920. const value = stream.httpHeaders[property];
  8921. if (value === undefined) {
  8922. continue;
  8923. }
  8924. this._httpHeaders[property] = value;
  8925. }
  8926. this._httpHeaders.Range = `bytes=${start}-${end - 1}`;
  8927. const handleResponse = response => {
  8928. if (response.statusCode === 404) {
  8929. const error = new _util.MissingPDFException(`Missing PDF "${this._url}".`);
  8930. this._storedError = error;
  8931. return;
  8932. }
  8933. this._setReadableStream(response);
  8934. };
  8935. this._request = null;
  8936. if (this._url.protocol === "http:") {
  8937. this._request = http.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
  8938. } else {
  8939. this._request = https.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
  8940. }
  8941. this._request.on("error", reason => {
  8942. this._storedError = reason;
  8943. });
  8944. this._request.end();
  8945. }
  8946. }
  8947. class PDFNodeStreamFsFullReader extends BaseFullReader {
  8948. constructor(stream) {
  8949. super(stream);
  8950. let path = decodeURIComponent(this._url.path);
  8951. if (fileUriRegex.test(this._url.href)) {
  8952. path = path.replace(/^\//, "");
  8953. }
  8954. fs.lstat(path, (error, stat) => {
  8955. if (error) {
  8956. if (error.code === "ENOENT") {
  8957. error = new _util.MissingPDFException(`Missing PDF "${path}".`);
  8958. }
  8959. this._storedError = error;
  8960. this._headersCapability.reject(error);
  8961. return;
  8962. }
  8963. this._contentLength = stat.size;
  8964. this._setReadableStream(fs.createReadStream(path));
  8965. this._headersCapability.resolve();
  8966. });
  8967. }
  8968. }
  8969. class PDFNodeStreamFsRangeReader extends BaseRangeReader {
  8970. constructor(stream, start, end) {
  8971. super(stream);
  8972. let path = decodeURIComponent(this._url.path);
  8973. if (fileUriRegex.test(this._url.href)) {
  8974. path = path.replace(/^\//, "");
  8975. }
  8976. this._setReadableStream(fs.createReadStream(path, {
  8977. start,
  8978. end: end - 1
  8979. }));
  8980. }
  8981. }
  8982. /***/ }),
  8983. /* 22 */
  8984. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  8985. Object.defineProperty(exports, "__esModule", ({
  8986. value: true
  8987. }));
  8988. exports.createResponseStatusError = createResponseStatusError;
  8989. exports.extractFilenameFromHeader = extractFilenameFromHeader;
  8990. exports.validateRangeRequestCapabilities = validateRangeRequestCapabilities;
  8991. exports.validateResponseStatus = validateResponseStatus;
  8992. var _util = __w_pdfjs_require__(1);
  8993. var _content_disposition = __w_pdfjs_require__(23);
  8994. var _display_utils = __w_pdfjs_require__(6);
  8995. function validateRangeRequestCapabilities({
  8996. getResponseHeader,
  8997. isHttp,
  8998. rangeChunkSize,
  8999. disableRange
  9000. }) {
  9001. const returnValues = {
  9002. allowRangeRequests: false,
  9003. suggestedLength: undefined
  9004. };
  9005. const length = parseInt(getResponseHeader("Content-Length"), 10);
  9006. if (!Number.isInteger(length)) {
  9007. return returnValues;
  9008. }
  9009. returnValues.suggestedLength = length;
  9010. if (length <= 2 * rangeChunkSize) {
  9011. return returnValues;
  9012. }
  9013. if (disableRange || !isHttp) {
  9014. return returnValues;
  9015. }
  9016. if (getResponseHeader("Accept-Ranges") !== "bytes") {
  9017. return returnValues;
  9018. }
  9019. const contentEncoding = getResponseHeader("Content-Encoding") || "identity";
  9020. if (contentEncoding !== "identity") {
  9021. return returnValues;
  9022. }
  9023. returnValues.allowRangeRequests = true;
  9024. return returnValues;
  9025. }
  9026. function extractFilenameFromHeader(getResponseHeader) {
  9027. const contentDisposition = getResponseHeader("Content-Disposition");
  9028. if (contentDisposition) {
  9029. let filename = (0, _content_disposition.getFilenameFromContentDispositionHeader)(contentDisposition);
  9030. if (filename.includes("%")) {
  9031. try {
  9032. filename = decodeURIComponent(filename);
  9033. } catch (ex) {}
  9034. }
  9035. if ((0, _display_utils.isPdfFile)(filename)) {
  9036. return filename;
  9037. }
  9038. }
  9039. return null;
  9040. }
  9041. function createResponseStatusError(status, url) {
  9042. if (status === 404 || status === 0 && url.startsWith("file:")) {
  9043. return new _util.MissingPDFException('Missing PDF "' + url + '".');
  9044. }
  9045. return new _util.UnexpectedResponseException(`Unexpected server response (${status}) while retrieving PDF "${url}".`, status);
  9046. }
  9047. function validateResponseStatus(status) {
  9048. return status === 200 || status === 206;
  9049. }
  9050. /***/ }),
  9051. /* 23 */
  9052. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  9053. Object.defineProperty(exports, "__esModule", ({
  9054. value: true
  9055. }));
  9056. exports.getFilenameFromContentDispositionHeader = getFilenameFromContentDispositionHeader;
  9057. var _util = __w_pdfjs_require__(1);
  9058. function getFilenameFromContentDispositionHeader(contentDisposition) {
  9059. let needsEncodingFixup = true;
  9060. let tmp = toParamRegExp("filename\\*", "i").exec(contentDisposition);
  9061. if (tmp) {
  9062. tmp = tmp[1];
  9063. let filename = rfc2616unquote(tmp);
  9064. filename = unescape(filename);
  9065. filename = rfc5987decode(filename);
  9066. filename = rfc2047decode(filename);
  9067. return fixupEncoding(filename);
  9068. }
  9069. tmp = rfc2231getparam(contentDisposition);
  9070. if (tmp) {
  9071. const filename = rfc2047decode(tmp);
  9072. return fixupEncoding(filename);
  9073. }
  9074. tmp = toParamRegExp("filename", "i").exec(contentDisposition);
  9075. if (tmp) {
  9076. tmp = tmp[1];
  9077. let filename = rfc2616unquote(tmp);
  9078. filename = rfc2047decode(filename);
  9079. return fixupEncoding(filename);
  9080. }
  9081. function toParamRegExp(attributePattern, flags) {
  9082. return new RegExp("(?:^|;)\\s*" + attributePattern + "\\s*=\\s*" + "(" + '[^";\\s][^;\\s]*' + "|" + '"(?:[^"\\\\]|\\\\"?)+"?' + ")", flags);
  9083. }
  9084. function textdecode(encoding, value) {
  9085. if (encoding) {
  9086. if (!/^[\x00-\xFF]+$/.test(value)) {
  9087. return value;
  9088. }
  9089. try {
  9090. const decoder = new TextDecoder(encoding, {
  9091. fatal: true
  9092. });
  9093. const buffer = (0, _util.stringToBytes)(value);
  9094. value = decoder.decode(buffer);
  9095. needsEncodingFixup = false;
  9096. } catch (e) {}
  9097. }
  9098. return value;
  9099. }
  9100. function fixupEncoding(value) {
  9101. if (needsEncodingFixup && /[\x80-\xff]/.test(value)) {
  9102. value = textdecode("utf-8", value);
  9103. if (needsEncodingFixup) {
  9104. value = textdecode("iso-8859-1", value);
  9105. }
  9106. }
  9107. return value;
  9108. }
  9109. function rfc2231getparam(contentDispositionStr) {
  9110. const matches = [];
  9111. let match;
  9112. const iter = toParamRegExp("filename\\*((?!0\\d)\\d+)(\\*?)", "ig");
  9113. while ((match = iter.exec(contentDispositionStr)) !== null) {
  9114. let [, n, quot, part] = match;
  9115. n = parseInt(n, 10);
  9116. if (n in matches) {
  9117. if (n === 0) {
  9118. break;
  9119. }
  9120. continue;
  9121. }
  9122. matches[n] = [quot, part];
  9123. }
  9124. const parts = [];
  9125. for (let n = 0; n < matches.length; ++n) {
  9126. if (!(n in matches)) {
  9127. break;
  9128. }
  9129. let [quot, part] = matches[n];
  9130. part = rfc2616unquote(part);
  9131. if (quot) {
  9132. part = unescape(part);
  9133. if (n === 0) {
  9134. part = rfc5987decode(part);
  9135. }
  9136. }
  9137. parts.push(part);
  9138. }
  9139. return parts.join("");
  9140. }
  9141. function rfc2616unquote(value) {
  9142. if (value.startsWith('"')) {
  9143. const parts = value.slice(1).split('\\"');
  9144. for (let i = 0; i < parts.length; ++i) {
  9145. const quotindex = parts[i].indexOf('"');
  9146. if (quotindex !== -1) {
  9147. parts[i] = parts[i].slice(0, quotindex);
  9148. parts.length = i + 1;
  9149. }
  9150. parts[i] = parts[i].replace(/\\(.)/g, "$1");
  9151. }
  9152. value = parts.join('"');
  9153. }
  9154. return value;
  9155. }
  9156. function rfc5987decode(extvalue) {
  9157. const encodingend = extvalue.indexOf("'");
  9158. if (encodingend === -1) {
  9159. return extvalue;
  9160. }
  9161. const encoding = extvalue.slice(0, encodingend);
  9162. const langvalue = extvalue.slice(encodingend + 1);
  9163. const value = langvalue.replace(/^[^']*'/, "");
  9164. return textdecode(encoding, value);
  9165. }
  9166. function rfc2047decode(value) {
  9167. if (!value.startsWith("=?") || /[\x00-\x19\x80-\xff]/.test(value)) {
  9168. return value;
  9169. }
  9170. return value.replace(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g, function (matches, charset, encoding, text) {
  9171. if (encoding === "q" || encoding === "Q") {
  9172. text = text.replace(/_/g, " ");
  9173. text = text.replace(/=([0-9a-fA-F]{2})/g, function (match, hex) {
  9174. return String.fromCharCode(parseInt(hex, 16));
  9175. });
  9176. return textdecode(charset, text);
  9177. }
  9178. try {
  9179. text = atob(text);
  9180. } catch (e) {}
  9181. return textdecode(charset, text);
  9182. });
  9183. }
  9184. return "";
  9185. }
  9186. /***/ }),
  9187. /* 24 */
  9188. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  9189. Object.defineProperty(exports, "__esModule", ({
  9190. value: true
  9191. }));
  9192. exports.PDFNetworkStream = void 0;
  9193. var _util = __w_pdfjs_require__(1);
  9194. var _network_utils = __w_pdfjs_require__(22);
  9195. ;
  9196. const OK_RESPONSE = 200;
  9197. const PARTIAL_CONTENT_RESPONSE = 206;
  9198. function getArrayBuffer(xhr) {
  9199. const data = xhr.response;
  9200. if (typeof data !== "string") {
  9201. return data;
  9202. }
  9203. return (0, _util.stringToBytes)(data).buffer;
  9204. }
  9205. class NetworkManager {
  9206. constructor(url, args = {}) {
  9207. this.url = url;
  9208. this.isHttp = /^https?:/i.test(url);
  9209. this.httpHeaders = this.isHttp && args.httpHeaders || Object.create(null);
  9210. this.withCredentials = args.withCredentials || false;
  9211. this.getXhr = args.getXhr || function NetworkManager_getXhr() {
  9212. return new XMLHttpRequest();
  9213. };
  9214. this.currXhrId = 0;
  9215. this.pendingRequests = Object.create(null);
  9216. }
  9217. requestRange(begin, end, listeners) {
  9218. const args = {
  9219. begin,
  9220. end
  9221. };
  9222. for (const prop in listeners) {
  9223. args[prop] = listeners[prop];
  9224. }
  9225. return this.request(args);
  9226. }
  9227. requestFull(listeners) {
  9228. return this.request(listeners);
  9229. }
  9230. request(args) {
  9231. const xhr = this.getXhr();
  9232. const xhrId = this.currXhrId++;
  9233. const pendingRequest = this.pendingRequests[xhrId] = {
  9234. xhr
  9235. };
  9236. xhr.open("GET", this.url);
  9237. xhr.withCredentials = this.withCredentials;
  9238. for (const property in this.httpHeaders) {
  9239. const value = this.httpHeaders[property];
  9240. if (value === undefined) {
  9241. continue;
  9242. }
  9243. xhr.setRequestHeader(property, value);
  9244. }
  9245. if (this.isHttp && "begin" in args && "end" in args) {
  9246. xhr.setRequestHeader("Range", `bytes=${args.begin}-${args.end - 1}`);
  9247. pendingRequest.expectedStatus = PARTIAL_CONTENT_RESPONSE;
  9248. } else {
  9249. pendingRequest.expectedStatus = OK_RESPONSE;
  9250. }
  9251. xhr.responseType = "arraybuffer";
  9252. if (args.onError) {
  9253. xhr.onerror = function (evt) {
  9254. args.onError(xhr.status);
  9255. };
  9256. }
  9257. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  9258. xhr.onprogress = this.onProgress.bind(this, xhrId);
  9259. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  9260. pendingRequest.onDone = args.onDone;
  9261. pendingRequest.onError = args.onError;
  9262. pendingRequest.onProgress = args.onProgress;
  9263. xhr.send(null);
  9264. return xhrId;
  9265. }
  9266. onProgress(xhrId, evt) {
  9267. const pendingRequest = this.pendingRequests[xhrId];
  9268. if (!pendingRequest) {
  9269. return;
  9270. }
  9271. pendingRequest.onProgress?.(evt);
  9272. }
  9273. onStateChange(xhrId, evt) {
  9274. const pendingRequest = this.pendingRequests[xhrId];
  9275. if (!pendingRequest) {
  9276. return;
  9277. }
  9278. const xhr = pendingRequest.xhr;
  9279. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  9280. pendingRequest.onHeadersReceived();
  9281. delete pendingRequest.onHeadersReceived;
  9282. }
  9283. if (xhr.readyState !== 4) {
  9284. return;
  9285. }
  9286. if (!(xhrId in this.pendingRequests)) {
  9287. return;
  9288. }
  9289. delete this.pendingRequests[xhrId];
  9290. if (xhr.status === 0 && this.isHttp) {
  9291. pendingRequest.onError?.(xhr.status);
  9292. return;
  9293. }
  9294. const xhrStatus = xhr.status || OK_RESPONSE;
  9295. const ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  9296. if (!ok_response_on_range_request && xhrStatus !== pendingRequest.expectedStatus) {
  9297. pendingRequest.onError?.(xhr.status);
  9298. return;
  9299. }
  9300. const chunk = getArrayBuffer(xhr);
  9301. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  9302. const rangeHeader = xhr.getResponseHeader("Content-Range");
  9303. const matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  9304. pendingRequest.onDone({
  9305. begin: parseInt(matches[1], 10),
  9306. chunk
  9307. });
  9308. } else if (chunk) {
  9309. pendingRequest.onDone({
  9310. begin: 0,
  9311. chunk
  9312. });
  9313. } else {
  9314. pendingRequest.onError?.(xhr.status);
  9315. }
  9316. }
  9317. getRequestXhr(xhrId) {
  9318. return this.pendingRequests[xhrId].xhr;
  9319. }
  9320. isPendingRequest(xhrId) {
  9321. return xhrId in this.pendingRequests;
  9322. }
  9323. abortRequest(xhrId) {
  9324. const xhr = this.pendingRequests[xhrId].xhr;
  9325. delete this.pendingRequests[xhrId];
  9326. xhr.abort();
  9327. }
  9328. }
  9329. class PDFNetworkStream {
  9330. constructor(source) {
  9331. this._source = source;
  9332. this._manager = new NetworkManager(source.url, {
  9333. httpHeaders: source.httpHeaders,
  9334. withCredentials: source.withCredentials
  9335. });
  9336. this._rangeChunkSize = source.rangeChunkSize;
  9337. this._fullRequestReader = null;
  9338. this._rangeRequestReaders = [];
  9339. }
  9340. _onRangeRequestReaderClosed(reader) {
  9341. const i = this._rangeRequestReaders.indexOf(reader);
  9342. if (i >= 0) {
  9343. this._rangeRequestReaders.splice(i, 1);
  9344. }
  9345. }
  9346. getFullReader() {
  9347. (0, _util.assert)(!this._fullRequestReader, "PDFNetworkStream.getFullReader can only be called once.");
  9348. this._fullRequestReader = new PDFNetworkStreamFullRequestReader(this._manager, this._source);
  9349. return this._fullRequestReader;
  9350. }
  9351. getRangeReader(begin, end) {
  9352. const reader = new PDFNetworkStreamRangeRequestReader(this._manager, begin, end);
  9353. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  9354. this._rangeRequestReaders.push(reader);
  9355. return reader;
  9356. }
  9357. cancelAllRequests(reason) {
  9358. this._fullRequestReader?.cancel(reason);
  9359. for (const reader of this._rangeRequestReaders.slice(0)) {
  9360. reader.cancel(reason);
  9361. }
  9362. }
  9363. }
  9364. exports.PDFNetworkStream = PDFNetworkStream;
  9365. class PDFNetworkStreamFullRequestReader {
  9366. constructor(manager, source) {
  9367. this._manager = manager;
  9368. const args = {
  9369. onHeadersReceived: this._onHeadersReceived.bind(this),
  9370. onDone: this._onDone.bind(this),
  9371. onError: this._onError.bind(this),
  9372. onProgress: this._onProgress.bind(this)
  9373. };
  9374. this._url = source.url;
  9375. this._fullRequestId = manager.requestFull(args);
  9376. this._headersReceivedCapability = (0, _util.createPromiseCapability)();
  9377. this._disableRange = source.disableRange || false;
  9378. this._contentLength = source.length;
  9379. this._rangeChunkSize = source.rangeChunkSize;
  9380. if (!this._rangeChunkSize && !this._disableRange) {
  9381. this._disableRange = true;
  9382. }
  9383. this._isStreamingSupported = false;
  9384. this._isRangeSupported = false;
  9385. this._cachedChunks = [];
  9386. this._requests = [];
  9387. this._done = false;
  9388. this._storedError = undefined;
  9389. this._filename = null;
  9390. this.onProgress = null;
  9391. }
  9392. _onHeadersReceived() {
  9393. const fullRequestXhrId = this._fullRequestId;
  9394. const fullRequestXhr = this._manager.getRequestXhr(fullRequestXhrId);
  9395. const getResponseHeader = name => {
  9396. return fullRequestXhr.getResponseHeader(name);
  9397. };
  9398. const {
  9399. allowRangeRequests,
  9400. suggestedLength
  9401. } = (0, _network_utils.validateRangeRequestCapabilities)({
  9402. getResponseHeader,
  9403. isHttp: this._manager.isHttp,
  9404. rangeChunkSize: this._rangeChunkSize,
  9405. disableRange: this._disableRange
  9406. });
  9407. if (allowRangeRequests) {
  9408. this._isRangeSupported = true;
  9409. }
  9410. this._contentLength = suggestedLength || this._contentLength;
  9411. this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
  9412. if (this._isRangeSupported) {
  9413. this._manager.abortRequest(fullRequestXhrId);
  9414. }
  9415. this._headersReceivedCapability.resolve();
  9416. }
  9417. _onDone(data) {
  9418. if (data) {
  9419. if (this._requests.length > 0) {
  9420. const requestCapability = this._requests.shift();
  9421. requestCapability.resolve({
  9422. value: data.chunk,
  9423. done: false
  9424. });
  9425. } else {
  9426. this._cachedChunks.push(data.chunk);
  9427. }
  9428. }
  9429. this._done = true;
  9430. if (this._cachedChunks.length > 0) {
  9431. return;
  9432. }
  9433. for (const requestCapability of this._requests) {
  9434. requestCapability.resolve({
  9435. value: undefined,
  9436. done: true
  9437. });
  9438. }
  9439. this._requests.length = 0;
  9440. }
  9441. _onError(status) {
  9442. this._storedError = (0, _network_utils.createResponseStatusError)(status, this._url);
  9443. this._headersReceivedCapability.reject(this._storedError);
  9444. for (const requestCapability of this._requests) {
  9445. requestCapability.reject(this._storedError);
  9446. }
  9447. this._requests.length = 0;
  9448. this._cachedChunks.length = 0;
  9449. }
  9450. _onProgress(evt) {
  9451. this.onProgress?.({
  9452. loaded: evt.loaded,
  9453. total: evt.lengthComputable ? evt.total : this._contentLength
  9454. });
  9455. }
  9456. get filename() {
  9457. return this._filename;
  9458. }
  9459. get isRangeSupported() {
  9460. return this._isRangeSupported;
  9461. }
  9462. get isStreamingSupported() {
  9463. return this._isStreamingSupported;
  9464. }
  9465. get contentLength() {
  9466. return this._contentLength;
  9467. }
  9468. get headersReady() {
  9469. return this._headersReceivedCapability.promise;
  9470. }
  9471. async read() {
  9472. if (this._storedError) {
  9473. throw this._storedError;
  9474. }
  9475. if (this._cachedChunks.length > 0) {
  9476. const chunk = this._cachedChunks.shift();
  9477. return {
  9478. value: chunk,
  9479. done: false
  9480. };
  9481. }
  9482. if (this._done) {
  9483. return {
  9484. value: undefined,
  9485. done: true
  9486. };
  9487. }
  9488. const requestCapability = (0, _util.createPromiseCapability)();
  9489. this._requests.push(requestCapability);
  9490. return requestCapability.promise;
  9491. }
  9492. cancel(reason) {
  9493. this._done = true;
  9494. this._headersReceivedCapability.reject(reason);
  9495. for (const requestCapability of this._requests) {
  9496. requestCapability.resolve({
  9497. value: undefined,
  9498. done: true
  9499. });
  9500. }
  9501. this._requests.length = 0;
  9502. if (this._manager.isPendingRequest(this._fullRequestId)) {
  9503. this._manager.abortRequest(this._fullRequestId);
  9504. }
  9505. this._fullRequestReader = null;
  9506. }
  9507. }
  9508. class PDFNetworkStreamRangeRequestReader {
  9509. constructor(manager, begin, end) {
  9510. this._manager = manager;
  9511. const args = {
  9512. onDone: this._onDone.bind(this),
  9513. onError: this._onError.bind(this),
  9514. onProgress: this._onProgress.bind(this)
  9515. };
  9516. this._url = manager.url;
  9517. this._requestId = manager.requestRange(begin, end, args);
  9518. this._requests = [];
  9519. this._queuedChunk = null;
  9520. this._done = false;
  9521. this._storedError = undefined;
  9522. this.onProgress = null;
  9523. this.onClosed = null;
  9524. }
  9525. _close() {
  9526. this.onClosed?.(this);
  9527. }
  9528. _onDone(data) {
  9529. const chunk = data.chunk;
  9530. if (this._requests.length > 0) {
  9531. const requestCapability = this._requests.shift();
  9532. requestCapability.resolve({
  9533. value: chunk,
  9534. done: false
  9535. });
  9536. } else {
  9537. this._queuedChunk = chunk;
  9538. }
  9539. this._done = true;
  9540. for (const requestCapability of this._requests) {
  9541. requestCapability.resolve({
  9542. value: undefined,
  9543. done: true
  9544. });
  9545. }
  9546. this._requests.length = 0;
  9547. this._close();
  9548. }
  9549. _onError(status) {
  9550. this._storedError = (0, _network_utils.createResponseStatusError)(status, this._url);
  9551. for (const requestCapability of this._requests) {
  9552. requestCapability.reject(this._storedError);
  9553. }
  9554. this._requests.length = 0;
  9555. this._queuedChunk = null;
  9556. }
  9557. _onProgress(evt) {
  9558. if (!this.isStreamingSupported) {
  9559. this.onProgress?.({
  9560. loaded: evt.loaded
  9561. });
  9562. }
  9563. }
  9564. get isStreamingSupported() {
  9565. return false;
  9566. }
  9567. async read() {
  9568. if (this._storedError) {
  9569. throw this._storedError;
  9570. }
  9571. if (this._queuedChunk !== null) {
  9572. const chunk = this._queuedChunk;
  9573. this._queuedChunk = null;
  9574. return {
  9575. value: chunk,
  9576. done: false
  9577. };
  9578. }
  9579. if (this._done) {
  9580. return {
  9581. value: undefined,
  9582. done: true
  9583. };
  9584. }
  9585. const requestCapability = (0, _util.createPromiseCapability)();
  9586. this._requests.push(requestCapability);
  9587. return requestCapability.promise;
  9588. }
  9589. cancel(reason) {
  9590. this._done = true;
  9591. for (const requestCapability of this._requests) {
  9592. requestCapability.resolve({
  9593. value: undefined,
  9594. done: true
  9595. });
  9596. }
  9597. this._requests.length = 0;
  9598. if (this._manager.isPendingRequest(this._requestId)) {
  9599. this._manager.abortRequest(this._requestId);
  9600. }
  9601. this._close();
  9602. }
  9603. }
  9604. /***/ }),
  9605. /* 25 */
  9606. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  9607. Object.defineProperty(exports, "__esModule", ({
  9608. value: true
  9609. }));
  9610. exports.PDFFetchStream = void 0;
  9611. var _util = __w_pdfjs_require__(1);
  9612. var _network_utils = __w_pdfjs_require__(22);
  9613. ;
  9614. function createFetchOptions(headers, withCredentials, abortController) {
  9615. return {
  9616. method: "GET",
  9617. headers,
  9618. signal: abortController.signal,
  9619. mode: "cors",
  9620. credentials: withCredentials ? "include" : "same-origin",
  9621. redirect: "follow"
  9622. };
  9623. }
  9624. function createHeaders(httpHeaders) {
  9625. const headers = new Headers();
  9626. for (const property in httpHeaders) {
  9627. const value = httpHeaders[property];
  9628. if (value === undefined) {
  9629. continue;
  9630. }
  9631. headers.append(property, value);
  9632. }
  9633. return headers;
  9634. }
  9635. function getArrayBuffer(val) {
  9636. if (val instanceof Uint8Array) {
  9637. return val.buffer;
  9638. }
  9639. if (val instanceof ArrayBuffer) {
  9640. return val;
  9641. }
  9642. (0, _util.warn)(`getArrayBuffer - unexpected data format: ${val}`);
  9643. return new Uint8Array(val).buffer;
  9644. }
  9645. class PDFFetchStream {
  9646. constructor(source) {
  9647. this.source = source;
  9648. this.isHttp = /^https?:/i.test(source.url);
  9649. this.httpHeaders = this.isHttp && source.httpHeaders || {};
  9650. this._fullRequestReader = null;
  9651. this._rangeRequestReaders = [];
  9652. }
  9653. get _progressiveDataLength() {
  9654. return this._fullRequestReader?._loaded ?? 0;
  9655. }
  9656. getFullReader() {
  9657. (0, _util.assert)(!this._fullRequestReader, "PDFFetchStream.getFullReader can only be called once.");
  9658. this._fullRequestReader = new PDFFetchStreamReader(this);
  9659. return this._fullRequestReader;
  9660. }
  9661. getRangeReader(begin, end) {
  9662. if (end <= this._progressiveDataLength) {
  9663. return null;
  9664. }
  9665. const reader = new PDFFetchStreamRangeReader(this, begin, end);
  9666. this._rangeRequestReaders.push(reader);
  9667. return reader;
  9668. }
  9669. cancelAllRequests(reason) {
  9670. this._fullRequestReader?.cancel(reason);
  9671. for (const reader of this._rangeRequestReaders.slice(0)) {
  9672. reader.cancel(reason);
  9673. }
  9674. }
  9675. }
  9676. exports.PDFFetchStream = PDFFetchStream;
  9677. class PDFFetchStreamReader {
  9678. constructor(stream) {
  9679. this._stream = stream;
  9680. this._reader = null;
  9681. this._loaded = 0;
  9682. this._filename = null;
  9683. const source = stream.source;
  9684. this._withCredentials = source.withCredentials || false;
  9685. this._contentLength = source.length;
  9686. this._headersCapability = (0, _util.createPromiseCapability)();
  9687. this._disableRange = source.disableRange || false;
  9688. this._rangeChunkSize = source.rangeChunkSize;
  9689. if (!this._rangeChunkSize && !this._disableRange) {
  9690. this._disableRange = true;
  9691. }
  9692. this._abortController = new AbortController();
  9693. this._isStreamingSupported = !source.disableStream;
  9694. this._isRangeSupported = !source.disableRange;
  9695. this._headers = createHeaders(this._stream.httpHeaders);
  9696. const url = source.url;
  9697. fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(response => {
  9698. if (!(0, _network_utils.validateResponseStatus)(response.status)) {
  9699. throw (0, _network_utils.createResponseStatusError)(response.status, url);
  9700. }
  9701. this._reader = response.body.getReader();
  9702. this._headersCapability.resolve();
  9703. const getResponseHeader = name => {
  9704. return response.headers.get(name);
  9705. };
  9706. const {
  9707. allowRangeRequests,
  9708. suggestedLength
  9709. } = (0, _network_utils.validateRangeRequestCapabilities)({
  9710. getResponseHeader,
  9711. isHttp: this._stream.isHttp,
  9712. rangeChunkSize: this._rangeChunkSize,
  9713. disableRange: this._disableRange
  9714. });
  9715. this._isRangeSupported = allowRangeRequests;
  9716. this._contentLength = suggestedLength || this._contentLength;
  9717. this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
  9718. if (!this._isStreamingSupported && this._isRangeSupported) {
  9719. this.cancel(new _util.AbortException("Streaming is disabled."));
  9720. }
  9721. }).catch(this._headersCapability.reject);
  9722. this.onProgress = null;
  9723. }
  9724. get headersReady() {
  9725. return this._headersCapability.promise;
  9726. }
  9727. get filename() {
  9728. return this._filename;
  9729. }
  9730. get contentLength() {
  9731. return this._contentLength;
  9732. }
  9733. get isRangeSupported() {
  9734. return this._isRangeSupported;
  9735. }
  9736. get isStreamingSupported() {
  9737. return this._isStreamingSupported;
  9738. }
  9739. async read() {
  9740. await this._headersCapability.promise;
  9741. const {
  9742. value,
  9743. done
  9744. } = await this._reader.read();
  9745. if (done) {
  9746. return {
  9747. value,
  9748. done
  9749. };
  9750. }
  9751. this._loaded += value.byteLength;
  9752. this.onProgress?.({
  9753. loaded: this._loaded,
  9754. total: this._contentLength
  9755. });
  9756. return {
  9757. value: getArrayBuffer(value),
  9758. done: false
  9759. };
  9760. }
  9761. cancel(reason) {
  9762. this._reader?.cancel(reason);
  9763. this._abortController.abort();
  9764. }
  9765. }
  9766. class PDFFetchStreamRangeReader {
  9767. constructor(stream, begin, end) {
  9768. this._stream = stream;
  9769. this._reader = null;
  9770. this._loaded = 0;
  9771. const source = stream.source;
  9772. this._withCredentials = source.withCredentials || false;
  9773. this._readCapability = (0, _util.createPromiseCapability)();
  9774. this._isStreamingSupported = !source.disableStream;
  9775. this._abortController = new AbortController();
  9776. this._headers = createHeaders(this._stream.httpHeaders);
  9777. this._headers.append("Range", `bytes=${begin}-${end - 1}`);
  9778. const url = source.url;
  9779. fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(response => {
  9780. if (!(0, _network_utils.validateResponseStatus)(response.status)) {
  9781. throw (0, _network_utils.createResponseStatusError)(response.status, url);
  9782. }
  9783. this._readCapability.resolve();
  9784. this._reader = response.body.getReader();
  9785. }).catch(this._readCapability.reject);
  9786. this.onProgress = null;
  9787. }
  9788. get isStreamingSupported() {
  9789. return this._isStreamingSupported;
  9790. }
  9791. async read() {
  9792. await this._readCapability.promise;
  9793. const {
  9794. value,
  9795. done
  9796. } = await this._reader.read();
  9797. if (done) {
  9798. return {
  9799. value,
  9800. done
  9801. };
  9802. }
  9803. this._loaded += value.byteLength;
  9804. this.onProgress?.({
  9805. loaded: this._loaded
  9806. });
  9807. return {
  9808. value: getArrayBuffer(value),
  9809. done: false
  9810. };
  9811. }
  9812. cancel(reason) {
  9813. this._reader?.cancel(reason);
  9814. this._abortController.abort();
  9815. }
  9816. }
  9817. /***/ }),
  9818. /* 26 */
  9819. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  9820. Object.defineProperty(exports, "__esModule", ({
  9821. value: true
  9822. }));
  9823. exports.TextLayerRenderTask = void 0;
  9824. exports.renderTextLayer = renderTextLayer;
  9825. exports.updateTextLayer = updateTextLayer;
  9826. var _util = __w_pdfjs_require__(1);
  9827. var _display_utils = __w_pdfjs_require__(6);
  9828. const MAX_TEXT_DIVS_TO_RENDER = 100000;
  9829. const DEFAULT_FONT_SIZE = 30;
  9830. const DEFAULT_FONT_ASCENT = 0.8;
  9831. const ascentCache = new Map();
  9832. function getCtx(size, isOffscreenCanvasSupported) {
  9833. let ctx;
  9834. if (isOffscreenCanvasSupported && _util.FeatureTest.isOffscreenCanvasSupported) {
  9835. ctx = new OffscreenCanvas(size, size).getContext("2d", {
  9836. alpha: false
  9837. });
  9838. } else {
  9839. const canvas = document.createElement("canvas");
  9840. canvas.width = canvas.height = size;
  9841. ctx = canvas.getContext("2d", {
  9842. alpha: false
  9843. });
  9844. }
  9845. return ctx;
  9846. }
  9847. function getAscent(fontFamily, isOffscreenCanvasSupported) {
  9848. const cachedAscent = ascentCache.get(fontFamily);
  9849. if (cachedAscent) {
  9850. return cachedAscent;
  9851. }
  9852. const ctx = getCtx(DEFAULT_FONT_SIZE, isOffscreenCanvasSupported);
  9853. ctx.font = `${DEFAULT_FONT_SIZE}px ${fontFamily}`;
  9854. const metrics = ctx.measureText("");
  9855. let ascent = metrics.fontBoundingBoxAscent;
  9856. let descent = Math.abs(metrics.fontBoundingBoxDescent);
  9857. if (ascent) {
  9858. const ratio = ascent / (ascent + descent);
  9859. ascentCache.set(fontFamily, ratio);
  9860. ctx.canvas.width = ctx.canvas.height = 0;
  9861. return ratio;
  9862. }
  9863. ctx.strokeStyle = "red";
  9864. ctx.clearRect(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE);
  9865. ctx.strokeText("g", 0, 0);
  9866. let pixels = ctx.getImageData(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE).data;
  9867. descent = 0;
  9868. for (let i = pixels.length - 1 - 3; i >= 0; i -= 4) {
  9869. if (pixels[i] > 0) {
  9870. descent = Math.ceil(i / 4 / DEFAULT_FONT_SIZE);
  9871. break;
  9872. }
  9873. }
  9874. ctx.clearRect(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE);
  9875. ctx.strokeText("A", 0, DEFAULT_FONT_SIZE);
  9876. pixels = ctx.getImageData(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE).data;
  9877. ascent = 0;
  9878. for (let i = 0, ii = pixels.length; i < ii; i += 4) {
  9879. if (pixels[i] > 0) {
  9880. ascent = DEFAULT_FONT_SIZE - Math.floor(i / 4 / DEFAULT_FONT_SIZE);
  9881. break;
  9882. }
  9883. }
  9884. ctx.canvas.width = ctx.canvas.height = 0;
  9885. if (ascent) {
  9886. const ratio = ascent / (ascent + descent);
  9887. ascentCache.set(fontFamily, ratio);
  9888. return ratio;
  9889. }
  9890. ascentCache.set(fontFamily, DEFAULT_FONT_ASCENT);
  9891. return DEFAULT_FONT_ASCENT;
  9892. }
  9893. function appendText(task, geom, styles) {
  9894. const textDiv = document.createElement("span");
  9895. const textDivProperties = {
  9896. angle: 0,
  9897. canvasWidth: 0,
  9898. hasText: geom.str !== "",
  9899. hasEOL: geom.hasEOL,
  9900. fontSize: 0
  9901. };
  9902. task._textDivs.push(textDiv);
  9903. const tx = _util.Util.transform(task._transform, geom.transform);
  9904. let angle = Math.atan2(tx[1], tx[0]);
  9905. const style = styles[geom.fontName];
  9906. if (style.vertical) {
  9907. angle += Math.PI / 2;
  9908. }
  9909. const fontHeight = Math.hypot(tx[2], tx[3]);
  9910. const fontAscent = fontHeight * getAscent(style.fontFamily, task._isOffscreenCanvasSupported);
  9911. let left, top;
  9912. if (angle === 0) {
  9913. left = tx[4];
  9914. top = tx[5] - fontAscent;
  9915. } else {
  9916. left = tx[4] + fontAscent * Math.sin(angle);
  9917. top = tx[5] - fontAscent * Math.cos(angle);
  9918. }
  9919. const scaleFactorStr = "calc(var(--scale-factor)*";
  9920. const divStyle = textDiv.style;
  9921. if (task._container === task._rootContainer) {
  9922. divStyle.left = `${(100 * left / task._pageWidth).toFixed(2)}%`;
  9923. divStyle.top = `${(100 * top / task._pageHeight).toFixed(2)}%`;
  9924. } else {
  9925. divStyle.left = `${scaleFactorStr}${left.toFixed(2)}px)`;
  9926. divStyle.top = `${scaleFactorStr}${top.toFixed(2)}px)`;
  9927. }
  9928. divStyle.fontSize = `${scaleFactorStr}${fontHeight.toFixed(2)}px)`;
  9929. divStyle.fontFamily = style.fontFamily;
  9930. textDivProperties.fontSize = fontHeight;
  9931. textDiv.setAttribute("role", "presentation");
  9932. textDiv.textContent = geom.str;
  9933. textDiv.dir = geom.dir;
  9934. if (task._fontInspectorEnabled) {
  9935. textDiv.dataset.fontName = geom.fontName;
  9936. }
  9937. if (angle !== 0) {
  9938. textDivProperties.angle = angle * (180 / Math.PI);
  9939. }
  9940. let shouldScaleText = false;
  9941. if (geom.str.length > 1) {
  9942. shouldScaleText = true;
  9943. } else if (geom.str !== " " && geom.transform[0] !== geom.transform[3]) {
  9944. const absScaleX = Math.abs(geom.transform[0]),
  9945. absScaleY = Math.abs(geom.transform[3]);
  9946. if (absScaleX !== absScaleY && Math.max(absScaleX, absScaleY) / Math.min(absScaleX, absScaleY) > 1.5) {
  9947. shouldScaleText = true;
  9948. }
  9949. }
  9950. if (shouldScaleText) {
  9951. textDivProperties.canvasWidth = style.vertical ? geom.height : geom.width;
  9952. }
  9953. task._textDivProperties.set(textDiv, textDivProperties);
  9954. if (task._isReadableStream) {
  9955. task._layoutText(textDiv);
  9956. }
  9957. }
  9958. function layout(params) {
  9959. const {
  9960. div,
  9961. scale,
  9962. properties,
  9963. ctx,
  9964. prevFontSize,
  9965. prevFontFamily
  9966. } = params;
  9967. const {
  9968. style
  9969. } = div;
  9970. let transform = "";
  9971. if (properties.canvasWidth !== 0 && properties.hasText) {
  9972. const {
  9973. fontFamily
  9974. } = style;
  9975. const {
  9976. canvasWidth,
  9977. fontSize
  9978. } = properties;
  9979. if (prevFontSize !== fontSize || prevFontFamily !== fontFamily) {
  9980. ctx.font = `${fontSize * scale}px ${fontFamily}`;
  9981. params.prevFontSize = fontSize;
  9982. params.prevFontFamily = fontFamily;
  9983. }
  9984. const {
  9985. width
  9986. } = ctx.measureText(div.textContent);
  9987. if (width > 0) {
  9988. transform = `scaleX(${canvasWidth * scale / width})`;
  9989. }
  9990. }
  9991. if (properties.angle !== 0) {
  9992. transform = `rotate(${properties.angle}deg) ${transform}`;
  9993. }
  9994. if (transform.length > 0) {
  9995. style.transform = transform;
  9996. }
  9997. }
  9998. function render(task) {
  9999. if (task._canceled) {
  10000. return;
  10001. }
  10002. const textDivs = task._textDivs;
  10003. const capability = task._capability;
  10004. const textDivsLength = textDivs.length;
  10005. if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
  10006. capability.resolve();
  10007. return;
  10008. }
  10009. if (!task._isReadableStream) {
  10010. for (const textDiv of textDivs) {
  10011. task._layoutText(textDiv);
  10012. }
  10013. }
  10014. capability.resolve();
  10015. }
  10016. class TextLayerRenderTask {
  10017. constructor({
  10018. textContentSource,
  10019. container,
  10020. viewport,
  10021. textDivs,
  10022. textDivProperties,
  10023. textContentItemsStr,
  10024. isOffscreenCanvasSupported
  10025. }) {
  10026. this._textContentSource = textContentSource;
  10027. this._isReadableStream = textContentSource instanceof ReadableStream;
  10028. this._container = this._rootContainer = container;
  10029. this._textDivs = textDivs || [];
  10030. this._textContentItemsStr = textContentItemsStr || [];
  10031. this._fontInspectorEnabled = !!globalThis.FontInspector?.enabled;
  10032. this._reader = null;
  10033. this._textDivProperties = textDivProperties || new WeakMap();
  10034. this._canceled = false;
  10035. this._capability = (0, _util.createPromiseCapability)();
  10036. this._layoutTextParams = {
  10037. prevFontSize: null,
  10038. prevFontFamily: null,
  10039. div: null,
  10040. scale: viewport.scale * (globalThis.devicePixelRatio || 1),
  10041. properties: null,
  10042. ctx: getCtx(0, isOffscreenCanvasSupported)
  10043. };
  10044. const {
  10045. pageWidth,
  10046. pageHeight,
  10047. pageX,
  10048. pageY
  10049. } = viewport.rawDims;
  10050. this._transform = [1, 0, 0, -1, -pageX, pageY + pageHeight];
  10051. this._pageWidth = pageWidth;
  10052. this._pageHeight = pageHeight;
  10053. (0, _display_utils.setLayerDimensions)(container, viewport);
  10054. this._capability.promise.finally(() => {
  10055. this._layoutTextParams = null;
  10056. }).catch(() => {});
  10057. }
  10058. get promise() {
  10059. return this._capability.promise;
  10060. }
  10061. cancel() {
  10062. this._canceled = true;
  10063. if (this._reader) {
  10064. this._reader.cancel(new _util.AbortException("TextLayer task cancelled.")).catch(() => {});
  10065. this._reader = null;
  10066. }
  10067. this._capability.reject(new _util.AbortException("TextLayer task cancelled."));
  10068. }
  10069. _processItems(items, styleCache) {
  10070. for (const item of items) {
  10071. if (item.str === undefined) {
  10072. if (item.type === "beginMarkedContentProps" || item.type === "beginMarkedContent") {
  10073. const parent = this._container;
  10074. this._container = document.createElement("span");
  10075. this._container.classList.add("markedContent");
  10076. if (item.id !== null) {
  10077. this._container.setAttribute("id", `${item.id}`);
  10078. }
  10079. parent.append(this._container);
  10080. } else if (item.type === "endMarkedContent") {
  10081. this._container = this._container.parentNode;
  10082. }
  10083. continue;
  10084. }
  10085. this._textContentItemsStr.push(item.str);
  10086. appendText(this, item, styleCache);
  10087. }
  10088. }
  10089. _layoutText(textDiv) {
  10090. const textDivProperties = this._layoutTextParams.properties = this._textDivProperties.get(textDiv);
  10091. this._layoutTextParams.div = textDiv;
  10092. layout(this._layoutTextParams);
  10093. if (textDivProperties.hasText) {
  10094. this._container.append(textDiv);
  10095. }
  10096. if (textDivProperties.hasEOL) {
  10097. const br = document.createElement("br");
  10098. br.setAttribute("role", "presentation");
  10099. this._container.append(br);
  10100. }
  10101. }
  10102. _render() {
  10103. const capability = (0, _util.createPromiseCapability)();
  10104. let styleCache = Object.create(null);
  10105. if (this._isReadableStream) {
  10106. const pump = () => {
  10107. this._reader.read().then(({
  10108. value,
  10109. done
  10110. }) => {
  10111. if (done) {
  10112. capability.resolve();
  10113. return;
  10114. }
  10115. Object.assign(styleCache, value.styles);
  10116. this._processItems(value.items, styleCache);
  10117. pump();
  10118. }, capability.reject);
  10119. };
  10120. this._reader = this._textContentSource.getReader();
  10121. pump();
  10122. } else if (this._textContentSource) {
  10123. const {
  10124. items,
  10125. styles
  10126. } = this._textContentSource;
  10127. this._processItems(items, styles);
  10128. capability.resolve();
  10129. } else {
  10130. throw new Error('No "textContentSource" parameter specified.');
  10131. }
  10132. capability.promise.then(() => {
  10133. styleCache = null;
  10134. render(this);
  10135. }, this._capability.reject);
  10136. }
  10137. }
  10138. exports.TextLayerRenderTask = TextLayerRenderTask;
  10139. function renderTextLayer(params) {
  10140. if (!params.textContentSource && (params.textContent || params.textContentStream)) {
  10141. (0, _display_utils.deprecated)("The TextLayerRender `textContent`/`textContentStream` parameters " + "will be removed in the future, please use `textContentSource` instead.");
  10142. params.textContentSource = params.textContent || params.textContentStream;
  10143. }
  10144. const task = new TextLayerRenderTask(params);
  10145. task._render();
  10146. return task;
  10147. }
  10148. function updateTextLayer({
  10149. container,
  10150. viewport,
  10151. textDivs,
  10152. textDivProperties,
  10153. isOffscreenCanvasSupported,
  10154. mustRotate = true,
  10155. mustRescale = true
  10156. }) {
  10157. if (mustRotate) {
  10158. (0, _display_utils.setLayerDimensions)(container, {
  10159. rotation: viewport.rotation
  10160. });
  10161. }
  10162. if (mustRescale) {
  10163. const ctx = getCtx(0, isOffscreenCanvasSupported);
  10164. const scale = viewport.scale * (globalThis.devicePixelRatio || 1);
  10165. const params = {
  10166. prevFontSize: null,
  10167. prevFontFamily: null,
  10168. div: null,
  10169. scale,
  10170. properties: null,
  10171. ctx
  10172. };
  10173. for (const div of textDivs) {
  10174. params.properties = textDivProperties.get(div);
  10175. params.div = div;
  10176. layout(params);
  10177. }
  10178. }
  10179. }
  10180. /***/ }),
  10181. /* 27 */
  10182. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  10183. Object.defineProperty(exports, "__esModule", ({
  10184. value: true
  10185. }));
  10186. exports.AnnotationEditorLayer = void 0;
  10187. var _util = __w_pdfjs_require__(1);
  10188. var _tools = __w_pdfjs_require__(5);
  10189. var _freetext = __w_pdfjs_require__(28);
  10190. var _ink = __w_pdfjs_require__(29);
  10191. var _display_utils = __w_pdfjs_require__(6);
  10192. class AnnotationEditorLayer {
  10193. #accessibilityManager;
  10194. #allowClick = false;
  10195. #boundPointerup = this.pointerup.bind(this);
  10196. #boundPointerdown = this.pointerdown.bind(this);
  10197. #editors = new Map();
  10198. #hadPointerDown = false;
  10199. #isCleaningUp = false;
  10200. #uiManager;
  10201. static _initialized = false;
  10202. constructor(options) {
  10203. if (!AnnotationEditorLayer._initialized) {
  10204. AnnotationEditorLayer._initialized = true;
  10205. _freetext.FreeTextEditor.initialize(options.l10n);
  10206. _ink.InkEditor.initialize(options.l10n);
  10207. }
  10208. options.uiManager.registerEditorTypes([_freetext.FreeTextEditor, _ink.InkEditor]);
  10209. this.#uiManager = options.uiManager;
  10210. this.pageIndex = options.pageIndex;
  10211. this.div = options.div;
  10212. this.#accessibilityManager = options.accessibilityManager;
  10213. this.#uiManager.addLayer(this);
  10214. }
  10215. updateToolbar(mode) {
  10216. this.#uiManager.updateToolbar(mode);
  10217. }
  10218. updateMode(mode = this.#uiManager.getMode()) {
  10219. this.#cleanup();
  10220. if (mode === _util.AnnotationEditorType.INK) {
  10221. this.addInkEditorIfNeeded(false);
  10222. this.disableClick();
  10223. } else {
  10224. this.enableClick();
  10225. }
  10226. this.#uiManager.unselectAll();
  10227. this.div.classList.toggle("freeTextEditing", mode === _util.AnnotationEditorType.FREETEXT);
  10228. this.div.classList.toggle("inkEditing", mode === _util.AnnotationEditorType.INK);
  10229. }
  10230. addInkEditorIfNeeded(isCommitting) {
  10231. if (!isCommitting && this.#uiManager.getMode() !== _util.AnnotationEditorType.INK) {
  10232. return;
  10233. }
  10234. if (!isCommitting) {
  10235. for (const editor of this.#editors.values()) {
  10236. if (editor.isEmpty()) {
  10237. editor.setInBackground();
  10238. return;
  10239. }
  10240. }
  10241. }
  10242. const editor = this.#createAndAddNewEditor({
  10243. offsetX: 0,
  10244. offsetY: 0
  10245. });
  10246. editor.setInBackground();
  10247. }
  10248. setEditingState(isEditing) {
  10249. this.#uiManager.setEditingState(isEditing);
  10250. }
  10251. addCommands(params) {
  10252. this.#uiManager.addCommands(params);
  10253. }
  10254. enable() {
  10255. this.div.style.pointerEvents = "auto";
  10256. for (const editor of this.#editors.values()) {
  10257. editor.enableEditing();
  10258. }
  10259. }
  10260. disable() {
  10261. this.div.style.pointerEvents = "none";
  10262. for (const editor of this.#editors.values()) {
  10263. editor.disableEditing();
  10264. }
  10265. }
  10266. setActiveEditor(editor) {
  10267. const currentActive = this.#uiManager.getActive();
  10268. if (currentActive === editor) {
  10269. return;
  10270. }
  10271. this.#uiManager.setActiveEditor(editor);
  10272. }
  10273. enableClick() {
  10274. this.div.addEventListener("pointerdown", this.#boundPointerdown);
  10275. this.div.addEventListener("pointerup", this.#boundPointerup);
  10276. }
  10277. disableClick() {
  10278. this.div.removeEventListener("pointerdown", this.#boundPointerdown);
  10279. this.div.removeEventListener("pointerup", this.#boundPointerup);
  10280. }
  10281. attach(editor) {
  10282. this.#editors.set(editor.id, editor);
  10283. }
  10284. detach(editor) {
  10285. this.#editors.delete(editor.id);
  10286. this.#accessibilityManager?.removePointerInTextLayer(editor.contentDiv);
  10287. }
  10288. remove(editor) {
  10289. this.#uiManager.removeEditor(editor);
  10290. this.detach(editor);
  10291. editor.div.style.display = "none";
  10292. setTimeout(() => {
  10293. editor.div.style.display = "";
  10294. editor.div.remove();
  10295. editor.isAttachedToDOM = false;
  10296. if (document.activeElement === document.body) {
  10297. this.#uiManager.focusMainContainer();
  10298. }
  10299. }, 0);
  10300. if (!this.#isCleaningUp) {
  10301. this.addInkEditorIfNeeded(false);
  10302. }
  10303. }
  10304. #changeParent(editor) {
  10305. if (editor.parent === this) {
  10306. return;
  10307. }
  10308. this.attach(editor);
  10309. editor.parent?.detach(editor);
  10310. editor.setParent(this);
  10311. if (editor.div && editor.isAttachedToDOM) {
  10312. editor.div.remove();
  10313. this.div.append(editor.div);
  10314. }
  10315. }
  10316. add(editor) {
  10317. this.#changeParent(editor);
  10318. this.#uiManager.addEditor(editor);
  10319. this.attach(editor);
  10320. if (!editor.isAttachedToDOM) {
  10321. const div = editor.render();
  10322. this.div.append(div);
  10323. editor.isAttachedToDOM = true;
  10324. }
  10325. this.moveEditorInDOM(editor);
  10326. editor.onceAdded();
  10327. this.#uiManager.addToAnnotationStorage(editor);
  10328. }
  10329. moveEditorInDOM(editor) {
  10330. this.#accessibilityManager?.moveElementInDOM(this.div, editor.div, editor.contentDiv, true);
  10331. }
  10332. addOrRebuild(editor) {
  10333. if (editor.needsToBeRebuilt()) {
  10334. editor.rebuild();
  10335. } else {
  10336. this.add(editor);
  10337. }
  10338. }
  10339. addANewEditor(editor) {
  10340. const cmd = () => {
  10341. this.addOrRebuild(editor);
  10342. };
  10343. const undo = () => {
  10344. editor.remove();
  10345. };
  10346. this.addCommands({
  10347. cmd,
  10348. undo,
  10349. mustExec: true
  10350. });
  10351. }
  10352. addUndoableEditor(editor) {
  10353. const cmd = () => {
  10354. this.addOrRebuild(editor);
  10355. };
  10356. const undo = () => {
  10357. editor.remove();
  10358. };
  10359. this.addCommands({
  10360. cmd,
  10361. undo,
  10362. mustExec: false
  10363. });
  10364. }
  10365. getNextId() {
  10366. return this.#uiManager.getId();
  10367. }
  10368. #createNewEditor(params) {
  10369. switch (this.#uiManager.getMode()) {
  10370. case _util.AnnotationEditorType.FREETEXT:
  10371. return new _freetext.FreeTextEditor(params);
  10372. case _util.AnnotationEditorType.INK:
  10373. return new _ink.InkEditor(params);
  10374. }
  10375. return null;
  10376. }
  10377. deserialize(data) {
  10378. switch (data.annotationType) {
  10379. case _util.AnnotationEditorType.FREETEXT:
  10380. return _freetext.FreeTextEditor.deserialize(data, this, this.#uiManager);
  10381. case _util.AnnotationEditorType.INK:
  10382. return _ink.InkEditor.deserialize(data, this, this.#uiManager);
  10383. }
  10384. return null;
  10385. }
  10386. #createAndAddNewEditor(event) {
  10387. const id = this.getNextId();
  10388. const editor = this.#createNewEditor({
  10389. parent: this,
  10390. id,
  10391. x: event.offsetX,
  10392. y: event.offsetY,
  10393. uiManager: this.#uiManager
  10394. });
  10395. if (editor) {
  10396. this.add(editor);
  10397. }
  10398. return editor;
  10399. }
  10400. setSelected(editor) {
  10401. this.#uiManager.setSelected(editor);
  10402. }
  10403. toggleSelected(editor) {
  10404. this.#uiManager.toggleSelected(editor);
  10405. }
  10406. isSelected(editor) {
  10407. return this.#uiManager.isSelected(editor);
  10408. }
  10409. unselect(editor) {
  10410. this.#uiManager.unselect(editor);
  10411. }
  10412. pointerup(event) {
  10413. const {
  10414. isMac
  10415. } = _util.FeatureTest.platform;
  10416. if (event.button !== 0 || event.ctrlKey && isMac) {
  10417. return;
  10418. }
  10419. if (event.target !== this.div) {
  10420. return;
  10421. }
  10422. if (!this.#hadPointerDown) {
  10423. return;
  10424. }
  10425. this.#hadPointerDown = false;
  10426. if (!this.#allowClick) {
  10427. this.#allowClick = true;
  10428. return;
  10429. }
  10430. this.#createAndAddNewEditor(event);
  10431. }
  10432. pointerdown(event) {
  10433. const {
  10434. isMac
  10435. } = _util.FeatureTest.platform;
  10436. if (event.button !== 0 || event.ctrlKey && isMac) {
  10437. return;
  10438. }
  10439. if (event.target !== this.div) {
  10440. return;
  10441. }
  10442. this.#hadPointerDown = true;
  10443. const editor = this.#uiManager.getActive();
  10444. this.#allowClick = !editor || editor.isEmpty();
  10445. }
  10446. drop(event) {
  10447. const id = event.dataTransfer.getData("text/plain");
  10448. const editor = this.#uiManager.getEditor(id);
  10449. if (!editor) {
  10450. return;
  10451. }
  10452. event.preventDefault();
  10453. event.dataTransfer.dropEffect = "move";
  10454. this.#changeParent(editor);
  10455. const rect = this.div.getBoundingClientRect();
  10456. const endX = event.clientX - rect.x;
  10457. const endY = event.clientY - rect.y;
  10458. editor.translate(endX - editor.startX, endY - editor.startY);
  10459. this.moveEditorInDOM(editor);
  10460. editor.div.focus();
  10461. }
  10462. dragover(event) {
  10463. event.preventDefault();
  10464. }
  10465. destroy() {
  10466. if (this.#uiManager.getActive()?.parent === this) {
  10467. this.#uiManager.setActiveEditor(null);
  10468. }
  10469. for (const editor of this.#editors.values()) {
  10470. this.#accessibilityManager?.removePointerInTextLayer(editor.contentDiv);
  10471. editor.setParent(null);
  10472. editor.isAttachedToDOM = false;
  10473. editor.div.remove();
  10474. }
  10475. this.div = null;
  10476. this.#editors.clear();
  10477. this.#uiManager.removeLayer(this);
  10478. }
  10479. #cleanup() {
  10480. this.#isCleaningUp = true;
  10481. for (const editor of this.#editors.values()) {
  10482. if (editor.isEmpty()) {
  10483. editor.remove();
  10484. }
  10485. }
  10486. this.#isCleaningUp = false;
  10487. }
  10488. render({
  10489. viewport
  10490. }) {
  10491. this.viewport = viewport;
  10492. (0, _display_utils.setLayerDimensions)(this.div, viewport);
  10493. (0, _tools.bindEvents)(this, this.div, ["dragover", "drop"]);
  10494. for (const editor of this.#uiManager.getEditors(this.pageIndex)) {
  10495. this.add(editor);
  10496. }
  10497. this.updateMode();
  10498. }
  10499. update({
  10500. viewport
  10501. }) {
  10502. this.#uiManager.commitOrRemove();
  10503. this.viewport = viewport;
  10504. (0, _display_utils.setLayerDimensions)(this.div, {
  10505. rotation: viewport.rotation
  10506. });
  10507. this.updateMode();
  10508. }
  10509. get pageDimensions() {
  10510. const {
  10511. pageWidth,
  10512. pageHeight
  10513. } = this.viewport.rawDims;
  10514. return [pageWidth, pageHeight];
  10515. }
  10516. }
  10517. exports.AnnotationEditorLayer = AnnotationEditorLayer;
  10518. /***/ }),
  10519. /* 28 */
  10520. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  10521. Object.defineProperty(exports, "__esModule", ({
  10522. value: true
  10523. }));
  10524. exports.FreeTextEditor = void 0;
  10525. var _util = __w_pdfjs_require__(1);
  10526. var _tools = __w_pdfjs_require__(5);
  10527. var _editor = __w_pdfjs_require__(4);
  10528. class FreeTextEditor extends _editor.AnnotationEditor {
  10529. #boundEditorDivBlur = this.editorDivBlur.bind(this);
  10530. #boundEditorDivFocus = this.editorDivFocus.bind(this);
  10531. #boundEditorDivInput = this.editorDivInput.bind(this);
  10532. #boundEditorDivKeydown = this.editorDivKeydown.bind(this);
  10533. #color;
  10534. #content = "";
  10535. #editorDivId = `${this.id}-editor`;
  10536. #hasAlreadyBeenCommitted = false;
  10537. #fontSize;
  10538. static _freeTextDefaultContent = "";
  10539. static _l10nPromise;
  10540. static _internalPadding = 0;
  10541. static _defaultColor = null;
  10542. static _defaultFontSize = 10;
  10543. static _keyboardManager = new _tools.KeyboardManager([[["ctrl+Enter", "mac+meta+Enter", "Escape", "mac+Escape"], FreeTextEditor.prototype.commitOrRemove]]);
  10544. static _type = "freetext";
  10545. constructor(params) {
  10546. super({
  10547. ...params,
  10548. name: "freeTextEditor"
  10549. });
  10550. this.#color = params.color || FreeTextEditor._defaultColor || _editor.AnnotationEditor._defaultLineColor;
  10551. this.#fontSize = params.fontSize || FreeTextEditor._defaultFontSize;
  10552. }
  10553. static initialize(l10n) {
  10554. this._l10nPromise = new Map(["free_text2_default_content", "editor_free_text2_aria_label"].map(str => [str, l10n.get(str)]));
  10555. const style = getComputedStyle(document.documentElement);
  10556. this._internalPadding = parseFloat(style.getPropertyValue("--freetext-padding"));
  10557. }
  10558. static updateDefaultParams(type, value) {
  10559. switch (type) {
  10560. case _util.AnnotationEditorParamsType.FREETEXT_SIZE:
  10561. FreeTextEditor._defaultFontSize = value;
  10562. break;
  10563. case _util.AnnotationEditorParamsType.FREETEXT_COLOR:
  10564. FreeTextEditor._defaultColor = value;
  10565. break;
  10566. }
  10567. }
  10568. updateParams(type, value) {
  10569. switch (type) {
  10570. case _util.AnnotationEditorParamsType.FREETEXT_SIZE:
  10571. this.#updateFontSize(value);
  10572. break;
  10573. case _util.AnnotationEditorParamsType.FREETEXT_COLOR:
  10574. this.#updateColor(value);
  10575. break;
  10576. }
  10577. }
  10578. static get defaultPropertiesToUpdate() {
  10579. return [[_util.AnnotationEditorParamsType.FREETEXT_SIZE, FreeTextEditor._defaultFontSize], [_util.AnnotationEditorParamsType.FREETEXT_COLOR, FreeTextEditor._defaultColor || _editor.AnnotationEditor._defaultLineColor]];
  10580. }
  10581. get propertiesToUpdate() {
  10582. return [[_util.AnnotationEditorParamsType.FREETEXT_SIZE, this.#fontSize], [_util.AnnotationEditorParamsType.FREETEXT_COLOR, this.#color]];
  10583. }
  10584. #updateFontSize(fontSize) {
  10585. const setFontsize = size => {
  10586. this.editorDiv.style.fontSize = `calc(${size}px * var(--scale-factor))`;
  10587. this.translate(0, -(size - this.#fontSize) * this.parentScale);
  10588. this.#fontSize = size;
  10589. this.#setEditorDimensions();
  10590. };
  10591. const savedFontsize = this.#fontSize;
  10592. this.addCommands({
  10593. cmd: () => {
  10594. setFontsize(fontSize);
  10595. },
  10596. undo: () => {
  10597. setFontsize(savedFontsize);
  10598. },
  10599. mustExec: true,
  10600. type: _util.AnnotationEditorParamsType.FREETEXT_SIZE,
  10601. overwriteIfSameType: true,
  10602. keepUndo: true
  10603. });
  10604. }
  10605. #updateColor(color) {
  10606. const savedColor = this.#color;
  10607. this.addCommands({
  10608. cmd: () => {
  10609. this.#color = this.editorDiv.style.color = color;
  10610. },
  10611. undo: () => {
  10612. this.#color = this.editorDiv.style.color = savedColor;
  10613. },
  10614. mustExec: true,
  10615. type: _util.AnnotationEditorParamsType.FREETEXT_COLOR,
  10616. overwriteIfSameType: true,
  10617. keepUndo: true
  10618. });
  10619. }
  10620. getInitialTranslation() {
  10621. const scale = this.parentScale;
  10622. return [-FreeTextEditor._internalPadding * scale, -(FreeTextEditor._internalPadding + this.#fontSize) * scale];
  10623. }
  10624. rebuild() {
  10625. super.rebuild();
  10626. if (this.div === null) {
  10627. return;
  10628. }
  10629. if (!this.isAttachedToDOM) {
  10630. this.parent.add(this);
  10631. }
  10632. }
  10633. enableEditMode() {
  10634. if (this.isInEditMode()) {
  10635. return;
  10636. }
  10637. this.parent.setEditingState(false);
  10638. this.parent.updateToolbar(_util.AnnotationEditorType.FREETEXT);
  10639. super.enableEditMode();
  10640. this.overlayDiv.classList.remove("enabled");
  10641. this.editorDiv.contentEditable = true;
  10642. this.div.draggable = false;
  10643. this.div.removeAttribute("aria-activedescendant");
  10644. this.editorDiv.addEventListener("keydown", this.#boundEditorDivKeydown);
  10645. this.editorDiv.addEventListener("focus", this.#boundEditorDivFocus);
  10646. this.editorDiv.addEventListener("blur", this.#boundEditorDivBlur);
  10647. this.editorDiv.addEventListener("input", this.#boundEditorDivInput);
  10648. }
  10649. disableEditMode() {
  10650. if (!this.isInEditMode()) {
  10651. return;
  10652. }
  10653. this.parent.setEditingState(true);
  10654. super.disableEditMode();
  10655. this.overlayDiv.classList.add("enabled");
  10656. this.editorDiv.contentEditable = false;
  10657. this.div.setAttribute("aria-activedescendant", this.#editorDivId);
  10658. this.div.draggable = true;
  10659. this.editorDiv.removeEventListener("keydown", this.#boundEditorDivKeydown);
  10660. this.editorDiv.removeEventListener("focus", this.#boundEditorDivFocus);
  10661. this.editorDiv.removeEventListener("blur", this.#boundEditorDivBlur);
  10662. this.editorDiv.removeEventListener("input", this.#boundEditorDivInput);
  10663. this.div.focus({
  10664. preventScroll: true
  10665. });
  10666. this.isEditing = false;
  10667. this.parent.div.classList.add("freeTextEditing");
  10668. }
  10669. focusin(event) {
  10670. super.focusin(event);
  10671. if (event.target !== this.editorDiv) {
  10672. this.editorDiv.focus();
  10673. }
  10674. }
  10675. onceAdded() {
  10676. if (this.width) {
  10677. return;
  10678. }
  10679. this.enableEditMode();
  10680. this.editorDiv.focus();
  10681. }
  10682. isEmpty() {
  10683. return !this.editorDiv || this.editorDiv.innerText.trim() === "";
  10684. }
  10685. remove() {
  10686. this.isEditing = false;
  10687. this.parent.setEditingState(true);
  10688. this.parent.div.classList.add("freeTextEditing");
  10689. super.remove();
  10690. }
  10691. #extractText() {
  10692. const divs = this.editorDiv.getElementsByTagName("div");
  10693. if (divs.length === 0) {
  10694. return this.editorDiv.innerText;
  10695. }
  10696. const buffer = [];
  10697. for (const div of divs) {
  10698. buffer.push(div.innerText.replace(/\r\n?|\n/, ""));
  10699. }
  10700. return buffer.join("\n");
  10701. }
  10702. #setEditorDimensions() {
  10703. const [parentWidth, parentHeight] = this.parentDimensions;
  10704. let rect;
  10705. if (this.isAttachedToDOM) {
  10706. rect = this.div.getBoundingClientRect();
  10707. } else {
  10708. const {
  10709. currentLayer,
  10710. div
  10711. } = this;
  10712. const savedDisplay = div.style.display;
  10713. div.style.display = "hidden";
  10714. currentLayer.div.append(this.div);
  10715. rect = div.getBoundingClientRect();
  10716. div.remove();
  10717. div.style.display = savedDisplay;
  10718. }
  10719. this.width = rect.width / parentWidth;
  10720. this.height = rect.height / parentHeight;
  10721. }
  10722. commit() {
  10723. if (!this.isInEditMode()) {
  10724. return;
  10725. }
  10726. super.commit();
  10727. if (!this.#hasAlreadyBeenCommitted) {
  10728. this.#hasAlreadyBeenCommitted = true;
  10729. this.parent.addUndoableEditor(this);
  10730. }
  10731. this.disableEditMode();
  10732. this.#content = this.#extractText().trimEnd();
  10733. this.#setEditorDimensions();
  10734. }
  10735. shouldGetKeyboardEvents() {
  10736. return this.isInEditMode();
  10737. }
  10738. dblclick(event) {
  10739. this.enableEditMode();
  10740. this.editorDiv.focus();
  10741. }
  10742. keydown(event) {
  10743. if (event.target === this.div && event.key === "Enter") {
  10744. this.enableEditMode();
  10745. this.editorDiv.focus();
  10746. }
  10747. }
  10748. editorDivKeydown(event) {
  10749. FreeTextEditor._keyboardManager.exec(this, event);
  10750. }
  10751. editorDivFocus(event) {
  10752. this.isEditing = true;
  10753. }
  10754. editorDivBlur(event) {
  10755. this.isEditing = false;
  10756. }
  10757. editorDivInput(event) {
  10758. this.parent.div.classList.toggle("freeTextEditing", this.isEmpty());
  10759. }
  10760. disableEditing() {
  10761. this.editorDiv.setAttribute("role", "comment");
  10762. this.editorDiv.removeAttribute("aria-multiline");
  10763. }
  10764. enableEditing() {
  10765. this.editorDiv.setAttribute("role", "textbox");
  10766. this.editorDiv.setAttribute("aria-multiline", true);
  10767. }
  10768. render() {
  10769. if (this.div) {
  10770. return this.div;
  10771. }
  10772. let baseX, baseY;
  10773. if (this.width) {
  10774. baseX = this.x;
  10775. baseY = this.y;
  10776. }
  10777. super.render();
  10778. this.editorDiv = document.createElement("div");
  10779. this.editorDiv.className = "internal";
  10780. this.editorDiv.setAttribute("id", this.#editorDivId);
  10781. this.enableEditing();
  10782. FreeTextEditor._l10nPromise.get("editor_free_text2_aria_label").then(msg => this.editorDiv?.setAttribute("aria-label", msg));
  10783. FreeTextEditor._l10nPromise.get("free_text2_default_content").then(msg => this.editorDiv?.setAttribute("default-content", msg));
  10784. this.editorDiv.contentEditable = true;
  10785. const {
  10786. style
  10787. } = this.editorDiv;
  10788. style.fontSize = `calc(${this.#fontSize}px * var(--scale-factor))`;
  10789. style.color = this.#color;
  10790. this.div.append(this.editorDiv);
  10791. this.overlayDiv = document.createElement("div");
  10792. this.overlayDiv.classList.add("overlay", "enabled");
  10793. this.div.append(this.overlayDiv);
  10794. (0, _tools.bindEvents)(this, this.div, ["dblclick", "keydown"]);
  10795. if (this.width) {
  10796. const [parentWidth, parentHeight] = this.parentDimensions;
  10797. this.setAt(baseX * parentWidth, baseY * parentHeight, this.width * parentWidth, this.height * parentHeight);
  10798. for (const line of this.#content.split("\n")) {
  10799. const div = document.createElement("div");
  10800. div.append(line ? document.createTextNode(line) : document.createElement("br"));
  10801. this.editorDiv.append(div);
  10802. }
  10803. this.div.draggable = true;
  10804. this.editorDiv.contentEditable = false;
  10805. } else {
  10806. this.div.draggable = false;
  10807. this.editorDiv.contentEditable = true;
  10808. }
  10809. return this.div;
  10810. }
  10811. get contentDiv() {
  10812. return this.editorDiv;
  10813. }
  10814. static deserialize(data, parent, uiManager) {
  10815. const editor = super.deserialize(data, parent, uiManager);
  10816. editor.#fontSize = data.fontSize;
  10817. editor.#color = _util.Util.makeHexColor(...data.color);
  10818. editor.#content = data.value;
  10819. return editor;
  10820. }
  10821. serialize() {
  10822. if (this.isEmpty()) {
  10823. return null;
  10824. }
  10825. const padding = FreeTextEditor._internalPadding * this.parentScale;
  10826. const rect = this.getRect(padding, padding);
  10827. const color = _editor.AnnotationEditor._colorManager.convert(this.isAttachedToDOM ? getComputedStyle(this.editorDiv).color : this.#color);
  10828. return {
  10829. annotationType: _util.AnnotationEditorType.FREETEXT,
  10830. color,
  10831. fontSize: this.#fontSize,
  10832. value: this.#content,
  10833. pageIndex: this.pageIndex,
  10834. rect,
  10835. rotation: this.rotation
  10836. };
  10837. }
  10838. }
  10839. exports.FreeTextEditor = FreeTextEditor;
  10840. /***/ }),
  10841. /* 29 */
  10842. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  10843. Object.defineProperty(exports, "__esModule", ({
  10844. value: true
  10845. }));
  10846. exports.InkEditor = void 0;
  10847. Object.defineProperty(exports, "fitCurve", ({
  10848. enumerable: true,
  10849. get: function () {
  10850. return _pdfjsFitCurve.fitCurve;
  10851. }
  10852. }));
  10853. var _util = __w_pdfjs_require__(1);
  10854. var _editor = __w_pdfjs_require__(4);
  10855. var _pdfjsFitCurve = __w_pdfjs_require__(30);
  10856. var _tools = __w_pdfjs_require__(5);
  10857. const RESIZER_SIZE = 16;
  10858. const TIME_TO_WAIT_BEFORE_FIXING_DIMS = 100;
  10859. class InkEditor extends _editor.AnnotationEditor {
  10860. #aspectRatio = 0;
  10861. #baseHeight = 0;
  10862. #baseWidth = 0;
  10863. #boundCanvasPointermove = this.canvasPointermove.bind(this);
  10864. #boundCanvasPointerleave = this.canvasPointerleave.bind(this);
  10865. #boundCanvasPointerup = this.canvasPointerup.bind(this);
  10866. #boundCanvasPointerdown = this.canvasPointerdown.bind(this);
  10867. #disableEditing = false;
  10868. #isCanvasInitialized = false;
  10869. #lastPoint = null;
  10870. #observer = null;
  10871. #realWidth = 0;
  10872. #realHeight = 0;
  10873. #requestFrameCallback = null;
  10874. static _defaultColor = null;
  10875. static _defaultOpacity = 1;
  10876. static _defaultThickness = 1;
  10877. static _l10nPromise;
  10878. static _type = "ink";
  10879. constructor(params) {
  10880. super({
  10881. ...params,
  10882. name: "inkEditor"
  10883. });
  10884. this.color = params.color || null;
  10885. this.thickness = params.thickness || null;
  10886. this.opacity = params.opacity || null;
  10887. this.paths = [];
  10888. this.bezierPath2D = [];
  10889. this.currentPath = [];
  10890. this.scaleFactor = 1;
  10891. this.translationX = this.translationY = 0;
  10892. this.x = 0;
  10893. this.y = 0;
  10894. }
  10895. static initialize(l10n) {
  10896. this._l10nPromise = new Map(["editor_ink_canvas_aria_label", "editor_ink2_aria_label"].map(str => [str, l10n.get(str)]));
  10897. }
  10898. static updateDefaultParams(type, value) {
  10899. switch (type) {
  10900. case _util.AnnotationEditorParamsType.INK_THICKNESS:
  10901. InkEditor._defaultThickness = value;
  10902. break;
  10903. case _util.AnnotationEditorParamsType.INK_COLOR:
  10904. InkEditor._defaultColor = value;
  10905. break;
  10906. case _util.AnnotationEditorParamsType.INK_OPACITY:
  10907. InkEditor._defaultOpacity = value / 100;
  10908. break;
  10909. }
  10910. }
  10911. updateParams(type, value) {
  10912. switch (type) {
  10913. case _util.AnnotationEditorParamsType.INK_THICKNESS:
  10914. this.#updateThickness(value);
  10915. break;
  10916. case _util.AnnotationEditorParamsType.INK_COLOR:
  10917. this.#updateColor(value);
  10918. break;
  10919. case _util.AnnotationEditorParamsType.INK_OPACITY:
  10920. this.#updateOpacity(value);
  10921. break;
  10922. }
  10923. }
  10924. static get defaultPropertiesToUpdate() {
  10925. 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)]];
  10926. }
  10927. get propertiesToUpdate() {
  10928. 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))]];
  10929. }
  10930. #updateThickness(thickness) {
  10931. const savedThickness = this.thickness;
  10932. this.addCommands({
  10933. cmd: () => {
  10934. this.thickness = thickness;
  10935. this.#fitToContent();
  10936. },
  10937. undo: () => {
  10938. this.thickness = savedThickness;
  10939. this.#fitToContent();
  10940. },
  10941. mustExec: true,
  10942. type: _util.AnnotationEditorParamsType.INK_THICKNESS,
  10943. overwriteIfSameType: true,
  10944. keepUndo: true
  10945. });
  10946. }
  10947. #updateColor(color) {
  10948. const savedColor = this.color;
  10949. this.addCommands({
  10950. cmd: () => {
  10951. this.color = color;
  10952. this.#redraw();
  10953. },
  10954. undo: () => {
  10955. this.color = savedColor;
  10956. this.#redraw();
  10957. },
  10958. mustExec: true,
  10959. type: _util.AnnotationEditorParamsType.INK_COLOR,
  10960. overwriteIfSameType: true,
  10961. keepUndo: true
  10962. });
  10963. }
  10964. #updateOpacity(opacity) {
  10965. opacity /= 100;
  10966. const savedOpacity = this.opacity;
  10967. this.addCommands({
  10968. cmd: () => {
  10969. this.opacity = opacity;
  10970. this.#redraw();
  10971. },
  10972. undo: () => {
  10973. this.opacity = savedOpacity;
  10974. this.#redraw();
  10975. },
  10976. mustExec: true,
  10977. type: _util.AnnotationEditorParamsType.INK_OPACITY,
  10978. overwriteIfSameType: true,
  10979. keepUndo: true
  10980. });
  10981. }
  10982. rebuild() {
  10983. super.rebuild();
  10984. if (this.div === null) {
  10985. return;
  10986. }
  10987. if (!this.canvas) {
  10988. this.#createCanvas();
  10989. this.#createObserver();
  10990. }
  10991. if (!this.isAttachedToDOM) {
  10992. this.parent.add(this);
  10993. this.#setCanvasDims();
  10994. }
  10995. this.#fitToContent();
  10996. }
  10997. remove() {
  10998. if (this.canvas === null) {
  10999. return;
  11000. }
  11001. if (!this.isEmpty()) {
  11002. this.commit();
  11003. }
  11004. this.canvas.width = this.canvas.height = 0;
  11005. this.canvas.remove();
  11006. this.canvas = null;
  11007. this.#observer.disconnect();
  11008. this.#observer = null;
  11009. super.remove();
  11010. }
  11011. setParent(parent) {
  11012. if (!this.parent && parent) {
  11013. this._uiManager.removeShouldRescale(this);
  11014. } else if (this.parent && parent === null) {
  11015. this._uiManager.addShouldRescale(this);
  11016. }
  11017. super.setParent(parent);
  11018. }
  11019. onScaleChanging() {
  11020. const [parentWidth, parentHeight] = this.parentDimensions;
  11021. const width = this.width * parentWidth;
  11022. const height = this.height * parentHeight;
  11023. this.setDimensions(width, height);
  11024. }
  11025. enableEditMode() {
  11026. if (this.#disableEditing || this.canvas === null) {
  11027. return;
  11028. }
  11029. super.enableEditMode();
  11030. this.div.draggable = false;
  11031. this.canvas.addEventListener("pointerdown", this.#boundCanvasPointerdown);
  11032. this.canvas.addEventListener("pointerup", this.#boundCanvasPointerup);
  11033. }
  11034. disableEditMode() {
  11035. if (!this.isInEditMode() || this.canvas === null) {
  11036. return;
  11037. }
  11038. super.disableEditMode();
  11039. this.div.draggable = !this.isEmpty();
  11040. this.div.classList.remove("editing");
  11041. this.canvas.removeEventListener("pointerdown", this.#boundCanvasPointerdown);
  11042. this.canvas.removeEventListener("pointerup", this.#boundCanvasPointerup);
  11043. }
  11044. onceAdded() {
  11045. this.div.draggable = !this.isEmpty();
  11046. }
  11047. isEmpty() {
  11048. return this.paths.length === 0 || this.paths.length === 1 && this.paths[0].length === 0;
  11049. }
  11050. #getInitialBBox() {
  11051. const {
  11052. parentRotation,
  11053. parentDimensions: [width, height]
  11054. } = this;
  11055. switch (parentRotation) {
  11056. case 90:
  11057. return [0, height, height, width];
  11058. case 180:
  11059. return [width, height, width, height];
  11060. case 270:
  11061. return [width, 0, height, width];
  11062. default:
  11063. return [0, 0, width, height];
  11064. }
  11065. }
  11066. #setStroke() {
  11067. const {
  11068. ctx,
  11069. color,
  11070. opacity,
  11071. thickness,
  11072. parentScale,
  11073. scaleFactor
  11074. } = this;
  11075. ctx.lineWidth = thickness * parentScale / scaleFactor;
  11076. ctx.lineCap = "round";
  11077. ctx.lineJoin = "round";
  11078. ctx.miterLimit = 10;
  11079. ctx.strokeStyle = `${color}${(0, _tools.opacityToHex)(opacity)}`;
  11080. }
  11081. #startDrawing(x, y) {
  11082. this.isEditing = true;
  11083. if (!this.#isCanvasInitialized) {
  11084. this.#isCanvasInitialized = true;
  11085. this.#setCanvasDims();
  11086. this.thickness ||= InkEditor._defaultThickness;
  11087. this.color ||= InkEditor._defaultColor || _editor.AnnotationEditor._defaultLineColor;
  11088. this.opacity ??= InkEditor._defaultOpacity;
  11089. }
  11090. this.currentPath.push([x, y]);
  11091. this.#lastPoint = null;
  11092. this.#setStroke();
  11093. this.ctx.beginPath();
  11094. this.ctx.moveTo(x, y);
  11095. this.#requestFrameCallback = () => {
  11096. if (!this.#requestFrameCallback) {
  11097. return;
  11098. }
  11099. if (this.#lastPoint) {
  11100. if (this.isEmpty()) {
  11101. this.ctx.setTransform(1, 0, 0, 1, 0, 0);
  11102. this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
  11103. } else {
  11104. this.#redraw();
  11105. }
  11106. this.ctx.lineTo(...this.#lastPoint);
  11107. this.#lastPoint = null;
  11108. this.ctx.stroke();
  11109. }
  11110. window.requestAnimationFrame(this.#requestFrameCallback);
  11111. };
  11112. window.requestAnimationFrame(this.#requestFrameCallback);
  11113. }
  11114. #draw(x, y) {
  11115. const [lastX, lastY] = this.currentPath.at(-1);
  11116. if (x === lastX && y === lastY) {
  11117. return;
  11118. }
  11119. this.currentPath.push([x, y]);
  11120. this.#lastPoint = [x, y];
  11121. }
  11122. #stopDrawing(x, y) {
  11123. this.ctx.closePath();
  11124. this.#requestFrameCallback = null;
  11125. x = Math.min(Math.max(x, 0), this.canvas.width);
  11126. y = Math.min(Math.max(y, 0), this.canvas.height);
  11127. const [lastX, lastY] = this.currentPath.at(-1);
  11128. if (x !== lastX || y !== lastY) {
  11129. this.currentPath.push([x, y]);
  11130. }
  11131. let bezier;
  11132. if (this.currentPath.length !== 1) {
  11133. bezier = (0, _pdfjsFitCurve.fitCurve)(this.currentPath, 30, null);
  11134. } else {
  11135. const xy = [x, y];
  11136. bezier = [[xy, xy.slice(), xy.slice(), xy]];
  11137. }
  11138. const path2D = InkEditor.#buildPath2D(bezier);
  11139. this.currentPath.length = 0;
  11140. const cmd = () => {
  11141. this.paths.push(bezier);
  11142. this.bezierPath2D.push(path2D);
  11143. this.rebuild();
  11144. };
  11145. const undo = () => {
  11146. this.paths.pop();
  11147. this.bezierPath2D.pop();
  11148. if (this.paths.length === 0) {
  11149. this.remove();
  11150. } else {
  11151. if (!this.canvas) {
  11152. this.#createCanvas();
  11153. this.#createObserver();
  11154. }
  11155. this.#fitToContent();
  11156. }
  11157. };
  11158. this.addCommands({
  11159. cmd,
  11160. undo,
  11161. mustExec: true
  11162. });
  11163. }
  11164. #redraw() {
  11165. if (this.isEmpty()) {
  11166. this.#updateTransform();
  11167. return;
  11168. }
  11169. this.#setStroke();
  11170. const {
  11171. canvas,
  11172. ctx
  11173. } = this;
  11174. ctx.setTransform(1, 0, 0, 1, 0, 0);
  11175. ctx.clearRect(0, 0, canvas.width, canvas.height);
  11176. this.#updateTransform();
  11177. for (const path of this.bezierPath2D) {
  11178. ctx.stroke(path);
  11179. }
  11180. }
  11181. commit() {
  11182. if (this.#disableEditing) {
  11183. return;
  11184. }
  11185. super.commit();
  11186. this.isEditing = false;
  11187. this.disableEditMode();
  11188. this.setInForeground();
  11189. this.#disableEditing = true;
  11190. this.div.classList.add("disabled");
  11191. this.#fitToContent(true);
  11192. this.parent.addInkEditorIfNeeded(true);
  11193. this.parent.moveEditorInDOM(this);
  11194. this.div.focus({
  11195. preventScroll: true
  11196. });
  11197. }
  11198. focusin(event) {
  11199. super.focusin(event);
  11200. this.enableEditMode();
  11201. }
  11202. canvasPointerdown(event) {
  11203. if (event.button !== 0 || !this.isInEditMode() || this.#disableEditing) {
  11204. return;
  11205. }
  11206. this.setInForeground();
  11207. if (event.type !== "mouse") {
  11208. this.div.focus();
  11209. }
  11210. event.stopPropagation();
  11211. this.canvas.addEventListener("pointerleave", this.#boundCanvasPointerleave);
  11212. this.canvas.addEventListener("pointermove", this.#boundCanvasPointermove);
  11213. this.#startDrawing(event.offsetX, event.offsetY);
  11214. }
  11215. canvasPointermove(event) {
  11216. event.stopPropagation();
  11217. this.#draw(event.offsetX, event.offsetY);
  11218. }
  11219. canvasPointerup(event) {
  11220. if (event.button !== 0) {
  11221. return;
  11222. }
  11223. if (this.isInEditMode() && this.currentPath.length !== 0) {
  11224. event.stopPropagation();
  11225. this.#endDrawing(event);
  11226. this.setInBackground();
  11227. }
  11228. }
  11229. canvasPointerleave(event) {
  11230. this.#endDrawing(event);
  11231. this.setInBackground();
  11232. }
  11233. #endDrawing(event) {
  11234. this.#stopDrawing(event.offsetX, event.offsetY);
  11235. this.canvas.removeEventListener("pointerleave", this.#boundCanvasPointerleave);
  11236. this.canvas.removeEventListener("pointermove", this.#boundCanvasPointermove);
  11237. this.addToAnnotationStorage();
  11238. }
  11239. #createCanvas() {
  11240. this.canvas = document.createElement("canvas");
  11241. this.canvas.width = this.canvas.height = 0;
  11242. this.canvas.className = "inkEditorCanvas";
  11243. InkEditor._l10nPromise.get("editor_ink_canvas_aria_label").then(msg => this.canvas?.setAttribute("aria-label", msg));
  11244. this.div.append(this.canvas);
  11245. this.ctx = this.canvas.getContext("2d");
  11246. }
  11247. #createObserver() {
  11248. let timeoutId = null;
  11249. this.#observer = new ResizeObserver(entries => {
  11250. const rect = entries[0].contentRect;
  11251. if (rect.width && rect.height) {
  11252. if (timeoutId !== null) {
  11253. clearTimeout(timeoutId);
  11254. }
  11255. timeoutId = setTimeout(() => {
  11256. this.fixDims();
  11257. timeoutId = null;
  11258. }, TIME_TO_WAIT_BEFORE_FIXING_DIMS);
  11259. this.setDimensions(rect.width, rect.height);
  11260. }
  11261. });
  11262. this.#observer.observe(this.div);
  11263. }
  11264. render() {
  11265. if (this.div) {
  11266. return this.div;
  11267. }
  11268. let baseX, baseY;
  11269. if (this.width) {
  11270. baseX = this.x;
  11271. baseY = this.y;
  11272. }
  11273. super.render();
  11274. InkEditor._l10nPromise.get("editor_ink2_aria_label").then(msg => this.div?.setAttribute("aria-label", msg));
  11275. const [x, y, w, h] = this.#getInitialBBox();
  11276. this.setAt(x, y, 0, 0);
  11277. this.setDims(w, h);
  11278. this.#createCanvas();
  11279. if (this.width) {
  11280. const [parentWidth, parentHeight] = this.parentDimensions;
  11281. this.setAt(baseX * parentWidth, baseY * parentHeight, this.width * parentWidth, this.height * parentHeight);
  11282. this.#isCanvasInitialized = true;
  11283. this.#setCanvasDims();
  11284. this.setDims(this.width * parentWidth, this.height * parentHeight);
  11285. this.#redraw();
  11286. this.#setMinDims();
  11287. this.div.classList.add("disabled");
  11288. } else {
  11289. this.div.classList.add("editing");
  11290. this.enableEditMode();
  11291. }
  11292. this.#createObserver();
  11293. return this.div;
  11294. }
  11295. #setCanvasDims() {
  11296. if (!this.#isCanvasInitialized) {
  11297. return;
  11298. }
  11299. const [parentWidth, parentHeight] = this.parentDimensions;
  11300. this.canvas.width = Math.ceil(this.width * parentWidth);
  11301. this.canvas.height = Math.ceil(this.height * parentHeight);
  11302. this.#updateTransform();
  11303. }
  11304. setDimensions(width, height) {
  11305. const roundedWidth = Math.round(width);
  11306. const roundedHeight = Math.round(height);
  11307. if (this.#realWidth === roundedWidth && this.#realHeight === roundedHeight) {
  11308. return;
  11309. }
  11310. this.#realWidth = roundedWidth;
  11311. this.#realHeight = roundedHeight;
  11312. this.canvas.style.visibility = "hidden";
  11313. if (this.#aspectRatio && Math.abs(this.#aspectRatio - width / height) > 1e-2) {
  11314. height = Math.ceil(width / this.#aspectRatio);
  11315. this.setDims(width, height);
  11316. }
  11317. const [parentWidth, parentHeight] = this.parentDimensions;
  11318. this.width = width / parentWidth;
  11319. this.height = height / parentHeight;
  11320. if (this.#disableEditing) {
  11321. this.#setScaleFactor(width, height);
  11322. }
  11323. this.#setCanvasDims();
  11324. this.#redraw();
  11325. this.canvas.style.visibility = "visible";
  11326. }
  11327. #setScaleFactor(width, height) {
  11328. const padding = this.#getPadding();
  11329. const scaleFactorW = (width - padding) / this.#baseWidth;
  11330. const scaleFactorH = (height - padding) / this.#baseHeight;
  11331. this.scaleFactor = Math.min(scaleFactorW, scaleFactorH);
  11332. }
  11333. #updateTransform() {
  11334. const padding = this.#getPadding() / 2;
  11335. this.ctx.setTransform(this.scaleFactor, 0, 0, this.scaleFactor, this.translationX * this.scaleFactor + padding, this.translationY * this.scaleFactor + padding);
  11336. }
  11337. static #buildPath2D(bezier) {
  11338. const path2D = new Path2D();
  11339. for (let i = 0, ii = bezier.length; i < ii; i++) {
  11340. const [first, control1, control2, second] = bezier[i];
  11341. if (i === 0) {
  11342. path2D.moveTo(...first);
  11343. }
  11344. path2D.bezierCurveTo(control1[0], control1[1], control2[0], control2[1], second[0], second[1]);
  11345. }
  11346. return path2D;
  11347. }
  11348. #serializePaths(s, tx, ty, h) {
  11349. const NUMBER_OF_POINTS_ON_BEZIER_CURVE = 4;
  11350. const paths = [];
  11351. const padding = this.thickness / 2;
  11352. let buffer, points;
  11353. for (const bezier of this.paths) {
  11354. buffer = [];
  11355. points = [];
  11356. for (let i = 0, ii = bezier.length; i < ii; i++) {
  11357. const [first, control1, control2, second] = bezier[i];
  11358. const p10 = s * (first[0] + tx) + padding;
  11359. const p11 = h - s * (first[1] + ty) - padding;
  11360. const p20 = s * (control1[0] + tx) + padding;
  11361. const p21 = h - s * (control1[1] + ty) - padding;
  11362. const p30 = s * (control2[0] + tx) + padding;
  11363. const p31 = h - s * (control2[1] + ty) - padding;
  11364. const p40 = s * (second[0] + tx) + padding;
  11365. const p41 = h - s * (second[1] + ty) - padding;
  11366. if (i === 0) {
  11367. buffer.push(p10, p11);
  11368. points.push(p10, p11);
  11369. }
  11370. buffer.push(p20, p21, p30, p31, p40, p41);
  11371. this.#extractPointsOnBezier(p10, p11, p20, p21, p30, p31, p40, p41, NUMBER_OF_POINTS_ON_BEZIER_CURVE, points);
  11372. }
  11373. paths.push({
  11374. bezier: buffer,
  11375. points
  11376. });
  11377. }
  11378. return paths;
  11379. }
  11380. #extractPointsOnBezier(p10, p11, p20, p21, p30, p31, p40, p41, n, points) {
  11381. if (this.#isAlmostFlat(p10, p11, p20, p21, p30, p31, p40, p41)) {
  11382. points.push(p40, p41);
  11383. return;
  11384. }
  11385. for (let i = 1; i < n - 1; i++) {
  11386. const t = i / n;
  11387. const mt = 1 - t;
  11388. let q10 = t * p10 + mt * p20;
  11389. let q11 = t * p11 + mt * p21;
  11390. let q20 = t * p20 + mt * p30;
  11391. let q21 = t * p21 + mt * p31;
  11392. const q30 = t * p30 + mt * p40;
  11393. const q31 = t * p31 + mt * p41;
  11394. q10 = t * q10 + mt * q20;
  11395. q11 = t * q11 + mt * q21;
  11396. q20 = t * q20 + mt * q30;
  11397. q21 = t * q21 + mt * q31;
  11398. q10 = t * q10 + mt * q20;
  11399. q11 = t * q11 + mt * q21;
  11400. points.push(q10, q11);
  11401. }
  11402. points.push(p40, p41);
  11403. }
  11404. #isAlmostFlat(p10, p11, p20, p21, p30, p31, p40, p41) {
  11405. const tol = 10;
  11406. const ax = (3 * p20 - 2 * p10 - p40) ** 2;
  11407. const ay = (3 * p21 - 2 * p11 - p41) ** 2;
  11408. const bx = (3 * p30 - p10 - 2 * p40) ** 2;
  11409. const by = (3 * p31 - p11 - 2 * p41) ** 2;
  11410. return Math.max(ax, bx) + Math.max(ay, by) <= tol;
  11411. }
  11412. #getBbox() {
  11413. let xMin = Infinity;
  11414. let xMax = -Infinity;
  11415. let yMin = Infinity;
  11416. let yMax = -Infinity;
  11417. for (const path of this.paths) {
  11418. for (const [first, control1, control2, second] of path) {
  11419. const bbox = _util.Util.bezierBoundingBox(...first, ...control1, ...control2, ...second);
  11420. xMin = Math.min(xMin, bbox[0]);
  11421. yMin = Math.min(yMin, bbox[1]);
  11422. xMax = Math.max(xMax, bbox[2]);
  11423. yMax = Math.max(yMax, bbox[3]);
  11424. }
  11425. }
  11426. return [xMin, yMin, xMax, yMax];
  11427. }
  11428. #getPadding() {
  11429. return this.#disableEditing ? Math.ceil(this.thickness * this.parentScale) : 0;
  11430. }
  11431. #fitToContent(firstTime = false) {
  11432. if (this.isEmpty()) {
  11433. return;
  11434. }
  11435. if (!this.#disableEditing) {
  11436. this.#redraw();
  11437. return;
  11438. }
  11439. const bbox = this.#getBbox();
  11440. const padding = this.#getPadding();
  11441. this.#baseWidth = Math.max(RESIZER_SIZE, bbox[2] - bbox[0]);
  11442. this.#baseHeight = Math.max(RESIZER_SIZE, bbox[3] - bbox[1]);
  11443. const width = Math.ceil(padding + this.#baseWidth * this.scaleFactor);
  11444. const height = Math.ceil(padding + this.#baseHeight * this.scaleFactor);
  11445. const [parentWidth, parentHeight] = this.parentDimensions;
  11446. this.width = width / parentWidth;
  11447. this.height = height / parentHeight;
  11448. this.#aspectRatio = width / height;
  11449. this.#setMinDims();
  11450. const prevTranslationX = this.translationX;
  11451. const prevTranslationY = this.translationY;
  11452. this.translationX = -bbox[0];
  11453. this.translationY = -bbox[1];
  11454. this.#setCanvasDims();
  11455. this.#redraw();
  11456. this.#realWidth = width;
  11457. this.#realHeight = height;
  11458. this.setDims(width, height);
  11459. const unscaledPadding = firstTime ? padding / this.scaleFactor / 2 : 0;
  11460. this.translate(prevTranslationX - this.translationX - unscaledPadding, prevTranslationY - this.translationY - unscaledPadding);
  11461. }
  11462. #setMinDims() {
  11463. const {
  11464. style
  11465. } = this.div;
  11466. if (this.#aspectRatio >= 1) {
  11467. style.minHeight = `${RESIZER_SIZE}px`;
  11468. style.minWidth = `${Math.round(this.#aspectRatio * RESIZER_SIZE)}px`;
  11469. } else {
  11470. style.minWidth = `${RESIZER_SIZE}px`;
  11471. style.minHeight = `${Math.round(RESIZER_SIZE / this.#aspectRatio)}px`;
  11472. }
  11473. }
  11474. static deserialize(data, parent, uiManager) {
  11475. const editor = super.deserialize(data, parent, uiManager);
  11476. editor.thickness = data.thickness;
  11477. editor.color = _util.Util.makeHexColor(...data.color);
  11478. editor.opacity = data.opacity;
  11479. const [pageWidth, pageHeight] = editor.pageDimensions;
  11480. const width = editor.width * pageWidth;
  11481. const height = editor.height * pageHeight;
  11482. const scaleFactor = editor.parentScale;
  11483. const padding = data.thickness / 2;
  11484. editor.#aspectRatio = width / height;
  11485. editor.#disableEditing = true;
  11486. editor.#realWidth = Math.round(width);
  11487. editor.#realHeight = Math.round(height);
  11488. for (const {
  11489. bezier
  11490. } of data.paths) {
  11491. const path = [];
  11492. editor.paths.push(path);
  11493. let p0 = scaleFactor * (bezier[0] - padding);
  11494. let p1 = scaleFactor * (height - bezier[1] - padding);
  11495. for (let i = 2, ii = bezier.length; i < ii; i += 6) {
  11496. const p10 = scaleFactor * (bezier[i] - padding);
  11497. const p11 = scaleFactor * (height - bezier[i + 1] - padding);
  11498. const p20 = scaleFactor * (bezier[i + 2] - padding);
  11499. const p21 = scaleFactor * (height - bezier[i + 3] - padding);
  11500. const p30 = scaleFactor * (bezier[i + 4] - padding);
  11501. const p31 = scaleFactor * (height - bezier[i + 5] - padding);
  11502. path.push([[p0, p1], [p10, p11], [p20, p21], [p30, p31]]);
  11503. p0 = p30;
  11504. p1 = p31;
  11505. }
  11506. const path2D = this.#buildPath2D(path);
  11507. editor.bezierPath2D.push(path2D);
  11508. }
  11509. const bbox = editor.#getBbox();
  11510. editor.#baseWidth = Math.max(RESIZER_SIZE, bbox[2] - bbox[0]);
  11511. editor.#baseHeight = Math.max(RESIZER_SIZE, bbox[3] - bbox[1]);
  11512. editor.#setScaleFactor(width, height);
  11513. return editor;
  11514. }
  11515. serialize() {
  11516. if (this.isEmpty()) {
  11517. return null;
  11518. }
  11519. const rect = this.getRect(0, 0);
  11520. const height = this.rotation % 180 === 0 ? rect[3] - rect[1] : rect[2] - rect[0];
  11521. const color = _editor.AnnotationEditor._colorManager.convert(this.ctx.strokeStyle);
  11522. return {
  11523. annotationType: _util.AnnotationEditorType.INK,
  11524. color,
  11525. thickness: this.thickness,
  11526. opacity: this.opacity,
  11527. paths: this.#serializePaths(this.scaleFactor / this.parentScale, this.translationX, this.translationY, height),
  11528. pageIndex: this.pageIndex,
  11529. rect,
  11530. rotation: this.rotation
  11531. };
  11532. }
  11533. }
  11534. exports.InkEditor = InkEditor;
  11535. /***/ }),
  11536. /* 30 */
  11537. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  11538. Object.defineProperty(exports, "__esModule", ({
  11539. value: true
  11540. }));
  11541. exports.fitCurve = void 0;
  11542. const fitCurve = __w_pdfjs_require__(31);
  11543. exports.fitCurve = fitCurve;
  11544. /***/ }),
  11545. /* 31 */
  11546. /***/ ((module) => {
  11547. function fitCurve(points, maxError, progressCallback) {
  11548. if (!Array.isArray(points)) {
  11549. throw new TypeError("First argument should be an array");
  11550. }
  11551. points.forEach(point => {
  11552. if (!Array.isArray(point) || point.some(item => typeof item !== 'number') || point.length !== points[0].length) {
  11553. throw Error("Each point should be an array of numbers. Each point should have the same amount of numbers.");
  11554. }
  11555. });
  11556. points = points.filter((point, i) => i === 0 || !point.every((val, j) => val === points[i - 1][j]));
  11557. if (points.length < 2) {
  11558. return [];
  11559. }
  11560. const len = points.length;
  11561. const leftTangent = createTangent(points[1], points[0]);
  11562. const rightTangent = createTangent(points[len - 2], points[len - 1]);
  11563. return fitCubic(points, leftTangent, rightTangent, maxError, progressCallback);
  11564. }
  11565. function fitCubic(points, leftTangent, rightTangent, error, progressCallback) {
  11566. const MaxIterations = 20;
  11567. var bezCurve, u, uPrime, maxError, prevErr, splitPoint, prevSplit, centerVector, toCenterTangent, fromCenterTangent, beziers, dist, i;
  11568. if (points.length === 2) {
  11569. dist = maths.vectorLen(maths.subtract(points[0], points[1])) / 3.0;
  11570. bezCurve = [points[0], maths.addArrays(points[0], maths.mulItems(leftTangent, dist)), maths.addArrays(points[1], maths.mulItems(rightTangent, dist)), points[1]];
  11571. return [bezCurve];
  11572. }
  11573. u = chordLengthParameterize(points);
  11574. [bezCurve, maxError, splitPoint] = generateAndReport(points, u, u, leftTangent, rightTangent, progressCallback);
  11575. if (maxError === 0 || maxError < error) {
  11576. return [bezCurve];
  11577. }
  11578. if (maxError < error * error) {
  11579. uPrime = u;
  11580. prevErr = maxError;
  11581. prevSplit = splitPoint;
  11582. for (i = 0; i < MaxIterations; i++) {
  11583. uPrime = reparameterize(bezCurve, points, uPrime);
  11584. [bezCurve, maxError, splitPoint] = generateAndReport(points, u, uPrime, leftTangent, rightTangent, progressCallback);
  11585. if (maxError < error) {
  11586. return [bezCurve];
  11587. } else if (splitPoint === prevSplit) {
  11588. let errChange = maxError / prevErr;
  11589. if (errChange > .9999 && errChange < 1.0001) {
  11590. break;
  11591. }
  11592. }
  11593. prevErr = maxError;
  11594. prevSplit = splitPoint;
  11595. }
  11596. }
  11597. beziers = [];
  11598. centerVector = maths.subtract(points[splitPoint - 1], points[splitPoint + 1]);
  11599. if (centerVector.every(val => val === 0)) {
  11600. centerVector = maths.subtract(points[splitPoint - 1], points[splitPoint]);
  11601. [centerVector[0], centerVector[1]] = [-centerVector[1], centerVector[0]];
  11602. }
  11603. toCenterTangent = maths.normalize(centerVector);
  11604. fromCenterTangent = maths.mulItems(toCenterTangent, -1);
  11605. beziers = beziers.concat(fitCubic(points.slice(0, splitPoint + 1), leftTangent, toCenterTangent, error, progressCallback));
  11606. beziers = beziers.concat(fitCubic(points.slice(splitPoint), fromCenterTangent, rightTangent, error, progressCallback));
  11607. return beziers;
  11608. }
  11609. ;
  11610. function generateAndReport(points, paramsOrig, paramsPrime, leftTangent, rightTangent, progressCallback) {
  11611. var bezCurve, maxError, splitPoint;
  11612. bezCurve = generateBezier(points, paramsPrime, leftTangent, rightTangent, progressCallback);
  11613. [maxError, splitPoint] = computeMaxError(points, bezCurve, paramsOrig);
  11614. if (progressCallback) {
  11615. progressCallback({
  11616. bez: bezCurve,
  11617. points: points,
  11618. params: paramsOrig,
  11619. maxErr: maxError,
  11620. maxPoint: splitPoint
  11621. });
  11622. }
  11623. return [bezCurve, maxError, splitPoint];
  11624. }
  11625. function generateBezier(points, parameters, leftTangent, rightTangent) {
  11626. var bezCurve,
  11627. A,
  11628. a,
  11629. C,
  11630. X,
  11631. det_C0_C1,
  11632. det_C0_X,
  11633. det_X_C1,
  11634. alpha_l,
  11635. alpha_r,
  11636. epsilon,
  11637. segLength,
  11638. i,
  11639. len,
  11640. tmp,
  11641. u,
  11642. ux,
  11643. firstPoint = points[0],
  11644. lastPoint = points[points.length - 1];
  11645. bezCurve = [firstPoint, null, null, lastPoint];
  11646. A = maths.zeros_Xx2x2(parameters.length);
  11647. for (i = 0, len = parameters.length; i < len; i++) {
  11648. u = parameters[i];
  11649. ux = 1 - u;
  11650. a = A[i];
  11651. a[0] = maths.mulItems(leftTangent, 3 * u * (ux * ux));
  11652. a[1] = maths.mulItems(rightTangent, 3 * ux * (u * u));
  11653. }
  11654. C = [[0, 0], [0, 0]];
  11655. X = [0, 0];
  11656. for (i = 0, len = points.length; i < len; i++) {
  11657. u = parameters[i];
  11658. a = A[i];
  11659. C[0][0] += maths.dot(a[0], a[0]);
  11660. C[0][1] += maths.dot(a[0], a[1]);
  11661. C[1][0] += maths.dot(a[0], a[1]);
  11662. C[1][1] += maths.dot(a[1], a[1]);
  11663. tmp = maths.subtract(points[i], bezier.q([firstPoint, firstPoint, lastPoint, lastPoint], u));
  11664. X[0] += maths.dot(a[0], tmp);
  11665. X[1] += maths.dot(a[1], tmp);
  11666. }
  11667. det_C0_C1 = C[0][0] * C[1][1] - C[1][0] * C[0][1];
  11668. det_C0_X = C[0][0] * X[1] - C[1][0] * X[0];
  11669. det_X_C1 = X[0] * C[1][1] - X[1] * C[0][1];
  11670. alpha_l = det_C0_C1 === 0 ? 0 : det_X_C1 / det_C0_C1;
  11671. alpha_r = det_C0_C1 === 0 ? 0 : det_C0_X / det_C0_C1;
  11672. segLength = maths.vectorLen(maths.subtract(firstPoint, lastPoint));
  11673. epsilon = 1.0e-6 * segLength;
  11674. if (alpha_l < epsilon || alpha_r < epsilon) {
  11675. bezCurve[1] = maths.addArrays(firstPoint, maths.mulItems(leftTangent, segLength / 3.0));
  11676. bezCurve[2] = maths.addArrays(lastPoint, maths.mulItems(rightTangent, segLength / 3.0));
  11677. } else {
  11678. bezCurve[1] = maths.addArrays(firstPoint, maths.mulItems(leftTangent, alpha_l));
  11679. bezCurve[2] = maths.addArrays(lastPoint, maths.mulItems(rightTangent, alpha_r));
  11680. }
  11681. return bezCurve;
  11682. }
  11683. ;
  11684. function reparameterize(bezier, points, parameters) {
  11685. return parameters.map((p, i) => newtonRaphsonRootFind(bezier, points[i], p));
  11686. }
  11687. ;
  11688. function newtonRaphsonRootFind(bez, point, u) {
  11689. var d = maths.subtract(bezier.q(bez, u), point),
  11690. qprime = bezier.qprime(bez, u),
  11691. numerator = maths.mulMatrix(d, qprime),
  11692. denominator = maths.sum(maths.squareItems(qprime)) + 2 * maths.mulMatrix(d, bezier.qprimeprime(bez, u));
  11693. if (denominator === 0) {
  11694. return u;
  11695. } else {
  11696. return u - numerator / denominator;
  11697. }
  11698. }
  11699. ;
  11700. function chordLengthParameterize(points) {
  11701. var u = [],
  11702. currU,
  11703. prevU,
  11704. prevP;
  11705. points.forEach((p, i) => {
  11706. currU = i ? prevU + maths.vectorLen(maths.subtract(p, prevP)) : 0;
  11707. u.push(currU);
  11708. prevU = currU;
  11709. prevP = p;
  11710. });
  11711. u = u.map(x => x / prevU);
  11712. return u;
  11713. }
  11714. ;
  11715. function computeMaxError(points, bez, parameters) {
  11716. var dist, maxDist, splitPoint, v, i, count, point, t;
  11717. maxDist = 0;
  11718. splitPoint = Math.floor(points.length / 2);
  11719. const t_distMap = mapTtoRelativeDistances(bez, 10);
  11720. for (i = 0, count = points.length; i < count; i++) {
  11721. point = points[i];
  11722. t = find_t(bez, parameters[i], t_distMap, 10);
  11723. v = maths.subtract(bezier.q(bez, t), point);
  11724. dist = v[0] * v[0] + v[1] * v[1];
  11725. if (dist > maxDist) {
  11726. maxDist = dist;
  11727. splitPoint = i;
  11728. }
  11729. }
  11730. return [maxDist, splitPoint];
  11731. }
  11732. ;
  11733. var mapTtoRelativeDistances = function (bez, B_parts) {
  11734. var B_t_curr;
  11735. var B_t_dist = [0];
  11736. var B_t_prev = bez[0];
  11737. var sumLen = 0;
  11738. for (var i = 1; i <= B_parts; i++) {
  11739. B_t_curr = bezier.q(bez, i / B_parts);
  11740. sumLen += maths.vectorLen(maths.subtract(B_t_curr, B_t_prev));
  11741. B_t_dist.push(sumLen);
  11742. B_t_prev = B_t_curr;
  11743. }
  11744. B_t_dist = B_t_dist.map(x => x / sumLen);
  11745. return B_t_dist;
  11746. };
  11747. function find_t(bez, param, t_distMap, B_parts) {
  11748. if (param < 0) {
  11749. return 0;
  11750. }
  11751. if (param > 1) {
  11752. return 1;
  11753. }
  11754. var lenMax, lenMin, tMax, tMin, t;
  11755. for (var i = 1; i <= B_parts; i++) {
  11756. if (param <= t_distMap[i]) {
  11757. tMin = (i - 1) / B_parts;
  11758. tMax = i / B_parts;
  11759. lenMin = t_distMap[i - 1];
  11760. lenMax = t_distMap[i];
  11761. t = (param - lenMin) / (lenMax - lenMin) * (tMax - tMin) + tMin;
  11762. break;
  11763. }
  11764. }
  11765. return t;
  11766. }
  11767. function createTangent(pointA, pointB) {
  11768. return maths.normalize(maths.subtract(pointA, pointB));
  11769. }
  11770. class maths {
  11771. static zeros_Xx2x2(x) {
  11772. var zs = [];
  11773. while (x--) {
  11774. zs.push([0, 0]);
  11775. }
  11776. return zs;
  11777. }
  11778. static mulItems(items, multiplier) {
  11779. return items.map(x => x * multiplier);
  11780. }
  11781. static mulMatrix(m1, m2) {
  11782. return m1.reduce((sum, x1, i) => sum + x1 * m2[i], 0);
  11783. }
  11784. static subtract(arr1, arr2) {
  11785. return arr1.map((x1, i) => x1 - arr2[i]);
  11786. }
  11787. static addArrays(arr1, arr2) {
  11788. return arr1.map((x1, i) => x1 + arr2[i]);
  11789. }
  11790. static addItems(items, addition) {
  11791. return items.map(x => x + addition);
  11792. }
  11793. static sum(items) {
  11794. return items.reduce((sum, x) => sum + x);
  11795. }
  11796. static dot(m1, m2) {
  11797. return maths.mulMatrix(m1, m2);
  11798. }
  11799. static vectorLen(v) {
  11800. return Math.hypot(...v);
  11801. }
  11802. static divItems(items, divisor) {
  11803. return items.map(x => x / divisor);
  11804. }
  11805. static squareItems(items) {
  11806. return items.map(x => x * x);
  11807. }
  11808. static normalize(v) {
  11809. return this.divItems(v, this.vectorLen(v));
  11810. }
  11811. }
  11812. class bezier {
  11813. static q(ctrlPoly, t) {
  11814. var tx = 1.0 - t;
  11815. var pA = maths.mulItems(ctrlPoly[0], tx * tx * tx),
  11816. pB = maths.mulItems(ctrlPoly[1], 3 * tx * tx * t),
  11817. pC = maths.mulItems(ctrlPoly[2], 3 * tx * t * t),
  11818. pD = maths.mulItems(ctrlPoly[3], t * t * t);
  11819. return maths.addArrays(maths.addArrays(pA, pB), maths.addArrays(pC, pD));
  11820. }
  11821. static qprime(ctrlPoly, t) {
  11822. var tx = 1.0 - t;
  11823. var pA = maths.mulItems(maths.subtract(ctrlPoly[1], ctrlPoly[0]), 3 * tx * tx),
  11824. pB = maths.mulItems(maths.subtract(ctrlPoly[2], ctrlPoly[1]), 6 * tx * t),
  11825. pC = maths.mulItems(maths.subtract(ctrlPoly[3], ctrlPoly[2]), 3 * t * t);
  11826. return maths.addArrays(maths.addArrays(pA, pB), pC);
  11827. }
  11828. static qprimeprime(ctrlPoly, t) {
  11829. return maths.addArrays(maths.mulItems(maths.addArrays(maths.subtract(ctrlPoly[2], maths.mulItems(ctrlPoly[1], 2)), ctrlPoly[0]), 6 * (1.0 - t)), maths.mulItems(maths.addArrays(maths.subtract(ctrlPoly[3], maths.mulItems(ctrlPoly[2], 2)), ctrlPoly[1]), 6 * t));
  11830. }
  11831. }
  11832. module.exports = fitCurve;
  11833. module.exports.fitCubic = fitCubic;
  11834. module.exports.createTangent = createTangent;
  11835. /***/ }),
  11836. /* 32 */
  11837. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  11838. Object.defineProperty(exports, "__esModule", ({
  11839. value: true
  11840. }));
  11841. exports.AnnotationLayer = void 0;
  11842. var _util = __w_pdfjs_require__(1);
  11843. var _display_utils = __w_pdfjs_require__(6);
  11844. var _annotation_storage = __w_pdfjs_require__(3);
  11845. var _scripting_utils = __w_pdfjs_require__(33);
  11846. var _xfa_layer = __w_pdfjs_require__(34);
  11847. const DEFAULT_TAB_INDEX = 1000;
  11848. const DEFAULT_FONT_SIZE = 9;
  11849. const GetElementsByNameSet = new WeakSet();
  11850. function getRectDims(rect) {
  11851. return {
  11852. width: rect[2] - rect[0],
  11853. height: rect[3] - rect[1]
  11854. };
  11855. }
  11856. class AnnotationElementFactory {
  11857. static create(parameters) {
  11858. const subtype = parameters.data.annotationType;
  11859. switch (subtype) {
  11860. case _util.AnnotationType.LINK:
  11861. return new LinkAnnotationElement(parameters);
  11862. case _util.AnnotationType.TEXT:
  11863. return new TextAnnotationElement(parameters);
  11864. case _util.AnnotationType.WIDGET:
  11865. const fieldType = parameters.data.fieldType;
  11866. switch (fieldType) {
  11867. case "Tx":
  11868. return new TextWidgetAnnotationElement(parameters);
  11869. case "Btn":
  11870. if (parameters.data.radioButton) {
  11871. return new RadioButtonWidgetAnnotationElement(parameters);
  11872. } else if (parameters.data.checkBox) {
  11873. return new CheckboxWidgetAnnotationElement(parameters);
  11874. }
  11875. return new PushButtonWidgetAnnotationElement(parameters);
  11876. case "Ch":
  11877. return new ChoiceWidgetAnnotationElement(parameters);
  11878. }
  11879. return new WidgetAnnotationElement(parameters);
  11880. case _util.AnnotationType.POPUP:
  11881. return new PopupAnnotationElement(parameters);
  11882. case _util.AnnotationType.FREETEXT:
  11883. return new FreeTextAnnotationElement(parameters);
  11884. case _util.AnnotationType.LINE:
  11885. return new LineAnnotationElement(parameters);
  11886. case _util.AnnotationType.SQUARE:
  11887. return new SquareAnnotationElement(parameters);
  11888. case _util.AnnotationType.CIRCLE:
  11889. return new CircleAnnotationElement(parameters);
  11890. case _util.AnnotationType.POLYLINE:
  11891. return new PolylineAnnotationElement(parameters);
  11892. case _util.AnnotationType.CARET:
  11893. return new CaretAnnotationElement(parameters);
  11894. case _util.AnnotationType.INK:
  11895. return new InkAnnotationElement(parameters);
  11896. case _util.AnnotationType.POLYGON:
  11897. return new PolygonAnnotationElement(parameters);
  11898. case _util.AnnotationType.HIGHLIGHT:
  11899. return new HighlightAnnotationElement(parameters);
  11900. case _util.AnnotationType.UNDERLINE:
  11901. return new UnderlineAnnotationElement(parameters);
  11902. case _util.AnnotationType.SQUIGGLY:
  11903. return new SquigglyAnnotationElement(parameters);
  11904. case _util.AnnotationType.STRIKEOUT:
  11905. return new StrikeOutAnnotationElement(parameters);
  11906. case _util.AnnotationType.STAMP:
  11907. return new StampAnnotationElement(parameters);
  11908. case _util.AnnotationType.FILEATTACHMENT:
  11909. return new FileAttachmentAnnotationElement(parameters);
  11910. default:
  11911. return new AnnotationElement(parameters);
  11912. }
  11913. }
  11914. }
  11915. class AnnotationElement {
  11916. constructor(parameters, {
  11917. isRenderable = false,
  11918. ignoreBorder = false,
  11919. createQuadrilaterals = false
  11920. } = {}) {
  11921. this.isRenderable = isRenderable;
  11922. this.data = parameters.data;
  11923. this.layer = parameters.layer;
  11924. this.page = parameters.page;
  11925. this.viewport = parameters.viewport;
  11926. this.linkService = parameters.linkService;
  11927. this.downloadManager = parameters.downloadManager;
  11928. this.imageResourcesPath = parameters.imageResourcesPath;
  11929. this.renderForms = parameters.renderForms;
  11930. this.svgFactory = parameters.svgFactory;
  11931. this.annotationStorage = parameters.annotationStorage;
  11932. this.enableScripting = parameters.enableScripting;
  11933. this.hasJSActions = parameters.hasJSActions;
  11934. this._fieldObjects = parameters.fieldObjects;
  11935. if (isRenderable) {
  11936. this.container = this._createContainer(ignoreBorder);
  11937. }
  11938. if (createQuadrilaterals) {
  11939. this.quadrilaterals = this._createQuadrilaterals(ignoreBorder);
  11940. }
  11941. }
  11942. _createContainer(ignoreBorder = false) {
  11943. const {
  11944. data,
  11945. page,
  11946. viewport
  11947. } = this;
  11948. const container = document.createElement("section");
  11949. container.setAttribute("data-annotation-id", data.id);
  11950. const {
  11951. pageWidth,
  11952. pageHeight,
  11953. pageX,
  11954. pageY
  11955. } = viewport.rawDims;
  11956. const {
  11957. width,
  11958. height
  11959. } = getRectDims(data.rect);
  11960. 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]]);
  11961. if (!ignoreBorder && data.borderStyle.width > 0) {
  11962. container.style.borderWidth = `${data.borderStyle.width}px`;
  11963. const horizontalRadius = data.borderStyle.horizontalCornerRadius;
  11964. const verticalRadius = data.borderStyle.verticalCornerRadius;
  11965. if (horizontalRadius > 0 || verticalRadius > 0) {
  11966. const radius = `calc(${horizontalRadius}px * var(--scale-factor)) / calc(${verticalRadius}px * var(--scale-factor))`;
  11967. container.style.borderRadius = radius;
  11968. } else if (this instanceof RadioButtonWidgetAnnotationElement) {
  11969. const radius = `calc(${width}px * var(--scale-factor)) / calc(${height}px * var(--scale-factor))`;
  11970. container.style.borderRadius = radius;
  11971. }
  11972. switch (data.borderStyle.style) {
  11973. case _util.AnnotationBorderStyleType.SOLID:
  11974. container.style.borderStyle = "solid";
  11975. break;
  11976. case _util.AnnotationBorderStyleType.DASHED:
  11977. container.style.borderStyle = "dashed";
  11978. break;
  11979. case _util.AnnotationBorderStyleType.BEVELED:
  11980. (0, _util.warn)("Unimplemented border style: beveled");
  11981. break;
  11982. case _util.AnnotationBorderStyleType.INSET:
  11983. (0, _util.warn)("Unimplemented border style: inset");
  11984. break;
  11985. case _util.AnnotationBorderStyleType.UNDERLINE:
  11986. container.style.borderBottomStyle = "solid";
  11987. break;
  11988. default:
  11989. break;
  11990. }
  11991. const borderColor = data.borderColor || null;
  11992. if (borderColor) {
  11993. container.style.borderColor = _util.Util.makeHexColor(borderColor[0] | 0, borderColor[1] | 0, borderColor[2] | 0);
  11994. } else {
  11995. container.style.borderWidth = 0;
  11996. }
  11997. }
  11998. container.style.left = `${100 * (rect[0] - pageX) / pageWidth}%`;
  11999. container.style.top = `${100 * (rect[1] - pageY) / pageHeight}%`;
  12000. const {
  12001. rotation
  12002. } = data;
  12003. if (data.hasOwnCanvas || rotation === 0) {
  12004. container.style.width = `${100 * width / pageWidth}%`;
  12005. container.style.height = `${100 * height / pageHeight}%`;
  12006. } else {
  12007. this.setRotation(rotation, container);
  12008. }
  12009. return container;
  12010. }
  12011. setRotation(angle, container = this.container) {
  12012. const {
  12013. pageWidth,
  12014. pageHeight
  12015. } = this.viewport.rawDims;
  12016. const {
  12017. width,
  12018. height
  12019. } = getRectDims(this.data.rect);
  12020. let elementWidth, elementHeight;
  12021. if (angle % 180 === 0) {
  12022. elementWidth = 100 * width / pageWidth;
  12023. elementHeight = 100 * height / pageHeight;
  12024. } else {
  12025. elementWidth = 100 * height / pageWidth;
  12026. elementHeight = 100 * width / pageHeight;
  12027. }
  12028. container.style.width = `${elementWidth}%`;
  12029. container.style.height = `${elementHeight}%`;
  12030. container.setAttribute("data-main-rotation", (360 - angle) % 360);
  12031. }
  12032. get _commonActions() {
  12033. const setColor = (jsName, styleName, event) => {
  12034. const color = event.detail[jsName];
  12035. event.target.style[styleName] = _scripting_utils.ColorConverters[`${color[0]}_HTML`](color.slice(1));
  12036. };
  12037. return (0, _util.shadow)(this, "_commonActions", {
  12038. display: event => {
  12039. const hidden = event.detail.display % 2 === 1;
  12040. this.container.style.visibility = hidden ? "hidden" : "visible";
  12041. this.annotationStorage.setValue(this.data.id, {
  12042. hidden,
  12043. print: event.detail.display === 0 || event.detail.display === 3
  12044. });
  12045. },
  12046. print: event => {
  12047. this.annotationStorage.setValue(this.data.id, {
  12048. print: event.detail.print
  12049. });
  12050. },
  12051. hidden: event => {
  12052. this.container.style.visibility = event.detail.hidden ? "hidden" : "visible";
  12053. this.annotationStorage.setValue(this.data.id, {
  12054. hidden: event.detail.hidden
  12055. });
  12056. },
  12057. focus: event => {
  12058. setTimeout(() => event.target.focus({
  12059. preventScroll: false
  12060. }), 0);
  12061. },
  12062. userName: event => {
  12063. event.target.title = event.detail.userName;
  12064. },
  12065. readonly: event => {
  12066. if (event.detail.readonly) {
  12067. event.target.setAttribute("readonly", "");
  12068. } else {
  12069. event.target.removeAttribute("readonly");
  12070. }
  12071. },
  12072. required: event => {
  12073. this._setRequired(event.target, event.detail.required);
  12074. },
  12075. bgColor: event => {
  12076. setColor("bgColor", "backgroundColor", event);
  12077. },
  12078. fillColor: event => {
  12079. setColor("fillColor", "backgroundColor", event);
  12080. },
  12081. fgColor: event => {
  12082. setColor("fgColor", "color", event);
  12083. },
  12084. textColor: event => {
  12085. setColor("textColor", "color", event);
  12086. },
  12087. borderColor: event => {
  12088. setColor("borderColor", "borderColor", event);
  12089. },
  12090. strokeColor: event => {
  12091. setColor("strokeColor", "borderColor", event);
  12092. },
  12093. rotation: event => {
  12094. const angle = event.detail.rotation;
  12095. this.setRotation(angle);
  12096. this.annotationStorage.setValue(this.data.id, {
  12097. rotation: angle
  12098. });
  12099. }
  12100. });
  12101. }
  12102. _dispatchEventFromSandbox(actions, jsEvent) {
  12103. const commonActions = this._commonActions;
  12104. for (const name of Object.keys(jsEvent.detail)) {
  12105. const action = actions[name] || commonActions[name];
  12106. action?.(jsEvent);
  12107. }
  12108. }
  12109. _setDefaultPropertiesFromJS(element) {
  12110. if (!this.enableScripting) {
  12111. return;
  12112. }
  12113. const storedData = this.annotationStorage.getRawValue(this.data.id);
  12114. if (!storedData) {
  12115. return;
  12116. }
  12117. const commonActions = this._commonActions;
  12118. for (const [actionName, detail] of Object.entries(storedData)) {
  12119. const action = commonActions[actionName];
  12120. if (action) {
  12121. const eventProxy = {
  12122. detail: {
  12123. [actionName]: detail
  12124. },
  12125. target: element
  12126. };
  12127. action(eventProxy);
  12128. delete storedData[actionName];
  12129. }
  12130. }
  12131. }
  12132. _createQuadrilaterals(ignoreBorder = false) {
  12133. if (!this.data.quadPoints) {
  12134. return null;
  12135. }
  12136. const quadrilaterals = [];
  12137. const savedRect = this.data.rect;
  12138. for (const quadPoint of this.data.quadPoints) {
  12139. this.data.rect = [quadPoint[2].x, quadPoint[2].y, quadPoint[1].x, quadPoint[1].y];
  12140. quadrilaterals.push(this._createContainer(ignoreBorder));
  12141. }
  12142. this.data.rect = savedRect;
  12143. return quadrilaterals;
  12144. }
  12145. _createPopup(trigger, data) {
  12146. let container = this.container;
  12147. if (this.quadrilaterals) {
  12148. trigger = trigger || this.quadrilaterals;
  12149. container = this.quadrilaterals[0];
  12150. }
  12151. if (!trigger) {
  12152. trigger = document.createElement("div");
  12153. trigger.className = "popupTriggerArea";
  12154. container.append(trigger);
  12155. }
  12156. const popupElement = new PopupElement({
  12157. container,
  12158. trigger,
  12159. color: data.color,
  12160. titleObj: data.titleObj,
  12161. modificationDate: data.modificationDate,
  12162. contentsObj: data.contentsObj,
  12163. richText: data.richText,
  12164. hideWrapper: true
  12165. });
  12166. const popup = popupElement.render();
  12167. popup.style.left = "100%";
  12168. container.append(popup);
  12169. }
  12170. _renderQuadrilaterals(className) {
  12171. for (const quadrilateral of this.quadrilaterals) {
  12172. quadrilateral.className = className;
  12173. }
  12174. return this.quadrilaterals;
  12175. }
  12176. render() {
  12177. (0, _util.unreachable)("Abstract method `AnnotationElement.render` called");
  12178. }
  12179. _getElementsByName(name, skipId = null) {
  12180. const fields = [];
  12181. if (this._fieldObjects) {
  12182. const fieldObj = this._fieldObjects[name];
  12183. if (fieldObj) {
  12184. for (const {
  12185. page,
  12186. id,
  12187. exportValues
  12188. } of fieldObj) {
  12189. if (page === -1) {
  12190. continue;
  12191. }
  12192. if (id === skipId) {
  12193. continue;
  12194. }
  12195. const exportValue = typeof exportValues === "string" ? exportValues : null;
  12196. const domElement = document.querySelector(`[data-element-id="${id}"]`);
  12197. if (domElement && !GetElementsByNameSet.has(domElement)) {
  12198. (0, _util.warn)(`_getElementsByName - element not allowed: ${id}`);
  12199. continue;
  12200. }
  12201. fields.push({
  12202. id,
  12203. exportValue,
  12204. domElement
  12205. });
  12206. }
  12207. }
  12208. return fields;
  12209. }
  12210. for (const domElement of document.getElementsByName(name)) {
  12211. const {
  12212. exportValue
  12213. } = domElement;
  12214. const id = domElement.getAttribute("data-element-id");
  12215. if (id === skipId) {
  12216. continue;
  12217. }
  12218. if (!GetElementsByNameSet.has(domElement)) {
  12219. continue;
  12220. }
  12221. fields.push({
  12222. id,
  12223. exportValue,
  12224. domElement
  12225. });
  12226. }
  12227. return fields;
  12228. }
  12229. }
  12230. class LinkAnnotationElement extends AnnotationElement {
  12231. constructor(parameters, options = null) {
  12232. super(parameters, {
  12233. isRenderable: true,
  12234. ignoreBorder: !!options?.ignoreBorder,
  12235. createQuadrilaterals: true
  12236. });
  12237. this.isTooltipOnly = parameters.data.isTooltipOnly;
  12238. }
  12239. render() {
  12240. const {
  12241. data,
  12242. linkService
  12243. } = this;
  12244. const link = document.createElement("a");
  12245. link.setAttribute("data-element-id", data.id);
  12246. let isBound = false;
  12247. if (data.url) {
  12248. linkService.addLinkAttributes(link, data.url, data.newWindow);
  12249. isBound = true;
  12250. } else if (data.action) {
  12251. this._bindNamedAction(link, data.action);
  12252. isBound = true;
  12253. } else if (data.attachment) {
  12254. this._bindAttachment(link, data.attachment);
  12255. isBound = true;
  12256. } else if (data.setOCGState) {
  12257. this.#bindSetOCGState(link, data.setOCGState);
  12258. isBound = true;
  12259. } else if (data.dest) {
  12260. this._bindLink(link, data.dest);
  12261. isBound = true;
  12262. } else {
  12263. if (data.actions && (data.actions.Action || data.actions["Mouse Up"] || data.actions["Mouse Down"]) && this.enableScripting && this.hasJSActions) {
  12264. this._bindJSAction(link, data);
  12265. isBound = true;
  12266. }
  12267. if (data.resetForm) {
  12268. this._bindResetFormAction(link, data.resetForm);
  12269. isBound = true;
  12270. } else if (this.isTooltipOnly && !isBound) {
  12271. this._bindLink(link, "");
  12272. isBound = true;
  12273. }
  12274. }
  12275. if (this.quadrilaterals) {
  12276. return this._renderQuadrilaterals("linkAnnotation").map((quadrilateral, index) => {
  12277. const linkElement = index === 0 ? link : link.cloneNode();
  12278. quadrilateral.append(linkElement);
  12279. return quadrilateral;
  12280. });
  12281. }
  12282. this.container.className = "linkAnnotation";
  12283. if (isBound) {
  12284. this.container.append(link);
  12285. }
  12286. return this.container;
  12287. }
  12288. #setInternalLink() {
  12289. this.container.setAttribute("data-internal-link", "");
  12290. }
  12291. _bindLink(link, destination) {
  12292. link.href = this.linkService.getDestinationHash(destination);
  12293. link.onclick = () => {
  12294. if (destination) {
  12295. this.linkService.goToDestination(destination);
  12296. }
  12297. return false;
  12298. };
  12299. if (destination || destination === "") {
  12300. this.#setInternalLink();
  12301. }
  12302. }
  12303. _bindNamedAction(link, action) {
  12304. link.href = this.linkService.getAnchorUrl("");
  12305. link.onclick = () => {
  12306. this.linkService.executeNamedAction(action);
  12307. return false;
  12308. };
  12309. this.#setInternalLink();
  12310. }
  12311. _bindAttachment(link, attachment) {
  12312. link.href = this.linkService.getAnchorUrl("");
  12313. link.onclick = () => {
  12314. this.downloadManager?.openOrDownloadData(this.container, attachment.content, attachment.filename);
  12315. return false;
  12316. };
  12317. this.#setInternalLink();
  12318. }
  12319. #bindSetOCGState(link, action) {
  12320. link.href = this.linkService.getAnchorUrl("");
  12321. link.onclick = () => {
  12322. this.linkService.executeSetOCGState(action);
  12323. return false;
  12324. };
  12325. this.#setInternalLink();
  12326. }
  12327. _bindJSAction(link, data) {
  12328. link.href = this.linkService.getAnchorUrl("");
  12329. const map = new Map([["Action", "onclick"], ["Mouse Up", "onmouseup"], ["Mouse Down", "onmousedown"]]);
  12330. for (const name of Object.keys(data.actions)) {
  12331. const jsName = map.get(name);
  12332. if (!jsName) {
  12333. continue;
  12334. }
  12335. link[jsName] = () => {
  12336. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  12337. source: this,
  12338. detail: {
  12339. id: data.id,
  12340. name
  12341. }
  12342. });
  12343. return false;
  12344. };
  12345. }
  12346. if (!link.onclick) {
  12347. link.onclick = () => false;
  12348. }
  12349. this.#setInternalLink();
  12350. }
  12351. _bindResetFormAction(link, resetForm) {
  12352. const otherClickAction = link.onclick;
  12353. if (!otherClickAction) {
  12354. link.href = this.linkService.getAnchorUrl("");
  12355. }
  12356. this.#setInternalLink();
  12357. if (!this._fieldObjects) {
  12358. (0, _util.warn)(`_bindResetFormAction - "resetForm" action not supported, ` + "ensure that the `fieldObjects` parameter is provided.");
  12359. if (!otherClickAction) {
  12360. link.onclick = () => false;
  12361. }
  12362. return;
  12363. }
  12364. link.onclick = () => {
  12365. otherClickAction?.();
  12366. const {
  12367. fields: resetFormFields,
  12368. refs: resetFormRefs,
  12369. include
  12370. } = resetForm;
  12371. const allFields = [];
  12372. if (resetFormFields.length !== 0 || resetFormRefs.length !== 0) {
  12373. const fieldIds = new Set(resetFormRefs);
  12374. for (const fieldName of resetFormFields) {
  12375. const fields = this._fieldObjects[fieldName] || [];
  12376. for (const {
  12377. id
  12378. } of fields) {
  12379. fieldIds.add(id);
  12380. }
  12381. }
  12382. for (const fields of Object.values(this._fieldObjects)) {
  12383. for (const field of fields) {
  12384. if (fieldIds.has(field.id) === include) {
  12385. allFields.push(field);
  12386. }
  12387. }
  12388. }
  12389. } else {
  12390. for (const fields of Object.values(this._fieldObjects)) {
  12391. allFields.push(...fields);
  12392. }
  12393. }
  12394. const storage = this.annotationStorage;
  12395. const allIds = [];
  12396. for (const field of allFields) {
  12397. const {
  12398. id
  12399. } = field;
  12400. allIds.push(id);
  12401. switch (field.type) {
  12402. case "text":
  12403. {
  12404. const value = field.defaultValue || "";
  12405. storage.setValue(id, {
  12406. value
  12407. });
  12408. break;
  12409. }
  12410. case "checkbox":
  12411. case "radiobutton":
  12412. {
  12413. const value = field.defaultValue === field.exportValues;
  12414. storage.setValue(id, {
  12415. value
  12416. });
  12417. break;
  12418. }
  12419. case "combobox":
  12420. case "listbox":
  12421. {
  12422. const value = field.defaultValue || "";
  12423. storage.setValue(id, {
  12424. value
  12425. });
  12426. break;
  12427. }
  12428. default:
  12429. continue;
  12430. }
  12431. const domElement = document.querySelector(`[data-element-id="${id}"]`);
  12432. if (!domElement) {
  12433. continue;
  12434. } else if (!GetElementsByNameSet.has(domElement)) {
  12435. (0, _util.warn)(`_bindResetFormAction - element not allowed: ${id}`);
  12436. continue;
  12437. }
  12438. domElement.dispatchEvent(new Event("resetform"));
  12439. }
  12440. if (this.enableScripting) {
  12441. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  12442. source: this,
  12443. detail: {
  12444. id: "app",
  12445. ids: allIds,
  12446. name: "ResetForm"
  12447. }
  12448. });
  12449. }
  12450. return false;
  12451. };
  12452. }
  12453. }
  12454. class TextAnnotationElement extends AnnotationElement {
  12455. constructor(parameters) {
  12456. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  12457. super(parameters, {
  12458. isRenderable
  12459. });
  12460. }
  12461. render() {
  12462. this.container.className = "textAnnotation";
  12463. const image = document.createElement("img");
  12464. image.src = this.imageResourcesPath + "annotation-" + this.data.name.toLowerCase() + ".svg";
  12465. image.alt = "[{{type}} Annotation]";
  12466. image.dataset.l10nId = "text_annotation_type";
  12467. image.dataset.l10nArgs = JSON.stringify({
  12468. type: this.data.name
  12469. });
  12470. if (!this.data.hasPopup) {
  12471. this._createPopup(image, this.data);
  12472. }
  12473. this.container.append(image);
  12474. return this.container;
  12475. }
  12476. }
  12477. class WidgetAnnotationElement extends AnnotationElement {
  12478. render() {
  12479. if (this.data.alternativeText) {
  12480. this.container.title = this.data.alternativeText;
  12481. }
  12482. return this.container;
  12483. }
  12484. _getKeyModifier(event) {
  12485. const {
  12486. isWin,
  12487. isMac
  12488. } = _util.FeatureTest.platform;
  12489. return isWin && event.ctrlKey || isMac && event.metaKey;
  12490. }
  12491. _setEventListener(element, baseName, eventName, valueGetter) {
  12492. if (baseName.includes("mouse")) {
  12493. element.addEventListener(baseName, event => {
  12494. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  12495. source: this,
  12496. detail: {
  12497. id: this.data.id,
  12498. name: eventName,
  12499. value: valueGetter(event),
  12500. shift: event.shiftKey,
  12501. modifier: this._getKeyModifier(event)
  12502. }
  12503. });
  12504. });
  12505. } else {
  12506. element.addEventListener(baseName, event => {
  12507. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  12508. source: this,
  12509. detail: {
  12510. id: this.data.id,
  12511. name: eventName,
  12512. value: valueGetter(event)
  12513. }
  12514. });
  12515. });
  12516. }
  12517. }
  12518. _setEventListeners(element, names, getter) {
  12519. for (const [baseName, eventName] of names) {
  12520. if (eventName === "Action" || this.data.actions?.[eventName]) {
  12521. this._setEventListener(element, baseName, eventName, getter);
  12522. }
  12523. }
  12524. }
  12525. _setBackgroundColor(element) {
  12526. const color = this.data.backgroundColor || null;
  12527. element.style.backgroundColor = color === null ? "transparent" : _util.Util.makeHexColor(color[0], color[1], color[2]);
  12528. }
  12529. _setTextStyle(element) {
  12530. const TEXT_ALIGNMENT = ["left", "center", "right"];
  12531. const {
  12532. fontColor
  12533. } = this.data.defaultAppearanceData;
  12534. const fontSize = this.data.defaultAppearanceData.fontSize || DEFAULT_FONT_SIZE;
  12535. const style = element.style;
  12536. let computedFontSize;
  12537. const BORDER_SIZE = 2;
  12538. const roundToOneDecimal = x => Math.round(10 * x) / 10;
  12539. if (this.data.multiLine) {
  12540. const height = Math.abs(this.data.rect[3] - this.data.rect[1] - BORDER_SIZE);
  12541. const numberOfLines = Math.round(height / (_util.LINE_FACTOR * fontSize)) || 1;
  12542. const lineHeight = height / numberOfLines;
  12543. computedFontSize = Math.min(fontSize, roundToOneDecimal(lineHeight / _util.LINE_FACTOR));
  12544. } else {
  12545. const height = Math.abs(this.data.rect[3] - this.data.rect[1] - BORDER_SIZE);
  12546. computedFontSize = Math.min(fontSize, roundToOneDecimal(height / _util.LINE_FACTOR));
  12547. }
  12548. style.fontSize = `calc(${computedFontSize}px * var(--scale-factor))`;
  12549. style.color = _util.Util.makeHexColor(fontColor[0], fontColor[1], fontColor[2]);
  12550. if (this.data.textAlignment !== null) {
  12551. style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
  12552. }
  12553. }
  12554. _setRequired(element, isRequired) {
  12555. if (isRequired) {
  12556. element.setAttribute("required", true);
  12557. } else {
  12558. element.removeAttribute("required");
  12559. }
  12560. element.setAttribute("aria-required", isRequired);
  12561. }
  12562. }
  12563. class TextWidgetAnnotationElement extends WidgetAnnotationElement {
  12564. constructor(parameters) {
  12565. const isRenderable = parameters.renderForms || !parameters.data.hasAppearance && !!parameters.data.fieldValue;
  12566. super(parameters, {
  12567. isRenderable
  12568. });
  12569. }
  12570. setPropertyOnSiblings(base, key, value, keyInStorage) {
  12571. const storage = this.annotationStorage;
  12572. for (const element of this._getElementsByName(base.name, base.id)) {
  12573. if (element.domElement) {
  12574. element.domElement[key] = value;
  12575. }
  12576. storage.setValue(element.id, {
  12577. [keyInStorage]: value
  12578. });
  12579. }
  12580. }
  12581. render() {
  12582. const storage = this.annotationStorage;
  12583. const id = this.data.id;
  12584. this.container.className = "textWidgetAnnotation";
  12585. let element = null;
  12586. if (this.renderForms) {
  12587. const storedData = storage.getValue(id, {
  12588. value: this.data.fieldValue
  12589. });
  12590. let textContent = storedData.formattedValue || storedData.value || "";
  12591. const maxLen = storage.getValue(id, {
  12592. charLimit: this.data.maxLen
  12593. }).charLimit;
  12594. if (maxLen && textContent.length > maxLen) {
  12595. textContent = textContent.slice(0, maxLen);
  12596. }
  12597. const elementData = {
  12598. userValue: textContent,
  12599. formattedValue: null,
  12600. lastCommittedValue: null,
  12601. commitKey: 1
  12602. };
  12603. if (this.data.multiLine) {
  12604. element = document.createElement("textarea");
  12605. element.textContent = textContent;
  12606. if (this.data.doNotScroll) {
  12607. element.style.overflowY = "hidden";
  12608. }
  12609. } else {
  12610. element = document.createElement("input");
  12611. element.type = "text";
  12612. element.setAttribute("value", textContent);
  12613. if (this.data.doNotScroll) {
  12614. element.style.overflowX = "hidden";
  12615. }
  12616. }
  12617. GetElementsByNameSet.add(element);
  12618. element.setAttribute("data-element-id", id);
  12619. element.disabled = this.data.readOnly;
  12620. element.name = this.data.fieldName;
  12621. element.tabIndex = DEFAULT_TAB_INDEX;
  12622. this._setRequired(element, this.data.required);
  12623. if (maxLen) {
  12624. element.maxLength = maxLen;
  12625. }
  12626. element.addEventListener("input", event => {
  12627. storage.setValue(id, {
  12628. value: event.target.value
  12629. });
  12630. this.setPropertyOnSiblings(element, "value", event.target.value, "value");
  12631. });
  12632. element.addEventListener("resetform", event => {
  12633. const defaultValue = this.data.defaultFieldValue ?? "";
  12634. element.value = elementData.userValue = defaultValue;
  12635. elementData.formattedValue = null;
  12636. });
  12637. let blurListener = event => {
  12638. const {
  12639. formattedValue
  12640. } = elementData;
  12641. if (formattedValue !== null && formattedValue !== undefined) {
  12642. event.target.value = formattedValue;
  12643. }
  12644. event.target.scrollLeft = 0;
  12645. };
  12646. if (this.enableScripting && this.hasJSActions) {
  12647. element.addEventListener("focus", event => {
  12648. const {
  12649. target
  12650. } = event;
  12651. if (elementData.userValue) {
  12652. target.value = elementData.userValue;
  12653. }
  12654. elementData.lastCommittedValue = target.value;
  12655. elementData.commitKey = 1;
  12656. });
  12657. element.addEventListener("updatefromsandbox", jsEvent => {
  12658. const actions = {
  12659. value(event) {
  12660. elementData.userValue = event.detail.value ?? "";
  12661. storage.setValue(id, {
  12662. value: elementData.userValue.toString()
  12663. });
  12664. event.target.value = elementData.userValue;
  12665. },
  12666. formattedValue(event) {
  12667. const {
  12668. formattedValue
  12669. } = event.detail;
  12670. elementData.formattedValue = formattedValue;
  12671. if (formattedValue !== null && formattedValue !== undefined && event.target !== document.activeElement) {
  12672. event.target.value = formattedValue;
  12673. }
  12674. storage.setValue(id, {
  12675. formattedValue
  12676. });
  12677. },
  12678. selRange(event) {
  12679. event.target.setSelectionRange(...event.detail.selRange);
  12680. },
  12681. charLimit: event => {
  12682. const {
  12683. charLimit
  12684. } = event.detail;
  12685. const {
  12686. target
  12687. } = event;
  12688. if (charLimit === 0) {
  12689. target.removeAttribute("maxLength");
  12690. return;
  12691. }
  12692. target.setAttribute("maxLength", charLimit);
  12693. let value = elementData.userValue;
  12694. if (!value || value.length <= charLimit) {
  12695. return;
  12696. }
  12697. value = value.slice(0, charLimit);
  12698. target.value = elementData.userValue = value;
  12699. storage.setValue(id, {
  12700. value
  12701. });
  12702. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  12703. source: this,
  12704. detail: {
  12705. id,
  12706. name: "Keystroke",
  12707. value,
  12708. willCommit: true,
  12709. commitKey: 1,
  12710. selStart: target.selectionStart,
  12711. selEnd: target.selectionEnd
  12712. }
  12713. });
  12714. }
  12715. };
  12716. this._dispatchEventFromSandbox(actions, jsEvent);
  12717. });
  12718. element.addEventListener("keydown", event => {
  12719. elementData.commitKey = 1;
  12720. let commitKey = -1;
  12721. if (event.key === "Escape") {
  12722. commitKey = 0;
  12723. } else if (event.key === "Enter" && !this.data.multiLine) {
  12724. commitKey = 2;
  12725. } else if (event.key === "Tab") {
  12726. elementData.commitKey = 3;
  12727. }
  12728. if (commitKey === -1) {
  12729. return;
  12730. }
  12731. const {
  12732. value
  12733. } = event.target;
  12734. if (elementData.lastCommittedValue === value) {
  12735. return;
  12736. }
  12737. elementData.lastCommittedValue = value;
  12738. elementData.userValue = value;
  12739. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  12740. source: this,
  12741. detail: {
  12742. id,
  12743. name: "Keystroke",
  12744. value,
  12745. willCommit: true,
  12746. commitKey,
  12747. selStart: event.target.selectionStart,
  12748. selEnd: event.target.selectionEnd
  12749. }
  12750. });
  12751. });
  12752. const _blurListener = blurListener;
  12753. blurListener = null;
  12754. element.addEventListener("blur", event => {
  12755. if (!event.relatedTarget) {
  12756. return;
  12757. }
  12758. const {
  12759. value
  12760. } = event.target;
  12761. elementData.userValue = value;
  12762. if (elementData.lastCommittedValue !== value) {
  12763. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  12764. source: this,
  12765. detail: {
  12766. id,
  12767. name: "Keystroke",
  12768. value,
  12769. willCommit: true,
  12770. commitKey: elementData.commitKey,
  12771. selStart: event.target.selectionStart,
  12772. selEnd: event.target.selectionEnd
  12773. }
  12774. });
  12775. }
  12776. _blurListener(event);
  12777. });
  12778. if (this.data.actions?.Keystroke) {
  12779. element.addEventListener("beforeinput", event => {
  12780. elementData.lastCommittedValue = null;
  12781. const {
  12782. data,
  12783. target
  12784. } = event;
  12785. const {
  12786. value,
  12787. selectionStart,
  12788. selectionEnd
  12789. } = target;
  12790. let selStart = selectionStart,
  12791. selEnd = selectionEnd;
  12792. switch (event.inputType) {
  12793. case "deleteWordBackward":
  12794. {
  12795. const match = value.substring(0, selectionStart).match(/\w*[^\w]*$/);
  12796. if (match) {
  12797. selStart -= match[0].length;
  12798. }
  12799. break;
  12800. }
  12801. case "deleteWordForward":
  12802. {
  12803. const match = value.substring(selectionStart).match(/^[^\w]*\w*/);
  12804. if (match) {
  12805. selEnd += match[0].length;
  12806. }
  12807. break;
  12808. }
  12809. case "deleteContentBackward":
  12810. if (selectionStart === selectionEnd) {
  12811. selStart -= 1;
  12812. }
  12813. break;
  12814. case "deleteContentForward":
  12815. if (selectionStart === selectionEnd) {
  12816. selEnd += 1;
  12817. }
  12818. break;
  12819. }
  12820. event.preventDefault();
  12821. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  12822. source: this,
  12823. detail: {
  12824. id,
  12825. name: "Keystroke",
  12826. value,
  12827. change: data || "",
  12828. willCommit: false,
  12829. selStart,
  12830. selEnd
  12831. }
  12832. });
  12833. });
  12834. }
  12835. this._setEventListeners(element, [["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"]], event => event.target.value);
  12836. }
  12837. if (blurListener) {
  12838. element.addEventListener("blur", blurListener);
  12839. }
  12840. if (this.data.comb) {
  12841. const fieldWidth = this.data.rect[2] - this.data.rect[0];
  12842. const combWidth = fieldWidth / maxLen;
  12843. element.classList.add("comb");
  12844. element.style.letterSpacing = `calc(${combWidth}px * var(--scale-factor) - 1ch)`;
  12845. }
  12846. } else {
  12847. element = document.createElement("div");
  12848. element.textContent = this.data.fieldValue;
  12849. element.style.verticalAlign = "middle";
  12850. element.style.display = "table-cell";
  12851. }
  12852. this._setTextStyle(element);
  12853. this._setBackgroundColor(element);
  12854. this._setDefaultPropertiesFromJS(element);
  12855. this.container.append(element);
  12856. return this.container;
  12857. }
  12858. }
  12859. class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement {
  12860. constructor(parameters) {
  12861. super(parameters, {
  12862. isRenderable: parameters.renderForms
  12863. });
  12864. }
  12865. render() {
  12866. const storage = this.annotationStorage;
  12867. const data = this.data;
  12868. const id = data.id;
  12869. let value = storage.getValue(id, {
  12870. value: data.exportValue === data.fieldValue
  12871. }).value;
  12872. if (typeof value === "string") {
  12873. value = value !== "Off";
  12874. storage.setValue(id, {
  12875. value
  12876. });
  12877. }
  12878. this.container.className = "buttonWidgetAnnotation checkBox";
  12879. const element = document.createElement("input");
  12880. GetElementsByNameSet.add(element);
  12881. element.setAttribute("data-element-id", id);
  12882. element.disabled = data.readOnly;
  12883. this._setRequired(element, this.data.required);
  12884. element.type = "checkbox";
  12885. element.name = data.fieldName;
  12886. if (value) {
  12887. element.setAttribute("checked", true);
  12888. }
  12889. element.setAttribute("exportValue", data.exportValue);
  12890. element.tabIndex = DEFAULT_TAB_INDEX;
  12891. element.addEventListener("change", event => {
  12892. const {
  12893. name,
  12894. checked
  12895. } = event.target;
  12896. for (const checkbox of this._getElementsByName(name, id)) {
  12897. const curChecked = checked && checkbox.exportValue === data.exportValue;
  12898. if (checkbox.domElement) {
  12899. checkbox.domElement.checked = curChecked;
  12900. }
  12901. storage.setValue(checkbox.id, {
  12902. value: curChecked
  12903. });
  12904. }
  12905. storage.setValue(id, {
  12906. value: checked
  12907. });
  12908. });
  12909. element.addEventListener("resetform", event => {
  12910. const defaultValue = data.defaultFieldValue || "Off";
  12911. event.target.checked = defaultValue === data.exportValue;
  12912. });
  12913. if (this.enableScripting && this.hasJSActions) {
  12914. element.addEventListener("updatefromsandbox", jsEvent => {
  12915. const actions = {
  12916. value(event) {
  12917. event.target.checked = event.detail.value !== "Off";
  12918. storage.setValue(id, {
  12919. value: event.target.checked
  12920. });
  12921. }
  12922. };
  12923. this._dispatchEventFromSandbox(actions, jsEvent);
  12924. });
  12925. 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);
  12926. }
  12927. this._setBackgroundColor(element);
  12928. this._setDefaultPropertiesFromJS(element);
  12929. this.container.append(element);
  12930. return this.container;
  12931. }
  12932. }
  12933. class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
  12934. constructor(parameters) {
  12935. super(parameters, {
  12936. isRenderable: parameters.renderForms
  12937. });
  12938. }
  12939. render() {
  12940. this.container.className = "buttonWidgetAnnotation radioButton";
  12941. const storage = this.annotationStorage;
  12942. const data = this.data;
  12943. const id = data.id;
  12944. let value = storage.getValue(id, {
  12945. value: data.fieldValue === data.buttonValue
  12946. }).value;
  12947. if (typeof value === "string") {
  12948. value = value !== data.buttonValue;
  12949. storage.setValue(id, {
  12950. value
  12951. });
  12952. }
  12953. const element = document.createElement("input");
  12954. GetElementsByNameSet.add(element);
  12955. element.setAttribute("data-element-id", id);
  12956. element.disabled = data.readOnly;
  12957. this._setRequired(element, this.data.required);
  12958. element.type = "radio";
  12959. element.name = data.fieldName;
  12960. if (value) {
  12961. element.setAttribute("checked", true);
  12962. }
  12963. element.tabIndex = DEFAULT_TAB_INDEX;
  12964. element.addEventListener("change", event => {
  12965. const {
  12966. name,
  12967. checked
  12968. } = event.target;
  12969. for (const radio of this._getElementsByName(name, id)) {
  12970. storage.setValue(radio.id, {
  12971. value: false
  12972. });
  12973. }
  12974. storage.setValue(id, {
  12975. value: checked
  12976. });
  12977. });
  12978. element.addEventListener("resetform", event => {
  12979. const defaultValue = data.defaultFieldValue;
  12980. event.target.checked = defaultValue !== null && defaultValue !== undefined && defaultValue === data.buttonValue;
  12981. });
  12982. if (this.enableScripting && this.hasJSActions) {
  12983. const pdfButtonValue = data.buttonValue;
  12984. element.addEventListener("updatefromsandbox", jsEvent => {
  12985. const actions = {
  12986. value: event => {
  12987. const checked = pdfButtonValue === event.detail.value;
  12988. for (const radio of this._getElementsByName(event.target.name)) {
  12989. const curChecked = checked && radio.id === id;
  12990. if (radio.domElement) {
  12991. radio.domElement.checked = curChecked;
  12992. }
  12993. storage.setValue(radio.id, {
  12994. value: curChecked
  12995. });
  12996. }
  12997. }
  12998. };
  12999. this._dispatchEventFromSandbox(actions, jsEvent);
  13000. });
  13001. 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);
  13002. }
  13003. this._setBackgroundColor(element);
  13004. this._setDefaultPropertiesFromJS(element);
  13005. this.container.append(element);
  13006. return this.container;
  13007. }
  13008. }
  13009. class PushButtonWidgetAnnotationElement extends LinkAnnotationElement {
  13010. constructor(parameters) {
  13011. super(parameters, {
  13012. ignoreBorder: parameters.data.hasAppearance
  13013. });
  13014. }
  13015. render() {
  13016. const container = super.render();
  13017. container.className = "buttonWidgetAnnotation pushButton";
  13018. if (this.data.alternativeText) {
  13019. container.title = this.data.alternativeText;
  13020. }
  13021. const linkElement = container.lastChild;
  13022. if (this.enableScripting && this.hasJSActions && linkElement) {
  13023. this._setDefaultPropertiesFromJS(linkElement);
  13024. linkElement.addEventListener("updatefromsandbox", jsEvent => {
  13025. this._dispatchEventFromSandbox({}, jsEvent);
  13026. });
  13027. }
  13028. return container;
  13029. }
  13030. }
  13031. class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
  13032. constructor(parameters) {
  13033. super(parameters, {
  13034. isRenderable: parameters.renderForms
  13035. });
  13036. }
  13037. render() {
  13038. this.container.className = "choiceWidgetAnnotation";
  13039. const storage = this.annotationStorage;
  13040. const id = this.data.id;
  13041. const storedData = storage.getValue(id, {
  13042. value: this.data.fieldValue
  13043. });
  13044. const selectElement = document.createElement("select");
  13045. GetElementsByNameSet.add(selectElement);
  13046. selectElement.setAttribute("data-element-id", id);
  13047. selectElement.disabled = this.data.readOnly;
  13048. this._setRequired(selectElement, this.data.required);
  13049. selectElement.name = this.data.fieldName;
  13050. selectElement.tabIndex = DEFAULT_TAB_INDEX;
  13051. let addAnEmptyEntry = this.data.combo && this.data.options.length > 0;
  13052. if (!this.data.combo) {
  13053. selectElement.size = this.data.options.length;
  13054. if (this.data.multiSelect) {
  13055. selectElement.multiple = true;
  13056. }
  13057. }
  13058. selectElement.addEventListener("resetform", event => {
  13059. const defaultValue = this.data.defaultFieldValue;
  13060. for (const option of selectElement.options) {
  13061. option.selected = option.value === defaultValue;
  13062. }
  13063. });
  13064. for (const option of this.data.options) {
  13065. const optionElement = document.createElement("option");
  13066. optionElement.textContent = option.displayValue;
  13067. optionElement.value = option.exportValue;
  13068. if (storedData.value.includes(option.exportValue)) {
  13069. optionElement.setAttribute("selected", true);
  13070. addAnEmptyEntry = false;
  13071. }
  13072. selectElement.append(optionElement);
  13073. }
  13074. let removeEmptyEntry = null;
  13075. if (addAnEmptyEntry) {
  13076. const noneOptionElement = document.createElement("option");
  13077. noneOptionElement.value = " ";
  13078. noneOptionElement.setAttribute("hidden", true);
  13079. noneOptionElement.setAttribute("selected", true);
  13080. selectElement.prepend(noneOptionElement);
  13081. removeEmptyEntry = () => {
  13082. noneOptionElement.remove();
  13083. selectElement.removeEventListener("input", removeEmptyEntry);
  13084. removeEmptyEntry = null;
  13085. };
  13086. selectElement.addEventListener("input", removeEmptyEntry);
  13087. }
  13088. const getValue = isExport => {
  13089. const name = isExport ? "value" : "textContent";
  13090. const {
  13091. options,
  13092. multiple
  13093. } = selectElement;
  13094. if (!multiple) {
  13095. return options.selectedIndex === -1 ? null : options[options.selectedIndex][name];
  13096. }
  13097. return Array.prototype.filter.call(options, option => option.selected).map(option => option[name]);
  13098. };
  13099. let selectedValues = getValue(false);
  13100. const getItems = event => {
  13101. const options = event.target.options;
  13102. return Array.prototype.map.call(options, option => {
  13103. return {
  13104. displayValue: option.textContent,
  13105. exportValue: option.value
  13106. };
  13107. });
  13108. };
  13109. if (this.enableScripting && this.hasJSActions) {
  13110. selectElement.addEventListener("updatefromsandbox", jsEvent => {
  13111. const actions = {
  13112. value(event) {
  13113. removeEmptyEntry?.();
  13114. const value = event.detail.value;
  13115. const values = new Set(Array.isArray(value) ? value : [value]);
  13116. for (const option of selectElement.options) {
  13117. option.selected = values.has(option.value);
  13118. }
  13119. storage.setValue(id, {
  13120. value: getValue(true)
  13121. });
  13122. selectedValues = getValue(false);
  13123. },
  13124. multipleSelection(event) {
  13125. selectElement.multiple = true;
  13126. },
  13127. remove(event) {
  13128. const options = selectElement.options;
  13129. const index = event.detail.remove;
  13130. options[index].selected = false;
  13131. selectElement.remove(index);
  13132. if (options.length > 0) {
  13133. const i = Array.prototype.findIndex.call(options, option => option.selected);
  13134. if (i === -1) {
  13135. options[0].selected = true;
  13136. }
  13137. }
  13138. storage.setValue(id, {
  13139. value: getValue(true),
  13140. items: getItems(event)
  13141. });
  13142. selectedValues = getValue(false);
  13143. },
  13144. clear(event) {
  13145. while (selectElement.length !== 0) {
  13146. selectElement.remove(0);
  13147. }
  13148. storage.setValue(id, {
  13149. value: null,
  13150. items: []
  13151. });
  13152. selectedValues = getValue(false);
  13153. },
  13154. insert(event) {
  13155. const {
  13156. index,
  13157. displayValue,
  13158. exportValue
  13159. } = event.detail.insert;
  13160. const selectChild = selectElement.children[index];
  13161. const optionElement = document.createElement("option");
  13162. optionElement.textContent = displayValue;
  13163. optionElement.value = exportValue;
  13164. if (selectChild) {
  13165. selectChild.before(optionElement);
  13166. } else {
  13167. selectElement.append(optionElement);
  13168. }
  13169. storage.setValue(id, {
  13170. value: getValue(true),
  13171. items: getItems(event)
  13172. });
  13173. selectedValues = getValue(false);
  13174. },
  13175. items(event) {
  13176. const {
  13177. items
  13178. } = event.detail;
  13179. while (selectElement.length !== 0) {
  13180. selectElement.remove(0);
  13181. }
  13182. for (const item of items) {
  13183. const {
  13184. displayValue,
  13185. exportValue
  13186. } = item;
  13187. const optionElement = document.createElement("option");
  13188. optionElement.textContent = displayValue;
  13189. optionElement.value = exportValue;
  13190. selectElement.append(optionElement);
  13191. }
  13192. if (selectElement.options.length > 0) {
  13193. selectElement.options[0].selected = true;
  13194. }
  13195. storage.setValue(id, {
  13196. value: getValue(true),
  13197. items: getItems(event)
  13198. });
  13199. selectedValues = getValue(false);
  13200. },
  13201. indices(event) {
  13202. const indices = new Set(event.detail.indices);
  13203. for (const option of event.target.options) {
  13204. option.selected = indices.has(option.index);
  13205. }
  13206. storage.setValue(id, {
  13207. value: getValue(true)
  13208. });
  13209. selectedValues = getValue(false);
  13210. },
  13211. editable(event) {
  13212. event.target.disabled = !event.detail.editable;
  13213. }
  13214. };
  13215. this._dispatchEventFromSandbox(actions, jsEvent);
  13216. });
  13217. selectElement.addEventListener("input", event => {
  13218. const exportValue = getValue(true);
  13219. storage.setValue(id, {
  13220. value: exportValue
  13221. });
  13222. event.preventDefault();
  13223. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  13224. source: this,
  13225. detail: {
  13226. id,
  13227. name: "Keystroke",
  13228. value: selectedValues,
  13229. changeEx: exportValue,
  13230. willCommit: false,
  13231. commitKey: 1,
  13232. keyDown: false
  13233. }
  13234. });
  13235. });
  13236. this._setEventListeners(selectElement, [["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"], ["input", "Action"]], event => event.target.checked);
  13237. } else {
  13238. selectElement.addEventListener("input", function (event) {
  13239. storage.setValue(id, {
  13240. value: getValue(true)
  13241. });
  13242. });
  13243. }
  13244. if (this.data.combo) {
  13245. this._setTextStyle(selectElement);
  13246. } else {}
  13247. this._setBackgroundColor(selectElement);
  13248. this._setDefaultPropertiesFromJS(selectElement);
  13249. this.container.append(selectElement);
  13250. return this.container;
  13251. }
  13252. }
  13253. class PopupAnnotationElement extends AnnotationElement {
  13254. static IGNORE_TYPES = new Set(["Line", "Square", "Circle", "PolyLine", "Polygon", "Ink"]);
  13255. constructor(parameters) {
  13256. const {
  13257. data
  13258. } = parameters;
  13259. const isRenderable = !PopupAnnotationElement.IGNORE_TYPES.has(data.parentType) && !!(data.titleObj?.str || data.contentsObj?.str || data.richText?.str);
  13260. super(parameters, {
  13261. isRenderable
  13262. });
  13263. }
  13264. render() {
  13265. this.container.className = "popupAnnotation";
  13266. const parentElements = this.layer.querySelectorAll(`[data-annotation-id="${this.data.parentId}"]`);
  13267. if (parentElements.length === 0) {
  13268. return this.container;
  13269. }
  13270. const popup = new PopupElement({
  13271. container: this.container,
  13272. trigger: Array.from(parentElements),
  13273. color: this.data.color,
  13274. titleObj: this.data.titleObj,
  13275. modificationDate: this.data.modificationDate,
  13276. contentsObj: this.data.contentsObj,
  13277. richText: this.data.richText
  13278. });
  13279. const page = this.page;
  13280. 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]]);
  13281. const popupLeft = rect[0] + this.data.parentRect[2] - this.data.parentRect[0];
  13282. const popupTop = rect[1];
  13283. const {
  13284. pageWidth,
  13285. pageHeight,
  13286. pageX,
  13287. pageY
  13288. } = this.viewport.rawDims;
  13289. this.container.style.left = `${100 * (popupLeft - pageX) / pageWidth}%`;
  13290. this.container.style.top = `${100 * (popupTop - pageY) / pageHeight}%`;
  13291. this.container.append(popup.render());
  13292. return this.container;
  13293. }
  13294. }
  13295. class PopupElement {
  13296. constructor(parameters) {
  13297. this.container = parameters.container;
  13298. this.trigger = parameters.trigger;
  13299. this.color = parameters.color;
  13300. this.titleObj = parameters.titleObj;
  13301. this.modificationDate = parameters.modificationDate;
  13302. this.contentsObj = parameters.contentsObj;
  13303. this.richText = parameters.richText;
  13304. this.hideWrapper = parameters.hideWrapper || false;
  13305. this.pinned = false;
  13306. }
  13307. render() {
  13308. const BACKGROUND_ENLIGHT = 0.7;
  13309. const wrapper = document.createElement("div");
  13310. wrapper.className = "popupWrapper";
  13311. this.hideElement = this.hideWrapper ? wrapper : this.container;
  13312. this.hideElement.hidden = true;
  13313. const popup = document.createElement("div");
  13314. popup.className = "popup";
  13315. const color = this.color;
  13316. if (color) {
  13317. const r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  13318. const g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  13319. const b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  13320. popup.style.backgroundColor = _util.Util.makeHexColor(r | 0, g | 0, b | 0);
  13321. }
  13322. const title = document.createElement("h1");
  13323. title.dir = this.titleObj.dir;
  13324. title.textContent = this.titleObj.str;
  13325. popup.append(title);
  13326. const dateObject = _display_utils.PDFDateString.toDateObject(this.modificationDate);
  13327. if (dateObject) {
  13328. const modificationDate = document.createElement("span");
  13329. modificationDate.className = "popupDate";
  13330. modificationDate.textContent = "{{date}}, {{time}}";
  13331. modificationDate.dataset.l10nId = "annotation_date_string";
  13332. modificationDate.dataset.l10nArgs = JSON.stringify({
  13333. date: dateObject.toLocaleDateString(),
  13334. time: dateObject.toLocaleTimeString()
  13335. });
  13336. popup.append(modificationDate);
  13337. }
  13338. if (this.richText?.str && (!this.contentsObj?.str || this.contentsObj.str === this.richText.str)) {
  13339. _xfa_layer.XfaLayer.render({
  13340. xfaHtml: this.richText.html,
  13341. intent: "richText",
  13342. div: popup
  13343. });
  13344. popup.lastChild.className = "richText popupContent";
  13345. } else {
  13346. const contents = this._formatContents(this.contentsObj);
  13347. popup.append(contents);
  13348. }
  13349. if (!Array.isArray(this.trigger)) {
  13350. this.trigger = [this.trigger];
  13351. }
  13352. for (const element of this.trigger) {
  13353. element.addEventListener("click", this._toggle.bind(this));
  13354. element.addEventListener("mouseover", this._show.bind(this, false));
  13355. element.addEventListener("mouseout", this._hide.bind(this, false));
  13356. }
  13357. popup.addEventListener("click", this._hide.bind(this, true));
  13358. wrapper.append(popup);
  13359. return wrapper;
  13360. }
  13361. _formatContents({
  13362. str,
  13363. dir
  13364. }) {
  13365. const p = document.createElement("p");
  13366. p.className = "popupContent";
  13367. p.dir = dir;
  13368. const lines = str.split(/(?:\r\n?|\n)/);
  13369. for (let i = 0, ii = lines.length; i < ii; ++i) {
  13370. const line = lines[i];
  13371. p.append(document.createTextNode(line));
  13372. if (i < ii - 1) {
  13373. p.append(document.createElement("br"));
  13374. }
  13375. }
  13376. return p;
  13377. }
  13378. _toggle() {
  13379. if (this.pinned) {
  13380. this._hide(true);
  13381. } else {
  13382. this._show(true);
  13383. }
  13384. }
  13385. _show(pin = false) {
  13386. if (pin) {
  13387. this.pinned = true;
  13388. }
  13389. if (this.hideElement.hidden) {
  13390. this.hideElement.hidden = false;
  13391. this.container.style.zIndex = parseInt(this.container.style.zIndex) + 1000;
  13392. }
  13393. }
  13394. _hide(unpin = true) {
  13395. if (unpin) {
  13396. this.pinned = false;
  13397. }
  13398. if (!this.hideElement.hidden && !this.pinned) {
  13399. this.hideElement.hidden = true;
  13400. this.container.style.zIndex = parseInt(this.container.style.zIndex) - 1000;
  13401. }
  13402. }
  13403. }
  13404. class FreeTextAnnotationElement extends AnnotationElement {
  13405. constructor(parameters) {
  13406. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  13407. super(parameters, {
  13408. isRenderable,
  13409. ignoreBorder: true
  13410. });
  13411. this.textContent = parameters.data.textContent;
  13412. }
  13413. render() {
  13414. this.container.className = "freeTextAnnotation";
  13415. if (this.textContent) {
  13416. const content = document.createElement("div");
  13417. content.className = "annotationTextContent";
  13418. content.setAttribute("role", "comment");
  13419. for (const line of this.textContent) {
  13420. const lineSpan = document.createElement("span");
  13421. lineSpan.textContent = line;
  13422. content.append(lineSpan);
  13423. }
  13424. this.container.append(content);
  13425. }
  13426. if (!this.data.hasPopup) {
  13427. this._createPopup(null, this.data);
  13428. }
  13429. return this.container;
  13430. }
  13431. }
  13432. class LineAnnotationElement extends AnnotationElement {
  13433. constructor(parameters) {
  13434. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  13435. super(parameters, {
  13436. isRenderable,
  13437. ignoreBorder: true
  13438. });
  13439. }
  13440. render() {
  13441. this.container.className = "lineAnnotation";
  13442. const data = this.data;
  13443. const {
  13444. width,
  13445. height
  13446. } = getRectDims(data.rect);
  13447. const svg = this.svgFactory.create(width, height, true);
  13448. const line = this.svgFactory.createElement("svg:line");
  13449. line.setAttribute("x1", data.rect[2] - data.lineCoordinates[0]);
  13450. line.setAttribute("y1", data.rect[3] - data.lineCoordinates[1]);
  13451. line.setAttribute("x2", data.rect[2] - data.lineCoordinates[2]);
  13452. line.setAttribute("y2", data.rect[3] - data.lineCoordinates[3]);
  13453. line.setAttribute("stroke-width", data.borderStyle.width || 1);
  13454. line.setAttribute("stroke", "transparent");
  13455. line.setAttribute("fill", "transparent");
  13456. svg.append(line);
  13457. this.container.append(svg);
  13458. this._createPopup(line, data);
  13459. return this.container;
  13460. }
  13461. }
  13462. class SquareAnnotationElement extends AnnotationElement {
  13463. constructor(parameters) {
  13464. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  13465. super(parameters, {
  13466. isRenderable,
  13467. ignoreBorder: true
  13468. });
  13469. }
  13470. render() {
  13471. this.container.className = "squareAnnotation";
  13472. const data = this.data;
  13473. const {
  13474. width,
  13475. height
  13476. } = getRectDims(data.rect);
  13477. const svg = this.svgFactory.create(width, height, true);
  13478. const borderWidth = data.borderStyle.width;
  13479. const square = this.svgFactory.createElement("svg:rect");
  13480. square.setAttribute("x", borderWidth / 2);
  13481. square.setAttribute("y", borderWidth / 2);
  13482. square.setAttribute("width", width - borderWidth);
  13483. square.setAttribute("height", height - borderWidth);
  13484. square.setAttribute("stroke-width", borderWidth || 1);
  13485. square.setAttribute("stroke", "transparent");
  13486. square.setAttribute("fill", "transparent");
  13487. svg.append(square);
  13488. this.container.append(svg);
  13489. this._createPopup(square, data);
  13490. return this.container;
  13491. }
  13492. }
  13493. class CircleAnnotationElement extends AnnotationElement {
  13494. constructor(parameters) {
  13495. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  13496. super(parameters, {
  13497. isRenderable,
  13498. ignoreBorder: true
  13499. });
  13500. }
  13501. render() {
  13502. this.container.className = "circleAnnotation";
  13503. const data = this.data;
  13504. const {
  13505. width,
  13506. height
  13507. } = getRectDims(data.rect);
  13508. const svg = this.svgFactory.create(width, height, true);
  13509. const borderWidth = data.borderStyle.width;
  13510. const circle = this.svgFactory.createElement("svg:ellipse");
  13511. circle.setAttribute("cx", width / 2);
  13512. circle.setAttribute("cy", height / 2);
  13513. circle.setAttribute("rx", width / 2 - borderWidth / 2);
  13514. circle.setAttribute("ry", height / 2 - borderWidth / 2);
  13515. circle.setAttribute("stroke-width", borderWidth || 1);
  13516. circle.setAttribute("stroke", "transparent");
  13517. circle.setAttribute("fill", "transparent");
  13518. svg.append(circle);
  13519. this.container.append(svg);
  13520. this._createPopup(circle, data);
  13521. return this.container;
  13522. }
  13523. }
  13524. class PolylineAnnotationElement extends AnnotationElement {
  13525. constructor(parameters) {
  13526. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  13527. super(parameters, {
  13528. isRenderable,
  13529. ignoreBorder: true
  13530. });
  13531. this.containerClassName = "polylineAnnotation";
  13532. this.svgElementName = "svg:polyline";
  13533. }
  13534. render() {
  13535. this.container.className = this.containerClassName;
  13536. const data = this.data;
  13537. const {
  13538. width,
  13539. height
  13540. } = getRectDims(data.rect);
  13541. const svg = this.svgFactory.create(width, height, true);
  13542. let points = [];
  13543. for (const coordinate of data.vertices) {
  13544. const x = coordinate.x - data.rect[0];
  13545. const y = data.rect[3] - coordinate.y;
  13546. points.push(x + "," + y);
  13547. }
  13548. points = points.join(" ");
  13549. const polyline = this.svgFactory.createElement(this.svgElementName);
  13550. polyline.setAttribute("points", points);
  13551. polyline.setAttribute("stroke-width", data.borderStyle.width || 1);
  13552. polyline.setAttribute("stroke", "transparent");
  13553. polyline.setAttribute("fill", "transparent");
  13554. svg.append(polyline);
  13555. this.container.append(svg);
  13556. this._createPopup(polyline, data);
  13557. return this.container;
  13558. }
  13559. }
  13560. class PolygonAnnotationElement extends PolylineAnnotationElement {
  13561. constructor(parameters) {
  13562. super(parameters);
  13563. this.containerClassName = "polygonAnnotation";
  13564. this.svgElementName = "svg:polygon";
  13565. }
  13566. }
  13567. class CaretAnnotationElement extends AnnotationElement {
  13568. constructor(parameters) {
  13569. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  13570. super(parameters, {
  13571. isRenderable,
  13572. ignoreBorder: true
  13573. });
  13574. }
  13575. render() {
  13576. this.container.className = "caretAnnotation";
  13577. if (!this.data.hasPopup) {
  13578. this._createPopup(null, this.data);
  13579. }
  13580. return this.container;
  13581. }
  13582. }
  13583. class InkAnnotationElement extends AnnotationElement {
  13584. constructor(parameters) {
  13585. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  13586. super(parameters, {
  13587. isRenderable,
  13588. ignoreBorder: true
  13589. });
  13590. this.containerClassName = "inkAnnotation";
  13591. this.svgElementName = "svg:polyline";
  13592. }
  13593. render() {
  13594. this.container.className = this.containerClassName;
  13595. const data = this.data;
  13596. const {
  13597. width,
  13598. height
  13599. } = getRectDims(data.rect);
  13600. const svg = this.svgFactory.create(width, height, true);
  13601. for (const inkList of data.inkLists) {
  13602. let points = [];
  13603. for (const coordinate of inkList) {
  13604. const x = coordinate.x - data.rect[0];
  13605. const y = data.rect[3] - coordinate.y;
  13606. points.push(`${x},${y}`);
  13607. }
  13608. points = points.join(" ");
  13609. const polyline = this.svgFactory.createElement(this.svgElementName);
  13610. polyline.setAttribute("points", points);
  13611. polyline.setAttribute("stroke-width", data.borderStyle.width || 1);
  13612. polyline.setAttribute("stroke", "transparent");
  13613. polyline.setAttribute("fill", "transparent");
  13614. this._createPopup(polyline, data);
  13615. svg.append(polyline);
  13616. }
  13617. this.container.append(svg);
  13618. return this.container;
  13619. }
  13620. }
  13621. class HighlightAnnotationElement extends AnnotationElement {
  13622. constructor(parameters) {
  13623. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  13624. super(parameters, {
  13625. isRenderable,
  13626. ignoreBorder: true,
  13627. createQuadrilaterals: true
  13628. });
  13629. }
  13630. render() {
  13631. if (!this.data.hasPopup) {
  13632. this._createPopup(null, this.data);
  13633. }
  13634. if (this.quadrilaterals) {
  13635. return this._renderQuadrilaterals("highlightAnnotation");
  13636. }
  13637. this.container.className = "highlightAnnotation";
  13638. return this.container;
  13639. }
  13640. }
  13641. class UnderlineAnnotationElement extends AnnotationElement {
  13642. constructor(parameters) {
  13643. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  13644. super(parameters, {
  13645. isRenderable,
  13646. ignoreBorder: true,
  13647. createQuadrilaterals: true
  13648. });
  13649. }
  13650. render() {
  13651. if (!this.data.hasPopup) {
  13652. this._createPopup(null, this.data);
  13653. }
  13654. if (this.quadrilaterals) {
  13655. return this._renderQuadrilaterals("underlineAnnotation");
  13656. }
  13657. this.container.className = "underlineAnnotation";
  13658. return this.container;
  13659. }
  13660. }
  13661. class SquigglyAnnotationElement extends AnnotationElement {
  13662. constructor(parameters) {
  13663. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  13664. super(parameters, {
  13665. isRenderable,
  13666. ignoreBorder: true,
  13667. createQuadrilaterals: true
  13668. });
  13669. }
  13670. render() {
  13671. if (!this.data.hasPopup) {
  13672. this._createPopup(null, this.data);
  13673. }
  13674. if (this.quadrilaterals) {
  13675. return this._renderQuadrilaterals("squigglyAnnotation");
  13676. }
  13677. this.container.className = "squigglyAnnotation";
  13678. return this.container;
  13679. }
  13680. }
  13681. class StrikeOutAnnotationElement extends AnnotationElement {
  13682. constructor(parameters) {
  13683. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  13684. super(parameters, {
  13685. isRenderable,
  13686. ignoreBorder: true,
  13687. createQuadrilaterals: true
  13688. });
  13689. }
  13690. render() {
  13691. if (!this.data.hasPopup) {
  13692. this._createPopup(null, this.data);
  13693. }
  13694. if (this.quadrilaterals) {
  13695. return this._renderQuadrilaterals("strikeoutAnnotation");
  13696. }
  13697. this.container.className = "strikeoutAnnotation";
  13698. return this.container;
  13699. }
  13700. }
  13701. class StampAnnotationElement extends AnnotationElement {
  13702. constructor(parameters) {
  13703. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  13704. super(parameters, {
  13705. isRenderable,
  13706. ignoreBorder: true
  13707. });
  13708. }
  13709. render() {
  13710. this.container.className = "stampAnnotation";
  13711. if (!this.data.hasPopup) {
  13712. this._createPopup(null, this.data);
  13713. }
  13714. return this.container;
  13715. }
  13716. }
  13717. class FileAttachmentAnnotationElement extends AnnotationElement {
  13718. constructor(parameters) {
  13719. super(parameters, {
  13720. isRenderable: true
  13721. });
  13722. const {
  13723. filename,
  13724. content
  13725. } = this.data.file;
  13726. this.filename = (0, _display_utils.getFilenameFromUrl)(filename, true);
  13727. this.content = content;
  13728. this.linkService.eventBus?.dispatch("fileattachmentannotation", {
  13729. source: this,
  13730. filename,
  13731. content
  13732. });
  13733. }
  13734. render() {
  13735. this.container.className = "fileAttachmentAnnotation";
  13736. let trigger;
  13737. if (this.data.hasAppearance) {
  13738. trigger = document.createElement("div");
  13739. } else {
  13740. trigger = document.createElement("img");
  13741. trigger.src = `${this.imageResourcesPath}annotation-${/paperclip/i.test(this.data.name) ? "paperclip" : "pushpin"}.svg`;
  13742. }
  13743. trigger.className = "popupTriggerArea";
  13744. trigger.addEventListener("dblclick", this._download.bind(this));
  13745. if (!this.data.hasPopup && (this.data.titleObj?.str || this.data.contentsObj?.str || this.data.richText)) {
  13746. this._createPopup(trigger, this.data);
  13747. }
  13748. this.container.append(trigger);
  13749. return this.container;
  13750. }
  13751. _download() {
  13752. this.downloadManager?.openOrDownloadData(this.container, this.content, this.filename);
  13753. }
  13754. }
  13755. class AnnotationLayer {
  13756. static #appendElement(element, id, div, accessibilityManager) {
  13757. const contentElement = element.firstChild || element;
  13758. contentElement.id = `${_display_utils.AnnotationPrefix}${id}`;
  13759. div.append(element);
  13760. accessibilityManager?.moveElementInDOM(div, element, contentElement, false);
  13761. }
  13762. static render(params) {
  13763. const {
  13764. annotations,
  13765. div,
  13766. viewport,
  13767. accessibilityManager
  13768. } = params;
  13769. (0, _display_utils.setLayerDimensions)(div, viewport);
  13770. const elementParams = {
  13771. data: null,
  13772. layer: div,
  13773. page: params.page,
  13774. viewport,
  13775. linkService: params.linkService,
  13776. downloadManager: params.downloadManager,
  13777. imageResourcesPath: params.imageResourcesPath || "",
  13778. renderForms: params.renderForms !== false,
  13779. svgFactory: new _display_utils.DOMSVGFactory(),
  13780. annotationStorage: params.annotationStorage || new _annotation_storage.AnnotationStorage(),
  13781. enableScripting: params.enableScripting === true,
  13782. hasJSActions: params.hasJSActions,
  13783. fieldObjects: params.fieldObjects
  13784. };
  13785. let zIndex = 0;
  13786. for (const data of annotations) {
  13787. if (data.annotationType !== _util.AnnotationType.POPUP) {
  13788. const {
  13789. width,
  13790. height
  13791. } = getRectDims(data.rect);
  13792. if (width <= 0 || height <= 0) {
  13793. continue;
  13794. }
  13795. }
  13796. elementParams.data = data;
  13797. const element = AnnotationElementFactory.create(elementParams);
  13798. if (!element.isRenderable) {
  13799. continue;
  13800. }
  13801. const rendered = element.render();
  13802. if (data.hidden) {
  13803. rendered.style.visibility = "hidden";
  13804. }
  13805. if (Array.isArray(rendered)) {
  13806. for (const renderedElement of rendered) {
  13807. renderedElement.style.zIndex = zIndex++;
  13808. AnnotationLayer.#appendElement(renderedElement, data.id, div, accessibilityManager);
  13809. }
  13810. } else {
  13811. rendered.style.zIndex = zIndex++;
  13812. if (element instanceof PopupAnnotationElement) {
  13813. div.prepend(rendered);
  13814. } else {
  13815. AnnotationLayer.#appendElement(rendered, data.id, div, accessibilityManager);
  13816. }
  13817. }
  13818. }
  13819. this.#setAnnotationCanvasMap(div, params.annotationCanvasMap);
  13820. }
  13821. static update(params) {
  13822. const {
  13823. annotationCanvasMap,
  13824. div,
  13825. viewport
  13826. } = params;
  13827. (0, _display_utils.setLayerDimensions)(div, {
  13828. rotation: viewport.rotation
  13829. });
  13830. this.#setAnnotationCanvasMap(div, annotationCanvasMap);
  13831. div.hidden = false;
  13832. }
  13833. static #setAnnotationCanvasMap(div, annotationCanvasMap) {
  13834. if (!annotationCanvasMap) {
  13835. return;
  13836. }
  13837. for (const [id, canvas] of annotationCanvasMap) {
  13838. const element = div.querySelector(`[data-annotation-id="${id}"]`);
  13839. if (!element) {
  13840. continue;
  13841. }
  13842. const {
  13843. firstChild
  13844. } = element;
  13845. if (!firstChild) {
  13846. element.append(canvas);
  13847. } else if (firstChild.nodeName === "CANVAS") {
  13848. firstChild.replaceWith(canvas);
  13849. } else {
  13850. firstChild.before(canvas);
  13851. }
  13852. }
  13853. annotationCanvasMap.clear();
  13854. }
  13855. }
  13856. exports.AnnotationLayer = AnnotationLayer;
  13857. /***/ }),
  13858. /* 33 */
  13859. /***/ ((__unused_webpack_module, exports) => {
  13860. Object.defineProperty(exports, "__esModule", ({
  13861. value: true
  13862. }));
  13863. exports.ColorConverters = void 0;
  13864. function makeColorComp(n) {
  13865. return Math.floor(Math.max(0, Math.min(1, n)) * 255).toString(16).padStart(2, "0");
  13866. }
  13867. class ColorConverters {
  13868. static CMYK_G([c, y, m, k]) {
  13869. return ["G", 1 - Math.min(1, 0.3 * c + 0.59 * m + 0.11 * y + k)];
  13870. }
  13871. static G_CMYK([g]) {
  13872. return ["CMYK", 0, 0, 0, 1 - g];
  13873. }
  13874. static G_RGB([g]) {
  13875. return ["RGB", g, g, g];
  13876. }
  13877. static G_HTML([g]) {
  13878. const G = makeColorComp(g);
  13879. return `#${G}${G}${G}`;
  13880. }
  13881. static RGB_G([r, g, b]) {
  13882. return ["G", 0.3 * r + 0.59 * g + 0.11 * b];
  13883. }
  13884. static RGB_HTML([r, g, b]) {
  13885. const R = makeColorComp(r);
  13886. const G = makeColorComp(g);
  13887. const B = makeColorComp(b);
  13888. return `#${R}${G}${B}`;
  13889. }
  13890. static T_HTML() {
  13891. return "#00000000";
  13892. }
  13893. static CMYK_RGB([c, y, m, k]) {
  13894. return ["RGB", 1 - Math.min(1, c + k), 1 - Math.min(1, m + k), 1 - Math.min(1, y + k)];
  13895. }
  13896. static CMYK_HTML(components) {
  13897. const rgb = this.CMYK_RGB(components).slice(1);
  13898. return this.RGB_HTML(rgb);
  13899. }
  13900. static RGB_CMYK([r, g, b]) {
  13901. const c = 1 - r;
  13902. const m = 1 - g;
  13903. const y = 1 - b;
  13904. const k = Math.min(c, m, y);
  13905. return ["CMYK", c, m, y, k];
  13906. }
  13907. }
  13908. exports.ColorConverters = ColorConverters;
  13909. /***/ }),
  13910. /* 34 */
  13911. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  13912. Object.defineProperty(exports, "__esModule", ({
  13913. value: true
  13914. }));
  13915. exports.XfaLayer = void 0;
  13916. var _xfa_text = __w_pdfjs_require__(19);
  13917. class XfaLayer {
  13918. static setupStorage(html, id, element, storage, intent) {
  13919. const storedData = storage.getValue(id, {
  13920. value: null
  13921. });
  13922. switch (element.name) {
  13923. case "textarea":
  13924. if (storedData.value !== null) {
  13925. html.textContent = storedData.value;
  13926. }
  13927. if (intent === "print") {
  13928. break;
  13929. }
  13930. html.addEventListener("input", event => {
  13931. storage.setValue(id, {
  13932. value: event.target.value
  13933. });
  13934. });
  13935. break;
  13936. case "input":
  13937. if (element.attributes.type === "radio" || element.attributes.type === "checkbox") {
  13938. if (storedData.value === element.attributes.xfaOn) {
  13939. html.setAttribute("checked", true);
  13940. } else if (storedData.value === element.attributes.xfaOff) {
  13941. html.removeAttribute("checked");
  13942. }
  13943. if (intent === "print") {
  13944. break;
  13945. }
  13946. html.addEventListener("change", event => {
  13947. storage.setValue(id, {
  13948. value: event.target.checked ? event.target.getAttribute("xfaOn") : event.target.getAttribute("xfaOff")
  13949. });
  13950. });
  13951. } else {
  13952. if (storedData.value !== null) {
  13953. html.setAttribute("value", storedData.value);
  13954. }
  13955. if (intent === "print") {
  13956. break;
  13957. }
  13958. html.addEventListener("input", event => {
  13959. storage.setValue(id, {
  13960. value: event.target.value
  13961. });
  13962. });
  13963. }
  13964. break;
  13965. case "select":
  13966. if (storedData.value !== null) {
  13967. for (const option of element.children) {
  13968. if (option.attributes.value === storedData.value) {
  13969. option.attributes.selected = true;
  13970. }
  13971. }
  13972. }
  13973. html.addEventListener("input", event => {
  13974. const options = event.target.options;
  13975. const value = options.selectedIndex === -1 ? "" : options[options.selectedIndex].value;
  13976. storage.setValue(id, {
  13977. value
  13978. });
  13979. });
  13980. break;
  13981. }
  13982. }
  13983. static setAttributes({
  13984. html,
  13985. element,
  13986. storage = null,
  13987. intent,
  13988. linkService
  13989. }) {
  13990. const {
  13991. attributes
  13992. } = element;
  13993. const isHTMLAnchorElement = html instanceof HTMLAnchorElement;
  13994. if (attributes.type === "radio") {
  13995. attributes.name = `${attributes.name}-${intent}`;
  13996. }
  13997. for (const [key, value] of Object.entries(attributes)) {
  13998. if (value === null || value === undefined) {
  13999. continue;
  14000. }
  14001. switch (key) {
  14002. case "class":
  14003. if (value.length) {
  14004. html.setAttribute(key, value.join(" "));
  14005. }
  14006. break;
  14007. case "dataId":
  14008. break;
  14009. case "id":
  14010. html.setAttribute("data-element-id", value);
  14011. break;
  14012. case "style":
  14013. Object.assign(html.style, value);
  14014. break;
  14015. case "textContent":
  14016. html.textContent = value;
  14017. break;
  14018. default:
  14019. if (!isHTMLAnchorElement || key !== "href" && key !== "newWindow") {
  14020. html.setAttribute(key, value);
  14021. }
  14022. }
  14023. }
  14024. if (isHTMLAnchorElement) {
  14025. linkService.addLinkAttributes(html, attributes.href, attributes.newWindow);
  14026. }
  14027. if (storage && attributes.dataId) {
  14028. this.setupStorage(html, attributes.dataId, element, storage);
  14029. }
  14030. }
  14031. static render(parameters) {
  14032. const storage = parameters.annotationStorage;
  14033. const linkService = parameters.linkService;
  14034. const root = parameters.xfaHtml;
  14035. const intent = parameters.intent || "display";
  14036. const rootHtml = document.createElement(root.name);
  14037. if (root.attributes) {
  14038. this.setAttributes({
  14039. html: rootHtml,
  14040. element: root,
  14041. intent,
  14042. linkService
  14043. });
  14044. }
  14045. const stack = [[root, -1, rootHtml]];
  14046. const rootDiv = parameters.div;
  14047. rootDiv.append(rootHtml);
  14048. if (parameters.viewport) {
  14049. const transform = `matrix(${parameters.viewport.transform.join(",")})`;
  14050. rootDiv.style.transform = transform;
  14051. }
  14052. if (intent !== "richText") {
  14053. rootDiv.setAttribute("class", "xfaLayer xfaFont");
  14054. }
  14055. const textDivs = [];
  14056. while (stack.length > 0) {
  14057. const [parent, i, html] = stack.at(-1);
  14058. if (i + 1 === parent.children.length) {
  14059. stack.pop();
  14060. continue;
  14061. }
  14062. const child = parent.children[++stack.at(-1)[1]];
  14063. if (child === null) {
  14064. continue;
  14065. }
  14066. const {
  14067. name
  14068. } = child;
  14069. if (name === "#text") {
  14070. const node = document.createTextNode(child.value);
  14071. textDivs.push(node);
  14072. html.append(node);
  14073. continue;
  14074. }
  14075. let childHtml;
  14076. if (child?.attributes?.xmlns) {
  14077. childHtml = document.createElementNS(child.attributes.xmlns, name);
  14078. } else {
  14079. childHtml = document.createElement(name);
  14080. }
  14081. html.append(childHtml);
  14082. if (child.attributes) {
  14083. this.setAttributes({
  14084. html: childHtml,
  14085. element: child,
  14086. storage,
  14087. intent,
  14088. linkService
  14089. });
  14090. }
  14091. if (child.children && child.children.length > 0) {
  14092. stack.push([child, -1, childHtml]);
  14093. } else if (child.value) {
  14094. const node = document.createTextNode(child.value);
  14095. if (_xfa_text.XfaText.shouldBuildText(name)) {
  14096. textDivs.push(node);
  14097. }
  14098. childHtml.append(node);
  14099. }
  14100. }
  14101. for (const el of rootDiv.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea")) {
  14102. el.setAttribute("readOnly", true);
  14103. }
  14104. return {
  14105. textDivs
  14106. };
  14107. }
  14108. static update(parameters) {
  14109. const transform = `matrix(${parameters.viewport.transform.join(",")})`;
  14110. parameters.div.style.transform = transform;
  14111. parameters.div.hidden = false;
  14112. }
  14113. }
  14114. exports.XfaLayer = XfaLayer;
  14115. /***/ }),
  14116. /* 35 */
  14117. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  14118. Object.defineProperty(exports, "__esModule", ({
  14119. value: true
  14120. }));
  14121. exports.SVGGraphics = void 0;
  14122. var _display_utils = __w_pdfjs_require__(6);
  14123. var _util = __w_pdfjs_require__(1);
  14124. var _is_node = __w_pdfjs_require__(10);
  14125. let SVGGraphics = class {
  14126. constructor() {
  14127. (0, _util.unreachable)("Not implemented: SVGGraphics");
  14128. }
  14129. };
  14130. exports.SVGGraphics = SVGGraphics;
  14131. {
  14132. const SVG_DEFAULTS = {
  14133. fontStyle: "normal",
  14134. fontWeight: "normal",
  14135. fillColor: "#000000"
  14136. };
  14137. const XML_NS = "http://www.w3.org/XML/1998/namespace";
  14138. const XLINK_NS = "http://www.w3.org/1999/xlink";
  14139. const LINE_CAP_STYLES = ["butt", "round", "square"];
  14140. const LINE_JOIN_STYLES = ["miter", "round", "bevel"];
  14141. const createObjectURL = function (data, contentType = "", forceDataSchema = false) {
  14142. if (URL.createObjectURL && typeof Blob !== "undefined" && !forceDataSchema) {
  14143. return URL.createObjectURL(new Blob([data], {
  14144. type: contentType
  14145. }));
  14146. }
  14147. const digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  14148. let buffer = `data:${contentType};base64,`;
  14149. for (let i = 0, ii = data.length; i < ii; i += 3) {
  14150. const b1 = data[i] & 0xff;
  14151. const b2 = data[i + 1] & 0xff;
  14152. const b3 = data[i + 2] & 0xff;
  14153. const d1 = b1 >> 2,
  14154. d2 = (b1 & 3) << 4 | b2 >> 4;
  14155. const d3 = i + 1 < ii ? (b2 & 0xf) << 2 | b3 >> 6 : 64;
  14156. const d4 = i + 2 < ii ? b3 & 0x3f : 64;
  14157. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  14158. }
  14159. return buffer;
  14160. };
  14161. const convertImgDataToPng = function () {
  14162. const PNG_HEADER = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  14163. const CHUNK_WRAPPER_SIZE = 12;
  14164. const crcTable = new Int32Array(256);
  14165. for (let i = 0; i < 256; i++) {
  14166. let c = i;
  14167. for (let h = 0; h < 8; h++) {
  14168. if (c & 1) {
  14169. c = 0xedb88320 ^ c >> 1 & 0x7fffffff;
  14170. } else {
  14171. c = c >> 1 & 0x7fffffff;
  14172. }
  14173. }
  14174. crcTable[i] = c;
  14175. }
  14176. function crc32(data, start, end) {
  14177. let crc = -1;
  14178. for (let i = start; i < end; i++) {
  14179. const a = (crc ^ data[i]) & 0xff;
  14180. const b = crcTable[a];
  14181. crc = crc >>> 8 ^ b;
  14182. }
  14183. return crc ^ -1;
  14184. }
  14185. function writePngChunk(type, body, data, offset) {
  14186. let p = offset;
  14187. const len = body.length;
  14188. data[p] = len >> 24 & 0xff;
  14189. data[p + 1] = len >> 16 & 0xff;
  14190. data[p + 2] = len >> 8 & 0xff;
  14191. data[p + 3] = len & 0xff;
  14192. p += 4;
  14193. data[p] = type.charCodeAt(0) & 0xff;
  14194. data[p + 1] = type.charCodeAt(1) & 0xff;
  14195. data[p + 2] = type.charCodeAt(2) & 0xff;
  14196. data[p + 3] = type.charCodeAt(3) & 0xff;
  14197. p += 4;
  14198. data.set(body, p);
  14199. p += body.length;
  14200. const crc = crc32(data, offset + 4, p);
  14201. data[p] = crc >> 24 & 0xff;
  14202. data[p + 1] = crc >> 16 & 0xff;
  14203. data[p + 2] = crc >> 8 & 0xff;
  14204. data[p + 3] = crc & 0xff;
  14205. }
  14206. function adler32(data, start, end) {
  14207. let a = 1;
  14208. let b = 0;
  14209. for (let i = start; i < end; ++i) {
  14210. a = (a + (data[i] & 0xff)) % 65521;
  14211. b = (b + a) % 65521;
  14212. }
  14213. return b << 16 | a;
  14214. }
  14215. function deflateSync(literals) {
  14216. if (!_is_node.isNodeJS) {
  14217. return deflateSyncUncompressed(literals);
  14218. }
  14219. try {
  14220. let input;
  14221. if (parseInt(process.versions.node) >= 8) {
  14222. input = literals;
  14223. } else {
  14224. input = Buffer.from(literals);
  14225. }
  14226. const output = require("zlib").deflateSync(input, {
  14227. level: 9
  14228. });
  14229. return output instanceof Uint8Array ? output : new Uint8Array(output);
  14230. } catch (e) {
  14231. (0, _util.warn)("Not compressing PNG because zlib.deflateSync is unavailable: " + e);
  14232. }
  14233. return deflateSyncUncompressed(literals);
  14234. }
  14235. function deflateSyncUncompressed(literals) {
  14236. let len = literals.length;
  14237. const maxBlockLength = 0xffff;
  14238. const deflateBlocks = Math.ceil(len / maxBlockLength);
  14239. const idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  14240. let pi = 0;
  14241. idat[pi++] = 0x78;
  14242. idat[pi++] = 0x9c;
  14243. let pos = 0;
  14244. while (len > maxBlockLength) {
  14245. idat[pi++] = 0x00;
  14246. idat[pi++] = 0xff;
  14247. idat[pi++] = 0xff;
  14248. idat[pi++] = 0x00;
  14249. idat[pi++] = 0x00;
  14250. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  14251. pi += maxBlockLength;
  14252. pos += maxBlockLength;
  14253. len -= maxBlockLength;
  14254. }
  14255. idat[pi++] = 0x01;
  14256. idat[pi++] = len & 0xff;
  14257. idat[pi++] = len >> 8 & 0xff;
  14258. idat[pi++] = ~len & 0xffff & 0xff;
  14259. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  14260. idat.set(literals.subarray(pos), pi);
  14261. pi += literals.length - pos;
  14262. const adler = adler32(literals, 0, literals.length);
  14263. idat[pi++] = adler >> 24 & 0xff;
  14264. idat[pi++] = adler >> 16 & 0xff;
  14265. idat[pi++] = adler >> 8 & 0xff;
  14266. idat[pi++] = adler & 0xff;
  14267. return idat;
  14268. }
  14269. function encode(imgData, kind, forceDataSchema, isMask) {
  14270. const width = imgData.width;
  14271. const height = imgData.height;
  14272. let bitDepth, colorType, lineSize;
  14273. const bytes = imgData.data;
  14274. switch (kind) {
  14275. case _util.ImageKind.GRAYSCALE_1BPP:
  14276. colorType = 0;
  14277. bitDepth = 1;
  14278. lineSize = width + 7 >> 3;
  14279. break;
  14280. case _util.ImageKind.RGB_24BPP:
  14281. colorType = 2;
  14282. bitDepth = 8;
  14283. lineSize = width * 3;
  14284. break;
  14285. case _util.ImageKind.RGBA_32BPP:
  14286. colorType = 6;
  14287. bitDepth = 8;
  14288. lineSize = width * 4;
  14289. break;
  14290. default:
  14291. throw new Error("invalid format");
  14292. }
  14293. const literals = new Uint8Array((1 + lineSize) * height);
  14294. let offsetLiterals = 0,
  14295. offsetBytes = 0;
  14296. for (let y = 0; y < height; ++y) {
  14297. literals[offsetLiterals++] = 0;
  14298. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize), offsetLiterals);
  14299. offsetBytes += lineSize;
  14300. offsetLiterals += lineSize;
  14301. }
  14302. if (kind === _util.ImageKind.GRAYSCALE_1BPP && isMask) {
  14303. offsetLiterals = 0;
  14304. for (let y = 0; y < height; y++) {
  14305. offsetLiterals++;
  14306. for (let i = 0; i < lineSize; i++) {
  14307. literals[offsetLiterals++] ^= 0xff;
  14308. }
  14309. }
  14310. }
  14311. 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]);
  14312. const idat = deflateSync(literals);
  14313. const pngLength = PNG_HEADER.length + CHUNK_WRAPPER_SIZE * 3 + ihdr.length + idat.length;
  14314. const data = new Uint8Array(pngLength);
  14315. let offset = 0;
  14316. data.set(PNG_HEADER, offset);
  14317. offset += PNG_HEADER.length;
  14318. writePngChunk("IHDR", ihdr, data, offset);
  14319. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  14320. writePngChunk("IDATA", idat, data, offset);
  14321. offset += CHUNK_WRAPPER_SIZE + idat.length;
  14322. writePngChunk("IEND", new Uint8Array(0), data, offset);
  14323. return createObjectURL(data, "image/png", forceDataSchema);
  14324. }
  14325. return function convertImgDataToPng(imgData, forceDataSchema, isMask) {
  14326. const kind = imgData.kind === undefined ? _util.ImageKind.GRAYSCALE_1BPP : imgData.kind;
  14327. return encode(imgData, kind, forceDataSchema, isMask);
  14328. };
  14329. }();
  14330. class SVGExtraState {
  14331. constructor() {
  14332. this.fontSizeScale = 1;
  14333. this.fontWeight = SVG_DEFAULTS.fontWeight;
  14334. this.fontSize = 0;
  14335. this.textMatrix = _util.IDENTITY_MATRIX;
  14336. this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
  14337. this.leading = 0;
  14338. this.textRenderingMode = _util.TextRenderingMode.FILL;
  14339. this.textMatrixScale = 1;
  14340. this.x = 0;
  14341. this.y = 0;
  14342. this.lineX = 0;
  14343. this.lineY = 0;
  14344. this.charSpacing = 0;
  14345. this.wordSpacing = 0;
  14346. this.textHScale = 1;
  14347. this.textRise = 0;
  14348. this.fillColor = SVG_DEFAULTS.fillColor;
  14349. this.strokeColor = "#000000";
  14350. this.fillAlpha = 1;
  14351. this.strokeAlpha = 1;
  14352. this.lineWidth = 1;
  14353. this.lineJoin = "";
  14354. this.lineCap = "";
  14355. this.miterLimit = 0;
  14356. this.dashArray = [];
  14357. this.dashPhase = 0;
  14358. this.dependencies = [];
  14359. this.activeClipUrl = null;
  14360. this.clipGroup = null;
  14361. this.maskId = "";
  14362. }
  14363. clone() {
  14364. return Object.create(this);
  14365. }
  14366. setCurrentPoint(x, y) {
  14367. this.x = x;
  14368. this.y = y;
  14369. }
  14370. }
  14371. function opListToTree(opList) {
  14372. let opTree = [];
  14373. const tmp = [];
  14374. for (const opListElement of opList) {
  14375. if (opListElement.fn === "save") {
  14376. opTree.push({
  14377. fnId: 92,
  14378. fn: "group",
  14379. items: []
  14380. });
  14381. tmp.push(opTree);
  14382. opTree = opTree.at(-1).items;
  14383. continue;
  14384. }
  14385. if (opListElement.fn === "restore") {
  14386. opTree = tmp.pop();
  14387. } else {
  14388. opTree.push(opListElement);
  14389. }
  14390. }
  14391. return opTree;
  14392. }
  14393. function pf(value) {
  14394. if (Number.isInteger(value)) {
  14395. return value.toString();
  14396. }
  14397. const s = value.toFixed(10);
  14398. let i = s.length - 1;
  14399. if (s[i] !== "0") {
  14400. return s;
  14401. }
  14402. do {
  14403. i--;
  14404. } while (s[i] === "0");
  14405. return s.substring(0, s[i] === "." ? i : i + 1);
  14406. }
  14407. function pm(m) {
  14408. if (m[4] === 0 && m[5] === 0) {
  14409. if (m[1] === 0 && m[2] === 0) {
  14410. if (m[0] === 1 && m[3] === 1) {
  14411. return "";
  14412. }
  14413. return `scale(${pf(m[0])} ${pf(m[3])})`;
  14414. }
  14415. if (m[0] === m[3] && m[1] === -m[2]) {
  14416. const a = Math.acos(m[0]) * 180 / Math.PI;
  14417. return `rotate(${pf(a)})`;
  14418. }
  14419. } else {
  14420. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  14421. return `translate(${pf(m[4])} ${pf(m[5])})`;
  14422. }
  14423. }
  14424. return `matrix(${pf(m[0])} ${pf(m[1])} ${pf(m[2])} ${pf(m[3])} ${pf(m[4])} ` + `${pf(m[5])})`;
  14425. }
  14426. let clipCount = 0;
  14427. let maskCount = 0;
  14428. let shadingCount = 0;
  14429. exports.SVGGraphics = SVGGraphics = class {
  14430. constructor(commonObjs, objs, forceDataSchema = false) {
  14431. (0, _display_utils.deprecated)("The SVG back-end is no longer maintained and *may* be removed in the future.");
  14432. this.svgFactory = new _display_utils.DOMSVGFactory();
  14433. this.current = new SVGExtraState();
  14434. this.transformMatrix = _util.IDENTITY_MATRIX;
  14435. this.transformStack = [];
  14436. this.extraStack = [];
  14437. this.commonObjs = commonObjs;
  14438. this.objs = objs;
  14439. this.pendingClip = null;
  14440. this.pendingEOFill = false;
  14441. this.embedFonts = false;
  14442. this.embeddedFonts = Object.create(null);
  14443. this.cssStyle = null;
  14444. this.forceDataSchema = !!forceDataSchema;
  14445. this._operatorIdMapping = [];
  14446. for (const op in _util.OPS) {
  14447. this._operatorIdMapping[_util.OPS[op]] = op;
  14448. }
  14449. }
  14450. getObject(data, fallback = null) {
  14451. if (typeof data === "string") {
  14452. return data.startsWith("g_") ? this.commonObjs.get(data) : this.objs.get(data);
  14453. }
  14454. return fallback;
  14455. }
  14456. save() {
  14457. this.transformStack.push(this.transformMatrix);
  14458. const old = this.current;
  14459. this.extraStack.push(old);
  14460. this.current = old.clone();
  14461. }
  14462. restore() {
  14463. this.transformMatrix = this.transformStack.pop();
  14464. this.current = this.extraStack.pop();
  14465. this.pendingClip = null;
  14466. this.tgrp = null;
  14467. }
  14468. group(items) {
  14469. this.save();
  14470. this.executeOpTree(items);
  14471. this.restore();
  14472. }
  14473. loadDependencies(operatorList) {
  14474. const fnArray = operatorList.fnArray;
  14475. const argsArray = operatorList.argsArray;
  14476. for (let i = 0, ii = fnArray.length; i < ii; i++) {
  14477. if (fnArray[i] !== _util.OPS.dependency) {
  14478. continue;
  14479. }
  14480. for (const obj of argsArray[i]) {
  14481. const objsPool = obj.startsWith("g_") ? this.commonObjs : this.objs;
  14482. const promise = new Promise(resolve => {
  14483. objsPool.get(obj, resolve);
  14484. });
  14485. this.current.dependencies.push(promise);
  14486. }
  14487. }
  14488. return Promise.all(this.current.dependencies);
  14489. }
  14490. transform(a, b, c, d, e, f) {
  14491. const transformMatrix = [a, b, c, d, e, f];
  14492. this.transformMatrix = _util.Util.transform(this.transformMatrix, transformMatrix);
  14493. this.tgrp = null;
  14494. }
  14495. getSVG(operatorList, viewport) {
  14496. this.viewport = viewport;
  14497. const svgElement = this._initialize(viewport);
  14498. return this.loadDependencies(operatorList).then(() => {
  14499. this.transformMatrix = _util.IDENTITY_MATRIX;
  14500. this.executeOpTree(this.convertOpList(operatorList));
  14501. return svgElement;
  14502. });
  14503. }
  14504. convertOpList(operatorList) {
  14505. const operatorIdMapping = this._operatorIdMapping;
  14506. const argsArray = operatorList.argsArray;
  14507. const fnArray = operatorList.fnArray;
  14508. const opList = [];
  14509. for (let i = 0, ii = fnArray.length; i < ii; i++) {
  14510. const fnId = fnArray[i];
  14511. opList.push({
  14512. fnId,
  14513. fn: operatorIdMapping[fnId],
  14514. args: argsArray[i]
  14515. });
  14516. }
  14517. return opListToTree(opList);
  14518. }
  14519. executeOpTree(opTree) {
  14520. for (const opTreeElement of opTree) {
  14521. const fn = opTreeElement.fn;
  14522. const fnId = opTreeElement.fnId;
  14523. const args = opTreeElement.args;
  14524. switch (fnId | 0) {
  14525. case _util.OPS.beginText:
  14526. this.beginText();
  14527. break;
  14528. case _util.OPS.dependency:
  14529. break;
  14530. case _util.OPS.setLeading:
  14531. this.setLeading(args);
  14532. break;
  14533. case _util.OPS.setLeadingMoveText:
  14534. this.setLeadingMoveText(args[0], args[1]);
  14535. break;
  14536. case _util.OPS.setFont:
  14537. this.setFont(args);
  14538. break;
  14539. case _util.OPS.showText:
  14540. this.showText(args[0]);
  14541. break;
  14542. case _util.OPS.showSpacedText:
  14543. this.showText(args[0]);
  14544. break;
  14545. case _util.OPS.endText:
  14546. this.endText();
  14547. break;
  14548. case _util.OPS.moveText:
  14549. this.moveText(args[0], args[1]);
  14550. break;
  14551. case _util.OPS.setCharSpacing:
  14552. this.setCharSpacing(args[0]);
  14553. break;
  14554. case _util.OPS.setWordSpacing:
  14555. this.setWordSpacing(args[0]);
  14556. break;
  14557. case _util.OPS.setHScale:
  14558. this.setHScale(args[0]);
  14559. break;
  14560. case _util.OPS.setTextMatrix:
  14561. this.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
  14562. break;
  14563. case _util.OPS.setTextRise:
  14564. this.setTextRise(args[0]);
  14565. break;
  14566. case _util.OPS.setTextRenderingMode:
  14567. this.setTextRenderingMode(args[0]);
  14568. break;
  14569. case _util.OPS.setLineWidth:
  14570. this.setLineWidth(args[0]);
  14571. break;
  14572. case _util.OPS.setLineJoin:
  14573. this.setLineJoin(args[0]);
  14574. break;
  14575. case _util.OPS.setLineCap:
  14576. this.setLineCap(args[0]);
  14577. break;
  14578. case _util.OPS.setMiterLimit:
  14579. this.setMiterLimit(args[0]);
  14580. break;
  14581. case _util.OPS.setFillRGBColor:
  14582. this.setFillRGBColor(args[0], args[1], args[2]);
  14583. break;
  14584. case _util.OPS.setStrokeRGBColor:
  14585. this.setStrokeRGBColor(args[0], args[1], args[2]);
  14586. break;
  14587. case _util.OPS.setStrokeColorN:
  14588. this.setStrokeColorN(args);
  14589. break;
  14590. case _util.OPS.setFillColorN:
  14591. this.setFillColorN(args);
  14592. break;
  14593. case _util.OPS.shadingFill:
  14594. this.shadingFill(args[0]);
  14595. break;
  14596. case _util.OPS.setDash:
  14597. this.setDash(args[0], args[1]);
  14598. break;
  14599. case _util.OPS.setRenderingIntent:
  14600. this.setRenderingIntent(args[0]);
  14601. break;
  14602. case _util.OPS.setFlatness:
  14603. this.setFlatness(args[0]);
  14604. break;
  14605. case _util.OPS.setGState:
  14606. this.setGState(args[0]);
  14607. break;
  14608. case _util.OPS.fill:
  14609. this.fill();
  14610. break;
  14611. case _util.OPS.eoFill:
  14612. this.eoFill();
  14613. break;
  14614. case _util.OPS.stroke:
  14615. this.stroke();
  14616. break;
  14617. case _util.OPS.fillStroke:
  14618. this.fillStroke();
  14619. break;
  14620. case _util.OPS.eoFillStroke:
  14621. this.eoFillStroke();
  14622. break;
  14623. case _util.OPS.clip:
  14624. this.clip("nonzero");
  14625. break;
  14626. case _util.OPS.eoClip:
  14627. this.clip("evenodd");
  14628. break;
  14629. case _util.OPS.paintSolidColorImageMask:
  14630. this.paintSolidColorImageMask();
  14631. break;
  14632. case _util.OPS.paintImageXObject:
  14633. this.paintImageXObject(args[0]);
  14634. break;
  14635. case _util.OPS.paintInlineImageXObject:
  14636. this.paintInlineImageXObject(args[0]);
  14637. break;
  14638. case _util.OPS.paintImageMaskXObject:
  14639. this.paintImageMaskXObject(args[0]);
  14640. break;
  14641. case _util.OPS.paintFormXObjectBegin:
  14642. this.paintFormXObjectBegin(args[0], args[1]);
  14643. break;
  14644. case _util.OPS.paintFormXObjectEnd:
  14645. this.paintFormXObjectEnd();
  14646. break;
  14647. case _util.OPS.closePath:
  14648. this.closePath();
  14649. break;
  14650. case _util.OPS.closeStroke:
  14651. this.closeStroke();
  14652. break;
  14653. case _util.OPS.closeFillStroke:
  14654. this.closeFillStroke();
  14655. break;
  14656. case _util.OPS.closeEOFillStroke:
  14657. this.closeEOFillStroke();
  14658. break;
  14659. case _util.OPS.nextLine:
  14660. this.nextLine();
  14661. break;
  14662. case _util.OPS.transform:
  14663. this.transform(args[0], args[1], args[2], args[3], args[4], args[5]);
  14664. break;
  14665. case _util.OPS.constructPath:
  14666. this.constructPath(args[0], args[1]);
  14667. break;
  14668. case _util.OPS.endPath:
  14669. this.endPath();
  14670. break;
  14671. case 92:
  14672. this.group(opTreeElement.items);
  14673. break;
  14674. default:
  14675. (0, _util.warn)(`Unimplemented operator ${fn}`);
  14676. break;
  14677. }
  14678. }
  14679. }
  14680. setWordSpacing(wordSpacing) {
  14681. this.current.wordSpacing = wordSpacing;
  14682. }
  14683. setCharSpacing(charSpacing) {
  14684. this.current.charSpacing = charSpacing;
  14685. }
  14686. nextLine() {
  14687. this.moveText(0, this.current.leading);
  14688. }
  14689. setTextMatrix(a, b, c, d, e, f) {
  14690. const current = this.current;
  14691. current.textMatrix = current.lineMatrix = [a, b, c, d, e, f];
  14692. current.textMatrixScale = Math.hypot(a, b);
  14693. current.x = current.lineX = 0;
  14694. current.y = current.lineY = 0;
  14695. current.xcoords = [];
  14696. current.ycoords = [];
  14697. current.tspan = this.svgFactory.createElement("svg:tspan");
  14698. current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
  14699. current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
  14700. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  14701. current.txtElement = this.svgFactory.createElement("svg:text");
  14702. current.txtElement.append(current.tspan);
  14703. }
  14704. beginText() {
  14705. const current = this.current;
  14706. current.x = current.lineX = 0;
  14707. current.y = current.lineY = 0;
  14708. current.textMatrix = _util.IDENTITY_MATRIX;
  14709. current.lineMatrix = _util.IDENTITY_MATRIX;
  14710. current.textMatrixScale = 1;
  14711. current.tspan = this.svgFactory.createElement("svg:tspan");
  14712. current.txtElement = this.svgFactory.createElement("svg:text");
  14713. current.txtgrp = this.svgFactory.createElement("svg:g");
  14714. current.xcoords = [];
  14715. current.ycoords = [];
  14716. }
  14717. moveText(x, y) {
  14718. const current = this.current;
  14719. current.x = current.lineX += x;
  14720. current.y = current.lineY += y;
  14721. current.xcoords = [];
  14722. current.ycoords = [];
  14723. current.tspan = this.svgFactory.createElement("svg:tspan");
  14724. current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
  14725. current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
  14726. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  14727. }
  14728. showText(glyphs) {
  14729. const current = this.current;
  14730. const font = current.font;
  14731. const fontSize = current.fontSize;
  14732. if (fontSize === 0) {
  14733. return;
  14734. }
  14735. const fontSizeScale = current.fontSizeScale;
  14736. const charSpacing = current.charSpacing;
  14737. const wordSpacing = current.wordSpacing;
  14738. const fontDirection = current.fontDirection;
  14739. const textHScale = current.textHScale * fontDirection;
  14740. const vertical = font.vertical;
  14741. const spacingDir = vertical ? 1 : -1;
  14742. const defaultVMetrics = font.defaultVMetrics;
  14743. const widthAdvanceScale = fontSize * current.fontMatrix[0];
  14744. let x = 0;
  14745. for (const glyph of glyphs) {
  14746. if (glyph === null) {
  14747. x += fontDirection * wordSpacing;
  14748. continue;
  14749. } else if (typeof glyph === "number") {
  14750. x += spacingDir * glyph * fontSize / 1000;
  14751. continue;
  14752. }
  14753. const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  14754. const character = glyph.fontChar;
  14755. let scaledX, scaledY;
  14756. let width = glyph.width;
  14757. if (vertical) {
  14758. let vx;
  14759. const vmetric = glyph.vmetric || defaultVMetrics;
  14760. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  14761. vx = -vx * widthAdvanceScale;
  14762. const vy = vmetric[2] * widthAdvanceScale;
  14763. width = vmetric ? -vmetric[0] : width;
  14764. scaledX = vx / fontSizeScale;
  14765. scaledY = (x + vy) / fontSizeScale;
  14766. } else {
  14767. scaledX = x / fontSizeScale;
  14768. scaledY = 0;
  14769. }
  14770. if (glyph.isInFont || font.missingFile) {
  14771. current.xcoords.push(current.x + scaledX);
  14772. if (vertical) {
  14773. current.ycoords.push(-current.y + scaledY);
  14774. }
  14775. current.tspan.textContent += character;
  14776. } else {}
  14777. let charWidth;
  14778. if (vertical) {
  14779. charWidth = width * widthAdvanceScale - spacing * fontDirection;
  14780. } else {
  14781. charWidth = width * widthAdvanceScale + spacing * fontDirection;
  14782. }
  14783. x += charWidth;
  14784. }
  14785. current.tspan.setAttributeNS(null, "x", current.xcoords.map(pf).join(" "));
  14786. if (vertical) {
  14787. current.tspan.setAttributeNS(null, "y", current.ycoords.map(pf).join(" "));
  14788. } else {
  14789. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  14790. }
  14791. if (vertical) {
  14792. current.y -= x;
  14793. } else {
  14794. current.x += x * textHScale;
  14795. }
  14796. current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
  14797. current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
  14798. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  14799. current.tspan.setAttributeNS(null, "font-style", current.fontStyle);
  14800. }
  14801. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  14802. current.tspan.setAttributeNS(null, "font-weight", current.fontWeight);
  14803. }
  14804. const fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  14805. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  14806. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  14807. current.tspan.setAttributeNS(null, "fill", current.fillColor);
  14808. }
  14809. if (current.fillAlpha < 1) {
  14810. current.tspan.setAttributeNS(null, "fill-opacity", current.fillAlpha);
  14811. }
  14812. } else if (current.textRenderingMode === _util.TextRenderingMode.ADD_TO_PATH) {
  14813. current.tspan.setAttributeNS(null, "fill", "transparent");
  14814. } else {
  14815. current.tspan.setAttributeNS(null, "fill", "none");
  14816. }
  14817. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  14818. const lineWidthScale = 1 / (current.textMatrixScale || 1);
  14819. this._setStrokeAttributes(current.tspan, lineWidthScale);
  14820. }
  14821. let textMatrix = current.textMatrix;
  14822. if (current.textRise !== 0) {
  14823. textMatrix = textMatrix.slice();
  14824. textMatrix[5] += current.textRise;
  14825. }
  14826. current.txtElement.setAttributeNS(null, "transform", `${pm(textMatrix)} scale(${pf(textHScale)}, -1)`);
  14827. current.txtElement.setAttributeNS(XML_NS, "xml:space", "preserve");
  14828. current.txtElement.append(current.tspan);
  14829. current.txtgrp.append(current.txtElement);
  14830. this._ensureTransformGroup().append(current.txtElement);
  14831. }
  14832. setLeadingMoveText(x, y) {
  14833. this.setLeading(-y);
  14834. this.moveText(x, y);
  14835. }
  14836. addFontStyle(fontObj) {
  14837. if (!fontObj.data) {
  14838. throw new Error("addFontStyle: No font data available, " + 'ensure that the "fontExtraProperties" API parameter is set.');
  14839. }
  14840. if (!this.cssStyle) {
  14841. this.cssStyle = this.svgFactory.createElement("svg:style");
  14842. this.cssStyle.setAttributeNS(null, "type", "text/css");
  14843. this.defs.append(this.cssStyle);
  14844. }
  14845. const url = createObjectURL(fontObj.data, fontObj.mimetype, this.forceDataSchema);
  14846. this.cssStyle.textContent += `@font-face { font-family: "${fontObj.loadedName}";` + ` src: url(${url}); }\n`;
  14847. }
  14848. setFont(details) {
  14849. const current = this.current;
  14850. const fontObj = this.commonObjs.get(details[0]);
  14851. let size = details[1];
  14852. current.font = fontObj;
  14853. if (this.embedFonts && !fontObj.missingFile && !this.embeddedFonts[fontObj.loadedName]) {
  14854. this.addFontStyle(fontObj);
  14855. this.embeddedFonts[fontObj.loadedName] = fontObj;
  14856. }
  14857. current.fontMatrix = fontObj.fontMatrix || _util.FONT_IDENTITY_MATRIX;
  14858. let bold = "normal";
  14859. if (fontObj.black) {
  14860. bold = "900";
  14861. } else if (fontObj.bold) {
  14862. bold = "bold";
  14863. }
  14864. const italic = fontObj.italic ? "italic" : "normal";
  14865. if (size < 0) {
  14866. size = -size;
  14867. current.fontDirection = -1;
  14868. } else {
  14869. current.fontDirection = 1;
  14870. }
  14871. current.fontSize = size;
  14872. current.fontFamily = fontObj.loadedName;
  14873. current.fontWeight = bold;
  14874. current.fontStyle = italic;
  14875. current.tspan = this.svgFactory.createElement("svg:tspan");
  14876. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  14877. current.xcoords = [];
  14878. current.ycoords = [];
  14879. }
  14880. endText() {
  14881. const current = this.current;
  14882. if (current.textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG && current.txtElement?.hasChildNodes()) {
  14883. current.element = current.txtElement;
  14884. this.clip("nonzero");
  14885. this.endPath();
  14886. }
  14887. }
  14888. setLineWidth(width) {
  14889. if (width > 0) {
  14890. this.current.lineWidth = width;
  14891. }
  14892. }
  14893. setLineCap(style) {
  14894. this.current.lineCap = LINE_CAP_STYLES[style];
  14895. }
  14896. setLineJoin(style) {
  14897. this.current.lineJoin = LINE_JOIN_STYLES[style];
  14898. }
  14899. setMiterLimit(limit) {
  14900. this.current.miterLimit = limit;
  14901. }
  14902. setStrokeAlpha(strokeAlpha) {
  14903. this.current.strokeAlpha = strokeAlpha;
  14904. }
  14905. setStrokeRGBColor(r, g, b) {
  14906. this.current.strokeColor = _util.Util.makeHexColor(r, g, b);
  14907. }
  14908. setFillAlpha(fillAlpha) {
  14909. this.current.fillAlpha = fillAlpha;
  14910. }
  14911. setFillRGBColor(r, g, b) {
  14912. this.current.fillColor = _util.Util.makeHexColor(r, g, b);
  14913. this.current.tspan = this.svgFactory.createElement("svg:tspan");
  14914. this.current.xcoords = [];
  14915. this.current.ycoords = [];
  14916. }
  14917. setStrokeColorN(args) {
  14918. this.current.strokeColor = this._makeColorN_Pattern(args);
  14919. }
  14920. setFillColorN(args) {
  14921. this.current.fillColor = this._makeColorN_Pattern(args);
  14922. }
  14923. shadingFill(args) {
  14924. const width = this.viewport.width;
  14925. const height = this.viewport.height;
  14926. const inv = _util.Util.inverseTransform(this.transformMatrix);
  14927. const bl = _util.Util.applyTransform([0, 0], inv);
  14928. const br = _util.Util.applyTransform([0, height], inv);
  14929. const ul = _util.Util.applyTransform([width, 0], inv);
  14930. const ur = _util.Util.applyTransform([width, height], inv);
  14931. const x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  14932. const y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  14933. const x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  14934. const y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  14935. const rect = this.svgFactory.createElement("svg:rect");
  14936. rect.setAttributeNS(null, "x", x0);
  14937. rect.setAttributeNS(null, "y", y0);
  14938. rect.setAttributeNS(null, "width", x1 - x0);
  14939. rect.setAttributeNS(null, "height", y1 - y0);
  14940. rect.setAttributeNS(null, "fill", this._makeShadingPattern(args));
  14941. if (this.current.fillAlpha < 1) {
  14942. rect.setAttributeNS(null, "fill-opacity", this.current.fillAlpha);
  14943. }
  14944. this._ensureTransformGroup().append(rect);
  14945. }
  14946. _makeColorN_Pattern(args) {
  14947. if (args[0] === "TilingPattern") {
  14948. return this._makeTilingPattern(args);
  14949. }
  14950. return this._makeShadingPattern(args);
  14951. }
  14952. _makeTilingPattern(args) {
  14953. const color = args[1];
  14954. const operatorList = args[2];
  14955. const matrix = args[3] || _util.IDENTITY_MATRIX;
  14956. const [x0, y0, x1, y1] = args[4];
  14957. const xstep = args[5];
  14958. const ystep = args[6];
  14959. const paintType = args[7];
  14960. const tilingId = `shading${shadingCount++}`;
  14961. const [tx0, ty0, tx1, ty1] = _util.Util.normalizeRect([..._util.Util.applyTransform([x0, y0], matrix), ..._util.Util.applyTransform([x1, y1], matrix)]);
  14962. const [xscale, yscale] = _util.Util.singularValueDecompose2dScale(matrix);
  14963. const txstep = xstep * xscale;
  14964. const tystep = ystep * yscale;
  14965. const tiling = this.svgFactory.createElement("svg:pattern");
  14966. tiling.setAttributeNS(null, "id", tilingId);
  14967. tiling.setAttributeNS(null, "patternUnits", "userSpaceOnUse");
  14968. tiling.setAttributeNS(null, "width", txstep);
  14969. tiling.setAttributeNS(null, "height", tystep);
  14970. tiling.setAttributeNS(null, "x", `${tx0}`);
  14971. tiling.setAttributeNS(null, "y", `${ty0}`);
  14972. const svg = this.svg;
  14973. const transformMatrix = this.transformMatrix;
  14974. const fillColor = this.current.fillColor;
  14975. const strokeColor = this.current.strokeColor;
  14976. const bbox = this.svgFactory.create(tx1 - tx0, ty1 - ty0);
  14977. this.svg = bbox;
  14978. this.transformMatrix = matrix;
  14979. if (paintType === 2) {
  14980. const cssColor = _util.Util.makeHexColor(...color);
  14981. this.current.fillColor = cssColor;
  14982. this.current.strokeColor = cssColor;
  14983. }
  14984. this.executeOpTree(this.convertOpList(operatorList));
  14985. this.svg = svg;
  14986. this.transformMatrix = transformMatrix;
  14987. this.current.fillColor = fillColor;
  14988. this.current.strokeColor = strokeColor;
  14989. tiling.append(bbox.childNodes[0]);
  14990. this.defs.append(tiling);
  14991. return `url(#${tilingId})`;
  14992. }
  14993. _makeShadingPattern(args) {
  14994. if (typeof args === "string") {
  14995. args = this.objs.get(args);
  14996. }
  14997. switch (args[0]) {
  14998. case "RadialAxial":
  14999. const shadingId = `shading${shadingCount++}`;
  15000. const colorStops = args[3];
  15001. let gradient;
  15002. switch (args[1]) {
  15003. case "axial":
  15004. const point0 = args[4];
  15005. const point1 = args[5];
  15006. gradient = this.svgFactory.createElement("svg:linearGradient");
  15007. gradient.setAttributeNS(null, "id", shadingId);
  15008. gradient.setAttributeNS(null, "gradientUnits", "userSpaceOnUse");
  15009. gradient.setAttributeNS(null, "x1", point0[0]);
  15010. gradient.setAttributeNS(null, "y1", point0[1]);
  15011. gradient.setAttributeNS(null, "x2", point1[0]);
  15012. gradient.setAttributeNS(null, "y2", point1[1]);
  15013. break;
  15014. case "radial":
  15015. const focalPoint = args[4];
  15016. const circlePoint = args[5];
  15017. const focalRadius = args[6];
  15018. const circleRadius = args[7];
  15019. gradient = this.svgFactory.createElement("svg:radialGradient");
  15020. gradient.setAttributeNS(null, "id", shadingId);
  15021. gradient.setAttributeNS(null, "gradientUnits", "userSpaceOnUse");
  15022. gradient.setAttributeNS(null, "cx", circlePoint[0]);
  15023. gradient.setAttributeNS(null, "cy", circlePoint[1]);
  15024. gradient.setAttributeNS(null, "r", circleRadius);
  15025. gradient.setAttributeNS(null, "fx", focalPoint[0]);
  15026. gradient.setAttributeNS(null, "fy", focalPoint[1]);
  15027. gradient.setAttributeNS(null, "fr", focalRadius);
  15028. break;
  15029. default:
  15030. throw new Error(`Unknown RadialAxial type: ${args[1]}`);
  15031. }
  15032. for (const colorStop of colorStops) {
  15033. const stop = this.svgFactory.createElement("svg:stop");
  15034. stop.setAttributeNS(null, "offset", colorStop[0]);
  15035. stop.setAttributeNS(null, "stop-color", colorStop[1]);
  15036. gradient.append(stop);
  15037. }
  15038. this.defs.append(gradient);
  15039. return `url(#${shadingId})`;
  15040. case "Mesh":
  15041. (0, _util.warn)("Unimplemented pattern Mesh");
  15042. return null;
  15043. case "Dummy":
  15044. return "hotpink";
  15045. default:
  15046. throw new Error(`Unknown IR type: ${args[0]}`);
  15047. }
  15048. }
  15049. setDash(dashArray, dashPhase) {
  15050. this.current.dashArray = dashArray;
  15051. this.current.dashPhase = dashPhase;
  15052. }
  15053. constructPath(ops, args) {
  15054. const current = this.current;
  15055. let x = current.x,
  15056. y = current.y;
  15057. let d = [];
  15058. let j = 0;
  15059. for (const op of ops) {
  15060. switch (op | 0) {
  15061. case _util.OPS.rectangle:
  15062. x = args[j++];
  15063. y = args[j++];
  15064. const width = args[j++];
  15065. const height = args[j++];
  15066. const xw = x + width;
  15067. const yh = y + height;
  15068. d.push("M", pf(x), pf(y), "L", pf(xw), pf(y), "L", pf(xw), pf(yh), "L", pf(x), pf(yh), "Z");
  15069. break;
  15070. case _util.OPS.moveTo:
  15071. x = args[j++];
  15072. y = args[j++];
  15073. d.push("M", pf(x), pf(y));
  15074. break;
  15075. case _util.OPS.lineTo:
  15076. x = args[j++];
  15077. y = args[j++];
  15078. d.push("L", pf(x), pf(y));
  15079. break;
  15080. case _util.OPS.curveTo:
  15081. x = args[j + 4];
  15082. y = args[j + 5];
  15083. d.push("C", pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]), pf(x), pf(y));
  15084. j += 6;
  15085. break;
  15086. case _util.OPS.curveTo2:
  15087. d.push("C", pf(x), pf(y), pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]));
  15088. x = args[j + 2];
  15089. y = args[j + 3];
  15090. j += 4;
  15091. break;
  15092. case _util.OPS.curveTo3:
  15093. x = args[j + 2];
  15094. y = args[j + 3];
  15095. d.push("C", pf(args[j]), pf(args[j + 1]), pf(x), pf(y), pf(x), pf(y));
  15096. j += 4;
  15097. break;
  15098. case _util.OPS.closePath:
  15099. d.push("Z");
  15100. break;
  15101. }
  15102. }
  15103. d = d.join(" ");
  15104. if (current.path && ops.length > 0 && ops[0] !== _util.OPS.rectangle && ops[0] !== _util.OPS.moveTo) {
  15105. d = current.path.getAttributeNS(null, "d") + d;
  15106. } else {
  15107. current.path = this.svgFactory.createElement("svg:path");
  15108. this._ensureTransformGroup().append(current.path);
  15109. }
  15110. current.path.setAttributeNS(null, "d", d);
  15111. current.path.setAttributeNS(null, "fill", "none");
  15112. current.element = current.path;
  15113. current.setCurrentPoint(x, y);
  15114. }
  15115. endPath() {
  15116. const current = this.current;
  15117. current.path = null;
  15118. if (!this.pendingClip) {
  15119. return;
  15120. }
  15121. if (!current.element) {
  15122. this.pendingClip = null;
  15123. return;
  15124. }
  15125. const clipId = `clippath${clipCount++}`;
  15126. const clipPath = this.svgFactory.createElement("svg:clipPath");
  15127. clipPath.setAttributeNS(null, "id", clipId);
  15128. clipPath.setAttributeNS(null, "transform", pm(this.transformMatrix));
  15129. const clipElement = current.element.cloneNode(true);
  15130. if (this.pendingClip === "evenodd") {
  15131. clipElement.setAttributeNS(null, "clip-rule", "evenodd");
  15132. } else {
  15133. clipElement.setAttributeNS(null, "clip-rule", "nonzero");
  15134. }
  15135. this.pendingClip = null;
  15136. clipPath.append(clipElement);
  15137. this.defs.append(clipPath);
  15138. if (current.activeClipUrl) {
  15139. current.clipGroup = null;
  15140. for (const prev of this.extraStack) {
  15141. prev.clipGroup = null;
  15142. }
  15143. clipPath.setAttributeNS(null, "clip-path", current.activeClipUrl);
  15144. }
  15145. current.activeClipUrl = `url(#${clipId})`;
  15146. this.tgrp = null;
  15147. }
  15148. clip(type) {
  15149. this.pendingClip = type;
  15150. }
  15151. closePath() {
  15152. const current = this.current;
  15153. if (current.path) {
  15154. const d = `${current.path.getAttributeNS(null, "d")}Z`;
  15155. current.path.setAttributeNS(null, "d", d);
  15156. }
  15157. }
  15158. setLeading(leading) {
  15159. this.current.leading = -leading;
  15160. }
  15161. setTextRise(textRise) {
  15162. this.current.textRise = textRise;
  15163. }
  15164. setTextRenderingMode(textRenderingMode) {
  15165. this.current.textRenderingMode = textRenderingMode;
  15166. }
  15167. setHScale(scale) {
  15168. this.current.textHScale = scale / 100;
  15169. }
  15170. setRenderingIntent(intent) {}
  15171. setFlatness(flatness) {}
  15172. setGState(states) {
  15173. for (const [key, value] of states) {
  15174. switch (key) {
  15175. case "LW":
  15176. this.setLineWidth(value);
  15177. break;
  15178. case "LC":
  15179. this.setLineCap(value);
  15180. break;
  15181. case "LJ":
  15182. this.setLineJoin(value);
  15183. break;
  15184. case "ML":
  15185. this.setMiterLimit(value);
  15186. break;
  15187. case "D":
  15188. this.setDash(value[0], value[1]);
  15189. break;
  15190. case "RI":
  15191. this.setRenderingIntent(value);
  15192. break;
  15193. case "FL":
  15194. this.setFlatness(value);
  15195. break;
  15196. case "Font":
  15197. this.setFont(value);
  15198. break;
  15199. case "CA":
  15200. this.setStrokeAlpha(value);
  15201. break;
  15202. case "ca":
  15203. this.setFillAlpha(value);
  15204. break;
  15205. default:
  15206. (0, _util.warn)(`Unimplemented graphic state operator ${key}`);
  15207. break;
  15208. }
  15209. }
  15210. }
  15211. fill() {
  15212. const current = this.current;
  15213. if (current.element) {
  15214. current.element.setAttributeNS(null, "fill", current.fillColor);
  15215. current.element.setAttributeNS(null, "fill-opacity", current.fillAlpha);
  15216. this.endPath();
  15217. }
  15218. }
  15219. stroke() {
  15220. const current = this.current;
  15221. if (current.element) {
  15222. this._setStrokeAttributes(current.element);
  15223. current.element.setAttributeNS(null, "fill", "none");
  15224. this.endPath();
  15225. }
  15226. }
  15227. _setStrokeAttributes(element, lineWidthScale = 1) {
  15228. const current = this.current;
  15229. let dashArray = current.dashArray;
  15230. if (lineWidthScale !== 1 && dashArray.length > 0) {
  15231. dashArray = dashArray.map(function (value) {
  15232. return lineWidthScale * value;
  15233. });
  15234. }
  15235. element.setAttributeNS(null, "stroke", current.strokeColor);
  15236. element.setAttributeNS(null, "stroke-opacity", current.strokeAlpha);
  15237. element.setAttributeNS(null, "stroke-miterlimit", pf(current.miterLimit));
  15238. element.setAttributeNS(null, "stroke-linecap", current.lineCap);
  15239. element.setAttributeNS(null, "stroke-linejoin", current.lineJoin);
  15240. element.setAttributeNS(null, "stroke-width", pf(lineWidthScale * current.lineWidth) + "px");
  15241. element.setAttributeNS(null, "stroke-dasharray", dashArray.map(pf).join(" "));
  15242. element.setAttributeNS(null, "stroke-dashoffset", pf(lineWidthScale * current.dashPhase) + "px");
  15243. }
  15244. eoFill() {
  15245. this.current.element?.setAttributeNS(null, "fill-rule", "evenodd");
  15246. this.fill();
  15247. }
  15248. fillStroke() {
  15249. this.stroke();
  15250. this.fill();
  15251. }
  15252. eoFillStroke() {
  15253. this.current.element?.setAttributeNS(null, "fill-rule", "evenodd");
  15254. this.fillStroke();
  15255. }
  15256. closeStroke() {
  15257. this.closePath();
  15258. this.stroke();
  15259. }
  15260. closeFillStroke() {
  15261. this.closePath();
  15262. this.fillStroke();
  15263. }
  15264. closeEOFillStroke() {
  15265. this.closePath();
  15266. this.eoFillStroke();
  15267. }
  15268. paintSolidColorImageMask() {
  15269. const rect = this.svgFactory.createElement("svg:rect");
  15270. rect.setAttributeNS(null, "x", "0");
  15271. rect.setAttributeNS(null, "y", "0");
  15272. rect.setAttributeNS(null, "width", "1px");
  15273. rect.setAttributeNS(null, "height", "1px");
  15274. rect.setAttributeNS(null, "fill", this.current.fillColor);
  15275. this._ensureTransformGroup().append(rect);
  15276. }
  15277. paintImageXObject(objId) {
  15278. const imgData = this.getObject(objId);
  15279. if (!imgData) {
  15280. (0, _util.warn)(`Dependent image with object ID ${objId} is not ready yet`);
  15281. return;
  15282. }
  15283. this.paintInlineImageXObject(imgData);
  15284. }
  15285. paintInlineImageXObject(imgData, mask) {
  15286. const width = imgData.width;
  15287. const height = imgData.height;
  15288. const imgSrc = convertImgDataToPng(imgData, this.forceDataSchema, !!mask);
  15289. const cliprect = this.svgFactory.createElement("svg:rect");
  15290. cliprect.setAttributeNS(null, "x", "0");
  15291. cliprect.setAttributeNS(null, "y", "0");
  15292. cliprect.setAttributeNS(null, "width", pf(width));
  15293. cliprect.setAttributeNS(null, "height", pf(height));
  15294. this.current.element = cliprect;
  15295. this.clip("nonzero");
  15296. const imgEl = this.svgFactory.createElement("svg:image");
  15297. imgEl.setAttributeNS(XLINK_NS, "xlink:href", imgSrc);
  15298. imgEl.setAttributeNS(null, "x", "0");
  15299. imgEl.setAttributeNS(null, "y", pf(-height));
  15300. imgEl.setAttributeNS(null, "width", pf(width) + "px");
  15301. imgEl.setAttributeNS(null, "height", pf(height) + "px");
  15302. imgEl.setAttributeNS(null, "transform", `scale(${pf(1 / width)} ${pf(-1 / height)})`);
  15303. if (mask) {
  15304. mask.append(imgEl);
  15305. } else {
  15306. this._ensureTransformGroup().append(imgEl);
  15307. }
  15308. }
  15309. paintImageMaskXObject(img) {
  15310. const imgData = this.getObject(img.data, img);
  15311. if (imgData.bitmap) {
  15312. (0, _util.warn)("paintImageMaskXObject: ImageBitmap support is not implemented, " + "ensure that the `isOffscreenCanvasSupported` API parameter is disabled.");
  15313. return;
  15314. }
  15315. const current = this.current;
  15316. const width = imgData.width;
  15317. const height = imgData.height;
  15318. const fillColor = current.fillColor;
  15319. current.maskId = `mask${maskCount++}`;
  15320. const mask = this.svgFactory.createElement("svg:mask");
  15321. mask.setAttributeNS(null, "id", current.maskId);
  15322. const rect = this.svgFactory.createElement("svg:rect");
  15323. rect.setAttributeNS(null, "x", "0");
  15324. rect.setAttributeNS(null, "y", "0");
  15325. rect.setAttributeNS(null, "width", pf(width));
  15326. rect.setAttributeNS(null, "height", pf(height));
  15327. rect.setAttributeNS(null, "fill", fillColor);
  15328. rect.setAttributeNS(null, "mask", `url(#${current.maskId})`);
  15329. this.defs.append(mask);
  15330. this._ensureTransformGroup().append(rect);
  15331. this.paintInlineImageXObject(imgData, mask);
  15332. }
  15333. paintFormXObjectBegin(matrix, bbox) {
  15334. if (Array.isArray(matrix) && matrix.length === 6) {
  15335. this.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
  15336. }
  15337. if (bbox) {
  15338. const width = bbox[2] - bbox[0];
  15339. const height = bbox[3] - bbox[1];
  15340. const cliprect = this.svgFactory.createElement("svg:rect");
  15341. cliprect.setAttributeNS(null, "x", bbox[0]);
  15342. cliprect.setAttributeNS(null, "y", bbox[1]);
  15343. cliprect.setAttributeNS(null, "width", pf(width));
  15344. cliprect.setAttributeNS(null, "height", pf(height));
  15345. this.current.element = cliprect;
  15346. this.clip("nonzero");
  15347. this.endPath();
  15348. }
  15349. }
  15350. paintFormXObjectEnd() {}
  15351. _initialize(viewport) {
  15352. const svg = this.svgFactory.create(viewport.width, viewport.height);
  15353. const definitions = this.svgFactory.createElement("svg:defs");
  15354. svg.append(definitions);
  15355. this.defs = definitions;
  15356. const rootGroup = this.svgFactory.createElement("svg:g");
  15357. rootGroup.setAttributeNS(null, "transform", pm(viewport.transform));
  15358. svg.append(rootGroup);
  15359. this.svg = rootGroup;
  15360. return svg;
  15361. }
  15362. _ensureClipGroup() {
  15363. if (!this.current.clipGroup) {
  15364. const clipGroup = this.svgFactory.createElement("svg:g");
  15365. clipGroup.setAttributeNS(null, "clip-path", this.current.activeClipUrl);
  15366. this.svg.append(clipGroup);
  15367. this.current.clipGroup = clipGroup;
  15368. }
  15369. return this.current.clipGroup;
  15370. }
  15371. _ensureTransformGroup() {
  15372. if (!this.tgrp) {
  15373. this.tgrp = this.svgFactory.createElement("svg:g");
  15374. this.tgrp.setAttributeNS(null, "transform", pm(this.transformMatrix));
  15375. if (this.current.activeClipUrl) {
  15376. this._ensureClipGroup().append(this.tgrp);
  15377. } else {
  15378. this.svg.append(this.tgrp);
  15379. }
  15380. }
  15381. return this.tgrp;
  15382. }
  15383. };
  15384. }
  15385. /***/ })
  15386. /******/ ]);
  15387. /************************************************************************/
  15388. /******/ // The module cache
  15389. /******/ var __webpack_module_cache__ = {};
  15390. /******/
  15391. /******/ // The require function
  15392. /******/ function __w_pdfjs_require__(moduleId) {
  15393. /******/ // Check if module is in cache
  15394. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  15395. /******/ if (cachedModule !== undefined) {
  15396. /******/ return cachedModule.exports;
  15397. /******/ }
  15398. /******/ // Create a new module (and put it into the cache)
  15399. /******/ var module = __webpack_module_cache__[moduleId] = {
  15400. /******/ // no module.id needed
  15401. /******/ // no module.loaded needed
  15402. /******/ exports: {}
  15403. /******/ };
  15404. /******/
  15405. /******/ // Execute the module function
  15406. /******/ __webpack_modules__[moduleId](module, module.exports, __w_pdfjs_require__);
  15407. /******/
  15408. /******/ // Return the exports of the module
  15409. /******/ return module.exports;
  15410. /******/ }
  15411. /******/
  15412. /************************************************************************/
  15413. var __webpack_exports__ = {};
  15414. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  15415. (() => {
  15416. var exports = __webpack_exports__;
  15417. Object.defineProperty(exports, "__esModule", ({
  15418. value: true
  15419. }));
  15420. Object.defineProperty(exports, "AbortException", ({
  15421. enumerable: true,
  15422. get: function () {
  15423. return _util.AbortException;
  15424. }
  15425. }));
  15426. Object.defineProperty(exports, "AnnotationEditorLayer", ({
  15427. enumerable: true,
  15428. get: function () {
  15429. return _annotation_editor_layer.AnnotationEditorLayer;
  15430. }
  15431. }));
  15432. Object.defineProperty(exports, "AnnotationEditorParamsType", ({
  15433. enumerable: true,
  15434. get: function () {
  15435. return _util.AnnotationEditorParamsType;
  15436. }
  15437. }));
  15438. Object.defineProperty(exports, "AnnotationEditorType", ({
  15439. enumerable: true,
  15440. get: function () {
  15441. return _util.AnnotationEditorType;
  15442. }
  15443. }));
  15444. Object.defineProperty(exports, "AnnotationEditorUIManager", ({
  15445. enumerable: true,
  15446. get: function () {
  15447. return _tools.AnnotationEditorUIManager;
  15448. }
  15449. }));
  15450. Object.defineProperty(exports, "AnnotationLayer", ({
  15451. enumerable: true,
  15452. get: function () {
  15453. return _annotation_layer.AnnotationLayer;
  15454. }
  15455. }));
  15456. Object.defineProperty(exports, "AnnotationMode", ({
  15457. enumerable: true,
  15458. get: function () {
  15459. return _util.AnnotationMode;
  15460. }
  15461. }));
  15462. Object.defineProperty(exports, "CMapCompressionType", ({
  15463. enumerable: true,
  15464. get: function () {
  15465. return _util.CMapCompressionType;
  15466. }
  15467. }));
  15468. Object.defineProperty(exports, "GlobalWorkerOptions", ({
  15469. enumerable: true,
  15470. get: function () {
  15471. return _worker_options.GlobalWorkerOptions;
  15472. }
  15473. }));
  15474. Object.defineProperty(exports, "InvalidPDFException", ({
  15475. enumerable: true,
  15476. get: function () {
  15477. return _util.InvalidPDFException;
  15478. }
  15479. }));
  15480. Object.defineProperty(exports, "MissingPDFException", ({
  15481. enumerable: true,
  15482. get: function () {
  15483. return _util.MissingPDFException;
  15484. }
  15485. }));
  15486. Object.defineProperty(exports, "OPS", ({
  15487. enumerable: true,
  15488. get: function () {
  15489. return _util.OPS;
  15490. }
  15491. }));
  15492. Object.defineProperty(exports, "PDFDataRangeTransport", ({
  15493. enumerable: true,
  15494. get: function () {
  15495. return _api.PDFDataRangeTransport;
  15496. }
  15497. }));
  15498. Object.defineProperty(exports, "PDFDateString", ({
  15499. enumerable: true,
  15500. get: function () {
  15501. return _display_utils.PDFDateString;
  15502. }
  15503. }));
  15504. Object.defineProperty(exports, "PDFWorker", ({
  15505. enumerable: true,
  15506. get: function () {
  15507. return _api.PDFWorker;
  15508. }
  15509. }));
  15510. Object.defineProperty(exports, "PasswordResponses", ({
  15511. enumerable: true,
  15512. get: function () {
  15513. return _util.PasswordResponses;
  15514. }
  15515. }));
  15516. Object.defineProperty(exports, "PermissionFlag", ({
  15517. enumerable: true,
  15518. get: function () {
  15519. return _util.PermissionFlag;
  15520. }
  15521. }));
  15522. Object.defineProperty(exports, "PixelsPerInch", ({
  15523. enumerable: true,
  15524. get: function () {
  15525. return _display_utils.PixelsPerInch;
  15526. }
  15527. }));
  15528. Object.defineProperty(exports, "RenderingCancelledException", ({
  15529. enumerable: true,
  15530. get: function () {
  15531. return _display_utils.RenderingCancelledException;
  15532. }
  15533. }));
  15534. Object.defineProperty(exports, "SVGGraphics", ({
  15535. enumerable: true,
  15536. get: function () {
  15537. return _svg.SVGGraphics;
  15538. }
  15539. }));
  15540. Object.defineProperty(exports, "UNSUPPORTED_FEATURES", ({
  15541. enumerable: true,
  15542. get: function () {
  15543. return _util.UNSUPPORTED_FEATURES;
  15544. }
  15545. }));
  15546. Object.defineProperty(exports, "UnexpectedResponseException", ({
  15547. enumerable: true,
  15548. get: function () {
  15549. return _util.UnexpectedResponseException;
  15550. }
  15551. }));
  15552. Object.defineProperty(exports, "Util", ({
  15553. enumerable: true,
  15554. get: function () {
  15555. return _util.Util;
  15556. }
  15557. }));
  15558. Object.defineProperty(exports, "VerbosityLevel", ({
  15559. enumerable: true,
  15560. get: function () {
  15561. return _util.VerbosityLevel;
  15562. }
  15563. }));
  15564. Object.defineProperty(exports, "XfaLayer", ({
  15565. enumerable: true,
  15566. get: function () {
  15567. return _xfa_layer.XfaLayer;
  15568. }
  15569. }));
  15570. Object.defineProperty(exports, "build", ({
  15571. enumerable: true,
  15572. get: function () {
  15573. return _api.build;
  15574. }
  15575. }));
  15576. Object.defineProperty(exports, "createPromiseCapability", ({
  15577. enumerable: true,
  15578. get: function () {
  15579. return _util.createPromiseCapability;
  15580. }
  15581. }));
  15582. Object.defineProperty(exports, "createValidAbsoluteUrl", ({
  15583. enumerable: true,
  15584. get: function () {
  15585. return _util.createValidAbsoluteUrl;
  15586. }
  15587. }));
  15588. Object.defineProperty(exports, "getDocument", ({
  15589. enumerable: true,
  15590. get: function () {
  15591. return _api.getDocument;
  15592. }
  15593. }));
  15594. Object.defineProperty(exports, "getFilenameFromUrl", ({
  15595. enumerable: true,
  15596. get: function () {
  15597. return _display_utils.getFilenameFromUrl;
  15598. }
  15599. }));
  15600. Object.defineProperty(exports, "getPdfFilenameFromUrl", ({
  15601. enumerable: true,
  15602. get: function () {
  15603. return _display_utils.getPdfFilenameFromUrl;
  15604. }
  15605. }));
  15606. Object.defineProperty(exports, "getXfaPageViewport", ({
  15607. enumerable: true,
  15608. get: function () {
  15609. return _display_utils.getXfaPageViewport;
  15610. }
  15611. }));
  15612. Object.defineProperty(exports, "isDataScheme", ({
  15613. enumerable: true,
  15614. get: function () {
  15615. return _display_utils.isDataScheme;
  15616. }
  15617. }));
  15618. Object.defineProperty(exports, "isPdfFile", ({
  15619. enumerable: true,
  15620. get: function () {
  15621. return _display_utils.isPdfFile;
  15622. }
  15623. }));
  15624. Object.defineProperty(exports, "loadScript", ({
  15625. enumerable: true,
  15626. get: function () {
  15627. return _display_utils.loadScript;
  15628. }
  15629. }));
  15630. Object.defineProperty(exports, "renderTextLayer", ({
  15631. enumerable: true,
  15632. get: function () {
  15633. return _text_layer.renderTextLayer;
  15634. }
  15635. }));
  15636. Object.defineProperty(exports, "setLayerDimensions", ({
  15637. enumerable: true,
  15638. get: function () {
  15639. return _display_utils.setLayerDimensions;
  15640. }
  15641. }));
  15642. Object.defineProperty(exports, "shadow", ({
  15643. enumerable: true,
  15644. get: function () {
  15645. return _util.shadow;
  15646. }
  15647. }));
  15648. Object.defineProperty(exports, "updateTextLayer", ({
  15649. enumerable: true,
  15650. get: function () {
  15651. return _text_layer.updateTextLayer;
  15652. }
  15653. }));
  15654. Object.defineProperty(exports, "version", ({
  15655. enumerable: true,
  15656. get: function () {
  15657. return _api.version;
  15658. }
  15659. }));
  15660. var _util = __w_pdfjs_require__(1);
  15661. var _api = __w_pdfjs_require__(2);
  15662. var _display_utils = __w_pdfjs_require__(6);
  15663. var _text_layer = __w_pdfjs_require__(26);
  15664. var _annotation_editor_layer = __w_pdfjs_require__(27);
  15665. var _tools = __w_pdfjs_require__(5);
  15666. var _annotation_layer = __w_pdfjs_require__(32);
  15667. var _worker_options = __w_pdfjs_require__(14);
  15668. var _svg = __w_pdfjs_require__(35);
  15669. var _xfa_layer = __w_pdfjs_require__(34);
  15670. const pdfjsVersion = '3.3.122';
  15671. const pdfjsBuild = '562045607';
  15672. })();
  15673. /******/ return __webpack_exports__;
  15674. /******/ })()
  15675. ;
  15676. });
  15677. //# sourceMappingURL=pdf.js.map