pdf.js 407 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806
  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, function() {
  32. return /******/ (() => { // webpackBootstrap
  33. /******/ "use strict";
  34. /******/ var __webpack_modules__ = ([
  35. /* 0 */,
  36. /* 1 */
  37. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  38. Object.defineProperty(exports, "__esModule", ({
  39. value: true
  40. }));
  41. exports.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.IsLittleEndianCached = exports.IsEvalSupportedCached = exports.InvalidPDFException = exports.ImageKind = exports.IDENTITY_MATRIX = exports.FormatError = exports.FontType = exports.FONT_IDENTITY_MATRIX = exports.DocumentActionEventType = exports.CMapCompressionType = exports.BaseException = exports.AnnotationType = exports.AnnotationStateModelType = exports.AnnotationReviewState = exports.AnnotationReplyType = exports.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.isSameOrigin = isSameOrigin;
  56. exports.objectFromMap = objectFromMap;
  57. exports.objectSize = objectSize;
  58. exports.setVerbosityLevel = setVerbosityLevel;
  59. exports.shadow = shadow;
  60. exports.string32 = string32;
  61. exports.stringToBytes = stringToBytes;
  62. exports.stringToPDFString = stringToPDFString;
  63. exports.stringToUTF16BEString = stringToUTF16BEString;
  64. exports.stringToUTF8String = stringToUTF8String;
  65. exports.unreachable = unreachable;
  66. exports.utf8StringToString = utf8StringToString;
  67. exports.warn = warn;
  68. __w_pdfjs_require__(2);
  69. const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  70. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  71. const FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  72. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  73. const RenderingIntentFlag = {
  74. ANY: 0x01,
  75. DISPLAY: 0x02,
  76. PRINT: 0x04,
  77. ANNOTATIONS_FORMS: 0x10,
  78. ANNOTATIONS_STORAGE: 0x20,
  79. ANNOTATIONS_DISABLE: 0x40,
  80. OPLIST: 0x100
  81. };
  82. exports.RenderingIntentFlag = RenderingIntentFlag;
  83. const AnnotationMode = {
  84. DISABLE: 0,
  85. ENABLE: 1,
  86. ENABLE_FORMS: 2,
  87. ENABLE_STORAGE: 3
  88. };
  89. exports.AnnotationMode = AnnotationMode;
  90. const PermissionFlag = {
  91. PRINT: 0x04,
  92. MODIFY_CONTENTS: 0x08,
  93. COPY: 0x10,
  94. MODIFY_ANNOTATIONS: 0x20,
  95. FILL_INTERACTIVE_FORMS: 0x100,
  96. COPY_FOR_ACCESSIBILITY: 0x200,
  97. ASSEMBLE: 0x400,
  98. PRINT_HIGH_QUALITY: 0x800
  99. };
  100. exports.PermissionFlag = PermissionFlag;
  101. const TextRenderingMode = {
  102. FILL: 0,
  103. STROKE: 1,
  104. FILL_STROKE: 2,
  105. INVISIBLE: 3,
  106. FILL_ADD_TO_PATH: 4,
  107. STROKE_ADD_TO_PATH: 5,
  108. FILL_STROKE_ADD_TO_PATH: 6,
  109. ADD_TO_PATH: 7,
  110. FILL_STROKE_MASK: 3,
  111. ADD_TO_PATH_FLAG: 4
  112. };
  113. exports.TextRenderingMode = TextRenderingMode;
  114. const ImageKind = {
  115. GRAYSCALE_1BPP: 1,
  116. RGB_24BPP: 2,
  117. RGBA_32BPP: 3
  118. };
  119. exports.ImageKind = ImageKind;
  120. const AnnotationType = {
  121. TEXT: 1,
  122. LINK: 2,
  123. FREETEXT: 3,
  124. LINE: 4,
  125. SQUARE: 5,
  126. CIRCLE: 6,
  127. POLYGON: 7,
  128. POLYLINE: 8,
  129. HIGHLIGHT: 9,
  130. UNDERLINE: 10,
  131. SQUIGGLY: 11,
  132. STRIKEOUT: 12,
  133. STAMP: 13,
  134. CARET: 14,
  135. INK: 15,
  136. POPUP: 16,
  137. FILEATTACHMENT: 17,
  138. SOUND: 18,
  139. MOVIE: 19,
  140. WIDGET: 20,
  141. SCREEN: 21,
  142. PRINTERMARK: 22,
  143. TRAPNET: 23,
  144. WATERMARK: 24,
  145. THREED: 25,
  146. REDACT: 26
  147. };
  148. exports.AnnotationType = AnnotationType;
  149. const AnnotationStateModelType = {
  150. MARKED: "Marked",
  151. REVIEW: "Review"
  152. };
  153. exports.AnnotationStateModelType = AnnotationStateModelType;
  154. const AnnotationMarkedState = {
  155. MARKED: "Marked",
  156. UNMARKED: "Unmarked"
  157. };
  158. exports.AnnotationMarkedState = AnnotationMarkedState;
  159. const AnnotationReviewState = {
  160. ACCEPTED: "Accepted",
  161. REJECTED: "Rejected",
  162. CANCELLED: "Cancelled",
  163. COMPLETED: "Completed",
  164. NONE: "None"
  165. };
  166. exports.AnnotationReviewState = AnnotationReviewState;
  167. const AnnotationReplyType = {
  168. GROUP: "Group",
  169. REPLY: "R"
  170. };
  171. exports.AnnotationReplyType = AnnotationReplyType;
  172. const AnnotationFlag = {
  173. INVISIBLE: 0x01,
  174. HIDDEN: 0x02,
  175. PRINT: 0x04,
  176. NOZOOM: 0x08,
  177. NOROTATE: 0x10,
  178. NOVIEW: 0x20,
  179. READONLY: 0x40,
  180. LOCKED: 0x80,
  181. TOGGLENOVIEW: 0x100,
  182. LOCKEDCONTENTS: 0x200
  183. };
  184. exports.AnnotationFlag = AnnotationFlag;
  185. const AnnotationFieldFlag = {
  186. READONLY: 0x0000001,
  187. REQUIRED: 0x0000002,
  188. NOEXPORT: 0x0000004,
  189. MULTILINE: 0x0001000,
  190. PASSWORD: 0x0002000,
  191. NOTOGGLETOOFF: 0x0004000,
  192. RADIO: 0x0008000,
  193. PUSHBUTTON: 0x0010000,
  194. COMBO: 0x0020000,
  195. EDIT: 0x0040000,
  196. SORT: 0x0080000,
  197. FILESELECT: 0x0100000,
  198. MULTISELECT: 0x0200000,
  199. DONOTSPELLCHECK: 0x0400000,
  200. DONOTSCROLL: 0x0800000,
  201. COMB: 0x1000000,
  202. RICHTEXT: 0x2000000,
  203. RADIOSINUNISON: 0x2000000,
  204. COMMITONSELCHANGE: 0x4000000
  205. };
  206. exports.AnnotationFieldFlag = AnnotationFieldFlag;
  207. const AnnotationBorderStyleType = {
  208. SOLID: 1,
  209. DASHED: 2,
  210. BEVELED: 3,
  211. INSET: 4,
  212. UNDERLINE: 5
  213. };
  214. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  215. const AnnotationActionEventType = {
  216. E: "Mouse Enter",
  217. X: "Mouse Exit",
  218. D: "Mouse Down",
  219. U: "Mouse Up",
  220. Fo: "Focus",
  221. Bl: "Blur",
  222. PO: "PageOpen",
  223. PC: "PageClose",
  224. PV: "PageVisible",
  225. PI: "PageInvisible",
  226. K: "Keystroke",
  227. F: "Format",
  228. V: "Validate",
  229. C: "Calculate"
  230. };
  231. exports.AnnotationActionEventType = AnnotationActionEventType;
  232. const DocumentActionEventType = {
  233. WC: "WillClose",
  234. WS: "WillSave",
  235. DS: "DidSave",
  236. WP: "WillPrint",
  237. DP: "DidPrint"
  238. };
  239. exports.DocumentActionEventType = DocumentActionEventType;
  240. const PageActionEventType = {
  241. O: "PageOpen",
  242. C: "PageClose"
  243. };
  244. exports.PageActionEventType = PageActionEventType;
  245. const StreamType = {
  246. UNKNOWN: "UNKNOWN",
  247. FLATE: "FLATE",
  248. LZW: "LZW",
  249. DCT: "DCT",
  250. JPX: "JPX",
  251. JBIG: "JBIG",
  252. A85: "A85",
  253. AHX: "AHX",
  254. CCF: "CCF",
  255. RLX: "RLX"
  256. };
  257. exports.StreamType = StreamType;
  258. const FontType = {
  259. UNKNOWN: "UNKNOWN",
  260. TYPE1: "TYPE1",
  261. TYPE1STANDARD: "TYPE1STANDARD",
  262. TYPE1C: "TYPE1C",
  263. CIDFONTTYPE0: "CIDFONTTYPE0",
  264. CIDFONTTYPE0C: "CIDFONTTYPE0C",
  265. TRUETYPE: "TRUETYPE",
  266. CIDFONTTYPE2: "CIDFONTTYPE2",
  267. TYPE3: "TYPE3",
  268. OPENTYPE: "OPENTYPE",
  269. TYPE0: "TYPE0",
  270. MMTYPE1: "MMTYPE1"
  271. };
  272. exports.FontType = FontType;
  273. const VerbosityLevel = {
  274. ERRORS: 0,
  275. WARNINGS: 1,
  276. INFOS: 5
  277. };
  278. exports.VerbosityLevel = VerbosityLevel;
  279. const CMapCompressionType = {
  280. NONE: 0,
  281. BINARY: 1,
  282. STREAM: 2
  283. };
  284. exports.CMapCompressionType = CMapCompressionType;
  285. const OPS = {
  286. dependency: 1,
  287. setLineWidth: 2,
  288. setLineCap: 3,
  289. setLineJoin: 4,
  290. setMiterLimit: 5,
  291. setDash: 6,
  292. setRenderingIntent: 7,
  293. setFlatness: 8,
  294. setGState: 9,
  295. save: 10,
  296. restore: 11,
  297. transform: 12,
  298. moveTo: 13,
  299. lineTo: 14,
  300. curveTo: 15,
  301. curveTo2: 16,
  302. curveTo3: 17,
  303. closePath: 18,
  304. rectangle: 19,
  305. stroke: 20,
  306. closeStroke: 21,
  307. fill: 22,
  308. eoFill: 23,
  309. fillStroke: 24,
  310. eoFillStroke: 25,
  311. closeFillStroke: 26,
  312. closeEOFillStroke: 27,
  313. endPath: 28,
  314. clip: 29,
  315. eoClip: 30,
  316. beginText: 31,
  317. endText: 32,
  318. setCharSpacing: 33,
  319. setWordSpacing: 34,
  320. setHScale: 35,
  321. setLeading: 36,
  322. setFont: 37,
  323. setTextRenderingMode: 38,
  324. setTextRise: 39,
  325. moveText: 40,
  326. setLeadingMoveText: 41,
  327. setTextMatrix: 42,
  328. nextLine: 43,
  329. showText: 44,
  330. showSpacedText: 45,
  331. nextLineShowText: 46,
  332. nextLineSetSpacingShowText: 47,
  333. setCharWidth: 48,
  334. setCharWidthAndBounds: 49,
  335. setStrokeColorSpace: 50,
  336. setFillColorSpace: 51,
  337. setStrokeColor: 52,
  338. setStrokeColorN: 53,
  339. setFillColor: 54,
  340. setFillColorN: 55,
  341. setStrokeGray: 56,
  342. setFillGray: 57,
  343. setStrokeRGBColor: 58,
  344. setFillRGBColor: 59,
  345. setStrokeCMYKColor: 60,
  346. setFillCMYKColor: 61,
  347. shadingFill: 62,
  348. beginInlineImage: 63,
  349. beginImageData: 64,
  350. endInlineImage: 65,
  351. paintXObject: 66,
  352. markPoint: 67,
  353. markPointProps: 68,
  354. beginMarkedContent: 69,
  355. beginMarkedContentProps: 70,
  356. endMarkedContent: 71,
  357. beginCompat: 72,
  358. endCompat: 73,
  359. paintFormXObjectBegin: 74,
  360. paintFormXObjectEnd: 75,
  361. beginGroup: 76,
  362. endGroup: 77,
  363. beginAnnotations: 78,
  364. endAnnotations: 79,
  365. beginAnnotation: 80,
  366. endAnnotation: 81,
  367. paintJpegXObject: 82,
  368. paintImageMaskXObject: 83,
  369. paintImageMaskXObjectGroup: 84,
  370. paintImageXObject: 85,
  371. paintInlineImageXObject: 86,
  372. paintInlineImageXObjectGroup: 87,
  373. paintImageXObjectRepeat: 88,
  374. paintImageMaskXObjectRepeat: 89,
  375. paintSolidColorImageMask: 90,
  376. constructPath: 91
  377. };
  378. exports.OPS = OPS;
  379. const UNSUPPORTED_FEATURES = {
  380. unknown: "unknown",
  381. forms: "forms",
  382. javaScript: "javaScript",
  383. signatures: "signatures",
  384. smask: "smask",
  385. shadingPattern: "shadingPattern",
  386. font: "font",
  387. errorTilingPattern: "errorTilingPattern",
  388. errorExtGState: "errorExtGState",
  389. errorXObject: "errorXObject",
  390. errorFontLoadType3: "errorFontLoadType3",
  391. errorFontState: "errorFontState",
  392. errorFontMissing: "errorFontMissing",
  393. errorFontTranslate: "errorFontTranslate",
  394. errorColorSpace: "errorColorSpace",
  395. errorOperatorList: "errorOperatorList",
  396. errorFontToUnicode: "errorFontToUnicode",
  397. errorFontLoadNative: "errorFontLoadNative",
  398. errorFontBuildPath: "errorFontBuildPath",
  399. errorFontGetPath: "errorFontGetPath",
  400. errorMarkedContent: "errorMarkedContent",
  401. errorContentSubStream: "errorContentSubStream"
  402. };
  403. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  404. const PasswordResponses = {
  405. NEED_PASSWORD: 1,
  406. INCORRECT_PASSWORD: 2
  407. };
  408. exports.PasswordResponses = PasswordResponses;
  409. let verbosity = VerbosityLevel.WARNINGS;
  410. function setVerbosityLevel(level) {
  411. if (Number.isInteger(level)) {
  412. verbosity = level;
  413. }
  414. }
  415. function getVerbosityLevel() {
  416. return verbosity;
  417. }
  418. function info(msg) {
  419. if (verbosity >= VerbosityLevel.INFOS) {
  420. console.log(`Info: ${msg}`);
  421. }
  422. }
  423. function warn(msg) {
  424. if (verbosity >= VerbosityLevel.WARNINGS) {
  425. console.log(`Warning: ${msg}`);
  426. }
  427. }
  428. function unreachable(msg) {
  429. throw new Error(msg);
  430. }
  431. function assert(cond, msg) {
  432. if (!cond) {
  433. unreachable(msg);
  434. }
  435. }
  436. function isSameOrigin(baseUrl, otherUrl) {
  437. let base;
  438. try {
  439. base = new URL(baseUrl);
  440. if (!base.origin || base.origin === "null") {
  441. return false;
  442. }
  443. } catch (e) {
  444. return false;
  445. }
  446. const other = new URL(otherUrl, base);
  447. return base.origin === other.origin;
  448. }
  449. function _isValidProtocol(url) {
  450. if (!url) {
  451. return false;
  452. }
  453. switch (url.protocol) {
  454. case "http:":
  455. case "https:":
  456. case "ftp:":
  457. case "mailto:":
  458. case "tel:":
  459. return true;
  460. default:
  461. return false;
  462. }
  463. }
  464. function createValidAbsoluteUrl(url, baseUrl = null, options = null) {
  465. if (!url) {
  466. return null;
  467. }
  468. try {
  469. if (options && typeof url === "string") {
  470. if (options.addDefaultProtocol && url.startsWith("www.")) {
  471. const dots = url.match(/\./g);
  472. if (dots && dots.length >= 2) {
  473. url = `http://${url}`;
  474. }
  475. }
  476. if (options.tryConvertEncoding) {
  477. try {
  478. url = stringToUTF8String(url);
  479. } catch (ex) {}
  480. }
  481. }
  482. const absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url);
  483. if (_isValidProtocol(absoluteUrl)) {
  484. return absoluteUrl;
  485. }
  486. } catch (ex) {}
  487. return null;
  488. }
  489. function shadow(obj, prop, value) {
  490. Object.defineProperty(obj, prop, {
  491. value,
  492. enumerable: true,
  493. configurable: true,
  494. writable: false
  495. });
  496. return value;
  497. }
  498. const BaseException = function BaseExceptionClosure() {
  499. function BaseException(message, name) {
  500. if (this.constructor === BaseException) {
  501. unreachable("Cannot initialize BaseException.");
  502. }
  503. this.message = message;
  504. this.name = name;
  505. }
  506. BaseException.prototype = new Error();
  507. BaseException.constructor = BaseException;
  508. return BaseException;
  509. }();
  510. exports.BaseException = BaseException;
  511. class PasswordException extends BaseException {
  512. constructor(msg, code) {
  513. super(msg, "PasswordException");
  514. this.code = code;
  515. }
  516. }
  517. exports.PasswordException = PasswordException;
  518. class UnknownErrorException extends BaseException {
  519. constructor(msg, details) {
  520. super(msg, "UnknownErrorException");
  521. this.details = details;
  522. }
  523. }
  524. exports.UnknownErrorException = UnknownErrorException;
  525. class InvalidPDFException extends BaseException {
  526. constructor(msg) {
  527. super(msg, "InvalidPDFException");
  528. }
  529. }
  530. exports.InvalidPDFException = InvalidPDFException;
  531. class MissingPDFException extends BaseException {
  532. constructor(msg) {
  533. super(msg, "MissingPDFException");
  534. }
  535. }
  536. exports.MissingPDFException = MissingPDFException;
  537. class UnexpectedResponseException extends BaseException {
  538. constructor(msg, status) {
  539. super(msg, "UnexpectedResponseException");
  540. this.status = status;
  541. }
  542. }
  543. exports.UnexpectedResponseException = UnexpectedResponseException;
  544. class FormatError extends BaseException {
  545. constructor(msg) {
  546. super(msg, "FormatError");
  547. }
  548. }
  549. exports.FormatError = FormatError;
  550. class AbortException extends BaseException {
  551. constructor(msg) {
  552. super(msg, "AbortException");
  553. }
  554. }
  555. exports.AbortException = AbortException;
  556. function bytesToString(bytes) {
  557. if (typeof bytes !== "object" || bytes === null || bytes.length === undefined) {
  558. unreachable("Invalid argument for bytesToString");
  559. }
  560. const length = bytes.length;
  561. const MAX_ARGUMENT_COUNT = 8192;
  562. if (length < MAX_ARGUMENT_COUNT) {
  563. return String.fromCharCode.apply(null, bytes);
  564. }
  565. const strBuf = [];
  566. for (let i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  567. const chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  568. const chunk = bytes.subarray(i, chunkEnd);
  569. strBuf.push(String.fromCharCode.apply(null, chunk));
  570. }
  571. return strBuf.join("");
  572. }
  573. function stringToBytes(str) {
  574. if (typeof str !== "string") {
  575. unreachable("Invalid argument for stringToBytes");
  576. }
  577. const length = str.length;
  578. const bytes = new Uint8Array(length);
  579. for (let i = 0; i < length; ++i) {
  580. bytes[i] = str.charCodeAt(i) & 0xff;
  581. }
  582. return bytes;
  583. }
  584. function arrayByteLength(arr) {
  585. if (arr.length !== undefined) {
  586. return arr.length;
  587. }
  588. if (arr.byteLength !== undefined) {
  589. return arr.byteLength;
  590. }
  591. unreachable("Invalid argument for arrayByteLength");
  592. }
  593. function arraysToBytes(arr) {
  594. const length = arr.length;
  595. if (length === 1 && arr[0] instanceof Uint8Array) {
  596. return arr[0];
  597. }
  598. let resultLength = 0;
  599. for (let i = 0; i < length; i++) {
  600. resultLength += arrayByteLength(arr[i]);
  601. }
  602. let pos = 0;
  603. const data = new Uint8Array(resultLength);
  604. for (let i = 0; i < length; i++) {
  605. let item = arr[i];
  606. if (!(item instanceof Uint8Array)) {
  607. if (typeof item === "string") {
  608. item = stringToBytes(item);
  609. } else {
  610. item = new Uint8Array(item);
  611. }
  612. }
  613. const itemLength = item.byteLength;
  614. data.set(item, pos);
  615. pos += itemLength;
  616. }
  617. return data;
  618. }
  619. function string32(value) {
  620. return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
  621. }
  622. function objectSize(obj) {
  623. return Object.keys(obj).length;
  624. }
  625. function objectFromMap(map) {
  626. const obj = Object.create(null);
  627. for (const [key, value] of map) {
  628. obj[key] = value;
  629. }
  630. return obj;
  631. }
  632. function isLittleEndian() {
  633. const buffer8 = new Uint8Array(4);
  634. buffer8[0] = 1;
  635. const view32 = new Uint32Array(buffer8.buffer, 0, 1);
  636. return view32[0] === 1;
  637. }
  638. const IsLittleEndianCached = {
  639. get value() {
  640. return shadow(this, "value", isLittleEndian());
  641. }
  642. };
  643. exports.IsLittleEndianCached = IsLittleEndianCached;
  644. function isEvalSupported() {
  645. try {
  646. new Function("");
  647. return true;
  648. } catch (e) {
  649. return false;
  650. }
  651. }
  652. const IsEvalSupportedCached = {
  653. get value() {
  654. return shadow(this, "value", isEvalSupported());
  655. }
  656. };
  657. exports.IsEvalSupportedCached = IsEvalSupportedCached;
  658. const hexNumbers = [...Array(256).keys()].map(n => n.toString(16).padStart(2, "0"));
  659. class Util {
  660. static makeHexColor(r, g, b) {
  661. return `#${hexNumbers[r]}${hexNumbers[g]}${hexNumbers[b]}`;
  662. }
  663. static transform(m1, m2) {
  664. 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]];
  665. }
  666. static applyTransform(p, m) {
  667. const xt = p[0] * m[0] + p[1] * m[2] + m[4];
  668. const yt = p[0] * m[1] + p[1] * m[3] + m[5];
  669. return [xt, yt];
  670. }
  671. static applyInverseTransform(p, m) {
  672. const d = m[0] * m[3] - m[1] * m[2];
  673. const xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  674. const yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  675. return [xt, yt];
  676. }
  677. static getAxialAlignedBoundingBox(r, m) {
  678. const p1 = Util.applyTransform(r, m);
  679. const p2 = Util.applyTransform(r.slice(2, 4), m);
  680. const p3 = Util.applyTransform([r[0], r[3]], m);
  681. const p4 = Util.applyTransform([r[2], r[1]], m);
  682. 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])];
  683. }
  684. static inverseTransform(m) {
  685. const d = m[0] * m[3] - m[1] * m[2];
  686. 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];
  687. }
  688. static apply3dTransform(m, v) {
  689. 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]];
  690. }
  691. static singularValueDecompose2dScale(m) {
  692. const transpose = [m[0], m[2], m[1], m[3]];
  693. const a = m[0] * transpose[0] + m[1] * transpose[2];
  694. const b = m[0] * transpose[1] + m[1] * transpose[3];
  695. const c = m[2] * transpose[0] + m[3] * transpose[2];
  696. const d = m[2] * transpose[1] + m[3] * transpose[3];
  697. const first = (a + d) / 2;
  698. const second = Math.sqrt((a + d) ** 2 - 4 * (a * d - c * b)) / 2;
  699. const sx = first + second || 1;
  700. const sy = first - second || 1;
  701. return [Math.sqrt(sx), Math.sqrt(sy)];
  702. }
  703. static normalizeRect(rect) {
  704. const r = rect.slice(0);
  705. if (rect[0] > rect[2]) {
  706. r[0] = rect[2];
  707. r[2] = rect[0];
  708. }
  709. if (rect[1] > rect[3]) {
  710. r[1] = rect[3];
  711. r[3] = rect[1];
  712. }
  713. return r;
  714. }
  715. static intersect(rect1, rect2) {
  716. function compare(a, b) {
  717. return a - b;
  718. }
  719. const orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare);
  720. const orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare);
  721. const result = [];
  722. rect1 = Util.normalizeRect(rect1);
  723. rect2 = Util.normalizeRect(rect2);
  724. if (orderedX[0] === rect1[0] && orderedX[1] === rect2[0] || orderedX[0] === rect2[0] && orderedX[1] === rect1[0]) {
  725. result[0] = orderedX[1];
  726. result[2] = orderedX[2];
  727. } else {
  728. return null;
  729. }
  730. if (orderedY[0] === rect1[1] && orderedY[1] === rect2[1] || orderedY[0] === rect2[1] && orderedY[1] === rect1[1]) {
  731. result[1] = orderedY[1];
  732. result[3] = orderedY[2];
  733. } else {
  734. return null;
  735. }
  736. return result;
  737. }
  738. static bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3) {
  739. const tvalues = [],
  740. bounds = [[], []];
  741. let a, b, c, t, t1, t2, b2ac, sqrtb2ac;
  742. for (let i = 0; i < 2; ++i) {
  743. if (i === 0) {
  744. b = 6 * x0 - 12 * x1 + 6 * x2;
  745. a = -3 * x0 + 9 * x1 - 9 * x2 + 3 * x3;
  746. c = 3 * x1 - 3 * x0;
  747. } else {
  748. b = 6 * y0 - 12 * y1 + 6 * y2;
  749. a = -3 * y0 + 9 * y1 - 9 * y2 + 3 * y3;
  750. c = 3 * y1 - 3 * y0;
  751. }
  752. if (Math.abs(a) < 1e-12) {
  753. if (Math.abs(b) < 1e-12) {
  754. continue;
  755. }
  756. t = -c / b;
  757. if (0 < t && t < 1) {
  758. tvalues.push(t);
  759. }
  760. continue;
  761. }
  762. b2ac = b * b - 4 * c * a;
  763. sqrtb2ac = Math.sqrt(b2ac);
  764. if (b2ac < 0) {
  765. continue;
  766. }
  767. t1 = (-b + sqrtb2ac) / (2 * a);
  768. if (0 < t1 && t1 < 1) {
  769. tvalues.push(t1);
  770. }
  771. t2 = (-b - sqrtb2ac) / (2 * a);
  772. if (0 < t2 && t2 < 1) {
  773. tvalues.push(t2);
  774. }
  775. }
  776. let j = tvalues.length,
  777. mt;
  778. const jlen = j;
  779. while (j--) {
  780. t = tvalues[j];
  781. mt = 1 - t;
  782. bounds[0][j] = mt * mt * mt * x0 + 3 * mt * mt * t * x1 + 3 * mt * t * t * x2 + t * t * t * x3;
  783. bounds[1][j] = mt * mt * mt * y0 + 3 * mt * mt * t * y1 + 3 * mt * t * t * y2 + t * t * t * y3;
  784. }
  785. bounds[0][jlen] = x0;
  786. bounds[1][jlen] = y0;
  787. bounds[0][jlen + 1] = x3;
  788. bounds[1][jlen + 1] = y3;
  789. bounds[0].length = bounds[1].length = jlen + 2;
  790. return [Math.min(...bounds[0]), Math.min(...bounds[1]), Math.max(...bounds[0]), Math.max(...bounds[1])];
  791. }
  792. }
  793. exports.Util = Util;
  794. 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];
  795. function stringToPDFString(str) {
  796. if (str[0] >= "\xEF") {
  797. let encoding;
  798. if (str[0] === "\xFE" && str[1] === "\xFF") {
  799. encoding = "utf-16be";
  800. } else if (str[0] === "\xFF" && str[1] === "\xFE") {
  801. encoding = "utf-16le";
  802. } else if (str[0] === "\xEF" && str[1] === "\xBB" && str[2] === "\xBF") {
  803. encoding = "utf-8";
  804. }
  805. if (encoding) {
  806. try {
  807. const decoder = new TextDecoder(encoding, {
  808. fatal: true
  809. });
  810. const buffer = stringToBytes(str);
  811. return decoder.decode(buffer);
  812. } catch (ex) {
  813. warn(`stringToPDFString: "${ex}".`);
  814. }
  815. }
  816. }
  817. const strBuf = [];
  818. for (let i = 0, ii = str.length; i < ii; i++) {
  819. const code = PDFStringTranslateTable[str.charCodeAt(i)];
  820. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  821. }
  822. return strBuf.join("");
  823. }
  824. function escapeString(str) {
  825. return str.replace(/([()\\\n\r])/g, match => {
  826. if (match === "\n") {
  827. return "\\n";
  828. } else if (match === "\r") {
  829. return "\\r";
  830. }
  831. return `\\${match}`;
  832. });
  833. }
  834. function isAscii(str) {
  835. return /^[\x00-\x7F]*$/.test(str);
  836. }
  837. function stringToUTF16BEString(str) {
  838. const buf = ["\xFE\xFF"];
  839. for (let i = 0, ii = str.length; i < ii; i++) {
  840. const char = str.charCodeAt(i);
  841. buf.push(String.fromCharCode(char >> 8 & 0xff), String.fromCharCode(char & 0xff));
  842. }
  843. return buf.join("");
  844. }
  845. function stringToUTF8String(str) {
  846. return decodeURIComponent(escape(str));
  847. }
  848. function utf8StringToString(str) {
  849. return unescape(encodeURIComponent(str));
  850. }
  851. function isArrayBuffer(v) {
  852. return typeof v === "object" && v !== null && v.byteLength !== undefined;
  853. }
  854. function isArrayEqual(arr1, arr2) {
  855. if (arr1.length !== arr2.length) {
  856. return false;
  857. }
  858. for (let i = 0, ii = arr1.length; i < ii; i++) {
  859. if (arr1[i] !== arr2[i]) {
  860. return false;
  861. }
  862. }
  863. return true;
  864. }
  865. function getModificationDate(date = new Date()) {
  866. 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")];
  867. return buffer.join("");
  868. }
  869. function createPromiseCapability() {
  870. const capability = Object.create(null);
  871. let isSettled = false;
  872. Object.defineProperty(capability, "settled", {
  873. get() {
  874. return isSettled;
  875. }
  876. });
  877. capability.promise = new Promise(function (resolve, reject) {
  878. capability.resolve = function (data) {
  879. isSettled = true;
  880. resolve(data);
  881. };
  882. capability.reject = function (reason) {
  883. isSettled = true;
  884. reject(reason);
  885. };
  886. });
  887. return capability;
  888. }
  889. /***/ }),
  890. /* 2 */
  891. /***/ ((__unused_webpack_module, __unused_webpack_exports, __w_pdfjs_require__) => {
  892. var _is_node = __w_pdfjs_require__(3);
  893. ;
  894. /***/ }),
  895. /* 3 */
  896. /***/ ((__unused_webpack_module, exports) => {
  897. Object.defineProperty(exports, "__esModule", ({
  898. value: true
  899. }));
  900. exports.isNodeJS = void 0;
  901. const isNodeJS = typeof process === "object" && process + "" === "[object process]" && !process.versions.nw && !(process.versions.electron && process.type && process.type !== "browser");
  902. exports.isNodeJS = isNodeJS;
  903. /***/ }),
  904. /* 4 */
  905. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  906. Object.defineProperty(exports, "__esModule", ({
  907. value: true
  908. }));
  909. exports.build = exports.RenderTask = exports.PDFWorker = exports.PDFPageProxy = exports.PDFDocumentProxy = exports.PDFDocumentLoadingTask = exports.PDFDataRangeTransport = exports.LoopbackPort = exports.DefaultStandardFontDataFactory = exports.DefaultCanvasFactory = exports.DefaultCMapReaderFactory = void 0;
  910. exports.getDocument = getDocument;
  911. exports.setPDFNetworkStreamFactory = setPDFNetworkStreamFactory;
  912. exports.version = void 0;
  913. var _util = __w_pdfjs_require__(1);
  914. var _display_utils = __w_pdfjs_require__(5);
  915. var _font_loader = __w_pdfjs_require__(7);
  916. var _node_utils = __w_pdfjs_require__(8);
  917. var _annotation_storage = __w_pdfjs_require__(9);
  918. var _canvas = __w_pdfjs_require__(10);
  919. var _worker_options = __w_pdfjs_require__(12);
  920. var _is_node = __w_pdfjs_require__(3);
  921. var _message_handler = __w_pdfjs_require__(13);
  922. var _metadata = __w_pdfjs_require__(14);
  923. var _optional_content_config = __w_pdfjs_require__(15);
  924. var _transport_stream = __w_pdfjs_require__(16);
  925. var _xfa_text = __w_pdfjs_require__(17);
  926. const DEFAULT_RANGE_CHUNK_SIZE = 65536;
  927. const RENDERING_CANCELLED_TIMEOUT = 100;
  928. const DefaultCanvasFactory = _is_node.isNodeJS ? _node_utils.NodeCanvasFactory : _display_utils.DOMCanvasFactory;
  929. exports.DefaultCanvasFactory = DefaultCanvasFactory;
  930. const DefaultCMapReaderFactory = _is_node.isNodeJS ? _node_utils.NodeCMapReaderFactory : _display_utils.DOMCMapReaderFactory;
  931. exports.DefaultCMapReaderFactory = DefaultCMapReaderFactory;
  932. const DefaultStandardFontDataFactory = _is_node.isNodeJS ? _node_utils.NodeStandardFontDataFactory : _display_utils.DOMStandardFontDataFactory;
  933. exports.DefaultStandardFontDataFactory = DefaultStandardFontDataFactory;
  934. let createPDFNetworkStream;
  935. function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) {
  936. createPDFNetworkStream = pdfNetworkStreamFactory;
  937. }
  938. function getDocument(src) {
  939. const task = new PDFDocumentLoadingTask();
  940. let source;
  941. if (typeof src === "string" || src instanceof URL) {
  942. source = {
  943. url: src
  944. };
  945. } else if ((0, _util.isArrayBuffer)(src)) {
  946. source = {
  947. data: src
  948. };
  949. } else if (src instanceof PDFDataRangeTransport) {
  950. source = {
  951. range: src
  952. };
  953. } else {
  954. if (typeof src !== "object") {
  955. throw new Error("Invalid parameter in getDocument, " + "need either string, URL, Uint8Array, or parameter object.");
  956. }
  957. if (!src.url && !src.data && !src.range) {
  958. throw new Error("Invalid parameter object: need either .data, .range or .url");
  959. }
  960. source = src;
  961. }
  962. const params = Object.create(null);
  963. let rangeTransport = null,
  964. worker = null;
  965. for (const key in source) {
  966. const value = source[key];
  967. switch (key) {
  968. case "url":
  969. if (typeof window !== "undefined") {
  970. try {
  971. params[key] = new URL(value, window.location).href;
  972. continue;
  973. } catch (ex) {
  974. (0, _util.warn)(`Cannot create valid URL: "${ex}".`);
  975. }
  976. } else if (typeof value === "string" || value instanceof URL) {
  977. params[key] = value.toString();
  978. continue;
  979. }
  980. throw new Error("Invalid PDF url data: " + "either string or URL-object is expected in the url property.");
  981. case "range":
  982. rangeTransport = value;
  983. continue;
  984. case "worker":
  985. worker = value;
  986. continue;
  987. case "data":
  988. if (_is_node.isNodeJS && typeof Buffer !== "undefined" && value instanceof Buffer) {
  989. params[key] = new Uint8Array(value);
  990. } else if (value instanceof Uint8Array) {
  991. break;
  992. } else if (typeof value === "string") {
  993. params[key] = (0, _util.stringToBytes)(value);
  994. } else if (typeof value === "object" && value !== null && !isNaN(value.length)) {
  995. params[key] = new Uint8Array(value);
  996. } else if ((0, _util.isArrayBuffer)(value)) {
  997. params[key] = new Uint8Array(value);
  998. } else {
  999. throw new Error("Invalid PDF binary data: either typed array, " + "string, or array-like object is expected in the data property.");
  1000. }
  1001. continue;
  1002. }
  1003. params[key] = value;
  1004. }
  1005. params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
  1006. params.CMapReaderFactory = params.CMapReaderFactory || DefaultCMapReaderFactory;
  1007. params.StandardFontDataFactory = params.StandardFontDataFactory || DefaultStandardFontDataFactory;
  1008. params.ignoreErrors = params.stopAtErrors !== true;
  1009. params.fontExtraProperties = params.fontExtraProperties === true;
  1010. params.pdfBug = params.pdfBug === true;
  1011. params.enableXfa = params.enableXfa === true;
  1012. if (typeof params.docBaseUrl !== "string" || (0, _display_utils.isDataScheme)(params.docBaseUrl)) {
  1013. params.docBaseUrl = null;
  1014. }
  1015. if (!Number.isInteger(params.maxImageSize)) {
  1016. params.maxImageSize = -1;
  1017. }
  1018. if (typeof params.useWorkerFetch !== "boolean") {
  1019. params.useWorkerFetch = params.CMapReaderFactory === _display_utils.DOMCMapReaderFactory && params.StandardFontDataFactory === _display_utils.DOMStandardFontDataFactory;
  1020. }
  1021. if (typeof params.isEvalSupported !== "boolean") {
  1022. params.isEvalSupported = true;
  1023. }
  1024. if (typeof params.disableFontFace !== "boolean") {
  1025. params.disableFontFace = _is_node.isNodeJS;
  1026. }
  1027. if (typeof params.useSystemFonts !== "boolean") {
  1028. params.useSystemFonts = !_is_node.isNodeJS && !params.disableFontFace;
  1029. }
  1030. if (typeof params.ownerDocument === "undefined") {
  1031. params.ownerDocument = globalThis.document;
  1032. }
  1033. if (typeof params.disableRange !== "boolean") {
  1034. params.disableRange = false;
  1035. }
  1036. if (typeof params.disableStream !== "boolean") {
  1037. params.disableStream = false;
  1038. }
  1039. if (typeof params.disableAutoFetch !== "boolean") {
  1040. params.disableAutoFetch = false;
  1041. }
  1042. (0, _util.setVerbosityLevel)(params.verbosity);
  1043. if (!worker) {
  1044. const workerParams = {
  1045. verbosity: params.verbosity,
  1046. port: _worker_options.GlobalWorkerOptions.workerPort
  1047. };
  1048. worker = workerParams.port ? PDFWorker.fromPort(workerParams) : new PDFWorker(workerParams);
  1049. task._worker = worker;
  1050. }
  1051. const docId = task.docId;
  1052. worker.promise.then(function () {
  1053. if (task.destroyed) {
  1054. throw new Error("Loading aborted");
  1055. }
  1056. const workerIdPromise = _fetchDocument(worker, params, rangeTransport, docId);
  1057. const networkStreamPromise = new Promise(function (resolve) {
  1058. let networkStream;
  1059. if (rangeTransport) {
  1060. networkStream = new _transport_stream.PDFDataTransportStream({
  1061. length: params.length,
  1062. initialData: params.initialData,
  1063. progressiveDone: params.progressiveDone,
  1064. contentDispositionFilename: params.contentDispositionFilename,
  1065. disableRange: params.disableRange,
  1066. disableStream: params.disableStream
  1067. }, rangeTransport);
  1068. } else if (!params.data) {
  1069. networkStream = createPDFNetworkStream({
  1070. url: params.url,
  1071. length: params.length,
  1072. httpHeaders: params.httpHeaders,
  1073. withCredentials: params.withCredentials,
  1074. rangeChunkSize: params.rangeChunkSize,
  1075. disableRange: params.disableRange,
  1076. disableStream: params.disableStream
  1077. });
  1078. }
  1079. resolve(networkStream);
  1080. });
  1081. return Promise.all([workerIdPromise, networkStreamPromise]).then(function ([workerId, networkStream]) {
  1082. if (task.destroyed) {
  1083. throw new Error("Loading aborted");
  1084. }
  1085. const messageHandler = new _message_handler.MessageHandler(docId, workerId, worker.port);
  1086. const transport = new WorkerTransport(messageHandler, task, networkStream, params);
  1087. task._transport = transport;
  1088. messageHandler.send("Ready", null);
  1089. });
  1090. }).catch(task._capability.reject);
  1091. return task;
  1092. }
  1093. async function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
  1094. if (worker.destroyed) {
  1095. throw new Error("Worker was destroyed");
  1096. }
  1097. if (pdfDataRangeTransport) {
  1098. source.length = pdfDataRangeTransport.length;
  1099. source.initialData = pdfDataRangeTransport.initialData;
  1100. source.progressiveDone = pdfDataRangeTransport.progressiveDone;
  1101. source.contentDispositionFilename = pdfDataRangeTransport.contentDispositionFilename;
  1102. }
  1103. const workerId = await worker.messageHandler.sendWithPromise("GetDocRequest", {
  1104. docId,
  1105. apiVersion: '2.13.216',
  1106. source: {
  1107. data: source.data,
  1108. url: source.url,
  1109. password: source.password,
  1110. disableAutoFetch: source.disableAutoFetch,
  1111. rangeChunkSize: source.rangeChunkSize,
  1112. length: source.length
  1113. },
  1114. maxImageSize: source.maxImageSize,
  1115. disableFontFace: source.disableFontFace,
  1116. docBaseUrl: source.docBaseUrl,
  1117. ignoreErrors: source.ignoreErrors,
  1118. isEvalSupported: source.isEvalSupported,
  1119. fontExtraProperties: source.fontExtraProperties,
  1120. enableXfa: source.enableXfa,
  1121. useSystemFonts: source.useSystemFonts,
  1122. cMapUrl: source.useWorkerFetch ? source.cMapUrl : null,
  1123. standardFontDataUrl: source.useWorkerFetch ? source.standardFontDataUrl : null
  1124. });
  1125. if (worker.destroyed) {
  1126. throw new Error("Worker was destroyed");
  1127. }
  1128. return workerId;
  1129. }
  1130. class PDFDocumentLoadingTask {
  1131. static get idCounters() {
  1132. return (0, _util.shadow)(this, "idCounters", {
  1133. doc: 0
  1134. });
  1135. }
  1136. constructor() {
  1137. this._capability = (0, _util.createPromiseCapability)();
  1138. this._transport = null;
  1139. this._worker = null;
  1140. this.docId = `d${PDFDocumentLoadingTask.idCounters.doc++}`;
  1141. this.destroyed = false;
  1142. this.onPassword = null;
  1143. this.onProgress = null;
  1144. this.onUnsupportedFeature = null;
  1145. }
  1146. get promise() {
  1147. return this._capability.promise;
  1148. }
  1149. async destroy() {
  1150. this.destroyed = true;
  1151. await this._transport?.destroy();
  1152. this._transport = null;
  1153. if (this._worker) {
  1154. this._worker.destroy();
  1155. this._worker = null;
  1156. }
  1157. }
  1158. }
  1159. exports.PDFDocumentLoadingTask = PDFDocumentLoadingTask;
  1160. class PDFDataRangeTransport {
  1161. constructor(length, initialData, progressiveDone = false, contentDispositionFilename = null) {
  1162. this.length = length;
  1163. this.initialData = initialData;
  1164. this.progressiveDone = progressiveDone;
  1165. this.contentDispositionFilename = contentDispositionFilename;
  1166. this._rangeListeners = [];
  1167. this._progressListeners = [];
  1168. this._progressiveReadListeners = [];
  1169. this._progressiveDoneListeners = [];
  1170. this._readyCapability = (0, _util.createPromiseCapability)();
  1171. }
  1172. addRangeListener(listener) {
  1173. this._rangeListeners.push(listener);
  1174. }
  1175. addProgressListener(listener) {
  1176. this._progressListeners.push(listener);
  1177. }
  1178. addProgressiveReadListener(listener) {
  1179. this._progressiveReadListeners.push(listener);
  1180. }
  1181. addProgressiveDoneListener(listener) {
  1182. this._progressiveDoneListeners.push(listener);
  1183. }
  1184. onDataRange(begin, chunk) {
  1185. for (const listener of this._rangeListeners) {
  1186. listener(begin, chunk);
  1187. }
  1188. }
  1189. onDataProgress(loaded, total) {
  1190. this._readyCapability.promise.then(() => {
  1191. for (const listener of this._progressListeners) {
  1192. listener(loaded, total);
  1193. }
  1194. });
  1195. }
  1196. onDataProgressiveRead(chunk) {
  1197. this._readyCapability.promise.then(() => {
  1198. for (const listener of this._progressiveReadListeners) {
  1199. listener(chunk);
  1200. }
  1201. });
  1202. }
  1203. onDataProgressiveDone() {
  1204. this._readyCapability.promise.then(() => {
  1205. for (const listener of this._progressiveDoneListeners) {
  1206. listener();
  1207. }
  1208. });
  1209. }
  1210. transportReady() {
  1211. this._readyCapability.resolve();
  1212. }
  1213. requestDataRange(begin, end) {
  1214. (0, _util.unreachable)("Abstract method PDFDataRangeTransport.requestDataRange");
  1215. }
  1216. abort() {}
  1217. }
  1218. exports.PDFDataRangeTransport = PDFDataRangeTransport;
  1219. class PDFDocumentProxy {
  1220. constructor(pdfInfo, transport) {
  1221. this._pdfInfo = pdfInfo;
  1222. this._transport = transport;
  1223. Object.defineProperty(this, "fingerprint", {
  1224. get() {
  1225. (0, _display_utils.deprecated)("`PDFDocumentProxy.fingerprint`, " + "please use `PDFDocumentProxy.fingerprints` instead.");
  1226. return this.fingerprints[0];
  1227. }
  1228. });
  1229. Object.defineProperty(this, "getStats", {
  1230. value: async () => {
  1231. (0, _display_utils.deprecated)("`PDFDocumentProxy.getStats`, " + "please use the `PDFDocumentProxy.stats`-getter instead.");
  1232. return this.stats || {
  1233. streamTypes: {},
  1234. fontTypes: {}
  1235. };
  1236. }
  1237. });
  1238. }
  1239. get annotationStorage() {
  1240. return this._transport.annotationStorage;
  1241. }
  1242. get numPages() {
  1243. return this._pdfInfo.numPages;
  1244. }
  1245. get fingerprints() {
  1246. return this._pdfInfo.fingerprints;
  1247. }
  1248. get stats() {
  1249. return this._transport.stats;
  1250. }
  1251. get isPureXfa() {
  1252. return !!this._transport._htmlForXfa;
  1253. }
  1254. get allXfaHtml() {
  1255. return this._transport._htmlForXfa;
  1256. }
  1257. getPage(pageNumber) {
  1258. return this._transport.getPage(pageNumber);
  1259. }
  1260. getPageIndex(ref) {
  1261. return this._transport.getPageIndex(ref);
  1262. }
  1263. getDestinations() {
  1264. return this._transport.getDestinations();
  1265. }
  1266. getDestination(id) {
  1267. return this._transport.getDestination(id);
  1268. }
  1269. getPageLabels() {
  1270. return this._transport.getPageLabels();
  1271. }
  1272. getPageLayout() {
  1273. return this._transport.getPageLayout();
  1274. }
  1275. getPageMode() {
  1276. return this._transport.getPageMode();
  1277. }
  1278. getViewerPreferences() {
  1279. return this._transport.getViewerPreferences();
  1280. }
  1281. getOpenAction() {
  1282. return this._transport.getOpenAction();
  1283. }
  1284. getAttachments() {
  1285. return this._transport.getAttachments();
  1286. }
  1287. getJavaScript() {
  1288. return this._transport.getJavaScript();
  1289. }
  1290. getJSActions() {
  1291. return this._transport.getDocJSActions();
  1292. }
  1293. getOutline() {
  1294. return this._transport.getOutline();
  1295. }
  1296. getOptionalContentConfig() {
  1297. return this._transport.getOptionalContentConfig();
  1298. }
  1299. getPermissions() {
  1300. return this._transport.getPermissions();
  1301. }
  1302. getMetadata() {
  1303. return this._transport.getMetadata();
  1304. }
  1305. getMarkInfo() {
  1306. return this._transport.getMarkInfo();
  1307. }
  1308. getData() {
  1309. return this._transport.getData();
  1310. }
  1311. getDownloadInfo() {
  1312. return this._transport.downloadInfoCapability.promise;
  1313. }
  1314. cleanup(keepLoadedFonts = false) {
  1315. return this._transport.startCleanup(keepLoadedFonts || this.isPureXfa);
  1316. }
  1317. destroy() {
  1318. return this.loadingTask.destroy();
  1319. }
  1320. get loadingParams() {
  1321. return this._transport.loadingParams;
  1322. }
  1323. get loadingTask() {
  1324. return this._transport.loadingTask;
  1325. }
  1326. saveDocument() {
  1327. if (this._transport.annotationStorage.size <= 0) {
  1328. (0, _display_utils.deprecated)("saveDocument called while `annotationStorage` is empty, " + "please use the getData-method instead.");
  1329. }
  1330. return this._transport.saveDocument();
  1331. }
  1332. getFieldObjects() {
  1333. return this._transport.getFieldObjects();
  1334. }
  1335. hasJSActions() {
  1336. return this._transport.hasJSActions();
  1337. }
  1338. getCalculationOrderIds() {
  1339. return this._transport.getCalculationOrderIds();
  1340. }
  1341. }
  1342. exports.PDFDocumentProxy = PDFDocumentProxy;
  1343. class PDFPageProxy {
  1344. constructor(pageIndex, pageInfo, transport, ownerDocument, pdfBug = false) {
  1345. this._pageIndex = pageIndex;
  1346. this._pageInfo = pageInfo;
  1347. this._ownerDocument = ownerDocument;
  1348. this._transport = transport;
  1349. this._stats = pdfBug ? new _display_utils.StatTimer() : null;
  1350. this._pdfBug = pdfBug;
  1351. this.commonObjs = transport.commonObjs;
  1352. this.objs = new PDFObjects();
  1353. this.cleanupAfterRender = false;
  1354. this.pendingCleanup = false;
  1355. this._intentStates = new Map();
  1356. this._annotationPromises = new Map();
  1357. this.destroyed = false;
  1358. }
  1359. get pageNumber() {
  1360. return this._pageIndex + 1;
  1361. }
  1362. get rotate() {
  1363. return this._pageInfo.rotate;
  1364. }
  1365. get ref() {
  1366. return this._pageInfo.ref;
  1367. }
  1368. get userUnit() {
  1369. return this._pageInfo.userUnit;
  1370. }
  1371. get view() {
  1372. return this._pageInfo.view;
  1373. }
  1374. getViewport({
  1375. scale,
  1376. rotation = this.rotate,
  1377. offsetX = 0,
  1378. offsetY = 0,
  1379. dontFlip = false
  1380. } = {}) {
  1381. return new _display_utils.PageViewport({
  1382. viewBox: this.view,
  1383. scale,
  1384. rotation,
  1385. offsetX,
  1386. offsetY,
  1387. dontFlip
  1388. });
  1389. }
  1390. getAnnotations({
  1391. intent = "display"
  1392. } = {}) {
  1393. const intentArgs = this._transport.getRenderingIntent(intent);
  1394. let promise = this._annotationPromises.get(intentArgs.cacheKey);
  1395. if (!promise) {
  1396. promise = this._transport.getAnnotations(this._pageIndex, intentArgs.renderingIntent);
  1397. this._annotationPromises.set(intentArgs.cacheKey, promise);
  1398. promise = promise.then(annotations => {
  1399. for (const annotation of annotations) {
  1400. if (annotation.titleObj !== undefined) {
  1401. Object.defineProperty(annotation, "title", {
  1402. get() {
  1403. (0, _display_utils.deprecated)("`title`-property on annotation, please use `titleObj` instead.");
  1404. return annotation.titleObj.str;
  1405. }
  1406. });
  1407. }
  1408. if (annotation.contentsObj !== undefined) {
  1409. Object.defineProperty(annotation, "contents", {
  1410. get() {
  1411. (0, _display_utils.deprecated)("`contents`-property on annotation, please use `contentsObj` instead.");
  1412. return annotation.contentsObj.str;
  1413. }
  1414. });
  1415. }
  1416. }
  1417. return annotations;
  1418. });
  1419. }
  1420. return promise;
  1421. }
  1422. getJSActions() {
  1423. return this._jsActionsPromise ||= this._transport.getPageJSActions(this._pageIndex);
  1424. }
  1425. async getXfa() {
  1426. return this._transport._htmlForXfa?.children[this._pageIndex] || null;
  1427. }
  1428. render({
  1429. canvasContext,
  1430. viewport,
  1431. intent = "display",
  1432. annotationMode = _util.AnnotationMode.ENABLE,
  1433. transform = null,
  1434. imageLayer = null,
  1435. canvasFactory = null,
  1436. background = null,
  1437. optionalContentConfigPromise = null,
  1438. annotationCanvasMap = null
  1439. }) {
  1440. if (arguments[0]?.renderInteractiveForms !== undefined) {
  1441. (0, _display_utils.deprecated)("render no longer accepts the `renderInteractiveForms`-option, " + "please use the `annotationMode`-option instead.");
  1442. if (arguments[0].renderInteractiveForms === true && annotationMode === _util.AnnotationMode.ENABLE) {
  1443. annotationMode = _util.AnnotationMode.ENABLE_FORMS;
  1444. }
  1445. }
  1446. if (arguments[0]?.includeAnnotationStorage !== undefined) {
  1447. (0, _display_utils.deprecated)("render no longer accepts the `includeAnnotationStorage`-option, " + "please use the `annotationMode`-option instead.");
  1448. if (arguments[0].includeAnnotationStorage === true && annotationMode === _util.AnnotationMode.ENABLE) {
  1449. annotationMode = _util.AnnotationMode.ENABLE_STORAGE;
  1450. }
  1451. }
  1452. if (this._stats) {
  1453. this._stats.time("Overall");
  1454. }
  1455. const intentArgs = this._transport.getRenderingIntent(intent, annotationMode);
  1456. this.pendingCleanup = false;
  1457. if (!optionalContentConfigPromise) {
  1458. optionalContentConfigPromise = this._transport.getOptionalContentConfig();
  1459. }
  1460. let intentState = this._intentStates.get(intentArgs.cacheKey);
  1461. if (!intentState) {
  1462. intentState = Object.create(null);
  1463. this._intentStates.set(intentArgs.cacheKey, intentState);
  1464. }
  1465. if (intentState.streamReaderCancelTimeout) {
  1466. clearTimeout(intentState.streamReaderCancelTimeout);
  1467. intentState.streamReaderCancelTimeout = null;
  1468. }
  1469. const canvasFactoryInstance = canvasFactory || new DefaultCanvasFactory({
  1470. ownerDocument: this._ownerDocument
  1471. });
  1472. const intentPrint = !!(intentArgs.renderingIntent & _util.RenderingIntentFlag.PRINT);
  1473. if (!intentState.displayReadyCapability) {
  1474. intentState.displayReadyCapability = (0, _util.createPromiseCapability)();
  1475. intentState.operatorList = {
  1476. fnArray: [],
  1477. argsArray: [],
  1478. lastChunk: false
  1479. };
  1480. if (this._stats) {
  1481. this._stats.time("Page Request");
  1482. }
  1483. this._pumpOperatorList(intentArgs);
  1484. }
  1485. const complete = error => {
  1486. intentState.renderTasks.delete(internalRenderTask);
  1487. if (this.cleanupAfterRender || intentPrint) {
  1488. this.pendingCleanup = true;
  1489. }
  1490. this._tryCleanup();
  1491. if (error) {
  1492. internalRenderTask.capability.reject(error);
  1493. this._abortOperatorList({
  1494. intentState,
  1495. reason: error instanceof Error ? error : new Error(error)
  1496. });
  1497. } else {
  1498. internalRenderTask.capability.resolve();
  1499. }
  1500. if (this._stats) {
  1501. this._stats.timeEnd("Rendering");
  1502. this._stats.timeEnd("Overall");
  1503. }
  1504. };
  1505. const internalRenderTask = new InternalRenderTask({
  1506. callback: complete,
  1507. params: {
  1508. canvasContext,
  1509. viewport,
  1510. transform,
  1511. imageLayer,
  1512. background
  1513. },
  1514. objs: this.objs,
  1515. commonObjs: this.commonObjs,
  1516. annotationCanvasMap,
  1517. operatorList: intentState.operatorList,
  1518. pageIndex: this._pageIndex,
  1519. canvasFactory: canvasFactoryInstance,
  1520. useRequestAnimationFrame: !intentPrint,
  1521. pdfBug: this._pdfBug
  1522. });
  1523. (intentState.renderTasks ||= new Set()).add(internalRenderTask);
  1524. const renderTask = internalRenderTask.task;
  1525. Promise.all([intentState.displayReadyCapability.promise, optionalContentConfigPromise]).then(([transparency, optionalContentConfig]) => {
  1526. if (this.pendingCleanup) {
  1527. complete();
  1528. return;
  1529. }
  1530. if (this._stats) {
  1531. this._stats.time("Rendering");
  1532. }
  1533. internalRenderTask.initializeGraphics({
  1534. transparency,
  1535. optionalContentConfig
  1536. });
  1537. internalRenderTask.operatorListChanged();
  1538. }).catch(complete);
  1539. return renderTask;
  1540. }
  1541. getOperatorList({
  1542. intent = "display",
  1543. annotationMode = _util.AnnotationMode.ENABLE
  1544. } = {}) {
  1545. function operatorListChanged() {
  1546. if (intentState.operatorList.lastChunk) {
  1547. intentState.opListReadCapability.resolve(intentState.operatorList);
  1548. intentState.renderTasks.delete(opListTask);
  1549. }
  1550. }
  1551. const intentArgs = this._transport.getRenderingIntent(intent, annotationMode, true);
  1552. let intentState = this._intentStates.get(intentArgs.cacheKey);
  1553. if (!intentState) {
  1554. intentState = Object.create(null);
  1555. this._intentStates.set(intentArgs.cacheKey, intentState);
  1556. }
  1557. let opListTask;
  1558. if (!intentState.opListReadCapability) {
  1559. opListTask = Object.create(null);
  1560. opListTask.operatorListChanged = operatorListChanged;
  1561. intentState.opListReadCapability = (0, _util.createPromiseCapability)();
  1562. (intentState.renderTasks ||= new Set()).add(opListTask);
  1563. intentState.operatorList = {
  1564. fnArray: [],
  1565. argsArray: [],
  1566. lastChunk: false
  1567. };
  1568. if (this._stats) {
  1569. this._stats.time("Page Request");
  1570. }
  1571. this._pumpOperatorList(intentArgs);
  1572. }
  1573. return intentState.opListReadCapability.promise;
  1574. }
  1575. streamTextContent({
  1576. disableCombineTextItems = false,
  1577. includeMarkedContent = false
  1578. } = {}) {
  1579. const TEXT_CONTENT_CHUNK_SIZE = 100;
  1580. return this._transport.messageHandler.sendWithStream("GetTextContent", {
  1581. pageIndex: this._pageIndex,
  1582. combineTextItems: disableCombineTextItems !== true,
  1583. includeMarkedContent: includeMarkedContent === true
  1584. }, {
  1585. highWaterMark: TEXT_CONTENT_CHUNK_SIZE,
  1586. size(textContent) {
  1587. return textContent.items.length;
  1588. }
  1589. });
  1590. }
  1591. getTextContent(params = {}) {
  1592. if (this._transport._htmlForXfa) {
  1593. return this.getXfa().then(xfa => {
  1594. return _xfa_text.XfaText.textContent(xfa);
  1595. });
  1596. }
  1597. const readableStream = this.streamTextContent(params);
  1598. return new Promise(function (resolve, reject) {
  1599. function pump() {
  1600. reader.read().then(function ({
  1601. value,
  1602. done
  1603. }) {
  1604. if (done) {
  1605. resolve(textContent);
  1606. return;
  1607. }
  1608. Object.assign(textContent.styles, value.styles);
  1609. textContent.items.push(...value.items);
  1610. pump();
  1611. }, reject);
  1612. }
  1613. const reader = readableStream.getReader();
  1614. const textContent = {
  1615. items: [],
  1616. styles: Object.create(null)
  1617. };
  1618. pump();
  1619. });
  1620. }
  1621. getStructTree() {
  1622. return this._structTreePromise ||= this._transport.getStructTree(this._pageIndex);
  1623. }
  1624. _destroy() {
  1625. this.destroyed = true;
  1626. const waitOn = [];
  1627. for (const intentState of this._intentStates.values()) {
  1628. this._abortOperatorList({
  1629. intentState,
  1630. reason: new Error("Page was destroyed."),
  1631. force: true
  1632. });
  1633. if (intentState.opListReadCapability) {
  1634. continue;
  1635. }
  1636. for (const internalRenderTask of intentState.renderTasks) {
  1637. waitOn.push(internalRenderTask.completed);
  1638. internalRenderTask.cancel();
  1639. }
  1640. }
  1641. this.objs.clear();
  1642. this._annotationPromises.clear();
  1643. this._jsActionsPromise = null;
  1644. this._structTreePromise = null;
  1645. this.pendingCleanup = false;
  1646. return Promise.all(waitOn);
  1647. }
  1648. cleanup(resetStats = false) {
  1649. this.pendingCleanup = true;
  1650. return this._tryCleanup(resetStats);
  1651. }
  1652. _tryCleanup(resetStats = false) {
  1653. if (!this.pendingCleanup) {
  1654. return false;
  1655. }
  1656. for (const {
  1657. renderTasks,
  1658. operatorList
  1659. } of this._intentStates.values()) {
  1660. if (renderTasks.size > 0 || !operatorList.lastChunk) {
  1661. return false;
  1662. }
  1663. }
  1664. this._intentStates.clear();
  1665. this.objs.clear();
  1666. this._annotationPromises.clear();
  1667. this._jsActionsPromise = null;
  1668. this._structTreePromise = null;
  1669. if (resetStats && this._stats) {
  1670. this._stats = new _display_utils.StatTimer();
  1671. }
  1672. this.pendingCleanup = false;
  1673. return true;
  1674. }
  1675. _startRenderPage(transparency, cacheKey) {
  1676. const intentState = this._intentStates.get(cacheKey);
  1677. if (!intentState) {
  1678. return;
  1679. }
  1680. if (this._stats) {
  1681. this._stats.timeEnd("Page Request");
  1682. }
  1683. if (intentState.displayReadyCapability) {
  1684. intentState.displayReadyCapability.resolve(transparency);
  1685. }
  1686. }
  1687. _renderPageChunk(operatorListChunk, intentState) {
  1688. for (let i = 0, ii = operatorListChunk.length; i < ii; i++) {
  1689. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  1690. intentState.operatorList.argsArray.push(operatorListChunk.argsArray[i]);
  1691. }
  1692. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  1693. for (const internalRenderTask of intentState.renderTasks) {
  1694. internalRenderTask.operatorListChanged();
  1695. }
  1696. if (operatorListChunk.lastChunk) {
  1697. this._tryCleanup();
  1698. }
  1699. }
  1700. _pumpOperatorList({
  1701. renderingIntent,
  1702. cacheKey
  1703. }) {
  1704. const readableStream = this._transport.messageHandler.sendWithStream("GetOperatorList", {
  1705. pageIndex: this._pageIndex,
  1706. intent: renderingIntent,
  1707. cacheKey,
  1708. annotationStorage: renderingIntent & _util.RenderingIntentFlag.ANNOTATIONS_STORAGE ? this._transport.annotationStorage.serializable : null
  1709. });
  1710. const reader = readableStream.getReader();
  1711. const intentState = this._intentStates.get(cacheKey);
  1712. intentState.streamReader = reader;
  1713. const pump = () => {
  1714. reader.read().then(({
  1715. value,
  1716. done
  1717. }) => {
  1718. if (done) {
  1719. intentState.streamReader = null;
  1720. return;
  1721. }
  1722. if (this._transport.destroyed) {
  1723. return;
  1724. }
  1725. this._renderPageChunk(value, intentState);
  1726. pump();
  1727. }, reason => {
  1728. intentState.streamReader = null;
  1729. if (this._transport.destroyed) {
  1730. return;
  1731. }
  1732. if (intentState.operatorList) {
  1733. intentState.operatorList.lastChunk = true;
  1734. for (const internalRenderTask of intentState.renderTasks) {
  1735. internalRenderTask.operatorListChanged();
  1736. }
  1737. this._tryCleanup();
  1738. }
  1739. if (intentState.displayReadyCapability) {
  1740. intentState.displayReadyCapability.reject(reason);
  1741. } else if (intentState.opListReadCapability) {
  1742. intentState.opListReadCapability.reject(reason);
  1743. } else {
  1744. throw reason;
  1745. }
  1746. });
  1747. };
  1748. pump();
  1749. }
  1750. _abortOperatorList({
  1751. intentState,
  1752. reason,
  1753. force = false
  1754. }) {
  1755. if (!intentState.streamReader) {
  1756. return;
  1757. }
  1758. if (!force) {
  1759. if (intentState.renderTasks.size > 0) {
  1760. return;
  1761. }
  1762. if (reason instanceof _display_utils.RenderingCancelledException) {
  1763. intentState.streamReaderCancelTimeout = setTimeout(() => {
  1764. this._abortOperatorList({
  1765. intentState,
  1766. reason,
  1767. force: true
  1768. });
  1769. intentState.streamReaderCancelTimeout = null;
  1770. }, RENDERING_CANCELLED_TIMEOUT);
  1771. return;
  1772. }
  1773. }
  1774. intentState.streamReader.cancel(new _util.AbortException(reason.message)).catch(() => {});
  1775. intentState.streamReader = null;
  1776. if (this._transport.destroyed) {
  1777. return;
  1778. }
  1779. for (const [curCacheKey, curIntentState] of this._intentStates) {
  1780. if (curIntentState === intentState) {
  1781. this._intentStates.delete(curCacheKey);
  1782. break;
  1783. }
  1784. }
  1785. this.cleanup();
  1786. }
  1787. get stats() {
  1788. return this._stats;
  1789. }
  1790. }
  1791. exports.PDFPageProxy = PDFPageProxy;
  1792. class LoopbackPort {
  1793. constructor() {
  1794. this._listeners = [];
  1795. this._deferred = Promise.resolve();
  1796. }
  1797. postMessage(obj, transfers) {
  1798. const event = {
  1799. data: structuredClone(obj, transfers)
  1800. };
  1801. this._deferred.then(() => {
  1802. for (const listener of this._listeners) {
  1803. listener.call(this, event);
  1804. }
  1805. });
  1806. }
  1807. addEventListener(name, listener) {
  1808. this._listeners.push(listener);
  1809. }
  1810. removeEventListener(name, listener) {
  1811. const i = this._listeners.indexOf(listener);
  1812. this._listeners.splice(i, 1);
  1813. }
  1814. terminate() {
  1815. this._listeners.length = 0;
  1816. }
  1817. }
  1818. exports.LoopbackPort = LoopbackPort;
  1819. const PDFWorkerUtil = {
  1820. isWorkerDisabled: false,
  1821. fallbackWorkerSrc: null,
  1822. fakeWorkerId: 0
  1823. };
  1824. {
  1825. if (_is_node.isNodeJS && typeof require === "function") {
  1826. PDFWorkerUtil.isWorkerDisabled = true;
  1827. PDFWorkerUtil.fallbackWorkerSrc = "./pdf.worker.js";
  1828. } else if (typeof document === "object") {
  1829. const pdfjsFilePath = document?.currentScript?.src;
  1830. if (pdfjsFilePath) {
  1831. PDFWorkerUtil.fallbackWorkerSrc = pdfjsFilePath.replace(/(\.(?:min\.)?js)(\?.*)?$/i, ".worker$1$2");
  1832. }
  1833. }
  1834. PDFWorkerUtil.createCDNWrapper = function (url) {
  1835. const wrapper = `importScripts("${url}");`;
  1836. return URL.createObjectURL(new Blob([wrapper]));
  1837. };
  1838. }
  1839. class PDFWorker {
  1840. static get _workerPorts() {
  1841. return (0, _util.shadow)(this, "_workerPorts", new WeakMap());
  1842. }
  1843. constructor({
  1844. name = null,
  1845. port = null,
  1846. verbosity = (0, _util.getVerbosityLevel)()
  1847. } = {}) {
  1848. if (port && PDFWorker._workerPorts.has(port)) {
  1849. throw new Error("Cannot use more than one PDFWorker per port.");
  1850. }
  1851. this.name = name;
  1852. this.destroyed = false;
  1853. this.verbosity = verbosity;
  1854. this._readyCapability = (0, _util.createPromiseCapability)();
  1855. this._port = null;
  1856. this._webWorker = null;
  1857. this._messageHandler = null;
  1858. if (port) {
  1859. PDFWorker._workerPorts.set(port, this);
  1860. this._initializeFromPort(port);
  1861. return;
  1862. }
  1863. this._initialize();
  1864. }
  1865. get promise() {
  1866. return this._readyCapability.promise;
  1867. }
  1868. get port() {
  1869. return this._port;
  1870. }
  1871. get messageHandler() {
  1872. return this._messageHandler;
  1873. }
  1874. _initializeFromPort(port) {
  1875. this._port = port;
  1876. this._messageHandler = new _message_handler.MessageHandler("main", "worker", port);
  1877. this._messageHandler.on("ready", function () {});
  1878. this._readyCapability.resolve();
  1879. }
  1880. _initialize() {
  1881. if (typeof Worker !== "undefined" && !PDFWorkerUtil.isWorkerDisabled && !PDFWorker._mainThreadWorkerMessageHandler) {
  1882. let workerSrc = PDFWorker.workerSrc;
  1883. try {
  1884. if (!(0, _util.isSameOrigin)(window.location.href, workerSrc)) {
  1885. workerSrc = PDFWorkerUtil.createCDNWrapper(new URL(workerSrc, window.location).href);
  1886. }
  1887. const worker = new Worker(workerSrc);
  1888. const messageHandler = new _message_handler.MessageHandler("main", "worker", worker);
  1889. const terminateEarly = () => {
  1890. worker.removeEventListener("error", onWorkerError);
  1891. messageHandler.destroy();
  1892. worker.terminate();
  1893. if (this.destroyed) {
  1894. this._readyCapability.reject(new Error("Worker was destroyed"));
  1895. } else {
  1896. this._setupFakeWorker();
  1897. }
  1898. };
  1899. const onWorkerError = () => {
  1900. if (!this._webWorker) {
  1901. terminateEarly();
  1902. }
  1903. };
  1904. worker.addEventListener("error", onWorkerError);
  1905. messageHandler.on("test", data => {
  1906. worker.removeEventListener("error", onWorkerError);
  1907. if (this.destroyed) {
  1908. terminateEarly();
  1909. return;
  1910. }
  1911. if (data) {
  1912. this._messageHandler = messageHandler;
  1913. this._port = worker;
  1914. this._webWorker = worker;
  1915. this._readyCapability.resolve();
  1916. messageHandler.send("configure", {
  1917. verbosity: this.verbosity
  1918. });
  1919. } else {
  1920. this._setupFakeWorker();
  1921. messageHandler.destroy();
  1922. worker.terminate();
  1923. }
  1924. });
  1925. messageHandler.on("ready", data => {
  1926. worker.removeEventListener("error", onWorkerError);
  1927. if (this.destroyed) {
  1928. terminateEarly();
  1929. return;
  1930. }
  1931. try {
  1932. sendTest();
  1933. } catch (e) {
  1934. this._setupFakeWorker();
  1935. }
  1936. });
  1937. const sendTest = () => {
  1938. const testObj = new Uint8Array([255]);
  1939. try {
  1940. messageHandler.send("test", testObj, [testObj.buffer]);
  1941. } catch (ex) {
  1942. (0, _util.warn)("Cannot use postMessage transfers.");
  1943. testObj[0] = 0;
  1944. messageHandler.send("test", testObj);
  1945. }
  1946. };
  1947. sendTest();
  1948. return;
  1949. } catch (e) {
  1950. (0, _util.info)("The worker has been disabled.");
  1951. }
  1952. }
  1953. this._setupFakeWorker();
  1954. }
  1955. _setupFakeWorker() {
  1956. if (!PDFWorkerUtil.isWorkerDisabled) {
  1957. (0, _util.warn)("Setting up fake worker.");
  1958. PDFWorkerUtil.isWorkerDisabled = true;
  1959. }
  1960. PDFWorker._setupFakeWorkerGlobal.then(WorkerMessageHandler => {
  1961. if (this.destroyed) {
  1962. this._readyCapability.reject(new Error("Worker was destroyed"));
  1963. return;
  1964. }
  1965. const port = new LoopbackPort();
  1966. this._port = port;
  1967. const id = `fake${PDFWorkerUtil.fakeWorkerId++}`;
  1968. const workerHandler = new _message_handler.MessageHandler(id + "_worker", id, port);
  1969. WorkerMessageHandler.setup(workerHandler, port);
  1970. const messageHandler = new _message_handler.MessageHandler(id, id + "_worker", port);
  1971. this._messageHandler = messageHandler;
  1972. this._readyCapability.resolve();
  1973. messageHandler.send("configure", {
  1974. verbosity: this.verbosity
  1975. });
  1976. }).catch(reason => {
  1977. this._readyCapability.reject(new Error(`Setting up fake worker failed: "${reason.message}".`));
  1978. });
  1979. }
  1980. destroy() {
  1981. this.destroyed = true;
  1982. if (this._webWorker) {
  1983. this._webWorker.terminate();
  1984. this._webWorker = null;
  1985. }
  1986. PDFWorker._workerPorts.delete(this._port);
  1987. this._port = null;
  1988. if (this._messageHandler) {
  1989. this._messageHandler.destroy();
  1990. this._messageHandler = null;
  1991. }
  1992. }
  1993. static fromPort(params) {
  1994. if (!params?.port) {
  1995. throw new Error("PDFWorker.fromPort - invalid method signature.");
  1996. }
  1997. if (this._workerPorts.has(params.port)) {
  1998. return this._workerPorts.get(params.port);
  1999. }
  2000. return new PDFWorker(params);
  2001. }
  2002. static get workerSrc() {
  2003. if (_worker_options.GlobalWorkerOptions.workerSrc) {
  2004. return _worker_options.GlobalWorkerOptions.workerSrc;
  2005. }
  2006. if (PDFWorkerUtil.fallbackWorkerSrc !== null) {
  2007. if (!_is_node.isNodeJS) {
  2008. (0, _display_utils.deprecated)('No "GlobalWorkerOptions.workerSrc" specified.');
  2009. }
  2010. return PDFWorkerUtil.fallbackWorkerSrc;
  2011. }
  2012. throw new Error('No "GlobalWorkerOptions.workerSrc" specified.');
  2013. }
  2014. static get _mainThreadWorkerMessageHandler() {
  2015. try {
  2016. return globalThis.pdfjsWorker?.WorkerMessageHandler || null;
  2017. } catch (ex) {
  2018. return null;
  2019. }
  2020. }
  2021. static get _setupFakeWorkerGlobal() {
  2022. const loader = async () => {
  2023. const mainWorkerMessageHandler = this._mainThreadWorkerMessageHandler;
  2024. if (mainWorkerMessageHandler) {
  2025. return mainWorkerMessageHandler;
  2026. }
  2027. if (_is_node.isNodeJS && typeof require === "function") {
  2028. const worker = eval("require")(this.workerSrc);
  2029. return worker.WorkerMessageHandler;
  2030. }
  2031. await (0, _display_utils.loadScript)(this.workerSrc);
  2032. return window.pdfjsWorker.WorkerMessageHandler;
  2033. };
  2034. return (0, _util.shadow)(this, "_setupFakeWorkerGlobal", loader());
  2035. }
  2036. }
  2037. exports.PDFWorker = PDFWorker;
  2038. {
  2039. PDFWorker.getWorkerSrc = function () {
  2040. (0, _display_utils.deprecated)("`PDFWorker.getWorkerSrc()`, please use `PDFWorker.workerSrc` instead.");
  2041. return this.workerSrc;
  2042. };
  2043. }
  2044. class WorkerTransport {
  2045. #docStats = null;
  2046. #pageCache = new Map();
  2047. #pagePromises = new Map();
  2048. #metadataPromise = null;
  2049. constructor(messageHandler, loadingTask, networkStream, params) {
  2050. this.messageHandler = messageHandler;
  2051. this.loadingTask = loadingTask;
  2052. this.commonObjs = new PDFObjects();
  2053. this.fontLoader = new _font_loader.FontLoader({
  2054. docId: loadingTask.docId,
  2055. onUnsupportedFeature: this._onUnsupportedFeature.bind(this),
  2056. ownerDocument: params.ownerDocument,
  2057. styleElement: params.styleElement
  2058. });
  2059. this._params = params;
  2060. if (!params.useWorkerFetch) {
  2061. this.CMapReaderFactory = new params.CMapReaderFactory({
  2062. baseUrl: params.cMapUrl,
  2063. isCompressed: params.cMapPacked
  2064. });
  2065. this.StandardFontDataFactory = new params.StandardFontDataFactory({
  2066. baseUrl: params.standardFontDataUrl
  2067. });
  2068. }
  2069. this.destroyed = false;
  2070. this.destroyCapability = null;
  2071. this._passwordCapability = null;
  2072. this._networkStream = networkStream;
  2073. this._fullReader = null;
  2074. this._lastProgress = null;
  2075. this.downloadInfoCapability = (0, _util.createPromiseCapability)();
  2076. this.setupMessageHandler();
  2077. }
  2078. get annotationStorage() {
  2079. return (0, _util.shadow)(this, "annotationStorage", new _annotation_storage.AnnotationStorage());
  2080. }
  2081. get stats() {
  2082. return this.#docStats;
  2083. }
  2084. getRenderingIntent(intent, annotationMode = _util.AnnotationMode.ENABLE, isOpList = false) {
  2085. let renderingIntent = _util.RenderingIntentFlag.DISPLAY;
  2086. let lastModified = "";
  2087. switch (intent) {
  2088. case "any":
  2089. renderingIntent = _util.RenderingIntentFlag.ANY;
  2090. break;
  2091. case "display":
  2092. break;
  2093. case "print":
  2094. renderingIntent = _util.RenderingIntentFlag.PRINT;
  2095. break;
  2096. default:
  2097. (0, _util.warn)(`getRenderingIntent - invalid intent: ${intent}`);
  2098. }
  2099. switch (annotationMode) {
  2100. case _util.AnnotationMode.DISABLE:
  2101. renderingIntent += _util.RenderingIntentFlag.ANNOTATIONS_DISABLE;
  2102. break;
  2103. case _util.AnnotationMode.ENABLE:
  2104. break;
  2105. case _util.AnnotationMode.ENABLE_FORMS:
  2106. renderingIntent += _util.RenderingIntentFlag.ANNOTATIONS_FORMS;
  2107. break;
  2108. case _util.AnnotationMode.ENABLE_STORAGE:
  2109. renderingIntent += _util.RenderingIntentFlag.ANNOTATIONS_STORAGE;
  2110. lastModified = this.annotationStorage.lastModified;
  2111. break;
  2112. default:
  2113. (0, _util.warn)(`getRenderingIntent - invalid annotationMode: ${annotationMode}`);
  2114. }
  2115. if (isOpList) {
  2116. renderingIntent += _util.RenderingIntentFlag.OPLIST;
  2117. }
  2118. return {
  2119. renderingIntent,
  2120. cacheKey: `${renderingIntent}_${lastModified}`
  2121. };
  2122. }
  2123. destroy() {
  2124. if (this.destroyCapability) {
  2125. return this.destroyCapability.promise;
  2126. }
  2127. this.destroyed = true;
  2128. this.destroyCapability = (0, _util.createPromiseCapability)();
  2129. if (this._passwordCapability) {
  2130. this._passwordCapability.reject(new Error("Worker was destroyed during onPassword callback"));
  2131. }
  2132. const waitOn = [];
  2133. for (const page of this.#pageCache.values()) {
  2134. waitOn.push(page._destroy());
  2135. }
  2136. this.#pageCache.clear();
  2137. this.#pagePromises.clear();
  2138. if (this.hasOwnProperty("annotationStorage")) {
  2139. this.annotationStorage.resetModified();
  2140. }
  2141. const terminated = this.messageHandler.sendWithPromise("Terminate", null);
  2142. waitOn.push(terminated);
  2143. Promise.all(waitOn).then(() => {
  2144. this.commonObjs.clear();
  2145. this.fontLoader.clear();
  2146. this.#metadataPromise = null;
  2147. this._getFieldObjectsPromise = null;
  2148. this._hasJSActionsPromise = null;
  2149. if (this._networkStream) {
  2150. this._networkStream.cancelAllRequests(new _util.AbortException("Worker was terminated."));
  2151. }
  2152. if (this.messageHandler) {
  2153. this.messageHandler.destroy();
  2154. this.messageHandler = null;
  2155. }
  2156. this.destroyCapability.resolve();
  2157. }, this.destroyCapability.reject);
  2158. return this.destroyCapability.promise;
  2159. }
  2160. setupMessageHandler() {
  2161. const {
  2162. messageHandler,
  2163. loadingTask
  2164. } = this;
  2165. messageHandler.on("GetReader", (data, sink) => {
  2166. (0, _util.assert)(this._networkStream, "GetReader - no `IPDFStream` instance available.");
  2167. this._fullReader = this._networkStream.getFullReader();
  2168. this._fullReader.onProgress = evt => {
  2169. this._lastProgress = {
  2170. loaded: evt.loaded,
  2171. total: evt.total
  2172. };
  2173. };
  2174. sink.onPull = () => {
  2175. this._fullReader.read().then(function ({
  2176. value,
  2177. done
  2178. }) {
  2179. if (done) {
  2180. sink.close();
  2181. return;
  2182. }
  2183. (0, _util.assert)((0, _util.isArrayBuffer)(value), "GetReader - expected an ArrayBuffer.");
  2184. sink.enqueue(new Uint8Array(value), 1, [value]);
  2185. }).catch(reason => {
  2186. sink.error(reason);
  2187. });
  2188. };
  2189. sink.onCancel = reason => {
  2190. this._fullReader.cancel(reason);
  2191. sink.ready.catch(readyReason => {
  2192. if (this.destroyed) {
  2193. return;
  2194. }
  2195. throw readyReason;
  2196. });
  2197. };
  2198. });
  2199. messageHandler.on("ReaderHeadersReady", data => {
  2200. const headersCapability = (0, _util.createPromiseCapability)();
  2201. const fullReader = this._fullReader;
  2202. fullReader.headersReady.then(() => {
  2203. if (!fullReader.isStreamingSupported || !fullReader.isRangeSupported) {
  2204. if (this._lastProgress) {
  2205. loadingTask.onProgress?.(this._lastProgress);
  2206. }
  2207. fullReader.onProgress = evt => {
  2208. loadingTask.onProgress?.({
  2209. loaded: evt.loaded,
  2210. total: evt.total
  2211. });
  2212. };
  2213. }
  2214. headersCapability.resolve({
  2215. isStreamingSupported: fullReader.isStreamingSupported,
  2216. isRangeSupported: fullReader.isRangeSupported,
  2217. contentLength: fullReader.contentLength
  2218. });
  2219. }, headersCapability.reject);
  2220. return headersCapability.promise;
  2221. });
  2222. messageHandler.on("GetRangeReader", (data, sink) => {
  2223. (0, _util.assert)(this._networkStream, "GetRangeReader - no `IPDFStream` instance available.");
  2224. const rangeReader = this._networkStream.getRangeReader(data.begin, data.end);
  2225. if (!rangeReader) {
  2226. sink.close();
  2227. return;
  2228. }
  2229. sink.onPull = () => {
  2230. rangeReader.read().then(function ({
  2231. value,
  2232. done
  2233. }) {
  2234. if (done) {
  2235. sink.close();
  2236. return;
  2237. }
  2238. (0, _util.assert)((0, _util.isArrayBuffer)(value), "GetRangeReader - expected an ArrayBuffer.");
  2239. sink.enqueue(new Uint8Array(value), 1, [value]);
  2240. }).catch(reason => {
  2241. sink.error(reason);
  2242. });
  2243. };
  2244. sink.onCancel = reason => {
  2245. rangeReader.cancel(reason);
  2246. sink.ready.catch(readyReason => {
  2247. if (this.destroyed) {
  2248. return;
  2249. }
  2250. throw readyReason;
  2251. });
  2252. };
  2253. });
  2254. messageHandler.on("GetDoc", ({
  2255. pdfInfo
  2256. }) => {
  2257. this._numPages = pdfInfo.numPages;
  2258. this._htmlForXfa = pdfInfo.htmlForXfa;
  2259. delete pdfInfo.htmlForXfa;
  2260. loadingTask._capability.resolve(new PDFDocumentProxy(pdfInfo, this));
  2261. });
  2262. messageHandler.on("DocException", function (ex) {
  2263. let reason;
  2264. switch (ex.name) {
  2265. case "PasswordException":
  2266. reason = new _util.PasswordException(ex.message, ex.code);
  2267. break;
  2268. case "InvalidPDFException":
  2269. reason = new _util.InvalidPDFException(ex.message);
  2270. break;
  2271. case "MissingPDFException":
  2272. reason = new _util.MissingPDFException(ex.message);
  2273. break;
  2274. case "UnexpectedResponseException":
  2275. reason = new _util.UnexpectedResponseException(ex.message, ex.status);
  2276. break;
  2277. case "UnknownErrorException":
  2278. reason = new _util.UnknownErrorException(ex.message, ex.details);
  2279. break;
  2280. default:
  2281. (0, _util.unreachable)("DocException - expected a valid Error.");
  2282. }
  2283. loadingTask._capability.reject(reason);
  2284. });
  2285. messageHandler.on("PasswordRequest", exception => {
  2286. this._passwordCapability = (0, _util.createPromiseCapability)();
  2287. if (loadingTask.onPassword) {
  2288. const updatePassword = password => {
  2289. if (password instanceof Error) {
  2290. this._passwordCapability.reject(password);
  2291. } else {
  2292. this._passwordCapability.resolve({
  2293. password
  2294. });
  2295. }
  2296. };
  2297. try {
  2298. loadingTask.onPassword(updatePassword, exception.code);
  2299. } catch (ex) {
  2300. this._passwordCapability.reject(ex);
  2301. }
  2302. } else {
  2303. this._passwordCapability.reject(new _util.PasswordException(exception.message, exception.code));
  2304. }
  2305. return this._passwordCapability.promise;
  2306. });
  2307. messageHandler.on("DataLoaded", data => {
  2308. loadingTask.onProgress?.({
  2309. loaded: data.length,
  2310. total: data.length
  2311. });
  2312. this.downloadInfoCapability.resolve(data);
  2313. });
  2314. messageHandler.on("StartRenderPage", data => {
  2315. if (this.destroyed) {
  2316. return;
  2317. }
  2318. const page = this.#pageCache.get(data.pageIndex);
  2319. page._startRenderPage(data.transparency, data.cacheKey);
  2320. });
  2321. messageHandler.on("commonobj", ([id, type, exportedData]) => {
  2322. if (this.destroyed) {
  2323. return;
  2324. }
  2325. if (this.commonObjs.has(id)) {
  2326. return;
  2327. }
  2328. switch (type) {
  2329. case "Font":
  2330. const params = this._params;
  2331. if ("error" in exportedData) {
  2332. const exportedError = exportedData.error;
  2333. (0, _util.warn)(`Error during font loading: ${exportedError}`);
  2334. this.commonObjs.resolve(id, exportedError);
  2335. break;
  2336. }
  2337. let fontRegistry = null;
  2338. if (params.pdfBug && globalThis.FontInspector?.enabled) {
  2339. fontRegistry = {
  2340. registerFont(font, url) {
  2341. globalThis.FontInspector.fontAdded(font, url);
  2342. }
  2343. };
  2344. }
  2345. const font = new _font_loader.FontFaceObject(exportedData, {
  2346. isEvalSupported: params.isEvalSupported,
  2347. disableFontFace: params.disableFontFace,
  2348. ignoreErrors: params.ignoreErrors,
  2349. onUnsupportedFeature: this._onUnsupportedFeature.bind(this),
  2350. fontRegistry
  2351. });
  2352. this.fontLoader.bind(font).catch(reason => {
  2353. return messageHandler.sendWithPromise("FontFallback", {
  2354. id
  2355. });
  2356. }).finally(() => {
  2357. if (!params.fontExtraProperties && font.data) {
  2358. font.data = null;
  2359. }
  2360. this.commonObjs.resolve(id, font);
  2361. });
  2362. break;
  2363. case "FontPath":
  2364. case "Image":
  2365. this.commonObjs.resolve(id, exportedData);
  2366. break;
  2367. default:
  2368. throw new Error(`Got unknown common object type ${type}`);
  2369. }
  2370. });
  2371. messageHandler.on("obj", ([id, pageIndex, type, imageData]) => {
  2372. if (this.destroyed) {
  2373. return;
  2374. }
  2375. const pageProxy = this.#pageCache.get(pageIndex);
  2376. if (pageProxy.objs.has(id)) {
  2377. return;
  2378. }
  2379. switch (type) {
  2380. case "Image":
  2381. pageProxy.objs.resolve(id, imageData);
  2382. const MAX_IMAGE_SIZE_TO_STORE = 8000000;
  2383. if (imageData?.data?.length > MAX_IMAGE_SIZE_TO_STORE) {
  2384. pageProxy.cleanupAfterRender = true;
  2385. }
  2386. break;
  2387. case "Pattern":
  2388. pageProxy.objs.resolve(id, imageData);
  2389. break;
  2390. default:
  2391. throw new Error(`Got unknown object type ${type}`);
  2392. }
  2393. });
  2394. messageHandler.on("DocProgress", data => {
  2395. if (this.destroyed) {
  2396. return;
  2397. }
  2398. loadingTask.onProgress?.({
  2399. loaded: data.loaded,
  2400. total: data.total
  2401. });
  2402. });
  2403. messageHandler.on("DocStats", data => {
  2404. if (this.destroyed) {
  2405. return;
  2406. }
  2407. this.#docStats = Object.freeze({
  2408. streamTypes: Object.freeze(data.streamTypes),
  2409. fontTypes: Object.freeze(data.fontTypes)
  2410. });
  2411. });
  2412. messageHandler.on("UnsupportedFeature", this._onUnsupportedFeature.bind(this));
  2413. messageHandler.on("FetchBuiltInCMap", data => {
  2414. if (this.destroyed) {
  2415. return Promise.reject(new Error("Worker was destroyed."));
  2416. }
  2417. if (!this.CMapReaderFactory) {
  2418. return Promise.reject(new Error("CMapReaderFactory not initialized, see the `useWorkerFetch` parameter."));
  2419. }
  2420. return this.CMapReaderFactory.fetch(data);
  2421. });
  2422. messageHandler.on("FetchStandardFontData", data => {
  2423. if (this.destroyed) {
  2424. return Promise.reject(new Error("Worker was destroyed."));
  2425. }
  2426. if (!this.StandardFontDataFactory) {
  2427. return Promise.reject(new Error("StandardFontDataFactory not initialized, see the `useWorkerFetch` parameter."));
  2428. }
  2429. return this.StandardFontDataFactory.fetch(data);
  2430. });
  2431. }
  2432. _onUnsupportedFeature({
  2433. featureId
  2434. }) {
  2435. if (this.destroyed) {
  2436. return;
  2437. }
  2438. this.loadingTask.onUnsupportedFeature?.(featureId);
  2439. }
  2440. getData() {
  2441. return this.messageHandler.sendWithPromise("GetData", null);
  2442. }
  2443. getPage(pageNumber) {
  2444. if (!Number.isInteger(pageNumber) || pageNumber <= 0 || pageNumber > this._numPages) {
  2445. return Promise.reject(new Error("Invalid page request."));
  2446. }
  2447. const pageIndex = pageNumber - 1,
  2448. cachedPromise = this.#pagePromises.get(pageIndex);
  2449. if (cachedPromise) {
  2450. return cachedPromise;
  2451. }
  2452. const promise = this.messageHandler.sendWithPromise("GetPage", {
  2453. pageIndex
  2454. }).then(pageInfo => {
  2455. if (this.destroyed) {
  2456. throw new Error("Transport destroyed");
  2457. }
  2458. const page = new PDFPageProxy(pageIndex, pageInfo, this, this._params.ownerDocument, this._params.pdfBug);
  2459. this.#pageCache.set(pageIndex, page);
  2460. return page;
  2461. });
  2462. this.#pagePromises.set(pageIndex, promise);
  2463. return promise;
  2464. }
  2465. getPageIndex(ref) {
  2466. if (typeof ref !== "object" || ref === null || !Number.isInteger(ref.num) || ref.num < 0 || !Number.isInteger(ref.gen) || ref.gen < 0) {
  2467. return Promise.reject(new Error("Invalid pageIndex request."));
  2468. }
  2469. return this.messageHandler.sendWithPromise("GetPageIndex", {
  2470. num: ref.num,
  2471. gen: ref.gen
  2472. });
  2473. }
  2474. getAnnotations(pageIndex, intent) {
  2475. return this.messageHandler.sendWithPromise("GetAnnotations", {
  2476. pageIndex,
  2477. intent
  2478. });
  2479. }
  2480. saveDocument() {
  2481. return this.messageHandler.sendWithPromise("SaveDocument", {
  2482. isPureXfa: !!this._htmlForXfa,
  2483. numPages: this._numPages,
  2484. annotationStorage: this.annotationStorage.serializable,
  2485. filename: this._fullReader?.filename ?? null
  2486. }).finally(() => {
  2487. this.annotationStorage.resetModified();
  2488. });
  2489. }
  2490. getFieldObjects() {
  2491. return this._getFieldObjectsPromise ||= this.messageHandler.sendWithPromise("GetFieldObjects", null);
  2492. }
  2493. hasJSActions() {
  2494. return this._hasJSActionsPromise ||= this.messageHandler.sendWithPromise("HasJSActions", null);
  2495. }
  2496. getCalculationOrderIds() {
  2497. return this.messageHandler.sendWithPromise("GetCalculationOrderIds", null);
  2498. }
  2499. getDestinations() {
  2500. return this.messageHandler.sendWithPromise("GetDestinations", null);
  2501. }
  2502. getDestination(id) {
  2503. if (typeof id !== "string") {
  2504. return Promise.reject(new Error("Invalid destination request."));
  2505. }
  2506. return this.messageHandler.sendWithPromise("GetDestination", {
  2507. id
  2508. });
  2509. }
  2510. getPageLabels() {
  2511. return this.messageHandler.sendWithPromise("GetPageLabels", null);
  2512. }
  2513. getPageLayout() {
  2514. return this.messageHandler.sendWithPromise("GetPageLayout", null);
  2515. }
  2516. getPageMode() {
  2517. return this.messageHandler.sendWithPromise("GetPageMode", null);
  2518. }
  2519. getViewerPreferences() {
  2520. return this.messageHandler.sendWithPromise("GetViewerPreferences", null);
  2521. }
  2522. getOpenAction() {
  2523. return this.messageHandler.sendWithPromise("GetOpenAction", null);
  2524. }
  2525. getAttachments() {
  2526. return this.messageHandler.sendWithPromise("GetAttachments", null);
  2527. }
  2528. getJavaScript() {
  2529. return this.messageHandler.sendWithPromise("GetJavaScript", null);
  2530. }
  2531. getDocJSActions() {
  2532. return this.messageHandler.sendWithPromise("GetDocJSActions", null);
  2533. }
  2534. getPageJSActions(pageIndex) {
  2535. return this.messageHandler.sendWithPromise("GetPageJSActions", {
  2536. pageIndex
  2537. });
  2538. }
  2539. getStructTree(pageIndex) {
  2540. return this.messageHandler.sendWithPromise("GetStructTree", {
  2541. pageIndex
  2542. });
  2543. }
  2544. getOutline() {
  2545. return this.messageHandler.sendWithPromise("GetOutline", null);
  2546. }
  2547. getOptionalContentConfig() {
  2548. return this.messageHandler.sendWithPromise("GetOptionalContentConfig", null).then(results => {
  2549. return new _optional_content_config.OptionalContentConfig(results);
  2550. });
  2551. }
  2552. getPermissions() {
  2553. return this.messageHandler.sendWithPromise("GetPermissions", null);
  2554. }
  2555. getMetadata() {
  2556. return this.#metadataPromise ||= this.messageHandler.sendWithPromise("GetMetadata", null).then(results => {
  2557. return {
  2558. info: results[0],
  2559. metadata: results[1] ? new _metadata.Metadata(results[1]) : null,
  2560. contentDispositionFilename: this._fullReader?.filename ?? null,
  2561. contentLength: this._fullReader?.contentLength ?? null
  2562. };
  2563. });
  2564. }
  2565. getMarkInfo() {
  2566. return this.messageHandler.sendWithPromise("GetMarkInfo", null);
  2567. }
  2568. async startCleanup(keepLoadedFonts = false) {
  2569. await this.messageHandler.sendWithPromise("Cleanup", null);
  2570. if (this.destroyed) {
  2571. return;
  2572. }
  2573. for (const page of this.#pageCache.values()) {
  2574. const cleanupSuccessful = page.cleanup();
  2575. if (!cleanupSuccessful) {
  2576. throw new Error(`startCleanup: Page ${page.pageNumber} is currently rendering.`);
  2577. }
  2578. }
  2579. this.commonObjs.clear();
  2580. if (!keepLoadedFonts) {
  2581. this.fontLoader.clear();
  2582. }
  2583. this.#metadataPromise = null;
  2584. this._getFieldObjectsPromise = null;
  2585. this._hasJSActionsPromise = null;
  2586. }
  2587. get loadingParams() {
  2588. const params = this._params;
  2589. return (0, _util.shadow)(this, "loadingParams", {
  2590. disableAutoFetch: params.disableAutoFetch,
  2591. enableXfa: params.enableXfa
  2592. });
  2593. }
  2594. }
  2595. class PDFObjects {
  2596. #objs = Object.create(null);
  2597. #ensureObj(objId) {
  2598. const obj = this.#objs[objId];
  2599. if (obj) {
  2600. return obj;
  2601. }
  2602. return this.#objs[objId] = {
  2603. capability: (0, _util.createPromiseCapability)(),
  2604. data: null
  2605. };
  2606. }
  2607. get(objId, callback = null) {
  2608. if (callback) {
  2609. const obj = this.#ensureObj(objId);
  2610. obj.capability.promise.then(() => callback(obj.data));
  2611. return null;
  2612. }
  2613. const obj = this.#objs[objId];
  2614. if (!obj?.capability.settled) {
  2615. throw new Error(`Requesting object that isn't resolved yet ${objId}.`);
  2616. }
  2617. return obj.data;
  2618. }
  2619. has(objId) {
  2620. const obj = this.#objs[objId];
  2621. return obj?.capability.settled || false;
  2622. }
  2623. resolve(objId, data = null) {
  2624. const obj = this.#ensureObj(objId);
  2625. obj.data = data;
  2626. obj.capability.resolve();
  2627. }
  2628. clear() {
  2629. this.#objs = Object.create(null);
  2630. }
  2631. }
  2632. class RenderTask {
  2633. constructor(internalRenderTask) {
  2634. this._internalRenderTask = internalRenderTask;
  2635. this.onContinue = null;
  2636. }
  2637. get promise() {
  2638. return this._internalRenderTask.capability.promise;
  2639. }
  2640. cancel() {
  2641. this._internalRenderTask.cancel();
  2642. }
  2643. }
  2644. exports.RenderTask = RenderTask;
  2645. class InternalRenderTask {
  2646. static get canvasInUse() {
  2647. return (0, _util.shadow)(this, "canvasInUse", new WeakSet());
  2648. }
  2649. constructor({
  2650. callback,
  2651. params,
  2652. objs,
  2653. commonObjs,
  2654. annotationCanvasMap,
  2655. operatorList,
  2656. pageIndex,
  2657. canvasFactory,
  2658. useRequestAnimationFrame = false,
  2659. pdfBug = false
  2660. }) {
  2661. this.callback = callback;
  2662. this.params = params;
  2663. this.objs = objs;
  2664. this.commonObjs = commonObjs;
  2665. this.annotationCanvasMap = annotationCanvasMap;
  2666. this.operatorListIdx = null;
  2667. this.operatorList = operatorList;
  2668. this._pageIndex = pageIndex;
  2669. this.canvasFactory = canvasFactory;
  2670. this._pdfBug = pdfBug;
  2671. this.running = false;
  2672. this.graphicsReadyCallback = null;
  2673. this.graphicsReady = false;
  2674. this._useRequestAnimationFrame = useRequestAnimationFrame === true && typeof window !== "undefined";
  2675. this.cancelled = false;
  2676. this.capability = (0, _util.createPromiseCapability)();
  2677. this.task = new RenderTask(this);
  2678. this._cancelBound = this.cancel.bind(this);
  2679. this._continueBound = this._continue.bind(this);
  2680. this._scheduleNextBound = this._scheduleNext.bind(this);
  2681. this._nextBound = this._next.bind(this);
  2682. this._canvas = params.canvasContext.canvas;
  2683. }
  2684. get completed() {
  2685. return this.capability.promise.catch(function () {});
  2686. }
  2687. initializeGraphics({
  2688. transparency = false,
  2689. optionalContentConfig
  2690. }) {
  2691. if (this.cancelled) {
  2692. return;
  2693. }
  2694. if (this._canvas) {
  2695. if (InternalRenderTask.canvasInUse.has(this._canvas)) {
  2696. throw new Error("Cannot use the same canvas during multiple render() operations. " + "Use different canvas or ensure previous operations were " + "cancelled or completed.");
  2697. }
  2698. InternalRenderTask.canvasInUse.add(this._canvas);
  2699. }
  2700. if (this._pdfBug && globalThis.StepperManager?.enabled) {
  2701. this.stepper = globalThis.StepperManager.create(this._pageIndex);
  2702. this.stepper.init(this.operatorList);
  2703. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  2704. }
  2705. const {
  2706. canvasContext,
  2707. viewport,
  2708. transform,
  2709. imageLayer,
  2710. background
  2711. } = this.params;
  2712. this.gfx = new _canvas.CanvasGraphics(canvasContext, this.commonObjs, this.objs, this.canvasFactory, imageLayer, optionalContentConfig, this.annotationCanvasMap);
  2713. this.gfx.beginDrawing({
  2714. transform,
  2715. viewport,
  2716. transparency,
  2717. background
  2718. });
  2719. this.operatorListIdx = 0;
  2720. this.graphicsReady = true;
  2721. if (this.graphicsReadyCallback) {
  2722. this.graphicsReadyCallback();
  2723. }
  2724. }
  2725. cancel(error = null) {
  2726. this.running = false;
  2727. this.cancelled = true;
  2728. if (this.gfx) {
  2729. this.gfx.endDrawing();
  2730. }
  2731. if (this._canvas) {
  2732. InternalRenderTask.canvasInUse.delete(this._canvas);
  2733. }
  2734. this.callback(error || new _display_utils.RenderingCancelledException(`Rendering cancelled, page ${this._pageIndex + 1}`, "canvas"));
  2735. }
  2736. operatorListChanged() {
  2737. if (!this.graphicsReady) {
  2738. if (!this.graphicsReadyCallback) {
  2739. this.graphicsReadyCallback = this._continueBound;
  2740. }
  2741. return;
  2742. }
  2743. if (this.stepper) {
  2744. this.stepper.updateOperatorList(this.operatorList);
  2745. }
  2746. if (this.running) {
  2747. return;
  2748. }
  2749. this._continue();
  2750. }
  2751. _continue() {
  2752. this.running = true;
  2753. if (this.cancelled) {
  2754. return;
  2755. }
  2756. if (this.task.onContinue) {
  2757. this.task.onContinue(this._scheduleNextBound);
  2758. } else {
  2759. this._scheduleNext();
  2760. }
  2761. }
  2762. _scheduleNext() {
  2763. if (this._useRequestAnimationFrame) {
  2764. window.requestAnimationFrame(() => {
  2765. this._nextBound().catch(this._cancelBound);
  2766. });
  2767. } else {
  2768. Promise.resolve().then(this._nextBound).catch(this._cancelBound);
  2769. }
  2770. }
  2771. async _next() {
  2772. if (this.cancelled) {
  2773. return;
  2774. }
  2775. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList, this.operatorListIdx, this._continueBound, this.stepper);
  2776. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  2777. this.running = false;
  2778. if (this.operatorList.lastChunk) {
  2779. this.gfx.endDrawing();
  2780. if (this._canvas) {
  2781. InternalRenderTask.canvasInUse.delete(this._canvas);
  2782. }
  2783. this.callback();
  2784. }
  2785. }
  2786. }
  2787. }
  2788. const version = '2.13.216';
  2789. exports.version = version;
  2790. const build = '399a0ec60';
  2791. exports.build = build;
  2792. /***/ }),
  2793. /* 5 */
  2794. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  2795. Object.defineProperty(exports, "__esModule", ({
  2796. value: true
  2797. }));
  2798. exports.StatTimer = exports.RenderingCancelledException = exports.PixelsPerInch = exports.PageViewport = exports.PDFDateString = exports.DOMStandardFontDataFactory = exports.DOMSVGFactory = exports.DOMCanvasFactory = exports.DOMCMapReaderFactory = void 0;
  2799. exports.deprecated = deprecated;
  2800. exports.getFilenameFromUrl = getFilenameFromUrl;
  2801. exports.getPdfFilenameFromUrl = getPdfFilenameFromUrl;
  2802. exports.getXfaPageViewport = getXfaPageViewport;
  2803. exports.isDataScheme = isDataScheme;
  2804. exports.isPdfFile = isPdfFile;
  2805. exports.isValidFetchUrl = isValidFetchUrl;
  2806. exports.loadScript = loadScript;
  2807. var _base_factory = __w_pdfjs_require__(6);
  2808. var _util = __w_pdfjs_require__(1);
  2809. const SVG_NS = "http://www.w3.org/2000/svg";
  2810. class PixelsPerInch {
  2811. static CSS = 96.0;
  2812. static PDF = 72.0;
  2813. static PDF_TO_CSS_UNITS = this.CSS / this.PDF;
  2814. }
  2815. exports.PixelsPerInch = PixelsPerInch;
  2816. class DOMCanvasFactory extends _base_factory.BaseCanvasFactory {
  2817. constructor({
  2818. ownerDocument = globalThis.document
  2819. } = {}) {
  2820. super();
  2821. this._document = ownerDocument;
  2822. }
  2823. _createCanvas(width, height) {
  2824. const canvas = this._document.createElement("canvas");
  2825. canvas.width = width;
  2826. canvas.height = height;
  2827. return canvas;
  2828. }
  2829. }
  2830. exports.DOMCanvasFactory = DOMCanvasFactory;
  2831. async function fetchData(url, asTypedArray = false) {
  2832. if (isValidFetchUrl(url, document.baseURI)) {
  2833. const response = await fetch(url);
  2834. if (!response.ok) {
  2835. throw new Error(response.statusText);
  2836. }
  2837. return asTypedArray ? new Uint8Array(await response.arrayBuffer()) : (0, _util.stringToBytes)(await response.text());
  2838. }
  2839. return new Promise((resolve, reject) => {
  2840. const request = new XMLHttpRequest();
  2841. request.open("GET", url, true);
  2842. if (asTypedArray) {
  2843. request.responseType = "arraybuffer";
  2844. }
  2845. request.onreadystatechange = () => {
  2846. if (request.readyState !== XMLHttpRequest.DONE) {
  2847. return;
  2848. }
  2849. if (request.status === 200 || request.status === 0) {
  2850. let data;
  2851. if (asTypedArray && request.response) {
  2852. data = new Uint8Array(request.response);
  2853. } else if (!asTypedArray && request.responseText) {
  2854. data = (0, _util.stringToBytes)(request.responseText);
  2855. }
  2856. if (data) {
  2857. resolve(data);
  2858. return;
  2859. }
  2860. }
  2861. reject(new Error(request.statusText));
  2862. };
  2863. request.send(null);
  2864. });
  2865. }
  2866. class DOMCMapReaderFactory extends _base_factory.BaseCMapReaderFactory {
  2867. _fetchData(url, compressionType) {
  2868. return fetchData(url, this.isCompressed).then(data => {
  2869. return {
  2870. cMapData: data,
  2871. compressionType
  2872. };
  2873. });
  2874. }
  2875. }
  2876. exports.DOMCMapReaderFactory = DOMCMapReaderFactory;
  2877. class DOMStandardFontDataFactory extends _base_factory.BaseStandardFontDataFactory {
  2878. _fetchData(url) {
  2879. return fetchData(url, true);
  2880. }
  2881. }
  2882. exports.DOMStandardFontDataFactory = DOMStandardFontDataFactory;
  2883. class DOMSVGFactory extends _base_factory.BaseSVGFactory {
  2884. _createSVG(type) {
  2885. return document.createElementNS(SVG_NS, type);
  2886. }
  2887. }
  2888. exports.DOMSVGFactory = DOMSVGFactory;
  2889. class PageViewport {
  2890. constructor({
  2891. viewBox,
  2892. scale,
  2893. rotation,
  2894. offsetX = 0,
  2895. offsetY = 0,
  2896. dontFlip = false
  2897. }) {
  2898. this.viewBox = viewBox;
  2899. this.scale = scale;
  2900. this.rotation = rotation;
  2901. this.offsetX = offsetX;
  2902. this.offsetY = offsetY;
  2903. const centerX = (viewBox[2] + viewBox[0]) / 2;
  2904. const centerY = (viewBox[3] + viewBox[1]) / 2;
  2905. let rotateA, rotateB, rotateC, rotateD;
  2906. rotation %= 360;
  2907. if (rotation < 0) {
  2908. rotation += 360;
  2909. }
  2910. switch (rotation) {
  2911. case 180:
  2912. rotateA = -1;
  2913. rotateB = 0;
  2914. rotateC = 0;
  2915. rotateD = 1;
  2916. break;
  2917. case 90:
  2918. rotateA = 0;
  2919. rotateB = 1;
  2920. rotateC = 1;
  2921. rotateD = 0;
  2922. break;
  2923. case 270:
  2924. rotateA = 0;
  2925. rotateB = -1;
  2926. rotateC = -1;
  2927. rotateD = 0;
  2928. break;
  2929. case 0:
  2930. rotateA = 1;
  2931. rotateB = 0;
  2932. rotateC = 0;
  2933. rotateD = -1;
  2934. break;
  2935. default:
  2936. throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.");
  2937. }
  2938. if (dontFlip) {
  2939. rotateC = -rotateC;
  2940. rotateD = -rotateD;
  2941. }
  2942. let offsetCanvasX, offsetCanvasY;
  2943. let width, height;
  2944. if (rotateA === 0) {
  2945. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  2946. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  2947. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  2948. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  2949. } else {
  2950. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  2951. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  2952. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  2953. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  2954. }
  2955. this.transform = [rotateA * scale, rotateB * scale, rotateC * scale, rotateD * scale, offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY, offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY];
  2956. this.width = width;
  2957. this.height = height;
  2958. }
  2959. clone({
  2960. scale = this.scale,
  2961. rotation = this.rotation,
  2962. offsetX = this.offsetX,
  2963. offsetY = this.offsetY,
  2964. dontFlip = false
  2965. } = {}) {
  2966. return new PageViewport({
  2967. viewBox: this.viewBox.slice(),
  2968. scale,
  2969. rotation,
  2970. offsetX,
  2971. offsetY,
  2972. dontFlip
  2973. });
  2974. }
  2975. convertToViewportPoint(x, y) {
  2976. return _util.Util.applyTransform([x, y], this.transform);
  2977. }
  2978. convertToViewportRectangle(rect) {
  2979. const topLeft = _util.Util.applyTransform([rect[0], rect[1]], this.transform);
  2980. const bottomRight = _util.Util.applyTransform([rect[2], rect[3]], this.transform);
  2981. return [topLeft[0], topLeft[1], bottomRight[0], bottomRight[1]];
  2982. }
  2983. convertToPdfPoint(x, y) {
  2984. return _util.Util.applyInverseTransform([x, y], this.transform);
  2985. }
  2986. }
  2987. exports.PageViewport = PageViewport;
  2988. class RenderingCancelledException extends _util.BaseException {
  2989. constructor(msg, type) {
  2990. super(msg, "RenderingCancelledException");
  2991. this.type = type;
  2992. }
  2993. }
  2994. exports.RenderingCancelledException = RenderingCancelledException;
  2995. function isDataScheme(url) {
  2996. const ii = url.length;
  2997. let i = 0;
  2998. while (i < ii && url[i].trim() === "") {
  2999. i++;
  3000. }
  3001. return url.substring(i, i + 5).toLowerCase() === "data:";
  3002. }
  3003. function isPdfFile(filename) {
  3004. return typeof filename === "string" && /\.pdf$/i.test(filename);
  3005. }
  3006. function getFilenameFromUrl(url) {
  3007. const anchor = url.indexOf("#");
  3008. const query = url.indexOf("?");
  3009. const end = Math.min(anchor > 0 ? anchor : url.length, query > 0 ? query : url.length);
  3010. return url.substring(url.lastIndexOf("/", end) + 1, end);
  3011. }
  3012. function getPdfFilenameFromUrl(url, defaultFilename = "document.pdf") {
  3013. if (typeof url !== "string") {
  3014. return defaultFilename;
  3015. }
  3016. if (isDataScheme(url)) {
  3017. (0, _util.warn)('getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.');
  3018. return defaultFilename;
  3019. }
  3020. const reURI = /^(?:(?:[^:]+:)?\/\/[^/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
  3021. const reFilename = /[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
  3022. const splitURI = reURI.exec(url);
  3023. let suggestedFilename = reFilename.exec(splitURI[1]) || reFilename.exec(splitURI[2]) || reFilename.exec(splitURI[3]);
  3024. if (suggestedFilename) {
  3025. suggestedFilename = suggestedFilename[0];
  3026. if (suggestedFilename.includes("%")) {
  3027. try {
  3028. suggestedFilename = reFilename.exec(decodeURIComponent(suggestedFilename))[0];
  3029. } catch (ex) {}
  3030. }
  3031. }
  3032. return suggestedFilename || defaultFilename;
  3033. }
  3034. class StatTimer {
  3035. constructor() {
  3036. this.started = Object.create(null);
  3037. this.times = [];
  3038. }
  3039. time(name) {
  3040. if (name in this.started) {
  3041. (0, _util.warn)(`Timer is already running for ${name}`);
  3042. }
  3043. this.started[name] = Date.now();
  3044. }
  3045. timeEnd(name) {
  3046. if (!(name in this.started)) {
  3047. (0, _util.warn)(`Timer has not been started for ${name}`);
  3048. }
  3049. this.times.push({
  3050. name,
  3051. start: this.started[name],
  3052. end: Date.now()
  3053. });
  3054. delete this.started[name];
  3055. }
  3056. toString() {
  3057. const outBuf = [];
  3058. let longest = 0;
  3059. for (const time of this.times) {
  3060. const name = time.name;
  3061. if (name.length > longest) {
  3062. longest = name.length;
  3063. }
  3064. }
  3065. for (const time of this.times) {
  3066. const duration = time.end - time.start;
  3067. outBuf.push(`${time.name.padEnd(longest)} ${duration}ms\n`);
  3068. }
  3069. return outBuf.join("");
  3070. }
  3071. }
  3072. exports.StatTimer = StatTimer;
  3073. function isValidFetchUrl(url, baseUrl) {
  3074. try {
  3075. const {
  3076. protocol
  3077. } = baseUrl ? new URL(url, baseUrl) : new URL(url);
  3078. return protocol === "http:" || protocol === "https:";
  3079. } catch (ex) {
  3080. return false;
  3081. }
  3082. }
  3083. function loadScript(src, removeScriptElement = false) {
  3084. return new Promise((resolve, reject) => {
  3085. const script = document.createElement("script");
  3086. script.src = src;
  3087. script.onload = function (evt) {
  3088. if (removeScriptElement) {
  3089. script.remove();
  3090. }
  3091. resolve(evt);
  3092. };
  3093. script.onerror = function () {
  3094. reject(new Error(`Cannot load script at: ${script.src}`));
  3095. };
  3096. (document.head || document.documentElement).appendChild(script);
  3097. });
  3098. }
  3099. function deprecated(details) {
  3100. console.log("Deprecated API usage: " + details);
  3101. }
  3102. let pdfDateStringRegex;
  3103. class PDFDateString {
  3104. static toDateObject(input) {
  3105. if (!input || typeof input !== "string") {
  3106. return null;
  3107. }
  3108. if (!pdfDateStringRegex) {
  3109. pdfDateStringRegex = new RegExp("^D:" + "(\\d{4})" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "([Z|+|-])?" + "(\\d{2})?" + "'?" + "(\\d{2})?" + "'?");
  3110. }
  3111. const matches = pdfDateStringRegex.exec(input);
  3112. if (!matches) {
  3113. return null;
  3114. }
  3115. const year = parseInt(matches[1], 10);
  3116. let month = parseInt(matches[2], 10);
  3117. month = month >= 1 && month <= 12 ? month - 1 : 0;
  3118. let day = parseInt(matches[3], 10);
  3119. day = day >= 1 && day <= 31 ? day : 1;
  3120. let hour = parseInt(matches[4], 10);
  3121. hour = hour >= 0 && hour <= 23 ? hour : 0;
  3122. let minute = parseInt(matches[5], 10);
  3123. minute = minute >= 0 && minute <= 59 ? minute : 0;
  3124. let second = parseInt(matches[6], 10);
  3125. second = second >= 0 && second <= 59 ? second : 0;
  3126. const universalTimeRelation = matches[7] || "Z";
  3127. let offsetHour = parseInt(matches[8], 10);
  3128. offsetHour = offsetHour >= 0 && offsetHour <= 23 ? offsetHour : 0;
  3129. let offsetMinute = parseInt(matches[9], 10) || 0;
  3130. offsetMinute = offsetMinute >= 0 && offsetMinute <= 59 ? offsetMinute : 0;
  3131. if (universalTimeRelation === "-") {
  3132. hour += offsetHour;
  3133. minute += offsetMinute;
  3134. } else if (universalTimeRelation === "+") {
  3135. hour -= offsetHour;
  3136. minute -= offsetMinute;
  3137. }
  3138. return new Date(Date.UTC(year, month, day, hour, minute, second));
  3139. }
  3140. }
  3141. exports.PDFDateString = PDFDateString;
  3142. function getXfaPageViewport(xfaPage, {
  3143. scale = 1,
  3144. rotation = 0
  3145. }) {
  3146. const {
  3147. width,
  3148. height
  3149. } = xfaPage.attributes.style;
  3150. const viewBox = [0, 0, parseInt(width), parseInt(height)];
  3151. return new PageViewport({
  3152. viewBox,
  3153. scale,
  3154. rotation
  3155. });
  3156. }
  3157. /***/ }),
  3158. /* 6 */
  3159. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3160. Object.defineProperty(exports, "__esModule", ({
  3161. value: true
  3162. }));
  3163. exports.BaseStandardFontDataFactory = exports.BaseSVGFactory = exports.BaseCanvasFactory = exports.BaseCMapReaderFactory = void 0;
  3164. var _util = __w_pdfjs_require__(1);
  3165. class BaseCanvasFactory {
  3166. constructor() {
  3167. if (this.constructor === BaseCanvasFactory) {
  3168. (0, _util.unreachable)("Cannot initialize BaseCanvasFactory.");
  3169. }
  3170. }
  3171. create(width, height) {
  3172. if (width <= 0 || height <= 0) {
  3173. throw new Error("Invalid canvas size");
  3174. }
  3175. const canvas = this._createCanvas(width, height);
  3176. return {
  3177. canvas,
  3178. context: canvas.getContext("2d")
  3179. };
  3180. }
  3181. reset(canvasAndContext, width, height) {
  3182. if (!canvasAndContext.canvas) {
  3183. throw new Error("Canvas is not specified");
  3184. }
  3185. if (width <= 0 || height <= 0) {
  3186. throw new Error("Invalid canvas size");
  3187. }
  3188. canvasAndContext.canvas.width = width;
  3189. canvasAndContext.canvas.height = height;
  3190. }
  3191. destroy(canvasAndContext) {
  3192. if (!canvasAndContext.canvas) {
  3193. throw new Error("Canvas is not specified");
  3194. }
  3195. canvasAndContext.canvas.width = 0;
  3196. canvasAndContext.canvas.height = 0;
  3197. canvasAndContext.canvas = null;
  3198. canvasAndContext.context = null;
  3199. }
  3200. _createCanvas(width, height) {
  3201. (0, _util.unreachable)("Abstract method `_createCanvas` called.");
  3202. }
  3203. }
  3204. exports.BaseCanvasFactory = BaseCanvasFactory;
  3205. class BaseCMapReaderFactory {
  3206. constructor({
  3207. baseUrl = null,
  3208. isCompressed = false
  3209. }) {
  3210. if (this.constructor === BaseCMapReaderFactory) {
  3211. (0, _util.unreachable)("Cannot initialize BaseCMapReaderFactory.");
  3212. }
  3213. this.baseUrl = baseUrl;
  3214. this.isCompressed = isCompressed;
  3215. }
  3216. async fetch({
  3217. name
  3218. }) {
  3219. if (!this.baseUrl) {
  3220. throw new Error('The CMap "baseUrl" parameter must be specified, ensure that ' + 'the "cMapUrl" and "cMapPacked" API parameters are provided.');
  3221. }
  3222. if (!name) {
  3223. throw new Error("CMap name must be specified.");
  3224. }
  3225. const url = this.baseUrl + name + (this.isCompressed ? ".bcmap" : "");
  3226. const compressionType = this.isCompressed ? _util.CMapCompressionType.BINARY : _util.CMapCompressionType.NONE;
  3227. return this._fetchData(url, compressionType).catch(reason => {
  3228. throw new Error(`Unable to load ${this.isCompressed ? "binary " : ""}CMap at: ${url}`);
  3229. });
  3230. }
  3231. _fetchData(url, compressionType) {
  3232. (0, _util.unreachable)("Abstract method `_fetchData` called.");
  3233. }
  3234. }
  3235. exports.BaseCMapReaderFactory = BaseCMapReaderFactory;
  3236. class BaseStandardFontDataFactory {
  3237. constructor({
  3238. baseUrl = null
  3239. }) {
  3240. if (this.constructor === BaseStandardFontDataFactory) {
  3241. (0, _util.unreachable)("Cannot initialize BaseStandardFontDataFactory.");
  3242. }
  3243. this.baseUrl = baseUrl;
  3244. }
  3245. async fetch({
  3246. filename
  3247. }) {
  3248. if (!this.baseUrl) {
  3249. throw new Error('The standard font "baseUrl" parameter must be specified, ensure that ' + 'the "standardFontDataUrl" API parameter is provided.');
  3250. }
  3251. if (!filename) {
  3252. throw new Error("Font filename must be specified.");
  3253. }
  3254. const url = `${this.baseUrl}${filename}`;
  3255. return this._fetchData(url).catch(reason => {
  3256. throw new Error(`Unable to load font data at: ${url}`);
  3257. });
  3258. }
  3259. _fetchData(url) {
  3260. (0, _util.unreachable)("Abstract method `_fetchData` called.");
  3261. }
  3262. }
  3263. exports.BaseStandardFontDataFactory = BaseStandardFontDataFactory;
  3264. class BaseSVGFactory {
  3265. constructor() {
  3266. if (this.constructor === BaseSVGFactory) {
  3267. (0, _util.unreachable)("Cannot initialize BaseSVGFactory.");
  3268. }
  3269. }
  3270. create(width, height) {
  3271. if (width <= 0 || height <= 0) {
  3272. throw new Error("Invalid SVG dimensions");
  3273. }
  3274. const svg = this._createSVG("svg:svg");
  3275. svg.setAttribute("version", "1.1");
  3276. svg.setAttribute("width", `${width}px`);
  3277. svg.setAttribute("height", `${height}px`);
  3278. svg.setAttribute("preserveAspectRatio", "none");
  3279. svg.setAttribute("viewBox", `0 0 ${width} ${height}`);
  3280. return svg;
  3281. }
  3282. createElement(type) {
  3283. if (typeof type !== "string") {
  3284. throw new Error("Invalid SVG element type");
  3285. }
  3286. return this._createSVG(type);
  3287. }
  3288. _createSVG(type) {
  3289. (0, _util.unreachable)("Abstract method `_createSVG` called.");
  3290. }
  3291. }
  3292. exports.BaseSVGFactory = BaseSVGFactory;
  3293. /***/ }),
  3294. /* 7 */
  3295. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3296. Object.defineProperty(exports, "__esModule", ({
  3297. value: true
  3298. }));
  3299. exports.FontLoader = exports.FontFaceObject = void 0;
  3300. var _util = __w_pdfjs_require__(1);
  3301. class BaseFontLoader {
  3302. constructor({
  3303. docId,
  3304. onUnsupportedFeature,
  3305. ownerDocument = globalThis.document,
  3306. styleElement = null
  3307. }) {
  3308. if (this.constructor === BaseFontLoader) {
  3309. (0, _util.unreachable)("Cannot initialize BaseFontLoader.");
  3310. }
  3311. this.docId = docId;
  3312. this._onUnsupportedFeature = onUnsupportedFeature;
  3313. this._document = ownerDocument;
  3314. this.nativeFontFaces = [];
  3315. this.styleElement = null;
  3316. }
  3317. addNativeFontFace(nativeFontFace) {
  3318. this.nativeFontFaces.push(nativeFontFace);
  3319. this._document.fonts.add(nativeFontFace);
  3320. }
  3321. insertRule(rule) {
  3322. let styleElement = this.styleElement;
  3323. if (!styleElement) {
  3324. styleElement = this.styleElement = this._document.createElement("style");
  3325. styleElement.id = `PDFJS_FONT_STYLE_TAG_${this.docId}`;
  3326. this._document.documentElement.getElementsByTagName("head")[0].appendChild(styleElement);
  3327. }
  3328. const styleSheet = styleElement.sheet;
  3329. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  3330. }
  3331. clear() {
  3332. for (const nativeFontFace of this.nativeFontFaces) {
  3333. this._document.fonts.delete(nativeFontFace);
  3334. }
  3335. this.nativeFontFaces.length = 0;
  3336. if (this.styleElement) {
  3337. this.styleElement.remove();
  3338. this.styleElement = null;
  3339. }
  3340. }
  3341. async bind(font) {
  3342. if (font.attached || font.missingFile) {
  3343. return;
  3344. }
  3345. font.attached = true;
  3346. if (this.isFontLoadingAPISupported) {
  3347. const nativeFontFace = font.createNativeFontFace();
  3348. if (nativeFontFace) {
  3349. this.addNativeFontFace(nativeFontFace);
  3350. try {
  3351. await nativeFontFace.loaded;
  3352. } catch (ex) {
  3353. this._onUnsupportedFeature({
  3354. featureId: _util.UNSUPPORTED_FEATURES.errorFontLoadNative
  3355. });
  3356. (0, _util.warn)(`Failed to load font '${nativeFontFace.family}': '${ex}'.`);
  3357. font.disableFontFace = true;
  3358. throw ex;
  3359. }
  3360. }
  3361. return;
  3362. }
  3363. const rule = font.createFontFaceRule();
  3364. if (rule) {
  3365. this.insertRule(rule);
  3366. if (this.isSyncFontLoadingSupported) {
  3367. return;
  3368. }
  3369. await new Promise(resolve => {
  3370. const request = this._queueLoadingCallback(resolve);
  3371. this._prepareFontLoadEvent([rule], [font], request);
  3372. });
  3373. }
  3374. }
  3375. _queueLoadingCallback(callback) {
  3376. (0, _util.unreachable)("Abstract method `_queueLoadingCallback`.");
  3377. }
  3378. get isFontLoadingAPISupported() {
  3379. const hasFonts = !!this._document?.fonts;
  3380. return (0, _util.shadow)(this, "isFontLoadingAPISupported", hasFonts);
  3381. }
  3382. get isSyncFontLoadingSupported() {
  3383. (0, _util.unreachable)("Abstract method `isSyncFontLoadingSupported`.");
  3384. }
  3385. get _loadTestFont() {
  3386. (0, _util.unreachable)("Abstract method `_loadTestFont`.");
  3387. }
  3388. _prepareFontLoadEvent(rules, fontsToLoad, request) {
  3389. (0, _util.unreachable)("Abstract method `_prepareFontLoadEvent`.");
  3390. }
  3391. }
  3392. let FontLoader;
  3393. exports.FontLoader = FontLoader;
  3394. {
  3395. exports.FontLoader = FontLoader = class GenericFontLoader extends BaseFontLoader {
  3396. constructor(params) {
  3397. super(params);
  3398. this.loadingContext = {
  3399. requests: [],
  3400. nextRequestId: 0
  3401. };
  3402. this.loadTestFontId = 0;
  3403. }
  3404. get isSyncFontLoadingSupported() {
  3405. let supported = false;
  3406. if (typeof navigator === "undefined") {
  3407. supported = true;
  3408. } else {
  3409. const m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(navigator.userAgent);
  3410. if (m?.[1] >= 14) {
  3411. supported = true;
  3412. }
  3413. }
  3414. return (0, _util.shadow)(this, "isSyncFontLoadingSupported", supported);
  3415. }
  3416. _queueLoadingCallback(callback) {
  3417. function completeRequest() {
  3418. (0, _util.assert)(!request.done, "completeRequest() cannot be called twice.");
  3419. request.done = true;
  3420. while (context.requests.length > 0 && context.requests[0].done) {
  3421. const otherRequest = context.requests.shift();
  3422. setTimeout(otherRequest.callback, 0);
  3423. }
  3424. }
  3425. const context = this.loadingContext;
  3426. const request = {
  3427. id: `pdfjs-font-loading-${context.nextRequestId++}`,
  3428. done: false,
  3429. complete: completeRequest,
  3430. callback
  3431. };
  3432. context.requests.push(request);
  3433. return request;
  3434. }
  3435. get _loadTestFont() {
  3436. const getLoadTestFont = function () {
  3437. 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==");
  3438. };
  3439. return (0, _util.shadow)(this, "_loadTestFont", getLoadTestFont());
  3440. }
  3441. _prepareFontLoadEvent(rules, fonts, request) {
  3442. function int32(data, offset) {
  3443. return data.charCodeAt(offset) << 24 | data.charCodeAt(offset + 1) << 16 | data.charCodeAt(offset + 2) << 8 | data.charCodeAt(offset + 3) & 0xff;
  3444. }
  3445. function spliceString(s, offset, remove, insert) {
  3446. const chunk1 = s.substring(0, offset);
  3447. const chunk2 = s.substring(offset + remove);
  3448. return chunk1 + insert + chunk2;
  3449. }
  3450. let i, ii;
  3451. const canvas = this._document.createElement("canvas");
  3452. canvas.width = 1;
  3453. canvas.height = 1;
  3454. const ctx = canvas.getContext("2d");
  3455. let called = 0;
  3456. function isFontReady(name, callback) {
  3457. called++;
  3458. if (called > 30) {
  3459. (0, _util.warn)("Load test font never loaded.");
  3460. callback();
  3461. return;
  3462. }
  3463. ctx.font = "30px " + name;
  3464. ctx.fillText(".", 0, 20);
  3465. const imageData = ctx.getImageData(0, 0, 1, 1);
  3466. if (imageData.data[3] > 0) {
  3467. callback();
  3468. return;
  3469. }
  3470. setTimeout(isFontReady.bind(null, name, callback));
  3471. }
  3472. const loadTestFontId = `lt${Date.now()}${this.loadTestFontId++}`;
  3473. let data = this._loadTestFont;
  3474. const COMMENT_OFFSET = 976;
  3475. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length, loadTestFontId);
  3476. const CFF_CHECKSUM_OFFSET = 16;
  3477. const XXXX_VALUE = 0x58585858;
  3478. let checksum = int32(data, CFF_CHECKSUM_OFFSET);
  3479. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  3480. checksum = checksum - XXXX_VALUE + int32(loadTestFontId, i) | 0;
  3481. }
  3482. if (i < loadTestFontId.length) {
  3483. checksum = checksum - XXXX_VALUE + int32(loadTestFontId + "XXX", i) | 0;
  3484. }
  3485. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, (0, _util.string32)(checksum));
  3486. const url = `url(data:font/opentype;base64,${btoa(data)});`;
  3487. const rule = `@font-face {font-family:"${loadTestFontId}";src:${url}}`;
  3488. this.insertRule(rule);
  3489. const names = [];
  3490. for (const font of fonts) {
  3491. names.push(font.loadedName);
  3492. }
  3493. names.push(loadTestFontId);
  3494. const div = this._document.createElement("div");
  3495. div.style.visibility = "hidden";
  3496. div.style.width = div.style.height = "10px";
  3497. div.style.position = "absolute";
  3498. div.style.top = div.style.left = "0px";
  3499. for (const name of names) {
  3500. const span = this._document.createElement("span");
  3501. span.textContent = "Hi";
  3502. span.style.fontFamily = name;
  3503. div.appendChild(span);
  3504. }
  3505. this._document.body.appendChild(div);
  3506. isFontReady(loadTestFontId, () => {
  3507. div.remove();
  3508. request.complete();
  3509. });
  3510. }
  3511. };
  3512. }
  3513. class FontFaceObject {
  3514. constructor(translatedData, {
  3515. isEvalSupported = true,
  3516. disableFontFace = false,
  3517. ignoreErrors = false,
  3518. onUnsupportedFeature,
  3519. fontRegistry = null
  3520. }) {
  3521. this.compiledGlyphs = Object.create(null);
  3522. for (const i in translatedData) {
  3523. this[i] = translatedData[i];
  3524. }
  3525. this.isEvalSupported = isEvalSupported !== false;
  3526. this.disableFontFace = disableFontFace === true;
  3527. this.ignoreErrors = ignoreErrors === true;
  3528. this._onUnsupportedFeature = onUnsupportedFeature;
  3529. this.fontRegistry = fontRegistry;
  3530. }
  3531. createNativeFontFace() {
  3532. if (!this.data || this.disableFontFace) {
  3533. return null;
  3534. }
  3535. let nativeFontFace;
  3536. if (!this.cssFontInfo) {
  3537. nativeFontFace = new FontFace(this.loadedName, this.data, {});
  3538. } else {
  3539. const css = {
  3540. weight: this.cssFontInfo.fontWeight
  3541. };
  3542. if (this.cssFontInfo.italicAngle) {
  3543. css.style = `oblique ${this.cssFontInfo.italicAngle}deg`;
  3544. }
  3545. nativeFontFace = new FontFace(this.cssFontInfo.fontFamily, this.data, css);
  3546. }
  3547. if (this.fontRegistry) {
  3548. this.fontRegistry.registerFont(this);
  3549. }
  3550. return nativeFontFace;
  3551. }
  3552. createFontFaceRule() {
  3553. if (!this.data || this.disableFontFace) {
  3554. return null;
  3555. }
  3556. const data = (0, _util.bytesToString)(this.data);
  3557. const url = `url(data:${this.mimetype};base64,${btoa(data)});`;
  3558. let rule;
  3559. if (!this.cssFontInfo) {
  3560. rule = `@font-face {font-family:"${this.loadedName}";src:${url}}`;
  3561. } else {
  3562. let css = `font-weight: ${this.cssFontInfo.fontWeight};`;
  3563. if (this.cssFontInfo.italicAngle) {
  3564. css += `font-style: oblique ${this.cssFontInfo.italicAngle}deg;`;
  3565. }
  3566. rule = `@font-face {font-family:"${this.cssFontInfo.fontFamily}";${css}src:${url}}`;
  3567. }
  3568. if (this.fontRegistry) {
  3569. this.fontRegistry.registerFont(this, url);
  3570. }
  3571. return rule;
  3572. }
  3573. getPathGenerator(objs, character) {
  3574. if (this.compiledGlyphs[character] !== undefined) {
  3575. return this.compiledGlyphs[character];
  3576. }
  3577. let cmds;
  3578. try {
  3579. cmds = objs.get(this.loadedName + "_path_" + character);
  3580. } catch (ex) {
  3581. if (!this.ignoreErrors) {
  3582. throw ex;
  3583. }
  3584. this._onUnsupportedFeature({
  3585. featureId: _util.UNSUPPORTED_FEATURES.errorFontGetPath
  3586. });
  3587. (0, _util.warn)(`getPathGenerator - ignoring character: "${ex}".`);
  3588. return this.compiledGlyphs[character] = function (c, size) {};
  3589. }
  3590. if (this.isEvalSupported && _util.IsEvalSupportedCached.value) {
  3591. const jsBuf = [];
  3592. for (const current of cmds) {
  3593. const args = current.args !== undefined ? current.args.join(",") : "";
  3594. jsBuf.push("c.", current.cmd, "(", args, ");\n");
  3595. }
  3596. return this.compiledGlyphs[character] = new Function("c", "size", jsBuf.join(""));
  3597. }
  3598. return this.compiledGlyphs[character] = function (c, size) {
  3599. for (const current of cmds) {
  3600. if (current.cmd === "scale") {
  3601. current.args = [size, -size];
  3602. }
  3603. c[current.cmd].apply(c, current.args);
  3604. }
  3605. };
  3606. }
  3607. }
  3608. exports.FontFaceObject = FontFaceObject;
  3609. /***/ }),
  3610. /* 8 */
  3611. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3612. Object.defineProperty(exports, "__esModule", ({
  3613. value: true
  3614. }));
  3615. exports.NodeStandardFontDataFactory = exports.NodeCanvasFactory = exports.NodeCMapReaderFactory = void 0;
  3616. var _base_factory = __w_pdfjs_require__(6);
  3617. var _is_node = __w_pdfjs_require__(3);
  3618. var _util = __w_pdfjs_require__(1);
  3619. let NodeCanvasFactory = class {
  3620. constructor() {
  3621. (0, _util.unreachable)("Not implemented: NodeCanvasFactory");
  3622. }
  3623. };
  3624. exports.NodeCanvasFactory = NodeCanvasFactory;
  3625. let NodeCMapReaderFactory = class {
  3626. constructor() {
  3627. (0, _util.unreachable)("Not implemented: NodeCMapReaderFactory");
  3628. }
  3629. };
  3630. exports.NodeCMapReaderFactory = NodeCMapReaderFactory;
  3631. let NodeStandardFontDataFactory = class {
  3632. constructor() {
  3633. (0, _util.unreachable)("Not implemented: NodeStandardFontDataFactory");
  3634. }
  3635. };
  3636. exports.NodeStandardFontDataFactory = NodeStandardFontDataFactory;
  3637. if (_is_node.isNodeJS) {
  3638. const fetchData = function (url) {
  3639. return new Promise((resolve, reject) => {
  3640. const fs = require("fs");
  3641. fs.readFile(url, (error, data) => {
  3642. if (error || !data) {
  3643. reject(new Error(error));
  3644. return;
  3645. }
  3646. resolve(new Uint8Array(data));
  3647. });
  3648. });
  3649. };
  3650. exports.NodeCanvasFactory = NodeCanvasFactory = class extends _base_factory.BaseCanvasFactory {
  3651. _createCanvas(width, height) {
  3652. const Canvas = require("canvas");
  3653. return Canvas.createCanvas(width, height);
  3654. }
  3655. };
  3656. exports.NodeCMapReaderFactory = NodeCMapReaderFactory = class extends _base_factory.BaseCMapReaderFactory {
  3657. _fetchData(url, compressionType) {
  3658. return fetchData(url).then(data => {
  3659. return {
  3660. cMapData: data,
  3661. compressionType
  3662. };
  3663. });
  3664. }
  3665. };
  3666. exports.NodeStandardFontDataFactory = NodeStandardFontDataFactory = class extends _base_factory.BaseStandardFontDataFactory {
  3667. _fetchData(url) {
  3668. return fetchData(url);
  3669. }
  3670. };
  3671. }
  3672. /***/ }),
  3673. /* 9 */
  3674. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3675. Object.defineProperty(exports, "__esModule", ({
  3676. value: true
  3677. }));
  3678. exports.AnnotationStorage = void 0;
  3679. var _util = __w_pdfjs_require__(1);
  3680. class AnnotationStorage {
  3681. constructor() {
  3682. this._storage = new Map();
  3683. this._timeStamp = Date.now();
  3684. this._modified = false;
  3685. this.onSetModified = null;
  3686. this.onResetModified = null;
  3687. }
  3688. getValue(key, defaultValue) {
  3689. const value = this._storage.get(key);
  3690. if (value === undefined) {
  3691. return defaultValue;
  3692. }
  3693. return Object.assign(defaultValue, value);
  3694. }
  3695. setValue(key, value) {
  3696. const obj = this._storage.get(key);
  3697. let modified = false;
  3698. if (obj !== undefined) {
  3699. for (const [entry, val] of Object.entries(value)) {
  3700. if (obj[entry] !== val) {
  3701. modified = true;
  3702. obj[entry] = val;
  3703. }
  3704. }
  3705. } else {
  3706. modified = true;
  3707. this._storage.set(key, value);
  3708. }
  3709. if (modified) {
  3710. this._timeStamp = Date.now();
  3711. this._setModified();
  3712. }
  3713. }
  3714. getAll() {
  3715. return this._storage.size > 0 ? (0, _util.objectFromMap)(this._storage) : null;
  3716. }
  3717. get size() {
  3718. return this._storage.size;
  3719. }
  3720. _setModified() {
  3721. if (!this._modified) {
  3722. this._modified = true;
  3723. if (typeof this.onSetModified === "function") {
  3724. this.onSetModified();
  3725. }
  3726. }
  3727. }
  3728. resetModified() {
  3729. if (this._modified) {
  3730. this._modified = false;
  3731. if (typeof this.onResetModified === "function") {
  3732. this.onResetModified();
  3733. }
  3734. }
  3735. }
  3736. get serializable() {
  3737. return this._storage.size > 0 ? this._storage : null;
  3738. }
  3739. get lastModified() {
  3740. return this._timeStamp.toString();
  3741. }
  3742. }
  3743. exports.AnnotationStorage = AnnotationStorage;
  3744. /***/ }),
  3745. /* 10 */
  3746. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3747. Object.defineProperty(exports, "__esModule", ({
  3748. value: true
  3749. }));
  3750. exports.CanvasGraphics = void 0;
  3751. var _util = __w_pdfjs_require__(1);
  3752. var _pattern_helper = __w_pdfjs_require__(11);
  3753. var _display_utils = __w_pdfjs_require__(5);
  3754. const MIN_FONT_SIZE = 16;
  3755. const MAX_FONT_SIZE = 100;
  3756. const MAX_GROUP_SIZE = 4096;
  3757. const EXECUTION_TIME = 15;
  3758. const EXECUTION_STEPS = 10;
  3759. const COMPILE_TYPE3_GLYPHS = true;
  3760. const MAX_SIZE_TO_COMPILE = 1000;
  3761. const FULL_CHUNK_HEIGHT = 16;
  3762. const LINEWIDTH_SCALE_FACTOR = 1.000001;
  3763. function mirrorContextOperations(ctx, destCtx) {
  3764. if (ctx._removeMirroring) {
  3765. throw new Error("Context is already forwarding operations.");
  3766. }
  3767. ctx.__originalSave = ctx.save;
  3768. ctx.__originalRestore = ctx.restore;
  3769. ctx.__originalRotate = ctx.rotate;
  3770. ctx.__originalScale = ctx.scale;
  3771. ctx.__originalTranslate = ctx.translate;
  3772. ctx.__originalTransform = ctx.transform;
  3773. ctx.__originalSetTransform = ctx.setTransform;
  3774. ctx.__originalResetTransform = ctx.resetTransform;
  3775. ctx.__originalClip = ctx.clip;
  3776. ctx.__originalMoveTo = ctx.moveTo;
  3777. ctx.__originalLineTo = ctx.lineTo;
  3778. ctx.__originalBezierCurveTo = ctx.bezierCurveTo;
  3779. ctx.__originalRect = ctx.rect;
  3780. ctx.__originalClosePath = ctx.closePath;
  3781. ctx.__originalBeginPath = ctx.beginPath;
  3782. ctx._removeMirroring = () => {
  3783. ctx.save = ctx.__originalSave;
  3784. ctx.restore = ctx.__originalRestore;
  3785. ctx.rotate = ctx.__originalRotate;
  3786. ctx.scale = ctx.__originalScale;
  3787. ctx.translate = ctx.__originalTranslate;
  3788. ctx.transform = ctx.__originalTransform;
  3789. ctx.setTransform = ctx.__originalSetTransform;
  3790. ctx.resetTransform = ctx.__originalResetTransform;
  3791. ctx.clip = ctx.__originalClip;
  3792. ctx.moveTo = ctx.__originalMoveTo;
  3793. ctx.lineTo = ctx.__originalLineTo;
  3794. ctx.bezierCurveTo = ctx.__originalBezierCurveTo;
  3795. ctx.rect = ctx.__originalRect;
  3796. ctx.closePath = ctx.__originalClosePath;
  3797. ctx.beginPath = ctx.__originalBeginPath;
  3798. delete ctx._removeMirroring;
  3799. };
  3800. ctx.save = function ctxSave() {
  3801. destCtx.save();
  3802. this.__originalSave();
  3803. };
  3804. ctx.restore = function ctxRestore() {
  3805. destCtx.restore();
  3806. this.__originalRestore();
  3807. };
  3808. ctx.translate = function ctxTranslate(x, y) {
  3809. destCtx.translate(x, y);
  3810. this.__originalTranslate(x, y);
  3811. };
  3812. ctx.scale = function ctxScale(x, y) {
  3813. destCtx.scale(x, y);
  3814. this.__originalScale(x, y);
  3815. };
  3816. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  3817. destCtx.transform(a, b, c, d, e, f);
  3818. this.__originalTransform(a, b, c, d, e, f);
  3819. };
  3820. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  3821. destCtx.setTransform(a, b, c, d, e, f);
  3822. this.__originalSetTransform(a, b, c, d, e, f);
  3823. };
  3824. ctx.resetTransform = function ctxResetTransform() {
  3825. destCtx.resetTransform();
  3826. this.__originalResetTransform();
  3827. };
  3828. ctx.rotate = function ctxRotate(angle) {
  3829. destCtx.rotate(angle);
  3830. this.__originalRotate(angle);
  3831. };
  3832. ctx.clip = function ctxRotate(rule) {
  3833. destCtx.clip(rule);
  3834. this.__originalClip(rule);
  3835. };
  3836. ctx.moveTo = function (x, y) {
  3837. destCtx.moveTo(x, y);
  3838. this.__originalMoveTo(x, y);
  3839. };
  3840. ctx.lineTo = function (x, y) {
  3841. destCtx.lineTo(x, y);
  3842. this.__originalLineTo(x, y);
  3843. };
  3844. ctx.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
  3845. destCtx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
  3846. this.__originalBezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
  3847. };
  3848. ctx.rect = function (x, y, width, height) {
  3849. destCtx.rect(x, y, width, height);
  3850. this.__originalRect(x, y, width, height);
  3851. };
  3852. ctx.closePath = function () {
  3853. destCtx.closePath();
  3854. this.__originalClosePath();
  3855. };
  3856. ctx.beginPath = function () {
  3857. destCtx.beginPath();
  3858. this.__originalBeginPath();
  3859. };
  3860. }
  3861. function addContextCurrentTransform(ctx) {
  3862. if (ctx._transformStack) {
  3863. ctx._transformStack = [];
  3864. }
  3865. if (ctx.mozCurrentTransform) {
  3866. return;
  3867. }
  3868. ctx._originalSave = ctx.save;
  3869. ctx._originalRestore = ctx.restore;
  3870. ctx._originalRotate = ctx.rotate;
  3871. ctx._originalScale = ctx.scale;
  3872. ctx._originalTranslate = ctx.translate;
  3873. ctx._originalTransform = ctx.transform;
  3874. ctx._originalSetTransform = ctx.setTransform;
  3875. ctx._originalResetTransform = ctx.resetTransform;
  3876. ctx._transformMatrix = ctx._transformMatrix || [1, 0, 0, 1, 0, 0];
  3877. ctx._transformStack = [];
  3878. try {
  3879. const desc = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(ctx), "lineWidth");
  3880. ctx._setLineWidth = desc.set;
  3881. ctx._getLineWidth = desc.get;
  3882. Object.defineProperty(ctx, "lineWidth", {
  3883. set: function setLineWidth(width) {
  3884. this._setLineWidth(width * LINEWIDTH_SCALE_FACTOR);
  3885. },
  3886. get: function getLineWidth() {
  3887. return this._getLineWidth();
  3888. }
  3889. });
  3890. } catch (_) {}
  3891. Object.defineProperty(ctx, "mozCurrentTransform", {
  3892. get: function getCurrentTransform() {
  3893. return this._transformMatrix;
  3894. }
  3895. });
  3896. Object.defineProperty(ctx, "mozCurrentTransformInverse", {
  3897. get: function getCurrentTransformInverse() {
  3898. const [a, b, c, d, e, f] = this._transformMatrix;
  3899. const ad_bc = a * d - b * c;
  3900. const bc_ad = b * c - a * d;
  3901. 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];
  3902. }
  3903. });
  3904. ctx.save = function ctxSave() {
  3905. const old = this._transformMatrix;
  3906. this._transformStack.push(old);
  3907. this._transformMatrix = old.slice(0, 6);
  3908. this._originalSave();
  3909. };
  3910. ctx.restore = function ctxRestore() {
  3911. if (this._transformStack.length === 0) {
  3912. (0, _util.warn)("Tried to restore a ctx when the stack was already empty.");
  3913. }
  3914. const prev = this._transformStack.pop();
  3915. if (prev) {
  3916. this._transformMatrix = prev;
  3917. this._originalRestore();
  3918. }
  3919. };
  3920. ctx.translate = function ctxTranslate(x, y) {
  3921. const m = this._transformMatrix;
  3922. m[4] = m[0] * x + m[2] * y + m[4];
  3923. m[5] = m[1] * x + m[3] * y + m[5];
  3924. this._originalTranslate(x, y);
  3925. };
  3926. ctx.scale = function ctxScale(x, y) {
  3927. const m = this._transformMatrix;
  3928. m[0] *= x;
  3929. m[1] *= x;
  3930. m[2] *= y;
  3931. m[3] *= y;
  3932. this._originalScale(x, y);
  3933. };
  3934. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  3935. const m = this._transformMatrix;
  3936. 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]];
  3937. ctx._originalTransform(a, b, c, d, e, f);
  3938. };
  3939. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  3940. this._transformMatrix = [a, b, c, d, e, f];
  3941. ctx._originalSetTransform(a, b, c, d, e, f);
  3942. };
  3943. ctx.resetTransform = function ctxResetTransform() {
  3944. this._transformMatrix = [1, 0, 0, 1, 0, 0];
  3945. ctx._originalResetTransform();
  3946. };
  3947. ctx.rotate = function ctxRotate(angle) {
  3948. const cosValue = Math.cos(angle);
  3949. const sinValue = Math.sin(angle);
  3950. const m = this._transformMatrix;
  3951. 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]];
  3952. this._originalRotate(angle);
  3953. };
  3954. }
  3955. class CachedCanvases {
  3956. constructor(canvasFactory) {
  3957. this.canvasFactory = canvasFactory;
  3958. this.cache = Object.create(null);
  3959. }
  3960. getCanvas(id, width, height, trackTransform) {
  3961. let canvasEntry;
  3962. if (this.cache[id] !== undefined) {
  3963. canvasEntry = this.cache[id];
  3964. this.canvasFactory.reset(canvasEntry, width, height);
  3965. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  3966. } else {
  3967. canvasEntry = this.canvasFactory.create(width, height);
  3968. this.cache[id] = canvasEntry;
  3969. }
  3970. if (trackTransform) {
  3971. addContextCurrentTransform(canvasEntry.context);
  3972. }
  3973. return canvasEntry;
  3974. }
  3975. clear() {
  3976. for (const id in this.cache) {
  3977. const canvasEntry = this.cache[id];
  3978. this.canvasFactory.destroy(canvasEntry);
  3979. delete this.cache[id];
  3980. }
  3981. }
  3982. }
  3983. function compileType3Glyph(imgData) {
  3984. const POINT_TO_PROCESS_LIMIT = 1000;
  3985. const POINT_TYPES = new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  3986. const width = imgData.width,
  3987. height = imgData.height,
  3988. width1 = width + 1;
  3989. let i, ii, j, j0;
  3990. const points = new Uint8Array(width1 * (height + 1));
  3991. const lineSize = width + 7 & ~7,
  3992. data0 = imgData.data;
  3993. const data = new Uint8Array(lineSize * height);
  3994. let pos = 0;
  3995. for (i = 0, ii = data0.length; i < ii; i++) {
  3996. const elem = data0[i];
  3997. let mask = 128;
  3998. while (mask > 0) {
  3999. data[pos++] = elem & mask ? 0 : 255;
  4000. mask >>= 1;
  4001. }
  4002. }
  4003. let count = 0;
  4004. pos = 0;
  4005. if (data[pos] !== 0) {
  4006. points[0] = 1;
  4007. ++count;
  4008. }
  4009. for (j = 1; j < width; j++) {
  4010. if (data[pos] !== data[pos + 1]) {
  4011. points[j] = data[pos] ? 2 : 1;
  4012. ++count;
  4013. }
  4014. pos++;
  4015. }
  4016. if (data[pos] !== 0) {
  4017. points[j] = 2;
  4018. ++count;
  4019. }
  4020. for (i = 1; i < height; i++) {
  4021. pos = i * lineSize;
  4022. j0 = i * width1;
  4023. if (data[pos - lineSize] !== data[pos]) {
  4024. points[j0] = data[pos] ? 1 : 8;
  4025. ++count;
  4026. }
  4027. let sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  4028. for (j = 1; j < width; j++) {
  4029. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) + (data[pos - lineSize + 1] ? 8 : 0);
  4030. if (POINT_TYPES[sum]) {
  4031. points[j0 + j] = POINT_TYPES[sum];
  4032. ++count;
  4033. }
  4034. pos++;
  4035. }
  4036. if (data[pos - lineSize] !== data[pos]) {
  4037. points[j0 + j] = data[pos] ? 2 : 4;
  4038. ++count;
  4039. }
  4040. if (count > POINT_TO_PROCESS_LIMIT) {
  4041. return null;
  4042. }
  4043. }
  4044. pos = lineSize * (height - 1);
  4045. j0 = i * width1;
  4046. if (data[pos] !== 0) {
  4047. points[j0] = 8;
  4048. ++count;
  4049. }
  4050. for (j = 1; j < width; j++) {
  4051. if (data[pos] !== data[pos + 1]) {
  4052. points[j0 + j] = data[pos] ? 4 : 8;
  4053. ++count;
  4054. }
  4055. pos++;
  4056. }
  4057. if (data[pos] !== 0) {
  4058. points[j0 + j] = 4;
  4059. ++count;
  4060. }
  4061. if (count > POINT_TO_PROCESS_LIMIT) {
  4062. return null;
  4063. }
  4064. const steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  4065. const outlines = [];
  4066. for (i = 0; count && i <= height; i++) {
  4067. let p = i * width1;
  4068. const end = p + width;
  4069. while (p < end && !points[p]) {
  4070. p++;
  4071. }
  4072. if (p === end) {
  4073. continue;
  4074. }
  4075. const coords = [p % width1, i];
  4076. const p0 = p;
  4077. let type = points[p];
  4078. do {
  4079. const step = steps[type];
  4080. do {
  4081. p += step;
  4082. } while (!points[p]);
  4083. const pp = points[p];
  4084. if (pp !== 5 && pp !== 10) {
  4085. type = pp;
  4086. points[p] = 0;
  4087. } else {
  4088. type = pp & 0x33 * type >> 4;
  4089. points[p] &= type >> 2 | type << 2;
  4090. }
  4091. coords.push(p % width1, p / width1 | 0);
  4092. if (!points[p]) {
  4093. --count;
  4094. }
  4095. } while (p0 !== p);
  4096. outlines.push(coords);
  4097. --i;
  4098. }
  4099. const drawOutline = function (c) {
  4100. c.save();
  4101. c.scale(1 / width, -1 / height);
  4102. c.translate(0, -height);
  4103. c.beginPath();
  4104. for (let k = 0, kk = outlines.length; k < kk; k++) {
  4105. const o = outlines[k];
  4106. c.moveTo(o[0], o[1]);
  4107. for (let l = 2, ll = o.length; l < ll; l += 2) {
  4108. c.lineTo(o[l], o[l + 1]);
  4109. }
  4110. }
  4111. c.fill();
  4112. c.beginPath();
  4113. c.restore();
  4114. };
  4115. return drawOutline;
  4116. }
  4117. class CanvasExtraState {
  4118. constructor(width, height) {
  4119. this.alphaIsShape = false;
  4120. this.fontSize = 0;
  4121. this.fontSizeScale = 1;
  4122. this.textMatrix = _util.IDENTITY_MATRIX;
  4123. this.textMatrixScale = 1;
  4124. this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
  4125. this.leading = 0;
  4126. this.x = 0;
  4127. this.y = 0;
  4128. this.lineX = 0;
  4129. this.lineY = 0;
  4130. this.charSpacing = 0;
  4131. this.wordSpacing = 0;
  4132. this.textHScale = 1;
  4133. this.textRenderingMode = _util.TextRenderingMode.FILL;
  4134. this.textRise = 0;
  4135. this.fillColor = "#000000";
  4136. this.strokeColor = "#000000";
  4137. this.patternFill = false;
  4138. this.fillAlpha = 1;
  4139. this.strokeAlpha = 1;
  4140. this.lineWidth = 1;
  4141. this.activeSMask = null;
  4142. this.transferMaps = null;
  4143. this.startNewPathAndClipBox([0, 0, width, height]);
  4144. }
  4145. clone() {
  4146. const clone = Object.create(this);
  4147. clone.clipBox = this.clipBox.slice();
  4148. return clone;
  4149. }
  4150. setCurrentPoint(x, y) {
  4151. this.x = x;
  4152. this.y = y;
  4153. }
  4154. updatePathMinMax(transform, x, y) {
  4155. [x, y] = _util.Util.applyTransform([x, y], transform);
  4156. this.minX = Math.min(this.minX, x);
  4157. this.minY = Math.min(this.minY, y);
  4158. this.maxX = Math.max(this.maxX, x);
  4159. this.maxY = Math.max(this.maxY, y);
  4160. }
  4161. updateCurvePathMinMax(transform, x0, y0, x1, y1, x2, y2, x3, y3) {
  4162. const box = _util.Util.bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3);
  4163. this.updatePathMinMax(transform, box[0], box[1]);
  4164. this.updatePathMinMax(transform, box[2], box[3]);
  4165. }
  4166. getPathBoundingBox(pathType = _pattern_helper.PathType.FILL, transform = null) {
  4167. const box = [this.minX, this.minY, this.maxX, this.maxY];
  4168. if (pathType === _pattern_helper.PathType.STROKE) {
  4169. if (!transform) {
  4170. (0, _util.unreachable)("Stroke bounding box must include transform.");
  4171. }
  4172. const scale = _util.Util.singularValueDecompose2dScale(transform);
  4173. const xStrokePad = scale[0] * this.lineWidth / 2;
  4174. const yStrokePad = scale[1] * this.lineWidth / 2;
  4175. box[0] -= xStrokePad;
  4176. box[1] -= yStrokePad;
  4177. box[2] += xStrokePad;
  4178. box[3] += yStrokePad;
  4179. }
  4180. return box;
  4181. }
  4182. updateClipFromPath() {
  4183. const intersect = _util.Util.intersect(this.clipBox, this.getPathBoundingBox());
  4184. this.startNewPathAndClipBox(intersect || [0, 0, 0, 0]);
  4185. }
  4186. startNewPathAndClipBox(box) {
  4187. this.clipBox = box;
  4188. this.minX = Infinity;
  4189. this.minY = Infinity;
  4190. this.maxX = 0;
  4191. this.maxY = 0;
  4192. }
  4193. getClippedPathBoundingBox(pathType = _pattern_helper.PathType.FILL, transform = null) {
  4194. return _util.Util.intersect(this.clipBox, this.getPathBoundingBox(pathType, transform));
  4195. }
  4196. }
  4197. function putBinaryImageData(ctx, imgData, transferMaps = null) {
  4198. if (typeof ImageData !== "undefined" && imgData instanceof ImageData) {
  4199. ctx.putImageData(imgData, 0, 0);
  4200. return;
  4201. }
  4202. const height = imgData.height,
  4203. width = imgData.width;
  4204. const partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  4205. const fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  4206. const totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  4207. const chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  4208. let srcPos = 0,
  4209. destPos;
  4210. const src = imgData.data;
  4211. const dest = chunkImgData.data;
  4212. let i, j, thisChunkHeight, elemsInThisChunk;
  4213. let transferMapRed, transferMapGreen, transferMapBlue, transferMapGray;
  4214. if (transferMaps) {
  4215. switch (transferMaps.length) {
  4216. case 1:
  4217. transferMapRed = transferMaps[0];
  4218. transferMapGreen = transferMaps[0];
  4219. transferMapBlue = transferMaps[0];
  4220. transferMapGray = transferMaps[0];
  4221. break;
  4222. case 4:
  4223. transferMapRed = transferMaps[0];
  4224. transferMapGreen = transferMaps[1];
  4225. transferMapBlue = transferMaps[2];
  4226. transferMapGray = transferMaps[3];
  4227. break;
  4228. }
  4229. }
  4230. if (imgData.kind === _util.ImageKind.GRAYSCALE_1BPP) {
  4231. const srcLength = src.byteLength;
  4232. const dest32 = new Uint32Array(dest.buffer, 0, dest.byteLength >> 2);
  4233. const dest32DataLength = dest32.length;
  4234. const fullSrcDiff = width + 7 >> 3;
  4235. let white = 0xffffffff;
  4236. let black = _util.IsLittleEndianCached.value ? 0xff000000 : 0x000000ff;
  4237. if (transferMapGray) {
  4238. if (transferMapGray[0] === 0xff && transferMapGray[0xff] === 0) {
  4239. [white, black] = [black, white];
  4240. }
  4241. }
  4242. for (i = 0; i < totalChunks; i++) {
  4243. thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  4244. destPos = 0;
  4245. for (j = 0; j < thisChunkHeight; j++) {
  4246. const srcDiff = srcLength - srcPos;
  4247. let k = 0;
  4248. const kEnd = srcDiff > fullSrcDiff ? width : srcDiff * 8 - 7;
  4249. const kEndUnrolled = kEnd & ~7;
  4250. let mask = 0;
  4251. let srcByte = 0;
  4252. for (; k < kEndUnrolled; k += 8) {
  4253. srcByte = src[srcPos++];
  4254. dest32[destPos++] = srcByte & 128 ? white : black;
  4255. dest32[destPos++] = srcByte & 64 ? white : black;
  4256. dest32[destPos++] = srcByte & 32 ? white : black;
  4257. dest32[destPos++] = srcByte & 16 ? white : black;
  4258. dest32[destPos++] = srcByte & 8 ? white : black;
  4259. dest32[destPos++] = srcByte & 4 ? white : black;
  4260. dest32[destPos++] = srcByte & 2 ? white : black;
  4261. dest32[destPos++] = srcByte & 1 ? white : black;
  4262. }
  4263. for (; k < kEnd; k++) {
  4264. if (mask === 0) {
  4265. srcByte = src[srcPos++];
  4266. mask = 128;
  4267. }
  4268. dest32[destPos++] = srcByte & mask ? white : black;
  4269. mask >>= 1;
  4270. }
  4271. }
  4272. while (destPos < dest32DataLength) {
  4273. dest32[destPos++] = 0;
  4274. }
  4275. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  4276. }
  4277. } else if (imgData.kind === _util.ImageKind.RGBA_32BPP) {
  4278. const hasTransferMaps = !!(transferMapRed || transferMapGreen || transferMapBlue);
  4279. j = 0;
  4280. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  4281. for (i = 0; i < fullChunks; i++) {
  4282. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  4283. srcPos += elemsInThisChunk;
  4284. if (hasTransferMaps) {
  4285. for (let k = 0; k < elemsInThisChunk; k += 4) {
  4286. if (transferMapRed) {
  4287. dest[k + 0] = transferMapRed[dest[k + 0]];
  4288. }
  4289. if (transferMapGreen) {
  4290. dest[k + 1] = transferMapGreen[dest[k + 1]];
  4291. }
  4292. if (transferMapBlue) {
  4293. dest[k + 2] = transferMapBlue[dest[k + 2]];
  4294. }
  4295. }
  4296. }
  4297. ctx.putImageData(chunkImgData, 0, j);
  4298. j += FULL_CHUNK_HEIGHT;
  4299. }
  4300. if (i < totalChunks) {
  4301. elemsInThisChunk = width * partialChunkHeight * 4;
  4302. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  4303. if (hasTransferMaps) {
  4304. for (let k = 0; k < elemsInThisChunk; k += 4) {
  4305. if (transferMapRed) {
  4306. dest[k + 0] = transferMapRed[dest[k + 0]];
  4307. }
  4308. if (transferMapGreen) {
  4309. dest[k + 1] = transferMapGreen[dest[k + 1]];
  4310. }
  4311. if (transferMapBlue) {
  4312. dest[k + 2] = transferMapBlue[dest[k + 2]];
  4313. }
  4314. }
  4315. }
  4316. ctx.putImageData(chunkImgData, 0, j);
  4317. }
  4318. } else if (imgData.kind === _util.ImageKind.RGB_24BPP) {
  4319. const hasTransferMaps = !!(transferMapRed || transferMapGreen || transferMapBlue);
  4320. thisChunkHeight = FULL_CHUNK_HEIGHT;
  4321. elemsInThisChunk = width * thisChunkHeight;
  4322. for (i = 0; i < totalChunks; i++) {
  4323. if (i >= fullChunks) {
  4324. thisChunkHeight = partialChunkHeight;
  4325. elemsInThisChunk = width * thisChunkHeight;
  4326. }
  4327. destPos = 0;
  4328. for (j = elemsInThisChunk; j--;) {
  4329. dest[destPos++] = src[srcPos++];
  4330. dest[destPos++] = src[srcPos++];
  4331. dest[destPos++] = src[srcPos++];
  4332. dest[destPos++] = 255;
  4333. }
  4334. if (hasTransferMaps) {
  4335. for (let k = 0; k < destPos; k += 4) {
  4336. if (transferMapRed) {
  4337. dest[k + 0] = transferMapRed[dest[k + 0]];
  4338. }
  4339. if (transferMapGreen) {
  4340. dest[k + 1] = transferMapGreen[dest[k + 1]];
  4341. }
  4342. if (transferMapBlue) {
  4343. dest[k + 2] = transferMapBlue[dest[k + 2]];
  4344. }
  4345. }
  4346. }
  4347. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  4348. }
  4349. } else {
  4350. throw new Error(`bad image kind: ${imgData.kind}`);
  4351. }
  4352. }
  4353. function putBinaryImageMask(ctx, imgData) {
  4354. const height = imgData.height,
  4355. width = imgData.width;
  4356. const partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  4357. const fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  4358. const totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  4359. const chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  4360. let srcPos = 0;
  4361. const src = imgData.data;
  4362. const dest = chunkImgData.data;
  4363. for (let i = 0; i < totalChunks; i++) {
  4364. const thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  4365. let destPos = 3;
  4366. for (let j = 0; j < thisChunkHeight; j++) {
  4367. let elem,
  4368. mask = 0;
  4369. for (let k = 0; k < width; k++) {
  4370. if (!mask) {
  4371. elem = src[srcPos++];
  4372. mask = 128;
  4373. }
  4374. dest[destPos] = elem & mask ? 0 : 255;
  4375. destPos += 4;
  4376. mask >>= 1;
  4377. }
  4378. }
  4379. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  4380. }
  4381. }
  4382. function copyCtxState(sourceCtx, destCtx) {
  4383. const properties = ["strokeStyle", "fillStyle", "fillRule", "globalAlpha", "lineWidth", "lineCap", "lineJoin", "miterLimit", "globalCompositeOperation", "font"];
  4384. for (let i = 0, ii = properties.length; i < ii; i++) {
  4385. const property = properties[i];
  4386. if (sourceCtx[property] !== undefined) {
  4387. destCtx[property] = sourceCtx[property];
  4388. }
  4389. }
  4390. if (sourceCtx.setLineDash !== undefined) {
  4391. destCtx.setLineDash(sourceCtx.getLineDash());
  4392. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  4393. }
  4394. }
  4395. function resetCtxToDefault(ctx) {
  4396. ctx.strokeStyle = "#000000";
  4397. ctx.fillStyle = "#000000";
  4398. ctx.fillRule = "nonzero";
  4399. ctx.globalAlpha = 1;
  4400. ctx.lineWidth = 1;
  4401. ctx.lineCap = "butt";
  4402. ctx.lineJoin = "miter";
  4403. ctx.miterLimit = 10;
  4404. ctx.globalCompositeOperation = "source-over";
  4405. ctx.font = "10px sans-serif";
  4406. if (ctx.setLineDash !== undefined) {
  4407. ctx.setLineDash([]);
  4408. ctx.lineDashOffset = 0;
  4409. }
  4410. }
  4411. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  4412. const length = bytes.length;
  4413. for (let i = 3; i < length; i += 4) {
  4414. const alpha = bytes[i];
  4415. if (alpha === 0) {
  4416. bytes[i - 3] = r0;
  4417. bytes[i - 2] = g0;
  4418. bytes[i - 1] = b0;
  4419. } else if (alpha < 255) {
  4420. const alpha_ = 255 - alpha;
  4421. bytes[i - 3] = bytes[i - 3] * alpha + r0 * alpha_ >> 8;
  4422. bytes[i - 2] = bytes[i - 2] * alpha + g0 * alpha_ >> 8;
  4423. bytes[i - 1] = bytes[i - 1] * alpha + b0 * alpha_ >> 8;
  4424. }
  4425. }
  4426. }
  4427. function composeSMaskAlpha(maskData, layerData, transferMap) {
  4428. const length = maskData.length;
  4429. const scale = 1 / 255;
  4430. for (let i = 3; i < length; i += 4) {
  4431. const alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
  4432. layerData[i] = layerData[i] * alpha * scale | 0;
  4433. }
  4434. }
  4435. function composeSMaskLuminosity(maskData, layerData, transferMap) {
  4436. const length = maskData.length;
  4437. for (let i = 3; i < length; i += 4) {
  4438. const y = maskData[i - 3] * 77 + maskData[i - 2] * 152 + maskData[i - 1] * 28;
  4439. layerData[i] = transferMap ? layerData[i] * transferMap[y >> 8] >> 8 : layerData[i] * y >> 16;
  4440. }
  4441. }
  4442. function genericComposeSMask(maskCtx, layerCtx, width, height, subtype, backdrop, transferMap, layerOffsetX, layerOffsetY, maskOffsetX, maskOffsetY) {
  4443. const hasBackdrop = !!backdrop;
  4444. const r0 = hasBackdrop ? backdrop[0] : 0;
  4445. const g0 = hasBackdrop ? backdrop[1] : 0;
  4446. const b0 = hasBackdrop ? backdrop[2] : 0;
  4447. let composeFn;
  4448. if (subtype === "Luminosity") {
  4449. composeFn = composeSMaskLuminosity;
  4450. } else {
  4451. composeFn = composeSMaskAlpha;
  4452. }
  4453. const PIXELS_TO_PROCESS = 1048576;
  4454. const chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  4455. for (let row = 0; row < height; row += chunkSize) {
  4456. const chunkHeight = Math.min(chunkSize, height - row);
  4457. const maskData = maskCtx.getImageData(layerOffsetX - maskOffsetX, row + (layerOffsetY - maskOffsetY), width, chunkHeight);
  4458. const layerData = layerCtx.getImageData(layerOffsetX, row + layerOffsetY, width, chunkHeight);
  4459. if (hasBackdrop) {
  4460. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  4461. }
  4462. composeFn(maskData.data, layerData.data, transferMap);
  4463. layerCtx.putImageData(layerData, layerOffsetX, row + layerOffsetY);
  4464. }
  4465. }
  4466. function composeSMask(ctx, smask, layerCtx, layerBox) {
  4467. const layerOffsetX = layerBox[0];
  4468. const layerOffsetY = layerBox[1];
  4469. const layerWidth = layerBox[2] - layerOffsetX;
  4470. const layerHeight = layerBox[3] - layerOffsetY;
  4471. if (layerWidth === 0 || layerHeight === 0) {
  4472. return;
  4473. }
  4474. genericComposeSMask(smask.context, layerCtx, layerWidth, layerHeight, smask.subtype, smask.backdrop, smask.transferMap, layerOffsetX, layerOffsetY, smask.offsetX, smask.offsetY);
  4475. ctx.save();
  4476. ctx.globalAlpha = 1;
  4477. ctx.globalCompositeOperation = "source-over";
  4478. ctx.setTransform(1, 0, 0, 1, 0, 0);
  4479. ctx.drawImage(layerCtx.canvas, 0, 0);
  4480. ctx.restore();
  4481. }
  4482. function getImageSmoothingEnabled(transform, interpolate) {
  4483. const scale = _util.Util.singularValueDecompose2dScale(transform);
  4484. scale[0] = Math.fround(scale[0]);
  4485. scale[1] = Math.fround(scale[1]);
  4486. const actualScale = Math.fround((globalThis.devicePixelRatio || 1) * _display_utils.PixelsPerInch.PDF_TO_CSS_UNITS);
  4487. if (interpolate !== undefined) {
  4488. return interpolate;
  4489. } else if (scale[0] <= actualScale || scale[1] <= actualScale) {
  4490. return true;
  4491. }
  4492. return false;
  4493. }
  4494. const LINE_CAP_STYLES = ["butt", "round", "square"];
  4495. const LINE_JOIN_STYLES = ["miter", "round", "bevel"];
  4496. const NORMAL_CLIP = {};
  4497. const EO_CLIP = {};
  4498. class CanvasGraphics {
  4499. constructor(canvasCtx, commonObjs, objs, canvasFactory, imageLayer, optionalContentConfig, annotationCanvasMap) {
  4500. this.ctx = canvasCtx;
  4501. this.current = new CanvasExtraState(this.ctx.canvas.width, this.ctx.canvas.height);
  4502. this.stateStack = [];
  4503. this.pendingClip = null;
  4504. this.pendingEOFill = false;
  4505. this.res = null;
  4506. this.xobjs = null;
  4507. this.commonObjs = commonObjs;
  4508. this.objs = objs;
  4509. this.canvasFactory = canvasFactory;
  4510. this.imageLayer = imageLayer;
  4511. this.groupStack = [];
  4512. this.processingType3 = null;
  4513. this.baseTransform = null;
  4514. this.baseTransformStack = [];
  4515. this.groupLevel = 0;
  4516. this.smaskStack = [];
  4517. this.smaskCounter = 0;
  4518. this.tempSMask = null;
  4519. this.suspendedCtx = null;
  4520. this.contentVisible = true;
  4521. this.markedContentStack = [];
  4522. this.optionalContentConfig = optionalContentConfig;
  4523. this.cachedCanvases = new CachedCanvases(this.canvasFactory);
  4524. this.cachedPatterns = new Map();
  4525. this.annotationCanvasMap = annotationCanvasMap;
  4526. this.viewportScale = 1;
  4527. this.outputScaleX = 1;
  4528. this.outputScaleY = 1;
  4529. if (canvasCtx) {
  4530. addContextCurrentTransform(canvasCtx);
  4531. }
  4532. this._cachedGetSinglePixelWidth = null;
  4533. }
  4534. beginDrawing({
  4535. transform,
  4536. viewport,
  4537. transparency = false,
  4538. background = null
  4539. }) {
  4540. const width = this.ctx.canvas.width;
  4541. const height = this.ctx.canvas.height;
  4542. this.ctx.save();
  4543. this.ctx.fillStyle = background || "rgb(255, 255, 255)";
  4544. this.ctx.fillRect(0, 0, width, height);
  4545. this.ctx.restore();
  4546. if (transparency) {
  4547. const transparentCanvas = this.cachedCanvases.getCanvas("transparent", width, height, true);
  4548. this.compositeCtx = this.ctx;
  4549. this.transparentCanvas = transparentCanvas.canvas;
  4550. this.ctx = transparentCanvas.context;
  4551. this.ctx.save();
  4552. this.ctx.transform.apply(this.ctx, this.compositeCtx.mozCurrentTransform);
  4553. }
  4554. this.ctx.save();
  4555. resetCtxToDefault(this.ctx);
  4556. if (transform) {
  4557. this.ctx.transform.apply(this.ctx, transform);
  4558. this.outputScaleX = transform[0];
  4559. this.outputScaleY = transform[0];
  4560. }
  4561. this.ctx.transform.apply(this.ctx, viewport.transform);
  4562. this.viewportScale = viewport.scale;
  4563. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  4564. this._combinedScaleFactor = Math.hypot(this.baseTransform[0], this.baseTransform[2]);
  4565. if (this.imageLayer) {
  4566. this.imageLayer.beginLayout();
  4567. }
  4568. }
  4569. executeOperatorList(operatorList, executionStartIdx, continueCallback, stepper) {
  4570. const argsArray = operatorList.argsArray;
  4571. const fnArray = operatorList.fnArray;
  4572. let i = executionStartIdx || 0;
  4573. const argsArrayLen = argsArray.length;
  4574. if (argsArrayLen === i) {
  4575. return i;
  4576. }
  4577. const chunkOperations = argsArrayLen - i > EXECUTION_STEPS && typeof continueCallback === "function";
  4578. const endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  4579. let steps = 0;
  4580. const commonObjs = this.commonObjs;
  4581. const objs = this.objs;
  4582. let fnId;
  4583. while (true) {
  4584. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  4585. stepper.breakIt(i, continueCallback);
  4586. return i;
  4587. }
  4588. fnId = fnArray[i];
  4589. if (fnId !== _util.OPS.dependency) {
  4590. this[fnId].apply(this, argsArray[i]);
  4591. } else {
  4592. for (const depObjId of argsArray[i]) {
  4593. const objsPool = depObjId.startsWith("g_") ? commonObjs : objs;
  4594. if (!objsPool.has(depObjId)) {
  4595. objsPool.get(depObjId, continueCallback);
  4596. return i;
  4597. }
  4598. }
  4599. }
  4600. i++;
  4601. if (i === argsArrayLen) {
  4602. return i;
  4603. }
  4604. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  4605. if (Date.now() > endTime) {
  4606. continueCallback();
  4607. return i;
  4608. }
  4609. steps = 0;
  4610. }
  4611. }
  4612. }
  4613. endDrawing() {
  4614. while (this.stateStack.length || this.inSMaskMode) {
  4615. this.restore();
  4616. }
  4617. this.ctx.restore();
  4618. if (this.transparentCanvas) {
  4619. this.ctx = this.compositeCtx;
  4620. this.ctx.save();
  4621. this.ctx.setTransform(1, 0, 0, 1, 0, 0);
  4622. this.ctx.drawImage(this.transparentCanvas, 0, 0);
  4623. this.ctx.restore();
  4624. this.transparentCanvas = null;
  4625. }
  4626. this.cachedCanvases.clear();
  4627. this.cachedPatterns.clear();
  4628. if (this.imageLayer) {
  4629. this.imageLayer.endLayout();
  4630. }
  4631. }
  4632. _scaleImage(img, inverseTransform) {
  4633. const width = img.width;
  4634. const height = img.height;
  4635. let widthScale = Math.max(Math.hypot(inverseTransform[0], inverseTransform[1]), 1);
  4636. let heightScale = Math.max(Math.hypot(inverseTransform[2], inverseTransform[3]), 1);
  4637. let paintWidth = width,
  4638. paintHeight = height;
  4639. let tmpCanvasId = "prescale1";
  4640. let tmpCanvas, tmpCtx;
  4641. while (widthScale > 2 && paintWidth > 1 || heightScale > 2 && paintHeight > 1) {
  4642. let newWidth = paintWidth,
  4643. newHeight = paintHeight;
  4644. if (widthScale > 2 && paintWidth > 1) {
  4645. newWidth = Math.ceil(paintWidth / 2);
  4646. widthScale /= paintWidth / newWidth;
  4647. }
  4648. if (heightScale > 2 && paintHeight > 1) {
  4649. newHeight = Math.ceil(paintHeight / 2);
  4650. heightScale /= paintHeight / newHeight;
  4651. }
  4652. tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
  4653. tmpCtx = tmpCanvas.context;
  4654. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  4655. tmpCtx.drawImage(img, 0, 0, paintWidth, paintHeight, 0, 0, newWidth, newHeight);
  4656. img = tmpCanvas.canvas;
  4657. paintWidth = newWidth;
  4658. paintHeight = newHeight;
  4659. tmpCanvasId = tmpCanvasId === "prescale1" ? "prescale2" : "prescale1";
  4660. }
  4661. return {
  4662. img,
  4663. paintWidth,
  4664. paintHeight
  4665. };
  4666. }
  4667. _createMaskCanvas(img) {
  4668. const ctx = this.ctx;
  4669. const width = img.width,
  4670. height = img.height;
  4671. const fillColor = this.current.fillColor;
  4672. const isPatternFill = this.current.patternFill;
  4673. const maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
  4674. const maskCtx = maskCanvas.context;
  4675. putBinaryImageMask(maskCtx, img);
  4676. const objToCanvas = ctx.mozCurrentTransform;
  4677. let maskToCanvas = _util.Util.transform(objToCanvas, [1 / width, 0, 0, -1 / height, 0, 0]);
  4678. maskToCanvas = _util.Util.transform(maskToCanvas, [1, 0, 0, 1, 0, -height]);
  4679. const cord1 = _util.Util.applyTransform([0, 0], maskToCanvas);
  4680. const cord2 = _util.Util.applyTransform([width, height], maskToCanvas);
  4681. const rect = _util.Util.normalizeRect([cord1[0], cord1[1], cord2[0], cord2[1]]);
  4682. const drawnWidth = Math.ceil(rect[2] - rect[0]);
  4683. const drawnHeight = Math.ceil(rect[3] - rect[1]);
  4684. const fillCanvas = this.cachedCanvases.getCanvas("fillCanvas", drawnWidth, drawnHeight, true);
  4685. const fillCtx = fillCanvas.context;
  4686. const offsetX = Math.min(cord1[0], cord2[0]);
  4687. const offsetY = Math.min(cord1[1], cord2[1]);
  4688. fillCtx.translate(-offsetX, -offsetY);
  4689. fillCtx.transform.apply(fillCtx, maskToCanvas);
  4690. const scaled = this._scaleImage(maskCanvas.canvas, fillCtx.mozCurrentTransformInverse);
  4691. fillCtx.imageSmoothingEnabled = getImageSmoothingEnabled(fillCtx.mozCurrentTransform, img.interpolate);
  4692. fillCtx.drawImage(scaled.img, 0, 0, scaled.img.width, scaled.img.height, 0, 0, width, height);
  4693. fillCtx.globalCompositeOperation = "source-in";
  4694. const inverse = _util.Util.transform(fillCtx.mozCurrentTransformInverse, [1, 0, 0, 1, -offsetX, -offsetY]);
  4695. fillCtx.fillStyle = isPatternFill ? fillColor.getPattern(ctx, this, inverse, _pattern_helper.PathType.FILL) : fillColor;
  4696. fillCtx.fillRect(0, 0, width, height);
  4697. return {
  4698. canvas: fillCanvas.canvas,
  4699. offsetX: Math.round(offsetX),
  4700. offsetY: Math.round(offsetY)
  4701. };
  4702. }
  4703. setLineWidth(width) {
  4704. this.current.lineWidth = width;
  4705. this.ctx.lineWidth = width;
  4706. }
  4707. setLineCap(style) {
  4708. this.ctx.lineCap = LINE_CAP_STYLES[style];
  4709. }
  4710. setLineJoin(style) {
  4711. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  4712. }
  4713. setMiterLimit(limit) {
  4714. this.ctx.miterLimit = limit;
  4715. }
  4716. setDash(dashArray, dashPhase) {
  4717. const ctx = this.ctx;
  4718. if (ctx.setLineDash !== undefined) {
  4719. ctx.setLineDash(dashArray);
  4720. ctx.lineDashOffset = dashPhase;
  4721. }
  4722. }
  4723. setRenderingIntent(intent) {}
  4724. setFlatness(flatness) {}
  4725. setGState(states) {
  4726. for (let i = 0, ii = states.length; i < ii; i++) {
  4727. const state = states[i];
  4728. const key = state[0];
  4729. const value = state[1];
  4730. switch (key) {
  4731. case "LW":
  4732. this.setLineWidth(value);
  4733. break;
  4734. case "LC":
  4735. this.setLineCap(value);
  4736. break;
  4737. case "LJ":
  4738. this.setLineJoin(value);
  4739. break;
  4740. case "ML":
  4741. this.setMiterLimit(value);
  4742. break;
  4743. case "D":
  4744. this.setDash(value[0], value[1]);
  4745. break;
  4746. case "RI":
  4747. this.setRenderingIntent(value);
  4748. break;
  4749. case "FL":
  4750. this.setFlatness(value);
  4751. break;
  4752. case "Font":
  4753. this.setFont(value[0], value[1]);
  4754. break;
  4755. case "CA":
  4756. this.current.strokeAlpha = state[1];
  4757. break;
  4758. case "ca":
  4759. this.current.fillAlpha = state[1];
  4760. this.ctx.globalAlpha = state[1];
  4761. break;
  4762. case "BM":
  4763. this.ctx.globalCompositeOperation = value;
  4764. break;
  4765. case "SMask":
  4766. this.current.activeSMask = value ? this.tempSMask : null;
  4767. this.tempSMask = null;
  4768. this.checkSMaskState();
  4769. break;
  4770. case "TR":
  4771. this.current.transferMaps = value;
  4772. }
  4773. }
  4774. }
  4775. get inSMaskMode() {
  4776. return !!this.suspendedCtx;
  4777. }
  4778. checkSMaskState() {
  4779. const inSMaskMode = this.inSMaskMode;
  4780. if (this.current.activeSMask && !inSMaskMode) {
  4781. this.beginSMaskMode();
  4782. } else if (!this.current.activeSMask && inSMaskMode) {
  4783. this.endSMaskMode();
  4784. }
  4785. }
  4786. beginSMaskMode() {
  4787. if (this.inSMaskMode) {
  4788. throw new Error("beginSMaskMode called while already in smask mode");
  4789. }
  4790. const drawnWidth = this.ctx.canvas.width;
  4791. const drawnHeight = this.ctx.canvas.height;
  4792. const cacheId = "smaskGroupAt" + this.groupLevel;
  4793. const scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true);
  4794. this.suspendedCtx = this.ctx;
  4795. this.ctx = scratchCanvas.context;
  4796. const ctx = this.ctx;
  4797. ctx.setTransform.apply(ctx, this.suspendedCtx.mozCurrentTransform);
  4798. copyCtxState(this.suspendedCtx, ctx);
  4799. mirrorContextOperations(ctx, this.suspendedCtx);
  4800. this.setGState([["BM", "source-over"], ["ca", 1], ["CA", 1]]);
  4801. }
  4802. endSMaskMode() {
  4803. if (!this.inSMaskMode) {
  4804. throw new Error("endSMaskMode called while not in smask mode");
  4805. }
  4806. this.ctx._removeMirroring();
  4807. copyCtxState(this.ctx, this.suspendedCtx);
  4808. this.ctx = this.suspendedCtx;
  4809. this.suspendedCtx = null;
  4810. }
  4811. compose(dirtyBox) {
  4812. if (!this.current.activeSMask) {
  4813. return;
  4814. }
  4815. if (!dirtyBox) {
  4816. dirtyBox = [0, 0, this.ctx.canvas.width, this.ctx.canvas.height];
  4817. } else {
  4818. dirtyBox[0] = Math.floor(dirtyBox[0]);
  4819. dirtyBox[1] = Math.floor(dirtyBox[1]);
  4820. dirtyBox[2] = Math.ceil(dirtyBox[2]);
  4821. dirtyBox[3] = Math.ceil(dirtyBox[3]);
  4822. }
  4823. const smask = this.current.activeSMask;
  4824. const suspendedCtx = this.suspendedCtx;
  4825. composeSMask(suspendedCtx, smask, this.ctx, dirtyBox);
  4826. this.ctx.save();
  4827. this.ctx.setTransform(1, 0, 0, 1, 0, 0);
  4828. this.ctx.clearRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height);
  4829. this.ctx.restore();
  4830. }
  4831. save() {
  4832. if (this.inSMaskMode) {
  4833. copyCtxState(this.ctx, this.suspendedCtx);
  4834. this.suspendedCtx.save();
  4835. } else {
  4836. this.ctx.save();
  4837. }
  4838. const old = this.current;
  4839. this.stateStack.push(old);
  4840. this.current = old.clone();
  4841. }
  4842. restore() {
  4843. if (this.stateStack.length === 0 && this.inSMaskMode) {
  4844. this.endSMaskMode();
  4845. }
  4846. if (this.stateStack.length !== 0) {
  4847. this.current = this.stateStack.pop();
  4848. if (this.inSMaskMode) {
  4849. this.suspendedCtx.restore();
  4850. copyCtxState(this.suspendedCtx, this.ctx);
  4851. } else {
  4852. this.ctx.restore();
  4853. }
  4854. this.checkSMaskState();
  4855. this.pendingClip = null;
  4856. this._cachedGetSinglePixelWidth = null;
  4857. }
  4858. }
  4859. transform(a, b, c, d, e, f) {
  4860. this.ctx.transform(a, b, c, d, e, f);
  4861. this._cachedGetSinglePixelWidth = null;
  4862. }
  4863. constructPath(ops, args) {
  4864. const ctx = this.ctx;
  4865. const current = this.current;
  4866. let x = current.x,
  4867. y = current.y;
  4868. let startX, startY;
  4869. for (let i = 0, j = 0, ii = ops.length; i < ii; i++) {
  4870. switch (ops[i] | 0) {
  4871. case _util.OPS.rectangle:
  4872. x = args[j++];
  4873. y = args[j++];
  4874. const width = args[j++];
  4875. const height = args[j++];
  4876. const xw = x + width;
  4877. const yh = y + height;
  4878. ctx.moveTo(x, y);
  4879. if (width === 0 || height === 0) {
  4880. ctx.lineTo(xw, yh);
  4881. } else {
  4882. ctx.lineTo(xw, y);
  4883. ctx.lineTo(xw, yh);
  4884. ctx.lineTo(x, yh);
  4885. }
  4886. current.updatePathMinMax(ctx.mozCurrentTransform, x, y);
  4887. current.updatePathMinMax(ctx.mozCurrentTransform, xw, yh);
  4888. ctx.closePath();
  4889. break;
  4890. case _util.OPS.moveTo:
  4891. x = args[j++];
  4892. y = args[j++];
  4893. ctx.moveTo(x, y);
  4894. current.updatePathMinMax(ctx.mozCurrentTransform, x, y);
  4895. break;
  4896. case _util.OPS.lineTo:
  4897. x = args[j++];
  4898. y = args[j++];
  4899. ctx.lineTo(x, y);
  4900. current.updatePathMinMax(ctx.mozCurrentTransform, x, y);
  4901. break;
  4902. case _util.OPS.curveTo:
  4903. startX = x;
  4904. startY = y;
  4905. x = args[j + 4];
  4906. y = args[j + 5];
  4907. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3], x, y);
  4908. current.updateCurvePathMinMax(ctx.mozCurrentTransform, startX, startY, args[j], args[j + 1], args[j + 2], args[j + 3], x, y);
  4909. j += 6;
  4910. break;
  4911. case _util.OPS.curveTo2:
  4912. startX = x;
  4913. startY = y;
  4914. ctx.bezierCurveTo(x, y, args[j], args[j + 1], args[j + 2], args[j + 3]);
  4915. current.updateCurvePathMinMax(ctx.mozCurrentTransform, startX, startY, x, y, args[j], args[j + 1], args[j + 2], args[j + 3]);
  4916. x = args[j + 2];
  4917. y = args[j + 3];
  4918. j += 4;
  4919. break;
  4920. case _util.OPS.curveTo3:
  4921. startX = x;
  4922. startY = y;
  4923. x = args[j + 2];
  4924. y = args[j + 3];
  4925. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  4926. current.updateCurvePathMinMax(ctx.mozCurrentTransform, startX, startY, args[j], args[j + 1], x, y, x, y);
  4927. j += 4;
  4928. break;
  4929. case _util.OPS.closePath:
  4930. ctx.closePath();
  4931. break;
  4932. }
  4933. }
  4934. current.setCurrentPoint(x, y);
  4935. }
  4936. closePath() {
  4937. this.ctx.closePath();
  4938. }
  4939. stroke(consumePath) {
  4940. consumePath = typeof consumePath !== "undefined" ? consumePath : true;
  4941. const ctx = this.ctx;
  4942. const strokeColor = this.current.strokeColor;
  4943. ctx.globalAlpha = this.current.strokeAlpha;
  4944. if (this.contentVisible) {
  4945. if (typeof strokeColor === "object" && strokeColor?.getPattern) {
  4946. const lineWidth = this.getSinglePixelWidth();
  4947. ctx.save();
  4948. ctx.strokeStyle = strokeColor.getPattern(ctx, this, ctx.mozCurrentTransformInverse, _pattern_helper.PathType.STROKE);
  4949. ctx.lineWidth = Math.max(lineWidth, this.current.lineWidth);
  4950. ctx.stroke();
  4951. ctx.restore();
  4952. } else {
  4953. const lineWidth = this.getSinglePixelWidth();
  4954. if (lineWidth < 0 && -lineWidth >= this.current.lineWidth) {
  4955. ctx.save();
  4956. ctx.resetTransform();
  4957. ctx.lineWidth = Math.floor(this._combinedScaleFactor);
  4958. ctx.stroke();
  4959. ctx.restore();
  4960. } else {
  4961. ctx.lineWidth = Math.max(lineWidth, this.current.lineWidth);
  4962. ctx.stroke();
  4963. }
  4964. }
  4965. }
  4966. if (consumePath) {
  4967. this.consumePath(this.current.getClippedPathBoundingBox());
  4968. }
  4969. ctx.globalAlpha = this.current.fillAlpha;
  4970. }
  4971. closeStroke() {
  4972. this.closePath();
  4973. this.stroke();
  4974. }
  4975. fill(consumePath) {
  4976. consumePath = typeof consumePath !== "undefined" ? consumePath : true;
  4977. const ctx = this.ctx;
  4978. const fillColor = this.current.fillColor;
  4979. const isPatternFill = this.current.patternFill;
  4980. let needRestore = false;
  4981. if (isPatternFill) {
  4982. ctx.save();
  4983. ctx.fillStyle = fillColor.getPattern(ctx, this, ctx.mozCurrentTransformInverse, _pattern_helper.PathType.FILL);
  4984. needRestore = true;
  4985. }
  4986. const intersect = this.current.getClippedPathBoundingBox();
  4987. if (this.contentVisible && intersect !== null) {
  4988. if (this.pendingEOFill) {
  4989. ctx.fill("evenodd");
  4990. this.pendingEOFill = false;
  4991. } else {
  4992. ctx.fill();
  4993. }
  4994. }
  4995. if (needRestore) {
  4996. ctx.restore();
  4997. }
  4998. if (consumePath) {
  4999. this.consumePath(intersect);
  5000. }
  5001. }
  5002. eoFill() {
  5003. this.pendingEOFill = true;
  5004. this.fill();
  5005. }
  5006. fillStroke() {
  5007. this.fill(false);
  5008. this.stroke(false);
  5009. this.consumePath();
  5010. }
  5011. eoFillStroke() {
  5012. this.pendingEOFill = true;
  5013. this.fillStroke();
  5014. }
  5015. closeFillStroke() {
  5016. this.closePath();
  5017. this.fillStroke();
  5018. }
  5019. closeEOFillStroke() {
  5020. this.pendingEOFill = true;
  5021. this.closePath();
  5022. this.fillStroke();
  5023. }
  5024. endPath() {
  5025. this.consumePath();
  5026. }
  5027. clip() {
  5028. this.pendingClip = NORMAL_CLIP;
  5029. }
  5030. eoClip() {
  5031. this.pendingClip = EO_CLIP;
  5032. }
  5033. beginText() {
  5034. this.current.textMatrix = _util.IDENTITY_MATRIX;
  5035. this.current.textMatrixScale = 1;
  5036. this.current.x = this.current.lineX = 0;
  5037. this.current.y = this.current.lineY = 0;
  5038. }
  5039. endText() {
  5040. const paths = this.pendingTextPaths;
  5041. const ctx = this.ctx;
  5042. if (paths === undefined) {
  5043. ctx.beginPath();
  5044. return;
  5045. }
  5046. ctx.save();
  5047. ctx.beginPath();
  5048. for (let i = 0; i < paths.length; i++) {
  5049. const path = paths[i];
  5050. ctx.setTransform.apply(ctx, path.transform);
  5051. ctx.translate(path.x, path.y);
  5052. path.addToPath(ctx, path.fontSize);
  5053. }
  5054. ctx.restore();
  5055. ctx.clip();
  5056. ctx.beginPath();
  5057. delete this.pendingTextPaths;
  5058. }
  5059. setCharSpacing(spacing) {
  5060. this.current.charSpacing = spacing;
  5061. }
  5062. setWordSpacing(spacing) {
  5063. this.current.wordSpacing = spacing;
  5064. }
  5065. setHScale(scale) {
  5066. this.current.textHScale = scale / 100;
  5067. }
  5068. setLeading(leading) {
  5069. this.current.leading = -leading;
  5070. }
  5071. setFont(fontRefName, size) {
  5072. const fontObj = this.commonObjs.get(fontRefName);
  5073. const current = this.current;
  5074. if (!fontObj) {
  5075. throw new Error(`Can't find font for ${fontRefName}`);
  5076. }
  5077. current.fontMatrix = fontObj.fontMatrix || _util.FONT_IDENTITY_MATRIX;
  5078. if (current.fontMatrix[0] === 0 || current.fontMatrix[3] === 0) {
  5079. (0, _util.warn)("Invalid font matrix for font " + fontRefName);
  5080. }
  5081. if (size < 0) {
  5082. size = -size;
  5083. current.fontDirection = -1;
  5084. } else {
  5085. current.fontDirection = 1;
  5086. }
  5087. this.current.font = fontObj;
  5088. this.current.fontSize = size;
  5089. if (fontObj.isType3Font) {
  5090. return;
  5091. }
  5092. const name = fontObj.loadedName || "sans-serif";
  5093. let bold = "normal";
  5094. if (fontObj.black) {
  5095. bold = "900";
  5096. } else if (fontObj.bold) {
  5097. bold = "bold";
  5098. }
  5099. const italic = fontObj.italic ? "italic" : "normal";
  5100. const typeface = `"${name}", ${fontObj.fallbackName}`;
  5101. let browserFontSize = size;
  5102. if (size < MIN_FONT_SIZE) {
  5103. browserFontSize = MIN_FONT_SIZE;
  5104. } else if (size > MAX_FONT_SIZE) {
  5105. browserFontSize = MAX_FONT_SIZE;
  5106. }
  5107. this.current.fontSizeScale = size / browserFontSize;
  5108. this.ctx.font = `${italic} ${bold} ${browserFontSize}px ${typeface}`;
  5109. }
  5110. setTextRenderingMode(mode) {
  5111. this.current.textRenderingMode = mode;
  5112. }
  5113. setTextRise(rise) {
  5114. this.current.textRise = rise;
  5115. }
  5116. moveText(x, y) {
  5117. this.current.x = this.current.lineX += x;
  5118. this.current.y = this.current.lineY += y;
  5119. }
  5120. setLeadingMoveText(x, y) {
  5121. this.setLeading(-y);
  5122. this.moveText(x, y);
  5123. }
  5124. setTextMatrix(a, b, c, d, e, f) {
  5125. this.current.textMatrix = [a, b, c, d, e, f];
  5126. this.current.textMatrixScale = Math.hypot(a, b);
  5127. this.current.x = this.current.lineX = 0;
  5128. this.current.y = this.current.lineY = 0;
  5129. }
  5130. nextLine() {
  5131. this.moveText(0, this.current.leading);
  5132. }
  5133. paintChar(character, x, y, patternTransform, resetLineWidthToOne) {
  5134. const ctx = this.ctx;
  5135. const current = this.current;
  5136. const font = current.font;
  5137. const textRenderingMode = current.textRenderingMode;
  5138. const fontSize = current.fontSize / current.fontSizeScale;
  5139. const fillStrokeMode = textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  5140. const isAddToPathSet = !!(textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG);
  5141. const patternFill = current.patternFill && !font.missingFile;
  5142. let addToPath;
  5143. if (font.disableFontFace || isAddToPathSet || patternFill) {
  5144. addToPath = font.getPathGenerator(this.commonObjs, character);
  5145. }
  5146. if (font.disableFontFace || patternFill) {
  5147. ctx.save();
  5148. ctx.translate(x, y);
  5149. ctx.beginPath();
  5150. addToPath(ctx, fontSize);
  5151. if (patternTransform) {
  5152. ctx.setTransform.apply(ctx, patternTransform);
  5153. }
  5154. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  5155. ctx.fill();
  5156. }
  5157. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  5158. if (resetLineWidthToOne) {
  5159. ctx.resetTransform();
  5160. ctx.lineWidth = Math.floor(this._combinedScaleFactor);
  5161. }
  5162. ctx.stroke();
  5163. }
  5164. ctx.restore();
  5165. } else {
  5166. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  5167. ctx.fillText(character, x, y);
  5168. }
  5169. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  5170. if (resetLineWidthToOne) {
  5171. ctx.save();
  5172. ctx.moveTo(x, y);
  5173. ctx.resetTransform();
  5174. ctx.lineWidth = Math.floor(this._combinedScaleFactor);
  5175. ctx.strokeText(character, 0, 0);
  5176. ctx.restore();
  5177. } else {
  5178. ctx.strokeText(character, x, y);
  5179. }
  5180. }
  5181. }
  5182. if (isAddToPathSet) {
  5183. const paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  5184. paths.push({
  5185. transform: ctx.mozCurrentTransform,
  5186. x,
  5187. y,
  5188. fontSize,
  5189. addToPath
  5190. });
  5191. }
  5192. }
  5193. get isFontSubpixelAAEnabled() {
  5194. const {
  5195. context: ctx
  5196. } = this.cachedCanvases.getCanvas("isFontSubpixelAAEnabled", 10, 10);
  5197. ctx.scale(1.5, 1);
  5198. ctx.fillText("I", 0, 10);
  5199. const data = ctx.getImageData(0, 0, 10, 10).data;
  5200. let enabled = false;
  5201. for (let i = 3; i < data.length; i += 4) {
  5202. if (data[i] > 0 && data[i] < 255) {
  5203. enabled = true;
  5204. break;
  5205. }
  5206. }
  5207. return (0, _util.shadow)(this, "isFontSubpixelAAEnabled", enabled);
  5208. }
  5209. showText(glyphs) {
  5210. const current = this.current;
  5211. const font = current.font;
  5212. if (font.isType3Font) {
  5213. return this.showType3Text(glyphs);
  5214. }
  5215. const fontSize = current.fontSize;
  5216. if (fontSize === 0) {
  5217. return undefined;
  5218. }
  5219. const ctx = this.ctx;
  5220. const fontSizeScale = current.fontSizeScale;
  5221. const charSpacing = current.charSpacing;
  5222. const wordSpacing = current.wordSpacing;
  5223. const fontDirection = current.fontDirection;
  5224. const textHScale = current.textHScale * fontDirection;
  5225. const glyphsLength = glyphs.length;
  5226. const vertical = font.vertical;
  5227. const spacingDir = vertical ? 1 : -1;
  5228. const defaultVMetrics = font.defaultVMetrics;
  5229. const widthAdvanceScale = fontSize * current.fontMatrix[0];
  5230. const simpleFillText = current.textRenderingMode === _util.TextRenderingMode.FILL && !font.disableFontFace && !current.patternFill;
  5231. ctx.save();
  5232. ctx.transform.apply(ctx, current.textMatrix);
  5233. ctx.translate(current.x, current.y + current.textRise);
  5234. if (fontDirection > 0) {
  5235. ctx.scale(textHScale, -1);
  5236. } else {
  5237. ctx.scale(textHScale, 1);
  5238. }
  5239. let patternTransform;
  5240. if (current.patternFill) {
  5241. ctx.save();
  5242. const pattern = current.fillColor.getPattern(ctx, this, ctx.mozCurrentTransformInverse, _pattern_helper.PathType.FILL);
  5243. patternTransform = ctx.mozCurrentTransform;
  5244. ctx.restore();
  5245. ctx.fillStyle = pattern;
  5246. }
  5247. let lineWidth = current.lineWidth;
  5248. let resetLineWidthToOne = false;
  5249. const scale = current.textMatrixScale;
  5250. if (scale === 0 || lineWidth === 0) {
  5251. const fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  5252. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  5253. this._cachedGetSinglePixelWidth = null;
  5254. lineWidth = this.getSinglePixelWidth();
  5255. resetLineWidthToOne = lineWidth < 0;
  5256. }
  5257. } else {
  5258. lineWidth /= scale;
  5259. }
  5260. if (fontSizeScale !== 1.0) {
  5261. ctx.scale(fontSizeScale, fontSizeScale);
  5262. lineWidth /= fontSizeScale;
  5263. }
  5264. ctx.lineWidth = lineWidth;
  5265. let x = 0,
  5266. i;
  5267. for (i = 0; i < glyphsLength; ++i) {
  5268. const glyph = glyphs[i];
  5269. if (typeof glyph === "number") {
  5270. x += spacingDir * glyph * fontSize / 1000;
  5271. continue;
  5272. }
  5273. let restoreNeeded = false;
  5274. const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  5275. const character = glyph.fontChar;
  5276. const accent = glyph.accent;
  5277. let scaledX, scaledY;
  5278. let width = glyph.width;
  5279. if (vertical) {
  5280. const vmetric = glyph.vmetric || defaultVMetrics;
  5281. const vx = -(glyph.vmetric ? vmetric[1] : width * 0.5) * widthAdvanceScale;
  5282. const vy = vmetric[2] * widthAdvanceScale;
  5283. width = vmetric ? -vmetric[0] : width;
  5284. scaledX = vx / fontSizeScale;
  5285. scaledY = (x + vy) / fontSizeScale;
  5286. } else {
  5287. scaledX = x / fontSizeScale;
  5288. scaledY = 0;
  5289. }
  5290. if (font.remeasure && width > 0) {
  5291. const measuredWidth = ctx.measureText(character).width * 1000 / fontSize * fontSizeScale;
  5292. if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
  5293. const characterScaleX = width / measuredWidth;
  5294. restoreNeeded = true;
  5295. ctx.save();
  5296. ctx.scale(characterScaleX, 1);
  5297. scaledX /= characterScaleX;
  5298. } else if (width !== measuredWidth) {
  5299. scaledX += (width - measuredWidth) / 2000 * fontSize / fontSizeScale;
  5300. }
  5301. }
  5302. if (this.contentVisible && (glyph.isInFont || font.missingFile)) {
  5303. if (simpleFillText && !accent) {
  5304. ctx.fillText(character, scaledX, scaledY);
  5305. } else {
  5306. this.paintChar(character, scaledX, scaledY, patternTransform, resetLineWidthToOne);
  5307. if (accent) {
  5308. const scaledAccentX = scaledX + fontSize * accent.offset.x / fontSizeScale;
  5309. const scaledAccentY = scaledY - fontSize * accent.offset.y / fontSizeScale;
  5310. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY, patternTransform, resetLineWidthToOne);
  5311. }
  5312. }
  5313. }
  5314. let charWidth;
  5315. if (vertical) {
  5316. charWidth = width * widthAdvanceScale - spacing * fontDirection;
  5317. } else {
  5318. charWidth = width * widthAdvanceScale + spacing * fontDirection;
  5319. }
  5320. x += charWidth;
  5321. if (restoreNeeded) {
  5322. ctx.restore();
  5323. }
  5324. }
  5325. if (vertical) {
  5326. current.y -= x;
  5327. } else {
  5328. current.x += x * textHScale;
  5329. }
  5330. ctx.restore();
  5331. this.compose();
  5332. return undefined;
  5333. }
  5334. showType3Text(glyphs) {
  5335. const ctx = this.ctx;
  5336. const current = this.current;
  5337. const font = current.font;
  5338. const fontSize = current.fontSize;
  5339. const fontDirection = current.fontDirection;
  5340. const spacingDir = font.vertical ? 1 : -1;
  5341. const charSpacing = current.charSpacing;
  5342. const wordSpacing = current.wordSpacing;
  5343. const textHScale = current.textHScale * fontDirection;
  5344. const fontMatrix = current.fontMatrix || _util.FONT_IDENTITY_MATRIX;
  5345. const glyphsLength = glyphs.length;
  5346. const isTextInvisible = current.textRenderingMode === _util.TextRenderingMode.INVISIBLE;
  5347. let i, glyph, width, spacingLength;
  5348. if (isTextInvisible || fontSize === 0) {
  5349. return;
  5350. }
  5351. this._cachedGetSinglePixelWidth = null;
  5352. ctx.save();
  5353. ctx.transform.apply(ctx, current.textMatrix);
  5354. ctx.translate(current.x, current.y);
  5355. ctx.scale(textHScale, fontDirection);
  5356. for (i = 0; i < glyphsLength; ++i) {
  5357. glyph = glyphs[i];
  5358. if (typeof glyph === "number") {
  5359. spacingLength = spacingDir * glyph * fontSize / 1000;
  5360. this.ctx.translate(spacingLength, 0);
  5361. current.x += spacingLength * textHScale;
  5362. continue;
  5363. }
  5364. const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  5365. const operatorList = font.charProcOperatorList[glyph.operatorListId];
  5366. if (!operatorList) {
  5367. (0, _util.warn)(`Type3 character "${glyph.operatorListId}" is not available.`);
  5368. continue;
  5369. }
  5370. if (this.contentVisible) {
  5371. this.processingType3 = glyph;
  5372. this.save();
  5373. ctx.scale(fontSize, fontSize);
  5374. ctx.transform.apply(ctx, fontMatrix);
  5375. this.executeOperatorList(operatorList);
  5376. this.restore();
  5377. }
  5378. const transformed = _util.Util.applyTransform([glyph.width, 0], fontMatrix);
  5379. width = transformed[0] * fontSize + spacing;
  5380. ctx.translate(width, 0);
  5381. current.x += width * textHScale;
  5382. }
  5383. ctx.restore();
  5384. this.processingType3 = null;
  5385. }
  5386. setCharWidth(xWidth, yWidth) {}
  5387. setCharWidthAndBounds(xWidth, yWidth, llx, lly, urx, ury) {
  5388. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  5389. this.clip();
  5390. this.endPath();
  5391. }
  5392. getColorN_Pattern(IR) {
  5393. let pattern;
  5394. if (IR[0] === "TilingPattern") {
  5395. const color = IR[1];
  5396. const baseTransform = this.baseTransform || this.ctx.mozCurrentTransform.slice();
  5397. const canvasGraphicsFactory = {
  5398. createCanvasGraphics: ctx => {
  5399. return new CanvasGraphics(ctx, this.commonObjs, this.objs, this.canvasFactory);
  5400. }
  5401. };
  5402. pattern = new _pattern_helper.TilingPattern(IR, color, this.ctx, canvasGraphicsFactory, baseTransform);
  5403. } else {
  5404. pattern = this._getPattern(IR[1], IR[2]);
  5405. }
  5406. return pattern;
  5407. }
  5408. setStrokeColorN() {
  5409. this.current.strokeColor = this.getColorN_Pattern(arguments);
  5410. }
  5411. setFillColorN() {
  5412. this.current.fillColor = this.getColorN_Pattern(arguments);
  5413. this.current.patternFill = true;
  5414. }
  5415. setStrokeRGBColor(r, g, b) {
  5416. const color = _util.Util.makeHexColor(r, g, b);
  5417. this.ctx.strokeStyle = color;
  5418. this.current.strokeColor = color;
  5419. }
  5420. setFillRGBColor(r, g, b) {
  5421. const color = _util.Util.makeHexColor(r, g, b);
  5422. this.ctx.fillStyle = color;
  5423. this.current.fillColor = color;
  5424. this.current.patternFill = false;
  5425. }
  5426. _getPattern(objId, matrix = null) {
  5427. let pattern;
  5428. if (this.cachedPatterns.has(objId)) {
  5429. pattern = this.cachedPatterns.get(objId);
  5430. } else {
  5431. pattern = (0, _pattern_helper.getShadingPattern)(this.objs.get(objId));
  5432. this.cachedPatterns.set(objId, pattern);
  5433. }
  5434. if (matrix) {
  5435. pattern.matrix = matrix;
  5436. }
  5437. return pattern;
  5438. }
  5439. shadingFill(objId) {
  5440. if (!this.contentVisible) {
  5441. return;
  5442. }
  5443. const ctx = this.ctx;
  5444. this.save();
  5445. const pattern = this._getPattern(objId);
  5446. ctx.fillStyle = pattern.getPattern(ctx, this, ctx.mozCurrentTransformInverse, _pattern_helper.PathType.SHADING);
  5447. const inv = ctx.mozCurrentTransformInverse;
  5448. if (inv) {
  5449. const canvas = ctx.canvas;
  5450. const width = canvas.width;
  5451. const height = canvas.height;
  5452. const bl = _util.Util.applyTransform([0, 0], inv);
  5453. const br = _util.Util.applyTransform([0, height], inv);
  5454. const ul = _util.Util.applyTransform([width, 0], inv);
  5455. const ur = _util.Util.applyTransform([width, height], inv);
  5456. const x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  5457. const y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  5458. const x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  5459. const y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  5460. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  5461. } else {
  5462. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  5463. }
  5464. this.compose(this.current.getClippedPathBoundingBox());
  5465. this.restore();
  5466. }
  5467. beginInlineImage() {
  5468. (0, _util.unreachable)("Should not call beginInlineImage");
  5469. }
  5470. beginImageData() {
  5471. (0, _util.unreachable)("Should not call beginImageData");
  5472. }
  5473. paintFormXObjectBegin(matrix, bbox) {
  5474. if (!this.contentVisible) {
  5475. return;
  5476. }
  5477. this.save();
  5478. this.baseTransformStack.push(this.baseTransform);
  5479. if (Array.isArray(matrix) && matrix.length === 6) {
  5480. this.transform.apply(this, matrix);
  5481. }
  5482. this.baseTransform = this.ctx.mozCurrentTransform;
  5483. if (bbox) {
  5484. const width = bbox[2] - bbox[0];
  5485. const height = bbox[3] - bbox[1];
  5486. this.ctx.rect(bbox[0], bbox[1], width, height);
  5487. this.current.updatePathMinMax(this.ctx.mozCurrentTransform, bbox[0], bbox[1]);
  5488. this.current.updatePathMinMax(this.ctx.mozCurrentTransform, bbox[2], bbox[3]);
  5489. this.clip();
  5490. this.endPath();
  5491. }
  5492. }
  5493. paintFormXObjectEnd() {
  5494. if (!this.contentVisible) {
  5495. return;
  5496. }
  5497. this.restore();
  5498. this.baseTransform = this.baseTransformStack.pop();
  5499. }
  5500. beginGroup(group) {
  5501. if (!this.contentVisible) {
  5502. return;
  5503. }
  5504. this.save();
  5505. if (this.inSMaskMode) {
  5506. this.endSMaskMode();
  5507. this.current.activeSMask = null;
  5508. }
  5509. const currentCtx = this.ctx;
  5510. if (!group.isolated) {
  5511. (0, _util.info)("TODO: Support non-isolated groups.");
  5512. }
  5513. if (group.knockout) {
  5514. (0, _util.warn)("Knockout groups not supported.");
  5515. }
  5516. const currentTransform = currentCtx.mozCurrentTransform;
  5517. if (group.matrix) {
  5518. currentCtx.transform.apply(currentCtx, group.matrix);
  5519. }
  5520. if (!group.bbox) {
  5521. throw new Error("Bounding box is required.");
  5522. }
  5523. let bounds = _util.Util.getAxialAlignedBoundingBox(group.bbox, currentCtx.mozCurrentTransform);
  5524. const canvasBounds = [0, 0, currentCtx.canvas.width, currentCtx.canvas.height];
  5525. bounds = _util.Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  5526. const offsetX = Math.floor(bounds[0]);
  5527. const offsetY = Math.floor(bounds[1]);
  5528. let drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  5529. let drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  5530. let scaleX = 1,
  5531. scaleY = 1;
  5532. if (drawnWidth > MAX_GROUP_SIZE) {
  5533. scaleX = drawnWidth / MAX_GROUP_SIZE;
  5534. drawnWidth = MAX_GROUP_SIZE;
  5535. }
  5536. if (drawnHeight > MAX_GROUP_SIZE) {
  5537. scaleY = drawnHeight / MAX_GROUP_SIZE;
  5538. drawnHeight = MAX_GROUP_SIZE;
  5539. }
  5540. this.current.startNewPathAndClipBox([0, 0, drawnWidth, drawnHeight]);
  5541. let cacheId = "groupAt" + this.groupLevel;
  5542. if (group.smask) {
  5543. cacheId += "_smask_" + this.smaskCounter++ % 2;
  5544. }
  5545. const scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true);
  5546. const groupCtx = scratchCanvas.context;
  5547. groupCtx.scale(1 / scaleX, 1 / scaleY);
  5548. groupCtx.translate(-offsetX, -offsetY);
  5549. groupCtx.transform.apply(groupCtx, currentTransform);
  5550. if (group.smask) {
  5551. this.smaskStack.push({
  5552. canvas: scratchCanvas.canvas,
  5553. context: groupCtx,
  5554. offsetX,
  5555. offsetY,
  5556. scaleX,
  5557. scaleY,
  5558. subtype: group.smask.subtype,
  5559. backdrop: group.smask.backdrop,
  5560. transferMap: group.smask.transferMap || null,
  5561. startTransformInverse: null
  5562. });
  5563. } else {
  5564. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  5565. currentCtx.translate(offsetX, offsetY);
  5566. currentCtx.scale(scaleX, scaleY);
  5567. currentCtx.save();
  5568. }
  5569. copyCtxState(currentCtx, groupCtx);
  5570. this.ctx = groupCtx;
  5571. this.setGState([["BM", "source-over"], ["ca", 1], ["CA", 1]]);
  5572. this.groupStack.push(currentCtx);
  5573. this.groupLevel++;
  5574. }
  5575. endGroup(group) {
  5576. if (!this.contentVisible) {
  5577. return;
  5578. }
  5579. this.groupLevel--;
  5580. const groupCtx = this.ctx;
  5581. const ctx = this.groupStack.pop();
  5582. this.ctx = ctx;
  5583. this.ctx.imageSmoothingEnabled = false;
  5584. if (group.smask) {
  5585. this.tempSMask = this.smaskStack.pop();
  5586. this.restore();
  5587. } else {
  5588. this.ctx.restore();
  5589. const currentMtx = this.ctx.mozCurrentTransform;
  5590. this.restore();
  5591. this.ctx.save();
  5592. this.ctx.setTransform.apply(this.ctx, currentMtx);
  5593. const dirtyBox = _util.Util.getAxialAlignedBoundingBox([0, 0, groupCtx.canvas.width, groupCtx.canvas.height], currentMtx);
  5594. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  5595. this.ctx.restore();
  5596. this.compose(dirtyBox);
  5597. }
  5598. }
  5599. beginAnnotations() {
  5600. this.save();
  5601. if (this.baseTransform) {
  5602. this.ctx.setTransform.apply(this.ctx, this.baseTransform);
  5603. }
  5604. }
  5605. endAnnotations() {
  5606. this.restore();
  5607. }
  5608. beginAnnotation(id, rect, transform, matrix, hasOwnCanvas) {
  5609. this.save();
  5610. if (Array.isArray(rect) && rect.length === 4) {
  5611. const width = rect[2] - rect[0];
  5612. const height = rect[3] - rect[1];
  5613. if (hasOwnCanvas && this.annotationCanvasMap) {
  5614. transform = transform.slice();
  5615. transform[4] -= rect[0];
  5616. transform[5] -= rect[1];
  5617. rect = rect.slice();
  5618. rect[0] = rect[1] = 0;
  5619. rect[2] = width;
  5620. rect[3] = height;
  5621. const [scaleX, scaleY] = _util.Util.singularValueDecompose2dScale(this.ctx.mozCurrentTransform);
  5622. const {
  5623. viewportScale
  5624. } = this;
  5625. const canvasWidth = Math.ceil(width * this.outputScaleX * viewportScale);
  5626. const canvasHeight = Math.ceil(height * this.outputScaleY * viewportScale);
  5627. this.annotationCanvas = this.canvasFactory.create(canvasWidth, canvasHeight);
  5628. const {
  5629. canvas,
  5630. context
  5631. } = this.annotationCanvas;
  5632. canvas.style.width = `calc(${width}px * var(--viewport-scale-factor))`;
  5633. canvas.style.height = `calc(${height}px * var(--viewport-scale-factor))`;
  5634. this.annotationCanvasMap.set(id, canvas);
  5635. this.annotationCanvas.savedCtx = this.ctx;
  5636. this.ctx = context;
  5637. this.ctx.setTransform(scaleX, 0, 0, -scaleY, 0, height * scaleY);
  5638. addContextCurrentTransform(this.ctx);
  5639. resetCtxToDefault(this.ctx);
  5640. } else {
  5641. resetCtxToDefault(this.ctx);
  5642. this.ctx.rect(rect[0], rect[1], width, height);
  5643. this.clip();
  5644. this.endPath();
  5645. }
  5646. }
  5647. this.current = new CanvasExtraState(this.ctx.canvas.width, this.ctx.canvas.height);
  5648. this.transform.apply(this, transform);
  5649. this.transform.apply(this, matrix);
  5650. }
  5651. endAnnotation() {
  5652. if (this.annotationCanvas) {
  5653. this.ctx = this.annotationCanvas.savedCtx;
  5654. delete this.annotationCanvas.savedCtx;
  5655. delete this.annotationCanvas;
  5656. }
  5657. this.restore();
  5658. }
  5659. paintImageMaskXObject(img) {
  5660. if (!this.contentVisible) {
  5661. return;
  5662. }
  5663. const ctx = this.ctx;
  5664. const width = img.width,
  5665. height = img.height;
  5666. const glyph = this.processingType3;
  5667. if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
  5668. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  5669. glyph.compiled = compileType3Glyph({
  5670. data: img.data,
  5671. width,
  5672. height
  5673. });
  5674. } else {
  5675. glyph.compiled = null;
  5676. }
  5677. }
  5678. if (glyph?.compiled) {
  5679. glyph.compiled(ctx);
  5680. return;
  5681. }
  5682. const mask = this._createMaskCanvas(img);
  5683. const maskCanvas = mask.canvas;
  5684. ctx.save();
  5685. ctx.setTransform(1, 0, 0, 1, 0, 0);
  5686. ctx.drawImage(maskCanvas, mask.offsetX, mask.offsetY);
  5687. ctx.restore();
  5688. this.compose();
  5689. }
  5690. paintImageMaskXObjectRepeat(imgData, scaleX, skewX = 0, skewY = 0, scaleY, positions) {
  5691. if (!this.contentVisible) {
  5692. return;
  5693. }
  5694. const ctx = this.ctx;
  5695. ctx.save();
  5696. const currentTransform = ctx.mozCurrentTransform;
  5697. ctx.transform(scaleX, skewX, skewY, scaleY, 0, 0);
  5698. const mask = this._createMaskCanvas(imgData);
  5699. ctx.setTransform(1, 0, 0, 1, 0, 0);
  5700. for (let i = 0, ii = positions.length; i < ii; i += 2) {
  5701. const trans = _util.Util.transform(currentTransform, [scaleX, skewX, skewY, scaleY, positions[i], positions[i + 1]]);
  5702. const [x, y] = _util.Util.applyTransform([0, 0], trans);
  5703. ctx.drawImage(mask.canvas, x, y);
  5704. }
  5705. ctx.restore();
  5706. this.compose();
  5707. }
  5708. paintImageMaskXObjectGroup(images) {
  5709. if (!this.contentVisible) {
  5710. return;
  5711. }
  5712. const ctx = this.ctx;
  5713. const fillColor = this.current.fillColor;
  5714. const isPatternFill = this.current.patternFill;
  5715. for (let i = 0, ii = images.length; i < ii; i++) {
  5716. const image = images[i];
  5717. const width = image.width,
  5718. height = image.height;
  5719. const maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
  5720. const maskCtx = maskCanvas.context;
  5721. maskCtx.save();
  5722. putBinaryImageMask(maskCtx, image);
  5723. maskCtx.globalCompositeOperation = "source-in";
  5724. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this, ctx.mozCurrentTransformInverse, _pattern_helper.PathType.FILL) : fillColor;
  5725. maskCtx.fillRect(0, 0, width, height);
  5726. maskCtx.restore();
  5727. ctx.save();
  5728. ctx.transform.apply(ctx, image.transform);
  5729. ctx.scale(1, -1);
  5730. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1);
  5731. ctx.restore();
  5732. }
  5733. this.compose();
  5734. }
  5735. paintImageXObject(objId) {
  5736. if (!this.contentVisible) {
  5737. return;
  5738. }
  5739. const imgData = objId.startsWith("g_") ? this.commonObjs.get(objId) : this.objs.get(objId);
  5740. if (!imgData) {
  5741. (0, _util.warn)("Dependent image isn't ready yet");
  5742. return;
  5743. }
  5744. this.paintInlineImageXObject(imgData);
  5745. }
  5746. paintImageXObjectRepeat(objId, scaleX, scaleY, positions) {
  5747. if (!this.contentVisible) {
  5748. return;
  5749. }
  5750. const imgData = objId.startsWith("g_") ? this.commonObjs.get(objId) : this.objs.get(objId);
  5751. if (!imgData) {
  5752. (0, _util.warn)("Dependent image isn't ready yet");
  5753. return;
  5754. }
  5755. const width = imgData.width;
  5756. const height = imgData.height;
  5757. const map = [];
  5758. for (let i = 0, ii = positions.length; i < ii; i += 2) {
  5759. map.push({
  5760. transform: [scaleX, 0, 0, scaleY, positions[i], positions[i + 1]],
  5761. x: 0,
  5762. y: 0,
  5763. w: width,
  5764. h: height
  5765. });
  5766. }
  5767. this.paintInlineImageXObjectGroup(imgData, map);
  5768. }
  5769. paintInlineImageXObject(imgData) {
  5770. if (!this.contentVisible) {
  5771. return;
  5772. }
  5773. const width = imgData.width;
  5774. const height = imgData.height;
  5775. const ctx = this.ctx;
  5776. this.save();
  5777. ctx.scale(1 / width, -1 / height);
  5778. let imgToPaint;
  5779. if (typeof HTMLElement === "function" && imgData instanceof HTMLElement || !imgData.data) {
  5780. imgToPaint = imgData;
  5781. } else {
  5782. const tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", width, height);
  5783. const tmpCtx = tmpCanvas.context;
  5784. putBinaryImageData(tmpCtx, imgData, this.current.transferMaps);
  5785. imgToPaint = tmpCanvas.canvas;
  5786. }
  5787. const scaled = this._scaleImage(imgToPaint, ctx.mozCurrentTransformInverse);
  5788. ctx.imageSmoothingEnabled = getImageSmoothingEnabled(ctx.mozCurrentTransform, imgData.interpolate);
  5789. ctx.drawImage(scaled.img, 0, 0, scaled.paintWidth, scaled.paintHeight, 0, -height, width, height);
  5790. if (this.imageLayer) {
  5791. const position = this.getCanvasPosition(0, -height);
  5792. this.imageLayer.appendImage({
  5793. imgData,
  5794. left: position[0],
  5795. top: position[1],
  5796. width: width / ctx.mozCurrentTransformInverse[0],
  5797. height: height / ctx.mozCurrentTransformInverse[3]
  5798. });
  5799. }
  5800. this.compose();
  5801. this.restore();
  5802. }
  5803. paintInlineImageXObjectGroup(imgData, map) {
  5804. if (!this.contentVisible) {
  5805. return;
  5806. }
  5807. const ctx = this.ctx;
  5808. const w = imgData.width;
  5809. const h = imgData.height;
  5810. const tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", w, h);
  5811. const tmpCtx = tmpCanvas.context;
  5812. putBinaryImageData(tmpCtx, imgData, this.current.transferMaps);
  5813. for (let i = 0, ii = map.length; i < ii; i++) {
  5814. const entry = map[i];
  5815. ctx.save();
  5816. ctx.transform.apply(ctx, entry.transform);
  5817. ctx.scale(1, -1);
  5818. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h, 0, -1, 1, 1);
  5819. if (this.imageLayer) {
  5820. const position = this.getCanvasPosition(entry.x, entry.y);
  5821. this.imageLayer.appendImage({
  5822. imgData,
  5823. left: position[0],
  5824. top: position[1],
  5825. width: w,
  5826. height: h
  5827. });
  5828. }
  5829. ctx.restore();
  5830. }
  5831. this.compose();
  5832. }
  5833. paintSolidColorImageMask() {
  5834. if (!this.contentVisible) {
  5835. return;
  5836. }
  5837. this.ctx.fillRect(0, 0, 1, 1);
  5838. this.compose();
  5839. }
  5840. markPoint(tag) {}
  5841. markPointProps(tag, properties) {}
  5842. beginMarkedContent(tag) {
  5843. this.markedContentStack.push({
  5844. visible: true
  5845. });
  5846. }
  5847. beginMarkedContentProps(tag, properties) {
  5848. if (tag === "OC") {
  5849. this.markedContentStack.push({
  5850. visible: this.optionalContentConfig.isVisible(properties)
  5851. });
  5852. } else {
  5853. this.markedContentStack.push({
  5854. visible: true
  5855. });
  5856. }
  5857. this.contentVisible = this.isContentVisible();
  5858. }
  5859. endMarkedContent() {
  5860. this.markedContentStack.pop();
  5861. this.contentVisible = this.isContentVisible();
  5862. }
  5863. beginCompat() {}
  5864. endCompat() {}
  5865. consumePath(clipBox) {
  5866. if (this.pendingClip) {
  5867. this.current.updateClipFromPath();
  5868. }
  5869. if (!this.pendingClip) {
  5870. this.compose(clipBox);
  5871. }
  5872. const ctx = this.ctx;
  5873. if (this.pendingClip) {
  5874. if (this.pendingClip === EO_CLIP) {
  5875. ctx.clip("evenodd");
  5876. } else {
  5877. ctx.clip();
  5878. }
  5879. this.pendingClip = null;
  5880. }
  5881. this.current.startNewPathAndClipBox(this.current.clipBox);
  5882. ctx.beginPath();
  5883. }
  5884. getSinglePixelWidth() {
  5885. if (this._cachedGetSinglePixelWidth === null) {
  5886. const m = this.ctx.mozCurrentTransform;
  5887. const absDet = Math.abs(m[0] * m[3] - m[2] * m[1]);
  5888. const sqNorm1 = m[0] ** 2 + m[2] ** 2;
  5889. const sqNorm2 = m[1] ** 2 + m[3] ** 2;
  5890. const pixelHeight = Math.sqrt(Math.max(sqNorm1, sqNorm2)) / absDet;
  5891. if (sqNorm1 !== sqNorm2 && this._combinedScaleFactor * pixelHeight > 1) {
  5892. this._cachedGetSinglePixelWidth = -(this._combinedScaleFactor * pixelHeight);
  5893. } else if (absDet > Number.EPSILON) {
  5894. this._cachedGetSinglePixelWidth = pixelHeight;
  5895. } else {
  5896. this._cachedGetSinglePixelWidth = 1;
  5897. }
  5898. }
  5899. return this._cachedGetSinglePixelWidth;
  5900. }
  5901. getCanvasPosition(x, y) {
  5902. const transform = this.ctx.mozCurrentTransform;
  5903. return [transform[0] * x + transform[2] * y + transform[4], transform[1] * x + transform[3] * y + transform[5]];
  5904. }
  5905. isContentVisible() {
  5906. for (let i = this.markedContentStack.length - 1; i >= 0; i--) {
  5907. if (!this.markedContentStack[i].visible) {
  5908. return false;
  5909. }
  5910. }
  5911. return true;
  5912. }
  5913. }
  5914. exports.CanvasGraphics = CanvasGraphics;
  5915. for (const op in _util.OPS) {
  5916. if (CanvasGraphics.prototype[op] !== undefined) {
  5917. CanvasGraphics.prototype[_util.OPS[op]] = CanvasGraphics.prototype[op];
  5918. }
  5919. }
  5920. /***/ }),
  5921. /* 11 */
  5922. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  5923. Object.defineProperty(exports, "__esModule", ({
  5924. value: true
  5925. }));
  5926. exports.TilingPattern = exports.PathType = void 0;
  5927. exports.getShadingPattern = getShadingPattern;
  5928. var _util = __w_pdfjs_require__(1);
  5929. const PathType = {
  5930. FILL: "Fill",
  5931. STROKE: "Stroke",
  5932. SHADING: "Shading"
  5933. };
  5934. exports.PathType = PathType;
  5935. function applyBoundingBox(ctx, bbox) {
  5936. if (!bbox || typeof Path2D === "undefined") {
  5937. return;
  5938. }
  5939. const width = bbox[2] - bbox[0];
  5940. const height = bbox[3] - bbox[1];
  5941. const region = new Path2D();
  5942. region.rect(bbox[0], bbox[1], width, height);
  5943. ctx.clip(region);
  5944. }
  5945. class BaseShadingPattern {
  5946. constructor() {
  5947. if (this.constructor === BaseShadingPattern) {
  5948. (0, _util.unreachable)("Cannot initialize BaseShadingPattern.");
  5949. }
  5950. }
  5951. getPattern() {
  5952. (0, _util.unreachable)("Abstract method `getPattern` called.");
  5953. }
  5954. }
  5955. class RadialAxialShadingPattern extends BaseShadingPattern {
  5956. constructor(IR) {
  5957. super();
  5958. this._type = IR[1];
  5959. this._bbox = IR[2];
  5960. this._colorStops = IR[3];
  5961. this._p0 = IR[4];
  5962. this._p1 = IR[5];
  5963. this._r0 = IR[6];
  5964. this._r1 = IR[7];
  5965. this.matrix = null;
  5966. }
  5967. _createGradient(ctx) {
  5968. let grad;
  5969. if (this._type === "axial") {
  5970. grad = ctx.createLinearGradient(this._p0[0], this._p0[1], this._p1[0], this._p1[1]);
  5971. } else if (this._type === "radial") {
  5972. grad = ctx.createRadialGradient(this._p0[0], this._p0[1], this._r0, this._p1[0], this._p1[1], this._r1);
  5973. }
  5974. for (const colorStop of this._colorStops) {
  5975. grad.addColorStop(colorStop[0], colorStop[1]);
  5976. }
  5977. return grad;
  5978. }
  5979. getPattern(ctx, owner, inverse, pathType) {
  5980. let pattern;
  5981. if (pathType === PathType.STROKE || pathType === PathType.FILL) {
  5982. const ownerBBox = owner.current.getClippedPathBoundingBox(pathType, ctx.mozCurrentTransform) || [0, 0, 0, 0];
  5983. const width = Math.ceil(ownerBBox[2] - ownerBBox[0]) || 1;
  5984. const height = Math.ceil(ownerBBox[3] - ownerBBox[1]) || 1;
  5985. const tmpCanvas = owner.cachedCanvases.getCanvas("pattern", width, height, true);
  5986. const tmpCtx = tmpCanvas.context;
  5987. tmpCtx.clearRect(0, 0, tmpCtx.canvas.width, tmpCtx.canvas.height);
  5988. tmpCtx.beginPath();
  5989. tmpCtx.rect(0, 0, tmpCtx.canvas.width, tmpCtx.canvas.height);
  5990. tmpCtx.translate(-ownerBBox[0], -ownerBBox[1]);
  5991. inverse = _util.Util.transform(inverse, [1, 0, 0, 1, ownerBBox[0], ownerBBox[1]]);
  5992. tmpCtx.transform.apply(tmpCtx, owner.baseTransform);
  5993. if (this.matrix) {
  5994. tmpCtx.transform.apply(tmpCtx, this.matrix);
  5995. }
  5996. applyBoundingBox(tmpCtx, this._bbox);
  5997. tmpCtx.fillStyle = this._createGradient(tmpCtx);
  5998. tmpCtx.fill();
  5999. pattern = ctx.createPattern(tmpCanvas.canvas, "no-repeat");
  6000. const domMatrix = new DOMMatrix(inverse);
  6001. try {
  6002. pattern.setTransform(domMatrix);
  6003. } catch (ex) {
  6004. (0, _util.warn)(`RadialAxialShadingPattern.getPattern: "${ex?.message}".`);
  6005. }
  6006. } else {
  6007. applyBoundingBox(ctx, this._bbox);
  6008. pattern = this._createGradient(ctx);
  6009. }
  6010. return pattern;
  6011. }
  6012. }
  6013. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  6014. const coords = context.coords,
  6015. colors = context.colors;
  6016. const bytes = data.data,
  6017. rowSize = data.width * 4;
  6018. let tmp;
  6019. if (coords[p1 + 1] > coords[p2 + 1]) {
  6020. tmp = p1;
  6021. p1 = p2;
  6022. p2 = tmp;
  6023. tmp = c1;
  6024. c1 = c2;
  6025. c2 = tmp;
  6026. }
  6027. if (coords[p2 + 1] > coords[p3 + 1]) {
  6028. tmp = p2;
  6029. p2 = p3;
  6030. p3 = tmp;
  6031. tmp = c2;
  6032. c2 = c3;
  6033. c3 = tmp;
  6034. }
  6035. if (coords[p1 + 1] > coords[p2 + 1]) {
  6036. tmp = p1;
  6037. p1 = p2;
  6038. p2 = tmp;
  6039. tmp = c1;
  6040. c1 = c2;
  6041. c2 = tmp;
  6042. }
  6043. const x1 = (coords[p1] + context.offsetX) * context.scaleX;
  6044. const y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  6045. const x2 = (coords[p2] + context.offsetX) * context.scaleX;
  6046. const y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  6047. const x3 = (coords[p3] + context.offsetX) * context.scaleX;
  6048. const y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  6049. if (y1 >= y3) {
  6050. return;
  6051. }
  6052. const c1r = colors[c1],
  6053. c1g = colors[c1 + 1],
  6054. c1b = colors[c1 + 2];
  6055. const c2r = colors[c2],
  6056. c2g = colors[c2 + 1],
  6057. c2b = colors[c2 + 2];
  6058. const c3r = colors[c3],
  6059. c3g = colors[c3 + 1],
  6060. c3b = colors[c3 + 2];
  6061. const minY = Math.round(y1),
  6062. maxY = Math.round(y3);
  6063. let xa, car, cag, cab;
  6064. let xb, cbr, cbg, cbb;
  6065. for (let y = minY; y <= maxY; y++) {
  6066. if (y < y2) {
  6067. let k;
  6068. if (y < y1) {
  6069. k = 0;
  6070. } else {
  6071. k = (y1 - y) / (y1 - y2);
  6072. }
  6073. xa = x1 - (x1 - x2) * k;
  6074. car = c1r - (c1r - c2r) * k;
  6075. cag = c1g - (c1g - c2g) * k;
  6076. cab = c1b - (c1b - c2b) * k;
  6077. } else {
  6078. let k;
  6079. if (y > y3) {
  6080. k = 1;
  6081. } else if (y2 === y3) {
  6082. k = 0;
  6083. } else {
  6084. k = (y2 - y) / (y2 - y3);
  6085. }
  6086. xa = x2 - (x2 - x3) * k;
  6087. car = c2r - (c2r - c3r) * k;
  6088. cag = c2g - (c2g - c3g) * k;
  6089. cab = c2b - (c2b - c3b) * k;
  6090. }
  6091. let k;
  6092. if (y < y1) {
  6093. k = 0;
  6094. } else if (y > y3) {
  6095. k = 1;
  6096. } else {
  6097. k = (y1 - y) / (y1 - y3);
  6098. }
  6099. xb = x1 - (x1 - x3) * k;
  6100. cbr = c1r - (c1r - c3r) * k;
  6101. cbg = c1g - (c1g - c3g) * k;
  6102. cbb = c1b - (c1b - c3b) * k;
  6103. const x1_ = Math.round(Math.min(xa, xb));
  6104. const x2_ = Math.round(Math.max(xa, xb));
  6105. let j = rowSize * y + x1_ * 4;
  6106. for (let x = x1_; x <= x2_; x++) {
  6107. k = (xa - x) / (xa - xb);
  6108. if (k < 0) {
  6109. k = 0;
  6110. } else if (k > 1) {
  6111. k = 1;
  6112. }
  6113. bytes[j++] = car - (car - cbr) * k | 0;
  6114. bytes[j++] = cag - (cag - cbg) * k | 0;
  6115. bytes[j++] = cab - (cab - cbb) * k | 0;
  6116. bytes[j++] = 255;
  6117. }
  6118. }
  6119. }
  6120. function drawFigure(data, figure, context) {
  6121. const ps = figure.coords;
  6122. const cs = figure.colors;
  6123. let i, ii;
  6124. switch (figure.type) {
  6125. case "lattice":
  6126. const verticesPerRow = figure.verticesPerRow;
  6127. const rows = Math.floor(ps.length / verticesPerRow) - 1;
  6128. const cols = verticesPerRow - 1;
  6129. for (i = 0; i < rows; i++) {
  6130. let q = i * verticesPerRow;
  6131. for (let j = 0; j < cols; j++, q++) {
  6132. drawTriangle(data, context, ps[q], ps[q + 1], ps[q + verticesPerRow], cs[q], cs[q + 1], cs[q + verticesPerRow]);
  6133. drawTriangle(data, context, ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow], cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  6134. }
  6135. }
  6136. break;
  6137. case "triangles":
  6138. for (i = 0, ii = ps.length; i < ii; i += 3) {
  6139. drawTriangle(data, context, ps[i], ps[i + 1], ps[i + 2], cs[i], cs[i + 1], cs[i + 2]);
  6140. }
  6141. break;
  6142. default:
  6143. throw new Error("illegal figure");
  6144. }
  6145. }
  6146. class MeshShadingPattern extends BaseShadingPattern {
  6147. constructor(IR) {
  6148. super();
  6149. this._coords = IR[2];
  6150. this._colors = IR[3];
  6151. this._figures = IR[4];
  6152. this._bounds = IR[5];
  6153. this._bbox = IR[7];
  6154. this._background = IR[8];
  6155. this.matrix = null;
  6156. }
  6157. _createMeshCanvas(combinedScale, backgroundColor, cachedCanvases) {
  6158. const EXPECTED_SCALE = 1.1;
  6159. const MAX_PATTERN_SIZE = 3000;
  6160. const BORDER_SIZE = 2;
  6161. const offsetX = Math.floor(this._bounds[0]);
  6162. const offsetY = Math.floor(this._bounds[1]);
  6163. const boundsWidth = Math.ceil(this._bounds[2]) - offsetX;
  6164. const boundsHeight = Math.ceil(this._bounds[3]) - offsetY;
  6165. const width = Math.min(Math.ceil(Math.abs(boundsWidth * combinedScale[0] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  6166. const height = Math.min(Math.ceil(Math.abs(boundsHeight * combinedScale[1] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  6167. const scaleX = boundsWidth / width;
  6168. const scaleY = boundsHeight / height;
  6169. const context = {
  6170. coords: this._coords,
  6171. colors: this._colors,
  6172. offsetX: -offsetX,
  6173. offsetY: -offsetY,
  6174. scaleX: 1 / scaleX,
  6175. scaleY: 1 / scaleY
  6176. };
  6177. const paddedWidth = width + BORDER_SIZE * 2;
  6178. const paddedHeight = height + BORDER_SIZE * 2;
  6179. const tmpCanvas = cachedCanvases.getCanvas("mesh", paddedWidth, paddedHeight, false);
  6180. const tmpCtx = tmpCanvas.context;
  6181. const data = tmpCtx.createImageData(width, height);
  6182. if (backgroundColor) {
  6183. const bytes = data.data;
  6184. for (let i = 0, ii = bytes.length; i < ii; i += 4) {
  6185. bytes[i] = backgroundColor[0];
  6186. bytes[i + 1] = backgroundColor[1];
  6187. bytes[i + 2] = backgroundColor[2];
  6188. bytes[i + 3] = 255;
  6189. }
  6190. }
  6191. for (const figure of this._figures) {
  6192. drawFigure(data, figure, context);
  6193. }
  6194. tmpCtx.putImageData(data, BORDER_SIZE, BORDER_SIZE);
  6195. const canvas = tmpCanvas.canvas;
  6196. return {
  6197. canvas,
  6198. offsetX: offsetX - BORDER_SIZE * scaleX,
  6199. offsetY: offsetY - BORDER_SIZE * scaleY,
  6200. scaleX,
  6201. scaleY
  6202. };
  6203. }
  6204. getPattern(ctx, owner, inverse, pathType) {
  6205. applyBoundingBox(ctx, this._bbox);
  6206. let scale;
  6207. if (pathType === PathType.SHADING) {
  6208. scale = _util.Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  6209. } else {
  6210. scale = _util.Util.singularValueDecompose2dScale(owner.baseTransform);
  6211. if (this.matrix) {
  6212. const matrixScale = _util.Util.singularValueDecompose2dScale(this.matrix);
  6213. scale = [scale[0] * matrixScale[0], scale[1] * matrixScale[1]];
  6214. }
  6215. }
  6216. const temporaryPatternCanvas = this._createMeshCanvas(scale, pathType === PathType.SHADING ? null : this._background, owner.cachedCanvases);
  6217. if (pathType !== PathType.SHADING) {
  6218. ctx.setTransform.apply(ctx, owner.baseTransform);
  6219. if (this.matrix) {
  6220. ctx.transform.apply(ctx, this.matrix);
  6221. }
  6222. }
  6223. ctx.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY);
  6224. ctx.scale(temporaryPatternCanvas.scaleX, temporaryPatternCanvas.scaleY);
  6225. return ctx.createPattern(temporaryPatternCanvas.canvas, "no-repeat");
  6226. }
  6227. }
  6228. class DummyShadingPattern extends BaseShadingPattern {
  6229. getPattern() {
  6230. return "hotpink";
  6231. }
  6232. }
  6233. function getShadingPattern(IR) {
  6234. switch (IR[0]) {
  6235. case "RadialAxial":
  6236. return new RadialAxialShadingPattern(IR);
  6237. case "Mesh":
  6238. return new MeshShadingPattern(IR);
  6239. case "Dummy":
  6240. return new DummyShadingPattern();
  6241. }
  6242. throw new Error(`Unknown IR type: ${IR[0]}`);
  6243. }
  6244. const PaintType = {
  6245. COLORED: 1,
  6246. UNCOLORED: 2
  6247. };
  6248. class TilingPattern {
  6249. static get MAX_PATTERN_SIZE() {
  6250. return (0, _util.shadow)(this, "MAX_PATTERN_SIZE", 3000);
  6251. }
  6252. constructor(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
  6253. this.operatorList = IR[2];
  6254. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  6255. this.bbox = IR[4];
  6256. this.xstep = IR[5];
  6257. this.ystep = IR[6];
  6258. this.paintType = IR[7];
  6259. this.tilingType = IR[8];
  6260. this.color = color;
  6261. this.ctx = ctx;
  6262. this.canvasGraphicsFactory = canvasGraphicsFactory;
  6263. this.baseTransform = baseTransform;
  6264. }
  6265. createPatternCanvas(owner) {
  6266. const operatorList = this.operatorList;
  6267. const bbox = this.bbox;
  6268. const xstep = this.xstep;
  6269. const ystep = this.ystep;
  6270. const paintType = this.paintType;
  6271. const tilingType = this.tilingType;
  6272. const color = this.color;
  6273. const canvasGraphicsFactory = this.canvasGraphicsFactory;
  6274. (0, _util.info)("TilingType: " + tilingType);
  6275. const x0 = bbox[0],
  6276. y0 = bbox[1],
  6277. x1 = bbox[2],
  6278. y1 = bbox[3];
  6279. const matrixScale = _util.Util.singularValueDecompose2dScale(this.matrix);
  6280. const curMatrixScale = _util.Util.singularValueDecompose2dScale(this.baseTransform);
  6281. const combinedScale = [matrixScale[0] * curMatrixScale[0], matrixScale[1] * curMatrixScale[1]];
  6282. const dimx = this.getSizeAndScale(xstep, this.ctx.canvas.width, combinedScale[0]);
  6283. const dimy = this.getSizeAndScale(ystep, this.ctx.canvas.height, combinedScale[1]);
  6284. const tmpCanvas = owner.cachedCanvases.getCanvas("pattern", dimx.size, dimy.size, true);
  6285. const tmpCtx = tmpCanvas.context;
  6286. const graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
  6287. graphics.groupLevel = owner.groupLevel;
  6288. this.setFillAndStrokeStyleToContext(graphics, paintType, color);
  6289. let adjustedX0 = x0;
  6290. let adjustedY0 = y0;
  6291. let adjustedX1 = x1;
  6292. let adjustedY1 = y1;
  6293. if (x0 < 0) {
  6294. adjustedX0 = 0;
  6295. adjustedX1 += Math.abs(x0);
  6296. }
  6297. if (y0 < 0) {
  6298. adjustedY0 = 0;
  6299. adjustedY1 += Math.abs(y0);
  6300. }
  6301. tmpCtx.translate(-(dimx.scale * adjustedX0), -(dimy.scale * adjustedY0));
  6302. graphics.transform(dimx.scale, 0, 0, dimy.scale, 0, 0);
  6303. tmpCtx.save();
  6304. this.clipBbox(graphics, adjustedX0, adjustedY0, adjustedX1, adjustedY1);
  6305. graphics.baseTransform = graphics.ctx.mozCurrentTransform.slice();
  6306. graphics.executeOperatorList(operatorList);
  6307. graphics.endDrawing();
  6308. return {
  6309. canvas: tmpCanvas.canvas,
  6310. scaleX: dimx.scale,
  6311. scaleY: dimy.scale,
  6312. offsetX: adjustedX0,
  6313. offsetY: adjustedY0
  6314. };
  6315. }
  6316. getSizeAndScale(step, realOutputSize, scale) {
  6317. step = Math.abs(step);
  6318. const maxSize = Math.max(TilingPattern.MAX_PATTERN_SIZE, realOutputSize);
  6319. let size = Math.ceil(step * scale);
  6320. if (size >= maxSize) {
  6321. size = maxSize;
  6322. } else {
  6323. scale = size / step;
  6324. }
  6325. return {
  6326. scale,
  6327. size
  6328. };
  6329. }
  6330. clipBbox(graphics, x0, y0, x1, y1) {
  6331. const bboxWidth = x1 - x0;
  6332. const bboxHeight = y1 - y0;
  6333. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  6334. graphics.clip();
  6335. graphics.endPath();
  6336. }
  6337. setFillAndStrokeStyleToContext(graphics, paintType, color) {
  6338. const context = graphics.ctx,
  6339. current = graphics.current;
  6340. switch (paintType) {
  6341. case PaintType.COLORED:
  6342. const ctx = this.ctx;
  6343. context.fillStyle = ctx.fillStyle;
  6344. context.strokeStyle = ctx.strokeStyle;
  6345. current.fillColor = ctx.fillStyle;
  6346. current.strokeColor = ctx.strokeStyle;
  6347. break;
  6348. case PaintType.UNCOLORED:
  6349. const cssColor = _util.Util.makeHexColor(color[0], color[1], color[2]);
  6350. context.fillStyle = cssColor;
  6351. context.strokeStyle = cssColor;
  6352. current.fillColor = cssColor;
  6353. current.strokeColor = cssColor;
  6354. break;
  6355. default:
  6356. throw new _util.FormatError(`Unsupported paint type: ${paintType}`);
  6357. }
  6358. }
  6359. getPattern(ctx, owner, inverse, pathType) {
  6360. let matrix = inverse;
  6361. if (pathType !== PathType.SHADING) {
  6362. matrix = _util.Util.transform(matrix, owner.baseTransform);
  6363. if (this.matrix) {
  6364. matrix = _util.Util.transform(matrix, this.matrix);
  6365. }
  6366. }
  6367. const temporaryPatternCanvas = this.createPatternCanvas(owner);
  6368. let domMatrix = new DOMMatrix(matrix);
  6369. domMatrix = domMatrix.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY);
  6370. domMatrix = domMatrix.scale(1 / temporaryPatternCanvas.scaleX, 1 / temporaryPatternCanvas.scaleY);
  6371. const pattern = ctx.createPattern(temporaryPatternCanvas.canvas, "repeat");
  6372. try {
  6373. pattern.setTransform(domMatrix);
  6374. } catch (ex) {
  6375. (0, _util.warn)(`TilingPattern.getPattern: "${ex?.message}".`);
  6376. }
  6377. return pattern;
  6378. }
  6379. }
  6380. exports.TilingPattern = TilingPattern;
  6381. /***/ }),
  6382. /* 12 */
  6383. /***/ ((__unused_webpack_module, exports) => {
  6384. Object.defineProperty(exports, "__esModule", ({
  6385. value: true
  6386. }));
  6387. exports.GlobalWorkerOptions = void 0;
  6388. const GlobalWorkerOptions = Object.create(null);
  6389. exports.GlobalWorkerOptions = GlobalWorkerOptions;
  6390. GlobalWorkerOptions.workerPort = GlobalWorkerOptions.workerPort === undefined ? null : GlobalWorkerOptions.workerPort;
  6391. GlobalWorkerOptions.workerSrc = GlobalWorkerOptions.workerSrc === undefined ? "" : GlobalWorkerOptions.workerSrc;
  6392. /***/ }),
  6393. /* 13 */
  6394. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  6395. Object.defineProperty(exports, "__esModule", ({
  6396. value: true
  6397. }));
  6398. exports.MessageHandler = void 0;
  6399. var _util = __w_pdfjs_require__(1);
  6400. const CallbackKind = {
  6401. UNKNOWN: 0,
  6402. DATA: 1,
  6403. ERROR: 2
  6404. };
  6405. const StreamKind = {
  6406. UNKNOWN: 0,
  6407. CANCEL: 1,
  6408. CANCEL_COMPLETE: 2,
  6409. CLOSE: 3,
  6410. ENQUEUE: 4,
  6411. ERROR: 5,
  6412. PULL: 6,
  6413. PULL_COMPLETE: 7,
  6414. START_COMPLETE: 8
  6415. };
  6416. function wrapReason(reason) {
  6417. if (!(reason instanceof Error || typeof reason === "object" && reason !== null)) {
  6418. (0, _util.unreachable)('wrapReason: Expected "reason" to be a (possibly cloned) Error.');
  6419. }
  6420. switch (reason.name) {
  6421. case "AbortException":
  6422. return new _util.AbortException(reason.message);
  6423. case "MissingPDFException":
  6424. return new _util.MissingPDFException(reason.message);
  6425. case "PasswordException":
  6426. return new _util.PasswordException(reason.message, reason.code);
  6427. case "UnexpectedResponseException":
  6428. return new _util.UnexpectedResponseException(reason.message, reason.status);
  6429. case "UnknownErrorException":
  6430. return new _util.UnknownErrorException(reason.message, reason.details);
  6431. default:
  6432. return new _util.UnknownErrorException(reason.message, reason.toString());
  6433. }
  6434. }
  6435. class MessageHandler {
  6436. constructor(sourceName, targetName, comObj) {
  6437. this.sourceName = sourceName;
  6438. this.targetName = targetName;
  6439. this.comObj = comObj;
  6440. this.callbackId = 1;
  6441. this.streamId = 1;
  6442. this.streamSinks = Object.create(null);
  6443. this.streamControllers = Object.create(null);
  6444. this.callbackCapabilities = Object.create(null);
  6445. this.actionHandler = Object.create(null);
  6446. this._onComObjOnMessage = event => {
  6447. const data = event.data;
  6448. if (data.targetName !== this.sourceName) {
  6449. return;
  6450. }
  6451. if (data.stream) {
  6452. this._processStreamMessage(data);
  6453. return;
  6454. }
  6455. if (data.callback) {
  6456. const callbackId = data.callbackId;
  6457. const capability = this.callbackCapabilities[callbackId];
  6458. if (!capability) {
  6459. throw new Error(`Cannot resolve callback ${callbackId}`);
  6460. }
  6461. delete this.callbackCapabilities[callbackId];
  6462. if (data.callback === CallbackKind.DATA) {
  6463. capability.resolve(data.data);
  6464. } else if (data.callback === CallbackKind.ERROR) {
  6465. capability.reject(wrapReason(data.reason));
  6466. } else {
  6467. throw new Error("Unexpected callback case");
  6468. }
  6469. return;
  6470. }
  6471. const action = this.actionHandler[data.action];
  6472. if (!action) {
  6473. throw new Error(`Unknown action from worker: ${data.action}`);
  6474. }
  6475. if (data.callbackId) {
  6476. const cbSourceName = this.sourceName;
  6477. const cbTargetName = data.sourceName;
  6478. new Promise(function (resolve) {
  6479. resolve(action(data.data));
  6480. }).then(function (result) {
  6481. comObj.postMessage({
  6482. sourceName: cbSourceName,
  6483. targetName: cbTargetName,
  6484. callback: CallbackKind.DATA,
  6485. callbackId: data.callbackId,
  6486. data: result
  6487. });
  6488. }, function (reason) {
  6489. comObj.postMessage({
  6490. sourceName: cbSourceName,
  6491. targetName: cbTargetName,
  6492. callback: CallbackKind.ERROR,
  6493. callbackId: data.callbackId,
  6494. reason: wrapReason(reason)
  6495. });
  6496. });
  6497. return;
  6498. }
  6499. if (data.streamId) {
  6500. this._createStreamSink(data);
  6501. return;
  6502. }
  6503. action(data.data);
  6504. };
  6505. comObj.addEventListener("message", this._onComObjOnMessage);
  6506. }
  6507. on(actionName, handler) {
  6508. const ah = this.actionHandler;
  6509. if (ah[actionName]) {
  6510. throw new Error(`There is already an actionName called "${actionName}"`);
  6511. }
  6512. ah[actionName] = handler;
  6513. }
  6514. send(actionName, data, transfers) {
  6515. this.comObj.postMessage({
  6516. sourceName: this.sourceName,
  6517. targetName: this.targetName,
  6518. action: actionName,
  6519. data
  6520. }, transfers);
  6521. }
  6522. sendWithPromise(actionName, data, transfers) {
  6523. const callbackId = this.callbackId++;
  6524. const capability = (0, _util.createPromiseCapability)();
  6525. this.callbackCapabilities[callbackId] = capability;
  6526. try {
  6527. this.comObj.postMessage({
  6528. sourceName: this.sourceName,
  6529. targetName: this.targetName,
  6530. action: actionName,
  6531. callbackId,
  6532. data
  6533. }, transfers);
  6534. } catch (ex) {
  6535. capability.reject(ex);
  6536. }
  6537. return capability.promise;
  6538. }
  6539. sendWithStream(actionName, data, queueingStrategy, transfers) {
  6540. const streamId = this.streamId++,
  6541. sourceName = this.sourceName,
  6542. targetName = this.targetName,
  6543. comObj = this.comObj;
  6544. return new ReadableStream({
  6545. start: controller => {
  6546. const startCapability = (0, _util.createPromiseCapability)();
  6547. this.streamControllers[streamId] = {
  6548. controller,
  6549. startCall: startCapability,
  6550. pullCall: null,
  6551. cancelCall: null,
  6552. isClosed: false
  6553. };
  6554. comObj.postMessage({
  6555. sourceName,
  6556. targetName,
  6557. action: actionName,
  6558. streamId,
  6559. data,
  6560. desiredSize: controller.desiredSize
  6561. }, transfers);
  6562. return startCapability.promise;
  6563. },
  6564. pull: controller => {
  6565. const pullCapability = (0, _util.createPromiseCapability)();
  6566. this.streamControllers[streamId].pullCall = pullCapability;
  6567. comObj.postMessage({
  6568. sourceName,
  6569. targetName,
  6570. stream: StreamKind.PULL,
  6571. streamId,
  6572. desiredSize: controller.desiredSize
  6573. });
  6574. return pullCapability.promise;
  6575. },
  6576. cancel: reason => {
  6577. (0, _util.assert)(reason instanceof Error, "cancel must have a valid reason");
  6578. const cancelCapability = (0, _util.createPromiseCapability)();
  6579. this.streamControllers[streamId].cancelCall = cancelCapability;
  6580. this.streamControllers[streamId].isClosed = true;
  6581. comObj.postMessage({
  6582. sourceName,
  6583. targetName,
  6584. stream: StreamKind.CANCEL,
  6585. streamId,
  6586. reason: wrapReason(reason)
  6587. });
  6588. return cancelCapability.promise;
  6589. }
  6590. }, queueingStrategy);
  6591. }
  6592. _createStreamSink(data) {
  6593. const streamId = data.streamId,
  6594. sourceName = this.sourceName,
  6595. targetName = data.sourceName,
  6596. comObj = this.comObj;
  6597. const self = this,
  6598. action = this.actionHandler[data.action];
  6599. const streamSink = {
  6600. enqueue(chunk, size = 1, transfers) {
  6601. if (this.isCancelled) {
  6602. return;
  6603. }
  6604. const lastDesiredSize = this.desiredSize;
  6605. this.desiredSize -= size;
  6606. if (lastDesiredSize > 0 && this.desiredSize <= 0) {
  6607. this.sinkCapability = (0, _util.createPromiseCapability)();
  6608. this.ready = this.sinkCapability.promise;
  6609. }
  6610. comObj.postMessage({
  6611. sourceName,
  6612. targetName,
  6613. stream: StreamKind.ENQUEUE,
  6614. streamId,
  6615. chunk
  6616. }, transfers);
  6617. },
  6618. close() {
  6619. if (this.isCancelled) {
  6620. return;
  6621. }
  6622. this.isCancelled = true;
  6623. comObj.postMessage({
  6624. sourceName,
  6625. targetName,
  6626. stream: StreamKind.CLOSE,
  6627. streamId
  6628. });
  6629. delete self.streamSinks[streamId];
  6630. },
  6631. error(reason) {
  6632. (0, _util.assert)(reason instanceof Error, "error must have a valid reason");
  6633. if (this.isCancelled) {
  6634. return;
  6635. }
  6636. this.isCancelled = true;
  6637. comObj.postMessage({
  6638. sourceName,
  6639. targetName,
  6640. stream: StreamKind.ERROR,
  6641. streamId,
  6642. reason: wrapReason(reason)
  6643. });
  6644. },
  6645. sinkCapability: (0, _util.createPromiseCapability)(),
  6646. onPull: null,
  6647. onCancel: null,
  6648. isCancelled: false,
  6649. desiredSize: data.desiredSize,
  6650. ready: null
  6651. };
  6652. streamSink.sinkCapability.resolve();
  6653. streamSink.ready = streamSink.sinkCapability.promise;
  6654. this.streamSinks[streamId] = streamSink;
  6655. new Promise(function (resolve) {
  6656. resolve(action(data.data, streamSink));
  6657. }).then(function () {
  6658. comObj.postMessage({
  6659. sourceName,
  6660. targetName,
  6661. stream: StreamKind.START_COMPLETE,
  6662. streamId,
  6663. success: true
  6664. });
  6665. }, function (reason) {
  6666. comObj.postMessage({
  6667. sourceName,
  6668. targetName,
  6669. stream: StreamKind.START_COMPLETE,
  6670. streamId,
  6671. reason: wrapReason(reason)
  6672. });
  6673. });
  6674. }
  6675. _processStreamMessage(data) {
  6676. const streamId = data.streamId,
  6677. sourceName = this.sourceName,
  6678. targetName = data.sourceName,
  6679. comObj = this.comObj;
  6680. const streamController = this.streamControllers[streamId],
  6681. streamSink = this.streamSinks[streamId];
  6682. switch (data.stream) {
  6683. case StreamKind.START_COMPLETE:
  6684. if (data.success) {
  6685. streamController.startCall.resolve();
  6686. } else {
  6687. streamController.startCall.reject(wrapReason(data.reason));
  6688. }
  6689. break;
  6690. case StreamKind.PULL_COMPLETE:
  6691. if (data.success) {
  6692. streamController.pullCall.resolve();
  6693. } else {
  6694. streamController.pullCall.reject(wrapReason(data.reason));
  6695. }
  6696. break;
  6697. case StreamKind.PULL:
  6698. if (!streamSink) {
  6699. comObj.postMessage({
  6700. sourceName,
  6701. targetName,
  6702. stream: StreamKind.PULL_COMPLETE,
  6703. streamId,
  6704. success: true
  6705. });
  6706. break;
  6707. }
  6708. if (streamSink.desiredSize <= 0 && data.desiredSize > 0) {
  6709. streamSink.sinkCapability.resolve();
  6710. }
  6711. streamSink.desiredSize = data.desiredSize;
  6712. new Promise(function (resolve) {
  6713. resolve(streamSink.onPull && streamSink.onPull());
  6714. }).then(function () {
  6715. comObj.postMessage({
  6716. sourceName,
  6717. targetName,
  6718. stream: StreamKind.PULL_COMPLETE,
  6719. streamId,
  6720. success: true
  6721. });
  6722. }, function (reason) {
  6723. comObj.postMessage({
  6724. sourceName,
  6725. targetName,
  6726. stream: StreamKind.PULL_COMPLETE,
  6727. streamId,
  6728. reason: wrapReason(reason)
  6729. });
  6730. });
  6731. break;
  6732. case StreamKind.ENQUEUE:
  6733. (0, _util.assert)(streamController, "enqueue should have stream controller");
  6734. if (streamController.isClosed) {
  6735. break;
  6736. }
  6737. streamController.controller.enqueue(data.chunk);
  6738. break;
  6739. case StreamKind.CLOSE:
  6740. (0, _util.assert)(streamController, "close should have stream controller");
  6741. if (streamController.isClosed) {
  6742. break;
  6743. }
  6744. streamController.isClosed = true;
  6745. streamController.controller.close();
  6746. this._deleteStreamController(streamController, streamId);
  6747. break;
  6748. case StreamKind.ERROR:
  6749. (0, _util.assert)(streamController, "error should have stream controller");
  6750. streamController.controller.error(wrapReason(data.reason));
  6751. this._deleteStreamController(streamController, streamId);
  6752. break;
  6753. case StreamKind.CANCEL_COMPLETE:
  6754. if (data.success) {
  6755. streamController.cancelCall.resolve();
  6756. } else {
  6757. streamController.cancelCall.reject(wrapReason(data.reason));
  6758. }
  6759. this._deleteStreamController(streamController, streamId);
  6760. break;
  6761. case StreamKind.CANCEL:
  6762. if (!streamSink) {
  6763. break;
  6764. }
  6765. new Promise(function (resolve) {
  6766. resolve(streamSink.onCancel && streamSink.onCancel(wrapReason(data.reason)));
  6767. }).then(function () {
  6768. comObj.postMessage({
  6769. sourceName,
  6770. targetName,
  6771. stream: StreamKind.CANCEL_COMPLETE,
  6772. streamId,
  6773. success: true
  6774. });
  6775. }, function (reason) {
  6776. comObj.postMessage({
  6777. sourceName,
  6778. targetName,
  6779. stream: StreamKind.CANCEL_COMPLETE,
  6780. streamId,
  6781. reason: wrapReason(reason)
  6782. });
  6783. });
  6784. streamSink.sinkCapability.reject(wrapReason(data.reason));
  6785. streamSink.isCancelled = true;
  6786. delete this.streamSinks[streamId];
  6787. break;
  6788. default:
  6789. throw new Error("Unexpected stream case");
  6790. }
  6791. }
  6792. async _deleteStreamController(streamController, streamId) {
  6793. await Promise.allSettled([streamController.startCall && streamController.startCall.promise, streamController.pullCall && streamController.pullCall.promise, streamController.cancelCall && streamController.cancelCall.promise]);
  6794. delete this.streamControllers[streamId];
  6795. }
  6796. destroy() {
  6797. this.comObj.removeEventListener("message", this._onComObjOnMessage);
  6798. }
  6799. }
  6800. exports.MessageHandler = MessageHandler;
  6801. /***/ }),
  6802. /* 14 */
  6803. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  6804. Object.defineProperty(exports, "__esModule", ({
  6805. value: true
  6806. }));
  6807. exports.Metadata = void 0;
  6808. var _util = __w_pdfjs_require__(1);
  6809. class Metadata {
  6810. #metadataMap;
  6811. #data;
  6812. constructor({
  6813. parsedData,
  6814. rawData
  6815. }) {
  6816. this.#metadataMap = parsedData;
  6817. this.#data = rawData;
  6818. }
  6819. getRaw() {
  6820. return this.#data;
  6821. }
  6822. get(name) {
  6823. return this.#metadataMap.get(name) ?? null;
  6824. }
  6825. getAll() {
  6826. return (0, _util.objectFromMap)(this.#metadataMap);
  6827. }
  6828. has(name) {
  6829. return this.#metadataMap.has(name);
  6830. }
  6831. }
  6832. exports.Metadata = Metadata;
  6833. /***/ }),
  6834. /* 15 */
  6835. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  6836. Object.defineProperty(exports, "__esModule", ({
  6837. value: true
  6838. }));
  6839. exports.OptionalContentConfig = void 0;
  6840. var _util = __w_pdfjs_require__(1);
  6841. class OptionalContentGroup {
  6842. constructor(name, intent) {
  6843. this.visible = true;
  6844. this.name = name;
  6845. this.intent = intent;
  6846. }
  6847. }
  6848. class OptionalContentConfig {
  6849. constructor(data) {
  6850. this.name = null;
  6851. this.creator = null;
  6852. this._order = null;
  6853. this._groups = new Map();
  6854. if (data === null) {
  6855. return;
  6856. }
  6857. this.name = data.name;
  6858. this.creator = data.creator;
  6859. this._order = data.order;
  6860. for (const group of data.groups) {
  6861. this._groups.set(group.id, new OptionalContentGroup(group.name, group.intent));
  6862. }
  6863. if (data.baseState === "OFF") {
  6864. for (const group of this._groups) {
  6865. group.visible = false;
  6866. }
  6867. }
  6868. for (const on of data.on) {
  6869. this._groups.get(on).visible = true;
  6870. }
  6871. for (const off of data.off) {
  6872. this._groups.get(off).visible = false;
  6873. }
  6874. }
  6875. _evaluateVisibilityExpression(array) {
  6876. const length = array.length;
  6877. if (length < 2) {
  6878. return true;
  6879. }
  6880. const operator = array[0];
  6881. for (let i = 1; i < length; i++) {
  6882. const element = array[i];
  6883. let state;
  6884. if (Array.isArray(element)) {
  6885. state = this._evaluateVisibilityExpression(element);
  6886. } else if (this._groups.has(element)) {
  6887. state = this._groups.get(element).visible;
  6888. } else {
  6889. (0, _util.warn)(`Optional content group not found: ${element}`);
  6890. return true;
  6891. }
  6892. switch (operator) {
  6893. case "And":
  6894. if (!state) {
  6895. return false;
  6896. }
  6897. break;
  6898. case "Or":
  6899. if (state) {
  6900. return true;
  6901. }
  6902. break;
  6903. case "Not":
  6904. return !state;
  6905. default:
  6906. return true;
  6907. }
  6908. }
  6909. return operator === "And";
  6910. }
  6911. isVisible(group) {
  6912. if (this._groups.size === 0) {
  6913. return true;
  6914. }
  6915. if (!group) {
  6916. (0, _util.warn)("Optional content group not defined.");
  6917. return true;
  6918. }
  6919. if (group.type === "OCG") {
  6920. if (!this._groups.has(group.id)) {
  6921. (0, _util.warn)(`Optional content group not found: ${group.id}`);
  6922. return true;
  6923. }
  6924. return this._groups.get(group.id).visible;
  6925. } else if (group.type === "OCMD") {
  6926. if (group.expression) {
  6927. return this._evaluateVisibilityExpression(group.expression);
  6928. }
  6929. if (!group.policy || group.policy === "AnyOn") {
  6930. for (const id of group.ids) {
  6931. if (!this._groups.has(id)) {
  6932. (0, _util.warn)(`Optional content group not found: ${id}`);
  6933. return true;
  6934. }
  6935. if (this._groups.get(id).visible) {
  6936. return true;
  6937. }
  6938. }
  6939. return false;
  6940. } else if (group.policy === "AllOn") {
  6941. for (const id of group.ids) {
  6942. if (!this._groups.has(id)) {
  6943. (0, _util.warn)(`Optional content group not found: ${id}`);
  6944. return true;
  6945. }
  6946. if (!this._groups.get(id).visible) {
  6947. return false;
  6948. }
  6949. }
  6950. return true;
  6951. } else if (group.policy === "AnyOff") {
  6952. for (const id of group.ids) {
  6953. if (!this._groups.has(id)) {
  6954. (0, _util.warn)(`Optional content group not found: ${id}`);
  6955. return true;
  6956. }
  6957. if (!this._groups.get(id).visible) {
  6958. return true;
  6959. }
  6960. }
  6961. return false;
  6962. } else if (group.policy === "AllOff") {
  6963. for (const id of group.ids) {
  6964. if (!this._groups.has(id)) {
  6965. (0, _util.warn)(`Optional content group not found: ${id}`);
  6966. return true;
  6967. }
  6968. if (this._groups.get(id).visible) {
  6969. return false;
  6970. }
  6971. }
  6972. return true;
  6973. }
  6974. (0, _util.warn)(`Unknown optional content policy ${group.policy}.`);
  6975. return true;
  6976. }
  6977. (0, _util.warn)(`Unknown group type ${group.type}.`);
  6978. return true;
  6979. }
  6980. setVisibility(id, visible = true) {
  6981. if (!this._groups.has(id)) {
  6982. (0, _util.warn)(`Optional content group not found: ${id}`);
  6983. return;
  6984. }
  6985. this._groups.get(id).visible = !!visible;
  6986. }
  6987. getOrder() {
  6988. if (!this._groups.size) {
  6989. return null;
  6990. }
  6991. if (this._order) {
  6992. return this._order.slice();
  6993. }
  6994. return Array.from(this._groups.keys());
  6995. }
  6996. getGroups() {
  6997. return this._groups.size > 0 ? (0, _util.objectFromMap)(this._groups) : null;
  6998. }
  6999. getGroup(id) {
  7000. return this._groups.get(id) || null;
  7001. }
  7002. }
  7003. exports.OptionalContentConfig = OptionalContentConfig;
  7004. /***/ }),
  7005. /* 16 */
  7006. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  7007. Object.defineProperty(exports, "__esModule", ({
  7008. value: true
  7009. }));
  7010. exports.PDFDataTransportStream = void 0;
  7011. var _util = __w_pdfjs_require__(1);
  7012. var _display_utils = __w_pdfjs_require__(5);
  7013. class PDFDataTransportStream {
  7014. constructor(params, pdfDataRangeTransport) {
  7015. (0, _util.assert)(pdfDataRangeTransport, 'PDFDataTransportStream - missing required "pdfDataRangeTransport" argument.');
  7016. this._queuedChunks = [];
  7017. this._progressiveDone = params.progressiveDone || false;
  7018. this._contentDispositionFilename = params.contentDispositionFilename || null;
  7019. const initialData = params.initialData;
  7020. if (initialData?.length > 0) {
  7021. const buffer = new Uint8Array(initialData).buffer;
  7022. this._queuedChunks.push(buffer);
  7023. }
  7024. this._pdfDataRangeTransport = pdfDataRangeTransport;
  7025. this._isStreamingSupported = !params.disableStream;
  7026. this._isRangeSupported = !params.disableRange;
  7027. this._contentLength = params.length;
  7028. this._fullRequestReader = null;
  7029. this._rangeReaders = [];
  7030. this._pdfDataRangeTransport.addRangeListener((begin, chunk) => {
  7031. this._onReceiveData({
  7032. begin,
  7033. chunk
  7034. });
  7035. });
  7036. this._pdfDataRangeTransport.addProgressListener((loaded, total) => {
  7037. this._onProgress({
  7038. loaded,
  7039. total
  7040. });
  7041. });
  7042. this._pdfDataRangeTransport.addProgressiveReadListener(chunk => {
  7043. this._onReceiveData({
  7044. chunk
  7045. });
  7046. });
  7047. this._pdfDataRangeTransport.addProgressiveDoneListener(() => {
  7048. this._onProgressiveDone();
  7049. });
  7050. this._pdfDataRangeTransport.transportReady();
  7051. }
  7052. _onReceiveData(args) {
  7053. const buffer = new Uint8Array(args.chunk).buffer;
  7054. if (args.begin === undefined) {
  7055. if (this._fullRequestReader) {
  7056. this._fullRequestReader._enqueue(buffer);
  7057. } else {
  7058. this._queuedChunks.push(buffer);
  7059. }
  7060. } else {
  7061. const found = this._rangeReaders.some(function (rangeReader) {
  7062. if (rangeReader._begin !== args.begin) {
  7063. return false;
  7064. }
  7065. rangeReader._enqueue(buffer);
  7066. return true;
  7067. });
  7068. (0, _util.assert)(found, "_onReceiveData - no `PDFDataTransportStreamRangeReader` instance found.");
  7069. }
  7070. }
  7071. get _progressiveDataLength() {
  7072. return this._fullRequestReader?._loaded ?? 0;
  7073. }
  7074. _onProgress(evt) {
  7075. if (evt.total === undefined) {
  7076. const firstReader = this._rangeReaders[0];
  7077. if (firstReader?.onProgress) {
  7078. firstReader.onProgress({
  7079. loaded: evt.loaded
  7080. });
  7081. }
  7082. } else {
  7083. const fullReader = this._fullRequestReader;
  7084. if (fullReader?.onProgress) {
  7085. fullReader.onProgress({
  7086. loaded: evt.loaded,
  7087. total: evt.total
  7088. });
  7089. }
  7090. }
  7091. }
  7092. _onProgressiveDone() {
  7093. if (this._fullRequestReader) {
  7094. this._fullRequestReader.progressiveDone();
  7095. }
  7096. this._progressiveDone = true;
  7097. }
  7098. _removeRangeReader(reader) {
  7099. const i = this._rangeReaders.indexOf(reader);
  7100. if (i >= 0) {
  7101. this._rangeReaders.splice(i, 1);
  7102. }
  7103. }
  7104. getFullReader() {
  7105. (0, _util.assert)(!this._fullRequestReader, "PDFDataTransportStream.getFullReader can only be called once.");
  7106. const queuedChunks = this._queuedChunks;
  7107. this._queuedChunks = null;
  7108. return new PDFDataTransportStreamReader(this, queuedChunks, this._progressiveDone, this._contentDispositionFilename);
  7109. }
  7110. getRangeReader(begin, end) {
  7111. if (end <= this._progressiveDataLength) {
  7112. return null;
  7113. }
  7114. const reader = new PDFDataTransportStreamRangeReader(this, begin, end);
  7115. this._pdfDataRangeTransport.requestDataRange(begin, end);
  7116. this._rangeReaders.push(reader);
  7117. return reader;
  7118. }
  7119. cancelAllRequests(reason) {
  7120. if (this._fullRequestReader) {
  7121. this._fullRequestReader.cancel(reason);
  7122. }
  7123. for (const reader of this._rangeReaders.slice(0)) {
  7124. reader.cancel(reason);
  7125. }
  7126. this._pdfDataRangeTransport.abort();
  7127. }
  7128. }
  7129. exports.PDFDataTransportStream = PDFDataTransportStream;
  7130. class PDFDataTransportStreamReader {
  7131. constructor(stream, queuedChunks, progressiveDone = false, contentDispositionFilename = null) {
  7132. this._stream = stream;
  7133. this._done = progressiveDone || false;
  7134. this._filename = (0, _display_utils.isPdfFile)(contentDispositionFilename) ? contentDispositionFilename : null;
  7135. this._queuedChunks = queuedChunks || [];
  7136. this._loaded = 0;
  7137. for (const chunk of this._queuedChunks) {
  7138. this._loaded += chunk.byteLength;
  7139. }
  7140. this._requests = [];
  7141. this._headersReady = Promise.resolve();
  7142. stream._fullRequestReader = this;
  7143. this.onProgress = null;
  7144. }
  7145. _enqueue(chunk) {
  7146. if (this._done) {
  7147. return;
  7148. }
  7149. if (this._requests.length > 0) {
  7150. const requestCapability = this._requests.shift();
  7151. requestCapability.resolve({
  7152. value: chunk,
  7153. done: false
  7154. });
  7155. } else {
  7156. this._queuedChunks.push(chunk);
  7157. }
  7158. this._loaded += chunk.byteLength;
  7159. }
  7160. get headersReady() {
  7161. return this._headersReady;
  7162. }
  7163. get filename() {
  7164. return this._filename;
  7165. }
  7166. get isRangeSupported() {
  7167. return this._stream._isRangeSupported;
  7168. }
  7169. get isStreamingSupported() {
  7170. return this._stream._isStreamingSupported;
  7171. }
  7172. get contentLength() {
  7173. return this._stream._contentLength;
  7174. }
  7175. async read() {
  7176. if (this._queuedChunks.length > 0) {
  7177. const chunk = this._queuedChunks.shift();
  7178. return {
  7179. value: chunk,
  7180. done: false
  7181. };
  7182. }
  7183. if (this._done) {
  7184. return {
  7185. value: undefined,
  7186. done: true
  7187. };
  7188. }
  7189. const requestCapability = (0, _util.createPromiseCapability)();
  7190. this._requests.push(requestCapability);
  7191. return requestCapability.promise;
  7192. }
  7193. cancel(reason) {
  7194. this._done = true;
  7195. for (const requestCapability of this._requests) {
  7196. requestCapability.resolve({
  7197. value: undefined,
  7198. done: true
  7199. });
  7200. }
  7201. this._requests.length = 0;
  7202. }
  7203. progressiveDone() {
  7204. if (this._done) {
  7205. return;
  7206. }
  7207. this._done = true;
  7208. }
  7209. }
  7210. class PDFDataTransportStreamRangeReader {
  7211. constructor(stream, begin, end) {
  7212. this._stream = stream;
  7213. this._begin = begin;
  7214. this._end = end;
  7215. this._queuedChunk = null;
  7216. this._requests = [];
  7217. this._done = false;
  7218. this.onProgress = null;
  7219. }
  7220. _enqueue(chunk) {
  7221. if (this._done) {
  7222. return;
  7223. }
  7224. if (this._requests.length === 0) {
  7225. this._queuedChunk = chunk;
  7226. } else {
  7227. const requestsCapability = this._requests.shift();
  7228. requestsCapability.resolve({
  7229. value: chunk,
  7230. done: false
  7231. });
  7232. for (const requestCapability of this._requests) {
  7233. requestCapability.resolve({
  7234. value: undefined,
  7235. done: true
  7236. });
  7237. }
  7238. this._requests.length = 0;
  7239. }
  7240. this._done = true;
  7241. this._stream._removeRangeReader(this);
  7242. }
  7243. get isStreamingSupported() {
  7244. return false;
  7245. }
  7246. async read() {
  7247. if (this._queuedChunk) {
  7248. const chunk = this._queuedChunk;
  7249. this._queuedChunk = null;
  7250. return {
  7251. value: chunk,
  7252. done: false
  7253. };
  7254. }
  7255. if (this._done) {
  7256. return {
  7257. value: undefined,
  7258. done: true
  7259. };
  7260. }
  7261. const requestCapability = (0, _util.createPromiseCapability)();
  7262. this._requests.push(requestCapability);
  7263. return requestCapability.promise;
  7264. }
  7265. cancel(reason) {
  7266. this._done = true;
  7267. for (const requestCapability of this._requests) {
  7268. requestCapability.resolve({
  7269. value: undefined,
  7270. done: true
  7271. });
  7272. }
  7273. this._requests.length = 0;
  7274. this._stream._removeRangeReader(this);
  7275. }
  7276. }
  7277. /***/ }),
  7278. /* 17 */
  7279. /***/ ((__unused_webpack_module, exports) => {
  7280. Object.defineProperty(exports, "__esModule", ({
  7281. value: true
  7282. }));
  7283. exports.XfaText = void 0;
  7284. class XfaText {
  7285. static textContent(xfa) {
  7286. const items = [];
  7287. const output = {
  7288. items,
  7289. styles: Object.create(null)
  7290. };
  7291. function walk(node) {
  7292. if (!node) {
  7293. return;
  7294. }
  7295. let str = null;
  7296. const name = node.name;
  7297. if (name === "#text") {
  7298. str = node.value;
  7299. } else if (!XfaText.shouldBuildText(name)) {
  7300. return;
  7301. } else if (node?.attributes?.textContent) {
  7302. str = node.attributes.textContent;
  7303. } else if (node.value) {
  7304. str = node.value;
  7305. }
  7306. if (str !== null) {
  7307. items.push({
  7308. str
  7309. });
  7310. }
  7311. if (!node.children) {
  7312. return;
  7313. }
  7314. for (const child of node.children) {
  7315. walk(child);
  7316. }
  7317. }
  7318. walk(xfa);
  7319. return output;
  7320. }
  7321. static shouldBuildText(name) {
  7322. return !(name === "textarea" || name === "input" || name === "option" || name === "select");
  7323. }
  7324. }
  7325. exports.XfaText = XfaText;
  7326. /***/ }),
  7327. /* 18 */
  7328. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  7329. Object.defineProperty(exports, "__esModule", ({
  7330. value: true
  7331. }));
  7332. exports.AnnotationLayer = void 0;
  7333. var _util = __w_pdfjs_require__(1);
  7334. var _display_utils = __w_pdfjs_require__(5);
  7335. var _annotation_storage = __w_pdfjs_require__(9);
  7336. var _scripting_utils = __w_pdfjs_require__(19);
  7337. var _xfa_layer = __w_pdfjs_require__(20);
  7338. const DEFAULT_TAB_INDEX = 1000;
  7339. const GetElementsByNameSet = new WeakSet();
  7340. function getRectDims(rect) {
  7341. return {
  7342. width: rect[2] - rect[0],
  7343. height: rect[3] - rect[1]
  7344. };
  7345. }
  7346. class AnnotationElementFactory {
  7347. static create(parameters) {
  7348. const subtype = parameters.data.annotationType;
  7349. switch (subtype) {
  7350. case _util.AnnotationType.LINK:
  7351. return new LinkAnnotationElement(parameters);
  7352. case _util.AnnotationType.TEXT:
  7353. return new TextAnnotationElement(parameters);
  7354. case _util.AnnotationType.WIDGET:
  7355. const fieldType = parameters.data.fieldType;
  7356. switch (fieldType) {
  7357. case "Tx":
  7358. return new TextWidgetAnnotationElement(parameters);
  7359. case "Btn":
  7360. if (parameters.data.radioButton) {
  7361. return new RadioButtonWidgetAnnotationElement(parameters);
  7362. } else if (parameters.data.checkBox) {
  7363. return new CheckboxWidgetAnnotationElement(parameters);
  7364. }
  7365. return new PushButtonWidgetAnnotationElement(parameters);
  7366. case "Ch":
  7367. return new ChoiceWidgetAnnotationElement(parameters);
  7368. }
  7369. return new WidgetAnnotationElement(parameters);
  7370. case _util.AnnotationType.POPUP:
  7371. return new PopupAnnotationElement(parameters);
  7372. case _util.AnnotationType.FREETEXT:
  7373. return new FreeTextAnnotationElement(parameters);
  7374. case _util.AnnotationType.LINE:
  7375. return new LineAnnotationElement(parameters);
  7376. case _util.AnnotationType.SQUARE:
  7377. return new SquareAnnotationElement(parameters);
  7378. case _util.AnnotationType.CIRCLE:
  7379. return new CircleAnnotationElement(parameters);
  7380. case _util.AnnotationType.POLYLINE:
  7381. return new PolylineAnnotationElement(parameters);
  7382. case _util.AnnotationType.CARET:
  7383. return new CaretAnnotationElement(parameters);
  7384. case _util.AnnotationType.INK:
  7385. return new InkAnnotationElement(parameters);
  7386. case _util.AnnotationType.POLYGON:
  7387. return new PolygonAnnotationElement(parameters);
  7388. case _util.AnnotationType.HIGHLIGHT:
  7389. return new HighlightAnnotationElement(parameters);
  7390. case _util.AnnotationType.UNDERLINE:
  7391. return new UnderlineAnnotationElement(parameters);
  7392. case _util.AnnotationType.SQUIGGLY:
  7393. return new SquigglyAnnotationElement(parameters);
  7394. case _util.AnnotationType.STRIKEOUT:
  7395. return new StrikeOutAnnotationElement(parameters);
  7396. case _util.AnnotationType.STAMP:
  7397. return new StampAnnotationElement(parameters);
  7398. case _util.AnnotationType.FILEATTACHMENT:
  7399. return new FileAttachmentAnnotationElement(parameters);
  7400. default:
  7401. return new AnnotationElement(parameters);
  7402. }
  7403. }
  7404. }
  7405. class AnnotationElement {
  7406. constructor(parameters, {
  7407. isRenderable = false,
  7408. ignoreBorder = false,
  7409. createQuadrilaterals = false
  7410. } = {}) {
  7411. this.isRenderable = isRenderable;
  7412. this.data = parameters.data;
  7413. this.layer = parameters.layer;
  7414. this.page = parameters.page;
  7415. this.viewport = parameters.viewport;
  7416. this.linkService = parameters.linkService;
  7417. this.downloadManager = parameters.downloadManager;
  7418. this.imageResourcesPath = parameters.imageResourcesPath;
  7419. this.renderForms = parameters.renderForms;
  7420. this.svgFactory = parameters.svgFactory;
  7421. this.annotationStorage = parameters.annotationStorage;
  7422. this.enableScripting = parameters.enableScripting;
  7423. this.hasJSActions = parameters.hasJSActions;
  7424. this._fieldObjects = parameters.fieldObjects;
  7425. this._mouseState = parameters.mouseState;
  7426. if (isRenderable) {
  7427. this.container = this._createContainer(ignoreBorder);
  7428. }
  7429. if (createQuadrilaterals) {
  7430. this.quadrilaterals = this._createQuadrilaterals(ignoreBorder);
  7431. }
  7432. }
  7433. _createContainer(ignoreBorder = false) {
  7434. const data = this.data,
  7435. page = this.page,
  7436. viewport = this.viewport;
  7437. const container = document.createElement("section");
  7438. let {
  7439. width,
  7440. height
  7441. } = getRectDims(data.rect);
  7442. container.setAttribute("data-annotation-id", data.id);
  7443. 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]]);
  7444. if (data.hasOwnCanvas) {
  7445. const transform = viewport.transform.slice();
  7446. const [scaleX, scaleY] = _util.Util.singularValueDecompose2dScale(transform);
  7447. width = Math.ceil(width * scaleX);
  7448. height = Math.ceil(height * scaleY);
  7449. rect[0] *= scaleX;
  7450. rect[1] *= scaleY;
  7451. for (let i = 0; i < 4; i++) {
  7452. transform[i] = Math.sign(transform[i]);
  7453. }
  7454. container.style.transform = `matrix(${transform.join(",")})`;
  7455. } else {
  7456. container.style.transform = `matrix(${viewport.transform.join(",")})`;
  7457. }
  7458. container.style.transformOrigin = `${-rect[0]}px ${-rect[1]}px`;
  7459. if (!ignoreBorder && data.borderStyle.width > 0) {
  7460. container.style.borderWidth = `${data.borderStyle.width}px`;
  7461. if (data.borderStyle.style !== _util.AnnotationBorderStyleType.UNDERLINE) {
  7462. width -= 2 * data.borderStyle.width;
  7463. height -= 2 * data.borderStyle.width;
  7464. }
  7465. const horizontalRadius = data.borderStyle.horizontalCornerRadius;
  7466. const verticalRadius = data.borderStyle.verticalCornerRadius;
  7467. if (horizontalRadius > 0 || verticalRadius > 0) {
  7468. const radius = `${horizontalRadius}px / ${verticalRadius}px`;
  7469. container.style.borderRadius = radius;
  7470. }
  7471. switch (data.borderStyle.style) {
  7472. case _util.AnnotationBorderStyleType.SOLID:
  7473. container.style.borderStyle = "solid";
  7474. break;
  7475. case _util.AnnotationBorderStyleType.DASHED:
  7476. container.style.borderStyle = "dashed";
  7477. break;
  7478. case _util.AnnotationBorderStyleType.BEVELED:
  7479. (0, _util.warn)("Unimplemented border style: beveled");
  7480. break;
  7481. case _util.AnnotationBorderStyleType.INSET:
  7482. (0, _util.warn)("Unimplemented border style: inset");
  7483. break;
  7484. case _util.AnnotationBorderStyleType.UNDERLINE:
  7485. container.style.borderBottomStyle = "solid";
  7486. break;
  7487. default:
  7488. break;
  7489. }
  7490. const borderColor = data.borderColor || data.color || null;
  7491. if (borderColor) {
  7492. container.style.borderColor = _util.Util.makeHexColor(data.color[0] | 0, data.color[1] | 0, data.color[2] | 0);
  7493. } else {
  7494. container.style.borderWidth = 0;
  7495. }
  7496. }
  7497. container.style.left = `${rect[0]}px`;
  7498. container.style.top = `${rect[1]}px`;
  7499. if (data.hasOwnCanvas) {
  7500. container.style.width = container.style.height = "auto";
  7501. } else {
  7502. container.style.width = `${width}px`;
  7503. container.style.height = `${height}px`;
  7504. }
  7505. return container;
  7506. }
  7507. _createQuadrilaterals(ignoreBorder = false) {
  7508. if (!this.data.quadPoints) {
  7509. return null;
  7510. }
  7511. const quadrilaterals = [];
  7512. const savedRect = this.data.rect;
  7513. for (const quadPoint of this.data.quadPoints) {
  7514. this.data.rect = [quadPoint[2].x, quadPoint[2].y, quadPoint[1].x, quadPoint[1].y];
  7515. quadrilaterals.push(this._createContainer(ignoreBorder));
  7516. }
  7517. this.data.rect = savedRect;
  7518. return quadrilaterals;
  7519. }
  7520. _createPopup(trigger, data) {
  7521. let container = this.container;
  7522. if (this.quadrilaterals) {
  7523. trigger = trigger || this.quadrilaterals;
  7524. container = this.quadrilaterals[0];
  7525. }
  7526. if (!trigger) {
  7527. trigger = document.createElement("div");
  7528. trigger.style.height = container.style.height;
  7529. trigger.style.width = container.style.width;
  7530. container.appendChild(trigger);
  7531. }
  7532. const popupElement = new PopupElement({
  7533. container,
  7534. trigger,
  7535. color: data.color,
  7536. titleObj: data.titleObj,
  7537. modificationDate: data.modificationDate,
  7538. contentsObj: data.contentsObj,
  7539. richText: data.richText,
  7540. hideWrapper: true
  7541. });
  7542. const popup = popupElement.render();
  7543. popup.style.left = container.style.width;
  7544. container.appendChild(popup);
  7545. }
  7546. _renderQuadrilaterals(className) {
  7547. for (const quadrilateral of this.quadrilaterals) {
  7548. quadrilateral.className = className;
  7549. }
  7550. return this.quadrilaterals;
  7551. }
  7552. render() {
  7553. (0, _util.unreachable)("Abstract method `AnnotationElement.render` called");
  7554. }
  7555. _getElementsByName(name, skipId = null) {
  7556. const fields = [];
  7557. if (this._fieldObjects) {
  7558. const fieldObj = this._fieldObjects[name];
  7559. if (fieldObj) {
  7560. for (const {
  7561. page,
  7562. id,
  7563. exportValues
  7564. } of fieldObj) {
  7565. if (page === -1) {
  7566. continue;
  7567. }
  7568. if (id === skipId) {
  7569. continue;
  7570. }
  7571. const exportValue = typeof exportValues === "string" ? exportValues : null;
  7572. const domElement = document.getElementById(id);
  7573. if (domElement && !GetElementsByNameSet.has(domElement)) {
  7574. (0, _util.warn)(`_getElementsByName - element not allowed: ${id}`);
  7575. continue;
  7576. }
  7577. fields.push({
  7578. id,
  7579. exportValue,
  7580. domElement
  7581. });
  7582. }
  7583. }
  7584. return fields;
  7585. }
  7586. for (const domElement of document.getElementsByName(name)) {
  7587. const {
  7588. id,
  7589. exportValue
  7590. } = domElement;
  7591. if (id === skipId) {
  7592. continue;
  7593. }
  7594. if (!GetElementsByNameSet.has(domElement)) {
  7595. continue;
  7596. }
  7597. fields.push({
  7598. id,
  7599. exportValue,
  7600. domElement
  7601. });
  7602. }
  7603. return fields;
  7604. }
  7605. static get platform() {
  7606. const platform = typeof navigator !== "undefined" ? navigator.platform : "";
  7607. return (0, _util.shadow)(this, "platform", {
  7608. isWin: platform.includes("Win"),
  7609. isMac: platform.includes("Mac")
  7610. });
  7611. }
  7612. }
  7613. class LinkAnnotationElement extends AnnotationElement {
  7614. constructor(parameters, options = null) {
  7615. 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"]));
  7616. super(parameters, {
  7617. isRenderable,
  7618. ignoreBorder: !!options?.ignoreBorder,
  7619. createQuadrilaterals: true
  7620. });
  7621. }
  7622. render() {
  7623. const {
  7624. data,
  7625. linkService
  7626. } = this;
  7627. const link = document.createElement("a");
  7628. if (data.url) {
  7629. if (!linkService.addLinkAttributes) {
  7630. (0, _util.warn)("LinkAnnotationElement.render - missing `addLinkAttributes`-method on the `linkService`-instance.");
  7631. }
  7632. linkService.addLinkAttributes?.(link, data.url, data.newWindow);
  7633. } else if (data.action) {
  7634. this._bindNamedAction(link, data.action);
  7635. } else if (data.dest) {
  7636. this._bindLink(link, data.dest);
  7637. } else {
  7638. let hasClickAction = false;
  7639. if (data.actions && (data.actions.Action || data.actions["Mouse Up"] || data.actions["Mouse Down"]) && this.enableScripting && this.hasJSActions) {
  7640. hasClickAction = true;
  7641. this._bindJSAction(link, data);
  7642. }
  7643. if (data.resetForm) {
  7644. this._bindResetFormAction(link, data.resetForm);
  7645. } else if (!hasClickAction) {
  7646. this._bindLink(link, "");
  7647. }
  7648. }
  7649. if (this.quadrilaterals) {
  7650. return this._renderQuadrilaterals("linkAnnotation").map((quadrilateral, index) => {
  7651. const linkElement = index === 0 ? link : link.cloneNode();
  7652. quadrilateral.appendChild(linkElement);
  7653. return quadrilateral;
  7654. });
  7655. }
  7656. this.container.className = "linkAnnotation";
  7657. this.container.appendChild(link);
  7658. return this.container;
  7659. }
  7660. _bindLink(link, destination) {
  7661. link.href = this.linkService.getDestinationHash(destination);
  7662. link.onclick = () => {
  7663. if (destination) {
  7664. this.linkService.goToDestination(destination);
  7665. }
  7666. return false;
  7667. };
  7668. if (destination || destination === "") {
  7669. link.className = "internalLink";
  7670. }
  7671. }
  7672. _bindNamedAction(link, action) {
  7673. link.href = this.linkService.getAnchorUrl("");
  7674. link.onclick = () => {
  7675. this.linkService.executeNamedAction(action);
  7676. return false;
  7677. };
  7678. link.className = "internalLink";
  7679. }
  7680. _bindJSAction(link, data) {
  7681. link.href = this.linkService.getAnchorUrl("");
  7682. const map = new Map([["Action", "onclick"], ["Mouse Up", "onmouseup"], ["Mouse Down", "onmousedown"]]);
  7683. for (const name of Object.keys(data.actions)) {
  7684. const jsName = map.get(name);
  7685. if (!jsName) {
  7686. continue;
  7687. }
  7688. link[jsName] = () => {
  7689. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  7690. source: this,
  7691. detail: {
  7692. id: data.id,
  7693. name
  7694. }
  7695. });
  7696. return false;
  7697. };
  7698. }
  7699. if (!link.onclick) {
  7700. link.onclick = () => false;
  7701. }
  7702. link.className = "internalLink";
  7703. }
  7704. _bindResetFormAction(link, resetForm) {
  7705. const otherClickAction = link.onclick;
  7706. if (!otherClickAction) {
  7707. link.href = this.linkService.getAnchorUrl("");
  7708. }
  7709. link.className = "internalLink";
  7710. if (!this._fieldObjects) {
  7711. (0, _util.warn)(`_bindResetFormAction - "resetForm" action not supported, ` + "ensure that the `fieldObjects` parameter is provided.");
  7712. if (!otherClickAction) {
  7713. link.onclick = () => false;
  7714. }
  7715. return;
  7716. }
  7717. link.onclick = () => {
  7718. if (otherClickAction) {
  7719. otherClickAction();
  7720. }
  7721. const {
  7722. fields: resetFormFields,
  7723. refs: resetFormRefs,
  7724. include
  7725. } = resetForm;
  7726. const allFields = [];
  7727. if (resetFormFields.length !== 0 || resetFormRefs.length !== 0) {
  7728. const fieldIds = new Set(resetFormRefs);
  7729. for (const fieldName of resetFormFields) {
  7730. const fields = this._fieldObjects[fieldName] || [];
  7731. for (const {
  7732. id
  7733. } of fields) {
  7734. fieldIds.add(id);
  7735. }
  7736. }
  7737. for (const fields of Object.values(this._fieldObjects)) {
  7738. for (const field of fields) {
  7739. if (fieldIds.has(field.id) === include) {
  7740. allFields.push(field);
  7741. }
  7742. }
  7743. }
  7744. } else {
  7745. for (const fields of Object.values(this._fieldObjects)) {
  7746. allFields.push(...fields);
  7747. }
  7748. }
  7749. const storage = this.annotationStorage;
  7750. const allIds = [];
  7751. for (const field of allFields) {
  7752. const {
  7753. id
  7754. } = field;
  7755. allIds.push(id);
  7756. switch (field.type) {
  7757. case "text":
  7758. {
  7759. const value = field.defaultValue || "";
  7760. storage.setValue(id, {
  7761. value,
  7762. valueAsString: value
  7763. });
  7764. break;
  7765. }
  7766. case "checkbox":
  7767. case "radiobutton":
  7768. {
  7769. const value = field.defaultValue === field.exportValues;
  7770. storage.setValue(id, {
  7771. value
  7772. });
  7773. break;
  7774. }
  7775. case "combobox":
  7776. case "listbox":
  7777. {
  7778. const value = field.defaultValue || "";
  7779. storage.setValue(id, {
  7780. value
  7781. });
  7782. break;
  7783. }
  7784. default:
  7785. continue;
  7786. }
  7787. const domElement = document.getElementById(id);
  7788. if (!domElement || !GetElementsByNameSet.has(domElement)) {
  7789. continue;
  7790. }
  7791. domElement.dispatchEvent(new Event("resetform"));
  7792. }
  7793. if (this.enableScripting) {
  7794. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  7795. source: this,
  7796. detail: {
  7797. id: "app",
  7798. ids: allIds,
  7799. name: "ResetForm"
  7800. }
  7801. });
  7802. }
  7803. return false;
  7804. };
  7805. }
  7806. }
  7807. class TextAnnotationElement extends AnnotationElement {
  7808. constructor(parameters) {
  7809. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  7810. super(parameters, {
  7811. isRenderable
  7812. });
  7813. }
  7814. render() {
  7815. this.container.className = "textAnnotation";
  7816. const image = document.createElement("img");
  7817. image.style.height = this.container.style.height;
  7818. image.style.width = this.container.style.width;
  7819. image.src = this.imageResourcesPath + "annotation-" + this.data.name.toLowerCase() + ".svg";
  7820. image.alt = "[{{type}} Annotation]";
  7821. image.dataset.l10nId = "text_annotation_type";
  7822. image.dataset.l10nArgs = JSON.stringify({
  7823. type: this.data.name
  7824. });
  7825. if (!this.data.hasPopup) {
  7826. this._createPopup(image, this.data);
  7827. }
  7828. this.container.appendChild(image);
  7829. return this.container;
  7830. }
  7831. }
  7832. class WidgetAnnotationElement extends AnnotationElement {
  7833. render() {
  7834. if (this.data.alternativeText) {
  7835. this.container.title = this.data.alternativeText;
  7836. }
  7837. return this.container;
  7838. }
  7839. _getKeyModifier(event) {
  7840. const {
  7841. isWin,
  7842. isMac
  7843. } = AnnotationElement.platform;
  7844. return isWin && event.ctrlKey || isMac && event.metaKey;
  7845. }
  7846. _setEventListener(element, baseName, eventName, valueGetter) {
  7847. if (baseName.includes("mouse")) {
  7848. element.addEventListener(baseName, event => {
  7849. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  7850. source: this,
  7851. detail: {
  7852. id: this.data.id,
  7853. name: eventName,
  7854. value: valueGetter(event),
  7855. shift: event.shiftKey,
  7856. modifier: this._getKeyModifier(event)
  7857. }
  7858. });
  7859. });
  7860. } else {
  7861. element.addEventListener(baseName, event => {
  7862. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  7863. source: this,
  7864. detail: {
  7865. id: this.data.id,
  7866. name: eventName,
  7867. value: valueGetter(event)
  7868. }
  7869. });
  7870. });
  7871. }
  7872. }
  7873. _setEventListeners(element, names, getter) {
  7874. for (const [baseName, eventName] of names) {
  7875. if (eventName === "Action" || this.data.actions?.[eventName]) {
  7876. this._setEventListener(element, baseName, eventName, getter);
  7877. }
  7878. }
  7879. }
  7880. _setBackgroundColor(element) {
  7881. const color = this.data.backgroundColor || null;
  7882. element.style.backgroundColor = color === null ? "transparent" : _util.Util.makeHexColor(color[0], color[1], color[2]);
  7883. }
  7884. _dispatchEventFromSandbox(actions, jsEvent) {
  7885. const setColor = (jsName, styleName, event) => {
  7886. const color = event.detail[jsName];
  7887. event.target.style[styleName] = _scripting_utils.ColorConverters[`${color[0]}_HTML`](color.slice(1));
  7888. };
  7889. const commonActions = {
  7890. display: event => {
  7891. const hidden = event.detail.display % 2 === 1;
  7892. event.target.style.visibility = hidden ? "hidden" : "visible";
  7893. this.annotationStorage.setValue(this.data.id, {
  7894. hidden,
  7895. print: event.detail.display === 0 || event.detail.display === 3
  7896. });
  7897. },
  7898. print: event => {
  7899. this.annotationStorage.setValue(this.data.id, {
  7900. print: event.detail.print
  7901. });
  7902. },
  7903. hidden: event => {
  7904. event.target.style.visibility = event.detail.hidden ? "hidden" : "visible";
  7905. this.annotationStorage.setValue(this.data.id, {
  7906. hidden: event.detail.hidden
  7907. });
  7908. },
  7909. focus: event => {
  7910. setTimeout(() => event.target.focus({
  7911. preventScroll: false
  7912. }), 0);
  7913. },
  7914. userName: event => {
  7915. event.target.title = event.detail.userName;
  7916. },
  7917. readonly: event => {
  7918. if (event.detail.readonly) {
  7919. event.target.setAttribute("readonly", "");
  7920. } else {
  7921. event.target.removeAttribute("readonly");
  7922. }
  7923. },
  7924. required: event => {
  7925. if (event.detail.required) {
  7926. event.target.setAttribute("required", "");
  7927. } else {
  7928. event.target.removeAttribute("required");
  7929. }
  7930. },
  7931. bgColor: event => {
  7932. setColor("bgColor", "backgroundColor", event);
  7933. },
  7934. fillColor: event => {
  7935. setColor("fillColor", "backgroundColor", event);
  7936. },
  7937. fgColor: event => {
  7938. setColor("fgColor", "color", event);
  7939. },
  7940. textColor: event => {
  7941. setColor("textColor", "color", event);
  7942. },
  7943. borderColor: event => {
  7944. setColor("borderColor", "borderColor", event);
  7945. },
  7946. strokeColor: event => {
  7947. setColor("strokeColor", "borderColor", event);
  7948. }
  7949. };
  7950. for (const name of Object.keys(jsEvent.detail)) {
  7951. const action = actions[name] || commonActions[name];
  7952. if (action) {
  7953. action(jsEvent);
  7954. }
  7955. }
  7956. }
  7957. }
  7958. class TextWidgetAnnotationElement extends WidgetAnnotationElement {
  7959. constructor(parameters) {
  7960. const isRenderable = parameters.renderForms || !parameters.data.hasAppearance && !!parameters.data.fieldValue;
  7961. super(parameters, {
  7962. isRenderable
  7963. });
  7964. }
  7965. setPropertyOnSiblings(base, key, value, keyInStorage) {
  7966. const storage = this.annotationStorage;
  7967. for (const element of this._getElementsByName(base.name, base.id)) {
  7968. if (element.domElement) {
  7969. element.domElement[key] = value;
  7970. }
  7971. storage.setValue(element.id, {
  7972. [keyInStorage]: value
  7973. });
  7974. }
  7975. }
  7976. render() {
  7977. const storage = this.annotationStorage;
  7978. const id = this.data.id;
  7979. this.container.className = "textWidgetAnnotation";
  7980. let element = null;
  7981. if (this.renderForms) {
  7982. const storedData = storage.getValue(id, {
  7983. value: this.data.fieldValue,
  7984. valueAsString: this.data.fieldValue
  7985. });
  7986. const textContent = storedData.valueAsString || storedData.value || "";
  7987. const elementData = {
  7988. userValue: null,
  7989. formattedValue: null
  7990. };
  7991. if (this.data.multiLine) {
  7992. element = document.createElement("textarea");
  7993. element.textContent = textContent;
  7994. } else {
  7995. element = document.createElement("input");
  7996. element.type = "text";
  7997. element.setAttribute("value", textContent);
  7998. }
  7999. GetElementsByNameSet.add(element);
  8000. element.disabled = this.data.readOnly;
  8001. element.name = this.data.fieldName;
  8002. element.tabIndex = DEFAULT_TAB_INDEX;
  8003. elementData.userValue = textContent;
  8004. element.setAttribute("id", id);
  8005. element.addEventListener("input", event => {
  8006. storage.setValue(id, {
  8007. value: event.target.value
  8008. });
  8009. this.setPropertyOnSiblings(element, "value", event.target.value, "value");
  8010. });
  8011. element.addEventListener("resetform", event => {
  8012. const defaultValue = this.data.defaultFieldValue || "";
  8013. element.value = elementData.userValue = defaultValue;
  8014. delete elementData.formattedValue;
  8015. });
  8016. let blurListener = event => {
  8017. if (elementData.formattedValue) {
  8018. event.target.value = elementData.formattedValue;
  8019. }
  8020. event.target.scrollLeft = 0;
  8021. };
  8022. if (this.enableScripting && this.hasJSActions) {
  8023. element.addEventListener("focus", event => {
  8024. if (elementData.userValue) {
  8025. event.target.value = elementData.userValue;
  8026. }
  8027. });
  8028. element.addEventListener("updatefromsandbox", jsEvent => {
  8029. const actions = {
  8030. value(event) {
  8031. elementData.userValue = event.detail.value || "";
  8032. storage.setValue(id, {
  8033. value: elementData.userValue.toString()
  8034. });
  8035. if (!elementData.formattedValue) {
  8036. event.target.value = elementData.userValue;
  8037. }
  8038. },
  8039. valueAsString(event) {
  8040. elementData.formattedValue = event.detail.valueAsString || "";
  8041. if (event.target !== document.activeElement) {
  8042. event.target.value = elementData.formattedValue;
  8043. }
  8044. storage.setValue(id, {
  8045. formattedValue: elementData.formattedValue
  8046. });
  8047. },
  8048. selRange(event) {
  8049. const [selStart, selEnd] = event.detail.selRange;
  8050. if (selStart >= 0 && selEnd < event.target.value.length) {
  8051. event.target.setSelectionRange(selStart, selEnd);
  8052. }
  8053. }
  8054. };
  8055. this._dispatchEventFromSandbox(actions, jsEvent);
  8056. });
  8057. element.addEventListener("keydown", event => {
  8058. let commitKey = -1;
  8059. if (event.key === "Escape") {
  8060. commitKey = 0;
  8061. } else if (event.key === "Enter") {
  8062. commitKey = 2;
  8063. } else if (event.key === "Tab") {
  8064. commitKey = 3;
  8065. }
  8066. if (commitKey === -1) {
  8067. return;
  8068. }
  8069. elementData.userValue = event.target.value;
  8070. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  8071. source: this,
  8072. detail: {
  8073. id,
  8074. name: "Keystroke",
  8075. value: event.target.value,
  8076. willCommit: true,
  8077. commitKey,
  8078. selStart: event.target.selectionStart,
  8079. selEnd: event.target.selectionEnd
  8080. }
  8081. });
  8082. });
  8083. const _blurListener = blurListener;
  8084. blurListener = null;
  8085. element.addEventListener("blur", event => {
  8086. elementData.userValue = event.target.value;
  8087. if (this._mouseState.isDown) {
  8088. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  8089. source: this,
  8090. detail: {
  8091. id,
  8092. name: "Keystroke",
  8093. value: event.target.value,
  8094. willCommit: true,
  8095. commitKey: 1,
  8096. selStart: event.target.selectionStart,
  8097. selEnd: event.target.selectionEnd
  8098. }
  8099. });
  8100. }
  8101. _blurListener(event);
  8102. });
  8103. if (this.data.actions?.Keystroke) {
  8104. element.addEventListener("beforeinput", event => {
  8105. elementData.formattedValue = "";
  8106. const {
  8107. data,
  8108. target
  8109. } = event;
  8110. const {
  8111. value,
  8112. selectionStart,
  8113. selectionEnd
  8114. } = target;
  8115. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  8116. source: this,
  8117. detail: {
  8118. id,
  8119. name: "Keystroke",
  8120. value,
  8121. change: data,
  8122. willCommit: false,
  8123. selStart: selectionStart,
  8124. selEnd: selectionEnd
  8125. }
  8126. });
  8127. });
  8128. }
  8129. this._setEventListeners(element, [["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"]], event => event.target.value);
  8130. }
  8131. if (blurListener) {
  8132. element.addEventListener("blur", blurListener);
  8133. }
  8134. if (this.data.maxLen !== null) {
  8135. element.maxLength = this.data.maxLen;
  8136. }
  8137. if (this.data.comb) {
  8138. const fieldWidth = this.data.rect[2] - this.data.rect[0];
  8139. const combWidth = fieldWidth / this.data.maxLen;
  8140. element.classList.add("comb");
  8141. element.style.letterSpacing = `calc(${combWidth}px - 1ch)`;
  8142. }
  8143. } else {
  8144. element = document.createElement("div");
  8145. element.textContent = this.data.fieldValue;
  8146. element.style.verticalAlign = "middle";
  8147. element.style.display = "table-cell";
  8148. }
  8149. this._setTextStyle(element);
  8150. this._setBackgroundColor(element);
  8151. this.container.appendChild(element);
  8152. return this.container;
  8153. }
  8154. _setTextStyle(element) {
  8155. const TEXT_ALIGNMENT = ["left", "center", "right"];
  8156. const {
  8157. fontSize,
  8158. fontColor
  8159. } = this.data.defaultAppearanceData;
  8160. const style = element.style;
  8161. if (fontSize) {
  8162. style.fontSize = `${fontSize}px`;
  8163. }
  8164. style.color = _util.Util.makeHexColor(fontColor[0], fontColor[1], fontColor[2]);
  8165. if (this.data.textAlignment !== null) {
  8166. style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
  8167. }
  8168. }
  8169. }
  8170. class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement {
  8171. constructor(parameters) {
  8172. super(parameters, {
  8173. isRenderable: parameters.renderForms
  8174. });
  8175. }
  8176. render() {
  8177. const storage = this.annotationStorage;
  8178. const data = this.data;
  8179. const id = data.id;
  8180. let value = storage.getValue(id, {
  8181. value: data.exportValue === data.fieldValue
  8182. }).value;
  8183. if (typeof value === "string") {
  8184. value = value !== "Off";
  8185. storage.setValue(id, {
  8186. value
  8187. });
  8188. }
  8189. this.container.className = "buttonWidgetAnnotation checkBox";
  8190. const element = document.createElement("input");
  8191. GetElementsByNameSet.add(element);
  8192. element.disabled = data.readOnly;
  8193. element.type = "checkbox";
  8194. element.name = data.fieldName;
  8195. if (value) {
  8196. element.setAttribute("checked", true);
  8197. }
  8198. element.setAttribute("id", id);
  8199. element.setAttribute("exportValue", data.exportValue);
  8200. element.tabIndex = DEFAULT_TAB_INDEX;
  8201. element.addEventListener("change", event => {
  8202. const {
  8203. name,
  8204. checked
  8205. } = event.target;
  8206. for (const checkbox of this._getElementsByName(name, id)) {
  8207. const curChecked = checked && checkbox.exportValue === data.exportValue;
  8208. if (checkbox.domElement) {
  8209. checkbox.domElement.checked = curChecked;
  8210. }
  8211. storage.setValue(checkbox.id, {
  8212. value: curChecked
  8213. });
  8214. }
  8215. storage.setValue(id, {
  8216. value: checked
  8217. });
  8218. });
  8219. element.addEventListener("resetform", event => {
  8220. const defaultValue = data.defaultFieldValue || "Off";
  8221. event.target.checked = defaultValue === data.exportValue;
  8222. });
  8223. if (this.enableScripting && this.hasJSActions) {
  8224. element.addEventListener("updatefromsandbox", jsEvent => {
  8225. const actions = {
  8226. value(event) {
  8227. event.target.checked = event.detail.value !== "Off";
  8228. storage.setValue(id, {
  8229. value: event.target.checked
  8230. });
  8231. }
  8232. };
  8233. this._dispatchEventFromSandbox(actions, jsEvent);
  8234. });
  8235. 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);
  8236. }
  8237. this._setBackgroundColor(element);
  8238. this.container.appendChild(element);
  8239. return this.container;
  8240. }
  8241. }
  8242. class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
  8243. constructor(parameters) {
  8244. super(parameters, {
  8245. isRenderable: parameters.renderForms
  8246. });
  8247. }
  8248. render() {
  8249. this.container.className = "buttonWidgetAnnotation radioButton";
  8250. const storage = this.annotationStorage;
  8251. const data = this.data;
  8252. const id = data.id;
  8253. let value = storage.getValue(id, {
  8254. value: data.fieldValue === data.buttonValue
  8255. }).value;
  8256. if (typeof value === "string") {
  8257. value = value !== data.buttonValue;
  8258. storage.setValue(id, {
  8259. value
  8260. });
  8261. }
  8262. const element = document.createElement("input");
  8263. GetElementsByNameSet.add(element);
  8264. element.disabled = data.readOnly;
  8265. element.type = "radio";
  8266. element.name = data.fieldName;
  8267. if (value) {
  8268. element.setAttribute("checked", true);
  8269. }
  8270. element.setAttribute("id", id);
  8271. element.tabIndex = DEFAULT_TAB_INDEX;
  8272. element.addEventListener("change", event => {
  8273. const {
  8274. name,
  8275. checked
  8276. } = event.target;
  8277. for (const radio of this._getElementsByName(name, id)) {
  8278. storage.setValue(radio.id, {
  8279. value: false
  8280. });
  8281. }
  8282. storage.setValue(id, {
  8283. value: checked
  8284. });
  8285. });
  8286. element.addEventListener("resetform", event => {
  8287. const defaultValue = data.defaultFieldValue;
  8288. event.target.checked = defaultValue !== null && defaultValue !== undefined && defaultValue === data.buttonValue;
  8289. });
  8290. if (this.enableScripting && this.hasJSActions) {
  8291. const pdfButtonValue = data.buttonValue;
  8292. element.addEventListener("updatefromsandbox", jsEvent => {
  8293. const actions = {
  8294. value: event => {
  8295. const checked = pdfButtonValue === event.detail.value;
  8296. for (const radio of this._getElementsByName(event.target.name)) {
  8297. const curChecked = checked && radio.id === id;
  8298. if (radio.domElement) {
  8299. radio.domElement.checked = curChecked;
  8300. }
  8301. storage.setValue(radio.id, {
  8302. value: curChecked
  8303. });
  8304. }
  8305. }
  8306. };
  8307. this._dispatchEventFromSandbox(actions, jsEvent);
  8308. });
  8309. 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);
  8310. }
  8311. this._setBackgroundColor(element);
  8312. this.container.appendChild(element);
  8313. return this.container;
  8314. }
  8315. }
  8316. class PushButtonWidgetAnnotationElement extends LinkAnnotationElement {
  8317. constructor(parameters) {
  8318. super(parameters, {
  8319. ignoreBorder: parameters.data.hasAppearance
  8320. });
  8321. }
  8322. render() {
  8323. const container = super.render();
  8324. container.className = "buttonWidgetAnnotation pushButton";
  8325. if (this.data.alternativeText) {
  8326. container.title = this.data.alternativeText;
  8327. }
  8328. return container;
  8329. }
  8330. }
  8331. class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
  8332. constructor(parameters) {
  8333. super(parameters, {
  8334. isRenderable: parameters.renderForms
  8335. });
  8336. }
  8337. render() {
  8338. this.container.className = "choiceWidgetAnnotation";
  8339. const storage = this.annotationStorage;
  8340. const id = this.data.id;
  8341. storage.getValue(id, {
  8342. value: this.data.fieldValue.length > 0 ? this.data.fieldValue[0] : undefined
  8343. });
  8344. let {
  8345. fontSize
  8346. } = this.data.defaultAppearanceData;
  8347. if (!fontSize) {
  8348. fontSize = 9;
  8349. }
  8350. const fontSizeStyle = `calc(${fontSize}px * var(--zoom-factor))`;
  8351. const selectElement = document.createElement("select");
  8352. GetElementsByNameSet.add(selectElement);
  8353. selectElement.disabled = this.data.readOnly;
  8354. selectElement.name = this.data.fieldName;
  8355. selectElement.setAttribute("id", id);
  8356. selectElement.tabIndex = DEFAULT_TAB_INDEX;
  8357. selectElement.style.fontSize = `${fontSize}px`;
  8358. if (!this.data.combo) {
  8359. selectElement.size = this.data.options.length;
  8360. if (this.data.multiSelect) {
  8361. selectElement.multiple = true;
  8362. }
  8363. }
  8364. selectElement.addEventListener("resetform", event => {
  8365. const defaultValue = this.data.defaultFieldValue;
  8366. for (const option of selectElement.options) {
  8367. option.selected = option.value === defaultValue;
  8368. }
  8369. });
  8370. for (const option of this.data.options) {
  8371. const optionElement = document.createElement("option");
  8372. optionElement.textContent = option.displayValue;
  8373. optionElement.value = option.exportValue;
  8374. if (this.data.combo) {
  8375. optionElement.style.fontSize = fontSizeStyle;
  8376. }
  8377. if (this.data.fieldValue.includes(option.exportValue)) {
  8378. optionElement.setAttribute("selected", true);
  8379. }
  8380. selectElement.appendChild(optionElement);
  8381. }
  8382. const getValue = (event, isExport) => {
  8383. const name = isExport ? "value" : "textContent";
  8384. const options = event.target.options;
  8385. if (!event.target.multiple) {
  8386. return options.selectedIndex === -1 ? null : options[options.selectedIndex][name];
  8387. }
  8388. return Array.prototype.filter.call(options, option => option.selected).map(option => option[name]);
  8389. };
  8390. const getItems = event => {
  8391. const options = event.target.options;
  8392. return Array.prototype.map.call(options, option => {
  8393. return {
  8394. displayValue: option.textContent,
  8395. exportValue: option.value
  8396. };
  8397. });
  8398. };
  8399. if (this.enableScripting && this.hasJSActions) {
  8400. selectElement.addEventListener("updatefromsandbox", jsEvent => {
  8401. const actions = {
  8402. value(event) {
  8403. const value = event.detail.value;
  8404. const values = new Set(Array.isArray(value) ? value : [value]);
  8405. for (const option of selectElement.options) {
  8406. option.selected = values.has(option.value);
  8407. }
  8408. storage.setValue(id, {
  8409. value: getValue(event, true)
  8410. });
  8411. },
  8412. multipleSelection(event) {
  8413. selectElement.multiple = true;
  8414. },
  8415. remove(event) {
  8416. const options = selectElement.options;
  8417. const index = event.detail.remove;
  8418. options[index].selected = false;
  8419. selectElement.remove(index);
  8420. if (options.length > 0) {
  8421. const i = Array.prototype.findIndex.call(options, option => option.selected);
  8422. if (i === -1) {
  8423. options[0].selected = true;
  8424. }
  8425. }
  8426. storage.setValue(id, {
  8427. value: getValue(event, true),
  8428. items: getItems(event)
  8429. });
  8430. },
  8431. clear(event) {
  8432. while (selectElement.length !== 0) {
  8433. selectElement.remove(0);
  8434. }
  8435. storage.setValue(id, {
  8436. value: null,
  8437. items: []
  8438. });
  8439. },
  8440. insert(event) {
  8441. const {
  8442. index,
  8443. displayValue,
  8444. exportValue
  8445. } = event.detail.insert;
  8446. const optionElement = document.createElement("option");
  8447. optionElement.textContent = displayValue;
  8448. optionElement.value = exportValue;
  8449. selectElement.insertBefore(optionElement, selectElement.children[index]);
  8450. storage.setValue(id, {
  8451. value: getValue(event, true),
  8452. items: getItems(event)
  8453. });
  8454. },
  8455. items(event) {
  8456. const {
  8457. items
  8458. } = event.detail;
  8459. while (selectElement.length !== 0) {
  8460. selectElement.remove(0);
  8461. }
  8462. for (const item of items) {
  8463. const {
  8464. displayValue,
  8465. exportValue
  8466. } = item;
  8467. const optionElement = document.createElement("option");
  8468. optionElement.textContent = displayValue;
  8469. optionElement.value = exportValue;
  8470. selectElement.appendChild(optionElement);
  8471. }
  8472. if (selectElement.options.length > 0) {
  8473. selectElement.options[0].selected = true;
  8474. }
  8475. storage.setValue(id, {
  8476. value: getValue(event, true),
  8477. items: getItems(event)
  8478. });
  8479. },
  8480. indices(event) {
  8481. const indices = new Set(event.detail.indices);
  8482. for (const option of event.target.options) {
  8483. option.selected = indices.has(option.index);
  8484. }
  8485. storage.setValue(id, {
  8486. value: getValue(event, true)
  8487. });
  8488. },
  8489. editable(event) {
  8490. event.target.disabled = !event.detail.editable;
  8491. }
  8492. };
  8493. this._dispatchEventFromSandbox(actions, jsEvent);
  8494. });
  8495. selectElement.addEventListener("input", event => {
  8496. const exportValue = getValue(event, true);
  8497. const value = getValue(event, false);
  8498. storage.setValue(id, {
  8499. value: exportValue
  8500. });
  8501. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  8502. source: this,
  8503. detail: {
  8504. id,
  8505. name: "Keystroke",
  8506. value,
  8507. changeEx: exportValue,
  8508. willCommit: true,
  8509. commitKey: 1,
  8510. keyDown: false
  8511. }
  8512. });
  8513. });
  8514. 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);
  8515. } else {
  8516. selectElement.addEventListener("input", function (event) {
  8517. storage.setValue(id, {
  8518. value: getValue(event)
  8519. });
  8520. });
  8521. }
  8522. this._setBackgroundColor(selectElement);
  8523. this.container.appendChild(selectElement);
  8524. return this.container;
  8525. }
  8526. }
  8527. class PopupAnnotationElement extends AnnotationElement {
  8528. constructor(parameters) {
  8529. const isRenderable = !!(parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  8530. super(parameters, {
  8531. isRenderable
  8532. });
  8533. }
  8534. render() {
  8535. const IGNORE_TYPES = ["Line", "Square", "Circle", "PolyLine", "Polygon", "Ink"];
  8536. this.container.className = "popupAnnotation";
  8537. if (IGNORE_TYPES.includes(this.data.parentType)) {
  8538. return this.container;
  8539. }
  8540. const selector = `[data-annotation-id="${this.data.parentId}"]`;
  8541. const parentElements = this.layer.querySelectorAll(selector);
  8542. if (parentElements.length === 0) {
  8543. return this.container;
  8544. }
  8545. const popup = new PopupElement({
  8546. container: this.container,
  8547. trigger: Array.from(parentElements),
  8548. color: this.data.color,
  8549. titleObj: this.data.titleObj,
  8550. modificationDate: this.data.modificationDate,
  8551. contentsObj: this.data.contentsObj,
  8552. richText: this.data.richText
  8553. });
  8554. const page = this.page;
  8555. 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]]);
  8556. const popupLeft = rect[0] + this.data.parentRect[2] - this.data.parentRect[0];
  8557. const popupTop = rect[1];
  8558. this.container.style.transformOrigin = `${-popupLeft}px ${-popupTop}px`;
  8559. this.container.style.left = `${popupLeft}px`;
  8560. this.container.style.top = `${popupTop}px`;
  8561. this.container.appendChild(popup.render());
  8562. return this.container;
  8563. }
  8564. }
  8565. class PopupElement {
  8566. constructor(parameters) {
  8567. this.container = parameters.container;
  8568. this.trigger = parameters.trigger;
  8569. this.color = parameters.color;
  8570. this.titleObj = parameters.titleObj;
  8571. this.modificationDate = parameters.modificationDate;
  8572. this.contentsObj = parameters.contentsObj;
  8573. this.richText = parameters.richText;
  8574. this.hideWrapper = parameters.hideWrapper || false;
  8575. this.pinned = false;
  8576. }
  8577. render() {
  8578. const BACKGROUND_ENLIGHT = 0.7;
  8579. const wrapper = document.createElement("div");
  8580. wrapper.className = "popupWrapper";
  8581. this.hideElement = this.hideWrapper ? wrapper : this.container;
  8582. this.hideElement.hidden = true;
  8583. const popup = document.createElement("div");
  8584. popup.className = "popup";
  8585. const color = this.color;
  8586. if (color) {
  8587. const r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  8588. const g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  8589. const b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  8590. popup.style.backgroundColor = _util.Util.makeHexColor(r | 0, g | 0, b | 0);
  8591. }
  8592. const title = document.createElement("h1");
  8593. title.dir = this.titleObj.dir;
  8594. title.textContent = this.titleObj.str;
  8595. popup.appendChild(title);
  8596. const dateObject = _display_utils.PDFDateString.toDateObject(this.modificationDate);
  8597. if (dateObject) {
  8598. const modificationDate = document.createElement("span");
  8599. modificationDate.className = "popupDate";
  8600. modificationDate.textContent = "{{date}}, {{time}}";
  8601. modificationDate.dataset.l10nId = "annotation_date_string";
  8602. modificationDate.dataset.l10nArgs = JSON.stringify({
  8603. date: dateObject.toLocaleDateString(),
  8604. time: dateObject.toLocaleTimeString()
  8605. });
  8606. popup.appendChild(modificationDate);
  8607. }
  8608. if (this.richText?.str && (!this.contentsObj?.str || this.contentsObj.str === this.richText.str)) {
  8609. _xfa_layer.XfaLayer.render({
  8610. xfaHtml: this.richText.html,
  8611. intent: "richText",
  8612. div: popup
  8613. });
  8614. popup.lastChild.className = "richText popupContent";
  8615. } else {
  8616. const contents = this._formatContents(this.contentsObj);
  8617. popup.appendChild(contents);
  8618. }
  8619. if (!Array.isArray(this.trigger)) {
  8620. this.trigger = [this.trigger];
  8621. }
  8622. for (const element of this.trigger) {
  8623. element.addEventListener("click", this._toggle.bind(this));
  8624. element.addEventListener("mouseover", this._show.bind(this, false));
  8625. element.addEventListener("mouseout", this._hide.bind(this, false));
  8626. }
  8627. popup.addEventListener("click", this._hide.bind(this, true));
  8628. wrapper.appendChild(popup);
  8629. return wrapper;
  8630. }
  8631. _formatContents({
  8632. str,
  8633. dir
  8634. }) {
  8635. const p = document.createElement("p");
  8636. p.className = "popupContent";
  8637. p.dir = dir;
  8638. const lines = str.split(/(?:\r\n?|\n)/);
  8639. for (let i = 0, ii = lines.length; i < ii; ++i) {
  8640. const line = lines[i];
  8641. p.appendChild(document.createTextNode(line));
  8642. if (i < ii - 1) {
  8643. p.appendChild(document.createElement("br"));
  8644. }
  8645. }
  8646. return p;
  8647. }
  8648. _toggle() {
  8649. if (this.pinned) {
  8650. this._hide(true);
  8651. } else {
  8652. this._show(true);
  8653. }
  8654. }
  8655. _show(pin = false) {
  8656. if (pin) {
  8657. this.pinned = true;
  8658. }
  8659. if (this.hideElement.hidden) {
  8660. this.hideElement.hidden = false;
  8661. this.container.style.zIndex += 1;
  8662. }
  8663. }
  8664. _hide(unpin = true) {
  8665. if (unpin) {
  8666. this.pinned = false;
  8667. }
  8668. if (!this.hideElement.hidden && !this.pinned) {
  8669. this.hideElement.hidden = true;
  8670. this.container.style.zIndex -= 1;
  8671. }
  8672. }
  8673. }
  8674. class FreeTextAnnotationElement extends AnnotationElement {
  8675. constructor(parameters) {
  8676. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  8677. super(parameters, {
  8678. isRenderable,
  8679. ignoreBorder: true
  8680. });
  8681. }
  8682. render() {
  8683. this.container.className = "freeTextAnnotation";
  8684. if (!this.data.hasPopup) {
  8685. this._createPopup(null, this.data);
  8686. }
  8687. return this.container;
  8688. }
  8689. }
  8690. class LineAnnotationElement extends AnnotationElement {
  8691. constructor(parameters) {
  8692. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  8693. super(parameters, {
  8694. isRenderable,
  8695. ignoreBorder: true
  8696. });
  8697. }
  8698. render() {
  8699. this.container.className = "lineAnnotation";
  8700. const data = this.data;
  8701. const {
  8702. width,
  8703. height
  8704. } = getRectDims(data.rect);
  8705. const svg = this.svgFactory.create(width, height);
  8706. const line = this.svgFactory.createElement("svg:line");
  8707. line.setAttribute("x1", data.rect[2] - data.lineCoordinates[0]);
  8708. line.setAttribute("y1", data.rect[3] - data.lineCoordinates[1]);
  8709. line.setAttribute("x2", data.rect[2] - data.lineCoordinates[2]);
  8710. line.setAttribute("y2", data.rect[3] - data.lineCoordinates[3]);
  8711. line.setAttribute("stroke-width", data.borderStyle.width || 1);
  8712. line.setAttribute("stroke", "transparent");
  8713. line.setAttribute("fill", "transparent");
  8714. svg.appendChild(line);
  8715. this.container.append(svg);
  8716. this._createPopup(line, data);
  8717. return this.container;
  8718. }
  8719. }
  8720. class SquareAnnotationElement extends AnnotationElement {
  8721. constructor(parameters) {
  8722. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  8723. super(parameters, {
  8724. isRenderable,
  8725. ignoreBorder: true
  8726. });
  8727. }
  8728. render() {
  8729. this.container.className = "squareAnnotation";
  8730. const data = this.data;
  8731. const {
  8732. width,
  8733. height
  8734. } = getRectDims(data.rect);
  8735. const svg = this.svgFactory.create(width, height);
  8736. const borderWidth = data.borderStyle.width;
  8737. const square = this.svgFactory.createElement("svg:rect");
  8738. square.setAttribute("x", borderWidth / 2);
  8739. square.setAttribute("y", borderWidth / 2);
  8740. square.setAttribute("width", width - borderWidth);
  8741. square.setAttribute("height", height - borderWidth);
  8742. square.setAttribute("stroke-width", borderWidth || 1);
  8743. square.setAttribute("stroke", "transparent");
  8744. square.setAttribute("fill", "transparent");
  8745. svg.appendChild(square);
  8746. this.container.append(svg);
  8747. this._createPopup(square, data);
  8748. return this.container;
  8749. }
  8750. }
  8751. class CircleAnnotationElement extends AnnotationElement {
  8752. constructor(parameters) {
  8753. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  8754. super(parameters, {
  8755. isRenderable,
  8756. ignoreBorder: true
  8757. });
  8758. }
  8759. render() {
  8760. this.container.className = "circleAnnotation";
  8761. const data = this.data;
  8762. const {
  8763. width,
  8764. height
  8765. } = getRectDims(data.rect);
  8766. const svg = this.svgFactory.create(width, height);
  8767. const borderWidth = data.borderStyle.width;
  8768. const circle = this.svgFactory.createElement("svg:ellipse");
  8769. circle.setAttribute("cx", width / 2);
  8770. circle.setAttribute("cy", height / 2);
  8771. circle.setAttribute("rx", width / 2 - borderWidth / 2);
  8772. circle.setAttribute("ry", height / 2 - borderWidth / 2);
  8773. circle.setAttribute("stroke-width", borderWidth || 1);
  8774. circle.setAttribute("stroke", "transparent");
  8775. circle.setAttribute("fill", "transparent");
  8776. svg.appendChild(circle);
  8777. this.container.append(svg);
  8778. this._createPopup(circle, data);
  8779. return this.container;
  8780. }
  8781. }
  8782. class PolylineAnnotationElement extends AnnotationElement {
  8783. constructor(parameters) {
  8784. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  8785. super(parameters, {
  8786. isRenderable,
  8787. ignoreBorder: true
  8788. });
  8789. this.containerClassName = "polylineAnnotation";
  8790. this.svgElementName = "svg:polyline";
  8791. }
  8792. render() {
  8793. this.container.className = this.containerClassName;
  8794. const data = this.data;
  8795. const {
  8796. width,
  8797. height
  8798. } = getRectDims(data.rect);
  8799. const svg = this.svgFactory.create(width, height);
  8800. let points = [];
  8801. for (const coordinate of data.vertices) {
  8802. const x = coordinate.x - data.rect[0];
  8803. const y = data.rect[3] - coordinate.y;
  8804. points.push(x + "," + y);
  8805. }
  8806. points = points.join(" ");
  8807. const polyline = this.svgFactory.createElement(this.svgElementName);
  8808. polyline.setAttribute("points", points);
  8809. polyline.setAttribute("stroke-width", data.borderStyle.width || 1);
  8810. polyline.setAttribute("stroke", "transparent");
  8811. polyline.setAttribute("fill", "transparent");
  8812. svg.appendChild(polyline);
  8813. this.container.append(svg);
  8814. this._createPopup(polyline, data);
  8815. return this.container;
  8816. }
  8817. }
  8818. class PolygonAnnotationElement extends PolylineAnnotationElement {
  8819. constructor(parameters) {
  8820. super(parameters);
  8821. this.containerClassName = "polygonAnnotation";
  8822. this.svgElementName = "svg:polygon";
  8823. }
  8824. }
  8825. class CaretAnnotationElement extends AnnotationElement {
  8826. constructor(parameters) {
  8827. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  8828. super(parameters, {
  8829. isRenderable,
  8830. ignoreBorder: true
  8831. });
  8832. }
  8833. render() {
  8834. this.container.className = "caretAnnotation";
  8835. if (!this.data.hasPopup) {
  8836. this._createPopup(null, this.data);
  8837. }
  8838. return this.container;
  8839. }
  8840. }
  8841. class InkAnnotationElement extends AnnotationElement {
  8842. constructor(parameters) {
  8843. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  8844. super(parameters, {
  8845. isRenderable,
  8846. ignoreBorder: true
  8847. });
  8848. this.containerClassName = "inkAnnotation";
  8849. this.svgElementName = "svg:polyline";
  8850. }
  8851. render() {
  8852. this.container.className = this.containerClassName;
  8853. const data = this.data;
  8854. const {
  8855. width,
  8856. height
  8857. } = getRectDims(data.rect);
  8858. const svg = this.svgFactory.create(width, height);
  8859. for (const inkList of data.inkLists) {
  8860. let points = [];
  8861. for (const coordinate of inkList) {
  8862. const x = coordinate.x - data.rect[0];
  8863. const y = data.rect[3] - coordinate.y;
  8864. points.push(`${x},${y}`);
  8865. }
  8866. points = points.join(" ");
  8867. const polyline = this.svgFactory.createElement(this.svgElementName);
  8868. polyline.setAttribute("points", points);
  8869. polyline.setAttribute("stroke-width", data.borderStyle.width || 1);
  8870. polyline.setAttribute("stroke", "transparent");
  8871. polyline.setAttribute("fill", "transparent");
  8872. this._createPopup(polyline, data);
  8873. svg.appendChild(polyline);
  8874. }
  8875. this.container.append(svg);
  8876. return this.container;
  8877. }
  8878. }
  8879. class HighlightAnnotationElement extends AnnotationElement {
  8880. constructor(parameters) {
  8881. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  8882. super(parameters, {
  8883. isRenderable,
  8884. ignoreBorder: true,
  8885. createQuadrilaterals: true
  8886. });
  8887. }
  8888. render() {
  8889. if (!this.data.hasPopup) {
  8890. this._createPopup(null, this.data);
  8891. }
  8892. if (this.quadrilaterals) {
  8893. return this._renderQuadrilaterals("highlightAnnotation");
  8894. }
  8895. this.container.className = "highlightAnnotation";
  8896. return this.container;
  8897. }
  8898. }
  8899. class UnderlineAnnotationElement extends AnnotationElement {
  8900. constructor(parameters) {
  8901. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  8902. super(parameters, {
  8903. isRenderable,
  8904. ignoreBorder: true,
  8905. createQuadrilaterals: true
  8906. });
  8907. }
  8908. render() {
  8909. if (!this.data.hasPopup) {
  8910. this._createPopup(null, this.data);
  8911. }
  8912. if (this.quadrilaterals) {
  8913. return this._renderQuadrilaterals("underlineAnnotation");
  8914. }
  8915. this.container.className = "underlineAnnotation";
  8916. return this.container;
  8917. }
  8918. }
  8919. class SquigglyAnnotationElement extends AnnotationElement {
  8920. constructor(parameters) {
  8921. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  8922. super(parameters, {
  8923. isRenderable,
  8924. ignoreBorder: true,
  8925. createQuadrilaterals: true
  8926. });
  8927. }
  8928. render() {
  8929. if (!this.data.hasPopup) {
  8930. this._createPopup(null, this.data);
  8931. }
  8932. if (this.quadrilaterals) {
  8933. return this._renderQuadrilaterals("squigglyAnnotation");
  8934. }
  8935. this.container.className = "squigglyAnnotation";
  8936. return this.container;
  8937. }
  8938. }
  8939. class StrikeOutAnnotationElement extends AnnotationElement {
  8940. constructor(parameters) {
  8941. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  8942. super(parameters, {
  8943. isRenderable,
  8944. ignoreBorder: true,
  8945. createQuadrilaterals: true
  8946. });
  8947. }
  8948. render() {
  8949. if (!this.data.hasPopup) {
  8950. this._createPopup(null, this.data);
  8951. }
  8952. if (this.quadrilaterals) {
  8953. return this._renderQuadrilaterals("strikeoutAnnotation");
  8954. }
  8955. this.container.className = "strikeoutAnnotation";
  8956. return this.container;
  8957. }
  8958. }
  8959. class StampAnnotationElement extends AnnotationElement {
  8960. constructor(parameters) {
  8961. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  8962. super(parameters, {
  8963. isRenderable,
  8964. ignoreBorder: true
  8965. });
  8966. }
  8967. render() {
  8968. this.container.className = "stampAnnotation";
  8969. if (!this.data.hasPopup) {
  8970. this._createPopup(null, this.data);
  8971. }
  8972. return this.container;
  8973. }
  8974. }
  8975. class FileAttachmentAnnotationElement extends AnnotationElement {
  8976. constructor(parameters) {
  8977. super(parameters, {
  8978. isRenderable: true
  8979. });
  8980. const {
  8981. filename,
  8982. content
  8983. } = this.data.file;
  8984. this.filename = (0, _display_utils.getFilenameFromUrl)(filename);
  8985. this.content = content;
  8986. this.linkService.eventBus?.dispatch("fileattachmentannotation", {
  8987. source: this,
  8988. id: (0, _util.stringToPDFString)(filename),
  8989. filename,
  8990. content
  8991. });
  8992. }
  8993. render() {
  8994. this.container.className = "fileAttachmentAnnotation";
  8995. const trigger = document.createElement("div");
  8996. trigger.style.height = this.container.style.height;
  8997. trigger.style.width = this.container.style.width;
  8998. trigger.addEventListener("dblclick", this._download.bind(this));
  8999. if (!this.data.hasPopup && (this.data.titleObj?.str || this.data.contentsObj?.str || this.data.richText)) {
  9000. this._createPopup(trigger, this.data);
  9001. }
  9002. this.container.appendChild(trigger);
  9003. return this.container;
  9004. }
  9005. _download() {
  9006. this.downloadManager?.openOrDownloadData(this.container, this.content, this.filename);
  9007. }
  9008. }
  9009. class AnnotationLayer {
  9010. static render(parameters) {
  9011. const sortedAnnotations = [],
  9012. popupAnnotations = [];
  9013. for (const data of parameters.annotations) {
  9014. if (!data) {
  9015. continue;
  9016. }
  9017. const {
  9018. width,
  9019. height
  9020. } = getRectDims(data.rect);
  9021. if (width <= 0 || height <= 0) {
  9022. continue;
  9023. }
  9024. if (data.annotationType === _util.AnnotationType.POPUP) {
  9025. popupAnnotations.push(data);
  9026. continue;
  9027. }
  9028. sortedAnnotations.push(data);
  9029. }
  9030. if (popupAnnotations.length) {
  9031. sortedAnnotations.push(...popupAnnotations);
  9032. }
  9033. const div = parameters.div;
  9034. for (const data of sortedAnnotations) {
  9035. const element = AnnotationElementFactory.create({
  9036. data,
  9037. layer: div,
  9038. page: parameters.page,
  9039. viewport: parameters.viewport,
  9040. linkService: parameters.linkService,
  9041. downloadManager: parameters.downloadManager,
  9042. imageResourcesPath: parameters.imageResourcesPath || "",
  9043. renderForms: parameters.renderForms !== false,
  9044. svgFactory: new _display_utils.DOMSVGFactory(),
  9045. annotationStorage: parameters.annotationStorage || new _annotation_storage.AnnotationStorage(),
  9046. enableScripting: parameters.enableScripting,
  9047. hasJSActions: parameters.hasJSActions,
  9048. fieldObjects: parameters.fieldObjects,
  9049. mouseState: parameters.mouseState || {
  9050. isDown: false
  9051. }
  9052. });
  9053. if (element.isRenderable) {
  9054. const rendered = element.render();
  9055. if (data.hidden) {
  9056. rendered.style.visibility = "hidden";
  9057. }
  9058. if (Array.isArray(rendered)) {
  9059. for (const renderedElement of rendered) {
  9060. div.appendChild(renderedElement);
  9061. }
  9062. } else {
  9063. if (element instanceof PopupAnnotationElement) {
  9064. div.prepend(rendered);
  9065. } else {
  9066. div.appendChild(rendered);
  9067. }
  9068. }
  9069. }
  9070. }
  9071. this.#setAnnotationCanvasMap(div, parameters.annotationCanvasMap);
  9072. }
  9073. static update(parameters) {
  9074. const {
  9075. page,
  9076. viewport,
  9077. annotations,
  9078. annotationCanvasMap,
  9079. div
  9080. } = parameters;
  9081. const transform = viewport.transform;
  9082. const matrix = `matrix(${transform.join(",")})`;
  9083. let scale, ownMatrix;
  9084. for (const data of annotations) {
  9085. const elements = div.querySelectorAll(`[data-annotation-id="${data.id}"]`);
  9086. if (elements) {
  9087. for (const element of elements) {
  9088. if (data.hasOwnCanvas) {
  9089. 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]]);
  9090. if (!ownMatrix) {
  9091. scale = Math.abs(transform[0] || transform[1]);
  9092. const ownTransform = transform.slice();
  9093. for (let i = 0; i < 4; i++) {
  9094. ownTransform[i] = Math.sign(ownTransform[i]);
  9095. }
  9096. ownMatrix = `matrix(${ownTransform.join(",")})`;
  9097. }
  9098. const left = rect[0] * scale;
  9099. const top = rect[1] * scale;
  9100. element.style.left = `${left}px`;
  9101. element.style.top = `${top}px`;
  9102. element.style.transformOrigin = `${-left}px ${-top}px`;
  9103. element.style.transform = ownMatrix;
  9104. } else {
  9105. element.style.transform = matrix;
  9106. }
  9107. }
  9108. }
  9109. }
  9110. this.#setAnnotationCanvasMap(div, annotationCanvasMap);
  9111. div.hidden = false;
  9112. }
  9113. static #setAnnotationCanvasMap(div, annotationCanvasMap) {
  9114. if (!annotationCanvasMap) {
  9115. return;
  9116. }
  9117. for (const [id, canvas] of annotationCanvasMap) {
  9118. const element = div.querySelector(`[data-annotation-id="${id}"]`);
  9119. if (!element) {
  9120. continue;
  9121. }
  9122. const {
  9123. firstChild
  9124. } = element;
  9125. if (firstChild.nodeName === "CANVAS") {
  9126. element.replaceChild(canvas, firstChild);
  9127. } else {
  9128. element.insertBefore(canvas, firstChild);
  9129. }
  9130. }
  9131. annotationCanvasMap.clear();
  9132. }
  9133. }
  9134. exports.AnnotationLayer = AnnotationLayer;
  9135. /***/ }),
  9136. /* 19 */
  9137. /***/ ((__unused_webpack_module, exports) => {
  9138. Object.defineProperty(exports, "__esModule", ({
  9139. value: true
  9140. }));
  9141. exports.ColorConverters = void 0;
  9142. function makeColorComp(n) {
  9143. return Math.floor(Math.max(0, Math.min(1, n)) * 255).toString(16).padStart(2, "0");
  9144. }
  9145. class ColorConverters {
  9146. static CMYK_G([c, y, m, k]) {
  9147. return ["G", 1 - Math.min(1, 0.3 * c + 0.59 * m + 0.11 * y + k)];
  9148. }
  9149. static G_CMYK([g]) {
  9150. return ["CMYK", 0, 0, 0, 1 - g];
  9151. }
  9152. static G_RGB([g]) {
  9153. return ["RGB", g, g, g];
  9154. }
  9155. static G_HTML([g]) {
  9156. const G = makeColorComp(g);
  9157. return `#${G}${G}${G}`;
  9158. }
  9159. static RGB_G([r, g, b]) {
  9160. return ["G", 0.3 * r + 0.59 * g + 0.11 * b];
  9161. }
  9162. static RGB_HTML([r, g, b]) {
  9163. const R = makeColorComp(r);
  9164. const G = makeColorComp(g);
  9165. const B = makeColorComp(b);
  9166. return `#${R}${G}${B}`;
  9167. }
  9168. static T_HTML() {
  9169. return "#00000000";
  9170. }
  9171. static CMYK_RGB([c, y, m, k]) {
  9172. return ["RGB", 1 - Math.min(1, c + k), 1 - Math.min(1, m + k), 1 - Math.min(1, y + k)];
  9173. }
  9174. static CMYK_HTML(components) {
  9175. return this.RGB_HTML(this.CMYK_RGB(components));
  9176. }
  9177. static RGB_CMYK([r, g, b]) {
  9178. const c = 1 - r;
  9179. const m = 1 - g;
  9180. const y = 1 - b;
  9181. const k = Math.min(c, m, y);
  9182. return ["CMYK", c, m, y, k];
  9183. }
  9184. }
  9185. exports.ColorConverters = ColorConverters;
  9186. /***/ }),
  9187. /* 20 */
  9188. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  9189. Object.defineProperty(exports, "__esModule", ({
  9190. value: true
  9191. }));
  9192. exports.XfaLayer = void 0;
  9193. var _util = __w_pdfjs_require__(1);
  9194. var _xfa_text = __w_pdfjs_require__(17);
  9195. class XfaLayer {
  9196. static setupStorage(html, id, element, storage, intent) {
  9197. const storedData = storage.getValue(id, {
  9198. value: null
  9199. });
  9200. switch (element.name) {
  9201. case "textarea":
  9202. if (storedData.value !== null) {
  9203. html.textContent = storedData.value;
  9204. }
  9205. if (intent === "print") {
  9206. break;
  9207. }
  9208. html.addEventListener("input", event => {
  9209. storage.setValue(id, {
  9210. value: event.target.value
  9211. });
  9212. });
  9213. break;
  9214. case "input":
  9215. if (element.attributes.type === "radio" || element.attributes.type === "checkbox") {
  9216. if (storedData.value === element.attributes.xfaOn) {
  9217. html.setAttribute("checked", true);
  9218. } else if (storedData.value === element.attributes.xfaOff) {
  9219. html.removeAttribute("checked");
  9220. }
  9221. if (intent === "print") {
  9222. break;
  9223. }
  9224. html.addEventListener("change", event => {
  9225. storage.setValue(id, {
  9226. value: event.target.checked ? event.target.getAttribute("xfaOn") : event.target.getAttribute("xfaOff")
  9227. });
  9228. });
  9229. } else {
  9230. if (storedData.value !== null) {
  9231. html.setAttribute("value", storedData.value);
  9232. }
  9233. if (intent === "print") {
  9234. break;
  9235. }
  9236. html.addEventListener("input", event => {
  9237. storage.setValue(id, {
  9238. value: event.target.value
  9239. });
  9240. });
  9241. }
  9242. break;
  9243. case "select":
  9244. if (storedData.value !== null) {
  9245. for (const option of element.children) {
  9246. if (option.attributes.value === storedData.value) {
  9247. option.attributes.selected = true;
  9248. }
  9249. }
  9250. }
  9251. html.addEventListener("input", event => {
  9252. const options = event.target.options;
  9253. const value = options.selectedIndex === -1 ? "" : options[options.selectedIndex].value;
  9254. storage.setValue(id, {
  9255. value
  9256. });
  9257. });
  9258. break;
  9259. }
  9260. }
  9261. static setAttributes({
  9262. html,
  9263. element,
  9264. storage = null,
  9265. intent,
  9266. linkService
  9267. }) {
  9268. const {
  9269. attributes
  9270. } = element;
  9271. const isHTMLAnchorElement = html instanceof HTMLAnchorElement;
  9272. if (attributes.type === "radio") {
  9273. attributes.name = `${attributes.name}-${intent}`;
  9274. }
  9275. for (const [key, value] of Object.entries(attributes)) {
  9276. if (value === null || value === undefined || key === "dataId") {
  9277. continue;
  9278. }
  9279. if (key !== "style") {
  9280. if (key === "textContent") {
  9281. html.textContent = value;
  9282. } else if (key === "class") {
  9283. if (value.length) {
  9284. html.setAttribute(key, value.join(" "));
  9285. }
  9286. } else {
  9287. if (isHTMLAnchorElement && (key === "href" || key === "newWindow")) {
  9288. continue;
  9289. }
  9290. html.setAttribute(key, value);
  9291. }
  9292. } else {
  9293. Object.assign(html.style, value);
  9294. }
  9295. }
  9296. if (isHTMLAnchorElement) {
  9297. if (!linkService.addLinkAttributes) {
  9298. (0, _util.warn)("XfaLayer.setAttribute - missing `addLinkAttributes`-method on the `linkService`-instance.");
  9299. }
  9300. linkService.addLinkAttributes?.(html, attributes.href, attributes.newWindow);
  9301. }
  9302. if (storage && attributes.dataId) {
  9303. this.setupStorage(html, attributes.dataId, element, storage);
  9304. }
  9305. }
  9306. static render(parameters) {
  9307. const storage = parameters.annotationStorage;
  9308. const linkService = parameters.linkService;
  9309. const root = parameters.xfaHtml;
  9310. const intent = parameters.intent || "display";
  9311. const rootHtml = document.createElement(root.name);
  9312. if (root.attributes) {
  9313. this.setAttributes({
  9314. html: rootHtml,
  9315. element: root,
  9316. intent,
  9317. linkService
  9318. });
  9319. }
  9320. const stack = [[root, -1, rootHtml]];
  9321. const rootDiv = parameters.div;
  9322. rootDiv.appendChild(rootHtml);
  9323. if (parameters.viewport) {
  9324. const transform = `matrix(${parameters.viewport.transform.join(",")})`;
  9325. rootDiv.style.transform = transform;
  9326. }
  9327. if (intent !== "richText") {
  9328. rootDiv.setAttribute("class", "xfaLayer xfaFont");
  9329. }
  9330. const textDivs = [];
  9331. while (stack.length > 0) {
  9332. const [parent, i, html] = stack[stack.length - 1];
  9333. if (i + 1 === parent.children.length) {
  9334. stack.pop();
  9335. continue;
  9336. }
  9337. const child = parent.children[++stack[stack.length - 1][1]];
  9338. if (child === null) {
  9339. continue;
  9340. }
  9341. const {
  9342. name
  9343. } = child;
  9344. if (name === "#text") {
  9345. const node = document.createTextNode(child.value);
  9346. textDivs.push(node);
  9347. html.appendChild(node);
  9348. continue;
  9349. }
  9350. let childHtml;
  9351. if (child?.attributes?.xmlns) {
  9352. childHtml = document.createElementNS(child.attributes.xmlns, name);
  9353. } else {
  9354. childHtml = document.createElement(name);
  9355. }
  9356. html.appendChild(childHtml);
  9357. if (child.attributes) {
  9358. this.setAttributes({
  9359. html: childHtml,
  9360. element: child,
  9361. storage,
  9362. intent,
  9363. linkService
  9364. });
  9365. }
  9366. if (child.children && child.children.length > 0) {
  9367. stack.push([child, -1, childHtml]);
  9368. } else if (child.value) {
  9369. const node = document.createTextNode(child.value);
  9370. if (_xfa_text.XfaText.shouldBuildText(name)) {
  9371. textDivs.push(node);
  9372. }
  9373. childHtml.appendChild(node);
  9374. }
  9375. }
  9376. for (const el of rootDiv.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea")) {
  9377. el.setAttribute("readOnly", true);
  9378. }
  9379. return {
  9380. textDivs
  9381. };
  9382. }
  9383. static update(parameters) {
  9384. const transform = `matrix(${parameters.viewport.transform.join(",")})`;
  9385. parameters.div.style.transform = transform;
  9386. parameters.div.hidden = false;
  9387. }
  9388. }
  9389. exports.XfaLayer = XfaLayer;
  9390. /***/ }),
  9391. /* 21 */
  9392. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  9393. Object.defineProperty(exports, "__esModule", ({
  9394. value: true
  9395. }));
  9396. exports.renderTextLayer = renderTextLayer;
  9397. var _util = __w_pdfjs_require__(1);
  9398. const MAX_TEXT_DIVS_TO_RENDER = 100000;
  9399. const DEFAULT_FONT_SIZE = 30;
  9400. const DEFAULT_FONT_ASCENT = 0.8;
  9401. const ascentCache = new Map();
  9402. const AllWhitespaceRegexp = /^\s+$/g;
  9403. function getAscent(fontFamily, ctx) {
  9404. const cachedAscent = ascentCache.get(fontFamily);
  9405. if (cachedAscent) {
  9406. return cachedAscent;
  9407. }
  9408. ctx.save();
  9409. ctx.font = `${DEFAULT_FONT_SIZE}px ${fontFamily}`;
  9410. const metrics = ctx.measureText("");
  9411. let ascent = metrics.fontBoundingBoxAscent;
  9412. let descent = Math.abs(metrics.fontBoundingBoxDescent);
  9413. if (ascent) {
  9414. ctx.restore();
  9415. const ratio = ascent / (ascent + descent);
  9416. ascentCache.set(fontFamily, ratio);
  9417. return ratio;
  9418. }
  9419. ctx.strokeStyle = "red";
  9420. ctx.clearRect(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE);
  9421. ctx.strokeText("g", 0, 0);
  9422. let pixels = ctx.getImageData(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE).data;
  9423. descent = 0;
  9424. for (let i = pixels.length - 1 - 3; i >= 0; i -= 4) {
  9425. if (pixels[i] > 0) {
  9426. descent = Math.ceil(i / 4 / DEFAULT_FONT_SIZE);
  9427. break;
  9428. }
  9429. }
  9430. ctx.clearRect(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE);
  9431. ctx.strokeText("A", 0, DEFAULT_FONT_SIZE);
  9432. pixels = ctx.getImageData(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE).data;
  9433. ascent = 0;
  9434. for (let i = 0, ii = pixels.length; i < ii; i += 4) {
  9435. if (pixels[i] > 0) {
  9436. ascent = DEFAULT_FONT_SIZE - Math.floor(i / 4 / DEFAULT_FONT_SIZE);
  9437. break;
  9438. }
  9439. }
  9440. ctx.restore();
  9441. if (ascent) {
  9442. const ratio = ascent / (ascent + descent);
  9443. ascentCache.set(fontFamily, ratio);
  9444. return ratio;
  9445. }
  9446. ascentCache.set(fontFamily, DEFAULT_FONT_ASCENT);
  9447. return DEFAULT_FONT_ASCENT;
  9448. }
  9449. function appendText(task, geom, styles, ctx) {
  9450. const textDiv = document.createElement("span");
  9451. const textDivProperties = task._enhanceTextSelection ? {
  9452. angle: 0,
  9453. canvasWidth: 0,
  9454. hasText: geom.str !== "",
  9455. hasEOL: geom.hasEOL,
  9456. originalTransform: null,
  9457. paddingBottom: 0,
  9458. paddingLeft: 0,
  9459. paddingRight: 0,
  9460. paddingTop: 0,
  9461. scale: 1
  9462. } : {
  9463. angle: 0,
  9464. canvasWidth: 0,
  9465. hasText: geom.str !== "",
  9466. hasEOL: geom.hasEOL
  9467. };
  9468. task._textDivs.push(textDiv);
  9469. const tx = _util.Util.transform(task._viewport.transform, geom.transform);
  9470. let angle = Math.atan2(tx[1], tx[0]);
  9471. const style = styles[geom.fontName];
  9472. if (style.vertical) {
  9473. angle += Math.PI / 2;
  9474. }
  9475. const fontHeight = Math.hypot(tx[2], tx[3]);
  9476. const fontAscent = fontHeight * getAscent(style.fontFamily, ctx);
  9477. let left, top;
  9478. if (angle === 0) {
  9479. left = tx[4];
  9480. top = tx[5] - fontAscent;
  9481. } else {
  9482. left = tx[4] + fontAscent * Math.sin(angle);
  9483. top = tx[5] - fontAscent * Math.cos(angle);
  9484. }
  9485. textDiv.style.left = `${left}px`;
  9486. textDiv.style.top = `${top}px`;
  9487. textDiv.style.fontSize = `${fontHeight}px`;
  9488. textDiv.style.fontFamily = style.fontFamily;
  9489. textDiv.setAttribute("role", "presentation");
  9490. textDiv.textContent = geom.str;
  9491. textDiv.dir = geom.dir;
  9492. if (task._fontInspectorEnabled) {
  9493. textDiv.dataset.fontName = geom.fontName;
  9494. }
  9495. if (angle !== 0) {
  9496. textDivProperties.angle = angle * (180 / Math.PI);
  9497. }
  9498. let shouldScaleText = false;
  9499. if (geom.str.length > 1 || task._enhanceTextSelection && AllWhitespaceRegexp.test(geom.str)) {
  9500. shouldScaleText = true;
  9501. } else if (geom.str !== " " && geom.transform[0] !== geom.transform[3]) {
  9502. const absScaleX = Math.abs(geom.transform[0]),
  9503. absScaleY = Math.abs(geom.transform[3]);
  9504. if (absScaleX !== absScaleY && Math.max(absScaleX, absScaleY) / Math.min(absScaleX, absScaleY) > 1.5) {
  9505. shouldScaleText = true;
  9506. }
  9507. }
  9508. if (shouldScaleText) {
  9509. if (style.vertical) {
  9510. textDivProperties.canvasWidth = geom.height * task._viewport.scale;
  9511. } else {
  9512. textDivProperties.canvasWidth = geom.width * task._viewport.scale;
  9513. }
  9514. }
  9515. task._textDivProperties.set(textDiv, textDivProperties);
  9516. if (task._textContentStream) {
  9517. task._layoutText(textDiv);
  9518. }
  9519. if (task._enhanceTextSelection && textDivProperties.hasText) {
  9520. let angleCos = 1,
  9521. angleSin = 0;
  9522. if (angle !== 0) {
  9523. angleCos = Math.cos(angle);
  9524. angleSin = Math.sin(angle);
  9525. }
  9526. const divWidth = (style.vertical ? geom.height : geom.width) * task._viewport.scale;
  9527. const divHeight = fontHeight;
  9528. let m, b;
  9529. if (angle !== 0) {
  9530. m = [angleCos, angleSin, -angleSin, angleCos, left, top];
  9531. b = _util.Util.getAxialAlignedBoundingBox([0, 0, divWidth, divHeight], m);
  9532. } else {
  9533. b = [left, top, left + divWidth, top + divHeight];
  9534. }
  9535. task._bounds.push({
  9536. left: b[0],
  9537. top: b[1],
  9538. right: b[2],
  9539. bottom: b[3],
  9540. div: textDiv,
  9541. size: [divWidth, divHeight],
  9542. m
  9543. });
  9544. }
  9545. }
  9546. function render(task) {
  9547. if (task._canceled) {
  9548. return;
  9549. }
  9550. const textDivs = task._textDivs;
  9551. const capability = task._capability;
  9552. const textDivsLength = textDivs.length;
  9553. if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
  9554. task._renderingDone = true;
  9555. capability.resolve();
  9556. return;
  9557. }
  9558. if (!task._textContentStream) {
  9559. for (let i = 0; i < textDivsLength; i++) {
  9560. task._layoutText(textDivs[i]);
  9561. }
  9562. }
  9563. task._renderingDone = true;
  9564. capability.resolve();
  9565. }
  9566. function findPositiveMin(ts, offset, count) {
  9567. let result = 0;
  9568. for (let i = 0; i < count; i++) {
  9569. const t = ts[offset++];
  9570. if (t > 0) {
  9571. result = result ? Math.min(t, result) : t;
  9572. }
  9573. }
  9574. return result;
  9575. }
  9576. function expand(task) {
  9577. const bounds = task._bounds;
  9578. const viewport = task._viewport;
  9579. const expanded = expandBounds(viewport.width, viewport.height, bounds);
  9580. for (let i = 0; i < expanded.length; i++) {
  9581. const div = bounds[i].div;
  9582. const divProperties = task._textDivProperties.get(div);
  9583. if (divProperties.angle === 0) {
  9584. divProperties.paddingLeft = bounds[i].left - expanded[i].left;
  9585. divProperties.paddingTop = bounds[i].top - expanded[i].top;
  9586. divProperties.paddingRight = expanded[i].right - bounds[i].right;
  9587. divProperties.paddingBottom = expanded[i].bottom - bounds[i].bottom;
  9588. task._textDivProperties.set(div, divProperties);
  9589. continue;
  9590. }
  9591. const e = expanded[i],
  9592. b = bounds[i];
  9593. const m = b.m,
  9594. c = m[0],
  9595. s = m[1];
  9596. const points = [[0, 0], [0, b.size[1]], [b.size[0], 0], b.size];
  9597. const ts = new Float64Array(64);
  9598. for (let j = 0, jj = points.length; j < jj; j++) {
  9599. const t = _util.Util.applyTransform(points[j], m);
  9600. ts[j + 0] = c && (e.left - t[0]) / c;
  9601. ts[j + 4] = s && (e.top - t[1]) / s;
  9602. ts[j + 8] = c && (e.right - t[0]) / c;
  9603. ts[j + 12] = s && (e.bottom - t[1]) / s;
  9604. ts[j + 16] = s && (e.left - t[0]) / -s;
  9605. ts[j + 20] = c && (e.top - t[1]) / c;
  9606. ts[j + 24] = s && (e.right - t[0]) / -s;
  9607. ts[j + 28] = c && (e.bottom - t[1]) / c;
  9608. ts[j + 32] = c && (e.left - t[0]) / -c;
  9609. ts[j + 36] = s && (e.top - t[1]) / -s;
  9610. ts[j + 40] = c && (e.right - t[0]) / -c;
  9611. ts[j + 44] = s && (e.bottom - t[1]) / -s;
  9612. ts[j + 48] = s && (e.left - t[0]) / s;
  9613. ts[j + 52] = c && (e.top - t[1]) / -c;
  9614. ts[j + 56] = s && (e.right - t[0]) / s;
  9615. ts[j + 60] = c && (e.bottom - t[1]) / -c;
  9616. }
  9617. const boxScale = 1 + Math.min(Math.abs(c), Math.abs(s));
  9618. divProperties.paddingLeft = findPositiveMin(ts, 32, 16) / boxScale;
  9619. divProperties.paddingTop = findPositiveMin(ts, 48, 16) / boxScale;
  9620. divProperties.paddingRight = findPositiveMin(ts, 0, 16) / boxScale;
  9621. divProperties.paddingBottom = findPositiveMin(ts, 16, 16) / boxScale;
  9622. task._textDivProperties.set(div, divProperties);
  9623. }
  9624. }
  9625. function expandBounds(width, height, boxes) {
  9626. const bounds = boxes.map(function (box, i) {
  9627. return {
  9628. x1: box.left,
  9629. y1: box.top,
  9630. x2: box.right,
  9631. y2: box.bottom,
  9632. index: i,
  9633. x1New: undefined,
  9634. x2New: undefined
  9635. };
  9636. });
  9637. expandBoundsLTR(width, bounds);
  9638. const expanded = new Array(boxes.length);
  9639. for (const b of bounds) {
  9640. const i = b.index;
  9641. expanded[i] = {
  9642. left: b.x1New,
  9643. top: 0,
  9644. right: b.x2New,
  9645. bottom: 0
  9646. };
  9647. }
  9648. boxes.map(function (box, i) {
  9649. const e = expanded[i],
  9650. b = bounds[i];
  9651. b.x1 = box.top;
  9652. b.y1 = width - e.right;
  9653. b.x2 = box.bottom;
  9654. b.y2 = width - e.left;
  9655. b.index = i;
  9656. b.x1New = undefined;
  9657. b.x2New = undefined;
  9658. });
  9659. expandBoundsLTR(height, bounds);
  9660. for (const b of bounds) {
  9661. const i = b.index;
  9662. expanded[i].top = b.x1New;
  9663. expanded[i].bottom = b.x2New;
  9664. }
  9665. return expanded;
  9666. }
  9667. function expandBoundsLTR(width, bounds) {
  9668. bounds.sort(function (a, b) {
  9669. return a.x1 - b.x1 || a.index - b.index;
  9670. });
  9671. const fakeBoundary = {
  9672. x1: -Infinity,
  9673. y1: -Infinity,
  9674. x2: 0,
  9675. y2: Infinity,
  9676. index: -1,
  9677. x1New: 0,
  9678. x2New: 0
  9679. };
  9680. const horizon = [{
  9681. start: -Infinity,
  9682. end: Infinity,
  9683. boundary: fakeBoundary
  9684. }];
  9685. for (const boundary of bounds) {
  9686. let i = 0;
  9687. while (i < horizon.length && horizon[i].end <= boundary.y1) {
  9688. i++;
  9689. }
  9690. let j = horizon.length - 1;
  9691. while (j >= 0 && horizon[j].start >= boundary.y2) {
  9692. j--;
  9693. }
  9694. let horizonPart, affectedBoundary;
  9695. let q,
  9696. k,
  9697. maxXNew = -Infinity;
  9698. for (q = i; q <= j; q++) {
  9699. horizonPart = horizon[q];
  9700. affectedBoundary = horizonPart.boundary;
  9701. let xNew;
  9702. if (affectedBoundary.x2 > boundary.x1) {
  9703. xNew = affectedBoundary.index > boundary.index ? affectedBoundary.x1New : boundary.x1;
  9704. } else if (affectedBoundary.x2New === undefined) {
  9705. xNew = (affectedBoundary.x2 + boundary.x1) / 2;
  9706. } else {
  9707. xNew = affectedBoundary.x2New;
  9708. }
  9709. if (xNew > maxXNew) {
  9710. maxXNew = xNew;
  9711. }
  9712. }
  9713. boundary.x1New = maxXNew;
  9714. for (q = i; q <= j; q++) {
  9715. horizonPart = horizon[q];
  9716. affectedBoundary = horizonPart.boundary;
  9717. if (affectedBoundary.x2New === undefined) {
  9718. if (affectedBoundary.x2 > boundary.x1) {
  9719. if (affectedBoundary.index > boundary.index) {
  9720. affectedBoundary.x2New = affectedBoundary.x2;
  9721. }
  9722. } else {
  9723. affectedBoundary.x2New = maxXNew;
  9724. }
  9725. } else if (affectedBoundary.x2New > maxXNew) {
  9726. affectedBoundary.x2New = Math.max(maxXNew, affectedBoundary.x2);
  9727. }
  9728. }
  9729. const changedHorizon = [];
  9730. let lastBoundary = null;
  9731. for (q = i; q <= j; q++) {
  9732. horizonPart = horizon[q];
  9733. affectedBoundary = horizonPart.boundary;
  9734. const useBoundary = affectedBoundary.x2 > boundary.x2 ? affectedBoundary : boundary;
  9735. if (lastBoundary === useBoundary) {
  9736. changedHorizon[changedHorizon.length - 1].end = horizonPart.end;
  9737. } else {
  9738. changedHorizon.push({
  9739. start: horizonPart.start,
  9740. end: horizonPart.end,
  9741. boundary: useBoundary
  9742. });
  9743. lastBoundary = useBoundary;
  9744. }
  9745. }
  9746. if (horizon[i].start < boundary.y1) {
  9747. changedHorizon[0].start = boundary.y1;
  9748. changedHorizon.unshift({
  9749. start: horizon[i].start,
  9750. end: boundary.y1,
  9751. boundary: horizon[i].boundary
  9752. });
  9753. }
  9754. if (boundary.y2 < horizon[j].end) {
  9755. changedHorizon[changedHorizon.length - 1].end = boundary.y2;
  9756. changedHorizon.push({
  9757. start: boundary.y2,
  9758. end: horizon[j].end,
  9759. boundary: horizon[j].boundary
  9760. });
  9761. }
  9762. for (q = i; q <= j; q++) {
  9763. horizonPart = horizon[q];
  9764. affectedBoundary = horizonPart.boundary;
  9765. if (affectedBoundary.x2New !== undefined) {
  9766. continue;
  9767. }
  9768. let used = false;
  9769. for (k = i - 1; !used && k >= 0 && horizon[k].start >= affectedBoundary.y1; k--) {
  9770. used = horizon[k].boundary === affectedBoundary;
  9771. }
  9772. for (k = j + 1; !used && k < horizon.length && horizon[k].end <= affectedBoundary.y2; k++) {
  9773. used = horizon[k].boundary === affectedBoundary;
  9774. }
  9775. for (k = 0; !used && k < changedHorizon.length; k++) {
  9776. used = changedHorizon[k].boundary === affectedBoundary;
  9777. }
  9778. if (!used) {
  9779. affectedBoundary.x2New = maxXNew;
  9780. }
  9781. }
  9782. Array.prototype.splice.apply(horizon, [i, j - i + 1].concat(changedHorizon));
  9783. }
  9784. for (const horizonPart of horizon) {
  9785. const affectedBoundary = horizonPart.boundary;
  9786. if (affectedBoundary.x2New === undefined) {
  9787. affectedBoundary.x2New = Math.max(width, affectedBoundary.x2);
  9788. }
  9789. }
  9790. }
  9791. class TextLayerRenderTask {
  9792. constructor({
  9793. textContent,
  9794. textContentStream,
  9795. container,
  9796. viewport,
  9797. textDivs,
  9798. textContentItemsStr,
  9799. enhanceTextSelection
  9800. }) {
  9801. this._textContent = textContent;
  9802. this._textContentStream = textContentStream;
  9803. this._container = container;
  9804. this._document = container.ownerDocument;
  9805. this._viewport = viewport;
  9806. this._textDivs = textDivs || [];
  9807. this._textContentItemsStr = textContentItemsStr || [];
  9808. this._enhanceTextSelection = !!enhanceTextSelection;
  9809. this._fontInspectorEnabled = !!globalThis.FontInspector?.enabled;
  9810. this._reader = null;
  9811. this._layoutTextLastFontSize = null;
  9812. this._layoutTextLastFontFamily = null;
  9813. this._layoutTextCtx = null;
  9814. this._textDivProperties = new WeakMap();
  9815. this._renderingDone = false;
  9816. this._canceled = false;
  9817. this._capability = (0, _util.createPromiseCapability)();
  9818. this._renderTimer = null;
  9819. this._bounds = [];
  9820. this._capability.promise.finally(() => {
  9821. if (!this._enhanceTextSelection) {
  9822. this._textDivProperties = null;
  9823. }
  9824. if (this._layoutTextCtx) {
  9825. this._layoutTextCtx.canvas.width = 0;
  9826. this._layoutTextCtx.canvas.height = 0;
  9827. this._layoutTextCtx = null;
  9828. }
  9829. }).catch(() => {});
  9830. }
  9831. get promise() {
  9832. return this._capability.promise;
  9833. }
  9834. cancel() {
  9835. this._canceled = true;
  9836. if (this._reader) {
  9837. this._reader.cancel(new _util.AbortException("TextLayer task cancelled.")).catch(() => {});
  9838. this._reader = null;
  9839. }
  9840. if (this._renderTimer !== null) {
  9841. clearTimeout(this._renderTimer);
  9842. this._renderTimer = null;
  9843. }
  9844. this._capability.reject(new Error("TextLayer task cancelled."));
  9845. }
  9846. _processItems(items, styleCache) {
  9847. for (let i = 0, len = items.length; i < len; i++) {
  9848. if (items[i].str === undefined) {
  9849. if (items[i].type === "beginMarkedContentProps" || items[i].type === "beginMarkedContent") {
  9850. const parent = this._container;
  9851. this._container = document.createElement("span");
  9852. this._container.classList.add("markedContent");
  9853. if (items[i].id !== null) {
  9854. this._container.setAttribute("id", `${items[i].id}`);
  9855. }
  9856. parent.appendChild(this._container);
  9857. } else if (items[i].type === "endMarkedContent") {
  9858. this._container = this._container.parentNode;
  9859. }
  9860. continue;
  9861. }
  9862. this._textContentItemsStr.push(items[i].str);
  9863. appendText(this, items[i], styleCache, this._layoutTextCtx);
  9864. }
  9865. }
  9866. _layoutText(textDiv) {
  9867. const textDivProperties = this._textDivProperties.get(textDiv);
  9868. let transform = "";
  9869. if (textDivProperties.canvasWidth !== 0 && textDivProperties.hasText) {
  9870. const {
  9871. fontSize,
  9872. fontFamily
  9873. } = textDiv.style;
  9874. if (fontSize !== this._layoutTextLastFontSize || fontFamily !== this._layoutTextLastFontFamily) {
  9875. this._layoutTextCtx.font = `${fontSize} ${fontFamily}`;
  9876. this._layoutTextLastFontSize = fontSize;
  9877. this._layoutTextLastFontFamily = fontFamily;
  9878. }
  9879. const {
  9880. width
  9881. } = this._layoutTextCtx.measureText(textDiv.textContent);
  9882. if (width > 0) {
  9883. const scale = textDivProperties.canvasWidth / width;
  9884. if (this._enhanceTextSelection) {
  9885. textDivProperties.scale = scale;
  9886. }
  9887. transform = `scaleX(${scale})`;
  9888. }
  9889. }
  9890. if (textDivProperties.angle !== 0) {
  9891. transform = `rotate(${textDivProperties.angle}deg) ${transform}`;
  9892. }
  9893. if (transform.length > 0) {
  9894. if (this._enhanceTextSelection) {
  9895. textDivProperties.originalTransform = transform;
  9896. }
  9897. textDiv.style.transform = transform;
  9898. }
  9899. if (textDivProperties.hasText) {
  9900. this._container.appendChild(textDiv);
  9901. }
  9902. if (textDivProperties.hasEOL) {
  9903. const br = document.createElement("br");
  9904. br.setAttribute("role", "presentation");
  9905. this._container.appendChild(br);
  9906. }
  9907. }
  9908. _render(timeout = 0) {
  9909. const capability = (0, _util.createPromiseCapability)();
  9910. let styleCache = Object.create(null);
  9911. const canvas = this._document.createElement("canvas");
  9912. canvas.height = canvas.width = DEFAULT_FONT_SIZE;
  9913. canvas.mozOpaque = true;
  9914. this._layoutTextCtx = canvas.getContext("2d", {
  9915. alpha: false
  9916. });
  9917. if (this._textContent) {
  9918. const textItems = this._textContent.items;
  9919. const textStyles = this._textContent.styles;
  9920. this._processItems(textItems, textStyles);
  9921. capability.resolve();
  9922. } else if (this._textContentStream) {
  9923. const pump = () => {
  9924. this._reader.read().then(({
  9925. value,
  9926. done
  9927. }) => {
  9928. if (done) {
  9929. capability.resolve();
  9930. return;
  9931. }
  9932. Object.assign(styleCache, value.styles);
  9933. this._processItems(value.items, styleCache);
  9934. pump();
  9935. }, capability.reject);
  9936. };
  9937. this._reader = this._textContentStream.getReader();
  9938. pump();
  9939. } else {
  9940. throw new Error('Neither "textContent" nor "textContentStream" parameters specified.');
  9941. }
  9942. capability.promise.then(() => {
  9943. styleCache = null;
  9944. if (!timeout) {
  9945. render(this);
  9946. } else {
  9947. this._renderTimer = setTimeout(() => {
  9948. render(this);
  9949. this._renderTimer = null;
  9950. }, timeout);
  9951. }
  9952. }, this._capability.reject);
  9953. }
  9954. expandTextDivs(expandDivs = false) {
  9955. if (!this._enhanceTextSelection || !this._renderingDone) {
  9956. return;
  9957. }
  9958. if (this._bounds !== null) {
  9959. expand(this);
  9960. this._bounds = null;
  9961. }
  9962. const transformBuf = [],
  9963. paddingBuf = [];
  9964. for (let i = 0, ii = this._textDivs.length; i < ii; i++) {
  9965. const div = this._textDivs[i];
  9966. const divProps = this._textDivProperties.get(div);
  9967. if (!divProps.hasText) {
  9968. continue;
  9969. }
  9970. if (expandDivs) {
  9971. transformBuf.length = 0;
  9972. paddingBuf.length = 0;
  9973. if (divProps.originalTransform) {
  9974. transformBuf.push(divProps.originalTransform);
  9975. }
  9976. if (divProps.paddingTop > 0) {
  9977. paddingBuf.push(`${divProps.paddingTop}px`);
  9978. transformBuf.push(`translateY(${-divProps.paddingTop}px)`);
  9979. } else {
  9980. paddingBuf.push(0);
  9981. }
  9982. if (divProps.paddingRight > 0) {
  9983. paddingBuf.push(`${divProps.paddingRight / divProps.scale}px`);
  9984. } else {
  9985. paddingBuf.push(0);
  9986. }
  9987. if (divProps.paddingBottom > 0) {
  9988. paddingBuf.push(`${divProps.paddingBottom}px`);
  9989. } else {
  9990. paddingBuf.push(0);
  9991. }
  9992. if (divProps.paddingLeft > 0) {
  9993. paddingBuf.push(`${divProps.paddingLeft / divProps.scale}px`);
  9994. transformBuf.push(`translateX(${-divProps.paddingLeft / divProps.scale}px)`);
  9995. } else {
  9996. paddingBuf.push(0);
  9997. }
  9998. div.style.padding = paddingBuf.join(" ");
  9999. if (transformBuf.length) {
  10000. div.style.transform = transformBuf.join(" ");
  10001. }
  10002. } else {
  10003. div.style.padding = null;
  10004. div.style.transform = divProps.originalTransform;
  10005. }
  10006. }
  10007. }
  10008. }
  10009. function renderTextLayer(renderParameters) {
  10010. const task = new TextLayerRenderTask({
  10011. textContent: renderParameters.textContent,
  10012. textContentStream: renderParameters.textContentStream,
  10013. container: renderParameters.container,
  10014. viewport: renderParameters.viewport,
  10015. textDivs: renderParameters.textDivs,
  10016. textContentItemsStr: renderParameters.textContentItemsStr,
  10017. enhanceTextSelection: renderParameters.enhanceTextSelection
  10018. });
  10019. task._render(renderParameters.timeout);
  10020. return task;
  10021. }
  10022. /***/ }),
  10023. /* 22 */
  10024. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  10025. Object.defineProperty(exports, "__esModule", ({
  10026. value: true
  10027. }));
  10028. exports.SVGGraphics = void 0;
  10029. var _util = __w_pdfjs_require__(1);
  10030. var _display_utils = __w_pdfjs_require__(5);
  10031. var _is_node = __w_pdfjs_require__(3);
  10032. let SVGGraphics = class {
  10033. constructor() {
  10034. (0, _util.unreachable)("Not implemented: SVGGraphics");
  10035. }
  10036. };
  10037. exports.SVGGraphics = SVGGraphics;
  10038. {
  10039. const SVG_DEFAULTS = {
  10040. fontStyle: "normal",
  10041. fontWeight: "normal",
  10042. fillColor: "#000000"
  10043. };
  10044. const XML_NS = "http://www.w3.org/XML/1998/namespace";
  10045. const XLINK_NS = "http://www.w3.org/1999/xlink";
  10046. const LINE_CAP_STYLES = ["butt", "round", "square"];
  10047. const LINE_JOIN_STYLES = ["miter", "round", "bevel"];
  10048. const createObjectURL = function (data, contentType = "", forceDataSchema = false) {
  10049. if (URL.createObjectURL && typeof Blob !== "undefined" && !forceDataSchema) {
  10050. return URL.createObjectURL(new Blob([data], {
  10051. type: contentType
  10052. }));
  10053. }
  10054. const digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  10055. let buffer = `data:${contentType};base64,`;
  10056. for (let i = 0, ii = data.length; i < ii; i += 3) {
  10057. const b1 = data[i] & 0xff;
  10058. const b2 = data[i + 1] & 0xff;
  10059. const b3 = data[i + 2] & 0xff;
  10060. const d1 = b1 >> 2,
  10061. d2 = (b1 & 3) << 4 | b2 >> 4;
  10062. const d3 = i + 1 < ii ? (b2 & 0xf) << 2 | b3 >> 6 : 64;
  10063. const d4 = i + 2 < ii ? b3 & 0x3f : 64;
  10064. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  10065. }
  10066. return buffer;
  10067. };
  10068. const convertImgDataToPng = function () {
  10069. const PNG_HEADER = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  10070. const CHUNK_WRAPPER_SIZE = 12;
  10071. const crcTable = new Int32Array(256);
  10072. for (let i = 0; i < 256; i++) {
  10073. let c = i;
  10074. for (let h = 0; h < 8; h++) {
  10075. if (c & 1) {
  10076. c = 0xedb88320 ^ c >> 1 & 0x7fffffff;
  10077. } else {
  10078. c = c >> 1 & 0x7fffffff;
  10079. }
  10080. }
  10081. crcTable[i] = c;
  10082. }
  10083. function crc32(data, start, end) {
  10084. let crc = -1;
  10085. for (let i = start; i < end; i++) {
  10086. const a = (crc ^ data[i]) & 0xff;
  10087. const b = crcTable[a];
  10088. crc = crc >>> 8 ^ b;
  10089. }
  10090. return crc ^ -1;
  10091. }
  10092. function writePngChunk(type, body, data, offset) {
  10093. let p = offset;
  10094. const len = body.length;
  10095. data[p] = len >> 24 & 0xff;
  10096. data[p + 1] = len >> 16 & 0xff;
  10097. data[p + 2] = len >> 8 & 0xff;
  10098. data[p + 3] = len & 0xff;
  10099. p += 4;
  10100. data[p] = type.charCodeAt(0) & 0xff;
  10101. data[p + 1] = type.charCodeAt(1) & 0xff;
  10102. data[p + 2] = type.charCodeAt(2) & 0xff;
  10103. data[p + 3] = type.charCodeAt(3) & 0xff;
  10104. p += 4;
  10105. data.set(body, p);
  10106. p += body.length;
  10107. const crc = crc32(data, offset + 4, p);
  10108. data[p] = crc >> 24 & 0xff;
  10109. data[p + 1] = crc >> 16 & 0xff;
  10110. data[p + 2] = crc >> 8 & 0xff;
  10111. data[p + 3] = crc & 0xff;
  10112. }
  10113. function adler32(data, start, end) {
  10114. let a = 1;
  10115. let b = 0;
  10116. for (let i = start; i < end; ++i) {
  10117. a = (a + (data[i] & 0xff)) % 65521;
  10118. b = (b + a) % 65521;
  10119. }
  10120. return b << 16 | a;
  10121. }
  10122. function deflateSync(literals) {
  10123. if (!_is_node.isNodeJS) {
  10124. return deflateSyncUncompressed(literals);
  10125. }
  10126. try {
  10127. let input;
  10128. if (parseInt(process.versions.node) >= 8) {
  10129. input = literals;
  10130. } else {
  10131. input = Buffer.from(literals);
  10132. }
  10133. const output = require("zlib").deflateSync(input, {
  10134. level: 9
  10135. });
  10136. return output instanceof Uint8Array ? output : new Uint8Array(output);
  10137. } catch (e) {
  10138. (0, _util.warn)("Not compressing PNG because zlib.deflateSync is unavailable: " + e);
  10139. }
  10140. return deflateSyncUncompressed(literals);
  10141. }
  10142. function deflateSyncUncompressed(literals) {
  10143. let len = literals.length;
  10144. const maxBlockLength = 0xffff;
  10145. const deflateBlocks = Math.ceil(len / maxBlockLength);
  10146. const idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  10147. let pi = 0;
  10148. idat[pi++] = 0x78;
  10149. idat[pi++] = 0x9c;
  10150. let pos = 0;
  10151. while (len > maxBlockLength) {
  10152. idat[pi++] = 0x00;
  10153. idat[pi++] = 0xff;
  10154. idat[pi++] = 0xff;
  10155. idat[pi++] = 0x00;
  10156. idat[pi++] = 0x00;
  10157. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  10158. pi += maxBlockLength;
  10159. pos += maxBlockLength;
  10160. len -= maxBlockLength;
  10161. }
  10162. idat[pi++] = 0x01;
  10163. idat[pi++] = len & 0xff;
  10164. idat[pi++] = len >> 8 & 0xff;
  10165. idat[pi++] = ~len & 0xffff & 0xff;
  10166. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  10167. idat.set(literals.subarray(pos), pi);
  10168. pi += literals.length - pos;
  10169. const adler = adler32(literals, 0, literals.length);
  10170. idat[pi++] = adler >> 24 & 0xff;
  10171. idat[pi++] = adler >> 16 & 0xff;
  10172. idat[pi++] = adler >> 8 & 0xff;
  10173. idat[pi++] = adler & 0xff;
  10174. return idat;
  10175. }
  10176. function encode(imgData, kind, forceDataSchema, isMask) {
  10177. const width = imgData.width;
  10178. const height = imgData.height;
  10179. let bitDepth, colorType, lineSize;
  10180. const bytes = imgData.data;
  10181. switch (kind) {
  10182. case _util.ImageKind.GRAYSCALE_1BPP:
  10183. colorType = 0;
  10184. bitDepth = 1;
  10185. lineSize = width + 7 >> 3;
  10186. break;
  10187. case _util.ImageKind.RGB_24BPP:
  10188. colorType = 2;
  10189. bitDepth = 8;
  10190. lineSize = width * 3;
  10191. break;
  10192. case _util.ImageKind.RGBA_32BPP:
  10193. colorType = 6;
  10194. bitDepth = 8;
  10195. lineSize = width * 4;
  10196. break;
  10197. default:
  10198. throw new Error("invalid format");
  10199. }
  10200. const literals = new Uint8Array((1 + lineSize) * height);
  10201. let offsetLiterals = 0,
  10202. offsetBytes = 0;
  10203. for (let y = 0; y < height; ++y) {
  10204. literals[offsetLiterals++] = 0;
  10205. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize), offsetLiterals);
  10206. offsetBytes += lineSize;
  10207. offsetLiterals += lineSize;
  10208. }
  10209. if (kind === _util.ImageKind.GRAYSCALE_1BPP && isMask) {
  10210. offsetLiterals = 0;
  10211. for (let y = 0; y < height; y++) {
  10212. offsetLiterals++;
  10213. for (let i = 0; i < lineSize; i++) {
  10214. literals[offsetLiterals++] ^= 0xff;
  10215. }
  10216. }
  10217. }
  10218. 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]);
  10219. const idat = deflateSync(literals);
  10220. const pngLength = PNG_HEADER.length + CHUNK_WRAPPER_SIZE * 3 + ihdr.length + idat.length;
  10221. const data = new Uint8Array(pngLength);
  10222. let offset = 0;
  10223. data.set(PNG_HEADER, offset);
  10224. offset += PNG_HEADER.length;
  10225. writePngChunk("IHDR", ihdr, data, offset);
  10226. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  10227. writePngChunk("IDATA", idat, data, offset);
  10228. offset += CHUNK_WRAPPER_SIZE + idat.length;
  10229. writePngChunk("IEND", new Uint8Array(0), data, offset);
  10230. return createObjectURL(data, "image/png", forceDataSchema);
  10231. }
  10232. return function convertImgDataToPng(imgData, forceDataSchema, isMask) {
  10233. const kind = imgData.kind === undefined ? _util.ImageKind.GRAYSCALE_1BPP : imgData.kind;
  10234. return encode(imgData, kind, forceDataSchema, isMask);
  10235. };
  10236. }();
  10237. class SVGExtraState {
  10238. constructor() {
  10239. this.fontSizeScale = 1;
  10240. this.fontWeight = SVG_DEFAULTS.fontWeight;
  10241. this.fontSize = 0;
  10242. this.textMatrix = _util.IDENTITY_MATRIX;
  10243. this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
  10244. this.leading = 0;
  10245. this.textRenderingMode = _util.TextRenderingMode.FILL;
  10246. this.textMatrixScale = 1;
  10247. this.x = 0;
  10248. this.y = 0;
  10249. this.lineX = 0;
  10250. this.lineY = 0;
  10251. this.charSpacing = 0;
  10252. this.wordSpacing = 0;
  10253. this.textHScale = 1;
  10254. this.textRise = 0;
  10255. this.fillColor = SVG_DEFAULTS.fillColor;
  10256. this.strokeColor = "#000000";
  10257. this.fillAlpha = 1;
  10258. this.strokeAlpha = 1;
  10259. this.lineWidth = 1;
  10260. this.lineJoin = "";
  10261. this.lineCap = "";
  10262. this.miterLimit = 0;
  10263. this.dashArray = [];
  10264. this.dashPhase = 0;
  10265. this.dependencies = [];
  10266. this.activeClipUrl = null;
  10267. this.clipGroup = null;
  10268. this.maskId = "";
  10269. }
  10270. clone() {
  10271. return Object.create(this);
  10272. }
  10273. setCurrentPoint(x, y) {
  10274. this.x = x;
  10275. this.y = y;
  10276. }
  10277. }
  10278. function opListToTree(opList) {
  10279. let opTree = [];
  10280. const tmp = [];
  10281. for (const opListElement of opList) {
  10282. if (opListElement.fn === "save") {
  10283. opTree.push({
  10284. fnId: 92,
  10285. fn: "group",
  10286. items: []
  10287. });
  10288. tmp.push(opTree);
  10289. opTree = opTree[opTree.length - 1].items;
  10290. continue;
  10291. }
  10292. if (opListElement.fn === "restore") {
  10293. opTree = tmp.pop();
  10294. } else {
  10295. opTree.push(opListElement);
  10296. }
  10297. }
  10298. return opTree;
  10299. }
  10300. function pf(value) {
  10301. if (Number.isInteger(value)) {
  10302. return value.toString();
  10303. }
  10304. const s = value.toFixed(10);
  10305. let i = s.length - 1;
  10306. if (s[i] !== "0") {
  10307. return s;
  10308. }
  10309. do {
  10310. i--;
  10311. } while (s[i] === "0");
  10312. return s.substring(0, s[i] === "." ? i : i + 1);
  10313. }
  10314. function pm(m) {
  10315. if (m[4] === 0 && m[5] === 0) {
  10316. if (m[1] === 0 && m[2] === 0) {
  10317. if (m[0] === 1 && m[3] === 1) {
  10318. return "";
  10319. }
  10320. return `scale(${pf(m[0])} ${pf(m[3])})`;
  10321. }
  10322. if (m[0] === m[3] && m[1] === -m[2]) {
  10323. const a = Math.acos(m[0]) * 180 / Math.PI;
  10324. return `rotate(${pf(a)})`;
  10325. }
  10326. } else {
  10327. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  10328. return `translate(${pf(m[4])} ${pf(m[5])})`;
  10329. }
  10330. }
  10331. return `matrix(${pf(m[0])} ${pf(m[1])} ${pf(m[2])} ${pf(m[3])} ${pf(m[4])} ` + `${pf(m[5])})`;
  10332. }
  10333. let clipCount = 0;
  10334. let maskCount = 0;
  10335. let shadingCount = 0;
  10336. exports.SVGGraphics = SVGGraphics = class {
  10337. constructor(commonObjs, objs, forceDataSchema = false) {
  10338. this.svgFactory = new _display_utils.DOMSVGFactory();
  10339. this.current = new SVGExtraState();
  10340. this.transformMatrix = _util.IDENTITY_MATRIX;
  10341. this.transformStack = [];
  10342. this.extraStack = [];
  10343. this.commonObjs = commonObjs;
  10344. this.objs = objs;
  10345. this.pendingClip = null;
  10346. this.pendingEOFill = false;
  10347. this.embedFonts = false;
  10348. this.embeddedFonts = Object.create(null);
  10349. this.cssStyle = null;
  10350. this.forceDataSchema = !!forceDataSchema;
  10351. this._operatorIdMapping = [];
  10352. for (const op in _util.OPS) {
  10353. this._operatorIdMapping[_util.OPS[op]] = op;
  10354. }
  10355. }
  10356. save() {
  10357. this.transformStack.push(this.transformMatrix);
  10358. const old = this.current;
  10359. this.extraStack.push(old);
  10360. this.current = old.clone();
  10361. }
  10362. restore() {
  10363. this.transformMatrix = this.transformStack.pop();
  10364. this.current = this.extraStack.pop();
  10365. this.pendingClip = null;
  10366. this.tgrp = null;
  10367. }
  10368. group(items) {
  10369. this.save();
  10370. this.executeOpTree(items);
  10371. this.restore();
  10372. }
  10373. loadDependencies(operatorList) {
  10374. const fnArray = operatorList.fnArray;
  10375. const argsArray = operatorList.argsArray;
  10376. for (let i = 0, ii = fnArray.length; i < ii; i++) {
  10377. if (fnArray[i] !== _util.OPS.dependency) {
  10378. continue;
  10379. }
  10380. for (const obj of argsArray[i]) {
  10381. const objsPool = obj.startsWith("g_") ? this.commonObjs : this.objs;
  10382. const promise = new Promise(resolve => {
  10383. objsPool.get(obj, resolve);
  10384. });
  10385. this.current.dependencies.push(promise);
  10386. }
  10387. }
  10388. return Promise.all(this.current.dependencies);
  10389. }
  10390. transform(a, b, c, d, e, f) {
  10391. const transformMatrix = [a, b, c, d, e, f];
  10392. this.transformMatrix = _util.Util.transform(this.transformMatrix, transformMatrix);
  10393. this.tgrp = null;
  10394. }
  10395. getSVG(operatorList, viewport) {
  10396. this.viewport = viewport;
  10397. const svgElement = this._initialize(viewport);
  10398. return this.loadDependencies(operatorList).then(() => {
  10399. this.transformMatrix = _util.IDENTITY_MATRIX;
  10400. this.executeOpTree(this.convertOpList(operatorList));
  10401. return svgElement;
  10402. });
  10403. }
  10404. convertOpList(operatorList) {
  10405. const operatorIdMapping = this._operatorIdMapping;
  10406. const argsArray = operatorList.argsArray;
  10407. const fnArray = operatorList.fnArray;
  10408. const opList = [];
  10409. for (let i = 0, ii = fnArray.length; i < ii; i++) {
  10410. const fnId = fnArray[i];
  10411. opList.push({
  10412. fnId,
  10413. fn: operatorIdMapping[fnId],
  10414. args: argsArray[i]
  10415. });
  10416. }
  10417. return opListToTree(opList);
  10418. }
  10419. executeOpTree(opTree) {
  10420. for (const opTreeElement of opTree) {
  10421. const fn = opTreeElement.fn;
  10422. const fnId = opTreeElement.fnId;
  10423. const args = opTreeElement.args;
  10424. switch (fnId | 0) {
  10425. case _util.OPS.beginText:
  10426. this.beginText();
  10427. break;
  10428. case _util.OPS.dependency:
  10429. break;
  10430. case _util.OPS.setLeading:
  10431. this.setLeading(args);
  10432. break;
  10433. case _util.OPS.setLeadingMoveText:
  10434. this.setLeadingMoveText(args[0], args[1]);
  10435. break;
  10436. case _util.OPS.setFont:
  10437. this.setFont(args);
  10438. break;
  10439. case _util.OPS.showText:
  10440. this.showText(args[0]);
  10441. break;
  10442. case _util.OPS.showSpacedText:
  10443. this.showText(args[0]);
  10444. break;
  10445. case _util.OPS.endText:
  10446. this.endText();
  10447. break;
  10448. case _util.OPS.moveText:
  10449. this.moveText(args[0], args[1]);
  10450. break;
  10451. case _util.OPS.setCharSpacing:
  10452. this.setCharSpacing(args[0]);
  10453. break;
  10454. case _util.OPS.setWordSpacing:
  10455. this.setWordSpacing(args[0]);
  10456. break;
  10457. case _util.OPS.setHScale:
  10458. this.setHScale(args[0]);
  10459. break;
  10460. case _util.OPS.setTextMatrix:
  10461. this.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
  10462. break;
  10463. case _util.OPS.setTextRise:
  10464. this.setTextRise(args[0]);
  10465. break;
  10466. case _util.OPS.setTextRenderingMode:
  10467. this.setTextRenderingMode(args[0]);
  10468. break;
  10469. case _util.OPS.setLineWidth:
  10470. this.setLineWidth(args[0]);
  10471. break;
  10472. case _util.OPS.setLineJoin:
  10473. this.setLineJoin(args[0]);
  10474. break;
  10475. case _util.OPS.setLineCap:
  10476. this.setLineCap(args[0]);
  10477. break;
  10478. case _util.OPS.setMiterLimit:
  10479. this.setMiterLimit(args[0]);
  10480. break;
  10481. case _util.OPS.setFillRGBColor:
  10482. this.setFillRGBColor(args[0], args[1], args[2]);
  10483. break;
  10484. case _util.OPS.setStrokeRGBColor:
  10485. this.setStrokeRGBColor(args[0], args[1], args[2]);
  10486. break;
  10487. case _util.OPS.setStrokeColorN:
  10488. this.setStrokeColorN(args);
  10489. break;
  10490. case _util.OPS.setFillColorN:
  10491. this.setFillColorN(args);
  10492. break;
  10493. case _util.OPS.shadingFill:
  10494. this.shadingFill(args[0]);
  10495. break;
  10496. case _util.OPS.setDash:
  10497. this.setDash(args[0], args[1]);
  10498. break;
  10499. case _util.OPS.setRenderingIntent:
  10500. this.setRenderingIntent(args[0]);
  10501. break;
  10502. case _util.OPS.setFlatness:
  10503. this.setFlatness(args[0]);
  10504. break;
  10505. case _util.OPS.setGState:
  10506. this.setGState(args[0]);
  10507. break;
  10508. case _util.OPS.fill:
  10509. this.fill();
  10510. break;
  10511. case _util.OPS.eoFill:
  10512. this.eoFill();
  10513. break;
  10514. case _util.OPS.stroke:
  10515. this.stroke();
  10516. break;
  10517. case _util.OPS.fillStroke:
  10518. this.fillStroke();
  10519. break;
  10520. case _util.OPS.eoFillStroke:
  10521. this.eoFillStroke();
  10522. break;
  10523. case _util.OPS.clip:
  10524. this.clip("nonzero");
  10525. break;
  10526. case _util.OPS.eoClip:
  10527. this.clip("evenodd");
  10528. break;
  10529. case _util.OPS.paintSolidColorImageMask:
  10530. this.paintSolidColorImageMask();
  10531. break;
  10532. case _util.OPS.paintImageXObject:
  10533. this.paintImageXObject(args[0]);
  10534. break;
  10535. case _util.OPS.paintInlineImageXObject:
  10536. this.paintInlineImageXObject(args[0]);
  10537. break;
  10538. case _util.OPS.paintImageMaskXObject:
  10539. this.paintImageMaskXObject(args[0]);
  10540. break;
  10541. case _util.OPS.paintFormXObjectBegin:
  10542. this.paintFormXObjectBegin(args[0], args[1]);
  10543. break;
  10544. case _util.OPS.paintFormXObjectEnd:
  10545. this.paintFormXObjectEnd();
  10546. break;
  10547. case _util.OPS.closePath:
  10548. this.closePath();
  10549. break;
  10550. case _util.OPS.closeStroke:
  10551. this.closeStroke();
  10552. break;
  10553. case _util.OPS.closeFillStroke:
  10554. this.closeFillStroke();
  10555. break;
  10556. case _util.OPS.closeEOFillStroke:
  10557. this.closeEOFillStroke();
  10558. break;
  10559. case _util.OPS.nextLine:
  10560. this.nextLine();
  10561. break;
  10562. case _util.OPS.transform:
  10563. this.transform(args[0], args[1], args[2], args[3], args[4], args[5]);
  10564. break;
  10565. case _util.OPS.constructPath:
  10566. this.constructPath(args[0], args[1]);
  10567. break;
  10568. case _util.OPS.endPath:
  10569. this.endPath();
  10570. break;
  10571. case 92:
  10572. this.group(opTreeElement.items);
  10573. break;
  10574. default:
  10575. (0, _util.warn)(`Unimplemented operator ${fn}`);
  10576. break;
  10577. }
  10578. }
  10579. }
  10580. setWordSpacing(wordSpacing) {
  10581. this.current.wordSpacing = wordSpacing;
  10582. }
  10583. setCharSpacing(charSpacing) {
  10584. this.current.charSpacing = charSpacing;
  10585. }
  10586. nextLine() {
  10587. this.moveText(0, this.current.leading);
  10588. }
  10589. setTextMatrix(a, b, c, d, e, f) {
  10590. const current = this.current;
  10591. current.textMatrix = current.lineMatrix = [a, b, c, d, e, f];
  10592. current.textMatrixScale = Math.hypot(a, b);
  10593. current.x = current.lineX = 0;
  10594. current.y = current.lineY = 0;
  10595. current.xcoords = [];
  10596. current.ycoords = [];
  10597. current.tspan = this.svgFactory.createElement("svg:tspan");
  10598. current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
  10599. current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
  10600. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  10601. current.txtElement = this.svgFactory.createElement("svg:text");
  10602. current.txtElement.appendChild(current.tspan);
  10603. }
  10604. beginText() {
  10605. const current = this.current;
  10606. current.x = current.lineX = 0;
  10607. current.y = current.lineY = 0;
  10608. current.textMatrix = _util.IDENTITY_MATRIX;
  10609. current.lineMatrix = _util.IDENTITY_MATRIX;
  10610. current.textMatrixScale = 1;
  10611. current.tspan = this.svgFactory.createElement("svg:tspan");
  10612. current.txtElement = this.svgFactory.createElement("svg:text");
  10613. current.txtgrp = this.svgFactory.createElement("svg:g");
  10614. current.xcoords = [];
  10615. current.ycoords = [];
  10616. }
  10617. moveText(x, y) {
  10618. const current = this.current;
  10619. current.x = current.lineX += x;
  10620. current.y = current.lineY += y;
  10621. current.xcoords = [];
  10622. current.ycoords = [];
  10623. current.tspan = this.svgFactory.createElement("svg:tspan");
  10624. current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
  10625. current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
  10626. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  10627. }
  10628. showText(glyphs) {
  10629. const current = this.current;
  10630. const font = current.font;
  10631. const fontSize = current.fontSize;
  10632. if (fontSize === 0) {
  10633. return;
  10634. }
  10635. const fontSizeScale = current.fontSizeScale;
  10636. const charSpacing = current.charSpacing;
  10637. const wordSpacing = current.wordSpacing;
  10638. const fontDirection = current.fontDirection;
  10639. const textHScale = current.textHScale * fontDirection;
  10640. const vertical = font.vertical;
  10641. const spacingDir = vertical ? 1 : -1;
  10642. const defaultVMetrics = font.defaultVMetrics;
  10643. const widthAdvanceScale = fontSize * current.fontMatrix[0];
  10644. let x = 0;
  10645. for (const glyph of glyphs) {
  10646. if (glyph === null) {
  10647. x += fontDirection * wordSpacing;
  10648. continue;
  10649. } else if (typeof glyph === "number") {
  10650. x += spacingDir * glyph * fontSize / 1000;
  10651. continue;
  10652. }
  10653. const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  10654. const character = glyph.fontChar;
  10655. let scaledX, scaledY;
  10656. let width = glyph.width;
  10657. if (vertical) {
  10658. let vx;
  10659. const vmetric = glyph.vmetric || defaultVMetrics;
  10660. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  10661. vx = -vx * widthAdvanceScale;
  10662. const vy = vmetric[2] * widthAdvanceScale;
  10663. width = vmetric ? -vmetric[0] : width;
  10664. scaledX = vx / fontSizeScale;
  10665. scaledY = (x + vy) / fontSizeScale;
  10666. } else {
  10667. scaledX = x / fontSizeScale;
  10668. scaledY = 0;
  10669. }
  10670. if (glyph.isInFont || font.missingFile) {
  10671. current.xcoords.push(current.x + scaledX);
  10672. if (vertical) {
  10673. current.ycoords.push(-current.y + scaledY);
  10674. }
  10675. current.tspan.textContent += character;
  10676. } else {}
  10677. let charWidth;
  10678. if (vertical) {
  10679. charWidth = width * widthAdvanceScale - spacing * fontDirection;
  10680. } else {
  10681. charWidth = width * widthAdvanceScale + spacing * fontDirection;
  10682. }
  10683. x += charWidth;
  10684. }
  10685. current.tspan.setAttributeNS(null, "x", current.xcoords.map(pf).join(" "));
  10686. if (vertical) {
  10687. current.tspan.setAttributeNS(null, "y", current.ycoords.map(pf).join(" "));
  10688. } else {
  10689. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  10690. }
  10691. if (vertical) {
  10692. current.y -= x;
  10693. } else {
  10694. current.x += x * textHScale;
  10695. }
  10696. current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
  10697. current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
  10698. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  10699. current.tspan.setAttributeNS(null, "font-style", current.fontStyle);
  10700. }
  10701. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  10702. current.tspan.setAttributeNS(null, "font-weight", current.fontWeight);
  10703. }
  10704. const fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  10705. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  10706. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  10707. current.tspan.setAttributeNS(null, "fill", current.fillColor);
  10708. }
  10709. if (current.fillAlpha < 1) {
  10710. current.tspan.setAttributeNS(null, "fill-opacity", current.fillAlpha);
  10711. }
  10712. } else if (current.textRenderingMode === _util.TextRenderingMode.ADD_TO_PATH) {
  10713. current.tspan.setAttributeNS(null, "fill", "transparent");
  10714. } else {
  10715. current.tspan.setAttributeNS(null, "fill", "none");
  10716. }
  10717. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  10718. const lineWidthScale = 1 / (current.textMatrixScale || 1);
  10719. this._setStrokeAttributes(current.tspan, lineWidthScale);
  10720. }
  10721. let textMatrix = current.textMatrix;
  10722. if (current.textRise !== 0) {
  10723. textMatrix = textMatrix.slice();
  10724. textMatrix[5] += current.textRise;
  10725. }
  10726. current.txtElement.setAttributeNS(null, "transform", `${pm(textMatrix)} scale(${pf(textHScale)}, -1)`);
  10727. current.txtElement.setAttributeNS(XML_NS, "xml:space", "preserve");
  10728. current.txtElement.appendChild(current.tspan);
  10729. current.txtgrp.appendChild(current.txtElement);
  10730. this._ensureTransformGroup().appendChild(current.txtElement);
  10731. }
  10732. setLeadingMoveText(x, y) {
  10733. this.setLeading(-y);
  10734. this.moveText(x, y);
  10735. }
  10736. addFontStyle(fontObj) {
  10737. if (!fontObj.data) {
  10738. throw new Error("addFontStyle: No font data available, " + 'ensure that the "fontExtraProperties" API parameter is set.');
  10739. }
  10740. if (!this.cssStyle) {
  10741. this.cssStyle = this.svgFactory.createElement("svg:style");
  10742. this.cssStyle.setAttributeNS(null, "type", "text/css");
  10743. this.defs.appendChild(this.cssStyle);
  10744. }
  10745. const url = createObjectURL(fontObj.data, fontObj.mimetype, this.forceDataSchema);
  10746. this.cssStyle.textContent += `@font-face { font-family: "${fontObj.loadedName}";` + ` src: url(${url}); }\n`;
  10747. }
  10748. setFont(details) {
  10749. const current = this.current;
  10750. const fontObj = this.commonObjs.get(details[0]);
  10751. let size = details[1];
  10752. current.font = fontObj;
  10753. if (this.embedFonts && !fontObj.missingFile && !this.embeddedFonts[fontObj.loadedName]) {
  10754. this.addFontStyle(fontObj);
  10755. this.embeddedFonts[fontObj.loadedName] = fontObj;
  10756. }
  10757. current.fontMatrix = fontObj.fontMatrix || _util.FONT_IDENTITY_MATRIX;
  10758. let bold = "normal";
  10759. if (fontObj.black) {
  10760. bold = "900";
  10761. } else if (fontObj.bold) {
  10762. bold = "bold";
  10763. }
  10764. const italic = fontObj.italic ? "italic" : "normal";
  10765. if (size < 0) {
  10766. size = -size;
  10767. current.fontDirection = -1;
  10768. } else {
  10769. current.fontDirection = 1;
  10770. }
  10771. current.fontSize = size;
  10772. current.fontFamily = fontObj.loadedName;
  10773. current.fontWeight = bold;
  10774. current.fontStyle = italic;
  10775. current.tspan = this.svgFactory.createElement("svg:tspan");
  10776. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  10777. current.xcoords = [];
  10778. current.ycoords = [];
  10779. }
  10780. endText() {
  10781. const current = this.current;
  10782. if (current.textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG && current.txtElement?.hasChildNodes()) {
  10783. current.element = current.txtElement;
  10784. this.clip("nonzero");
  10785. this.endPath();
  10786. }
  10787. }
  10788. setLineWidth(width) {
  10789. if (width > 0) {
  10790. this.current.lineWidth = width;
  10791. }
  10792. }
  10793. setLineCap(style) {
  10794. this.current.lineCap = LINE_CAP_STYLES[style];
  10795. }
  10796. setLineJoin(style) {
  10797. this.current.lineJoin = LINE_JOIN_STYLES[style];
  10798. }
  10799. setMiterLimit(limit) {
  10800. this.current.miterLimit = limit;
  10801. }
  10802. setStrokeAlpha(strokeAlpha) {
  10803. this.current.strokeAlpha = strokeAlpha;
  10804. }
  10805. setStrokeRGBColor(r, g, b) {
  10806. this.current.strokeColor = _util.Util.makeHexColor(r, g, b);
  10807. }
  10808. setFillAlpha(fillAlpha) {
  10809. this.current.fillAlpha = fillAlpha;
  10810. }
  10811. setFillRGBColor(r, g, b) {
  10812. this.current.fillColor = _util.Util.makeHexColor(r, g, b);
  10813. this.current.tspan = this.svgFactory.createElement("svg:tspan");
  10814. this.current.xcoords = [];
  10815. this.current.ycoords = [];
  10816. }
  10817. setStrokeColorN(args) {
  10818. this.current.strokeColor = this._makeColorN_Pattern(args);
  10819. }
  10820. setFillColorN(args) {
  10821. this.current.fillColor = this._makeColorN_Pattern(args);
  10822. }
  10823. shadingFill(args) {
  10824. const width = this.viewport.width;
  10825. const height = this.viewport.height;
  10826. const inv = _util.Util.inverseTransform(this.transformMatrix);
  10827. const bl = _util.Util.applyTransform([0, 0], inv);
  10828. const br = _util.Util.applyTransform([0, height], inv);
  10829. const ul = _util.Util.applyTransform([width, 0], inv);
  10830. const ur = _util.Util.applyTransform([width, height], inv);
  10831. const x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  10832. const y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  10833. const x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  10834. const y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  10835. const rect = this.svgFactory.createElement("svg:rect");
  10836. rect.setAttributeNS(null, "x", x0);
  10837. rect.setAttributeNS(null, "y", y0);
  10838. rect.setAttributeNS(null, "width", x1 - x0);
  10839. rect.setAttributeNS(null, "height", y1 - y0);
  10840. rect.setAttributeNS(null, "fill", this._makeShadingPattern(args));
  10841. if (this.current.fillAlpha < 1) {
  10842. rect.setAttributeNS(null, "fill-opacity", this.current.fillAlpha);
  10843. }
  10844. this._ensureTransformGroup().appendChild(rect);
  10845. }
  10846. _makeColorN_Pattern(args) {
  10847. if (args[0] === "TilingPattern") {
  10848. return this._makeTilingPattern(args);
  10849. }
  10850. return this._makeShadingPattern(args);
  10851. }
  10852. _makeTilingPattern(args) {
  10853. const color = args[1];
  10854. const operatorList = args[2];
  10855. const matrix = args[3] || _util.IDENTITY_MATRIX;
  10856. const [x0, y0, x1, y1] = args[4];
  10857. const xstep = args[5];
  10858. const ystep = args[6];
  10859. const paintType = args[7];
  10860. const tilingId = `shading${shadingCount++}`;
  10861. const [tx0, ty0, tx1, ty1] = _util.Util.normalizeRect([..._util.Util.applyTransform([x0, y0], matrix), ..._util.Util.applyTransform([x1, y1], matrix)]);
  10862. const [xscale, yscale] = _util.Util.singularValueDecompose2dScale(matrix);
  10863. const txstep = xstep * xscale;
  10864. const tystep = ystep * yscale;
  10865. const tiling = this.svgFactory.createElement("svg:pattern");
  10866. tiling.setAttributeNS(null, "id", tilingId);
  10867. tiling.setAttributeNS(null, "patternUnits", "userSpaceOnUse");
  10868. tiling.setAttributeNS(null, "width", txstep);
  10869. tiling.setAttributeNS(null, "height", tystep);
  10870. tiling.setAttributeNS(null, "x", `${tx0}`);
  10871. tiling.setAttributeNS(null, "y", `${ty0}`);
  10872. const svg = this.svg;
  10873. const transformMatrix = this.transformMatrix;
  10874. const fillColor = this.current.fillColor;
  10875. const strokeColor = this.current.strokeColor;
  10876. const bbox = this.svgFactory.create(tx1 - tx0, ty1 - ty0);
  10877. this.svg = bbox;
  10878. this.transformMatrix = matrix;
  10879. if (paintType === 2) {
  10880. const cssColor = _util.Util.makeHexColor(...color);
  10881. this.current.fillColor = cssColor;
  10882. this.current.strokeColor = cssColor;
  10883. }
  10884. this.executeOpTree(this.convertOpList(operatorList));
  10885. this.svg = svg;
  10886. this.transformMatrix = transformMatrix;
  10887. this.current.fillColor = fillColor;
  10888. this.current.strokeColor = strokeColor;
  10889. tiling.appendChild(bbox.childNodes[0]);
  10890. this.defs.appendChild(tiling);
  10891. return `url(#${tilingId})`;
  10892. }
  10893. _makeShadingPattern(args) {
  10894. if (typeof args === "string") {
  10895. args = this.objs.get(args);
  10896. }
  10897. switch (args[0]) {
  10898. case "RadialAxial":
  10899. const shadingId = `shading${shadingCount++}`;
  10900. const colorStops = args[3];
  10901. let gradient;
  10902. switch (args[1]) {
  10903. case "axial":
  10904. const point0 = args[4];
  10905. const point1 = args[5];
  10906. gradient = this.svgFactory.createElement("svg:linearGradient");
  10907. gradient.setAttributeNS(null, "id", shadingId);
  10908. gradient.setAttributeNS(null, "gradientUnits", "userSpaceOnUse");
  10909. gradient.setAttributeNS(null, "x1", point0[0]);
  10910. gradient.setAttributeNS(null, "y1", point0[1]);
  10911. gradient.setAttributeNS(null, "x2", point1[0]);
  10912. gradient.setAttributeNS(null, "y2", point1[1]);
  10913. break;
  10914. case "radial":
  10915. const focalPoint = args[4];
  10916. const circlePoint = args[5];
  10917. const focalRadius = args[6];
  10918. const circleRadius = args[7];
  10919. gradient = this.svgFactory.createElement("svg:radialGradient");
  10920. gradient.setAttributeNS(null, "id", shadingId);
  10921. gradient.setAttributeNS(null, "gradientUnits", "userSpaceOnUse");
  10922. gradient.setAttributeNS(null, "cx", circlePoint[0]);
  10923. gradient.setAttributeNS(null, "cy", circlePoint[1]);
  10924. gradient.setAttributeNS(null, "r", circleRadius);
  10925. gradient.setAttributeNS(null, "fx", focalPoint[0]);
  10926. gradient.setAttributeNS(null, "fy", focalPoint[1]);
  10927. gradient.setAttributeNS(null, "fr", focalRadius);
  10928. break;
  10929. default:
  10930. throw new Error(`Unknown RadialAxial type: ${args[1]}`);
  10931. }
  10932. for (const colorStop of colorStops) {
  10933. const stop = this.svgFactory.createElement("svg:stop");
  10934. stop.setAttributeNS(null, "offset", colorStop[0]);
  10935. stop.setAttributeNS(null, "stop-color", colorStop[1]);
  10936. gradient.appendChild(stop);
  10937. }
  10938. this.defs.appendChild(gradient);
  10939. return `url(#${shadingId})`;
  10940. case "Mesh":
  10941. (0, _util.warn)("Unimplemented pattern Mesh");
  10942. return null;
  10943. case "Dummy":
  10944. return "hotpink";
  10945. default:
  10946. throw new Error(`Unknown IR type: ${args[0]}`);
  10947. }
  10948. }
  10949. setDash(dashArray, dashPhase) {
  10950. this.current.dashArray = dashArray;
  10951. this.current.dashPhase = dashPhase;
  10952. }
  10953. constructPath(ops, args) {
  10954. const current = this.current;
  10955. let x = current.x,
  10956. y = current.y;
  10957. let d = [];
  10958. let j = 0;
  10959. for (const op of ops) {
  10960. switch (op | 0) {
  10961. case _util.OPS.rectangle:
  10962. x = args[j++];
  10963. y = args[j++];
  10964. const width = args[j++];
  10965. const height = args[j++];
  10966. const xw = x + width;
  10967. const yh = y + height;
  10968. d.push("M", pf(x), pf(y), "L", pf(xw), pf(y), "L", pf(xw), pf(yh), "L", pf(x), pf(yh), "Z");
  10969. break;
  10970. case _util.OPS.moveTo:
  10971. x = args[j++];
  10972. y = args[j++];
  10973. d.push("M", pf(x), pf(y));
  10974. break;
  10975. case _util.OPS.lineTo:
  10976. x = args[j++];
  10977. y = args[j++];
  10978. d.push("L", pf(x), pf(y));
  10979. break;
  10980. case _util.OPS.curveTo:
  10981. x = args[j + 4];
  10982. y = args[j + 5];
  10983. d.push("C", pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]), pf(x), pf(y));
  10984. j += 6;
  10985. break;
  10986. case _util.OPS.curveTo2:
  10987. d.push("C", pf(x), pf(y), pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]));
  10988. x = args[j + 2];
  10989. y = args[j + 3];
  10990. j += 4;
  10991. break;
  10992. case _util.OPS.curveTo3:
  10993. x = args[j + 2];
  10994. y = args[j + 3];
  10995. d.push("C", pf(args[j]), pf(args[j + 1]), pf(x), pf(y), pf(x), pf(y));
  10996. j += 4;
  10997. break;
  10998. case _util.OPS.closePath:
  10999. d.push("Z");
  11000. break;
  11001. }
  11002. }
  11003. d = d.join(" ");
  11004. if (current.path && ops.length > 0 && ops[0] !== _util.OPS.rectangle && ops[0] !== _util.OPS.moveTo) {
  11005. d = current.path.getAttributeNS(null, "d") + d;
  11006. } else {
  11007. current.path = this.svgFactory.createElement("svg:path");
  11008. this._ensureTransformGroup().appendChild(current.path);
  11009. }
  11010. current.path.setAttributeNS(null, "d", d);
  11011. current.path.setAttributeNS(null, "fill", "none");
  11012. current.element = current.path;
  11013. current.setCurrentPoint(x, y);
  11014. }
  11015. endPath() {
  11016. const current = this.current;
  11017. current.path = null;
  11018. if (!this.pendingClip) {
  11019. return;
  11020. }
  11021. if (!current.element) {
  11022. this.pendingClip = null;
  11023. return;
  11024. }
  11025. const clipId = `clippath${clipCount++}`;
  11026. const clipPath = this.svgFactory.createElement("svg:clipPath");
  11027. clipPath.setAttributeNS(null, "id", clipId);
  11028. clipPath.setAttributeNS(null, "transform", pm(this.transformMatrix));
  11029. const clipElement = current.element.cloneNode(true);
  11030. if (this.pendingClip === "evenodd") {
  11031. clipElement.setAttributeNS(null, "clip-rule", "evenodd");
  11032. } else {
  11033. clipElement.setAttributeNS(null, "clip-rule", "nonzero");
  11034. }
  11035. this.pendingClip = null;
  11036. clipPath.appendChild(clipElement);
  11037. this.defs.appendChild(clipPath);
  11038. if (current.activeClipUrl) {
  11039. current.clipGroup = null;
  11040. for (const prev of this.extraStack) {
  11041. prev.clipGroup = null;
  11042. }
  11043. clipPath.setAttributeNS(null, "clip-path", current.activeClipUrl);
  11044. }
  11045. current.activeClipUrl = `url(#${clipId})`;
  11046. this.tgrp = null;
  11047. }
  11048. clip(type) {
  11049. this.pendingClip = type;
  11050. }
  11051. closePath() {
  11052. const current = this.current;
  11053. if (current.path) {
  11054. const d = `${current.path.getAttributeNS(null, "d")}Z`;
  11055. current.path.setAttributeNS(null, "d", d);
  11056. }
  11057. }
  11058. setLeading(leading) {
  11059. this.current.leading = -leading;
  11060. }
  11061. setTextRise(textRise) {
  11062. this.current.textRise = textRise;
  11063. }
  11064. setTextRenderingMode(textRenderingMode) {
  11065. this.current.textRenderingMode = textRenderingMode;
  11066. }
  11067. setHScale(scale) {
  11068. this.current.textHScale = scale / 100;
  11069. }
  11070. setRenderingIntent(intent) {}
  11071. setFlatness(flatness) {}
  11072. setGState(states) {
  11073. for (const [key, value] of states) {
  11074. switch (key) {
  11075. case "LW":
  11076. this.setLineWidth(value);
  11077. break;
  11078. case "LC":
  11079. this.setLineCap(value);
  11080. break;
  11081. case "LJ":
  11082. this.setLineJoin(value);
  11083. break;
  11084. case "ML":
  11085. this.setMiterLimit(value);
  11086. break;
  11087. case "D":
  11088. this.setDash(value[0], value[1]);
  11089. break;
  11090. case "RI":
  11091. this.setRenderingIntent(value);
  11092. break;
  11093. case "FL":
  11094. this.setFlatness(value);
  11095. break;
  11096. case "Font":
  11097. this.setFont(value);
  11098. break;
  11099. case "CA":
  11100. this.setStrokeAlpha(value);
  11101. break;
  11102. case "ca":
  11103. this.setFillAlpha(value);
  11104. break;
  11105. default:
  11106. (0, _util.warn)(`Unimplemented graphic state operator ${key}`);
  11107. break;
  11108. }
  11109. }
  11110. }
  11111. fill() {
  11112. const current = this.current;
  11113. if (current.element) {
  11114. current.element.setAttributeNS(null, "fill", current.fillColor);
  11115. current.element.setAttributeNS(null, "fill-opacity", current.fillAlpha);
  11116. this.endPath();
  11117. }
  11118. }
  11119. stroke() {
  11120. const current = this.current;
  11121. if (current.element) {
  11122. this._setStrokeAttributes(current.element);
  11123. current.element.setAttributeNS(null, "fill", "none");
  11124. this.endPath();
  11125. }
  11126. }
  11127. _setStrokeAttributes(element, lineWidthScale = 1) {
  11128. const current = this.current;
  11129. let dashArray = current.dashArray;
  11130. if (lineWidthScale !== 1 && dashArray.length > 0) {
  11131. dashArray = dashArray.map(function (value) {
  11132. return lineWidthScale * value;
  11133. });
  11134. }
  11135. element.setAttributeNS(null, "stroke", current.strokeColor);
  11136. element.setAttributeNS(null, "stroke-opacity", current.strokeAlpha);
  11137. element.setAttributeNS(null, "stroke-miterlimit", pf(current.miterLimit));
  11138. element.setAttributeNS(null, "stroke-linecap", current.lineCap);
  11139. element.setAttributeNS(null, "stroke-linejoin", current.lineJoin);
  11140. element.setAttributeNS(null, "stroke-width", pf(lineWidthScale * current.lineWidth) + "px");
  11141. element.setAttributeNS(null, "stroke-dasharray", dashArray.map(pf).join(" "));
  11142. element.setAttributeNS(null, "stroke-dashoffset", pf(lineWidthScale * current.dashPhase) + "px");
  11143. }
  11144. eoFill() {
  11145. if (this.current.element) {
  11146. this.current.element.setAttributeNS(null, "fill-rule", "evenodd");
  11147. }
  11148. this.fill();
  11149. }
  11150. fillStroke() {
  11151. this.stroke();
  11152. this.fill();
  11153. }
  11154. eoFillStroke() {
  11155. if (this.current.element) {
  11156. this.current.element.setAttributeNS(null, "fill-rule", "evenodd");
  11157. }
  11158. this.fillStroke();
  11159. }
  11160. closeStroke() {
  11161. this.closePath();
  11162. this.stroke();
  11163. }
  11164. closeFillStroke() {
  11165. this.closePath();
  11166. this.fillStroke();
  11167. }
  11168. closeEOFillStroke() {
  11169. this.closePath();
  11170. this.eoFillStroke();
  11171. }
  11172. paintSolidColorImageMask() {
  11173. const rect = this.svgFactory.createElement("svg:rect");
  11174. rect.setAttributeNS(null, "x", "0");
  11175. rect.setAttributeNS(null, "y", "0");
  11176. rect.setAttributeNS(null, "width", "1px");
  11177. rect.setAttributeNS(null, "height", "1px");
  11178. rect.setAttributeNS(null, "fill", this.current.fillColor);
  11179. this._ensureTransformGroup().appendChild(rect);
  11180. }
  11181. paintImageXObject(objId) {
  11182. const imgData = objId.startsWith("g_") ? this.commonObjs.get(objId) : this.objs.get(objId);
  11183. if (!imgData) {
  11184. (0, _util.warn)(`Dependent image with object ID ${objId} is not ready yet`);
  11185. return;
  11186. }
  11187. this.paintInlineImageXObject(imgData);
  11188. }
  11189. paintInlineImageXObject(imgData, mask) {
  11190. const width = imgData.width;
  11191. const height = imgData.height;
  11192. const imgSrc = convertImgDataToPng(imgData, this.forceDataSchema, !!mask);
  11193. const cliprect = this.svgFactory.createElement("svg:rect");
  11194. cliprect.setAttributeNS(null, "x", "0");
  11195. cliprect.setAttributeNS(null, "y", "0");
  11196. cliprect.setAttributeNS(null, "width", pf(width));
  11197. cliprect.setAttributeNS(null, "height", pf(height));
  11198. this.current.element = cliprect;
  11199. this.clip("nonzero");
  11200. const imgEl = this.svgFactory.createElement("svg:image");
  11201. imgEl.setAttributeNS(XLINK_NS, "xlink:href", imgSrc);
  11202. imgEl.setAttributeNS(null, "x", "0");
  11203. imgEl.setAttributeNS(null, "y", pf(-height));
  11204. imgEl.setAttributeNS(null, "width", pf(width) + "px");
  11205. imgEl.setAttributeNS(null, "height", pf(height) + "px");
  11206. imgEl.setAttributeNS(null, "transform", `scale(${pf(1 / width)} ${pf(-1 / height)})`);
  11207. if (mask) {
  11208. mask.appendChild(imgEl);
  11209. } else {
  11210. this._ensureTransformGroup().appendChild(imgEl);
  11211. }
  11212. }
  11213. paintImageMaskXObject(imgData) {
  11214. const current = this.current;
  11215. const width = imgData.width;
  11216. const height = imgData.height;
  11217. const fillColor = current.fillColor;
  11218. current.maskId = `mask${maskCount++}`;
  11219. const mask = this.svgFactory.createElement("svg:mask");
  11220. mask.setAttributeNS(null, "id", current.maskId);
  11221. const rect = this.svgFactory.createElement("svg:rect");
  11222. rect.setAttributeNS(null, "x", "0");
  11223. rect.setAttributeNS(null, "y", "0");
  11224. rect.setAttributeNS(null, "width", pf(width));
  11225. rect.setAttributeNS(null, "height", pf(height));
  11226. rect.setAttributeNS(null, "fill", fillColor);
  11227. rect.setAttributeNS(null, "mask", `url(#${current.maskId})`);
  11228. this.defs.appendChild(mask);
  11229. this._ensureTransformGroup().appendChild(rect);
  11230. this.paintInlineImageXObject(imgData, mask);
  11231. }
  11232. paintFormXObjectBegin(matrix, bbox) {
  11233. if (Array.isArray(matrix) && matrix.length === 6) {
  11234. this.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
  11235. }
  11236. if (bbox) {
  11237. const width = bbox[2] - bbox[0];
  11238. const height = bbox[3] - bbox[1];
  11239. const cliprect = this.svgFactory.createElement("svg:rect");
  11240. cliprect.setAttributeNS(null, "x", bbox[0]);
  11241. cliprect.setAttributeNS(null, "y", bbox[1]);
  11242. cliprect.setAttributeNS(null, "width", pf(width));
  11243. cliprect.setAttributeNS(null, "height", pf(height));
  11244. this.current.element = cliprect;
  11245. this.clip("nonzero");
  11246. this.endPath();
  11247. }
  11248. }
  11249. paintFormXObjectEnd() {}
  11250. _initialize(viewport) {
  11251. const svg = this.svgFactory.create(viewport.width, viewport.height);
  11252. const definitions = this.svgFactory.createElement("svg:defs");
  11253. svg.appendChild(definitions);
  11254. this.defs = definitions;
  11255. const rootGroup = this.svgFactory.createElement("svg:g");
  11256. rootGroup.setAttributeNS(null, "transform", pm(viewport.transform));
  11257. svg.appendChild(rootGroup);
  11258. this.svg = rootGroup;
  11259. return svg;
  11260. }
  11261. _ensureClipGroup() {
  11262. if (!this.current.clipGroup) {
  11263. const clipGroup = this.svgFactory.createElement("svg:g");
  11264. clipGroup.setAttributeNS(null, "clip-path", this.current.activeClipUrl);
  11265. this.svg.appendChild(clipGroup);
  11266. this.current.clipGroup = clipGroup;
  11267. }
  11268. return this.current.clipGroup;
  11269. }
  11270. _ensureTransformGroup() {
  11271. if (!this.tgrp) {
  11272. this.tgrp = this.svgFactory.createElement("svg:g");
  11273. this.tgrp.setAttributeNS(null, "transform", pm(this.transformMatrix));
  11274. if (this.current.activeClipUrl) {
  11275. this._ensureClipGroup().appendChild(this.tgrp);
  11276. } else {
  11277. this.svg.appendChild(this.tgrp);
  11278. }
  11279. }
  11280. return this.tgrp;
  11281. }
  11282. };
  11283. }
  11284. /***/ }),
  11285. /* 23 */
  11286. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  11287. Object.defineProperty(exports, "__esModule", ({
  11288. value: true
  11289. }));
  11290. exports.PDFNodeStream = void 0;
  11291. var _util = __w_pdfjs_require__(1);
  11292. var _network_utils = __w_pdfjs_require__(24);
  11293. ;
  11294. const fs = require("fs");
  11295. const http = require("http");
  11296. const https = require("https");
  11297. const url = require("url");
  11298. const fileUriRegex = /^file:\/\/\/[a-zA-Z]:\//;
  11299. function parseUrl(sourceUrl) {
  11300. const parsedUrl = url.parse(sourceUrl);
  11301. if (parsedUrl.protocol === "file:" || parsedUrl.host) {
  11302. return parsedUrl;
  11303. }
  11304. if (/^[a-z]:[/\\]/i.test(sourceUrl)) {
  11305. return url.parse(`file:///${sourceUrl}`);
  11306. }
  11307. if (!parsedUrl.host) {
  11308. parsedUrl.protocol = "file:";
  11309. }
  11310. return parsedUrl;
  11311. }
  11312. class PDFNodeStream {
  11313. constructor(source) {
  11314. this.source = source;
  11315. this.url = parseUrl(source.url);
  11316. this.isHttp = this.url.protocol === "http:" || this.url.protocol === "https:";
  11317. this.isFsUrl = this.url.protocol === "file:";
  11318. this.httpHeaders = this.isHttp && source.httpHeaders || {};
  11319. this._fullRequestReader = null;
  11320. this._rangeRequestReaders = [];
  11321. }
  11322. get _progressiveDataLength() {
  11323. return this._fullRequestReader?._loaded ?? 0;
  11324. }
  11325. getFullReader() {
  11326. (0, _util.assert)(!this._fullRequestReader, "PDFNodeStream.getFullReader can only be called once.");
  11327. this._fullRequestReader = this.isFsUrl ? new PDFNodeStreamFsFullReader(this) : new PDFNodeStreamFullReader(this);
  11328. return this._fullRequestReader;
  11329. }
  11330. getRangeReader(start, end) {
  11331. if (end <= this._progressiveDataLength) {
  11332. return null;
  11333. }
  11334. const rangeReader = this.isFsUrl ? new PDFNodeStreamFsRangeReader(this, start, end) : new PDFNodeStreamRangeReader(this, start, end);
  11335. this._rangeRequestReaders.push(rangeReader);
  11336. return rangeReader;
  11337. }
  11338. cancelAllRequests(reason) {
  11339. if (this._fullRequestReader) {
  11340. this._fullRequestReader.cancel(reason);
  11341. }
  11342. for (const reader of this._rangeRequestReaders.slice(0)) {
  11343. reader.cancel(reason);
  11344. }
  11345. }
  11346. }
  11347. exports.PDFNodeStream = PDFNodeStream;
  11348. class BaseFullReader {
  11349. constructor(stream) {
  11350. this._url = stream.url;
  11351. this._done = false;
  11352. this._storedError = null;
  11353. this.onProgress = null;
  11354. const source = stream.source;
  11355. this._contentLength = source.length;
  11356. this._loaded = 0;
  11357. this._filename = null;
  11358. this._disableRange = source.disableRange || false;
  11359. this._rangeChunkSize = source.rangeChunkSize;
  11360. if (!this._rangeChunkSize && !this._disableRange) {
  11361. this._disableRange = true;
  11362. }
  11363. this._isStreamingSupported = !source.disableStream;
  11364. this._isRangeSupported = !source.disableRange;
  11365. this._readableStream = null;
  11366. this._readCapability = (0, _util.createPromiseCapability)();
  11367. this._headersCapability = (0, _util.createPromiseCapability)();
  11368. }
  11369. get headersReady() {
  11370. return this._headersCapability.promise;
  11371. }
  11372. get filename() {
  11373. return this._filename;
  11374. }
  11375. get contentLength() {
  11376. return this._contentLength;
  11377. }
  11378. get isRangeSupported() {
  11379. return this._isRangeSupported;
  11380. }
  11381. get isStreamingSupported() {
  11382. return this._isStreamingSupported;
  11383. }
  11384. async read() {
  11385. await this._readCapability.promise;
  11386. if (this._done) {
  11387. return {
  11388. value: undefined,
  11389. done: true
  11390. };
  11391. }
  11392. if (this._storedError) {
  11393. throw this._storedError;
  11394. }
  11395. const chunk = this._readableStream.read();
  11396. if (chunk === null) {
  11397. this._readCapability = (0, _util.createPromiseCapability)();
  11398. return this.read();
  11399. }
  11400. this._loaded += chunk.length;
  11401. if (this.onProgress) {
  11402. this.onProgress({
  11403. loaded: this._loaded,
  11404. total: this._contentLength
  11405. });
  11406. }
  11407. const buffer = new Uint8Array(chunk).buffer;
  11408. return {
  11409. value: buffer,
  11410. done: false
  11411. };
  11412. }
  11413. cancel(reason) {
  11414. if (!this._readableStream) {
  11415. this._error(reason);
  11416. return;
  11417. }
  11418. this._readableStream.destroy(reason);
  11419. }
  11420. _error(reason) {
  11421. this._storedError = reason;
  11422. this._readCapability.resolve();
  11423. }
  11424. _setReadableStream(readableStream) {
  11425. this._readableStream = readableStream;
  11426. readableStream.on("readable", () => {
  11427. this._readCapability.resolve();
  11428. });
  11429. readableStream.on("end", () => {
  11430. readableStream.destroy();
  11431. this._done = true;
  11432. this._readCapability.resolve();
  11433. });
  11434. readableStream.on("error", reason => {
  11435. this._error(reason);
  11436. });
  11437. if (!this._isStreamingSupported && this._isRangeSupported) {
  11438. this._error(new _util.AbortException("streaming is disabled"));
  11439. }
  11440. if (this._storedError) {
  11441. this._readableStream.destroy(this._storedError);
  11442. }
  11443. }
  11444. }
  11445. class BaseRangeReader {
  11446. constructor(stream) {
  11447. this._url = stream.url;
  11448. this._done = false;
  11449. this._storedError = null;
  11450. this.onProgress = null;
  11451. this._loaded = 0;
  11452. this._readableStream = null;
  11453. this._readCapability = (0, _util.createPromiseCapability)();
  11454. const source = stream.source;
  11455. this._isStreamingSupported = !source.disableStream;
  11456. }
  11457. get isStreamingSupported() {
  11458. return this._isStreamingSupported;
  11459. }
  11460. async read() {
  11461. await this._readCapability.promise;
  11462. if (this._done) {
  11463. return {
  11464. value: undefined,
  11465. done: true
  11466. };
  11467. }
  11468. if (this._storedError) {
  11469. throw this._storedError;
  11470. }
  11471. const chunk = this._readableStream.read();
  11472. if (chunk === null) {
  11473. this._readCapability = (0, _util.createPromiseCapability)();
  11474. return this.read();
  11475. }
  11476. this._loaded += chunk.length;
  11477. if (this.onProgress) {
  11478. this.onProgress({
  11479. loaded: this._loaded
  11480. });
  11481. }
  11482. const buffer = new Uint8Array(chunk).buffer;
  11483. return {
  11484. value: buffer,
  11485. done: false
  11486. };
  11487. }
  11488. cancel(reason) {
  11489. if (!this._readableStream) {
  11490. this._error(reason);
  11491. return;
  11492. }
  11493. this._readableStream.destroy(reason);
  11494. }
  11495. _error(reason) {
  11496. this._storedError = reason;
  11497. this._readCapability.resolve();
  11498. }
  11499. _setReadableStream(readableStream) {
  11500. this._readableStream = readableStream;
  11501. readableStream.on("readable", () => {
  11502. this._readCapability.resolve();
  11503. });
  11504. readableStream.on("end", () => {
  11505. readableStream.destroy();
  11506. this._done = true;
  11507. this._readCapability.resolve();
  11508. });
  11509. readableStream.on("error", reason => {
  11510. this._error(reason);
  11511. });
  11512. if (this._storedError) {
  11513. this._readableStream.destroy(this._storedError);
  11514. }
  11515. }
  11516. }
  11517. function createRequestOptions(parsedUrl, headers) {
  11518. return {
  11519. protocol: parsedUrl.protocol,
  11520. auth: parsedUrl.auth,
  11521. host: parsedUrl.hostname,
  11522. port: parsedUrl.port,
  11523. path: parsedUrl.path,
  11524. method: "GET",
  11525. headers
  11526. };
  11527. }
  11528. class PDFNodeStreamFullReader extends BaseFullReader {
  11529. constructor(stream) {
  11530. super(stream);
  11531. const handleResponse = response => {
  11532. if (response.statusCode === 404) {
  11533. const error = new _util.MissingPDFException(`Missing PDF "${this._url}".`);
  11534. this._storedError = error;
  11535. this._headersCapability.reject(error);
  11536. return;
  11537. }
  11538. this._headersCapability.resolve();
  11539. this._setReadableStream(response);
  11540. const getResponseHeader = name => {
  11541. return this._readableStream.headers[name.toLowerCase()];
  11542. };
  11543. const {
  11544. allowRangeRequests,
  11545. suggestedLength
  11546. } = (0, _network_utils.validateRangeRequestCapabilities)({
  11547. getResponseHeader,
  11548. isHttp: stream.isHttp,
  11549. rangeChunkSize: this._rangeChunkSize,
  11550. disableRange: this._disableRange
  11551. });
  11552. this._isRangeSupported = allowRangeRequests;
  11553. this._contentLength = suggestedLength || this._contentLength;
  11554. this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
  11555. };
  11556. this._request = null;
  11557. if (this._url.protocol === "http:") {
  11558. this._request = http.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
  11559. } else {
  11560. this._request = https.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
  11561. }
  11562. this._request.on("error", reason => {
  11563. this._storedError = reason;
  11564. this._headersCapability.reject(reason);
  11565. });
  11566. this._request.end();
  11567. }
  11568. }
  11569. class PDFNodeStreamRangeReader extends BaseRangeReader {
  11570. constructor(stream, start, end) {
  11571. super(stream);
  11572. this._httpHeaders = {};
  11573. for (const property in stream.httpHeaders) {
  11574. const value = stream.httpHeaders[property];
  11575. if (typeof value === "undefined") {
  11576. continue;
  11577. }
  11578. this._httpHeaders[property] = value;
  11579. }
  11580. this._httpHeaders.Range = `bytes=${start}-${end - 1}`;
  11581. const handleResponse = response => {
  11582. if (response.statusCode === 404) {
  11583. const error = new _util.MissingPDFException(`Missing PDF "${this._url}".`);
  11584. this._storedError = error;
  11585. return;
  11586. }
  11587. this._setReadableStream(response);
  11588. };
  11589. this._request = null;
  11590. if (this._url.protocol === "http:") {
  11591. this._request = http.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
  11592. } else {
  11593. this._request = https.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
  11594. }
  11595. this._request.on("error", reason => {
  11596. this._storedError = reason;
  11597. });
  11598. this._request.end();
  11599. }
  11600. }
  11601. class PDFNodeStreamFsFullReader extends BaseFullReader {
  11602. constructor(stream) {
  11603. super(stream);
  11604. let path = decodeURIComponent(this._url.path);
  11605. if (fileUriRegex.test(this._url.href)) {
  11606. path = path.replace(/^\//, "");
  11607. }
  11608. fs.lstat(path, (error, stat) => {
  11609. if (error) {
  11610. if (error.code === "ENOENT") {
  11611. error = new _util.MissingPDFException(`Missing PDF "${path}".`);
  11612. }
  11613. this._storedError = error;
  11614. this._headersCapability.reject(error);
  11615. return;
  11616. }
  11617. this._contentLength = stat.size;
  11618. this._setReadableStream(fs.createReadStream(path));
  11619. this._headersCapability.resolve();
  11620. });
  11621. }
  11622. }
  11623. class PDFNodeStreamFsRangeReader extends BaseRangeReader {
  11624. constructor(stream, start, end) {
  11625. super(stream);
  11626. let path = decodeURIComponent(this._url.path);
  11627. if (fileUriRegex.test(this._url.href)) {
  11628. path = path.replace(/^\//, "");
  11629. }
  11630. this._setReadableStream(fs.createReadStream(path, {
  11631. start,
  11632. end: end - 1
  11633. }));
  11634. }
  11635. }
  11636. /***/ }),
  11637. /* 24 */
  11638. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  11639. Object.defineProperty(exports, "__esModule", ({
  11640. value: true
  11641. }));
  11642. exports.createResponseStatusError = createResponseStatusError;
  11643. exports.extractFilenameFromHeader = extractFilenameFromHeader;
  11644. exports.validateRangeRequestCapabilities = validateRangeRequestCapabilities;
  11645. exports.validateResponseStatus = validateResponseStatus;
  11646. var _util = __w_pdfjs_require__(1);
  11647. var _content_disposition = __w_pdfjs_require__(25);
  11648. var _display_utils = __w_pdfjs_require__(5);
  11649. function validateRangeRequestCapabilities({
  11650. getResponseHeader,
  11651. isHttp,
  11652. rangeChunkSize,
  11653. disableRange
  11654. }) {
  11655. (0, _util.assert)(rangeChunkSize > 0, "Range chunk size must be larger than zero");
  11656. const returnValues = {
  11657. allowRangeRequests: false,
  11658. suggestedLength: undefined
  11659. };
  11660. const length = parseInt(getResponseHeader("Content-Length"), 10);
  11661. if (!Number.isInteger(length)) {
  11662. return returnValues;
  11663. }
  11664. returnValues.suggestedLength = length;
  11665. if (length <= 2 * rangeChunkSize) {
  11666. return returnValues;
  11667. }
  11668. if (disableRange || !isHttp) {
  11669. return returnValues;
  11670. }
  11671. if (getResponseHeader("Accept-Ranges") !== "bytes") {
  11672. return returnValues;
  11673. }
  11674. const contentEncoding = getResponseHeader("Content-Encoding") || "identity";
  11675. if (contentEncoding !== "identity") {
  11676. return returnValues;
  11677. }
  11678. returnValues.allowRangeRequests = true;
  11679. return returnValues;
  11680. }
  11681. function extractFilenameFromHeader(getResponseHeader) {
  11682. const contentDisposition = getResponseHeader("Content-Disposition");
  11683. if (contentDisposition) {
  11684. let filename = (0, _content_disposition.getFilenameFromContentDispositionHeader)(contentDisposition);
  11685. if (filename.includes("%")) {
  11686. try {
  11687. filename = decodeURIComponent(filename);
  11688. } catch (ex) {}
  11689. }
  11690. if ((0, _display_utils.isPdfFile)(filename)) {
  11691. return filename;
  11692. }
  11693. }
  11694. return null;
  11695. }
  11696. function createResponseStatusError(status, url) {
  11697. if (status === 404 || status === 0 && url.startsWith("file:")) {
  11698. return new _util.MissingPDFException('Missing PDF "' + url + '".');
  11699. }
  11700. return new _util.UnexpectedResponseException(`Unexpected server response (${status}) while retrieving PDF "${url}".`, status);
  11701. }
  11702. function validateResponseStatus(status) {
  11703. return status === 200 || status === 206;
  11704. }
  11705. /***/ }),
  11706. /* 25 */
  11707. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  11708. Object.defineProperty(exports, "__esModule", ({
  11709. value: true
  11710. }));
  11711. exports.getFilenameFromContentDispositionHeader = getFilenameFromContentDispositionHeader;
  11712. var _util = __w_pdfjs_require__(1);
  11713. function getFilenameFromContentDispositionHeader(contentDisposition) {
  11714. let needsEncodingFixup = true;
  11715. let tmp = toParamRegExp("filename\\*", "i").exec(contentDisposition);
  11716. if (tmp) {
  11717. tmp = tmp[1];
  11718. let filename = rfc2616unquote(tmp);
  11719. filename = unescape(filename);
  11720. filename = rfc5987decode(filename);
  11721. filename = rfc2047decode(filename);
  11722. return fixupEncoding(filename);
  11723. }
  11724. tmp = rfc2231getparam(contentDisposition);
  11725. if (tmp) {
  11726. const filename = rfc2047decode(tmp);
  11727. return fixupEncoding(filename);
  11728. }
  11729. tmp = toParamRegExp("filename", "i").exec(contentDisposition);
  11730. if (tmp) {
  11731. tmp = tmp[1];
  11732. let filename = rfc2616unquote(tmp);
  11733. filename = rfc2047decode(filename);
  11734. return fixupEncoding(filename);
  11735. }
  11736. function toParamRegExp(attributePattern, flags) {
  11737. return new RegExp("(?:^|;)\\s*" + attributePattern + "\\s*=\\s*" + "(" + '[^";\\s][^;\\s]*' + "|" + '"(?:[^"\\\\]|\\\\"?)+"?' + ")", flags);
  11738. }
  11739. function textdecode(encoding, value) {
  11740. if (encoding) {
  11741. if (!/^[\x00-\xFF]+$/.test(value)) {
  11742. return value;
  11743. }
  11744. try {
  11745. const decoder = new TextDecoder(encoding, {
  11746. fatal: true
  11747. });
  11748. const buffer = (0, _util.stringToBytes)(value);
  11749. value = decoder.decode(buffer);
  11750. needsEncodingFixup = false;
  11751. } catch (e) {}
  11752. }
  11753. return value;
  11754. }
  11755. function fixupEncoding(value) {
  11756. if (needsEncodingFixup && /[\x80-\xff]/.test(value)) {
  11757. value = textdecode("utf-8", value);
  11758. if (needsEncodingFixup) {
  11759. value = textdecode("iso-8859-1", value);
  11760. }
  11761. }
  11762. return value;
  11763. }
  11764. function rfc2231getparam(contentDispositionStr) {
  11765. const matches = [];
  11766. let match;
  11767. const iter = toParamRegExp("filename\\*((?!0\\d)\\d+)(\\*?)", "ig");
  11768. while ((match = iter.exec(contentDispositionStr)) !== null) {
  11769. let [, n, quot, part] = match;
  11770. n = parseInt(n, 10);
  11771. if (n in matches) {
  11772. if (n === 0) {
  11773. break;
  11774. }
  11775. continue;
  11776. }
  11777. matches[n] = [quot, part];
  11778. }
  11779. const parts = [];
  11780. for (let n = 0; n < matches.length; ++n) {
  11781. if (!(n in matches)) {
  11782. break;
  11783. }
  11784. let [quot, part] = matches[n];
  11785. part = rfc2616unquote(part);
  11786. if (quot) {
  11787. part = unescape(part);
  11788. if (n === 0) {
  11789. part = rfc5987decode(part);
  11790. }
  11791. }
  11792. parts.push(part);
  11793. }
  11794. return parts.join("");
  11795. }
  11796. function rfc2616unquote(value) {
  11797. if (value.startsWith('"')) {
  11798. const parts = value.slice(1).split('\\"');
  11799. for (let i = 0; i < parts.length; ++i) {
  11800. const quotindex = parts[i].indexOf('"');
  11801. if (quotindex !== -1) {
  11802. parts[i] = parts[i].slice(0, quotindex);
  11803. parts.length = i + 1;
  11804. }
  11805. parts[i] = parts[i].replace(/\\(.)/g, "$1");
  11806. }
  11807. value = parts.join('"');
  11808. }
  11809. return value;
  11810. }
  11811. function rfc5987decode(extvalue) {
  11812. const encodingend = extvalue.indexOf("'");
  11813. if (encodingend === -1) {
  11814. return extvalue;
  11815. }
  11816. const encoding = extvalue.slice(0, encodingend);
  11817. const langvalue = extvalue.slice(encodingend + 1);
  11818. const value = langvalue.replace(/^[^']*'/, "");
  11819. return textdecode(encoding, value);
  11820. }
  11821. function rfc2047decode(value) {
  11822. if (!value.startsWith("=?") || /[\x00-\x19\x80-\xff]/.test(value)) {
  11823. return value;
  11824. }
  11825. return value.replace(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g, function (matches, charset, encoding, text) {
  11826. if (encoding === "q" || encoding === "Q") {
  11827. text = text.replace(/_/g, " ");
  11828. text = text.replace(/=([0-9a-fA-F]{2})/g, function (match, hex) {
  11829. return String.fromCharCode(parseInt(hex, 16));
  11830. });
  11831. return textdecode(charset, text);
  11832. }
  11833. try {
  11834. text = atob(text);
  11835. } catch (e) {}
  11836. return textdecode(charset, text);
  11837. });
  11838. }
  11839. return "";
  11840. }
  11841. /***/ }),
  11842. /* 26 */
  11843. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  11844. Object.defineProperty(exports, "__esModule", ({
  11845. value: true
  11846. }));
  11847. exports.PDFNetworkStream = void 0;
  11848. var _util = __w_pdfjs_require__(1);
  11849. var _network_utils = __w_pdfjs_require__(24);
  11850. ;
  11851. const OK_RESPONSE = 200;
  11852. const PARTIAL_CONTENT_RESPONSE = 206;
  11853. function getArrayBuffer(xhr) {
  11854. const data = xhr.response;
  11855. if (typeof data !== "string") {
  11856. return data;
  11857. }
  11858. const array = (0, _util.stringToBytes)(data);
  11859. return array.buffer;
  11860. }
  11861. class NetworkManager {
  11862. constructor(url, args = {}) {
  11863. this.url = url;
  11864. this.isHttp = /^https?:/i.test(url);
  11865. this.httpHeaders = this.isHttp && args.httpHeaders || Object.create(null);
  11866. this.withCredentials = args.withCredentials || false;
  11867. this.getXhr = args.getXhr || function NetworkManager_getXhr() {
  11868. return new XMLHttpRequest();
  11869. };
  11870. this.currXhrId = 0;
  11871. this.pendingRequests = Object.create(null);
  11872. }
  11873. requestRange(begin, end, listeners) {
  11874. const args = {
  11875. begin,
  11876. end
  11877. };
  11878. for (const prop in listeners) {
  11879. args[prop] = listeners[prop];
  11880. }
  11881. return this.request(args);
  11882. }
  11883. requestFull(listeners) {
  11884. return this.request(listeners);
  11885. }
  11886. request(args) {
  11887. const xhr = this.getXhr();
  11888. const xhrId = this.currXhrId++;
  11889. const pendingRequest = this.pendingRequests[xhrId] = {
  11890. xhr
  11891. };
  11892. xhr.open("GET", this.url);
  11893. xhr.withCredentials = this.withCredentials;
  11894. for (const property in this.httpHeaders) {
  11895. const value = this.httpHeaders[property];
  11896. if (typeof value === "undefined") {
  11897. continue;
  11898. }
  11899. xhr.setRequestHeader(property, value);
  11900. }
  11901. if (this.isHttp && "begin" in args && "end" in args) {
  11902. xhr.setRequestHeader("Range", `bytes=${args.begin}-${args.end - 1}`);
  11903. pendingRequest.expectedStatus = PARTIAL_CONTENT_RESPONSE;
  11904. } else {
  11905. pendingRequest.expectedStatus = OK_RESPONSE;
  11906. }
  11907. xhr.responseType = "arraybuffer";
  11908. if (args.onError) {
  11909. xhr.onerror = function (evt) {
  11910. args.onError(xhr.status);
  11911. };
  11912. }
  11913. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  11914. xhr.onprogress = this.onProgress.bind(this, xhrId);
  11915. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  11916. pendingRequest.onDone = args.onDone;
  11917. pendingRequest.onError = args.onError;
  11918. pendingRequest.onProgress = args.onProgress;
  11919. xhr.send(null);
  11920. return xhrId;
  11921. }
  11922. onProgress(xhrId, evt) {
  11923. const pendingRequest = this.pendingRequests[xhrId];
  11924. if (!pendingRequest) {
  11925. return;
  11926. }
  11927. pendingRequest.onProgress?.(evt);
  11928. }
  11929. onStateChange(xhrId, evt) {
  11930. const pendingRequest = this.pendingRequests[xhrId];
  11931. if (!pendingRequest) {
  11932. return;
  11933. }
  11934. const xhr = pendingRequest.xhr;
  11935. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  11936. pendingRequest.onHeadersReceived();
  11937. delete pendingRequest.onHeadersReceived;
  11938. }
  11939. if (xhr.readyState !== 4) {
  11940. return;
  11941. }
  11942. if (!(xhrId in this.pendingRequests)) {
  11943. return;
  11944. }
  11945. delete this.pendingRequests[xhrId];
  11946. if (xhr.status === 0 && this.isHttp) {
  11947. pendingRequest.onError?.(xhr.status);
  11948. return;
  11949. }
  11950. const xhrStatus = xhr.status || OK_RESPONSE;
  11951. const ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  11952. if (!ok_response_on_range_request && xhrStatus !== pendingRequest.expectedStatus) {
  11953. pendingRequest.onError?.(xhr.status);
  11954. return;
  11955. }
  11956. const chunk = getArrayBuffer(xhr);
  11957. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  11958. const rangeHeader = xhr.getResponseHeader("Content-Range");
  11959. const matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  11960. pendingRequest.onDone({
  11961. begin: parseInt(matches[1], 10),
  11962. chunk
  11963. });
  11964. } else if (chunk) {
  11965. pendingRequest.onDone({
  11966. begin: 0,
  11967. chunk
  11968. });
  11969. } else {
  11970. pendingRequest.onError?.(xhr.status);
  11971. }
  11972. }
  11973. getRequestXhr(xhrId) {
  11974. return this.pendingRequests[xhrId].xhr;
  11975. }
  11976. isPendingRequest(xhrId) {
  11977. return xhrId in this.pendingRequests;
  11978. }
  11979. abortRequest(xhrId) {
  11980. const xhr = this.pendingRequests[xhrId].xhr;
  11981. delete this.pendingRequests[xhrId];
  11982. xhr.abort();
  11983. }
  11984. }
  11985. class PDFNetworkStream {
  11986. constructor(source) {
  11987. this._source = source;
  11988. this._manager = new NetworkManager(source.url, {
  11989. httpHeaders: source.httpHeaders,
  11990. withCredentials: source.withCredentials
  11991. });
  11992. this._rangeChunkSize = source.rangeChunkSize;
  11993. this._fullRequestReader = null;
  11994. this._rangeRequestReaders = [];
  11995. }
  11996. _onRangeRequestReaderClosed(reader) {
  11997. const i = this._rangeRequestReaders.indexOf(reader);
  11998. if (i >= 0) {
  11999. this._rangeRequestReaders.splice(i, 1);
  12000. }
  12001. }
  12002. getFullReader() {
  12003. (0, _util.assert)(!this._fullRequestReader, "PDFNetworkStream.getFullReader can only be called once.");
  12004. this._fullRequestReader = new PDFNetworkStreamFullRequestReader(this._manager, this._source);
  12005. return this._fullRequestReader;
  12006. }
  12007. getRangeReader(begin, end) {
  12008. const reader = new PDFNetworkStreamRangeRequestReader(this._manager, begin, end);
  12009. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  12010. this._rangeRequestReaders.push(reader);
  12011. return reader;
  12012. }
  12013. cancelAllRequests(reason) {
  12014. this._fullRequestReader?.cancel(reason);
  12015. for (const reader of this._rangeRequestReaders.slice(0)) {
  12016. reader.cancel(reason);
  12017. }
  12018. }
  12019. }
  12020. exports.PDFNetworkStream = PDFNetworkStream;
  12021. class PDFNetworkStreamFullRequestReader {
  12022. constructor(manager, source) {
  12023. this._manager = manager;
  12024. const args = {
  12025. onHeadersReceived: this._onHeadersReceived.bind(this),
  12026. onDone: this._onDone.bind(this),
  12027. onError: this._onError.bind(this),
  12028. onProgress: this._onProgress.bind(this)
  12029. };
  12030. this._url = source.url;
  12031. this._fullRequestId = manager.requestFull(args);
  12032. this._headersReceivedCapability = (0, _util.createPromiseCapability)();
  12033. this._disableRange = source.disableRange || false;
  12034. this._contentLength = source.length;
  12035. this._rangeChunkSize = source.rangeChunkSize;
  12036. if (!this._rangeChunkSize && !this._disableRange) {
  12037. this._disableRange = true;
  12038. }
  12039. this._isStreamingSupported = false;
  12040. this._isRangeSupported = false;
  12041. this._cachedChunks = [];
  12042. this._requests = [];
  12043. this._done = false;
  12044. this._storedError = undefined;
  12045. this._filename = null;
  12046. this.onProgress = null;
  12047. }
  12048. _onHeadersReceived() {
  12049. const fullRequestXhrId = this._fullRequestId;
  12050. const fullRequestXhr = this._manager.getRequestXhr(fullRequestXhrId);
  12051. const getResponseHeader = name => {
  12052. return fullRequestXhr.getResponseHeader(name);
  12053. };
  12054. const {
  12055. allowRangeRequests,
  12056. suggestedLength
  12057. } = (0, _network_utils.validateRangeRequestCapabilities)({
  12058. getResponseHeader,
  12059. isHttp: this._manager.isHttp,
  12060. rangeChunkSize: this._rangeChunkSize,
  12061. disableRange: this._disableRange
  12062. });
  12063. if (allowRangeRequests) {
  12064. this._isRangeSupported = true;
  12065. }
  12066. this._contentLength = suggestedLength || this._contentLength;
  12067. this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
  12068. if (this._isRangeSupported) {
  12069. this._manager.abortRequest(fullRequestXhrId);
  12070. }
  12071. this._headersReceivedCapability.resolve();
  12072. }
  12073. _onDone(data) {
  12074. if (data) {
  12075. if (this._requests.length > 0) {
  12076. const requestCapability = this._requests.shift();
  12077. requestCapability.resolve({
  12078. value: data.chunk,
  12079. done: false
  12080. });
  12081. } else {
  12082. this._cachedChunks.push(data.chunk);
  12083. }
  12084. }
  12085. this._done = true;
  12086. if (this._cachedChunks.length > 0) {
  12087. return;
  12088. }
  12089. for (const requestCapability of this._requests) {
  12090. requestCapability.resolve({
  12091. value: undefined,
  12092. done: true
  12093. });
  12094. }
  12095. this._requests.length = 0;
  12096. }
  12097. _onError(status) {
  12098. this._storedError = (0, _network_utils.createResponseStatusError)(status, this._url);
  12099. this._headersReceivedCapability.reject(this._storedError);
  12100. for (const requestCapability of this._requests) {
  12101. requestCapability.reject(this._storedError);
  12102. }
  12103. this._requests.length = 0;
  12104. this._cachedChunks.length = 0;
  12105. }
  12106. _onProgress(evt) {
  12107. this.onProgress?.({
  12108. loaded: evt.loaded,
  12109. total: evt.lengthComputable ? evt.total : this._contentLength
  12110. });
  12111. }
  12112. get filename() {
  12113. return this._filename;
  12114. }
  12115. get isRangeSupported() {
  12116. return this._isRangeSupported;
  12117. }
  12118. get isStreamingSupported() {
  12119. return this._isStreamingSupported;
  12120. }
  12121. get contentLength() {
  12122. return this._contentLength;
  12123. }
  12124. get headersReady() {
  12125. return this._headersReceivedCapability.promise;
  12126. }
  12127. async read() {
  12128. if (this._storedError) {
  12129. throw this._storedError;
  12130. }
  12131. if (this._cachedChunks.length > 0) {
  12132. const chunk = this._cachedChunks.shift();
  12133. return {
  12134. value: chunk,
  12135. done: false
  12136. };
  12137. }
  12138. if (this._done) {
  12139. return {
  12140. value: undefined,
  12141. done: true
  12142. };
  12143. }
  12144. const requestCapability = (0, _util.createPromiseCapability)();
  12145. this._requests.push(requestCapability);
  12146. return requestCapability.promise;
  12147. }
  12148. cancel(reason) {
  12149. this._done = true;
  12150. this._headersReceivedCapability.reject(reason);
  12151. for (const requestCapability of this._requests) {
  12152. requestCapability.resolve({
  12153. value: undefined,
  12154. done: true
  12155. });
  12156. }
  12157. this._requests.length = 0;
  12158. if (this._manager.isPendingRequest(this._fullRequestId)) {
  12159. this._manager.abortRequest(this._fullRequestId);
  12160. }
  12161. this._fullRequestReader = null;
  12162. }
  12163. }
  12164. class PDFNetworkStreamRangeRequestReader {
  12165. constructor(manager, begin, end) {
  12166. this._manager = manager;
  12167. const args = {
  12168. onDone: this._onDone.bind(this),
  12169. onError: this._onError.bind(this),
  12170. onProgress: this._onProgress.bind(this)
  12171. };
  12172. this._url = manager.url;
  12173. this._requestId = manager.requestRange(begin, end, args);
  12174. this._requests = [];
  12175. this._queuedChunk = null;
  12176. this._done = false;
  12177. this._storedError = undefined;
  12178. this.onProgress = null;
  12179. this.onClosed = null;
  12180. }
  12181. _close() {
  12182. this.onClosed?.(this);
  12183. }
  12184. _onDone(data) {
  12185. const chunk = data.chunk;
  12186. if (this._requests.length > 0) {
  12187. const requestCapability = this._requests.shift();
  12188. requestCapability.resolve({
  12189. value: chunk,
  12190. done: false
  12191. });
  12192. } else {
  12193. this._queuedChunk = chunk;
  12194. }
  12195. this._done = true;
  12196. for (const requestCapability of this._requests) {
  12197. requestCapability.resolve({
  12198. value: undefined,
  12199. done: true
  12200. });
  12201. }
  12202. this._requests.length = 0;
  12203. this._close();
  12204. }
  12205. _onError(status) {
  12206. this._storedError = (0, _network_utils.createResponseStatusError)(status, this._url);
  12207. for (const requestCapability of this._requests) {
  12208. requestCapability.reject(this._storedError);
  12209. }
  12210. this._requests.length = 0;
  12211. this._queuedChunk = null;
  12212. }
  12213. _onProgress(evt) {
  12214. if (!this.isStreamingSupported) {
  12215. this.onProgress?.({
  12216. loaded: evt.loaded
  12217. });
  12218. }
  12219. }
  12220. get isStreamingSupported() {
  12221. return false;
  12222. }
  12223. async read() {
  12224. if (this._storedError) {
  12225. throw this._storedError;
  12226. }
  12227. if (this._queuedChunk !== null) {
  12228. const chunk = this._queuedChunk;
  12229. this._queuedChunk = null;
  12230. return {
  12231. value: chunk,
  12232. done: false
  12233. };
  12234. }
  12235. if (this._done) {
  12236. return {
  12237. value: undefined,
  12238. done: true
  12239. };
  12240. }
  12241. const requestCapability = (0, _util.createPromiseCapability)();
  12242. this._requests.push(requestCapability);
  12243. return requestCapability.promise;
  12244. }
  12245. cancel(reason) {
  12246. this._done = true;
  12247. for (const requestCapability of this._requests) {
  12248. requestCapability.resolve({
  12249. value: undefined,
  12250. done: true
  12251. });
  12252. }
  12253. this._requests.length = 0;
  12254. if (this._manager.isPendingRequest(this._requestId)) {
  12255. this._manager.abortRequest(this._requestId);
  12256. }
  12257. this._close();
  12258. }
  12259. }
  12260. /***/ }),
  12261. /* 27 */
  12262. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  12263. Object.defineProperty(exports, "__esModule", ({
  12264. value: true
  12265. }));
  12266. exports.PDFFetchStream = void 0;
  12267. var _util = __w_pdfjs_require__(1);
  12268. var _network_utils = __w_pdfjs_require__(24);
  12269. ;
  12270. function createFetchOptions(headers, withCredentials, abortController) {
  12271. return {
  12272. method: "GET",
  12273. headers,
  12274. signal: abortController?.signal,
  12275. mode: "cors",
  12276. credentials: withCredentials ? "include" : "same-origin",
  12277. redirect: "follow"
  12278. };
  12279. }
  12280. function createHeaders(httpHeaders) {
  12281. const headers = new Headers();
  12282. for (const property in httpHeaders) {
  12283. const value = httpHeaders[property];
  12284. if (typeof value === "undefined") {
  12285. continue;
  12286. }
  12287. headers.append(property, value);
  12288. }
  12289. return headers;
  12290. }
  12291. class PDFFetchStream {
  12292. constructor(source) {
  12293. this.source = source;
  12294. this.isHttp = /^https?:/i.test(source.url);
  12295. this.httpHeaders = this.isHttp && source.httpHeaders || {};
  12296. this._fullRequestReader = null;
  12297. this._rangeRequestReaders = [];
  12298. }
  12299. get _progressiveDataLength() {
  12300. return this._fullRequestReader?._loaded ?? 0;
  12301. }
  12302. getFullReader() {
  12303. (0, _util.assert)(!this._fullRequestReader, "PDFFetchStream.getFullReader can only be called once.");
  12304. this._fullRequestReader = new PDFFetchStreamReader(this);
  12305. return this._fullRequestReader;
  12306. }
  12307. getRangeReader(begin, end) {
  12308. if (end <= this._progressiveDataLength) {
  12309. return null;
  12310. }
  12311. const reader = new PDFFetchStreamRangeReader(this, begin, end);
  12312. this._rangeRequestReaders.push(reader);
  12313. return reader;
  12314. }
  12315. cancelAllRequests(reason) {
  12316. if (this._fullRequestReader) {
  12317. this._fullRequestReader.cancel(reason);
  12318. }
  12319. for (const reader of this._rangeRequestReaders.slice(0)) {
  12320. reader.cancel(reason);
  12321. }
  12322. }
  12323. }
  12324. exports.PDFFetchStream = PDFFetchStream;
  12325. class PDFFetchStreamReader {
  12326. constructor(stream) {
  12327. this._stream = stream;
  12328. this._reader = null;
  12329. this._loaded = 0;
  12330. this._filename = null;
  12331. const source = stream.source;
  12332. this._withCredentials = source.withCredentials || false;
  12333. this._contentLength = source.length;
  12334. this._headersCapability = (0, _util.createPromiseCapability)();
  12335. this._disableRange = source.disableRange || false;
  12336. this._rangeChunkSize = source.rangeChunkSize;
  12337. if (!this._rangeChunkSize && !this._disableRange) {
  12338. this._disableRange = true;
  12339. }
  12340. if (typeof AbortController !== "undefined") {
  12341. this._abortController = new AbortController();
  12342. }
  12343. this._isStreamingSupported = !source.disableStream;
  12344. this._isRangeSupported = !source.disableRange;
  12345. this._headers = createHeaders(this._stream.httpHeaders);
  12346. const url = source.url;
  12347. fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(response => {
  12348. if (!(0, _network_utils.validateResponseStatus)(response.status)) {
  12349. throw (0, _network_utils.createResponseStatusError)(response.status, url);
  12350. }
  12351. this._reader = response.body.getReader();
  12352. this._headersCapability.resolve();
  12353. const getResponseHeader = name => {
  12354. return response.headers.get(name);
  12355. };
  12356. const {
  12357. allowRangeRequests,
  12358. suggestedLength
  12359. } = (0, _network_utils.validateRangeRequestCapabilities)({
  12360. getResponseHeader,
  12361. isHttp: this._stream.isHttp,
  12362. rangeChunkSize: this._rangeChunkSize,
  12363. disableRange: this._disableRange
  12364. });
  12365. this._isRangeSupported = allowRangeRequests;
  12366. this._contentLength = suggestedLength || this._contentLength;
  12367. this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
  12368. if (!this._isStreamingSupported && this._isRangeSupported) {
  12369. this.cancel(new _util.AbortException("Streaming is disabled."));
  12370. }
  12371. }).catch(this._headersCapability.reject);
  12372. this.onProgress = null;
  12373. }
  12374. get headersReady() {
  12375. return this._headersCapability.promise;
  12376. }
  12377. get filename() {
  12378. return this._filename;
  12379. }
  12380. get contentLength() {
  12381. return this._contentLength;
  12382. }
  12383. get isRangeSupported() {
  12384. return this._isRangeSupported;
  12385. }
  12386. get isStreamingSupported() {
  12387. return this._isStreamingSupported;
  12388. }
  12389. async read() {
  12390. await this._headersCapability.promise;
  12391. const {
  12392. value,
  12393. done
  12394. } = await this._reader.read();
  12395. if (done) {
  12396. return {
  12397. value,
  12398. done
  12399. };
  12400. }
  12401. this._loaded += value.byteLength;
  12402. if (this.onProgress) {
  12403. this.onProgress({
  12404. loaded: this._loaded,
  12405. total: this._contentLength
  12406. });
  12407. }
  12408. const buffer = new Uint8Array(value).buffer;
  12409. return {
  12410. value: buffer,
  12411. done: false
  12412. };
  12413. }
  12414. cancel(reason) {
  12415. if (this._reader) {
  12416. this._reader.cancel(reason);
  12417. }
  12418. if (this._abortController) {
  12419. this._abortController.abort();
  12420. }
  12421. }
  12422. }
  12423. class PDFFetchStreamRangeReader {
  12424. constructor(stream, begin, end) {
  12425. this._stream = stream;
  12426. this._reader = null;
  12427. this._loaded = 0;
  12428. const source = stream.source;
  12429. this._withCredentials = source.withCredentials || false;
  12430. this._readCapability = (0, _util.createPromiseCapability)();
  12431. this._isStreamingSupported = !source.disableStream;
  12432. if (typeof AbortController !== "undefined") {
  12433. this._abortController = new AbortController();
  12434. }
  12435. this._headers = createHeaders(this._stream.httpHeaders);
  12436. this._headers.append("Range", `bytes=${begin}-${end - 1}`);
  12437. const url = source.url;
  12438. fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(response => {
  12439. if (!(0, _network_utils.validateResponseStatus)(response.status)) {
  12440. throw (0, _network_utils.createResponseStatusError)(response.status, url);
  12441. }
  12442. this._readCapability.resolve();
  12443. this._reader = response.body.getReader();
  12444. }).catch(this._readCapability.reject);
  12445. this.onProgress = null;
  12446. }
  12447. get isStreamingSupported() {
  12448. return this._isStreamingSupported;
  12449. }
  12450. async read() {
  12451. await this._readCapability.promise;
  12452. const {
  12453. value,
  12454. done
  12455. } = await this._reader.read();
  12456. if (done) {
  12457. return {
  12458. value,
  12459. done
  12460. };
  12461. }
  12462. this._loaded += value.byteLength;
  12463. if (this.onProgress) {
  12464. this.onProgress({
  12465. loaded: this._loaded
  12466. });
  12467. }
  12468. const buffer = new Uint8Array(value).buffer;
  12469. return {
  12470. value: buffer,
  12471. done: false
  12472. };
  12473. }
  12474. cancel(reason) {
  12475. if (this._reader) {
  12476. this._reader.cancel(reason);
  12477. }
  12478. if (this._abortController) {
  12479. this._abortController.abort();
  12480. }
  12481. }
  12482. }
  12483. /***/ })
  12484. /******/ ]);
  12485. /************************************************************************/
  12486. /******/ // The module cache
  12487. /******/ var __webpack_module_cache__ = {};
  12488. /******/
  12489. /******/ // The require function
  12490. /******/ function __w_pdfjs_require__(moduleId) {
  12491. /******/ // Check if module is in cache
  12492. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  12493. /******/ if (cachedModule !== undefined) {
  12494. /******/ return cachedModule.exports;
  12495. /******/ }
  12496. /******/ // Create a new module (and put it into the cache)
  12497. /******/ var module = __webpack_module_cache__[moduleId] = {
  12498. /******/ // no module.id needed
  12499. /******/ // no module.loaded needed
  12500. /******/ exports: {}
  12501. /******/ };
  12502. /******/
  12503. /******/ // Execute the module function
  12504. /******/ __webpack_modules__[moduleId](module, module.exports, __w_pdfjs_require__);
  12505. /******/
  12506. /******/ // Return the exports of the module
  12507. /******/ return module.exports;
  12508. /******/ }
  12509. /******/
  12510. /************************************************************************/
  12511. var __webpack_exports__ = {};
  12512. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  12513. (() => {
  12514. var exports = __webpack_exports__;
  12515. Object.defineProperty(exports, "__esModule", ({
  12516. value: true
  12517. }));
  12518. Object.defineProperty(exports, "AnnotationLayer", ({
  12519. enumerable: true,
  12520. get: function () {
  12521. return _annotation_layer.AnnotationLayer;
  12522. }
  12523. }));
  12524. Object.defineProperty(exports, "AnnotationMode", ({
  12525. enumerable: true,
  12526. get: function () {
  12527. return _util.AnnotationMode;
  12528. }
  12529. }));
  12530. Object.defineProperty(exports, "CMapCompressionType", ({
  12531. enumerable: true,
  12532. get: function () {
  12533. return _util.CMapCompressionType;
  12534. }
  12535. }));
  12536. Object.defineProperty(exports, "GlobalWorkerOptions", ({
  12537. enumerable: true,
  12538. get: function () {
  12539. return _worker_options.GlobalWorkerOptions;
  12540. }
  12541. }));
  12542. Object.defineProperty(exports, "InvalidPDFException", ({
  12543. enumerable: true,
  12544. get: function () {
  12545. return _util.InvalidPDFException;
  12546. }
  12547. }));
  12548. Object.defineProperty(exports, "LoopbackPort", ({
  12549. enumerable: true,
  12550. get: function () {
  12551. return _api.LoopbackPort;
  12552. }
  12553. }));
  12554. Object.defineProperty(exports, "MissingPDFException", ({
  12555. enumerable: true,
  12556. get: function () {
  12557. return _util.MissingPDFException;
  12558. }
  12559. }));
  12560. Object.defineProperty(exports, "OPS", ({
  12561. enumerable: true,
  12562. get: function () {
  12563. return _util.OPS;
  12564. }
  12565. }));
  12566. Object.defineProperty(exports, "PDFDataRangeTransport", ({
  12567. enumerable: true,
  12568. get: function () {
  12569. return _api.PDFDataRangeTransport;
  12570. }
  12571. }));
  12572. Object.defineProperty(exports, "PDFDateString", ({
  12573. enumerable: true,
  12574. get: function () {
  12575. return _display_utils.PDFDateString;
  12576. }
  12577. }));
  12578. Object.defineProperty(exports, "PDFWorker", ({
  12579. enumerable: true,
  12580. get: function () {
  12581. return _api.PDFWorker;
  12582. }
  12583. }));
  12584. Object.defineProperty(exports, "PasswordResponses", ({
  12585. enumerable: true,
  12586. get: function () {
  12587. return _util.PasswordResponses;
  12588. }
  12589. }));
  12590. Object.defineProperty(exports, "PermissionFlag", ({
  12591. enumerable: true,
  12592. get: function () {
  12593. return _util.PermissionFlag;
  12594. }
  12595. }));
  12596. Object.defineProperty(exports, "PixelsPerInch", ({
  12597. enumerable: true,
  12598. get: function () {
  12599. return _display_utils.PixelsPerInch;
  12600. }
  12601. }));
  12602. Object.defineProperty(exports, "RenderingCancelledException", ({
  12603. enumerable: true,
  12604. get: function () {
  12605. return _display_utils.RenderingCancelledException;
  12606. }
  12607. }));
  12608. Object.defineProperty(exports, "SVGGraphics", ({
  12609. enumerable: true,
  12610. get: function () {
  12611. return _svg.SVGGraphics;
  12612. }
  12613. }));
  12614. Object.defineProperty(exports, "UNSUPPORTED_FEATURES", ({
  12615. enumerable: true,
  12616. get: function () {
  12617. return _util.UNSUPPORTED_FEATURES;
  12618. }
  12619. }));
  12620. Object.defineProperty(exports, "UnexpectedResponseException", ({
  12621. enumerable: true,
  12622. get: function () {
  12623. return _util.UnexpectedResponseException;
  12624. }
  12625. }));
  12626. Object.defineProperty(exports, "Util", ({
  12627. enumerable: true,
  12628. get: function () {
  12629. return _util.Util;
  12630. }
  12631. }));
  12632. Object.defineProperty(exports, "VerbosityLevel", ({
  12633. enumerable: true,
  12634. get: function () {
  12635. return _util.VerbosityLevel;
  12636. }
  12637. }));
  12638. Object.defineProperty(exports, "XfaLayer", ({
  12639. enumerable: true,
  12640. get: function () {
  12641. return _xfa_layer.XfaLayer;
  12642. }
  12643. }));
  12644. Object.defineProperty(exports, "build", ({
  12645. enumerable: true,
  12646. get: function () {
  12647. return _api.build;
  12648. }
  12649. }));
  12650. Object.defineProperty(exports, "createPromiseCapability", ({
  12651. enumerable: true,
  12652. get: function () {
  12653. return _util.createPromiseCapability;
  12654. }
  12655. }));
  12656. Object.defineProperty(exports, "createValidAbsoluteUrl", ({
  12657. enumerable: true,
  12658. get: function () {
  12659. return _util.createValidAbsoluteUrl;
  12660. }
  12661. }));
  12662. Object.defineProperty(exports, "getDocument", ({
  12663. enumerable: true,
  12664. get: function () {
  12665. return _api.getDocument;
  12666. }
  12667. }));
  12668. Object.defineProperty(exports, "getFilenameFromUrl", ({
  12669. enumerable: true,
  12670. get: function () {
  12671. return _display_utils.getFilenameFromUrl;
  12672. }
  12673. }));
  12674. Object.defineProperty(exports, "getPdfFilenameFromUrl", ({
  12675. enumerable: true,
  12676. get: function () {
  12677. return _display_utils.getPdfFilenameFromUrl;
  12678. }
  12679. }));
  12680. Object.defineProperty(exports, "getXfaPageViewport", ({
  12681. enumerable: true,
  12682. get: function () {
  12683. return _display_utils.getXfaPageViewport;
  12684. }
  12685. }));
  12686. Object.defineProperty(exports, "isPdfFile", ({
  12687. enumerable: true,
  12688. get: function () {
  12689. return _display_utils.isPdfFile;
  12690. }
  12691. }));
  12692. Object.defineProperty(exports, "loadScript", ({
  12693. enumerable: true,
  12694. get: function () {
  12695. return _display_utils.loadScript;
  12696. }
  12697. }));
  12698. Object.defineProperty(exports, "renderTextLayer", ({
  12699. enumerable: true,
  12700. get: function () {
  12701. return _text_layer.renderTextLayer;
  12702. }
  12703. }));
  12704. Object.defineProperty(exports, "shadow", ({
  12705. enumerable: true,
  12706. get: function () {
  12707. return _util.shadow;
  12708. }
  12709. }));
  12710. Object.defineProperty(exports, "version", ({
  12711. enumerable: true,
  12712. get: function () {
  12713. return _api.version;
  12714. }
  12715. }));
  12716. var _util = __w_pdfjs_require__(1);
  12717. var _api = __w_pdfjs_require__(4);
  12718. var _display_utils = __w_pdfjs_require__(5);
  12719. var _annotation_layer = __w_pdfjs_require__(18);
  12720. var _worker_options = __w_pdfjs_require__(12);
  12721. var _is_node = __w_pdfjs_require__(3);
  12722. var _text_layer = __w_pdfjs_require__(21);
  12723. var _svg = __w_pdfjs_require__(22);
  12724. var _xfa_layer = __w_pdfjs_require__(20);
  12725. const pdfjsVersion = '2.13.216';
  12726. const pdfjsBuild = '399a0ec60';
  12727. {
  12728. if (_is_node.isNodeJS) {
  12729. const {
  12730. PDFNodeStream
  12731. } = __w_pdfjs_require__(23);
  12732. (0, _api.setPDFNetworkStreamFactory)(params => {
  12733. return new PDFNodeStream(params);
  12734. });
  12735. } else {
  12736. const {
  12737. PDFNetworkStream
  12738. } = __w_pdfjs_require__(26);
  12739. const {
  12740. PDFFetchStream
  12741. } = __w_pdfjs_require__(27);
  12742. (0, _api.setPDFNetworkStreamFactory)(params => {
  12743. if ((0, _display_utils.isValidFetchUrl)(params.url)) {
  12744. return new PDFFetchStream(params);
  12745. }
  12746. return new PDFNetworkStream(params);
  12747. });
  12748. }
  12749. }
  12750. })();
  12751. /******/ return __webpack_exports__;
  12752. /******/ })()
  12753. ;
  12754. });
  12755. //# sourceMappingURL=pdf.js.map