pdf.js 422 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * JavaScript code in this page
  4. *
  5. * Copyright 2022 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * JavaScript code in this page
  21. */
  22. (function webpackUniversalModuleDefinition(root, factory) {
  23. if(typeof exports === 'object' && typeof module === 'object')
  24. module.exports = factory();
  25. else if(typeof define === 'function' && define.amd)
  26. define("pdfjs-dist/build/pdf", [], factory);
  27. else if(typeof exports === 'object')
  28. exports["pdfjs-dist/build/pdf"] = factory();
  29. else
  30. root["pdfjs-dist/build/pdf"] = root.pdfjsLib = factory();
  31. })(this, () => {
  32. return /******/ (() => { // webpackBootstrap
  33. /******/ "use strict";
  34. /******/ var __webpack_modules__ = ([
  35. /* 0 */,
  36. /* 1 */
  37. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  38. Object.defineProperty(exports, "__esModule", ({
  39. value: true
  40. }));
  41. exports.VerbosityLevel = exports.Util = exports.UnknownErrorException = exports.UnexpectedResponseException = exports.UNSUPPORTED_FEATURES = exports.TextRenderingMode = exports.StreamType = exports.RenderingIntentFlag = exports.PermissionFlag = exports.PasswordResponses = exports.PasswordException = exports.PageActionEventType = exports.OPS = exports.MissingPDFException = exports.InvalidPDFException = exports.ImageKind = exports.IDENTITY_MATRIX = exports.FormatError = exports.FontType = exports.FeatureTest = exports.FONT_IDENTITY_MATRIX = exports.DocumentActionEventType = exports.CMapCompressionType = exports.BaseException = exports.AnnotationType = exports.AnnotationStateModelType = exports.AnnotationReviewState = exports.AnnotationReplyType = exports.AnnotationMode = exports.AnnotationMarkedState = exports.AnnotationFlag = exports.AnnotationFieldFlag = 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.escapeString = escapeString;
  49. exports.getModificationDate = getModificationDate;
  50. exports.getVerbosityLevel = getVerbosityLevel;
  51. exports.info = info;
  52. exports.isArrayBuffer = isArrayBuffer;
  53. exports.isArrayEqual = isArrayEqual;
  54. exports.isAscii = isAscii;
  55. exports.objectFromMap = objectFromMap;
  56. exports.objectSize = objectSize;
  57. exports.setVerbosityLevel = setVerbosityLevel;
  58. exports.shadow = shadow;
  59. exports.string32 = string32;
  60. exports.stringToBytes = stringToBytes;
  61. exports.stringToPDFString = stringToPDFString;
  62. exports.stringToUTF16BEString = stringToUTF16BEString;
  63. exports.stringToUTF8String = stringToUTF8String;
  64. exports.unreachable = unreachable;
  65. exports.utf8StringToString = utf8StringToString;
  66. exports.warn = warn;
  67. __w_pdfjs_require__(2);
  68. const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  69. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  70. const FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  71. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  72. const RenderingIntentFlag = {
  73. ANY: 0x01,
  74. DISPLAY: 0x02,
  75. PRINT: 0x04,
  76. ANNOTATIONS_FORMS: 0x10,
  77. ANNOTATIONS_STORAGE: 0x20,
  78. ANNOTATIONS_DISABLE: 0x40,
  79. OPLIST: 0x100
  80. };
  81. exports.RenderingIntentFlag = RenderingIntentFlag;
  82. const AnnotationMode = {
  83. DISABLE: 0,
  84. ENABLE: 1,
  85. ENABLE_FORMS: 2,
  86. ENABLE_STORAGE: 3
  87. };
  88. exports.AnnotationMode = AnnotationMode;
  89. const PermissionFlag = {
  90. PRINT: 0x04,
  91. MODIFY_CONTENTS: 0x08,
  92. COPY: 0x10,
  93. MODIFY_ANNOTATIONS: 0x20,
  94. FILL_INTERACTIVE_FORMS: 0x100,
  95. COPY_FOR_ACCESSIBILITY: 0x200,
  96. ASSEMBLE: 0x400,
  97. PRINT_HIGH_QUALITY: 0x800
  98. };
  99. exports.PermissionFlag = PermissionFlag;
  100. const TextRenderingMode = {
  101. FILL: 0,
  102. STROKE: 1,
  103. FILL_STROKE: 2,
  104. INVISIBLE: 3,
  105. FILL_ADD_TO_PATH: 4,
  106. STROKE_ADD_TO_PATH: 5,
  107. FILL_STROKE_ADD_TO_PATH: 6,
  108. ADD_TO_PATH: 7,
  109. FILL_STROKE_MASK: 3,
  110. ADD_TO_PATH_FLAG: 4
  111. };
  112. exports.TextRenderingMode = TextRenderingMode;
  113. const ImageKind = {
  114. GRAYSCALE_1BPP: 1,
  115. RGB_24BPP: 2,
  116. RGBA_32BPP: 3
  117. };
  118. exports.ImageKind = ImageKind;
  119. const AnnotationType = {
  120. TEXT: 1,
  121. LINK: 2,
  122. FREETEXT: 3,
  123. LINE: 4,
  124. SQUARE: 5,
  125. CIRCLE: 6,
  126. POLYGON: 7,
  127. POLYLINE: 8,
  128. HIGHLIGHT: 9,
  129. UNDERLINE: 10,
  130. SQUIGGLY: 11,
  131. STRIKEOUT: 12,
  132. STAMP: 13,
  133. CARET: 14,
  134. INK: 15,
  135. POPUP: 16,
  136. FILEATTACHMENT: 17,
  137. SOUND: 18,
  138. MOVIE: 19,
  139. WIDGET: 20,
  140. SCREEN: 21,
  141. PRINTERMARK: 22,
  142. TRAPNET: 23,
  143. WATERMARK: 24,
  144. THREED: 25,
  145. REDACT: 26
  146. };
  147. exports.AnnotationType = AnnotationType;
  148. const AnnotationStateModelType = {
  149. MARKED: "Marked",
  150. REVIEW: "Review"
  151. };
  152. exports.AnnotationStateModelType = AnnotationStateModelType;
  153. const AnnotationMarkedState = {
  154. MARKED: "Marked",
  155. UNMARKED: "Unmarked"
  156. };
  157. exports.AnnotationMarkedState = AnnotationMarkedState;
  158. const AnnotationReviewState = {
  159. ACCEPTED: "Accepted",
  160. REJECTED: "Rejected",
  161. CANCELLED: "Cancelled",
  162. COMPLETED: "Completed",
  163. NONE: "None"
  164. };
  165. exports.AnnotationReviewState = AnnotationReviewState;
  166. const AnnotationReplyType = {
  167. GROUP: "Group",
  168. REPLY: "R"
  169. };
  170. exports.AnnotationReplyType = AnnotationReplyType;
  171. const AnnotationFlag = {
  172. INVISIBLE: 0x01,
  173. HIDDEN: 0x02,
  174. PRINT: 0x04,
  175. NOZOOM: 0x08,
  176. NOROTATE: 0x10,
  177. NOVIEW: 0x20,
  178. READONLY: 0x40,
  179. LOCKED: 0x80,
  180. TOGGLENOVIEW: 0x100,
  181. LOCKEDCONTENTS: 0x200
  182. };
  183. exports.AnnotationFlag = AnnotationFlag;
  184. const AnnotationFieldFlag = {
  185. READONLY: 0x0000001,
  186. REQUIRED: 0x0000002,
  187. NOEXPORT: 0x0000004,
  188. MULTILINE: 0x0001000,
  189. PASSWORD: 0x0002000,
  190. NOTOGGLETOOFF: 0x0004000,
  191. RADIO: 0x0008000,
  192. PUSHBUTTON: 0x0010000,
  193. COMBO: 0x0020000,
  194. EDIT: 0x0040000,
  195. SORT: 0x0080000,
  196. FILESELECT: 0x0100000,
  197. MULTISELECT: 0x0200000,
  198. DONOTSPELLCHECK: 0x0400000,
  199. DONOTSCROLL: 0x0800000,
  200. COMB: 0x1000000,
  201. RICHTEXT: 0x2000000,
  202. RADIOSINUNISON: 0x2000000,
  203. COMMITONSELCHANGE: 0x4000000
  204. };
  205. exports.AnnotationFieldFlag = AnnotationFieldFlag;
  206. const AnnotationBorderStyleType = {
  207. SOLID: 1,
  208. DASHED: 2,
  209. BEVELED: 3,
  210. INSET: 4,
  211. UNDERLINE: 5
  212. };
  213. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  214. const AnnotationActionEventType = {
  215. E: "Mouse Enter",
  216. X: "Mouse Exit",
  217. D: "Mouse Down",
  218. U: "Mouse Up",
  219. Fo: "Focus",
  220. Bl: "Blur",
  221. PO: "PageOpen",
  222. PC: "PageClose",
  223. PV: "PageVisible",
  224. PI: "PageInvisible",
  225. K: "Keystroke",
  226. F: "Format",
  227. V: "Validate",
  228. C: "Calculate"
  229. };
  230. exports.AnnotationActionEventType = AnnotationActionEventType;
  231. const DocumentActionEventType = {
  232. WC: "WillClose",
  233. WS: "WillSave",
  234. DS: "DidSave",
  235. WP: "WillPrint",
  236. DP: "DidPrint"
  237. };
  238. exports.DocumentActionEventType = DocumentActionEventType;
  239. const PageActionEventType = {
  240. O: "PageOpen",
  241. C: "PageClose"
  242. };
  243. exports.PageActionEventType = PageActionEventType;
  244. const StreamType = {
  245. UNKNOWN: "UNKNOWN",
  246. FLATE: "FLATE",
  247. LZW: "LZW",
  248. DCT: "DCT",
  249. JPX: "JPX",
  250. JBIG: "JBIG",
  251. A85: "A85",
  252. AHX: "AHX",
  253. CCF: "CCF",
  254. RLX: "RLX"
  255. };
  256. exports.StreamType = StreamType;
  257. const FontType = {
  258. UNKNOWN: "UNKNOWN",
  259. TYPE1: "TYPE1",
  260. TYPE1STANDARD: "TYPE1STANDARD",
  261. TYPE1C: "TYPE1C",
  262. CIDFONTTYPE0: "CIDFONTTYPE0",
  263. CIDFONTTYPE0C: "CIDFONTTYPE0C",
  264. TRUETYPE: "TRUETYPE",
  265. CIDFONTTYPE2: "CIDFONTTYPE2",
  266. TYPE3: "TYPE3",
  267. OPENTYPE: "OPENTYPE",
  268. TYPE0: "TYPE0",
  269. MMTYPE1: "MMTYPE1"
  270. };
  271. exports.FontType = FontType;
  272. const VerbosityLevel = {
  273. ERRORS: 0,
  274. WARNINGS: 1,
  275. INFOS: 5
  276. };
  277. exports.VerbosityLevel = VerbosityLevel;
  278. const CMapCompressionType = {
  279. NONE: 0,
  280. BINARY: 1,
  281. STREAM: 2
  282. };
  283. exports.CMapCompressionType = CMapCompressionType;
  284. const OPS = {
  285. dependency: 1,
  286. setLineWidth: 2,
  287. setLineCap: 3,
  288. setLineJoin: 4,
  289. setMiterLimit: 5,
  290. setDash: 6,
  291. setRenderingIntent: 7,
  292. setFlatness: 8,
  293. setGState: 9,
  294. save: 10,
  295. restore: 11,
  296. transform: 12,
  297. moveTo: 13,
  298. lineTo: 14,
  299. curveTo: 15,
  300. curveTo2: 16,
  301. curveTo3: 17,
  302. closePath: 18,
  303. rectangle: 19,
  304. stroke: 20,
  305. closeStroke: 21,
  306. fill: 22,
  307. eoFill: 23,
  308. fillStroke: 24,
  309. eoFillStroke: 25,
  310. closeFillStroke: 26,
  311. closeEOFillStroke: 27,
  312. endPath: 28,
  313. clip: 29,
  314. eoClip: 30,
  315. beginText: 31,
  316. endText: 32,
  317. setCharSpacing: 33,
  318. setWordSpacing: 34,
  319. setHScale: 35,
  320. setLeading: 36,
  321. setFont: 37,
  322. setTextRenderingMode: 38,
  323. setTextRise: 39,
  324. moveText: 40,
  325. setLeadingMoveText: 41,
  326. setTextMatrix: 42,
  327. nextLine: 43,
  328. showText: 44,
  329. showSpacedText: 45,
  330. nextLineShowText: 46,
  331. nextLineSetSpacingShowText: 47,
  332. setCharWidth: 48,
  333. setCharWidthAndBounds: 49,
  334. setStrokeColorSpace: 50,
  335. setFillColorSpace: 51,
  336. setStrokeColor: 52,
  337. setStrokeColorN: 53,
  338. setFillColor: 54,
  339. setFillColorN: 55,
  340. setStrokeGray: 56,
  341. setFillGray: 57,
  342. setStrokeRGBColor: 58,
  343. setFillRGBColor: 59,
  344. setStrokeCMYKColor: 60,
  345. setFillCMYKColor: 61,
  346. shadingFill: 62,
  347. beginInlineImage: 63,
  348. beginImageData: 64,
  349. endInlineImage: 65,
  350. paintXObject: 66,
  351. markPoint: 67,
  352. markPointProps: 68,
  353. beginMarkedContent: 69,
  354. beginMarkedContentProps: 70,
  355. endMarkedContent: 71,
  356. beginCompat: 72,
  357. endCompat: 73,
  358. paintFormXObjectBegin: 74,
  359. paintFormXObjectEnd: 75,
  360. beginGroup: 76,
  361. endGroup: 77,
  362. beginAnnotations: 78,
  363. endAnnotations: 79,
  364. beginAnnotation: 80,
  365. endAnnotation: 81,
  366. paintJpegXObject: 82,
  367. paintImageMaskXObject: 83,
  368. paintImageMaskXObjectGroup: 84,
  369. paintImageXObject: 85,
  370. paintInlineImageXObject: 86,
  371. paintInlineImageXObjectGroup: 87,
  372. paintImageXObjectRepeat: 88,
  373. paintImageMaskXObjectRepeat: 89,
  374. paintSolidColorImageMask: 90,
  375. constructPath: 91
  376. };
  377. exports.OPS = OPS;
  378. const UNSUPPORTED_FEATURES = {
  379. unknown: "unknown",
  380. forms: "forms",
  381. javaScript: "javaScript",
  382. signatures: "signatures",
  383. smask: "smask",
  384. shadingPattern: "shadingPattern",
  385. font: "font",
  386. errorTilingPattern: "errorTilingPattern",
  387. errorExtGState: "errorExtGState",
  388. errorXObject: "errorXObject",
  389. errorFontLoadType3: "errorFontLoadType3",
  390. errorFontState: "errorFontState",
  391. errorFontMissing: "errorFontMissing",
  392. errorFontTranslate: "errorFontTranslate",
  393. errorColorSpace: "errorColorSpace",
  394. errorOperatorList: "errorOperatorList",
  395. errorFontToUnicode: "errorFontToUnicode",
  396. errorFontLoadNative: "errorFontLoadNative",
  397. errorFontBuildPath: "errorFontBuildPath",
  398. errorFontGetPath: "errorFontGetPath",
  399. errorMarkedContent: "errorMarkedContent",
  400. errorContentSubStream: "errorContentSubStream"
  401. };
  402. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  403. const PasswordResponses = {
  404. NEED_PASSWORD: 1,
  405. INCORRECT_PASSWORD: 2
  406. };
  407. exports.PasswordResponses = PasswordResponses;
  408. let verbosity = VerbosityLevel.WARNINGS;
  409. function setVerbosityLevel(level) {
  410. if (Number.isInteger(level)) {
  411. verbosity = level;
  412. }
  413. }
  414. function getVerbosityLevel() {
  415. return verbosity;
  416. }
  417. function info(msg) {
  418. if (verbosity >= VerbosityLevel.INFOS) {
  419. console.log(`Info: ${msg}`);
  420. }
  421. }
  422. function warn(msg) {
  423. if (verbosity >= VerbosityLevel.WARNINGS) {
  424. console.log(`Warning: ${msg}`);
  425. }
  426. }
  427. function unreachable(msg) {
  428. throw new Error(msg);
  429. }
  430. function assert(cond, msg) {
  431. if (!cond) {
  432. unreachable(msg);
  433. }
  434. }
  435. function _isValidProtocol(url) {
  436. if (!url) {
  437. return false;
  438. }
  439. switch (url.protocol) {
  440. case "http:":
  441. case "https:":
  442. case "ftp:":
  443. case "mailto:":
  444. case "tel:":
  445. return true;
  446. default:
  447. return false;
  448. }
  449. }
  450. function createValidAbsoluteUrl(url, baseUrl = null, options = null) {
  451. if (!url) {
  452. return null;
  453. }
  454. try {
  455. if (options && typeof url === "string") {
  456. if (options.addDefaultProtocol && url.startsWith("www.")) {
  457. const dots = url.match(/\./g);
  458. if (dots && dots.length >= 2) {
  459. url = `http://${url}`;
  460. }
  461. }
  462. if (options.tryConvertEncoding) {
  463. try {
  464. url = stringToUTF8String(url);
  465. } catch (ex) {}
  466. }
  467. }
  468. const absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url);
  469. if (_isValidProtocol(absoluteUrl)) {
  470. return absoluteUrl;
  471. }
  472. } catch (ex) {}
  473. return null;
  474. }
  475. function shadow(obj, prop, value) {
  476. Object.defineProperty(obj, prop, {
  477. value,
  478. enumerable: true,
  479. configurable: true,
  480. writable: false
  481. });
  482. return value;
  483. }
  484. const BaseException = function BaseExceptionClosure() {
  485. function BaseException(message, name) {
  486. if (this.constructor === BaseException) {
  487. unreachable("Cannot initialize BaseException.");
  488. }
  489. this.message = message;
  490. this.name = name;
  491. }
  492. BaseException.prototype = new Error();
  493. BaseException.constructor = BaseException;
  494. return BaseException;
  495. }();
  496. exports.BaseException = BaseException;
  497. class PasswordException extends BaseException {
  498. constructor(msg, code) {
  499. super(msg, "PasswordException");
  500. this.code = code;
  501. }
  502. }
  503. exports.PasswordException = PasswordException;
  504. class UnknownErrorException extends BaseException {
  505. constructor(msg, details) {
  506. super(msg, "UnknownErrorException");
  507. this.details = details;
  508. }
  509. }
  510. exports.UnknownErrorException = UnknownErrorException;
  511. class InvalidPDFException extends BaseException {
  512. constructor(msg) {
  513. super(msg, "InvalidPDFException");
  514. }
  515. }
  516. exports.InvalidPDFException = InvalidPDFException;
  517. class MissingPDFException extends BaseException {
  518. constructor(msg) {
  519. super(msg, "MissingPDFException");
  520. }
  521. }
  522. exports.MissingPDFException = MissingPDFException;
  523. class UnexpectedResponseException extends BaseException {
  524. constructor(msg, status) {
  525. super(msg, "UnexpectedResponseException");
  526. this.status = status;
  527. }
  528. }
  529. exports.UnexpectedResponseException = UnexpectedResponseException;
  530. class FormatError extends BaseException {
  531. constructor(msg) {
  532. super(msg, "FormatError");
  533. }
  534. }
  535. exports.FormatError = FormatError;
  536. class AbortException extends BaseException {
  537. constructor(msg) {
  538. super(msg, "AbortException");
  539. }
  540. }
  541. exports.AbortException = AbortException;
  542. function bytesToString(bytes) {
  543. if (typeof bytes !== "object" || bytes === null || bytes.length === undefined) {
  544. unreachable("Invalid argument for bytesToString");
  545. }
  546. const length = bytes.length;
  547. const MAX_ARGUMENT_COUNT = 8192;
  548. if (length < MAX_ARGUMENT_COUNT) {
  549. return String.fromCharCode.apply(null, bytes);
  550. }
  551. const strBuf = [];
  552. for (let i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  553. const chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  554. const chunk = bytes.subarray(i, chunkEnd);
  555. strBuf.push(String.fromCharCode.apply(null, chunk));
  556. }
  557. return strBuf.join("");
  558. }
  559. function stringToBytes(str) {
  560. if (typeof str !== "string") {
  561. unreachable("Invalid argument for stringToBytes");
  562. }
  563. const length = str.length;
  564. const bytes = new Uint8Array(length);
  565. for (let i = 0; i < length; ++i) {
  566. bytes[i] = str.charCodeAt(i) & 0xff;
  567. }
  568. return bytes;
  569. }
  570. function arrayByteLength(arr) {
  571. if (arr.length !== undefined) {
  572. return arr.length;
  573. }
  574. if (arr.byteLength !== undefined) {
  575. return arr.byteLength;
  576. }
  577. unreachable("Invalid argument for arrayByteLength");
  578. }
  579. function arraysToBytes(arr) {
  580. const length = arr.length;
  581. if (length === 1 && arr[0] instanceof Uint8Array) {
  582. return arr[0];
  583. }
  584. let resultLength = 0;
  585. for (let i = 0; i < length; i++) {
  586. resultLength += arrayByteLength(arr[i]);
  587. }
  588. let pos = 0;
  589. const data = new Uint8Array(resultLength);
  590. for (let i = 0; i < length; i++) {
  591. let item = arr[i];
  592. if (!(item instanceof Uint8Array)) {
  593. if (typeof item === "string") {
  594. item = stringToBytes(item);
  595. } else {
  596. item = new Uint8Array(item);
  597. }
  598. }
  599. const itemLength = item.byteLength;
  600. data.set(item, pos);
  601. pos += itemLength;
  602. }
  603. return data;
  604. }
  605. function string32(value) {
  606. return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
  607. }
  608. function objectSize(obj) {
  609. return Object.keys(obj).length;
  610. }
  611. function objectFromMap(map) {
  612. const obj = Object.create(null);
  613. for (const [key, value] of map) {
  614. obj[key] = value;
  615. }
  616. return obj;
  617. }
  618. function isLittleEndian() {
  619. const buffer8 = new Uint8Array(4);
  620. buffer8[0] = 1;
  621. const view32 = new Uint32Array(buffer8.buffer, 0, 1);
  622. return view32[0] === 1;
  623. }
  624. function isEvalSupported() {
  625. try {
  626. new Function("");
  627. return true;
  628. } catch (e) {
  629. return false;
  630. }
  631. }
  632. class FeatureTest {
  633. static get isLittleEndian() {
  634. return shadow(this, "isLittleEndian", isLittleEndian());
  635. }
  636. static get isEvalSupported() {
  637. return shadow(this, "isEvalSupported", isEvalSupported());
  638. }
  639. static get isOffscreenCanvasSupported() {
  640. return shadow(this, "isOffscreenCanvasSupported", typeof OffscreenCanvas !== "undefined");
  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 apply3dTransform(m, v) {
  719. return [m[0] * v[0] + m[1] * v[1] + m[2] * v[2], m[3] * v[0] + m[4] * v[1] + m[5] * v[2], m[6] * v[0] + m[7] * v[1] + m[8] * v[2]];
  720. }
  721. static singularValueDecompose2dScale(m) {
  722. const transpose = [m[0], m[2], m[1], m[3]];
  723. const a = m[0] * transpose[0] + m[1] * transpose[2];
  724. const b = m[0] * transpose[1] + m[1] * transpose[3];
  725. const c = m[2] * transpose[0] + m[3] * transpose[2];
  726. const d = m[2] * transpose[1] + m[3] * transpose[3];
  727. const first = (a + d) / 2;
  728. const second = Math.sqrt((a + d) ** 2 - 4 * (a * d - c * b)) / 2;
  729. const sx = first + second || 1;
  730. const sy = first - second || 1;
  731. return [Math.sqrt(sx), Math.sqrt(sy)];
  732. }
  733. static normalizeRect(rect) {
  734. const r = rect.slice(0);
  735. if (rect[0] > rect[2]) {
  736. r[0] = rect[2];
  737. r[2] = rect[0];
  738. }
  739. if (rect[1] > rect[3]) {
  740. r[1] = rect[3];
  741. r[3] = rect[1];
  742. }
  743. return r;
  744. }
  745. static intersect(rect1, rect2) {
  746. const xLow = Math.max(Math.min(rect1[0], rect1[2]), Math.min(rect2[0], rect2[2]));
  747. const xHigh = Math.min(Math.max(rect1[0], rect1[2]), Math.max(rect2[0], rect2[2]));
  748. if (xLow > xHigh) {
  749. return null;
  750. }
  751. const yLow = Math.max(Math.min(rect1[1], rect1[3]), Math.min(rect2[1], rect2[3]));
  752. const yHigh = Math.min(Math.max(rect1[1], rect1[3]), Math.max(rect2[1], rect2[3]));
  753. if (yLow > yHigh) {
  754. return null;
  755. }
  756. return [xLow, yLow, xHigh, yHigh];
  757. }
  758. static bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3) {
  759. const tvalues = [],
  760. bounds = [[], []];
  761. let a, b, c, t, t1, t2, b2ac, sqrtb2ac;
  762. for (let i = 0; i < 2; ++i) {
  763. if (i === 0) {
  764. b = 6 * x0 - 12 * x1 + 6 * x2;
  765. a = -3 * x0 + 9 * x1 - 9 * x2 + 3 * x3;
  766. c = 3 * x1 - 3 * x0;
  767. } else {
  768. b = 6 * y0 - 12 * y1 + 6 * y2;
  769. a = -3 * y0 + 9 * y1 - 9 * y2 + 3 * y3;
  770. c = 3 * y1 - 3 * y0;
  771. }
  772. if (Math.abs(a) < 1e-12) {
  773. if (Math.abs(b) < 1e-12) {
  774. continue;
  775. }
  776. t = -c / b;
  777. if (0 < t && t < 1) {
  778. tvalues.push(t);
  779. }
  780. continue;
  781. }
  782. b2ac = b * b - 4 * c * a;
  783. sqrtb2ac = Math.sqrt(b2ac);
  784. if (b2ac < 0) {
  785. continue;
  786. }
  787. t1 = (-b + sqrtb2ac) / (2 * a);
  788. if (0 < t1 && t1 < 1) {
  789. tvalues.push(t1);
  790. }
  791. t2 = (-b - sqrtb2ac) / (2 * a);
  792. if (0 < t2 && t2 < 1) {
  793. tvalues.push(t2);
  794. }
  795. }
  796. let j = tvalues.length,
  797. mt;
  798. const jlen = j;
  799. while (j--) {
  800. t = tvalues[j];
  801. mt = 1 - t;
  802. bounds[0][j] = mt * mt * mt * x0 + 3 * mt * mt * t * x1 + 3 * mt * t * t * x2 + t * t * t * x3;
  803. bounds[1][j] = mt * mt * mt * y0 + 3 * mt * mt * t * y1 + 3 * mt * t * t * y2 + t * t * t * y3;
  804. }
  805. bounds[0][jlen] = x0;
  806. bounds[1][jlen] = y0;
  807. bounds[0][jlen + 1] = x3;
  808. bounds[1][jlen + 1] = y3;
  809. bounds[0].length = bounds[1].length = jlen + 2;
  810. return [Math.min(...bounds[0]), Math.min(...bounds[1]), Math.max(...bounds[0]), Math.max(...bounds[1])];
  811. }
  812. }
  813. exports.Util = Util;
  814. 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];
  815. function stringToPDFString(str) {
  816. if (str[0] >= "\xEF") {
  817. let encoding;
  818. if (str[0] === "\xFE" && str[1] === "\xFF") {
  819. encoding = "utf-16be";
  820. } else if (str[0] === "\xFF" && str[1] === "\xFE") {
  821. encoding = "utf-16le";
  822. } else if (str[0] === "\xEF" && str[1] === "\xBB" && str[2] === "\xBF") {
  823. encoding = "utf-8";
  824. }
  825. if (encoding) {
  826. try {
  827. const decoder = new TextDecoder(encoding, {
  828. fatal: true
  829. });
  830. const buffer = stringToBytes(str);
  831. return decoder.decode(buffer);
  832. } catch (ex) {
  833. warn(`stringToPDFString: "${ex}".`);
  834. }
  835. }
  836. }
  837. const strBuf = [];
  838. for (let i = 0, ii = str.length; i < ii; i++) {
  839. const code = PDFStringTranslateTable[str.charCodeAt(i)];
  840. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  841. }
  842. return strBuf.join("");
  843. }
  844. function escapeString(str) {
  845. return str.replace(/([()\\\n\r])/g, match => {
  846. if (match === "\n") {
  847. return "\\n";
  848. } else if (match === "\r") {
  849. return "\\r";
  850. }
  851. return `\\${match}`;
  852. });
  853. }
  854. function isAscii(str) {
  855. return /^[\x00-\x7F]*$/.test(str);
  856. }
  857. function stringToUTF16BEString(str) {
  858. const buf = ["\xFE\xFF"];
  859. for (let i = 0, ii = str.length; i < ii; i++) {
  860. const char = str.charCodeAt(i);
  861. buf.push(String.fromCharCode(char >> 8 & 0xff), String.fromCharCode(char & 0xff));
  862. }
  863. return buf.join("");
  864. }
  865. function stringToUTF8String(str) {
  866. return decodeURIComponent(escape(str));
  867. }
  868. function utf8StringToString(str) {
  869. return unescape(encodeURIComponent(str));
  870. }
  871. function isArrayBuffer(v) {
  872. return typeof v === "object" && v !== null && v.byteLength !== undefined;
  873. }
  874. function isArrayEqual(arr1, arr2) {
  875. if (arr1.length !== arr2.length) {
  876. return false;
  877. }
  878. for (let i = 0, ii = arr1.length; i < ii; i++) {
  879. if (arr1[i] !== arr2[i]) {
  880. return false;
  881. }
  882. }
  883. return true;
  884. }
  885. function getModificationDate(date = new Date()) {
  886. 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")];
  887. return buffer.join("");
  888. }
  889. function createPromiseCapability() {
  890. const capability = Object.create(null);
  891. let isSettled = false;
  892. Object.defineProperty(capability, "settled", {
  893. get() {
  894. return isSettled;
  895. }
  896. });
  897. capability.promise = new Promise(function (resolve, reject) {
  898. capability.resolve = function (data) {
  899. isSettled = true;
  900. resolve(data);
  901. };
  902. capability.reject = function (reason) {
  903. isSettled = true;
  904. reject(reason);
  905. };
  906. });
  907. return capability;
  908. }
  909. /***/ }),
  910. /* 2 */
  911. /***/ ((__unused_webpack_module, __unused_webpack_exports, __w_pdfjs_require__) => {
  912. var _is_node = __w_pdfjs_require__(3);
  913. ;
  914. /***/ }),
  915. /* 3 */
  916. /***/ ((__unused_webpack_module, exports) => {
  917. Object.defineProperty(exports, "__esModule", ({
  918. value: true
  919. }));
  920. exports.isNodeJS = void 0;
  921. const isNodeJS = typeof process === "object" && process + "" === "[object process]" && !process.versions.nw && !(process.versions.electron && process.type && process.type !== "browser");
  922. exports.isNodeJS = isNodeJS;
  923. /***/ }),
  924. /* 4 */
  925. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  926. Object.defineProperty(exports, "__esModule", ({
  927. value: true
  928. }));
  929. 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;
  930. exports.getDocument = getDocument;
  931. exports.setPDFNetworkStreamFactory = setPDFNetworkStreamFactory;
  932. exports.version = void 0;
  933. var _util = __w_pdfjs_require__(1);
  934. var _display_utils = __w_pdfjs_require__(5);
  935. var _font_loader = __w_pdfjs_require__(7);
  936. var _annotation_storage = __w_pdfjs_require__(8);
  937. var _canvas = __w_pdfjs_require__(10);
  938. var _worker_options = __w_pdfjs_require__(13);
  939. var _is_node = __w_pdfjs_require__(3);
  940. var _message_handler = __w_pdfjs_require__(14);
  941. var _metadata = __w_pdfjs_require__(15);
  942. var _optional_content_config = __w_pdfjs_require__(16);
  943. var _transport_stream = __w_pdfjs_require__(17);
  944. var _xfa_text = __w_pdfjs_require__(18);
  945. const DEFAULT_RANGE_CHUNK_SIZE = 65536;
  946. const RENDERING_CANCELLED_TIMEOUT = 100;
  947. let DefaultCanvasFactory = _display_utils.DOMCanvasFactory;
  948. exports.DefaultCanvasFactory = DefaultCanvasFactory;
  949. let DefaultCMapReaderFactory = _display_utils.DOMCMapReaderFactory;
  950. exports.DefaultCMapReaderFactory = DefaultCMapReaderFactory;
  951. let DefaultStandardFontDataFactory = _display_utils.DOMStandardFontDataFactory;
  952. exports.DefaultStandardFontDataFactory = DefaultStandardFontDataFactory;
  953. if (_is_node.isNodeJS) {
  954. const {
  955. NodeCanvasFactory,
  956. NodeCMapReaderFactory,
  957. NodeStandardFontDataFactory
  958. } = __w_pdfjs_require__(19);
  959. exports.DefaultCanvasFactory = DefaultCanvasFactory = NodeCanvasFactory;
  960. exports.DefaultCMapReaderFactory = DefaultCMapReaderFactory = NodeCMapReaderFactory;
  961. exports.DefaultStandardFontDataFactory = DefaultStandardFontDataFactory = NodeStandardFontDataFactory;
  962. }
  963. let createPDFNetworkStream;
  964. function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) {
  965. createPDFNetworkStream = pdfNetworkStreamFactory;
  966. }
  967. function getDocument(src) {
  968. const task = new PDFDocumentLoadingTask();
  969. let source;
  970. if (typeof src === "string" || src instanceof URL) {
  971. source = {
  972. url: src
  973. };
  974. } else if ((0, _util.isArrayBuffer)(src)) {
  975. source = {
  976. data: src
  977. };
  978. } else if (src instanceof PDFDataRangeTransport) {
  979. source = {
  980. range: src
  981. };
  982. } else {
  983. if (typeof src !== "object") {
  984. throw new Error("Invalid parameter in getDocument, " + "need either string, URL, Uint8Array, or parameter object.");
  985. }
  986. if (!src.url && !src.data && !src.range) {
  987. throw new Error("Invalid parameter object: need either .data, .range or .url");
  988. }
  989. source = src;
  990. }
  991. const params = Object.create(null);
  992. let rangeTransport = null,
  993. worker = null;
  994. for (const key in source) {
  995. const value = source[key];
  996. switch (key) {
  997. case "url":
  998. if (typeof window !== "undefined") {
  999. try {
  1000. params[key] = new URL(value, window.location).href;
  1001. continue;
  1002. } catch (ex) {
  1003. (0, _util.warn)(`Cannot create valid URL: "${ex}".`);
  1004. }
  1005. } else if (typeof value === "string" || value instanceof URL) {
  1006. params[key] = value.toString();
  1007. continue;
  1008. }
  1009. throw new Error("Invalid PDF url data: " + "either string or URL-object is expected in the url property.");
  1010. case "range":
  1011. rangeTransport = value;
  1012. continue;
  1013. case "worker":
  1014. worker = value;
  1015. continue;
  1016. case "data":
  1017. if (_is_node.isNodeJS && typeof Buffer !== "undefined" && value instanceof Buffer) {
  1018. params[key] = new Uint8Array(value);
  1019. } else if (value instanceof Uint8Array) {
  1020. break;
  1021. } else if (typeof value === "string") {
  1022. params[key] = (0, _util.stringToBytes)(value);
  1023. } else if (typeof value === "object" && value !== null && !isNaN(value.length)) {
  1024. params[key] = new Uint8Array(value);
  1025. } else if ((0, _util.isArrayBuffer)(value)) {
  1026. params[key] = new Uint8Array(value);
  1027. } else {
  1028. throw new Error("Invalid PDF binary data: either typed array, " + "string, or array-like object is expected in the data property.");
  1029. }
  1030. continue;
  1031. }
  1032. params[key] = value;
  1033. }
  1034. params.CMapReaderFactory = params.CMapReaderFactory || DefaultCMapReaderFactory;
  1035. params.StandardFontDataFactory = params.StandardFontDataFactory || DefaultStandardFontDataFactory;
  1036. params.ignoreErrors = params.stopAtErrors !== true;
  1037. params.fontExtraProperties = params.fontExtraProperties === true;
  1038. params.pdfBug = params.pdfBug === true;
  1039. params.enableXfa = params.enableXfa === true;
  1040. if (!Number.isInteger(params.rangeChunkSize) || params.rangeChunkSize < 1) {
  1041. params.rangeChunkSize = DEFAULT_RANGE_CHUNK_SIZE;
  1042. }
  1043. if (typeof params.docBaseUrl !== "string" || (0, _display_utils.isDataScheme)(params.docBaseUrl)) {
  1044. params.docBaseUrl = null;
  1045. }
  1046. if (!Number.isInteger(params.maxImageSize) || params.maxImageSize < -1) {
  1047. params.maxImageSize = -1;
  1048. }
  1049. if (typeof params.cMapUrl !== "string") {
  1050. params.cMapUrl = null;
  1051. }
  1052. if (typeof params.standardFontDataUrl !== "string") {
  1053. params.standardFontDataUrl = null;
  1054. }
  1055. if (typeof params.useWorkerFetch !== "boolean") {
  1056. params.useWorkerFetch = params.CMapReaderFactory === _display_utils.DOMCMapReaderFactory && params.StandardFontDataFactory === _display_utils.DOMStandardFontDataFactory;
  1057. }
  1058. if (typeof params.isEvalSupported !== "boolean") {
  1059. params.isEvalSupported = true;
  1060. }
  1061. if (typeof params.disableFontFace !== "boolean") {
  1062. params.disableFontFace = _is_node.isNodeJS;
  1063. }
  1064. if (typeof params.useSystemFonts !== "boolean") {
  1065. params.useSystemFonts = !_is_node.isNodeJS && !params.disableFontFace;
  1066. }
  1067. if (typeof params.ownerDocument !== "object" || params.ownerDocument === null) {
  1068. params.ownerDocument = globalThis.document;
  1069. }
  1070. if (typeof params.disableRange !== "boolean") {
  1071. params.disableRange = false;
  1072. }
  1073. if (typeof params.disableStream !== "boolean") {
  1074. params.disableStream = false;
  1075. }
  1076. if (typeof params.disableAutoFetch !== "boolean") {
  1077. params.disableAutoFetch = false;
  1078. }
  1079. (0, _util.setVerbosityLevel)(params.verbosity);
  1080. if (!worker) {
  1081. const workerParams = {
  1082. verbosity: params.verbosity,
  1083. port: _worker_options.GlobalWorkerOptions.workerPort
  1084. };
  1085. worker = workerParams.port ? PDFWorker.fromPort(workerParams) : new PDFWorker(workerParams);
  1086. task._worker = worker;
  1087. }
  1088. const docId = task.docId;
  1089. worker.promise.then(function () {
  1090. if (task.destroyed) {
  1091. throw new Error("Loading aborted");
  1092. }
  1093. const workerIdPromise = _fetchDocument(worker, params, rangeTransport, docId);
  1094. const networkStreamPromise = new Promise(function (resolve) {
  1095. let networkStream;
  1096. if (rangeTransport) {
  1097. networkStream = new _transport_stream.PDFDataTransportStream({
  1098. length: params.length,
  1099. initialData: params.initialData,
  1100. progressiveDone: params.progressiveDone,
  1101. contentDispositionFilename: params.contentDispositionFilename,
  1102. disableRange: params.disableRange,
  1103. disableStream: params.disableStream
  1104. }, rangeTransport);
  1105. } else if (!params.data) {
  1106. networkStream = createPDFNetworkStream({
  1107. url: params.url,
  1108. length: params.length,
  1109. httpHeaders: params.httpHeaders,
  1110. withCredentials: params.withCredentials,
  1111. rangeChunkSize: params.rangeChunkSize,
  1112. disableRange: params.disableRange,
  1113. disableStream: params.disableStream
  1114. });
  1115. }
  1116. resolve(networkStream);
  1117. });
  1118. return Promise.all([workerIdPromise, networkStreamPromise]).then(function ([workerId, networkStream]) {
  1119. if (task.destroyed) {
  1120. throw new Error("Loading aborted");
  1121. }
  1122. const messageHandler = new _message_handler.MessageHandler(docId, workerId, worker.port);
  1123. const transport = new WorkerTransport(messageHandler, task, networkStream, params);
  1124. task._transport = transport;
  1125. messageHandler.send("Ready", null);
  1126. });
  1127. }).catch(task._capability.reject);
  1128. return task;
  1129. }
  1130. async function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
  1131. if (worker.destroyed) {
  1132. throw new Error("Worker was destroyed");
  1133. }
  1134. if (pdfDataRangeTransport) {
  1135. source.length = pdfDataRangeTransport.length;
  1136. source.initialData = pdfDataRangeTransport.initialData;
  1137. source.progressiveDone = pdfDataRangeTransport.progressiveDone;
  1138. source.contentDispositionFilename = pdfDataRangeTransport.contentDispositionFilename;
  1139. }
  1140. const workerId = await worker.messageHandler.sendWithPromise("GetDocRequest", {
  1141. docId,
  1142. apiVersion: '2.14.305',
  1143. source: {
  1144. data: source.data,
  1145. url: source.url,
  1146. password: source.password,
  1147. disableAutoFetch: source.disableAutoFetch,
  1148. rangeChunkSize: source.rangeChunkSize,
  1149. length: source.length
  1150. },
  1151. maxImageSize: source.maxImageSize,
  1152. disableFontFace: source.disableFontFace,
  1153. docBaseUrl: source.docBaseUrl,
  1154. ignoreErrors: source.ignoreErrors,
  1155. isEvalSupported: source.isEvalSupported,
  1156. fontExtraProperties: source.fontExtraProperties,
  1157. enableXfa: source.enableXfa,
  1158. useSystemFonts: source.useSystemFonts,
  1159. cMapUrl: source.useWorkerFetch ? source.cMapUrl : null,
  1160. standardFontDataUrl: source.useWorkerFetch ? source.standardFontDataUrl : null
  1161. });
  1162. if (worker.destroyed) {
  1163. throw new Error("Worker was destroyed");
  1164. }
  1165. return workerId;
  1166. }
  1167. class PDFDocumentLoadingTask {
  1168. static #docId = 0;
  1169. constructor() {
  1170. this._capability = (0, _util.createPromiseCapability)();
  1171. this._transport = null;
  1172. this._worker = null;
  1173. this.docId = `d${PDFDocumentLoadingTask.#docId++}`;
  1174. this.destroyed = false;
  1175. this.onPassword = null;
  1176. this.onProgress = null;
  1177. this.onUnsupportedFeature = null;
  1178. }
  1179. get promise() {
  1180. return this._capability.promise;
  1181. }
  1182. async destroy() {
  1183. this.destroyed = true;
  1184. await this._transport?.destroy();
  1185. this._transport = null;
  1186. if (this._worker) {
  1187. this._worker.destroy();
  1188. this._worker = null;
  1189. }
  1190. }
  1191. }
  1192. exports.PDFDocumentLoadingTask = PDFDocumentLoadingTask;
  1193. class PDFDataRangeTransport {
  1194. constructor(length, initialData, progressiveDone = false, contentDispositionFilename = null) {
  1195. this.length = length;
  1196. this.initialData = initialData;
  1197. this.progressiveDone = progressiveDone;
  1198. this.contentDispositionFilename = contentDispositionFilename;
  1199. this._rangeListeners = [];
  1200. this._progressListeners = [];
  1201. this._progressiveReadListeners = [];
  1202. this._progressiveDoneListeners = [];
  1203. this._readyCapability = (0, _util.createPromiseCapability)();
  1204. }
  1205. addRangeListener(listener) {
  1206. this._rangeListeners.push(listener);
  1207. }
  1208. addProgressListener(listener) {
  1209. this._progressListeners.push(listener);
  1210. }
  1211. addProgressiveReadListener(listener) {
  1212. this._progressiveReadListeners.push(listener);
  1213. }
  1214. addProgressiveDoneListener(listener) {
  1215. this._progressiveDoneListeners.push(listener);
  1216. }
  1217. onDataRange(begin, chunk) {
  1218. for (const listener of this._rangeListeners) {
  1219. listener(begin, chunk);
  1220. }
  1221. }
  1222. onDataProgress(loaded, total) {
  1223. this._readyCapability.promise.then(() => {
  1224. for (const listener of this._progressListeners) {
  1225. listener(loaded, total);
  1226. }
  1227. });
  1228. }
  1229. onDataProgressiveRead(chunk) {
  1230. this._readyCapability.promise.then(() => {
  1231. for (const listener of this._progressiveReadListeners) {
  1232. listener(chunk);
  1233. }
  1234. });
  1235. }
  1236. onDataProgressiveDone() {
  1237. this._readyCapability.promise.then(() => {
  1238. for (const listener of this._progressiveDoneListeners) {
  1239. listener();
  1240. }
  1241. });
  1242. }
  1243. transportReady() {
  1244. this._readyCapability.resolve();
  1245. }
  1246. requestDataRange(begin, end) {
  1247. (0, _util.unreachable)("Abstract method PDFDataRangeTransport.requestDataRange");
  1248. }
  1249. abort() {}
  1250. }
  1251. exports.PDFDataRangeTransport = PDFDataRangeTransport;
  1252. class PDFDocumentProxy {
  1253. constructor(pdfInfo, transport) {
  1254. this._pdfInfo = pdfInfo;
  1255. this._transport = transport;
  1256. Object.defineProperty(this, "fingerprint", {
  1257. get() {
  1258. (0, _display_utils.deprecated)("`PDFDocumentProxy.fingerprint`, " + "please use `PDFDocumentProxy.fingerprints` instead.");
  1259. return this.fingerprints[0];
  1260. }
  1261. });
  1262. Object.defineProperty(this, "getStats", {
  1263. value: async () => {
  1264. (0, _display_utils.deprecated)("`PDFDocumentProxy.getStats`, " + "please use the `PDFDocumentProxy.stats`-getter instead.");
  1265. return this.stats || {
  1266. streamTypes: {},
  1267. fontTypes: {}
  1268. };
  1269. }
  1270. });
  1271. }
  1272. get annotationStorage() {
  1273. return this._transport.annotationStorage;
  1274. }
  1275. get numPages() {
  1276. return this._pdfInfo.numPages;
  1277. }
  1278. get fingerprints() {
  1279. return this._pdfInfo.fingerprints;
  1280. }
  1281. get stats() {
  1282. return this._transport.stats;
  1283. }
  1284. get isPureXfa() {
  1285. return !!this._transport._htmlForXfa;
  1286. }
  1287. get allXfaHtml() {
  1288. return this._transport._htmlForXfa;
  1289. }
  1290. getPage(pageNumber) {
  1291. return this._transport.getPage(pageNumber);
  1292. }
  1293. getPageIndex(ref) {
  1294. return this._transport.getPageIndex(ref);
  1295. }
  1296. getDestinations() {
  1297. return this._transport.getDestinations();
  1298. }
  1299. getDestination(id) {
  1300. return this._transport.getDestination(id);
  1301. }
  1302. getPageLabels() {
  1303. return this._transport.getPageLabels();
  1304. }
  1305. getPageLayout() {
  1306. return this._transport.getPageLayout();
  1307. }
  1308. getPageMode() {
  1309. return this._transport.getPageMode();
  1310. }
  1311. getViewerPreferences() {
  1312. return this._transport.getViewerPreferences();
  1313. }
  1314. getOpenAction() {
  1315. return this._transport.getOpenAction();
  1316. }
  1317. getAttachments() {
  1318. return this._transport.getAttachments();
  1319. }
  1320. getJavaScript() {
  1321. return this._transport.getJavaScript();
  1322. }
  1323. getJSActions() {
  1324. return this._transport.getDocJSActions();
  1325. }
  1326. getOutline() {
  1327. return this._transport.getOutline();
  1328. }
  1329. getOptionalContentConfig() {
  1330. return this._transport.getOptionalContentConfig();
  1331. }
  1332. getPermissions() {
  1333. return this._transport.getPermissions();
  1334. }
  1335. getMetadata() {
  1336. return this._transport.getMetadata();
  1337. }
  1338. getMarkInfo() {
  1339. return this._transport.getMarkInfo();
  1340. }
  1341. getData() {
  1342. return this._transport.getData();
  1343. }
  1344. getDownloadInfo() {
  1345. return this._transport.downloadInfoCapability.promise;
  1346. }
  1347. cleanup(keepLoadedFonts = false) {
  1348. return this._transport.startCleanup(keepLoadedFonts || this.isPureXfa);
  1349. }
  1350. destroy() {
  1351. return this.loadingTask.destroy();
  1352. }
  1353. get loadingParams() {
  1354. return this._transport.loadingParams;
  1355. }
  1356. get loadingTask() {
  1357. return this._transport.loadingTask;
  1358. }
  1359. saveDocument() {
  1360. if (this._transport.annotationStorage.size <= 0) {
  1361. (0, _display_utils.deprecated)("saveDocument called while `annotationStorage` is empty, " + "please use the getData-method instead.");
  1362. }
  1363. return this._transport.saveDocument();
  1364. }
  1365. getFieldObjects() {
  1366. return this._transport.getFieldObjects();
  1367. }
  1368. hasJSActions() {
  1369. return this._transport.hasJSActions();
  1370. }
  1371. getCalculationOrderIds() {
  1372. return this._transport.getCalculationOrderIds();
  1373. }
  1374. }
  1375. exports.PDFDocumentProxy = PDFDocumentProxy;
  1376. class PDFPageProxy {
  1377. constructor(pageIndex, pageInfo, transport, ownerDocument, pdfBug = false) {
  1378. this._pageIndex = pageIndex;
  1379. this._pageInfo = pageInfo;
  1380. this._ownerDocument = ownerDocument;
  1381. this._transport = transport;
  1382. this._stats = pdfBug ? new _display_utils.StatTimer() : null;
  1383. this._pdfBug = pdfBug;
  1384. this.commonObjs = transport.commonObjs;
  1385. this.objs = new PDFObjects();
  1386. this._bitmaps = new Set();
  1387. this.cleanupAfterRender = false;
  1388. this.pendingCleanup = false;
  1389. this._intentStates = new Map();
  1390. this._annotationPromises = new Map();
  1391. this.destroyed = false;
  1392. }
  1393. get pageNumber() {
  1394. return this._pageIndex + 1;
  1395. }
  1396. get rotate() {
  1397. return this._pageInfo.rotate;
  1398. }
  1399. get ref() {
  1400. return this._pageInfo.ref;
  1401. }
  1402. get userUnit() {
  1403. return this._pageInfo.userUnit;
  1404. }
  1405. get view() {
  1406. return this._pageInfo.view;
  1407. }
  1408. getViewport({
  1409. scale,
  1410. rotation = this.rotate,
  1411. offsetX = 0,
  1412. offsetY = 0,
  1413. dontFlip = false
  1414. } = {}) {
  1415. return new _display_utils.PageViewport({
  1416. viewBox: this.view,
  1417. scale,
  1418. rotation,
  1419. offsetX,
  1420. offsetY,
  1421. dontFlip
  1422. });
  1423. }
  1424. getAnnotations({
  1425. intent = "display"
  1426. } = {}) {
  1427. const intentArgs = this._transport.getRenderingIntent(intent);
  1428. let promise = this._annotationPromises.get(intentArgs.cacheKey);
  1429. if (!promise) {
  1430. promise = this._transport.getAnnotations(this._pageIndex, intentArgs.renderingIntent);
  1431. this._annotationPromises.set(intentArgs.cacheKey, promise);
  1432. promise = promise.then(annotations => {
  1433. for (const annotation of annotations) {
  1434. if (annotation.titleObj !== undefined) {
  1435. Object.defineProperty(annotation, "title", {
  1436. get() {
  1437. (0, _display_utils.deprecated)("`title`-property on annotation, please use `titleObj` instead.");
  1438. return annotation.titleObj.str;
  1439. }
  1440. });
  1441. }
  1442. if (annotation.contentsObj !== undefined) {
  1443. Object.defineProperty(annotation, "contents", {
  1444. get() {
  1445. (0, _display_utils.deprecated)("`contents`-property on annotation, please use `contentsObj` instead.");
  1446. return annotation.contentsObj.str;
  1447. }
  1448. });
  1449. }
  1450. }
  1451. return annotations;
  1452. });
  1453. }
  1454. return promise;
  1455. }
  1456. getJSActions() {
  1457. return this._jsActionsPromise ||= this._transport.getPageJSActions(this._pageIndex);
  1458. }
  1459. async getXfa() {
  1460. return this._transport._htmlForXfa?.children[this._pageIndex] || null;
  1461. }
  1462. render({
  1463. canvasContext,
  1464. viewport,
  1465. intent = "display",
  1466. annotationMode = _util.AnnotationMode.ENABLE,
  1467. transform = null,
  1468. imageLayer = null,
  1469. canvasFactory = null,
  1470. background = null,
  1471. optionalContentConfigPromise = null,
  1472. annotationCanvasMap = null,
  1473. pageColors = null
  1474. }) {
  1475. if (arguments[0]?.renderInteractiveForms !== undefined) {
  1476. (0, _display_utils.deprecated)("render no longer accepts the `renderInteractiveForms`-option, " + "please use the `annotationMode`-option instead.");
  1477. if (arguments[0].renderInteractiveForms === true && annotationMode === _util.AnnotationMode.ENABLE) {
  1478. annotationMode = _util.AnnotationMode.ENABLE_FORMS;
  1479. }
  1480. }
  1481. if (arguments[0]?.includeAnnotationStorage !== undefined) {
  1482. (0, _display_utils.deprecated)("render no longer accepts the `includeAnnotationStorage`-option, " + "please use the `annotationMode`-option instead.");
  1483. if (arguments[0].includeAnnotationStorage === true && annotationMode === _util.AnnotationMode.ENABLE) {
  1484. annotationMode = _util.AnnotationMode.ENABLE_STORAGE;
  1485. }
  1486. }
  1487. if (this._stats) {
  1488. this._stats.time("Overall");
  1489. }
  1490. const intentArgs = this._transport.getRenderingIntent(intent, annotationMode);
  1491. this.pendingCleanup = false;
  1492. if (!optionalContentConfigPromise) {
  1493. optionalContentConfigPromise = this._transport.getOptionalContentConfig();
  1494. }
  1495. let intentState = this._intentStates.get(intentArgs.cacheKey);
  1496. if (!intentState) {
  1497. intentState = Object.create(null);
  1498. this._intentStates.set(intentArgs.cacheKey, intentState);
  1499. }
  1500. if (intentState.streamReaderCancelTimeout) {
  1501. clearTimeout(intentState.streamReaderCancelTimeout);
  1502. intentState.streamReaderCancelTimeout = null;
  1503. }
  1504. const canvasFactoryInstance = canvasFactory || new DefaultCanvasFactory({
  1505. ownerDocument: this._ownerDocument
  1506. });
  1507. const intentPrint = !!(intentArgs.renderingIntent & _util.RenderingIntentFlag.PRINT);
  1508. if (!intentState.displayReadyCapability) {
  1509. intentState.displayReadyCapability = (0, _util.createPromiseCapability)();
  1510. intentState.operatorList = {
  1511. fnArray: [],
  1512. argsArray: [],
  1513. lastChunk: false
  1514. };
  1515. if (this._stats) {
  1516. this._stats.time("Page Request");
  1517. }
  1518. this._pumpOperatorList(intentArgs);
  1519. }
  1520. const complete = error => {
  1521. intentState.renderTasks.delete(internalRenderTask);
  1522. if (this.cleanupAfterRender || intentPrint) {
  1523. this.pendingCleanup = true;
  1524. }
  1525. this._tryCleanup();
  1526. if (error) {
  1527. internalRenderTask.capability.reject(error);
  1528. this._abortOperatorList({
  1529. intentState,
  1530. reason: error instanceof Error ? error : new Error(error)
  1531. });
  1532. } else {
  1533. internalRenderTask.capability.resolve();
  1534. }
  1535. if (this._stats) {
  1536. this._stats.timeEnd("Rendering");
  1537. this._stats.timeEnd("Overall");
  1538. }
  1539. };
  1540. const internalRenderTask = new InternalRenderTask({
  1541. callback: complete,
  1542. params: {
  1543. canvasContext,
  1544. viewport,
  1545. transform,
  1546. imageLayer,
  1547. background
  1548. },
  1549. objs: this.objs,
  1550. commonObjs: this.commonObjs,
  1551. annotationCanvasMap,
  1552. operatorList: intentState.operatorList,
  1553. pageIndex: this._pageIndex,
  1554. canvasFactory: canvasFactoryInstance,
  1555. useRequestAnimationFrame: !intentPrint,
  1556. pdfBug: this._pdfBug,
  1557. pageColors
  1558. });
  1559. (intentState.renderTasks ||= new Set()).add(internalRenderTask);
  1560. const renderTask = internalRenderTask.task;
  1561. Promise.all([intentState.displayReadyCapability.promise, optionalContentConfigPromise]).then(([transparency, optionalContentConfig]) => {
  1562. if (this.pendingCleanup) {
  1563. complete();
  1564. return;
  1565. }
  1566. if (this._stats) {
  1567. this._stats.time("Rendering");
  1568. }
  1569. internalRenderTask.initializeGraphics({
  1570. transparency,
  1571. optionalContentConfig
  1572. });
  1573. internalRenderTask.operatorListChanged();
  1574. }).catch(complete);
  1575. return renderTask;
  1576. }
  1577. getOperatorList({
  1578. intent = "display",
  1579. annotationMode = _util.AnnotationMode.ENABLE
  1580. } = {}) {
  1581. function operatorListChanged() {
  1582. if (intentState.operatorList.lastChunk) {
  1583. intentState.opListReadCapability.resolve(intentState.operatorList);
  1584. intentState.renderTasks.delete(opListTask);
  1585. }
  1586. }
  1587. const intentArgs = this._transport.getRenderingIntent(intent, annotationMode, true);
  1588. let intentState = this._intentStates.get(intentArgs.cacheKey);
  1589. if (!intentState) {
  1590. intentState = Object.create(null);
  1591. this._intentStates.set(intentArgs.cacheKey, intentState);
  1592. }
  1593. let opListTask;
  1594. if (!intentState.opListReadCapability) {
  1595. opListTask = Object.create(null);
  1596. opListTask.operatorListChanged = operatorListChanged;
  1597. intentState.opListReadCapability = (0, _util.createPromiseCapability)();
  1598. (intentState.renderTasks ||= new Set()).add(opListTask);
  1599. intentState.operatorList = {
  1600. fnArray: [],
  1601. argsArray: [],
  1602. lastChunk: false
  1603. };
  1604. if (this._stats) {
  1605. this._stats.time("Page Request");
  1606. }
  1607. this._pumpOperatorList(intentArgs);
  1608. }
  1609. return intentState.opListReadCapability.promise;
  1610. }
  1611. streamTextContent({
  1612. disableCombineTextItems = false,
  1613. includeMarkedContent = false
  1614. } = {}) {
  1615. const TEXT_CONTENT_CHUNK_SIZE = 100;
  1616. return this._transport.messageHandler.sendWithStream("GetTextContent", {
  1617. pageIndex: this._pageIndex,
  1618. combineTextItems: disableCombineTextItems !== true,
  1619. includeMarkedContent: includeMarkedContent === true
  1620. }, {
  1621. highWaterMark: TEXT_CONTENT_CHUNK_SIZE,
  1622. size(textContent) {
  1623. return textContent.items.length;
  1624. }
  1625. });
  1626. }
  1627. getTextContent(params = {}) {
  1628. if (this._transport._htmlForXfa) {
  1629. return this.getXfa().then(xfa => {
  1630. return _xfa_text.XfaText.textContent(xfa);
  1631. });
  1632. }
  1633. const readableStream = this.streamTextContent(params);
  1634. return new Promise(function (resolve, reject) {
  1635. function pump() {
  1636. reader.read().then(function ({
  1637. value,
  1638. done
  1639. }) {
  1640. if (done) {
  1641. resolve(textContent);
  1642. return;
  1643. }
  1644. Object.assign(textContent.styles, value.styles);
  1645. textContent.items.push(...value.items);
  1646. pump();
  1647. }, reject);
  1648. }
  1649. const reader = readableStream.getReader();
  1650. const textContent = {
  1651. items: [],
  1652. styles: Object.create(null)
  1653. };
  1654. pump();
  1655. });
  1656. }
  1657. getStructTree() {
  1658. return this._structTreePromise ||= this._transport.getStructTree(this._pageIndex);
  1659. }
  1660. _destroy() {
  1661. this.destroyed = true;
  1662. const waitOn = [];
  1663. for (const intentState of this._intentStates.values()) {
  1664. this._abortOperatorList({
  1665. intentState,
  1666. reason: new Error("Page was destroyed."),
  1667. force: true
  1668. });
  1669. if (intentState.opListReadCapability) {
  1670. continue;
  1671. }
  1672. for (const internalRenderTask of intentState.renderTasks) {
  1673. waitOn.push(internalRenderTask.completed);
  1674. internalRenderTask.cancel();
  1675. }
  1676. }
  1677. this.objs.clear();
  1678. for (const bitmap of this._bitmaps) {
  1679. bitmap.close();
  1680. }
  1681. this._bitmaps.clear();
  1682. this._annotationPromises.clear();
  1683. this._jsActionsPromise = null;
  1684. this._structTreePromise = null;
  1685. this.pendingCleanup = false;
  1686. return Promise.all(waitOn);
  1687. }
  1688. cleanup(resetStats = false) {
  1689. this.pendingCleanup = true;
  1690. return this._tryCleanup(resetStats);
  1691. }
  1692. _tryCleanup(resetStats = false) {
  1693. if (!this.pendingCleanup) {
  1694. return false;
  1695. }
  1696. for (const {
  1697. renderTasks,
  1698. operatorList
  1699. } of this._intentStates.values()) {
  1700. if (renderTasks.size > 0 || !operatorList.lastChunk) {
  1701. return false;
  1702. }
  1703. }
  1704. this._intentStates.clear();
  1705. this.objs.clear();
  1706. this._annotationPromises.clear();
  1707. this._jsActionsPromise = null;
  1708. this._structTreePromise = null;
  1709. if (resetStats && this._stats) {
  1710. this._stats = new _display_utils.StatTimer();
  1711. }
  1712. for (const bitmap of this._bitmaps) {
  1713. bitmap.close();
  1714. }
  1715. this._bitmaps.clear();
  1716. this.pendingCleanup = false;
  1717. return true;
  1718. }
  1719. _startRenderPage(transparency, cacheKey) {
  1720. const intentState = this._intentStates.get(cacheKey);
  1721. if (!intentState) {
  1722. return;
  1723. }
  1724. if (this._stats) {
  1725. this._stats.timeEnd("Page Request");
  1726. }
  1727. if (intentState.displayReadyCapability) {
  1728. intentState.displayReadyCapability.resolve(transparency);
  1729. }
  1730. }
  1731. _renderPageChunk(operatorListChunk, intentState) {
  1732. for (let i = 0, ii = operatorListChunk.length; i < ii; i++) {
  1733. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  1734. intentState.operatorList.argsArray.push(operatorListChunk.argsArray[i]);
  1735. }
  1736. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  1737. for (const internalRenderTask of intentState.renderTasks) {
  1738. internalRenderTask.operatorListChanged();
  1739. }
  1740. if (operatorListChunk.lastChunk) {
  1741. this._tryCleanup();
  1742. }
  1743. }
  1744. _pumpOperatorList({
  1745. renderingIntent,
  1746. cacheKey
  1747. }) {
  1748. const readableStream = this._transport.messageHandler.sendWithStream("GetOperatorList", {
  1749. pageIndex: this._pageIndex,
  1750. intent: renderingIntent,
  1751. cacheKey,
  1752. annotationStorage: renderingIntent & _util.RenderingIntentFlag.ANNOTATIONS_STORAGE ? this._transport.annotationStorage.serializable : null
  1753. });
  1754. const reader = readableStream.getReader();
  1755. const intentState = this._intentStates.get(cacheKey);
  1756. intentState.streamReader = reader;
  1757. const pump = () => {
  1758. reader.read().then(({
  1759. value,
  1760. done
  1761. }) => {
  1762. if (done) {
  1763. intentState.streamReader = null;
  1764. return;
  1765. }
  1766. if (this._transport.destroyed) {
  1767. return;
  1768. }
  1769. this._renderPageChunk(value, intentState);
  1770. pump();
  1771. }, reason => {
  1772. intentState.streamReader = null;
  1773. if (this._transport.destroyed) {
  1774. return;
  1775. }
  1776. if (intentState.operatorList) {
  1777. intentState.operatorList.lastChunk = true;
  1778. for (const internalRenderTask of intentState.renderTasks) {
  1779. internalRenderTask.operatorListChanged();
  1780. }
  1781. this._tryCleanup();
  1782. }
  1783. if (intentState.displayReadyCapability) {
  1784. intentState.displayReadyCapability.reject(reason);
  1785. } else if (intentState.opListReadCapability) {
  1786. intentState.opListReadCapability.reject(reason);
  1787. } else {
  1788. throw reason;
  1789. }
  1790. });
  1791. };
  1792. pump();
  1793. }
  1794. _abortOperatorList({
  1795. intentState,
  1796. reason,
  1797. force = false
  1798. }) {
  1799. if (!intentState.streamReader) {
  1800. return;
  1801. }
  1802. if (!force) {
  1803. if (intentState.renderTasks.size > 0) {
  1804. return;
  1805. }
  1806. if (reason instanceof _display_utils.RenderingCancelledException) {
  1807. intentState.streamReaderCancelTimeout = setTimeout(() => {
  1808. this._abortOperatorList({
  1809. intentState,
  1810. reason,
  1811. force: true
  1812. });
  1813. intentState.streamReaderCancelTimeout = null;
  1814. }, RENDERING_CANCELLED_TIMEOUT);
  1815. return;
  1816. }
  1817. }
  1818. intentState.streamReader.cancel(new _util.AbortException(reason.message)).catch(() => {});
  1819. intentState.streamReader = null;
  1820. if (this._transport.destroyed) {
  1821. return;
  1822. }
  1823. for (const [curCacheKey, curIntentState] of this._intentStates) {
  1824. if (curIntentState === intentState) {
  1825. this._intentStates.delete(curCacheKey);
  1826. break;
  1827. }
  1828. }
  1829. this.cleanup();
  1830. }
  1831. get stats() {
  1832. return this._stats;
  1833. }
  1834. }
  1835. exports.PDFPageProxy = PDFPageProxy;
  1836. class LoopbackPort {
  1837. constructor() {
  1838. this._listeners = [];
  1839. this._deferred = Promise.resolve();
  1840. }
  1841. postMessage(obj, transfers) {
  1842. const event = {
  1843. data: structuredClone(obj, transfers)
  1844. };
  1845. this._deferred.then(() => {
  1846. for (const listener of this._listeners) {
  1847. listener.call(this, event);
  1848. }
  1849. });
  1850. }
  1851. addEventListener(name, listener) {
  1852. this._listeners.push(listener);
  1853. }
  1854. removeEventListener(name, listener) {
  1855. const i = this._listeners.indexOf(listener);
  1856. this._listeners.splice(i, 1);
  1857. }
  1858. terminate() {
  1859. this._listeners.length = 0;
  1860. }
  1861. }
  1862. exports.LoopbackPort = LoopbackPort;
  1863. const PDFWorkerUtil = {
  1864. isWorkerDisabled: false,
  1865. fallbackWorkerSrc: null,
  1866. fakeWorkerId: 0
  1867. };
  1868. exports.PDFWorkerUtil = PDFWorkerUtil;
  1869. {
  1870. if (_is_node.isNodeJS && typeof require === "function") {
  1871. PDFWorkerUtil.isWorkerDisabled = true;
  1872. PDFWorkerUtil.fallbackWorkerSrc = "./pdf.worker.js";
  1873. } else if (typeof document === "object") {
  1874. const pdfjsFilePath = document?.currentScript?.src;
  1875. if (pdfjsFilePath) {
  1876. PDFWorkerUtil.fallbackWorkerSrc = pdfjsFilePath.replace(/(\.(?:min\.)?js)(\?.*)?$/i, ".worker$1$2");
  1877. }
  1878. }
  1879. PDFWorkerUtil.isSameOrigin = function (baseUrl, otherUrl) {
  1880. let base;
  1881. try {
  1882. base = new URL(baseUrl);
  1883. if (!base.origin || base.origin === "null") {
  1884. return false;
  1885. }
  1886. } catch (e) {
  1887. return false;
  1888. }
  1889. const other = new URL(otherUrl, base);
  1890. return base.origin === other.origin;
  1891. };
  1892. PDFWorkerUtil.createCDNWrapper = function (url) {
  1893. const wrapper = `importScripts("${url}");`;
  1894. return URL.createObjectURL(new Blob([wrapper]));
  1895. };
  1896. }
  1897. class PDFWorker {
  1898. static #workerPorts = new WeakMap();
  1899. constructor({
  1900. name = null,
  1901. port = null,
  1902. verbosity = (0, _util.getVerbosityLevel)()
  1903. } = {}) {
  1904. if (port && PDFWorker.#workerPorts.has(port)) {
  1905. throw new Error("Cannot use more than one PDFWorker per port.");
  1906. }
  1907. this.name = name;
  1908. this.destroyed = false;
  1909. this.verbosity = verbosity;
  1910. this._readyCapability = (0, _util.createPromiseCapability)();
  1911. this._port = null;
  1912. this._webWorker = null;
  1913. this._messageHandler = null;
  1914. if (port) {
  1915. PDFWorker.#workerPorts.set(port, this);
  1916. this._initializeFromPort(port);
  1917. return;
  1918. }
  1919. this._initialize();
  1920. }
  1921. get promise() {
  1922. return this._readyCapability.promise;
  1923. }
  1924. get port() {
  1925. return this._port;
  1926. }
  1927. get messageHandler() {
  1928. return this._messageHandler;
  1929. }
  1930. _initializeFromPort(port) {
  1931. this._port = port;
  1932. this._messageHandler = new _message_handler.MessageHandler("main", "worker", port);
  1933. this._messageHandler.on("ready", function () {});
  1934. this._readyCapability.resolve();
  1935. }
  1936. _initialize() {
  1937. if (typeof Worker !== "undefined" && !PDFWorkerUtil.isWorkerDisabled && !PDFWorker._mainThreadWorkerMessageHandler) {
  1938. let workerSrc = PDFWorker.workerSrc;
  1939. try {
  1940. if (!PDFWorkerUtil.isSameOrigin(window.location.href, workerSrc)) {
  1941. workerSrc = PDFWorkerUtil.createCDNWrapper(new URL(workerSrc, window.location).href);
  1942. }
  1943. const worker = new Worker(workerSrc);
  1944. const messageHandler = new _message_handler.MessageHandler("main", "worker", worker);
  1945. const terminateEarly = () => {
  1946. worker.removeEventListener("error", onWorkerError);
  1947. messageHandler.destroy();
  1948. worker.terminate();
  1949. if (this.destroyed) {
  1950. this._readyCapability.reject(new Error("Worker was destroyed"));
  1951. } else {
  1952. this._setupFakeWorker();
  1953. }
  1954. };
  1955. const onWorkerError = () => {
  1956. if (!this._webWorker) {
  1957. terminateEarly();
  1958. }
  1959. };
  1960. worker.addEventListener("error", onWorkerError);
  1961. messageHandler.on("test", data => {
  1962. worker.removeEventListener("error", onWorkerError);
  1963. if (this.destroyed) {
  1964. terminateEarly();
  1965. return;
  1966. }
  1967. if (data) {
  1968. this._messageHandler = messageHandler;
  1969. this._port = worker;
  1970. this._webWorker = worker;
  1971. this._readyCapability.resolve();
  1972. messageHandler.send("configure", {
  1973. verbosity: this.verbosity
  1974. });
  1975. } else {
  1976. this._setupFakeWorker();
  1977. messageHandler.destroy();
  1978. worker.terminate();
  1979. }
  1980. });
  1981. messageHandler.on("ready", data => {
  1982. worker.removeEventListener("error", onWorkerError);
  1983. if (this.destroyed) {
  1984. terminateEarly();
  1985. return;
  1986. }
  1987. try {
  1988. sendTest();
  1989. } catch (e) {
  1990. this._setupFakeWorker();
  1991. }
  1992. });
  1993. const sendTest = () => {
  1994. const testObj = new Uint8Array();
  1995. messageHandler.send("test", testObj, [testObj.buffer]);
  1996. };
  1997. sendTest();
  1998. return;
  1999. } catch (e) {
  2000. (0, _util.info)("The worker has been disabled.");
  2001. }
  2002. }
  2003. this._setupFakeWorker();
  2004. }
  2005. _setupFakeWorker() {
  2006. if (!PDFWorkerUtil.isWorkerDisabled) {
  2007. (0, _util.warn)("Setting up fake worker.");
  2008. PDFWorkerUtil.isWorkerDisabled = true;
  2009. }
  2010. PDFWorker._setupFakeWorkerGlobal.then(WorkerMessageHandler => {
  2011. if (this.destroyed) {
  2012. this._readyCapability.reject(new Error("Worker was destroyed"));
  2013. return;
  2014. }
  2015. const port = new LoopbackPort();
  2016. this._port = port;
  2017. const id = `fake${PDFWorkerUtil.fakeWorkerId++}`;
  2018. const workerHandler = new _message_handler.MessageHandler(id + "_worker", id, port);
  2019. WorkerMessageHandler.setup(workerHandler, port);
  2020. const messageHandler = new _message_handler.MessageHandler(id, id + "_worker", port);
  2021. this._messageHandler = messageHandler;
  2022. this._readyCapability.resolve();
  2023. messageHandler.send("configure", {
  2024. verbosity: this.verbosity
  2025. });
  2026. }).catch(reason => {
  2027. this._readyCapability.reject(new Error(`Setting up fake worker failed: "${reason.message}".`));
  2028. });
  2029. }
  2030. destroy() {
  2031. this.destroyed = true;
  2032. if (this._webWorker) {
  2033. this._webWorker.terminate();
  2034. this._webWorker = null;
  2035. }
  2036. PDFWorker.#workerPorts.delete(this._port);
  2037. this._port = null;
  2038. if (this._messageHandler) {
  2039. this._messageHandler.destroy();
  2040. this._messageHandler = null;
  2041. }
  2042. }
  2043. static fromPort(params) {
  2044. if (!params?.port) {
  2045. throw new Error("PDFWorker.fromPort - invalid method signature.");
  2046. }
  2047. if (this.#workerPorts.has(params.port)) {
  2048. return this.#workerPorts.get(params.port);
  2049. }
  2050. return new PDFWorker(params);
  2051. }
  2052. static get workerSrc() {
  2053. if (_worker_options.GlobalWorkerOptions.workerSrc) {
  2054. return _worker_options.GlobalWorkerOptions.workerSrc;
  2055. }
  2056. if (PDFWorkerUtil.fallbackWorkerSrc !== null) {
  2057. if (!_is_node.isNodeJS) {
  2058. (0, _display_utils.deprecated)('No "GlobalWorkerOptions.workerSrc" specified.');
  2059. }
  2060. return PDFWorkerUtil.fallbackWorkerSrc;
  2061. }
  2062. throw new Error('No "GlobalWorkerOptions.workerSrc" specified.');
  2063. }
  2064. static get _mainThreadWorkerMessageHandler() {
  2065. try {
  2066. return globalThis.pdfjsWorker?.WorkerMessageHandler || null;
  2067. } catch (ex) {
  2068. return null;
  2069. }
  2070. }
  2071. static get _setupFakeWorkerGlobal() {
  2072. const loader = async () => {
  2073. const mainWorkerMessageHandler = this._mainThreadWorkerMessageHandler;
  2074. if (mainWorkerMessageHandler) {
  2075. return mainWorkerMessageHandler;
  2076. }
  2077. if (_is_node.isNodeJS && typeof require === "function") {
  2078. const worker = eval("require")(this.workerSrc);
  2079. return worker.WorkerMessageHandler;
  2080. }
  2081. await (0, _display_utils.loadScript)(this.workerSrc);
  2082. return window.pdfjsWorker.WorkerMessageHandler;
  2083. };
  2084. return (0, _util.shadow)(this, "_setupFakeWorkerGlobal", loader());
  2085. }
  2086. }
  2087. exports.PDFWorker = PDFWorker;
  2088. {
  2089. PDFWorker.getWorkerSrc = function () {
  2090. (0, _display_utils.deprecated)("`PDFWorker.getWorkerSrc()`, please use `PDFWorker.workerSrc` instead.");
  2091. return this.workerSrc;
  2092. };
  2093. }
  2094. class WorkerTransport {
  2095. #docStats = null;
  2096. #pageCache = new Map();
  2097. #pagePromises = new Map();
  2098. #metadataPromise = null;
  2099. constructor(messageHandler, loadingTask, networkStream, params) {
  2100. this.messageHandler = messageHandler;
  2101. this.loadingTask = loadingTask;
  2102. this.commonObjs = new PDFObjects();
  2103. this.fontLoader = new _font_loader.FontLoader({
  2104. docId: loadingTask.docId,
  2105. onUnsupportedFeature: this._onUnsupportedFeature.bind(this),
  2106. ownerDocument: params.ownerDocument,
  2107. styleElement: params.styleElement
  2108. });
  2109. this._params = params;
  2110. if (!params.useWorkerFetch) {
  2111. this.CMapReaderFactory = new params.CMapReaderFactory({
  2112. baseUrl: params.cMapUrl,
  2113. isCompressed: params.cMapPacked
  2114. });
  2115. this.StandardFontDataFactory = new params.StandardFontDataFactory({
  2116. baseUrl: params.standardFontDataUrl
  2117. });
  2118. }
  2119. this.destroyed = false;
  2120. this.destroyCapability = null;
  2121. this._passwordCapability = null;
  2122. this._networkStream = networkStream;
  2123. this._fullReader = null;
  2124. this._lastProgress = null;
  2125. this.downloadInfoCapability = (0, _util.createPromiseCapability)();
  2126. this.setupMessageHandler();
  2127. }
  2128. get annotationStorage() {
  2129. return (0, _util.shadow)(this, "annotationStorage", new _annotation_storage.AnnotationStorage());
  2130. }
  2131. get stats() {
  2132. return this.#docStats;
  2133. }
  2134. getRenderingIntent(intent, annotationMode = _util.AnnotationMode.ENABLE, isOpList = false) {
  2135. let renderingIntent = _util.RenderingIntentFlag.DISPLAY;
  2136. let annotationHash = "";
  2137. switch (intent) {
  2138. case "any":
  2139. renderingIntent = _util.RenderingIntentFlag.ANY;
  2140. break;
  2141. case "display":
  2142. break;
  2143. case "print":
  2144. renderingIntent = _util.RenderingIntentFlag.PRINT;
  2145. break;
  2146. default:
  2147. (0, _util.warn)(`getRenderingIntent - invalid intent: ${intent}`);
  2148. }
  2149. switch (annotationMode) {
  2150. case _util.AnnotationMode.DISABLE:
  2151. renderingIntent += _util.RenderingIntentFlag.ANNOTATIONS_DISABLE;
  2152. break;
  2153. case _util.AnnotationMode.ENABLE:
  2154. break;
  2155. case _util.AnnotationMode.ENABLE_FORMS:
  2156. renderingIntent += _util.RenderingIntentFlag.ANNOTATIONS_FORMS;
  2157. break;
  2158. case _util.AnnotationMode.ENABLE_STORAGE:
  2159. renderingIntent += _util.RenderingIntentFlag.ANNOTATIONS_STORAGE;
  2160. annotationHash = this.annotationStorage.hash;
  2161. break;
  2162. default:
  2163. (0, _util.warn)(`getRenderingIntent - invalid annotationMode: ${annotationMode}`);
  2164. }
  2165. if (isOpList) {
  2166. renderingIntent += _util.RenderingIntentFlag.OPLIST;
  2167. }
  2168. return {
  2169. renderingIntent,
  2170. cacheKey: `${renderingIntent}_${annotationHash}`
  2171. };
  2172. }
  2173. destroy() {
  2174. if (this.destroyCapability) {
  2175. return this.destroyCapability.promise;
  2176. }
  2177. this.destroyed = true;
  2178. this.destroyCapability = (0, _util.createPromiseCapability)();
  2179. if (this._passwordCapability) {
  2180. this._passwordCapability.reject(new Error("Worker was destroyed during onPassword callback"));
  2181. }
  2182. const waitOn = [];
  2183. for (const page of this.#pageCache.values()) {
  2184. waitOn.push(page._destroy());
  2185. }
  2186. this.#pageCache.clear();
  2187. this.#pagePromises.clear();
  2188. if (this.hasOwnProperty("annotationStorage")) {
  2189. this.annotationStorage.resetModified();
  2190. }
  2191. const terminated = this.messageHandler.sendWithPromise("Terminate", null);
  2192. waitOn.push(terminated);
  2193. Promise.all(waitOn).then(() => {
  2194. this.commonObjs.clear();
  2195. this.fontLoader.clear();
  2196. this.#metadataPromise = null;
  2197. this._getFieldObjectsPromise = null;
  2198. this._hasJSActionsPromise = null;
  2199. if (this._networkStream) {
  2200. this._networkStream.cancelAllRequests(new _util.AbortException("Worker was terminated."));
  2201. }
  2202. if (this.messageHandler) {
  2203. this.messageHandler.destroy();
  2204. this.messageHandler = null;
  2205. }
  2206. this.destroyCapability.resolve();
  2207. }, this.destroyCapability.reject);
  2208. return this.destroyCapability.promise;
  2209. }
  2210. setupMessageHandler() {
  2211. const {
  2212. messageHandler,
  2213. loadingTask
  2214. } = this;
  2215. messageHandler.on("GetReader", (data, sink) => {
  2216. (0, _util.assert)(this._networkStream, "GetReader - no `IPDFStream` instance available.");
  2217. this._fullReader = this._networkStream.getFullReader();
  2218. this._fullReader.onProgress = evt => {
  2219. this._lastProgress = {
  2220. loaded: evt.loaded,
  2221. total: evt.total
  2222. };
  2223. };
  2224. sink.onPull = () => {
  2225. this._fullReader.read().then(function ({
  2226. value,
  2227. done
  2228. }) {
  2229. if (done) {
  2230. sink.close();
  2231. return;
  2232. }
  2233. (0, _util.assert)((0, _util.isArrayBuffer)(value), "GetReader - expected an ArrayBuffer.");
  2234. sink.enqueue(new Uint8Array(value), 1, [value]);
  2235. }).catch(reason => {
  2236. sink.error(reason);
  2237. });
  2238. };
  2239. sink.onCancel = reason => {
  2240. this._fullReader.cancel(reason);
  2241. sink.ready.catch(readyReason => {
  2242. if (this.destroyed) {
  2243. return;
  2244. }
  2245. throw readyReason;
  2246. });
  2247. };
  2248. });
  2249. messageHandler.on("ReaderHeadersReady", data => {
  2250. const headersCapability = (0, _util.createPromiseCapability)();
  2251. const fullReader = this._fullReader;
  2252. fullReader.headersReady.then(() => {
  2253. if (!fullReader.isStreamingSupported || !fullReader.isRangeSupported) {
  2254. if (this._lastProgress) {
  2255. loadingTask.onProgress?.(this._lastProgress);
  2256. }
  2257. fullReader.onProgress = evt => {
  2258. loadingTask.onProgress?.({
  2259. loaded: evt.loaded,
  2260. total: evt.total
  2261. });
  2262. };
  2263. }
  2264. headersCapability.resolve({
  2265. isStreamingSupported: fullReader.isStreamingSupported,
  2266. isRangeSupported: fullReader.isRangeSupported,
  2267. contentLength: fullReader.contentLength
  2268. });
  2269. }, headersCapability.reject);
  2270. return headersCapability.promise;
  2271. });
  2272. messageHandler.on("GetRangeReader", (data, sink) => {
  2273. (0, _util.assert)(this._networkStream, "GetRangeReader - no `IPDFStream` instance available.");
  2274. const rangeReader = this._networkStream.getRangeReader(data.begin, data.end);
  2275. if (!rangeReader) {
  2276. sink.close();
  2277. return;
  2278. }
  2279. sink.onPull = () => {
  2280. rangeReader.read().then(function ({
  2281. value,
  2282. done
  2283. }) {
  2284. if (done) {
  2285. sink.close();
  2286. return;
  2287. }
  2288. (0, _util.assert)((0, _util.isArrayBuffer)(value), "GetRangeReader - expected an ArrayBuffer.");
  2289. sink.enqueue(new Uint8Array(value), 1, [value]);
  2290. }).catch(reason => {
  2291. sink.error(reason);
  2292. });
  2293. };
  2294. sink.onCancel = reason => {
  2295. rangeReader.cancel(reason);
  2296. sink.ready.catch(readyReason => {
  2297. if (this.destroyed) {
  2298. return;
  2299. }
  2300. throw readyReason;
  2301. });
  2302. };
  2303. });
  2304. messageHandler.on("GetDoc", ({
  2305. pdfInfo
  2306. }) => {
  2307. this._numPages = pdfInfo.numPages;
  2308. this._htmlForXfa = pdfInfo.htmlForXfa;
  2309. delete pdfInfo.htmlForXfa;
  2310. loadingTask._capability.resolve(new PDFDocumentProxy(pdfInfo, this));
  2311. });
  2312. messageHandler.on("DocException", function (ex) {
  2313. let reason;
  2314. switch (ex.name) {
  2315. case "PasswordException":
  2316. reason = new _util.PasswordException(ex.message, ex.code);
  2317. break;
  2318. case "InvalidPDFException":
  2319. reason = new _util.InvalidPDFException(ex.message);
  2320. break;
  2321. case "MissingPDFException":
  2322. reason = new _util.MissingPDFException(ex.message);
  2323. break;
  2324. case "UnexpectedResponseException":
  2325. reason = new _util.UnexpectedResponseException(ex.message, ex.status);
  2326. break;
  2327. case "UnknownErrorException":
  2328. reason = new _util.UnknownErrorException(ex.message, ex.details);
  2329. break;
  2330. default:
  2331. (0, _util.unreachable)("DocException - expected a valid Error.");
  2332. }
  2333. loadingTask._capability.reject(reason);
  2334. });
  2335. messageHandler.on("PasswordRequest", exception => {
  2336. this._passwordCapability = (0, _util.createPromiseCapability)();
  2337. if (loadingTask.onPassword) {
  2338. const updatePassword = password => {
  2339. if (password instanceof Error) {
  2340. this._passwordCapability.reject(password);
  2341. } else {
  2342. this._passwordCapability.resolve({
  2343. password
  2344. });
  2345. }
  2346. };
  2347. try {
  2348. loadingTask.onPassword(updatePassword, exception.code);
  2349. } catch (ex) {
  2350. this._passwordCapability.reject(ex);
  2351. }
  2352. } else {
  2353. this._passwordCapability.reject(new _util.PasswordException(exception.message, exception.code));
  2354. }
  2355. return this._passwordCapability.promise;
  2356. });
  2357. messageHandler.on("DataLoaded", data => {
  2358. loadingTask.onProgress?.({
  2359. loaded: data.length,
  2360. total: data.length
  2361. });
  2362. this.downloadInfoCapability.resolve(data);
  2363. });
  2364. messageHandler.on("StartRenderPage", data => {
  2365. if (this.destroyed) {
  2366. return;
  2367. }
  2368. const page = this.#pageCache.get(data.pageIndex);
  2369. page._startRenderPage(data.transparency, data.cacheKey);
  2370. });
  2371. messageHandler.on("commonobj", ([id, type, exportedData]) => {
  2372. if (this.destroyed) {
  2373. return;
  2374. }
  2375. if (this.commonObjs.has(id)) {
  2376. return;
  2377. }
  2378. switch (type) {
  2379. case "Font":
  2380. const params = this._params;
  2381. if ("error" in exportedData) {
  2382. const exportedError = exportedData.error;
  2383. (0, _util.warn)(`Error during font loading: ${exportedError}`);
  2384. this.commonObjs.resolve(id, exportedError);
  2385. break;
  2386. }
  2387. let fontRegistry = null;
  2388. if (params.pdfBug && globalThis.FontInspector?.enabled) {
  2389. fontRegistry = {
  2390. registerFont(font, url) {
  2391. globalThis.FontInspector.fontAdded(font, url);
  2392. }
  2393. };
  2394. }
  2395. const font = new _font_loader.FontFaceObject(exportedData, {
  2396. isEvalSupported: params.isEvalSupported,
  2397. disableFontFace: params.disableFontFace,
  2398. ignoreErrors: params.ignoreErrors,
  2399. onUnsupportedFeature: this._onUnsupportedFeature.bind(this),
  2400. fontRegistry
  2401. });
  2402. this.fontLoader.bind(font).catch(reason => {
  2403. return messageHandler.sendWithPromise("FontFallback", {
  2404. id
  2405. });
  2406. }).finally(() => {
  2407. if (!params.fontExtraProperties && font.data) {
  2408. font.data = null;
  2409. }
  2410. this.commonObjs.resolve(id, font);
  2411. });
  2412. break;
  2413. case "FontPath":
  2414. case "Image":
  2415. this.commonObjs.resolve(id, exportedData);
  2416. break;
  2417. default:
  2418. throw new Error(`Got unknown common object type ${type}`);
  2419. }
  2420. });
  2421. messageHandler.on("obj", ([id, pageIndex, type, imageData]) => {
  2422. if (this.destroyed) {
  2423. return;
  2424. }
  2425. const pageProxy = this.#pageCache.get(pageIndex);
  2426. if (pageProxy.objs.has(id)) {
  2427. return;
  2428. }
  2429. switch (type) {
  2430. case "Image":
  2431. pageProxy.objs.resolve(id, imageData);
  2432. const MAX_IMAGE_SIZE_TO_STORE = 8000000;
  2433. if (imageData) {
  2434. let length;
  2435. if (imageData.bitmap) {
  2436. const {
  2437. bitmap,
  2438. width,
  2439. height
  2440. } = imageData;
  2441. length = width * height * 4;
  2442. pageProxy._bitmaps.add(bitmap);
  2443. } else {
  2444. length = imageData.data?.length || 0;
  2445. }
  2446. if (length > MAX_IMAGE_SIZE_TO_STORE) {
  2447. pageProxy.cleanupAfterRender = true;
  2448. }
  2449. }
  2450. break;
  2451. case "Pattern":
  2452. pageProxy.objs.resolve(id, imageData);
  2453. break;
  2454. default:
  2455. throw new Error(`Got unknown object type ${type}`);
  2456. }
  2457. });
  2458. messageHandler.on("DocProgress", data => {
  2459. if (this.destroyed) {
  2460. return;
  2461. }
  2462. loadingTask.onProgress?.({
  2463. loaded: data.loaded,
  2464. total: data.total
  2465. });
  2466. });
  2467. messageHandler.on("DocStats", data => {
  2468. if (this.destroyed) {
  2469. return;
  2470. }
  2471. this.#docStats = Object.freeze({
  2472. streamTypes: Object.freeze(data.streamTypes),
  2473. fontTypes: Object.freeze(data.fontTypes)
  2474. });
  2475. });
  2476. messageHandler.on("UnsupportedFeature", this._onUnsupportedFeature.bind(this));
  2477. messageHandler.on("FetchBuiltInCMap", data => {
  2478. if (this.destroyed) {
  2479. return Promise.reject(new Error("Worker was destroyed."));
  2480. }
  2481. if (!this.CMapReaderFactory) {
  2482. return Promise.reject(new Error("CMapReaderFactory not initialized, see the `useWorkerFetch` parameter."));
  2483. }
  2484. return this.CMapReaderFactory.fetch(data);
  2485. });
  2486. messageHandler.on("FetchStandardFontData", data => {
  2487. if (this.destroyed) {
  2488. return Promise.reject(new Error("Worker was destroyed."));
  2489. }
  2490. if (!this.StandardFontDataFactory) {
  2491. return Promise.reject(new Error("StandardFontDataFactory not initialized, see the `useWorkerFetch` parameter."));
  2492. }
  2493. return this.StandardFontDataFactory.fetch(data);
  2494. });
  2495. }
  2496. _onUnsupportedFeature({
  2497. featureId
  2498. }) {
  2499. if (this.destroyed) {
  2500. return;
  2501. }
  2502. this.loadingTask.onUnsupportedFeature?.(featureId);
  2503. }
  2504. getData() {
  2505. return this.messageHandler.sendWithPromise("GetData", null);
  2506. }
  2507. getPage(pageNumber) {
  2508. if (!Number.isInteger(pageNumber) || pageNumber <= 0 || pageNumber > this._numPages) {
  2509. return Promise.reject(new Error("Invalid page request."));
  2510. }
  2511. const pageIndex = pageNumber - 1,
  2512. cachedPromise = this.#pagePromises.get(pageIndex);
  2513. if (cachedPromise) {
  2514. return cachedPromise;
  2515. }
  2516. const promise = this.messageHandler.sendWithPromise("GetPage", {
  2517. pageIndex
  2518. }).then(pageInfo => {
  2519. if (this.destroyed) {
  2520. throw new Error("Transport destroyed");
  2521. }
  2522. const page = new PDFPageProxy(pageIndex, pageInfo, this, this._params.ownerDocument, this._params.pdfBug);
  2523. this.#pageCache.set(pageIndex, page);
  2524. return page;
  2525. });
  2526. this.#pagePromises.set(pageIndex, promise);
  2527. return promise;
  2528. }
  2529. getPageIndex(ref) {
  2530. if (typeof ref !== "object" || ref === null || !Number.isInteger(ref.num) || ref.num < 0 || !Number.isInteger(ref.gen) || ref.gen < 0) {
  2531. return Promise.reject(new Error("Invalid pageIndex request."));
  2532. }
  2533. return this.messageHandler.sendWithPromise("GetPageIndex", {
  2534. num: ref.num,
  2535. gen: ref.gen
  2536. });
  2537. }
  2538. getAnnotations(pageIndex, intent) {
  2539. return this.messageHandler.sendWithPromise("GetAnnotations", {
  2540. pageIndex,
  2541. intent
  2542. });
  2543. }
  2544. saveDocument() {
  2545. return this.messageHandler.sendWithPromise("SaveDocument", {
  2546. isPureXfa: !!this._htmlForXfa,
  2547. numPages: this._numPages,
  2548. annotationStorage: this.annotationStorage.serializable,
  2549. filename: this._fullReader?.filename ?? null
  2550. }).finally(() => {
  2551. this.annotationStorage.resetModified();
  2552. });
  2553. }
  2554. getFieldObjects() {
  2555. return this._getFieldObjectsPromise ||= this.messageHandler.sendWithPromise("GetFieldObjects", null);
  2556. }
  2557. hasJSActions() {
  2558. return this._hasJSActionsPromise ||= this.messageHandler.sendWithPromise("HasJSActions", null);
  2559. }
  2560. getCalculationOrderIds() {
  2561. return this.messageHandler.sendWithPromise("GetCalculationOrderIds", null);
  2562. }
  2563. getDestinations() {
  2564. return this.messageHandler.sendWithPromise("GetDestinations", null);
  2565. }
  2566. getDestination(id) {
  2567. if (typeof id !== "string") {
  2568. return Promise.reject(new Error("Invalid destination request."));
  2569. }
  2570. return this.messageHandler.sendWithPromise("GetDestination", {
  2571. id
  2572. });
  2573. }
  2574. getPageLabels() {
  2575. return this.messageHandler.sendWithPromise("GetPageLabels", null);
  2576. }
  2577. getPageLayout() {
  2578. return this.messageHandler.sendWithPromise("GetPageLayout", null);
  2579. }
  2580. getPageMode() {
  2581. return this.messageHandler.sendWithPromise("GetPageMode", null);
  2582. }
  2583. getViewerPreferences() {
  2584. return this.messageHandler.sendWithPromise("GetViewerPreferences", null);
  2585. }
  2586. getOpenAction() {
  2587. return this.messageHandler.sendWithPromise("GetOpenAction", null);
  2588. }
  2589. getAttachments() {
  2590. return this.messageHandler.sendWithPromise("GetAttachments", null);
  2591. }
  2592. getJavaScript() {
  2593. return this.messageHandler.sendWithPromise("GetJavaScript", null);
  2594. }
  2595. getDocJSActions() {
  2596. return this.messageHandler.sendWithPromise("GetDocJSActions", null);
  2597. }
  2598. getPageJSActions(pageIndex) {
  2599. return this.messageHandler.sendWithPromise("GetPageJSActions", {
  2600. pageIndex
  2601. });
  2602. }
  2603. getStructTree(pageIndex) {
  2604. return this.messageHandler.sendWithPromise("GetStructTree", {
  2605. pageIndex
  2606. });
  2607. }
  2608. getOutline() {
  2609. return this.messageHandler.sendWithPromise("GetOutline", null);
  2610. }
  2611. getOptionalContentConfig() {
  2612. return this.messageHandler.sendWithPromise("GetOptionalContentConfig", null).then(results => {
  2613. return new _optional_content_config.OptionalContentConfig(results);
  2614. });
  2615. }
  2616. getPermissions() {
  2617. return this.messageHandler.sendWithPromise("GetPermissions", null);
  2618. }
  2619. getMetadata() {
  2620. return this.#metadataPromise ||= this.messageHandler.sendWithPromise("GetMetadata", null).then(results => {
  2621. return {
  2622. info: results[0],
  2623. metadata: results[1] ? new _metadata.Metadata(results[1]) : null,
  2624. contentDispositionFilename: this._fullReader?.filename ?? null,
  2625. contentLength: this._fullReader?.contentLength ?? null
  2626. };
  2627. });
  2628. }
  2629. getMarkInfo() {
  2630. return this.messageHandler.sendWithPromise("GetMarkInfo", null);
  2631. }
  2632. async startCleanup(keepLoadedFonts = false) {
  2633. await this.messageHandler.sendWithPromise("Cleanup", null);
  2634. if (this.destroyed) {
  2635. return;
  2636. }
  2637. for (const page of this.#pageCache.values()) {
  2638. const cleanupSuccessful = page.cleanup();
  2639. if (!cleanupSuccessful) {
  2640. throw new Error(`startCleanup: Page ${page.pageNumber} is currently rendering.`);
  2641. }
  2642. }
  2643. this.commonObjs.clear();
  2644. if (!keepLoadedFonts) {
  2645. this.fontLoader.clear();
  2646. }
  2647. this.#metadataPromise = null;
  2648. this._getFieldObjectsPromise = null;
  2649. this._hasJSActionsPromise = null;
  2650. }
  2651. get loadingParams() {
  2652. const params = this._params;
  2653. return (0, _util.shadow)(this, "loadingParams", {
  2654. disableAutoFetch: params.disableAutoFetch,
  2655. enableXfa: params.enableXfa
  2656. });
  2657. }
  2658. }
  2659. class PDFObjects {
  2660. #objs = Object.create(null);
  2661. #ensureObj(objId) {
  2662. const obj = this.#objs[objId];
  2663. if (obj) {
  2664. return obj;
  2665. }
  2666. return this.#objs[objId] = {
  2667. capability: (0, _util.createPromiseCapability)(),
  2668. data: null
  2669. };
  2670. }
  2671. get(objId, callback = null) {
  2672. if (callback) {
  2673. const obj = this.#ensureObj(objId);
  2674. obj.capability.promise.then(() => callback(obj.data));
  2675. return null;
  2676. }
  2677. const obj = this.#objs[objId];
  2678. if (!obj?.capability.settled) {
  2679. throw new Error(`Requesting object that isn't resolved yet ${objId}.`);
  2680. }
  2681. return obj.data;
  2682. }
  2683. has(objId) {
  2684. const obj = this.#objs[objId];
  2685. return obj?.capability.settled || false;
  2686. }
  2687. resolve(objId, data = null) {
  2688. const obj = this.#ensureObj(objId);
  2689. obj.data = data;
  2690. obj.capability.resolve();
  2691. }
  2692. clear() {
  2693. this.#objs = Object.create(null);
  2694. }
  2695. }
  2696. class RenderTask {
  2697. constructor(internalRenderTask) {
  2698. this._internalRenderTask = internalRenderTask;
  2699. this.onContinue = null;
  2700. }
  2701. get promise() {
  2702. return this._internalRenderTask.capability.promise;
  2703. }
  2704. cancel() {
  2705. this._internalRenderTask.cancel();
  2706. }
  2707. }
  2708. exports.RenderTask = RenderTask;
  2709. class InternalRenderTask {
  2710. static #canvasInUse = new WeakSet();
  2711. constructor({
  2712. callback,
  2713. params,
  2714. objs,
  2715. commonObjs,
  2716. annotationCanvasMap,
  2717. operatorList,
  2718. pageIndex,
  2719. canvasFactory,
  2720. useRequestAnimationFrame = false,
  2721. pdfBug = false,
  2722. pageColors = null
  2723. }) {
  2724. this.callback = callback;
  2725. this.params = params;
  2726. this.objs = objs;
  2727. this.commonObjs = commonObjs;
  2728. this.annotationCanvasMap = annotationCanvasMap;
  2729. this.operatorListIdx = null;
  2730. this.operatorList = operatorList;
  2731. this._pageIndex = pageIndex;
  2732. this.canvasFactory = canvasFactory;
  2733. this._pdfBug = pdfBug;
  2734. this.pageColors = pageColors;
  2735. this.running = false;
  2736. this.graphicsReadyCallback = null;
  2737. this.graphicsReady = false;
  2738. this._useRequestAnimationFrame = useRequestAnimationFrame === true && typeof window !== "undefined";
  2739. this.cancelled = false;
  2740. this.capability = (0, _util.createPromiseCapability)();
  2741. this.task = new RenderTask(this);
  2742. this._cancelBound = this.cancel.bind(this);
  2743. this._continueBound = this._continue.bind(this);
  2744. this._scheduleNextBound = this._scheduleNext.bind(this);
  2745. this._nextBound = this._next.bind(this);
  2746. this._canvas = params.canvasContext.canvas;
  2747. }
  2748. get completed() {
  2749. return this.capability.promise.catch(function () {});
  2750. }
  2751. initializeGraphics({
  2752. transparency = false,
  2753. optionalContentConfig
  2754. }) {
  2755. if (this.cancelled) {
  2756. return;
  2757. }
  2758. if (this._canvas) {
  2759. if (InternalRenderTask.#canvasInUse.has(this._canvas)) {
  2760. throw new Error("Cannot use the same canvas during multiple render() operations. " + "Use different canvas or ensure previous operations were " + "cancelled or completed.");
  2761. }
  2762. InternalRenderTask.#canvasInUse.add(this._canvas);
  2763. }
  2764. if (this._pdfBug && globalThis.StepperManager?.enabled) {
  2765. this.stepper = globalThis.StepperManager.create(this._pageIndex);
  2766. this.stepper.init(this.operatorList);
  2767. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  2768. }
  2769. const {
  2770. canvasContext,
  2771. viewport,
  2772. transform,
  2773. imageLayer,
  2774. background
  2775. } = this.params;
  2776. this.gfx = new _canvas.CanvasGraphics(canvasContext, this.commonObjs, this.objs, this.canvasFactory, imageLayer, optionalContentConfig, this.annotationCanvasMap, this.pageColors);
  2777. this.gfx.beginDrawing({
  2778. transform,
  2779. viewport,
  2780. transparency,
  2781. background
  2782. });
  2783. this.operatorListIdx = 0;
  2784. this.graphicsReady = true;
  2785. if (this.graphicsReadyCallback) {
  2786. this.graphicsReadyCallback();
  2787. }
  2788. }
  2789. cancel(error = null) {
  2790. this.running = false;
  2791. this.cancelled = true;
  2792. if (this.gfx) {
  2793. this.gfx.endDrawing();
  2794. }
  2795. if (this._canvas) {
  2796. InternalRenderTask.#canvasInUse.delete(this._canvas);
  2797. }
  2798. this.callback(error || new _display_utils.RenderingCancelledException(`Rendering cancelled, page ${this._pageIndex + 1}`, "canvas"));
  2799. }
  2800. operatorListChanged() {
  2801. if (!this.graphicsReady) {
  2802. if (!this.graphicsReadyCallback) {
  2803. this.graphicsReadyCallback = this._continueBound;
  2804. }
  2805. return;
  2806. }
  2807. if (this.stepper) {
  2808. this.stepper.updateOperatorList(this.operatorList);
  2809. }
  2810. if (this.running) {
  2811. return;
  2812. }
  2813. this._continue();
  2814. }
  2815. _continue() {
  2816. this.running = true;
  2817. if (this.cancelled) {
  2818. return;
  2819. }
  2820. if (this.task.onContinue) {
  2821. this.task.onContinue(this._scheduleNextBound);
  2822. } else {
  2823. this._scheduleNext();
  2824. }
  2825. }
  2826. _scheduleNext() {
  2827. if (this._useRequestAnimationFrame) {
  2828. window.requestAnimationFrame(() => {
  2829. this._nextBound().catch(this._cancelBound);
  2830. });
  2831. } else {
  2832. Promise.resolve().then(this._nextBound).catch(this._cancelBound);
  2833. }
  2834. }
  2835. async _next() {
  2836. if (this.cancelled) {
  2837. return;
  2838. }
  2839. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList, this.operatorListIdx, this._continueBound, this.stepper);
  2840. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  2841. this.running = false;
  2842. if (this.operatorList.lastChunk) {
  2843. this.gfx.endDrawing();
  2844. if (this._canvas) {
  2845. InternalRenderTask.#canvasInUse.delete(this._canvas);
  2846. }
  2847. this.callback();
  2848. }
  2849. }
  2850. }
  2851. }
  2852. const version = '2.14.305';
  2853. exports.version = version;
  2854. const build = 'eaaa8b4ad';
  2855. exports.build = build;
  2856. /***/ }),
  2857. /* 5 */
  2858. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  2859. Object.defineProperty(exports, "__esModule", ({
  2860. value: true
  2861. }));
  2862. exports.StatTimer = exports.RenderingCancelledException = exports.PixelsPerInch = exports.PageViewport = exports.PDFDateString = exports.DOMStandardFontDataFactory = exports.DOMSVGFactory = exports.DOMCanvasFactory = exports.DOMCMapReaderFactory = void 0;
  2863. exports.deprecated = deprecated;
  2864. exports.getFilenameFromUrl = getFilenameFromUrl;
  2865. exports.getPdfFilenameFromUrl = getPdfFilenameFromUrl;
  2866. exports.getXfaPageViewport = getXfaPageViewport;
  2867. exports.isDataScheme = isDataScheme;
  2868. exports.isPdfFile = isPdfFile;
  2869. exports.isValidFetchUrl = isValidFetchUrl;
  2870. exports.loadScript = loadScript;
  2871. var _base_factory = __w_pdfjs_require__(6);
  2872. var _util = __w_pdfjs_require__(1);
  2873. const SVG_NS = "http://www.w3.org/2000/svg";
  2874. class PixelsPerInch {
  2875. static CSS = 96.0;
  2876. static PDF = 72.0;
  2877. static PDF_TO_CSS_UNITS = this.CSS / this.PDF;
  2878. }
  2879. exports.PixelsPerInch = PixelsPerInch;
  2880. class DOMCanvasFactory extends _base_factory.BaseCanvasFactory {
  2881. constructor({
  2882. ownerDocument = globalThis.document
  2883. } = {}) {
  2884. super();
  2885. this._document = ownerDocument;
  2886. }
  2887. _createCanvas(width, height) {
  2888. const canvas = this._document.createElement("canvas");
  2889. canvas.width = width;
  2890. canvas.height = height;
  2891. return canvas;
  2892. }
  2893. }
  2894. exports.DOMCanvasFactory = DOMCanvasFactory;
  2895. async function fetchData(url, asTypedArray = false) {
  2896. if (isValidFetchUrl(url, document.baseURI)) {
  2897. const response = await fetch(url);
  2898. if (!response.ok) {
  2899. throw new Error(response.statusText);
  2900. }
  2901. return asTypedArray ? new Uint8Array(await response.arrayBuffer()) : (0, _util.stringToBytes)(await response.text());
  2902. }
  2903. return new Promise((resolve, reject) => {
  2904. const request = new XMLHttpRequest();
  2905. request.open("GET", url, true);
  2906. if (asTypedArray) {
  2907. request.responseType = "arraybuffer";
  2908. }
  2909. request.onreadystatechange = () => {
  2910. if (request.readyState !== XMLHttpRequest.DONE) {
  2911. return;
  2912. }
  2913. if (request.status === 200 || request.status === 0) {
  2914. let data;
  2915. if (asTypedArray && request.response) {
  2916. data = new Uint8Array(request.response);
  2917. } else if (!asTypedArray && request.responseText) {
  2918. data = (0, _util.stringToBytes)(request.responseText);
  2919. }
  2920. if (data) {
  2921. resolve(data);
  2922. return;
  2923. }
  2924. }
  2925. reject(new Error(request.statusText));
  2926. };
  2927. request.send(null);
  2928. });
  2929. }
  2930. class DOMCMapReaderFactory extends _base_factory.BaseCMapReaderFactory {
  2931. _fetchData(url, compressionType) {
  2932. return fetchData(url, this.isCompressed).then(data => {
  2933. return {
  2934. cMapData: data,
  2935. compressionType
  2936. };
  2937. });
  2938. }
  2939. }
  2940. exports.DOMCMapReaderFactory = DOMCMapReaderFactory;
  2941. class DOMStandardFontDataFactory extends _base_factory.BaseStandardFontDataFactory {
  2942. _fetchData(url) {
  2943. return fetchData(url, true);
  2944. }
  2945. }
  2946. exports.DOMStandardFontDataFactory = DOMStandardFontDataFactory;
  2947. class DOMSVGFactory extends _base_factory.BaseSVGFactory {
  2948. _createSVG(type) {
  2949. return document.createElementNS(SVG_NS, type);
  2950. }
  2951. }
  2952. exports.DOMSVGFactory = DOMSVGFactory;
  2953. class PageViewport {
  2954. constructor({
  2955. viewBox,
  2956. scale,
  2957. rotation,
  2958. offsetX = 0,
  2959. offsetY = 0,
  2960. dontFlip = false
  2961. }) {
  2962. this.viewBox = viewBox;
  2963. this.scale = scale;
  2964. this.rotation = rotation;
  2965. this.offsetX = offsetX;
  2966. this.offsetY = offsetY;
  2967. const centerX = (viewBox[2] + viewBox[0]) / 2;
  2968. const centerY = (viewBox[3] + viewBox[1]) / 2;
  2969. let rotateA, rotateB, rotateC, rotateD;
  2970. rotation %= 360;
  2971. if (rotation < 0) {
  2972. rotation += 360;
  2973. }
  2974. switch (rotation) {
  2975. case 180:
  2976. rotateA = -1;
  2977. rotateB = 0;
  2978. rotateC = 0;
  2979. rotateD = 1;
  2980. break;
  2981. case 90:
  2982. rotateA = 0;
  2983. rotateB = 1;
  2984. rotateC = 1;
  2985. rotateD = 0;
  2986. break;
  2987. case 270:
  2988. rotateA = 0;
  2989. rotateB = -1;
  2990. rotateC = -1;
  2991. rotateD = 0;
  2992. break;
  2993. case 0:
  2994. rotateA = 1;
  2995. rotateB = 0;
  2996. rotateC = 0;
  2997. rotateD = -1;
  2998. break;
  2999. default:
  3000. throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.");
  3001. }
  3002. if (dontFlip) {
  3003. rotateC = -rotateC;
  3004. rotateD = -rotateD;
  3005. }
  3006. let offsetCanvasX, offsetCanvasY;
  3007. let width, height;
  3008. if (rotateA === 0) {
  3009. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  3010. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  3011. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  3012. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  3013. } else {
  3014. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  3015. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  3016. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  3017. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  3018. }
  3019. this.transform = [rotateA * scale, rotateB * scale, rotateC * scale, rotateD * scale, offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY, offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY];
  3020. this.width = width;
  3021. this.height = height;
  3022. }
  3023. clone({
  3024. scale = this.scale,
  3025. rotation = this.rotation,
  3026. offsetX = this.offsetX,
  3027. offsetY = this.offsetY,
  3028. dontFlip = false
  3029. } = {}) {
  3030. return new PageViewport({
  3031. viewBox: this.viewBox.slice(),
  3032. scale,
  3033. rotation,
  3034. offsetX,
  3035. offsetY,
  3036. dontFlip
  3037. });
  3038. }
  3039. convertToViewportPoint(x, y) {
  3040. return _util.Util.applyTransform([x, y], this.transform);
  3041. }
  3042. convertToViewportRectangle(rect) {
  3043. const topLeft = _util.Util.applyTransform([rect[0], rect[1]], this.transform);
  3044. const bottomRight = _util.Util.applyTransform([rect[2], rect[3]], this.transform);
  3045. return [topLeft[0], topLeft[1], bottomRight[0], bottomRight[1]];
  3046. }
  3047. convertToPdfPoint(x, y) {
  3048. return _util.Util.applyInverseTransform([x, y], this.transform);
  3049. }
  3050. }
  3051. exports.PageViewport = PageViewport;
  3052. class RenderingCancelledException extends _util.BaseException {
  3053. constructor(msg, type) {
  3054. super(msg, "RenderingCancelledException");
  3055. this.type = type;
  3056. }
  3057. }
  3058. exports.RenderingCancelledException = RenderingCancelledException;
  3059. function isDataScheme(url) {
  3060. const ii = url.length;
  3061. let i = 0;
  3062. while (i < ii && url[i].trim() === "") {
  3063. i++;
  3064. }
  3065. return url.substring(i, i + 5).toLowerCase() === "data:";
  3066. }
  3067. function isPdfFile(filename) {
  3068. return typeof filename === "string" && /\.pdf$/i.test(filename);
  3069. }
  3070. function getFilenameFromUrl(url) {
  3071. const anchor = url.indexOf("#");
  3072. const query = url.indexOf("?");
  3073. const end = Math.min(anchor > 0 ? anchor : url.length, query > 0 ? query : url.length);
  3074. return url.substring(url.lastIndexOf("/", end) + 1, end);
  3075. }
  3076. function getPdfFilenameFromUrl(url, defaultFilename = "document.pdf") {
  3077. if (typeof url !== "string") {
  3078. return defaultFilename;
  3079. }
  3080. if (isDataScheme(url)) {
  3081. (0, _util.warn)('getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.');
  3082. return defaultFilename;
  3083. }
  3084. const reURI = /^(?:(?:[^:]+:)?\/\/[^/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
  3085. const reFilename = /[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
  3086. const splitURI = reURI.exec(url);
  3087. let suggestedFilename = reFilename.exec(splitURI[1]) || reFilename.exec(splitURI[2]) || reFilename.exec(splitURI[3]);
  3088. if (suggestedFilename) {
  3089. suggestedFilename = suggestedFilename[0];
  3090. if (suggestedFilename.includes("%")) {
  3091. try {
  3092. suggestedFilename = reFilename.exec(decodeURIComponent(suggestedFilename))[0];
  3093. } catch (ex) {}
  3094. }
  3095. }
  3096. return suggestedFilename || defaultFilename;
  3097. }
  3098. class StatTimer {
  3099. constructor() {
  3100. this.started = Object.create(null);
  3101. this.times = [];
  3102. }
  3103. time(name) {
  3104. if (name in this.started) {
  3105. (0, _util.warn)(`Timer is already running for ${name}`);
  3106. }
  3107. this.started[name] = Date.now();
  3108. }
  3109. timeEnd(name) {
  3110. if (!(name in this.started)) {
  3111. (0, _util.warn)(`Timer has not been started for ${name}`);
  3112. }
  3113. this.times.push({
  3114. name,
  3115. start: this.started[name],
  3116. end: Date.now()
  3117. });
  3118. delete this.started[name];
  3119. }
  3120. toString() {
  3121. const outBuf = [];
  3122. let longest = 0;
  3123. for (const time of this.times) {
  3124. const name = time.name;
  3125. if (name.length > longest) {
  3126. longest = name.length;
  3127. }
  3128. }
  3129. for (const time of this.times) {
  3130. const duration = time.end - time.start;
  3131. outBuf.push(`${time.name.padEnd(longest)} ${duration}ms\n`);
  3132. }
  3133. return outBuf.join("");
  3134. }
  3135. }
  3136. exports.StatTimer = StatTimer;
  3137. function isValidFetchUrl(url, baseUrl) {
  3138. try {
  3139. const {
  3140. protocol
  3141. } = baseUrl ? new URL(url, baseUrl) : new URL(url);
  3142. return protocol === "http:" || protocol === "https:";
  3143. } catch (ex) {
  3144. return false;
  3145. }
  3146. }
  3147. function loadScript(src, removeScriptElement = false) {
  3148. return new Promise((resolve, reject) => {
  3149. const script = document.createElement("script");
  3150. script.src = src;
  3151. script.onload = function (evt) {
  3152. if (removeScriptElement) {
  3153. script.remove();
  3154. }
  3155. resolve(evt);
  3156. };
  3157. script.onerror = function () {
  3158. reject(new Error(`Cannot load script at: ${script.src}`));
  3159. };
  3160. (document.head || document.documentElement).appendChild(script);
  3161. });
  3162. }
  3163. function deprecated(details) {
  3164. console.log("Deprecated API usage: " + details);
  3165. }
  3166. let pdfDateStringRegex;
  3167. class PDFDateString {
  3168. static toDateObject(input) {
  3169. if (!input || typeof input !== "string") {
  3170. return null;
  3171. }
  3172. if (!pdfDateStringRegex) {
  3173. pdfDateStringRegex = new RegExp("^D:" + "(\\d{4})" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "([Z|+|-])?" + "(\\d{2})?" + "'?" + "(\\d{2})?" + "'?");
  3174. }
  3175. const matches = pdfDateStringRegex.exec(input);
  3176. if (!matches) {
  3177. return null;
  3178. }
  3179. const year = parseInt(matches[1], 10);
  3180. let month = parseInt(matches[2], 10);
  3181. month = month >= 1 && month <= 12 ? month - 1 : 0;
  3182. let day = parseInt(matches[3], 10);
  3183. day = day >= 1 && day <= 31 ? day : 1;
  3184. let hour = parseInt(matches[4], 10);
  3185. hour = hour >= 0 && hour <= 23 ? hour : 0;
  3186. let minute = parseInt(matches[5], 10);
  3187. minute = minute >= 0 && minute <= 59 ? minute : 0;
  3188. let second = parseInt(matches[6], 10);
  3189. second = second >= 0 && second <= 59 ? second : 0;
  3190. const universalTimeRelation = matches[7] || "Z";
  3191. let offsetHour = parseInt(matches[8], 10);
  3192. offsetHour = offsetHour >= 0 && offsetHour <= 23 ? offsetHour : 0;
  3193. let offsetMinute = parseInt(matches[9], 10) || 0;
  3194. offsetMinute = offsetMinute >= 0 && offsetMinute <= 59 ? offsetMinute : 0;
  3195. if (universalTimeRelation === "-") {
  3196. hour += offsetHour;
  3197. minute += offsetMinute;
  3198. } else if (universalTimeRelation === "+") {
  3199. hour -= offsetHour;
  3200. minute -= offsetMinute;
  3201. }
  3202. return new Date(Date.UTC(year, month, day, hour, minute, second));
  3203. }
  3204. }
  3205. exports.PDFDateString = PDFDateString;
  3206. function getXfaPageViewport(xfaPage, {
  3207. scale = 1,
  3208. rotation = 0
  3209. }) {
  3210. const {
  3211. width,
  3212. height
  3213. } = xfaPage.attributes.style;
  3214. const viewBox = [0, 0, parseInt(width), parseInt(height)];
  3215. return new PageViewport({
  3216. viewBox,
  3217. scale,
  3218. rotation
  3219. });
  3220. }
  3221. /***/ }),
  3222. /* 6 */
  3223. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3224. Object.defineProperty(exports, "__esModule", ({
  3225. value: true
  3226. }));
  3227. exports.BaseStandardFontDataFactory = exports.BaseSVGFactory = exports.BaseCanvasFactory = exports.BaseCMapReaderFactory = void 0;
  3228. var _util = __w_pdfjs_require__(1);
  3229. class BaseCanvasFactory {
  3230. constructor() {
  3231. if (this.constructor === BaseCanvasFactory) {
  3232. (0, _util.unreachable)("Cannot initialize BaseCanvasFactory.");
  3233. }
  3234. }
  3235. create(width, height) {
  3236. if (width <= 0 || height <= 0) {
  3237. throw new Error("Invalid canvas size");
  3238. }
  3239. const canvas = this._createCanvas(width, height);
  3240. return {
  3241. canvas,
  3242. context: canvas.getContext("2d")
  3243. };
  3244. }
  3245. reset(canvasAndContext, width, height) {
  3246. if (!canvasAndContext.canvas) {
  3247. throw new Error("Canvas is not specified");
  3248. }
  3249. if (width <= 0 || height <= 0) {
  3250. throw new Error("Invalid canvas size");
  3251. }
  3252. canvasAndContext.canvas.width = width;
  3253. canvasAndContext.canvas.height = height;
  3254. }
  3255. destroy(canvasAndContext) {
  3256. if (!canvasAndContext.canvas) {
  3257. throw new Error("Canvas is not specified");
  3258. }
  3259. canvasAndContext.canvas.width = 0;
  3260. canvasAndContext.canvas.height = 0;
  3261. canvasAndContext.canvas = null;
  3262. canvasAndContext.context = null;
  3263. }
  3264. _createCanvas(width, height) {
  3265. (0, _util.unreachable)("Abstract method `_createCanvas` called.");
  3266. }
  3267. }
  3268. exports.BaseCanvasFactory = BaseCanvasFactory;
  3269. class BaseCMapReaderFactory {
  3270. constructor({
  3271. baseUrl = null,
  3272. isCompressed = false
  3273. }) {
  3274. if (this.constructor === BaseCMapReaderFactory) {
  3275. (0, _util.unreachable)("Cannot initialize BaseCMapReaderFactory.");
  3276. }
  3277. this.baseUrl = baseUrl;
  3278. this.isCompressed = isCompressed;
  3279. }
  3280. async fetch({
  3281. name
  3282. }) {
  3283. if (!this.baseUrl) {
  3284. throw new Error('The CMap "baseUrl" parameter must be specified, ensure that ' + 'the "cMapUrl" and "cMapPacked" API parameters are provided.');
  3285. }
  3286. if (!name) {
  3287. throw new Error("CMap name must be specified.");
  3288. }
  3289. const url = this.baseUrl + name + (this.isCompressed ? ".bcmap" : "");
  3290. const compressionType = this.isCompressed ? _util.CMapCompressionType.BINARY : _util.CMapCompressionType.NONE;
  3291. return this._fetchData(url, compressionType).catch(reason => {
  3292. throw new Error(`Unable to load ${this.isCompressed ? "binary " : ""}CMap at: ${url}`);
  3293. });
  3294. }
  3295. _fetchData(url, compressionType) {
  3296. (0, _util.unreachable)("Abstract method `_fetchData` called.");
  3297. }
  3298. }
  3299. exports.BaseCMapReaderFactory = BaseCMapReaderFactory;
  3300. class BaseStandardFontDataFactory {
  3301. constructor({
  3302. baseUrl = null
  3303. }) {
  3304. if (this.constructor === BaseStandardFontDataFactory) {
  3305. (0, _util.unreachable)("Cannot initialize BaseStandardFontDataFactory.");
  3306. }
  3307. this.baseUrl = baseUrl;
  3308. }
  3309. async fetch({
  3310. filename
  3311. }) {
  3312. if (!this.baseUrl) {
  3313. throw new Error('The standard font "baseUrl" parameter must be specified, ensure that ' + 'the "standardFontDataUrl" API parameter is provided.');
  3314. }
  3315. if (!filename) {
  3316. throw new Error("Font filename must be specified.");
  3317. }
  3318. const url = `${this.baseUrl}${filename}`;
  3319. return this._fetchData(url).catch(reason => {
  3320. throw new Error(`Unable to load font data at: ${url}`);
  3321. });
  3322. }
  3323. _fetchData(url) {
  3324. (0, _util.unreachable)("Abstract method `_fetchData` called.");
  3325. }
  3326. }
  3327. exports.BaseStandardFontDataFactory = BaseStandardFontDataFactory;
  3328. class BaseSVGFactory {
  3329. constructor() {
  3330. if (this.constructor === BaseSVGFactory) {
  3331. (0, _util.unreachable)("Cannot initialize BaseSVGFactory.");
  3332. }
  3333. }
  3334. create(width, height) {
  3335. if (width <= 0 || height <= 0) {
  3336. throw new Error("Invalid SVG dimensions");
  3337. }
  3338. const svg = this._createSVG("svg:svg");
  3339. svg.setAttribute("version", "1.1");
  3340. svg.setAttribute("width", `${width}px`);
  3341. svg.setAttribute("height", `${height}px`);
  3342. svg.setAttribute("preserveAspectRatio", "none");
  3343. svg.setAttribute("viewBox", `0 0 ${width} ${height}`);
  3344. return svg;
  3345. }
  3346. createElement(type) {
  3347. if (typeof type !== "string") {
  3348. throw new Error("Invalid SVG element type");
  3349. }
  3350. return this._createSVG(type);
  3351. }
  3352. _createSVG(type) {
  3353. (0, _util.unreachable)("Abstract method `_createSVG` called.");
  3354. }
  3355. }
  3356. exports.BaseSVGFactory = BaseSVGFactory;
  3357. /***/ }),
  3358. /* 7 */
  3359. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3360. Object.defineProperty(exports, "__esModule", ({
  3361. value: true
  3362. }));
  3363. exports.FontLoader = exports.FontFaceObject = void 0;
  3364. var _util = __w_pdfjs_require__(1);
  3365. class BaseFontLoader {
  3366. constructor({
  3367. docId,
  3368. onUnsupportedFeature,
  3369. ownerDocument = globalThis.document,
  3370. styleElement = null
  3371. }) {
  3372. if (this.constructor === BaseFontLoader) {
  3373. (0, _util.unreachable)("Cannot initialize BaseFontLoader.");
  3374. }
  3375. this.docId = docId;
  3376. this._onUnsupportedFeature = onUnsupportedFeature;
  3377. this._document = ownerDocument;
  3378. this.nativeFontFaces = [];
  3379. this.styleElement = null;
  3380. }
  3381. addNativeFontFace(nativeFontFace) {
  3382. this.nativeFontFaces.push(nativeFontFace);
  3383. this._document.fonts.add(nativeFontFace);
  3384. }
  3385. insertRule(rule) {
  3386. let styleElement = this.styleElement;
  3387. if (!styleElement) {
  3388. styleElement = this.styleElement = this._document.createElement("style");
  3389. styleElement.id = `PDFJS_FONT_STYLE_TAG_${this.docId}`;
  3390. this._document.documentElement.getElementsByTagName("head")[0].appendChild(styleElement);
  3391. }
  3392. const styleSheet = styleElement.sheet;
  3393. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  3394. }
  3395. clear() {
  3396. for (const nativeFontFace of this.nativeFontFaces) {
  3397. this._document.fonts.delete(nativeFontFace);
  3398. }
  3399. this.nativeFontFaces.length = 0;
  3400. if (this.styleElement) {
  3401. this.styleElement.remove();
  3402. this.styleElement = null;
  3403. }
  3404. }
  3405. async bind(font) {
  3406. if (font.attached || font.missingFile) {
  3407. return;
  3408. }
  3409. font.attached = true;
  3410. if (this.isFontLoadingAPISupported) {
  3411. const nativeFontFace = font.createNativeFontFace();
  3412. if (nativeFontFace) {
  3413. this.addNativeFontFace(nativeFontFace);
  3414. try {
  3415. await nativeFontFace.loaded;
  3416. } catch (ex) {
  3417. this._onUnsupportedFeature({
  3418. featureId: _util.UNSUPPORTED_FEATURES.errorFontLoadNative
  3419. });
  3420. (0, _util.warn)(`Failed to load font '${nativeFontFace.family}': '${ex}'.`);
  3421. font.disableFontFace = true;
  3422. throw ex;
  3423. }
  3424. }
  3425. return;
  3426. }
  3427. const rule = font.createFontFaceRule();
  3428. if (rule) {
  3429. this.insertRule(rule);
  3430. if (this.isSyncFontLoadingSupported) {
  3431. return;
  3432. }
  3433. await new Promise(resolve => {
  3434. const request = this._queueLoadingCallback(resolve);
  3435. this._prepareFontLoadEvent([rule], [font], request);
  3436. });
  3437. }
  3438. }
  3439. _queueLoadingCallback(callback) {
  3440. (0, _util.unreachable)("Abstract method `_queueLoadingCallback`.");
  3441. }
  3442. get isFontLoadingAPISupported() {
  3443. const hasFonts = !!this._document?.fonts;
  3444. return (0, _util.shadow)(this, "isFontLoadingAPISupported", hasFonts);
  3445. }
  3446. get isSyncFontLoadingSupported() {
  3447. (0, _util.unreachable)("Abstract method `isSyncFontLoadingSupported`.");
  3448. }
  3449. get _loadTestFont() {
  3450. (0, _util.unreachable)("Abstract method `_loadTestFont`.");
  3451. }
  3452. _prepareFontLoadEvent(rules, fontsToLoad, request) {
  3453. (0, _util.unreachable)("Abstract method `_prepareFontLoadEvent`.");
  3454. }
  3455. }
  3456. let FontLoader;
  3457. exports.FontLoader = FontLoader;
  3458. {
  3459. exports.FontLoader = FontLoader = class GenericFontLoader extends BaseFontLoader {
  3460. constructor(params) {
  3461. super(params);
  3462. this.loadingContext = {
  3463. requests: [],
  3464. nextRequestId: 0
  3465. };
  3466. this.loadTestFontId = 0;
  3467. }
  3468. get isSyncFontLoadingSupported() {
  3469. let supported = false;
  3470. if (typeof navigator === "undefined") {
  3471. supported = true;
  3472. } else {
  3473. const m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(navigator.userAgent);
  3474. if (m?.[1] >= 14) {
  3475. supported = true;
  3476. }
  3477. }
  3478. return (0, _util.shadow)(this, "isSyncFontLoadingSupported", supported);
  3479. }
  3480. _queueLoadingCallback(callback) {
  3481. function completeRequest() {
  3482. (0, _util.assert)(!request.done, "completeRequest() cannot be called twice.");
  3483. request.done = true;
  3484. while (context.requests.length > 0 && context.requests[0].done) {
  3485. const otherRequest = context.requests.shift();
  3486. setTimeout(otherRequest.callback, 0);
  3487. }
  3488. }
  3489. const context = this.loadingContext;
  3490. const request = {
  3491. id: `pdfjs-font-loading-${context.nextRequestId++}`,
  3492. done: false,
  3493. complete: completeRequest,
  3494. callback
  3495. };
  3496. context.requests.push(request);
  3497. return request;
  3498. }
  3499. get _loadTestFont() {
  3500. const getLoadTestFont = function () {
  3501. return atob("T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQA" + "FQAABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAA" + "ALwAAAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgA" + "AAAGbmFtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1" + "AAsD6AAAAADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD" + "6AAAAAAD6AABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACM" + "AooCvAAAAeAAMQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4D" + "IP84AFoDIQAAAAAAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAA" + "AAEAAQAAAAEAAAAAAAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUA" + "AQAAAAEAAAAAAAYAAQAAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgAB" + "AAMAAQQJAAMAAgABAAMAAQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABY" + "AAAAAAAAAwAAAAMAAAAcAAEAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAA" + "AC7////TAAEAAAAAAAABBgAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAA" + "AAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgcA/gXBIwMAYuL+nz5tQXkD5j3CBLnEQAC" + "AQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYAAABAQAADwACAQEEE/t3" + "Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQAAAAAAAABAAAAAMmJbzEAAAAAzgTj" + "FQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAgABAAAAAAAAAAAD6AAAAAAAAA==");
  3502. };
  3503. return (0, _util.shadow)(this, "_loadTestFont", getLoadTestFont());
  3504. }
  3505. _prepareFontLoadEvent(rules, fonts, request) {
  3506. function int32(data, offset) {
  3507. return data.charCodeAt(offset) << 24 | data.charCodeAt(offset + 1) << 16 | data.charCodeAt(offset + 2) << 8 | data.charCodeAt(offset + 3) & 0xff;
  3508. }
  3509. function spliceString(s, offset, remove, insert) {
  3510. const chunk1 = s.substring(0, offset);
  3511. const chunk2 = s.substring(offset + remove);
  3512. return chunk1 + insert + chunk2;
  3513. }
  3514. let i, ii;
  3515. const canvas = this._document.createElement("canvas");
  3516. canvas.width = 1;
  3517. canvas.height = 1;
  3518. const ctx = canvas.getContext("2d");
  3519. let called = 0;
  3520. function isFontReady(name, callback) {
  3521. called++;
  3522. if (called > 30) {
  3523. (0, _util.warn)("Load test font never loaded.");
  3524. callback();
  3525. return;
  3526. }
  3527. ctx.font = "30px " + name;
  3528. ctx.fillText(".", 0, 20);
  3529. const imageData = ctx.getImageData(0, 0, 1, 1);
  3530. if (imageData.data[3] > 0) {
  3531. callback();
  3532. return;
  3533. }
  3534. setTimeout(isFontReady.bind(null, name, callback));
  3535. }
  3536. const loadTestFontId = `lt${Date.now()}${this.loadTestFontId++}`;
  3537. let data = this._loadTestFont;
  3538. const COMMENT_OFFSET = 976;
  3539. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length, loadTestFontId);
  3540. const CFF_CHECKSUM_OFFSET = 16;
  3541. const XXXX_VALUE = 0x58585858;
  3542. let checksum = int32(data, CFF_CHECKSUM_OFFSET);
  3543. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  3544. checksum = checksum - XXXX_VALUE + int32(loadTestFontId, i) | 0;
  3545. }
  3546. if (i < loadTestFontId.length) {
  3547. checksum = checksum - XXXX_VALUE + int32(loadTestFontId + "XXX", i) | 0;
  3548. }
  3549. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, (0, _util.string32)(checksum));
  3550. const url = `url(data:font/opentype;base64,${btoa(data)});`;
  3551. const rule = `@font-face {font-family:"${loadTestFontId}";src:${url}}`;
  3552. this.insertRule(rule);
  3553. const names = [];
  3554. for (const font of fonts) {
  3555. names.push(font.loadedName);
  3556. }
  3557. names.push(loadTestFontId);
  3558. const div = this._document.createElement("div");
  3559. div.style.visibility = "hidden";
  3560. div.style.width = div.style.height = "10px";
  3561. div.style.position = "absolute";
  3562. div.style.top = div.style.left = "0px";
  3563. for (const name of names) {
  3564. const span = this._document.createElement("span");
  3565. span.textContent = "Hi";
  3566. span.style.fontFamily = name;
  3567. div.appendChild(span);
  3568. }
  3569. this._document.body.appendChild(div);
  3570. isFontReady(loadTestFontId, () => {
  3571. div.remove();
  3572. request.complete();
  3573. });
  3574. }
  3575. };
  3576. }
  3577. class FontFaceObject {
  3578. constructor(translatedData, {
  3579. isEvalSupported = true,
  3580. disableFontFace = false,
  3581. ignoreErrors = false,
  3582. onUnsupportedFeature,
  3583. fontRegistry = null
  3584. }) {
  3585. this.compiledGlyphs = Object.create(null);
  3586. for (const i in translatedData) {
  3587. this[i] = translatedData[i];
  3588. }
  3589. this.isEvalSupported = isEvalSupported !== false;
  3590. this.disableFontFace = disableFontFace === true;
  3591. this.ignoreErrors = ignoreErrors === true;
  3592. this._onUnsupportedFeature = onUnsupportedFeature;
  3593. this.fontRegistry = fontRegistry;
  3594. }
  3595. createNativeFontFace() {
  3596. if (!this.data || this.disableFontFace) {
  3597. return null;
  3598. }
  3599. let nativeFontFace;
  3600. if (!this.cssFontInfo) {
  3601. nativeFontFace = new FontFace(this.loadedName, this.data, {});
  3602. } else {
  3603. const css = {
  3604. weight: this.cssFontInfo.fontWeight
  3605. };
  3606. if (this.cssFontInfo.italicAngle) {
  3607. css.style = `oblique ${this.cssFontInfo.italicAngle}deg`;
  3608. }
  3609. nativeFontFace = new FontFace(this.cssFontInfo.fontFamily, this.data, css);
  3610. }
  3611. if (this.fontRegistry) {
  3612. this.fontRegistry.registerFont(this);
  3613. }
  3614. return nativeFontFace;
  3615. }
  3616. createFontFaceRule() {
  3617. if (!this.data || this.disableFontFace) {
  3618. return null;
  3619. }
  3620. const data = (0, _util.bytesToString)(this.data);
  3621. const url = `url(data:${this.mimetype};base64,${btoa(data)});`;
  3622. let rule;
  3623. if (!this.cssFontInfo) {
  3624. rule = `@font-face {font-family:"${this.loadedName}";src:${url}}`;
  3625. } else {
  3626. let css = `font-weight: ${this.cssFontInfo.fontWeight};`;
  3627. if (this.cssFontInfo.italicAngle) {
  3628. css += `font-style: oblique ${this.cssFontInfo.italicAngle}deg;`;
  3629. }
  3630. rule = `@font-face {font-family:"${this.cssFontInfo.fontFamily}";${css}src:${url}}`;
  3631. }
  3632. if (this.fontRegistry) {
  3633. this.fontRegistry.registerFont(this, url);
  3634. }
  3635. return rule;
  3636. }
  3637. getPathGenerator(objs, character) {
  3638. if (this.compiledGlyphs[character] !== undefined) {
  3639. return this.compiledGlyphs[character];
  3640. }
  3641. let cmds;
  3642. try {
  3643. cmds = objs.get(this.loadedName + "_path_" + character);
  3644. } catch (ex) {
  3645. if (!this.ignoreErrors) {
  3646. throw ex;
  3647. }
  3648. this._onUnsupportedFeature({
  3649. featureId: _util.UNSUPPORTED_FEATURES.errorFontGetPath
  3650. });
  3651. (0, _util.warn)(`getPathGenerator - ignoring character: "${ex}".`);
  3652. return this.compiledGlyphs[character] = function (c, size) {};
  3653. }
  3654. if (this.isEvalSupported && _util.FeatureTest.isEvalSupported) {
  3655. const jsBuf = [];
  3656. for (const current of cmds) {
  3657. const args = current.args !== undefined ? current.args.join(",") : "";
  3658. jsBuf.push("c.", current.cmd, "(", args, ");\n");
  3659. }
  3660. return this.compiledGlyphs[character] = new Function("c", "size", jsBuf.join(""));
  3661. }
  3662. return this.compiledGlyphs[character] = function (c, size) {
  3663. for (const current of cmds) {
  3664. if (current.cmd === "scale") {
  3665. current.args = [size, -size];
  3666. }
  3667. c[current.cmd].apply(c, current.args);
  3668. }
  3669. };
  3670. }
  3671. }
  3672. exports.FontFaceObject = FontFaceObject;
  3673. /***/ }),
  3674. /* 8 */
  3675. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3676. Object.defineProperty(exports, "__esModule", ({
  3677. value: true
  3678. }));
  3679. exports.AnnotationStorage = void 0;
  3680. var _murmurhash = __w_pdfjs_require__(9);
  3681. var _util = __w_pdfjs_require__(1);
  3682. class AnnotationStorage {
  3683. constructor() {
  3684. this._storage = new Map();
  3685. this._modified = false;
  3686. this.onSetModified = null;
  3687. this.onResetModified = null;
  3688. }
  3689. getValue(key, defaultValue) {
  3690. const value = this._storage.get(key);
  3691. if (value === undefined) {
  3692. return defaultValue;
  3693. }
  3694. return Object.assign(defaultValue, value);
  3695. }
  3696. getRawValue(key) {
  3697. return this._storage.get(key);
  3698. }
  3699. setValue(key, value) {
  3700. const obj = this._storage.get(key);
  3701. let modified = false;
  3702. if (obj !== undefined) {
  3703. for (const [entry, val] of Object.entries(value)) {
  3704. if (obj[entry] !== val) {
  3705. modified = true;
  3706. obj[entry] = val;
  3707. }
  3708. }
  3709. } else {
  3710. modified = true;
  3711. this._storage.set(key, value);
  3712. }
  3713. if (modified) {
  3714. this._setModified();
  3715. }
  3716. }
  3717. getAll() {
  3718. return this._storage.size > 0 ? (0, _util.objectFromMap)(this._storage) : null;
  3719. }
  3720. get size() {
  3721. return this._storage.size;
  3722. }
  3723. _setModified() {
  3724. if (!this._modified) {
  3725. this._modified = true;
  3726. if (typeof this.onSetModified === "function") {
  3727. this.onSetModified();
  3728. }
  3729. }
  3730. }
  3731. resetModified() {
  3732. if (this._modified) {
  3733. this._modified = false;
  3734. if (typeof this.onResetModified === "function") {
  3735. this.onResetModified();
  3736. }
  3737. }
  3738. }
  3739. get serializable() {
  3740. return this._storage.size > 0 ? this._storage : null;
  3741. }
  3742. get hash() {
  3743. const hash = new _murmurhash.MurmurHash3_64();
  3744. for (const [key, value] of this._storage) {
  3745. hash.update(`${key}:${JSON.stringify(value)}`);
  3746. }
  3747. return hash.hexdigest();
  3748. }
  3749. }
  3750. exports.AnnotationStorage = AnnotationStorage;
  3751. /***/ }),
  3752. /* 9 */
  3753. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3754. Object.defineProperty(exports, "__esModule", ({
  3755. value: true
  3756. }));
  3757. exports.MurmurHash3_64 = void 0;
  3758. var _util = __w_pdfjs_require__(1);
  3759. const SEED = 0xc3d2e1f0;
  3760. const MASK_HIGH = 0xffff0000;
  3761. const MASK_LOW = 0xffff;
  3762. class MurmurHash3_64 {
  3763. constructor(seed) {
  3764. this.h1 = seed ? seed & 0xffffffff : SEED;
  3765. this.h2 = seed ? seed & 0xffffffff : SEED;
  3766. }
  3767. update(input) {
  3768. let data, length;
  3769. if (typeof input === "string") {
  3770. data = new Uint8Array(input.length * 2);
  3771. length = 0;
  3772. for (let i = 0, ii = input.length; i < ii; i++) {
  3773. const code = input.charCodeAt(i);
  3774. if (code <= 0xff) {
  3775. data[length++] = code;
  3776. } else {
  3777. data[length++] = code >>> 8;
  3778. data[length++] = code & 0xff;
  3779. }
  3780. }
  3781. } else if ((0, _util.isArrayBuffer)(input)) {
  3782. data = input.slice();
  3783. length = data.byteLength;
  3784. } else {
  3785. throw new Error("Wrong data format in MurmurHash3_64_update. " + "Input must be a string or array.");
  3786. }
  3787. const blockCounts = length >> 2;
  3788. const tailLength = length - blockCounts * 4;
  3789. const dataUint32 = new Uint32Array(data.buffer, 0, blockCounts);
  3790. let k1 = 0,
  3791. k2 = 0;
  3792. let h1 = this.h1,
  3793. h2 = this.h2;
  3794. const C1 = 0xcc9e2d51,
  3795. C2 = 0x1b873593;
  3796. const C1_LOW = C1 & MASK_LOW,
  3797. C2_LOW = C2 & MASK_LOW;
  3798. for (let i = 0; i < blockCounts; i++) {
  3799. if (i & 1) {
  3800. k1 = dataUint32[i];
  3801. k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
  3802. k1 = k1 << 15 | k1 >>> 17;
  3803. k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
  3804. h1 ^= k1;
  3805. h1 = h1 << 13 | h1 >>> 19;
  3806. h1 = h1 * 5 + 0xe6546b64;
  3807. } else {
  3808. k2 = dataUint32[i];
  3809. k2 = k2 * C1 & MASK_HIGH | k2 * C1_LOW & MASK_LOW;
  3810. k2 = k2 << 15 | k2 >>> 17;
  3811. k2 = k2 * C2 & MASK_HIGH | k2 * C2_LOW & MASK_LOW;
  3812. h2 ^= k2;
  3813. h2 = h2 << 13 | h2 >>> 19;
  3814. h2 = h2 * 5 + 0xe6546b64;
  3815. }
  3816. }
  3817. k1 = 0;
  3818. switch (tailLength) {
  3819. case 3:
  3820. k1 ^= data[blockCounts * 4 + 2] << 16;
  3821. case 2:
  3822. k1 ^= data[blockCounts * 4 + 1] << 8;
  3823. case 1:
  3824. k1 ^= data[blockCounts * 4];
  3825. k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
  3826. k1 = k1 << 15 | k1 >>> 17;
  3827. k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
  3828. if (blockCounts & 1) {
  3829. h1 ^= k1;
  3830. } else {
  3831. h2 ^= k1;
  3832. }
  3833. }
  3834. this.h1 = h1;
  3835. this.h2 = h2;
  3836. }
  3837. hexdigest() {
  3838. let h1 = this.h1,
  3839. h2 = this.h2;
  3840. h1 ^= h2 >>> 1;
  3841. h1 = h1 * 0xed558ccd & MASK_HIGH | h1 * 0x8ccd & MASK_LOW;
  3842. h2 = h2 * 0xff51afd7 & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16;
  3843. h1 ^= h2 >>> 1;
  3844. h1 = h1 * 0x1a85ec53 & MASK_HIGH | h1 * 0xec53 & MASK_LOW;
  3845. h2 = h2 * 0xc4ceb9fe & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16;
  3846. h1 ^= h2 >>> 1;
  3847. const hex1 = (h1 >>> 0).toString(16),
  3848. hex2 = (h2 >>> 0).toString(16);
  3849. return hex1.padStart(8, "0") + hex2.padStart(8, "0");
  3850. }
  3851. }
  3852. exports.MurmurHash3_64 = MurmurHash3_64;
  3853. /***/ }),
  3854. /* 10 */
  3855. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3856. Object.defineProperty(exports, "__esModule", ({
  3857. value: true
  3858. }));
  3859. exports.CanvasGraphics = void 0;
  3860. var _util = __w_pdfjs_require__(1);
  3861. var _pattern_helper = __w_pdfjs_require__(11);
  3862. var _image_utils = __w_pdfjs_require__(12);
  3863. var _is_node = __w_pdfjs_require__(3);
  3864. var _display_utils = __w_pdfjs_require__(5);
  3865. const MIN_FONT_SIZE = 16;
  3866. const MAX_FONT_SIZE = 100;
  3867. const MAX_GROUP_SIZE = 4096;
  3868. const EXECUTION_TIME = 15;
  3869. const EXECUTION_STEPS = 10;
  3870. const COMPILE_TYPE3_GLYPHS = true;
  3871. const MAX_SIZE_TO_COMPILE = 1000;
  3872. const FULL_CHUNK_HEIGHT = 16;
  3873. const LINEWIDTH_SCALE_FACTOR = 1.000001;
  3874. function mirrorContextOperations(ctx, destCtx) {
  3875. if (ctx._removeMirroring) {
  3876. throw new Error("Context is already forwarding operations.");
  3877. }
  3878. ctx.__originalSave = ctx.save;
  3879. ctx.__originalRestore = ctx.restore;
  3880. ctx.__originalRotate = ctx.rotate;
  3881. ctx.__originalScale = ctx.scale;
  3882. ctx.__originalTranslate = ctx.translate;
  3883. ctx.__originalTransform = ctx.transform;
  3884. ctx.__originalSetTransform = ctx.setTransform;
  3885. ctx.__originalResetTransform = ctx.resetTransform;
  3886. ctx.__originalClip = ctx.clip;
  3887. ctx.__originalMoveTo = ctx.moveTo;
  3888. ctx.__originalLineTo = ctx.lineTo;
  3889. ctx.__originalBezierCurveTo = ctx.bezierCurveTo;
  3890. ctx.__originalRect = ctx.rect;
  3891. ctx.__originalClosePath = ctx.closePath;
  3892. ctx.__originalBeginPath = ctx.beginPath;
  3893. ctx._removeMirroring = () => {
  3894. ctx.save = ctx.__originalSave;
  3895. ctx.restore = ctx.__originalRestore;
  3896. ctx.rotate = ctx.__originalRotate;
  3897. ctx.scale = ctx.__originalScale;
  3898. ctx.translate = ctx.__originalTranslate;
  3899. ctx.transform = ctx.__originalTransform;
  3900. ctx.setTransform = ctx.__originalSetTransform;
  3901. ctx.resetTransform = ctx.__originalResetTransform;
  3902. ctx.clip = ctx.__originalClip;
  3903. ctx.moveTo = ctx.__originalMoveTo;
  3904. ctx.lineTo = ctx.__originalLineTo;
  3905. ctx.bezierCurveTo = ctx.__originalBezierCurveTo;
  3906. ctx.rect = ctx.__originalRect;
  3907. ctx.closePath = ctx.__originalClosePath;
  3908. ctx.beginPath = ctx.__originalBeginPath;
  3909. delete ctx._removeMirroring;
  3910. };
  3911. ctx.save = function ctxSave() {
  3912. destCtx.save();
  3913. this.__originalSave();
  3914. };
  3915. ctx.restore = function ctxRestore() {
  3916. destCtx.restore();
  3917. this.__originalRestore();
  3918. };
  3919. ctx.translate = function ctxTranslate(x, y) {
  3920. destCtx.translate(x, y);
  3921. this.__originalTranslate(x, y);
  3922. };
  3923. ctx.scale = function ctxScale(x, y) {
  3924. destCtx.scale(x, y);
  3925. this.__originalScale(x, y);
  3926. };
  3927. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  3928. destCtx.transform(a, b, c, d, e, f);
  3929. this.__originalTransform(a, b, c, d, e, f);
  3930. };
  3931. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  3932. destCtx.setTransform(a, b, c, d, e, f);
  3933. this.__originalSetTransform(a, b, c, d, e, f);
  3934. };
  3935. ctx.resetTransform = function ctxResetTransform() {
  3936. destCtx.resetTransform();
  3937. this.__originalResetTransform();
  3938. };
  3939. ctx.rotate = function ctxRotate(angle) {
  3940. destCtx.rotate(angle);
  3941. this.__originalRotate(angle);
  3942. };
  3943. ctx.clip = function ctxRotate(rule) {
  3944. destCtx.clip(rule);
  3945. this.__originalClip(rule);
  3946. };
  3947. ctx.moveTo = function (x, y) {
  3948. destCtx.moveTo(x, y);
  3949. this.__originalMoveTo(x, y);
  3950. };
  3951. ctx.lineTo = function (x, y) {
  3952. destCtx.lineTo(x, y);
  3953. this.__originalLineTo(x, y);
  3954. };
  3955. ctx.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
  3956. destCtx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
  3957. this.__originalBezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
  3958. };
  3959. ctx.rect = function (x, y, width, height) {
  3960. destCtx.rect(x, y, width, height);
  3961. this.__originalRect(x, y, width, height);
  3962. };
  3963. ctx.closePath = function () {
  3964. destCtx.closePath();
  3965. this.__originalClosePath();
  3966. };
  3967. ctx.beginPath = function () {
  3968. destCtx.beginPath();
  3969. this.__originalBeginPath();
  3970. };
  3971. }
  3972. function addContextCurrentTransform(ctx) {
  3973. if (ctx._transformStack) {
  3974. ctx._transformStack = [];
  3975. }
  3976. if (ctx.mozCurrentTransform) {
  3977. return;
  3978. }
  3979. ctx._originalSave = ctx.save;
  3980. ctx._originalRestore = ctx.restore;
  3981. ctx._originalRotate = ctx.rotate;
  3982. ctx._originalScale = ctx.scale;
  3983. ctx._originalTranslate = ctx.translate;
  3984. ctx._originalTransform = ctx.transform;
  3985. ctx._originalSetTransform = ctx.setTransform;
  3986. ctx._originalResetTransform = ctx.resetTransform;
  3987. ctx._transformMatrix = ctx._transformMatrix || [1, 0, 0, 1, 0, 0];
  3988. ctx._transformStack = [];
  3989. try {
  3990. const desc = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(ctx), "lineWidth");
  3991. ctx._setLineWidth = desc.set;
  3992. ctx._getLineWidth = desc.get;
  3993. Object.defineProperty(ctx, "lineWidth", {
  3994. set: function setLineWidth(width) {
  3995. this._setLineWidth(width * LINEWIDTH_SCALE_FACTOR);
  3996. },
  3997. get: function getLineWidth() {
  3998. return this._getLineWidth();
  3999. }
  4000. });
  4001. } catch (_) {}
  4002. Object.defineProperty(ctx, "mozCurrentTransform", {
  4003. get: function getCurrentTransform() {
  4004. return this._transformMatrix;
  4005. }
  4006. });
  4007. Object.defineProperty(ctx, "mozCurrentTransformInverse", {
  4008. get: function getCurrentTransformInverse() {
  4009. const [a, b, c, d, e, f] = this._transformMatrix;
  4010. const ad_bc = a * d - b * c;
  4011. const bc_ad = b * c - a * d;
  4012. return [d / ad_bc, b / bc_ad, c / bc_ad, a / ad_bc, (d * e - c * f) / bc_ad, (b * e - a * f) / ad_bc];
  4013. }
  4014. });
  4015. ctx.save = function ctxSave() {
  4016. const old = this._transformMatrix;
  4017. this._transformStack.push(old);
  4018. this._transformMatrix = old.slice(0, 6);
  4019. this._originalSave();
  4020. };
  4021. ctx.restore = function ctxRestore() {
  4022. if (this._transformStack.length === 0) {
  4023. (0, _util.warn)("Tried to restore a ctx when the stack was already empty.");
  4024. }
  4025. const prev = this._transformStack.pop();
  4026. if (prev) {
  4027. this._transformMatrix = prev;
  4028. this._originalRestore();
  4029. }
  4030. };
  4031. ctx.translate = function ctxTranslate(x, y) {
  4032. const m = this._transformMatrix;
  4033. m[4] = m[0] * x + m[2] * y + m[4];
  4034. m[5] = m[1] * x + m[3] * y + m[5];
  4035. this._originalTranslate(x, y);
  4036. };
  4037. ctx.scale = function ctxScale(x, y) {
  4038. const m = this._transformMatrix;
  4039. m[0] *= x;
  4040. m[1] *= x;
  4041. m[2] *= y;
  4042. m[3] *= y;
  4043. this._originalScale(x, y);
  4044. };
  4045. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  4046. const m = this._transformMatrix;
  4047. this._transformMatrix = [m[0] * a + m[2] * b, m[1] * a + m[3] * b, m[0] * c + m[2] * d, m[1] * c + m[3] * d, m[0] * e + m[2] * f + m[4], m[1] * e + m[3] * f + m[5]];
  4048. ctx._originalTransform(a, b, c, d, e, f);
  4049. };
  4050. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  4051. this._transformMatrix = [a, b, c, d, e, f];
  4052. ctx._originalSetTransform(a, b, c, d, e, f);
  4053. };
  4054. ctx.resetTransform = function ctxResetTransform() {
  4055. this._transformMatrix = [1, 0, 0, 1, 0, 0];
  4056. ctx._originalResetTransform();
  4057. };
  4058. ctx.rotate = function ctxRotate(angle) {
  4059. const cosValue = Math.cos(angle);
  4060. const sinValue = Math.sin(angle);
  4061. const m = this._transformMatrix;
  4062. this._transformMatrix = [m[0] * cosValue + m[2] * sinValue, m[1] * cosValue + m[3] * sinValue, m[0] * -sinValue + m[2] * cosValue, m[1] * -sinValue + m[3] * cosValue, m[4], m[5]];
  4063. this._originalRotate(angle);
  4064. };
  4065. }
  4066. class CachedCanvases {
  4067. constructor(canvasFactory) {
  4068. this.canvasFactory = canvasFactory;
  4069. this.cache = Object.create(null);
  4070. }
  4071. getCanvas(id, width, height, trackTransform) {
  4072. let canvasEntry;
  4073. if (this.cache[id] !== undefined) {
  4074. canvasEntry = this.cache[id];
  4075. this.canvasFactory.reset(canvasEntry, width, height);
  4076. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  4077. } else {
  4078. canvasEntry = this.canvasFactory.create(width, height);
  4079. this.cache[id] = canvasEntry;
  4080. }
  4081. if (trackTransform) {
  4082. addContextCurrentTransform(canvasEntry.context);
  4083. }
  4084. return canvasEntry;
  4085. }
  4086. delete(id) {
  4087. delete this.cache[id];
  4088. }
  4089. clear() {
  4090. for (const id in this.cache) {
  4091. const canvasEntry = this.cache[id];
  4092. this.canvasFactory.destroy(canvasEntry);
  4093. delete this.cache[id];
  4094. }
  4095. }
  4096. }
  4097. function drawImageAtIntegerCoords(ctx, srcImg, srcX, srcY, srcW, srcH, destX, destY, destW, destH) {
  4098. const [a, b, c, d, tx, ty] = ctx.mozCurrentTransform;
  4099. if (b === 0 && c === 0) {
  4100. const tlX = destX * a + tx;
  4101. const rTlX = Math.round(tlX);
  4102. const tlY = destY * d + ty;
  4103. const rTlY = Math.round(tlY);
  4104. const brX = (destX + destW) * a + tx;
  4105. const rWidth = Math.abs(Math.round(brX) - rTlX) || 1;
  4106. const brY = (destY + destH) * d + ty;
  4107. const rHeight = Math.abs(Math.round(brY) - rTlY) || 1;
  4108. ctx.setTransform(Math.sign(a), 0, 0, Math.sign(d), rTlX, rTlY);
  4109. ctx.drawImage(srcImg, srcX, srcY, srcW, srcH, 0, 0, rWidth, rHeight);
  4110. ctx.setTransform(a, b, c, d, tx, ty);
  4111. return [rWidth, rHeight];
  4112. }
  4113. if (a === 0 && d === 0) {
  4114. const tlX = destY * c + tx;
  4115. const rTlX = Math.round(tlX);
  4116. const tlY = destX * b + ty;
  4117. const rTlY = Math.round(tlY);
  4118. const brX = (destY + destH) * c + tx;
  4119. const rWidth = Math.abs(Math.round(brX) - rTlX) || 1;
  4120. const brY = (destX + destW) * b + ty;
  4121. const rHeight = Math.abs(Math.round(brY) - rTlY) || 1;
  4122. ctx.setTransform(0, Math.sign(b), Math.sign(c), 0, rTlX, rTlY);
  4123. ctx.drawImage(srcImg, srcX, srcY, srcW, srcH, 0, 0, rHeight, rWidth);
  4124. ctx.setTransform(a, b, c, d, tx, ty);
  4125. return [rHeight, rWidth];
  4126. }
  4127. ctx.drawImage(srcImg, srcX, srcY, srcW, srcH, destX, destY, destW, destH);
  4128. const scaleX = Math.hypot(a, b);
  4129. const scaleY = Math.hypot(c, d);
  4130. return [scaleX * destW, scaleY * destH];
  4131. }
  4132. function compileType3Glyph(imgData) {
  4133. const {
  4134. width,
  4135. height
  4136. } = imgData;
  4137. if (!COMPILE_TYPE3_GLYPHS || width > MAX_SIZE_TO_COMPILE || height > MAX_SIZE_TO_COMPILE) {
  4138. return null;
  4139. }
  4140. const POINT_TO_PROCESS_LIMIT = 1000;
  4141. const POINT_TYPES = new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  4142. const width1 = width + 1;
  4143. let points = new Uint8Array(width1 * (height + 1));
  4144. let i, j, j0;
  4145. const lineSize = width + 7 & ~7;
  4146. let data = new Uint8Array(lineSize * height),
  4147. pos = 0;
  4148. for (const elem of imgData.data) {
  4149. let mask = 128;
  4150. while (mask > 0) {
  4151. data[pos++] = elem & mask ? 0 : 255;
  4152. mask >>= 1;
  4153. }
  4154. }
  4155. let count = 0;
  4156. pos = 0;
  4157. if (data[pos] !== 0) {
  4158. points[0] = 1;
  4159. ++count;
  4160. }
  4161. for (j = 1; j < width; j++) {
  4162. if (data[pos] !== data[pos + 1]) {
  4163. points[j] = data[pos] ? 2 : 1;
  4164. ++count;
  4165. }
  4166. pos++;
  4167. }
  4168. if (data[pos] !== 0) {
  4169. points[j] = 2;
  4170. ++count;
  4171. }
  4172. for (i = 1; i < height; i++) {
  4173. pos = i * lineSize;
  4174. j0 = i * width1;
  4175. if (data[pos - lineSize] !== data[pos]) {
  4176. points[j0] = data[pos] ? 1 : 8;
  4177. ++count;
  4178. }
  4179. let sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  4180. for (j = 1; j < width; j++) {
  4181. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) + (data[pos - lineSize + 1] ? 8 : 0);
  4182. if (POINT_TYPES[sum]) {
  4183. points[j0 + j] = POINT_TYPES[sum];
  4184. ++count;
  4185. }
  4186. pos++;
  4187. }
  4188. if (data[pos - lineSize] !== data[pos]) {
  4189. points[j0 + j] = data[pos] ? 2 : 4;
  4190. ++count;
  4191. }
  4192. if (count > POINT_TO_PROCESS_LIMIT) {
  4193. return null;
  4194. }
  4195. }
  4196. pos = lineSize * (height - 1);
  4197. j0 = i * width1;
  4198. if (data[pos] !== 0) {
  4199. points[j0] = 8;
  4200. ++count;
  4201. }
  4202. for (j = 1; j < width; j++) {
  4203. if (data[pos] !== data[pos + 1]) {
  4204. points[j0 + j] = data[pos] ? 4 : 8;
  4205. ++count;
  4206. }
  4207. pos++;
  4208. }
  4209. if (data[pos] !== 0) {
  4210. points[j0 + j] = 4;
  4211. ++count;
  4212. }
  4213. if (count > POINT_TO_PROCESS_LIMIT) {
  4214. return null;
  4215. }
  4216. const steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  4217. let path, outlines, coords;
  4218. if (!_is_node.isNodeJS) {
  4219. path = new Path2D();
  4220. } else {
  4221. outlines = [];
  4222. }
  4223. for (i = 0; count && i <= height; i++) {
  4224. let p = i * width1;
  4225. const end = p + width;
  4226. while (p < end && !points[p]) {
  4227. p++;
  4228. }
  4229. if (p === end) {
  4230. continue;
  4231. }
  4232. if (path) {
  4233. path.moveTo(p % width1, i);
  4234. } else {
  4235. coords = [p % width1, i];
  4236. }
  4237. const p0 = p;
  4238. let type = points[p];
  4239. do {
  4240. const step = steps[type];
  4241. do {
  4242. p += step;
  4243. } while (!points[p]);
  4244. const pp = points[p];
  4245. if (pp !== 5 && pp !== 10) {
  4246. type = pp;
  4247. points[p] = 0;
  4248. } else {
  4249. type = pp & 0x33 * type >> 4;
  4250. points[p] &= type >> 2 | type << 2;
  4251. }
  4252. if (path) {
  4253. path.lineTo(p % width1, p / width1 | 0);
  4254. } else {
  4255. coords.push(p % width1, p / width1 | 0);
  4256. }
  4257. if (!points[p]) {
  4258. --count;
  4259. }
  4260. } while (p0 !== p);
  4261. if (!path) {
  4262. outlines.push(coords);
  4263. }
  4264. --i;
  4265. }
  4266. data = null;
  4267. points = null;
  4268. const drawOutline = function (c) {
  4269. c.save();
  4270. c.scale(1 / width, -1 / height);
  4271. c.translate(0, -height);
  4272. if (path) {
  4273. c.fill(path);
  4274. } else {
  4275. c.beginPath();
  4276. for (const o of outlines) {
  4277. c.moveTo(o[0], o[1]);
  4278. for (let l = 2, ll = o.length; l < ll; l += 2) {
  4279. c.lineTo(o[l], o[l + 1]);
  4280. }
  4281. }
  4282. c.fill();
  4283. }
  4284. c.beginPath();
  4285. c.restore();
  4286. };
  4287. return drawOutline;
  4288. }
  4289. class CanvasExtraState {
  4290. constructor(width, height) {
  4291. this.alphaIsShape = false;
  4292. this.fontSize = 0;
  4293. this.fontSizeScale = 1;
  4294. this.textMatrix = _util.IDENTITY_MATRIX;
  4295. this.textMatrixScale = 1;
  4296. this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
  4297. this.leading = 0;
  4298. this.x = 0;
  4299. this.y = 0;
  4300. this.lineX = 0;
  4301. this.lineY = 0;
  4302. this.charSpacing = 0;
  4303. this.wordSpacing = 0;
  4304. this.textHScale = 1;
  4305. this.textRenderingMode = _util.TextRenderingMode.FILL;
  4306. this.textRise = 0;
  4307. this.fillColor = "#000000";
  4308. this.strokeColor = "#000000";
  4309. this.patternFill = false;
  4310. this.fillAlpha = 1;
  4311. this.strokeAlpha = 1;
  4312. this.lineWidth = 1;
  4313. this.activeSMask = null;
  4314. this.transferMaps = null;
  4315. this.startNewPathAndClipBox([0, 0, width, height]);
  4316. }
  4317. clone() {
  4318. const clone = Object.create(this);
  4319. clone.clipBox = this.clipBox.slice();
  4320. return clone;
  4321. }
  4322. setCurrentPoint(x, y) {
  4323. this.x = x;
  4324. this.y = y;
  4325. }
  4326. updatePathMinMax(transform, x, y) {
  4327. [x, y] = _util.Util.applyTransform([x, y], transform);
  4328. this.minX = Math.min(this.minX, x);
  4329. this.minY = Math.min(this.minY, y);
  4330. this.maxX = Math.max(this.maxX, x);
  4331. this.maxY = Math.max(this.maxY, y);
  4332. }
  4333. updateRectMinMax(transform, rect) {
  4334. const p1 = _util.Util.applyTransform(rect, transform);
  4335. const p2 = _util.Util.applyTransform(rect.slice(2), transform);
  4336. this.minX = Math.min(this.minX, p1[0], p2[0]);
  4337. this.minY = Math.min(this.minY, p1[1], p2[1]);
  4338. this.maxX = Math.max(this.maxX, p1[0], p2[0]);
  4339. this.maxY = Math.max(this.maxY, p1[1], p2[1]);
  4340. }
  4341. updateScalingPathMinMax(transform, minMax) {
  4342. _util.Util.scaleMinMax(transform, minMax);
  4343. this.minX = Math.min(this.minX, minMax[0]);
  4344. this.maxX = Math.max(this.maxX, minMax[1]);
  4345. this.minY = Math.min(this.minY, minMax[2]);
  4346. this.maxY = Math.max(this.maxY, minMax[3]);
  4347. }
  4348. updateCurvePathMinMax(transform, x0, y0, x1, y1, x2, y2, x3, y3, minMax) {
  4349. const box = _util.Util.bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3);
  4350. if (minMax) {
  4351. minMax[0] = Math.min(minMax[0], box[0], box[2]);
  4352. minMax[1] = Math.max(minMax[1], box[0], box[2]);
  4353. minMax[2] = Math.min(minMax[2], box[1], box[3]);
  4354. minMax[3] = Math.max(minMax[3], box[1], box[3]);
  4355. return;
  4356. }
  4357. this.updateRectMinMax(transform, box);
  4358. }
  4359. getPathBoundingBox(pathType = _pattern_helper.PathType.FILL, transform = null) {
  4360. const box = [this.minX, this.minY, this.maxX, this.maxY];
  4361. if (pathType === _pattern_helper.PathType.STROKE) {
  4362. if (!transform) {
  4363. (0, _util.unreachable)("Stroke bounding box must include transform.");
  4364. }
  4365. const scale = _util.Util.singularValueDecompose2dScale(transform);
  4366. const xStrokePad = scale[0] * this.lineWidth / 2;
  4367. const yStrokePad = scale[1] * this.lineWidth / 2;
  4368. box[0] -= xStrokePad;
  4369. box[1] -= yStrokePad;
  4370. box[2] += xStrokePad;
  4371. box[3] += yStrokePad;
  4372. }
  4373. return box;
  4374. }
  4375. updateClipFromPath() {
  4376. const intersect = _util.Util.intersect(this.clipBox, this.getPathBoundingBox());
  4377. this.startNewPathAndClipBox(intersect || [0, 0, 0, 0]);
  4378. }
  4379. isEmptyClip() {
  4380. return this.minX === Infinity;
  4381. }
  4382. startNewPathAndClipBox(box) {
  4383. this.clipBox = box;
  4384. this.minX = Infinity;
  4385. this.minY = Infinity;
  4386. this.maxX = 0;
  4387. this.maxY = 0;
  4388. }
  4389. getClippedPathBoundingBox(pathType = _pattern_helper.PathType.FILL, transform = null) {
  4390. return _util.Util.intersect(this.clipBox, this.getPathBoundingBox(pathType, transform));
  4391. }
  4392. }
  4393. function putBinaryImageData(ctx, imgData, transferMaps = null) {
  4394. if (typeof ImageData !== "undefined" && imgData instanceof ImageData) {
  4395. ctx.putImageData(imgData, 0, 0);
  4396. return;
  4397. }
  4398. const height = imgData.height,
  4399. width = imgData.width;
  4400. const partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  4401. const fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  4402. const totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  4403. const chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  4404. let srcPos = 0,
  4405. destPos;
  4406. const src = imgData.data;
  4407. const dest = chunkImgData.data;
  4408. let i, j, thisChunkHeight, elemsInThisChunk;
  4409. let transferMapRed, transferMapGreen, transferMapBlue, transferMapGray;
  4410. if (transferMaps) {
  4411. switch (transferMaps.length) {
  4412. case 1:
  4413. transferMapRed = transferMaps[0];
  4414. transferMapGreen = transferMaps[0];
  4415. transferMapBlue = transferMaps[0];
  4416. transferMapGray = transferMaps[0];
  4417. break;
  4418. case 4:
  4419. transferMapRed = transferMaps[0];
  4420. transferMapGreen = transferMaps[1];
  4421. transferMapBlue = transferMaps[2];
  4422. transferMapGray = transferMaps[3];
  4423. break;
  4424. }
  4425. }
  4426. if (imgData.kind === _util.ImageKind.GRAYSCALE_1BPP) {
  4427. const srcLength = src.byteLength;
  4428. const dest32 = new Uint32Array(dest.buffer, 0, dest.byteLength >> 2);
  4429. const dest32DataLength = dest32.length;
  4430. const fullSrcDiff = width + 7 >> 3;
  4431. let white = 0xffffffff;
  4432. let black = _util.FeatureTest.isLittleEndian ? 0xff000000 : 0x000000ff;
  4433. if (transferMapGray) {
  4434. if (transferMapGray[0] === 0xff && transferMapGray[0xff] === 0) {
  4435. [white, black] = [black, white];
  4436. }
  4437. }
  4438. for (i = 0; i < totalChunks; i++) {
  4439. thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  4440. destPos = 0;
  4441. for (j = 0; j < thisChunkHeight; j++) {
  4442. const srcDiff = srcLength - srcPos;
  4443. let k = 0;
  4444. const kEnd = srcDiff > fullSrcDiff ? width : srcDiff * 8 - 7;
  4445. const kEndUnrolled = kEnd & ~7;
  4446. let mask = 0;
  4447. let srcByte = 0;
  4448. for (; k < kEndUnrolled; k += 8) {
  4449. srcByte = src[srcPos++];
  4450. dest32[destPos++] = srcByte & 128 ? white : black;
  4451. dest32[destPos++] = srcByte & 64 ? white : black;
  4452. dest32[destPos++] = srcByte & 32 ? white : black;
  4453. dest32[destPos++] = srcByte & 16 ? white : black;
  4454. dest32[destPos++] = srcByte & 8 ? white : black;
  4455. dest32[destPos++] = srcByte & 4 ? white : black;
  4456. dest32[destPos++] = srcByte & 2 ? white : black;
  4457. dest32[destPos++] = srcByte & 1 ? white : black;
  4458. }
  4459. for (; k < kEnd; k++) {
  4460. if (mask === 0) {
  4461. srcByte = src[srcPos++];
  4462. mask = 128;
  4463. }
  4464. dest32[destPos++] = srcByte & mask ? white : black;
  4465. mask >>= 1;
  4466. }
  4467. }
  4468. while (destPos < dest32DataLength) {
  4469. dest32[destPos++] = 0;
  4470. }
  4471. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  4472. }
  4473. } else if (imgData.kind === _util.ImageKind.RGBA_32BPP) {
  4474. const hasTransferMaps = !!(transferMapRed || transferMapGreen || transferMapBlue);
  4475. j = 0;
  4476. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  4477. for (i = 0; i < fullChunks; i++) {
  4478. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  4479. srcPos += elemsInThisChunk;
  4480. if (hasTransferMaps) {
  4481. for (let k = 0; k < elemsInThisChunk; k += 4) {
  4482. if (transferMapRed) {
  4483. dest[k + 0] = transferMapRed[dest[k + 0]];
  4484. }
  4485. if (transferMapGreen) {
  4486. dest[k + 1] = transferMapGreen[dest[k + 1]];
  4487. }
  4488. if (transferMapBlue) {
  4489. dest[k + 2] = transferMapBlue[dest[k + 2]];
  4490. }
  4491. }
  4492. }
  4493. ctx.putImageData(chunkImgData, 0, j);
  4494. j += FULL_CHUNK_HEIGHT;
  4495. }
  4496. if (i < totalChunks) {
  4497. elemsInThisChunk = width * partialChunkHeight * 4;
  4498. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  4499. if (hasTransferMaps) {
  4500. for (let k = 0; k < elemsInThisChunk; k += 4) {
  4501. if (transferMapRed) {
  4502. dest[k + 0] = transferMapRed[dest[k + 0]];
  4503. }
  4504. if (transferMapGreen) {
  4505. dest[k + 1] = transferMapGreen[dest[k + 1]];
  4506. }
  4507. if (transferMapBlue) {
  4508. dest[k + 2] = transferMapBlue[dest[k + 2]];
  4509. }
  4510. }
  4511. }
  4512. ctx.putImageData(chunkImgData, 0, j);
  4513. }
  4514. } else if (imgData.kind === _util.ImageKind.RGB_24BPP) {
  4515. const hasTransferMaps = !!(transferMapRed || transferMapGreen || transferMapBlue);
  4516. thisChunkHeight = FULL_CHUNK_HEIGHT;
  4517. elemsInThisChunk = width * thisChunkHeight;
  4518. for (i = 0; i < totalChunks; i++) {
  4519. if (i >= fullChunks) {
  4520. thisChunkHeight = partialChunkHeight;
  4521. elemsInThisChunk = width * thisChunkHeight;
  4522. }
  4523. destPos = 0;
  4524. for (j = elemsInThisChunk; j--;) {
  4525. dest[destPos++] = src[srcPos++];
  4526. dest[destPos++] = src[srcPos++];
  4527. dest[destPos++] = src[srcPos++];
  4528. dest[destPos++] = 255;
  4529. }
  4530. if (hasTransferMaps) {
  4531. for (let k = 0; k < destPos; k += 4) {
  4532. if (transferMapRed) {
  4533. dest[k + 0] = transferMapRed[dest[k + 0]];
  4534. }
  4535. if (transferMapGreen) {
  4536. dest[k + 1] = transferMapGreen[dest[k + 1]];
  4537. }
  4538. if (transferMapBlue) {
  4539. dest[k + 2] = transferMapBlue[dest[k + 2]];
  4540. }
  4541. }
  4542. }
  4543. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  4544. }
  4545. } else {
  4546. throw new Error(`bad image kind: ${imgData.kind}`);
  4547. }
  4548. }
  4549. function putBinaryImageMask(ctx, imgData) {
  4550. if (imgData.bitmap) {
  4551. ctx.drawImage(imgData.bitmap, 0, 0);
  4552. return;
  4553. }
  4554. const height = imgData.height,
  4555. width = imgData.width;
  4556. const partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  4557. const fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  4558. const totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  4559. const chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  4560. let srcPos = 0;
  4561. const src = imgData.data;
  4562. const dest = chunkImgData.data;
  4563. for (let i = 0; i < totalChunks; i++) {
  4564. const thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  4565. ({
  4566. srcPos
  4567. } = (0, _image_utils.applyMaskImageData)({
  4568. src,
  4569. srcPos,
  4570. dest,
  4571. width,
  4572. height: thisChunkHeight
  4573. }));
  4574. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  4575. }
  4576. }
  4577. function copyCtxState(sourceCtx, destCtx) {
  4578. const properties = ["strokeStyle", "fillStyle", "fillRule", "globalAlpha", "lineWidth", "lineCap", "lineJoin", "miterLimit", "globalCompositeOperation", "font"];
  4579. for (let i = 0, ii = properties.length; i < ii; i++) {
  4580. const property = properties[i];
  4581. if (sourceCtx[property] !== undefined) {
  4582. destCtx[property] = sourceCtx[property];
  4583. }
  4584. }
  4585. if (sourceCtx.setLineDash !== undefined) {
  4586. destCtx.setLineDash(sourceCtx.getLineDash());
  4587. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  4588. }
  4589. }
  4590. function resetCtxToDefault(ctx, foregroundColor) {
  4591. ctx.strokeStyle = ctx.fillStyle = foregroundColor || "#000000";
  4592. ctx.fillRule = "nonzero";
  4593. ctx.globalAlpha = 1;
  4594. ctx.lineWidth = 1;
  4595. ctx.lineCap = "butt";
  4596. ctx.lineJoin = "miter";
  4597. ctx.miterLimit = 10;
  4598. ctx.globalCompositeOperation = "source-over";
  4599. ctx.font = "10px sans-serif";
  4600. if (ctx.setLineDash !== undefined) {
  4601. ctx.setLineDash([]);
  4602. ctx.lineDashOffset = 0;
  4603. }
  4604. }
  4605. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  4606. const length = bytes.length;
  4607. for (let i = 3; i < length; i += 4) {
  4608. const alpha = bytes[i];
  4609. if (alpha === 0) {
  4610. bytes[i - 3] = r0;
  4611. bytes[i - 2] = g0;
  4612. bytes[i - 1] = b0;
  4613. } else if (alpha < 255) {
  4614. const alpha_ = 255 - alpha;
  4615. bytes[i - 3] = bytes[i - 3] * alpha + r0 * alpha_ >> 8;
  4616. bytes[i - 2] = bytes[i - 2] * alpha + g0 * alpha_ >> 8;
  4617. bytes[i - 1] = bytes[i - 1] * alpha + b0 * alpha_ >> 8;
  4618. }
  4619. }
  4620. }
  4621. function composeSMaskAlpha(maskData, layerData, transferMap) {
  4622. const length = maskData.length;
  4623. const scale = 1 / 255;
  4624. for (let i = 3; i < length; i += 4) {
  4625. const alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
  4626. layerData[i] = layerData[i] * alpha * scale | 0;
  4627. }
  4628. }
  4629. function composeSMaskLuminosity(maskData, layerData, transferMap) {
  4630. const length = maskData.length;
  4631. for (let i = 3; i < length; i += 4) {
  4632. const y = maskData[i - 3] * 77 + maskData[i - 2] * 152 + maskData[i - 1] * 28;
  4633. layerData[i] = transferMap ? layerData[i] * transferMap[y >> 8] >> 8 : layerData[i] * y >> 16;
  4634. }
  4635. }
  4636. function genericComposeSMask(maskCtx, layerCtx, width, height, subtype, backdrop, transferMap, layerOffsetX, layerOffsetY, maskOffsetX, maskOffsetY) {
  4637. const hasBackdrop = !!backdrop;
  4638. const r0 = hasBackdrop ? backdrop[0] : 0;
  4639. const g0 = hasBackdrop ? backdrop[1] : 0;
  4640. const b0 = hasBackdrop ? backdrop[2] : 0;
  4641. let composeFn;
  4642. if (subtype === "Luminosity") {
  4643. composeFn = composeSMaskLuminosity;
  4644. } else {
  4645. composeFn = composeSMaskAlpha;
  4646. }
  4647. const PIXELS_TO_PROCESS = 1048576;
  4648. const chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  4649. for (let row = 0; row < height; row += chunkSize) {
  4650. const chunkHeight = Math.min(chunkSize, height - row);
  4651. const maskData = maskCtx.getImageData(layerOffsetX - maskOffsetX, row + (layerOffsetY - maskOffsetY), width, chunkHeight);
  4652. const layerData = layerCtx.getImageData(layerOffsetX, row + layerOffsetY, width, chunkHeight);
  4653. if (hasBackdrop) {
  4654. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  4655. }
  4656. composeFn(maskData.data, layerData.data, transferMap);
  4657. layerCtx.putImageData(layerData, layerOffsetX, row + layerOffsetY);
  4658. }
  4659. }
  4660. function composeSMask(ctx, smask, layerCtx, layerBox) {
  4661. const layerOffsetX = layerBox[0];
  4662. const layerOffsetY = layerBox[1];
  4663. const layerWidth = layerBox[2] - layerOffsetX;
  4664. const layerHeight = layerBox[3] - layerOffsetY;
  4665. if (layerWidth === 0 || layerHeight === 0) {
  4666. return;
  4667. }
  4668. genericComposeSMask(smask.context, layerCtx, layerWidth, layerHeight, smask.subtype, smask.backdrop, smask.transferMap, layerOffsetX, layerOffsetY, smask.offsetX, smask.offsetY);
  4669. ctx.save();
  4670. ctx.globalAlpha = 1;
  4671. ctx.globalCompositeOperation = "source-over";
  4672. ctx.setTransform(1, 0, 0, 1, 0, 0);
  4673. ctx.drawImage(layerCtx.canvas, 0, 0);
  4674. ctx.restore();
  4675. }
  4676. function getImageSmoothingEnabled(transform, interpolate) {
  4677. const scale = _util.Util.singularValueDecompose2dScale(transform);
  4678. scale[0] = Math.fround(scale[0]);
  4679. scale[1] = Math.fround(scale[1]);
  4680. const actualScale = Math.fround((globalThis.devicePixelRatio || 1) * _display_utils.PixelsPerInch.PDF_TO_CSS_UNITS);
  4681. if (interpolate !== undefined) {
  4682. return interpolate;
  4683. } else if (scale[0] <= actualScale || scale[1] <= actualScale) {
  4684. return true;
  4685. }
  4686. return false;
  4687. }
  4688. const LINE_CAP_STYLES = ["butt", "round", "square"];
  4689. const LINE_JOIN_STYLES = ["miter", "round", "bevel"];
  4690. const NORMAL_CLIP = {};
  4691. const EO_CLIP = {};
  4692. class CanvasGraphics {
  4693. constructor(canvasCtx, commonObjs, objs, canvasFactory, imageLayer, optionalContentConfig, annotationCanvasMap, pageColors) {
  4694. this.ctx = canvasCtx;
  4695. this.current = new CanvasExtraState(this.ctx.canvas.width, this.ctx.canvas.height);
  4696. this.stateStack = [];
  4697. this.pendingClip = null;
  4698. this.pendingEOFill = false;
  4699. this.res = null;
  4700. this.xobjs = null;
  4701. this.commonObjs = commonObjs;
  4702. this.objs = objs;
  4703. this.canvasFactory = canvasFactory;
  4704. this.imageLayer = imageLayer;
  4705. this.groupStack = [];
  4706. this.processingType3 = null;
  4707. this.baseTransform = null;
  4708. this.baseTransformStack = [];
  4709. this.groupLevel = 0;
  4710. this.smaskStack = [];
  4711. this.smaskCounter = 0;
  4712. this.tempSMask = null;
  4713. this.suspendedCtx = null;
  4714. this.contentVisible = true;
  4715. this.markedContentStack = [];
  4716. this.optionalContentConfig = optionalContentConfig;
  4717. this.cachedCanvases = new CachedCanvases(this.canvasFactory);
  4718. this.cachedPatterns = new Map();
  4719. this.annotationCanvasMap = annotationCanvasMap;
  4720. this.viewportScale = 1;
  4721. this.outputScaleX = 1;
  4722. this.outputScaleY = 1;
  4723. this.backgroundColor = pageColors?.background || null;
  4724. this.foregroundColor = pageColors?.foreground || null;
  4725. if (canvasCtx) {
  4726. addContextCurrentTransform(canvasCtx);
  4727. }
  4728. this._cachedScaleForStroking = null;
  4729. this._cachedGetSinglePixelWidth = null;
  4730. this._cachedBitmapsMap = new Map();
  4731. }
  4732. getObject(data, fallback = null) {
  4733. if (typeof data === "string") {
  4734. return data.startsWith("g_") ? this.commonObjs.get(data) : this.objs.get(data);
  4735. }
  4736. return fallback;
  4737. }
  4738. beginDrawing({
  4739. transform,
  4740. viewport,
  4741. transparency = false,
  4742. background = null
  4743. }) {
  4744. const width = this.ctx.canvas.width;
  4745. const height = this.ctx.canvas.height;
  4746. const defaultBackgroundColor = background || "#ffffff";
  4747. this.ctx.save();
  4748. if (this.foregroundColor && this.backgroundColor) {
  4749. this.ctx.fillStyle = this.foregroundColor;
  4750. const fg = this.foregroundColor = this.ctx.fillStyle;
  4751. this.ctx.fillStyle = this.backgroundColor;
  4752. const bg = this.backgroundColor = this.ctx.fillStyle;
  4753. let isValidDefaultBg = true;
  4754. let defaultBg = defaultBackgroundColor;
  4755. this.ctx.fillStyle = defaultBackgroundColor;
  4756. defaultBg = this.ctx.fillStyle;
  4757. isValidDefaultBg = typeof defaultBg === "string" && /^#[0-9A-Fa-f]{6}$/.test(defaultBg);
  4758. if (fg === "#000000" && bg === "#ffffff" || fg === bg || !isValidDefaultBg) {
  4759. this.foregroundColor = this.backgroundColor = null;
  4760. } else {
  4761. const cB = parseInt(defaultBg.slice(1), 16);
  4762. const rB = (cB && 0xff0000) >> 16;
  4763. const gB = (cB && 0x00ff00) >> 8;
  4764. const bB = cB && 0x0000ff;
  4765. const newComp = x => {
  4766. x /= 255;
  4767. return x <= 0.03928 ? x / 12.92 : ((x + 0.055) / 1.055) ** 2.4;
  4768. };
  4769. const lumB = Math.round(0.2126 * newComp(rB) + 0.7152 * newComp(gB) + 0.0722 * newComp(bB));
  4770. this.selectColor = (r, g, b) => {
  4771. const lumC = 0.2126 * newComp(r) + 0.7152 * newComp(g) + 0.0722 * newComp(b);
  4772. return Math.round(lumC) === lumB ? bg : fg;
  4773. };
  4774. }
  4775. }
  4776. this.ctx.fillStyle = this.backgroundColor || defaultBackgroundColor;
  4777. this.ctx.fillRect(0, 0, width, height);
  4778. this.ctx.restore();
  4779. if (transparency) {
  4780. const transparentCanvas = this.cachedCanvases.getCanvas("transparent", width, height, true);
  4781. this.compositeCtx = this.ctx;
  4782. this.transparentCanvas = transparentCanvas.canvas;
  4783. this.ctx = transparentCanvas.context;
  4784. this.ctx.save();
  4785. this.ctx.transform.apply(this.ctx, this.compositeCtx.mozCurrentTransform);
  4786. }
  4787. this.ctx.save();
  4788. resetCtxToDefault(this.ctx, this.foregroundColor);
  4789. if (transform) {
  4790. this.ctx.transform.apply(this.ctx, transform);
  4791. this.outputScaleX = transform[0];
  4792. this.outputScaleY = transform[0];
  4793. }
  4794. this.ctx.transform.apply(this.ctx, viewport.transform);
  4795. this.viewportScale = viewport.scale;
  4796. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  4797. if (this.imageLayer) {
  4798. this.imageLayer.beginLayout();
  4799. }
  4800. }
  4801. executeOperatorList(operatorList, executionStartIdx, continueCallback, stepper) {
  4802. const argsArray = operatorList.argsArray;
  4803. const fnArray = operatorList.fnArray;
  4804. let i = executionStartIdx || 0;
  4805. const argsArrayLen = argsArray.length;
  4806. if (argsArrayLen === i) {
  4807. return i;
  4808. }
  4809. const chunkOperations = argsArrayLen - i > EXECUTION_STEPS && typeof continueCallback === "function";
  4810. const endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  4811. let steps = 0;
  4812. const commonObjs = this.commonObjs;
  4813. const objs = this.objs;
  4814. let fnId;
  4815. while (true) {
  4816. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  4817. stepper.breakIt(i, continueCallback);
  4818. return i;
  4819. }
  4820. fnId = fnArray[i];
  4821. if (fnId !== _util.OPS.dependency) {
  4822. this[fnId].apply(this, argsArray[i]);
  4823. } else {
  4824. for (const depObjId of argsArray[i]) {
  4825. const objsPool = depObjId.startsWith("g_") ? commonObjs : objs;
  4826. if (!objsPool.has(depObjId)) {
  4827. objsPool.get(depObjId, continueCallback);
  4828. return i;
  4829. }
  4830. }
  4831. }
  4832. i++;
  4833. if (i === argsArrayLen) {
  4834. return i;
  4835. }
  4836. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  4837. if (Date.now() > endTime) {
  4838. continueCallback();
  4839. return i;
  4840. }
  4841. steps = 0;
  4842. }
  4843. }
  4844. }
  4845. endDrawing() {
  4846. while (this.stateStack.length || this.inSMaskMode) {
  4847. this.restore();
  4848. }
  4849. this.ctx.restore();
  4850. if (this.transparentCanvas) {
  4851. this.ctx = this.compositeCtx;
  4852. this.ctx.save();
  4853. this.ctx.setTransform(1, 0, 0, 1, 0, 0);
  4854. this.ctx.drawImage(this.transparentCanvas, 0, 0);
  4855. this.ctx.restore();
  4856. this.transparentCanvas = null;
  4857. }
  4858. this.cachedCanvases.clear();
  4859. this.cachedPatterns.clear();
  4860. for (const cache of this._cachedBitmapsMap.values()) {
  4861. for (const canvas of cache.values()) {
  4862. if (typeof HTMLCanvasElement !== "undefined" && canvas instanceof HTMLCanvasElement) {
  4863. canvas.width = canvas.height = 0;
  4864. }
  4865. }
  4866. cache.clear();
  4867. }
  4868. this._cachedBitmapsMap.clear();
  4869. if (this.imageLayer) {
  4870. this.imageLayer.endLayout();
  4871. }
  4872. }
  4873. _scaleImage(img, inverseTransform) {
  4874. const width = img.width;
  4875. const height = img.height;
  4876. let widthScale = Math.max(Math.hypot(inverseTransform[0], inverseTransform[1]), 1);
  4877. let heightScale = Math.max(Math.hypot(inverseTransform[2], inverseTransform[3]), 1);
  4878. let paintWidth = width,
  4879. paintHeight = height;
  4880. let tmpCanvasId = "prescale1";
  4881. let tmpCanvas, tmpCtx;
  4882. while (widthScale > 2 && paintWidth > 1 || heightScale > 2 && paintHeight > 1) {
  4883. let newWidth = paintWidth,
  4884. newHeight = paintHeight;
  4885. if (widthScale > 2 && paintWidth > 1) {
  4886. newWidth = Math.ceil(paintWidth / 2);
  4887. widthScale /= paintWidth / newWidth;
  4888. }
  4889. if (heightScale > 2 && paintHeight > 1) {
  4890. newHeight = Math.ceil(paintHeight / 2);
  4891. heightScale /= paintHeight / newHeight;
  4892. }
  4893. tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight, false);
  4894. tmpCtx = tmpCanvas.context;
  4895. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  4896. tmpCtx.drawImage(img, 0, 0, paintWidth, paintHeight, 0, 0, newWidth, newHeight);
  4897. img = tmpCanvas.canvas;
  4898. paintWidth = newWidth;
  4899. paintHeight = newHeight;
  4900. tmpCanvasId = tmpCanvasId === "prescale1" ? "prescale2" : "prescale1";
  4901. }
  4902. return {
  4903. img,
  4904. paintWidth,
  4905. paintHeight
  4906. };
  4907. }
  4908. _createMaskCanvas(img) {
  4909. const ctx = this.ctx;
  4910. const {
  4911. width,
  4912. height
  4913. } = img;
  4914. const fillColor = this.current.fillColor;
  4915. const isPatternFill = this.current.patternFill;
  4916. const currentTransform = ctx.mozCurrentTransform;
  4917. let cache, cacheKey, scaled, maskCanvas;
  4918. if ((img.bitmap || img.data) && img.count > 1) {
  4919. const mainKey = img.bitmap || img.data.buffer;
  4920. const withoutTranslation = currentTransform.slice(0, 4);
  4921. cacheKey = JSON.stringify(isPatternFill ? withoutTranslation : [withoutTranslation, fillColor]);
  4922. cache = this._cachedBitmapsMap.get(mainKey);
  4923. if (!cache) {
  4924. cache = new Map();
  4925. this._cachedBitmapsMap.set(mainKey, cache);
  4926. }
  4927. const cachedImage = cache.get(cacheKey);
  4928. if (cachedImage && !isPatternFill) {
  4929. const offsetX = Math.round(Math.min(currentTransform[0], currentTransform[2]) + currentTransform[4]);
  4930. const offsetY = Math.round(Math.min(currentTransform[1], currentTransform[3]) + currentTransform[5]);
  4931. return {
  4932. canvas: cachedImage,
  4933. offsetX,
  4934. offsetY
  4935. };
  4936. }
  4937. scaled = cachedImage;
  4938. }
  4939. if (!scaled) {
  4940. maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height, false);
  4941. putBinaryImageMask(maskCanvas.context, img);
  4942. }
  4943. let maskToCanvas = _util.Util.transform(currentTransform, [1 / width, 0, 0, -1 / height, 0, 0]);
  4944. maskToCanvas = _util.Util.transform(maskToCanvas, [1, 0, 0, 1, 0, -height]);
  4945. const cord1 = _util.Util.applyTransform([0, 0], maskToCanvas);
  4946. const cord2 = _util.Util.applyTransform([width, height], maskToCanvas);
  4947. const rect = _util.Util.normalizeRect([cord1[0], cord1[1], cord2[0], cord2[1]]);
  4948. const drawnWidth = Math.round(rect[2] - rect[0]) || 1;
  4949. const drawnHeight = Math.round(rect[3] - rect[1]) || 1;
  4950. const fillCanvas = this.cachedCanvases.getCanvas("fillCanvas", drawnWidth, drawnHeight, true);
  4951. const fillCtx = fillCanvas.context;
  4952. const offsetX = Math.min(cord1[0], cord2[0]);
  4953. const offsetY = Math.min(cord1[1], cord2[1]);
  4954. fillCtx.translate(-offsetX, -offsetY);
  4955. fillCtx.transform.apply(fillCtx, maskToCanvas);
  4956. if (!scaled) {
  4957. scaled = this._scaleImage(maskCanvas.canvas, fillCtx.mozCurrentTransformInverse);
  4958. scaled = scaled.img;
  4959. if (cache && isPatternFill) {
  4960. cache.set(cacheKey, scaled);
  4961. }
  4962. }
  4963. fillCtx.imageSmoothingEnabled = getImageSmoothingEnabled(fillCtx.mozCurrentTransform, img.interpolate);
  4964. drawImageAtIntegerCoords(fillCtx, scaled, 0, 0, scaled.width, scaled.height, 0, 0, width, height);
  4965. fillCtx.globalCompositeOperation = "source-in";
  4966. const inverse = _util.Util.transform(fillCtx.mozCurrentTransformInverse, [1, 0, 0, 1, -offsetX, -offsetY]);
  4967. fillCtx.fillStyle = isPatternFill ? fillColor.getPattern(ctx, this, inverse, _pattern_helper.PathType.FILL) : fillColor;
  4968. fillCtx.fillRect(0, 0, width, height);
  4969. if (cache && !isPatternFill) {
  4970. this.cachedCanvases.delete("fillCanvas");
  4971. cache.set(cacheKey, fillCanvas.canvas);
  4972. }
  4973. return {
  4974. canvas: fillCanvas.canvas,
  4975. offsetX: Math.round(offsetX),
  4976. offsetY: Math.round(offsetY)
  4977. };
  4978. }
  4979. setLineWidth(width) {
  4980. if (width !== this.current.lineWidth) {
  4981. this._cachedScaleForStroking = null;
  4982. }
  4983. this.current.lineWidth = width;
  4984. this.ctx.lineWidth = width;
  4985. }
  4986. setLineCap(style) {
  4987. this.ctx.lineCap = LINE_CAP_STYLES[style];
  4988. }
  4989. setLineJoin(style) {
  4990. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  4991. }
  4992. setMiterLimit(limit) {
  4993. this.ctx.miterLimit = limit;
  4994. }
  4995. setDash(dashArray, dashPhase) {
  4996. const ctx = this.ctx;
  4997. if (ctx.setLineDash !== undefined) {
  4998. ctx.setLineDash(dashArray);
  4999. ctx.lineDashOffset = dashPhase;
  5000. }
  5001. }
  5002. setRenderingIntent(intent) {}
  5003. setFlatness(flatness) {}
  5004. setGState(states) {
  5005. for (let i = 0, ii = states.length; i < ii; i++) {
  5006. const state = states[i];
  5007. const key = state[0];
  5008. const value = state[1];
  5009. switch (key) {
  5010. case "LW":
  5011. this.setLineWidth(value);
  5012. break;
  5013. case "LC":
  5014. this.setLineCap(value);
  5015. break;
  5016. case "LJ":
  5017. this.setLineJoin(value);
  5018. break;
  5019. case "ML":
  5020. this.setMiterLimit(value);
  5021. break;
  5022. case "D":
  5023. this.setDash(value[0], value[1]);
  5024. break;
  5025. case "RI":
  5026. this.setRenderingIntent(value);
  5027. break;
  5028. case "FL":
  5029. this.setFlatness(value);
  5030. break;
  5031. case "Font":
  5032. this.setFont(value[0], value[1]);
  5033. break;
  5034. case "CA":
  5035. this.current.strokeAlpha = state[1];
  5036. break;
  5037. case "ca":
  5038. this.current.fillAlpha = state[1];
  5039. this.ctx.globalAlpha = state[1];
  5040. break;
  5041. case "BM":
  5042. this.ctx.globalCompositeOperation = value;
  5043. break;
  5044. case "SMask":
  5045. this.current.activeSMask = value ? this.tempSMask : null;
  5046. this.tempSMask = null;
  5047. this.checkSMaskState();
  5048. break;
  5049. case "TR":
  5050. this.current.transferMaps = value;
  5051. }
  5052. }
  5053. }
  5054. get inSMaskMode() {
  5055. return !!this.suspendedCtx;
  5056. }
  5057. checkSMaskState() {
  5058. const inSMaskMode = this.inSMaskMode;
  5059. if (this.current.activeSMask && !inSMaskMode) {
  5060. this.beginSMaskMode();
  5061. } else if (!this.current.activeSMask && inSMaskMode) {
  5062. this.endSMaskMode();
  5063. }
  5064. }
  5065. beginSMaskMode() {
  5066. if (this.inSMaskMode) {
  5067. throw new Error("beginSMaskMode called while already in smask mode");
  5068. }
  5069. const drawnWidth = this.ctx.canvas.width;
  5070. const drawnHeight = this.ctx.canvas.height;
  5071. const cacheId = "smaskGroupAt" + this.groupLevel;
  5072. const scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true);
  5073. this.suspendedCtx = this.ctx;
  5074. this.ctx = scratchCanvas.context;
  5075. const ctx = this.ctx;
  5076. ctx.setTransform.apply(ctx, this.suspendedCtx.mozCurrentTransform);
  5077. copyCtxState(this.suspendedCtx, ctx);
  5078. mirrorContextOperations(ctx, this.suspendedCtx);
  5079. this.setGState([["BM", "source-over"], ["ca", 1], ["CA", 1]]);
  5080. }
  5081. endSMaskMode() {
  5082. if (!this.inSMaskMode) {
  5083. throw new Error("endSMaskMode called while not in smask mode");
  5084. }
  5085. this.ctx._removeMirroring();
  5086. copyCtxState(this.ctx, this.suspendedCtx);
  5087. this.ctx = this.suspendedCtx;
  5088. this.suspendedCtx = null;
  5089. }
  5090. compose(dirtyBox) {
  5091. if (!this.current.activeSMask) {
  5092. return;
  5093. }
  5094. if (!dirtyBox) {
  5095. dirtyBox = [0, 0, this.ctx.canvas.width, this.ctx.canvas.height];
  5096. } else {
  5097. dirtyBox[0] = Math.floor(dirtyBox[0]);
  5098. dirtyBox[1] = Math.floor(dirtyBox[1]);
  5099. dirtyBox[2] = Math.ceil(dirtyBox[2]);
  5100. dirtyBox[3] = Math.ceil(dirtyBox[3]);
  5101. }
  5102. const smask = this.current.activeSMask;
  5103. const suspendedCtx = this.suspendedCtx;
  5104. composeSMask(suspendedCtx, smask, this.ctx, dirtyBox);
  5105. this.ctx.save();
  5106. this.ctx.setTransform(1, 0, 0, 1, 0, 0);
  5107. this.ctx.clearRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height);
  5108. this.ctx.restore();
  5109. }
  5110. save() {
  5111. if (this.inSMaskMode) {
  5112. copyCtxState(this.ctx, this.suspendedCtx);
  5113. this.suspendedCtx.save();
  5114. } else {
  5115. this.ctx.save();
  5116. }
  5117. const old = this.current;
  5118. this.stateStack.push(old);
  5119. this.current = old.clone();
  5120. }
  5121. restore() {
  5122. if (this.stateStack.length === 0 && this.inSMaskMode) {
  5123. this.endSMaskMode();
  5124. }
  5125. if (this.stateStack.length !== 0) {
  5126. this.current = this.stateStack.pop();
  5127. if (this.inSMaskMode) {
  5128. this.suspendedCtx.restore();
  5129. copyCtxState(this.suspendedCtx, this.ctx);
  5130. } else {
  5131. this.ctx.restore();
  5132. }
  5133. this.checkSMaskState();
  5134. this.pendingClip = null;
  5135. this._cachedScaleForStroking = null;
  5136. this._cachedGetSinglePixelWidth = null;
  5137. }
  5138. }
  5139. transform(a, b, c, d, e, f) {
  5140. this.ctx.transform(a, b, c, d, e, f);
  5141. this._cachedScaleForStroking = null;
  5142. this._cachedGetSinglePixelWidth = null;
  5143. }
  5144. constructPath(ops, args, minMax) {
  5145. const ctx = this.ctx;
  5146. const current = this.current;
  5147. let x = current.x,
  5148. y = current.y;
  5149. let startX, startY;
  5150. const currentTransform = ctx.mozCurrentTransform;
  5151. const isScalingMatrix = currentTransform[0] === 0 && currentTransform[3] === 0 || currentTransform[1] === 0 && currentTransform[2] === 0;
  5152. const minMaxForBezier = isScalingMatrix ? minMax.slice(0) : null;
  5153. for (let i = 0, j = 0, ii = ops.length; i < ii; i++) {
  5154. switch (ops[i] | 0) {
  5155. case _util.OPS.rectangle:
  5156. x = args[j++];
  5157. y = args[j++];
  5158. const width = args[j++];
  5159. const height = args[j++];
  5160. const xw = x + width;
  5161. const yh = y + height;
  5162. ctx.moveTo(x, y);
  5163. if (width === 0 || height === 0) {
  5164. ctx.lineTo(xw, yh);
  5165. } else {
  5166. ctx.lineTo(xw, y);
  5167. ctx.lineTo(xw, yh);
  5168. ctx.lineTo(x, yh);
  5169. }
  5170. if (!isScalingMatrix) {
  5171. current.updateRectMinMax(currentTransform, [x, y, xw, yh]);
  5172. }
  5173. ctx.closePath();
  5174. break;
  5175. case _util.OPS.moveTo:
  5176. x = args[j++];
  5177. y = args[j++];
  5178. ctx.moveTo(x, y);
  5179. if (!isScalingMatrix) {
  5180. current.updatePathMinMax(currentTransform, x, y);
  5181. }
  5182. break;
  5183. case _util.OPS.lineTo:
  5184. x = args[j++];
  5185. y = args[j++];
  5186. ctx.lineTo(x, y);
  5187. if (!isScalingMatrix) {
  5188. current.updatePathMinMax(currentTransform, x, y);
  5189. }
  5190. break;
  5191. case _util.OPS.curveTo:
  5192. startX = x;
  5193. startY = y;
  5194. x = args[j + 4];
  5195. y = args[j + 5];
  5196. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3], x, y);
  5197. current.updateCurvePathMinMax(currentTransform, startX, startY, args[j], args[j + 1], args[j + 2], args[j + 3], x, y, minMaxForBezier);
  5198. j += 6;
  5199. break;
  5200. case _util.OPS.curveTo2:
  5201. startX = x;
  5202. startY = y;
  5203. ctx.bezierCurveTo(x, y, args[j], args[j + 1], args[j + 2], args[j + 3]);
  5204. current.updateCurvePathMinMax(currentTransform, startX, startY, x, y, args[j], args[j + 1], args[j + 2], args[j + 3], minMaxForBezier);
  5205. x = args[j + 2];
  5206. y = args[j + 3];
  5207. j += 4;
  5208. break;
  5209. case _util.OPS.curveTo3:
  5210. startX = x;
  5211. startY = y;
  5212. x = args[j + 2];
  5213. y = args[j + 3];
  5214. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  5215. current.updateCurvePathMinMax(currentTransform, startX, startY, args[j], args[j + 1], x, y, x, y, minMaxForBezier);
  5216. j += 4;
  5217. break;
  5218. case _util.OPS.closePath:
  5219. ctx.closePath();
  5220. break;
  5221. }
  5222. }
  5223. if (isScalingMatrix) {
  5224. current.updateScalingPathMinMax(currentTransform, minMaxForBezier);
  5225. }
  5226. current.setCurrentPoint(x, y);
  5227. }
  5228. closePath() {
  5229. this.ctx.closePath();
  5230. }
  5231. stroke(consumePath) {
  5232. consumePath = typeof consumePath !== "undefined" ? consumePath : true;
  5233. const ctx = this.ctx;
  5234. const strokeColor = this.current.strokeColor;
  5235. ctx.globalAlpha = this.current.strokeAlpha;
  5236. if (this.contentVisible) {
  5237. if (typeof strokeColor === "object" && strokeColor?.getPattern) {
  5238. ctx.save();
  5239. ctx.strokeStyle = strokeColor.getPattern(ctx, this, ctx.mozCurrentTransformInverse, _pattern_helper.PathType.STROKE);
  5240. this.rescaleAndStroke(false);
  5241. ctx.restore();
  5242. } else {
  5243. this.rescaleAndStroke(true);
  5244. }
  5245. }
  5246. if (consumePath) {
  5247. this.consumePath(this.current.getClippedPathBoundingBox());
  5248. }
  5249. ctx.globalAlpha = this.current.fillAlpha;
  5250. }
  5251. closeStroke() {
  5252. this.closePath();
  5253. this.stroke();
  5254. }
  5255. fill(consumePath) {
  5256. consumePath = typeof consumePath !== "undefined" ? consumePath : true;
  5257. const ctx = this.ctx;
  5258. const fillColor = this.current.fillColor;
  5259. const isPatternFill = this.current.patternFill;
  5260. let needRestore = false;
  5261. if (isPatternFill) {
  5262. ctx.save();
  5263. ctx.fillStyle = fillColor.getPattern(ctx, this, ctx.mozCurrentTransformInverse, _pattern_helper.PathType.FILL);
  5264. needRestore = true;
  5265. }
  5266. const intersect = this.current.getClippedPathBoundingBox();
  5267. if (this.contentVisible && intersect !== null) {
  5268. if (this.pendingEOFill) {
  5269. ctx.fill("evenodd");
  5270. this.pendingEOFill = false;
  5271. } else {
  5272. ctx.fill();
  5273. }
  5274. }
  5275. if (needRestore) {
  5276. ctx.restore();
  5277. }
  5278. if (consumePath) {
  5279. this.consumePath(intersect);
  5280. }
  5281. }
  5282. eoFill() {
  5283. this.pendingEOFill = true;
  5284. this.fill();
  5285. }
  5286. fillStroke() {
  5287. this.fill(false);
  5288. this.stroke(false);
  5289. this.consumePath();
  5290. }
  5291. eoFillStroke() {
  5292. this.pendingEOFill = true;
  5293. this.fillStroke();
  5294. }
  5295. closeFillStroke() {
  5296. this.closePath();
  5297. this.fillStroke();
  5298. }
  5299. closeEOFillStroke() {
  5300. this.pendingEOFill = true;
  5301. this.closePath();
  5302. this.fillStroke();
  5303. }
  5304. endPath() {
  5305. this.consumePath();
  5306. }
  5307. clip() {
  5308. this.pendingClip = NORMAL_CLIP;
  5309. }
  5310. eoClip() {
  5311. this.pendingClip = EO_CLIP;
  5312. }
  5313. beginText() {
  5314. this.current.textMatrix = _util.IDENTITY_MATRIX;
  5315. this.current.textMatrixScale = 1;
  5316. this.current.x = this.current.lineX = 0;
  5317. this.current.y = this.current.lineY = 0;
  5318. }
  5319. endText() {
  5320. const paths = this.pendingTextPaths;
  5321. const ctx = this.ctx;
  5322. if (paths === undefined) {
  5323. ctx.beginPath();
  5324. return;
  5325. }
  5326. ctx.save();
  5327. ctx.beginPath();
  5328. for (let i = 0; i < paths.length; i++) {
  5329. const path = paths[i];
  5330. ctx.setTransform.apply(ctx, path.transform);
  5331. ctx.translate(path.x, path.y);
  5332. path.addToPath(ctx, path.fontSize);
  5333. }
  5334. ctx.restore();
  5335. ctx.clip();
  5336. ctx.beginPath();
  5337. delete this.pendingTextPaths;
  5338. }
  5339. setCharSpacing(spacing) {
  5340. this.current.charSpacing = spacing;
  5341. }
  5342. setWordSpacing(spacing) {
  5343. this.current.wordSpacing = spacing;
  5344. }
  5345. setHScale(scale) {
  5346. this.current.textHScale = scale / 100;
  5347. }
  5348. setLeading(leading) {
  5349. this.current.leading = -leading;
  5350. }
  5351. setFont(fontRefName, size) {
  5352. const fontObj = this.commonObjs.get(fontRefName);
  5353. const current = this.current;
  5354. if (!fontObj) {
  5355. throw new Error(`Can't find font for ${fontRefName}`);
  5356. }
  5357. current.fontMatrix = fontObj.fontMatrix || _util.FONT_IDENTITY_MATRIX;
  5358. if (current.fontMatrix[0] === 0 || current.fontMatrix[3] === 0) {
  5359. (0, _util.warn)("Invalid font matrix for font " + fontRefName);
  5360. }
  5361. if (size < 0) {
  5362. size = -size;
  5363. current.fontDirection = -1;
  5364. } else {
  5365. current.fontDirection = 1;
  5366. }
  5367. this.current.font = fontObj;
  5368. this.current.fontSize = size;
  5369. if (fontObj.isType3Font) {
  5370. return;
  5371. }
  5372. const name = fontObj.loadedName || "sans-serif";
  5373. let bold = "normal";
  5374. if (fontObj.black) {
  5375. bold = "900";
  5376. } else if (fontObj.bold) {
  5377. bold = "bold";
  5378. }
  5379. const italic = fontObj.italic ? "italic" : "normal";
  5380. const typeface = `"${name}", ${fontObj.fallbackName}`;
  5381. let browserFontSize = size;
  5382. if (size < MIN_FONT_SIZE) {
  5383. browserFontSize = MIN_FONT_SIZE;
  5384. } else if (size > MAX_FONT_SIZE) {
  5385. browserFontSize = MAX_FONT_SIZE;
  5386. }
  5387. this.current.fontSizeScale = size / browserFontSize;
  5388. this.ctx.font = `${italic} ${bold} ${browserFontSize}px ${typeface}`;
  5389. }
  5390. setTextRenderingMode(mode) {
  5391. this.current.textRenderingMode = mode;
  5392. }
  5393. setTextRise(rise) {
  5394. this.current.textRise = rise;
  5395. }
  5396. moveText(x, y) {
  5397. this.current.x = this.current.lineX += x;
  5398. this.current.y = this.current.lineY += y;
  5399. }
  5400. setLeadingMoveText(x, y) {
  5401. this.setLeading(-y);
  5402. this.moveText(x, y);
  5403. }
  5404. setTextMatrix(a, b, c, d, e, f) {
  5405. this.current.textMatrix = [a, b, c, d, e, f];
  5406. this.current.textMatrixScale = Math.hypot(a, b);
  5407. this.current.x = this.current.lineX = 0;
  5408. this.current.y = this.current.lineY = 0;
  5409. }
  5410. nextLine() {
  5411. this.moveText(0, this.current.leading);
  5412. }
  5413. paintChar(character, x, y, patternTransform) {
  5414. const ctx = this.ctx;
  5415. const current = this.current;
  5416. const font = current.font;
  5417. const textRenderingMode = current.textRenderingMode;
  5418. const fontSize = current.fontSize / current.fontSizeScale;
  5419. const fillStrokeMode = textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  5420. const isAddToPathSet = !!(textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG);
  5421. const patternFill = current.patternFill && !font.missingFile;
  5422. let addToPath;
  5423. if (font.disableFontFace || isAddToPathSet || patternFill) {
  5424. addToPath = font.getPathGenerator(this.commonObjs, character);
  5425. }
  5426. if (font.disableFontFace || patternFill) {
  5427. ctx.save();
  5428. ctx.translate(x, y);
  5429. ctx.beginPath();
  5430. addToPath(ctx, fontSize);
  5431. if (patternTransform) {
  5432. ctx.setTransform.apply(ctx, patternTransform);
  5433. }
  5434. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  5435. ctx.fill();
  5436. }
  5437. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  5438. ctx.stroke();
  5439. }
  5440. ctx.restore();
  5441. } else {
  5442. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  5443. ctx.fillText(character, x, y);
  5444. }
  5445. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  5446. ctx.strokeText(character, x, y);
  5447. }
  5448. }
  5449. if (isAddToPathSet) {
  5450. const paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  5451. paths.push({
  5452. transform: ctx.mozCurrentTransform,
  5453. x,
  5454. y,
  5455. fontSize,
  5456. addToPath
  5457. });
  5458. }
  5459. }
  5460. get isFontSubpixelAAEnabled() {
  5461. const {
  5462. context: ctx
  5463. } = this.cachedCanvases.getCanvas("isFontSubpixelAAEnabled", 10, 10, false);
  5464. ctx.scale(1.5, 1);
  5465. ctx.fillText("I", 0, 10);
  5466. const data = ctx.getImageData(0, 0, 10, 10).data;
  5467. let enabled = false;
  5468. for (let i = 3; i < data.length; i += 4) {
  5469. if (data[i] > 0 && data[i] < 255) {
  5470. enabled = true;
  5471. break;
  5472. }
  5473. }
  5474. return (0, _util.shadow)(this, "isFontSubpixelAAEnabled", enabled);
  5475. }
  5476. showText(glyphs) {
  5477. const current = this.current;
  5478. const font = current.font;
  5479. if (font.isType3Font) {
  5480. return this.showType3Text(glyphs);
  5481. }
  5482. const fontSize = current.fontSize;
  5483. if (fontSize === 0) {
  5484. return undefined;
  5485. }
  5486. const ctx = this.ctx;
  5487. const fontSizeScale = current.fontSizeScale;
  5488. const charSpacing = current.charSpacing;
  5489. const wordSpacing = current.wordSpacing;
  5490. const fontDirection = current.fontDirection;
  5491. const textHScale = current.textHScale * fontDirection;
  5492. const glyphsLength = glyphs.length;
  5493. const vertical = font.vertical;
  5494. const spacingDir = vertical ? 1 : -1;
  5495. const defaultVMetrics = font.defaultVMetrics;
  5496. const widthAdvanceScale = fontSize * current.fontMatrix[0];
  5497. const simpleFillText = current.textRenderingMode === _util.TextRenderingMode.FILL && !font.disableFontFace && !current.patternFill;
  5498. ctx.save();
  5499. ctx.transform.apply(ctx, current.textMatrix);
  5500. ctx.translate(current.x, current.y + current.textRise);
  5501. if (fontDirection > 0) {
  5502. ctx.scale(textHScale, -1);
  5503. } else {
  5504. ctx.scale(textHScale, 1);
  5505. }
  5506. let patternTransform;
  5507. if (current.patternFill) {
  5508. ctx.save();
  5509. const pattern = current.fillColor.getPattern(ctx, this, ctx.mozCurrentTransformInverse, _pattern_helper.PathType.FILL);
  5510. patternTransform = ctx.mozCurrentTransform;
  5511. ctx.restore();
  5512. ctx.fillStyle = pattern;
  5513. }
  5514. let lineWidth = current.lineWidth;
  5515. const scale = current.textMatrixScale;
  5516. if (scale === 0 || lineWidth === 0) {
  5517. const fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  5518. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  5519. lineWidth = this.getSinglePixelWidth();
  5520. }
  5521. } else {
  5522. lineWidth /= scale;
  5523. }
  5524. if (fontSizeScale !== 1.0) {
  5525. ctx.scale(fontSizeScale, fontSizeScale);
  5526. lineWidth /= fontSizeScale;
  5527. }
  5528. ctx.lineWidth = lineWidth;
  5529. let x = 0,
  5530. i;
  5531. for (i = 0; i < glyphsLength; ++i) {
  5532. const glyph = glyphs[i];
  5533. if (typeof glyph === "number") {
  5534. x += spacingDir * glyph * fontSize / 1000;
  5535. continue;
  5536. }
  5537. let restoreNeeded = false;
  5538. const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  5539. const character = glyph.fontChar;
  5540. const accent = glyph.accent;
  5541. let scaledX, scaledY;
  5542. let width = glyph.width;
  5543. if (vertical) {
  5544. const vmetric = glyph.vmetric || defaultVMetrics;
  5545. const vx = -(glyph.vmetric ? vmetric[1] : width * 0.5) * widthAdvanceScale;
  5546. const vy = vmetric[2] * widthAdvanceScale;
  5547. width = vmetric ? -vmetric[0] : width;
  5548. scaledX = vx / fontSizeScale;
  5549. scaledY = (x + vy) / fontSizeScale;
  5550. } else {
  5551. scaledX = x / fontSizeScale;
  5552. scaledY = 0;
  5553. }
  5554. if (font.remeasure && width > 0) {
  5555. const measuredWidth = ctx.measureText(character).width * 1000 / fontSize * fontSizeScale;
  5556. if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
  5557. const characterScaleX = width / measuredWidth;
  5558. restoreNeeded = true;
  5559. ctx.save();
  5560. ctx.scale(characterScaleX, 1);
  5561. scaledX /= characterScaleX;
  5562. } else if (width !== measuredWidth) {
  5563. scaledX += (width - measuredWidth) / 2000 * fontSize / fontSizeScale;
  5564. }
  5565. }
  5566. if (this.contentVisible && (glyph.isInFont || font.missingFile)) {
  5567. if (simpleFillText && !accent) {
  5568. ctx.fillText(character, scaledX, scaledY);
  5569. } else {
  5570. this.paintChar(character, scaledX, scaledY, patternTransform);
  5571. if (accent) {
  5572. const scaledAccentX = scaledX + fontSize * accent.offset.x / fontSizeScale;
  5573. const scaledAccentY = scaledY - fontSize * accent.offset.y / fontSizeScale;
  5574. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY, patternTransform);
  5575. }
  5576. }
  5577. }
  5578. let charWidth;
  5579. if (vertical) {
  5580. charWidth = width * widthAdvanceScale - spacing * fontDirection;
  5581. } else {
  5582. charWidth = width * widthAdvanceScale + spacing * fontDirection;
  5583. }
  5584. x += charWidth;
  5585. if (restoreNeeded) {
  5586. ctx.restore();
  5587. }
  5588. }
  5589. if (vertical) {
  5590. current.y -= x;
  5591. } else {
  5592. current.x += x * textHScale;
  5593. }
  5594. ctx.restore();
  5595. this.compose();
  5596. return undefined;
  5597. }
  5598. showType3Text(glyphs) {
  5599. const ctx = this.ctx;
  5600. const current = this.current;
  5601. const font = current.font;
  5602. const fontSize = current.fontSize;
  5603. const fontDirection = current.fontDirection;
  5604. const spacingDir = font.vertical ? 1 : -1;
  5605. const charSpacing = current.charSpacing;
  5606. const wordSpacing = current.wordSpacing;
  5607. const textHScale = current.textHScale * fontDirection;
  5608. const fontMatrix = current.fontMatrix || _util.FONT_IDENTITY_MATRIX;
  5609. const glyphsLength = glyphs.length;
  5610. const isTextInvisible = current.textRenderingMode === _util.TextRenderingMode.INVISIBLE;
  5611. let i, glyph, width, spacingLength;
  5612. if (isTextInvisible || fontSize === 0) {
  5613. return;
  5614. }
  5615. this._cachedScaleForStroking = null;
  5616. this._cachedGetSinglePixelWidth = null;
  5617. ctx.save();
  5618. ctx.transform.apply(ctx, current.textMatrix);
  5619. ctx.translate(current.x, current.y);
  5620. ctx.scale(textHScale, fontDirection);
  5621. for (i = 0; i < glyphsLength; ++i) {
  5622. glyph = glyphs[i];
  5623. if (typeof glyph === "number") {
  5624. spacingLength = spacingDir * glyph * fontSize / 1000;
  5625. this.ctx.translate(spacingLength, 0);
  5626. current.x += spacingLength * textHScale;
  5627. continue;
  5628. }
  5629. const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  5630. const operatorList = font.charProcOperatorList[glyph.operatorListId];
  5631. if (!operatorList) {
  5632. (0, _util.warn)(`Type3 character "${glyph.operatorListId}" is not available.`);
  5633. continue;
  5634. }
  5635. if (this.contentVisible) {
  5636. this.processingType3 = glyph;
  5637. this.save();
  5638. ctx.scale(fontSize, fontSize);
  5639. ctx.transform.apply(ctx, fontMatrix);
  5640. this.executeOperatorList(operatorList);
  5641. this.restore();
  5642. }
  5643. const transformed = _util.Util.applyTransform([glyph.width, 0], fontMatrix);
  5644. width = transformed[0] * fontSize + spacing;
  5645. ctx.translate(width, 0);
  5646. current.x += width * textHScale;
  5647. }
  5648. ctx.restore();
  5649. this.processingType3 = null;
  5650. }
  5651. setCharWidth(xWidth, yWidth) {}
  5652. setCharWidthAndBounds(xWidth, yWidth, llx, lly, urx, ury) {
  5653. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  5654. this.ctx.clip();
  5655. this.endPath();
  5656. }
  5657. getColorN_Pattern(IR) {
  5658. let pattern;
  5659. if (IR[0] === "TilingPattern") {
  5660. const color = IR[1];
  5661. const baseTransform = this.baseTransform || this.ctx.mozCurrentTransform.slice();
  5662. const canvasGraphicsFactory = {
  5663. createCanvasGraphics: ctx => {
  5664. return new CanvasGraphics(ctx, this.commonObjs, this.objs, this.canvasFactory);
  5665. }
  5666. };
  5667. pattern = new _pattern_helper.TilingPattern(IR, color, this.ctx, canvasGraphicsFactory, baseTransform);
  5668. } else {
  5669. pattern = this._getPattern(IR[1], IR[2]);
  5670. }
  5671. return pattern;
  5672. }
  5673. setStrokeColorN() {
  5674. this.current.strokeColor = this.getColorN_Pattern(arguments);
  5675. }
  5676. setFillColorN() {
  5677. this.current.fillColor = this.getColorN_Pattern(arguments);
  5678. this.current.patternFill = true;
  5679. }
  5680. setStrokeRGBColor(r, g, b) {
  5681. const color = this.selectColor?.(r, g, b) || _util.Util.makeHexColor(r, g, b);
  5682. this.ctx.strokeStyle = color;
  5683. this.current.strokeColor = color;
  5684. }
  5685. setFillRGBColor(r, g, b) {
  5686. const color = this.selectColor?.(r, g, b) || _util.Util.makeHexColor(r, g, b);
  5687. this.ctx.fillStyle = color;
  5688. this.current.fillColor = color;
  5689. this.current.patternFill = false;
  5690. }
  5691. _getPattern(objId, matrix = null) {
  5692. let pattern;
  5693. if (this.cachedPatterns.has(objId)) {
  5694. pattern = this.cachedPatterns.get(objId);
  5695. } else {
  5696. pattern = (0, _pattern_helper.getShadingPattern)(this.objs.get(objId));
  5697. this.cachedPatterns.set(objId, pattern);
  5698. }
  5699. if (matrix) {
  5700. pattern.matrix = matrix;
  5701. }
  5702. return pattern;
  5703. }
  5704. shadingFill(objId) {
  5705. if (!this.contentVisible) {
  5706. return;
  5707. }
  5708. const ctx = this.ctx;
  5709. this.save();
  5710. const pattern = this._getPattern(objId);
  5711. ctx.fillStyle = pattern.getPattern(ctx, this, ctx.mozCurrentTransformInverse, _pattern_helper.PathType.SHADING);
  5712. const inv = ctx.mozCurrentTransformInverse;
  5713. if (inv) {
  5714. const canvas = ctx.canvas;
  5715. const width = canvas.width;
  5716. const height = canvas.height;
  5717. const bl = _util.Util.applyTransform([0, 0], inv);
  5718. const br = _util.Util.applyTransform([0, height], inv);
  5719. const ul = _util.Util.applyTransform([width, 0], inv);
  5720. const ur = _util.Util.applyTransform([width, height], inv);
  5721. const x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  5722. const y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  5723. const x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  5724. const y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  5725. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  5726. } else {
  5727. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  5728. }
  5729. this.compose(this.current.getClippedPathBoundingBox());
  5730. this.restore();
  5731. }
  5732. beginInlineImage() {
  5733. (0, _util.unreachable)("Should not call beginInlineImage");
  5734. }
  5735. beginImageData() {
  5736. (0, _util.unreachable)("Should not call beginImageData");
  5737. }
  5738. paintFormXObjectBegin(matrix, bbox) {
  5739. if (!this.contentVisible) {
  5740. return;
  5741. }
  5742. this.save();
  5743. this.baseTransformStack.push(this.baseTransform);
  5744. if (Array.isArray(matrix) && matrix.length === 6) {
  5745. this.transform.apply(this, matrix);
  5746. }
  5747. this.baseTransform = this.ctx.mozCurrentTransform;
  5748. if (bbox) {
  5749. const width = bbox[2] - bbox[0];
  5750. const height = bbox[3] - bbox[1];
  5751. this.ctx.rect(bbox[0], bbox[1], width, height);
  5752. this.current.updateRectMinMax(this.ctx.mozCurrentTransform, bbox);
  5753. this.clip();
  5754. this.endPath();
  5755. }
  5756. }
  5757. paintFormXObjectEnd() {
  5758. if (!this.contentVisible) {
  5759. return;
  5760. }
  5761. this.restore();
  5762. this.baseTransform = this.baseTransformStack.pop();
  5763. }
  5764. beginGroup(group) {
  5765. if (!this.contentVisible) {
  5766. return;
  5767. }
  5768. this.save();
  5769. if (this.inSMaskMode) {
  5770. this.endSMaskMode();
  5771. this.current.activeSMask = null;
  5772. }
  5773. const currentCtx = this.ctx;
  5774. if (!group.isolated) {
  5775. (0, _util.info)("TODO: Support non-isolated groups.");
  5776. }
  5777. if (group.knockout) {
  5778. (0, _util.warn)("Knockout groups not supported.");
  5779. }
  5780. const currentTransform = currentCtx.mozCurrentTransform;
  5781. if (group.matrix) {
  5782. currentCtx.transform.apply(currentCtx, group.matrix);
  5783. }
  5784. if (!group.bbox) {
  5785. throw new Error("Bounding box is required.");
  5786. }
  5787. let bounds = _util.Util.getAxialAlignedBoundingBox(group.bbox, currentCtx.mozCurrentTransform);
  5788. const canvasBounds = [0, 0, currentCtx.canvas.width, currentCtx.canvas.height];
  5789. bounds = _util.Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  5790. const offsetX = Math.floor(bounds[0]);
  5791. const offsetY = Math.floor(bounds[1]);
  5792. let drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  5793. let drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  5794. let scaleX = 1,
  5795. scaleY = 1;
  5796. if (drawnWidth > MAX_GROUP_SIZE) {
  5797. scaleX = drawnWidth / MAX_GROUP_SIZE;
  5798. drawnWidth = MAX_GROUP_SIZE;
  5799. }
  5800. if (drawnHeight > MAX_GROUP_SIZE) {
  5801. scaleY = drawnHeight / MAX_GROUP_SIZE;
  5802. drawnHeight = MAX_GROUP_SIZE;
  5803. }
  5804. this.current.startNewPathAndClipBox([0, 0, drawnWidth, drawnHeight]);
  5805. let cacheId = "groupAt" + this.groupLevel;
  5806. if (group.smask) {
  5807. cacheId += "_smask_" + this.smaskCounter++ % 2;
  5808. }
  5809. const scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true);
  5810. const groupCtx = scratchCanvas.context;
  5811. groupCtx.scale(1 / scaleX, 1 / scaleY);
  5812. groupCtx.translate(-offsetX, -offsetY);
  5813. groupCtx.transform.apply(groupCtx, currentTransform);
  5814. if (group.smask) {
  5815. this.smaskStack.push({
  5816. canvas: scratchCanvas.canvas,
  5817. context: groupCtx,
  5818. offsetX,
  5819. offsetY,
  5820. scaleX,
  5821. scaleY,
  5822. subtype: group.smask.subtype,
  5823. backdrop: group.smask.backdrop,
  5824. transferMap: group.smask.transferMap || null,
  5825. startTransformInverse: null
  5826. });
  5827. } else {
  5828. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  5829. currentCtx.translate(offsetX, offsetY);
  5830. currentCtx.scale(scaleX, scaleY);
  5831. currentCtx.save();
  5832. }
  5833. copyCtxState(currentCtx, groupCtx);
  5834. this.ctx = groupCtx;
  5835. this.setGState([["BM", "source-over"], ["ca", 1], ["CA", 1]]);
  5836. this.groupStack.push(currentCtx);
  5837. this.groupLevel++;
  5838. }
  5839. endGroup(group) {
  5840. if (!this.contentVisible) {
  5841. return;
  5842. }
  5843. this.groupLevel--;
  5844. const groupCtx = this.ctx;
  5845. const ctx = this.groupStack.pop();
  5846. this.ctx = ctx;
  5847. this.ctx.imageSmoothingEnabled = false;
  5848. if (group.smask) {
  5849. this.tempSMask = this.smaskStack.pop();
  5850. this.restore();
  5851. } else {
  5852. this.ctx.restore();
  5853. const currentMtx = this.ctx.mozCurrentTransform;
  5854. this.restore();
  5855. this.ctx.save();
  5856. this.ctx.setTransform.apply(this.ctx, currentMtx);
  5857. const dirtyBox = _util.Util.getAxialAlignedBoundingBox([0, 0, groupCtx.canvas.width, groupCtx.canvas.height], currentMtx);
  5858. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  5859. this.ctx.restore();
  5860. this.compose(dirtyBox);
  5861. }
  5862. }
  5863. beginAnnotations() {
  5864. this.save();
  5865. if (this.baseTransform) {
  5866. this.ctx.setTransform.apply(this.ctx, this.baseTransform);
  5867. }
  5868. }
  5869. endAnnotations() {
  5870. this.restore();
  5871. }
  5872. beginAnnotation(id, rect, transform, matrix, hasOwnCanvas) {
  5873. this.save();
  5874. if (Array.isArray(rect) && rect.length === 4) {
  5875. const width = rect[2] - rect[0];
  5876. const height = rect[3] - rect[1];
  5877. if (hasOwnCanvas && this.annotationCanvasMap) {
  5878. transform = transform.slice();
  5879. transform[4] -= rect[0];
  5880. transform[5] -= rect[1];
  5881. rect = rect.slice();
  5882. rect[0] = rect[1] = 0;
  5883. rect[2] = width;
  5884. rect[3] = height;
  5885. const [scaleX, scaleY] = _util.Util.singularValueDecompose2dScale(this.ctx.mozCurrentTransform);
  5886. const {
  5887. viewportScale
  5888. } = this;
  5889. const canvasWidth = Math.ceil(width * this.outputScaleX * viewportScale);
  5890. const canvasHeight = Math.ceil(height * this.outputScaleY * viewportScale);
  5891. this.annotationCanvas = this.canvasFactory.create(canvasWidth, canvasHeight);
  5892. const {
  5893. canvas,
  5894. context
  5895. } = this.annotationCanvas;
  5896. const viewportScaleFactorStr = `var(--zoom-factor) * ${_display_utils.PixelsPerInch.PDF_TO_CSS_UNITS}`;
  5897. canvas.style.width = `calc(${width}px * ${viewportScaleFactorStr})`;
  5898. canvas.style.height = `calc(${height}px * ${viewportScaleFactorStr})`;
  5899. this.annotationCanvasMap.set(id, canvas);
  5900. this.annotationCanvas.savedCtx = this.ctx;
  5901. this.ctx = context;
  5902. this.ctx.setTransform(scaleX, 0, 0, -scaleY, 0, height * scaleY);
  5903. addContextCurrentTransform(this.ctx);
  5904. resetCtxToDefault(this.ctx, this.foregroundColor);
  5905. } else {
  5906. resetCtxToDefault(this.ctx, this.foregroundColor);
  5907. this.ctx.rect(rect[0], rect[1], width, height);
  5908. this.ctx.clip();
  5909. this.endPath();
  5910. }
  5911. }
  5912. this.current = new CanvasExtraState(this.ctx.canvas.width, this.ctx.canvas.height);
  5913. this.transform.apply(this, transform);
  5914. this.transform.apply(this, matrix);
  5915. }
  5916. endAnnotation() {
  5917. if (this.annotationCanvas) {
  5918. this.ctx = this.annotationCanvas.savedCtx;
  5919. delete this.annotationCanvas.savedCtx;
  5920. delete this.annotationCanvas;
  5921. }
  5922. this.restore();
  5923. }
  5924. paintImageMaskXObject(img) {
  5925. if (!this.contentVisible) {
  5926. return;
  5927. }
  5928. const count = img.count;
  5929. img = this.getObject(img.data, img);
  5930. img.count = count;
  5931. const ctx = this.ctx;
  5932. const glyph = this.processingType3;
  5933. if (glyph) {
  5934. if (glyph.compiled === undefined) {
  5935. glyph.compiled = compileType3Glyph(img);
  5936. }
  5937. if (glyph.compiled) {
  5938. glyph.compiled(ctx);
  5939. return;
  5940. }
  5941. }
  5942. const mask = this._createMaskCanvas(img);
  5943. const maskCanvas = mask.canvas;
  5944. ctx.save();
  5945. ctx.setTransform(1, 0, 0, 1, 0, 0);
  5946. ctx.drawImage(maskCanvas, mask.offsetX, mask.offsetY);
  5947. ctx.restore();
  5948. this.compose();
  5949. }
  5950. paintImageMaskXObjectRepeat(img, scaleX, skewX = 0, skewY = 0, scaleY, positions) {
  5951. if (!this.contentVisible) {
  5952. return;
  5953. }
  5954. img = this.getObject(img.data, img);
  5955. const ctx = this.ctx;
  5956. ctx.save();
  5957. const currentTransform = ctx.mozCurrentTransform;
  5958. ctx.transform(scaleX, skewX, skewY, scaleY, 0, 0);
  5959. const mask = this._createMaskCanvas(img);
  5960. ctx.setTransform(1, 0, 0, 1, 0, 0);
  5961. for (let i = 0, ii = positions.length; i < ii; i += 2) {
  5962. const trans = _util.Util.transform(currentTransform, [scaleX, skewX, skewY, scaleY, positions[i], positions[i + 1]]);
  5963. const [x, y] = _util.Util.applyTransform([0, 0], trans);
  5964. ctx.drawImage(mask.canvas, x, y);
  5965. }
  5966. ctx.restore();
  5967. this.compose();
  5968. }
  5969. paintImageMaskXObjectGroup(images) {
  5970. if (!this.contentVisible) {
  5971. return;
  5972. }
  5973. const ctx = this.ctx;
  5974. const fillColor = this.current.fillColor;
  5975. const isPatternFill = this.current.patternFill;
  5976. for (let i = 0, ii = images.length; i < ii; i++) {
  5977. const image = images[i];
  5978. const width = image.width,
  5979. height = image.height;
  5980. const maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height, false);
  5981. const maskCtx = maskCanvas.context;
  5982. maskCtx.save();
  5983. putBinaryImageMask(maskCtx, image);
  5984. maskCtx.globalCompositeOperation = "source-in";
  5985. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this, ctx.mozCurrentTransformInverse, _pattern_helper.PathType.FILL) : fillColor;
  5986. maskCtx.fillRect(0, 0, width, height);
  5987. maskCtx.restore();
  5988. ctx.save();
  5989. ctx.transform.apply(ctx, image.transform);
  5990. ctx.scale(1, -1);
  5991. drawImageAtIntegerCoords(ctx, maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1);
  5992. ctx.restore();
  5993. }
  5994. this.compose();
  5995. }
  5996. paintImageXObject(objId) {
  5997. if (!this.contentVisible) {
  5998. return;
  5999. }
  6000. const imgData = this.getObject(objId);
  6001. if (!imgData) {
  6002. (0, _util.warn)("Dependent image isn't ready yet");
  6003. return;
  6004. }
  6005. this.paintInlineImageXObject(imgData);
  6006. }
  6007. paintImageXObjectRepeat(objId, scaleX, scaleY, positions) {
  6008. if (!this.contentVisible) {
  6009. return;
  6010. }
  6011. const imgData = this.getObject(objId);
  6012. if (!imgData) {
  6013. (0, _util.warn)("Dependent image isn't ready yet");
  6014. return;
  6015. }
  6016. const width = imgData.width;
  6017. const height = imgData.height;
  6018. const map = [];
  6019. for (let i = 0, ii = positions.length; i < ii; i += 2) {
  6020. map.push({
  6021. transform: [scaleX, 0, 0, scaleY, positions[i], positions[i + 1]],
  6022. x: 0,
  6023. y: 0,
  6024. w: width,
  6025. h: height
  6026. });
  6027. }
  6028. this.paintInlineImageXObjectGroup(imgData, map);
  6029. }
  6030. paintInlineImageXObject(imgData) {
  6031. if (!this.contentVisible) {
  6032. return;
  6033. }
  6034. const width = imgData.width;
  6035. const height = imgData.height;
  6036. const ctx = this.ctx;
  6037. this.save();
  6038. ctx.scale(1 / width, -1 / height);
  6039. let imgToPaint;
  6040. if (typeof HTMLElement === "function" && imgData instanceof HTMLElement || !imgData.data) {
  6041. imgToPaint = imgData;
  6042. } else {
  6043. const tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", width, height, false);
  6044. const tmpCtx = tmpCanvas.context;
  6045. putBinaryImageData(tmpCtx, imgData, this.current.transferMaps);
  6046. imgToPaint = tmpCanvas.canvas;
  6047. }
  6048. const scaled = this._scaleImage(imgToPaint, ctx.mozCurrentTransformInverse);
  6049. ctx.imageSmoothingEnabled = getImageSmoothingEnabled(ctx.mozCurrentTransform, imgData.interpolate);
  6050. const [rWidth, rHeight] = drawImageAtIntegerCoords(ctx, scaled.img, 0, 0, scaled.paintWidth, scaled.paintHeight, 0, -height, width, height);
  6051. if (this.imageLayer) {
  6052. const position = this.getCanvasPosition(0, -height);
  6053. this.imageLayer.appendImage({
  6054. imgData,
  6055. left: position[0],
  6056. top: position[1],
  6057. width: rWidth,
  6058. height: rHeight
  6059. });
  6060. }
  6061. this.compose();
  6062. this.restore();
  6063. }
  6064. paintInlineImageXObjectGroup(imgData, map) {
  6065. if (!this.contentVisible) {
  6066. return;
  6067. }
  6068. const ctx = this.ctx;
  6069. const w = imgData.width;
  6070. const h = imgData.height;
  6071. const tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", w, h, false);
  6072. const tmpCtx = tmpCanvas.context;
  6073. putBinaryImageData(tmpCtx, imgData, this.current.transferMaps);
  6074. for (let i = 0, ii = map.length; i < ii; i++) {
  6075. const entry = map[i];
  6076. ctx.save();
  6077. ctx.transform.apply(ctx, entry.transform);
  6078. ctx.scale(1, -1);
  6079. drawImageAtIntegerCoords(ctx, tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h, 0, -1, 1, 1);
  6080. if (this.imageLayer) {
  6081. const position = this.getCanvasPosition(entry.x, entry.y);
  6082. this.imageLayer.appendImage({
  6083. imgData,
  6084. left: position[0],
  6085. top: position[1],
  6086. width: w,
  6087. height: h
  6088. });
  6089. }
  6090. ctx.restore();
  6091. }
  6092. this.compose();
  6093. }
  6094. paintSolidColorImageMask() {
  6095. if (!this.contentVisible) {
  6096. return;
  6097. }
  6098. this.ctx.fillRect(0, 0, 1, 1);
  6099. this.compose();
  6100. }
  6101. markPoint(tag) {}
  6102. markPointProps(tag, properties) {}
  6103. beginMarkedContent(tag) {
  6104. this.markedContentStack.push({
  6105. visible: true
  6106. });
  6107. }
  6108. beginMarkedContentProps(tag, properties) {
  6109. if (tag === "OC") {
  6110. this.markedContentStack.push({
  6111. visible: this.optionalContentConfig.isVisible(properties)
  6112. });
  6113. } else {
  6114. this.markedContentStack.push({
  6115. visible: true
  6116. });
  6117. }
  6118. this.contentVisible = this.isContentVisible();
  6119. }
  6120. endMarkedContent() {
  6121. this.markedContentStack.pop();
  6122. this.contentVisible = this.isContentVisible();
  6123. }
  6124. beginCompat() {}
  6125. endCompat() {}
  6126. consumePath(clipBox) {
  6127. const isEmpty = this.current.isEmptyClip();
  6128. if (this.pendingClip) {
  6129. this.current.updateClipFromPath();
  6130. }
  6131. if (!this.pendingClip) {
  6132. this.compose(clipBox);
  6133. }
  6134. const ctx = this.ctx;
  6135. if (this.pendingClip) {
  6136. if (!isEmpty) {
  6137. if (this.pendingClip === EO_CLIP) {
  6138. ctx.clip("evenodd");
  6139. } else {
  6140. ctx.clip();
  6141. }
  6142. }
  6143. this.pendingClip = null;
  6144. }
  6145. this.current.startNewPathAndClipBox(this.current.clipBox);
  6146. ctx.beginPath();
  6147. }
  6148. getSinglePixelWidth() {
  6149. if (!this._cachedGetSinglePixelWidth) {
  6150. const m = this.ctx.mozCurrentTransform;
  6151. if (m[1] === 0 && m[2] === 0) {
  6152. this._cachedGetSinglePixelWidth = 1 / Math.min(Math.abs(m[0]), Math.abs(m[3]));
  6153. } else {
  6154. const absDet = Math.abs(m[0] * m[3] - m[2] * m[1]);
  6155. const normX = Math.hypot(m[0], m[2]);
  6156. const normY = Math.hypot(m[1], m[3]);
  6157. this._cachedGetSinglePixelWidth = Math.max(normX, normY) / absDet;
  6158. }
  6159. }
  6160. return this._cachedGetSinglePixelWidth;
  6161. }
  6162. getScaleForStroking() {
  6163. if (!this._cachedScaleForStroking) {
  6164. const {
  6165. lineWidth
  6166. } = this.current;
  6167. const m = this.ctx.mozCurrentTransform;
  6168. let scaleX, scaleY;
  6169. if (m[1] === 0 && m[2] === 0) {
  6170. const normX = Math.abs(m[0]);
  6171. const normY = Math.abs(m[3]);
  6172. if (lineWidth === 0) {
  6173. scaleX = 1 / normX;
  6174. scaleY = 1 / normY;
  6175. } else {
  6176. const scaledXLineWidth = normX * lineWidth;
  6177. const scaledYLineWidth = normY * lineWidth;
  6178. scaleX = scaledXLineWidth < 1 ? 1 / scaledXLineWidth : 1;
  6179. scaleY = scaledYLineWidth < 1 ? 1 / scaledYLineWidth : 1;
  6180. }
  6181. } else {
  6182. const absDet = Math.abs(m[0] * m[3] - m[2] * m[1]);
  6183. const normX = Math.hypot(m[0], m[1]);
  6184. const normY = Math.hypot(m[2], m[3]);
  6185. if (lineWidth === 0) {
  6186. scaleX = normY / absDet;
  6187. scaleY = normX / absDet;
  6188. } else {
  6189. const baseArea = lineWidth * absDet;
  6190. scaleX = normY > baseArea ? normY / baseArea : 1;
  6191. scaleY = normX > baseArea ? normX / baseArea : 1;
  6192. }
  6193. }
  6194. this._cachedScaleForStroking = [scaleX, scaleY];
  6195. }
  6196. return this._cachedScaleForStroking;
  6197. }
  6198. rescaleAndStroke(saveRestore) {
  6199. const {
  6200. ctx
  6201. } = this;
  6202. const {
  6203. lineWidth
  6204. } = this.current;
  6205. const [scaleX, scaleY] = this.getScaleForStroking();
  6206. ctx.lineWidth = lineWidth || 1;
  6207. if (scaleX === 1 && scaleY === 1) {
  6208. ctx.stroke();
  6209. return;
  6210. }
  6211. let savedMatrix, savedDashes, savedDashOffset;
  6212. if (saveRestore) {
  6213. savedMatrix = ctx.mozCurrentTransform.slice();
  6214. savedDashes = ctx.getLineDash().slice();
  6215. savedDashOffset = ctx.lineDashOffset;
  6216. }
  6217. ctx.scale(scaleX, scaleY);
  6218. const scale = Math.max(scaleX, scaleY);
  6219. ctx.setLineDash(ctx.getLineDash().map(x => x / scale));
  6220. ctx.lineDashOffset /= scale;
  6221. ctx.stroke();
  6222. if (saveRestore) {
  6223. ctx.setTransform(...savedMatrix);
  6224. ctx.setLineDash(savedDashes);
  6225. ctx.lineDashOffset = savedDashOffset;
  6226. }
  6227. }
  6228. getCanvasPosition(x, y) {
  6229. const transform = this.ctx.mozCurrentTransform;
  6230. return [transform[0] * x + transform[2] * y + transform[4], transform[1] * x + transform[3] * y + transform[5]];
  6231. }
  6232. isContentVisible() {
  6233. for (let i = this.markedContentStack.length - 1; i >= 0; i--) {
  6234. if (!this.markedContentStack[i].visible) {
  6235. return false;
  6236. }
  6237. }
  6238. return true;
  6239. }
  6240. }
  6241. exports.CanvasGraphics = CanvasGraphics;
  6242. for (const op in _util.OPS) {
  6243. if (CanvasGraphics.prototype[op] !== undefined) {
  6244. CanvasGraphics.prototype[_util.OPS[op]] = CanvasGraphics.prototype[op];
  6245. }
  6246. }
  6247. /***/ }),
  6248. /* 11 */
  6249. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  6250. Object.defineProperty(exports, "__esModule", ({
  6251. value: true
  6252. }));
  6253. exports.TilingPattern = exports.PathType = void 0;
  6254. exports.getShadingPattern = getShadingPattern;
  6255. var _util = __w_pdfjs_require__(1);
  6256. var _is_node = __w_pdfjs_require__(3);
  6257. const PathType = {
  6258. FILL: "Fill",
  6259. STROKE: "Stroke",
  6260. SHADING: "Shading"
  6261. };
  6262. exports.PathType = PathType;
  6263. function applyBoundingBox(ctx, bbox) {
  6264. if (!bbox || _is_node.isNodeJS) {
  6265. return;
  6266. }
  6267. const width = bbox[2] - bbox[0];
  6268. const height = bbox[3] - bbox[1];
  6269. const region = new Path2D();
  6270. region.rect(bbox[0], bbox[1], width, height);
  6271. ctx.clip(region);
  6272. }
  6273. class BaseShadingPattern {
  6274. constructor() {
  6275. if (this.constructor === BaseShadingPattern) {
  6276. (0, _util.unreachable)("Cannot initialize BaseShadingPattern.");
  6277. }
  6278. }
  6279. getPattern() {
  6280. (0, _util.unreachable)("Abstract method `getPattern` called.");
  6281. }
  6282. }
  6283. class RadialAxialShadingPattern extends BaseShadingPattern {
  6284. constructor(IR) {
  6285. super();
  6286. this._type = IR[1];
  6287. this._bbox = IR[2];
  6288. this._colorStops = IR[3];
  6289. this._p0 = IR[4];
  6290. this._p1 = IR[5];
  6291. this._r0 = IR[6];
  6292. this._r1 = IR[7];
  6293. this.matrix = null;
  6294. }
  6295. _createGradient(ctx) {
  6296. let grad;
  6297. if (this._type === "axial") {
  6298. grad = ctx.createLinearGradient(this._p0[0], this._p0[1], this._p1[0], this._p1[1]);
  6299. } else if (this._type === "radial") {
  6300. grad = ctx.createRadialGradient(this._p0[0], this._p0[1], this._r0, this._p1[0], this._p1[1], this._r1);
  6301. }
  6302. for (const colorStop of this._colorStops) {
  6303. grad.addColorStop(colorStop[0], colorStop[1]);
  6304. }
  6305. return grad;
  6306. }
  6307. getPattern(ctx, owner, inverse, pathType) {
  6308. let pattern;
  6309. if (pathType === PathType.STROKE || pathType === PathType.FILL) {
  6310. const ownerBBox = owner.current.getClippedPathBoundingBox(pathType, ctx.mozCurrentTransform) || [0, 0, 0, 0];
  6311. const width = Math.ceil(ownerBBox[2] - ownerBBox[0]) || 1;
  6312. const height = Math.ceil(ownerBBox[3] - ownerBBox[1]) || 1;
  6313. const tmpCanvas = owner.cachedCanvases.getCanvas("pattern", width, height, true);
  6314. const tmpCtx = tmpCanvas.context;
  6315. tmpCtx.clearRect(0, 0, tmpCtx.canvas.width, tmpCtx.canvas.height);
  6316. tmpCtx.beginPath();
  6317. tmpCtx.rect(0, 0, tmpCtx.canvas.width, tmpCtx.canvas.height);
  6318. tmpCtx.translate(-ownerBBox[0], -ownerBBox[1]);
  6319. inverse = _util.Util.transform(inverse, [1, 0, 0, 1, ownerBBox[0], ownerBBox[1]]);
  6320. tmpCtx.transform.apply(tmpCtx, owner.baseTransform);
  6321. if (this.matrix) {
  6322. tmpCtx.transform.apply(tmpCtx, this.matrix);
  6323. }
  6324. applyBoundingBox(tmpCtx, this._bbox);
  6325. tmpCtx.fillStyle = this._createGradient(tmpCtx);
  6326. tmpCtx.fill();
  6327. pattern = ctx.createPattern(tmpCanvas.canvas, "no-repeat");
  6328. const domMatrix = new DOMMatrix(inverse);
  6329. try {
  6330. pattern.setTransform(domMatrix);
  6331. } catch (ex) {
  6332. (0, _util.warn)(`RadialAxialShadingPattern.getPattern: "${ex?.message}".`);
  6333. }
  6334. } else {
  6335. applyBoundingBox(ctx, this._bbox);
  6336. pattern = this._createGradient(ctx);
  6337. }
  6338. return pattern;
  6339. }
  6340. }
  6341. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  6342. const coords = context.coords,
  6343. colors = context.colors;
  6344. const bytes = data.data,
  6345. rowSize = data.width * 4;
  6346. let tmp;
  6347. if (coords[p1 + 1] > coords[p2 + 1]) {
  6348. tmp = p1;
  6349. p1 = p2;
  6350. p2 = tmp;
  6351. tmp = c1;
  6352. c1 = c2;
  6353. c2 = tmp;
  6354. }
  6355. if (coords[p2 + 1] > coords[p3 + 1]) {
  6356. tmp = p2;
  6357. p2 = p3;
  6358. p3 = tmp;
  6359. tmp = c2;
  6360. c2 = c3;
  6361. c3 = tmp;
  6362. }
  6363. if (coords[p1 + 1] > coords[p2 + 1]) {
  6364. tmp = p1;
  6365. p1 = p2;
  6366. p2 = tmp;
  6367. tmp = c1;
  6368. c1 = c2;
  6369. c2 = tmp;
  6370. }
  6371. const x1 = (coords[p1] + context.offsetX) * context.scaleX;
  6372. const y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  6373. const x2 = (coords[p2] + context.offsetX) * context.scaleX;
  6374. const y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  6375. const x3 = (coords[p3] + context.offsetX) * context.scaleX;
  6376. const y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  6377. if (y1 >= y3) {
  6378. return;
  6379. }
  6380. const c1r = colors[c1],
  6381. c1g = colors[c1 + 1],
  6382. c1b = colors[c1 + 2];
  6383. const c2r = colors[c2],
  6384. c2g = colors[c2 + 1],
  6385. c2b = colors[c2 + 2];
  6386. const c3r = colors[c3],
  6387. c3g = colors[c3 + 1],
  6388. c3b = colors[c3 + 2];
  6389. const minY = Math.round(y1),
  6390. maxY = Math.round(y3);
  6391. let xa, car, cag, cab;
  6392. let xb, cbr, cbg, cbb;
  6393. for (let y = minY; y <= maxY; y++) {
  6394. if (y < y2) {
  6395. let k;
  6396. if (y < y1) {
  6397. k = 0;
  6398. } else {
  6399. k = (y1 - y) / (y1 - y2);
  6400. }
  6401. xa = x1 - (x1 - x2) * k;
  6402. car = c1r - (c1r - c2r) * k;
  6403. cag = c1g - (c1g - c2g) * k;
  6404. cab = c1b - (c1b - c2b) * k;
  6405. } else {
  6406. let k;
  6407. if (y > y3) {
  6408. k = 1;
  6409. } else if (y2 === y3) {
  6410. k = 0;
  6411. } else {
  6412. k = (y2 - y) / (y2 - y3);
  6413. }
  6414. xa = x2 - (x2 - x3) * k;
  6415. car = c2r - (c2r - c3r) * k;
  6416. cag = c2g - (c2g - c3g) * k;
  6417. cab = c2b - (c2b - c3b) * k;
  6418. }
  6419. let k;
  6420. if (y < y1) {
  6421. k = 0;
  6422. } else if (y > y3) {
  6423. k = 1;
  6424. } else {
  6425. k = (y1 - y) / (y1 - y3);
  6426. }
  6427. xb = x1 - (x1 - x3) * k;
  6428. cbr = c1r - (c1r - c3r) * k;
  6429. cbg = c1g - (c1g - c3g) * k;
  6430. cbb = c1b - (c1b - c3b) * k;
  6431. const x1_ = Math.round(Math.min(xa, xb));
  6432. const x2_ = Math.round(Math.max(xa, xb));
  6433. let j = rowSize * y + x1_ * 4;
  6434. for (let x = x1_; x <= x2_; x++) {
  6435. k = (xa - x) / (xa - xb);
  6436. if (k < 0) {
  6437. k = 0;
  6438. } else if (k > 1) {
  6439. k = 1;
  6440. }
  6441. bytes[j++] = car - (car - cbr) * k | 0;
  6442. bytes[j++] = cag - (cag - cbg) * k | 0;
  6443. bytes[j++] = cab - (cab - cbb) * k | 0;
  6444. bytes[j++] = 255;
  6445. }
  6446. }
  6447. }
  6448. function drawFigure(data, figure, context) {
  6449. const ps = figure.coords;
  6450. const cs = figure.colors;
  6451. let i, ii;
  6452. switch (figure.type) {
  6453. case "lattice":
  6454. const verticesPerRow = figure.verticesPerRow;
  6455. const rows = Math.floor(ps.length / verticesPerRow) - 1;
  6456. const cols = verticesPerRow - 1;
  6457. for (i = 0; i < rows; i++) {
  6458. let q = i * verticesPerRow;
  6459. for (let j = 0; j < cols; j++, q++) {
  6460. drawTriangle(data, context, ps[q], ps[q + 1], ps[q + verticesPerRow], cs[q], cs[q + 1], cs[q + verticesPerRow]);
  6461. drawTriangle(data, context, ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow], cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  6462. }
  6463. }
  6464. break;
  6465. case "triangles":
  6466. for (i = 0, ii = ps.length; i < ii; i += 3) {
  6467. drawTriangle(data, context, ps[i], ps[i + 1], ps[i + 2], cs[i], cs[i + 1], cs[i + 2]);
  6468. }
  6469. break;
  6470. default:
  6471. throw new Error("illegal figure");
  6472. }
  6473. }
  6474. class MeshShadingPattern extends BaseShadingPattern {
  6475. constructor(IR) {
  6476. super();
  6477. this._coords = IR[2];
  6478. this._colors = IR[3];
  6479. this._figures = IR[4];
  6480. this._bounds = IR[5];
  6481. this._bbox = IR[7];
  6482. this._background = IR[8];
  6483. this.matrix = null;
  6484. }
  6485. _createMeshCanvas(combinedScale, backgroundColor, cachedCanvases) {
  6486. const EXPECTED_SCALE = 1.1;
  6487. const MAX_PATTERN_SIZE = 3000;
  6488. const BORDER_SIZE = 2;
  6489. const offsetX = Math.floor(this._bounds[0]);
  6490. const offsetY = Math.floor(this._bounds[1]);
  6491. const boundsWidth = Math.ceil(this._bounds[2]) - offsetX;
  6492. const boundsHeight = Math.ceil(this._bounds[3]) - offsetY;
  6493. const width = Math.min(Math.ceil(Math.abs(boundsWidth * combinedScale[0] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  6494. const height = Math.min(Math.ceil(Math.abs(boundsHeight * combinedScale[1] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  6495. const scaleX = boundsWidth / width;
  6496. const scaleY = boundsHeight / height;
  6497. const context = {
  6498. coords: this._coords,
  6499. colors: this._colors,
  6500. offsetX: -offsetX,
  6501. offsetY: -offsetY,
  6502. scaleX: 1 / scaleX,
  6503. scaleY: 1 / scaleY
  6504. };
  6505. const paddedWidth = width + BORDER_SIZE * 2;
  6506. const paddedHeight = height + BORDER_SIZE * 2;
  6507. const tmpCanvas = cachedCanvases.getCanvas("mesh", paddedWidth, paddedHeight, false);
  6508. const tmpCtx = tmpCanvas.context;
  6509. const data = tmpCtx.createImageData(width, height);
  6510. if (backgroundColor) {
  6511. const bytes = data.data;
  6512. for (let i = 0, ii = bytes.length; i < ii; i += 4) {
  6513. bytes[i] = backgroundColor[0];
  6514. bytes[i + 1] = backgroundColor[1];
  6515. bytes[i + 2] = backgroundColor[2];
  6516. bytes[i + 3] = 255;
  6517. }
  6518. }
  6519. for (const figure of this._figures) {
  6520. drawFigure(data, figure, context);
  6521. }
  6522. tmpCtx.putImageData(data, BORDER_SIZE, BORDER_SIZE);
  6523. const canvas = tmpCanvas.canvas;
  6524. return {
  6525. canvas,
  6526. offsetX: offsetX - BORDER_SIZE * scaleX,
  6527. offsetY: offsetY - BORDER_SIZE * scaleY,
  6528. scaleX,
  6529. scaleY
  6530. };
  6531. }
  6532. getPattern(ctx, owner, inverse, pathType) {
  6533. applyBoundingBox(ctx, this._bbox);
  6534. let scale;
  6535. if (pathType === PathType.SHADING) {
  6536. scale = _util.Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  6537. } else {
  6538. scale = _util.Util.singularValueDecompose2dScale(owner.baseTransform);
  6539. if (this.matrix) {
  6540. const matrixScale = _util.Util.singularValueDecompose2dScale(this.matrix);
  6541. scale = [scale[0] * matrixScale[0], scale[1] * matrixScale[1]];
  6542. }
  6543. }
  6544. const temporaryPatternCanvas = this._createMeshCanvas(scale, pathType === PathType.SHADING ? null : this._background, owner.cachedCanvases);
  6545. if (pathType !== PathType.SHADING) {
  6546. ctx.setTransform.apply(ctx, owner.baseTransform);
  6547. if (this.matrix) {
  6548. ctx.transform.apply(ctx, this.matrix);
  6549. }
  6550. }
  6551. ctx.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY);
  6552. ctx.scale(temporaryPatternCanvas.scaleX, temporaryPatternCanvas.scaleY);
  6553. return ctx.createPattern(temporaryPatternCanvas.canvas, "no-repeat");
  6554. }
  6555. }
  6556. class DummyShadingPattern extends BaseShadingPattern {
  6557. getPattern() {
  6558. return "hotpink";
  6559. }
  6560. }
  6561. function getShadingPattern(IR) {
  6562. switch (IR[0]) {
  6563. case "RadialAxial":
  6564. return new RadialAxialShadingPattern(IR);
  6565. case "Mesh":
  6566. return new MeshShadingPattern(IR);
  6567. case "Dummy":
  6568. return new DummyShadingPattern();
  6569. }
  6570. throw new Error(`Unknown IR type: ${IR[0]}`);
  6571. }
  6572. const PaintType = {
  6573. COLORED: 1,
  6574. UNCOLORED: 2
  6575. };
  6576. class TilingPattern {
  6577. static get MAX_PATTERN_SIZE() {
  6578. return (0, _util.shadow)(this, "MAX_PATTERN_SIZE", 3000);
  6579. }
  6580. constructor(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
  6581. this.operatorList = IR[2];
  6582. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  6583. this.bbox = IR[4];
  6584. this.xstep = IR[5];
  6585. this.ystep = IR[6];
  6586. this.paintType = IR[7];
  6587. this.tilingType = IR[8];
  6588. this.color = color;
  6589. this.ctx = ctx;
  6590. this.canvasGraphicsFactory = canvasGraphicsFactory;
  6591. this.baseTransform = baseTransform;
  6592. }
  6593. createPatternCanvas(owner) {
  6594. const operatorList = this.operatorList;
  6595. const bbox = this.bbox;
  6596. const xstep = this.xstep;
  6597. const ystep = this.ystep;
  6598. const paintType = this.paintType;
  6599. const tilingType = this.tilingType;
  6600. const color = this.color;
  6601. const canvasGraphicsFactory = this.canvasGraphicsFactory;
  6602. (0, _util.info)("TilingType: " + tilingType);
  6603. const x0 = bbox[0],
  6604. y0 = bbox[1],
  6605. x1 = bbox[2],
  6606. y1 = bbox[3];
  6607. const matrixScale = _util.Util.singularValueDecompose2dScale(this.matrix);
  6608. const curMatrixScale = _util.Util.singularValueDecompose2dScale(this.baseTransform);
  6609. const combinedScale = [matrixScale[0] * curMatrixScale[0], matrixScale[1] * curMatrixScale[1]];
  6610. const dimx = this.getSizeAndScale(xstep, this.ctx.canvas.width, combinedScale[0]);
  6611. const dimy = this.getSizeAndScale(ystep, this.ctx.canvas.height, combinedScale[1]);
  6612. const tmpCanvas = owner.cachedCanvases.getCanvas("pattern", dimx.size, dimy.size, true);
  6613. const tmpCtx = tmpCanvas.context;
  6614. const graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
  6615. graphics.groupLevel = owner.groupLevel;
  6616. this.setFillAndStrokeStyleToContext(graphics, paintType, color);
  6617. let adjustedX0 = x0;
  6618. let adjustedY0 = y0;
  6619. let adjustedX1 = x1;
  6620. let adjustedY1 = y1;
  6621. if (x0 < 0) {
  6622. adjustedX0 = 0;
  6623. adjustedX1 += Math.abs(x0);
  6624. }
  6625. if (y0 < 0) {
  6626. adjustedY0 = 0;
  6627. adjustedY1 += Math.abs(y0);
  6628. }
  6629. tmpCtx.translate(-(dimx.scale * adjustedX0), -(dimy.scale * adjustedY0));
  6630. graphics.transform(dimx.scale, 0, 0, dimy.scale, 0, 0);
  6631. tmpCtx.save();
  6632. this.clipBbox(graphics, adjustedX0, adjustedY0, adjustedX1, adjustedY1);
  6633. graphics.baseTransform = graphics.ctx.mozCurrentTransform.slice();
  6634. graphics.executeOperatorList(operatorList);
  6635. graphics.endDrawing();
  6636. return {
  6637. canvas: tmpCanvas.canvas,
  6638. scaleX: dimx.scale,
  6639. scaleY: dimy.scale,
  6640. offsetX: adjustedX0,
  6641. offsetY: adjustedY0
  6642. };
  6643. }
  6644. getSizeAndScale(step, realOutputSize, scale) {
  6645. step = Math.abs(step);
  6646. const maxSize = Math.max(TilingPattern.MAX_PATTERN_SIZE, realOutputSize);
  6647. let size = Math.ceil(step * scale);
  6648. if (size >= maxSize) {
  6649. size = maxSize;
  6650. } else {
  6651. scale = size / step;
  6652. }
  6653. return {
  6654. scale,
  6655. size
  6656. };
  6657. }
  6658. clipBbox(graphics, x0, y0, x1, y1) {
  6659. const bboxWidth = x1 - x0;
  6660. const bboxHeight = y1 - y0;
  6661. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  6662. graphics.current.updateRectMinMax(graphics.ctx.mozCurrentTransform, [x0, y0, x1, y1]);
  6663. graphics.clip();
  6664. graphics.endPath();
  6665. }
  6666. setFillAndStrokeStyleToContext(graphics, paintType, color) {
  6667. const context = graphics.ctx,
  6668. current = graphics.current;
  6669. switch (paintType) {
  6670. case PaintType.COLORED:
  6671. const ctx = this.ctx;
  6672. context.fillStyle = ctx.fillStyle;
  6673. context.strokeStyle = ctx.strokeStyle;
  6674. current.fillColor = ctx.fillStyle;
  6675. current.strokeColor = ctx.strokeStyle;
  6676. break;
  6677. case PaintType.UNCOLORED:
  6678. const cssColor = _util.Util.makeHexColor(color[0], color[1], color[2]);
  6679. context.fillStyle = cssColor;
  6680. context.strokeStyle = cssColor;
  6681. current.fillColor = cssColor;
  6682. current.strokeColor = cssColor;
  6683. break;
  6684. default:
  6685. throw new _util.FormatError(`Unsupported paint type: ${paintType}`);
  6686. }
  6687. }
  6688. getPattern(ctx, owner, inverse, pathType) {
  6689. let matrix = inverse;
  6690. if (pathType !== PathType.SHADING) {
  6691. matrix = _util.Util.transform(matrix, owner.baseTransform);
  6692. if (this.matrix) {
  6693. matrix = _util.Util.transform(matrix, this.matrix);
  6694. }
  6695. }
  6696. const temporaryPatternCanvas = this.createPatternCanvas(owner);
  6697. let domMatrix = new DOMMatrix(matrix);
  6698. domMatrix = domMatrix.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY);
  6699. domMatrix = domMatrix.scale(1 / temporaryPatternCanvas.scaleX, 1 / temporaryPatternCanvas.scaleY);
  6700. const pattern = ctx.createPattern(temporaryPatternCanvas.canvas, "repeat");
  6701. try {
  6702. pattern.setTransform(domMatrix);
  6703. } catch (ex) {
  6704. (0, _util.warn)(`TilingPattern.getPattern: "${ex?.message}".`);
  6705. }
  6706. return pattern;
  6707. }
  6708. }
  6709. exports.TilingPattern = TilingPattern;
  6710. /***/ }),
  6711. /* 12 */
  6712. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  6713. Object.defineProperty(exports, "__esModule", ({
  6714. value: true
  6715. }));
  6716. exports.applyMaskImageData = applyMaskImageData;
  6717. var _util = __w_pdfjs_require__(1);
  6718. function applyMaskImageData({
  6719. src,
  6720. srcPos = 0,
  6721. dest,
  6722. destPos = 0,
  6723. width,
  6724. height,
  6725. inverseDecode = false
  6726. }) {
  6727. const opaque = _util.FeatureTest.isLittleEndian ? 0xff000000 : 0x000000ff;
  6728. const [zeroMapping, oneMapping] = !inverseDecode ? [opaque, 0] : [0, opaque];
  6729. const widthInSource = width >> 3;
  6730. const widthRemainder = width & 7;
  6731. const srcLength = src.length;
  6732. dest = new Uint32Array(dest.buffer);
  6733. for (let i = 0; i < height; i++) {
  6734. for (const max = srcPos + widthInSource; srcPos < max; srcPos++) {
  6735. const elem = srcPos < srcLength ? src[srcPos] : 255;
  6736. dest[destPos++] = elem & 0b10000000 ? oneMapping : zeroMapping;
  6737. dest[destPos++] = elem & 0b1000000 ? oneMapping : zeroMapping;
  6738. dest[destPos++] = elem & 0b100000 ? oneMapping : zeroMapping;
  6739. dest[destPos++] = elem & 0b10000 ? oneMapping : zeroMapping;
  6740. dest[destPos++] = elem & 0b1000 ? oneMapping : zeroMapping;
  6741. dest[destPos++] = elem & 0b100 ? oneMapping : zeroMapping;
  6742. dest[destPos++] = elem & 0b10 ? oneMapping : zeroMapping;
  6743. dest[destPos++] = elem & 0b1 ? oneMapping : zeroMapping;
  6744. }
  6745. if (widthRemainder === 0) {
  6746. continue;
  6747. }
  6748. const elem = srcPos < srcLength ? src[srcPos++] : 255;
  6749. for (let j = 0; j < widthRemainder; j++) {
  6750. dest[destPos++] = elem & 1 << 7 - j ? oneMapping : zeroMapping;
  6751. }
  6752. }
  6753. return {
  6754. srcPos,
  6755. destPos
  6756. };
  6757. }
  6758. /***/ }),
  6759. /* 13 */
  6760. /***/ ((__unused_webpack_module, exports) => {
  6761. Object.defineProperty(exports, "__esModule", ({
  6762. value: true
  6763. }));
  6764. exports.GlobalWorkerOptions = void 0;
  6765. const GlobalWorkerOptions = Object.create(null);
  6766. exports.GlobalWorkerOptions = GlobalWorkerOptions;
  6767. GlobalWorkerOptions.workerPort = GlobalWorkerOptions.workerPort === undefined ? null : GlobalWorkerOptions.workerPort;
  6768. GlobalWorkerOptions.workerSrc = GlobalWorkerOptions.workerSrc === undefined ? "" : GlobalWorkerOptions.workerSrc;
  6769. /***/ }),
  6770. /* 14 */
  6771. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  6772. Object.defineProperty(exports, "__esModule", ({
  6773. value: true
  6774. }));
  6775. exports.MessageHandler = void 0;
  6776. var _util = __w_pdfjs_require__(1);
  6777. const CallbackKind = {
  6778. UNKNOWN: 0,
  6779. DATA: 1,
  6780. ERROR: 2
  6781. };
  6782. const StreamKind = {
  6783. UNKNOWN: 0,
  6784. CANCEL: 1,
  6785. CANCEL_COMPLETE: 2,
  6786. CLOSE: 3,
  6787. ENQUEUE: 4,
  6788. ERROR: 5,
  6789. PULL: 6,
  6790. PULL_COMPLETE: 7,
  6791. START_COMPLETE: 8
  6792. };
  6793. function wrapReason(reason) {
  6794. if (!(reason instanceof Error || typeof reason === "object" && reason !== null)) {
  6795. (0, _util.unreachable)('wrapReason: Expected "reason" to be a (possibly cloned) Error.');
  6796. }
  6797. switch (reason.name) {
  6798. case "AbortException":
  6799. return new _util.AbortException(reason.message);
  6800. case "MissingPDFException":
  6801. return new _util.MissingPDFException(reason.message);
  6802. case "PasswordException":
  6803. return new _util.PasswordException(reason.message, reason.code);
  6804. case "UnexpectedResponseException":
  6805. return new _util.UnexpectedResponseException(reason.message, reason.status);
  6806. case "UnknownErrorException":
  6807. return new _util.UnknownErrorException(reason.message, reason.details);
  6808. default:
  6809. return new _util.UnknownErrorException(reason.message, reason.toString());
  6810. }
  6811. }
  6812. class MessageHandler {
  6813. constructor(sourceName, targetName, comObj) {
  6814. this.sourceName = sourceName;
  6815. this.targetName = targetName;
  6816. this.comObj = comObj;
  6817. this.callbackId = 1;
  6818. this.streamId = 1;
  6819. this.streamSinks = Object.create(null);
  6820. this.streamControllers = Object.create(null);
  6821. this.callbackCapabilities = Object.create(null);
  6822. this.actionHandler = Object.create(null);
  6823. this._onComObjOnMessage = event => {
  6824. const data = event.data;
  6825. if (data.targetName !== this.sourceName) {
  6826. return;
  6827. }
  6828. if (data.stream) {
  6829. this._processStreamMessage(data);
  6830. return;
  6831. }
  6832. if (data.callback) {
  6833. const callbackId = data.callbackId;
  6834. const capability = this.callbackCapabilities[callbackId];
  6835. if (!capability) {
  6836. throw new Error(`Cannot resolve callback ${callbackId}`);
  6837. }
  6838. delete this.callbackCapabilities[callbackId];
  6839. if (data.callback === CallbackKind.DATA) {
  6840. capability.resolve(data.data);
  6841. } else if (data.callback === CallbackKind.ERROR) {
  6842. capability.reject(wrapReason(data.reason));
  6843. } else {
  6844. throw new Error("Unexpected callback case");
  6845. }
  6846. return;
  6847. }
  6848. const action = this.actionHandler[data.action];
  6849. if (!action) {
  6850. throw new Error(`Unknown action from worker: ${data.action}`);
  6851. }
  6852. if (data.callbackId) {
  6853. const cbSourceName = this.sourceName;
  6854. const cbTargetName = data.sourceName;
  6855. new Promise(function (resolve) {
  6856. resolve(action(data.data));
  6857. }).then(function (result) {
  6858. comObj.postMessage({
  6859. sourceName: cbSourceName,
  6860. targetName: cbTargetName,
  6861. callback: CallbackKind.DATA,
  6862. callbackId: data.callbackId,
  6863. data: result
  6864. });
  6865. }, function (reason) {
  6866. comObj.postMessage({
  6867. sourceName: cbSourceName,
  6868. targetName: cbTargetName,
  6869. callback: CallbackKind.ERROR,
  6870. callbackId: data.callbackId,
  6871. reason: wrapReason(reason)
  6872. });
  6873. });
  6874. return;
  6875. }
  6876. if (data.streamId) {
  6877. this._createStreamSink(data);
  6878. return;
  6879. }
  6880. action(data.data);
  6881. };
  6882. comObj.addEventListener("message", this._onComObjOnMessage);
  6883. }
  6884. on(actionName, handler) {
  6885. const ah = this.actionHandler;
  6886. if (ah[actionName]) {
  6887. throw new Error(`There is already an actionName called "${actionName}"`);
  6888. }
  6889. ah[actionName] = handler;
  6890. }
  6891. send(actionName, data, transfers) {
  6892. this.comObj.postMessage({
  6893. sourceName: this.sourceName,
  6894. targetName: this.targetName,
  6895. action: actionName,
  6896. data
  6897. }, transfers);
  6898. }
  6899. sendWithPromise(actionName, data, transfers) {
  6900. const callbackId = this.callbackId++;
  6901. const capability = (0, _util.createPromiseCapability)();
  6902. this.callbackCapabilities[callbackId] = capability;
  6903. try {
  6904. this.comObj.postMessage({
  6905. sourceName: this.sourceName,
  6906. targetName: this.targetName,
  6907. action: actionName,
  6908. callbackId,
  6909. data
  6910. }, transfers);
  6911. } catch (ex) {
  6912. capability.reject(ex);
  6913. }
  6914. return capability.promise;
  6915. }
  6916. sendWithStream(actionName, data, queueingStrategy, transfers) {
  6917. const streamId = this.streamId++,
  6918. sourceName = this.sourceName,
  6919. targetName = this.targetName,
  6920. comObj = this.comObj;
  6921. return new ReadableStream({
  6922. start: controller => {
  6923. const startCapability = (0, _util.createPromiseCapability)();
  6924. this.streamControllers[streamId] = {
  6925. controller,
  6926. startCall: startCapability,
  6927. pullCall: null,
  6928. cancelCall: null,
  6929. isClosed: false
  6930. };
  6931. comObj.postMessage({
  6932. sourceName,
  6933. targetName,
  6934. action: actionName,
  6935. streamId,
  6936. data,
  6937. desiredSize: controller.desiredSize
  6938. }, transfers);
  6939. return startCapability.promise;
  6940. },
  6941. pull: controller => {
  6942. const pullCapability = (0, _util.createPromiseCapability)();
  6943. this.streamControllers[streamId].pullCall = pullCapability;
  6944. comObj.postMessage({
  6945. sourceName,
  6946. targetName,
  6947. stream: StreamKind.PULL,
  6948. streamId,
  6949. desiredSize: controller.desiredSize
  6950. });
  6951. return pullCapability.promise;
  6952. },
  6953. cancel: reason => {
  6954. (0, _util.assert)(reason instanceof Error, "cancel must have a valid reason");
  6955. const cancelCapability = (0, _util.createPromiseCapability)();
  6956. this.streamControllers[streamId].cancelCall = cancelCapability;
  6957. this.streamControllers[streamId].isClosed = true;
  6958. comObj.postMessage({
  6959. sourceName,
  6960. targetName,
  6961. stream: StreamKind.CANCEL,
  6962. streamId,
  6963. reason: wrapReason(reason)
  6964. });
  6965. return cancelCapability.promise;
  6966. }
  6967. }, queueingStrategy);
  6968. }
  6969. _createStreamSink(data) {
  6970. const streamId = data.streamId,
  6971. sourceName = this.sourceName,
  6972. targetName = data.sourceName,
  6973. comObj = this.comObj;
  6974. const self = this,
  6975. action = this.actionHandler[data.action];
  6976. const streamSink = {
  6977. enqueue(chunk, size = 1, transfers) {
  6978. if (this.isCancelled) {
  6979. return;
  6980. }
  6981. const lastDesiredSize = this.desiredSize;
  6982. this.desiredSize -= size;
  6983. if (lastDesiredSize > 0 && this.desiredSize <= 0) {
  6984. this.sinkCapability = (0, _util.createPromiseCapability)();
  6985. this.ready = this.sinkCapability.promise;
  6986. }
  6987. comObj.postMessage({
  6988. sourceName,
  6989. targetName,
  6990. stream: StreamKind.ENQUEUE,
  6991. streamId,
  6992. chunk
  6993. }, transfers);
  6994. },
  6995. close() {
  6996. if (this.isCancelled) {
  6997. return;
  6998. }
  6999. this.isCancelled = true;
  7000. comObj.postMessage({
  7001. sourceName,
  7002. targetName,
  7003. stream: StreamKind.CLOSE,
  7004. streamId
  7005. });
  7006. delete self.streamSinks[streamId];
  7007. },
  7008. error(reason) {
  7009. (0, _util.assert)(reason instanceof Error, "error must have a valid reason");
  7010. if (this.isCancelled) {
  7011. return;
  7012. }
  7013. this.isCancelled = true;
  7014. comObj.postMessage({
  7015. sourceName,
  7016. targetName,
  7017. stream: StreamKind.ERROR,
  7018. streamId,
  7019. reason: wrapReason(reason)
  7020. });
  7021. },
  7022. sinkCapability: (0, _util.createPromiseCapability)(),
  7023. onPull: null,
  7024. onCancel: null,
  7025. isCancelled: false,
  7026. desiredSize: data.desiredSize,
  7027. ready: null
  7028. };
  7029. streamSink.sinkCapability.resolve();
  7030. streamSink.ready = streamSink.sinkCapability.promise;
  7031. this.streamSinks[streamId] = streamSink;
  7032. new Promise(function (resolve) {
  7033. resolve(action(data.data, streamSink));
  7034. }).then(function () {
  7035. comObj.postMessage({
  7036. sourceName,
  7037. targetName,
  7038. stream: StreamKind.START_COMPLETE,
  7039. streamId,
  7040. success: true
  7041. });
  7042. }, function (reason) {
  7043. comObj.postMessage({
  7044. sourceName,
  7045. targetName,
  7046. stream: StreamKind.START_COMPLETE,
  7047. streamId,
  7048. reason: wrapReason(reason)
  7049. });
  7050. });
  7051. }
  7052. _processStreamMessage(data) {
  7053. const streamId = data.streamId,
  7054. sourceName = this.sourceName,
  7055. targetName = data.sourceName,
  7056. comObj = this.comObj;
  7057. const streamController = this.streamControllers[streamId],
  7058. streamSink = this.streamSinks[streamId];
  7059. switch (data.stream) {
  7060. case StreamKind.START_COMPLETE:
  7061. if (data.success) {
  7062. streamController.startCall.resolve();
  7063. } else {
  7064. streamController.startCall.reject(wrapReason(data.reason));
  7065. }
  7066. break;
  7067. case StreamKind.PULL_COMPLETE:
  7068. if (data.success) {
  7069. streamController.pullCall.resolve();
  7070. } else {
  7071. streamController.pullCall.reject(wrapReason(data.reason));
  7072. }
  7073. break;
  7074. case StreamKind.PULL:
  7075. if (!streamSink) {
  7076. comObj.postMessage({
  7077. sourceName,
  7078. targetName,
  7079. stream: StreamKind.PULL_COMPLETE,
  7080. streamId,
  7081. success: true
  7082. });
  7083. break;
  7084. }
  7085. if (streamSink.desiredSize <= 0 && data.desiredSize > 0) {
  7086. streamSink.sinkCapability.resolve();
  7087. }
  7088. streamSink.desiredSize = data.desiredSize;
  7089. new Promise(function (resolve) {
  7090. resolve(streamSink.onPull && streamSink.onPull());
  7091. }).then(function () {
  7092. comObj.postMessage({
  7093. sourceName,
  7094. targetName,
  7095. stream: StreamKind.PULL_COMPLETE,
  7096. streamId,
  7097. success: true
  7098. });
  7099. }, function (reason) {
  7100. comObj.postMessage({
  7101. sourceName,
  7102. targetName,
  7103. stream: StreamKind.PULL_COMPLETE,
  7104. streamId,
  7105. reason: wrapReason(reason)
  7106. });
  7107. });
  7108. break;
  7109. case StreamKind.ENQUEUE:
  7110. (0, _util.assert)(streamController, "enqueue should have stream controller");
  7111. if (streamController.isClosed) {
  7112. break;
  7113. }
  7114. streamController.controller.enqueue(data.chunk);
  7115. break;
  7116. case StreamKind.CLOSE:
  7117. (0, _util.assert)(streamController, "close should have stream controller");
  7118. if (streamController.isClosed) {
  7119. break;
  7120. }
  7121. streamController.isClosed = true;
  7122. streamController.controller.close();
  7123. this._deleteStreamController(streamController, streamId);
  7124. break;
  7125. case StreamKind.ERROR:
  7126. (0, _util.assert)(streamController, "error should have stream controller");
  7127. streamController.controller.error(wrapReason(data.reason));
  7128. this._deleteStreamController(streamController, streamId);
  7129. break;
  7130. case StreamKind.CANCEL_COMPLETE:
  7131. if (data.success) {
  7132. streamController.cancelCall.resolve();
  7133. } else {
  7134. streamController.cancelCall.reject(wrapReason(data.reason));
  7135. }
  7136. this._deleteStreamController(streamController, streamId);
  7137. break;
  7138. case StreamKind.CANCEL:
  7139. if (!streamSink) {
  7140. break;
  7141. }
  7142. new Promise(function (resolve) {
  7143. resolve(streamSink.onCancel && streamSink.onCancel(wrapReason(data.reason)));
  7144. }).then(function () {
  7145. comObj.postMessage({
  7146. sourceName,
  7147. targetName,
  7148. stream: StreamKind.CANCEL_COMPLETE,
  7149. streamId,
  7150. success: true
  7151. });
  7152. }, function (reason) {
  7153. comObj.postMessage({
  7154. sourceName,
  7155. targetName,
  7156. stream: StreamKind.CANCEL_COMPLETE,
  7157. streamId,
  7158. reason: wrapReason(reason)
  7159. });
  7160. });
  7161. streamSink.sinkCapability.reject(wrapReason(data.reason));
  7162. streamSink.isCancelled = true;
  7163. delete this.streamSinks[streamId];
  7164. break;
  7165. default:
  7166. throw new Error("Unexpected stream case");
  7167. }
  7168. }
  7169. async _deleteStreamController(streamController, streamId) {
  7170. await Promise.allSettled([streamController.startCall && streamController.startCall.promise, streamController.pullCall && streamController.pullCall.promise, streamController.cancelCall && streamController.cancelCall.promise]);
  7171. delete this.streamControllers[streamId];
  7172. }
  7173. destroy() {
  7174. this.comObj.removeEventListener("message", this._onComObjOnMessage);
  7175. }
  7176. }
  7177. exports.MessageHandler = MessageHandler;
  7178. /***/ }),
  7179. /* 15 */
  7180. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  7181. Object.defineProperty(exports, "__esModule", ({
  7182. value: true
  7183. }));
  7184. exports.Metadata = void 0;
  7185. var _util = __w_pdfjs_require__(1);
  7186. class Metadata {
  7187. #metadataMap;
  7188. #data;
  7189. constructor({
  7190. parsedData,
  7191. rawData
  7192. }) {
  7193. this.#metadataMap = parsedData;
  7194. this.#data = rawData;
  7195. }
  7196. getRaw() {
  7197. return this.#data;
  7198. }
  7199. get(name) {
  7200. return this.#metadataMap.get(name) ?? null;
  7201. }
  7202. getAll() {
  7203. return (0, _util.objectFromMap)(this.#metadataMap);
  7204. }
  7205. has(name) {
  7206. return this.#metadataMap.has(name);
  7207. }
  7208. }
  7209. exports.Metadata = Metadata;
  7210. /***/ }),
  7211. /* 16 */
  7212. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  7213. Object.defineProperty(exports, "__esModule", ({
  7214. value: true
  7215. }));
  7216. exports.OptionalContentConfig = void 0;
  7217. var _util = __w_pdfjs_require__(1);
  7218. class OptionalContentGroup {
  7219. constructor(name, intent) {
  7220. this.visible = true;
  7221. this.name = name;
  7222. this.intent = intent;
  7223. }
  7224. }
  7225. class OptionalContentConfig {
  7226. constructor(data) {
  7227. this.name = null;
  7228. this.creator = null;
  7229. this._order = null;
  7230. this._groups = new Map();
  7231. if (data === null) {
  7232. return;
  7233. }
  7234. this.name = data.name;
  7235. this.creator = data.creator;
  7236. this._order = data.order;
  7237. for (const group of data.groups) {
  7238. this._groups.set(group.id, new OptionalContentGroup(group.name, group.intent));
  7239. }
  7240. if (data.baseState === "OFF") {
  7241. for (const group of this._groups) {
  7242. group.visible = false;
  7243. }
  7244. }
  7245. for (const on of data.on) {
  7246. this._groups.get(on).visible = true;
  7247. }
  7248. for (const off of data.off) {
  7249. this._groups.get(off).visible = false;
  7250. }
  7251. }
  7252. _evaluateVisibilityExpression(array) {
  7253. const length = array.length;
  7254. if (length < 2) {
  7255. return true;
  7256. }
  7257. const operator = array[0];
  7258. for (let i = 1; i < length; i++) {
  7259. const element = array[i];
  7260. let state;
  7261. if (Array.isArray(element)) {
  7262. state = this._evaluateVisibilityExpression(element);
  7263. } else if (this._groups.has(element)) {
  7264. state = this._groups.get(element).visible;
  7265. } else {
  7266. (0, _util.warn)(`Optional content group not found: ${element}`);
  7267. return true;
  7268. }
  7269. switch (operator) {
  7270. case "And":
  7271. if (!state) {
  7272. return false;
  7273. }
  7274. break;
  7275. case "Or":
  7276. if (state) {
  7277. return true;
  7278. }
  7279. break;
  7280. case "Not":
  7281. return !state;
  7282. default:
  7283. return true;
  7284. }
  7285. }
  7286. return operator === "And";
  7287. }
  7288. isVisible(group) {
  7289. if (this._groups.size === 0) {
  7290. return true;
  7291. }
  7292. if (!group) {
  7293. (0, _util.warn)("Optional content group not defined.");
  7294. return true;
  7295. }
  7296. if (group.type === "OCG") {
  7297. if (!this._groups.has(group.id)) {
  7298. (0, _util.warn)(`Optional content group not found: ${group.id}`);
  7299. return true;
  7300. }
  7301. return this._groups.get(group.id).visible;
  7302. } else if (group.type === "OCMD") {
  7303. if (group.expression) {
  7304. return this._evaluateVisibilityExpression(group.expression);
  7305. }
  7306. if (!group.policy || group.policy === "AnyOn") {
  7307. for (const id of group.ids) {
  7308. if (!this._groups.has(id)) {
  7309. (0, _util.warn)(`Optional content group not found: ${id}`);
  7310. return true;
  7311. }
  7312. if (this._groups.get(id).visible) {
  7313. return true;
  7314. }
  7315. }
  7316. return false;
  7317. } else if (group.policy === "AllOn") {
  7318. for (const id of group.ids) {
  7319. if (!this._groups.has(id)) {
  7320. (0, _util.warn)(`Optional content group not found: ${id}`);
  7321. return true;
  7322. }
  7323. if (!this._groups.get(id).visible) {
  7324. return false;
  7325. }
  7326. }
  7327. return true;
  7328. } else if (group.policy === "AnyOff") {
  7329. for (const id of group.ids) {
  7330. if (!this._groups.has(id)) {
  7331. (0, _util.warn)(`Optional content group not found: ${id}`);
  7332. return true;
  7333. }
  7334. if (!this._groups.get(id).visible) {
  7335. return true;
  7336. }
  7337. }
  7338. return false;
  7339. } else if (group.policy === "AllOff") {
  7340. for (const id of group.ids) {
  7341. if (!this._groups.has(id)) {
  7342. (0, _util.warn)(`Optional content group not found: ${id}`);
  7343. return true;
  7344. }
  7345. if (this._groups.get(id).visible) {
  7346. return false;
  7347. }
  7348. }
  7349. return true;
  7350. }
  7351. (0, _util.warn)(`Unknown optional content policy ${group.policy}.`);
  7352. return true;
  7353. }
  7354. (0, _util.warn)(`Unknown group type ${group.type}.`);
  7355. return true;
  7356. }
  7357. setVisibility(id, visible = true) {
  7358. if (!this._groups.has(id)) {
  7359. (0, _util.warn)(`Optional content group not found: ${id}`);
  7360. return;
  7361. }
  7362. this._groups.get(id).visible = !!visible;
  7363. }
  7364. getOrder() {
  7365. if (!this._groups.size) {
  7366. return null;
  7367. }
  7368. if (this._order) {
  7369. return this._order.slice();
  7370. }
  7371. return Array.from(this._groups.keys());
  7372. }
  7373. getGroups() {
  7374. return this._groups.size > 0 ? (0, _util.objectFromMap)(this._groups) : null;
  7375. }
  7376. getGroup(id) {
  7377. return this._groups.get(id) || null;
  7378. }
  7379. }
  7380. exports.OptionalContentConfig = OptionalContentConfig;
  7381. /***/ }),
  7382. /* 17 */
  7383. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  7384. Object.defineProperty(exports, "__esModule", ({
  7385. value: true
  7386. }));
  7387. exports.PDFDataTransportStream = void 0;
  7388. var _util = __w_pdfjs_require__(1);
  7389. var _display_utils = __w_pdfjs_require__(5);
  7390. class PDFDataTransportStream {
  7391. constructor(params, pdfDataRangeTransport) {
  7392. (0, _util.assert)(pdfDataRangeTransport, 'PDFDataTransportStream - missing required "pdfDataRangeTransport" argument.');
  7393. this._queuedChunks = [];
  7394. this._progressiveDone = params.progressiveDone || false;
  7395. this._contentDispositionFilename = params.contentDispositionFilename || null;
  7396. const initialData = params.initialData;
  7397. if (initialData?.length > 0) {
  7398. const buffer = new Uint8Array(initialData).buffer;
  7399. this._queuedChunks.push(buffer);
  7400. }
  7401. this._pdfDataRangeTransport = pdfDataRangeTransport;
  7402. this._isStreamingSupported = !params.disableStream;
  7403. this._isRangeSupported = !params.disableRange;
  7404. this._contentLength = params.length;
  7405. this._fullRequestReader = null;
  7406. this._rangeReaders = [];
  7407. this._pdfDataRangeTransport.addRangeListener((begin, chunk) => {
  7408. this._onReceiveData({
  7409. begin,
  7410. chunk
  7411. });
  7412. });
  7413. this._pdfDataRangeTransport.addProgressListener((loaded, total) => {
  7414. this._onProgress({
  7415. loaded,
  7416. total
  7417. });
  7418. });
  7419. this._pdfDataRangeTransport.addProgressiveReadListener(chunk => {
  7420. this._onReceiveData({
  7421. chunk
  7422. });
  7423. });
  7424. this._pdfDataRangeTransport.addProgressiveDoneListener(() => {
  7425. this._onProgressiveDone();
  7426. });
  7427. this._pdfDataRangeTransport.transportReady();
  7428. }
  7429. _onReceiveData(args) {
  7430. const buffer = new Uint8Array(args.chunk).buffer;
  7431. if (args.begin === undefined) {
  7432. if (this._fullRequestReader) {
  7433. this._fullRequestReader._enqueue(buffer);
  7434. } else {
  7435. this._queuedChunks.push(buffer);
  7436. }
  7437. } else {
  7438. const found = this._rangeReaders.some(function (rangeReader) {
  7439. if (rangeReader._begin !== args.begin) {
  7440. return false;
  7441. }
  7442. rangeReader._enqueue(buffer);
  7443. return true;
  7444. });
  7445. (0, _util.assert)(found, "_onReceiveData - no `PDFDataTransportStreamRangeReader` instance found.");
  7446. }
  7447. }
  7448. get _progressiveDataLength() {
  7449. return this._fullRequestReader?._loaded ?? 0;
  7450. }
  7451. _onProgress(evt) {
  7452. if (evt.total === undefined) {
  7453. const firstReader = this._rangeReaders[0];
  7454. if (firstReader?.onProgress) {
  7455. firstReader.onProgress({
  7456. loaded: evt.loaded
  7457. });
  7458. }
  7459. } else {
  7460. const fullReader = this._fullRequestReader;
  7461. if (fullReader?.onProgress) {
  7462. fullReader.onProgress({
  7463. loaded: evt.loaded,
  7464. total: evt.total
  7465. });
  7466. }
  7467. }
  7468. }
  7469. _onProgressiveDone() {
  7470. if (this._fullRequestReader) {
  7471. this._fullRequestReader.progressiveDone();
  7472. }
  7473. this._progressiveDone = true;
  7474. }
  7475. _removeRangeReader(reader) {
  7476. const i = this._rangeReaders.indexOf(reader);
  7477. if (i >= 0) {
  7478. this._rangeReaders.splice(i, 1);
  7479. }
  7480. }
  7481. getFullReader() {
  7482. (0, _util.assert)(!this._fullRequestReader, "PDFDataTransportStream.getFullReader can only be called once.");
  7483. const queuedChunks = this._queuedChunks;
  7484. this._queuedChunks = null;
  7485. return new PDFDataTransportStreamReader(this, queuedChunks, this._progressiveDone, this._contentDispositionFilename);
  7486. }
  7487. getRangeReader(begin, end) {
  7488. if (end <= this._progressiveDataLength) {
  7489. return null;
  7490. }
  7491. const reader = new PDFDataTransportStreamRangeReader(this, begin, end);
  7492. this._pdfDataRangeTransport.requestDataRange(begin, end);
  7493. this._rangeReaders.push(reader);
  7494. return reader;
  7495. }
  7496. cancelAllRequests(reason) {
  7497. if (this._fullRequestReader) {
  7498. this._fullRequestReader.cancel(reason);
  7499. }
  7500. for (const reader of this._rangeReaders.slice(0)) {
  7501. reader.cancel(reason);
  7502. }
  7503. this._pdfDataRangeTransport.abort();
  7504. }
  7505. }
  7506. exports.PDFDataTransportStream = PDFDataTransportStream;
  7507. class PDFDataTransportStreamReader {
  7508. constructor(stream, queuedChunks, progressiveDone = false, contentDispositionFilename = null) {
  7509. this._stream = stream;
  7510. this._done = progressiveDone || false;
  7511. this._filename = (0, _display_utils.isPdfFile)(contentDispositionFilename) ? contentDispositionFilename : null;
  7512. this._queuedChunks = queuedChunks || [];
  7513. this._loaded = 0;
  7514. for (const chunk of this._queuedChunks) {
  7515. this._loaded += chunk.byteLength;
  7516. }
  7517. this._requests = [];
  7518. this._headersReady = Promise.resolve();
  7519. stream._fullRequestReader = this;
  7520. this.onProgress = null;
  7521. }
  7522. _enqueue(chunk) {
  7523. if (this._done) {
  7524. return;
  7525. }
  7526. if (this._requests.length > 0) {
  7527. const requestCapability = this._requests.shift();
  7528. requestCapability.resolve({
  7529. value: chunk,
  7530. done: false
  7531. });
  7532. } else {
  7533. this._queuedChunks.push(chunk);
  7534. }
  7535. this._loaded += chunk.byteLength;
  7536. }
  7537. get headersReady() {
  7538. return this._headersReady;
  7539. }
  7540. get filename() {
  7541. return this._filename;
  7542. }
  7543. get isRangeSupported() {
  7544. return this._stream._isRangeSupported;
  7545. }
  7546. get isStreamingSupported() {
  7547. return this._stream._isStreamingSupported;
  7548. }
  7549. get contentLength() {
  7550. return this._stream._contentLength;
  7551. }
  7552. async read() {
  7553. if (this._queuedChunks.length > 0) {
  7554. const chunk = this._queuedChunks.shift();
  7555. return {
  7556. value: chunk,
  7557. done: false
  7558. };
  7559. }
  7560. if (this._done) {
  7561. return {
  7562. value: undefined,
  7563. done: true
  7564. };
  7565. }
  7566. const requestCapability = (0, _util.createPromiseCapability)();
  7567. this._requests.push(requestCapability);
  7568. return requestCapability.promise;
  7569. }
  7570. cancel(reason) {
  7571. this._done = true;
  7572. for (const requestCapability of this._requests) {
  7573. requestCapability.resolve({
  7574. value: undefined,
  7575. done: true
  7576. });
  7577. }
  7578. this._requests.length = 0;
  7579. }
  7580. progressiveDone() {
  7581. if (this._done) {
  7582. return;
  7583. }
  7584. this._done = true;
  7585. }
  7586. }
  7587. class PDFDataTransportStreamRangeReader {
  7588. constructor(stream, begin, end) {
  7589. this._stream = stream;
  7590. this._begin = begin;
  7591. this._end = end;
  7592. this._queuedChunk = null;
  7593. this._requests = [];
  7594. this._done = false;
  7595. this.onProgress = null;
  7596. }
  7597. _enqueue(chunk) {
  7598. if (this._done) {
  7599. return;
  7600. }
  7601. if (this._requests.length === 0) {
  7602. this._queuedChunk = chunk;
  7603. } else {
  7604. const requestsCapability = this._requests.shift();
  7605. requestsCapability.resolve({
  7606. value: chunk,
  7607. done: false
  7608. });
  7609. for (const requestCapability of this._requests) {
  7610. requestCapability.resolve({
  7611. value: undefined,
  7612. done: true
  7613. });
  7614. }
  7615. this._requests.length = 0;
  7616. }
  7617. this._done = true;
  7618. this._stream._removeRangeReader(this);
  7619. }
  7620. get isStreamingSupported() {
  7621. return false;
  7622. }
  7623. async read() {
  7624. if (this._queuedChunk) {
  7625. const chunk = this._queuedChunk;
  7626. this._queuedChunk = null;
  7627. return {
  7628. value: chunk,
  7629. done: false
  7630. };
  7631. }
  7632. if (this._done) {
  7633. return {
  7634. value: undefined,
  7635. done: true
  7636. };
  7637. }
  7638. const requestCapability = (0, _util.createPromiseCapability)();
  7639. this._requests.push(requestCapability);
  7640. return requestCapability.promise;
  7641. }
  7642. cancel(reason) {
  7643. this._done = true;
  7644. for (const requestCapability of this._requests) {
  7645. requestCapability.resolve({
  7646. value: undefined,
  7647. done: true
  7648. });
  7649. }
  7650. this._requests.length = 0;
  7651. this._stream._removeRangeReader(this);
  7652. }
  7653. }
  7654. /***/ }),
  7655. /* 18 */
  7656. /***/ ((__unused_webpack_module, exports) => {
  7657. Object.defineProperty(exports, "__esModule", ({
  7658. value: true
  7659. }));
  7660. exports.XfaText = void 0;
  7661. class XfaText {
  7662. static textContent(xfa) {
  7663. const items = [];
  7664. const output = {
  7665. items,
  7666. styles: Object.create(null)
  7667. };
  7668. function walk(node) {
  7669. if (!node) {
  7670. return;
  7671. }
  7672. let str = null;
  7673. const name = node.name;
  7674. if (name === "#text") {
  7675. str = node.value;
  7676. } else if (!XfaText.shouldBuildText(name)) {
  7677. return;
  7678. } else if (node?.attributes?.textContent) {
  7679. str = node.attributes.textContent;
  7680. } else if (node.value) {
  7681. str = node.value;
  7682. }
  7683. if (str !== null) {
  7684. items.push({
  7685. str
  7686. });
  7687. }
  7688. if (!node.children) {
  7689. return;
  7690. }
  7691. for (const child of node.children) {
  7692. walk(child);
  7693. }
  7694. }
  7695. walk(xfa);
  7696. return output;
  7697. }
  7698. static shouldBuildText(name) {
  7699. return !(name === "textarea" || name === "input" || name === "option" || name === "select");
  7700. }
  7701. }
  7702. exports.XfaText = XfaText;
  7703. /***/ }),
  7704. /* 19 */
  7705. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  7706. Object.defineProperty(exports, "__esModule", ({
  7707. value: true
  7708. }));
  7709. exports.NodeStandardFontDataFactory = exports.NodeCanvasFactory = exports.NodeCMapReaderFactory = void 0;
  7710. var _base_factory = __w_pdfjs_require__(6);
  7711. ;
  7712. const fetchData = function (url) {
  7713. return new Promise((resolve, reject) => {
  7714. const fs = require("fs");
  7715. fs.readFile(url, (error, data) => {
  7716. if (error || !data) {
  7717. reject(new Error(error));
  7718. return;
  7719. }
  7720. resolve(new Uint8Array(data));
  7721. });
  7722. });
  7723. };
  7724. class NodeCanvasFactory extends _base_factory.BaseCanvasFactory {
  7725. _createCanvas(width, height) {
  7726. const Canvas = require("canvas");
  7727. return Canvas.createCanvas(width, height);
  7728. }
  7729. }
  7730. exports.NodeCanvasFactory = NodeCanvasFactory;
  7731. class NodeCMapReaderFactory extends _base_factory.BaseCMapReaderFactory {
  7732. _fetchData(url, compressionType) {
  7733. return fetchData(url).then(data => {
  7734. return {
  7735. cMapData: data,
  7736. compressionType
  7737. };
  7738. });
  7739. }
  7740. }
  7741. exports.NodeCMapReaderFactory = NodeCMapReaderFactory;
  7742. class NodeStandardFontDataFactory extends _base_factory.BaseStandardFontDataFactory {
  7743. _fetchData(url) {
  7744. return fetchData(url);
  7745. }
  7746. }
  7747. exports.NodeStandardFontDataFactory = NodeStandardFontDataFactory;
  7748. /***/ }),
  7749. /* 20 */
  7750. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  7751. Object.defineProperty(exports, "__esModule", ({
  7752. value: true
  7753. }));
  7754. exports.AnnotationLayer = void 0;
  7755. var _util = __w_pdfjs_require__(1);
  7756. var _display_utils = __w_pdfjs_require__(5);
  7757. var _annotation_storage = __w_pdfjs_require__(8);
  7758. var _scripting_utils = __w_pdfjs_require__(21);
  7759. var _xfa_layer = __w_pdfjs_require__(22);
  7760. const DEFAULT_TAB_INDEX = 1000;
  7761. const GetElementsByNameSet = new WeakSet();
  7762. function getRectDims(rect) {
  7763. return {
  7764. width: rect[2] - rect[0],
  7765. height: rect[3] - rect[1]
  7766. };
  7767. }
  7768. class AnnotationElementFactory {
  7769. static create(parameters) {
  7770. const subtype = parameters.data.annotationType;
  7771. switch (subtype) {
  7772. case _util.AnnotationType.LINK:
  7773. return new LinkAnnotationElement(parameters);
  7774. case _util.AnnotationType.TEXT:
  7775. return new TextAnnotationElement(parameters);
  7776. case _util.AnnotationType.WIDGET:
  7777. const fieldType = parameters.data.fieldType;
  7778. switch (fieldType) {
  7779. case "Tx":
  7780. return new TextWidgetAnnotationElement(parameters);
  7781. case "Btn":
  7782. if (parameters.data.radioButton) {
  7783. return new RadioButtonWidgetAnnotationElement(parameters);
  7784. } else if (parameters.data.checkBox) {
  7785. return new CheckboxWidgetAnnotationElement(parameters);
  7786. }
  7787. return new PushButtonWidgetAnnotationElement(parameters);
  7788. case "Ch":
  7789. return new ChoiceWidgetAnnotationElement(parameters);
  7790. }
  7791. return new WidgetAnnotationElement(parameters);
  7792. case _util.AnnotationType.POPUP:
  7793. return new PopupAnnotationElement(parameters);
  7794. case _util.AnnotationType.FREETEXT:
  7795. return new FreeTextAnnotationElement(parameters);
  7796. case _util.AnnotationType.LINE:
  7797. return new LineAnnotationElement(parameters);
  7798. case _util.AnnotationType.SQUARE:
  7799. return new SquareAnnotationElement(parameters);
  7800. case _util.AnnotationType.CIRCLE:
  7801. return new CircleAnnotationElement(parameters);
  7802. case _util.AnnotationType.POLYLINE:
  7803. return new PolylineAnnotationElement(parameters);
  7804. case _util.AnnotationType.CARET:
  7805. return new CaretAnnotationElement(parameters);
  7806. case _util.AnnotationType.INK:
  7807. return new InkAnnotationElement(parameters);
  7808. case _util.AnnotationType.POLYGON:
  7809. return new PolygonAnnotationElement(parameters);
  7810. case _util.AnnotationType.HIGHLIGHT:
  7811. return new HighlightAnnotationElement(parameters);
  7812. case _util.AnnotationType.UNDERLINE:
  7813. return new UnderlineAnnotationElement(parameters);
  7814. case _util.AnnotationType.SQUIGGLY:
  7815. return new SquigglyAnnotationElement(parameters);
  7816. case _util.AnnotationType.STRIKEOUT:
  7817. return new StrikeOutAnnotationElement(parameters);
  7818. case _util.AnnotationType.STAMP:
  7819. return new StampAnnotationElement(parameters);
  7820. case _util.AnnotationType.FILEATTACHMENT:
  7821. return new FileAttachmentAnnotationElement(parameters);
  7822. default:
  7823. return new AnnotationElement(parameters);
  7824. }
  7825. }
  7826. }
  7827. class AnnotationElement {
  7828. constructor(parameters, {
  7829. isRenderable = false,
  7830. ignoreBorder = false,
  7831. createQuadrilaterals = false
  7832. } = {}) {
  7833. this.isRenderable = isRenderable;
  7834. this.data = parameters.data;
  7835. this.layer = parameters.layer;
  7836. this.page = parameters.page;
  7837. this.viewport = parameters.viewport;
  7838. this.linkService = parameters.linkService;
  7839. this.downloadManager = parameters.downloadManager;
  7840. this.imageResourcesPath = parameters.imageResourcesPath;
  7841. this.renderForms = parameters.renderForms;
  7842. this.svgFactory = parameters.svgFactory;
  7843. this.annotationStorage = parameters.annotationStorage;
  7844. this.enableScripting = parameters.enableScripting;
  7845. this.hasJSActions = parameters.hasJSActions;
  7846. this._fieldObjects = parameters.fieldObjects;
  7847. this._mouseState = parameters.mouseState;
  7848. if (isRenderable) {
  7849. this.container = this._createContainer(ignoreBorder);
  7850. }
  7851. if (createQuadrilaterals) {
  7852. this.quadrilaterals = this._createQuadrilaterals(ignoreBorder);
  7853. }
  7854. }
  7855. _createContainer(ignoreBorder = false) {
  7856. const data = this.data,
  7857. page = this.page,
  7858. viewport = this.viewport;
  7859. const container = document.createElement("section");
  7860. let {
  7861. width,
  7862. height
  7863. } = getRectDims(data.rect);
  7864. container.setAttribute("data-annotation-id", data.id);
  7865. 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]]);
  7866. if (data.hasOwnCanvas) {
  7867. const transform = viewport.transform.slice();
  7868. const [scaleX, scaleY] = _util.Util.singularValueDecompose2dScale(transform);
  7869. width = Math.ceil(width * scaleX);
  7870. height = Math.ceil(height * scaleY);
  7871. rect[0] *= scaleX;
  7872. rect[1] *= scaleY;
  7873. for (let i = 0; i < 4; i++) {
  7874. transform[i] = Math.sign(transform[i]);
  7875. }
  7876. container.style.transform = `matrix(${transform.join(",")})`;
  7877. } else {
  7878. container.style.transform = `matrix(${viewport.transform.join(",")})`;
  7879. }
  7880. container.style.transformOrigin = `${-rect[0]}px ${-rect[1]}px`;
  7881. if (!ignoreBorder && data.borderStyle.width > 0) {
  7882. container.style.borderWidth = `${data.borderStyle.width}px`;
  7883. if (data.borderStyle.style !== _util.AnnotationBorderStyleType.UNDERLINE) {
  7884. width -= 2 * data.borderStyle.width;
  7885. height -= 2 * data.borderStyle.width;
  7886. }
  7887. const horizontalRadius = data.borderStyle.horizontalCornerRadius;
  7888. const verticalRadius = data.borderStyle.verticalCornerRadius;
  7889. if (horizontalRadius > 0 || verticalRadius > 0) {
  7890. const radius = `${horizontalRadius}px / ${verticalRadius}px`;
  7891. container.style.borderRadius = radius;
  7892. }
  7893. switch (data.borderStyle.style) {
  7894. case _util.AnnotationBorderStyleType.SOLID:
  7895. container.style.borderStyle = "solid";
  7896. break;
  7897. case _util.AnnotationBorderStyleType.DASHED:
  7898. container.style.borderStyle = "dashed";
  7899. break;
  7900. case _util.AnnotationBorderStyleType.BEVELED:
  7901. (0, _util.warn)("Unimplemented border style: beveled");
  7902. break;
  7903. case _util.AnnotationBorderStyleType.INSET:
  7904. (0, _util.warn)("Unimplemented border style: inset");
  7905. break;
  7906. case _util.AnnotationBorderStyleType.UNDERLINE:
  7907. container.style.borderBottomStyle = "solid";
  7908. break;
  7909. default:
  7910. break;
  7911. }
  7912. const borderColor = data.borderColor || data.color || null;
  7913. if (borderColor) {
  7914. container.style.borderColor = _util.Util.makeHexColor(data.color[0] | 0, data.color[1] | 0, data.color[2] | 0);
  7915. } else {
  7916. container.style.borderWidth = 0;
  7917. }
  7918. }
  7919. container.style.left = `${rect[0]}px`;
  7920. container.style.top = `${rect[1]}px`;
  7921. if (data.hasOwnCanvas) {
  7922. container.style.width = container.style.height = "auto";
  7923. } else {
  7924. container.style.width = `${width}px`;
  7925. container.style.height = `${height}px`;
  7926. }
  7927. return container;
  7928. }
  7929. get _commonActions() {
  7930. const setColor = (jsName, styleName, event) => {
  7931. const color = event.detail[jsName];
  7932. event.target.style[styleName] = _scripting_utils.ColorConverters[`${color[0]}_HTML`](color.slice(1));
  7933. };
  7934. return (0, _util.shadow)(this, "_commonActions", {
  7935. display: event => {
  7936. const hidden = event.detail.display % 2 === 1;
  7937. event.target.style.visibility = hidden ? "hidden" : "visible";
  7938. this.annotationStorage.setValue(this.data.id, {
  7939. hidden,
  7940. print: event.detail.display === 0 || event.detail.display === 3
  7941. });
  7942. },
  7943. print: event => {
  7944. this.annotationStorage.setValue(this.data.id, {
  7945. print: event.detail.print
  7946. });
  7947. },
  7948. hidden: event => {
  7949. event.target.style.visibility = event.detail.hidden ? "hidden" : "visible";
  7950. this.annotationStorage.setValue(this.data.id, {
  7951. hidden: event.detail.hidden
  7952. });
  7953. },
  7954. focus: event => {
  7955. setTimeout(() => event.target.focus({
  7956. preventScroll: false
  7957. }), 0);
  7958. },
  7959. userName: event => {
  7960. event.target.title = event.detail.userName;
  7961. },
  7962. readonly: event => {
  7963. if (event.detail.readonly) {
  7964. event.target.setAttribute("readonly", "");
  7965. } else {
  7966. event.target.removeAttribute("readonly");
  7967. }
  7968. },
  7969. required: event => {
  7970. if (event.detail.required) {
  7971. event.target.setAttribute("required", "");
  7972. } else {
  7973. event.target.removeAttribute("required");
  7974. }
  7975. },
  7976. bgColor: event => {
  7977. setColor("bgColor", "backgroundColor", event);
  7978. },
  7979. fillColor: event => {
  7980. setColor("fillColor", "backgroundColor", event);
  7981. },
  7982. fgColor: event => {
  7983. setColor("fgColor", "color", event);
  7984. },
  7985. textColor: event => {
  7986. setColor("textColor", "color", event);
  7987. },
  7988. borderColor: event => {
  7989. setColor("borderColor", "borderColor", event);
  7990. },
  7991. strokeColor: event => {
  7992. setColor("strokeColor", "borderColor", event);
  7993. }
  7994. });
  7995. }
  7996. _dispatchEventFromSandbox(actions, jsEvent) {
  7997. const commonActions = this._commonActions;
  7998. for (const name of Object.keys(jsEvent.detail)) {
  7999. const action = actions[name] || commonActions[name];
  8000. if (action) {
  8001. action(jsEvent);
  8002. }
  8003. }
  8004. }
  8005. _setDefaultPropertiesFromJS(element) {
  8006. if (!this.enableScripting) {
  8007. return;
  8008. }
  8009. const storedData = this.annotationStorage.getRawValue(this.data.id);
  8010. if (!storedData) {
  8011. return;
  8012. }
  8013. const commonActions = this._commonActions;
  8014. for (const [actionName, detail] of Object.entries(storedData)) {
  8015. const action = commonActions[actionName];
  8016. if (action) {
  8017. action({
  8018. detail,
  8019. target: element
  8020. });
  8021. delete storedData[actionName];
  8022. }
  8023. }
  8024. }
  8025. _createQuadrilaterals(ignoreBorder = false) {
  8026. if (!this.data.quadPoints) {
  8027. return null;
  8028. }
  8029. const quadrilaterals = [];
  8030. const savedRect = this.data.rect;
  8031. for (const quadPoint of this.data.quadPoints) {
  8032. this.data.rect = [quadPoint[2].x, quadPoint[2].y, quadPoint[1].x, quadPoint[1].y];
  8033. quadrilaterals.push(this._createContainer(ignoreBorder));
  8034. }
  8035. this.data.rect = savedRect;
  8036. return quadrilaterals;
  8037. }
  8038. _createPopup(trigger, data) {
  8039. let container = this.container;
  8040. if (this.quadrilaterals) {
  8041. trigger = trigger || this.quadrilaterals;
  8042. container = this.quadrilaterals[0];
  8043. }
  8044. if (!trigger) {
  8045. trigger = document.createElement("div");
  8046. trigger.style.height = container.style.height;
  8047. trigger.style.width = container.style.width;
  8048. container.appendChild(trigger);
  8049. }
  8050. const popupElement = new PopupElement({
  8051. container,
  8052. trigger,
  8053. color: data.color,
  8054. titleObj: data.titleObj,
  8055. modificationDate: data.modificationDate,
  8056. contentsObj: data.contentsObj,
  8057. richText: data.richText,
  8058. hideWrapper: true
  8059. });
  8060. const popup = popupElement.render();
  8061. popup.style.left = container.style.width;
  8062. container.appendChild(popup);
  8063. }
  8064. _renderQuadrilaterals(className) {
  8065. for (const quadrilateral of this.quadrilaterals) {
  8066. quadrilateral.className = className;
  8067. }
  8068. return this.quadrilaterals;
  8069. }
  8070. render() {
  8071. (0, _util.unreachable)("Abstract method `AnnotationElement.render` called");
  8072. }
  8073. _getElementsByName(name, skipId = null) {
  8074. const fields = [];
  8075. if (this._fieldObjects) {
  8076. const fieldObj = this._fieldObjects[name];
  8077. if (fieldObj) {
  8078. for (const {
  8079. page,
  8080. id,
  8081. exportValues
  8082. } of fieldObj) {
  8083. if (page === -1) {
  8084. continue;
  8085. }
  8086. if (id === skipId) {
  8087. continue;
  8088. }
  8089. const exportValue = typeof exportValues === "string" ? exportValues : null;
  8090. const domElement = document.getElementById(id);
  8091. if (domElement && !GetElementsByNameSet.has(domElement)) {
  8092. (0, _util.warn)(`_getElementsByName - element not allowed: ${id}`);
  8093. continue;
  8094. }
  8095. fields.push({
  8096. id,
  8097. exportValue,
  8098. domElement
  8099. });
  8100. }
  8101. }
  8102. return fields;
  8103. }
  8104. for (const domElement of document.getElementsByName(name)) {
  8105. const {
  8106. id,
  8107. exportValue
  8108. } = domElement;
  8109. if (id === skipId) {
  8110. continue;
  8111. }
  8112. if (!GetElementsByNameSet.has(domElement)) {
  8113. continue;
  8114. }
  8115. fields.push({
  8116. id,
  8117. exportValue,
  8118. domElement
  8119. });
  8120. }
  8121. return fields;
  8122. }
  8123. static get platform() {
  8124. const platform = typeof navigator !== "undefined" ? navigator.platform : "";
  8125. return (0, _util.shadow)(this, "platform", {
  8126. isWin: platform.includes("Win"),
  8127. isMac: platform.includes("Mac")
  8128. });
  8129. }
  8130. }
  8131. class LinkAnnotationElement extends AnnotationElement {
  8132. constructor(parameters, options = null) {
  8133. const isRenderable = !!(parameters.data.url || parameters.data.dest || parameters.data.action || parameters.data.isTooltipOnly || parameters.data.resetForm || parameters.data.actions && (parameters.data.actions.Action || parameters.data.actions["Mouse Up"] || parameters.data.actions["Mouse Down"]));
  8134. super(parameters, {
  8135. isRenderable,
  8136. ignoreBorder: !!options?.ignoreBorder,
  8137. createQuadrilaterals: true
  8138. });
  8139. }
  8140. render() {
  8141. const {
  8142. data,
  8143. linkService
  8144. } = this;
  8145. const link = document.createElement("a");
  8146. if (data.url) {
  8147. linkService.addLinkAttributes(link, data.url, data.newWindow);
  8148. } else if (data.action) {
  8149. this._bindNamedAction(link, data.action);
  8150. } else if (data.dest) {
  8151. this._bindLink(link, data.dest);
  8152. } else {
  8153. let hasClickAction = false;
  8154. if (data.actions && (data.actions.Action || data.actions["Mouse Up"] || data.actions["Mouse Down"]) && this.enableScripting && this.hasJSActions) {
  8155. hasClickAction = true;
  8156. this._bindJSAction(link, data);
  8157. }
  8158. if (data.resetForm) {
  8159. this._bindResetFormAction(link, data.resetForm);
  8160. } else if (!hasClickAction) {
  8161. this._bindLink(link, "");
  8162. }
  8163. }
  8164. if (this.quadrilaterals) {
  8165. return this._renderQuadrilaterals("linkAnnotation").map((quadrilateral, index) => {
  8166. const linkElement = index === 0 ? link : link.cloneNode();
  8167. quadrilateral.appendChild(linkElement);
  8168. return quadrilateral;
  8169. });
  8170. }
  8171. this.container.className = "linkAnnotation";
  8172. this.container.appendChild(link);
  8173. return this.container;
  8174. }
  8175. _bindLink(link, destination) {
  8176. link.href = this.linkService.getDestinationHash(destination);
  8177. link.onclick = () => {
  8178. if (destination) {
  8179. this.linkService.goToDestination(destination);
  8180. }
  8181. return false;
  8182. };
  8183. if (destination || destination === "") {
  8184. link.className = "internalLink";
  8185. }
  8186. }
  8187. _bindNamedAction(link, action) {
  8188. link.href = this.linkService.getAnchorUrl("");
  8189. link.onclick = () => {
  8190. this.linkService.executeNamedAction(action);
  8191. return false;
  8192. };
  8193. link.className = "internalLink";
  8194. }
  8195. _bindJSAction(link, data) {
  8196. link.href = this.linkService.getAnchorUrl("");
  8197. const map = new Map([["Action", "onclick"], ["Mouse Up", "onmouseup"], ["Mouse Down", "onmousedown"]]);
  8198. for (const name of Object.keys(data.actions)) {
  8199. const jsName = map.get(name);
  8200. if (!jsName) {
  8201. continue;
  8202. }
  8203. link[jsName] = () => {
  8204. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  8205. source: this,
  8206. detail: {
  8207. id: data.id,
  8208. name
  8209. }
  8210. });
  8211. return false;
  8212. };
  8213. }
  8214. if (!link.onclick) {
  8215. link.onclick = () => false;
  8216. }
  8217. link.className = "internalLink";
  8218. }
  8219. _bindResetFormAction(link, resetForm) {
  8220. const otherClickAction = link.onclick;
  8221. if (!otherClickAction) {
  8222. link.href = this.linkService.getAnchorUrl("");
  8223. }
  8224. link.className = "internalLink";
  8225. if (!this._fieldObjects) {
  8226. (0, _util.warn)(`_bindResetFormAction - "resetForm" action not supported, ` + "ensure that the `fieldObjects` parameter is provided.");
  8227. if (!otherClickAction) {
  8228. link.onclick = () => false;
  8229. }
  8230. return;
  8231. }
  8232. link.onclick = () => {
  8233. if (otherClickAction) {
  8234. otherClickAction();
  8235. }
  8236. const {
  8237. fields: resetFormFields,
  8238. refs: resetFormRefs,
  8239. include
  8240. } = resetForm;
  8241. const allFields = [];
  8242. if (resetFormFields.length !== 0 || resetFormRefs.length !== 0) {
  8243. const fieldIds = new Set(resetFormRefs);
  8244. for (const fieldName of resetFormFields) {
  8245. const fields = this._fieldObjects[fieldName] || [];
  8246. for (const {
  8247. id
  8248. } of fields) {
  8249. fieldIds.add(id);
  8250. }
  8251. }
  8252. for (const fields of Object.values(this._fieldObjects)) {
  8253. for (const field of fields) {
  8254. if (fieldIds.has(field.id) === include) {
  8255. allFields.push(field);
  8256. }
  8257. }
  8258. }
  8259. } else {
  8260. for (const fields of Object.values(this._fieldObjects)) {
  8261. allFields.push(...fields);
  8262. }
  8263. }
  8264. const storage = this.annotationStorage;
  8265. const allIds = [];
  8266. for (const field of allFields) {
  8267. const {
  8268. id
  8269. } = field;
  8270. allIds.push(id);
  8271. switch (field.type) {
  8272. case "text":
  8273. {
  8274. const value = field.defaultValue || "";
  8275. storage.setValue(id, {
  8276. value
  8277. });
  8278. break;
  8279. }
  8280. case "checkbox":
  8281. case "radiobutton":
  8282. {
  8283. const value = field.defaultValue === field.exportValues;
  8284. storage.setValue(id, {
  8285. value
  8286. });
  8287. break;
  8288. }
  8289. case "combobox":
  8290. case "listbox":
  8291. {
  8292. const value = field.defaultValue || "";
  8293. storage.setValue(id, {
  8294. value
  8295. });
  8296. break;
  8297. }
  8298. default:
  8299. continue;
  8300. }
  8301. const domElement = document.getElementById(id);
  8302. if (!domElement || !GetElementsByNameSet.has(domElement)) {
  8303. continue;
  8304. }
  8305. domElement.dispatchEvent(new Event("resetform"));
  8306. }
  8307. if (this.enableScripting) {
  8308. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  8309. source: this,
  8310. detail: {
  8311. id: "app",
  8312. ids: allIds,
  8313. name: "ResetForm"
  8314. }
  8315. });
  8316. }
  8317. return false;
  8318. };
  8319. }
  8320. }
  8321. class TextAnnotationElement extends AnnotationElement {
  8322. constructor(parameters) {
  8323. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  8324. super(parameters, {
  8325. isRenderable
  8326. });
  8327. }
  8328. render() {
  8329. this.container.className = "textAnnotation";
  8330. const image = document.createElement("img");
  8331. image.style.height = this.container.style.height;
  8332. image.style.width = this.container.style.width;
  8333. image.src = this.imageResourcesPath + "annotation-" + this.data.name.toLowerCase() + ".svg";
  8334. image.alt = "[{{type}} Annotation]";
  8335. image.dataset.l10nId = "text_annotation_type";
  8336. image.dataset.l10nArgs = JSON.stringify({
  8337. type: this.data.name
  8338. });
  8339. if (!this.data.hasPopup) {
  8340. this._createPopup(image, this.data);
  8341. }
  8342. this.container.appendChild(image);
  8343. return this.container;
  8344. }
  8345. }
  8346. class WidgetAnnotationElement extends AnnotationElement {
  8347. render() {
  8348. if (this.data.alternativeText) {
  8349. this.container.title = this.data.alternativeText;
  8350. }
  8351. return this.container;
  8352. }
  8353. _getKeyModifier(event) {
  8354. const {
  8355. isWin,
  8356. isMac
  8357. } = AnnotationElement.platform;
  8358. return isWin && event.ctrlKey || isMac && event.metaKey;
  8359. }
  8360. _setEventListener(element, baseName, eventName, valueGetter) {
  8361. if (baseName.includes("mouse")) {
  8362. element.addEventListener(baseName, event => {
  8363. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  8364. source: this,
  8365. detail: {
  8366. id: this.data.id,
  8367. name: eventName,
  8368. value: valueGetter(event),
  8369. shift: event.shiftKey,
  8370. modifier: this._getKeyModifier(event)
  8371. }
  8372. });
  8373. });
  8374. } else {
  8375. element.addEventListener(baseName, event => {
  8376. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  8377. source: this,
  8378. detail: {
  8379. id: this.data.id,
  8380. name: eventName,
  8381. value: valueGetter(event)
  8382. }
  8383. });
  8384. });
  8385. }
  8386. }
  8387. _setEventListeners(element, names, getter) {
  8388. for (const [baseName, eventName] of names) {
  8389. if (eventName === "Action" || this.data.actions?.[eventName]) {
  8390. this._setEventListener(element, baseName, eventName, getter);
  8391. }
  8392. }
  8393. }
  8394. _setBackgroundColor(element) {
  8395. const color = this.data.backgroundColor || null;
  8396. element.style.backgroundColor = color === null ? "transparent" : _util.Util.makeHexColor(color[0], color[1], color[2]);
  8397. }
  8398. }
  8399. class TextWidgetAnnotationElement extends WidgetAnnotationElement {
  8400. constructor(parameters) {
  8401. const isRenderable = parameters.renderForms || !parameters.data.hasAppearance && !!parameters.data.fieldValue;
  8402. super(parameters, {
  8403. isRenderable
  8404. });
  8405. }
  8406. setPropertyOnSiblings(base, key, value, keyInStorage) {
  8407. const storage = this.annotationStorage;
  8408. for (const element of this._getElementsByName(base.name, base.id)) {
  8409. if (element.domElement) {
  8410. element.domElement[key] = value;
  8411. }
  8412. storage.setValue(element.id, {
  8413. [keyInStorage]: value
  8414. });
  8415. }
  8416. }
  8417. render() {
  8418. const storage = this.annotationStorage;
  8419. const id = this.data.id;
  8420. this.container.className = "textWidgetAnnotation";
  8421. let element = null;
  8422. if (this.renderForms) {
  8423. const storedData = storage.getValue(id, {
  8424. value: this.data.fieldValue
  8425. });
  8426. const textContent = storedData.formattedValue || storedData.value || "";
  8427. const elementData = {
  8428. userValue: null,
  8429. formattedValue: null,
  8430. valueOnFocus: ""
  8431. };
  8432. if (this.data.multiLine) {
  8433. element = document.createElement("textarea");
  8434. element.textContent = textContent;
  8435. } else {
  8436. element = document.createElement("input");
  8437. element.type = "text";
  8438. element.setAttribute("value", textContent);
  8439. }
  8440. GetElementsByNameSet.add(element);
  8441. element.disabled = this.data.readOnly;
  8442. element.name = this.data.fieldName;
  8443. element.tabIndex = DEFAULT_TAB_INDEX;
  8444. elementData.userValue = textContent;
  8445. element.setAttribute("id", id);
  8446. element.addEventListener("input", event => {
  8447. storage.setValue(id, {
  8448. value: event.target.value
  8449. });
  8450. this.setPropertyOnSiblings(element, "value", event.target.value, "value");
  8451. });
  8452. element.addEventListener("resetform", event => {
  8453. const defaultValue = this.data.defaultFieldValue ?? "";
  8454. element.value = elementData.userValue = defaultValue;
  8455. elementData.formattedValue = null;
  8456. });
  8457. let blurListener = event => {
  8458. const {
  8459. formattedValue
  8460. } = elementData;
  8461. if (formattedValue !== null && formattedValue !== undefined) {
  8462. event.target.value = formattedValue;
  8463. }
  8464. event.target.scrollLeft = 0;
  8465. };
  8466. if (this.enableScripting && this.hasJSActions) {
  8467. element.addEventListener("focus", event => {
  8468. if (elementData.userValue) {
  8469. event.target.value = elementData.userValue;
  8470. }
  8471. elementData.valueOnFocus = event.target.value;
  8472. });
  8473. element.addEventListener("updatefromsandbox", jsEvent => {
  8474. const actions = {
  8475. value(event) {
  8476. elementData.userValue = event.detail.value ?? "";
  8477. storage.setValue(id, {
  8478. value: elementData.userValue.toString()
  8479. });
  8480. event.target.value = elementData.userValue;
  8481. },
  8482. formattedValue(event) {
  8483. const {
  8484. formattedValue
  8485. } = event.detail;
  8486. elementData.formattedValue = formattedValue;
  8487. if (formattedValue !== null && formattedValue !== undefined && event.target !== document.activeElement) {
  8488. event.target.value = formattedValue;
  8489. }
  8490. storage.setValue(id, {
  8491. formattedValue
  8492. });
  8493. },
  8494. selRange(event) {
  8495. event.target.setSelectionRange(...event.detail.selRange);
  8496. }
  8497. };
  8498. this._dispatchEventFromSandbox(actions, jsEvent);
  8499. });
  8500. element.addEventListener("keydown", event => {
  8501. let commitKey = -1;
  8502. if (event.key === "Escape") {
  8503. commitKey = 0;
  8504. } else if (event.key === "Enter") {
  8505. commitKey = 2;
  8506. } else if (event.key === "Tab") {
  8507. commitKey = 3;
  8508. }
  8509. if (commitKey === -1) {
  8510. return;
  8511. }
  8512. const {
  8513. value
  8514. } = event.target;
  8515. if (elementData.valueOnFocus === value) {
  8516. return;
  8517. }
  8518. elementData.userValue = value;
  8519. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  8520. source: this,
  8521. detail: {
  8522. id,
  8523. name: "Keystroke",
  8524. value,
  8525. willCommit: true,
  8526. commitKey,
  8527. selStart: event.target.selectionStart,
  8528. selEnd: event.target.selectionEnd
  8529. }
  8530. });
  8531. });
  8532. const _blurListener = blurListener;
  8533. blurListener = null;
  8534. element.addEventListener("blur", event => {
  8535. const {
  8536. value
  8537. } = event.target;
  8538. elementData.userValue = value;
  8539. if (this._mouseState.isDown && elementData.valueOnFocus !== value) {
  8540. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  8541. source: this,
  8542. detail: {
  8543. id,
  8544. name: "Keystroke",
  8545. value,
  8546. willCommit: true,
  8547. commitKey: 1,
  8548. selStart: event.target.selectionStart,
  8549. selEnd: event.target.selectionEnd
  8550. }
  8551. });
  8552. }
  8553. _blurListener(event);
  8554. });
  8555. if (this.data.actions?.Keystroke) {
  8556. element.addEventListener("beforeinput", event => {
  8557. const {
  8558. data,
  8559. target
  8560. } = event;
  8561. const {
  8562. value,
  8563. selectionStart,
  8564. selectionEnd
  8565. } = target;
  8566. let selStart = selectionStart,
  8567. selEnd = selectionEnd;
  8568. switch (event.inputType) {
  8569. case "deleteWordBackward":
  8570. {
  8571. const match = value.substring(0, selectionStart).match(/\w*[^\w]*$/);
  8572. if (match) {
  8573. selStart -= match[0].length;
  8574. }
  8575. break;
  8576. }
  8577. case "deleteWordForward":
  8578. {
  8579. const match = value.substring(selectionStart).match(/^[^\w]*\w*/);
  8580. if (match) {
  8581. selEnd += match[0].length;
  8582. }
  8583. break;
  8584. }
  8585. case "deleteContentBackward":
  8586. if (selectionStart === selectionEnd) {
  8587. selStart -= 1;
  8588. }
  8589. break;
  8590. case "deleteContentForward":
  8591. if (selectionStart === selectionEnd) {
  8592. selEnd += 1;
  8593. }
  8594. break;
  8595. }
  8596. event.preventDefault();
  8597. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  8598. source: this,
  8599. detail: {
  8600. id,
  8601. name: "Keystroke",
  8602. value,
  8603. change: data || "",
  8604. willCommit: false,
  8605. selStart,
  8606. selEnd
  8607. }
  8608. });
  8609. });
  8610. }
  8611. this._setEventListeners(element, [["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"]], event => event.target.value);
  8612. }
  8613. if (blurListener) {
  8614. element.addEventListener("blur", blurListener);
  8615. }
  8616. if (this.data.maxLen !== null) {
  8617. element.maxLength = this.data.maxLen;
  8618. }
  8619. if (this.data.comb) {
  8620. const fieldWidth = this.data.rect[2] - this.data.rect[0];
  8621. const combWidth = fieldWidth / this.data.maxLen;
  8622. element.classList.add("comb");
  8623. element.style.letterSpacing = `calc(${combWidth}px - 1ch)`;
  8624. }
  8625. } else {
  8626. element = document.createElement("div");
  8627. element.textContent = this.data.fieldValue;
  8628. element.style.verticalAlign = "middle";
  8629. element.style.display = "table-cell";
  8630. }
  8631. this._setTextStyle(element);
  8632. this._setBackgroundColor(element);
  8633. this._setDefaultPropertiesFromJS(element);
  8634. this.container.appendChild(element);
  8635. return this.container;
  8636. }
  8637. _setTextStyle(element) {
  8638. const TEXT_ALIGNMENT = ["left", "center", "right"];
  8639. const {
  8640. fontSize,
  8641. fontColor
  8642. } = this.data.defaultAppearanceData;
  8643. const style = element.style;
  8644. if (fontSize) {
  8645. style.fontSize = `${fontSize}px`;
  8646. }
  8647. style.color = _util.Util.makeHexColor(fontColor[0], fontColor[1], fontColor[2]);
  8648. if (this.data.textAlignment !== null) {
  8649. style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
  8650. }
  8651. }
  8652. }
  8653. class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement {
  8654. constructor(parameters) {
  8655. super(parameters, {
  8656. isRenderable: parameters.renderForms
  8657. });
  8658. }
  8659. render() {
  8660. const storage = this.annotationStorage;
  8661. const data = this.data;
  8662. const id = data.id;
  8663. let value = storage.getValue(id, {
  8664. value: data.exportValue === data.fieldValue
  8665. }).value;
  8666. if (typeof value === "string") {
  8667. value = value !== "Off";
  8668. storage.setValue(id, {
  8669. value
  8670. });
  8671. }
  8672. this.container.className = "buttonWidgetAnnotation checkBox";
  8673. const element = document.createElement("input");
  8674. GetElementsByNameSet.add(element);
  8675. element.disabled = data.readOnly;
  8676. element.type = "checkbox";
  8677. element.name = data.fieldName;
  8678. if (value) {
  8679. element.setAttribute("checked", true);
  8680. }
  8681. element.setAttribute("id", id);
  8682. element.setAttribute("exportValue", data.exportValue);
  8683. element.tabIndex = DEFAULT_TAB_INDEX;
  8684. element.addEventListener("change", event => {
  8685. const {
  8686. name,
  8687. checked
  8688. } = event.target;
  8689. for (const checkbox of this._getElementsByName(name, id)) {
  8690. const curChecked = checked && checkbox.exportValue === data.exportValue;
  8691. if (checkbox.domElement) {
  8692. checkbox.domElement.checked = curChecked;
  8693. }
  8694. storage.setValue(checkbox.id, {
  8695. value: curChecked
  8696. });
  8697. }
  8698. storage.setValue(id, {
  8699. value: checked
  8700. });
  8701. });
  8702. element.addEventListener("resetform", event => {
  8703. const defaultValue = data.defaultFieldValue || "Off";
  8704. event.target.checked = defaultValue === data.exportValue;
  8705. });
  8706. if (this.enableScripting && this.hasJSActions) {
  8707. element.addEventListener("updatefromsandbox", jsEvent => {
  8708. const actions = {
  8709. value(event) {
  8710. event.target.checked = event.detail.value !== "Off";
  8711. storage.setValue(id, {
  8712. value: event.target.checked
  8713. });
  8714. }
  8715. };
  8716. this._dispatchEventFromSandbox(actions, jsEvent);
  8717. });
  8718. 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);
  8719. }
  8720. this._setBackgroundColor(element);
  8721. this._setDefaultPropertiesFromJS(element);
  8722. this.container.appendChild(element);
  8723. return this.container;
  8724. }
  8725. }
  8726. class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
  8727. constructor(parameters) {
  8728. super(parameters, {
  8729. isRenderable: parameters.renderForms
  8730. });
  8731. }
  8732. render() {
  8733. this.container.className = "buttonWidgetAnnotation radioButton";
  8734. const storage = this.annotationStorage;
  8735. const data = this.data;
  8736. const id = data.id;
  8737. let value = storage.getValue(id, {
  8738. value: data.fieldValue === data.buttonValue
  8739. }).value;
  8740. if (typeof value === "string") {
  8741. value = value !== data.buttonValue;
  8742. storage.setValue(id, {
  8743. value
  8744. });
  8745. }
  8746. const element = document.createElement("input");
  8747. GetElementsByNameSet.add(element);
  8748. element.disabled = data.readOnly;
  8749. element.type = "radio";
  8750. element.name = data.fieldName;
  8751. if (value) {
  8752. element.setAttribute("checked", true);
  8753. }
  8754. element.setAttribute("id", id);
  8755. element.tabIndex = DEFAULT_TAB_INDEX;
  8756. element.addEventListener("change", event => {
  8757. const {
  8758. name,
  8759. checked
  8760. } = event.target;
  8761. for (const radio of this._getElementsByName(name, id)) {
  8762. storage.setValue(radio.id, {
  8763. value: false
  8764. });
  8765. }
  8766. storage.setValue(id, {
  8767. value: checked
  8768. });
  8769. });
  8770. element.addEventListener("resetform", event => {
  8771. const defaultValue = data.defaultFieldValue;
  8772. event.target.checked = defaultValue !== null && defaultValue !== undefined && defaultValue === data.buttonValue;
  8773. });
  8774. if (this.enableScripting && this.hasJSActions) {
  8775. const pdfButtonValue = data.buttonValue;
  8776. element.addEventListener("updatefromsandbox", jsEvent => {
  8777. const actions = {
  8778. value: event => {
  8779. const checked = pdfButtonValue === event.detail.value;
  8780. for (const radio of this._getElementsByName(event.target.name)) {
  8781. const curChecked = checked && radio.id === id;
  8782. if (radio.domElement) {
  8783. radio.domElement.checked = curChecked;
  8784. }
  8785. storage.setValue(radio.id, {
  8786. value: curChecked
  8787. });
  8788. }
  8789. }
  8790. };
  8791. this._dispatchEventFromSandbox(actions, jsEvent);
  8792. });
  8793. 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);
  8794. }
  8795. this._setBackgroundColor(element);
  8796. this._setDefaultPropertiesFromJS(element);
  8797. this.container.appendChild(element);
  8798. return this.container;
  8799. }
  8800. }
  8801. class PushButtonWidgetAnnotationElement extends LinkAnnotationElement {
  8802. constructor(parameters) {
  8803. super(parameters, {
  8804. ignoreBorder: parameters.data.hasAppearance
  8805. });
  8806. }
  8807. render() {
  8808. const container = super.render();
  8809. container.className = "buttonWidgetAnnotation pushButton";
  8810. if (this.data.alternativeText) {
  8811. container.title = this.data.alternativeText;
  8812. }
  8813. this._setDefaultPropertiesFromJS(container);
  8814. return container;
  8815. }
  8816. }
  8817. class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
  8818. constructor(parameters) {
  8819. super(parameters, {
  8820. isRenderable: parameters.renderForms
  8821. });
  8822. }
  8823. render() {
  8824. this.container.className = "choiceWidgetAnnotation";
  8825. const storage = this.annotationStorage;
  8826. const id = this.data.id;
  8827. const storedData = storage.getValue(id, {
  8828. value: this.data.fieldValue
  8829. });
  8830. let {
  8831. fontSize
  8832. } = this.data.defaultAppearanceData;
  8833. if (!fontSize) {
  8834. fontSize = 9;
  8835. }
  8836. const fontSizeStyle = `calc(${fontSize}px * var(--zoom-factor))`;
  8837. const selectElement = document.createElement("select");
  8838. GetElementsByNameSet.add(selectElement);
  8839. selectElement.disabled = this.data.readOnly;
  8840. selectElement.name = this.data.fieldName;
  8841. selectElement.setAttribute("id", id);
  8842. selectElement.tabIndex = DEFAULT_TAB_INDEX;
  8843. selectElement.style.fontSize = `${fontSize}px`;
  8844. if (!this.data.combo) {
  8845. selectElement.size = this.data.options.length;
  8846. if (this.data.multiSelect) {
  8847. selectElement.multiple = true;
  8848. }
  8849. }
  8850. selectElement.addEventListener("resetform", event => {
  8851. const defaultValue = this.data.defaultFieldValue;
  8852. for (const option of selectElement.options) {
  8853. option.selected = option.value === defaultValue;
  8854. }
  8855. });
  8856. for (const option of this.data.options) {
  8857. const optionElement = document.createElement("option");
  8858. optionElement.textContent = option.displayValue;
  8859. optionElement.value = option.exportValue;
  8860. if (this.data.combo) {
  8861. optionElement.style.fontSize = fontSizeStyle;
  8862. }
  8863. if (storedData.value.includes(option.exportValue)) {
  8864. optionElement.setAttribute("selected", true);
  8865. }
  8866. selectElement.appendChild(optionElement);
  8867. }
  8868. const getValue = (event, isExport) => {
  8869. const name = isExport ? "value" : "textContent";
  8870. const options = event.target.options;
  8871. if (!event.target.multiple) {
  8872. return options.selectedIndex === -1 ? null : options[options.selectedIndex][name];
  8873. }
  8874. return Array.prototype.filter.call(options, option => option.selected).map(option => option[name]);
  8875. };
  8876. const getItems = event => {
  8877. const options = event.target.options;
  8878. return Array.prototype.map.call(options, option => {
  8879. return {
  8880. displayValue: option.textContent,
  8881. exportValue: option.value
  8882. };
  8883. });
  8884. };
  8885. if (this.enableScripting && this.hasJSActions) {
  8886. selectElement.addEventListener("updatefromsandbox", jsEvent => {
  8887. const actions = {
  8888. value(event) {
  8889. const value = event.detail.value;
  8890. const values = new Set(Array.isArray(value) ? value : [value]);
  8891. for (const option of selectElement.options) {
  8892. option.selected = values.has(option.value);
  8893. }
  8894. storage.setValue(id, {
  8895. value: getValue(event, true)
  8896. });
  8897. },
  8898. multipleSelection(event) {
  8899. selectElement.multiple = true;
  8900. },
  8901. remove(event) {
  8902. const options = selectElement.options;
  8903. const index = event.detail.remove;
  8904. options[index].selected = false;
  8905. selectElement.remove(index);
  8906. if (options.length > 0) {
  8907. const i = Array.prototype.findIndex.call(options, option => option.selected);
  8908. if (i === -1) {
  8909. options[0].selected = true;
  8910. }
  8911. }
  8912. storage.setValue(id, {
  8913. value: getValue(event, true),
  8914. items: getItems(event)
  8915. });
  8916. },
  8917. clear(event) {
  8918. while (selectElement.length !== 0) {
  8919. selectElement.remove(0);
  8920. }
  8921. storage.setValue(id, {
  8922. value: null,
  8923. items: []
  8924. });
  8925. },
  8926. insert(event) {
  8927. const {
  8928. index,
  8929. displayValue,
  8930. exportValue
  8931. } = event.detail.insert;
  8932. const optionElement = document.createElement("option");
  8933. optionElement.textContent = displayValue;
  8934. optionElement.value = exportValue;
  8935. selectElement.insertBefore(optionElement, selectElement.children[index]);
  8936. storage.setValue(id, {
  8937. value: getValue(event, true),
  8938. items: getItems(event)
  8939. });
  8940. },
  8941. items(event) {
  8942. const {
  8943. items
  8944. } = event.detail;
  8945. while (selectElement.length !== 0) {
  8946. selectElement.remove(0);
  8947. }
  8948. for (const item of items) {
  8949. const {
  8950. displayValue,
  8951. exportValue
  8952. } = item;
  8953. const optionElement = document.createElement("option");
  8954. optionElement.textContent = displayValue;
  8955. optionElement.value = exportValue;
  8956. selectElement.appendChild(optionElement);
  8957. }
  8958. if (selectElement.options.length > 0) {
  8959. selectElement.options[0].selected = true;
  8960. }
  8961. storage.setValue(id, {
  8962. value: getValue(event, true),
  8963. items: getItems(event)
  8964. });
  8965. },
  8966. indices(event) {
  8967. const indices = new Set(event.detail.indices);
  8968. for (const option of event.target.options) {
  8969. option.selected = indices.has(option.index);
  8970. }
  8971. storage.setValue(id, {
  8972. value: getValue(event, true)
  8973. });
  8974. },
  8975. editable(event) {
  8976. event.target.disabled = !event.detail.editable;
  8977. }
  8978. };
  8979. this._dispatchEventFromSandbox(actions, jsEvent);
  8980. });
  8981. selectElement.addEventListener("input", event => {
  8982. const exportValue = getValue(event, true);
  8983. const value = getValue(event, false);
  8984. storage.setValue(id, {
  8985. value: exportValue
  8986. });
  8987. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  8988. source: this,
  8989. detail: {
  8990. id,
  8991. name: "Keystroke",
  8992. value,
  8993. changeEx: exportValue,
  8994. willCommit: true,
  8995. commitKey: 1,
  8996. keyDown: false
  8997. }
  8998. });
  8999. });
  9000. 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);
  9001. } else {
  9002. selectElement.addEventListener("input", function (event) {
  9003. storage.setValue(id, {
  9004. value: getValue(event, true)
  9005. });
  9006. });
  9007. }
  9008. this._setBackgroundColor(selectElement);
  9009. this._setDefaultPropertiesFromJS(selectElement);
  9010. this.container.appendChild(selectElement);
  9011. return this.container;
  9012. }
  9013. }
  9014. class PopupAnnotationElement extends AnnotationElement {
  9015. constructor(parameters) {
  9016. const isRenderable = !!(parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  9017. super(parameters, {
  9018. isRenderable
  9019. });
  9020. }
  9021. render() {
  9022. const IGNORE_TYPES = ["Line", "Square", "Circle", "PolyLine", "Polygon", "Ink"];
  9023. this.container.className = "popupAnnotation";
  9024. if (IGNORE_TYPES.includes(this.data.parentType)) {
  9025. return this.container;
  9026. }
  9027. const selector = `[data-annotation-id="${this.data.parentId}"]`;
  9028. const parentElements = this.layer.querySelectorAll(selector);
  9029. if (parentElements.length === 0) {
  9030. return this.container;
  9031. }
  9032. const popup = new PopupElement({
  9033. container: this.container,
  9034. trigger: Array.from(parentElements),
  9035. color: this.data.color,
  9036. titleObj: this.data.titleObj,
  9037. modificationDate: this.data.modificationDate,
  9038. contentsObj: this.data.contentsObj,
  9039. richText: this.data.richText
  9040. });
  9041. const page = this.page;
  9042. 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]]);
  9043. const popupLeft = rect[0] + this.data.parentRect[2] - this.data.parentRect[0];
  9044. const popupTop = rect[1];
  9045. this.container.style.transformOrigin = `${-popupLeft}px ${-popupTop}px`;
  9046. this.container.style.left = `${popupLeft}px`;
  9047. this.container.style.top = `${popupTop}px`;
  9048. this.container.appendChild(popup.render());
  9049. return this.container;
  9050. }
  9051. }
  9052. class PopupElement {
  9053. constructor(parameters) {
  9054. this.container = parameters.container;
  9055. this.trigger = parameters.trigger;
  9056. this.color = parameters.color;
  9057. this.titleObj = parameters.titleObj;
  9058. this.modificationDate = parameters.modificationDate;
  9059. this.contentsObj = parameters.contentsObj;
  9060. this.richText = parameters.richText;
  9061. this.hideWrapper = parameters.hideWrapper || false;
  9062. this.pinned = false;
  9063. }
  9064. render() {
  9065. const BACKGROUND_ENLIGHT = 0.7;
  9066. const wrapper = document.createElement("div");
  9067. wrapper.className = "popupWrapper";
  9068. this.hideElement = this.hideWrapper ? wrapper : this.container;
  9069. this.hideElement.hidden = true;
  9070. const popup = document.createElement("div");
  9071. popup.className = "popup";
  9072. const color = this.color;
  9073. if (color) {
  9074. const r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  9075. const g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  9076. const b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  9077. popup.style.backgroundColor = _util.Util.makeHexColor(r | 0, g | 0, b | 0);
  9078. }
  9079. const title = document.createElement("h1");
  9080. title.dir = this.titleObj.dir;
  9081. title.textContent = this.titleObj.str;
  9082. popup.appendChild(title);
  9083. const dateObject = _display_utils.PDFDateString.toDateObject(this.modificationDate);
  9084. if (dateObject) {
  9085. const modificationDate = document.createElement("span");
  9086. modificationDate.className = "popupDate";
  9087. modificationDate.textContent = "{{date}}, {{time}}";
  9088. modificationDate.dataset.l10nId = "annotation_date_string";
  9089. modificationDate.dataset.l10nArgs = JSON.stringify({
  9090. date: dateObject.toLocaleDateString(),
  9091. time: dateObject.toLocaleTimeString()
  9092. });
  9093. popup.appendChild(modificationDate);
  9094. }
  9095. if (this.richText?.str && (!this.contentsObj?.str || this.contentsObj.str === this.richText.str)) {
  9096. _xfa_layer.XfaLayer.render({
  9097. xfaHtml: this.richText.html,
  9098. intent: "richText",
  9099. div: popup
  9100. });
  9101. popup.lastChild.className = "richText popupContent";
  9102. } else {
  9103. const contents = this._formatContents(this.contentsObj);
  9104. popup.appendChild(contents);
  9105. }
  9106. if (!Array.isArray(this.trigger)) {
  9107. this.trigger = [this.trigger];
  9108. }
  9109. for (const element of this.trigger) {
  9110. element.addEventListener("click", this._toggle.bind(this));
  9111. element.addEventListener("mouseover", this._show.bind(this, false));
  9112. element.addEventListener("mouseout", this._hide.bind(this, false));
  9113. }
  9114. popup.addEventListener("click", this._hide.bind(this, true));
  9115. wrapper.appendChild(popup);
  9116. return wrapper;
  9117. }
  9118. _formatContents({
  9119. str,
  9120. dir
  9121. }) {
  9122. const p = document.createElement("p");
  9123. p.className = "popupContent";
  9124. p.dir = dir;
  9125. const lines = str.split(/(?:\r\n?|\n)/);
  9126. for (let i = 0, ii = lines.length; i < ii; ++i) {
  9127. const line = lines[i];
  9128. p.appendChild(document.createTextNode(line));
  9129. if (i < ii - 1) {
  9130. p.appendChild(document.createElement("br"));
  9131. }
  9132. }
  9133. return p;
  9134. }
  9135. _toggle() {
  9136. if (this.pinned) {
  9137. this._hide(true);
  9138. } else {
  9139. this._show(true);
  9140. }
  9141. }
  9142. _show(pin = false) {
  9143. if (pin) {
  9144. this.pinned = true;
  9145. }
  9146. if (this.hideElement.hidden) {
  9147. this.hideElement.hidden = false;
  9148. this.container.style.zIndex += 1;
  9149. }
  9150. }
  9151. _hide(unpin = true) {
  9152. if (unpin) {
  9153. this.pinned = false;
  9154. }
  9155. if (!this.hideElement.hidden && !this.pinned) {
  9156. this.hideElement.hidden = true;
  9157. this.container.style.zIndex -= 1;
  9158. }
  9159. }
  9160. }
  9161. class FreeTextAnnotationElement extends AnnotationElement {
  9162. constructor(parameters) {
  9163. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  9164. super(parameters, {
  9165. isRenderable,
  9166. ignoreBorder: true
  9167. });
  9168. }
  9169. render() {
  9170. this.container.className = "freeTextAnnotation";
  9171. if (!this.data.hasPopup) {
  9172. this._createPopup(null, this.data);
  9173. }
  9174. return this.container;
  9175. }
  9176. }
  9177. class LineAnnotationElement extends AnnotationElement {
  9178. constructor(parameters) {
  9179. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  9180. super(parameters, {
  9181. isRenderable,
  9182. ignoreBorder: true
  9183. });
  9184. }
  9185. render() {
  9186. this.container.className = "lineAnnotation";
  9187. const data = this.data;
  9188. const {
  9189. width,
  9190. height
  9191. } = getRectDims(data.rect);
  9192. const svg = this.svgFactory.create(width, height);
  9193. const line = this.svgFactory.createElement("svg:line");
  9194. line.setAttribute("x1", data.rect[2] - data.lineCoordinates[0]);
  9195. line.setAttribute("y1", data.rect[3] - data.lineCoordinates[1]);
  9196. line.setAttribute("x2", data.rect[2] - data.lineCoordinates[2]);
  9197. line.setAttribute("y2", data.rect[3] - data.lineCoordinates[3]);
  9198. line.setAttribute("stroke-width", data.borderStyle.width || 1);
  9199. line.setAttribute("stroke", "transparent");
  9200. line.setAttribute("fill", "transparent");
  9201. svg.appendChild(line);
  9202. this.container.append(svg);
  9203. this._createPopup(line, data);
  9204. return this.container;
  9205. }
  9206. }
  9207. class SquareAnnotationElement extends AnnotationElement {
  9208. constructor(parameters) {
  9209. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  9210. super(parameters, {
  9211. isRenderable,
  9212. ignoreBorder: true
  9213. });
  9214. }
  9215. render() {
  9216. this.container.className = "squareAnnotation";
  9217. const data = this.data;
  9218. const {
  9219. width,
  9220. height
  9221. } = getRectDims(data.rect);
  9222. const svg = this.svgFactory.create(width, height);
  9223. const borderWidth = data.borderStyle.width;
  9224. const square = this.svgFactory.createElement("svg:rect");
  9225. square.setAttribute("x", borderWidth / 2);
  9226. square.setAttribute("y", borderWidth / 2);
  9227. square.setAttribute("width", width - borderWidth);
  9228. square.setAttribute("height", height - borderWidth);
  9229. square.setAttribute("stroke-width", borderWidth || 1);
  9230. square.setAttribute("stroke", "transparent");
  9231. square.setAttribute("fill", "transparent");
  9232. svg.appendChild(square);
  9233. this.container.append(svg);
  9234. this._createPopup(square, data);
  9235. return this.container;
  9236. }
  9237. }
  9238. class CircleAnnotationElement extends AnnotationElement {
  9239. constructor(parameters) {
  9240. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  9241. super(parameters, {
  9242. isRenderable,
  9243. ignoreBorder: true
  9244. });
  9245. }
  9246. render() {
  9247. this.container.className = "circleAnnotation";
  9248. const data = this.data;
  9249. const {
  9250. width,
  9251. height
  9252. } = getRectDims(data.rect);
  9253. const svg = this.svgFactory.create(width, height);
  9254. const borderWidth = data.borderStyle.width;
  9255. const circle = this.svgFactory.createElement("svg:ellipse");
  9256. circle.setAttribute("cx", width / 2);
  9257. circle.setAttribute("cy", height / 2);
  9258. circle.setAttribute("rx", width / 2 - borderWidth / 2);
  9259. circle.setAttribute("ry", height / 2 - borderWidth / 2);
  9260. circle.setAttribute("stroke-width", borderWidth || 1);
  9261. circle.setAttribute("stroke", "transparent");
  9262. circle.setAttribute("fill", "transparent");
  9263. svg.appendChild(circle);
  9264. this.container.append(svg);
  9265. this._createPopup(circle, data);
  9266. return this.container;
  9267. }
  9268. }
  9269. class PolylineAnnotationElement extends AnnotationElement {
  9270. constructor(parameters) {
  9271. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  9272. super(parameters, {
  9273. isRenderable,
  9274. ignoreBorder: true
  9275. });
  9276. this.containerClassName = "polylineAnnotation";
  9277. this.svgElementName = "svg:polyline";
  9278. }
  9279. render() {
  9280. this.container.className = this.containerClassName;
  9281. const data = this.data;
  9282. const {
  9283. width,
  9284. height
  9285. } = getRectDims(data.rect);
  9286. const svg = this.svgFactory.create(width, height);
  9287. let points = [];
  9288. for (const coordinate of data.vertices) {
  9289. const x = coordinate.x - data.rect[0];
  9290. const y = data.rect[3] - coordinate.y;
  9291. points.push(x + "," + y);
  9292. }
  9293. points = points.join(" ");
  9294. const polyline = this.svgFactory.createElement(this.svgElementName);
  9295. polyline.setAttribute("points", points);
  9296. polyline.setAttribute("stroke-width", data.borderStyle.width || 1);
  9297. polyline.setAttribute("stroke", "transparent");
  9298. polyline.setAttribute("fill", "transparent");
  9299. svg.appendChild(polyline);
  9300. this.container.append(svg);
  9301. this._createPopup(polyline, data);
  9302. return this.container;
  9303. }
  9304. }
  9305. class PolygonAnnotationElement extends PolylineAnnotationElement {
  9306. constructor(parameters) {
  9307. super(parameters);
  9308. this.containerClassName = "polygonAnnotation";
  9309. this.svgElementName = "svg:polygon";
  9310. }
  9311. }
  9312. class CaretAnnotationElement extends AnnotationElement {
  9313. constructor(parameters) {
  9314. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  9315. super(parameters, {
  9316. isRenderable,
  9317. ignoreBorder: true
  9318. });
  9319. }
  9320. render() {
  9321. this.container.className = "caretAnnotation";
  9322. if (!this.data.hasPopup) {
  9323. this._createPopup(null, this.data);
  9324. }
  9325. return this.container;
  9326. }
  9327. }
  9328. class InkAnnotationElement extends AnnotationElement {
  9329. constructor(parameters) {
  9330. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  9331. super(parameters, {
  9332. isRenderable,
  9333. ignoreBorder: true
  9334. });
  9335. this.containerClassName = "inkAnnotation";
  9336. this.svgElementName = "svg:polyline";
  9337. }
  9338. render() {
  9339. this.container.className = this.containerClassName;
  9340. const data = this.data;
  9341. const {
  9342. width,
  9343. height
  9344. } = getRectDims(data.rect);
  9345. const svg = this.svgFactory.create(width, height);
  9346. for (const inkList of data.inkLists) {
  9347. let points = [];
  9348. for (const coordinate of inkList) {
  9349. const x = coordinate.x - data.rect[0];
  9350. const y = data.rect[3] - coordinate.y;
  9351. points.push(`${x},${y}`);
  9352. }
  9353. points = points.join(" ");
  9354. const polyline = this.svgFactory.createElement(this.svgElementName);
  9355. polyline.setAttribute("points", points);
  9356. polyline.setAttribute("stroke-width", data.borderStyle.width || 1);
  9357. polyline.setAttribute("stroke", "transparent");
  9358. polyline.setAttribute("fill", "transparent");
  9359. this._createPopup(polyline, data);
  9360. svg.appendChild(polyline);
  9361. }
  9362. this.container.append(svg);
  9363. return this.container;
  9364. }
  9365. }
  9366. class HighlightAnnotationElement extends AnnotationElement {
  9367. constructor(parameters) {
  9368. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  9369. super(parameters, {
  9370. isRenderable,
  9371. ignoreBorder: true,
  9372. createQuadrilaterals: true
  9373. });
  9374. }
  9375. render() {
  9376. if (!this.data.hasPopup) {
  9377. this._createPopup(null, this.data);
  9378. }
  9379. if (this.quadrilaterals) {
  9380. return this._renderQuadrilaterals("highlightAnnotation");
  9381. }
  9382. this.container.className = "highlightAnnotation";
  9383. return this.container;
  9384. }
  9385. }
  9386. class UnderlineAnnotationElement extends AnnotationElement {
  9387. constructor(parameters) {
  9388. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  9389. super(parameters, {
  9390. isRenderable,
  9391. ignoreBorder: true,
  9392. createQuadrilaterals: true
  9393. });
  9394. }
  9395. render() {
  9396. if (!this.data.hasPopup) {
  9397. this._createPopup(null, this.data);
  9398. }
  9399. if (this.quadrilaterals) {
  9400. return this._renderQuadrilaterals("underlineAnnotation");
  9401. }
  9402. this.container.className = "underlineAnnotation";
  9403. return this.container;
  9404. }
  9405. }
  9406. class SquigglyAnnotationElement extends AnnotationElement {
  9407. constructor(parameters) {
  9408. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  9409. super(parameters, {
  9410. isRenderable,
  9411. ignoreBorder: true,
  9412. createQuadrilaterals: true
  9413. });
  9414. }
  9415. render() {
  9416. if (!this.data.hasPopup) {
  9417. this._createPopup(null, this.data);
  9418. }
  9419. if (this.quadrilaterals) {
  9420. return this._renderQuadrilaterals("squigglyAnnotation");
  9421. }
  9422. this.container.className = "squigglyAnnotation";
  9423. return this.container;
  9424. }
  9425. }
  9426. class StrikeOutAnnotationElement extends AnnotationElement {
  9427. constructor(parameters) {
  9428. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  9429. super(parameters, {
  9430. isRenderable,
  9431. ignoreBorder: true,
  9432. createQuadrilaterals: true
  9433. });
  9434. }
  9435. render() {
  9436. if (!this.data.hasPopup) {
  9437. this._createPopup(null, this.data);
  9438. }
  9439. if (this.quadrilaterals) {
  9440. return this._renderQuadrilaterals("strikeoutAnnotation");
  9441. }
  9442. this.container.className = "strikeoutAnnotation";
  9443. return this.container;
  9444. }
  9445. }
  9446. class StampAnnotationElement extends AnnotationElement {
  9447. constructor(parameters) {
  9448. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  9449. super(parameters, {
  9450. isRenderable,
  9451. ignoreBorder: true
  9452. });
  9453. }
  9454. render() {
  9455. this.container.className = "stampAnnotation";
  9456. if (!this.data.hasPopup) {
  9457. this._createPopup(null, this.data);
  9458. }
  9459. return this.container;
  9460. }
  9461. }
  9462. class FileAttachmentAnnotationElement extends AnnotationElement {
  9463. constructor(parameters) {
  9464. super(parameters, {
  9465. isRenderable: true
  9466. });
  9467. const {
  9468. filename,
  9469. content
  9470. } = this.data.file;
  9471. this.filename = (0, _display_utils.getFilenameFromUrl)(filename);
  9472. this.content = content;
  9473. this.linkService.eventBus?.dispatch("fileattachmentannotation", {
  9474. source: this,
  9475. filename,
  9476. content
  9477. });
  9478. }
  9479. render() {
  9480. this.container.className = "fileAttachmentAnnotation";
  9481. const trigger = document.createElement("div");
  9482. trigger.style.height = this.container.style.height;
  9483. trigger.style.width = this.container.style.width;
  9484. trigger.addEventListener("dblclick", this._download.bind(this));
  9485. if (!this.data.hasPopup && (this.data.titleObj?.str || this.data.contentsObj?.str || this.data.richText)) {
  9486. this._createPopup(trigger, this.data);
  9487. }
  9488. this.container.appendChild(trigger);
  9489. return this.container;
  9490. }
  9491. _download() {
  9492. this.downloadManager?.openOrDownloadData(this.container, this.content, this.filename);
  9493. }
  9494. }
  9495. class AnnotationLayer {
  9496. static render(parameters) {
  9497. const sortedAnnotations = [],
  9498. popupAnnotations = [];
  9499. for (const data of parameters.annotations) {
  9500. if (!data) {
  9501. continue;
  9502. }
  9503. const {
  9504. width,
  9505. height
  9506. } = getRectDims(data.rect);
  9507. if (width <= 0 || height <= 0) {
  9508. continue;
  9509. }
  9510. if (data.annotationType === _util.AnnotationType.POPUP) {
  9511. popupAnnotations.push(data);
  9512. continue;
  9513. }
  9514. sortedAnnotations.push(data);
  9515. }
  9516. if (popupAnnotations.length) {
  9517. sortedAnnotations.push(...popupAnnotations);
  9518. }
  9519. const div = parameters.div;
  9520. for (const data of sortedAnnotations) {
  9521. const element = AnnotationElementFactory.create({
  9522. data,
  9523. layer: div,
  9524. page: parameters.page,
  9525. viewport: parameters.viewport,
  9526. linkService: parameters.linkService,
  9527. downloadManager: parameters.downloadManager,
  9528. imageResourcesPath: parameters.imageResourcesPath || "",
  9529. renderForms: parameters.renderForms !== false,
  9530. svgFactory: new _display_utils.DOMSVGFactory(),
  9531. annotationStorage: parameters.annotationStorage || new _annotation_storage.AnnotationStorage(),
  9532. enableScripting: parameters.enableScripting,
  9533. hasJSActions: parameters.hasJSActions,
  9534. fieldObjects: parameters.fieldObjects,
  9535. mouseState: parameters.mouseState || {
  9536. isDown: false
  9537. }
  9538. });
  9539. if (element.isRenderable) {
  9540. const rendered = element.render();
  9541. if (data.hidden) {
  9542. rendered.style.visibility = "hidden";
  9543. }
  9544. if (Array.isArray(rendered)) {
  9545. for (const renderedElement of rendered) {
  9546. div.appendChild(renderedElement);
  9547. }
  9548. } else {
  9549. if (element instanceof PopupAnnotationElement) {
  9550. div.prepend(rendered);
  9551. } else {
  9552. div.appendChild(rendered);
  9553. }
  9554. }
  9555. }
  9556. }
  9557. this.#setAnnotationCanvasMap(div, parameters.annotationCanvasMap);
  9558. }
  9559. static update(parameters) {
  9560. const {
  9561. page,
  9562. viewport,
  9563. annotations,
  9564. annotationCanvasMap,
  9565. div
  9566. } = parameters;
  9567. const transform = viewport.transform;
  9568. const matrix = `matrix(${transform.join(",")})`;
  9569. let scale, ownMatrix;
  9570. for (const data of annotations) {
  9571. const elements = div.querySelectorAll(`[data-annotation-id="${data.id}"]`);
  9572. if (elements) {
  9573. for (const element of elements) {
  9574. if (data.hasOwnCanvas) {
  9575. 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]]);
  9576. if (!ownMatrix) {
  9577. scale = Math.abs(transform[0] || transform[1]);
  9578. const ownTransform = transform.slice();
  9579. for (let i = 0; i < 4; i++) {
  9580. ownTransform[i] = Math.sign(ownTransform[i]);
  9581. }
  9582. ownMatrix = `matrix(${ownTransform.join(",")})`;
  9583. }
  9584. const left = rect[0] * scale;
  9585. const top = rect[1] * scale;
  9586. element.style.left = `${left}px`;
  9587. element.style.top = `${top}px`;
  9588. element.style.transformOrigin = `${-left}px ${-top}px`;
  9589. element.style.transform = ownMatrix;
  9590. } else {
  9591. element.style.transform = matrix;
  9592. }
  9593. }
  9594. }
  9595. }
  9596. this.#setAnnotationCanvasMap(div, annotationCanvasMap);
  9597. div.hidden = false;
  9598. }
  9599. static #setAnnotationCanvasMap(div, annotationCanvasMap) {
  9600. if (!annotationCanvasMap) {
  9601. return;
  9602. }
  9603. for (const [id, canvas] of annotationCanvasMap) {
  9604. const element = div.querySelector(`[data-annotation-id="${id}"]`);
  9605. if (!element) {
  9606. continue;
  9607. }
  9608. const {
  9609. firstChild
  9610. } = element;
  9611. if (firstChild.nodeName === "CANVAS") {
  9612. element.replaceChild(canvas, firstChild);
  9613. } else {
  9614. element.insertBefore(canvas, firstChild);
  9615. }
  9616. }
  9617. annotationCanvasMap.clear();
  9618. }
  9619. }
  9620. exports.AnnotationLayer = AnnotationLayer;
  9621. /***/ }),
  9622. /* 21 */
  9623. /***/ ((__unused_webpack_module, exports) => {
  9624. Object.defineProperty(exports, "__esModule", ({
  9625. value: true
  9626. }));
  9627. exports.ColorConverters = void 0;
  9628. function makeColorComp(n) {
  9629. return Math.floor(Math.max(0, Math.min(1, n)) * 255).toString(16).padStart(2, "0");
  9630. }
  9631. class ColorConverters {
  9632. static CMYK_G([c, y, m, k]) {
  9633. return ["G", 1 - Math.min(1, 0.3 * c + 0.59 * m + 0.11 * y + k)];
  9634. }
  9635. static G_CMYK([g]) {
  9636. return ["CMYK", 0, 0, 0, 1 - g];
  9637. }
  9638. static G_RGB([g]) {
  9639. return ["RGB", g, g, g];
  9640. }
  9641. static G_HTML([g]) {
  9642. const G = makeColorComp(g);
  9643. return `#${G}${G}${G}`;
  9644. }
  9645. static RGB_G([r, g, b]) {
  9646. return ["G", 0.3 * r + 0.59 * g + 0.11 * b];
  9647. }
  9648. static RGB_HTML([r, g, b]) {
  9649. const R = makeColorComp(r);
  9650. const G = makeColorComp(g);
  9651. const B = makeColorComp(b);
  9652. return `#${R}${G}${B}`;
  9653. }
  9654. static T_HTML() {
  9655. return "#00000000";
  9656. }
  9657. static CMYK_RGB([c, y, m, k]) {
  9658. return ["RGB", 1 - Math.min(1, c + k), 1 - Math.min(1, m + k), 1 - Math.min(1, y + k)];
  9659. }
  9660. static CMYK_HTML(components) {
  9661. return this.RGB_HTML(this.CMYK_RGB(components));
  9662. }
  9663. static RGB_CMYK([r, g, b]) {
  9664. const c = 1 - r;
  9665. const m = 1 - g;
  9666. const y = 1 - b;
  9667. const k = Math.min(c, m, y);
  9668. return ["CMYK", c, m, y, k];
  9669. }
  9670. }
  9671. exports.ColorConverters = ColorConverters;
  9672. /***/ }),
  9673. /* 22 */
  9674. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  9675. Object.defineProperty(exports, "__esModule", ({
  9676. value: true
  9677. }));
  9678. exports.XfaLayer = void 0;
  9679. var _xfa_text = __w_pdfjs_require__(18);
  9680. class XfaLayer {
  9681. static setupStorage(html, id, element, storage, intent) {
  9682. const storedData = storage.getValue(id, {
  9683. value: null
  9684. });
  9685. switch (element.name) {
  9686. case "textarea":
  9687. if (storedData.value !== null) {
  9688. html.textContent = storedData.value;
  9689. }
  9690. if (intent === "print") {
  9691. break;
  9692. }
  9693. html.addEventListener("input", event => {
  9694. storage.setValue(id, {
  9695. value: event.target.value
  9696. });
  9697. });
  9698. break;
  9699. case "input":
  9700. if (element.attributes.type === "radio" || element.attributes.type === "checkbox") {
  9701. if (storedData.value === element.attributes.xfaOn) {
  9702. html.setAttribute("checked", true);
  9703. } else if (storedData.value === element.attributes.xfaOff) {
  9704. html.removeAttribute("checked");
  9705. }
  9706. if (intent === "print") {
  9707. break;
  9708. }
  9709. html.addEventListener("change", event => {
  9710. storage.setValue(id, {
  9711. value: event.target.checked ? event.target.getAttribute("xfaOn") : event.target.getAttribute("xfaOff")
  9712. });
  9713. });
  9714. } else {
  9715. if (storedData.value !== null) {
  9716. html.setAttribute("value", storedData.value);
  9717. }
  9718. if (intent === "print") {
  9719. break;
  9720. }
  9721. html.addEventListener("input", event => {
  9722. storage.setValue(id, {
  9723. value: event.target.value
  9724. });
  9725. });
  9726. }
  9727. break;
  9728. case "select":
  9729. if (storedData.value !== null) {
  9730. for (const option of element.children) {
  9731. if (option.attributes.value === storedData.value) {
  9732. option.attributes.selected = true;
  9733. }
  9734. }
  9735. }
  9736. html.addEventListener("input", event => {
  9737. const options = event.target.options;
  9738. const value = options.selectedIndex === -1 ? "" : options[options.selectedIndex].value;
  9739. storage.setValue(id, {
  9740. value
  9741. });
  9742. });
  9743. break;
  9744. }
  9745. }
  9746. static setAttributes({
  9747. html,
  9748. element,
  9749. storage = null,
  9750. intent,
  9751. linkService
  9752. }) {
  9753. const {
  9754. attributes
  9755. } = element;
  9756. const isHTMLAnchorElement = html instanceof HTMLAnchorElement;
  9757. if (attributes.type === "radio") {
  9758. attributes.name = `${attributes.name}-${intent}`;
  9759. }
  9760. for (const [key, value] of Object.entries(attributes)) {
  9761. if (value === null || value === undefined || key === "dataId") {
  9762. continue;
  9763. }
  9764. if (key !== "style") {
  9765. if (key === "textContent") {
  9766. html.textContent = value;
  9767. } else if (key === "class") {
  9768. if (value.length) {
  9769. html.setAttribute(key, value.join(" "));
  9770. }
  9771. } else {
  9772. if (isHTMLAnchorElement && (key === "href" || key === "newWindow")) {
  9773. continue;
  9774. }
  9775. html.setAttribute(key, value);
  9776. }
  9777. } else {
  9778. Object.assign(html.style, value);
  9779. }
  9780. }
  9781. if (isHTMLAnchorElement) {
  9782. linkService.addLinkAttributes(html, attributes.href, attributes.newWindow);
  9783. }
  9784. if (storage && attributes.dataId) {
  9785. this.setupStorage(html, attributes.dataId, element, storage);
  9786. }
  9787. }
  9788. static render(parameters) {
  9789. const storage = parameters.annotationStorage;
  9790. const linkService = parameters.linkService;
  9791. const root = parameters.xfaHtml;
  9792. const intent = parameters.intent || "display";
  9793. const rootHtml = document.createElement(root.name);
  9794. if (root.attributes) {
  9795. this.setAttributes({
  9796. html: rootHtml,
  9797. element: root,
  9798. intent,
  9799. linkService
  9800. });
  9801. }
  9802. const stack = [[root, -1, rootHtml]];
  9803. const rootDiv = parameters.div;
  9804. rootDiv.appendChild(rootHtml);
  9805. if (parameters.viewport) {
  9806. const transform = `matrix(${parameters.viewport.transform.join(",")})`;
  9807. rootDiv.style.transform = transform;
  9808. }
  9809. if (intent !== "richText") {
  9810. rootDiv.setAttribute("class", "xfaLayer xfaFont");
  9811. }
  9812. const textDivs = [];
  9813. while (stack.length > 0) {
  9814. const [parent, i, html] = stack[stack.length - 1];
  9815. if (i + 1 === parent.children.length) {
  9816. stack.pop();
  9817. continue;
  9818. }
  9819. const child = parent.children[++stack[stack.length - 1][1]];
  9820. if (child === null) {
  9821. continue;
  9822. }
  9823. const {
  9824. name
  9825. } = child;
  9826. if (name === "#text") {
  9827. const node = document.createTextNode(child.value);
  9828. textDivs.push(node);
  9829. html.appendChild(node);
  9830. continue;
  9831. }
  9832. let childHtml;
  9833. if (child?.attributes?.xmlns) {
  9834. childHtml = document.createElementNS(child.attributes.xmlns, name);
  9835. } else {
  9836. childHtml = document.createElement(name);
  9837. }
  9838. html.appendChild(childHtml);
  9839. if (child.attributes) {
  9840. this.setAttributes({
  9841. html: childHtml,
  9842. element: child,
  9843. storage,
  9844. intent,
  9845. linkService
  9846. });
  9847. }
  9848. if (child.children && child.children.length > 0) {
  9849. stack.push([child, -1, childHtml]);
  9850. } else if (child.value) {
  9851. const node = document.createTextNode(child.value);
  9852. if (_xfa_text.XfaText.shouldBuildText(name)) {
  9853. textDivs.push(node);
  9854. }
  9855. childHtml.appendChild(node);
  9856. }
  9857. }
  9858. for (const el of rootDiv.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea")) {
  9859. el.setAttribute("readOnly", true);
  9860. }
  9861. return {
  9862. textDivs
  9863. };
  9864. }
  9865. static update(parameters) {
  9866. const transform = `matrix(${parameters.viewport.transform.join(",")})`;
  9867. parameters.div.style.transform = transform;
  9868. parameters.div.hidden = false;
  9869. }
  9870. }
  9871. exports.XfaLayer = XfaLayer;
  9872. /***/ }),
  9873. /* 23 */
  9874. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  9875. Object.defineProperty(exports, "__esModule", ({
  9876. value: true
  9877. }));
  9878. exports.renderTextLayer = renderTextLayer;
  9879. var _util = __w_pdfjs_require__(1);
  9880. const MAX_TEXT_DIVS_TO_RENDER = 100000;
  9881. const DEFAULT_FONT_SIZE = 30;
  9882. const DEFAULT_FONT_ASCENT = 0.8;
  9883. const ascentCache = new Map();
  9884. const AllWhitespaceRegexp = /^\s+$/g;
  9885. function getAscent(fontFamily, ctx) {
  9886. const cachedAscent = ascentCache.get(fontFamily);
  9887. if (cachedAscent) {
  9888. return cachedAscent;
  9889. }
  9890. ctx.save();
  9891. ctx.font = `${DEFAULT_FONT_SIZE}px ${fontFamily}`;
  9892. const metrics = ctx.measureText("");
  9893. let ascent = metrics.fontBoundingBoxAscent;
  9894. let descent = Math.abs(metrics.fontBoundingBoxDescent);
  9895. if (ascent) {
  9896. ctx.restore();
  9897. const ratio = ascent / (ascent + descent);
  9898. ascentCache.set(fontFamily, ratio);
  9899. return ratio;
  9900. }
  9901. ctx.strokeStyle = "red";
  9902. ctx.clearRect(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE);
  9903. ctx.strokeText("g", 0, 0);
  9904. let pixels = ctx.getImageData(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE).data;
  9905. descent = 0;
  9906. for (let i = pixels.length - 1 - 3; i >= 0; i -= 4) {
  9907. if (pixels[i] > 0) {
  9908. descent = Math.ceil(i / 4 / DEFAULT_FONT_SIZE);
  9909. break;
  9910. }
  9911. }
  9912. ctx.clearRect(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE);
  9913. ctx.strokeText("A", 0, DEFAULT_FONT_SIZE);
  9914. pixels = ctx.getImageData(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE).data;
  9915. ascent = 0;
  9916. for (let i = 0, ii = pixels.length; i < ii; i += 4) {
  9917. if (pixels[i] > 0) {
  9918. ascent = DEFAULT_FONT_SIZE - Math.floor(i / 4 / DEFAULT_FONT_SIZE);
  9919. break;
  9920. }
  9921. }
  9922. ctx.restore();
  9923. if (ascent) {
  9924. const ratio = ascent / (ascent + descent);
  9925. ascentCache.set(fontFamily, ratio);
  9926. return ratio;
  9927. }
  9928. ascentCache.set(fontFamily, DEFAULT_FONT_ASCENT);
  9929. return DEFAULT_FONT_ASCENT;
  9930. }
  9931. function appendText(task, geom, styles, ctx) {
  9932. const textDiv = document.createElement("span");
  9933. const textDivProperties = task._enhanceTextSelection ? {
  9934. angle: 0,
  9935. canvasWidth: 0,
  9936. hasText: geom.str !== "",
  9937. hasEOL: geom.hasEOL,
  9938. originalTransform: null,
  9939. paddingBottom: 0,
  9940. paddingLeft: 0,
  9941. paddingRight: 0,
  9942. paddingTop: 0,
  9943. scale: 1
  9944. } : {
  9945. angle: 0,
  9946. canvasWidth: 0,
  9947. hasText: geom.str !== "",
  9948. hasEOL: geom.hasEOL
  9949. };
  9950. task._textDivs.push(textDiv);
  9951. const tx = _util.Util.transform(task._viewport.transform, geom.transform);
  9952. let angle = Math.atan2(tx[1], tx[0]);
  9953. const style = styles[geom.fontName];
  9954. if (style.vertical) {
  9955. angle += Math.PI / 2;
  9956. }
  9957. const fontHeight = Math.hypot(tx[2], tx[3]);
  9958. const fontAscent = fontHeight * getAscent(style.fontFamily, ctx);
  9959. let left, top;
  9960. if (angle === 0) {
  9961. left = tx[4];
  9962. top = tx[5] - fontAscent;
  9963. } else {
  9964. left = tx[4] + fontAscent * Math.sin(angle);
  9965. top = tx[5] - fontAscent * Math.cos(angle);
  9966. }
  9967. textDiv.style.left = `${left}px`;
  9968. textDiv.style.top = `${top}px`;
  9969. textDiv.style.fontSize = `${fontHeight}px`;
  9970. textDiv.style.fontFamily = style.fontFamily;
  9971. textDiv.setAttribute("role", "presentation");
  9972. textDiv.textContent = geom.str;
  9973. textDiv.dir = geom.dir;
  9974. if (task._fontInspectorEnabled) {
  9975. textDiv.dataset.fontName = geom.fontName;
  9976. }
  9977. if (angle !== 0) {
  9978. textDivProperties.angle = angle * (180 / Math.PI);
  9979. }
  9980. let shouldScaleText = false;
  9981. if (geom.str.length > 1 || task._enhanceTextSelection && AllWhitespaceRegexp.test(geom.str)) {
  9982. shouldScaleText = true;
  9983. } else if (geom.str !== " " && geom.transform[0] !== geom.transform[3]) {
  9984. const absScaleX = Math.abs(geom.transform[0]),
  9985. absScaleY = Math.abs(geom.transform[3]);
  9986. if (absScaleX !== absScaleY && Math.max(absScaleX, absScaleY) / Math.min(absScaleX, absScaleY) > 1.5) {
  9987. shouldScaleText = true;
  9988. }
  9989. }
  9990. if (shouldScaleText) {
  9991. if (style.vertical) {
  9992. textDivProperties.canvasWidth = geom.height * task._viewport.scale;
  9993. } else {
  9994. textDivProperties.canvasWidth = geom.width * task._viewport.scale;
  9995. }
  9996. }
  9997. task._textDivProperties.set(textDiv, textDivProperties);
  9998. if (task._textContentStream) {
  9999. task._layoutText(textDiv);
  10000. }
  10001. if (task._enhanceTextSelection && textDivProperties.hasText) {
  10002. let angleCos = 1,
  10003. angleSin = 0;
  10004. if (angle !== 0) {
  10005. angleCos = Math.cos(angle);
  10006. angleSin = Math.sin(angle);
  10007. }
  10008. const divWidth = (style.vertical ? geom.height : geom.width) * task._viewport.scale;
  10009. const divHeight = fontHeight;
  10010. let m, b;
  10011. if (angle !== 0) {
  10012. m = [angleCos, angleSin, -angleSin, angleCos, left, top];
  10013. b = _util.Util.getAxialAlignedBoundingBox([0, 0, divWidth, divHeight], m);
  10014. } else {
  10015. b = [left, top, left + divWidth, top + divHeight];
  10016. }
  10017. task._bounds.push({
  10018. left: b[0],
  10019. top: b[1],
  10020. right: b[2],
  10021. bottom: b[3],
  10022. div: textDiv,
  10023. size: [divWidth, divHeight],
  10024. m
  10025. });
  10026. }
  10027. }
  10028. function render(task) {
  10029. if (task._canceled) {
  10030. return;
  10031. }
  10032. const textDivs = task._textDivs;
  10033. const capability = task._capability;
  10034. const textDivsLength = textDivs.length;
  10035. if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
  10036. task._renderingDone = true;
  10037. capability.resolve();
  10038. return;
  10039. }
  10040. if (!task._textContentStream) {
  10041. for (let i = 0; i < textDivsLength; i++) {
  10042. task._layoutText(textDivs[i]);
  10043. }
  10044. }
  10045. task._renderingDone = true;
  10046. capability.resolve();
  10047. }
  10048. function findPositiveMin(ts, offset, count) {
  10049. let result = 0;
  10050. for (let i = 0; i < count; i++) {
  10051. const t = ts[offset++];
  10052. if (t > 0) {
  10053. result = result ? Math.min(t, result) : t;
  10054. }
  10055. }
  10056. return result;
  10057. }
  10058. function expand(task) {
  10059. const bounds = task._bounds;
  10060. const viewport = task._viewport;
  10061. const expanded = expandBounds(viewport.width, viewport.height, bounds);
  10062. for (let i = 0; i < expanded.length; i++) {
  10063. const div = bounds[i].div;
  10064. const divProperties = task._textDivProperties.get(div);
  10065. if (divProperties.angle === 0) {
  10066. divProperties.paddingLeft = bounds[i].left - expanded[i].left;
  10067. divProperties.paddingTop = bounds[i].top - expanded[i].top;
  10068. divProperties.paddingRight = expanded[i].right - bounds[i].right;
  10069. divProperties.paddingBottom = expanded[i].bottom - bounds[i].bottom;
  10070. task._textDivProperties.set(div, divProperties);
  10071. continue;
  10072. }
  10073. const e = expanded[i],
  10074. b = bounds[i];
  10075. const m = b.m,
  10076. c = m[0],
  10077. s = m[1];
  10078. const points = [[0, 0], [0, b.size[1]], [b.size[0], 0], b.size];
  10079. const ts = new Float64Array(64);
  10080. for (let j = 0, jj = points.length; j < jj; j++) {
  10081. const t = _util.Util.applyTransform(points[j], m);
  10082. ts[j + 0] = c && (e.left - t[0]) / c;
  10083. ts[j + 4] = s && (e.top - t[1]) / s;
  10084. ts[j + 8] = c && (e.right - t[0]) / c;
  10085. ts[j + 12] = s && (e.bottom - t[1]) / s;
  10086. ts[j + 16] = s && (e.left - t[0]) / -s;
  10087. ts[j + 20] = c && (e.top - t[1]) / c;
  10088. ts[j + 24] = s && (e.right - t[0]) / -s;
  10089. ts[j + 28] = c && (e.bottom - t[1]) / c;
  10090. ts[j + 32] = c && (e.left - t[0]) / -c;
  10091. ts[j + 36] = s && (e.top - t[1]) / -s;
  10092. ts[j + 40] = c && (e.right - t[0]) / -c;
  10093. ts[j + 44] = s && (e.bottom - t[1]) / -s;
  10094. ts[j + 48] = s && (e.left - t[0]) / s;
  10095. ts[j + 52] = c && (e.top - t[1]) / -c;
  10096. ts[j + 56] = s && (e.right - t[0]) / s;
  10097. ts[j + 60] = c && (e.bottom - t[1]) / -c;
  10098. }
  10099. const boxScale = 1 + Math.min(Math.abs(c), Math.abs(s));
  10100. divProperties.paddingLeft = findPositiveMin(ts, 32, 16) / boxScale;
  10101. divProperties.paddingTop = findPositiveMin(ts, 48, 16) / boxScale;
  10102. divProperties.paddingRight = findPositiveMin(ts, 0, 16) / boxScale;
  10103. divProperties.paddingBottom = findPositiveMin(ts, 16, 16) / boxScale;
  10104. task._textDivProperties.set(div, divProperties);
  10105. }
  10106. }
  10107. function expandBounds(width, height, boxes) {
  10108. const bounds = boxes.map(function (box, i) {
  10109. return {
  10110. x1: box.left,
  10111. y1: box.top,
  10112. x2: box.right,
  10113. y2: box.bottom,
  10114. index: i,
  10115. x1New: undefined,
  10116. x2New: undefined
  10117. };
  10118. });
  10119. expandBoundsLTR(width, bounds);
  10120. const expanded = new Array(boxes.length);
  10121. for (const b of bounds) {
  10122. const i = b.index;
  10123. expanded[i] = {
  10124. left: b.x1New,
  10125. top: 0,
  10126. right: b.x2New,
  10127. bottom: 0
  10128. };
  10129. }
  10130. boxes.map(function (box, i) {
  10131. const e = expanded[i],
  10132. b = bounds[i];
  10133. b.x1 = box.top;
  10134. b.y1 = width - e.right;
  10135. b.x2 = box.bottom;
  10136. b.y2 = width - e.left;
  10137. b.index = i;
  10138. b.x1New = undefined;
  10139. b.x2New = undefined;
  10140. });
  10141. expandBoundsLTR(height, bounds);
  10142. for (const b of bounds) {
  10143. const i = b.index;
  10144. expanded[i].top = b.x1New;
  10145. expanded[i].bottom = b.x2New;
  10146. }
  10147. return expanded;
  10148. }
  10149. function expandBoundsLTR(width, bounds) {
  10150. bounds.sort(function (a, b) {
  10151. return a.x1 - b.x1 || a.index - b.index;
  10152. });
  10153. const fakeBoundary = {
  10154. x1: -Infinity,
  10155. y1: -Infinity,
  10156. x2: 0,
  10157. y2: Infinity,
  10158. index: -1,
  10159. x1New: 0,
  10160. x2New: 0
  10161. };
  10162. const horizon = [{
  10163. start: -Infinity,
  10164. end: Infinity,
  10165. boundary: fakeBoundary
  10166. }];
  10167. for (const boundary of bounds) {
  10168. let i = 0;
  10169. while (i < horizon.length && horizon[i].end <= boundary.y1) {
  10170. i++;
  10171. }
  10172. let j = horizon.length - 1;
  10173. while (j >= 0 && horizon[j].start >= boundary.y2) {
  10174. j--;
  10175. }
  10176. let horizonPart, affectedBoundary;
  10177. let q,
  10178. k,
  10179. maxXNew = -Infinity;
  10180. for (q = i; q <= j; q++) {
  10181. horizonPart = horizon[q];
  10182. affectedBoundary = horizonPart.boundary;
  10183. let xNew;
  10184. if (affectedBoundary.x2 > boundary.x1) {
  10185. xNew = affectedBoundary.index > boundary.index ? affectedBoundary.x1New : boundary.x1;
  10186. } else if (affectedBoundary.x2New === undefined) {
  10187. xNew = (affectedBoundary.x2 + boundary.x1) / 2;
  10188. } else {
  10189. xNew = affectedBoundary.x2New;
  10190. }
  10191. if (xNew > maxXNew) {
  10192. maxXNew = xNew;
  10193. }
  10194. }
  10195. boundary.x1New = maxXNew;
  10196. for (q = i; q <= j; q++) {
  10197. horizonPart = horizon[q];
  10198. affectedBoundary = horizonPart.boundary;
  10199. if (affectedBoundary.x2New === undefined) {
  10200. if (affectedBoundary.x2 > boundary.x1) {
  10201. if (affectedBoundary.index > boundary.index) {
  10202. affectedBoundary.x2New = affectedBoundary.x2;
  10203. }
  10204. } else {
  10205. affectedBoundary.x2New = maxXNew;
  10206. }
  10207. } else if (affectedBoundary.x2New > maxXNew) {
  10208. affectedBoundary.x2New = Math.max(maxXNew, affectedBoundary.x2);
  10209. }
  10210. }
  10211. const changedHorizon = [];
  10212. let lastBoundary = null;
  10213. for (q = i; q <= j; q++) {
  10214. horizonPart = horizon[q];
  10215. affectedBoundary = horizonPart.boundary;
  10216. const useBoundary = affectedBoundary.x2 > boundary.x2 ? affectedBoundary : boundary;
  10217. if (lastBoundary === useBoundary) {
  10218. changedHorizon[changedHorizon.length - 1].end = horizonPart.end;
  10219. } else {
  10220. changedHorizon.push({
  10221. start: horizonPart.start,
  10222. end: horizonPart.end,
  10223. boundary: useBoundary
  10224. });
  10225. lastBoundary = useBoundary;
  10226. }
  10227. }
  10228. if (horizon[i].start < boundary.y1) {
  10229. changedHorizon[0].start = boundary.y1;
  10230. changedHorizon.unshift({
  10231. start: horizon[i].start,
  10232. end: boundary.y1,
  10233. boundary: horizon[i].boundary
  10234. });
  10235. }
  10236. if (boundary.y2 < horizon[j].end) {
  10237. changedHorizon[changedHorizon.length - 1].end = boundary.y2;
  10238. changedHorizon.push({
  10239. start: boundary.y2,
  10240. end: horizon[j].end,
  10241. boundary: horizon[j].boundary
  10242. });
  10243. }
  10244. for (q = i; q <= j; q++) {
  10245. horizonPart = horizon[q];
  10246. affectedBoundary = horizonPart.boundary;
  10247. if (affectedBoundary.x2New !== undefined) {
  10248. continue;
  10249. }
  10250. let used = false;
  10251. for (k = i - 1; !used && k >= 0 && horizon[k].start >= affectedBoundary.y1; k--) {
  10252. used = horizon[k].boundary === affectedBoundary;
  10253. }
  10254. for (k = j + 1; !used && k < horizon.length && horizon[k].end <= affectedBoundary.y2; k++) {
  10255. used = horizon[k].boundary === affectedBoundary;
  10256. }
  10257. for (k = 0; !used && k < changedHorizon.length; k++) {
  10258. used = changedHorizon[k].boundary === affectedBoundary;
  10259. }
  10260. if (!used) {
  10261. affectedBoundary.x2New = maxXNew;
  10262. }
  10263. }
  10264. Array.prototype.splice.apply(horizon, [i, j - i + 1].concat(changedHorizon));
  10265. }
  10266. for (const horizonPart of horizon) {
  10267. const affectedBoundary = horizonPart.boundary;
  10268. if (affectedBoundary.x2New === undefined) {
  10269. affectedBoundary.x2New = Math.max(width, affectedBoundary.x2);
  10270. }
  10271. }
  10272. }
  10273. class TextLayerRenderTask {
  10274. constructor({
  10275. textContent,
  10276. textContentStream,
  10277. container,
  10278. viewport,
  10279. textDivs,
  10280. textContentItemsStr,
  10281. enhanceTextSelection
  10282. }) {
  10283. this._textContent = textContent;
  10284. this._textContentStream = textContentStream;
  10285. this._container = container;
  10286. this._document = container.ownerDocument;
  10287. this._viewport = viewport;
  10288. this._textDivs = textDivs || [];
  10289. this._textContentItemsStr = textContentItemsStr || [];
  10290. this._enhanceTextSelection = !!enhanceTextSelection;
  10291. this._fontInspectorEnabled = !!globalThis.FontInspector?.enabled;
  10292. this._reader = null;
  10293. this._layoutTextLastFontSize = null;
  10294. this._layoutTextLastFontFamily = null;
  10295. this._layoutTextCtx = null;
  10296. this._textDivProperties = new WeakMap();
  10297. this._renderingDone = false;
  10298. this._canceled = false;
  10299. this._capability = (0, _util.createPromiseCapability)();
  10300. this._renderTimer = null;
  10301. this._bounds = [];
  10302. this._capability.promise.finally(() => {
  10303. if (!this._enhanceTextSelection) {
  10304. this._textDivProperties = null;
  10305. }
  10306. if (this._layoutTextCtx) {
  10307. this._layoutTextCtx.canvas.width = 0;
  10308. this._layoutTextCtx.canvas.height = 0;
  10309. this._layoutTextCtx = null;
  10310. }
  10311. }).catch(() => {});
  10312. }
  10313. get promise() {
  10314. return this._capability.promise;
  10315. }
  10316. cancel() {
  10317. this._canceled = true;
  10318. if (this._reader) {
  10319. this._reader.cancel(new _util.AbortException("TextLayer task cancelled.")).catch(() => {});
  10320. this._reader = null;
  10321. }
  10322. if (this._renderTimer !== null) {
  10323. clearTimeout(this._renderTimer);
  10324. this._renderTimer = null;
  10325. }
  10326. this._capability.reject(new Error("TextLayer task cancelled."));
  10327. }
  10328. _processItems(items, styleCache) {
  10329. for (let i = 0, len = items.length; i < len; i++) {
  10330. if (items[i].str === undefined) {
  10331. if (items[i].type === "beginMarkedContentProps" || items[i].type === "beginMarkedContent") {
  10332. const parent = this._container;
  10333. this._container = document.createElement("span");
  10334. this._container.classList.add("markedContent");
  10335. if (items[i].id !== null) {
  10336. this._container.setAttribute("id", `${items[i].id}`);
  10337. }
  10338. parent.appendChild(this._container);
  10339. } else if (items[i].type === "endMarkedContent") {
  10340. this._container = this._container.parentNode;
  10341. }
  10342. continue;
  10343. }
  10344. this._textContentItemsStr.push(items[i].str);
  10345. appendText(this, items[i], styleCache, this._layoutTextCtx);
  10346. }
  10347. }
  10348. _layoutText(textDiv) {
  10349. const textDivProperties = this._textDivProperties.get(textDiv);
  10350. let transform = "";
  10351. if (textDivProperties.canvasWidth !== 0 && textDivProperties.hasText) {
  10352. const {
  10353. fontSize,
  10354. fontFamily
  10355. } = textDiv.style;
  10356. if (fontSize !== this._layoutTextLastFontSize || fontFamily !== this._layoutTextLastFontFamily) {
  10357. this._layoutTextCtx.font = `${fontSize} ${fontFamily}`;
  10358. this._layoutTextLastFontSize = fontSize;
  10359. this._layoutTextLastFontFamily = fontFamily;
  10360. }
  10361. const {
  10362. width
  10363. } = this._layoutTextCtx.measureText(textDiv.textContent);
  10364. if (width > 0) {
  10365. const scale = textDivProperties.canvasWidth / width;
  10366. if (this._enhanceTextSelection) {
  10367. textDivProperties.scale = scale;
  10368. }
  10369. transform = `scaleX(${scale})`;
  10370. }
  10371. }
  10372. if (textDivProperties.angle !== 0) {
  10373. transform = `rotate(${textDivProperties.angle}deg) ${transform}`;
  10374. }
  10375. if (transform.length > 0) {
  10376. if (this._enhanceTextSelection) {
  10377. textDivProperties.originalTransform = transform;
  10378. }
  10379. textDiv.style.transform = transform;
  10380. }
  10381. if (textDivProperties.hasText) {
  10382. this._container.appendChild(textDiv);
  10383. }
  10384. if (textDivProperties.hasEOL) {
  10385. const br = document.createElement("br");
  10386. br.setAttribute("role", "presentation");
  10387. this._container.appendChild(br);
  10388. }
  10389. }
  10390. _render(timeout = 0) {
  10391. const capability = (0, _util.createPromiseCapability)();
  10392. let styleCache = Object.create(null);
  10393. const canvas = this._document.createElement("canvas");
  10394. canvas.height = canvas.width = DEFAULT_FONT_SIZE;
  10395. this._layoutTextCtx = canvas.getContext("2d", {
  10396. alpha: false
  10397. });
  10398. if (this._textContent) {
  10399. const textItems = this._textContent.items;
  10400. const textStyles = this._textContent.styles;
  10401. this._processItems(textItems, textStyles);
  10402. capability.resolve();
  10403. } else if (this._textContentStream) {
  10404. const pump = () => {
  10405. this._reader.read().then(({
  10406. value,
  10407. done
  10408. }) => {
  10409. if (done) {
  10410. capability.resolve();
  10411. return;
  10412. }
  10413. Object.assign(styleCache, value.styles);
  10414. this._processItems(value.items, styleCache);
  10415. pump();
  10416. }, capability.reject);
  10417. };
  10418. this._reader = this._textContentStream.getReader();
  10419. pump();
  10420. } else {
  10421. throw new Error('Neither "textContent" nor "textContentStream" parameters specified.');
  10422. }
  10423. capability.promise.then(() => {
  10424. styleCache = null;
  10425. if (!timeout) {
  10426. render(this);
  10427. } else {
  10428. this._renderTimer = setTimeout(() => {
  10429. render(this);
  10430. this._renderTimer = null;
  10431. }, timeout);
  10432. }
  10433. }, this._capability.reject);
  10434. }
  10435. expandTextDivs(expandDivs = false) {
  10436. if (!this._enhanceTextSelection || !this._renderingDone) {
  10437. return;
  10438. }
  10439. if (this._bounds !== null) {
  10440. expand(this);
  10441. this._bounds = null;
  10442. }
  10443. const transformBuf = [],
  10444. paddingBuf = [];
  10445. for (let i = 0, ii = this._textDivs.length; i < ii; i++) {
  10446. const div = this._textDivs[i];
  10447. const divProps = this._textDivProperties.get(div);
  10448. if (!divProps.hasText) {
  10449. continue;
  10450. }
  10451. if (expandDivs) {
  10452. transformBuf.length = 0;
  10453. paddingBuf.length = 0;
  10454. if (divProps.originalTransform) {
  10455. transformBuf.push(divProps.originalTransform);
  10456. }
  10457. if (divProps.paddingTop > 0) {
  10458. paddingBuf.push(`${divProps.paddingTop}px`);
  10459. transformBuf.push(`translateY(${-divProps.paddingTop}px)`);
  10460. } else {
  10461. paddingBuf.push(0);
  10462. }
  10463. if (divProps.paddingRight > 0) {
  10464. paddingBuf.push(`${divProps.paddingRight / divProps.scale}px`);
  10465. } else {
  10466. paddingBuf.push(0);
  10467. }
  10468. if (divProps.paddingBottom > 0) {
  10469. paddingBuf.push(`${divProps.paddingBottom}px`);
  10470. } else {
  10471. paddingBuf.push(0);
  10472. }
  10473. if (divProps.paddingLeft > 0) {
  10474. paddingBuf.push(`${divProps.paddingLeft / divProps.scale}px`);
  10475. transformBuf.push(`translateX(${-divProps.paddingLeft / divProps.scale}px)`);
  10476. } else {
  10477. paddingBuf.push(0);
  10478. }
  10479. div.style.padding = paddingBuf.join(" ");
  10480. if (transformBuf.length) {
  10481. div.style.transform = transformBuf.join(" ");
  10482. }
  10483. } else {
  10484. div.style.padding = null;
  10485. div.style.transform = divProps.originalTransform;
  10486. }
  10487. }
  10488. }
  10489. }
  10490. function renderTextLayer(renderParameters) {
  10491. const task = new TextLayerRenderTask({
  10492. textContent: renderParameters.textContent,
  10493. textContentStream: renderParameters.textContentStream,
  10494. container: renderParameters.container,
  10495. viewport: renderParameters.viewport,
  10496. textDivs: renderParameters.textDivs,
  10497. textContentItemsStr: renderParameters.textContentItemsStr,
  10498. enhanceTextSelection: renderParameters.enhanceTextSelection
  10499. });
  10500. task._render(renderParameters.timeout);
  10501. return task;
  10502. }
  10503. /***/ }),
  10504. /* 24 */
  10505. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  10506. Object.defineProperty(exports, "__esModule", ({
  10507. value: true
  10508. }));
  10509. exports.SVGGraphics = void 0;
  10510. var _util = __w_pdfjs_require__(1);
  10511. var _display_utils = __w_pdfjs_require__(5);
  10512. var _is_node = __w_pdfjs_require__(3);
  10513. let SVGGraphics = class {
  10514. constructor() {
  10515. (0, _util.unreachable)("Not implemented: SVGGraphics");
  10516. }
  10517. };
  10518. exports.SVGGraphics = SVGGraphics;
  10519. {
  10520. const SVG_DEFAULTS = {
  10521. fontStyle: "normal",
  10522. fontWeight: "normal",
  10523. fillColor: "#000000"
  10524. };
  10525. const XML_NS = "http://www.w3.org/XML/1998/namespace";
  10526. const XLINK_NS = "http://www.w3.org/1999/xlink";
  10527. const LINE_CAP_STYLES = ["butt", "round", "square"];
  10528. const LINE_JOIN_STYLES = ["miter", "round", "bevel"];
  10529. const createObjectURL = function (data, contentType = "", forceDataSchema = false) {
  10530. if (URL.createObjectURL && typeof Blob !== "undefined" && !forceDataSchema) {
  10531. return URL.createObjectURL(new Blob([data], {
  10532. type: contentType
  10533. }));
  10534. }
  10535. const digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  10536. let buffer = `data:${contentType};base64,`;
  10537. for (let i = 0, ii = data.length; i < ii; i += 3) {
  10538. const b1 = data[i] & 0xff;
  10539. const b2 = data[i + 1] & 0xff;
  10540. const b3 = data[i + 2] & 0xff;
  10541. const d1 = b1 >> 2,
  10542. d2 = (b1 & 3) << 4 | b2 >> 4;
  10543. const d3 = i + 1 < ii ? (b2 & 0xf) << 2 | b3 >> 6 : 64;
  10544. const d4 = i + 2 < ii ? b3 & 0x3f : 64;
  10545. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  10546. }
  10547. return buffer;
  10548. };
  10549. const convertImgDataToPng = function () {
  10550. const PNG_HEADER = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  10551. const CHUNK_WRAPPER_SIZE = 12;
  10552. const crcTable = new Int32Array(256);
  10553. for (let i = 0; i < 256; i++) {
  10554. let c = i;
  10555. for (let h = 0; h < 8; h++) {
  10556. if (c & 1) {
  10557. c = 0xedb88320 ^ c >> 1 & 0x7fffffff;
  10558. } else {
  10559. c = c >> 1 & 0x7fffffff;
  10560. }
  10561. }
  10562. crcTable[i] = c;
  10563. }
  10564. function crc32(data, start, end) {
  10565. let crc = -1;
  10566. for (let i = start; i < end; i++) {
  10567. const a = (crc ^ data[i]) & 0xff;
  10568. const b = crcTable[a];
  10569. crc = crc >>> 8 ^ b;
  10570. }
  10571. return crc ^ -1;
  10572. }
  10573. function writePngChunk(type, body, data, offset) {
  10574. let p = offset;
  10575. const len = body.length;
  10576. data[p] = len >> 24 & 0xff;
  10577. data[p + 1] = len >> 16 & 0xff;
  10578. data[p + 2] = len >> 8 & 0xff;
  10579. data[p + 3] = len & 0xff;
  10580. p += 4;
  10581. data[p] = type.charCodeAt(0) & 0xff;
  10582. data[p + 1] = type.charCodeAt(1) & 0xff;
  10583. data[p + 2] = type.charCodeAt(2) & 0xff;
  10584. data[p + 3] = type.charCodeAt(3) & 0xff;
  10585. p += 4;
  10586. data.set(body, p);
  10587. p += body.length;
  10588. const crc = crc32(data, offset + 4, p);
  10589. data[p] = crc >> 24 & 0xff;
  10590. data[p + 1] = crc >> 16 & 0xff;
  10591. data[p + 2] = crc >> 8 & 0xff;
  10592. data[p + 3] = crc & 0xff;
  10593. }
  10594. function adler32(data, start, end) {
  10595. let a = 1;
  10596. let b = 0;
  10597. for (let i = start; i < end; ++i) {
  10598. a = (a + (data[i] & 0xff)) % 65521;
  10599. b = (b + a) % 65521;
  10600. }
  10601. return b << 16 | a;
  10602. }
  10603. function deflateSync(literals) {
  10604. if (!_is_node.isNodeJS) {
  10605. return deflateSyncUncompressed(literals);
  10606. }
  10607. try {
  10608. let input;
  10609. if (parseInt(process.versions.node) >= 8) {
  10610. input = literals;
  10611. } else {
  10612. input = Buffer.from(literals);
  10613. }
  10614. const output = require("zlib").deflateSync(input, {
  10615. level: 9
  10616. });
  10617. return output instanceof Uint8Array ? output : new Uint8Array(output);
  10618. } catch (e) {
  10619. (0, _util.warn)("Not compressing PNG because zlib.deflateSync is unavailable: " + e);
  10620. }
  10621. return deflateSyncUncompressed(literals);
  10622. }
  10623. function deflateSyncUncompressed(literals) {
  10624. let len = literals.length;
  10625. const maxBlockLength = 0xffff;
  10626. const deflateBlocks = Math.ceil(len / maxBlockLength);
  10627. const idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  10628. let pi = 0;
  10629. idat[pi++] = 0x78;
  10630. idat[pi++] = 0x9c;
  10631. let pos = 0;
  10632. while (len > maxBlockLength) {
  10633. idat[pi++] = 0x00;
  10634. idat[pi++] = 0xff;
  10635. idat[pi++] = 0xff;
  10636. idat[pi++] = 0x00;
  10637. idat[pi++] = 0x00;
  10638. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  10639. pi += maxBlockLength;
  10640. pos += maxBlockLength;
  10641. len -= maxBlockLength;
  10642. }
  10643. idat[pi++] = 0x01;
  10644. idat[pi++] = len & 0xff;
  10645. idat[pi++] = len >> 8 & 0xff;
  10646. idat[pi++] = ~len & 0xffff & 0xff;
  10647. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  10648. idat.set(literals.subarray(pos), pi);
  10649. pi += literals.length - pos;
  10650. const adler = adler32(literals, 0, literals.length);
  10651. idat[pi++] = adler >> 24 & 0xff;
  10652. idat[pi++] = adler >> 16 & 0xff;
  10653. idat[pi++] = adler >> 8 & 0xff;
  10654. idat[pi++] = adler & 0xff;
  10655. return idat;
  10656. }
  10657. function encode(imgData, kind, forceDataSchema, isMask) {
  10658. const width = imgData.width;
  10659. const height = imgData.height;
  10660. let bitDepth, colorType, lineSize;
  10661. const bytes = imgData.data;
  10662. switch (kind) {
  10663. case _util.ImageKind.GRAYSCALE_1BPP:
  10664. colorType = 0;
  10665. bitDepth = 1;
  10666. lineSize = width + 7 >> 3;
  10667. break;
  10668. case _util.ImageKind.RGB_24BPP:
  10669. colorType = 2;
  10670. bitDepth = 8;
  10671. lineSize = width * 3;
  10672. break;
  10673. case _util.ImageKind.RGBA_32BPP:
  10674. colorType = 6;
  10675. bitDepth = 8;
  10676. lineSize = width * 4;
  10677. break;
  10678. default:
  10679. throw new Error("invalid format");
  10680. }
  10681. const literals = new Uint8Array((1 + lineSize) * height);
  10682. let offsetLiterals = 0,
  10683. offsetBytes = 0;
  10684. for (let y = 0; y < height; ++y) {
  10685. literals[offsetLiterals++] = 0;
  10686. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize), offsetLiterals);
  10687. offsetBytes += lineSize;
  10688. offsetLiterals += lineSize;
  10689. }
  10690. if (kind === _util.ImageKind.GRAYSCALE_1BPP && isMask) {
  10691. offsetLiterals = 0;
  10692. for (let y = 0; y < height; y++) {
  10693. offsetLiterals++;
  10694. for (let i = 0; i < lineSize; i++) {
  10695. literals[offsetLiterals++] ^= 0xff;
  10696. }
  10697. }
  10698. }
  10699. 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]);
  10700. const idat = deflateSync(literals);
  10701. const pngLength = PNG_HEADER.length + CHUNK_WRAPPER_SIZE * 3 + ihdr.length + idat.length;
  10702. const data = new Uint8Array(pngLength);
  10703. let offset = 0;
  10704. data.set(PNG_HEADER, offset);
  10705. offset += PNG_HEADER.length;
  10706. writePngChunk("IHDR", ihdr, data, offset);
  10707. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  10708. writePngChunk("IDATA", idat, data, offset);
  10709. offset += CHUNK_WRAPPER_SIZE + idat.length;
  10710. writePngChunk("IEND", new Uint8Array(0), data, offset);
  10711. return createObjectURL(data, "image/png", forceDataSchema);
  10712. }
  10713. return function convertImgDataToPng(imgData, forceDataSchema, isMask) {
  10714. const kind = imgData.kind === undefined ? _util.ImageKind.GRAYSCALE_1BPP : imgData.kind;
  10715. return encode(imgData, kind, forceDataSchema, isMask);
  10716. };
  10717. }();
  10718. class SVGExtraState {
  10719. constructor() {
  10720. this.fontSizeScale = 1;
  10721. this.fontWeight = SVG_DEFAULTS.fontWeight;
  10722. this.fontSize = 0;
  10723. this.textMatrix = _util.IDENTITY_MATRIX;
  10724. this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
  10725. this.leading = 0;
  10726. this.textRenderingMode = _util.TextRenderingMode.FILL;
  10727. this.textMatrixScale = 1;
  10728. this.x = 0;
  10729. this.y = 0;
  10730. this.lineX = 0;
  10731. this.lineY = 0;
  10732. this.charSpacing = 0;
  10733. this.wordSpacing = 0;
  10734. this.textHScale = 1;
  10735. this.textRise = 0;
  10736. this.fillColor = SVG_DEFAULTS.fillColor;
  10737. this.strokeColor = "#000000";
  10738. this.fillAlpha = 1;
  10739. this.strokeAlpha = 1;
  10740. this.lineWidth = 1;
  10741. this.lineJoin = "";
  10742. this.lineCap = "";
  10743. this.miterLimit = 0;
  10744. this.dashArray = [];
  10745. this.dashPhase = 0;
  10746. this.dependencies = [];
  10747. this.activeClipUrl = null;
  10748. this.clipGroup = null;
  10749. this.maskId = "";
  10750. }
  10751. clone() {
  10752. return Object.create(this);
  10753. }
  10754. setCurrentPoint(x, y) {
  10755. this.x = x;
  10756. this.y = y;
  10757. }
  10758. }
  10759. function opListToTree(opList) {
  10760. let opTree = [];
  10761. const tmp = [];
  10762. for (const opListElement of opList) {
  10763. if (opListElement.fn === "save") {
  10764. opTree.push({
  10765. fnId: 92,
  10766. fn: "group",
  10767. items: []
  10768. });
  10769. tmp.push(opTree);
  10770. opTree = opTree[opTree.length - 1].items;
  10771. continue;
  10772. }
  10773. if (opListElement.fn === "restore") {
  10774. opTree = tmp.pop();
  10775. } else {
  10776. opTree.push(opListElement);
  10777. }
  10778. }
  10779. return opTree;
  10780. }
  10781. function pf(value) {
  10782. if (Number.isInteger(value)) {
  10783. return value.toString();
  10784. }
  10785. const s = value.toFixed(10);
  10786. let i = s.length - 1;
  10787. if (s[i] !== "0") {
  10788. return s;
  10789. }
  10790. do {
  10791. i--;
  10792. } while (s[i] === "0");
  10793. return s.substring(0, s[i] === "." ? i : i + 1);
  10794. }
  10795. function pm(m) {
  10796. if (m[4] === 0 && m[5] === 0) {
  10797. if (m[1] === 0 && m[2] === 0) {
  10798. if (m[0] === 1 && m[3] === 1) {
  10799. return "";
  10800. }
  10801. return `scale(${pf(m[0])} ${pf(m[3])})`;
  10802. }
  10803. if (m[0] === m[3] && m[1] === -m[2]) {
  10804. const a = Math.acos(m[0]) * 180 / Math.PI;
  10805. return `rotate(${pf(a)})`;
  10806. }
  10807. } else {
  10808. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  10809. return `translate(${pf(m[4])} ${pf(m[5])})`;
  10810. }
  10811. }
  10812. return `matrix(${pf(m[0])} ${pf(m[1])} ${pf(m[2])} ${pf(m[3])} ${pf(m[4])} ` + `${pf(m[5])})`;
  10813. }
  10814. let clipCount = 0;
  10815. let maskCount = 0;
  10816. let shadingCount = 0;
  10817. exports.SVGGraphics = SVGGraphics = class {
  10818. constructor(commonObjs, objs, forceDataSchema = false) {
  10819. this.svgFactory = new _display_utils.DOMSVGFactory();
  10820. this.current = new SVGExtraState();
  10821. this.transformMatrix = _util.IDENTITY_MATRIX;
  10822. this.transformStack = [];
  10823. this.extraStack = [];
  10824. this.commonObjs = commonObjs;
  10825. this.objs = objs;
  10826. this.pendingClip = null;
  10827. this.pendingEOFill = false;
  10828. this.embedFonts = false;
  10829. this.embeddedFonts = Object.create(null);
  10830. this.cssStyle = null;
  10831. this.forceDataSchema = !!forceDataSchema;
  10832. this._operatorIdMapping = [];
  10833. for (const op in _util.OPS) {
  10834. this._operatorIdMapping[_util.OPS[op]] = op;
  10835. }
  10836. }
  10837. save() {
  10838. this.transformStack.push(this.transformMatrix);
  10839. const old = this.current;
  10840. this.extraStack.push(old);
  10841. this.current = old.clone();
  10842. }
  10843. restore() {
  10844. this.transformMatrix = this.transformStack.pop();
  10845. this.current = this.extraStack.pop();
  10846. this.pendingClip = null;
  10847. this.tgrp = null;
  10848. }
  10849. group(items) {
  10850. this.save();
  10851. this.executeOpTree(items);
  10852. this.restore();
  10853. }
  10854. loadDependencies(operatorList) {
  10855. const fnArray = operatorList.fnArray;
  10856. const argsArray = operatorList.argsArray;
  10857. for (let i = 0, ii = fnArray.length; i < ii; i++) {
  10858. if (fnArray[i] !== _util.OPS.dependency) {
  10859. continue;
  10860. }
  10861. for (const obj of argsArray[i]) {
  10862. const objsPool = obj.startsWith("g_") ? this.commonObjs : this.objs;
  10863. const promise = new Promise(resolve => {
  10864. objsPool.get(obj, resolve);
  10865. });
  10866. this.current.dependencies.push(promise);
  10867. }
  10868. }
  10869. return Promise.all(this.current.dependencies);
  10870. }
  10871. transform(a, b, c, d, e, f) {
  10872. const transformMatrix = [a, b, c, d, e, f];
  10873. this.transformMatrix = _util.Util.transform(this.transformMatrix, transformMatrix);
  10874. this.tgrp = null;
  10875. }
  10876. getSVG(operatorList, viewport) {
  10877. this.viewport = viewport;
  10878. const svgElement = this._initialize(viewport);
  10879. return this.loadDependencies(operatorList).then(() => {
  10880. this.transformMatrix = _util.IDENTITY_MATRIX;
  10881. this.executeOpTree(this.convertOpList(operatorList));
  10882. return svgElement;
  10883. });
  10884. }
  10885. convertOpList(operatorList) {
  10886. const operatorIdMapping = this._operatorIdMapping;
  10887. const argsArray = operatorList.argsArray;
  10888. const fnArray = operatorList.fnArray;
  10889. const opList = [];
  10890. for (let i = 0, ii = fnArray.length; i < ii; i++) {
  10891. const fnId = fnArray[i];
  10892. opList.push({
  10893. fnId,
  10894. fn: operatorIdMapping[fnId],
  10895. args: argsArray[i]
  10896. });
  10897. }
  10898. return opListToTree(opList);
  10899. }
  10900. executeOpTree(opTree) {
  10901. for (const opTreeElement of opTree) {
  10902. const fn = opTreeElement.fn;
  10903. const fnId = opTreeElement.fnId;
  10904. const args = opTreeElement.args;
  10905. switch (fnId | 0) {
  10906. case _util.OPS.beginText:
  10907. this.beginText();
  10908. break;
  10909. case _util.OPS.dependency:
  10910. break;
  10911. case _util.OPS.setLeading:
  10912. this.setLeading(args);
  10913. break;
  10914. case _util.OPS.setLeadingMoveText:
  10915. this.setLeadingMoveText(args[0], args[1]);
  10916. break;
  10917. case _util.OPS.setFont:
  10918. this.setFont(args);
  10919. break;
  10920. case _util.OPS.showText:
  10921. this.showText(args[0]);
  10922. break;
  10923. case _util.OPS.showSpacedText:
  10924. this.showText(args[0]);
  10925. break;
  10926. case _util.OPS.endText:
  10927. this.endText();
  10928. break;
  10929. case _util.OPS.moveText:
  10930. this.moveText(args[0], args[1]);
  10931. break;
  10932. case _util.OPS.setCharSpacing:
  10933. this.setCharSpacing(args[0]);
  10934. break;
  10935. case _util.OPS.setWordSpacing:
  10936. this.setWordSpacing(args[0]);
  10937. break;
  10938. case _util.OPS.setHScale:
  10939. this.setHScale(args[0]);
  10940. break;
  10941. case _util.OPS.setTextMatrix:
  10942. this.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
  10943. break;
  10944. case _util.OPS.setTextRise:
  10945. this.setTextRise(args[0]);
  10946. break;
  10947. case _util.OPS.setTextRenderingMode:
  10948. this.setTextRenderingMode(args[0]);
  10949. break;
  10950. case _util.OPS.setLineWidth:
  10951. this.setLineWidth(args[0]);
  10952. break;
  10953. case _util.OPS.setLineJoin:
  10954. this.setLineJoin(args[0]);
  10955. break;
  10956. case _util.OPS.setLineCap:
  10957. this.setLineCap(args[0]);
  10958. break;
  10959. case _util.OPS.setMiterLimit:
  10960. this.setMiterLimit(args[0]);
  10961. break;
  10962. case _util.OPS.setFillRGBColor:
  10963. this.setFillRGBColor(args[0], args[1], args[2]);
  10964. break;
  10965. case _util.OPS.setStrokeRGBColor:
  10966. this.setStrokeRGBColor(args[0], args[1], args[2]);
  10967. break;
  10968. case _util.OPS.setStrokeColorN:
  10969. this.setStrokeColorN(args);
  10970. break;
  10971. case _util.OPS.setFillColorN:
  10972. this.setFillColorN(args);
  10973. break;
  10974. case _util.OPS.shadingFill:
  10975. this.shadingFill(args[0]);
  10976. break;
  10977. case _util.OPS.setDash:
  10978. this.setDash(args[0], args[1]);
  10979. break;
  10980. case _util.OPS.setRenderingIntent:
  10981. this.setRenderingIntent(args[0]);
  10982. break;
  10983. case _util.OPS.setFlatness:
  10984. this.setFlatness(args[0]);
  10985. break;
  10986. case _util.OPS.setGState:
  10987. this.setGState(args[0]);
  10988. break;
  10989. case _util.OPS.fill:
  10990. this.fill();
  10991. break;
  10992. case _util.OPS.eoFill:
  10993. this.eoFill();
  10994. break;
  10995. case _util.OPS.stroke:
  10996. this.stroke();
  10997. break;
  10998. case _util.OPS.fillStroke:
  10999. this.fillStroke();
  11000. break;
  11001. case _util.OPS.eoFillStroke:
  11002. this.eoFillStroke();
  11003. break;
  11004. case _util.OPS.clip:
  11005. this.clip("nonzero");
  11006. break;
  11007. case _util.OPS.eoClip:
  11008. this.clip("evenodd");
  11009. break;
  11010. case _util.OPS.paintSolidColorImageMask:
  11011. this.paintSolidColorImageMask();
  11012. break;
  11013. case _util.OPS.paintImageXObject:
  11014. this.paintImageXObject(args[0]);
  11015. break;
  11016. case _util.OPS.paintInlineImageXObject:
  11017. this.paintInlineImageXObject(args[0]);
  11018. break;
  11019. case _util.OPS.paintImageMaskXObject:
  11020. this.paintImageMaskXObject(args[0]);
  11021. break;
  11022. case _util.OPS.paintFormXObjectBegin:
  11023. this.paintFormXObjectBegin(args[0], args[1]);
  11024. break;
  11025. case _util.OPS.paintFormXObjectEnd:
  11026. this.paintFormXObjectEnd();
  11027. break;
  11028. case _util.OPS.closePath:
  11029. this.closePath();
  11030. break;
  11031. case _util.OPS.closeStroke:
  11032. this.closeStroke();
  11033. break;
  11034. case _util.OPS.closeFillStroke:
  11035. this.closeFillStroke();
  11036. break;
  11037. case _util.OPS.closeEOFillStroke:
  11038. this.closeEOFillStroke();
  11039. break;
  11040. case _util.OPS.nextLine:
  11041. this.nextLine();
  11042. break;
  11043. case _util.OPS.transform:
  11044. this.transform(args[0], args[1], args[2], args[3], args[4], args[5]);
  11045. break;
  11046. case _util.OPS.constructPath:
  11047. this.constructPath(args[0], args[1]);
  11048. break;
  11049. case _util.OPS.endPath:
  11050. this.endPath();
  11051. break;
  11052. case 92:
  11053. this.group(opTreeElement.items);
  11054. break;
  11055. default:
  11056. (0, _util.warn)(`Unimplemented operator ${fn}`);
  11057. break;
  11058. }
  11059. }
  11060. }
  11061. setWordSpacing(wordSpacing) {
  11062. this.current.wordSpacing = wordSpacing;
  11063. }
  11064. setCharSpacing(charSpacing) {
  11065. this.current.charSpacing = charSpacing;
  11066. }
  11067. nextLine() {
  11068. this.moveText(0, this.current.leading);
  11069. }
  11070. setTextMatrix(a, b, c, d, e, f) {
  11071. const current = this.current;
  11072. current.textMatrix = current.lineMatrix = [a, b, c, d, e, f];
  11073. current.textMatrixScale = Math.hypot(a, b);
  11074. current.x = current.lineX = 0;
  11075. current.y = current.lineY = 0;
  11076. current.xcoords = [];
  11077. current.ycoords = [];
  11078. current.tspan = this.svgFactory.createElement("svg:tspan");
  11079. current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
  11080. current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
  11081. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  11082. current.txtElement = this.svgFactory.createElement("svg:text");
  11083. current.txtElement.appendChild(current.tspan);
  11084. }
  11085. beginText() {
  11086. const current = this.current;
  11087. current.x = current.lineX = 0;
  11088. current.y = current.lineY = 0;
  11089. current.textMatrix = _util.IDENTITY_MATRIX;
  11090. current.lineMatrix = _util.IDENTITY_MATRIX;
  11091. current.textMatrixScale = 1;
  11092. current.tspan = this.svgFactory.createElement("svg:tspan");
  11093. current.txtElement = this.svgFactory.createElement("svg:text");
  11094. current.txtgrp = this.svgFactory.createElement("svg:g");
  11095. current.xcoords = [];
  11096. current.ycoords = [];
  11097. }
  11098. moveText(x, y) {
  11099. const current = this.current;
  11100. current.x = current.lineX += x;
  11101. current.y = current.lineY += y;
  11102. current.xcoords = [];
  11103. current.ycoords = [];
  11104. current.tspan = this.svgFactory.createElement("svg:tspan");
  11105. current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
  11106. current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
  11107. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  11108. }
  11109. showText(glyphs) {
  11110. const current = this.current;
  11111. const font = current.font;
  11112. const fontSize = current.fontSize;
  11113. if (fontSize === 0) {
  11114. return;
  11115. }
  11116. const fontSizeScale = current.fontSizeScale;
  11117. const charSpacing = current.charSpacing;
  11118. const wordSpacing = current.wordSpacing;
  11119. const fontDirection = current.fontDirection;
  11120. const textHScale = current.textHScale * fontDirection;
  11121. const vertical = font.vertical;
  11122. const spacingDir = vertical ? 1 : -1;
  11123. const defaultVMetrics = font.defaultVMetrics;
  11124. const widthAdvanceScale = fontSize * current.fontMatrix[0];
  11125. let x = 0;
  11126. for (const glyph of glyphs) {
  11127. if (glyph === null) {
  11128. x += fontDirection * wordSpacing;
  11129. continue;
  11130. } else if (typeof glyph === "number") {
  11131. x += spacingDir * glyph * fontSize / 1000;
  11132. continue;
  11133. }
  11134. const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  11135. const character = glyph.fontChar;
  11136. let scaledX, scaledY;
  11137. let width = glyph.width;
  11138. if (vertical) {
  11139. let vx;
  11140. const vmetric = glyph.vmetric || defaultVMetrics;
  11141. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  11142. vx = -vx * widthAdvanceScale;
  11143. const vy = vmetric[2] * widthAdvanceScale;
  11144. width = vmetric ? -vmetric[0] : width;
  11145. scaledX = vx / fontSizeScale;
  11146. scaledY = (x + vy) / fontSizeScale;
  11147. } else {
  11148. scaledX = x / fontSizeScale;
  11149. scaledY = 0;
  11150. }
  11151. if (glyph.isInFont || font.missingFile) {
  11152. current.xcoords.push(current.x + scaledX);
  11153. if (vertical) {
  11154. current.ycoords.push(-current.y + scaledY);
  11155. }
  11156. current.tspan.textContent += character;
  11157. } else {}
  11158. let charWidth;
  11159. if (vertical) {
  11160. charWidth = width * widthAdvanceScale - spacing * fontDirection;
  11161. } else {
  11162. charWidth = width * widthAdvanceScale + spacing * fontDirection;
  11163. }
  11164. x += charWidth;
  11165. }
  11166. current.tspan.setAttributeNS(null, "x", current.xcoords.map(pf).join(" "));
  11167. if (vertical) {
  11168. current.tspan.setAttributeNS(null, "y", current.ycoords.map(pf).join(" "));
  11169. } else {
  11170. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  11171. }
  11172. if (vertical) {
  11173. current.y -= x;
  11174. } else {
  11175. current.x += x * textHScale;
  11176. }
  11177. current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
  11178. current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
  11179. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  11180. current.tspan.setAttributeNS(null, "font-style", current.fontStyle);
  11181. }
  11182. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  11183. current.tspan.setAttributeNS(null, "font-weight", current.fontWeight);
  11184. }
  11185. const fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  11186. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  11187. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  11188. current.tspan.setAttributeNS(null, "fill", current.fillColor);
  11189. }
  11190. if (current.fillAlpha < 1) {
  11191. current.tspan.setAttributeNS(null, "fill-opacity", current.fillAlpha);
  11192. }
  11193. } else if (current.textRenderingMode === _util.TextRenderingMode.ADD_TO_PATH) {
  11194. current.tspan.setAttributeNS(null, "fill", "transparent");
  11195. } else {
  11196. current.tspan.setAttributeNS(null, "fill", "none");
  11197. }
  11198. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  11199. const lineWidthScale = 1 / (current.textMatrixScale || 1);
  11200. this._setStrokeAttributes(current.tspan, lineWidthScale);
  11201. }
  11202. let textMatrix = current.textMatrix;
  11203. if (current.textRise !== 0) {
  11204. textMatrix = textMatrix.slice();
  11205. textMatrix[5] += current.textRise;
  11206. }
  11207. current.txtElement.setAttributeNS(null, "transform", `${pm(textMatrix)} scale(${pf(textHScale)}, -1)`);
  11208. current.txtElement.setAttributeNS(XML_NS, "xml:space", "preserve");
  11209. current.txtElement.appendChild(current.tspan);
  11210. current.txtgrp.appendChild(current.txtElement);
  11211. this._ensureTransformGroup().appendChild(current.txtElement);
  11212. }
  11213. setLeadingMoveText(x, y) {
  11214. this.setLeading(-y);
  11215. this.moveText(x, y);
  11216. }
  11217. addFontStyle(fontObj) {
  11218. if (!fontObj.data) {
  11219. throw new Error("addFontStyle: No font data available, " + 'ensure that the "fontExtraProperties" API parameter is set.');
  11220. }
  11221. if (!this.cssStyle) {
  11222. this.cssStyle = this.svgFactory.createElement("svg:style");
  11223. this.cssStyle.setAttributeNS(null, "type", "text/css");
  11224. this.defs.appendChild(this.cssStyle);
  11225. }
  11226. const url = createObjectURL(fontObj.data, fontObj.mimetype, this.forceDataSchema);
  11227. this.cssStyle.textContent += `@font-face { font-family: "${fontObj.loadedName}";` + ` src: url(${url}); }\n`;
  11228. }
  11229. setFont(details) {
  11230. const current = this.current;
  11231. const fontObj = this.commonObjs.get(details[0]);
  11232. let size = details[1];
  11233. current.font = fontObj;
  11234. if (this.embedFonts && !fontObj.missingFile && !this.embeddedFonts[fontObj.loadedName]) {
  11235. this.addFontStyle(fontObj);
  11236. this.embeddedFonts[fontObj.loadedName] = fontObj;
  11237. }
  11238. current.fontMatrix = fontObj.fontMatrix || _util.FONT_IDENTITY_MATRIX;
  11239. let bold = "normal";
  11240. if (fontObj.black) {
  11241. bold = "900";
  11242. } else if (fontObj.bold) {
  11243. bold = "bold";
  11244. }
  11245. const italic = fontObj.italic ? "italic" : "normal";
  11246. if (size < 0) {
  11247. size = -size;
  11248. current.fontDirection = -1;
  11249. } else {
  11250. current.fontDirection = 1;
  11251. }
  11252. current.fontSize = size;
  11253. current.fontFamily = fontObj.loadedName;
  11254. current.fontWeight = bold;
  11255. current.fontStyle = italic;
  11256. current.tspan = this.svgFactory.createElement("svg:tspan");
  11257. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  11258. current.xcoords = [];
  11259. current.ycoords = [];
  11260. }
  11261. endText() {
  11262. const current = this.current;
  11263. if (current.textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG && current.txtElement?.hasChildNodes()) {
  11264. current.element = current.txtElement;
  11265. this.clip("nonzero");
  11266. this.endPath();
  11267. }
  11268. }
  11269. setLineWidth(width) {
  11270. if (width > 0) {
  11271. this.current.lineWidth = width;
  11272. }
  11273. }
  11274. setLineCap(style) {
  11275. this.current.lineCap = LINE_CAP_STYLES[style];
  11276. }
  11277. setLineJoin(style) {
  11278. this.current.lineJoin = LINE_JOIN_STYLES[style];
  11279. }
  11280. setMiterLimit(limit) {
  11281. this.current.miterLimit = limit;
  11282. }
  11283. setStrokeAlpha(strokeAlpha) {
  11284. this.current.strokeAlpha = strokeAlpha;
  11285. }
  11286. setStrokeRGBColor(r, g, b) {
  11287. this.current.strokeColor = _util.Util.makeHexColor(r, g, b);
  11288. }
  11289. setFillAlpha(fillAlpha) {
  11290. this.current.fillAlpha = fillAlpha;
  11291. }
  11292. setFillRGBColor(r, g, b) {
  11293. this.current.fillColor = _util.Util.makeHexColor(r, g, b);
  11294. this.current.tspan = this.svgFactory.createElement("svg:tspan");
  11295. this.current.xcoords = [];
  11296. this.current.ycoords = [];
  11297. }
  11298. setStrokeColorN(args) {
  11299. this.current.strokeColor = this._makeColorN_Pattern(args);
  11300. }
  11301. setFillColorN(args) {
  11302. this.current.fillColor = this._makeColorN_Pattern(args);
  11303. }
  11304. shadingFill(args) {
  11305. const width = this.viewport.width;
  11306. const height = this.viewport.height;
  11307. const inv = _util.Util.inverseTransform(this.transformMatrix);
  11308. const bl = _util.Util.applyTransform([0, 0], inv);
  11309. const br = _util.Util.applyTransform([0, height], inv);
  11310. const ul = _util.Util.applyTransform([width, 0], inv);
  11311. const ur = _util.Util.applyTransform([width, height], inv);
  11312. const x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  11313. const y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  11314. const x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  11315. const y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  11316. const rect = this.svgFactory.createElement("svg:rect");
  11317. rect.setAttributeNS(null, "x", x0);
  11318. rect.setAttributeNS(null, "y", y0);
  11319. rect.setAttributeNS(null, "width", x1 - x0);
  11320. rect.setAttributeNS(null, "height", y1 - y0);
  11321. rect.setAttributeNS(null, "fill", this._makeShadingPattern(args));
  11322. if (this.current.fillAlpha < 1) {
  11323. rect.setAttributeNS(null, "fill-opacity", this.current.fillAlpha);
  11324. }
  11325. this._ensureTransformGroup().appendChild(rect);
  11326. }
  11327. _makeColorN_Pattern(args) {
  11328. if (args[0] === "TilingPattern") {
  11329. return this._makeTilingPattern(args);
  11330. }
  11331. return this._makeShadingPattern(args);
  11332. }
  11333. _makeTilingPattern(args) {
  11334. const color = args[1];
  11335. const operatorList = args[2];
  11336. const matrix = args[3] || _util.IDENTITY_MATRIX;
  11337. const [x0, y0, x1, y1] = args[4];
  11338. const xstep = args[5];
  11339. const ystep = args[6];
  11340. const paintType = args[7];
  11341. const tilingId = `shading${shadingCount++}`;
  11342. const [tx0, ty0, tx1, ty1] = _util.Util.normalizeRect([..._util.Util.applyTransform([x0, y0], matrix), ..._util.Util.applyTransform([x1, y1], matrix)]);
  11343. const [xscale, yscale] = _util.Util.singularValueDecompose2dScale(matrix);
  11344. const txstep = xstep * xscale;
  11345. const tystep = ystep * yscale;
  11346. const tiling = this.svgFactory.createElement("svg:pattern");
  11347. tiling.setAttributeNS(null, "id", tilingId);
  11348. tiling.setAttributeNS(null, "patternUnits", "userSpaceOnUse");
  11349. tiling.setAttributeNS(null, "width", txstep);
  11350. tiling.setAttributeNS(null, "height", tystep);
  11351. tiling.setAttributeNS(null, "x", `${tx0}`);
  11352. tiling.setAttributeNS(null, "y", `${ty0}`);
  11353. const svg = this.svg;
  11354. const transformMatrix = this.transformMatrix;
  11355. const fillColor = this.current.fillColor;
  11356. const strokeColor = this.current.strokeColor;
  11357. const bbox = this.svgFactory.create(tx1 - tx0, ty1 - ty0);
  11358. this.svg = bbox;
  11359. this.transformMatrix = matrix;
  11360. if (paintType === 2) {
  11361. const cssColor = _util.Util.makeHexColor(...color);
  11362. this.current.fillColor = cssColor;
  11363. this.current.strokeColor = cssColor;
  11364. }
  11365. this.executeOpTree(this.convertOpList(operatorList));
  11366. this.svg = svg;
  11367. this.transformMatrix = transformMatrix;
  11368. this.current.fillColor = fillColor;
  11369. this.current.strokeColor = strokeColor;
  11370. tiling.appendChild(bbox.childNodes[0]);
  11371. this.defs.appendChild(tiling);
  11372. return `url(#${tilingId})`;
  11373. }
  11374. _makeShadingPattern(args) {
  11375. if (typeof args === "string") {
  11376. args = this.objs.get(args);
  11377. }
  11378. switch (args[0]) {
  11379. case "RadialAxial":
  11380. const shadingId = `shading${shadingCount++}`;
  11381. const colorStops = args[3];
  11382. let gradient;
  11383. switch (args[1]) {
  11384. case "axial":
  11385. const point0 = args[4];
  11386. const point1 = args[5];
  11387. gradient = this.svgFactory.createElement("svg:linearGradient");
  11388. gradient.setAttributeNS(null, "id", shadingId);
  11389. gradient.setAttributeNS(null, "gradientUnits", "userSpaceOnUse");
  11390. gradient.setAttributeNS(null, "x1", point0[0]);
  11391. gradient.setAttributeNS(null, "y1", point0[1]);
  11392. gradient.setAttributeNS(null, "x2", point1[0]);
  11393. gradient.setAttributeNS(null, "y2", point1[1]);
  11394. break;
  11395. case "radial":
  11396. const focalPoint = args[4];
  11397. const circlePoint = args[5];
  11398. const focalRadius = args[6];
  11399. const circleRadius = args[7];
  11400. gradient = this.svgFactory.createElement("svg:radialGradient");
  11401. gradient.setAttributeNS(null, "id", shadingId);
  11402. gradient.setAttributeNS(null, "gradientUnits", "userSpaceOnUse");
  11403. gradient.setAttributeNS(null, "cx", circlePoint[0]);
  11404. gradient.setAttributeNS(null, "cy", circlePoint[1]);
  11405. gradient.setAttributeNS(null, "r", circleRadius);
  11406. gradient.setAttributeNS(null, "fx", focalPoint[0]);
  11407. gradient.setAttributeNS(null, "fy", focalPoint[1]);
  11408. gradient.setAttributeNS(null, "fr", focalRadius);
  11409. break;
  11410. default:
  11411. throw new Error(`Unknown RadialAxial type: ${args[1]}`);
  11412. }
  11413. for (const colorStop of colorStops) {
  11414. const stop = this.svgFactory.createElement("svg:stop");
  11415. stop.setAttributeNS(null, "offset", colorStop[0]);
  11416. stop.setAttributeNS(null, "stop-color", colorStop[1]);
  11417. gradient.appendChild(stop);
  11418. }
  11419. this.defs.appendChild(gradient);
  11420. return `url(#${shadingId})`;
  11421. case "Mesh":
  11422. (0, _util.warn)("Unimplemented pattern Mesh");
  11423. return null;
  11424. case "Dummy":
  11425. return "hotpink";
  11426. default:
  11427. throw new Error(`Unknown IR type: ${args[0]}`);
  11428. }
  11429. }
  11430. setDash(dashArray, dashPhase) {
  11431. this.current.dashArray = dashArray;
  11432. this.current.dashPhase = dashPhase;
  11433. }
  11434. constructPath(ops, args) {
  11435. const current = this.current;
  11436. let x = current.x,
  11437. y = current.y;
  11438. let d = [];
  11439. let j = 0;
  11440. for (const op of ops) {
  11441. switch (op | 0) {
  11442. case _util.OPS.rectangle:
  11443. x = args[j++];
  11444. y = args[j++];
  11445. const width = args[j++];
  11446. const height = args[j++];
  11447. const xw = x + width;
  11448. const yh = y + height;
  11449. d.push("M", pf(x), pf(y), "L", pf(xw), pf(y), "L", pf(xw), pf(yh), "L", pf(x), pf(yh), "Z");
  11450. break;
  11451. case _util.OPS.moveTo:
  11452. x = args[j++];
  11453. y = args[j++];
  11454. d.push("M", pf(x), pf(y));
  11455. break;
  11456. case _util.OPS.lineTo:
  11457. x = args[j++];
  11458. y = args[j++];
  11459. d.push("L", pf(x), pf(y));
  11460. break;
  11461. case _util.OPS.curveTo:
  11462. x = args[j + 4];
  11463. y = args[j + 5];
  11464. d.push("C", pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]), pf(x), pf(y));
  11465. j += 6;
  11466. break;
  11467. case _util.OPS.curveTo2:
  11468. d.push("C", pf(x), pf(y), pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]));
  11469. x = args[j + 2];
  11470. y = args[j + 3];
  11471. j += 4;
  11472. break;
  11473. case _util.OPS.curveTo3:
  11474. x = args[j + 2];
  11475. y = args[j + 3];
  11476. d.push("C", pf(args[j]), pf(args[j + 1]), pf(x), pf(y), pf(x), pf(y));
  11477. j += 4;
  11478. break;
  11479. case _util.OPS.closePath:
  11480. d.push("Z");
  11481. break;
  11482. }
  11483. }
  11484. d = d.join(" ");
  11485. if (current.path && ops.length > 0 && ops[0] !== _util.OPS.rectangle && ops[0] !== _util.OPS.moveTo) {
  11486. d = current.path.getAttributeNS(null, "d") + d;
  11487. } else {
  11488. current.path = this.svgFactory.createElement("svg:path");
  11489. this._ensureTransformGroup().appendChild(current.path);
  11490. }
  11491. current.path.setAttributeNS(null, "d", d);
  11492. current.path.setAttributeNS(null, "fill", "none");
  11493. current.element = current.path;
  11494. current.setCurrentPoint(x, y);
  11495. }
  11496. endPath() {
  11497. const current = this.current;
  11498. current.path = null;
  11499. if (!this.pendingClip) {
  11500. return;
  11501. }
  11502. if (!current.element) {
  11503. this.pendingClip = null;
  11504. return;
  11505. }
  11506. const clipId = `clippath${clipCount++}`;
  11507. const clipPath = this.svgFactory.createElement("svg:clipPath");
  11508. clipPath.setAttributeNS(null, "id", clipId);
  11509. clipPath.setAttributeNS(null, "transform", pm(this.transformMatrix));
  11510. const clipElement = current.element.cloneNode(true);
  11511. if (this.pendingClip === "evenodd") {
  11512. clipElement.setAttributeNS(null, "clip-rule", "evenodd");
  11513. } else {
  11514. clipElement.setAttributeNS(null, "clip-rule", "nonzero");
  11515. }
  11516. this.pendingClip = null;
  11517. clipPath.appendChild(clipElement);
  11518. this.defs.appendChild(clipPath);
  11519. if (current.activeClipUrl) {
  11520. current.clipGroup = null;
  11521. for (const prev of this.extraStack) {
  11522. prev.clipGroup = null;
  11523. }
  11524. clipPath.setAttributeNS(null, "clip-path", current.activeClipUrl);
  11525. }
  11526. current.activeClipUrl = `url(#${clipId})`;
  11527. this.tgrp = null;
  11528. }
  11529. clip(type) {
  11530. this.pendingClip = type;
  11531. }
  11532. closePath() {
  11533. const current = this.current;
  11534. if (current.path) {
  11535. const d = `${current.path.getAttributeNS(null, "d")}Z`;
  11536. current.path.setAttributeNS(null, "d", d);
  11537. }
  11538. }
  11539. setLeading(leading) {
  11540. this.current.leading = -leading;
  11541. }
  11542. setTextRise(textRise) {
  11543. this.current.textRise = textRise;
  11544. }
  11545. setTextRenderingMode(textRenderingMode) {
  11546. this.current.textRenderingMode = textRenderingMode;
  11547. }
  11548. setHScale(scale) {
  11549. this.current.textHScale = scale / 100;
  11550. }
  11551. setRenderingIntent(intent) {}
  11552. setFlatness(flatness) {}
  11553. setGState(states) {
  11554. for (const [key, value] of states) {
  11555. switch (key) {
  11556. case "LW":
  11557. this.setLineWidth(value);
  11558. break;
  11559. case "LC":
  11560. this.setLineCap(value);
  11561. break;
  11562. case "LJ":
  11563. this.setLineJoin(value);
  11564. break;
  11565. case "ML":
  11566. this.setMiterLimit(value);
  11567. break;
  11568. case "D":
  11569. this.setDash(value[0], value[1]);
  11570. break;
  11571. case "RI":
  11572. this.setRenderingIntent(value);
  11573. break;
  11574. case "FL":
  11575. this.setFlatness(value);
  11576. break;
  11577. case "Font":
  11578. this.setFont(value);
  11579. break;
  11580. case "CA":
  11581. this.setStrokeAlpha(value);
  11582. break;
  11583. case "ca":
  11584. this.setFillAlpha(value);
  11585. break;
  11586. default:
  11587. (0, _util.warn)(`Unimplemented graphic state operator ${key}`);
  11588. break;
  11589. }
  11590. }
  11591. }
  11592. fill() {
  11593. const current = this.current;
  11594. if (current.element) {
  11595. current.element.setAttributeNS(null, "fill", current.fillColor);
  11596. current.element.setAttributeNS(null, "fill-opacity", current.fillAlpha);
  11597. this.endPath();
  11598. }
  11599. }
  11600. stroke() {
  11601. const current = this.current;
  11602. if (current.element) {
  11603. this._setStrokeAttributes(current.element);
  11604. current.element.setAttributeNS(null, "fill", "none");
  11605. this.endPath();
  11606. }
  11607. }
  11608. _setStrokeAttributes(element, lineWidthScale = 1) {
  11609. const current = this.current;
  11610. let dashArray = current.dashArray;
  11611. if (lineWidthScale !== 1 && dashArray.length > 0) {
  11612. dashArray = dashArray.map(function (value) {
  11613. return lineWidthScale * value;
  11614. });
  11615. }
  11616. element.setAttributeNS(null, "stroke", current.strokeColor);
  11617. element.setAttributeNS(null, "stroke-opacity", current.strokeAlpha);
  11618. element.setAttributeNS(null, "stroke-miterlimit", pf(current.miterLimit));
  11619. element.setAttributeNS(null, "stroke-linecap", current.lineCap);
  11620. element.setAttributeNS(null, "stroke-linejoin", current.lineJoin);
  11621. element.setAttributeNS(null, "stroke-width", pf(lineWidthScale * current.lineWidth) + "px");
  11622. element.setAttributeNS(null, "stroke-dasharray", dashArray.map(pf).join(" "));
  11623. element.setAttributeNS(null, "stroke-dashoffset", pf(lineWidthScale * current.dashPhase) + "px");
  11624. }
  11625. eoFill() {
  11626. if (this.current.element) {
  11627. this.current.element.setAttributeNS(null, "fill-rule", "evenodd");
  11628. }
  11629. this.fill();
  11630. }
  11631. fillStroke() {
  11632. this.stroke();
  11633. this.fill();
  11634. }
  11635. eoFillStroke() {
  11636. if (this.current.element) {
  11637. this.current.element.setAttributeNS(null, "fill-rule", "evenodd");
  11638. }
  11639. this.fillStroke();
  11640. }
  11641. closeStroke() {
  11642. this.closePath();
  11643. this.stroke();
  11644. }
  11645. closeFillStroke() {
  11646. this.closePath();
  11647. this.fillStroke();
  11648. }
  11649. closeEOFillStroke() {
  11650. this.closePath();
  11651. this.eoFillStroke();
  11652. }
  11653. paintSolidColorImageMask() {
  11654. const rect = this.svgFactory.createElement("svg:rect");
  11655. rect.setAttributeNS(null, "x", "0");
  11656. rect.setAttributeNS(null, "y", "0");
  11657. rect.setAttributeNS(null, "width", "1px");
  11658. rect.setAttributeNS(null, "height", "1px");
  11659. rect.setAttributeNS(null, "fill", this.current.fillColor);
  11660. this._ensureTransformGroup().appendChild(rect);
  11661. }
  11662. paintImageXObject(objId) {
  11663. const imgData = objId.startsWith("g_") ? this.commonObjs.get(objId) : this.objs.get(objId);
  11664. if (!imgData) {
  11665. (0, _util.warn)(`Dependent image with object ID ${objId} is not ready yet`);
  11666. return;
  11667. }
  11668. this.paintInlineImageXObject(imgData);
  11669. }
  11670. paintInlineImageXObject(imgData, mask) {
  11671. const width = imgData.width;
  11672. const height = imgData.height;
  11673. const imgSrc = convertImgDataToPng(imgData, this.forceDataSchema, !!mask);
  11674. const cliprect = this.svgFactory.createElement("svg:rect");
  11675. cliprect.setAttributeNS(null, "x", "0");
  11676. cliprect.setAttributeNS(null, "y", "0");
  11677. cliprect.setAttributeNS(null, "width", pf(width));
  11678. cliprect.setAttributeNS(null, "height", pf(height));
  11679. this.current.element = cliprect;
  11680. this.clip("nonzero");
  11681. const imgEl = this.svgFactory.createElement("svg:image");
  11682. imgEl.setAttributeNS(XLINK_NS, "xlink:href", imgSrc);
  11683. imgEl.setAttributeNS(null, "x", "0");
  11684. imgEl.setAttributeNS(null, "y", pf(-height));
  11685. imgEl.setAttributeNS(null, "width", pf(width) + "px");
  11686. imgEl.setAttributeNS(null, "height", pf(height) + "px");
  11687. imgEl.setAttributeNS(null, "transform", `scale(${pf(1 / width)} ${pf(-1 / height)})`);
  11688. if (mask) {
  11689. mask.appendChild(imgEl);
  11690. } else {
  11691. this._ensureTransformGroup().appendChild(imgEl);
  11692. }
  11693. }
  11694. paintImageMaskXObject(imgData) {
  11695. const current = this.current;
  11696. const width = imgData.width;
  11697. const height = imgData.height;
  11698. const fillColor = current.fillColor;
  11699. current.maskId = `mask${maskCount++}`;
  11700. const mask = this.svgFactory.createElement("svg:mask");
  11701. mask.setAttributeNS(null, "id", current.maskId);
  11702. const rect = this.svgFactory.createElement("svg:rect");
  11703. rect.setAttributeNS(null, "x", "0");
  11704. rect.setAttributeNS(null, "y", "0");
  11705. rect.setAttributeNS(null, "width", pf(width));
  11706. rect.setAttributeNS(null, "height", pf(height));
  11707. rect.setAttributeNS(null, "fill", fillColor);
  11708. rect.setAttributeNS(null, "mask", `url(#${current.maskId})`);
  11709. this.defs.appendChild(mask);
  11710. this._ensureTransformGroup().appendChild(rect);
  11711. this.paintInlineImageXObject(imgData, mask);
  11712. }
  11713. paintFormXObjectBegin(matrix, bbox) {
  11714. if (Array.isArray(matrix) && matrix.length === 6) {
  11715. this.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
  11716. }
  11717. if (bbox) {
  11718. const width = bbox[2] - bbox[0];
  11719. const height = bbox[3] - bbox[1];
  11720. const cliprect = this.svgFactory.createElement("svg:rect");
  11721. cliprect.setAttributeNS(null, "x", bbox[0]);
  11722. cliprect.setAttributeNS(null, "y", bbox[1]);
  11723. cliprect.setAttributeNS(null, "width", pf(width));
  11724. cliprect.setAttributeNS(null, "height", pf(height));
  11725. this.current.element = cliprect;
  11726. this.clip("nonzero");
  11727. this.endPath();
  11728. }
  11729. }
  11730. paintFormXObjectEnd() {}
  11731. _initialize(viewport) {
  11732. const svg = this.svgFactory.create(viewport.width, viewport.height);
  11733. const definitions = this.svgFactory.createElement("svg:defs");
  11734. svg.appendChild(definitions);
  11735. this.defs = definitions;
  11736. const rootGroup = this.svgFactory.createElement("svg:g");
  11737. rootGroup.setAttributeNS(null, "transform", pm(viewport.transform));
  11738. svg.appendChild(rootGroup);
  11739. this.svg = rootGroup;
  11740. return svg;
  11741. }
  11742. _ensureClipGroup() {
  11743. if (!this.current.clipGroup) {
  11744. const clipGroup = this.svgFactory.createElement("svg:g");
  11745. clipGroup.setAttributeNS(null, "clip-path", this.current.activeClipUrl);
  11746. this.svg.appendChild(clipGroup);
  11747. this.current.clipGroup = clipGroup;
  11748. }
  11749. return this.current.clipGroup;
  11750. }
  11751. _ensureTransformGroup() {
  11752. if (!this.tgrp) {
  11753. this.tgrp = this.svgFactory.createElement("svg:g");
  11754. this.tgrp.setAttributeNS(null, "transform", pm(this.transformMatrix));
  11755. if (this.current.activeClipUrl) {
  11756. this._ensureClipGroup().appendChild(this.tgrp);
  11757. } else {
  11758. this.svg.appendChild(this.tgrp);
  11759. }
  11760. }
  11761. return this.tgrp;
  11762. }
  11763. };
  11764. }
  11765. /***/ }),
  11766. /* 25 */
  11767. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  11768. Object.defineProperty(exports, "__esModule", ({
  11769. value: true
  11770. }));
  11771. exports.PDFNodeStream = void 0;
  11772. var _util = __w_pdfjs_require__(1);
  11773. var _network_utils = __w_pdfjs_require__(26);
  11774. ;
  11775. const fs = require("fs");
  11776. const http = require("http");
  11777. const https = require("https");
  11778. const url = require("url");
  11779. const fileUriRegex = /^file:\/\/\/[a-zA-Z]:\//;
  11780. function parseUrl(sourceUrl) {
  11781. const parsedUrl = url.parse(sourceUrl);
  11782. if (parsedUrl.protocol === "file:" || parsedUrl.host) {
  11783. return parsedUrl;
  11784. }
  11785. if (/^[a-z]:[/\\]/i.test(sourceUrl)) {
  11786. return url.parse(`file:///${sourceUrl}`);
  11787. }
  11788. if (!parsedUrl.host) {
  11789. parsedUrl.protocol = "file:";
  11790. }
  11791. return parsedUrl;
  11792. }
  11793. class PDFNodeStream {
  11794. constructor(source) {
  11795. this.source = source;
  11796. this.url = parseUrl(source.url);
  11797. this.isHttp = this.url.protocol === "http:" || this.url.protocol === "https:";
  11798. this.isFsUrl = this.url.protocol === "file:";
  11799. this.httpHeaders = this.isHttp && source.httpHeaders || {};
  11800. this._fullRequestReader = null;
  11801. this._rangeRequestReaders = [];
  11802. }
  11803. get _progressiveDataLength() {
  11804. return this._fullRequestReader?._loaded ?? 0;
  11805. }
  11806. getFullReader() {
  11807. (0, _util.assert)(!this._fullRequestReader, "PDFNodeStream.getFullReader can only be called once.");
  11808. this._fullRequestReader = this.isFsUrl ? new PDFNodeStreamFsFullReader(this) : new PDFNodeStreamFullReader(this);
  11809. return this._fullRequestReader;
  11810. }
  11811. getRangeReader(start, end) {
  11812. if (end <= this._progressiveDataLength) {
  11813. return null;
  11814. }
  11815. const rangeReader = this.isFsUrl ? new PDFNodeStreamFsRangeReader(this, start, end) : new PDFNodeStreamRangeReader(this, start, end);
  11816. this._rangeRequestReaders.push(rangeReader);
  11817. return rangeReader;
  11818. }
  11819. cancelAllRequests(reason) {
  11820. if (this._fullRequestReader) {
  11821. this._fullRequestReader.cancel(reason);
  11822. }
  11823. for (const reader of this._rangeRequestReaders.slice(0)) {
  11824. reader.cancel(reason);
  11825. }
  11826. }
  11827. }
  11828. exports.PDFNodeStream = PDFNodeStream;
  11829. class BaseFullReader {
  11830. constructor(stream) {
  11831. this._url = stream.url;
  11832. this._done = false;
  11833. this._storedError = null;
  11834. this.onProgress = null;
  11835. const source = stream.source;
  11836. this._contentLength = source.length;
  11837. this._loaded = 0;
  11838. this._filename = null;
  11839. this._disableRange = source.disableRange || false;
  11840. this._rangeChunkSize = source.rangeChunkSize;
  11841. if (!this._rangeChunkSize && !this._disableRange) {
  11842. this._disableRange = true;
  11843. }
  11844. this._isStreamingSupported = !source.disableStream;
  11845. this._isRangeSupported = !source.disableRange;
  11846. this._readableStream = null;
  11847. this._readCapability = (0, _util.createPromiseCapability)();
  11848. this._headersCapability = (0, _util.createPromiseCapability)();
  11849. }
  11850. get headersReady() {
  11851. return this._headersCapability.promise;
  11852. }
  11853. get filename() {
  11854. return this._filename;
  11855. }
  11856. get contentLength() {
  11857. return this._contentLength;
  11858. }
  11859. get isRangeSupported() {
  11860. return this._isRangeSupported;
  11861. }
  11862. get isStreamingSupported() {
  11863. return this._isStreamingSupported;
  11864. }
  11865. async read() {
  11866. await this._readCapability.promise;
  11867. if (this._done) {
  11868. return {
  11869. value: undefined,
  11870. done: true
  11871. };
  11872. }
  11873. if (this._storedError) {
  11874. throw this._storedError;
  11875. }
  11876. const chunk = this._readableStream.read();
  11877. if (chunk === null) {
  11878. this._readCapability = (0, _util.createPromiseCapability)();
  11879. return this.read();
  11880. }
  11881. this._loaded += chunk.length;
  11882. if (this.onProgress) {
  11883. this.onProgress({
  11884. loaded: this._loaded,
  11885. total: this._contentLength
  11886. });
  11887. }
  11888. const buffer = new Uint8Array(chunk).buffer;
  11889. return {
  11890. value: buffer,
  11891. done: false
  11892. };
  11893. }
  11894. cancel(reason) {
  11895. if (!this._readableStream) {
  11896. this._error(reason);
  11897. return;
  11898. }
  11899. this._readableStream.destroy(reason);
  11900. }
  11901. _error(reason) {
  11902. this._storedError = reason;
  11903. this._readCapability.resolve();
  11904. }
  11905. _setReadableStream(readableStream) {
  11906. this._readableStream = readableStream;
  11907. readableStream.on("readable", () => {
  11908. this._readCapability.resolve();
  11909. });
  11910. readableStream.on("end", () => {
  11911. readableStream.destroy();
  11912. this._done = true;
  11913. this._readCapability.resolve();
  11914. });
  11915. readableStream.on("error", reason => {
  11916. this._error(reason);
  11917. });
  11918. if (!this._isStreamingSupported && this._isRangeSupported) {
  11919. this._error(new _util.AbortException("streaming is disabled"));
  11920. }
  11921. if (this._storedError) {
  11922. this._readableStream.destroy(this._storedError);
  11923. }
  11924. }
  11925. }
  11926. class BaseRangeReader {
  11927. constructor(stream) {
  11928. this._url = stream.url;
  11929. this._done = false;
  11930. this._storedError = null;
  11931. this.onProgress = null;
  11932. this._loaded = 0;
  11933. this._readableStream = null;
  11934. this._readCapability = (0, _util.createPromiseCapability)();
  11935. const source = stream.source;
  11936. this._isStreamingSupported = !source.disableStream;
  11937. }
  11938. get isStreamingSupported() {
  11939. return this._isStreamingSupported;
  11940. }
  11941. async read() {
  11942. await this._readCapability.promise;
  11943. if (this._done) {
  11944. return {
  11945. value: undefined,
  11946. done: true
  11947. };
  11948. }
  11949. if (this._storedError) {
  11950. throw this._storedError;
  11951. }
  11952. const chunk = this._readableStream.read();
  11953. if (chunk === null) {
  11954. this._readCapability = (0, _util.createPromiseCapability)();
  11955. return this.read();
  11956. }
  11957. this._loaded += chunk.length;
  11958. if (this.onProgress) {
  11959. this.onProgress({
  11960. loaded: this._loaded
  11961. });
  11962. }
  11963. const buffer = new Uint8Array(chunk).buffer;
  11964. return {
  11965. value: buffer,
  11966. done: false
  11967. };
  11968. }
  11969. cancel(reason) {
  11970. if (!this._readableStream) {
  11971. this._error(reason);
  11972. return;
  11973. }
  11974. this._readableStream.destroy(reason);
  11975. }
  11976. _error(reason) {
  11977. this._storedError = reason;
  11978. this._readCapability.resolve();
  11979. }
  11980. _setReadableStream(readableStream) {
  11981. this._readableStream = readableStream;
  11982. readableStream.on("readable", () => {
  11983. this._readCapability.resolve();
  11984. });
  11985. readableStream.on("end", () => {
  11986. readableStream.destroy();
  11987. this._done = true;
  11988. this._readCapability.resolve();
  11989. });
  11990. readableStream.on("error", reason => {
  11991. this._error(reason);
  11992. });
  11993. if (this._storedError) {
  11994. this._readableStream.destroy(this._storedError);
  11995. }
  11996. }
  11997. }
  11998. function createRequestOptions(parsedUrl, headers) {
  11999. return {
  12000. protocol: parsedUrl.protocol,
  12001. auth: parsedUrl.auth,
  12002. host: parsedUrl.hostname,
  12003. port: parsedUrl.port,
  12004. path: parsedUrl.path,
  12005. method: "GET",
  12006. headers
  12007. };
  12008. }
  12009. class PDFNodeStreamFullReader extends BaseFullReader {
  12010. constructor(stream) {
  12011. super(stream);
  12012. const handleResponse = response => {
  12013. if (response.statusCode === 404) {
  12014. const error = new _util.MissingPDFException(`Missing PDF "${this._url}".`);
  12015. this._storedError = error;
  12016. this._headersCapability.reject(error);
  12017. return;
  12018. }
  12019. this._headersCapability.resolve();
  12020. this._setReadableStream(response);
  12021. const getResponseHeader = name => {
  12022. return this._readableStream.headers[name.toLowerCase()];
  12023. };
  12024. const {
  12025. allowRangeRequests,
  12026. suggestedLength
  12027. } = (0, _network_utils.validateRangeRequestCapabilities)({
  12028. getResponseHeader,
  12029. isHttp: stream.isHttp,
  12030. rangeChunkSize: this._rangeChunkSize,
  12031. disableRange: this._disableRange
  12032. });
  12033. this._isRangeSupported = allowRangeRequests;
  12034. this._contentLength = suggestedLength || this._contentLength;
  12035. this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
  12036. };
  12037. this._request = null;
  12038. if (this._url.protocol === "http:") {
  12039. this._request = http.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
  12040. } else {
  12041. this._request = https.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
  12042. }
  12043. this._request.on("error", reason => {
  12044. this._storedError = reason;
  12045. this._headersCapability.reject(reason);
  12046. });
  12047. this._request.end();
  12048. }
  12049. }
  12050. class PDFNodeStreamRangeReader extends BaseRangeReader {
  12051. constructor(stream, start, end) {
  12052. super(stream);
  12053. this._httpHeaders = {};
  12054. for (const property in stream.httpHeaders) {
  12055. const value = stream.httpHeaders[property];
  12056. if (typeof value === "undefined") {
  12057. continue;
  12058. }
  12059. this._httpHeaders[property] = value;
  12060. }
  12061. this._httpHeaders.Range = `bytes=${start}-${end - 1}`;
  12062. const handleResponse = response => {
  12063. if (response.statusCode === 404) {
  12064. const error = new _util.MissingPDFException(`Missing PDF "${this._url}".`);
  12065. this._storedError = error;
  12066. return;
  12067. }
  12068. this._setReadableStream(response);
  12069. };
  12070. this._request = null;
  12071. if (this._url.protocol === "http:") {
  12072. this._request = http.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
  12073. } else {
  12074. this._request = https.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
  12075. }
  12076. this._request.on("error", reason => {
  12077. this._storedError = reason;
  12078. });
  12079. this._request.end();
  12080. }
  12081. }
  12082. class PDFNodeStreamFsFullReader extends BaseFullReader {
  12083. constructor(stream) {
  12084. super(stream);
  12085. let path = decodeURIComponent(this._url.path);
  12086. if (fileUriRegex.test(this._url.href)) {
  12087. path = path.replace(/^\//, "");
  12088. }
  12089. fs.lstat(path, (error, stat) => {
  12090. if (error) {
  12091. if (error.code === "ENOENT") {
  12092. error = new _util.MissingPDFException(`Missing PDF "${path}".`);
  12093. }
  12094. this._storedError = error;
  12095. this._headersCapability.reject(error);
  12096. return;
  12097. }
  12098. this._contentLength = stat.size;
  12099. this._setReadableStream(fs.createReadStream(path));
  12100. this._headersCapability.resolve();
  12101. });
  12102. }
  12103. }
  12104. class PDFNodeStreamFsRangeReader extends BaseRangeReader {
  12105. constructor(stream, start, end) {
  12106. super(stream);
  12107. let path = decodeURIComponent(this._url.path);
  12108. if (fileUriRegex.test(this._url.href)) {
  12109. path = path.replace(/^\//, "");
  12110. }
  12111. this._setReadableStream(fs.createReadStream(path, {
  12112. start,
  12113. end: end - 1
  12114. }));
  12115. }
  12116. }
  12117. /***/ }),
  12118. /* 26 */
  12119. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  12120. Object.defineProperty(exports, "__esModule", ({
  12121. value: true
  12122. }));
  12123. exports.createResponseStatusError = createResponseStatusError;
  12124. exports.extractFilenameFromHeader = extractFilenameFromHeader;
  12125. exports.validateRangeRequestCapabilities = validateRangeRequestCapabilities;
  12126. exports.validateResponseStatus = validateResponseStatus;
  12127. var _util = __w_pdfjs_require__(1);
  12128. var _content_disposition = __w_pdfjs_require__(27);
  12129. var _display_utils = __w_pdfjs_require__(5);
  12130. function validateRangeRequestCapabilities({
  12131. getResponseHeader,
  12132. isHttp,
  12133. rangeChunkSize,
  12134. disableRange
  12135. }) {
  12136. const returnValues = {
  12137. allowRangeRequests: false,
  12138. suggestedLength: undefined
  12139. };
  12140. const length = parseInt(getResponseHeader("Content-Length"), 10);
  12141. if (!Number.isInteger(length)) {
  12142. return returnValues;
  12143. }
  12144. returnValues.suggestedLength = length;
  12145. if (length <= 2 * rangeChunkSize) {
  12146. return returnValues;
  12147. }
  12148. if (disableRange || !isHttp) {
  12149. return returnValues;
  12150. }
  12151. if (getResponseHeader("Accept-Ranges") !== "bytes") {
  12152. return returnValues;
  12153. }
  12154. const contentEncoding = getResponseHeader("Content-Encoding") || "identity";
  12155. if (contentEncoding !== "identity") {
  12156. return returnValues;
  12157. }
  12158. returnValues.allowRangeRequests = true;
  12159. return returnValues;
  12160. }
  12161. function extractFilenameFromHeader(getResponseHeader) {
  12162. const contentDisposition = getResponseHeader("Content-Disposition");
  12163. if (contentDisposition) {
  12164. let filename = (0, _content_disposition.getFilenameFromContentDispositionHeader)(contentDisposition);
  12165. if (filename.includes("%")) {
  12166. try {
  12167. filename = decodeURIComponent(filename);
  12168. } catch (ex) {}
  12169. }
  12170. if ((0, _display_utils.isPdfFile)(filename)) {
  12171. return filename;
  12172. }
  12173. }
  12174. return null;
  12175. }
  12176. function createResponseStatusError(status, url) {
  12177. if (status === 404 || status === 0 && url.startsWith("file:")) {
  12178. return new _util.MissingPDFException('Missing PDF "' + url + '".');
  12179. }
  12180. return new _util.UnexpectedResponseException(`Unexpected server response (${status}) while retrieving PDF "${url}".`, status);
  12181. }
  12182. function validateResponseStatus(status) {
  12183. return status === 200 || status === 206;
  12184. }
  12185. /***/ }),
  12186. /* 27 */
  12187. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  12188. Object.defineProperty(exports, "__esModule", ({
  12189. value: true
  12190. }));
  12191. exports.getFilenameFromContentDispositionHeader = getFilenameFromContentDispositionHeader;
  12192. var _util = __w_pdfjs_require__(1);
  12193. function getFilenameFromContentDispositionHeader(contentDisposition) {
  12194. let needsEncodingFixup = true;
  12195. let tmp = toParamRegExp("filename\\*", "i").exec(contentDisposition);
  12196. if (tmp) {
  12197. tmp = tmp[1];
  12198. let filename = rfc2616unquote(tmp);
  12199. filename = unescape(filename);
  12200. filename = rfc5987decode(filename);
  12201. filename = rfc2047decode(filename);
  12202. return fixupEncoding(filename);
  12203. }
  12204. tmp = rfc2231getparam(contentDisposition);
  12205. if (tmp) {
  12206. const filename = rfc2047decode(tmp);
  12207. return fixupEncoding(filename);
  12208. }
  12209. tmp = toParamRegExp("filename", "i").exec(contentDisposition);
  12210. if (tmp) {
  12211. tmp = tmp[1];
  12212. let filename = rfc2616unquote(tmp);
  12213. filename = rfc2047decode(filename);
  12214. return fixupEncoding(filename);
  12215. }
  12216. function toParamRegExp(attributePattern, flags) {
  12217. return new RegExp("(?:^|;)\\s*" + attributePattern + "\\s*=\\s*" + "(" + '[^";\\s][^;\\s]*' + "|" + '"(?:[^"\\\\]|\\\\"?)+"?' + ")", flags);
  12218. }
  12219. function textdecode(encoding, value) {
  12220. if (encoding) {
  12221. if (!/^[\x00-\xFF]+$/.test(value)) {
  12222. return value;
  12223. }
  12224. try {
  12225. const decoder = new TextDecoder(encoding, {
  12226. fatal: true
  12227. });
  12228. const buffer = (0, _util.stringToBytes)(value);
  12229. value = decoder.decode(buffer);
  12230. needsEncodingFixup = false;
  12231. } catch (e) {}
  12232. }
  12233. return value;
  12234. }
  12235. function fixupEncoding(value) {
  12236. if (needsEncodingFixup && /[\x80-\xff]/.test(value)) {
  12237. value = textdecode("utf-8", value);
  12238. if (needsEncodingFixup) {
  12239. value = textdecode("iso-8859-1", value);
  12240. }
  12241. }
  12242. return value;
  12243. }
  12244. function rfc2231getparam(contentDispositionStr) {
  12245. const matches = [];
  12246. let match;
  12247. const iter = toParamRegExp("filename\\*((?!0\\d)\\d+)(\\*?)", "ig");
  12248. while ((match = iter.exec(contentDispositionStr)) !== null) {
  12249. let [, n, quot, part] = match;
  12250. n = parseInt(n, 10);
  12251. if (n in matches) {
  12252. if (n === 0) {
  12253. break;
  12254. }
  12255. continue;
  12256. }
  12257. matches[n] = [quot, part];
  12258. }
  12259. const parts = [];
  12260. for (let n = 0; n < matches.length; ++n) {
  12261. if (!(n in matches)) {
  12262. break;
  12263. }
  12264. let [quot, part] = matches[n];
  12265. part = rfc2616unquote(part);
  12266. if (quot) {
  12267. part = unescape(part);
  12268. if (n === 0) {
  12269. part = rfc5987decode(part);
  12270. }
  12271. }
  12272. parts.push(part);
  12273. }
  12274. return parts.join("");
  12275. }
  12276. function rfc2616unquote(value) {
  12277. if (value.startsWith('"')) {
  12278. const parts = value.slice(1).split('\\"');
  12279. for (let i = 0; i < parts.length; ++i) {
  12280. const quotindex = parts[i].indexOf('"');
  12281. if (quotindex !== -1) {
  12282. parts[i] = parts[i].slice(0, quotindex);
  12283. parts.length = i + 1;
  12284. }
  12285. parts[i] = parts[i].replace(/\\(.)/g, "$1");
  12286. }
  12287. value = parts.join('"');
  12288. }
  12289. return value;
  12290. }
  12291. function rfc5987decode(extvalue) {
  12292. const encodingend = extvalue.indexOf("'");
  12293. if (encodingend === -1) {
  12294. return extvalue;
  12295. }
  12296. const encoding = extvalue.slice(0, encodingend);
  12297. const langvalue = extvalue.slice(encodingend + 1);
  12298. const value = langvalue.replace(/^[^']*'/, "");
  12299. return textdecode(encoding, value);
  12300. }
  12301. function rfc2047decode(value) {
  12302. if (!value.startsWith("=?") || /[\x00-\x19\x80-\xff]/.test(value)) {
  12303. return value;
  12304. }
  12305. return value.replace(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g, function (matches, charset, encoding, text) {
  12306. if (encoding === "q" || encoding === "Q") {
  12307. text = text.replace(/_/g, " ");
  12308. text = text.replace(/=([0-9a-fA-F]{2})/g, function (match, hex) {
  12309. return String.fromCharCode(parseInt(hex, 16));
  12310. });
  12311. return textdecode(charset, text);
  12312. }
  12313. try {
  12314. text = atob(text);
  12315. } catch (e) {}
  12316. return textdecode(charset, text);
  12317. });
  12318. }
  12319. return "";
  12320. }
  12321. /***/ }),
  12322. /* 28 */
  12323. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  12324. Object.defineProperty(exports, "__esModule", ({
  12325. value: true
  12326. }));
  12327. exports.PDFNetworkStream = void 0;
  12328. var _util = __w_pdfjs_require__(1);
  12329. var _network_utils = __w_pdfjs_require__(26);
  12330. ;
  12331. const OK_RESPONSE = 200;
  12332. const PARTIAL_CONTENT_RESPONSE = 206;
  12333. function getArrayBuffer(xhr) {
  12334. const data = xhr.response;
  12335. if (typeof data !== "string") {
  12336. return data;
  12337. }
  12338. const array = (0, _util.stringToBytes)(data);
  12339. return array.buffer;
  12340. }
  12341. class NetworkManager {
  12342. constructor(url, args = {}) {
  12343. this.url = url;
  12344. this.isHttp = /^https?:/i.test(url);
  12345. this.httpHeaders = this.isHttp && args.httpHeaders || Object.create(null);
  12346. this.withCredentials = args.withCredentials || false;
  12347. this.getXhr = args.getXhr || function NetworkManager_getXhr() {
  12348. return new XMLHttpRequest();
  12349. };
  12350. this.currXhrId = 0;
  12351. this.pendingRequests = Object.create(null);
  12352. }
  12353. requestRange(begin, end, listeners) {
  12354. const args = {
  12355. begin,
  12356. end
  12357. };
  12358. for (const prop in listeners) {
  12359. args[prop] = listeners[prop];
  12360. }
  12361. return this.request(args);
  12362. }
  12363. requestFull(listeners) {
  12364. return this.request(listeners);
  12365. }
  12366. request(args) {
  12367. const xhr = this.getXhr();
  12368. const xhrId = this.currXhrId++;
  12369. const pendingRequest = this.pendingRequests[xhrId] = {
  12370. xhr
  12371. };
  12372. xhr.open("GET", this.url);
  12373. xhr.withCredentials = this.withCredentials;
  12374. for (const property in this.httpHeaders) {
  12375. const value = this.httpHeaders[property];
  12376. if (typeof value === "undefined") {
  12377. continue;
  12378. }
  12379. xhr.setRequestHeader(property, value);
  12380. }
  12381. if (this.isHttp && "begin" in args && "end" in args) {
  12382. xhr.setRequestHeader("Range", `bytes=${args.begin}-${args.end - 1}`);
  12383. pendingRequest.expectedStatus = PARTIAL_CONTENT_RESPONSE;
  12384. } else {
  12385. pendingRequest.expectedStatus = OK_RESPONSE;
  12386. }
  12387. xhr.responseType = "arraybuffer";
  12388. if (args.onError) {
  12389. xhr.onerror = function (evt) {
  12390. args.onError(xhr.status);
  12391. };
  12392. }
  12393. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  12394. xhr.onprogress = this.onProgress.bind(this, xhrId);
  12395. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  12396. pendingRequest.onDone = args.onDone;
  12397. pendingRequest.onError = args.onError;
  12398. pendingRequest.onProgress = args.onProgress;
  12399. xhr.send(null);
  12400. return xhrId;
  12401. }
  12402. onProgress(xhrId, evt) {
  12403. const pendingRequest = this.pendingRequests[xhrId];
  12404. if (!pendingRequest) {
  12405. return;
  12406. }
  12407. pendingRequest.onProgress?.(evt);
  12408. }
  12409. onStateChange(xhrId, evt) {
  12410. const pendingRequest = this.pendingRequests[xhrId];
  12411. if (!pendingRequest) {
  12412. return;
  12413. }
  12414. const xhr = pendingRequest.xhr;
  12415. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  12416. pendingRequest.onHeadersReceived();
  12417. delete pendingRequest.onHeadersReceived;
  12418. }
  12419. if (xhr.readyState !== 4) {
  12420. return;
  12421. }
  12422. if (!(xhrId in this.pendingRequests)) {
  12423. return;
  12424. }
  12425. delete this.pendingRequests[xhrId];
  12426. if (xhr.status === 0 && this.isHttp) {
  12427. pendingRequest.onError?.(xhr.status);
  12428. return;
  12429. }
  12430. const xhrStatus = xhr.status || OK_RESPONSE;
  12431. const ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  12432. if (!ok_response_on_range_request && xhrStatus !== pendingRequest.expectedStatus) {
  12433. pendingRequest.onError?.(xhr.status);
  12434. return;
  12435. }
  12436. const chunk = getArrayBuffer(xhr);
  12437. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  12438. const rangeHeader = xhr.getResponseHeader("Content-Range");
  12439. const matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  12440. pendingRequest.onDone({
  12441. begin: parseInt(matches[1], 10),
  12442. chunk
  12443. });
  12444. } else if (chunk) {
  12445. pendingRequest.onDone({
  12446. begin: 0,
  12447. chunk
  12448. });
  12449. } else {
  12450. pendingRequest.onError?.(xhr.status);
  12451. }
  12452. }
  12453. getRequestXhr(xhrId) {
  12454. return this.pendingRequests[xhrId].xhr;
  12455. }
  12456. isPendingRequest(xhrId) {
  12457. return xhrId in this.pendingRequests;
  12458. }
  12459. abortRequest(xhrId) {
  12460. const xhr = this.pendingRequests[xhrId].xhr;
  12461. delete this.pendingRequests[xhrId];
  12462. xhr.abort();
  12463. }
  12464. }
  12465. class PDFNetworkStream {
  12466. constructor(source) {
  12467. this._source = source;
  12468. this._manager = new NetworkManager(source.url, {
  12469. httpHeaders: source.httpHeaders,
  12470. withCredentials: source.withCredentials
  12471. });
  12472. this._rangeChunkSize = source.rangeChunkSize;
  12473. this._fullRequestReader = null;
  12474. this._rangeRequestReaders = [];
  12475. }
  12476. _onRangeRequestReaderClosed(reader) {
  12477. const i = this._rangeRequestReaders.indexOf(reader);
  12478. if (i >= 0) {
  12479. this._rangeRequestReaders.splice(i, 1);
  12480. }
  12481. }
  12482. getFullReader() {
  12483. (0, _util.assert)(!this._fullRequestReader, "PDFNetworkStream.getFullReader can only be called once.");
  12484. this._fullRequestReader = new PDFNetworkStreamFullRequestReader(this._manager, this._source);
  12485. return this._fullRequestReader;
  12486. }
  12487. getRangeReader(begin, end) {
  12488. const reader = new PDFNetworkStreamRangeRequestReader(this._manager, begin, end);
  12489. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  12490. this._rangeRequestReaders.push(reader);
  12491. return reader;
  12492. }
  12493. cancelAllRequests(reason) {
  12494. this._fullRequestReader?.cancel(reason);
  12495. for (const reader of this._rangeRequestReaders.slice(0)) {
  12496. reader.cancel(reason);
  12497. }
  12498. }
  12499. }
  12500. exports.PDFNetworkStream = PDFNetworkStream;
  12501. class PDFNetworkStreamFullRequestReader {
  12502. constructor(manager, source) {
  12503. this._manager = manager;
  12504. const args = {
  12505. onHeadersReceived: this._onHeadersReceived.bind(this),
  12506. onDone: this._onDone.bind(this),
  12507. onError: this._onError.bind(this),
  12508. onProgress: this._onProgress.bind(this)
  12509. };
  12510. this._url = source.url;
  12511. this._fullRequestId = manager.requestFull(args);
  12512. this._headersReceivedCapability = (0, _util.createPromiseCapability)();
  12513. this._disableRange = source.disableRange || false;
  12514. this._contentLength = source.length;
  12515. this._rangeChunkSize = source.rangeChunkSize;
  12516. if (!this._rangeChunkSize && !this._disableRange) {
  12517. this._disableRange = true;
  12518. }
  12519. this._isStreamingSupported = false;
  12520. this._isRangeSupported = false;
  12521. this._cachedChunks = [];
  12522. this._requests = [];
  12523. this._done = false;
  12524. this._storedError = undefined;
  12525. this._filename = null;
  12526. this.onProgress = null;
  12527. }
  12528. _onHeadersReceived() {
  12529. const fullRequestXhrId = this._fullRequestId;
  12530. const fullRequestXhr = this._manager.getRequestXhr(fullRequestXhrId);
  12531. const getResponseHeader = name => {
  12532. return fullRequestXhr.getResponseHeader(name);
  12533. };
  12534. const {
  12535. allowRangeRequests,
  12536. suggestedLength
  12537. } = (0, _network_utils.validateRangeRequestCapabilities)({
  12538. getResponseHeader,
  12539. isHttp: this._manager.isHttp,
  12540. rangeChunkSize: this._rangeChunkSize,
  12541. disableRange: this._disableRange
  12542. });
  12543. if (allowRangeRequests) {
  12544. this._isRangeSupported = true;
  12545. }
  12546. this._contentLength = suggestedLength || this._contentLength;
  12547. this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
  12548. if (this._isRangeSupported) {
  12549. this._manager.abortRequest(fullRequestXhrId);
  12550. }
  12551. this._headersReceivedCapability.resolve();
  12552. }
  12553. _onDone(data) {
  12554. if (data) {
  12555. if (this._requests.length > 0) {
  12556. const requestCapability = this._requests.shift();
  12557. requestCapability.resolve({
  12558. value: data.chunk,
  12559. done: false
  12560. });
  12561. } else {
  12562. this._cachedChunks.push(data.chunk);
  12563. }
  12564. }
  12565. this._done = true;
  12566. if (this._cachedChunks.length > 0) {
  12567. return;
  12568. }
  12569. for (const requestCapability of this._requests) {
  12570. requestCapability.resolve({
  12571. value: undefined,
  12572. done: true
  12573. });
  12574. }
  12575. this._requests.length = 0;
  12576. }
  12577. _onError(status) {
  12578. this._storedError = (0, _network_utils.createResponseStatusError)(status, this._url);
  12579. this._headersReceivedCapability.reject(this._storedError);
  12580. for (const requestCapability of this._requests) {
  12581. requestCapability.reject(this._storedError);
  12582. }
  12583. this._requests.length = 0;
  12584. this._cachedChunks.length = 0;
  12585. }
  12586. _onProgress(evt) {
  12587. this.onProgress?.({
  12588. loaded: evt.loaded,
  12589. total: evt.lengthComputable ? evt.total : this._contentLength
  12590. });
  12591. }
  12592. get filename() {
  12593. return this._filename;
  12594. }
  12595. get isRangeSupported() {
  12596. return this._isRangeSupported;
  12597. }
  12598. get isStreamingSupported() {
  12599. return this._isStreamingSupported;
  12600. }
  12601. get contentLength() {
  12602. return this._contentLength;
  12603. }
  12604. get headersReady() {
  12605. return this._headersReceivedCapability.promise;
  12606. }
  12607. async read() {
  12608. if (this._storedError) {
  12609. throw this._storedError;
  12610. }
  12611. if (this._cachedChunks.length > 0) {
  12612. const chunk = this._cachedChunks.shift();
  12613. return {
  12614. value: chunk,
  12615. done: false
  12616. };
  12617. }
  12618. if (this._done) {
  12619. return {
  12620. value: undefined,
  12621. done: true
  12622. };
  12623. }
  12624. const requestCapability = (0, _util.createPromiseCapability)();
  12625. this._requests.push(requestCapability);
  12626. return requestCapability.promise;
  12627. }
  12628. cancel(reason) {
  12629. this._done = true;
  12630. this._headersReceivedCapability.reject(reason);
  12631. for (const requestCapability of this._requests) {
  12632. requestCapability.resolve({
  12633. value: undefined,
  12634. done: true
  12635. });
  12636. }
  12637. this._requests.length = 0;
  12638. if (this._manager.isPendingRequest(this._fullRequestId)) {
  12639. this._manager.abortRequest(this._fullRequestId);
  12640. }
  12641. this._fullRequestReader = null;
  12642. }
  12643. }
  12644. class PDFNetworkStreamRangeRequestReader {
  12645. constructor(manager, begin, end) {
  12646. this._manager = manager;
  12647. const args = {
  12648. onDone: this._onDone.bind(this),
  12649. onError: this._onError.bind(this),
  12650. onProgress: this._onProgress.bind(this)
  12651. };
  12652. this._url = manager.url;
  12653. this._requestId = manager.requestRange(begin, end, args);
  12654. this._requests = [];
  12655. this._queuedChunk = null;
  12656. this._done = false;
  12657. this._storedError = undefined;
  12658. this.onProgress = null;
  12659. this.onClosed = null;
  12660. }
  12661. _close() {
  12662. this.onClosed?.(this);
  12663. }
  12664. _onDone(data) {
  12665. const chunk = data.chunk;
  12666. if (this._requests.length > 0) {
  12667. const requestCapability = this._requests.shift();
  12668. requestCapability.resolve({
  12669. value: chunk,
  12670. done: false
  12671. });
  12672. } else {
  12673. this._queuedChunk = chunk;
  12674. }
  12675. this._done = true;
  12676. for (const requestCapability of this._requests) {
  12677. requestCapability.resolve({
  12678. value: undefined,
  12679. done: true
  12680. });
  12681. }
  12682. this._requests.length = 0;
  12683. this._close();
  12684. }
  12685. _onError(status) {
  12686. this._storedError = (0, _network_utils.createResponseStatusError)(status, this._url);
  12687. for (const requestCapability of this._requests) {
  12688. requestCapability.reject(this._storedError);
  12689. }
  12690. this._requests.length = 0;
  12691. this._queuedChunk = null;
  12692. }
  12693. _onProgress(evt) {
  12694. if (!this.isStreamingSupported) {
  12695. this.onProgress?.({
  12696. loaded: evt.loaded
  12697. });
  12698. }
  12699. }
  12700. get isStreamingSupported() {
  12701. return false;
  12702. }
  12703. async read() {
  12704. if (this._storedError) {
  12705. throw this._storedError;
  12706. }
  12707. if (this._queuedChunk !== null) {
  12708. const chunk = this._queuedChunk;
  12709. this._queuedChunk = null;
  12710. return {
  12711. value: chunk,
  12712. done: false
  12713. };
  12714. }
  12715. if (this._done) {
  12716. return {
  12717. value: undefined,
  12718. done: true
  12719. };
  12720. }
  12721. const requestCapability = (0, _util.createPromiseCapability)();
  12722. this._requests.push(requestCapability);
  12723. return requestCapability.promise;
  12724. }
  12725. cancel(reason) {
  12726. this._done = true;
  12727. for (const requestCapability of this._requests) {
  12728. requestCapability.resolve({
  12729. value: undefined,
  12730. done: true
  12731. });
  12732. }
  12733. this._requests.length = 0;
  12734. if (this._manager.isPendingRequest(this._requestId)) {
  12735. this._manager.abortRequest(this._requestId);
  12736. }
  12737. this._close();
  12738. }
  12739. }
  12740. /***/ }),
  12741. /* 29 */
  12742. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  12743. Object.defineProperty(exports, "__esModule", ({
  12744. value: true
  12745. }));
  12746. exports.PDFFetchStream = void 0;
  12747. var _util = __w_pdfjs_require__(1);
  12748. var _network_utils = __w_pdfjs_require__(26);
  12749. ;
  12750. function createFetchOptions(headers, withCredentials, abortController) {
  12751. return {
  12752. method: "GET",
  12753. headers,
  12754. signal: abortController?.signal,
  12755. mode: "cors",
  12756. credentials: withCredentials ? "include" : "same-origin",
  12757. redirect: "follow"
  12758. };
  12759. }
  12760. function createHeaders(httpHeaders) {
  12761. const headers = new Headers();
  12762. for (const property in httpHeaders) {
  12763. const value = httpHeaders[property];
  12764. if (typeof value === "undefined") {
  12765. continue;
  12766. }
  12767. headers.append(property, value);
  12768. }
  12769. return headers;
  12770. }
  12771. class PDFFetchStream {
  12772. constructor(source) {
  12773. this.source = source;
  12774. this.isHttp = /^https?:/i.test(source.url);
  12775. this.httpHeaders = this.isHttp && source.httpHeaders || {};
  12776. this._fullRequestReader = null;
  12777. this._rangeRequestReaders = [];
  12778. }
  12779. get _progressiveDataLength() {
  12780. return this._fullRequestReader?._loaded ?? 0;
  12781. }
  12782. getFullReader() {
  12783. (0, _util.assert)(!this._fullRequestReader, "PDFFetchStream.getFullReader can only be called once.");
  12784. this._fullRequestReader = new PDFFetchStreamReader(this);
  12785. return this._fullRequestReader;
  12786. }
  12787. getRangeReader(begin, end) {
  12788. if (end <= this._progressiveDataLength) {
  12789. return null;
  12790. }
  12791. const reader = new PDFFetchStreamRangeReader(this, begin, end);
  12792. this._rangeRequestReaders.push(reader);
  12793. return reader;
  12794. }
  12795. cancelAllRequests(reason) {
  12796. if (this._fullRequestReader) {
  12797. this._fullRequestReader.cancel(reason);
  12798. }
  12799. for (const reader of this._rangeRequestReaders.slice(0)) {
  12800. reader.cancel(reason);
  12801. }
  12802. }
  12803. }
  12804. exports.PDFFetchStream = PDFFetchStream;
  12805. class PDFFetchStreamReader {
  12806. constructor(stream) {
  12807. this._stream = stream;
  12808. this._reader = null;
  12809. this._loaded = 0;
  12810. this._filename = null;
  12811. const source = stream.source;
  12812. this._withCredentials = source.withCredentials || false;
  12813. this._contentLength = source.length;
  12814. this._headersCapability = (0, _util.createPromiseCapability)();
  12815. this._disableRange = source.disableRange || false;
  12816. this._rangeChunkSize = source.rangeChunkSize;
  12817. if (!this._rangeChunkSize && !this._disableRange) {
  12818. this._disableRange = true;
  12819. }
  12820. if (typeof AbortController !== "undefined") {
  12821. this._abortController = new AbortController();
  12822. }
  12823. this._isStreamingSupported = !source.disableStream;
  12824. this._isRangeSupported = !source.disableRange;
  12825. this._headers = createHeaders(this._stream.httpHeaders);
  12826. const url = source.url;
  12827. fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(response => {
  12828. if (!(0, _network_utils.validateResponseStatus)(response.status)) {
  12829. throw (0, _network_utils.createResponseStatusError)(response.status, url);
  12830. }
  12831. this._reader = response.body.getReader();
  12832. this._headersCapability.resolve();
  12833. const getResponseHeader = name => {
  12834. return response.headers.get(name);
  12835. };
  12836. const {
  12837. allowRangeRequests,
  12838. suggestedLength
  12839. } = (0, _network_utils.validateRangeRequestCapabilities)({
  12840. getResponseHeader,
  12841. isHttp: this._stream.isHttp,
  12842. rangeChunkSize: this._rangeChunkSize,
  12843. disableRange: this._disableRange
  12844. });
  12845. this._isRangeSupported = allowRangeRequests;
  12846. this._contentLength = suggestedLength || this._contentLength;
  12847. this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
  12848. if (!this._isStreamingSupported && this._isRangeSupported) {
  12849. this.cancel(new _util.AbortException("Streaming is disabled."));
  12850. }
  12851. }).catch(this._headersCapability.reject);
  12852. this.onProgress = null;
  12853. }
  12854. get headersReady() {
  12855. return this._headersCapability.promise;
  12856. }
  12857. get filename() {
  12858. return this._filename;
  12859. }
  12860. get contentLength() {
  12861. return this._contentLength;
  12862. }
  12863. get isRangeSupported() {
  12864. return this._isRangeSupported;
  12865. }
  12866. get isStreamingSupported() {
  12867. return this._isStreamingSupported;
  12868. }
  12869. async read() {
  12870. await this._headersCapability.promise;
  12871. const {
  12872. value,
  12873. done
  12874. } = await this._reader.read();
  12875. if (done) {
  12876. return {
  12877. value,
  12878. done
  12879. };
  12880. }
  12881. this._loaded += value.byteLength;
  12882. if (this.onProgress) {
  12883. this.onProgress({
  12884. loaded: this._loaded,
  12885. total: this._contentLength
  12886. });
  12887. }
  12888. const buffer = new Uint8Array(value).buffer;
  12889. return {
  12890. value: buffer,
  12891. done: false
  12892. };
  12893. }
  12894. cancel(reason) {
  12895. if (this._reader) {
  12896. this._reader.cancel(reason);
  12897. }
  12898. if (this._abortController) {
  12899. this._abortController.abort();
  12900. }
  12901. }
  12902. }
  12903. class PDFFetchStreamRangeReader {
  12904. constructor(stream, begin, end) {
  12905. this._stream = stream;
  12906. this._reader = null;
  12907. this._loaded = 0;
  12908. const source = stream.source;
  12909. this._withCredentials = source.withCredentials || false;
  12910. this._readCapability = (0, _util.createPromiseCapability)();
  12911. this._isStreamingSupported = !source.disableStream;
  12912. if (typeof AbortController !== "undefined") {
  12913. this._abortController = new AbortController();
  12914. }
  12915. this._headers = createHeaders(this._stream.httpHeaders);
  12916. this._headers.append("Range", `bytes=${begin}-${end - 1}`);
  12917. const url = source.url;
  12918. fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(response => {
  12919. if (!(0, _network_utils.validateResponseStatus)(response.status)) {
  12920. throw (0, _network_utils.createResponseStatusError)(response.status, url);
  12921. }
  12922. this._readCapability.resolve();
  12923. this._reader = response.body.getReader();
  12924. }).catch(this._readCapability.reject);
  12925. this.onProgress = null;
  12926. }
  12927. get isStreamingSupported() {
  12928. return this._isStreamingSupported;
  12929. }
  12930. async read() {
  12931. await this._readCapability.promise;
  12932. const {
  12933. value,
  12934. done
  12935. } = await this._reader.read();
  12936. if (done) {
  12937. return {
  12938. value,
  12939. done
  12940. };
  12941. }
  12942. this._loaded += value.byteLength;
  12943. if (this.onProgress) {
  12944. this.onProgress({
  12945. loaded: this._loaded
  12946. });
  12947. }
  12948. const buffer = new Uint8Array(value).buffer;
  12949. return {
  12950. value: buffer,
  12951. done: false
  12952. };
  12953. }
  12954. cancel(reason) {
  12955. if (this._reader) {
  12956. this._reader.cancel(reason);
  12957. }
  12958. if (this._abortController) {
  12959. this._abortController.abort();
  12960. }
  12961. }
  12962. }
  12963. /***/ })
  12964. /******/ ]);
  12965. /************************************************************************/
  12966. /******/ // The module cache
  12967. /******/ var __webpack_module_cache__ = {};
  12968. /******/
  12969. /******/ // The require function
  12970. /******/ function __w_pdfjs_require__(moduleId) {
  12971. /******/ // Check if module is in cache
  12972. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  12973. /******/ if (cachedModule !== undefined) {
  12974. /******/ return cachedModule.exports;
  12975. /******/ }
  12976. /******/ // Create a new module (and put it into the cache)
  12977. /******/ var module = __webpack_module_cache__[moduleId] = {
  12978. /******/ // no module.id needed
  12979. /******/ // no module.loaded needed
  12980. /******/ exports: {}
  12981. /******/ };
  12982. /******/
  12983. /******/ // Execute the module function
  12984. /******/ __webpack_modules__[moduleId](module, module.exports, __w_pdfjs_require__);
  12985. /******/
  12986. /******/ // Return the exports of the module
  12987. /******/ return module.exports;
  12988. /******/ }
  12989. /******/
  12990. /************************************************************************/
  12991. var __webpack_exports__ = {};
  12992. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  12993. (() => {
  12994. var exports = __webpack_exports__;
  12995. Object.defineProperty(exports, "__esModule", ({
  12996. value: true
  12997. }));
  12998. Object.defineProperty(exports, "AnnotationLayer", ({
  12999. enumerable: true,
  13000. get: function () {
  13001. return _annotation_layer.AnnotationLayer;
  13002. }
  13003. }));
  13004. Object.defineProperty(exports, "AnnotationMode", ({
  13005. enumerable: true,
  13006. get: function () {
  13007. return _util.AnnotationMode;
  13008. }
  13009. }));
  13010. Object.defineProperty(exports, "CMapCompressionType", ({
  13011. enumerable: true,
  13012. get: function () {
  13013. return _util.CMapCompressionType;
  13014. }
  13015. }));
  13016. Object.defineProperty(exports, "GlobalWorkerOptions", ({
  13017. enumerable: true,
  13018. get: function () {
  13019. return _worker_options.GlobalWorkerOptions;
  13020. }
  13021. }));
  13022. Object.defineProperty(exports, "InvalidPDFException", ({
  13023. enumerable: true,
  13024. get: function () {
  13025. return _util.InvalidPDFException;
  13026. }
  13027. }));
  13028. Object.defineProperty(exports, "LoopbackPort", ({
  13029. enumerable: true,
  13030. get: function () {
  13031. return _api.LoopbackPort;
  13032. }
  13033. }));
  13034. Object.defineProperty(exports, "MissingPDFException", ({
  13035. enumerable: true,
  13036. get: function () {
  13037. return _util.MissingPDFException;
  13038. }
  13039. }));
  13040. Object.defineProperty(exports, "OPS", ({
  13041. enumerable: true,
  13042. get: function () {
  13043. return _util.OPS;
  13044. }
  13045. }));
  13046. Object.defineProperty(exports, "PDFDataRangeTransport", ({
  13047. enumerable: true,
  13048. get: function () {
  13049. return _api.PDFDataRangeTransport;
  13050. }
  13051. }));
  13052. Object.defineProperty(exports, "PDFDateString", ({
  13053. enumerable: true,
  13054. get: function () {
  13055. return _display_utils.PDFDateString;
  13056. }
  13057. }));
  13058. Object.defineProperty(exports, "PDFWorker", ({
  13059. enumerable: true,
  13060. get: function () {
  13061. return _api.PDFWorker;
  13062. }
  13063. }));
  13064. Object.defineProperty(exports, "PasswordResponses", ({
  13065. enumerable: true,
  13066. get: function () {
  13067. return _util.PasswordResponses;
  13068. }
  13069. }));
  13070. Object.defineProperty(exports, "PermissionFlag", ({
  13071. enumerable: true,
  13072. get: function () {
  13073. return _util.PermissionFlag;
  13074. }
  13075. }));
  13076. Object.defineProperty(exports, "PixelsPerInch", ({
  13077. enumerable: true,
  13078. get: function () {
  13079. return _display_utils.PixelsPerInch;
  13080. }
  13081. }));
  13082. Object.defineProperty(exports, "RenderingCancelledException", ({
  13083. enumerable: true,
  13084. get: function () {
  13085. return _display_utils.RenderingCancelledException;
  13086. }
  13087. }));
  13088. Object.defineProperty(exports, "SVGGraphics", ({
  13089. enumerable: true,
  13090. get: function () {
  13091. return _svg.SVGGraphics;
  13092. }
  13093. }));
  13094. Object.defineProperty(exports, "UNSUPPORTED_FEATURES", ({
  13095. enumerable: true,
  13096. get: function () {
  13097. return _util.UNSUPPORTED_FEATURES;
  13098. }
  13099. }));
  13100. Object.defineProperty(exports, "UnexpectedResponseException", ({
  13101. enumerable: true,
  13102. get: function () {
  13103. return _util.UnexpectedResponseException;
  13104. }
  13105. }));
  13106. Object.defineProperty(exports, "Util", ({
  13107. enumerable: true,
  13108. get: function () {
  13109. return _util.Util;
  13110. }
  13111. }));
  13112. Object.defineProperty(exports, "VerbosityLevel", ({
  13113. enumerable: true,
  13114. get: function () {
  13115. return _util.VerbosityLevel;
  13116. }
  13117. }));
  13118. Object.defineProperty(exports, "XfaLayer", ({
  13119. enumerable: true,
  13120. get: function () {
  13121. return _xfa_layer.XfaLayer;
  13122. }
  13123. }));
  13124. Object.defineProperty(exports, "build", ({
  13125. enumerable: true,
  13126. get: function () {
  13127. return _api.build;
  13128. }
  13129. }));
  13130. Object.defineProperty(exports, "createPromiseCapability", ({
  13131. enumerable: true,
  13132. get: function () {
  13133. return _util.createPromiseCapability;
  13134. }
  13135. }));
  13136. Object.defineProperty(exports, "createValidAbsoluteUrl", ({
  13137. enumerable: true,
  13138. get: function () {
  13139. return _util.createValidAbsoluteUrl;
  13140. }
  13141. }));
  13142. Object.defineProperty(exports, "getDocument", ({
  13143. enumerable: true,
  13144. get: function () {
  13145. return _api.getDocument;
  13146. }
  13147. }));
  13148. Object.defineProperty(exports, "getFilenameFromUrl", ({
  13149. enumerable: true,
  13150. get: function () {
  13151. return _display_utils.getFilenameFromUrl;
  13152. }
  13153. }));
  13154. Object.defineProperty(exports, "getPdfFilenameFromUrl", ({
  13155. enumerable: true,
  13156. get: function () {
  13157. return _display_utils.getPdfFilenameFromUrl;
  13158. }
  13159. }));
  13160. Object.defineProperty(exports, "getXfaPageViewport", ({
  13161. enumerable: true,
  13162. get: function () {
  13163. return _display_utils.getXfaPageViewport;
  13164. }
  13165. }));
  13166. Object.defineProperty(exports, "isPdfFile", ({
  13167. enumerable: true,
  13168. get: function () {
  13169. return _display_utils.isPdfFile;
  13170. }
  13171. }));
  13172. Object.defineProperty(exports, "loadScript", ({
  13173. enumerable: true,
  13174. get: function () {
  13175. return _display_utils.loadScript;
  13176. }
  13177. }));
  13178. Object.defineProperty(exports, "renderTextLayer", ({
  13179. enumerable: true,
  13180. get: function () {
  13181. return _text_layer.renderTextLayer;
  13182. }
  13183. }));
  13184. Object.defineProperty(exports, "shadow", ({
  13185. enumerable: true,
  13186. get: function () {
  13187. return _util.shadow;
  13188. }
  13189. }));
  13190. Object.defineProperty(exports, "version", ({
  13191. enumerable: true,
  13192. get: function () {
  13193. return _api.version;
  13194. }
  13195. }));
  13196. var _util = __w_pdfjs_require__(1);
  13197. var _api = __w_pdfjs_require__(4);
  13198. var _display_utils = __w_pdfjs_require__(5);
  13199. var _annotation_layer = __w_pdfjs_require__(20);
  13200. var _worker_options = __w_pdfjs_require__(13);
  13201. var _is_node = __w_pdfjs_require__(3);
  13202. var _text_layer = __w_pdfjs_require__(23);
  13203. var _svg = __w_pdfjs_require__(24);
  13204. var _xfa_layer = __w_pdfjs_require__(22);
  13205. const pdfjsVersion = '2.14.305';
  13206. const pdfjsBuild = 'eaaa8b4ad';
  13207. {
  13208. if (_is_node.isNodeJS) {
  13209. const {
  13210. PDFNodeStream
  13211. } = __w_pdfjs_require__(25);
  13212. (0, _api.setPDFNetworkStreamFactory)(params => {
  13213. return new PDFNodeStream(params);
  13214. });
  13215. } else {
  13216. const {
  13217. PDFNetworkStream
  13218. } = __w_pdfjs_require__(28);
  13219. const {
  13220. PDFFetchStream
  13221. } = __w_pdfjs_require__(29);
  13222. (0, _api.setPDFNetworkStreamFactory)(params => {
  13223. if ((0, _display_utils.isValidFetchUrl)(params.url)) {
  13224. return new PDFFetchStream(params);
  13225. }
  13226. return new PDFNetworkStream(params);
  13227. });
  13228. }
  13229. }
  13230. })();
  13231. /******/ return __webpack_exports__;
  13232. /******/ })()
  13233. ;
  13234. });
  13235. //# sourceMappingURL=pdf.js.map