pdf.js 401 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2020 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. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  37. Object.defineProperty(exports, "__esModule", ({
  38. value: true
  39. }));
  40. Object.defineProperty(exports, "addLinkAttributes", ({
  41. enumerable: true,
  42. get: function () {
  43. return _display_utils.addLinkAttributes;
  44. }
  45. }));
  46. Object.defineProperty(exports, "getFilenameFromUrl", ({
  47. enumerable: true,
  48. get: function () {
  49. return _display_utils.getFilenameFromUrl;
  50. }
  51. }));
  52. Object.defineProperty(exports, "LinkTarget", ({
  53. enumerable: true,
  54. get: function () {
  55. return _display_utils.LinkTarget;
  56. }
  57. }));
  58. Object.defineProperty(exports, "loadScript", ({
  59. enumerable: true,
  60. get: function () {
  61. return _display_utils.loadScript;
  62. }
  63. }));
  64. Object.defineProperty(exports, "PDFDateString", ({
  65. enumerable: true,
  66. get: function () {
  67. return _display_utils.PDFDateString;
  68. }
  69. }));
  70. Object.defineProperty(exports, "RenderingCancelledException", ({
  71. enumerable: true,
  72. get: function () {
  73. return _display_utils.RenderingCancelledException;
  74. }
  75. }));
  76. Object.defineProperty(exports, "build", ({
  77. enumerable: true,
  78. get: function () {
  79. return _api.build;
  80. }
  81. }));
  82. Object.defineProperty(exports, "getDocument", ({
  83. enumerable: true,
  84. get: function () {
  85. return _api.getDocument;
  86. }
  87. }));
  88. Object.defineProperty(exports, "LoopbackPort", ({
  89. enumerable: true,
  90. get: function () {
  91. return _api.LoopbackPort;
  92. }
  93. }));
  94. Object.defineProperty(exports, "PDFDataRangeTransport", ({
  95. enumerable: true,
  96. get: function () {
  97. return _api.PDFDataRangeTransport;
  98. }
  99. }));
  100. Object.defineProperty(exports, "PDFWorker", ({
  101. enumerable: true,
  102. get: function () {
  103. return _api.PDFWorker;
  104. }
  105. }));
  106. Object.defineProperty(exports, "version", ({
  107. enumerable: true,
  108. get: function () {
  109. return _api.version;
  110. }
  111. }));
  112. Object.defineProperty(exports, "CMapCompressionType", ({
  113. enumerable: true,
  114. get: function () {
  115. return _util.CMapCompressionType;
  116. }
  117. }));
  118. Object.defineProperty(exports, "createObjectURL", ({
  119. enumerable: true,
  120. get: function () {
  121. return _util.createObjectURL;
  122. }
  123. }));
  124. Object.defineProperty(exports, "createPromiseCapability", ({
  125. enumerable: true,
  126. get: function () {
  127. return _util.createPromiseCapability;
  128. }
  129. }));
  130. Object.defineProperty(exports, "createValidAbsoluteUrl", ({
  131. enumerable: true,
  132. get: function () {
  133. return _util.createValidAbsoluteUrl;
  134. }
  135. }));
  136. Object.defineProperty(exports, "InvalidPDFException", ({
  137. enumerable: true,
  138. get: function () {
  139. return _util.InvalidPDFException;
  140. }
  141. }));
  142. Object.defineProperty(exports, "MissingPDFException", ({
  143. enumerable: true,
  144. get: function () {
  145. return _util.MissingPDFException;
  146. }
  147. }));
  148. Object.defineProperty(exports, "OPS", ({
  149. enumerable: true,
  150. get: function () {
  151. return _util.OPS;
  152. }
  153. }));
  154. Object.defineProperty(exports, "PasswordResponses", ({
  155. enumerable: true,
  156. get: function () {
  157. return _util.PasswordResponses;
  158. }
  159. }));
  160. Object.defineProperty(exports, "PermissionFlag", ({
  161. enumerable: true,
  162. get: function () {
  163. return _util.PermissionFlag;
  164. }
  165. }));
  166. Object.defineProperty(exports, "removeNullCharacters", ({
  167. enumerable: true,
  168. get: function () {
  169. return _util.removeNullCharacters;
  170. }
  171. }));
  172. Object.defineProperty(exports, "shadow", ({
  173. enumerable: true,
  174. get: function () {
  175. return _util.shadow;
  176. }
  177. }));
  178. Object.defineProperty(exports, "UnexpectedResponseException", ({
  179. enumerable: true,
  180. get: function () {
  181. return _util.UnexpectedResponseException;
  182. }
  183. }));
  184. Object.defineProperty(exports, "UNSUPPORTED_FEATURES", ({
  185. enumerable: true,
  186. get: function () {
  187. return _util.UNSUPPORTED_FEATURES;
  188. }
  189. }));
  190. Object.defineProperty(exports, "Util", ({
  191. enumerable: true,
  192. get: function () {
  193. return _util.Util;
  194. }
  195. }));
  196. Object.defineProperty(exports, "VerbosityLevel", ({
  197. enumerable: true,
  198. get: function () {
  199. return _util.VerbosityLevel;
  200. }
  201. }));
  202. Object.defineProperty(exports, "AnnotationLayer", ({
  203. enumerable: true,
  204. get: function () {
  205. return _annotation_layer.AnnotationLayer;
  206. }
  207. }));
  208. Object.defineProperty(exports, "apiCompatibilityParams", ({
  209. enumerable: true,
  210. get: function () {
  211. return _api_compatibility.apiCompatibilityParams;
  212. }
  213. }));
  214. Object.defineProperty(exports, "GlobalWorkerOptions", ({
  215. enumerable: true,
  216. get: function () {
  217. return _worker_options.GlobalWorkerOptions;
  218. }
  219. }));
  220. Object.defineProperty(exports, "renderTextLayer", ({
  221. enumerable: true,
  222. get: function () {
  223. return _text_layer.renderTextLayer;
  224. }
  225. }));
  226. Object.defineProperty(exports, "SVGGraphics", ({
  227. enumerable: true,
  228. get: function () {
  229. return _svg.SVGGraphics;
  230. }
  231. }));
  232. var _display_utils = __w_pdfjs_require__(1);
  233. var _api = __w_pdfjs_require__(5);
  234. var _util = __w_pdfjs_require__(2);
  235. var _annotation_layer = __w_pdfjs_require__(19);
  236. var _api_compatibility = __w_pdfjs_require__(9);
  237. var _worker_options = __w_pdfjs_require__(12);
  238. var _text_layer = __w_pdfjs_require__(21);
  239. var _svg = __w_pdfjs_require__(22);
  240. const pdfjsVersion = '2.7.570';
  241. const pdfjsBuild = 'f2c7338b0';
  242. {
  243. const {
  244. isNodeJS
  245. } = __w_pdfjs_require__(4);
  246. if (isNodeJS) {
  247. const PDFNodeStream = __w_pdfjs_require__(23).PDFNodeStream;
  248. (0, _api.setPDFNetworkStreamFactory)(params => {
  249. return new PDFNodeStream(params);
  250. });
  251. } else {
  252. const PDFNetworkStream = __w_pdfjs_require__(26).PDFNetworkStream;
  253. let PDFFetchStream;
  254. if ((0, _display_utils.isFetchSupported)()) {
  255. PDFFetchStream = __w_pdfjs_require__(27).PDFFetchStream;
  256. }
  257. (0, _api.setPDFNetworkStreamFactory)(params => {
  258. if (PDFFetchStream && (0, _display_utils.isValidFetchUrl)(params.url)) {
  259. return new PDFFetchStream(params);
  260. }
  261. return new PDFNetworkStream(params);
  262. });
  263. }
  264. }
  265. /***/ }),
  266. /* 1 */
  267. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  268. Object.defineProperty(exports, "__esModule", ({
  269. value: true
  270. }));
  271. exports.addLinkAttributes = addLinkAttributes;
  272. exports.deprecated = deprecated;
  273. exports.getFilenameFromUrl = getFilenameFromUrl;
  274. exports.isFetchSupported = isFetchSupported;
  275. exports.isValidFetchUrl = isValidFetchUrl;
  276. exports.loadScript = loadScript;
  277. exports.StatTimer = exports.RenderingCancelledException = exports.PDFDateString = exports.PageViewport = exports.LinkTarget = exports.DOMSVGFactory = exports.DOMCMapReaderFactory = exports.DOMCanvasFactory = exports.DEFAULT_LINK_REL = exports.BaseCMapReaderFactory = exports.BaseCanvasFactory = void 0;
  278. var _util = __w_pdfjs_require__(2);
  279. const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
  280. exports.DEFAULT_LINK_REL = DEFAULT_LINK_REL;
  281. const SVG_NS = "http://www.w3.org/2000/svg";
  282. class BaseCanvasFactory {
  283. constructor() {
  284. if (this.constructor === BaseCanvasFactory) {
  285. (0, _util.unreachable)("Cannot initialize BaseCanvasFactory.");
  286. }
  287. }
  288. create(width, height) {
  289. (0, _util.unreachable)("Abstract method `create` called.");
  290. }
  291. reset(canvasAndContext, width, height) {
  292. if (!canvasAndContext.canvas) {
  293. throw new Error("Canvas is not specified");
  294. }
  295. if (width <= 0 || height <= 0) {
  296. throw new Error("Invalid canvas size");
  297. }
  298. canvasAndContext.canvas.width = width;
  299. canvasAndContext.canvas.height = height;
  300. }
  301. destroy(canvasAndContext) {
  302. if (!canvasAndContext.canvas) {
  303. throw new Error("Canvas is not specified");
  304. }
  305. canvasAndContext.canvas.width = 0;
  306. canvasAndContext.canvas.height = 0;
  307. canvasAndContext.canvas = null;
  308. canvasAndContext.context = null;
  309. }
  310. }
  311. exports.BaseCanvasFactory = BaseCanvasFactory;
  312. class DOMCanvasFactory extends BaseCanvasFactory {
  313. constructor({
  314. ownerDocument = globalThis.document
  315. } = {}) {
  316. super();
  317. this._document = ownerDocument;
  318. }
  319. create(width, height) {
  320. if (width <= 0 || height <= 0) {
  321. throw new Error("Invalid canvas size");
  322. }
  323. const canvas = this._document.createElement("canvas");
  324. const context = canvas.getContext("2d");
  325. canvas.width = width;
  326. canvas.height = height;
  327. return {
  328. canvas,
  329. context
  330. };
  331. }
  332. }
  333. exports.DOMCanvasFactory = DOMCanvasFactory;
  334. class BaseCMapReaderFactory {
  335. constructor({
  336. baseUrl = null,
  337. isCompressed = false
  338. }) {
  339. if (this.constructor === BaseCMapReaderFactory) {
  340. (0, _util.unreachable)("Cannot initialize BaseCMapReaderFactory.");
  341. }
  342. this.baseUrl = baseUrl;
  343. this.isCompressed = isCompressed;
  344. }
  345. async fetch({
  346. name
  347. }) {
  348. if (!this.baseUrl) {
  349. throw new Error('The CMap "baseUrl" parameter must be specified, ensure that ' + 'the "cMapUrl" and "cMapPacked" API parameters are provided.');
  350. }
  351. if (!name) {
  352. throw new Error("CMap name must be specified.");
  353. }
  354. const url = this.baseUrl + name + (this.isCompressed ? ".bcmap" : "");
  355. const compressionType = this.isCompressed ? _util.CMapCompressionType.BINARY : _util.CMapCompressionType.NONE;
  356. return this._fetchData(url, compressionType).catch(reason => {
  357. throw new Error(`Unable to load ${this.isCompressed ? "binary " : ""}CMap at: ${url}`);
  358. });
  359. }
  360. _fetchData(url, compressionType) {
  361. (0, _util.unreachable)("Abstract method `_fetchData` called.");
  362. }
  363. }
  364. exports.BaseCMapReaderFactory = BaseCMapReaderFactory;
  365. class DOMCMapReaderFactory extends BaseCMapReaderFactory {
  366. _fetchData(url, compressionType) {
  367. if (isFetchSupported() && isValidFetchUrl(url, document.baseURI)) {
  368. return fetch(url).then(async response => {
  369. if (!response.ok) {
  370. throw new Error(response.statusText);
  371. }
  372. let cMapData;
  373. if (this.isCompressed) {
  374. cMapData = new Uint8Array(await response.arrayBuffer());
  375. } else {
  376. cMapData = (0, _util.stringToBytes)(await response.text());
  377. }
  378. return {
  379. cMapData,
  380. compressionType
  381. };
  382. });
  383. }
  384. return new Promise((resolve, reject) => {
  385. const request = new XMLHttpRequest();
  386. request.open("GET", url, true);
  387. if (this.isCompressed) {
  388. request.responseType = "arraybuffer";
  389. }
  390. request.onreadystatechange = () => {
  391. if (request.readyState !== XMLHttpRequest.DONE) {
  392. return;
  393. }
  394. if (request.status === 200 || request.status === 0) {
  395. let cMapData;
  396. if (this.isCompressed && request.response) {
  397. cMapData = new Uint8Array(request.response);
  398. } else if (!this.isCompressed && request.responseText) {
  399. cMapData = (0, _util.stringToBytes)(request.responseText);
  400. }
  401. if (cMapData) {
  402. resolve({
  403. cMapData,
  404. compressionType
  405. });
  406. return;
  407. }
  408. }
  409. reject(new Error(request.statusText));
  410. };
  411. request.send(null);
  412. });
  413. }
  414. }
  415. exports.DOMCMapReaderFactory = DOMCMapReaderFactory;
  416. class DOMSVGFactory {
  417. create(width, height) {
  418. (0, _util.assert)(width > 0 && height > 0, "Invalid SVG dimensions");
  419. const svg = document.createElementNS(SVG_NS, "svg:svg");
  420. svg.setAttribute("version", "1.1");
  421. svg.setAttribute("width", width + "px");
  422. svg.setAttribute("height", height + "px");
  423. svg.setAttribute("preserveAspectRatio", "none");
  424. svg.setAttribute("viewBox", "0 0 " + width + " " + height);
  425. return svg;
  426. }
  427. createElement(type) {
  428. (0, _util.assert)(typeof type === "string", "Invalid SVG element type");
  429. return document.createElementNS(SVG_NS, type);
  430. }
  431. }
  432. exports.DOMSVGFactory = DOMSVGFactory;
  433. class PageViewport {
  434. constructor({
  435. viewBox,
  436. scale,
  437. rotation,
  438. offsetX = 0,
  439. offsetY = 0,
  440. dontFlip = false
  441. }) {
  442. this.viewBox = viewBox;
  443. this.scale = scale;
  444. this.rotation = rotation;
  445. this.offsetX = offsetX;
  446. this.offsetY = offsetY;
  447. const centerX = (viewBox[2] + viewBox[0]) / 2;
  448. const centerY = (viewBox[3] + viewBox[1]) / 2;
  449. let rotateA, rotateB, rotateC, rotateD;
  450. rotation = rotation % 360;
  451. rotation = rotation < 0 ? rotation + 360 : rotation;
  452. switch (rotation) {
  453. case 180:
  454. rotateA = -1;
  455. rotateB = 0;
  456. rotateC = 0;
  457. rotateD = 1;
  458. break;
  459. case 90:
  460. rotateA = 0;
  461. rotateB = 1;
  462. rotateC = 1;
  463. rotateD = 0;
  464. break;
  465. case 270:
  466. rotateA = 0;
  467. rotateB = -1;
  468. rotateC = -1;
  469. rotateD = 0;
  470. break;
  471. case 0:
  472. rotateA = 1;
  473. rotateB = 0;
  474. rotateC = 0;
  475. rotateD = -1;
  476. break;
  477. default:
  478. throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.");
  479. }
  480. if (dontFlip) {
  481. rotateC = -rotateC;
  482. rotateD = -rotateD;
  483. }
  484. let offsetCanvasX, offsetCanvasY;
  485. let width, height;
  486. if (rotateA === 0) {
  487. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  488. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  489. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  490. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  491. } else {
  492. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  493. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  494. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  495. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  496. }
  497. this.transform = [rotateA * scale, rotateB * scale, rotateC * scale, rotateD * scale, offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY, offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY];
  498. this.width = width;
  499. this.height = height;
  500. }
  501. clone({
  502. scale = this.scale,
  503. rotation = this.rotation,
  504. offsetX = this.offsetX,
  505. offsetY = this.offsetY,
  506. dontFlip = false
  507. } = {}) {
  508. return new PageViewport({
  509. viewBox: this.viewBox.slice(),
  510. scale,
  511. rotation,
  512. offsetX,
  513. offsetY,
  514. dontFlip
  515. });
  516. }
  517. convertToViewportPoint(x, y) {
  518. return _util.Util.applyTransform([x, y], this.transform);
  519. }
  520. convertToViewportRectangle(rect) {
  521. const topLeft = _util.Util.applyTransform([rect[0], rect[1]], this.transform);
  522. const bottomRight = _util.Util.applyTransform([rect[2], rect[3]], this.transform);
  523. return [topLeft[0], topLeft[1], bottomRight[0], bottomRight[1]];
  524. }
  525. convertToPdfPoint(x, y) {
  526. return _util.Util.applyInverseTransform([x, y], this.transform);
  527. }
  528. }
  529. exports.PageViewport = PageViewport;
  530. class RenderingCancelledException extends _util.BaseException {
  531. constructor(msg, type) {
  532. super(msg);
  533. this.type = type;
  534. }
  535. }
  536. exports.RenderingCancelledException = RenderingCancelledException;
  537. const LinkTarget = {
  538. NONE: 0,
  539. SELF: 1,
  540. BLANK: 2,
  541. PARENT: 3,
  542. TOP: 4
  543. };
  544. exports.LinkTarget = LinkTarget;
  545. function addLinkAttributes(link, {
  546. url,
  547. target,
  548. rel,
  549. enabled = true
  550. } = {}) {
  551. (0, _util.assert)(url && typeof url === "string", 'addLinkAttributes: A valid "url" parameter must provided.');
  552. const urlNullRemoved = (0, _util.removeNullCharacters)(url);
  553. if (enabled) {
  554. link.href = link.title = urlNullRemoved;
  555. } else {
  556. link.href = "";
  557. link.title = `Disabled: ${urlNullRemoved}`;
  558. link.onclick = () => {
  559. return false;
  560. };
  561. }
  562. let targetStr = "";
  563. switch (target) {
  564. case LinkTarget.NONE:
  565. break;
  566. case LinkTarget.SELF:
  567. targetStr = "_self";
  568. break;
  569. case LinkTarget.BLANK:
  570. targetStr = "_blank";
  571. break;
  572. case LinkTarget.PARENT:
  573. targetStr = "_parent";
  574. break;
  575. case LinkTarget.TOP:
  576. targetStr = "_top";
  577. break;
  578. }
  579. link.target = targetStr;
  580. link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL;
  581. }
  582. function getFilenameFromUrl(url) {
  583. const anchor = url.indexOf("#");
  584. const query = url.indexOf("?");
  585. const end = Math.min(anchor > 0 ? anchor : url.length, query > 0 ? query : url.length);
  586. return url.substring(url.lastIndexOf("/", end) + 1, end);
  587. }
  588. class StatTimer {
  589. constructor() {
  590. this.started = Object.create(null);
  591. this.times = [];
  592. }
  593. time(name) {
  594. if (name in this.started) {
  595. (0, _util.warn)(`Timer is already running for ${name}`);
  596. }
  597. this.started[name] = Date.now();
  598. }
  599. timeEnd(name) {
  600. if (!(name in this.started)) {
  601. (0, _util.warn)(`Timer has not been started for ${name}`);
  602. }
  603. this.times.push({
  604. name,
  605. start: this.started[name],
  606. end: Date.now()
  607. });
  608. delete this.started[name];
  609. }
  610. toString() {
  611. const outBuf = [];
  612. let longest = 0;
  613. for (const time of this.times) {
  614. const name = time.name;
  615. if (name.length > longest) {
  616. longest = name.length;
  617. }
  618. }
  619. for (const time of this.times) {
  620. const duration = time.end - time.start;
  621. outBuf.push(`${time.name.padEnd(longest)} ${duration}ms\n`);
  622. }
  623. return outBuf.join("");
  624. }
  625. }
  626. exports.StatTimer = StatTimer;
  627. function isFetchSupported() {
  628. return typeof fetch !== "undefined" && typeof Response !== "undefined" && "body" in Response.prototype && typeof ReadableStream !== "undefined";
  629. }
  630. function isValidFetchUrl(url, baseUrl) {
  631. try {
  632. const {
  633. protocol
  634. } = baseUrl ? new URL(url, baseUrl) : new URL(url);
  635. return protocol === "http:" || protocol === "https:";
  636. } catch (ex) {
  637. return false;
  638. }
  639. }
  640. function loadScript(src, removeScriptElement = false) {
  641. return new Promise((resolve, reject) => {
  642. const script = document.createElement("script");
  643. script.src = src;
  644. script.onload = function (evt) {
  645. if (removeScriptElement) {
  646. script.remove();
  647. }
  648. resolve(evt);
  649. };
  650. script.onerror = function () {
  651. reject(new Error(`Cannot load script at: ${script.src}`));
  652. };
  653. (document.head || document.documentElement).appendChild(script);
  654. });
  655. }
  656. function deprecated(details) {
  657. console.log("Deprecated API usage: " + details);
  658. }
  659. let pdfDateStringRegex;
  660. class PDFDateString {
  661. static toDateObject(input) {
  662. if (!input || !(0, _util.isString)(input)) {
  663. return null;
  664. }
  665. if (!pdfDateStringRegex) {
  666. pdfDateStringRegex = new RegExp("^D:" + "(\\d{4})" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "([Z|+|-])?" + "(\\d{2})?" + "'?" + "(\\d{2})?" + "'?");
  667. }
  668. const matches = pdfDateStringRegex.exec(input);
  669. if (!matches) {
  670. return null;
  671. }
  672. const year = parseInt(matches[1], 10);
  673. let month = parseInt(matches[2], 10);
  674. month = month >= 1 && month <= 12 ? month - 1 : 0;
  675. let day = parseInt(matches[3], 10);
  676. day = day >= 1 && day <= 31 ? day : 1;
  677. let hour = parseInt(matches[4], 10);
  678. hour = hour >= 0 && hour <= 23 ? hour : 0;
  679. let minute = parseInt(matches[5], 10);
  680. minute = minute >= 0 && minute <= 59 ? minute : 0;
  681. let second = parseInt(matches[6], 10);
  682. second = second >= 0 && second <= 59 ? second : 0;
  683. const universalTimeRelation = matches[7] || "Z";
  684. let offsetHour = parseInt(matches[8], 10);
  685. offsetHour = offsetHour >= 0 && offsetHour <= 23 ? offsetHour : 0;
  686. let offsetMinute = parseInt(matches[9], 10) || 0;
  687. offsetMinute = offsetMinute >= 0 && offsetMinute <= 59 ? offsetMinute : 0;
  688. if (universalTimeRelation === "-") {
  689. hour += offsetHour;
  690. minute += offsetMinute;
  691. } else if (universalTimeRelation === "+") {
  692. hour -= offsetHour;
  693. minute -= offsetMinute;
  694. }
  695. return new Date(Date.UTC(year, month, day, hour, minute, second));
  696. }
  697. }
  698. exports.PDFDateString = PDFDateString;
  699. /***/ }),
  700. /* 2 */
  701. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  702. Object.defineProperty(exports, "__esModule", ({
  703. value: true
  704. }));
  705. exports.arrayByteLength = arrayByteLength;
  706. exports.arraysToBytes = arraysToBytes;
  707. exports.assert = assert;
  708. exports.bytesToString = bytesToString;
  709. exports.createPromiseCapability = createPromiseCapability;
  710. exports.createValidAbsoluteUrl = createValidAbsoluteUrl;
  711. exports.encodeToXmlString = encodeToXmlString;
  712. exports.escapeString = escapeString;
  713. exports.getModificationDate = getModificationDate;
  714. exports.getVerbosityLevel = getVerbosityLevel;
  715. exports.info = info;
  716. exports.isArrayBuffer = isArrayBuffer;
  717. exports.isArrayEqual = isArrayEqual;
  718. exports.isAscii = isAscii;
  719. exports.isBool = isBool;
  720. exports.isNum = isNum;
  721. exports.isSameOrigin = isSameOrigin;
  722. exports.isString = isString;
  723. exports.objectFromEntries = objectFromEntries;
  724. exports.objectSize = objectSize;
  725. exports.removeNullCharacters = removeNullCharacters;
  726. exports.setVerbosityLevel = setVerbosityLevel;
  727. exports.shadow = shadow;
  728. exports.string32 = string32;
  729. exports.stringToBytes = stringToBytes;
  730. exports.stringToPDFString = stringToPDFString;
  731. exports.stringToUTF16BEString = stringToUTF16BEString;
  732. exports.stringToUTF8String = stringToUTF8String;
  733. exports.unreachable = unreachable;
  734. exports.utf8StringToString = utf8StringToString;
  735. exports.warn = warn;
  736. exports.VerbosityLevel = exports.Util = exports.UNSUPPORTED_FEATURES = exports.UnknownErrorException = exports.UnexpectedResponseException = exports.TextRenderingMode = exports.StreamType = exports.PermissionFlag = exports.PasswordResponses = exports.PasswordException = exports.PageActionEventType = exports.OPS = exports.MissingPDFException = exports.IsLittleEndianCached = exports.IsEvalSupportedCached = exports.InvalidPDFException = exports.ImageKind = exports.IDENTITY_MATRIX = exports.FormatError = exports.FontType = exports.FONT_IDENTITY_MATRIX = exports.DocumentActionEventType = exports.createObjectURL = exports.CMapCompressionType = exports.BaseException = exports.AnnotationType = exports.AnnotationStateModelType = exports.AnnotationReviewState = exports.AnnotationReplyType = exports.AnnotationMarkedState = exports.AnnotationFlag = exports.AnnotationFieldFlag = exports.AnnotationBorderStyleType = exports.AnnotationActionEventType = exports.AbortException = void 0;
  737. __w_pdfjs_require__(3);
  738. const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  739. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  740. const FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  741. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  742. const PermissionFlag = {
  743. PRINT: 0x04,
  744. MODIFY_CONTENTS: 0x08,
  745. COPY: 0x10,
  746. MODIFY_ANNOTATIONS: 0x20,
  747. FILL_INTERACTIVE_FORMS: 0x100,
  748. COPY_FOR_ACCESSIBILITY: 0x200,
  749. ASSEMBLE: 0x400,
  750. PRINT_HIGH_QUALITY: 0x800
  751. };
  752. exports.PermissionFlag = PermissionFlag;
  753. const TextRenderingMode = {
  754. FILL: 0,
  755. STROKE: 1,
  756. FILL_STROKE: 2,
  757. INVISIBLE: 3,
  758. FILL_ADD_TO_PATH: 4,
  759. STROKE_ADD_TO_PATH: 5,
  760. FILL_STROKE_ADD_TO_PATH: 6,
  761. ADD_TO_PATH: 7,
  762. FILL_STROKE_MASK: 3,
  763. ADD_TO_PATH_FLAG: 4
  764. };
  765. exports.TextRenderingMode = TextRenderingMode;
  766. const ImageKind = {
  767. GRAYSCALE_1BPP: 1,
  768. RGB_24BPP: 2,
  769. RGBA_32BPP: 3
  770. };
  771. exports.ImageKind = ImageKind;
  772. const AnnotationType = {
  773. TEXT: 1,
  774. LINK: 2,
  775. FREETEXT: 3,
  776. LINE: 4,
  777. SQUARE: 5,
  778. CIRCLE: 6,
  779. POLYGON: 7,
  780. POLYLINE: 8,
  781. HIGHLIGHT: 9,
  782. UNDERLINE: 10,
  783. SQUIGGLY: 11,
  784. STRIKEOUT: 12,
  785. STAMP: 13,
  786. CARET: 14,
  787. INK: 15,
  788. POPUP: 16,
  789. FILEATTACHMENT: 17,
  790. SOUND: 18,
  791. MOVIE: 19,
  792. WIDGET: 20,
  793. SCREEN: 21,
  794. PRINTERMARK: 22,
  795. TRAPNET: 23,
  796. WATERMARK: 24,
  797. THREED: 25,
  798. REDACT: 26
  799. };
  800. exports.AnnotationType = AnnotationType;
  801. const AnnotationStateModelType = {
  802. MARKED: "Marked",
  803. REVIEW: "Review"
  804. };
  805. exports.AnnotationStateModelType = AnnotationStateModelType;
  806. const AnnotationMarkedState = {
  807. MARKED: "Marked",
  808. UNMARKED: "Unmarked"
  809. };
  810. exports.AnnotationMarkedState = AnnotationMarkedState;
  811. const AnnotationReviewState = {
  812. ACCEPTED: "Accepted",
  813. REJECTED: "Rejected",
  814. CANCELLED: "Cancelled",
  815. COMPLETED: "Completed",
  816. NONE: "None"
  817. };
  818. exports.AnnotationReviewState = AnnotationReviewState;
  819. const AnnotationReplyType = {
  820. GROUP: "Group",
  821. REPLY: "R"
  822. };
  823. exports.AnnotationReplyType = AnnotationReplyType;
  824. const AnnotationFlag = {
  825. INVISIBLE: 0x01,
  826. HIDDEN: 0x02,
  827. PRINT: 0x04,
  828. NOZOOM: 0x08,
  829. NOROTATE: 0x10,
  830. NOVIEW: 0x20,
  831. READONLY: 0x40,
  832. LOCKED: 0x80,
  833. TOGGLENOVIEW: 0x100,
  834. LOCKEDCONTENTS: 0x200
  835. };
  836. exports.AnnotationFlag = AnnotationFlag;
  837. const AnnotationFieldFlag = {
  838. READONLY: 0x0000001,
  839. REQUIRED: 0x0000002,
  840. NOEXPORT: 0x0000004,
  841. MULTILINE: 0x0001000,
  842. PASSWORD: 0x0002000,
  843. NOTOGGLETOOFF: 0x0004000,
  844. RADIO: 0x0008000,
  845. PUSHBUTTON: 0x0010000,
  846. COMBO: 0x0020000,
  847. EDIT: 0x0040000,
  848. SORT: 0x0080000,
  849. FILESELECT: 0x0100000,
  850. MULTISELECT: 0x0200000,
  851. DONOTSPELLCHECK: 0x0400000,
  852. DONOTSCROLL: 0x0800000,
  853. COMB: 0x1000000,
  854. RICHTEXT: 0x2000000,
  855. RADIOSINUNISON: 0x2000000,
  856. COMMITONSELCHANGE: 0x4000000
  857. };
  858. exports.AnnotationFieldFlag = AnnotationFieldFlag;
  859. const AnnotationBorderStyleType = {
  860. SOLID: 1,
  861. DASHED: 2,
  862. BEVELED: 3,
  863. INSET: 4,
  864. UNDERLINE: 5
  865. };
  866. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  867. const AnnotationActionEventType = {
  868. E: "Mouse Enter",
  869. X: "Mouse Exit",
  870. D: "Mouse Down",
  871. U: "Mouse Up",
  872. Fo: "Focus",
  873. Bl: "Blur",
  874. PO: "PageOpen",
  875. PC: "PageClose",
  876. PV: "PageVisible",
  877. PI: "PageInvisible",
  878. K: "Keystroke",
  879. F: "Format",
  880. V: "Validate",
  881. C: "Calculate"
  882. };
  883. exports.AnnotationActionEventType = AnnotationActionEventType;
  884. const DocumentActionEventType = {
  885. WC: "WillClose",
  886. WS: "WillSave",
  887. DS: "DidSave",
  888. WP: "WillPrint",
  889. DP: "DidPrint"
  890. };
  891. exports.DocumentActionEventType = DocumentActionEventType;
  892. const PageActionEventType = {
  893. O: "PageOpen",
  894. C: "PageClose"
  895. };
  896. exports.PageActionEventType = PageActionEventType;
  897. const StreamType = {
  898. UNKNOWN: "UNKNOWN",
  899. FLATE: "FLATE",
  900. LZW: "LZW",
  901. DCT: "DCT",
  902. JPX: "JPX",
  903. JBIG: "JBIG",
  904. A85: "A85",
  905. AHX: "AHX",
  906. CCF: "CCF",
  907. RLX: "RLX"
  908. };
  909. exports.StreamType = StreamType;
  910. const FontType = {
  911. UNKNOWN: "UNKNOWN",
  912. TYPE1: "TYPE1",
  913. TYPE1C: "TYPE1C",
  914. CIDFONTTYPE0: "CIDFONTTYPE0",
  915. CIDFONTTYPE0C: "CIDFONTTYPE0C",
  916. TRUETYPE: "TRUETYPE",
  917. CIDFONTTYPE2: "CIDFONTTYPE2",
  918. TYPE3: "TYPE3",
  919. OPENTYPE: "OPENTYPE",
  920. TYPE0: "TYPE0",
  921. MMTYPE1: "MMTYPE1"
  922. };
  923. exports.FontType = FontType;
  924. const VerbosityLevel = {
  925. ERRORS: 0,
  926. WARNINGS: 1,
  927. INFOS: 5
  928. };
  929. exports.VerbosityLevel = VerbosityLevel;
  930. const CMapCompressionType = {
  931. NONE: 0,
  932. BINARY: 1,
  933. STREAM: 2
  934. };
  935. exports.CMapCompressionType = CMapCompressionType;
  936. const OPS = {
  937. dependency: 1,
  938. setLineWidth: 2,
  939. setLineCap: 3,
  940. setLineJoin: 4,
  941. setMiterLimit: 5,
  942. setDash: 6,
  943. setRenderingIntent: 7,
  944. setFlatness: 8,
  945. setGState: 9,
  946. save: 10,
  947. restore: 11,
  948. transform: 12,
  949. moveTo: 13,
  950. lineTo: 14,
  951. curveTo: 15,
  952. curveTo2: 16,
  953. curveTo3: 17,
  954. closePath: 18,
  955. rectangle: 19,
  956. stroke: 20,
  957. closeStroke: 21,
  958. fill: 22,
  959. eoFill: 23,
  960. fillStroke: 24,
  961. eoFillStroke: 25,
  962. closeFillStroke: 26,
  963. closeEOFillStroke: 27,
  964. endPath: 28,
  965. clip: 29,
  966. eoClip: 30,
  967. beginText: 31,
  968. endText: 32,
  969. setCharSpacing: 33,
  970. setWordSpacing: 34,
  971. setHScale: 35,
  972. setLeading: 36,
  973. setFont: 37,
  974. setTextRenderingMode: 38,
  975. setTextRise: 39,
  976. moveText: 40,
  977. setLeadingMoveText: 41,
  978. setTextMatrix: 42,
  979. nextLine: 43,
  980. showText: 44,
  981. showSpacedText: 45,
  982. nextLineShowText: 46,
  983. nextLineSetSpacingShowText: 47,
  984. setCharWidth: 48,
  985. setCharWidthAndBounds: 49,
  986. setStrokeColorSpace: 50,
  987. setFillColorSpace: 51,
  988. setStrokeColor: 52,
  989. setStrokeColorN: 53,
  990. setFillColor: 54,
  991. setFillColorN: 55,
  992. setStrokeGray: 56,
  993. setFillGray: 57,
  994. setStrokeRGBColor: 58,
  995. setFillRGBColor: 59,
  996. setStrokeCMYKColor: 60,
  997. setFillCMYKColor: 61,
  998. shadingFill: 62,
  999. beginInlineImage: 63,
  1000. beginImageData: 64,
  1001. endInlineImage: 65,
  1002. paintXObject: 66,
  1003. markPoint: 67,
  1004. markPointProps: 68,
  1005. beginMarkedContent: 69,
  1006. beginMarkedContentProps: 70,
  1007. endMarkedContent: 71,
  1008. beginCompat: 72,
  1009. endCompat: 73,
  1010. paintFormXObjectBegin: 74,
  1011. paintFormXObjectEnd: 75,
  1012. beginGroup: 76,
  1013. endGroup: 77,
  1014. beginAnnotations: 78,
  1015. endAnnotations: 79,
  1016. beginAnnotation: 80,
  1017. endAnnotation: 81,
  1018. paintJpegXObject: 82,
  1019. paintImageMaskXObject: 83,
  1020. paintImageMaskXObjectGroup: 84,
  1021. paintImageXObject: 85,
  1022. paintInlineImageXObject: 86,
  1023. paintInlineImageXObjectGroup: 87,
  1024. paintImageXObjectRepeat: 88,
  1025. paintImageMaskXObjectRepeat: 89,
  1026. paintSolidColorImageMask: 90,
  1027. constructPath: 91
  1028. };
  1029. exports.OPS = OPS;
  1030. const UNSUPPORTED_FEATURES = {
  1031. unknown: "unknown",
  1032. forms: "forms",
  1033. javaScript: "javaScript",
  1034. smask: "smask",
  1035. shadingPattern: "shadingPattern",
  1036. font: "font",
  1037. errorTilingPattern: "errorTilingPattern",
  1038. errorExtGState: "errorExtGState",
  1039. errorXObject: "errorXObject",
  1040. errorFontLoadType3: "errorFontLoadType3",
  1041. errorFontState: "errorFontState",
  1042. errorFontMissing: "errorFontMissing",
  1043. errorFontTranslate: "errorFontTranslate",
  1044. errorColorSpace: "errorColorSpace",
  1045. errorOperatorList: "errorOperatorList",
  1046. errorFontToUnicode: "errorFontToUnicode",
  1047. errorFontLoadNative: "errorFontLoadNative",
  1048. errorFontGetPath: "errorFontGetPath",
  1049. errorMarkedContent: "errorMarkedContent"
  1050. };
  1051. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  1052. const PasswordResponses = {
  1053. NEED_PASSWORD: 1,
  1054. INCORRECT_PASSWORD: 2
  1055. };
  1056. exports.PasswordResponses = PasswordResponses;
  1057. let verbosity = VerbosityLevel.WARNINGS;
  1058. function setVerbosityLevel(level) {
  1059. if (Number.isInteger(level)) {
  1060. verbosity = level;
  1061. }
  1062. }
  1063. function getVerbosityLevel() {
  1064. return verbosity;
  1065. }
  1066. function info(msg) {
  1067. if (verbosity >= VerbosityLevel.INFOS) {
  1068. console.log(`Info: ${msg}`);
  1069. }
  1070. }
  1071. function warn(msg) {
  1072. if (verbosity >= VerbosityLevel.WARNINGS) {
  1073. console.log(`Warning: ${msg}`);
  1074. }
  1075. }
  1076. function unreachable(msg) {
  1077. throw new Error(msg);
  1078. }
  1079. function assert(cond, msg) {
  1080. if (!cond) {
  1081. unreachable(msg);
  1082. }
  1083. }
  1084. function isSameOrigin(baseUrl, otherUrl) {
  1085. let base;
  1086. try {
  1087. base = new URL(baseUrl);
  1088. if (!base.origin || base.origin === "null") {
  1089. return false;
  1090. }
  1091. } catch (e) {
  1092. return false;
  1093. }
  1094. const other = new URL(otherUrl, base);
  1095. return base.origin === other.origin;
  1096. }
  1097. function _isValidProtocol(url) {
  1098. if (!url) {
  1099. return false;
  1100. }
  1101. switch (url.protocol) {
  1102. case "http:":
  1103. case "https:":
  1104. case "ftp:":
  1105. case "mailto:":
  1106. case "tel:":
  1107. return true;
  1108. default:
  1109. return false;
  1110. }
  1111. }
  1112. function createValidAbsoluteUrl(url, baseUrl) {
  1113. if (!url) {
  1114. return null;
  1115. }
  1116. try {
  1117. const absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url);
  1118. if (_isValidProtocol(absoluteUrl)) {
  1119. return absoluteUrl;
  1120. }
  1121. } catch (ex) {}
  1122. return null;
  1123. }
  1124. function shadow(obj, prop, value) {
  1125. Object.defineProperty(obj, prop, {
  1126. value,
  1127. enumerable: true,
  1128. configurable: true,
  1129. writable: false
  1130. });
  1131. return value;
  1132. }
  1133. const BaseException = function BaseExceptionClosure() {
  1134. function BaseException(message) {
  1135. if (this.constructor === BaseException) {
  1136. unreachable("Cannot initialize BaseException.");
  1137. }
  1138. this.message = message;
  1139. this.name = this.constructor.name;
  1140. }
  1141. BaseException.prototype = new Error();
  1142. BaseException.constructor = BaseException;
  1143. return BaseException;
  1144. }();
  1145. exports.BaseException = BaseException;
  1146. class PasswordException extends BaseException {
  1147. constructor(msg, code) {
  1148. super(msg);
  1149. this.code = code;
  1150. }
  1151. }
  1152. exports.PasswordException = PasswordException;
  1153. class UnknownErrorException extends BaseException {
  1154. constructor(msg, details) {
  1155. super(msg);
  1156. this.details = details;
  1157. }
  1158. }
  1159. exports.UnknownErrorException = UnknownErrorException;
  1160. class InvalidPDFException extends BaseException {}
  1161. exports.InvalidPDFException = InvalidPDFException;
  1162. class MissingPDFException extends BaseException {}
  1163. exports.MissingPDFException = MissingPDFException;
  1164. class UnexpectedResponseException extends BaseException {
  1165. constructor(msg, status) {
  1166. super(msg);
  1167. this.status = status;
  1168. }
  1169. }
  1170. exports.UnexpectedResponseException = UnexpectedResponseException;
  1171. class FormatError extends BaseException {}
  1172. exports.FormatError = FormatError;
  1173. class AbortException extends BaseException {}
  1174. exports.AbortException = AbortException;
  1175. const NullCharactersRegExp = /\x00/g;
  1176. function removeNullCharacters(str) {
  1177. if (typeof str !== "string") {
  1178. warn("The argument for removeNullCharacters must be a string.");
  1179. return str;
  1180. }
  1181. return str.replace(NullCharactersRegExp, "");
  1182. }
  1183. function bytesToString(bytes) {
  1184. assert(bytes !== null && typeof bytes === "object" && bytes.length !== undefined, "Invalid argument for bytesToString");
  1185. const length = bytes.length;
  1186. const MAX_ARGUMENT_COUNT = 8192;
  1187. if (length < MAX_ARGUMENT_COUNT) {
  1188. return String.fromCharCode.apply(null, bytes);
  1189. }
  1190. const strBuf = [];
  1191. for (let i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  1192. const chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  1193. const chunk = bytes.subarray(i, chunkEnd);
  1194. strBuf.push(String.fromCharCode.apply(null, chunk));
  1195. }
  1196. return strBuf.join("");
  1197. }
  1198. function stringToBytes(str) {
  1199. assert(typeof str === "string", "Invalid argument for stringToBytes");
  1200. const length = str.length;
  1201. const bytes = new Uint8Array(length);
  1202. for (let i = 0; i < length; ++i) {
  1203. bytes[i] = str.charCodeAt(i) & 0xff;
  1204. }
  1205. return bytes;
  1206. }
  1207. function arrayByteLength(arr) {
  1208. if (arr.length !== undefined) {
  1209. return arr.length;
  1210. }
  1211. assert(arr.byteLength !== undefined, "arrayByteLength - invalid argument.");
  1212. return arr.byteLength;
  1213. }
  1214. function arraysToBytes(arr) {
  1215. const length = arr.length;
  1216. if (length === 1 && arr[0] instanceof Uint8Array) {
  1217. return arr[0];
  1218. }
  1219. let resultLength = 0;
  1220. for (let i = 0; i < length; i++) {
  1221. resultLength += arrayByteLength(arr[i]);
  1222. }
  1223. let pos = 0;
  1224. const data = new Uint8Array(resultLength);
  1225. for (let i = 0; i < length; i++) {
  1226. let item = arr[i];
  1227. if (!(item instanceof Uint8Array)) {
  1228. if (typeof item === "string") {
  1229. item = stringToBytes(item);
  1230. } else {
  1231. item = new Uint8Array(item);
  1232. }
  1233. }
  1234. const itemLength = item.byteLength;
  1235. data.set(item, pos);
  1236. pos += itemLength;
  1237. }
  1238. return data;
  1239. }
  1240. function string32(value) {
  1241. return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
  1242. }
  1243. function objectSize(obj) {
  1244. return Object.keys(obj).length;
  1245. }
  1246. function objectFromEntries(iterable) {
  1247. return Object.assign(Object.create(null), Object.fromEntries(iterable));
  1248. }
  1249. function isLittleEndian() {
  1250. const buffer8 = new Uint8Array(4);
  1251. buffer8[0] = 1;
  1252. const view32 = new Uint32Array(buffer8.buffer, 0, 1);
  1253. return view32[0] === 1;
  1254. }
  1255. const IsLittleEndianCached = {
  1256. get value() {
  1257. return shadow(this, "value", isLittleEndian());
  1258. }
  1259. };
  1260. exports.IsLittleEndianCached = IsLittleEndianCached;
  1261. function isEvalSupported() {
  1262. try {
  1263. new Function("");
  1264. return true;
  1265. } catch (e) {
  1266. return false;
  1267. }
  1268. }
  1269. const IsEvalSupportedCached = {
  1270. get value() {
  1271. return shadow(this, "value", isEvalSupported());
  1272. }
  1273. };
  1274. exports.IsEvalSupportedCached = IsEvalSupportedCached;
  1275. const hexNumbers = [...Array(256).keys()].map(n => n.toString(16).padStart(2, "0"));
  1276. class Util {
  1277. static makeHexColor(r, g, b) {
  1278. return `#${hexNumbers[r]}${hexNumbers[g]}${hexNumbers[b]}`;
  1279. }
  1280. static transform(m1, m2) {
  1281. 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]];
  1282. }
  1283. static applyTransform(p, m) {
  1284. const xt = p[0] * m[0] + p[1] * m[2] + m[4];
  1285. const yt = p[0] * m[1] + p[1] * m[3] + m[5];
  1286. return [xt, yt];
  1287. }
  1288. static applyInverseTransform(p, m) {
  1289. const d = m[0] * m[3] - m[1] * m[2];
  1290. const xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  1291. const yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  1292. return [xt, yt];
  1293. }
  1294. static getAxialAlignedBoundingBox(r, m) {
  1295. const p1 = Util.applyTransform(r, m);
  1296. const p2 = Util.applyTransform(r.slice(2, 4), m);
  1297. const p3 = Util.applyTransform([r[0], r[3]], m);
  1298. const p4 = Util.applyTransform([r[2], r[1]], m);
  1299. 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])];
  1300. }
  1301. static inverseTransform(m) {
  1302. const d = m[0] * m[3] - m[1] * m[2];
  1303. 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];
  1304. }
  1305. static apply3dTransform(m, v) {
  1306. 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]];
  1307. }
  1308. static singularValueDecompose2dScale(m) {
  1309. const transpose = [m[0], m[2], m[1], m[3]];
  1310. const a = m[0] * transpose[0] + m[1] * transpose[2];
  1311. const b = m[0] * transpose[1] + m[1] * transpose[3];
  1312. const c = m[2] * transpose[0] + m[3] * transpose[2];
  1313. const d = m[2] * transpose[1] + m[3] * transpose[3];
  1314. const first = (a + d) / 2;
  1315. const second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  1316. const sx = first + second || 1;
  1317. const sy = first - second || 1;
  1318. return [Math.sqrt(sx), Math.sqrt(sy)];
  1319. }
  1320. static normalizeRect(rect) {
  1321. const r = rect.slice(0);
  1322. if (rect[0] > rect[2]) {
  1323. r[0] = rect[2];
  1324. r[2] = rect[0];
  1325. }
  1326. if (rect[1] > rect[3]) {
  1327. r[1] = rect[3];
  1328. r[3] = rect[1];
  1329. }
  1330. return r;
  1331. }
  1332. static intersect(rect1, rect2) {
  1333. function compare(a, b) {
  1334. return a - b;
  1335. }
  1336. const orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare);
  1337. const orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare);
  1338. const result = [];
  1339. rect1 = Util.normalizeRect(rect1);
  1340. rect2 = Util.normalizeRect(rect2);
  1341. if (orderedX[0] === rect1[0] && orderedX[1] === rect2[0] || orderedX[0] === rect2[0] && orderedX[1] === rect1[0]) {
  1342. result[0] = orderedX[1];
  1343. result[2] = orderedX[2];
  1344. } else {
  1345. return null;
  1346. }
  1347. if (orderedY[0] === rect1[1] && orderedY[1] === rect2[1] || orderedY[0] === rect2[1] && orderedY[1] === rect1[1]) {
  1348. result[1] = orderedY[1];
  1349. result[3] = orderedY[2];
  1350. } else {
  1351. return null;
  1352. }
  1353. return result;
  1354. }
  1355. }
  1356. exports.Util = Util;
  1357. 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];
  1358. function stringToPDFString(str) {
  1359. const length = str.length,
  1360. strBuf = [];
  1361. if (str[0] === "\xFE" && str[1] === "\xFF") {
  1362. for (let i = 2; i < length; i += 2) {
  1363. strBuf.push(String.fromCharCode(str.charCodeAt(i) << 8 | str.charCodeAt(i + 1)));
  1364. }
  1365. } else if (str[0] === "\xFF" && str[1] === "\xFE") {
  1366. for (let i = 2; i < length; i += 2) {
  1367. strBuf.push(String.fromCharCode(str.charCodeAt(i + 1) << 8 | str.charCodeAt(i)));
  1368. }
  1369. } else {
  1370. for (let i = 0; i < length; ++i) {
  1371. const code = PDFStringTranslateTable[str.charCodeAt(i)];
  1372. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  1373. }
  1374. }
  1375. return strBuf.join("");
  1376. }
  1377. function escapeString(str) {
  1378. return str.replace(/([()\\\n\r])/g, match => {
  1379. if (match === "\n") {
  1380. return "\\n";
  1381. } else if (match === "\r") {
  1382. return "\\r";
  1383. }
  1384. return `\\${match}`;
  1385. });
  1386. }
  1387. function isAscii(str) {
  1388. return /^[\x00-\x7F]*$/.test(str);
  1389. }
  1390. function stringToUTF16BEString(str) {
  1391. const buf = ["\xFE\xFF"];
  1392. for (let i = 0, ii = str.length; i < ii; i++) {
  1393. const char = str.charCodeAt(i);
  1394. buf.push(String.fromCharCode(char >> 8 & 0xff));
  1395. buf.push(String.fromCharCode(char & 0xff));
  1396. }
  1397. return buf.join("");
  1398. }
  1399. function stringToUTF8String(str) {
  1400. return decodeURIComponent(escape(str));
  1401. }
  1402. function utf8StringToString(str) {
  1403. return unescape(encodeURIComponent(str));
  1404. }
  1405. function isBool(v) {
  1406. return typeof v === "boolean";
  1407. }
  1408. function isNum(v) {
  1409. return typeof v === "number";
  1410. }
  1411. function isString(v) {
  1412. return typeof v === "string";
  1413. }
  1414. function isArrayBuffer(v) {
  1415. return typeof v === "object" && v !== null && v.byteLength !== undefined;
  1416. }
  1417. function isArrayEqual(arr1, arr2) {
  1418. if (arr1.length !== arr2.length) {
  1419. return false;
  1420. }
  1421. return arr1.every(function (element, index) {
  1422. return element === arr2[index];
  1423. });
  1424. }
  1425. function getModificationDate(date = new Date()) {
  1426. 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")];
  1427. return buffer.join("");
  1428. }
  1429. function createPromiseCapability() {
  1430. const capability = Object.create(null);
  1431. let isSettled = false;
  1432. Object.defineProperty(capability, "settled", {
  1433. get() {
  1434. return isSettled;
  1435. }
  1436. });
  1437. capability.promise = new Promise(function (resolve, reject) {
  1438. capability.resolve = function (data) {
  1439. isSettled = true;
  1440. resolve(data);
  1441. };
  1442. capability.reject = function (reason) {
  1443. isSettled = true;
  1444. reject(reason);
  1445. };
  1446. });
  1447. return capability;
  1448. }
  1449. const createObjectURL = function createObjectURLClosure() {
  1450. const digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  1451. return function createObjectURL(data, contentType, forceDataSchema = false) {
  1452. if (!forceDataSchema && URL.createObjectURL) {
  1453. const blob = new Blob([data], {
  1454. type: contentType
  1455. });
  1456. return URL.createObjectURL(blob);
  1457. }
  1458. let buffer = `data:${contentType};base64,`;
  1459. for (let i = 0, ii = data.length; i < ii; i += 3) {
  1460. const b1 = data[i] & 0xff;
  1461. const b2 = data[i + 1] & 0xff;
  1462. const b3 = data[i + 2] & 0xff;
  1463. const d1 = b1 >> 2,
  1464. d2 = (b1 & 3) << 4 | b2 >> 4;
  1465. const d3 = i + 1 < ii ? (b2 & 0xf) << 2 | b3 >> 6 : 64;
  1466. const d4 = i + 2 < ii ? b3 & 0x3f : 64;
  1467. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1468. }
  1469. return buffer;
  1470. };
  1471. }();
  1472. exports.createObjectURL = createObjectURL;
  1473. const XMLEntities = {
  1474. 0x3c: "&lt;",
  1475. 0x3e: "&gt;",
  1476. 0x26: "&amp;",
  1477. 0x22: "&quot;",
  1478. 0x27: "&apos;"
  1479. };
  1480. function encodeToXmlString(str) {
  1481. const buffer = [];
  1482. let start = 0;
  1483. for (let i = 0, ii = str.length; i < ii; i++) {
  1484. const char = str.codePointAt(i);
  1485. if (0x20 <= char && char <= 0x7e) {
  1486. const entity = XMLEntities[char];
  1487. if (entity) {
  1488. if (start < i) {
  1489. buffer.push(str.substring(start, i));
  1490. }
  1491. buffer.push(entity);
  1492. start = i + 1;
  1493. }
  1494. } else {
  1495. if (start < i) {
  1496. buffer.push(str.substring(start, i));
  1497. }
  1498. buffer.push(`&#x${char.toString(16).toUpperCase()};`);
  1499. if (char > 0xd7ff && (char < 0xe000 || char > 0xfffd)) {
  1500. i++;
  1501. }
  1502. start = i + 1;
  1503. }
  1504. }
  1505. if (buffer.length === 0) {
  1506. return str;
  1507. }
  1508. if (start < str.length) {
  1509. buffer.push(str.substring(start, str.length));
  1510. }
  1511. return buffer.join("");
  1512. }
  1513. /***/ }),
  1514. /* 3 */
  1515. /***/ ((__unused_webpack_module, __unused_webpack_exports, __w_pdfjs_require__) => {
  1516. var _is_node = __w_pdfjs_require__(4);
  1517. ;
  1518. /***/ }),
  1519. /* 4 */
  1520. /***/ ((__unused_webpack_module, exports) => {
  1521. Object.defineProperty(exports, "__esModule", ({
  1522. value: true
  1523. }));
  1524. exports.isNodeJS = void 0;
  1525. const isNodeJS = typeof process === "object" && process + "" === "[object process]" && !process.versions.nw && !(process.versions.electron && process.type && process.type !== "browser");
  1526. exports.isNodeJS = isNodeJS;
  1527. /***/ }),
  1528. /* 5 */
  1529. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  1530. Object.defineProperty(exports, "__esModule", ({
  1531. value: true
  1532. }));
  1533. exports.getDocument = getDocument;
  1534. exports.setPDFNetworkStreamFactory = setPDFNetworkStreamFactory;
  1535. exports.version = exports.PDFWorker = exports.PDFPageProxy = exports.PDFDocumentProxy = exports.PDFDataRangeTransport = exports.LoopbackPort = exports.DefaultCMapReaderFactory = exports.DefaultCanvasFactory = exports.build = void 0;
  1536. var _util = __w_pdfjs_require__(2);
  1537. var _display_utils = __w_pdfjs_require__(1);
  1538. var _font_loader = __w_pdfjs_require__(6);
  1539. var _node_utils = __w_pdfjs_require__(7);
  1540. var _annotation_storage = __w_pdfjs_require__(8);
  1541. var _api_compatibility = __w_pdfjs_require__(9);
  1542. var _canvas = __w_pdfjs_require__(10);
  1543. var _worker_options = __w_pdfjs_require__(12);
  1544. var _is_node = __w_pdfjs_require__(4);
  1545. var _message_handler = __w_pdfjs_require__(13);
  1546. var _metadata = __w_pdfjs_require__(14);
  1547. var _optional_content_config = __w_pdfjs_require__(16);
  1548. var _transport_stream = __w_pdfjs_require__(17);
  1549. var _webgl = __w_pdfjs_require__(18);
  1550. const DEFAULT_RANGE_CHUNK_SIZE = 65536;
  1551. const RENDERING_CANCELLED_TIMEOUT = 100;
  1552. const DefaultCanvasFactory = _is_node.isNodeJS ? _node_utils.NodeCanvasFactory : _display_utils.DOMCanvasFactory;
  1553. exports.DefaultCanvasFactory = DefaultCanvasFactory;
  1554. const DefaultCMapReaderFactory = _is_node.isNodeJS ? _node_utils.NodeCMapReaderFactory : _display_utils.DOMCMapReaderFactory;
  1555. exports.DefaultCMapReaderFactory = DefaultCMapReaderFactory;
  1556. let createPDFNetworkStream;
  1557. function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) {
  1558. createPDFNetworkStream = pdfNetworkStreamFactory;
  1559. }
  1560. function getDocument(src) {
  1561. const task = new PDFDocumentLoadingTask();
  1562. let source;
  1563. if (typeof src === "string") {
  1564. source = {
  1565. url: src
  1566. };
  1567. } else if ((0, _util.isArrayBuffer)(src)) {
  1568. source = {
  1569. data: src
  1570. };
  1571. } else if (src instanceof PDFDataRangeTransport) {
  1572. source = {
  1573. range: src
  1574. };
  1575. } else {
  1576. if (typeof src !== "object") {
  1577. throw new Error("Invalid parameter in getDocument, " + "need either Uint8Array, string or a parameter object");
  1578. }
  1579. if (!src.url && !src.data && !src.range) {
  1580. throw new Error("Invalid parameter object: need either .data, .range or .url");
  1581. }
  1582. source = src;
  1583. }
  1584. const params = Object.create(null);
  1585. let rangeTransport = null,
  1586. worker = null;
  1587. for (const key in source) {
  1588. if (key === "url" && typeof window !== "undefined") {
  1589. params[key] = new URL(source[key], window.location).href;
  1590. continue;
  1591. } else if (key === "range") {
  1592. rangeTransport = source[key];
  1593. continue;
  1594. } else if (key === "worker") {
  1595. worker = source[key];
  1596. continue;
  1597. } else if (key === "data" && !(source[key] instanceof Uint8Array)) {
  1598. const pdfBytes = source[key];
  1599. if (typeof pdfBytes === "string") {
  1600. params[key] = (0, _util.stringToBytes)(pdfBytes);
  1601. } else if (typeof pdfBytes === "object" && pdfBytes !== null && !isNaN(pdfBytes.length)) {
  1602. params[key] = new Uint8Array(pdfBytes);
  1603. } else if ((0, _util.isArrayBuffer)(pdfBytes)) {
  1604. params[key] = new Uint8Array(pdfBytes);
  1605. } else {
  1606. throw new Error("Invalid PDF binary data: either typed array, " + "string or array-like object is expected in the " + "data property.");
  1607. }
  1608. continue;
  1609. }
  1610. params[key] = source[key];
  1611. }
  1612. params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
  1613. params.CMapReaderFactory = params.CMapReaderFactory || DefaultCMapReaderFactory;
  1614. params.ignoreErrors = params.stopAtErrors !== true;
  1615. params.fontExtraProperties = params.fontExtraProperties === true;
  1616. params.pdfBug = params.pdfBug === true;
  1617. if (!Number.isInteger(params.maxImageSize)) {
  1618. params.maxImageSize = -1;
  1619. }
  1620. if (typeof params.isEvalSupported !== "boolean") {
  1621. params.isEvalSupported = true;
  1622. }
  1623. if (typeof params.disableFontFace !== "boolean") {
  1624. params.disableFontFace = _api_compatibility.apiCompatibilityParams.disableFontFace || false;
  1625. }
  1626. if (typeof params.ownerDocument === "undefined") {
  1627. params.ownerDocument = globalThis.document;
  1628. }
  1629. if (typeof params.disableRange !== "boolean") {
  1630. params.disableRange = false;
  1631. }
  1632. if (typeof params.disableStream !== "boolean") {
  1633. params.disableStream = false;
  1634. }
  1635. if (typeof params.disableAutoFetch !== "boolean") {
  1636. params.disableAutoFetch = false;
  1637. }
  1638. (0, _util.setVerbosityLevel)(params.verbosity);
  1639. if (!worker) {
  1640. const workerParams = {
  1641. verbosity: params.verbosity,
  1642. port: _worker_options.GlobalWorkerOptions.workerPort
  1643. };
  1644. worker = workerParams.port ? PDFWorker.fromPort(workerParams) : new PDFWorker(workerParams);
  1645. task._worker = worker;
  1646. }
  1647. const docId = task.docId;
  1648. worker.promise.then(function () {
  1649. if (task.destroyed) {
  1650. throw new Error("Loading aborted");
  1651. }
  1652. const workerIdPromise = _fetchDocument(worker, params, rangeTransport, docId);
  1653. const networkStreamPromise = new Promise(function (resolve) {
  1654. let networkStream;
  1655. if (rangeTransport) {
  1656. networkStream = new _transport_stream.PDFDataTransportStream({
  1657. length: params.length,
  1658. initialData: params.initialData,
  1659. progressiveDone: params.progressiveDone,
  1660. disableRange: params.disableRange,
  1661. disableStream: params.disableStream
  1662. }, rangeTransport);
  1663. } else if (!params.data) {
  1664. networkStream = createPDFNetworkStream({
  1665. url: params.url,
  1666. length: params.length,
  1667. httpHeaders: params.httpHeaders,
  1668. withCredentials: params.withCredentials,
  1669. rangeChunkSize: params.rangeChunkSize,
  1670. disableRange: params.disableRange,
  1671. disableStream: params.disableStream
  1672. });
  1673. }
  1674. resolve(networkStream);
  1675. });
  1676. return Promise.all([workerIdPromise, networkStreamPromise]).then(function ([workerId, networkStream]) {
  1677. if (task.destroyed) {
  1678. throw new Error("Loading aborted");
  1679. }
  1680. const messageHandler = new _message_handler.MessageHandler(docId, workerId, worker.port);
  1681. messageHandler.postMessageTransfers = worker.postMessageTransfers;
  1682. const transport = new WorkerTransport(messageHandler, task, networkStream, params);
  1683. task._transport = transport;
  1684. messageHandler.send("Ready", null);
  1685. });
  1686. }).catch(task._capability.reject);
  1687. return task;
  1688. }
  1689. function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
  1690. if (worker.destroyed) {
  1691. return Promise.reject(new Error("Worker was destroyed"));
  1692. }
  1693. if (pdfDataRangeTransport) {
  1694. source.length = pdfDataRangeTransport.length;
  1695. source.initialData = pdfDataRangeTransport.initialData;
  1696. source.progressiveDone = pdfDataRangeTransport.progressiveDone;
  1697. }
  1698. return worker.messageHandler.sendWithPromise("GetDocRequest", {
  1699. docId,
  1700. apiVersion: '2.7.570',
  1701. source: {
  1702. data: source.data,
  1703. url: source.url,
  1704. password: source.password,
  1705. disableAutoFetch: source.disableAutoFetch,
  1706. rangeChunkSize: source.rangeChunkSize,
  1707. length: source.length
  1708. },
  1709. maxImageSize: source.maxImageSize,
  1710. disableFontFace: source.disableFontFace,
  1711. postMessageTransfers: worker.postMessageTransfers,
  1712. docBaseUrl: source.docBaseUrl,
  1713. ignoreErrors: source.ignoreErrors,
  1714. isEvalSupported: source.isEvalSupported,
  1715. fontExtraProperties: source.fontExtraProperties
  1716. }).then(function (workerId) {
  1717. if (worker.destroyed) {
  1718. throw new Error("Worker was destroyed");
  1719. }
  1720. return workerId;
  1721. });
  1722. }
  1723. const PDFDocumentLoadingTask = function PDFDocumentLoadingTaskClosure() {
  1724. let nextDocumentId = 0;
  1725. class PDFDocumentLoadingTask {
  1726. constructor() {
  1727. this._capability = (0, _util.createPromiseCapability)();
  1728. this._transport = null;
  1729. this._worker = null;
  1730. this.docId = "d" + nextDocumentId++;
  1731. this.destroyed = false;
  1732. this.onPassword = null;
  1733. this.onProgress = null;
  1734. this.onUnsupportedFeature = null;
  1735. }
  1736. get promise() {
  1737. return this._capability.promise;
  1738. }
  1739. destroy() {
  1740. this.destroyed = true;
  1741. const transportDestroyed = !this._transport ? Promise.resolve() : this._transport.destroy();
  1742. return transportDestroyed.then(() => {
  1743. this._transport = null;
  1744. if (this._worker) {
  1745. this._worker.destroy();
  1746. this._worker = null;
  1747. }
  1748. });
  1749. }
  1750. }
  1751. return PDFDocumentLoadingTask;
  1752. }();
  1753. class PDFDataRangeTransport {
  1754. constructor(length, initialData, progressiveDone = false) {
  1755. this.length = length;
  1756. this.initialData = initialData;
  1757. this.progressiveDone = progressiveDone;
  1758. this._rangeListeners = [];
  1759. this._progressListeners = [];
  1760. this._progressiveReadListeners = [];
  1761. this._progressiveDoneListeners = [];
  1762. this._readyCapability = (0, _util.createPromiseCapability)();
  1763. }
  1764. addRangeListener(listener) {
  1765. this._rangeListeners.push(listener);
  1766. }
  1767. addProgressListener(listener) {
  1768. this._progressListeners.push(listener);
  1769. }
  1770. addProgressiveReadListener(listener) {
  1771. this._progressiveReadListeners.push(listener);
  1772. }
  1773. addProgressiveDoneListener(listener) {
  1774. this._progressiveDoneListeners.push(listener);
  1775. }
  1776. onDataRange(begin, chunk) {
  1777. for (const listener of this._rangeListeners) {
  1778. listener(begin, chunk);
  1779. }
  1780. }
  1781. onDataProgress(loaded, total) {
  1782. this._readyCapability.promise.then(() => {
  1783. for (const listener of this._progressListeners) {
  1784. listener(loaded, total);
  1785. }
  1786. });
  1787. }
  1788. onDataProgressiveRead(chunk) {
  1789. this._readyCapability.promise.then(() => {
  1790. for (const listener of this._progressiveReadListeners) {
  1791. listener(chunk);
  1792. }
  1793. });
  1794. }
  1795. onDataProgressiveDone() {
  1796. this._readyCapability.promise.then(() => {
  1797. for (const listener of this._progressiveDoneListeners) {
  1798. listener();
  1799. }
  1800. });
  1801. }
  1802. transportReady() {
  1803. this._readyCapability.resolve();
  1804. }
  1805. requestDataRange(begin, end) {
  1806. (0, _util.unreachable)("Abstract method PDFDataRangeTransport.requestDataRange");
  1807. }
  1808. abort() {}
  1809. }
  1810. exports.PDFDataRangeTransport = PDFDataRangeTransport;
  1811. class PDFDocumentProxy {
  1812. constructor(pdfInfo, transport) {
  1813. this._pdfInfo = pdfInfo;
  1814. this._transport = transport;
  1815. }
  1816. get annotationStorage() {
  1817. return (0, _util.shadow)(this, "annotationStorage", new _annotation_storage.AnnotationStorage());
  1818. }
  1819. get numPages() {
  1820. return this._pdfInfo.numPages;
  1821. }
  1822. get fingerprint() {
  1823. return this._pdfInfo.fingerprint;
  1824. }
  1825. getPage(pageNumber) {
  1826. return this._transport.getPage(pageNumber);
  1827. }
  1828. getPageIndex(ref) {
  1829. return this._transport.getPageIndex(ref);
  1830. }
  1831. getDestinations() {
  1832. return this._transport.getDestinations();
  1833. }
  1834. getDestination(id) {
  1835. return this._transport.getDestination(id);
  1836. }
  1837. getPageLabels() {
  1838. return this._transport.getPageLabels();
  1839. }
  1840. getPageLayout() {
  1841. return this._transport.getPageLayout();
  1842. }
  1843. getPageMode() {
  1844. return this._transport.getPageMode();
  1845. }
  1846. getViewerPreferences() {
  1847. return this._transport.getViewerPreferences();
  1848. }
  1849. getOpenAction() {
  1850. return this._transport.getOpenAction();
  1851. }
  1852. getAttachments() {
  1853. return this._transport.getAttachments();
  1854. }
  1855. getJavaScript() {
  1856. return this._transport.getJavaScript();
  1857. }
  1858. getJSActions() {
  1859. return this._transport.getDocJSActions();
  1860. }
  1861. getOutline() {
  1862. return this._transport.getOutline();
  1863. }
  1864. getOptionalContentConfig() {
  1865. return this._transport.getOptionalContentConfig();
  1866. }
  1867. getPermissions() {
  1868. return this._transport.getPermissions();
  1869. }
  1870. getMetadata() {
  1871. return this._transport.getMetadata();
  1872. }
  1873. getMarkInfo() {
  1874. return this._transport.getMarkInfo();
  1875. }
  1876. getData() {
  1877. return this._transport.getData();
  1878. }
  1879. getDownloadInfo() {
  1880. return this._transport.downloadInfoCapability.promise;
  1881. }
  1882. getStats() {
  1883. return this._transport.getStats();
  1884. }
  1885. cleanup() {
  1886. return this._transport.startCleanup();
  1887. }
  1888. destroy() {
  1889. return this.loadingTask.destroy();
  1890. }
  1891. get loadingParams() {
  1892. return this._transport.loadingParams;
  1893. }
  1894. get loadingTask() {
  1895. return this._transport.loadingTask;
  1896. }
  1897. saveDocument(annotationStorage) {
  1898. return this._transport.saveDocument(annotationStorage);
  1899. }
  1900. getFieldObjects() {
  1901. return this._transport.getFieldObjects();
  1902. }
  1903. hasJSActions() {
  1904. return this._transport.hasJSActions();
  1905. }
  1906. getCalculationOrderIds() {
  1907. return this._transport.getCalculationOrderIds();
  1908. }
  1909. }
  1910. exports.PDFDocumentProxy = PDFDocumentProxy;
  1911. class PDFPageProxy {
  1912. constructor(pageIndex, pageInfo, transport, ownerDocument, pdfBug = false) {
  1913. this._pageIndex = pageIndex;
  1914. this._pageInfo = pageInfo;
  1915. this._ownerDocument = ownerDocument;
  1916. this._transport = transport;
  1917. this._stats = pdfBug ? new _display_utils.StatTimer() : null;
  1918. this._pdfBug = pdfBug;
  1919. this.commonObjs = transport.commonObjs;
  1920. this.objs = new PDFObjects();
  1921. this.cleanupAfterRender = false;
  1922. this.pendingCleanup = false;
  1923. this._intentStates = new Map();
  1924. this.destroyed = false;
  1925. }
  1926. get pageNumber() {
  1927. return this._pageIndex + 1;
  1928. }
  1929. get rotate() {
  1930. return this._pageInfo.rotate;
  1931. }
  1932. get ref() {
  1933. return this._pageInfo.ref;
  1934. }
  1935. get userUnit() {
  1936. return this._pageInfo.userUnit;
  1937. }
  1938. get view() {
  1939. return this._pageInfo.view;
  1940. }
  1941. getViewport({
  1942. scale,
  1943. rotation = this.rotate,
  1944. offsetX = 0,
  1945. offsetY = 0,
  1946. dontFlip = false
  1947. } = {}) {
  1948. return new _display_utils.PageViewport({
  1949. viewBox: this.view,
  1950. scale,
  1951. rotation,
  1952. offsetX,
  1953. offsetY,
  1954. dontFlip
  1955. });
  1956. }
  1957. getAnnotations({
  1958. intent = null
  1959. } = {}) {
  1960. if (!this.annotationsPromise || this.annotationsIntent !== intent) {
  1961. this.annotationsPromise = this._transport.getAnnotations(this._pageIndex, intent);
  1962. this.annotationsIntent = intent;
  1963. }
  1964. return this.annotationsPromise;
  1965. }
  1966. getJSActions() {
  1967. return this._jsActionsPromise || (this._jsActionsPromise = this._transport.getPageJSActions(this._pageIndex));
  1968. }
  1969. render({
  1970. canvasContext,
  1971. viewport,
  1972. intent = "display",
  1973. enableWebGL = false,
  1974. renderInteractiveForms = false,
  1975. transform = null,
  1976. imageLayer = null,
  1977. canvasFactory = null,
  1978. background = null,
  1979. annotationStorage = null,
  1980. optionalContentConfigPromise = null
  1981. }) {
  1982. if (this._stats) {
  1983. this._stats.time("Overall");
  1984. }
  1985. const renderingIntent = intent === "print" ? "print" : "display";
  1986. this.pendingCleanup = false;
  1987. if (!optionalContentConfigPromise) {
  1988. optionalContentConfigPromise = this._transport.getOptionalContentConfig();
  1989. }
  1990. let intentState = this._intentStates.get(renderingIntent);
  1991. if (!intentState) {
  1992. intentState = Object.create(null);
  1993. this._intentStates.set(renderingIntent, intentState);
  1994. }
  1995. if (intentState.streamReaderCancelTimeout) {
  1996. clearTimeout(intentState.streamReaderCancelTimeout);
  1997. intentState.streamReaderCancelTimeout = null;
  1998. }
  1999. const canvasFactoryInstance = canvasFactory || new DefaultCanvasFactory({
  2000. ownerDocument: this._ownerDocument
  2001. });
  2002. const webGLContext = new _webgl.WebGLContext({
  2003. enable: enableWebGL
  2004. });
  2005. if (!intentState.displayReadyCapability) {
  2006. intentState.displayReadyCapability = (0, _util.createPromiseCapability)();
  2007. intentState.operatorList = {
  2008. fnArray: [],
  2009. argsArray: [],
  2010. lastChunk: false
  2011. };
  2012. if (this._stats) {
  2013. this._stats.time("Page Request");
  2014. }
  2015. this._pumpOperatorList({
  2016. pageIndex: this._pageIndex,
  2017. intent: renderingIntent,
  2018. renderInteractiveForms: renderInteractiveForms === true,
  2019. annotationStorage: annotationStorage?.getAll() || null
  2020. });
  2021. }
  2022. const complete = error => {
  2023. const i = intentState.renderTasks.indexOf(internalRenderTask);
  2024. if (i >= 0) {
  2025. intentState.renderTasks.splice(i, 1);
  2026. }
  2027. if (this.cleanupAfterRender || renderingIntent === "print") {
  2028. this.pendingCleanup = true;
  2029. }
  2030. this._tryCleanup();
  2031. if (error) {
  2032. internalRenderTask.capability.reject(error);
  2033. this._abortOperatorList({
  2034. intentState,
  2035. reason: error
  2036. });
  2037. } else {
  2038. internalRenderTask.capability.resolve();
  2039. }
  2040. if (this._stats) {
  2041. this._stats.timeEnd("Rendering");
  2042. this._stats.timeEnd("Overall");
  2043. }
  2044. };
  2045. const internalRenderTask = new InternalRenderTask({
  2046. callback: complete,
  2047. params: {
  2048. canvasContext,
  2049. viewport,
  2050. transform,
  2051. imageLayer,
  2052. background
  2053. },
  2054. objs: this.objs,
  2055. commonObjs: this.commonObjs,
  2056. operatorList: intentState.operatorList,
  2057. pageIndex: this._pageIndex,
  2058. canvasFactory: canvasFactoryInstance,
  2059. webGLContext,
  2060. useRequestAnimationFrame: renderingIntent !== "print",
  2061. pdfBug: this._pdfBug
  2062. });
  2063. if (!intentState.renderTasks) {
  2064. intentState.renderTasks = [];
  2065. }
  2066. intentState.renderTasks.push(internalRenderTask);
  2067. const renderTask = internalRenderTask.task;
  2068. Promise.all([intentState.displayReadyCapability.promise, optionalContentConfigPromise]).then(([transparency, optionalContentConfig]) => {
  2069. if (this.pendingCleanup) {
  2070. complete();
  2071. return;
  2072. }
  2073. if (this._stats) {
  2074. this._stats.time("Rendering");
  2075. }
  2076. internalRenderTask.initializeGraphics({
  2077. transparency,
  2078. optionalContentConfig
  2079. });
  2080. internalRenderTask.operatorListChanged();
  2081. }).catch(complete);
  2082. return renderTask;
  2083. }
  2084. getOperatorList() {
  2085. function operatorListChanged() {
  2086. if (intentState.operatorList.lastChunk) {
  2087. intentState.opListReadCapability.resolve(intentState.operatorList);
  2088. const i = intentState.renderTasks.indexOf(opListTask);
  2089. if (i >= 0) {
  2090. intentState.renderTasks.splice(i, 1);
  2091. }
  2092. }
  2093. }
  2094. const renderingIntent = "oplist";
  2095. let intentState = this._intentStates.get(renderingIntent);
  2096. if (!intentState) {
  2097. intentState = Object.create(null);
  2098. this._intentStates.set(renderingIntent, intentState);
  2099. }
  2100. let opListTask;
  2101. if (!intentState.opListReadCapability) {
  2102. opListTask = Object.create(null);
  2103. opListTask.operatorListChanged = operatorListChanged;
  2104. intentState.opListReadCapability = (0, _util.createPromiseCapability)();
  2105. intentState.renderTasks = [];
  2106. intentState.renderTasks.push(opListTask);
  2107. intentState.operatorList = {
  2108. fnArray: [],
  2109. argsArray: [],
  2110. lastChunk: false
  2111. };
  2112. if (this._stats) {
  2113. this._stats.time("Page Request");
  2114. }
  2115. this._pumpOperatorList({
  2116. pageIndex: this._pageIndex,
  2117. intent: renderingIntent
  2118. });
  2119. }
  2120. return intentState.opListReadCapability.promise;
  2121. }
  2122. streamTextContent({
  2123. normalizeWhitespace = false,
  2124. disableCombineTextItems = false
  2125. } = {}) {
  2126. const TEXT_CONTENT_CHUNK_SIZE = 100;
  2127. return this._transport.messageHandler.sendWithStream("GetTextContent", {
  2128. pageIndex: this._pageIndex,
  2129. normalizeWhitespace: normalizeWhitespace === true,
  2130. combineTextItems: disableCombineTextItems !== true
  2131. }, {
  2132. highWaterMark: TEXT_CONTENT_CHUNK_SIZE,
  2133. size(textContent) {
  2134. return textContent.items.length;
  2135. }
  2136. });
  2137. }
  2138. getTextContent(params = {}) {
  2139. const readableStream = this.streamTextContent(params);
  2140. return new Promise(function (resolve, reject) {
  2141. function pump() {
  2142. reader.read().then(function ({
  2143. value,
  2144. done
  2145. }) {
  2146. if (done) {
  2147. resolve(textContent);
  2148. return;
  2149. }
  2150. Object.assign(textContent.styles, value.styles);
  2151. textContent.items.push(...value.items);
  2152. pump();
  2153. }, reject);
  2154. }
  2155. const reader = readableStream.getReader();
  2156. const textContent = {
  2157. items: [],
  2158. styles: Object.create(null)
  2159. };
  2160. pump();
  2161. });
  2162. }
  2163. _destroy() {
  2164. this.destroyed = true;
  2165. this._transport.pageCache[this._pageIndex] = null;
  2166. const waitOn = [];
  2167. for (const [intent, intentState] of this._intentStates) {
  2168. this._abortOperatorList({
  2169. intentState,
  2170. reason: new Error("Page was destroyed."),
  2171. force: true
  2172. });
  2173. if (intent === "oplist") {
  2174. continue;
  2175. }
  2176. for (const internalRenderTask of intentState.renderTasks) {
  2177. waitOn.push(internalRenderTask.completed);
  2178. internalRenderTask.cancel();
  2179. }
  2180. }
  2181. this.objs.clear();
  2182. this.annotationsPromise = null;
  2183. this._jsActionsPromise = null;
  2184. this.pendingCleanup = false;
  2185. return Promise.all(waitOn);
  2186. }
  2187. cleanup(resetStats = false) {
  2188. this.pendingCleanup = true;
  2189. return this._tryCleanup(resetStats);
  2190. }
  2191. _tryCleanup(resetStats = false) {
  2192. if (!this.pendingCleanup) {
  2193. return false;
  2194. }
  2195. for (const {
  2196. renderTasks,
  2197. operatorList
  2198. } of this._intentStates.values()) {
  2199. if (renderTasks.length !== 0 || !operatorList.lastChunk) {
  2200. return false;
  2201. }
  2202. }
  2203. this._intentStates.clear();
  2204. this.objs.clear();
  2205. this.annotationsPromise = null;
  2206. this._jsActionsPromise = null;
  2207. if (resetStats && this._stats) {
  2208. this._stats = new _display_utils.StatTimer();
  2209. }
  2210. this.pendingCleanup = false;
  2211. return true;
  2212. }
  2213. _startRenderPage(transparency, intent) {
  2214. const intentState = this._intentStates.get(intent);
  2215. if (!intentState) {
  2216. return;
  2217. }
  2218. if (this._stats) {
  2219. this._stats.timeEnd("Page Request");
  2220. }
  2221. if (intentState.displayReadyCapability) {
  2222. intentState.displayReadyCapability.resolve(transparency);
  2223. }
  2224. }
  2225. _renderPageChunk(operatorListChunk, intentState) {
  2226. for (let i = 0, ii = operatorListChunk.length; i < ii; i++) {
  2227. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  2228. intentState.operatorList.argsArray.push(operatorListChunk.argsArray[i]);
  2229. }
  2230. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  2231. for (let i = 0; i < intentState.renderTasks.length; i++) {
  2232. intentState.renderTasks[i].operatorListChanged();
  2233. }
  2234. if (operatorListChunk.lastChunk) {
  2235. this._tryCleanup();
  2236. }
  2237. }
  2238. _pumpOperatorList(args) {
  2239. (0, _util.assert)(args.intent, 'PDFPageProxy._pumpOperatorList: Expected "intent" argument.');
  2240. const readableStream = this._transport.messageHandler.sendWithStream("GetOperatorList", args);
  2241. const reader = readableStream.getReader();
  2242. const intentState = this._intentStates.get(args.intent);
  2243. intentState.streamReader = reader;
  2244. const pump = () => {
  2245. reader.read().then(({
  2246. value,
  2247. done
  2248. }) => {
  2249. if (done) {
  2250. intentState.streamReader = null;
  2251. return;
  2252. }
  2253. if (this._transport.destroyed) {
  2254. return;
  2255. }
  2256. this._renderPageChunk(value, intentState);
  2257. pump();
  2258. }, reason => {
  2259. intentState.streamReader = null;
  2260. if (this._transport.destroyed) {
  2261. return;
  2262. }
  2263. if (intentState.operatorList) {
  2264. intentState.operatorList.lastChunk = true;
  2265. for (let i = 0; i < intentState.renderTasks.length; i++) {
  2266. intentState.renderTasks[i].operatorListChanged();
  2267. }
  2268. this._tryCleanup();
  2269. }
  2270. if (intentState.displayReadyCapability) {
  2271. intentState.displayReadyCapability.reject(reason);
  2272. } else if (intentState.opListReadCapability) {
  2273. intentState.opListReadCapability.reject(reason);
  2274. } else {
  2275. throw reason;
  2276. }
  2277. });
  2278. };
  2279. pump();
  2280. }
  2281. _abortOperatorList({
  2282. intentState,
  2283. reason,
  2284. force = false
  2285. }) {
  2286. (0, _util.assert)(reason instanceof Error || typeof reason === "object" && reason !== null, 'PDFPageProxy._abortOperatorList: Expected "reason" argument.');
  2287. if (!intentState.streamReader) {
  2288. return;
  2289. }
  2290. if (!force) {
  2291. if (intentState.renderTasks.length !== 0) {
  2292. return;
  2293. }
  2294. if (reason instanceof _display_utils.RenderingCancelledException) {
  2295. intentState.streamReaderCancelTimeout = setTimeout(() => {
  2296. this._abortOperatorList({
  2297. intentState,
  2298. reason,
  2299. force: true
  2300. });
  2301. intentState.streamReaderCancelTimeout = null;
  2302. }, RENDERING_CANCELLED_TIMEOUT);
  2303. return;
  2304. }
  2305. }
  2306. intentState.streamReader.cancel(new _util.AbortException(reason?.message));
  2307. intentState.streamReader = null;
  2308. if (this._transport.destroyed) {
  2309. return;
  2310. }
  2311. for (const [intent, curIntentState] of this._intentStates) {
  2312. if (curIntentState === intentState) {
  2313. this._intentStates.delete(intent);
  2314. break;
  2315. }
  2316. }
  2317. this.cleanup();
  2318. }
  2319. get stats() {
  2320. return this._stats;
  2321. }
  2322. }
  2323. exports.PDFPageProxy = PDFPageProxy;
  2324. class LoopbackPort {
  2325. constructor(defer = true) {
  2326. this._listeners = [];
  2327. this._defer = defer;
  2328. this._deferred = Promise.resolve(undefined);
  2329. }
  2330. postMessage(obj, transfers) {
  2331. function cloneValue(value) {
  2332. if (typeof value !== "object" || value === null) {
  2333. return value;
  2334. }
  2335. if (cloned.has(value)) {
  2336. return cloned.get(value);
  2337. }
  2338. let buffer, result;
  2339. if ((buffer = value.buffer) && (0, _util.isArrayBuffer)(buffer)) {
  2340. if (transfers?.includes(buffer)) {
  2341. result = new value.constructor(buffer, value.byteOffset, value.byteLength);
  2342. } else {
  2343. result = new value.constructor(value);
  2344. }
  2345. cloned.set(value, result);
  2346. return result;
  2347. }
  2348. result = Array.isArray(value) ? [] : {};
  2349. cloned.set(value, result);
  2350. for (const i in value) {
  2351. let desc,
  2352. p = value;
  2353. while (!(desc = Object.getOwnPropertyDescriptor(p, i))) {
  2354. p = Object.getPrototypeOf(p);
  2355. }
  2356. if (typeof desc.value === "undefined") {
  2357. continue;
  2358. }
  2359. if (typeof desc.value === "function") {
  2360. if (value.hasOwnProperty && value.hasOwnProperty(i)) {
  2361. throw new Error(`LoopbackPort.postMessage - cannot clone: ${value[i]}`);
  2362. }
  2363. continue;
  2364. }
  2365. result[i] = cloneValue(desc.value);
  2366. }
  2367. return result;
  2368. }
  2369. if (!this._defer) {
  2370. this._listeners.forEach(listener => {
  2371. listener.call(this, {
  2372. data: obj
  2373. });
  2374. });
  2375. return;
  2376. }
  2377. const cloned = new WeakMap();
  2378. const e = {
  2379. data: cloneValue(obj)
  2380. };
  2381. this._deferred.then(() => {
  2382. this._listeners.forEach(listener => {
  2383. listener.call(this, e);
  2384. });
  2385. });
  2386. }
  2387. addEventListener(name, listener) {
  2388. this._listeners.push(listener);
  2389. }
  2390. removeEventListener(name, listener) {
  2391. const i = this._listeners.indexOf(listener);
  2392. this._listeners.splice(i, 1);
  2393. }
  2394. terminate() {
  2395. this._listeners.length = 0;
  2396. }
  2397. }
  2398. exports.LoopbackPort = LoopbackPort;
  2399. const PDFWorker = function PDFWorkerClosure() {
  2400. const pdfWorkerPorts = new WeakMap();
  2401. let isWorkerDisabled = false;
  2402. let fallbackWorkerSrc;
  2403. let nextFakeWorkerId = 0;
  2404. let fakeWorkerCapability;
  2405. if (_is_node.isNodeJS && typeof require === "function") {
  2406. isWorkerDisabled = true;
  2407. fallbackWorkerSrc = "./pdf.worker.js";
  2408. } else if (typeof document === "object" && "currentScript" in document) {
  2409. const pdfjsFilePath = document.currentScript?.src;
  2410. if (pdfjsFilePath) {
  2411. fallbackWorkerSrc = pdfjsFilePath.replace(/(\.(?:min\.)?js)(\?.*)?$/i, ".worker$1$2");
  2412. }
  2413. }
  2414. function getWorkerSrc() {
  2415. if (_worker_options.GlobalWorkerOptions.workerSrc) {
  2416. return _worker_options.GlobalWorkerOptions.workerSrc;
  2417. }
  2418. if (typeof fallbackWorkerSrc !== "undefined") {
  2419. if (!_is_node.isNodeJS) {
  2420. (0, _display_utils.deprecated)('No "GlobalWorkerOptions.workerSrc" specified.');
  2421. }
  2422. return fallbackWorkerSrc;
  2423. }
  2424. throw new Error('No "GlobalWorkerOptions.workerSrc" specified.');
  2425. }
  2426. function getMainThreadWorkerMessageHandler() {
  2427. let mainWorkerMessageHandler;
  2428. try {
  2429. mainWorkerMessageHandler = globalThis.pdfjsWorker?.WorkerMessageHandler;
  2430. } catch (ex) {}
  2431. return mainWorkerMessageHandler || null;
  2432. }
  2433. function setupFakeWorkerGlobal() {
  2434. if (fakeWorkerCapability) {
  2435. return fakeWorkerCapability.promise;
  2436. }
  2437. fakeWorkerCapability = (0, _util.createPromiseCapability)();
  2438. const loader = async function () {
  2439. const mainWorkerMessageHandler = getMainThreadWorkerMessageHandler();
  2440. if (mainWorkerMessageHandler) {
  2441. return mainWorkerMessageHandler;
  2442. }
  2443. if (_is_node.isNodeJS && typeof require === "function") {
  2444. const worker = eval("require")(getWorkerSrc());
  2445. return worker.WorkerMessageHandler;
  2446. }
  2447. await (0, _display_utils.loadScript)(getWorkerSrc());
  2448. return window.pdfjsWorker.WorkerMessageHandler;
  2449. };
  2450. loader().then(fakeWorkerCapability.resolve, fakeWorkerCapability.reject);
  2451. return fakeWorkerCapability.promise;
  2452. }
  2453. function createCDNWrapper(url) {
  2454. const wrapper = "importScripts('" + url + "');";
  2455. return URL.createObjectURL(new Blob([wrapper]));
  2456. }
  2457. class PDFWorker {
  2458. constructor({
  2459. name = null,
  2460. port = null,
  2461. verbosity = (0, _util.getVerbosityLevel)()
  2462. } = {}) {
  2463. if (port && pdfWorkerPorts.has(port)) {
  2464. throw new Error("Cannot use more than one PDFWorker per port");
  2465. }
  2466. this.name = name;
  2467. this.destroyed = false;
  2468. this.postMessageTransfers = true;
  2469. this.verbosity = verbosity;
  2470. this._readyCapability = (0, _util.createPromiseCapability)();
  2471. this._port = null;
  2472. this._webWorker = null;
  2473. this._messageHandler = null;
  2474. if (port) {
  2475. pdfWorkerPorts.set(port, this);
  2476. this._initializeFromPort(port);
  2477. return;
  2478. }
  2479. this._initialize();
  2480. }
  2481. get promise() {
  2482. return this._readyCapability.promise;
  2483. }
  2484. get port() {
  2485. return this._port;
  2486. }
  2487. get messageHandler() {
  2488. return this._messageHandler;
  2489. }
  2490. _initializeFromPort(port) {
  2491. this._port = port;
  2492. this._messageHandler = new _message_handler.MessageHandler("main", "worker", port);
  2493. this._messageHandler.on("ready", function () {});
  2494. this._readyCapability.resolve();
  2495. }
  2496. _initialize() {
  2497. if (typeof Worker !== "undefined" && !isWorkerDisabled && !getMainThreadWorkerMessageHandler()) {
  2498. let workerSrc = getWorkerSrc();
  2499. try {
  2500. if (!(0, _util.isSameOrigin)(window.location.href, workerSrc)) {
  2501. workerSrc = createCDNWrapper(new URL(workerSrc, window.location).href);
  2502. }
  2503. const worker = new Worker(workerSrc);
  2504. const messageHandler = new _message_handler.MessageHandler("main", "worker", worker);
  2505. const terminateEarly = () => {
  2506. worker.removeEventListener("error", onWorkerError);
  2507. messageHandler.destroy();
  2508. worker.terminate();
  2509. if (this.destroyed) {
  2510. this._readyCapability.reject(new Error("Worker was destroyed"));
  2511. } else {
  2512. this._setupFakeWorker();
  2513. }
  2514. };
  2515. const onWorkerError = () => {
  2516. if (!this._webWorker) {
  2517. terminateEarly();
  2518. }
  2519. };
  2520. worker.addEventListener("error", onWorkerError);
  2521. messageHandler.on("test", data => {
  2522. worker.removeEventListener("error", onWorkerError);
  2523. if (this.destroyed) {
  2524. terminateEarly();
  2525. return;
  2526. }
  2527. if (data) {
  2528. this._messageHandler = messageHandler;
  2529. this._port = worker;
  2530. this._webWorker = worker;
  2531. if (!data.supportTransfers) {
  2532. this.postMessageTransfers = false;
  2533. }
  2534. this._readyCapability.resolve();
  2535. messageHandler.send("configure", {
  2536. verbosity: this.verbosity
  2537. });
  2538. } else {
  2539. this._setupFakeWorker();
  2540. messageHandler.destroy();
  2541. worker.terminate();
  2542. }
  2543. });
  2544. messageHandler.on("ready", data => {
  2545. worker.removeEventListener("error", onWorkerError);
  2546. if (this.destroyed) {
  2547. terminateEarly();
  2548. return;
  2549. }
  2550. try {
  2551. sendTest();
  2552. } catch (e) {
  2553. this._setupFakeWorker();
  2554. }
  2555. });
  2556. const sendTest = () => {
  2557. const testObj = new Uint8Array([this.postMessageTransfers ? 255 : 0]);
  2558. try {
  2559. messageHandler.send("test", testObj, [testObj.buffer]);
  2560. } catch (ex) {
  2561. (0, _util.warn)("Cannot use postMessage transfers.");
  2562. testObj[0] = 0;
  2563. messageHandler.send("test", testObj);
  2564. }
  2565. };
  2566. sendTest();
  2567. return;
  2568. } catch (e) {
  2569. (0, _util.info)("The worker has been disabled.");
  2570. }
  2571. }
  2572. this._setupFakeWorker();
  2573. }
  2574. _setupFakeWorker() {
  2575. if (!isWorkerDisabled) {
  2576. (0, _util.warn)("Setting up fake worker.");
  2577. isWorkerDisabled = true;
  2578. }
  2579. setupFakeWorkerGlobal().then(WorkerMessageHandler => {
  2580. if (this.destroyed) {
  2581. this._readyCapability.reject(new Error("Worker was destroyed"));
  2582. return;
  2583. }
  2584. const port = new LoopbackPort();
  2585. this._port = port;
  2586. const id = "fake" + nextFakeWorkerId++;
  2587. const workerHandler = new _message_handler.MessageHandler(id + "_worker", id, port);
  2588. WorkerMessageHandler.setup(workerHandler, port);
  2589. const messageHandler = new _message_handler.MessageHandler(id, id + "_worker", port);
  2590. this._messageHandler = messageHandler;
  2591. this._readyCapability.resolve();
  2592. messageHandler.send("configure", {
  2593. verbosity: this.verbosity
  2594. });
  2595. }).catch(reason => {
  2596. this._readyCapability.reject(new Error(`Setting up fake worker failed: "${reason.message}".`));
  2597. });
  2598. }
  2599. destroy() {
  2600. this.destroyed = true;
  2601. if (this._webWorker) {
  2602. this._webWorker.terminate();
  2603. this._webWorker = null;
  2604. }
  2605. pdfWorkerPorts.delete(this._port);
  2606. this._port = null;
  2607. if (this._messageHandler) {
  2608. this._messageHandler.destroy();
  2609. this._messageHandler = null;
  2610. }
  2611. }
  2612. static fromPort(params) {
  2613. if (!params || !params.port) {
  2614. throw new Error("PDFWorker.fromPort - invalid method signature.");
  2615. }
  2616. if (pdfWorkerPorts.has(params.port)) {
  2617. return pdfWorkerPorts.get(params.port);
  2618. }
  2619. return new PDFWorker(params);
  2620. }
  2621. static getWorkerSrc() {
  2622. return getWorkerSrc();
  2623. }
  2624. }
  2625. return PDFWorker;
  2626. }();
  2627. exports.PDFWorker = PDFWorker;
  2628. class WorkerTransport {
  2629. constructor(messageHandler, loadingTask, networkStream, params) {
  2630. this.messageHandler = messageHandler;
  2631. this.loadingTask = loadingTask;
  2632. this.commonObjs = new PDFObjects();
  2633. this.fontLoader = new _font_loader.FontLoader({
  2634. docId: loadingTask.docId,
  2635. onUnsupportedFeature: this._onUnsupportedFeature.bind(this),
  2636. ownerDocument: params.ownerDocument
  2637. });
  2638. this._params = params;
  2639. this.CMapReaderFactory = new params.CMapReaderFactory({
  2640. baseUrl: params.cMapUrl,
  2641. isCompressed: params.cMapPacked
  2642. });
  2643. this.destroyed = false;
  2644. this.destroyCapability = null;
  2645. this._passwordCapability = null;
  2646. this._networkStream = networkStream;
  2647. this._fullReader = null;
  2648. this._lastProgress = null;
  2649. this.pageCache = [];
  2650. this.pagePromises = [];
  2651. this.downloadInfoCapability = (0, _util.createPromiseCapability)();
  2652. this.setupMessageHandler();
  2653. }
  2654. get loadingTaskSettled() {
  2655. return this.loadingTask._capability.settled;
  2656. }
  2657. destroy() {
  2658. if (this.destroyCapability) {
  2659. return this.destroyCapability.promise;
  2660. }
  2661. this.destroyed = true;
  2662. this.destroyCapability = (0, _util.createPromiseCapability)();
  2663. if (this._passwordCapability) {
  2664. this._passwordCapability.reject(new Error("Worker was destroyed during onPassword callback"));
  2665. }
  2666. const waitOn = [];
  2667. this.pageCache.forEach(function (page) {
  2668. if (page) {
  2669. waitOn.push(page._destroy());
  2670. }
  2671. });
  2672. this.pageCache.length = 0;
  2673. this.pagePromises.length = 0;
  2674. const terminated = this.messageHandler.sendWithPromise("Terminate", null);
  2675. waitOn.push(terminated);
  2676. if (this.loadingTaskSettled) {
  2677. const annotationStorageResetModified = this.loadingTask.promise.then(pdfDocument => {
  2678. if (pdfDocument.hasOwnProperty("annotationStorage")) {
  2679. pdfDocument.annotationStorage.resetModified();
  2680. }
  2681. }).catch(() => {});
  2682. waitOn.push(annotationStorageResetModified);
  2683. }
  2684. Promise.all(waitOn).then(() => {
  2685. this.commonObjs.clear();
  2686. this.fontLoader.clear();
  2687. this._hasJSActionsPromise = null;
  2688. if (this._networkStream) {
  2689. this._networkStream.cancelAllRequests(new _util.AbortException("Worker was terminated."));
  2690. }
  2691. if (this.messageHandler) {
  2692. this.messageHandler.destroy();
  2693. this.messageHandler = null;
  2694. }
  2695. this.destroyCapability.resolve();
  2696. }, this.destroyCapability.reject);
  2697. return this.destroyCapability.promise;
  2698. }
  2699. setupMessageHandler() {
  2700. const {
  2701. messageHandler,
  2702. loadingTask
  2703. } = this;
  2704. messageHandler.on("GetReader", (data, sink) => {
  2705. (0, _util.assert)(this._networkStream, "GetReader - no `IPDFStream` instance available.");
  2706. this._fullReader = this._networkStream.getFullReader();
  2707. this._fullReader.onProgress = evt => {
  2708. this._lastProgress = {
  2709. loaded: evt.loaded,
  2710. total: evt.total
  2711. };
  2712. };
  2713. sink.onPull = () => {
  2714. this._fullReader.read().then(function ({
  2715. value,
  2716. done
  2717. }) {
  2718. if (done) {
  2719. sink.close();
  2720. return;
  2721. }
  2722. (0, _util.assert)((0, _util.isArrayBuffer)(value), "GetReader - expected an ArrayBuffer.");
  2723. sink.enqueue(new Uint8Array(value), 1, [value]);
  2724. }).catch(reason => {
  2725. sink.error(reason);
  2726. });
  2727. };
  2728. sink.onCancel = reason => {
  2729. this._fullReader.cancel(reason);
  2730. sink.ready.catch(readyReason => {
  2731. if (this.destroyed) {
  2732. return;
  2733. }
  2734. throw readyReason;
  2735. });
  2736. };
  2737. });
  2738. messageHandler.on("ReaderHeadersReady", data => {
  2739. const headersCapability = (0, _util.createPromiseCapability)();
  2740. const fullReader = this._fullReader;
  2741. fullReader.headersReady.then(() => {
  2742. if (!fullReader.isStreamingSupported || !fullReader.isRangeSupported) {
  2743. if (this._lastProgress && loadingTask.onProgress) {
  2744. loadingTask.onProgress(this._lastProgress);
  2745. }
  2746. fullReader.onProgress = evt => {
  2747. if (loadingTask.onProgress) {
  2748. loadingTask.onProgress({
  2749. loaded: evt.loaded,
  2750. total: evt.total
  2751. });
  2752. }
  2753. };
  2754. }
  2755. headersCapability.resolve({
  2756. isStreamingSupported: fullReader.isStreamingSupported,
  2757. isRangeSupported: fullReader.isRangeSupported,
  2758. contentLength: fullReader.contentLength
  2759. });
  2760. }, headersCapability.reject);
  2761. return headersCapability.promise;
  2762. });
  2763. messageHandler.on("GetRangeReader", (data, sink) => {
  2764. (0, _util.assert)(this._networkStream, "GetRangeReader - no `IPDFStream` instance available.");
  2765. const rangeReader = this._networkStream.getRangeReader(data.begin, data.end);
  2766. if (!rangeReader) {
  2767. sink.close();
  2768. return;
  2769. }
  2770. sink.onPull = () => {
  2771. rangeReader.read().then(function ({
  2772. value,
  2773. done
  2774. }) {
  2775. if (done) {
  2776. sink.close();
  2777. return;
  2778. }
  2779. (0, _util.assert)((0, _util.isArrayBuffer)(value), "GetRangeReader - expected an ArrayBuffer.");
  2780. sink.enqueue(new Uint8Array(value), 1, [value]);
  2781. }).catch(reason => {
  2782. sink.error(reason);
  2783. });
  2784. };
  2785. sink.onCancel = reason => {
  2786. rangeReader.cancel(reason);
  2787. sink.ready.catch(readyReason => {
  2788. if (this.destroyed) {
  2789. return;
  2790. }
  2791. throw readyReason;
  2792. });
  2793. };
  2794. });
  2795. messageHandler.on("GetDoc", ({
  2796. pdfInfo
  2797. }) => {
  2798. this._numPages = pdfInfo.numPages;
  2799. loadingTask._capability.resolve(new PDFDocumentProxy(pdfInfo, this));
  2800. });
  2801. messageHandler.on("DocException", function (ex) {
  2802. let reason;
  2803. switch (ex.name) {
  2804. case "PasswordException":
  2805. reason = new _util.PasswordException(ex.message, ex.code);
  2806. break;
  2807. case "InvalidPDFException":
  2808. reason = new _util.InvalidPDFException(ex.message);
  2809. break;
  2810. case "MissingPDFException":
  2811. reason = new _util.MissingPDFException(ex.message);
  2812. break;
  2813. case "UnexpectedResponseException":
  2814. reason = new _util.UnexpectedResponseException(ex.message, ex.status);
  2815. break;
  2816. case "UnknownErrorException":
  2817. reason = new _util.UnknownErrorException(ex.message, ex.details);
  2818. break;
  2819. }
  2820. if (!(reason instanceof Error)) {
  2821. const msg = "DocException - expected a valid Error.";
  2822. (0, _util.warn)(msg);
  2823. }
  2824. loadingTask._capability.reject(reason);
  2825. });
  2826. messageHandler.on("PasswordRequest", exception => {
  2827. this._passwordCapability = (0, _util.createPromiseCapability)();
  2828. if (loadingTask.onPassword) {
  2829. const updatePassword = password => {
  2830. this._passwordCapability.resolve({
  2831. password
  2832. });
  2833. };
  2834. try {
  2835. loadingTask.onPassword(updatePassword, exception.code);
  2836. } catch (ex) {
  2837. this._passwordCapability.reject(ex);
  2838. }
  2839. } else {
  2840. this._passwordCapability.reject(new _util.PasswordException(exception.message, exception.code));
  2841. }
  2842. return this._passwordCapability.promise;
  2843. });
  2844. messageHandler.on("DataLoaded", data => {
  2845. if (loadingTask.onProgress) {
  2846. loadingTask.onProgress({
  2847. loaded: data.length,
  2848. total: data.length
  2849. });
  2850. }
  2851. this.downloadInfoCapability.resolve(data);
  2852. });
  2853. messageHandler.on("StartRenderPage", data => {
  2854. if (this.destroyed) {
  2855. return;
  2856. }
  2857. const page = this.pageCache[data.pageIndex];
  2858. page._startRenderPage(data.transparency, data.intent);
  2859. });
  2860. messageHandler.on("commonobj", data => {
  2861. if (this.destroyed) {
  2862. return;
  2863. }
  2864. const [id, type, exportedData] = data;
  2865. if (this.commonObjs.has(id)) {
  2866. return;
  2867. }
  2868. switch (type) {
  2869. case "Font":
  2870. const params = this._params;
  2871. if ("error" in exportedData) {
  2872. const exportedError = exportedData.error;
  2873. (0, _util.warn)(`Error during font loading: ${exportedError}`);
  2874. this.commonObjs.resolve(id, exportedError);
  2875. break;
  2876. }
  2877. let fontRegistry = null;
  2878. if (params.pdfBug && globalThis.FontInspector?.enabled) {
  2879. fontRegistry = {
  2880. registerFont(font, url) {
  2881. globalThis.FontInspector.fontAdded(font, url);
  2882. }
  2883. };
  2884. }
  2885. const font = new _font_loader.FontFaceObject(exportedData, {
  2886. isEvalSupported: params.isEvalSupported,
  2887. disableFontFace: params.disableFontFace,
  2888. ignoreErrors: params.ignoreErrors,
  2889. onUnsupportedFeature: this._onUnsupportedFeature.bind(this),
  2890. fontRegistry
  2891. });
  2892. this.fontLoader.bind(font).catch(reason => {
  2893. return messageHandler.sendWithPromise("FontFallback", {
  2894. id
  2895. });
  2896. }).finally(() => {
  2897. if (!params.fontExtraProperties && font.data) {
  2898. font.data = null;
  2899. }
  2900. this.commonObjs.resolve(id, font);
  2901. });
  2902. break;
  2903. case "FontPath":
  2904. case "Image":
  2905. this.commonObjs.resolve(id, exportedData);
  2906. break;
  2907. default:
  2908. throw new Error(`Got unknown common object type ${type}`);
  2909. }
  2910. });
  2911. messageHandler.on("obj", data => {
  2912. if (this.destroyed) {
  2913. return undefined;
  2914. }
  2915. const [id, pageIndex, type, imageData] = data;
  2916. const pageProxy = this.pageCache[pageIndex];
  2917. if (pageProxy.objs.has(id)) {
  2918. return undefined;
  2919. }
  2920. switch (type) {
  2921. case "Image":
  2922. pageProxy.objs.resolve(id, imageData);
  2923. const MAX_IMAGE_SIZE_TO_STORE = 8000000;
  2924. if (imageData?.data?.length > MAX_IMAGE_SIZE_TO_STORE) {
  2925. pageProxy.cleanupAfterRender = true;
  2926. }
  2927. break;
  2928. default:
  2929. throw new Error(`Got unknown object type ${type}`);
  2930. }
  2931. return undefined;
  2932. });
  2933. messageHandler.on("DocProgress", data => {
  2934. if (this.destroyed) {
  2935. return;
  2936. }
  2937. if (loadingTask.onProgress) {
  2938. loadingTask.onProgress({
  2939. loaded: data.loaded,
  2940. total: data.total
  2941. });
  2942. }
  2943. });
  2944. messageHandler.on("UnsupportedFeature", this._onUnsupportedFeature.bind(this));
  2945. messageHandler.on("FetchBuiltInCMap", (data, sink) => {
  2946. if (this.destroyed) {
  2947. sink.error(new Error("Worker was destroyed"));
  2948. return;
  2949. }
  2950. let fetched = false;
  2951. sink.onPull = () => {
  2952. if (fetched) {
  2953. sink.close();
  2954. return;
  2955. }
  2956. fetched = true;
  2957. this.CMapReaderFactory.fetch(data).then(function (builtInCMap) {
  2958. sink.enqueue(builtInCMap, 1, [builtInCMap.cMapData.buffer]);
  2959. }).catch(function (reason) {
  2960. sink.error(reason);
  2961. });
  2962. };
  2963. });
  2964. }
  2965. _onUnsupportedFeature({
  2966. featureId
  2967. }) {
  2968. if (this.destroyed) {
  2969. return;
  2970. }
  2971. if (this.loadingTask.onUnsupportedFeature) {
  2972. this.loadingTask.onUnsupportedFeature(featureId);
  2973. }
  2974. }
  2975. getData() {
  2976. return this.messageHandler.sendWithPromise("GetData", null);
  2977. }
  2978. getPage(pageNumber) {
  2979. if (!Number.isInteger(pageNumber) || pageNumber <= 0 || pageNumber > this._numPages) {
  2980. return Promise.reject(new Error("Invalid page request"));
  2981. }
  2982. const pageIndex = pageNumber - 1;
  2983. if (pageIndex in this.pagePromises) {
  2984. return this.pagePromises[pageIndex];
  2985. }
  2986. const promise = this.messageHandler.sendWithPromise("GetPage", {
  2987. pageIndex
  2988. }).then(pageInfo => {
  2989. if (this.destroyed) {
  2990. throw new Error("Transport destroyed");
  2991. }
  2992. const page = new PDFPageProxy(pageIndex, pageInfo, this, this._params.ownerDocument, this._params.pdfBug);
  2993. this.pageCache[pageIndex] = page;
  2994. return page;
  2995. });
  2996. this.pagePromises[pageIndex] = promise;
  2997. return promise;
  2998. }
  2999. getPageIndex(ref) {
  3000. return this.messageHandler.sendWithPromise("GetPageIndex", {
  3001. ref
  3002. }).catch(function (reason) {
  3003. return Promise.reject(new Error(reason));
  3004. });
  3005. }
  3006. getAnnotations(pageIndex, intent) {
  3007. return this.messageHandler.sendWithPromise("GetAnnotations", {
  3008. pageIndex,
  3009. intent
  3010. });
  3011. }
  3012. saveDocument(annotationStorage) {
  3013. return this.messageHandler.sendWithPromise("SaveDocument", {
  3014. numPages: this._numPages,
  3015. annotationStorage: annotationStorage?.getAll() || null,
  3016. filename: this._fullReader?.filename ?? null
  3017. }).finally(() => {
  3018. if (annotationStorage) {
  3019. annotationStorage.resetModified();
  3020. }
  3021. });
  3022. }
  3023. getFieldObjects() {
  3024. return this.messageHandler.sendWithPromise("GetFieldObjects", null);
  3025. }
  3026. hasJSActions() {
  3027. return this._hasJSActionsPromise || (this._hasJSActionsPromise = this.messageHandler.sendWithPromise("HasJSActions", null));
  3028. }
  3029. getCalculationOrderIds() {
  3030. return this.messageHandler.sendWithPromise("GetCalculationOrderIds", null);
  3031. }
  3032. getDestinations() {
  3033. return this.messageHandler.sendWithPromise("GetDestinations", null);
  3034. }
  3035. getDestination(id) {
  3036. if (typeof id !== "string") {
  3037. return Promise.reject(new Error("Invalid destination request."));
  3038. }
  3039. return this.messageHandler.sendWithPromise("GetDestination", {
  3040. id
  3041. });
  3042. }
  3043. getPageLabels() {
  3044. return this.messageHandler.sendWithPromise("GetPageLabels", null);
  3045. }
  3046. getPageLayout() {
  3047. return this.messageHandler.sendWithPromise("GetPageLayout", null);
  3048. }
  3049. getPageMode() {
  3050. return this.messageHandler.sendWithPromise("GetPageMode", null);
  3051. }
  3052. getViewerPreferences() {
  3053. return this.messageHandler.sendWithPromise("GetViewerPreferences", null);
  3054. }
  3055. getOpenAction() {
  3056. return this.messageHandler.sendWithPromise("GetOpenAction", null);
  3057. }
  3058. getAttachments() {
  3059. return this.messageHandler.sendWithPromise("GetAttachments", null);
  3060. }
  3061. getJavaScript() {
  3062. return this.messageHandler.sendWithPromise("GetJavaScript", null);
  3063. }
  3064. getDocJSActions() {
  3065. return this.messageHandler.sendWithPromise("GetDocJSActions", null);
  3066. }
  3067. getPageJSActions(pageIndex) {
  3068. return this.messageHandler.sendWithPromise("GetPageJSActions", {
  3069. pageIndex
  3070. });
  3071. }
  3072. getOutline() {
  3073. return this.messageHandler.sendWithPromise("GetOutline", null);
  3074. }
  3075. getOptionalContentConfig() {
  3076. return this.messageHandler.sendWithPromise("GetOptionalContentConfig", null).then(results => {
  3077. return new _optional_content_config.OptionalContentConfig(results);
  3078. });
  3079. }
  3080. getPermissions() {
  3081. return this.messageHandler.sendWithPromise("GetPermissions", null);
  3082. }
  3083. getMetadata() {
  3084. return this.messageHandler.sendWithPromise("GetMetadata", null).then(results => {
  3085. return {
  3086. info: results[0],
  3087. metadata: results[1] ? new _metadata.Metadata(results[1]) : null,
  3088. contentDispositionFilename: this._fullReader?.filename ?? null,
  3089. contentLength: this._fullReader?.contentLength ?? null
  3090. };
  3091. });
  3092. }
  3093. getMarkInfo() {
  3094. return this.messageHandler.sendWithPromise("GetMarkInfo", null);
  3095. }
  3096. getStats() {
  3097. return this.messageHandler.sendWithPromise("GetStats", null);
  3098. }
  3099. startCleanup() {
  3100. return this.messageHandler.sendWithPromise("Cleanup", null).then(() => {
  3101. for (let i = 0, ii = this.pageCache.length; i < ii; i++) {
  3102. const page = this.pageCache[i];
  3103. if (page) {
  3104. const cleanupSuccessful = page.cleanup();
  3105. if (!cleanupSuccessful) {
  3106. throw new Error(`startCleanup: Page ${i + 1} is currently rendering.`);
  3107. }
  3108. }
  3109. }
  3110. this.commonObjs.clear();
  3111. this.fontLoader.clear();
  3112. this._hasJSActionsPromise = null;
  3113. });
  3114. }
  3115. get loadingParams() {
  3116. const params = this._params;
  3117. return (0, _util.shadow)(this, "loadingParams", {
  3118. disableAutoFetch: params.disableAutoFetch,
  3119. disableFontFace: params.disableFontFace
  3120. });
  3121. }
  3122. }
  3123. class PDFObjects {
  3124. constructor() {
  3125. this._objs = Object.create(null);
  3126. }
  3127. _ensureObj(objId) {
  3128. if (this._objs[objId]) {
  3129. return this._objs[objId];
  3130. }
  3131. return this._objs[objId] = {
  3132. capability: (0, _util.createPromiseCapability)(),
  3133. data: null,
  3134. resolved: false
  3135. };
  3136. }
  3137. get(objId, callback = null) {
  3138. if (callback) {
  3139. this._ensureObj(objId).capability.promise.then(callback);
  3140. return null;
  3141. }
  3142. const obj = this._objs[objId];
  3143. if (!obj || !obj.resolved) {
  3144. throw new Error(`Requesting object that isn't resolved yet ${objId}.`);
  3145. }
  3146. return obj.data;
  3147. }
  3148. has(objId) {
  3149. const obj = this._objs[objId];
  3150. return obj?.resolved || false;
  3151. }
  3152. resolve(objId, data) {
  3153. const obj = this._ensureObj(objId);
  3154. obj.resolved = true;
  3155. obj.data = data;
  3156. obj.capability.resolve(data);
  3157. }
  3158. clear() {
  3159. this._objs = Object.create(null);
  3160. }
  3161. }
  3162. class RenderTask {
  3163. constructor(internalRenderTask) {
  3164. this._internalRenderTask = internalRenderTask;
  3165. this.onContinue = null;
  3166. }
  3167. get promise() {
  3168. return this._internalRenderTask.capability.promise;
  3169. }
  3170. cancel() {
  3171. this._internalRenderTask.cancel();
  3172. }
  3173. }
  3174. const InternalRenderTask = function InternalRenderTaskClosure() {
  3175. const canvasInRendering = new WeakSet();
  3176. class InternalRenderTask {
  3177. constructor({
  3178. callback,
  3179. params,
  3180. objs,
  3181. commonObjs,
  3182. operatorList,
  3183. pageIndex,
  3184. canvasFactory,
  3185. webGLContext,
  3186. useRequestAnimationFrame = false,
  3187. pdfBug = false
  3188. }) {
  3189. this.callback = callback;
  3190. this.params = params;
  3191. this.objs = objs;
  3192. this.commonObjs = commonObjs;
  3193. this.operatorListIdx = null;
  3194. this.operatorList = operatorList;
  3195. this._pageIndex = pageIndex;
  3196. this.canvasFactory = canvasFactory;
  3197. this.webGLContext = webGLContext;
  3198. this._pdfBug = pdfBug;
  3199. this.running = false;
  3200. this.graphicsReadyCallback = null;
  3201. this.graphicsReady = false;
  3202. this._useRequestAnimationFrame = useRequestAnimationFrame === true && typeof window !== "undefined";
  3203. this.cancelled = false;
  3204. this.capability = (0, _util.createPromiseCapability)();
  3205. this.task = new RenderTask(this);
  3206. this._continueBound = this._continue.bind(this);
  3207. this._scheduleNextBound = this._scheduleNext.bind(this);
  3208. this._nextBound = this._next.bind(this);
  3209. this._canvas = params.canvasContext.canvas;
  3210. }
  3211. get completed() {
  3212. return this.capability.promise.catch(function () {});
  3213. }
  3214. initializeGraphics({
  3215. transparency = false,
  3216. optionalContentConfig
  3217. }) {
  3218. if (this.cancelled) {
  3219. return;
  3220. }
  3221. if (this._canvas) {
  3222. if (canvasInRendering.has(this._canvas)) {
  3223. throw new Error("Cannot use the same canvas during multiple render() operations. " + "Use different canvas or ensure previous operations were " + "cancelled or completed.");
  3224. }
  3225. canvasInRendering.add(this._canvas);
  3226. }
  3227. if (this._pdfBug && globalThis.StepperManager?.enabled) {
  3228. this.stepper = globalThis.StepperManager.create(this._pageIndex);
  3229. this.stepper.init(this.operatorList);
  3230. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  3231. }
  3232. const {
  3233. canvasContext,
  3234. viewport,
  3235. transform,
  3236. imageLayer,
  3237. background
  3238. } = this.params;
  3239. this.gfx = new _canvas.CanvasGraphics(canvasContext, this.commonObjs, this.objs, this.canvasFactory, this.webGLContext, imageLayer, optionalContentConfig);
  3240. this.gfx.beginDrawing({
  3241. transform,
  3242. viewport,
  3243. transparency,
  3244. background
  3245. });
  3246. this.operatorListIdx = 0;
  3247. this.graphicsReady = true;
  3248. if (this.graphicsReadyCallback) {
  3249. this.graphicsReadyCallback();
  3250. }
  3251. }
  3252. cancel(error = null) {
  3253. this.running = false;
  3254. this.cancelled = true;
  3255. if (this.gfx) {
  3256. this.gfx.endDrawing();
  3257. }
  3258. if (this._canvas) {
  3259. canvasInRendering.delete(this._canvas);
  3260. }
  3261. this.callback(error || new _display_utils.RenderingCancelledException(`Rendering cancelled, page ${this._pageIndex + 1}`, "canvas"));
  3262. }
  3263. operatorListChanged() {
  3264. if (!this.graphicsReady) {
  3265. if (!this.graphicsReadyCallback) {
  3266. this.graphicsReadyCallback = this._continueBound;
  3267. }
  3268. return;
  3269. }
  3270. if (this.stepper) {
  3271. this.stepper.updateOperatorList(this.operatorList);
  3272. }
  3273. if (this.running) {
  3274. return;
  3275. }
  3276. this._continue();
  3277. }
  3278. _continue() {
  3279. this.running = true;
  3280. if (this.cancelled) {
  3281. return;
  3282. }
  3283. if (this.task.onContinue) {
  3284. this.task.onContinue(this._scheduleNextBound);
  3285. } else {
  3286. this._scheduleNext();
  3287. }
  3288. }
  3289. _scheduleNext() {
  3290. if (this._useRequestAnimationFrame) {
  3291. window.requestAnimationFrame(() => {
  3292. this._nextBound().catch(this.cancel.bind(this));
  3293. });
  3294. } else {
  3295. Promise.resolve().then(this._nextBound).catch(this.cancel.bind(this));
  3296. }
  3297. }
  3298. async _next() {
  3299. if (this.cancelled) {
  3300. return;
  3301. }
  3302. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList, this.operatorListIdx, this._continueBound, this.stepper);
  3303. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  3304. this.running = false;
  3305. if (this.operatorList.lastChunk) {
  3306. this.gfx.endDrawing();
  3307. if (this._canvas) {
  3308. canvasInRendering.delete(this._canvas);
  3309. }
  3310. this.callback();
  3311. }
  3312. }
  3313. }
  3314. }
  3315. return InternalRenderTask;
  3316. }();
  3317. const version = '2.7.570';
  3318. exports.version = version;
  3319. const build = 'f2c7338b0';
  3320. exports.build = build;
  3321. /***/ }),
  3322. /* 6 */
  3323. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3324. Object.defineProperty(exports, "__esModule", ({
  3325. value: true
  3326. }));
  3327. exports.FontLoader = exports.FontFaceObject = void 0;
  3328. var _util = __w_pdfjs_require__(2);
  3329. class BaseFontLoader {
  3330. constructor({
  3331. docId,
  3332. onUnsupportedFeature,
  3333. ownerDocument = globalThis.document
  3334. }) {
  3335. if (this.constructor === BaseFontLoader) {
  3336. (0, _util.unreachable)("Cannot initialize BaseFontLoader.");
  3337. }
  3338. this.docId = docId;
  3339. this._onUnsupportedFeature = onUnsupportedFeature;
  3340. this._document = ownerDocument;
  3341. this.nativeFontFaces = [];
  3342. this.styleElement = null;
  3343. }
  3344. addNativeFontFace(nativeFontFace) {
  3345. this.nativeFontFaces.push(nativeFontFace);
  3346. this._document.fonts.add(nativeFontFace);
  3347. }
  3348. insertRule(rule) {
  3349. let styleElement = this.styleElement;
  3350. if (!styleElement) {
  3351. styleElement = this.styleElement = this._document.createElement("style");
  3352. styleElement.id = `PDFJS_FONT_STYLE_TAG_${this.docId}`;
  3353. this._document.documentElement.getElementsByTagName("head")[0].appendChild(styleElement);
  3354. }
  3355. const styleSheet = styleElement.sheet;
  3356. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  3357. }
  3358. clear() {
  3359. this.nativeFontFaces.forEach(nativeFontFace => {
  3360. this._document.fonts.delete(nativeFontFace);
  3361. });
  3362. this.nativeFontFaces.length = 0;
  3363. if (this.styleElement) {
  3364. this.styleElement.remove();
  3365. this.styleElement = null;
  3366. }
  3367. }
  3368. async bind(font) {
  3369. if (font.attached || font.missingFile) {
  3370. return;
  3371. }
  3372. font.attached = true;
  3373. if (this.isFontLoadingAPISupported) {
  3374. const nativeFontFace = font.createNativeFontFace();
  3375. if (nativeFontFace) {
  3376. this.addNativeFontFace(nativeFontFace);
  3377. try {
  3378. await nativeFontFace.loaded;
  3379. } catch (ex) {
  3380. this._onUnsupportedFeature({
  3381. featureId: _util.UNSUPPORTED_FEATURES.errorFontLoadNative
  3382. });
  3383. (0, _util.warn)(`Failed to load font '${nativeFontFace.family}': '${ex}'.`);
  3384. font.disableFontFace = true;
  3385. throw ex;
  3386. }
  3387. }
  3388. return;
  3389. }
  3390. const rule = font.createFontFaceRule();
  3391. if (rule) {
  3392. this.insertRule(rule);
  3393. if (this.isSyncFontLoadingSupported) {
  3394. return;
  3395. }
  3396. await new Promise(resolve => {
  3397. const request = this._queueLoadingCallback(resolve);
  3398. this._prepareFontLoadEvent([rule], [font], request);
  3399. });
  3400. }
  3401. }
  3402. _queueLoadingCallback(callback) {
  3403. (0, _util.unreachable)("Abstract method `_queueLoadingCallback`.");
  3404. }
  3405. get isFontLoadingAPISupported() {
  3406. return (0, _util.shadow)(this, "isFontLoadingAPISupported", !!this._document?.fonts);
  3407. }
  3408. get isSyncFontLoadingSupported() {
  3409. (0, _util.unreachable)("Abstract method `isSyncFontLoadingSupported`.");
  3410. }
  3411. get _loadTestFont() {
  3412. (0, _util.unreachable)("Abstract method `_loadTestFont`.");
  3413. }
  3414. _prepareFontLoadEvent(rules, fontsToLoad, request) {
  3415. (0, _util.unreachable)("Abstract method `_prepareFontLoadEvent`.");
  3416. }
  3417. }
  3418. let FontLoader;
  3419. exports.FontLoader = FontLoader;
  3420. {
  3421. exports.FontLoader = FontLoader = class GenericFontLoader extends BaseFontLoader {
  3422. constructor(params) {
  3423. super(params);
  3424. this.loadingContext = {
  3425. requests: [],
  3426. nextRequestId: 0
  3427. };
  3428. this.loadTestFontId = 0;
  3429. }
  3430. get isSyncFontLoadingSupported() {
  3431. let supported = false;
  3432. if (typeof navigator === "undefined") {
  3433. supported = true;
  3434. } else {
  3435. const m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(navigator.userAgent);
  3436. if (m?.[1] >= 14) {
  3437. supported = true;
  3438. }
  3439. }
  3440. return (0, _util.shadow)(this, "isSyncFontLoadingSupported", supported);
  3441. }
  3442. _queueLoadingCallback(callback) {
  3443. function completeRequest() {
  3444. (0, _util.assert)(!request.done, "completeRequest() cannot be called twice.");
  3445. request.done = true;
  3446. while (context.requests.length > 0 && context.requests[0].done) {
  3447. const otherRequest = context.requests.shift();
  3448. setTimeout(otherRequest.callback, 0);
  3449. }
  3450. }
  3451. const context = this.loadingContext;
  3452. const request = {
  3453. id: `pdfjs-font-loading-${context.nextRequestId++}`,
  3454. done: false,
  3455. complete: completeRequest,
  3456. callback
  3457. };
  3458. context.requests.push(request);
  3459. return request;
  3460. }
  3461. get _loadTestFont() {
  3462. const getLoadTestFont = function () {
  3463. 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==");
  3464. };
  3465. return (0, _util.shadow)(this, "_loadTestFont", getLoadTestFont());
  3466. }
  3467. _prepareFontLoadEvent(rules, fonts, request) {
  3468. function int32(data, offset) {
  3469. return data.charCodeAt(offset) << 24 | data.charCodeAt(offset + 1) << 16 | data.charCodeAt(offset + 2) << 8 | data.charCodeAt(offset + 3) & 0xff;
  3470. }
  3471. function spliceString(s, offset, remove, insert) {
  3472. const chunk1 = s.substring(0, offset);
  3473. const chunk2 = s.substring(offset + remove);
  3474. return chunk1 + insert + chunk2;
  3475. }
  3476. let i, ii;
  3477. const canvas = this._document.createElement("canvas");
  3478. canvas.width = 1;
  3479. canvas.height = 1;
  3480. const ctx = canvas.getContext("2d");
  3481. let called = 0;
  3482. function isFontReady(name, callback) {
  3483. called++;
  3484. if (called > 30) {
  3485. (0, _util.warn)("Load test font never loaded.");
  3486. callback();
  3487. return;
  3488. }
  3489. ctx.font = "30px " + name;
  3490. ctx.fillText(".", 0, 20);
  3491. const imageData = ctx.getImageData(0, 0, 1, 1);
  3492. if (imageData.data[3] > 0) {
  3493. callback();
  3494. return;
  3495. }
  3496. setTimeout(isFontReady.bind(null, name, callback));
  3497. }
  3498. const loadTestFontId = `lt${Date.now()}${this.loadTestFontId++}`;
  3499. let data = this._loadTestFont;
  3500. const COMMENT_OFFSET = 976;
  3501. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length, loadTestFontId);
  3502. const CFF_CHECKSUM_OFFSET = 16;
  3503. const XXXX_VALUE = 0x58585858;
  3504. let checksum = int32(data, CFF_CHECKSUM_OFFSET);
  3505. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  3506. checksum = checksum - XXXX_VALUE + int32(loadTestFontId, i) | 0;
  3507. }
  3508. if (i < loadTestFontId.length) {
  3509. checksum = checksum - XXXX_VALUE + int32(loadTestFontId + "XXX", i) | 0;
  3510. }
  3511. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, (0, _util.string32)(checksum));
  3512. const url = `url(data:font/opentype;base64,${btoa(data)});`;
  3513. const rule = `@font-face {font-family:"${loadTestFontId}";src:${url}}`;
  3514. this.insertRule(rule);
  3515. const names = [];
  3516. for (i = 0, ii = fonts.length; i < ii; i++) {
  3517. names.push(fonts[i].loadedName);
  3518. }
  3519. names.push(loadTestFontId);
  3520. const div = this._document.createElement("div");
  3521. div.style.visibility = "hidden";
  3522. div.style.width = div.style.height = "10px";
  3523. div.style.position = "absolute";
  3524. div.style.top = div.style.left = "0px";
  3525. for (i = 0, ii = names.length; i < ii; ++i) {
  3526. const span = this._document.createElement("span");
  3527. span.textContent = "Hi";
  3528. span.style.fontFamily = names[i];
  3529. div.appendChild(span);
  3530. }
  3531. this._document.body.appendChild(div);
  3532. isFontReady(loadTestFontId, () => {
  3533. this._document.body.removeChild(div);
  3534. request.complete();
  3535. });
  3536. }
  3537. };
  3538. }
  3539. class FontFaceObject {
  3540. constructor(translatedData, {
  3541. isEvalSupported = true,
  3542. disableFontFace = false,
  3543. ignoreErrors = false,
  3544. onUnsupportedFeature = null,
  3545. fontRegistry = null
  3546. }) {
  3547. this.compiledGlyphs = Object.create(null);
  3548. for (const i in translatedData) {
  3549. this[i] = translatedData[i];
  3550. }
  3551. this.isEvalSupported = isEvalSupported !== false;
  3552. this.disableFontFace = disableFontFace === true;
  3553. this.ignoreErrors = ignoreErrors === true;
  3554. this._onUnsupportedFeature = onUnsupportedFeature;
  3555. this.fontRegistry = fontRegistry;
  3556. }
  3557. createNativeFontFace() {
  3558. if (!this.data || this.disableFontFace) {
  3559. return null;
  3560. }
  3561. const nativeFontFace = new FontFace(this.loadedName, this.data, {});
  3562. if (this.fontRegistry) {
  3563. this.fontRegistry.registerFont(this);
  3564. }
  3565. return nativeFontFace;
  3566. }
  3567. createFontFaceRule() {
  3568. if (!this.data || this.disableFontFace) {
  3569. return null;
  3570. }
  3571. const data = (0, _util.bytesToString)(new Uint8Array(this.data));
  3572. const url = `url(data:${this.mimetype};base64,${btoa(data)});`;
  3573. const rule = `@font-face {font-family:"${this.loadedName}";src:${url}}`;
  3574. if (this.fontRegistry) {
  3575. this.fontRegistry.registerFont(this, url);
  3576. }
  3577. return rule;
  3578. }
  3579. getPathGenerator(objs, character) {
  3580. if (this.compiledGlyphs[character] !== undefined) {
  3581. return this.compiledGlyphs[character];
  3582. }
  3583. let cmds, current;
  3584. try {
  3585. cmds = objs.get(this.loadedName + "_path_" + character);
  3586. } catch (ex) {
  3587. if (!this.ignoreErrors) {
  3588. throw ex;
  3589. }
  3590. if (this._onUnsupportedFeature) {
  3591. this._onUnsupportedFeature({
  3592. featureId: _util.UNSUPPORTED_FEATURES.errorFontGetPath
  3593. });
  3594. }
  3595. (0, _util.warn)(`getPathGenerator - ignoring character: "${ex}".`);
  3596. return this.compiledGlyphs[character] = function (c, size) {};
  3597. }
  3598. if (this.isEvalSupported && _util.IsEvalSupportedCached.value) {
  3599. let args,
  3600. js = "";
  3601. for (let i = 0, ii = cmds.length; i < ii; i++) {
  3602. current = cmds[i];
  3603. if (current.args !== undefined) {
  3604. args = current.args.join(",");
  3605. } else {
  3606. args = "";
  3607. }
  3608. js += "c." + current.cmd + "(" + args + ");\n";
  3609. }
  3610. return this.compiledGlyphs[character] = new Function("c", "size", js);
  3611. }
  3612. return this.compiledGlyphs[character] = function (c, size) {
  3613. for (let i = 0, ii = cmds.length; i < ii; i++) {
  3614. current = cmds[i];
  3615. if (current.cmd === "scale") {
  3616. current.args = [size, -size];
  3617. }
  3618. c[current.cmd].apply(c, current.args);
  3619. }
  3620. };
  3621. }
  3622. }
  3623. exports.FontFaceObject = FontFaceObject;
  3624. /***/ }),
  3625. /* 7 */
  3626. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3627. Object.defineProperty(exports, "__esModule", ({
  3628. value: true
  3629. }));
  3630. exports.NodeCMapReaderFactory = exports.NodeCanvasFactory = void 0;
  3631. var _display_utils = __w_pdfjs_require__(1);
  3632. var _is_node = __w_pdfjs_require__(4);
  3633. var _util = __w_pdfjs_require__(2);
  3634. let NodeCanvasFactory = class {
  3635. constructor() {
  3636. (0, _util.unreachable)("Not implemented: NodeCanvasFactory");
  3637. }
  3638. };
  3639. exports.NodeCanvasFactory = NodeCanvasFactory;
  3640. let NodeCMapReaderFactory = class {
  3641. constructor() {
  3642. (0, _util.unreachable)("Not implemented: NodeCMapReaderFactory");
  3643. }
  3644. };
  3645. exports.NodeCMapReaderFactory = NodeCMapReaderFactory;
  3646. if (_is_node.isNodeJS) {
  3647. exports.NodeCanvasFactory = NodeCanvasFactory = class extends _display_utils.BaseCanvasFactory {
  3648. create(width, height) {
  3649. if (width <= 0 || height <= 0) {
  3650. throw new Error("Invalid canvas size");
  3651. }
  3652. const Canvas = require("canvas");
  3653. const canvas = Canvas.createCanvas(width, height);
  3654. return {
  3655. canvas,
  3656. context: canvas.getContext("2d")
  3657. };
  3658. }
  3659. };
  3660. exports.NodeCMapReaderFactory = NodeCMapReaderFactory = class extends _display_utils.BaseCMapReaderFactory {
  3661. _fetchData(url, compressionType) {
  3662. return new Promise((resolve, reject) => {
  3663. const fs = require("fs");
  3664. fs.readFile(url, (error, data) => {
  3665. if (error || !data) {
  3666. reject(new Error(error));
  3667. return;
  3668. }
  3669. resolve({
  3670. cMapData: new Uint8Array(data),
  3671. compressionType
  3672. });
  3673. });
  3674. });
  3675. }
  3676. };
  3677. }
  3678. /***/ }),
  3679. /* 8 */
  3680. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3681. Object.defineProperty(exports, "__esModule", ({
  3682. value: true
  3683. }));
  3684. exports.AnnotationStorage = void 0;
  3685. var _util = __w_pdfjs_require__(2);
  3686. class AnnotationStorage {
  3687. constructor() {
  3688. this._storage = new Map();
  3689. this._modified = false;
  3690. this.onSetModified = null;
  3691. this.onResetModified = null;
  3692. }
  3693. getOrCreateValue(key, defaultValue) {
  3694. if (this._storage.has(key)) {
  3695. return this._storage.get(key);
  3696. }
  3697. this._storage.set(key, defaultValue);
  3698. return defaultValue;
  3699. }
  3700. setValue(key, value) {
  3701. const obj = this._storage.get(key);
  3702. let modified = false;
  3703. if (obj !== undefined) {
  3704. for (const [entry, val] of Object.entries(value)) {
  3705. if (obj[entry] !== val) {
  3706. modified = true;
  3707. obj[entry] = val;
  3708. }
  3709. }
  3710. } else {
  3711. this._storage.set(key, value);
  3712. modified = true;
  3713. }
  3714. if (modified) {
  3715. this._setModified();
  3716. }
  3717. }
  3718. getAll() {
  3719. if (this._storage.size === 0) {
  3720. return null;
  3721. }
  3722. return (0, _util.objectFromEntries)(this._storage);
  3723. }
  3724. get size() {
  3725. return this._storage.size;
  3726. }
  3727. _setModified() {
  3728. if (!this._modified) {
  3729. this._modified = true;
  3730. if (typeof this.onSetModified === "function") {
  3731. this.onSetModified();
  3732. }
  3733. }
  3734. }
  3735. resetModified() {
  3736. if (this._modified) {
  3737. this._modified = false;
  3738. if (typeof this.onResetModified === "function") {
  3739. this.onResetModified();
  3740. }
  3741. }
  3742. }
  3743. }
  3744. exports.AnnotationStorage = AnnotationStorage;
  3745. /***/ }),
  3746. /* 9 */
  3747. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3748. Object.defineProperty(exports, "__esModule", ({
  3749. value: true
  3750. }));
  3751. exports.apiCompatibilityParams = void 0;
  3752. var _is_node = __w_pdfjs_require__(4);
  3753. const compatibilityParams = Object.create(null);
  3754. {
  3755. (function checkFontFace() {
  3756. if (_is_node.isNodeJS) {
  3757. compatibilityParams.disableFontFace = true;
  3758. }
  3759. })();
  3760. }
  3761. const apiCompatibilityParams = Object.freeze(compatibilityParams);
  3762. exports.apiCompatibilityParams = apiCompatibilityParams;
  3763. /***/ }),
  3764. /* 10 */
  3765. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3766. Object.defineProperty(exports, "__esModule", ({
  3767. value: true
  3768. }));
  3769. exports.CanvasGraphics = void 0;
  3770. var _util = __w_pdfjs_require__(2);
  3771. var _pattern_helper = __w_pdfjs_require__(11);
  3772. const MIN_FONT_SIZE = 16;
  3773. const MAX_FONT_SIZE = 100;
  3774. const MAX_GROUP_SIZE = 4096;
  3775. const COMPILE_TYPE3_GLYPHS = true;
  3776. const MAX_SIZE_TO_COMPILE = 1000;
  3777. const FULL_CHUNK_HEIGHT = 16;
  3778. function addContextCurrentTransform(ctx) {
  3779. if (!ctx.mozCurrentTransform) {
  3780. ctx._originalSave = ctx.save;
  3781. ctx._originalRestore = ctx.restore;
  3782. ctx._originalRotate = ctx.rotate;
  3783. ctx._originalScale = ctx.scale;
  3784. ctx._originalTranslate = ctx.translate;
  3785. ctx._originalTransform = ctx.transform;
  3786. ctx._originalSetTransform = ctx.setTransform;
  3787. ctx._transformMatrix = ctx._transformMatrix || [1, 0, 0, 1, 0, 0];
  3788. ctx._transformStack = [];
  3789. Object.defineProperty(ctx, "mozCurrentTransform", {
  3790. get: function getCurrentTransform() {
  3791. return this._transformMatrix;
  3792. }
  3793. });
  3794. Object.defineProperty(ctx, "mozCurrentTransformInverse", {
  3795. get: function getCurrentTransformInverse() {
  3796. const m = this._transformMatrix;
  3797. const a = m[0],
  3798. b = m[1],
  3799. c = m[2],
  3800. d = m[3],
  3801. e = m[4],
  3802. f = m[5];
  3803. const ad_bc = a * d - b * c;
  3804. const bc_ad = b * c - a * d;
  3805. 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];
  3806. }
  3807. });
  3808. ctx.save = function ctxSave() {
  3809. const old = this._transformMatrix;
  3810. this._transformStack.push(old);
  3811. this._transformMatrix = old.slice(0, 6);
  3812. this._originalSave();
  3813. };
  3814. ctx.restore = function ctxRestore() {
  3815. const prev = this._transformStack.pop();
  3816. if (prev) {
  3817. this._transformMatrix = prev;
  3818. this._originalRestore();
  3819. }
  3820. };
  3821. ctx.translate = function ctxTranslate(x, y) {
  3822. const m = this._transformMatrix;
  3823. m[4] = m[0] * x + m[2] * y + m[4];
  3824. m[5] = m[1] * x + m[3] * y + m[5];
  3825. this._originalTranslate(x, y);
  3826. };
  3827. ctx.scale = function ctxScale(x, y) {
  3828. const m = this._transformMatrix;
  3829. m[0] = m[0] * x;
  3830. m[1] = m[1] * x;
  3831. m[2] = m[2] * y;
  3832. m[3] = m[3] * y;
  3833. this._originalScale(x, y);
  3834. };
  3835. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  3836. const m = this._transformMatrix;
  3837. 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]];
  3838. ctx._originalTransform(a, b, c, d, e, f);
  3839. };
  3840. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  3841. this._transformMatrix = [a, b, c, d, e, f];
  3842. ctx._originalSetTransform(a, b, c, d, e, f);
  3843. };
  3844. ctx.rotate = function ctxRotate(angle) {
  3845. const cosValue = Math.cos(angle);
  3846. const sinValue = Math.sin(angle);
  3847. const m = this._transformMatrix;
  3848. 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]];
  3849. this._originalRotate(angle);
  3850. };
  3851. }
  3852. }
  3853. const CachedCanvases = function CachedCanvasesClosure() {
  3854. function CachedCanvases(canvasFactory) {
  3855. this.canvasFactory = canvasFactory;
  3856. this.cache = Object.create(null);
  3857. }
  3858. CachedCanvases.prototype = {
  3859. getCanvas: function CachedCanvases_getCanvas(id, width, height, trackTransform) {
  3860. let canvasEntry;
  3861. if (this.cache[id] !== undefined) {
  3862. canvasEntry = this.cache[id];
  3863. this.canvasFactory.reset(canvasEntry, width, height);
  3864. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  3865. } else {
  3866. canvasEntry = this.canvasFactory.create(width, height);
  3867. this.cache[id] = canvasEntry;
  3868. }
  3869. if (trackTransform) {
  3870. addContextCurrentTransform(canvasEntry.context);
  3871. }
  3872. return canvasEntry;
  3873. },
  3874. clear() {
  3875. for (const id in this.cache) {
  3876. const canvasEntry = this.cache[id];
  3877. this.canvasFactory.destroy(canvasEntry);
  3878. delete this.cache[id];
  3879. }
  3880. }
  3881. };
  3882. return CachedCanvases;
  3883. }();
  3884. function compileType3Glyph(imgData) {
  3885. const POINT_TO_PROCESS_LIMIT = 1000;
  3886. const width = imgData.width,
  3887. height = imgData.height,
  3888. width1 = width + 1;
  3889. let i, ii, j, j0;
  3890. const points = new Uint8Array(width1 * (height + 1));
  3891. const POINT_TYPES = new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  3892. const lineSize = width + 7 & ~7,
  3893. data0 = imgData.data;
  3894. const data = new Uint8Array(lineSize * height);
  3895. let pos = 0;
  3896. for (i = 0, ii = data0.length; i < ii; i++) {
  3897. const elem = data0[i];
  3898. let mask = 128;
  3899. while (mask > 0) {
  3900. data[pos++] = elem & mask ? 0 : 255;
  3901. mask >>= 1;
  3902. }
  3903. }
  3904. let count = 0;
  3905. pos = 0;
  3906. if (data[pos] !== 0) {
  3907. points[0] = 1;
  3908. ++count;
  3909. }
  3910. for (j = 1; j < width; j++) {
  3911. if (data[pos] !== data[pos + 1]) {
  3912. points[j] = data[pos] ? 2 : 1;
  3913. ++count;
  3914. }
  3915. pos++;
  3916. }
  3917. if (data[pos] !== 0) {
  3918. points[j] = 2;
  3919. ++count;
  3920. }
  3921. for (i = 1; i < height; i++) {
  3922. pos = i * lineSize;
  3923. j0 = i * width1;
  3924. if (data[pos - lineSize] !== data[pos]) {
  3925. points[j0] = data[pos] ? 1 : 8;
  3926. ++count;
  3927. }
  3928. let sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  3929. for (j = 1; j < width; j++) {
  3930. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) + (data[pos - lineSize + 1] ? 8 : 0);
  3931. if (POINT_TYPES[sum]) {
  3932. points[j0 + j] = POINT_TYPES[sum];
  3933. ++count;
  3934. }
  3935. pos++;
  3936. }
  3937. if (data[pos - lineSize] !== data[pos]) {
  3938. points[j0 + j] = data[pos] ? 2 : 4;
  3939. ++count;
  3940. }
  3941. if (count > POINT_TO_PROCESS_LIMIT) {
  3942. return null;
  3943. }
  3944. }
  3945. pos = lineSize * (height - 1);
  3946. j0 = i * width1;
  3947. if (data[pos] !== 0) {
  3948. points[j0] = 8;
  3949. ++count;
  3950. }
  3951. for (j = 1; j < width; j++) {
  3952. if (data[pos] !== data[pos + 1]) {
  3953. points[j0 + j] = data[pos] ? 4 : 8;
  3954. ++count;
  3955. }
  3956. pos++;
  3957. }
  3958. if (data[pos] !== 0) {
  3959. points[j0 + j] = 4;
  3960. ++count;
  3961. }
  3962. if (count > POINT_TO_PROCESS_LIMIT) {
  3963. return null;
  3964. }
  3965. const steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  3966. const outlines = [];
  3967. for (i = 0; count && i <= height; i++) {
  3968. let p = i * width1;
  3969. const end = p + width;
  3970. while (p < end && !points[p]) {
  3971. p++;
  3972. }
  3973. if (p === end) {
  3974. continue;
  3975. }
  3976. const coords = [p % width1, i];
  3977. const p0 = p;
  3978. let type = points[p];
  3979. do {
  3980. const step = steps[type];
  3981. do {
  3982. p += step;
  3983. } while (!points[p]);
  3984. const pp = points[p];
  3985. if (pp !== 5 && pp !== 10) {
  3986. type = pp;
  3987. points[p] = 0;
  3988. } else {
  3989. type = pp & 0x33 * type >> 4;
  3990. points[p] &= type >> 2 | type << 2;
  3991. }
  3992. coords.push(p % width1);
  3993. coords.push(p / width1 | 0);
  3994. if (!points[p]) {
  3995. --count;
  3996. }
  3997. } while (p0 !== p);
  3998. outlines.push(coords);
  3999. --i;
  4000. }
  4001. const drawOutline = function (c) {
  4002. c.save();
  4003. c.scale(1 / width, -1 / height);
  4004. c.translate(0, -height);
  4005. c.beginPath();
  4006. for (let k = 0, kk = outlines.length; k < kk; k++) {
  4007. const o = outlines[k];
  4008. c.moveTo(o[0], o[1]);
  4009. for (let l = 2, ll = o.length; l < ll; l += 2) {
  4010. c.lineTo(o[l], o[l + 1]);
  4011. }
  4012. }
  4013. c.fill();
  4014. c.beginPath();
  4015. c.restore();
  4016. };
  4017. return drawOutline;
  4018. }
  4019. const CanvasExtraState = function CanvasExtraStateClosure() {
  4020. function CanvasExtraState() {
  4021. this.alphaIsShape = false;
  4022. this.fontSize = 0;
  4023. this.fontSizeScale = 1;
  4024. this.textMatrix = _util.IDENTITY_MATRIX;
  4025. this.textMatrixScale = 1;
  4026. this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
  4027. this.leading = 0;
  4028. this.x = 0;
  4029. this.y = 0;
  4030. this.lineX = 0;
  4031. this.lineY = 0;
  4032. this.charSpacing = 0;
  4033. this.wordSpacing = 0;
  4034. this.textHScale = 1;
  4035. this.textRenderingMode = _util.TextRenderingMode.FILL;
  4036. this.textRise = 0;
  4037. this.fillColor = "#000000";
  4038. this.strokeColor = "#000000";
  4039. this.patternFill = false;
  4040. this.fillAlpha = 1;
  4041. this.strokeAlpha = 1;
  4042. this.lineWidth = 1;
  4043. this.activeSMask = null;
  4044. this.resumeSMaskCtx = null;
  4045. this.transferMaps = null;
  4046. }
  4047. CanvasExtraState.prototype = {
  4048. clone: function CanvasExtraState_clone() {
  4049. return Object.create(this);
  4050. },
  4051. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  4052. this.x = x;
  4053. this.y = y;
  4054. }
  4055. };
  4056. return CanvasExtraState;
  4057. }();
  4058. const CanvasGraphics = function CanvasGraphicsClosure() {
  4059. const EXECUTION_TIME = 15;
  4060. const EXECUTION_STEPS = 10;
  4061. function CanvasGraphics(canvasCtx, commonObjs, objs, canvasFactory, webGLContext, imageLayer, optionalContentConfig) {
  4062. this.ctx = canvasCtx;
  4063. this.current = new CanvasExtraState();
  4064. this.stateStack = [];
  4065. this.pendingClip = null;
  4066. this.pendingEOFill = false;
  4067. this.res = null;
  4068. this.xobjs = null;
  4069. this.commonObjs = commonObjs;
  4070. this.objs = objs;
  4071. this.canvasFactory = canvasFactory;
  4072. this.webGLContext = webGLContext;
  4073. this.imageLayer = imageLayer;
  4074. this.groupStack = [];
  4075. this.processingType3 = null;
  4076. this.baseTransform = null;
  4077. this.baseTransformStack = [];
  4078. this.groupLevel = 0;
  4079. this.smaskStack = [];
  4080. this.smaskCounter = 0;
  4081. this.tempSMask = null;
  4082. this.contentVisible = true;
  4083. this.markedContentStack = [];
  4084. this.optionalContentConfig = optionalContentConfig;
  4085. this.cachedCanvases = new CachedCanvases(this.canvasFactory);
  4086. if (canvasCtx) {
  4087. addContextCurrentTransform(canvasCtx);
  4088. }
  4089. this._cachedGetSinglePixelWidth = null;
  4090. }
  4091. function putBinaryImageData(ctx, imgData, transferMaps = null) {
  4092. if (typeof ImageData !== "undefined" && imgData instanceof ImageData) {
  4093. ctx.putImageData(imgData, 0, 0);
  4094. return;
  4095. }
  4096. const height = imgData.height,
  4097. width = imgData.width;
  4098. const partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  4099. const fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  4100. const totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  4101. const chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  4102. let srcPos = 0,
  4103. destPos;
  4104. const src = imgData.data;
  4105. const dest = chunkImgData.data;
  4106. let i, j, thisChunkHeight, elemsInThisChunk;
  4107. let transferMapRed, transferMapGreen, transferMapBlue, transferMapGray;
  4108. if (transferMaps) {
  4109. switch (transferMaps.length) {
  4110. case 1:
  4111. transferMapRed = transferMaps[0];
  4112. transferMapGreen = transferMaps[0];
  4113. transferMapBlue = transferMaps[0];
  4114. transferMapGray = transferMaps[0];
  4115. break;
  4116. case 4:
  4117. transferMapRed = transferMaps[0];
  4118. transferMapGreen = transferMaps[1];
  4119. transferMapBlue = transferMaps[2];
  4120. transferMapGray = transferMaps[3];
  4121. break;
  4122. }
  4123. }
  4124. if (imgData.kind === _util.ImageKind.GRAYSCALE_1BPP) {
  4125. const srcLength = src.byteLength;
  4126. const dest32 = new Uint32Array(dest.buffer, 0, dest.byteLength >> 2);
  4127. const dest32DataLength = dest32.length;
  4128. const fullSrcDiff = width + 7 >> 3;
  4129. let white = 0xffffffff;
  4130. let black = _util.IsLittleEndianCached.value ? 0xff000000 : 0x000000ff;
  4131. if (transferMapGray) {
  4132. if (transferMapGray[0] === 0xff && transferMapGray[0xff] === 0) {
  4133. [white, black] = [black, white];
  4134. }
  4135. }
  4136. for (i = 0; i < totalChunks; i++) {
  4137. thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  4138. destPos = 0;
  4139. for (j = 0; j < thisChunkHeight; j++) {
  4140. const srcDiff = srcLength - srcPos;
  4141. let k = 0;
  4142. const kEnd = srcDiff > fullSrcDiff ? width : srcDiff * 8 - 7;
  4143. const kEndUnrolled = kEnd & ~7;
  4144. let mask = 0;
  4145. let srcByte = 0;
  4146. for (; k < kEndUnrolled; k += 8) {
  4147. srcByte = src[srcPos++];
  4148. dest32[destPos++] = srcByte & 128 ? white : black;
  4149. dest32[destPos++] = srcByte & 64 ? white : black;
  4150. dest32[destPos++] = srcByte & 32 ? white : black;
  4151. dest32[destPos++] = srcByte & 16 ? white : black;
  4152. dest32[destPos++] = srcByte & 8 ? white : black;
  4153. dest32[destPos++] = srcByte & 4 ? white : black;
  4154. dest32[destPos++] = srcByte & 2 ? white : black;
  4155. dest32[destPos++] = srcByte & 1 ? white : black;
  4156. }
  4157. for (; k < kEnd; k++) {
  4158. if (mask === 0) {
  4159. srcByte = src[srcPos++];
  4160. mask = 128;
  4161. }
  4162. dest32[destPos++] = srcByte & mask ? white : black;
  4163. mask >>= 1;
  4164. }
  4165. }
  4166. while (destPos < dest32DataLength) {
  4167. dest32[destPos++] = 0;
  4168. }
  4169. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  4170. }
  4171. } else if (imgData.kind === _util.ImageKind.RGBA_32BPP) {
  4172. const hasTransferMaps = !!(transferMapRed || transferMapGreen || transferMapBlue);
  4173. j = 0;
  4174. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  4175. for (i = 0; i < fullChunks; i++) {
  4176. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  4177. srcPos += elemsInThisChunk;
  4178. if (hasTransferMaps) {
  4179. for (let k = 0; k < elemsInThisChunk; k += 4) {
  4180. if (transferMapRed) {
  4181. dest[k + 0] = transferMapRed[dest[k + 0]];
  4182. }
  4183. if (transferMapGreen) {
  4184. dest[k + 1] = transferMapGreen[dest[k + 1]];
  4185. }
  4186. if (transferMapBlue) {
  4187. dest[k + 2] = transferMapBlue[dest[k + 2]];
  4188. }
  4189. }
  4190. }
  4191. ctx.putImageData(chunkImgData, 0, j);
  4192. j += FULL_CHUNK_HEIGHT;
  4193. }
  4194. if (i < totalChunks) {
  4195. elemsInThisChunk = width * partialChunkHeight * 4;
  4196. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  4197. if (hasTransferMaps) {
  4198. for (let k = 0; k < elemsInThisChunk; k += 4) {
  4199. if (transferMapRed) {
  4200. dest[k + 0] = transferMapRed[dest[k + 0]];
  4201. }
  4202. if (transferMapGreen) {
  4203. dest[k + 1] = transferMapGreen[dest[k + 1]];
  4204. }
  4205. if (transferMapBlue) {
  4206. dest[k + 2] = transferMapBlue[dest[k + 2]];
  4207. }
  4208. }
  4209. }
  4210. ctx.putImageData(chunkImgData, 0, j);
  4211. }
  4212. } else if (imgData.kind === _util.ImageKind.RGB_24BPP) {
  4213. const hasTransferMaps = !!(transferMapRed || transferMapGreen || transferMapBlue);
  4214. thisChunkHeight = FULL_CHUNK_HEIGHT;
  4215. elemsInThisChunk = width * thisChunkHeight;
  4216. for (i = 0; i < totalChunks; i++) {
  4217. if (i >= fullChunks) {
  4218. thisChunkHeight = partialChunkHeight;
  4219. elemsInThisChunk = width * thisChunkHeight;
  4220. }
  4221. destPos = 0;
  4222. for (j = elemsInThisChunk; j--;) {
  4223. dest[destPos++] = src[srcPos++];
  4224. dest[destPos++] = src[srcPos++];
  4225. dest[destPos++] = src[srcPos++];
  4226. dest[destPos++] = 255;
  4227. }
  4228. if (hasTransferMaps) {
  4229. for (let k = 0; k < destPos; k += 4) {
  4230. if (transferMapRed) {
  4231. dest[k + 0] = transferMapRed[dest[k + 0]];
  4232. }
  4233. if (transferMapGreen) {
  4234. dest[k + 1] = transferMapGreen[dest[k + 1]];
  4235. }
  4236. if (transferMapBlue) {
  4237. dest[k + 2] = transferMapBlue[dest[k + 2]];
  4238. }
  4239. }
  4240. }
  4241. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  4242. }
  4243. } else {
  4244. throw new Error(`bad image kind: ${imgData.kind}`);
  4245. }
  4246. }
  4247. function putBinaryImageMask(ctx, imgData) {
  4248. const height = imgData.height,
  4249. width = imgData.width;
  4250. const partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  4251. const fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  4252. const totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  4253. const chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  4254. let srcPos = 0;
  4255. const src = imgData.data;
  4256. const dest = chunkImgData.data;
  4257. for (let i = 0; i < totalChunks; i++) {
  4258. const thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  4259. let destPos = 3;
  4260. for (let j = 0; j < thisChunkHeight; j++) {
  4261. let elem,
  4262. mask = 0;
  4263. for (let k = 0; k < width; k++) {
  4264. if (!mask) {
  4265. elem = src[srcPos++];
  4266. mask = 128;
  4267. }
  4268. dest[destPos] = elem & mask ? 0 : 255;
  4269. destPos += 4;
  4270. mask >>= 1;
  4271. }
  4272. }
  4273. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  4274. }
  4275. }
  4276. function copyCtxState(sourceCtx, destCtx) {
  4277. const properties = ["strokeStyle", "fillStyle", "fillRule", "globalAlpha", "lineWidth", "lineCap", "lineJoin", "miterLimit", "globalCompositeOperation", "font"];
  4278. for (let i = 0, ii = properties.length; i < ii; i++) {
  4279. const property = properties[i];
  4280. if (sourceCtx[property] !== undefined) {
  4281. destCtx[property] = sourceCtx[property];
  4282. }
  4283. }
  4284. if (sourceCtx.setLineDash !== undefined) {
  4285. destCtx.setLineDash(sourceCtx.getLineDash());
  4286. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  4287. }
  4288. }
  4289. function resetCtxToDefault(ctx) {
  4290. ctx.strokeStyle = "#000000";
  4291. ctx.fillStyle = "#000000";
  4292. ctx.fillRule = "nonzero";
  4293. ctx.globalAlpha = 1;
  4294. ctx.lineWidth = 1;
  4295. ctx.lineCap = "butt";
  4296. ctx.lineJoin = "miter";
  4297. ctx.miterLimit = 10;
  4298. ctx.globalCompositeOperation = "source-over";
  4299. ctx.font = "10px sans-serif";
  4300. if (ctx.setLineDash !== undefined) {
  4301. ctx.setLineDash([]);
  4302. ctx.lineDashOffset = 0;
  4303. }
  4304. }
  4305. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  4306. const length = bytes.length;
  4307. for (let i = 3; i < length; i += 4) {
  4308. const alpha = bytes[i];
  4309. if (alpha === 0) {
  4310. bytes[i - 3] = r0;
  4311. bytes[i - 2] = g0;
  4312. bytes[i - 1] = b0;
  4313. } else if (alpha < 255) {
  4314. const alpha_ = 255 - alpha;
  4315. bytes[i - 3] = bytes[i - 3] * alpha + r0 * alpha_ >> 8;
  4316. bytes[i - 2] = bytes[i - 2] * alpha + g0 * alpha_ >> 8;
  4317. bytes[i - 1] = bytes[i - 1] * alpha + b0 * alpha_ >> 8;
  4318. }
  4319. }
  4320. }
  4321. function composeSMaskAlpha(maskData, layerData, transferMap) {
  4322. const length = maskData.length;
  4323. const scale = 1 / 255;
  4324. for (let i = 3; i < length; i += 4) {
  4325. const alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
  4326. layerData[i] = layerData[i] * alpha * scale | 0;
  4327. }
  4328. }
  4329. function composeSMaskLuminosity(maskData, layerData, transferMap) {
  4330. const length = maskData.length;
  4331. for (let i = 3; i < length; i += 4) {
  4332. const y = maskData[i - 3] * 77 + maskData[i - 2] * 152 + maskData[i - 1] * 28;
  4333. layerData[i] = transferMap ? layerData[i] * transferMap[y >> 8] >> 8 : layerData[i] * y >> 16;
  4334. }
  4335. }
  4336. function genericComposeSMask(maskCtx, layerCtx, width, height, subtype, backdrop, transferMap) {
  4337. const hasBackdrop = !!backdrop;
  4338. const r0 = hasBackdrop ? backdrop[0] : 0;
  4339. const g0 = hasBackdrop ? backdrop[1] : 0;
  4340. const b0 = hasBackdrop ? backdrop[2] : 0;
  4341. let composeFn;
  4342. if (subtype === "Luminosity") {
  4343. composeFn = composeSMaskLuminosity;
  4344. } else {
  4345. composeFn = composeSMaskAlpha;
  4346. }
  4347. const PIXELS_TO_PROCESS = 1048576;
  4348. const chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  4349. for (let row = 0; row < height; row += chunkSize) {
  4350. const chunkHeight = Math.min(chunkSize, height - row);
  4351. const maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  4352. const layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  4353. if (hasBackdrop) {
  4354. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  4355. }
  4356. composeFn(maskData.data, layerData.data, transferMap);
  4357. maskCtx.putImageData(layerData, 0, row);
  4358. }
  4359. }
  4360. function composeSMask(ctx, smask, layerCtx, webGLContext) {
  4361. const mask = smask.canvas;
  4362. const maskCtx = smask.context;
  4363. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY, smask.offsetX, smask.offsetY);
  4364. const backdrop = smask.backdrop || null;
  4365. if (!smask.transferMap && webGLContext.isEnabled) {
  4366. const composed = webGLContext.composeSMask({
  4367. layer: layerCtx.canvas,
  4368. mask,
  4369. properties: {
  4370. subtype: smask.subtype,
  4371. backdrop
  4372. }
  4373. });
  4374. ctx.setTransform(1, 0, 0, 1, 0, 0);
  4375. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  4376. return;
  4377. }
  4378. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height, smask.subtype, backdrop, smask.transferMap);
  4379. ctx.drawImage(mask, 0, 0);
  4380. }
  4381. const LINE_CAP_STYLES = ["butt", "round", "square"];
  4382. const LINE_JOIN_STYLES = ["miter", "round", "bevel"];
  4383. const NORMAL_CLIP = {};
  4384. const EO_CLIP = {};
  4385. CanvasGraphics.prototype = {
  4386. beginDrawing({
  4387. transform,
  4388. viewport,
  4389. transparency = false,
  4390. background = null
  4391. }) {
  4392. const width = this.ctx.canvas.width;
  4393. const height = this.ctx.canvas.height;
  4394. this.ctx.save();
  4395. this.ctx.fillStyle = background || "rgb(255, 255, 255)";
  4396. this.ctx.fillRect(0, 0, width, height);
  4397. this.ctx.restore();
  4398. if (transparency) {
  4399. const transparentCanvas = this.cachedCanvases.getCanvas("transparent", width, height, true);
  4400. this.compositeCtx = this.ctx;
  4401. this.transparentCanvas = transparentCanvas.canvas;
  4402. this.ctx = transparentCanvas.context;
  4403. this.ctx.save();
  4404. this.ctx.transform.apply(this.ctx, this.compositeCtx.mozCurrentTransform);
  4405. }
  4406. this.ctx.save();
  4407. resetCtxToDefault(this.ctx);
  4408. if (transform) {
  4409. this.ctx.transform.apply(this.ctx, transform);
  4410. }
  4411. this.ctx.transform.apply(this.ctx, viewport.transform);
  4412. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  4413. this._combinedScaleFactor = Math.hypot(this.baseTransform[0], this.baseTransform[2]);
  4414. if (this.imageLayer) {
  4415. this.imageLayer.beginLayout();
  4416. }
  4417. },
  4418. executeOperatorList: function CanvasGraphics_executeOperatorList(operatorList, executionStartIdx, continueCallback, stepper) {
  4419. const argsArray = operatorList.argsArray;
  4420. const fnArray = operatorList.fnArray;
  4421. let i = executionStartIdx || 0;
  4422. const argsArrayLen = argsArray.length;
  4423. if (argsArrayLen === i) {
  4424. return i;
  4425. }
  4426. const chunkOperations = argsArrayLen - i > EXECUTION_STEPS && typeof continueCallback === "function";
  4427. const endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  4428. let steps = 0;
  4429. const commonObjs = this.commonObjs;
  4430. const objs = this.objs;
  4431. let fnId;
  4432. while (true) {
  4433. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  4434. stepper.breakIt(i, continueCallback);
  4435. return i;
  4436. }
  4437. fnId = fnArray[i];
  4438. if (fnId !== _util.OPS.dependency) {
  4439. this[fnId].apply(this, argsArray[i]);
  4440. } else {
  4441. for (const depObjId of argsArray[i]) {
  4442. const objsPool = depObjId.startsWith("g_") ? commonObjs : objs;
  4443. if (!objsPool.has(depObjId)) {
  4444. objsPool.get(depObjId, continueCallback);
  4445. return i;
  4446. }
  4447. }
  4448. }
  4449. i++;
  4450. if (i === argsArrayLen) {
  4451. return i;
  4452. }
  4453. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  4454. if (Date.now() > endTime) {
  4455. continueCallback();
  4456. return i;
  4457. }
  4458. steps = 0;
  4459. }
  4460. }
  4461. },
  4462. endDrawing: function CanvasGraphics_endDrawing() {
  4463. while (this.stateStack.length || this.current.activeSMask !== null) {
  4464. this.restore();
  4465. }
  4466. this.ctx.restore();
  4467. if (this.transparentCanvas) {
  4468. this.ctx = this.compositeCtx;
  4469. this.ctx.save();
  4470. this.ctx.setTransform(1, 0, 0, 1, 0, 0);
  4471. this.ctx.drawImage(this.transparentCanvas, 0, 0);
  4472. this.ctx.restore();
  4473. this.transparentCanvas = null;
  4474. }
  4475. this.cachedCanvases.clear();
  4476. this.webGLContext.clear();
  4477. if (this.imageLayer) {
  4478. this.imageLayer.endLayout();
  4479. }
  4480. },
  4481. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  4482. this.current.lineWidth = width;
  4483. this.ctx.lineWidth = width;
  4484. },
  4485. setLineCap: function CanvasGraphics_setLineCap(style) {
  4486. this.ctx.lineCap = LINE_CAP_STYLES[style];
  4487. },
  4488. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  4489. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  4490. },
  4491. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  4492. this.ctx.miterLimit = limit;
  4493. },
  4494. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  4495. const ctx = this.ctx;
  4496. if (ctx.setLineDash !== undefined) {
  4497. ctx.setLineDash(dashArray);
  4498. ctx.lineDashOffset = dashPhase;
  4499. }
  4500. },
  4501. setRenderingIntent(intent) {},
  4502. setFlatness(flatness) {},
  4503. setGState: function CanvasGraphics_setGState(states) {
  4504. for (let i = 0, ii = states.length; i < ii; i++) {
  4505. const state = states[i];
  4506. const key = state[0];
  4507. const value = state[1];
  4508. switch (key) {
  4509. case "LW":
  4510. this.setLineWidth(value);
  4511. break;
  4512. case "LC":
  4513. this.setLineCap(value);
  4514. break;
  4515. case "LJ":
  4516. this.setLineJoin(value);
  4517. break;
  4518. case "ML":
  4519. this.setMiterLimit(value);
  4520. break;
  4521. case "D":
  4522. this.setDash(value[0], value[1]);
  4523. break;
  4524. case "RI":
  4525. this.setRenderingIntent(value);
  4526. break;
  4527. case "FL":
  4528. this.setFlatness(value);
  4529. break;
  4530. case "Font":
  4531. this.setFont(value[0], value[1]);
  4532. break;
  4533. case "CA":
  4534. this.current.strokeAlpha = state[1];
  4535. break;
  4536. case "ca":
  4537. this.current.fillAlpha = state[1];
  4538. this.ctx.globalAlpha = state[1];
  4539. break;
  4540. case "BM":
  4541. this.ctx.globalCompositeOperation = value;
  4542. break;
  4543. case "SMask":
  4544. if (this.current.activeSMask) {
  4545. if (this.stateStack.length > 0 && this.stateStack[this.stateStack.length - 1].activeSMask === this.current.activeSMask) {
  4546. this.suspendSMaskGroup();
  4547. } else {
  4548. this.endSMaskGroup();
  4549. }
  4550. }
  4551. this.current.activeSMask = value ? this.tempSMask : null;
  4552. if (this.current.activeSMask) {
  4553. this.beginSMaskGroup();
  4554. }
  4555. this.tempSMask = null;
  4556. break;
  4557. case "TR":
  4558. this.current.transferMaps = value;
  4559. }
  4560. }
  4561. },
  4562. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  4563. const activeSMask = this.current.activeSMask;
  4564. const drawnWidth = activeSMask.canvas.width;
  4565. const drawnHeight = activeSMask.canvas.height;
  4566. const cacheId = "smaskGroupAt" + this.groupLevel;
  4567. const scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true);
  4568. const currentCtx = this.ctx;
  4569. const currentTransform = currentCtx.mozCurrentTransform;
  4570. this.ctx.save();
  4571. const groupCtx = scratchCanvas.context;
  4572. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  4573. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  4574. groupCtx.transform.apply(groupCtx, currentTransform);
  4575. activeSMask.startTransformInverse = groupCtx.mozCurrentTransformInverse;
  4576. copyCtxState(currentCtx, groupCtx);
  4577. this.ctx = groupCtx;
  4578. this.setGState([["BM", "source-over"], ["ca", 1], ["CA", 1]]);
  4579. this.groupStack.push(currentCtx);
  4580. this.groupLevel++;
  4581. },
  4582. suspendSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  4583. const groupCtx = this.ctx;
  4584. this.groupLevel--;
  4585. this.ctx = this.groupStack.pop();
  4586. composeSMask(this.ctx, this.current.activeSMask, groupCtx, this.webGLContext);
  4587. this.ctx.restore();
  4588. this.ctx.save();
  4589. copyCtxState(groupCtx, this.ctx);
  4590. this.current.resumeSMaskCtx = groupCtx;
  4591. const deltaTransform = _util.Util.transform(this.current.activeSMask.startTransformInverse, groupCtx.mozCurrentTransform);
  4592. this.ctx.transform.apply(this.ctx, deltaTransform);
  4593. groupCtx.save();
  4594. groupCtx.setTransform(1, 0, 0, 1, 0, 0);
  4595. groupCtx.clearRect(0, 0, groupCtx.canvas.width, groupCtx.canvas.height);
  4596. groupCtx.restore();
  4597. },
  4598. resumeSMaskGroup: function CanvasGraphics_resumeSMaskGroup() {
  4599. const groupCtx = this.current.resumeSMaskCtx;
  4600. const currentCtx = this.ctx;
  4601. this.ctx = groupCtx;
  4602. this.groupStack.push(currentCtx);
  4603. this.groupLevel++;
  4604. },
  4605. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  4606. const groupCtx = this.ctx;
  4607. this.groupLevel--;
  4608. this.ctx = this.groupStack.pop();
  4609. composeSMask(this.ctx, this.current.activeSMask, groupCtx, this.webGLContext);
  4610. this.ctx.restore();
  4611. copyCtxState(groupCtx, this.ctx);
  4612. const deltaTransform = _util.Util.transform(this.current.activeSMask.startTransformInverse, groupCtx.mozCurrentTransform);
  4613. this.ctx.transform.apply(this.ctx, deltaTransform);
  4614. },
  4615. save: function CanvasGraphics_save() {
  4616. this.ctx.save();
  4617. const old = this.current;
  4618. this.stateStack.push(old);
  4619. this.current = old.clone();
  4620. this.current.resumeSMaskCtx = null;
  4621. },
  4622. restore: function CanvasGraphics_restore() {
  4623. if (this.current.resumeSMaskCtx) {
  4624. this.resumeSMaskGroup();
  4625. }
  4626. if (this.current.activeSMask !== null && (this.stateStack.length === 0 || this.stateStack[this.stateStack.length - 1].activeSMask !== this.current.activeSMask)) {
  4627. this.endSMaskGroup();
  4628. }
  4629. if (this.stateStack.length !== 0) {
  4630. this.current = this.stateStack.pop();
  4631. this.ctx.restore();
  4632. this.pendingClip = null;
  4633. this._cachedGetSinglePixelWidth = null;
  4634. } else {
  4635. this.current.activeSMask = null;
  4636. }
  4637. },
  4638. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  4639. this.ctx.transform(a, b, c, d, e, f);
  4640. this._cachedGetSinglePixelWidth = null;
  4641. },
  4642. constructPath: function CanvasGraphics_constructPath(ops, args) {
  4643. const ctx = this.ctx;
  4644. const current = this.current;
  4645. let x = current.x,
  4646. y = current.y;
  4647. for (let i = 0, j = 0, ii = ops.length; i < ii; i++) {
  4648. switch (ops[i] | 0) {
  4649. case _util.OPS.rectangle:
  4650. x = args[j++];
  4651. y = args[j++];
  4652. const width = args[j++];
  4653. const height = args[j++];
  4654. const xw = x + width;
  4655. const yh = y + height;
  4656. ctx.moveTo(x, y);
  4657. if (width === 0 || height === 0) {
  4658. ctx.lineTo(xw, yh);
  4659. } else {
  4660. ctx.lineTo(xw, y);
  4661. ctx.lineTo(xw, yh);
  4662. ctx.lineTo(x, yh);
  4663. }
  4664. ctx.closePath();
  4665. break;
  4666. case _util.OPS.moveTo:
  4667. x = args[j++];
  4668. y = args[j++];
  4669. ctx.moveTo(x, y);
  4670. break;
  4671. case _util.OPS.lineTo:
  4672. x = args[j++];
  4673. y = args[j++];
  4674. ctx.lineTo(x, y);
  4675. break;
  4676. case _util.OPS.curveTo:
  4677. x = args[j + 4];
  4678. y = args[j + 5];
  4679. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3], x, y);
  4680. j += 6;
  4681. break;
  4682. case _util.OPS.curveTo2:
  4683. ctx.bezierCurveTo(x, y, args[j], args[j + 1], args[j + 2], args[j + 3]);
  4684. x = args[j + 2];
  4685. y = args[j + 3];
  4686. j += 4;
  4687. break;
  4688. case _util.OPS.curveTo3:
  4689. x = args[j + 2];
  4690. y = args[j + 3];
  4691. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  4692. j += 4;
  4693. break;
  4694. case _util.OPS.closePath:
  4695. ctx.closePath();
  4696. break;
  4697. }
  4698. }
  4699. current.setCurrentPoint(x, y);
  4700. },
  4701. closePath: function CanvasGraphics_closePath() {
  4702. this.ctx.closePath();
  4703. },
  4704. stroke: function CanvasGraphics_stroke(consumePath) {
  4705. consumePath = typeof consumePath !== "undefined" ? consumePath : true;
  4706. const ctx = this.ctx;
  4707. const strokeColor = this.current.strokeColor;
  4708. ctx.globalAlpha = this.current.strokeAlpha;
  4709. if (this.contentVisible) {
  4710. if (typeof strokeColor === "object" && strokeColor?.getPattern) {
  4711. ctx.save();
  4712. const transform = ctx.mozCurrentTransform;
  4713. const scale = _util.Util.singularValueDecompose2dScale(transform)[0];
  4714. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  4715. const lineWidth = this.getSinglePixelWidth();
  4716. const scaledLineWidth = this.current.lineWidth * scale;
  4717. if (lineWidth < 0 && -lineWidth >= scaledLineWidth) {
  4718. ctx.resetTransform();
  4719. ctx.lineWidth = Math.round(this._combinedScaleFactor);
  4720. } else {
  4721. ctx.lineWidth = Math.max(lineWidth, scaledLineWidth);
  4722. }
  4723. ctx.stroke();
  4724. ctx.restore();
  4725. } else {
  4726. const lineWidth = this.getSinglePixelWidth();
  4727. if (lineWidth < 0 && -lineWidth >= this.current.lineWidth) {
  4728. ctx.save();
  4729. ctx.resetTransform();
  4730. ctx.lineWidth = Math.round(this._combinedScaleFactor);
  4731. ctx.stroke();
  4732. ctx.restore();
  4733. } else {
  4734. ctx.lineWidth = Math.max(lineWidth, this.current.lineWidth);
  4735. ctx.stroke();
  4736. }
  4737. }
  4738. }
  4739. if (consumePath) {
  4740. this.consumePath();
  4741. }
  4742. ctx.globalAlpha = this.current.fillAlpha;
  4743. },
  4744. closeStroke: function CanvasGraphics_closeStroke() {
  4745. this.closePath();
  4746. this.stroke();
  4747. },
  4748. fill: function CanvasGraphics_fill(consumePath) {
  4749. consumePath = typeof consumePath !== "undefined" ? consumePath : true;
  4750. const ctx = this.ctx;
  4751. const fillColor = this.current.fillColor;
  4752. const isPatternFill = this.current.patternFill;
  4753. let needRestore = false;
  4754. if (isPatternFill) {
  4755. ctx.save();
  4756. if (this.baseTransform) {
  4757. ctx.setTransform.apply(ctx, this.baseTransform);
  4758. }
  4759. ctx.fillStyle = fillColor.getPattern(ctx, this);
  4760. needRestore = true;
  4761. }
  4762. if (this.contentVisible) {
  4763. if (this.pendingEOFill) {
  4764. ctx.fill("evenodd");
  4765. this.pendingEOFill = false;
  4766. } else {
  4767. ctx.fill();
  4768. }
  4769. }
  4770. if (needRestore) {
  4771. ctx.restore();
  4772. }
  4773. if (consumePath) {
  4774. this.consumePath();
  4775. }
  4776. },
  4777. eoFill: function CanvasGraphics_eoFill() {
  4778. this.pendingEOFill = true;
  4779. this.fill();
  4780. },
  4781. fillStroke: function CanvasGraphics_fillStroke() {
  4782. this.fill(false);
  4783. this.stroke(false);
  4784. this.consumePath();
  4785. },
  4786. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  4787. this.pendingEOFill = true;
  4788. this.fillStroke();
  4789. },
  4790. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  4791. this.closePath();
  4792. this.fillStroke();
  4793. },
  4794. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  4795. this.pendingEOFill = true;
  4796. this.closePath();
  4797. this.fillStroke();
  4798. },
  4799. endPath: function CanvasGraphics_endPath() {
  4800. this.consumePath();
  4801. },
  4802. clip: function CanvasGraphics_clip() {
  4803. this.pendingClip = NORMAL_CLIP;
  4804. },
  4805. eoClip: function CanvasGraphics_eoClip() {
  4806. this.pendingClip = EO_CLIP;
  4807. },
  4808. beginText: function CanvasGraphics_beginText() {
  4809. this.current.textMatrix = _util.IDENTITY_MATRIX;
  4810. this.current.textMatrixScale = 1;
  4811. this.current.x = this.current.lineX = 0;
  4812. this.current.y = this.current.lineY = 0;
  4813. },
  4814. endText: function CanvasGraphics_endText() {
  4815. const paths = this.pendingTextPaths;
  4816. const ctx = this.ctx;
  4817. if (paths === undefined) {
  4818. ctx.beginPath();
  4819. return;
  4820. }
  4821. ctx.save();
  4822. ctx.beginPath();
  4823. for (let i = 0; i < paths.length; i++) {
  4824. const path = paths[i];
  4825. ctx.setTransform.apply(ctx, path.transform);
  4826. ctx.translate(path.x, path.y);
  4827. path.addToPath(ctx, path.fontSize);
  4828. }
  4829. ctx.restore();
  4830. ctx.clip();
  4831. ctx.beginPath();
  4832. delete this.pendingTextPaths;
  4833. },
  4834. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  4835. this.current.charSpacing = spacing;
  4836. },
  4837. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  4838. this.current.wordSpacing = spacing;
  4839. },
  4840. setHScale: function CanvasGraphics_setHScale(scale) {
  4841. this.current.textHScale = scale / 100;
  4842. },
  4843. setLeading: function CanvasGraphics_setLeading(leading) {
  4844. this.current.leading = -leading;
  4845. },
  4846. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  4847. const fontObj = this.commonObjs.get(fontRefName);
  4848. const current = this.current;
  4849. if (!fontObj) {
  4850. throw new Error(`Can't find font for ${fontRefName}`);
  4851. }
  4852. current.fontMatrix = fontObj.fontMatrix || _util.FONT_IDENTITY_MATRIX;
  4853. if (current.fontMatrix[0] === 0 || current.fontMatrix[3] === 0) {
  4854. (0, _util.warn)("Invalid font matrix for font " + fontRefName);
  4855. }
  4856. if (size < 0) {
  4857. size = -size;
  4858. current.fontDirection = -1;
  4859. } else {
  4860. current.fontDirection = 1;
  4861. }
  4862. this.current.font = fontObj;
  4863. this.current.fontSize = size;
  4864. if (fontObj.isType3Font) {
  4865. return;
  4866. }
  4867. const name = fontObj.loadedName || "sans-serif";
  4868. let bold = "normal";
  4869. if (fontObj.black) {
  4870. bold = "900";
  4871. } else if (fontObj.bold) {
  4872. bold = "bold";
  4873. }
  4874. const italic = fontObj.italic ? "italic" : "normal";
  4875. const typeface = `"${name}", ${fontObj.fallbackName}`;
  4876. let browserFontSize = size;
  4877. if (size < MIN_FONT_SIZE) {
  4878. browserFontSize = MIN_FONT_SIZE;
  4879. } else if (size > MAX_FONT_SIZE) {
  4880. browserFontSize = MAX_FONT_SIZE;
  4881. }
  4882. this.current.fontSizeScale = size / browserFontSize;
  4883. this.ctx.font = `${italic} ${bold} ${browserFontSize}px ${typeface}`;
  4884. },
  4885. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  4886. this.current.textRenderingMode = mode;
  4887. },
  4888. setTextRise: function CanvasGraphics_setTextRise(rise) {
  4889. this.current.textRise = rise;
  4890. },
  4891. moveText: function CanvasGraphics_moveText(x, y) {
  4892. this.current.x = this.current.lineX += x;
  4893. this.current.y = this.current.lineY += y;
  4894. },
  4895. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  4896. this.setLeading(-y);
  4897. this.moveText(x, y);
  4898. },
  4899. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  4900. this.current.textMatrix = [a, b, c, d, e, f];
  4901. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  4902. this.current.x = this.current.lineX = 0;
  4903. this.current.y = this.current.lineY = 0;
  4904. },
  4905. nextLine: function CanvasGraphics_nextLine() {
  4906. this.moveText(0, this.current.leading);
  4907. },
  4908. paintChar(character, x, y, patternTransform, resetLineWidthToOne) {
  4909. const ctx = this.ctx;
  4910. const current = this.current;
  4911. const font = current.font;
  4912. const textRenderingMode = current.textRenderingMode;
  4913. const fontSize = current.fontSize / current.fontSizeScale;
  4914. const fillStrokeMode = textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  4915. const isAddToPathSet = !!(textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG);
  4916. const patternFill = current.patternFill && !font.missingFile;
  4917. let addToPath;
  4918. if (font.disableFontFace || isAddToPathSet || patternFill) {
  4919. addToPath = font.getPathGenerator(this.commonObjs, character);
  4920. }
  4921. if (font.disableFontFace || patternFill) {
  4922. ctx.save();
  4923. ctx.translate(x, y);
  4924. ctx.beginPath();
  4925. addToPath(ctx, fontSize);
  4926. if (patternTransform) {
  4927. ctx.setTransform.apply(ctx, patternTransform);
  4928. }
  4929. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  4930. ctx.fill();
  4931. }
  4932. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  4933. if (resetLineWidthToOne) {
  4934. ctx.resetTransform();
  4935. ctx.lineWidth = Math.round(this._combinedScaleFactor);
  4936. }
  4937. ctx.stroke();
  4938. }
  4939. ctx.restore();
  4940. } else {
  4941. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  4942. ctx.fillText(character, x, y);
  4943. }
  4944. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  4945. if (resetLineWidthToOne) {
  4946. ctx.save();
  4947. ctx.moveTo(x, y);
  4948. ctx.resetTransform();
  4949. ctx.lineWidth = Math.round(this._combinedScaleFactor);
  4950. ctx.strokeText(character, 0, 0);
  4951. ctx.restore();
  4952. } else {
  4953. ctx.strokeText(character, x, y);
  4954. }
  4955. }
  4956. }
  4957. if (isAddToPathSet) {
  4958. const paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  4959. paths.push({
  4960. transform: ctx.mozCurrentTransform,
  4961. x,
  4962. y,
  4963. fontSize,
  4964. addToPath
  4965. });
  4966. }
  4967. },
  4968. get isFontSubpixelAAEnabled() {
  4969. const {
  4970. context: ctx
  4971. } = this.cachedCanvases.getCanvas("isFontSubpixelAAEnabled", 10, 10);
  4972. ctx.scale(1.5, 1);
  4973. ctx.fillText("I", 0, 10);
  4974. const data = ctx.getImageData(0, 0, 10, 10).data;
  4975. let enabled = false;
  4976. for (let i = 3; i < data.length; i += 4) {
  4977. if (data[i] > 0 && data[i] < 255) {
  4978. enabled = true;
  4979. break;
  4980. }
  4981. }
  4982. return (0, _util.shadow)(this, "isFontSubpixelAAEnabled", enabled);
  4983. },
  4984. showText: function CanvasGraphics_showText(glyphs) {
  4985. const current = this.current;
  4986. const font = current.font;
  4987. if (font.isType3Font) {
  4988. return this.showType3Text(glyphs);
  4989. }
  4990. const fontSize = current.fontSize;
  4991. if (fontSize === 0) {
  4992. return undefined;
  4993. }
  4994. const ctx = this.ctx;
  4995. const fontSizeScale = current.fontSizeScale;
  4996. const charSpacing = current.charSpacing;
  4997. const wordSpacing = current.wordSpacing;
  4998. const fontDirection = current.fontDirection;
  4999. const textHScale = current.textHScale * fontDirection;
  5000. const glyphsLength = glyphs.length;
  5001. const vertical = font.vertical;
  5002. const spacingDir = vertical ? 1 : -1;
  5003. const defaultVMetrics = font.defaultVMetrics;
  5004. const widthAdvanceScale = fontSize * current.fontMatrix[0];
  5005. const simpleFillText = current.textRenderingMode === _util.TextRenderingMode.FILL && !font.disableFontFace && !current.patternFill;
  5006. ctx.save();
  5007. let patternTransform;
  5008. if (current.patternFill) {
  5009. ctx.save();
  5010. const pattern = current.fillColor.getPattern(ctx, this);
  5011. patternTransform = ctx.mozCurrentTransform;
  5012. ctx.restore();
  5013. ctx.fillStyle = pattern;
  5014. }
  5015. ctx.transform.apply(ctx, current.textMatrix);
  5016. ctx.translate(current.x, current.y + current.textRise);
  5017. if (fontDirection > 0) {
  5018. ctx.scale(textHScale, -1);
  5019. } else {
  5020. ctx.scale(textHScale, 1);
  5021. }
  5022. let lineWidth = current.lineWidth;
  5023. let resetLineWidthToOne = false;
  5024. const scale = current.textMatrixScale;
  5025. if (scale === 0 || lineWidth === 0) {
  5026. const fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  5027. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  5028. this._cachedGetSinglePixelWidth = null;
  5029. lineWidth = this.getSinglePixelWidth();
  5030. resetLineWidthToOne = lineWidth < 0;
  5031. }
  5032. } else {
  5033. lineWidth /= scale;
  5034. }
  5035. if (fontSizeScale !== 1.0) {
  5036. ctx.scale(fontSizeScale, fontSizeScale);
  5037. lineWidth /= fontSizeScale;
  5038. }
  5039. ctx.lineWidth = lineWidth;
  5040. let x = 0,
  5041. i;
  5042. for (i = 0; i < glyphsLength; ++i) {
  5043. const glyph = glyphs[i];
  5044. if ((0, _util.isNum)(glyph)) {
  5045. x += spacingDir * glyph * fontSize / 1000;
  5046. continue;
  5047. }
  5048. let restoreNeeded = false;
  5049. const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  5050. const character = glyph.fontChar;
  5051. const accent = glyph.accent;
  5052. let scaledX, scaledY;
  5053. let width = glyph.width;
  5054. if (vertical) {
  5055. const vmetric = glyph.vmetric || defaultVMetrics;
  5056. const vx = -(glyph.vmetric ? vmetric[1] : width * 0.5) * widthAdvanceScale;
  5057. const vy = vmetric[2] * widthAdvanceScale;
  5058. width = vmetric ? -vmetric[0] : width;
  5059. scaledX = vx / fontSizeScale;
  5060. scaledY = (x + vy) / fontSizeScale;
  5061. } else {
  5062. scaledX = x / fontSizeScale;
  5063. scaledY = 0;
  5064. }
  5065. if (font.remeasure && width > 0) {
  5066. const measuredWidth = ctx.measureText(character).width * 1000 / fontSize * fontSizeScale;
  5067. if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
  5068. const characterScaleX = width / measuredWidth;
  5069. restoreNeeded = true;
  5070. ctx.save();
  5071. ctx.scale(characterScaleX, 1);
  5072. scaledX /= characterScaleX;
  5073. } else if (width !== measuredWidth) {
  5074. scaledX += (width - measuredWidth) / 2000 * fontSize / fontSizeScale;
  5075. }
  5076. }
  5077. if (this.contentVisible && (glyph.isInFont || font.missingFile)) {
  5078. if (simpleFillText && !accent) {
  5079. ctx.fillText(character, scaledX, scaledY);
  5080. } else {
  5081. this.paintChar(character, scaledX, scaledY, patternTransform, resetLineWidthToOne);
  5082. if (accent) {
  5083. const scaledAccentX = scaledX + fontSize * accent.offset.x / fontSizeScale;
  5084. const scaledAccentY = scaledY - fontSize * accent.offset.y / fontSizeScale;
  5085. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY, patternTransform, resetLineWidthToOne);
  5086. }
  5087. }
  5088. }
  5089. let charWidth;
  5090. if (vertical) {
  5091. charWidth = width * widthAdvanceScale - spacing * fontDirection;
  5092. } else {
  5093. charWidth = width * widthAdvanceScale + spacing * fontDirection;
  5094. }
  5095. x += charWidth;
  5096. if (restoreNeeded) {
  5097. ctx.restore();
  5098. }
  5099. }
  5100. if (vertical) {
  5101. current.y -= x;
  5102. } else {
  5103. current.x += x * textHScale;
  5104. }
  5105. ctx.restore();
  5106. },
  5107. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  5108. const ctx = this.ctx;
  5109. const current = this.current;
  5110. const font = current.font;
  5111. const fontSize = current.fontSize;
  5112. const fontDirection = current.fontDirection;
  5113. const spacingDir = font.vertical ? 1 : -1;
  5114. const charSpacing = current.charSpacing;
  5115. const wordSpacing = current.wordSpacing;
  5116. const textHScale = current.textHScale * fontDirection;
  5117. const fontMatrix = current.fontMatrix || _util.FONT_IDENTITY_MATRIX;
  5118. const glyphsLength = glyphs.length;
  5119. const isTextInvisible = current.textRenderingMode === _util.TextRenderingMode.INVISIBLE;
  5120. let i, glyph, width, spacingLength;
  5121. if (isTextInvisible || fontSize === 0) {
  5122. return;
  5123. }
  5124. this._cachedGetSinglePixelWidth = null;
  5125. ctx.save();
  5126. ctx.transform.apply(ctx, current.textMatrix);
  5127. ctx.translate(current.x, current.y);
  5128. ctx.scale(textHScale, fontDirection);
  5129. for (i = 0; i < glyphsLength; ++i) {
  5130. glyph = glyphs[i];
  5131. if ((0, _util.isNum)(glyph)) {
  5132. spacingLength = spacingDir * glyph * fontSize / 1000;
  5133. this.ctx.translate(spacingLength, 0);
  5134. current.x += spacingLength * textHScale;
  5135. continue;
  5136. }
  5137. const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  5138. const operatorList = font.charProcOperatorList[glyph.operatorListId];
  5139. if (!operatorList) {
  5140. (0, _util.warn)(`Type3 character "${glyph.operatorListId}" is not available.`);
  5141. continue;
  5142. }
  5143. if (this.contentVisible) {
  5144. this.processingType3 = glyph;
  5145. this.save();
  5146. ctx.scale(fontSize, fontSize);
  5147. ctx.transform.apply(ctx, fontMatrix);
  5148. this.executeOperatorList(operatorList);
  5149. this.restore();
  5150. }
  5151. const transformed = _util.Util.applyTransform([glyph.width, 0], fontMatrix);
  5152. width = transformed[0] * fontSize + spacing;
  5153. ctx.translate(width, 0);
  5154. current.x += width * textHScale;
  5155. }
  5156. ctx.restore();
  5157. this.processingType3 = null;
  5158. },
  5159. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {},
  5160. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth, yWidth, llx, lly, urx, ury) {
  5161. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  5162. this.clip();
  5163. this.endPath();
  5164. },
  5165. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  5166. let pattern;
  5167. if (IR[0] === "TilingPattern") {
  5168. const color = IR[1];
  5169. const baseTransform = this.baseTransform || this.ctx.mozCurrentTransform.slice();
  5170. const canvasGraphicsFactory = {
  5171. createCanvasGraphics: ctx => {
  5172. return new CanvasGraphics(ctx, this.commonObjs, this.objs, this.canvasFactory, this.webGLContext);
  5173. }
  5174. };
  5175. pattern = new _pattern_helper.TilingPattern(IR, color, this.ctx, canvasGraphicsFactory, baseTransform);
  5176. } else {
  5177. pattern = (0, _pattern_helper.getShadingPatternFromIR)(IR);
  5178. }
  5179. return pattern;
  5180. },
  5181. setStrokeColorN: function CanvasGraphics_setStrokeColorN() {
  5182. this.current.strokeColor = this.getColorN_Pattern(arguments);
  5183. },
  5184. setFillColorN: function CanvasGraphics_setFillColorN() {
  5185. this.current.fillColor = this.getColorN_Pattern(arguments);
  5186. this.current.patternFill = true;
  5187. },
  5188. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  5189. const color = _util.Util.makeHexColor(r, g, b);
  5190. this.ctx.strokeStyle = color;
  5191. this.current.strokeColor = color;
  5192. },
  5193. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  5194. const color = _util.Util.makeHexColor(r, g, b);
  5195. this.ctx.fillStyle = color;
  5196. this.current.fillColor = color;
  5197. this.current.patternFill = false;
  5198. },
  5199. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  5200. if (!this.contentVisible) {
  5201. return;
  5202. }
  5203. const ctx = this.ctx;
  5204. this.save();
  5205. const pattern = (0, _pattern_helper.getShadingPatternFromIR)(patternIR);
  5206. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  5207. const inv = ctx.mozCurrentTransformInverse;
  5208. if (inv) {
  5209. const canvas = ctx.canvas;
  5210. const width = canvas.width;
  5211. const height = canvas.height;
  5212. const bl = _util.Util.applyTransform([0, 0], inv);
  5213. const br = _util.Util.applyTransform([0, height], inv);
  5214. const ul = _util.Util.applyTransform([width, 0], inv);
  5215. const ur = _util.Util.applyTransform([width, height], inv);
  5216. const x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  5217. const y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  5218. const x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  5219. const y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  5220. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  5221. } else {
  5222. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  5223. }
  5224. this.restore();
  5225. },
  5226. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  5227. (0, _util.unreachable)("Should not call beginInlineImage");
  5228. },
  5229. beginImageData: function CanvasGraphics_beginImageData() {
  5230. (0, _util.unreachable)("Should not call beginImageData");
  5231. },
  5232. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix, bbox) {
  5233. if (!this.contentVisible) {
  5234. return;
  5235. }
  5236. this.save();
  5237. this.baseTransformStack.push(this.baseTransform);
  5238. if (Array.isArray(matrix) && matrix.length === 6) {
  5239. this.transform.apply(this, matrix);
  5240. }
  5241. this.baseTransform = this.ctx.mozCurrentTransform;
  5242. if (bbox) {
  5243. const width = bbox[2] - bbox[0];
  5244. const height = bbox[3] - bbox[1];
  5245. this.ctx.rect(bbox[0], bbox[1], width, height);
  5246. this.clip();
  5247. this.endPath();
  5248. }
  5249. },
  5250. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  5251. if (!this.contentVisible) {
  5252. return;
  5253. }
  5254. this.restore();
  5255. this.baseTransform = this.baseTransformStack.pop();
  5256. },
  5257. beginGroup: function CanvasGraphics_beginGroup(group) {
  5258. if (!this.contentVisible) {
  5259. return;
  5260. }
  5261. this.save();
  5262. const currentCtx = this.ctx;
  5263. if (!group.isolated) {
  5264. (0, _util.info)("TODO: Support non-isolated groups.");
  5265. }
  5266. if (group.knockout) {
  5267. (0, _util.warn)("Knockout groups not supported.");
  5268. }
  5269. const currentTransform = currentCtx.mozCurrentTransform;
  5270. if (group.matrix) {
  5271. currentCtx.transform.apply(currentCtx, group.matrix);
  5272. }
  5273. if (!group.bbox) {
  5274. throw new Error("Bounding box is required.");
  5275. }
  5276. let bounds = _util.Util.getAxialAlignedBoundingBox(group.bbox, currentCtx.mozCurrentTransform);
  5277. const canvasBounds = [0, 0, currentCtx.canvas.width, currentCtx.canvas.height];
  5278. bounds = _util.Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  5279. const offsetX = Math.floor(bounds[0]);
  5280. const offsetY = Math.floor(bounds[1]);
  5281. let drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  5282. let drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  5283. let scaleX = 1,
  5284. scaleY = 1;
  5285. if (drawnWidth > MAX_GROUP_SIZE) {
  5286. scaleX = drawnWidth / MAX_GROUP_SIZE;
  5287. drawnWidth = MAX_GROUP_SIZE;
  5288. }
  5289. if (drawnHeight > MAX_GROUP_SIZE) {
  5290. scaleY = drawnHeight / MAX_GROUP_SIZE;
  5291. drawnHeight = MAX_GROUP_SIZE;
  5292. }
  5293. let cacheId = "groupAt" + this.groupLevel;
  5294. if (group.smask) {
  5295. cacheId += "_smask_" + this.smaskCounter++ % 2;
  5296. }
  5297. const scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true);
  5298. const groupCtx = scratchCanvas.context;
  5299. groupCtx.scale(1 / scaleX, 1 / scaleY);
  5300. groupCtx.translate(-offsetX, -offsetY);
  5301. groupCtx.transform.apply(groupCtx, currentTransform);
  5302. if (group.smask) {
  5303. this.smaskStack.push({
  5304. canvas: scratchCanvas.canvas,
  5305. context: groupCtx,
  5306. offsetX,
  5307. offsetY,
  5308. scaleX,
  5309. scaleY,
  5310. subtype: group.smask.subtype,
  5311. backdrop: group.smask.backdrop,
  5312. transferMap: group.smask.transferMap || null,
  5313. startTransformInverse: null
  5314. });
  5315. } else {
  5316. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  5317. currentCtx.translate(offsetX, offsetY);
  5318. currentCtx.scale(scaleX, scaleY);
  5319. }
  5320. copyCtxState(currentCtx, groupCtx);
  5321. this.ctx = groupCtx;
  5322. this.setGState([["BM", "source-over"], ["ca", 1], ["CA", 1]]);
  5323. this.groupStack.push(currentCtx);
  5324. this.groupLevel++;
  5325. this.current.activeSMask = null;
  5326. },
  5327. endGroup: function CanvasGraphics_endGroup(group) {
  5328. if (!this.contentVisible) {
  5329. return;
  5330. }
  5331. this.groupLevel--;
  5332. const groupCtx = this.ctx;
  5333. this.ctx = this.groupStack.pop();
  5334. if (this.ctx.imageSmoothingEnabled !== undefined) {
  5335. this.ctx.imageSmoothingEnabled = false;
  5336. } else {
  5337. this.ctx.mozImageSmoothingEnabled = false;
  5338. }
  5339. if (group.smask) {
  5340. this.tempSMask = this.smaskStack.pop();
  5341. } else {
  5342. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  5343. }
  5344. this.restore();
  5345. },
  5346. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  5347. this.save();
  5348. if (this.baseTransform) {
  5349. this.ctx.setTransform.apply(this.ctx, this.baseTransform);
  5350. }
  5351. },
  5352. endAnnotations: function CanvasGraphics_endAnnotations() {
  5353. this.restore();
  5354. },
  5355. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform, matrix) {
  5356. this.save();
  5357. resetCtxToDefault(this.ctx);
  5358. this.current = new CanvasExtraState();
  5359. if (Array.isArray(rect) && rect.length === 4) {
  5360. const width = rect[2] - rect[0];
  5361. const height = rect[3] - rect[1];
  5362. this.ctx.rect(rect[0], rect[1], width, height);
  5363. this.clip();
  5364. this.endPath();
  5365. }
  5366. this.transform.apply(this, transform);
  5367. this.transform.apply(this, matrix);
  5368. },
  5369. endAnnotation: function CanvasGraphics_endAnnotation() {
  5370. this.restore();
  5371. },
  5372. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  5373. if (!this.contentVisible) {
  5374. return;
  5375. }
  5376. const ctx = this.ctx;
  5377. const width = img.width,
  5378. height = img.height;
  5379. const fillColor = this.current.fillColor;
  5380. const isPatternFill = this.current.patternFill;
  5381. const glyph = this.processingType3;
  5382. if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
  5383. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  5384. glyph.compiled = compileType3Glyph({
  5385. data: img.data,
  5386. width,
  5387. height
  5388. });
  5389. } else {
  5390. glyph.compiled = null;
  5391. }
  5392. }
  5393. if (glyph?.compiled) {
  5394. glyph.compiled(ctx);
  5395. return;
  5396. }
  5397. const maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
  5398. const maskCtx = maskCanvas.context;
  5399. maskCtx.save();
  5400. putBinaryImageMask(maskCtx, img);
  5401. maskCtx.globalCompositeOperation = "source-in";
  5402. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor;
  5403. maskCtx.fillRect(0, 0, width, height);
  5404. maskCtx.restore();
  5405. this.paintInlineImageXObject(maskCanvas.canvas);
  5406. },
  5407. paintImageMaskXObjectRepeat(imgData, scaleX, skewX = 0, skewY = 0, scaleY, positions) {
  5408. if (!this.contentVisible) {
  5409. return;
  5410. }
  5411. const width = imgData.width;
  5412. const height = imgData.height;
  5413. const fillColor = this.current.fillColor;
  5414. const isPatternFill = this.current.patternFill;
  5415. const maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
  5416. const maskCtx = maskCanvas.context;
  5417. maskCtx.save();
  5418. putBinaryImageMask(maskCtx, imgData);
  5419. maskCtx.globalCompositeOperation = "source-in";
  5420. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor;
  5421. maskCtx.fillRect(0, 0, width, height);
  5422. maskCtx.restore();
  5423. const ctx = this.ctx;
  5424. for (let i = 0, ii = positions.length; i < ii; i += 2) {
  5425. ctx.save();
  5426. ctx.transform(scaleX, skewX, skewY, scaleY, positions[i], positions[i + 1]);
  5427. ctx.scale(1, -1);
  5428. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1);
  5429. ctx.restore();
  5430. }
  5431. },
  5432. paintImageMaskXObjectGroup: function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  5433. if (!this.contentVisible) {
  5434. return;
  5435. }
  5436. const ctx = this.ctx;
  5437. const fillColor = this.current.fillColor;
  5438. const isPatternFill = this.current.patternFill;
  5439. for (let i = 0, ii = images.length; i < ii; i++) {
  5440. const image = images[i];
  5441. const width = image.width,
  5442. height = image.height;
  5443. const maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
  5444. const maskCtx = maskCanvas.context;
  5445. maskCtx.save();
  5446. putBinaryImageMask(maskCtx, image);
  5447. maskCtx.globalCompositeOperation = "source-in";
  5448. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor;
  5449. maskCtx.fillRect(0, 0, width, height);
  5450. maskCtx.restore();
  5451. ctx.save();
  5452. ctx.transform.apply(ctx, image.transform);
  5453. ctx.scale(1, -1);
  5454. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1);
  5455. ctx.restore();
  5456. }
  5457. },
  5458. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  5459. if (!this.contentVisible) {
  5460. return;
  5461. }
  5462. const imgData = objId.startsWith("g_") ? this.commonObjs.get(objId) : this.objs.get(objId);
  5463. if (!imgData) {
  5464. (0, _util.warn)("Dependent image isn't ready yet");
  5465. return;
  5466. }
  5467. this.paintInlineImageXObject(imgData);
  5468. },
  5469. paintImageXObjectRepeat: function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY, positions) {
  5470. if (!this.contentVisible) {
  5471. return;
  5472. }
  5473. const imgData = objId.startsWith("g_") ? this.commonObjs.get(objId) : this.objs.get(objId);
  5474. if (!imgData) {
  5475. (0, _util.warn)("Dependent image isn't ready yet");
  5476. return;
  5477. }
  5478. const width = imgData.width;
  5479. const height = imgData.height;
  5480. const map = [];
  5481. for (let i = 0, ii = positions.length; i < ii; i += 2) {
  5482. map.push({
  5483. transform: [scaleX, 0, 0, scaleY, positions[i], positions[i + 1]],
  5484. x: 0,
  5485. y: 0,
  5486. w: width,
  5487. h: height
  5488. });
  5489. }
  5490. this.paintInlineImageXObjectGroup(imgData, map);
  5491. },
  5492. paintInlineImageXObject: function CanvasGraphics_paintInlineImageXObject(imgData) {
  5493. if (!this.contentVisible) {
  5494. return;
  5495. }
  5496. const width = imgData.width;
  5497. const height = imgData.height;
  5498. const ctx = this.ctx;
  5499. this.save();
  5500. ctx.scale(1 / width, -1 / height);
  5501. const currentTransform = ctx.mozCurrentTransformInverse;
  5502. const a = currentTransform[0],
  5503. b = currentTransform[1];
  5504. let widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  5505. const c = currentTransform[2],
  5506. d = currentTransform[3];
  5507. let heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  5508. let imgToPaint, tmpCanvas, tmpCtx;
  5509. if (typeof HTMLElement === "function" && imgData instanceof HTMLElement || !imgData.data) {
  5510. imgToPaint = imgData;
  5511. } else {
  5512. tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", width, height);
  5513. tmpCtx = tmpCanvas.context;
  5514. putBinaryImageData(tmpCtx, imgData, this.current.transferMaps);
  5515. imgToPaint = tmpCanvas.canvas;
  5516. }
  5517. let paintWidth = width,
  5518. paintHeight = height;
  5519. let tmpCanvasId = "prescale1";
  5520. while (widthScale > 2 && paintWidth > 1 || heightScale > 2 && paintHeight > 1) {
  5521. let newWidth = paintWidth,
  5522. newHeight = paintHeight;
  5523. if (widthScale > 2 && paintWidth > 1) {
  5524. newWidth = Math.ceil(paintWidth / 2);
  5525. widthScale /= paintWidth / newWidth;
  5526. }
  5527. if (heightScale > 2 && paintHeight > 1) {
  5528. newHeight = Math.ceil(paintHeight / 2);
  5529. heightScale /= paintHeight / newHeight;
  5530. }
  5531. tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
  5532. tmpCtx = tmpCanvas.context;
  5533. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  5534. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, 0, 0, newWidth, newHeight);
  5535. imgToPaint = tmpCanvas.canvas;
  5536. paintWidth = newWidth;
  5537. paintHeight = newHeight;
  5538. tmpCanvasId = tmpCanvasId === "prescale1" ? "prescale2" : "prescale1";
  5539. }
  5540. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, 0, -height, width, height);
  5541. if (this.imageLayer) {
  5542. const position = this.getCanvasPosition(0, -height);
  5543. this.imageLayer.appendImage({
  5544. imgData,
  5545. left: position[0],
  5546. top: position[1],
  5547. width: width / currentTransform[0],
  5548. height: height / currentTransform[3]
  5549. });
  5550. }
  5551. this.restore();
  5552. },
  5553. paintInlineImageXObjectGroup: function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  5554. if (!this.contentVisible) {
  5555. return;
  5556. }
  5557. const ctx = this.ctx;
  5558. const w = imgData.width;
  5559. const h = imgData.height;
  5560. const tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", w, h);
  5561. const tmpCtx = tmpCanvas.context;
  5562. putBinaryImageData(tmpCtx, imgData, this.current.transferMaps);
  5563. for (let i = 0, ii = map.length; i < ii; i++) {
  5564. const entry = map[i];
  5565. ctx.save();
  5566. ctx.transform.apply(ctx, entry.transform);
  5567. ctx.scale(1, -1);
  5568. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h, 0, -1, 1, 1);
  5569. if (this.imageLayer) {
  5570. const position = this.getCanvasPosition(entry.x, entry.y);
  5571. this.imageLayer.appendImage({
  5572. imgData,
  5573. left: position[0],
  5574. top: position[1],
  5575. width: w,
  5576. height: h
  5577. });
  5578. }
  5579. ctx.restore();
  5580. }
  5581. },
  5582. paintSolidColorImageMask: function CanvasGraphics_paintSolidColorImageMask() {
  5583. if (!this.contentVisible) {
  5584. return;
  5585. }
  5586. this.ctx.fillRect(0, 0, 1, 1);
  5587. },
  5588. markPoint: function CanvasGraphics_markPoint(tag) {},
  5589. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {},
  5590. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  5591. this.markedContentStack.push({
  5592. visible: true
  5593. });
  5594. },
  5595. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(tag, properties) {
  5596. if (tag === "OC") {
  5597. this.markedContentStack.push({
  5598. visible: this.optionalContentConfig.isVisible(properties)
  5599. });
  5600. } else {
  5601. this.markedContentStack.push({
  5602. visible: true
  5603. });
  5604. }
  5605. this.contentVisible = this.isContentVisible();
  5606. },
  5607. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  5608. this.markedContentStack.pop();
  5609. this.contentVisible = this.isContentVisible();
  5610. },
  5611. beginCompat: function CanvasGraphics_beginCompat() {},
  5612. endCompat: function CanvasGraphics_endCompat() {},
  5613. consumePath: function CanvasGraphics_consumePath() {
  5614. const ctx = this.ctx;
  5615. if (this.pendingClip) {
  5616. if (this.pendingClip === EO_CLIP) {
  5617. ctx.clip("evenodd");
  5618. } else {
  5619. ctx.clip();
  5620. }
  5621. this.pendingClip = null;
  5622. }
  5623. ctx.beginPath();
  5624. },
  5625. getSinglePixelWidth() {
  5626. if (this._cachedGetSinglePixelWidth === null) {
  5627. const m = this.ctx.mozCurrentTransform;
  5628. const absDet = Math.abs(m[0] * m[3] - m[2] * m[1]);
  5629. const sqNorm1 = m[0] ** 2 + m[2] ** 2;
  5630. const sqNorm2 = m[1] ** 2 + m[3] ** 2;
  5631. const pixelHeight = Math.sqrt(Math.max(sqNorm1, sqNorm2)) / absDet;
  5632. if (sqNorm1 !== sqNorm2 && this._combinedScaleFactor * pixelHeight > 1) {
  5633. this._cachedGetSinglePixelWidth = -(this._combinedScaleFactor * pixelHeight);
  5634. } else if (absDet > Number.EPSILON) {
  5635. this._cachedGetSinglePixelWidth = pixelHeight * 1.0000001;
  5636. } else {
  5637. this._cachedGetSinglePixelWidth = 1;
  5638. }
  5639. }
  5640. return this._cachedGetSinglePixelWidth;
  5641. },
  5642. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  5643. const transform = this.ctx.mozCurrentTransform;
  5644. return [transform[0] * x + transform[2] * y + transform[4], transform[1] * x + transform[3] * y + transform[5]];
  5645. },
  5646. isContentVisible: function CanvasGraphics_isContentVisible() {
  5647. for (let i = this.markedContentStack.length - 1; i >= 0; i--) {
  5648. if (!this.markedContentStack[i].visible) {
  5649. return false;
  5650. }
  5651. }
  5652. return true;
  5653. }
  5654. };
  5655. for (const op in _util.OPS) {
  5656. CanvasGraphics.prototype[_util.OPS[op]] = CanvasGraphics.prototype[op];
  5657. }
  5658. return CanvasGraphics;
  5659. }();
  5660. exports.CanvasGraphics = CanvasGraphics;
  5661. /***/ }),
  5662. /* 11 */
  5663. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  5664. Object.defineProperty(exports, "__esModule", ({
  5665. value: true
  5666. }));
  5667. exports.getShadingPatternFromIR = getShadingPatternFromIR;
  5668. exports.TilingPattern = void 0;
  5669. var _util = __w_pdfjs_require__(2);
  5670. const ShadingIRs = {};
  5671. function applyBoundingBox(ctx, bbox) {
  5672. if (!bbox || typeof Path2D === "undefined") {
  5673. return;
  5674. }
  5675. const width = bbox[2] - bbox[0];
  5676. const height = bbox[3] - bbox[1];
  5677. const region = new Path2D();
  5678. region.rect(bbox[0], bbox[1], width, height);
  5679. ctx.clip(region);
  5680. }
  5681. ShadingIRs.RadialAxial = {
  5682. fromIR: function RadialAxial_fromIR(raw) {
  5683. const type = raw[1];
  5684. const bbox = raw[2];
  5685. const colorStops = raw[3];
  5686. const p0 = raw[4];
  5687. const p1 = raw[5];
  5688. const r0 = raw[6];
  5689. const r1 = raw[7];
  5690. return {
  5691. getPattern: function RadialAxial_getPattern(ctx) {
  5692. applyBoundingBox(ctx, bbox);
  5693. let grad;
  5694. if (type === "axial") {
  5695. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  5696. } else if (type === "radial") {
  5697. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  5698. }
  5699. for (let i = 0, ii = colorStops.length; i < ii; ++i) {
  5700. const c = colorStops[i];
  5701. grad.addColorStop(c[0], c[1]);
  5702. }
  5703. return grad;
  5704. }
  5705. };
  5706. }
  5707. };
  5708. const createMeshCanvas = function createMeshCanvasClosure() {
  5709. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  5710. const coords = context.coords,
  5711. colors = context.colors;
  5712. const bytes = data.data,
  5713. rowSize = data.width * 4;
  5714. let tmp;
  5715. if (coords[p1 + 1] > coords[p2 + 1]) {
  5716. tmp = p1;
  5717. p1 = p2;
  5718. p2 = tmp;
  5719. tmp = c1;
  5720. c1 = c2;
  5721. c2 = tmp;
  5722. }
  5723. if (coords[p2 + 1] > coords[p3 + 1]) {
  5724. tmp = p2;
  5725. p2 = p3;
  5726. p3 = tmp;
  5727. tmp = c2;
  5728. c2 = c3;
  5729. c3 = tmp;
  5730. }
  5731. if (coords[p1 + 1] > coords[p2 + 1]) {
  5732. tmp = p1;
  5733. p1 = p2;
  5734. p2 = tmp;
  5735. tmp = c1;
  5736. c1 = c2;
  5737. c2 = tmp;
  5738. }
  5739. const x1 = (coords[p1] + context.offsetX) * context.scaleX;
  5740. const y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  5741. const x2 = (coords[p2] + context.offsetX) * context.scaleX;
  5742. const y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  5743. const x3 = (coords[p3] + context.offsetX) * context.scaleX;
  5744. const y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  5745. if (y1 >= y3) {
  5746. return;
  5747. }
  5748. const c1r = colors[c1],
  5749. c1g = colors[c1 + 1],
  5750. c1b = colors[c1 + 2];
  5751. const c2r = colors[c2],
  5752. c2g = colors[c2 + 1],
  5753. c2b = colors[c2 + 2];
  5754. const c3r = colors[c3],
  5755. c3g = colors[c3 + 1],
  5756. c3b = colors[c3 + 2];
  5757. const minY = Math.round(y1),
  5758. maxY = Math.round(y3);
  5759. let xa, car, cag, cab;
  5760. let xb, cbr, cbg, cbb;
  5761. for (let y = minY; y <= maxY; y++) {
  5762. if (y < y2) {
  5763. let k;
  5764. if (y < y1) {
  5765. k = 0;
  5766. } else if (y1 === y2) {
  5767. k = 1;
  5768. } else {
  5769. k = (y1 - y) / (y1 - y2);
  5770. }
  5771. xa = x1 - (x1 - x2) * k;
  5772. car = c1r - (c1r - c2r) * k;
  5773. cag = c1g - (c1g - c2g) * k;
  5774. cab = c1b - (c1b - c2b) * k;
  5775. } else {
  5776. let k;
  5777. if (y > y3) {
  5778. k = 1;
  5779. } else if (y2 === y3) {
  5780. k = 0;
  5781. } else {
  5782. k = (y2 - y) / (y2 - y3);
  5783. }
  5784. xa = x2 - (x2 - x3) * k;
  5785. car = c2r - (c2r - c3r) * k;
  5786. cag = c2g - (c2g - c3g) * k;
  5787. cab = c2b - (c2b - c3b) * k;
  5788. }
  5789. let k;
  5790. if (y < y1) {
  5791. k = 0;
  5792. } else if (y > y3) {
  5793. k = 1;
  5794. } else {
  5795. k = (y1 - y) / (y1 - y3);
  5796. }
  5797. xb = x1 - (x1 - x3) * k;
  5798. cbr = c1r - (c1r - c3r) * k;
  5799. cbg = c1g - (c1g - c3g) * k;
  5800. cbb = c1b - (c1b - c3b) * k;
  5801. const x1_ = Math.round(Math.min(xa, xb));
  5802. const x2_ = Math.round(Math.max(xa, xb));
  5803. let j = rowSize * y + x1_ * 4;
  5804. for (let x = x1_; x <= x2_; x++) {
  5805. k = (xa - x) / (xa - xb);
  5806. if (k < 0) {
  5807. k = 0;
  5808. } else if (k > 1) {
  5809. k = 1;
  5810. }
  5811. bytes[j++] = car - (car - cbr) * k | 0;
  5812. bytes[j++] = cag - (cag - cbg) * k | 0;
  5813. bytes[j++] = cab - (cab - cbb) * k | 0;
  5814. bytes[j++] = 255;
  5815. }
  5816. }
  5817. }
  5818. function drawFigure(data, figure, context) {
  5819. const ps = figure.coords;
  5820. const cs = figure.colors;
  5821. let i, ii;
  5822. switch (figure.type) {
  5823. case "lattice":
  5824. const verticesPerRow = figure.verticesPerRow;
  5825. const rows = Math.floor(ps.length / verticesPerRow) - 1;
  5826. const cols = verticesPerRow - 1;
  5827. for (i = 0; i < rows; i++) {
  5828. let q = i * verticesPerRow;
  5829. for (let j = 0; j < cols; j++, q++) {
  5830. drawTriangle(data, context, ps[q], ps[q + 1], ps[q + verticesPerRow], cs[q], cs[q + 1], cs[q + verticesPerRow]);
  5831. drawTriangle(data, context, ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow], cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  5832. }
  5833. }
  5834. break;
  5835. case "triangles":
  5836. for (i = 0, ii = ps.length; i < ii; i += 3) {
  5837. drawTriangle(data, context, ps[i], ps[i + 1], ps[i + 2], cs[i], cs[i + 1], cs[i + 2]);
  5838. }
  5839. break;
  5840. default:
  5841. throw new Error("illegal figure");
  5842. }
  5843. }
  5844. function createMeshCanvas(bounds, combinesScale, coords, colors, figures, backgroundColor, cachedCanvases, webGLContext) {
  5845. const EXPECTED_SCALE = 1.1;
  5846. const MAX_PATTERN_SIZE = 3000;
  5847. const BORDER_SIZE = 2;
  5848. const offsetX = Math.floor(bounds[0]);
  5849. const offsetY = Math.floor(bounds[1]);
  5850. const boundsWidth = Math.ceil(bounds[2]) - offsetX;
  5851. const boundsHeight = Math.ceil(bounds[3]) - offsetY;
  5852. const width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5853. const height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5854. const scaleX = boundsWidth / width;
  5855. const scaleY = boundsHeight / height;
  5856. const context = {
  5857. coords,
  5858. colors,
  5859. offsetX: -offsetX,
  5860. offsetY: -offsetY,
  5861. scaleX: 1 / scaleX,
  5862. scaleY: 1 / scaleY
  5863. };
  5864. const paddedWidth = width + BORDER_SIZE * 2;
  5865. const paddedHeight = height + BORDER_SIZE * 2;
  5866. let canvas, tmpCanvas, i, ii;
  5867. if (webGLContext.isEnabled) {
  5868. canvas = webGLContext.drawFigures({
  5869. width,
  5870. height,
  5871. backgroundColor,
  5872. figures,
  5873. context
  5874. });
  5875. tmpCanvas = cachedCanvases.getCanvas("mesh", paddedWidth, paddedHeight, false);
  5876. tmpCanvas.context.drawImage(canvas, BORDER_SIZE, BORDER_SIZE);
  5877. canvas = tmpCanvas.canvas;
  5878. } else {
  5879. tmpCanvas = cachedCanvases.getCanvas("mesh", paddedWidth, paddedHeight, false);
  5880. const tmpCtx = tmpCanvas.context;
  5881. const data = tmpCtx.createImageData(width, height);
  5882. if (backgroundColor) {
  5883. const bytes = data.data;
  5884. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  5885. bytes[i] = backgroundColor[0];
  5886. bytes[i + 1] = backgroundColor[1];
  5887. bytes[i + 2] = backgroundColor[2];
  5888. bytes[i + 3] = 255;
  5889. }
  5890. }
  5891. for (i = 0; i < figures.length; i++) {
  5892. drawFigure(data, figures[i], context);
  5893. }
  5894. tmpCtx.putImageData(data, BORDER_SIZE, BORDER_SIZE);
  5895. canvas = tmpCanvas.canvas;
  5896. }
  5897. return {
  5898. canvas,
  5899. offsetX: offsetX - BORDER_SIZE * scaleX,
  5900. offsetY: offsetY - BORDER_SIZE * scaleY,
  5901. scaleX,
  5902. scaleY
  5903. };
  5904. }
  5905. return createMeshCanvas;
  5906. }();
  5907. ShadingIRs.Mesh = {
  5908. fromIR: function Mesh_fromIR(raw) {
  5909. const coords = raw[2];
  5910. const colors = raw[3];
  5911. const figures = raw[4];
  5912. const bounds = raw[5];
  5913. const matrix = raw[6];
  5914. const bbox = raw[7];
  5915. const background = raw[8];
  5916. return {
  5917. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  5918. applyBoundingBox(ctx, bbox);
  5919. let scale;
  5920. if (shadingFill) {
  5921. scale = _util.Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  5922. } else {
  5923. scale = _util.Util.singularValueDecompose2dScale(owner.baseTransform);
  5924. if (matrix) {
  5925. const matrixScale = _util.Util.singularValueDecompose2dScale(matrix);
  5926. scale = [scale[0] * matrixScale[0], scale[1] * matrixScale[1]];
  5927. }
  5928. }
  5929. const temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords, colors, figures, shadingFill ? null : background, owner.cachedCanvases, owner.webGLContext);
  5930. if (!shadingFill) {
  5931. ctx.setTransform.apply(ctx, owner.baseTransform);
  5932. if (matrix) {
  5933. ctx.transform.apply(ctx, matrix);
  5934. }
  5935. }
  5936. ctx.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY);
  5937. ctx.scale(temporaryPatternCanvas.scaleX, temporaryPatternCanvas.scaleY);
  5938. return ctx.createPattern(temporaryPatternCanvas.canvas, "no-repeat");
  5939. }
  5940. };
  5941. }
  5942. };
  5943. ShadingIRs.Dummy = {
  5944. fromIR: function Dummy_fromIR() {
  5945. return {
  5946. getPattern: function Dummy_fromIR_getPattern() {
  5947. return "hotpink";
  5948. }
  5949. };
  5950. }
  5951. };
  5952. function getShadingPatternFromIR(raw) {
  5953. const shadingIR = ShadingIRs[raw[0]];
  5954. if (!shadingIR) {
  5955. throw new Error(`Unknown IR type: ${raw[0]}`);
  5956. }
  5957. return shadingIR.fromIR(raw);
  5958. }
  5959. const TilingPattern = function TilingPatternClosure() {
  5960. const PaintType = {
  5961. COLORED: 1,
  5962. UNCOLORED: 2
  5963. };
  5964. const MAX_PATTERN_SIZE = 3000;
  5965. function TilingPattern(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
  5966. this.operatorList = IR[2];
  5967. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  5968. this.bbox = IR[4];
  5969. this.xstep = IR[5];
  5970. this.ystep = IR[6];
  5971. this.paintType = IR[7];
  5972. this.tilingType = IR[8];
  5973. this.color = color;
  5974. this.canvasGraphicsFactory = canvasGraphicsFactory;
  5975. this.baseTransform = baseTransform;
  5976. this.ctx = ctx;
  5977. }
  5978. TilingPattern.prototype = {
  5979. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  5980. const operatorList = this.operatorList;
  5981. const bbox = this.bbox;
  5982. const xstep = this.xstep;
  5983. const ystep = this.ystep;
  5984. const paintType = this.paintType;
  5985. const tilingType = this.tilingType;
  5986. const color = this.color;
  5987. const canvasGraphicsFactory = this.canvasGraphicsFactory;
  5988. (0, _util.info)("TilingType: " + tilingType);
  5989. const x0 = bbox[0],
  5990. y0 = bbox[1],
  5991. x1 = bbox[2],
  5992. y1 = bbox[3];
  5993. const matrixScale = _util.Util.singularValueDecompose2dScale(this.matrix);
  5994. const curMatrixScale = _util.Util.singularValueDecompose2dScale(this.baseTransform);
  5995. const combinedScale = [matrixScale[0] * curMatrixScale[0], matrixScale[1] * curMatrixScale[1]];
  5996. const dimx = this.getSizeAndScale(xstep, this.ctx.canvas.width, combinedScale[0]);
  5997. const dimy = this.getSizeAndScale(ystep, this.ctx.canvas.height, combinedScale[1]);
  5998. const tmpCanvas = owner.cachedCanvases.getCanvas("pattern", dimx.size, dimy.size, true);
  5999. const tmpCtx = tmpCanvas.context;
  6000. const graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
  6001. graphics.groupLevel = owner.groupLevel;
  6002. this.setFillAndStrokeStyleToContext(graphics, paintType, color);
  6003. graphics.transform(dimx.scale, 0, 0, dimy.scale, 0, 0);
  6004. graphics.transform(1, 0, 0, 1, -x0, -y0);
  6005. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  6006. graphics.executeOperatorList(operatorList);
  6007. this.ctx.transform(1, 0, 0, 1, x0, y0);
  6008. this.ctx.scale(1 / dimx.scale, 1 / dimy.scale);
  6009. return tmpCanvas.canvas;
  6010. },
  6011. getSizeAndScale: function TilingPattern_getSizeAndScale(step, realOutputSize, scale) {
  6012. step = Math.abs(step);
  6013. const maxSize = Math.max(MAX_PATTERN_SIZE, realOutputSize);
  6014. let size = Math.ceil(step * scale);
  6015. if (size >= maxSize) {
  6016. size = maxSize;
  6017. } else {
  6018. scale = size / step;
  6019. }
  6020. return {
  6021. scale,
  6022. size
  6023. };
  6024. },
  6025. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  6026. if (Array.isArray(bbox) && bbox.length === 4) {
  6027. const bboxWidth = x1 - x0;
  6028. const bboxHeight = y1 - y0;
  6029. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  6030. graphics.clip();
  6031. graphics.endPath();
  6032. }
  6033. },
  6034. setFillAndStrokeStyleToContext: function setFillAndStrokeStyleToContext(graphics, paintType, color) {
  6035. const context = graphics.ctx,
  6036. current = graphics.current;
  6037. switch (paintType) {
  6038. case PaintType.COLORED:
  6039. const ctx = this.ctx;
  6040. context.fillStyle = ctx.fillStyle;
  6041. context.strokeStyle = ctx.strokeStyle;
  6042. current.fillColor = ctx.fillStyle;
  6043. current.strokeColor = ctx.strokeStyle;
  6044. break;
  6045. case PaintType.UNCOLORED:
  6046. const cssColor = _util.Util.makeHexColor(color[0], color[1], color[2]);
  6047. context.fillStyle = cssColor;
  6048. context.strokeStyle = cssColor;
  6049. current.fillColor = cssColor;
  6050. current.strokeColor = cssColor;
  6051. break;
  6052. default:
  6053. throw new _util.FormatError(`Unsupported paint type: ${paintType}`);
  6054. }
  6055. },
  6056. getPattern: function TilingPattern_getPattern(ctx, owner) {
  6057. ctx = this.ctx;
  6058. ctx.setTransform.apply(ctx, this.baseTransform);
  6059. ctx.transform.apply(ctx, this.matrix);
  6060. const temporaryPatternCanvas = this.createPatternCanvas(owner);
  6061. return ctx.createPattern(temporaryPatternCanvas, "repeat");
  6062. }
  6063. };
  6064. return TilingPattern;
  6065. }();
  6066. exports.TilingPattern = TilingPattern;
  6067. /***/ }),
  6068. /* 12 */
  6069. /***/ ((__unused_webpack_module, exports) => {
  6070. Object.defineProperty(exports, "__esModule", ({
  6071. value: true
  6072. }));
  6073. exports.GlobalWorkerOptions = void 0;
  6074. const GlobalWorkerOptions = Object.create(null);
  6075. exports.GlobalWorkerOptions = GlobalWorkerOptions;
  6076. GlobalWorkerOptions.workerPort = GlobalWorkerOptions.workerPort === undefined ? null : GlobalWorkerOptions.workerPort;
  6077. GlobalWorkerOptions.workerSrc = GlobalWorkerOptions.workerSrc === undefined ? "" : GlobalWorkerOptions.workerSrc;
  6078. /***/ }),
  6079. /* 13 */
  6080. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  6081. Object.defineProperty(exports, "__esModule", ({
  6082. value: true
  6083. }));
  6084. exports.MessageHandler = void 0;
  6085. var _util = __w_pdfjs_require__(2);
  6086. const CallbackKind = {
  6087. UNKNOWN: 0,
  6088. DATA: 1,
  6089. ERROR: 2
  6090. };
  6091. const StreamKind = {
  6092. UNKNOWN: 0,
  6093. CANCEL: 1,
  6094. CANCEL_COMPLETE: 2,
  6095. CLOSE: 3,
  6096. ENQUEUE: 4,
  6097. ERROR: 5,
  6098. PULL: 6,
  6099. PULL_COMPLETE: 7,
  6100. START_COMPLETE: 8
  6101. };
  6102. function wrapReason(reason) {
  6103. if (typeof reason !== "object" || reason === null) {
  6104. return reason;
  6105. }
  6106. switch (reason.name) {
  6107. case "AbortException":
  6108. return new _util.AbortException(reason.message);
  6109. case "MissingPDFException":
  6110. return new _util.MissingPDFException(reason.message);
  6111. case "UnexpectedResponseException":
  6112. return new _util.UnexpectedResponseException(reason.message, reason.status);
  6113. case "UnknownErrorException":
  6114. return new _util.UnknownErrorException(reason.message, reason.details);
  6115. default:
  6116. return new _util.UnknownErrorException(reason.message, reason.toString());
  6117. }
  6118. }
  6119. class MessageHandler {
  6120. constructor(sourceName, targetName, comObj) {
  6121. this.sourceName = sourceName;
  6122. this.targetName = targetName;
  6123. this.comObj = comObj;
  6124. this.callbackId = 1;
  6125. this.streamId = 1;
  6126. this.postMessageTransfers = true;
  6127. this.streamSinks = Object.create(null);
  6128. this.streamControllers = Object.create(null);
  6129. this.callbackCapabilities = Object.create(null);
  6130. this.actionHandler = Object.create(null);
  6131. this._onComObjOnMessage = event => {
  6132. const data = event.data;
  6133. if (data.targetName !== this.sourceName) {
  6134. return;
  6135. }
  6136. if (data.stream) {
  6137. this._processStreamMessage(data);
  6138. return;
  6139. }
  6140. if (data.callback) {
  6141. const callbackId = data.callbackId;
  6142. const capability = this.callbackCapabilities[callbackId];
  6143. if (!capability) {
  6144. throw new Error(`Cannot resolve callback ${callbackId}`);
  6145. }
  6146. delete this.callbackCapabilities[callbackId];
  6147. if (data.callback === CallbackKind.DATA) {
  6148. capability.resolve(data.data);
  6149. } else if (data.callback === CallbackKind.ERROR) {
  6150. capability.reject(wrapReason(data.reason));
  6151. } else {
  6152. throw new Error("Unexpected callback case");
  6153. }
  6154. return;
  6155. }
  6156. const action = this.actionHandler[data.action];
  6157. if (!action) {
  6158. throw new Error(`Unknown action from worker: ${data.action}`);
  6159. }
  6160. if (data.callbackId) {
  6161. const cbSourceName = this.sourceName;
  6162. const cbTargetName = data.sourceName;
  6163. new Promise(function (resolve) {
  6164. resolve(action(data.data));
  6165. }).then(function (result) {
  6166. comObj.postMessage({
  6167. sourceName: cbSourceName,
  6168. targetName: cbTargetName,
  6169. callback: CallbackKind.DATA,
  6170. callbackId: data.callbackId,
  6171. data: result
  6172. });
  6173. }, function (reason) {
  6174. comObj.postMessage({
  6175. sourceName: cbSourceName,
  6176. targetName: cbTargetName,
  6177. callback: CallbackKind.ERROR,
  6178. callbackId: data.callbackId,
  6179. reason: wrapReason(reason)
  6180. });
  6181. });
  6182. return;
  6183. }
  6184. if (data.streamId) {
  6185. this._createStreamSink(data);
  6186. return;
  6187. }
  6188. action(data.data);
  6189. };
  6190. comObj.addEventListener("message", this._onComObjOnMessage);
  6191. }
  6192. on(actionName, handler) {
  6193. const ah = this.actionHandler;
  6194. if (ah[actionName]) {
  6195. throw new Error(`There is already an actionName called "${actionName}"`);
  6196. }
  6197. ah[actionName] = handler;
  6198. }
  6199. send(actionName, data, transfers) {
  6200. this._postMessage({
  6201. sourceName: this.sourceName,
  6202. targetName: this.targetName,
  6203. action: actionName,
  6204. data
  6205. }, transfers);
  6206. }
  6207. sendWithPromise(actionName, data, transfers) {
  6208. const callbackId = this.callbackId++;
  6209. const capability = (0, _util.createPromiseCapability)();
  6210. this.callbackCapabilities[callbackId] = capability;
  6211. try {
  6212. this._postMessage({
  6213. sourceName: this.sourceName,
  6214. targetName: this.targetName,
  6215. action: actionName,
  6216. callbackId,
  6217. data
  6218. }, transfers);
  6219. } catch (ex) {
  6220. capability.reject(ex);
  6221. }
  6222. return capability.promise;
  6223. }
  6224. sendWithStream(actionName, data, queueingStrategy, transfers) {
  6225. const streamId = this.streamId++;
  6226. const sourceName = this.sourceName;
  6227. const targetName = this.targetName;
  6228. const comObj = this.comObj;
  6229. return new ReadableStream({
  6230. start: controller => {
  6231. const startCapability = (0, _util.createPromiseCapability)();
  6232. this.streamControllers[streamId] = {
  6233. controller,
  6234. startCall: startCapability,
  6235. pullCall: null,
  6236. cancelCall: null,
  6237. isClosed: false
  6238. };
  6239. this._postMessage({
  6240. sourceName,
  6241. targetName,
  6242. action: actionName,
  6243. streamId,
  6244. data,
  6245. desiredSize: controller.desiredSize
  6246. }, transfers);
  6247. return startCapability.promise;
  6248. },
  6249. pull: controller => {
  6250. const pullCapability = (0, _util.createPromiseCapability)();
  6251. this.streamControllers[streamId].pullCall = pullCapability;
  6252. comObj.postMessage({
  6253. sourceName,
  6254. targetName,
  6255. stream: StreamKind.PULL,
  6256. streamId,
  6257. desiredSize: controller.desiredSize
  6258. });
  6259. return pullCapability.promise;
  6260. },
  6261. cancel: reason => {
  6262. (0, _util.assert)(reason instanceof Error, "cancel must have a valid reason");
  6263. const cancelCapability = (0, _util.createPromiseCapability)();
  6264. this.streamControllers[streamId].cancelCall = cancelCapability;
  6265. this.streamControllers[streamId].isClosed = true;
  6266. comObj.postMessage({
  6267. sourceName,
  6268. targetName,
  6269. stream: StreamKind.CANCEL,
  6270. streamId,
  6271. reason: wrapReason(reason)
  6272. });
  6273. return cancelCapability.promise;
  6274. }
  6275. }, queueingStrategy);
  6276. }
  6277. _createStreamSink(data) {
  6278. const self = this;
  6279. const action = this.actionHandler[data.action];
  6280. const streamId = data.streamId;
  6281. const sourceName = this.sourceName;
  6282. const targetName = data.sourceName;
  6283. const comObj = this.comObj;
  6284. const streamSink = {
  6285. enqueue(chunk, size = 1, transfers) {
  6286. if (this.isCancelled) {
  6287. return;
  6288. }
  6289. const lastDesiredSize = this.desiredSize;
  6290. this.desiredSize -= size;
  6291. if (lastDesiredSize > 0 && this.desiredSize <= 0) {
  6292. this.sinkCapability = (0, _util.createPromiseCapability)();
  6293. this.ready = this.sinkCapability.promise;
  6294. }
  6295. self._postMessage({
  6296. sourceName,
  6297. targetName,
  6298. stream: StreamKind.ENQUEUE,
  6299. streamId,
  6300. chunk
  6301. }, transfers);
  6302. },
  6303. close() {
  6304. if (this.isCancelled) {
  6305. return;
  6306. }
  6307. this.isCancelled = true;
  6308. comObj.postMessage({
  6309. sourceName,
  6310. targetName,
  6311. stream: StreamKind.CLOSE,
  6312. streamId
  6313. });
  6314. delete self.streamSinks[streamId];
  6315. },
  6316. error(reason) {
  6317. (0, _util.assert)(reason instanceof Error, "error must have a valid reason");
  6318. if (this.isCancelled) {
  6319. return;
  6320. }
  6321. this.isCancelled = true;
  6322. comObj.postMessage({
  6323. sourceName,
  6324. targetName,
  6325. stream: StreamKind.ERROR,
  6326. streamId,
  6327. reason: wrapReason(reason)
  6328. });
  6329. },
  6330. sinkCapability: (0, _util.createPromiseCapability)(),
  6331. onPull: null,
  6332. onCancel: null,
  6333. isCancelled: false,
  6334. desiredSize: data.desiredSize,
  6335. ready: null
  6336. };
  6337. streamSink.sinkCapability.resolve();
  6338. streamSink.ready = streamSink.sinkCapability.promise;
  6339. this.streamSinks[streamId] = streamSink;
  6340. new Promise(function (resolve) {
  6341. resolve(action(data.data, streamSink));
  6342. }).then(function () {
  6343. comObj.postMessage({
  6344. sourceName,
  6345. targetName,
  6346. stream: StreamKind.START_COMPLETE,
  6347. streamId,
  6348. success: true
  6349. });
  6350. }, function (reason) {
  6351. comObj.postMessage({
  6352. sourceName,
  6353. targetName,
  6354. stream: StreamKind.START_COMPLETE,
  6355. streamId,
  6356. reason: wrapReason(reason)
  6357. });
  6358. });
  6359. }
  6360. _processStreamMessage(data) {
  6361. const streamId = data.streamId;
  6362. const sourceName = this.sourceName;
  6363. const targetName = data.sourceName;
  6364. const comObj = this.comObj;
  6365. switch (data.stream) {
  6366. case StreamKind.START_COMPLETE:
  6367. if (data.success) {
  6368. this.streamControllers[streamId].startCall.resolve();
  6369. } else {
  6370. this.streamControllers[streamId].startCall.reject(wrapReason(data.reason));
  6371. }
  6372. break;
  6373. case StreamKind.PULL_COMPLETE:
  6374. if (data.success) {
  6375. this.streamControllers[streamId].pullCall.resolve();
  6376. } else {
  6377. this.streamControllers[streamId].pullCall.reject(wrapReason(data.reason));
  6378. }
  6379. break;
  6380. case StreamKind.PULL:
  6381. if (!this.streamSinks[streamId]) {
  6382. comObj.postMessage({
  6383. sourceName,
  6384. targetName,
  6385. stream: StreamKind.PULL_COMPLETE,
  6386. streamId,
  6387. success: true
  6388. });
  6389. break;
  6390. }
  6391. if (this.streamSinks[streamId].desiredSize <= 0 && data.desiredSize > 0) {
  6392. this.streamSinks[streamId].sinkCapability.resolve();
  6393. }
  6394. this.streamSinks[streamId].desiredSize = data.desiredSize;
  6395. const {
  6396. onPull
  6397. } = this.streamSinks[data.streamId];
  6398. new Promise(function (resolve) {
  6399. resolve(onPull && onPull());
  6400. }).then(function () {
  6401. comObj.postMessage({
  6402. sourceName,
  6403. targetName,
  6404. stream: StreamKind.PULL_COMPLETE,
  6405. streamId,
  6406. success: true
  6407. });
  6408. }, function (reason) {
  6409. comObj.postMessage({
  6410. sourceName,
  6411. targetName,
  6412. stream: StreamKind.PULL_COMPLETE,
  6413. streamId,
  6414. reason: wrapReason(reason)
  6415. });
  6416. });
  6417. break;
  6418. case StreamKind.ENQUEUE:
  6419. (0, _util.assert)(this.streamControllers[streamId], "enqueue should have stream controller");
  6420. if (this.streamControllers[streamId].isClosed) {
  6421. break;
  6422. }
  6423. this.streamControllers[streamId].controller.enqueue(data.chunk);
  6424. break;
  6425. case StreamKind.CLOSE:
  6426. (0, _util.assert)(this.streamControllers[streamId], "close should have stream controller");
  6427. if (this.streamControllers[streamId].isClosed) {
  6428. break;
  6429. }
  6430. this.streamControllers[streamId].isClosed = true;
  6431. this.streamControllers[streamId].controller.close();
  6432. this._deleteStreamController(streamId);
  6433. break;
  6434. case StreamKind.ERROR:
  6435. (0, _util.assert)(this.streamControllers[streamId], "error should have stream controller");
  6436. this.streamControllers[streamId].controller.error(wrapReason(data.reason));
  6437. this._deleteStreamController(streamId);
  6438. break;
  6439. case StreamKind.CANCEL_COMPLETE:
  6440. if (data.success) {
  6441. this.streamControllers[streamId].cancelCall.resolve();
  6442. } else {
  6443. this.streamControllers[streamId].cancelCall.reject(wrapReason(data.reason));
  6444. }
  6445. this._deleteStreamController(streamId);
  6446. break;
  6447. case StreamKind.CANCEL:
  6448. if (!this.streamSinks[streamId]) {
  6449. break;
  6450. }
  6451. const {
  6452. onCancel
  6453. } = this.streamSinks[data.streamId];
  6454. new Promise(function (resolve) {
  6455. resolve(onCancel && onCancel(wrapReason(data.reason)));
  6456. }).then(function () {
  6457. comObj.postMessage({
  6458. sourceName,
  6459. targetName,
  6460. stream: StreamKind.CANCEL_COMPLETE,
  6461. streamId,
  6462. success: true
  6463. });
  6464. }, function (reason) {
  6465. comObj.postMessage({
  6466. sourceName,
  6467. targetName,
  6468. stream: StreamKind.CANCEL_COMPLETE,
  6469. streamId,
  6470. reason: wrapReason(reason)
  6471. });
  6472. });
  6473. this.streamSinks[streamId].sinkCapability.reject(wrapReason(data.reason));
  6474. this.streamSinks[streamId].isCancelled = true;
  6475. delete this.streamSinks[streamId];
  6476. break;
  6477. default:
  6478. throw new Error("Unexpected stream case");
  6479. }
  6480. }
  6481. async _deleteStreamController(streamId) {
  6482. await Promise.allSettled([this.streamControllers[streamId].startCall, this.streamControllers[streamId].pullCall, this.streamControllers[streamId].cancelCall].map(function (capability) {
  6483. return capability && capability.promise;
  6484. }));
  6485. delete this.streamControllers[streamId];
  6486. }
  6487. _postMessage(message, transfers) {
  6488. if (transfers && this.postMessageTransfers) {
  6489. this.comObj.postMessage(message, transfers);
  6490. } else {
  6491. this.comObj.postMessage(message);
  6492. }
  6493. }
  6494. destroy() {
  6495. this.comObj.removeEventListener("message", this._onComObjOnMessage);
  6496. }
  6497. }
  6498. exports.MessageHandler = MessageHandler;
  6499. /***/ }),
  6500. /* 14 */
  6501. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  6502. Object.defineProperty(exports, "__esModule", ({
  6503. value: true
  6504. }));
  6505. exports.Metadata = void 0;
  6506. var _util = __w_pdfjs_require__(2);
  6507. var _xml_parser = __w_pdfjs_require__(15);
  6508. class Metadata {
  6509. constructor(data) {
  6510. (0, _util.assert)(typeof data === "string", "Metadata: input is not a string");
  6511. data = this._repair(data);
  6512. const parser = new _xml_parser.SimpleXMLParser({
  6513. lowerCaseName: true
  6514. });
  6515. const xmlDocument = parser.parseFromString(data);
  6516. this._metadataMap = new Map();
  6517. if (xmlDocument) {
  6518. this._parse(xmlDocument);
  6519. }
  6520. this._data = data;
  6521. }
  6522. _repair(data) {
  6523. return data.replace(/^[^<]+/, "").replace(/>\\376\\377([^<]+)/g, function (all, codes) {
  6524. const bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g, function (code, d1, d2, d3) {
  6525. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  6526. }).replace(/&(amp|apos|gt|lt|quot);/g, function (str, name) {
  6527. switch (name) {
  6528. case "amp":
  6529. return "&";
  6530. case "apos":
  6531. return "'";
  6532. case "gt":
  6533. return ">";
  6534. case "lt":
  6535. return "<";
  6536. case "quot":
  6537. return '"';
  6538. }
  6539. throw new Error(`_repair: ${name} isn't defined.`);
  6540. });
  6541. let chars = "";
  6542. for (let i = 0, ii = bytes.length; i < ii; i += 2) {
  6543. const code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  6544. if (code >= 32 && code < 127 && code !== 60 && code !== 62 && code !== 38) {
  6545. chars += String.fromCharCode(code);
  6546. } else {
  6547. chars += "&#x" + (0x10000 + code).toString(16).substring(1) + ";";
  6548. }
  6549. }
  6550. return ">" + chars;
  6551. });
  6552. }
  6553. _getSequence(entry) {
  6554. const name = entry.nodeName;
  6555. if (name !== "rdf:bag" && name !== "rdf:seq" && name !== "rdf:alt") {
  6556. return null;
  6557. }
  6558. return entry.childNodes.filter(node => node.nodeName === "rdf:li");
  6559. }
  6560. _getCreators(entry) {
  6561. if (entry.nodeName !== "dc:creator") {
  6562. return false;
  6563. }
  6564. if (!entry.hasChildNodes()) {
  6565. return true;
  6566. }
  6567. const seqNode = entry.childNodes[0];
  6568. const authors = this._getSequence(seqNode) || [];
  6569. this._metadataMap.set(entry.nodeName, authors.map(node => node.textContent.trim()));
  6570. return true;
  6571. }
  6572. _parse(xmlDocument) {
  6573. let rdf = xmlDocument.documentElement;
  6574. if (rdf.nodeName !== "rdf:rdf") {
  6575. rdf = rdf.firstChild;
  6576. while (rdf && rdf.nodeName !== "rdf:rdf") {
  6577. rdf = rdf.nextSibling;
  6578. }
  6579. }
  6580. if (!rdf || rdf.nodeName !== "rdf:rdf" || !rdf.hasChildNodes()) {
  6581. return;
  6582. }
  6583. for (const desc of rdf.childNodes) {
  6584. if (desc.nodeName !== "rdf:description") {
  6585. continue;
  6586. }
  6587. for (const entry of desc.childNodes) {
  6588. const name = entry.nodeName;
  6589. if (name === "#text") {
  6590. continue;
  6591. }
  6592. if (this._getCreators(entry)) {
  6593. continue;
  6594. }
  6595. this._metadataMap.set(name, entry.textContent.trim());
  6596. }
  6597. }
  6598. }
  6599. getRaw() {
  6600. return this._data;
  6601. }
  6602. get(name) {
  6603. return this._metadataMap.get(name) ?? null;
  6604. }
  6605. getAll() {
  6606. return (0, _util.objectFromEntries)(this._metadataMap);
  6607. }
  6608. has(name) {
  6609. return this._metadataMap.has(name);
  6610. }
  6611. }
  6612. exports.Metadata = Metadata;
  6613. /***/ }),
  6614. /* 15 */
  6615. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  6616. Object.defineProperty(exports, "__esModule", ({
  6617. value: true
  6618. }));
  6619. exports.SimpleXMLParser = exports.SimpleDOMNode = void 0;
  6620. var _util = __w_pdfjs_require__(2);
  6621. const XMLParserErrorCode = {
  6622. NoError: 0,
  6623. EndOfDocument: -1,
  6624. UnterminatedCdat: -2,
  6625. UnterminatedXmlDeclaration: -3,
  6626. UnterminatedDoctypeDeclaration: -4,
  6627. UnterminatedComment: -5,
  6628. MalformedElement: -6,
  6629. OutOfMemory: -7,
  6630. UnterminatedAttributeValue: -8,
  6631. UnterminatedElement: -9,
  6632. ElementNeverBegun: -10
  6633. };
  6634. function isWhitespace(s, index) {
  6635. const ch = s[index];
  6636. return ch === " " || ch === "\n" || ch === "\r" || ch === "\t";
  6637. }
  6638. function isWhitespaceString(s) {
  6639. for (let i = 0, ii = s.length; i < ii; i++) {
  6640. if (!isWhitespace(s, i)) {
  6641. return false;
  6642. }
  6643. }
  6644. return true;
  6645. }
  6646. class XMLParserBase {
  6647. _resolveEntities(s) {
  6648. return s.replace(/&([^;]+);/g, (all, entity) => {
  6649. if (entity.substring(0, 2) === "#x") {
  6650. return String.fromCodePoint(parseInt(entity.substring(2), 16));
  6651. } else if (entity.substring(0, 1) === "#") {
  6652. return String.fromCodePoint(parseInt(entity.substring(1), 10));
  6653. }
  6654. switch (entity) {
  6655. case "lt":
  6656. return "<";
  6657. case "gt":
  6658. return ">";
  6659. case "amp":
  6660. return "&";
  6661. case "quot":
  6662. return '"';
  6663. }
  6664. return this.onResolveEntity(entity);
  6665. });
  6666. }
  6667. _parseContent(s, start) {
  6668. const attributes = [];
  6669. let pos = start;
  6670. function skipWs() {
  6671. while (pos < s.length && isWhitespace(s, pos)) {
  6672. ++pos;
  6673. }
  6674. }
  6675. while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== ">" && s[pos] !== "/") {
  6676. ++pos;
  6677. }
  6678. const name = s.substring(start, pos);
  6679. skipWs();
  6680. while (pos < s.length && s[pos] !== ">" && s[pos] !== "/" && s[pos] !== "?") {
  6681. skipWs();
  6682. let attrName = "",
  6683. attrValue = "";
  6684. while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== "=") {
  6685. attrName += s[pos];
  6686. ++pos;
  6687. }
  6688. skipWs();
  6689. if (s[pos] !== "=") {
  6690. return null;
  6691. }
  6692. ++pos;
  6693. skipWs();
  6694. const attrEndChar = s[pos];
  6695. if (attrEndChar !== '"' && attrEndChar !== "'") {
  6696. return null;
  6697. }
  6698. const attrEndIndex = s.indexOf(attrEndChar, ++pos);
  6699. if (attrEndIndex < 0) {
  6700. return null;
  6701. }
  6702. attrValue = s.substring(pos, attrEndIndex);
  6703. attributes.push({
  6704. name: attrName,
  6705. value: this._resolveEntities(attrValue)
  6706. });
  6707. pos = attrEndIndex + 1;
  6708. skipWs();
  6709. }
  6710. return {
  6711. name,
  6712. attributes,
  6713. parsed: pos - start
  6714. };
  6715. }
  6716. _parseProcessingInstruction(s, start) {
  6717. let pos = start;
  6718. function skipWs() {
  6719. while (pos < s.length && isWhitespace(s, pos)) {
  6720. ++pos;
  6721. }
  6722. }
  6723. while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== ">" && s[pos] !== "/") {
  6724. ++pos;
  6725. }
  6726. const name = s.substring(start, pos);
  6727. skipWs();
  6728. const attrStart = pos;
  6729. while (pos < s.length && (s[pos] !== "?" || s[pos + 1] !== ">")) {
  6730. ++pos;
  6731. }
  6732. const value = s.substring(attrStart, pos);
  6733. return {
  6734. name,
  6735. value,
  6736. parsed: pos - start
  6737. };
  6738. }
  6739. parseXml(s) {
  6740. let i = 0;
  6741. while (i < s.length) {
  6742. const ch = s[i];
  6743. let j = i;
  6744. if (ch === "<") {
  6745. ++j;
  6746. const ch2 = s[j];
  6747. let q;
  6748. switch (ch2) {
  6749. case "/":
  6750. ++j;
  6751. q = s.indexOf(">", j);
  6752. if (q < 0) {
  6753. this.onError(XMLParserErrorCode.UnterminatedElement);
  6754. return;
  6755. }
  6756. this.onEndElement(s.substring(j, q));
  6757. j = q + 1;
  6758. break;
  6759. case "?":
  6760. ++j;
  6761. const pi = this._parseProcessingInstruction(s, j);
  6762. if (s.substring(j + pi.parsed, j + pi.parsed + 2) !== "?>") {
  6763. this.onError(XMLParserErrorCode.UnterminatedXmlDeclaration);
  6764. return;
  6765. }
  6766. this.onPi(pi.name, pi.value);
  6767. j += pi.parsed + 2;
  6768. break;
  6769. case "!":
  6770. if (s.substring(j + 1, j + 3) === "--") {
  6771. q = s.indexOf("-->", j + 3);
  6772. if (q < 0) {
  6773. this.onError(XMLParserErrorCode.UnterminatedComment);
  6774. return;
  6775. }
  6776. this.onComment(s.substring(j + 3, q));
  6777. j = q + 3;
  6778. } else if (s.substring(j + 1, j + 8) === "[CDATA[") {
  6779. q = s.indexOf("]]>", j + 8);
  6780. if (q < 0) {
  6781. this.onError(XMLParserErrorCode.UnterminatedCdat);
  6782. return;
  6783. }
  6784. this.onCdata(s.substring(j + 8, q));
  6785. j = q + 3;
  6786. } else if (s.substring(j + 1, j + 8) === "DOCTYPE") {
  6787. const q2 = s.indexOf("[", j + 8);
  6788. let complexDoctype = false;
  6789. q = s.indexOf(">", j + 8);
  6790. if (q < 0) {
  6791. this.onError(XMLParserErrorCode.UnterminatedDoctypeDeclaration);
  6792. return;
  6793. }
  6794. if (q2 > 0 && q > q2) {
  6795. q = s.indexOf("]>", j + 8);
  6796. if (q < 0) {
  6797. this.onError(XMLParserErrorCode.UnterminatedDoctypeDeclaration);
  6798. return;
  6799. }
  6800. complexDoctype = true;
  6801. }
  6802. const doctypeContent = s.substring(j + 8, q + (complexDoctype ? 1 : 0));
  6803. this.onDoctype(doctypeContent);
  6804. j = q + (complexDoctype ? 2 : 1);
  6805. } else {
  6806. this.onError(XMLParserErrorCode.MalformedElement);
  6807. return;
  6808. }
  6809. break;
  6810. default:
  6811. const content = this._parseContent(s, j);
  6812. if (content === null) {
  6813. this.onError(XMLParserErrorCode.MalformedElement);
  6814. return;
  6815. }
  6816. let isClosed = false;
  6817. if (s.substring(j + content.parsed, j + content.parsed + 2) === "/>") {
  6818. isClosed = true;
  6819. } else if (s.substring(j + content.parsed, j + content.parsed + 1) !== ">") {
  6820. this.onError(XMLParserErrorCode.UnterminatedElement);
  6821. return;
  6822. }
  6823. this.onBeginElement(content.name, content.attributes, isClosed);
  6824. j += content.parsed + (isClosed ? 2 : 1);
  6825. break;
  6826. }
  6827. } else {
  6828. while (j < s.length && s[j] !== "<") {
  6829. j++;
  6830. }
  6831. const text = s.substring(i, j);
  6832. this.onText(this._resolveEntities(text));
  6833. }
  6834. i = j;
  6835. }
  6836. }
  6837. onResolveEntity(name) {
  6838. return `&${name};`;
  6839. }
  6840. onPi(name, value) {}
  6841. onComment(text) {}
  6842. onCdata(text) {}
  6843. onDoctype(doctypeContent) {}
  6844. onText(text) {}
  6845. onBeginElement(name, attributes, isEmpty) {}
  6846. onEndElement(name) {}
  6847. onError(code) {}
  6848. }
  6849. class SimpleDOMNode {
  6850. constructor(nodeName, nodeValue) {
  6851. this.nodeName = nodeName;
  6852. this.nodeValue = nodeValue;
  6853. Object.defineProperty(this, "parentNode", {
  6854. value: null,
  6855. writable: true
  6856. });
  6857. }
  6858. get firstChild() {
  6859. return this.childNodes && this.childNodes[0];
  6860. }
  6861. get nextSibling() {
  6862. const childNodes = this.parentNode.childNodes;
  6863. if (!childNodes) {
  6864. return undefined;
  6865. }
  6866. const index = childNodes.indexOf(this);
  6867. if (index === -1) {
  6868. return undefined;
  6869. }
  6870. return childNodes[index + 1];
  6871. }
  6872. get textContent() {
  6873. if (!this.childNodes) {
  6874. return this.nodeValue || "";
  6875. }
  6876. return this.childNodes.map(function (child) {
  6877. return child.textContent;
  6878. }).join("");
  6879. }
  6880. hasChildNodes() {
  6881. return this.childNodes && this.childNodes.length > 0;
  6882. }
  6883. searchNode(paths, pos) {
  6884. if (pos >= paths.length) {
  6885. return this;
  6886. }
  6887. const component = paths[pos];
  6888. const stack = [];
  6889. let node = this;
  6890. while (true) {
  6891. if (component.name === node.nodeName) {
  6892. if (component.pos === 0) {
  6893. const res = node.searchNode(paths, pos + 1);
  6894. if (res !== null) {
  6895. return res;
  6896. }
  6897. } else if (stack.length === 0) {
  6898. return null;
  6899. } else {
  6900. const [parent] = stack.pop();
  6901. let siblingPos = 0;
  6902. for (const child of parent.childNodes) {
  6903. if (component.name === child.nodeName) {
  6904. if (siblingPos === component.pos) {
  6905. return child.searchNode(paths, pos + 1);
  6906. }
  6907. siblingPos++;
  6908. }
  6909. }
  6910. return node.searchNode(paths, pos + 1);
  6911. }
  6912. }
  6913. if (node.childNodes && node.childNodes.length !== 0) {
  6914. stack.push([node, 0]);
  6915. node = node.childNodes[0];
  6916. } else if (stack.length === 0) {
  6917. return null;
  6918. } else {
  6919. while (stack.length !== 0) {
  6920. const [parent, currentPos] = stack.pop();
  6921. const newPos = currentPos + 1;
  6922. if (newPos < parent.childNodes.length) {
  6923. stack.push([parent, newPos]);
  6924. node = parent.childNodes[newPos];
  6925. break;
  6926. }
  6927. }
  6928. if (stack.length === 0) {
  6929. return null;
  6930. }
  6931. }
  6932. }
  6933. }
  6934. dump(buffer) {
  6935. if (this.nodeName === "#text") {
  6936. buffer.push((0, _util.encodeToXmlString)(this.nodeValue));
  6937. return;
  6938. }
  6939. buffer.push(`<${this.nodeName}`);
  6940. if (this.attributes) {
  6941. for (const attribute of this.attributes) {
  6942. buffer.push(` ${attribute.name}="${(0, _util.encodeToXmlString)(attribute.value)}"`);
  6943. }
  6944. }
  6945. if (this.hasChildNodes()) {
  6946. buffer.push(">");
  6947. for (const child of this.childNodes) {
  6948. child.dump(buffer);
  6949. }
  6950. buffer.push(`</${this.nodeName}>`);
  6951. } else if (this.nodeValue) {
  6952. buffer.push(`>${(0, _util.encodeToXmlString)(this.nodeValue)}</${this.nodeName}>`);
  6953. } else {
  6954. buffer.push("/>");
  6955. }
  6956. }
  6957. }
  6958. exports.SimpleDOMNode = SimpleDOMNode;
  6959. class SimpleXMLParser extends XMLParserBase {
  6960. constructor({
  6961. hasAttributes = false,
  6962. lowerCaseName = false
  6963. }) {
  6964. super();
  6965. this._currentFragment = null;
  6966. this._stack = null;
  6967. this._errorCode = XMLParserErrorCode.NoError;
  6968. this._hasAttributes = hasAttributes;
  6969. this._lowerCaseName = lowerCaseName;
  6970. }
  6971. parseFromString(data) {
  6972. this._currentFragment = [];
  6973. this._stack = [];
  6974. this._errorCode = XMLParserErrorCode.NoError;
  6975. this.parseXml(data);
  6976. if (this._errorCode !== XMLParserErrorCode.NoError) {
  6977. return undefined;
  6978. }
  6979. const [documentElement] = this._currentFragment;
  6980. if (!documentElement) {
  6981. return undefined;
  6982. }
  6983. return {
  6984. documentElement
  6985. };
  6986. }
  6987. onResolveEntity(name) {
  6988. switch (name) {
  6989. case "apos":
  6990. return "'";
  6991. }
  6992. return super.onResolveEntity(name);
  6993. }
  6994. onText(text) {
  6995. if (isWhitespaceString(text)) {
  6996. return;
  6997. }
  6998. const node = new SimpleDOMNode("#text", text);
  6999. this._currentFragment.push(node);
  7000. }
  7001. onCdata(text) {
  7002. const node = new SimpleDOMNode("#text", text);
  7003. this._currentFragment.push(node);
  7004. }
  7005. onBeginElement(name, attributes, isEmpty) {
  7006. if (this._lowerCaseName) {
  7007. name = name.toLowerCase();
  7008. }
  7009. const node = new SimpleDOMNode(name);
  7010. node.childNodes = [];
  7011. if (this._hasAttributes) {
  7012. node.attributes = attributes;
  7013. }
  7014. this._currentFragment.push(node);
  7015. if (isEmpty) {
  7016. return;
  7017. }
  7018. this._stack.push(this._currentFragment);
  7019. this._currentFragment = node.childNodes;
  7020. }
  7021. onEndElement(name) {
  7022. this._currentFragment = this._stack.pop() || [];
  7023. const lastElement = this._currentFragment[this._currentFragment.length - 1];
  7024. if (!lastElement) {
  7025. return;
  7026. }
  7027. for (let i = 0, ii = lastElement.childNodes.length; i < ii; i++) {
  7028. lastElement.childNodes[i].parentNode = lastElement;
  7029. }
  7030. }
  7031. onError(code) {
  7032. this._errorCode = code;
  7033. }
  7034. }
  7035. exports.SimpleXMLParser = SimpleXMLParser;
  7036. /***/ }),
  7037. /* 16 */
  7038. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  7039. Object.defineProperty(exports, "__esModule", ({
  7040. value: true
  7041. }));
  7042. exports.OptionalContentConfig = void 0;
  7043. var _util = __w_pdfjs_require__(2);
  7044. class OptionalContentGroup {
  7045. constructor(name, intent) {
  7046. this.visible = true;
  7047. this.name = name;
  7048. this.intent = intent;
  7049. }
  7050. }
  7051. class OptionalContentConfig {
  7052. constructor(data) {
  7053. this.name = null;
  7054. this.creator = null;
  7055. this._order = null;
  7056. this._groups = new Map();
  7057. if (data === null) {
  7058. return;
  7059. }
  7060. this.name = data.name;
  7061. this.creator = data.creator;
  7062. this._order = data.order;
  7063. for (const group of data.groups) {
  7064. this._groups.set(group.id, new OptionalContentGroup(group.name, group.intent));
  7065. }
  7066. if (data.baseState === "OFF") {
  7067. for (const group of this._groups) {
  7068. group.visible = false;
  7069. }
  7070. }
  7071. for (const on of data.on) {
  7072. this._groups.get(on).visible = true;
  7073. }
  7074. for (const off of data.off) {
  7075. this._groups.get(off).visible = false;
  7076. }
  7077. }
  7078. isVisible(group) {
  7079. if (group.type === "OCG") {
  7080. if (!this._groups.has(group.id)) {
  7081. (0, _util.warn)(`Optional content group not found: ${group.id}`);
  7082. return true;
  7083. }
  7084. return this._groups.get(group.id).visible;
  7085. } else if (group.type === "OCMD") {
  7086. if (group.expression) {
  7087. (0, _util.warn)("Visibility expression not supported yet.");
  7088. }
  7089. if (!group.policy || group.policy === "AnyOn") {
  7090. for (const id of group.ids) {
  7091. if (!this._groups.has(id)) {
  7092. (0, _util.warn)(`Optional content group not found: ${id}`);
  7093. return true;
  7094. }
  7095. if (this._groups.get(id).visible) {
  7096. return true;
  7097. }
  7098. }
  7099. return false;
  7100. } else if (group.policy === "AllOn") {
  7101. for (const id of group.ids) {
  7102. if (!this._groups.has(id)) {
  7103. (0, _util.warn)(`Optional content group not found: ${id}`);
  7104. return true;
  7105. }
  7106. if (!this._groups.get(id).visible) {
  7107. return false;
  7108. }
  7109. }
  7110. return true;
  7111. } else if (group.policy === "AnyOff") {
  7112. for (const id of group.ids) {
  7113. if (!this._groups.has(id)) {
  7114. (0, _util.warn)(`Optional content group not found: ${id}`);
  7115. return true;
  7116. }
  7117. if (!this._groups.get(id).visible) {
  7118. return true;
  7119. }
  7120. }
  7121. return false;
  7122. } else if (group.policy === "AllOff") {
  7123. for (const id of group.ids) {
  7124. if (!this._groups.has(id)) {
  7125. (0, _util.warn)(`Optional content group not found: ${id}`);
  7126. return true;
  7127. }
  7128. if (this._groups.get(id).visible) {
  7129. return false;
  7130. }
  7131. }
  7132. return true;
  7133. }
  7134. (0, _util.warn)(`Unknown optional content policy ${group.policy}.`);
  7135. return true;
  7136. }
  7137. (0, _util.warn)(`Unknown group type ${group.type}.`);
  7138. return true;
  7139. }
  7140. setVisibility(id, visible = true) {
  7141. if (!this._groups.has(id)) {
  7142. (0, _util.warn)(`Optional content group not found: ${id}`);
  7143. return;
  7144. }
  7145. this._groups.get(id).visible = !!visible;
  7146. }
  7147. getOrder() {
  7148. if (!this._groups.size) {
  7149. return null;
  7150. }
  7151. if (this._order) {
  7152. return this._order.slice();
  7153. }
  7154. return Array.from(this._groups.keys());
  7155. }
  7156. getGroups() {
  7157. if (!this._groups.size) {
  7158. return null;
  7159. }
  7160. return (0, _util.objectFromEntries)(this._groups);
  7161. }
  7162. getGroup(id) {
  7163. return this._groups.get(id) || null;
  7164. }
  7165. }
  7166. exports.OptionalContentConfig = OptionalContentConfig;
  7167. /***/ }),
  7168. /* 17 */
  7169. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  7170. Object.defineProperty(exports, "__esModule", ({
  7171. value: true
  7172. }));
  7173. exports.PDFDataTransportStream = void 0;
  7174. var _util = __w_pdfjs_require__(2);
  7175. class PDFDataTransportStream {
  7176. constructor(params, pdfDataRangeTransport) {
  7177. (0, _util.assert)(pdfDataRangeTransport, 'PDFDataTransportStream - missing required "pdfDataRangeTransport" argument.');
  7178. this._queuedChunks = [];
  7179. this._progressiveDone = params.progressiveDone || false;
  7180. const initialData = params.initialData;
  7181. if (initialData?.length > 0) {
  7182. const buffer = new Uint8Array(initialData).buffer;
  7183. this._queuedChunks.push(buffer);
  7184. }
  7185. this._pdfDataRangeTransport = pdfDataRangeTransport;
  7186. this._isStreamingSupported = !params.disableStream;
  7187. this._isRangeSupported = !params.disableRange;
  7188. this._contentLength = params.length;
  7189. this._fullRequestReader = null;
  7190. this._rangeReaders = [];
  7191. this._pdfDataRangeTransport.addRangeListener((begin, chunk) => {
  7192. this._onReceiveData({
  7193. begin,
  7194. chunk
  7195. });
  7196. });
  7197. this._pdfDataRangeTransport.addProgressListener((loaded, total) => {
  7198. this._onProgress({
  7199. loaded,
  7200. total
  7201. });
  7202. });
  7203. this._pdfDataRangeTransport.addProgressiveReadListener(chunk => {
  7204. this._onReceiveData({
  7205. chunk
  7206. });
  7207. });
  7208. this._pdfDataRangeTransport.addProgressiveDoneListener(() => {
  7209. this._onProgressiveDone();
  7210. });
  7211. this._pdfDataRangeTransport.transportReady();
  7212. }
  7213. _onReceiveData(args) {
  7214. const buffer = new Uint8Array(args.chunk).buffer;
  7215. if (args.begin === undefined) {
  7216. if (this._fullRequestReader) {
  7217. this._fullRequestReader._enqueue(buffer);
  7218. } else {
  7219. this._queuedChunks.push(buffer);
  7220. }
  7221. } else {
  7222. const found = this._rangeReaders.some(function (rangeReader) {
  7223. if (rangeReader._begin !== args.begin) {
  7224. return false;
  7225. }
  7226. rangeReader._enqueue(buffer);
  7227. return true;
  7228. });
  7229. (0, _util.assert)(found, "_onReceiveData - no `PDFDataTransportStreamRangeReader` instance found.");
  7230. }
  7231. }
  7232. get _progressiveDataLength() {
  7233. return this._fullRequestReader?._loaded ?? 0;
  7234. }
  7235. _onProgress(evt) {
  7236. if (evt.total === undefined) {
  7237. const firstReader = this._rangeReaders[0];
  7238. if (firstReader?.onProgress) {
  7239. firstReader.onProgress({
  7240. loaded: evt.loaded
  7241. });
  7242. }
  7243. } else {
  7244. const fullReader = this._fullRequestReader;
  7245. if (fullReader?.onProgress) {
  7246. fullReader.onProgress({
  7247. loaded: evt.loaded,
  7248. total: evt.total
  7249. });
  7250. }
  7251. }
  7252. }
  7253. _onProgressiveDone() {
  7254. if (this._fullRequestReader) {
  7255. this._fullRequestReader.progressiveDone();
  7256. }
  7257. this._progressiveDone = true;
  7258. }
  7259. _removeRangeReader(reader) {
  7260. const i = this._rangeReaders.indexOf(reader);
  7261. if (i >= 0) {
  7262. this._rangeReaders.splice(i, 1);
  7263. }
  7264. }
  7265. getFullReader() {
  7266. (0, _util.assert)(!this._fullRequestReader, "PDFDataTransportStream.getFullReader can only be called once.");
  7267. const queuedChunks = this._queuedChunks;
  7268. this._queuedChunks = null;
  7269. return new PDFDataTransportStreamReader(this, queuedChunks, this._progressiveDone);
  7270. }
  7271. getRangeReader(begin, end) {
  7272. if (end <= this._progressiveDataLength) {
  7273. return null;
  7274. }
  7275. const reader = new PDFDataTransportStreamRangeReader(this, begin, end);
  7276. this._pdfDataRangeTransport.requestDataRange(begin, end);
  7277. this._rangeReaders.push(reader);
  7278. return reader;
  7279. }
  7280. cancelAllRequests(reason) {
  7281. if (this._fullRequestReader) {
  7282. this._fullRequestReader.cancel(reason);
  7283. }
  7284. const readers = this._rangeReaders.slice(0);
  7285. readers.forEach(function (rangeReader) {
  7286. rangeReader.cancel(reason);
  7287. });
  7288. this._pdfDataRangeTransport.abort();
  7289. }
  7290. }
  7291. exports.PDFDataTransportStream = PDFDataTransportStream;
  7292. class PDFDataTransportStreamReader {
  7293. constructor(stream, queuedChunks, progressiveDone = false) {
  7294. this._stream = stream;
  7295. this._done = progressiveDone || false;
  7296. this._filename = null;
  7297. this._queuedChunks = queuedChunks || [];
  7298. this._loaded = 0;
  7299. for (const chunk of this._queuedChunks) {
  7300. this._loaded += chunk.byteLength;
  7301. }
  7302. this._requests = [];
  7303. this._headersReady = Promise.resolve();
  7304. stream._fullRequestReader = this;
  7305. this.onProgress = null;
  7306. }
  7307. _enqueue(chunk) {
  7308. if (this._done) {
  7309. return;
  7310. }
  7311. if (this._requests.length > 0) {
  7312. const requestCapability = this._requests.shift();
  7313. requestCapability.resolve({
  7314. value: chunk,
  7315. done: false
  7316. });
  7317. } else {
  7318. this._queuedChunks.push(chunk);
  7319. }
  7320. this._loaded += chunk.byteLength;
  7321. }
  7322. get headersReady() {
  7323. return this._headersReady;
  7324. }
  7325. get filename() {
  7326. return this._filename;
  7327. }
  7328. get isRangeSupported() {
  7329. return this._stream._isRangeSupported;
  7330. }
  7331. get isStreamingSupported() {
  7332. return this._stream._isStreamingSupported;
  7333. }
  7334. get contentLength() {
  7335. return this._stream._contentLength;
  7336. }
  7337. async read() {
  7338. if (this._queuedChunks.length > 0) {
  7339. const chunk = this._queuedChunks.shift();
  7340. return {
  7341. value: chunk,
  7342. done: false
  7343. };
  7344. }
  7345. if (this._done) {
  7346. return {
  7347. value: undefined,
  7348. done: true
  7349. };
  7350. }
  7351. const requestCapability = (0, _util.createPromiseCapability)();
  7352. this._requests.push(requestCapability);
  7353. return requestCapability.promise;
  7354. }
  7355. cancel(reason) {
  7356. this._done = true;
  7357. this._requests.forEach(function (requestCapability) {
  7358. requestCapability.resolve({
  7359. value: undefined,
  7360. done: true
  7361. });
  7362. });
  7363. this._requests = [];
  7364. }
  7365. progressiveDone() {
  7366. if (this._done) {
  7367. return;
  7368. }
  7369. this._done = true;
  7370. }
  7371. }
  7372. class PDFDataTransportStreamRangeReader {
  7373. constructor(stream, begin, end) {
  7374. this._stream = stream;
  7375. this._begin = begin;
  7376. this._end = end;
  7377. this._queuedChunk = null;
  7378. this._requests = [];
  7379. this._done = false;
  7380. this.onProgress = null;
  7381. }
  7382. _enqueue(chunk) {
  7383. if (this._done) {
  7384. return;
  7385. }
  7386. if (this._requests.length === 0) {
  7387. this._queuedChunk = chunk;
  7388. } else {
  7389. const requestsCapability = this._requests.shift();
  7390. requestsCapability.resolve({
  7391. value: chunk,
  7392. done: false
  7393. });
  7394. this._requests.forEach(function (requestCapability) {
  7395. requestCapability.resolve({
  7396. value: undefined,
  7397. done: true
  7398. });
  7399. });
  7400. this._requests = [];
  7401. }
  7402. this._done = true;
  7403. this._stream._removeRangeReader(this);
  7404. }
  7405. get isStreamingSupported() {
  7406. return false;
  7407. }
  7408. async read() {
  7409. if (this._queuedChunk) {
  7410. const chunk = this._queuedChunk;
  7411. this._queuedChunk = null;
  7412. return {
  7413. value: chunk,
  7414. done: false
  7415. };
  7416. }
  7417. if (this._done) {
  7418. return {
  7419. value: undefined,
  7420. done: true
  7421. };
  7422. }
  7423. const requestCapability = (0, _util.createPromiseCapability)();
  7424. this._requests.push(requestCapability);
  7425. return requestCapability.promise;
  7426. }
  7427. cancel(reason) {
  7428. this._done = true;
  7429. this._requests.forEach(function (requestCapability) {
  7430. requestCapability.resolve({
  7431. value: undefined,
  7432. done: true
  7433. });
  7434. });
  7435. this._requests = [];
  7436. this._stream._removeRangeReader(this);
  7437. }
  7438. }
  7439. /***/ }),
  7440. /* 18 */
  7441. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  7442. Object.defineProperty(exports, "__esModule", ({
  7443. value: true
  7444. }));
  7445. exports.WebGLContext = void 0;
  7446. var _util = __w_pdfjs_require__(2);
  7447. class WebGLContext {
  7448. constructor({
  7449. enable = false
  7450. }) {
  7451. this._enabled = enable === true;
  7452. }
  7453. get isEnabled() {
  7454. let enabled = this._enabled;
  7455. if (enabled) {
  7456. enabled = WebGLUtils.tryInitGL();
  7457. }
  7458. return (0, _util.shadow)(this, "isEnabled", enabled);
  7459. }
  7460. composeSMask({
  7461. layer,
  7462. mask,
  7463. properties
  7464. }) {
  7465. return WebGLUtils.composeSMask(layer, mask, properties);
  7466. }
  7467. drawFigures({
  7468. width,
  7469. height,
  7470. backgroundColor,
  7471. figures,
  7472. context
  7473. }) {
  7474. return WebGLUtils.drawFigures(width, height, backgroundColor, figures, context);
  7475. }
  7476. clear() {
  7477. WebGLUtils.cleanup();
  7478. }
  7479. }
  7480. exports.WebGLContext = WebGLContext;
  7481. const WebGLUtils = function WebGLUtilsClosure() {
  7482. function loadShader(gl, code, shaderType) {
  7483. const shader = gl.createShader(shaderType);
  7484. gl.shaderSource(shader, code);
  7485. gl.compileShader(shader);
  7486. const compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  7487. if (!compiled) {
  7488. const errorMsg = gl.getShaderInfoLog(shader);
  7489. throw new Error("Error during shader compilation: " + errorMsg);
  7490. }
  7491. return shader;
  7492. }
  7493. function createVertexShader(gl, code) {
  7494. return loadShader(gl, code, gl.VERTEX_SHADER);
  7495. }
  7496. function createFragmentShader(gl, code) {
  7497. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  7498. }
  7499. function createProgram(gl, shaders) {
  7500. const program = gl.createProgram();
  7501. for (let i = 0, ii = shaders.length; i < ii; ++i) {
  7502. gl.attachShader(program, shaders[i]);
  7503. }
  7504. gl.linkProgram(program);
  7505. const linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  7506. if (!linked) {
  7507. const errorMsg = gl.getProgramInfoLog(program);
  7508. throw new Error("Error during program linking: " + errorMsg);
  7509. }
  7510. return program;
  7511. }
  7512. function createTexture(gl, image, textureId) {
  7513. gl.activeTexture(textureId);
  7514. const texture = gl.createTexture();
  7515. gl.bindTexture(gl.TEXTURE_2D, texture);
  7516. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  7517. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  7518. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  7519. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  7520. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  7521. return texture;
  7522. }
  7523. let currentGL, currentCanvas;
  7524. function generateGL() {
  7525. if (currentGL) {
  7526. return;
  7527. }
  7528. currentCanvas = document.createElement("canvas");
  7529. currentGL = currentCanvas.getContext("webgl", {
  7530. premultipliedalpha: false
  7531. });
  7532. }
  7533. const smaskVertexShaderCode = "\
  7534. attribute vec2 a_position; \
  7535. attribute vec2 a_texCoord; \
  7536. \
  7537. uniform vec2 u_resolution; \
  7538. \
  7539. varying vec2 v_texCoord; \
  7540. \
  7541. void main() { \
  7542. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  7543. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  7544. \
  7545. v_texCoord = a_texCoord; \
  7546. } ";
  7547. const smaskFragmentShaderCode = "\
  7548. precision mediump float; \
  7549. \
  7550. uniform vec4 u_backdrop; \
  7551. uniform int u_subtype; \
  7552. uniform sampler2D u_image; \
  7553. uniform sampler2D u_mask; \
  7554. \
  7555. varying vec2 v_texCoord; \
  7556. \
  7557. void main() { \
  7558. vec4 imageColor = texture2D(u_image, v_texCoord); \
  7559. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  7560. if (u_backdrop.a > 0.0) { \
  7561. maskColor.rgb = maskColor.rgb * maskColor.a + \
  7562. u_backdrop.rgb * (1.0 - maskColor.a); \
  7563. } \
  7564. float lum; \
  7565. if (u_subtype == 0) { \
  7566. lum = maskColor.a; \
  7567. } else { \
  7568. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  7569. maskColor.b * 0.11; \
  7570. } \
  7571. imageColor.a *= lum; \
  7572. imageColor.rgb *= imageColor.a; \
  7573. gl_FragColor = imageColor; \
  7574. } ";
  7575. let smaskCache = null;
  7576. function initSmaskGL() {
  7577. generateGL();
  7578. const canvas = currentCanvas;
  7579. currentCanvas = null;
  7580. const gl = currentGL;
  7581. currentGL = null;
  7582. const vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  7583. const fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  7584. const program = createProgram(gl, [vertexShader, fragmentShader]);
  7585. gl.useProgram(program);
  7586. const cache = {};
  7587. cache.gl = gl;
  7588. cache.canvas = canvas;
  7589. cache.resolutionLocation = gl.getUniformLocation(program, "u_resolution");
  7590. cache.positionLocation = gl.getAttribLocation(program, "a_position");
  7591. cache.backdropLocation = gl.getUniformLocation(program, "u_backdrop");
  7592. cache.subtypeLocation = gl.getUniformLocation(program, "u_subtype");
  7593. const texCoordLocation = gl.getAttribLocation(program, "a_texCoord");
  7594. const texLayerLocation = gl.getUniformLocation(program, "u_image");
  7595. const texMaskLocation = gl.getUniformLocation(program, "u_mask");
  7596. const texCoordBuffer = gl.createBuffer();
  7597. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  7598. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0]), gl.STATIC_DRAW);
  7599. gl.enableVertexAttribArray(texCoordLocation);
  7600. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  7601. gl.uniform1i(texLayerLocation, 0);
  7602. gl.uniform1i(texMaskLocation, 1);
  7603. smaskCache = cache;
  7604. }
  7605. function composeSMask(layer, mask, properties) {
  7606. const width = layer.width,
  7607. height = layer.height;
  7608. if (!smaskCache) {
  7609. initSmaskGL();
  7610. }
  7611. const cache = smaskCache,
  7612. canvas = cache.canvas,
  7613. gl = cache.gl;
  7614. canvas.width = width;
  7615. canvas.height = height;
  7616. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  7617. gl.uniform2f(cache.resolutionLocation, width, height);
  7618. if (properties.backdrop) {
  7619. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0], properties.backdrop[1], properties.backdrop[2], 1);
  7620. } else {
  7621. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  7622. }
  7623. gl.uniform1i(cache.subtypeLocation, properties.subtype === "Luminosity" ? 1 : 0);
  7624. const texture = createTexture(gl, layer, gl.TEXTURE0);
  7625. const maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  7626. const buffer = gl.createBuffer();
  7627. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  7628. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0, 0, width, 0, 0, height, 0, height, width, 0, width, height]), gl.STATIC_DRAW);
  7629. gl.enableVertexAttribArray(cache.positionLocation);
  7630. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  7631. gl.clearColor(0, 0, 0, 0);
  7632. gl.enable(gl.BLEND);
  7633. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  7634. gl.clear(gl.COLOR_BUFFER_BIT);
  7635. gl.drawArrays(gl.TRIANGLES, 0, 6);
  7636. gl.flush();
  7637. gl.deleteTexture(texture);
  7638. gl.deleteTexture(maskTexture);
  7639. gl.deleteBuffer(buffer);
  7640. return canvas;
  7641. }
  7642. const figuresVertexShaderCode = "\
  7643. attribute vec2 a_position; \
  7644. attribute vec3 a_color; \
  7645. \
  7646. uniform vec2 u_resolution; \
  7647. uniform vec2 u_scale; \
  7648. uniform vec2 u_offset; \
  7649. \
  7650. varying vec4 v_color; \
  7651. \
  7652. void main() { \
  7653. vec2 position = (a_position + u_offset) * u_scale; \
  7654. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  7655. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  7656. \
  7657. v_color = vec4(a_color / 255.0, 1.0); \
  7658. } ";
  7659. const figuresFragmentShaderCode = "\
  7660. precision mediump float; \
  7661. \
  7662. varying vec4 v_color; \
  7663. \
  7664. void main() { \
  7665. gl_FragColor = v_color; \
  7666. } ";
  7667. let figuresCache = null;
  7668. function initFiguresGL() {
  7669. generateGL();
  7670. const canvas = currentCanvas;
  7671. currentCanvas = null;
  7672. const gl = currentGL;
  7673. currentGL = null;
  7674. const vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  7675. const fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  7676. const program = createProgram(gl, [vertexShader, fragmentShader]);
  7677. gl.useProgram(program);
  7678. const cache = {};
  7679. cache.gl = gl;
  7680. cache.canvas = canvas;
  7681. cache.resolutionLocation = gl.getUniformLocation(program, "u_resolution");
  7682. cache.scaleLocation = gl.getUniformLocation(program, "u_scale");
  7683. cache.offsetLocation = gl.getUniformLocation(program, "u_offset");
  7684. cache.positionLocation = gl.getAttribLocation(program, "a_position");
  7685. cache.colorLocation = gl.getAttribLocation(program, "a_color");
  7686. figuresCache = cache;
  7687. }
  7688. function drawFigures(width, height, backgroundColor, figures, context) {
  7689. if (!figuresCache) {
  7690. initFiguresGL();
  7691. }
  7692. const cache = figuresCache,
  7693. canvas = cache.canvas,
  7694. gl = cache.gl;
  7695. canvas.width = width;
  7696. canvas.height = height;
  7697. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  7698. gl.uniform2f(cache.resolutionLocation, width, height);
  7699. let count = 0;
  7700. for (let i = 0, ii = figures.length; i < ii; i++) {
  7701. switch (figures[i].type) {
  7702. case "lattice":
  7703. const rows = figures[i].coords.length / figures[i].verticesPerRow | 0;
  7704. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  7705. break;
  7706. case "triangles":
  7707. count += figures[i].coords.length;
  7708. break;
  7709. }
  7710. }
  7711. const coords = new Float32Array(count * 2);
  7712. const colors = new Uint8Array(count * 3);
  7713. const coordsMap = context.coords,
  7714. colorsMap = context.colors;
  7715. let pIndex = 0,
  7716. cIndex = 0;
  7717. for (let i = 0, ii = figures.length; i < ii; i++) {
  7718. const figure = figures[i],
  7719. ps = figure.coords,
  7720. cs = figure.colors;
  7721. switch (figure.type) {
  7722. case "lattice":
  7723. const cols = figure.verticesPerRow;
  7724. const rows = ps.length / cols | 0;
  7725. for (let row = 1; row < rows; row++) {
  7726. let offset = row * cols + 1;
  7727. for (let col = 1; col < cols; col++, offset++) {
  7728. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  7729. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  7730. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  7731. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  7732. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  7733. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  7734. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  7735. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  7736. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  7737. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  7738. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  7739. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  7740. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  7741. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  7742. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  7743. coords[pIndex + 6] = coords[pIndex + 2];
  7744. coords[pIndex + 7] = coords[pIndex + 3];
  7745. coords[pIndex + 8] = coords[pIndex + 4];
  7746. coords[pIndex + 9] = coords[pIndex + 5];
  7747. coords[pIndex + 10] = coordsMap[ps[offset]];
  7748. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  7749. colors[cIndex + 9] = colors[cIndex + 3];
  7750. colors[cIndex + 10] = colors[cIndex + 4];
  7751. colors[cIndex + 11] = colors[cIndex + 5];
  7752. colors[cIndex + 12] = colors[cIndex + 6];
  7753. colors[cIndex + 13] = colors[cIndex + 7];
  7754. colors[cIndex + 14] = colors[cIndex + 8];
  7755. colors[cIndex + 15] = colorsMap[cs[offset]];
  7756. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  7757. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  7758. pIndex += 12;
  7759. cIndex += 18;
  7760. }
  7761. }
  7762. break;
  7763. case "triangles":
  7764. for (let j = 0, jj = ps.length; j < jj; j++) {
  7765. coords[pIndex] = coordsMap[ps[j]];
  7766. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  7767. colors[cIndex] = colorsMap[cs[j]];
  7768. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  7769. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  7770. pIndex += 2;
  7771. cIndex += 3;
  7772. }
  7773. break;
  7774. }
  7775. }
  7776. if (backgroundColor) {
  7777. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255, backgroundColor[2] / 255, 1.0);
  7778. } else {
  7779. gl.clearColor(0, 0, 0, 0);
  7780. }
  7781. gl.clear(gl.COLOR_BUFFER_BIT);
  7782. const coordsBuffer = gl.createBuffer();
  7783. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  7784. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  7785. gl.enableVertexAttribArray(cache.positionLocation);
  7786. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  7787. const colorsBuffer = gl.createBuffer();
  7788. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  7789. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  7790. gl.enableVertexAttribArray(cache.colorLocation);
  7791. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false, 0, 0);
  7792. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  7793. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  7794. gl.drawArrays(gl.TRIANGLES, 0, count);
  7795. gl.flush();
  7796. gl.deleteBuffer(coordsBuffer);
  7797. gl.deleteBuffer(colorsBuffer);
  7798. return canvas;
  7799. }
  7800. return {
  7801. tryInitGL() {
  7802. try {
  7803. generateGL();
  7804. return !!currentGL;
  7805. } catch (ex) {}
  7806. return false;
  7807. },
  7808. composeSMask,
  7809. drawFigures,
  7810. cleanup() {
  7811. if (smaskCache?.canvas) {
  7812. smaskCache.canvas.width = 0;
  7813. smaskCache.canvas.height = 0;
  7814. }
  7815. if (figuresCache?.canvas) {
  7816. figuresCache.canvas.width = 0;
  7817. figuresCache.canvas.height = 0;
  7818. }
  7819. smaskCache = null;
  7820. figuresCache = null;
  7821. }
  7822. };
  7823. }();
  7824. /***/ }),
  7825. /* 19 */
  7826. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  7827. Object.defineProperty(exports, "__esModule", ({
  7828. value: true
  7829. }));
  7830. exports.AnnotationLayer = void 0;
  7831. var _display_utils = __w_pdfjs_require__(1);
  7832. var _util = __w_pdfjs_require__(2);
  7833. var _annotation_storage = __w_pdfjs_require__(8);
  7834. var _scripting_utils = __w_pdfjs_require__(20);
  7835. class AnnotationElementFactory {
  7836. static create(parameters) {
  7837. const subtype = parameters.data.annotationType;
  7838. switch (subtype) {
  7839. case _util.AnnotationType.LINK:
  7840. return new LinkAnnotationElement(parameters);
  7841. case _util.AnnotationType.TEXT:
  7842. return new TextAnnotationElement(parameters);
  7843. case _util.AnnotationType.WIDGET:
  7844. const fieldType = parameters.data.fieldType;
  7845. switch (fieldType) {
  7846. case "Tx":
  7847. return new TextWidgetAnnotationElement(parameters);
  7848. case "Btn":
  7849. if (parameters.data.radioButton) {
  7850. return new RadioButtonWidgetAnnotationElement(parameters);
  7851. } else if (parameters.data.checkBox) {
  7852. return new CheckboxWidgetAnnotationElement(parameters);
  7853. }
  7854. return new PushButtonWidgetAnnotationElement(parameters);
  7855. case "Ch":
  7856. return new ChoiceWidgetAnnotationElement(parameters);
  7857. }
  7858. return new WidgetAnnotationElement(parameters);
  7859. case _util.AnnotationType.POPUP:
  7860. return new PopupAnnotationElement(parameters);
  7861. case _util.AnnotationType.FREETEXT:
  7862. return new FreeTextAnnotationElement(parameters);
  7863. case _util.AnnotationType.LINE:
  7864. return new LineAnnotationElement(parameters);
  7865. case _util.AnnotationType.SQUARE:
  7866. return new SquareAnnotationElement(parameters);
  7867. case _util.AnnotationType.CIRCLE:
  7868. return new CircleAnnotationElement(parameters);
  7869. case _util.AnnotationType.POLYLINE:
  7870. return new PolylineAnnotationElement(parameters);
  7871. case _util.AnnotationType.CARET:
  7872. return new CaretAnnotationElement(parameters);
  7873. case _util.AnnotationType.INK:
  7874. return new InkAnnotationElement(parameters);
  7875. case _util.AnnotationType.POLYGON:
  7876. return new PolygonAnnotationElement(parameters);
  7877. case _util.AnnotationType.HIGHLIGHT:
  7878. return new HighlightAnnotationElement(parameters);
  7879. case _util.AnnotationType.UNDERLINE:
  7880. return new UnderlineAnnotationElement(parameters);
  7881. case _util.AnnotationType.SQUIGGLY:
  7882. return new SquigglyAnnotationElement(parameters);
  7883. case _util.AnnotationType.STRIKEOUT:
  7884. return new StrikeOutAnnotationElement(parameters);
  7885. case _util.AnnotationType.STAMP:
  7886. return new StampAnnotationElement(parameters);
  7887. case _util.AnnotationType.FILEATTACHMENT:
  7888. return new FileAttachmentAnnotationElement(parameters);
  7889. default:
  7890. return new AnnotationElement(parameters);
  7891. }
  7892. }
  7893. }
  7894. class AnnotationElement {
  7895. constructor(parameters, {
  7896. isRenderable = false,
  7897. ignoreBorder = false,
  7898. createQuadrilaterals = false
  7899. } = {}) {
  7900. this.isRenderable = isRenderable;
  7901. this.data = parameters.data;
  7902. this.layer = parameters.layer;
  7903. this.page = parameters.page;
  7904. this.viewport = parameters.viewport;
  7905. this.linkService = parameters.linkService;
  7906. this.downloadManager = parameters.downloadManager;
  7907. this.imageResourcesPath = parameters.imageResourcesPath;
  7908. this.renderInteractiveForms = parameters.renderInteractiveForms;
  7909. this.svgFactory = parameters.svgFactory;
  7910. this.annotationStorage = parameters.annotationStorage;
  7911. this.enableScripting = parameters.enableScripting;
  7912. this.hasJSActions = parameters.hasJSActions;
  7913. this._mouseState = parameters.mouseState;
  7914. if (isRenderable) {
  7915. this.container = this._createContainer(ignoreBorder);
  7916. }
  7917. if (createQuadrilaterals) {
  7918. this.quadrilaterals = this._createQuadrilaterals(ignoreBorder);
  7919. }
  7920. }
  7921. _createContainer(ignoreBorder = false) {
  7922. const data = this.data,
  7923. page = this.page,
  7924. viewport = this.viewport;
  7925. const container = document.createElement("section");
  7926. let width = data.rect[2] - data.rect[0];
  7927. let height = data.rect[3] - data.rect[1];
  7928. container.setAttribute("data-annotation-id", data.id);
  7929. 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]]);
  7930. container.style.transform = `matrix(${viewport.transform.join(",")})`;
  7931. container.style.transformOrigin = `${-rect[0]}px ${-rect[1]}px`;
  7932. if (!ignoreBorder && data.borderStyle.width > 0) {
  7933. container.style.borderWidth = `${data.borderStyle.width}px`;
  7934. if (data.borderStyle.style !== _util.AnnotationBorderStyleType.UNDERLINE) {
  7935. width = width - 2 * data.borderStyle.width;
  7936. height = height - 2 * data.borderStyle.width;
  7937. }
  7938. const horizontalRadius = data.borderStyle.horizontalCornerRadius;
  7939. const verticalRadius = data.borderStyle.verticalCornerRadius;
  7940. if (horizontalRadius > 0 || verticalRadius > 0) {
  7941. const radius = `${horizontalRadius}px / ${verticalRadius}px`;
  7942. container.style.borderRadius = radius;
  7943. }
  7944. switch (data.borderStyle.style) {
  7945. case _util.AnnotationBorderStyleType.SOLID:
  7946. container.style.borderStyle = "solid";
  7947. break;
  7948. case _util.AnnotationBorderStyleType.DASHED:
  7949. container.style.borderStyle = "dashed";
  7950. break;
  7951. case _util.AnnotationBorderStyleType.BEVELED:
  7952. (0, _util.warn)("Unimplemented border style: beveled");
  7953. break;
  7954. case _util.AnnotationBorderStyleType.INSET:
  7955. (0, _util.warn)("Unimplemented border style: inset");
  7956. break;
  7957. case _util.AnnotationBorderStyleType.UNDERLINE:
  7958. container.style.borderBottomStyle = "solid";
  7959. break;
  7960. default:
  7961. break;
  7962. }
  7963. if (data.color) {
  7964. container.style.borderColor = _util.Util.makeHexColor(data.color[0] | 0, data.color[1] | 0, data.color[2] | 0);
  7965. } else {
  7966. container.style.borderWidth = 0;
  7967. }
  7968. }
  7969. container.style.left = `${rect[0]}px`;
  7970. container.style.top = `${rect[1]}px`;
  7971. container.style.width = `${width}px`;
  7972. container.style.height = `${height}px`;
  7973. return container;
  7974. }
  7975. _createQuadrilaterals(ignoreBorder = false) {
  7976. if (!this.data.quadPoints) {
  7977. return null;
  7978. }
  7979. const quadrilaterals = [];
  7980. const savedRect = this.data.rect;
  7981. for (const quadPoint of this.data.quadPoints) {
  7982. this.data.rect = [quadPoint[2].x, quadPoint[2].y, quadPoint[1].x, quadPoint[1].y];
  7983. quadrilaterals.push(this._createContainer(ignoreBorder));
  7984. }
  7985. this.data.rect = savedRect;
  7986. return quadrilaterals;
  7987. }
  7988. _createPopup(trigger, data) {
  7989. let container = this.container;
  7990. if (this.quadrilaterals) {
  7991. trigger = trigger || this.quadrilaterals;
  7992. container = this.quadrilaterals[0];
  7993. }
  7994. if (!trigger) {
  7995. trigger = document.createElement("div");
  7996. trigger.style.height = container.style.height;
  7997. trigger.style.width = container.style.width;
  7998. container.appendChild(trigger);
  7999. }
  8000. const popupElement = new PopupElement({
  8001. container,
  8002. trigger,
  8003. color: data.color,
  8004. title: data.title,
  8005. modificationDate: data.modificationDate,
  8006. contents: data.contents,
  8007. hideWrapper: true
  8008. });
  8009. const popup = popupElement.render();
  8010. popup.style.left = container.style.width;
  8011. container.appendChild(popup);
  8012. }
  8013. _renderQuadrilaterals(className) {
  8014. this.quadrilaterals.forEach(quadrilateral => {
  8015. quadrilateral.className = className;
  8016. });
  8017. return this.quadrilaterals;
  8018. }
  8019. render() {
  8020. (0, _util.unreachable)("Abstract method `AnnotationElement.render` called");
  8021. }
  8022. }
  8023. class LinkAnnotationElement extends AnnotationElement {
  8024. constructor(parameters) {
  8025. const isRenderable = !!(parameters.data.url || parameters.data.dest || parameters.data.action || parameters.data.isTooltipOnly || parameters.data.actions && (parameters.data.actions.Action || parameters.data.actions["Mouse Up"] || parameters.data.actions["Mouse Down"]));
  8026. super(parameters, {
  8027. isRenderable,
  8028. createQuadrilaterals: true
  8029. });
  8030. }
  8031. render() {
  8032. const {
  8033. data,
  8034. linkService
  8035. } = this;
  8036. const link = document.createElement("a");
  8037. if (data.url) {
  8038. (0, _display_utils.addLinkAttributes)(link, {
  8039. url: data.url,
  8040. target: data.newWindow ? _display_utils.LinkTarget.BLANK : linkService.externalLinkTarget,
  8041. rel: linkService.externalLinkRel,
  8042. enabled: linkService.externalLinkEnabled
  8043. });
  8044. } else if (data.action) {
  8045. this._bindNamedAction(link, data.action);
  8046. } else if (data.dest) {
  8047. this._bindLink(link, data.dest);
  8048. } else if (data.actions && (data.actions.Action || data.actions["Mouse Up"] || data.actions["Mouse Down"]) && this.enableScripting && this.hasJSActions) {
  8049. this._bindJSAction(link, data);
  8050. } else {
  8051. this._bindLink(link, "");
  8052. }
  8053. if (this.quadrilaterals) {
  8054. return this._renderQuadrilaterals("linkAnnotation").map((quadrilateral, index) => {
  8055. const linkElement = index === 0 ? link : link.cloneNode();
  8056. quadrilateral.appendChild(linkElement);
  8057. return quadrilateral;
  8058. });
  8059. }
  8060. this.container.className = "linkAnnotation";
  8061. this.container.appendChild(link);
  8062. return this.container;
  8063. }
  8064. _bindLink(link, destination) {
  8065. link.href = this.linkService.getDestinationHash(destination);
  8066. link.onclick = () => {
  8067. if (destination) {
  8068. this.linkService.goToDestination(destination);
  8069. }
  8070. return false;
  8071. };
  8072. if (destination || destination === "") {
  8073. link.className = "internalLink";
  8074. }
  8075. }
  8076. _bindNamedAction(link, action) {
  8077. link.href = this.linkService.getAnchorUrl("");
  8078. link.onclick = () => {
  8079. this.linkService.executeNamedAction(action);
  8080. return false;
  8081. };
  8082. link.className = "internalLink";
  8083. }
  8084. _bindJSAction(link, data) {
  8085. link.href = this.linkService.getAnchorUrl("");
  8086. const map = new Map([["Action", "onclick"], ["Mouse Up", "onmouseup"], ["Mouse Down", "onmousedown"]]);
  8087. for (const name of Object.keys(data.actions)) {
  8088. const jsName = map.get(name);
  8089. if (!jsName) {
  8090. continue;
  8091. }
  8092. link[jsName] = () => {
  8093. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  8094. source: this,
  8095. detail: {
  8096. id: data.id,
  8097. name
  8098. }
  8099. });
  8100. return false;
  8101. };
  8102. }
  8103. link.className = "internalLink";
  8104. }
  8105. }
  8106. class TextAnnotationElement extends AnnotationElement {
  8107. constructor(parameters) {
  8108. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8109. super(parameters, {
  8110. isRenderable
  8111. });
  8112. }
  8113. render() {
  8114. this.container.className = "textAnnotation";
  8115. const image = document.createElement("img");
  8116. image.style.height = this.container.style.height;
  8117. image.style.width = this.container.style.width;
  8118. image.src = this.imageResourcesPath + "annotation-" + this.data.name.toLowerCase() + ".svg";
  8119. image.alt = "[{{type}} Annotation]";
  8120. image.dataset.l10nId = "text_annotation_type";
  8121. image.dataset.l10nArgs = JSON.stringify({
  8122. type: this.data.name
  8123. });
  8124. if (!this.data.hasPopup) {
  8125. this._createPopup(image, this.data);
  8126. }
  8127. this.container.appendChild(image);
  8128. return this.container;
  8129. }
  8130. }
  8131. class WidgetAnnotationElement extends AnnotationElement {
  8132. render() {
  8133. if (this.data.alternativeText) {
  8134. this.container.title = this.data.alternativeText;
  8135. }
  8136. return this.container;
  8137. }
  8138. _getKeyModifier(event) {
  8139. return navigator.platform.includes("Win") && event.ctrlKey || navigator.platform.includes("Mac") && event.metaKey;
  8140. }
  8141. _setEventListener(element, baseName, eventName, valueGetter) {
  8142. if (baseName.includes("mouse")) {
  8143. element.addEventListener(baseName, event => {
  8144. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  8145. source: this,
  8146. detail: {
  8147. id: this.data.id,
  8148. name: eventName,
  8149. value: valueGetter(event),
  8150. shift: event.shiftKey,
  8151. modifier: this._getKeyModifier(event)
  8152. }
  8153. });
  8154. });
  8155. } else {
  8156. element.addEventListener(baseName, event => {
  8157. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  8158. source: this,
  8159. detail: {
  8160. id: this.data.id,
  8161. name: eventName,
  8162. value: event.target.checked
  8163. }
  8164. });
  8165. });
  8166. }
  8167. }
  8168. _setEventListeners(element, names, getter) {
  8169. for (const [baseName, eventName] of names) {
  8170. if (eventName === "Action" || this.data.actions?.[eventName]) {
  8171. this._setEventListener(element, baseName, eventName, getter);
  8172. }
  8173. }
  8174. }
  8175. }
  8176. class TextWidgetAnnotationElement extends WidgetAnnotationElement {
  8177. constructor(parameters) {
  8178. const isRenderable = parameters.renderInteractiveForms || !parameters.data.hasAppearance && !!parameters.data.fieldValue;
  8179. super(parameters, {
  8180. isRenderable
  8181. });
  8182. }
  8183. render() {
  8184. const storage = this.annotationStorage;
  8185. const id = this.data.id;
  8186. this.container.className = "textWidgetAnnotation";
  8187. let element = null;
  8188. if (this.renderInteractiveForms) {
  8189. const textContent = storage.getOrCreateValue(id, {
  8190. value: this.data.fieldValue
  8191. }).value;
  8192. const elementData = {
  8193. userValue: null,
  8194. formattedValue: null,
  8195. beforeInputSelectionRange: null,
  8196. beforeInputValue: null
  8197. };
  8198. if (this.data.multiLine) {
  8199. element = document.createElement("textarea");
  8200. element.textContent = textContent;
  8201. } else {
  8202. element = document.createElement("input");
  8203. element.type = "text";
  8204. element.setAttribute("value", textContent);
  8205. }
  8206. elementData.userValue = textContent;
  8207. element.setAttribute("id", id);
  8208. element.addEventListener("input", function (event) {
  8209. storage.setValue(id, {
  8210. value: event.target.value
  8211. });
  8212. });
  8213. let blurListener = event => {
  8214. if (elementData.formattedValue) {
  8215. event.target.value = elementData.formattedValue;
  8216. }
  8217. event.target.setSelectionRange(0, 0);
  8218. elementData.beforeInputSelectionRange = null;
  8219. };
  8220. if (this.enableScripting && this.hasJSActions) {
  8221. element.addEventListener("focus", event => {
  8222. if (elementData.userValue) {
  8223. event.target.value = elementData.userValue;
  8224. }
  8225. });
  8226. element.addEventListener("updatefromsandbox", function (event) {
  8227. const {
  8228. detail
  8229. } = event;
  8230. const actions = {
  8231. value() {
  8232. elementData.userValue = detail.value || "";
  8233. storage.setValue(id, {
  8234. value: elementData.userValue.toString()
  8235. });
  8236. if (!elementData.formattedValue) {
  8237. event.target.value = elementData.userValue;
  8238. }
  8239. },
  8240. valueAsString() {
  8241. elementData.formattedValue = detail.valueAsString || "";
  8242. if (event.target !== document.activeElement) {
  8243. event.target.value = elementData.formattedValue;
  8244. }
  8245. storage.setValue(id, {
  8246. formattedValue: elementData.formattedValue
  8247. });
  8248. },
  8249. focus() {
  8250. setTimeout(() => event.target.focus({
  8251. preventScroll: false
  8252. }), 0);
  8253. },
  8254. userName() {
  8255. event.target.title = detail.userName;
  8256. },
  8257. hidden() {
  8258. event.target.style.visibility = detail.hidden ? "hidden" : "visible";
  8259. storage.setValue(id, {
  8260. hidden: detail.hidden
  8261. });
  8262. },
  8263. editable() {
  8264. event.target.disabled = !detail.editable;
  8265. },
  8266. selRange() {
  8267. const [selStart, selEnd] = detail.selRange;
  8268. if (selStart >= 0 && selEnd < event.target.value.length) {
  8269. event.target.setSelectionRange(selStart, selEnd);
  8270. }
  8271. },
  8272. strokeColor() {
  8273. const color = detail.strokeColor;
  8274. event.target.style.color = _scripting_utils.ColorConverters[`${color[0]}_HTML`](color.slice(1));
  8275. }
  8276. };
  8277. Object.keys(detail).filter(name => name in actions).forEach(name => actions[name]());
  8278. });
  8279. if (this.data.actions) {
  8280. element.addEventListener("keydown", event => {
  8281. elementData.beforeInputValue = event.target.value;
  8282. let commitKey = -1;
  8283. if (event.key === "Escape") {
  8284. commitKey = 0;
  8285. } else if (event.key === "Enter") {
  8286. commitKey = 2;
  8287. } else if (event.key === "Tab") {
  8288. commitKey = 3;
  8289. }
  8290. if (commitKey === -1) {
  8291. return;
  8292. }
  8293. elementData.userValue = event.target.value;
  8294. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  8295. source: this,
  8296. detail: {
  8297. id,
  8298. name: "Keystroke",
  8299. value: event.target.value,
  8300. willCommit: true,
  8301. commitKey,
  8302. selStart: event.target.selectionStart,
  8303. selEnd: event.target.selectionEnd
  8304. }
  8305. });
  8306. });
  8307. const _blurListener = blurListener;
  8308. blurListener = null;
  8309. element.addEventListener("blur", event => {
  8310. if (this._mouseState.isDown) {
  8311. elementData.userValue = event.target.value;
  8312. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  8313. source: this,
  8314. detail: {
  8315. id,
  8316. name: "Keystroke",
  8317. value: event.target.value,
  8318. willCommit: true,
  8319. commitKey: 1,
  8320. selStart: event.target.selectionStart,
  8321. selEnd: event.target.selectionEnd
  8322. }
  8323. });
  8324. }
  8325. _blurListener(event);
  8326. });
  8327. element.addEventListener("mousedown", event => {
  8328. elementData.beforeInputValue = event.target.value;
  8329. elementData.beforeInputSelectionRange = null;
  8330. });
  8331. element.addEventListener("keyup", event => {
  8332. if (event.target.selectionStart === event.target.selectionEnd) {
  8333. elementData.beforeInputSelectionRange = null;
  8334. }
  8335. });
  8336. element.addEventListener("select", event => {
  8337. elementData.beforeInputSelectionRange = [event.target.selectionStart, event.target.selectionEnd];
  8338. });
  8339. if ("Keystroke" in this.data.actions) {
  8340. element.addEventListener("input", event => {
  8341. let selStart = -1;
  8342. let selEnd = -1;
  8343. if (elementData.beforeInputSelectionRange) {
  8344. [selStart, selEnd] = elementData.beforeInputSelectionRange;
  8345. }
  8346. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  8347. source: this,
  8348. detail: {
  8349. id,
  8350. name: "Keystroke",
  8351. value: elementData.beforeInputValue,
  8352. change: event.data,
  8353. willCommit: false,
  8354. selStart,
  8355. selEnd
  8356. }
  8357. });
  8358. });
  8359. }
  8360. this._setEventListeners(element, [["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"]], event => event.target.value);
  8361. }
  8362. }
  8363. if (blurListener) {
  8364. element.addEventListener("blur", blurListener);
  8365. }
  8366. element.disabled = this.data.readOnly;
  8367. element.name = this.data.fieldName;
  8368. if (this.data.maxLen !== null) {
  8369. element.maxLength = this.data.maxLen;
  8370. }
  8371. if (this.data.comb) {
  8372. const fieldWidth = this.data.rect[2] - this.data.rect[0];
  8373. const combWidth = fieldWidth / this.data.maxLen;
  8374. element.classList.add("comb");
  8375. element.style.letterSpacing = `calc(${combWidth}px - 1ch)`;
  8376. }
  8377. } else {
  8378. element = document.createElement("div");
  8379. element.textContent = this.data.fieldValue;
  8380. element.style.verticalAlign = "middle";
  8381. element.style.display = "table-cell";
  8382. }
  8383. this._setTextStyle(element);
  8384. this.container.appendChild(element);
  8385. return this.container;
  8386. }
  8387. _setTextStyle(element) {
  8388. const TEXT_ALIGNMENT = ["left", "center", "right"];
  8389. const {
  8390. fontSize,
  8391. fontColor
  8392. } = this.data.defaultAppearanceData;
  8393. const style = element.style;
  8394. if (fontSize) {
  8395. style.fontSize = `${fontSize}px`;
  8396. }
  8397. style.color = _util.Util.makeHexColor(fontColor[0], fontColor[1], fontColor[2]);
  8398. if (this.data.textAlignment !== null) {
  8399. style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
  8400. }
  8401. }
  8402. }
  8403. class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement {
  8404. constructor(parameters) {
  8405. super(parameters, {
  8406. isRenderable: parameters.renderInteractiveForms
  8407. });
  8408. }
  8409. render() {
  8410. const storage = this.annotationStorage;
  8411. const data = this.data;
  8412. const id = data.id;
  8413. const value = storage.getOrCreateValue(id, {
  8414. value: data.fieldValue && data.fieldValue !== "Off"
  8415. }).value;
  8416. this.container.className = "buttonWidgetAnnotation checkBox";
  8417. const element = document.createElement("input");
  8418. element.disabled = data.readOnly;
  8419. element.type = "checkbox";
  8420. element.name = this.data.fieldName;
  8421. if (value) {
  8422. element.setAttribute("checked", true);
  8423. }
  8424. element.setAttribute("id", id);
  8425. element.addEventListener("change", function (event) {
  8426. const name = event.target.name;
  8427. for (const checkbox of document.getElementsByName(name)) {
  8428. if (checkbox !== event.target) {
  8429. checkbox.checked = false;
  8430. storage.setValue(checkbox.parentNode.getAttribute("data-annotation-id"), {
  8431. value: false
  8432. });
  8433. }
  8434. }
  8435. storage.setValue(id, {
  8436. value: event.target.checked
  8437. });
  8438. });
  8439. if (this.enableScripting && this.hasJSActions) {
  8440. element.addEventListener("updatefromsandbox", event => {
  8441. const {
  8442. detail
  8443. } = event;
  8444. const actions = {
  8445. value() {
  8446. event.target.checked = detail.value !== "Off";
  8447. storage.setValue(id, {
  8448. value: event.target.checked
  8449. });
  8450. },
  8451. focus() {
  8452. setTimeout(() => event.target.focus({
  8453. preventScroll: false
  8454. }), 0);
  8455. },
  8456. hidden() {
  8457. event.target.style.visibility = detail.hidden ? "hidden" : "visible";
  8458. storage.setValue(id, {
  8459. hidden: detail.hidden
  8460. });
  8461. },
  8462. editable() {
  8463. event.target.disabled = !detail.editable;
  8464. }
  8465. };
  8466. Object.keys(detail).filter(name => name in actions).forEach(name => actions[name]());
  8467. });
  8468. 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);
  8469. }
  8470. this.container.appendChild(element);
  8471. return this.container;
  8472. }
  8473. }
  8474. class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
  8475. constructor(parameters) {
  8476. super(parameters, {
  8477. isRenderable: parameters.renderInteractiveForms
  8478. });
  8479. }
  8480. render() {
  8481. this.container.className = "buttonWidgetAnnotation radioButton";
  8482. const storage = this.annotationStorage;
  8483. const data = this.data;
  8484. const id = data.id;
  8485. const value = storage.getOrCreateValue(id, {
  8486. value: data.fieldValue === data.buttonValue
  8487. }).value;
  8488. const element = document.createElement("input");
  8489. element.disabled = data.readOnly;
  8490. element.type = "radio";
  8491. element.name = data.fieldName;
  8492. if (value) {
  8493. element.setAttribute("checked", true);
  8494. }
  8495. element.setAttribute("pdfButtonValue", data.buttonValue);
  8496. element.setAttribute("id", id);
  8497. element.addEventListener("change", function (event) {
  8498. const {
  8499. target
  8500. } = event;
  8501. for (const radio of document.getElementsByName(target.name)) {
  8502. if (radio !== target) {
  8503. storage.setValue(radio.getAttribute("id"), {
  8504. value: false
  8505. });
  8506. }
  8507. }
  8508. storage.setValue(id, {
  8509. value: target.checked
  8510. });
  8511. });
  8512. if (this.enableScripting && this.hasJSActions) {
  8513. element.addEventListener("updatefromsandbox", event => {
  8514. const {
  8515. detail
  8516. } = event;
  8517. const actions = {
  8518. value() {
  8519. const fieldValue = detail.value;
  8520. for (const radio of document.getElementsByName(event.target.name)) {
  8521. const radioId = radio.getAttribute("id");
  8522. if (fieldValue === radio.getAttribute("pdfButtonValue")) {
  8523. radio.setAttribute("checked", true);
  8524. storage.setValue(radioId, {
  8525. value: true
  8526. });
  8527. } else {
  8528. storage.setValue(radioId, {
  8529. value: false
  8530. });
  8531. }
  8532. }
  8533. },
  8534. focus() {
  8535. setTimeout(() => event.target.focus({
  8536. preventScroll: false
  8537. }), 0);
  8538. },
  8539. hidden() {
  8540. event.target.style.visibility = detail.hidden ? "hidden" : "visible";
  8541. storage.setValue(id, {
  8542. hidden: detail.hidden
  8543. });
  8544. },
  8545. editable() {
  8546. event.target.disabled = !detail.editable;
  8547. }
  8548. };
  8549. Object.keys(detail).filter(name => name in actions).forEach(name => actions[name]());
  8550. });
  8551. 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);
  8552. }
  8553. this.container.appendChild(element);
  8554. return this.container;
  8555. }
  8556. }
  8557. class PushButtonWidgetAnnotationElement extends LinkAnnotationElement {
  8558. render() {
  8559. const container = super.render();
  8560. container.className = "buttonWidgetAnnotation pushButton";
  8561. if (this.data.alternativeText) {
  8562. container.title = this.data.alternativeText;
  8563. }
  8564. return container;
  8565. }
  8566. }
  8567. class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
  8568. constructor(parameters) {
  8569. super(parameters, {
  8570. isRenderable: parameters.renderInteractiveForms
  8571. });
  8572. }
  8573. render() {
  8574. this.container.className = "choiceWidgetAnnotation";
  8575. const storage = this.annotationStorage;
  8576. const id = this.data.id;
  8577. storage.getOrCreateValue(id, {
  8578. value: this.data.fieldValue.length > 0 ? this.data.fieldValue[0] : undefined
  8579. });
  8580. const selectElement = document.createElement("select");
  8581. selectElement.disabled = this.data.readOnly;
  8582. selectElement.name = this.data.fieldName;
  8583. selectElement.setAttribute("id", id);
  8584. if (!this.data.combo) {
  8585. selectElement.size = this.data.options.length;
  8586. if (this.data.multiSelect) {
  8587. selectElement.multiple = true;
  8588. }
  8589. }
  8590. for (const option of this.data.options) {
  8591. const optionElement = document.createElement("option");
  8592. optionElement.textContent = option.displayValue;
  8593. optionElement.value = option.exportValue;
  8594. if (this.data.fieldValue.includes(option.exportValue)) {
  8595. optionElement.setAttribute("selected", true);
  8596. }
  8597. selectElement.appendChild(optionElement);
  8598. }
  8599. function getValue(event) {
  8600. const options = event.target.options;
  8601. return options[options.selectedIndex].value;
  8602. }
  8603. if (this.enableScripting && this.hasJSActions) {
  8604. selectElement.addEventListener("updatefromsandbox", event => {
  8605. const {
  8606. detail
  8607. } = event;
  8608. const actions = {
  8609. value() {
  8610. const options = event.target.options;
  8611. const value = detail.value;
  8612. const i = options.indexOf(value);
  8613. if (i !== -1) {
  8614. options.selectedIndex = i;
  8615. storage.setValue(id, {
  8616. value
  8617. });
  8618. }
  8619. },
  8620. focus() {
  8621. setTimeout(() => event.target.focus({
  8622. preventScroll: false
  8623. }), 0);
  8624. },
  8625. hidden() {
  8626. event.target.style.visibility = detail.hidden ? "hidden" : "visible";
  8627. storage.setValue(id, {
  8628. hidden: detail.hidden
  8629. });
  8630. },
  8631. editable() {
  8632. event.target.disabled = !detail.editable;
  8633. }
  8634. };
  8635. Object.keys(detail).filter(name => name in actions).forEach(name => actions[name]());
  8636. });
  8637. selectElement.addEventListener("input", event => {
  8638. const value = getValue(event);
  8639. storage.setValue(id, {
  8640. value
  8641. });
  8642. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  8643. source: this,
  8644. detail: {
  8645. id,
  8646. name: "Keystroke",
  8647. changeEx: value,
  8648. willCommit: true,
  8649. commitKey: 1,
  8650. keyDown: false
  8651. }
  8652. });
  8653. });
  8654. this._setEventListeners(selectElement, [["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"]], event => event.target.checked);
  8655. } else {
  8656. selectElement.addEventListener("input", function (event) {
  8657. storage.setValue(id, {
  8658. value: getValue(event)
  8659. });
  8660. });
  8661. }
  8662. this.container.appendChild(selectElement);
  8663. return this.container;
  8664. }
  8665. }
  8666. class PopupAnnotationElement extends AnnotationElement {
  8667. constructor(parameters) {
  8668. const isRenderable = !!(parameters.data.title || parameters.data.contents);
  8669. super(parameters, {
  8670. isRenderable
  8671. });
  8672. }
  8673. render() {
  8674. const IGNORE_TYPES = ["Line", "Square", "Circle", "PolyLine", "Polygon", "Ink"];
  8675. this.container.className = "popupAnnotation";
  8676. if (IGNORE_TYPES.includes(this.data.parentType)) {
  8677. return this.container;
  8678. }
  8679. const selector = `[data-annotation-id="${this.data.parentId}"]`;
  8680. const parentElements = this.layer.querySelectorAll(selector);
  8681. if (parentElements.length === 0) {
  8682. return this.container;
  8683. }
  8684. const popup = new PopupElement({
  8685. container: this.container,
  8686. trigger: Array.from(parentElements),
  8687. color: this.data.color,
  8688. title: this.data.title,
  8689. modificationDate: this.data.modificationDate,
  8690. contents: this.data.contents
  8691. });
  8692. const page = this.page;
  8693. 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]]);
  8694. const popupLeft = rect[0] + this.data.parentRect[2] - this.data.parentRect[0];
  8695. const popupTop = rect[1];
  8696. this.container.style.transformOrigin = `${-popupLeft}px ${-popupTop}px`;
  8697. this.container.style.left = `${popupLeft}px`;
  8698. this.container.style.top = `${popupTop}px`;
  8699. this.container.appendChild(popup.render());
  8700. return this.container;
  8701. }
  8702. }
  8703. class PopupElement {
  8704. constructor(parameters) {
  8705. this.container = parameters.container;
  8706. this.trigger = parameters.trigger;
  8707. this.color = parameters.color;
  8708. this.title = parameters.title;
  8709. this.modificationDate = parameters.modificationDate;
  8710. this.contents = parameters.contents;
  8711. this.hideWrapper = parameters.hideWrapper || false;
  8712. this.pinned = false;
  8713. }
  8714. render() {
  8715. const BACKGROUND_ENLIGHT = 0.7;
  8716. const wrapper = document.createElement("div");
  8717. wrapper.className = "popupWrapper";
  8718. this.hideElement = this.hideWrapper ? wrapper : this.container;
  8719. this.hideElement.setAttribute("hidden", true);
  8720. const popup = document.createElement("div");
  8721. popup.className = "popup";
  8722. const color = this.color;
  8723. if (color) {
  8724. const r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  8725. const g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  8726. const b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  8727. popup.style.backgroundColor = _util.Util.makeHexColor(r | 0, g | 0, b | 0);
  8728. }
  8729. const title = document.createElement("h1");
  8730. title.textContent = this.title;
  8731. popup.appendChild(title);
  8732. const dateObject = _display_utils.PDFDateString.toDateObject(this.modificationDate);
  8733. if (dateObject) {
  8734. const modificationDate = document.createElement("span");
  8735. modificationDate.textContent = "{{date}}, {{time}}";
  8736. modificationDate.dataset.l10nId = "annotation_date_string";
  8737. modificationDate.dataset.l10nArgs = JSON.stringify({
  8738. date: dateObject.toLocaleDateString(),
  8739. time: dateObject.toLocaleTimeString()
  8740. });
  8741. popup.appendChild(modificationDate);
  8742. }
  8743. const contents = this._formatContents(this.contents);
  8744. popup.appendChild(contents);
  8745. if (!Array.isArray(this.trigger)) {
  8746. this.trigger = [this.trigger];
  8747. }
  8748. this.trigger.forEach(element => {
  8749. element.addEventListener("click", this._toggle.bind(this));
  8750. element.addEventListener("mouseover", this._show.bind(this, false));
  8751. element.addEventListener("mouseout", this._hide.bind(this, false));
  8752. });
  8753. popup.addEventListener("click", this._hide.bind(this, true));
  8754. wrapper.appendChild(popup);
  8755. return wrapper;
  8756. }
  8757. _formatContents(contents) {
  8758. const p = document.createElement("p");
  8759. const lines = contents.split(/(?:\r\n?|\n)/);
  8760. for (let i = 0, ii = lines.length; i < ii; ++i) {
  8761. const line = lines[i];
  8762. p.appendChild(document.createTextNode(line));
  8763. if (i < ii - 1) {
  8764. p.appendChild(document.createElement("br"));
  8765. }
  8766. }
  8767. return p;
  8768. }
  8769. _toggle() {
  8770. if (this.pinned) {
  8771. this._hide(true);
  8772. } else {
  8773. this._show(true);
  8774. }
  8775. }
  8776. _show(pin = false) {
  8777. if (pin) {
  8778. this.pinned = true;
  8779. }
  8780. if (this.hideElement.hasAttribute("hidden")) {
  8781. this.hideElement.removeAttribute("hidden");
  8782. this.container.style.zIndex += 1;
  8783. }
  8784. }
  8785. _hide(unpin = true) {
  8786. if (unpin) {
  8787. this.pinned = false;
  8788. }
  8789. if (!this.hideElement.hasAttribute("hidden") && !this.pinned) {
  8790. this.hideElement.setAttribute("hidden", true);
  8791. this.container.style.zIndex -= 1;
  8792. }
  8793. }
  8794. }
  8795. class FreeTextAnnotationElement extends AnnotationElement {
  8796. constructor(parameters) {
  8797. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8798. super(parameters, {
  8799. isRenderable,
  8800. ignoreBorder: true
  8801. });
  8802. }
  8803. render() {
  8804. this.container.className = "freeTextAnnotation";
  8805. if (!this.data.hasPopup) {
  8806. this._createPopup(null, this.data);
  8807. }
  8808. return this.container;
  8809. }
  8810. }
  8811. class LineAnnotationElement extends AnnotationElement {
  8812. constructor(parameters) {
  8813. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8814. super(parameters, {
  8815. isRenderable,
  8816. ignoreBorder: true
  8817. });
  8818. }
  8819. render() {
  8820. this.container.className = "lineAnnotation";
  8821. const data = this.data;
  8822. const width = data.rect[2] - data.rect[0];
  8823. const height = data.rect[3] - data.rect[1];
  8824. const svg = this.svgFactory.create(width, height);
  8825. const line = this.svgFactory.createElement("svg:line");
  8826. line.setAttribute("x1", data.rect[2] - data.lineCoordinates[0]);
  8827. line.setAttribute("y1", data.rect[3] - data.lineCoordinates[1]);
  8828. line.setAttribute("x2", data.rect[2] - data.lineCoordinates[2]);
  8829. line.setAttribute("y2", data.rect[3] - data.lineCoordinates[3]);
  8830. line.setAttribute("stroke-width", data.borderStyle.width || 1);
  8831. line.setAttribute("stroke", "transparent");
  8832. svg.appendChild(line);
  8833. this.container.append(svg);
  8834. this._createPopup(line, data);
  8835. return this.container;
  8836. }
  8837. }
  8838. class SquareAnnotationElement extends AnnotationElement {
  8839. constructor(parameters) {
  8840. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8841. super(parameters, {
  8842. isRenderable,
  8843. ignoreBorder: true
  8844. });
  8845. }
  8846. render() {
  8847. this.container.className = "squareAnnotation";
  8848. const data = this.data;
  8849. const width = data.rect[2] - data.rect[0];
  8850. const height = data.rect[3] - data.rect[1];
  8851. const svg = this.svgFactory.create(width, height);
  8852. const borderWidth = data.borderStyle.width;
  8853. const square = this.svgFactory.createElement("svg:rect");
  8854. square.setAttribute("x", borderWidth / 2);
  8855. square.setAttribute("y", borderWidth / 2);
  8856. square.setAttribute("width", width - borderWidth);
  8857. square.setAttribute("height", height - borderWidth);
  8858. square.setAttribute("stroke-width", borderWidth || 1);
  8859. square.setAttribute("stroke", "transparent");
  8860. square.setAttribute("fill", "none");
  8861. svg.appendChild(square);
  8862. this.container.append(svg);
  8863. this._createPopup(square, data);
  8864. return this.container;
  8865. }
  8866. }
  8867. class CircleAnnotationElement extends AnnotationElement {
  8868. constructor(parameters) {
  8869. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8870. super(parameters, {
  8871. isRenderable,
  8872. ignoreBorder: true
  8873. });
  8874. }
  8875. render() {
  8876. this.container.className = "circleAnnotation";
  8877. const data = this.data;
  8878. const width = data.rect[2] - data.rect[0];
  8879. const height = data.rect[3] - data.rect[1];
  8880. const svg = this.svgFactory.create(width, height);
  8881. const borderWidth = data.borderStyle.width;
  8882. const circle = this.svgFactory.createElement("svg:ellipse");
  8883. circle.setAttribute("cx", width / 2);
  8884. circle.setAttribute("cy", height / 2);
  8885. circle.setAttribute("rx", width / 2 - borderWidth / 2);
  8886. circle.setAttribute("ry", height / 2 - borderWidth / 2);
  8887. circle.setAttribute("stroke-width", borderWidth || 1);
  8888. circle.setAttribute("stroke", "transparent");
  8889. circle.setAttribute("fill", "none");
  8890. svg.appendChild(circle);
  8891. this.container.append(svg);
  8892. this._createPopup(circle, data);
  8893. return this.container;
  8894. }
  8895. }
  8896. class PolylineAnnotationElement extends AnnotationElement {
  8897. constructor(parameters) {
  8898. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8899. super(parameters, {
  8900. isRenderable,
  8901. ignoreBorder: true
  8902. });
  8903. this.containerClassName = "polylineAnnotation";
  8904. this.svgElementName = "svg:polyline";
  8905. }
  8906. render() {
  8907. this.container.className = this.containerClassName;
  8908. const data = this.data;
  8909. const width = data.rect[2] - data.rect[0];
  8910. const height = data.rect[3] - data.rect[1];
  8911. const svg = this.svgFactory.create(width, height);
  8912. let points = [];
  8913. for (const coordinate of data.vertices) {
  8914. const x = coordinate.x - data.rect[0];
  8915. const y = data.rect[3] - coordinate.y;
  8916. points.push(x + "," + y);
  8917. }
  8918. points = points.join(" ");
  8919. const polyline = this.svgFactory.createElement(this.svgElementName);
  8920. polyline.setAttribute("points", points);
  8921. polyline.setAttribute("stroke-width", data.borderStyle.width || 1);
  8922. polyline.setAttribute("stroke", "transparent");
  8923. polyline.setAttribute("fill", "none");
  8924. svg.appendChild(polyline);
  8925. this.container.append(svg);
  8926. this._createPopup(polyline, data);
  8927. return this.container;
  8928. }
  8929. }
  8930. class PolygonAnnotationElement extends PolylineAnnotationElement {
  8931. constructor(parameters) {
  8932. super(parameters);
  8933. this.containerClassName = "polygonAnnotation";
  8934. this.svgElementName = "svg:polygon";
  8935. }
  8936. }
  8937. class CaretAnnotationElement extends AnnotationElement {
  8938. constructor(parameters) {
  8939. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8940. super(parameters, {
  8941. isRenderable,
  8942. ignoreBorder: true
  8943. });
  8944. }
  8945. render() {
  8946. this.container.className = "caretAnnotation";
  8947. if (!this.data.hasPopup) {
  8948. this._createPopup(null, this.data);
  8949. }
  8950. return this.container;
  8951. }
  8952. }
  8953. class InkAnnotationElement extends AnnotationElement {
  8954. constructor(parameters) {
  8955. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8956. super(parameters, {
  8957. isRenderable,
  8958. ignoreBorder: true
  8959. });
  8960. this.containerClassName = "inkAnnotation";
  8961. this.svgElementName = "svg:polyline";
  8962. }
  8963. render() {
  8964. this.container.className = this.containerClassName;
  8965. const data = this.data;
  8966. const width = data.rect[2] - data.rect[0];
  8967. const height = data.rect[3] - data.rect[1];
  8968. const svg = this.svgFactory.create(width, height);
  8969. for (const inkList of data.inkLists) {
  8970. let points = [];
  8971. for (const coordinate of inkList) {
  8972. const x = coordinate.x - data.rect[0];
  8973. const y = data.rect[3] - coordinate.y;
  8974. points.push(`${x},${y}`);
  8975. }
  8976. points = points.join(" ");
  8977. const polyline = this.svgFactory.createElement(this.svgElementName);
  8978. polyline.setAttribute("points", points);
  8979. polyline.setAttribute("stroke-width", data.borderStyle.width || 1);
  8980. polyline.setAttribute("stroke", "transparent");
  8981. polyline.setAttribute("fill", "none");
  8982. this._createPopup(polyline, data);
  8983. svg.appendChild(polyline);
  8984. }
  8985. this.container.append(svg);
  8986. return this.container;
  8987. }
  8988. }
  8989. class HighlightAnnotationElement extends AnnotationElement {
  8990. constructor(parameters) {
  8991. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8992. super(parameters, {
  8993. isRenderable,
  8994. ignoreBorder: true,
  8995. createQuadrilaterals: true
  8996. });
  8997. }
  8998. render() {
  8999. if (!this.data.hasPopup) {
  9000. this._createPopup(null, this.data);
  9001. }
  9002. if (this.quadrilaterals) {
  9003. return this._renderQuadrilaterals("highlightAnnotation");
  9004. }
  9005. this.container.className = "highlightAnnotation";
  9006. return this.container;
  9007. }
  9008. }
  9009. class UnderlineAnnotationElement extends AnnotationElement {
  9010. constructor(parameters) {
  9011. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  9012. super(parameters, {
  9013. isRenderable,
  9014. ignoreBorder: true,
  9015. createQuadrilaterals: true
  9016. });
  9017. }
  9018. render() {
  9019. if (!this.data.hasPopup) {
  9020. this._createPopup(null, this.data);
  9021. }
  9022. if (this.quadrilaterals) {
  9023. return this._renderQuadrilaterals("underlineAnnotation");
  9024. }
  9025. this.container.className = "underlineAnnotation";
  9026. return this.container;
  9027. }
  9028. }
  9029. class SquigglyAnnotationElement extends AnnotationElement {
  9030. constructor(parameters) {
  9031. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  9032. super(parameters, {
  9033. isRenderable,
  9034. ignoreBorder: true,
  9035. createQuadrilaterals: true
  9036. });
  9037. }
  9038. render() {
  9039. if (!this.data.hasPopup) {
  9040. this._createPopup(null, this.data);
  9041. }
  9042. if (this.quadrilaterals) {
  9043. return this._renderQuadrilaterals("squigglyAnnotation");
  9044. }
  9045. this.container.className = "squigglyAnnotation";
  9046. return this.container;
  9047. }
  9048. }
  9049. class StrikeOutAnnotationElement extends AnnotationElement {
  9050. constructor(parameters) {
  9051. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  9052. super(parameters, {
  9053. isRenderable,
  9054. ignoreBorder: true,
  9055. createQuadrilaterals: true
  9056. });
  9057. }
  9058. render() {
  9059. if (!this.data.hasPopup) {
  9060. this._createPopup(null, this.data);
  9061. }
  9062. if (this.quadrilaterals) {
  9063. return this._renderQuadrilaterals("strikeoutAnnotation");
  9064. }
  9065. this.container.className = "strikeoutAnnotation";
  9066. return this.container;
  9067. }
  9068. }
  9069. class StampAnnotationElement extends AnnotationElement {
  9070. constructor(parameters) {
  9071. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  9072. super(parameters, {
  9073. isRenderable,
  9074. ignoreBorder: true
  9075. });
  9076. }
  9077. render() {
  9078. this.container.className = "stampAnnotation";
  9079. if (!this.data.hasPopup) {
  9080. this._createPopup(null, this.data);
  9081. }
  9082. return this.container;
  9083. }
  9084. }
  9085. class FileAttachmentAnnotationElement extends AnnotationElement {
  9086. constructor(parameters) {
  9087. super(parameters, {
  9088. isRenderable: true
  9089. });
  9090. const {
  9091. filename,
  9092. content
  9093. } = this.data.file;
  9094. this.filename = (0, _display_utils.getFilenameFromUrl)(filename);
  9095. this.content = content;
  9096. this.linkService.eventBus?.dispatch("fileattachmentannotation", {
  9097. source: this,
  9098. id: (0, _util.stringToPDFString)(filename),
  9099. filename,
  9100. content
  9101. });
  9102. }
  9103. render() {
  9104. this.container.className = "fileAttachmentAnnotation";
  9105. const trigger = document.createElement("div");
  9106. trigger.style.height = this.container.style.height;
  9107. trigger.style.width = this.container.style.width;
  9108. trigger.addEventListener("dblclick", this._download.bind(this));
  9109. if (!this.data.hasPopup && (this.data.title || this.data.contents)) {
  9110. this._createPopup(trigger, this.data);
  9111. }
  9112. this.container.appendChild(trigger);
  9113. return this.container;
  9114. }
  9115. _download() {
  9116. if (!this.downloadManager) {
  9117. (0, _util.warn)("Download cannot be started due to unavailable download manager");
  9118. return;
  9119. }
  9120. this.downloadManager.downloadData(this.content, this.filename, "");
  9121. }
  9122. }
  9123. class AnnotationLayer {
  9124. static render(parameters) {
  9125. const sortedAnnotations = [],
  9126. popupAnnotations = [];
  9127. for (const data of parameters.annotations) {
  9128. if (!data) {
  9129. continue;
  9130. }
  9131. if (data.annotationType === _util.AnnotationType.POPUP) {
  9132. popupAnnotations.push(data);
  9133. continue;
  9134. }
  9135. sortedAnnotations.push(data);
  9136. }
  9137. if (popupAnnotations.length) {
  9138. sortedAnnotations.push(...popupAnnotations);
  9139. }
  9140. for (const data of sortedAnnotations) {
  9141. const element = AnnotationElementFactory.create({
  9142. data,
  9143. layer: parameters.div,
  9144. page: parameters.page,
  9145. viewport: parameters.viewport,
  9146. linkService: parameters.linkService,
  9147. downloadManager: parameters.downloadManager,
  9148. imageResourcesPath: parameters.imageResourcesPath || "",
  9149. renderInteractiveForms: typeof parameters.renderInteractiveForms === "boolean" ? parameters.renderInteractiveForms : true,
  9150. svgFactory: new _display_utils.DOMSVGFactory(),
  9151. annotationStorage: parameters.annotationStorage || new _annotation_storage.AnnotationStorage(),
  9152. enableScripting: parameters.enableScripting,
  9153. hasJSActions: parameters.hasJSActions,
  9154. mouseState: parameters.mouseState || {
  9155. isDown: false
  9156. }
  9157. });
  9158. if (element.isRenderable) {
  9159. const rendered = element.render();
  9160. if (data.hidden) {
  9161. rendered.style.visibility = "hidden";
  9162. }
  9163. if (Array.isArray(rendered)) {
  9164. for (const renderedElement of rendered) {
  9165. parameters.div.appendChild(renderedElement);
  9166. }
  9167. } else {
  9168. if (element instanceof PopupAnnotationElement) {
  9169. parameters.div.prepend(rendered);
  9170. } else {
  9171. parameters.div.appendChild(rendered);
  9172. }
  9173. }
  9174. }
  9175. }
  9176. }
  9177. static update(parameters) {
  9178. const transform = `matrix(${parameters.viewport.transform.join(",")})`;
  9179. for (const data of parameters.annotations) {
  9180. const elements = parameters.div.querySelectorAll(`[data-annotation-id="${data.id}"]`);
  9181. if (elements) {
  9182. elements.forEach(element => {
  9183. element.style.transform = transform;
  9184. });
  9185. }
  9186. }
  9187. parameters.div.removeAttribute("hidden");
  9188. }
  9189. }
  9190. exports.AnnotationLayer = AnnotationLayer;
  9191. /***/ }),
  9192. /* 20 */
  9193. /***/ ((__unused_webpack_module, exports) => {
  9194. Object.defineProperty(exports, "__esModule", ({
  9195. value: true
  9196. }));
  9197. exports.ColorConverters = void 0;
  9198. function makeColorComp(n) {
  9199. return Math.floor(Math.max(0, Math.min(1, n)) * 255).toString(16).padStart(2, "0");
  9200. }
  9201. class ColorConverters {
  9202. static CMYK_G([c, y, m, k]) {
  9203. return ["G", 1 - Math.min(1, 0.3 * c + 0.59 * m + 0.11 * y + k)];
  9204. }
  9205. static G_CMYK([g]) {
  9206. return ["CMYK", 0, 0, 0, 1 - g];
  9207. }
  9208. static G_RGB([g]) {
  9209. return ["RGB", g, g, g];
  9210. }
  9211. static G_HTML([g]) {
  9212. const G = makeColorComp(g);
  9213. return `#${G}${G}${G}`;
  9214. }
  9215. static RGB_G([r, g, b]) {
  9216. return ["G", 0.3 * r + 0.59 * g + 0.11 * b];
  9217. }
  9218. static RGB_HTML([r, g, b]) {
  9219. const R = makeColorComp(r);
  9220. const G = makeColorComp(g);
  9221. const B = makeColorComp(b);
  9222. return `#${R}${G}${B}`;
  9223. }
  9224. static T_HTML() {
  9225. return "#00000000";
  9226. }
  9227. static CMYK_RGB([c, y, m, k]) {
  9228. return ["RGB", 1 - Math.min(1, c + k), 1 - Math.min(1, m + k), 1 - Math.min(1, y + k)];
  9229. }
  9230. static CMYK_HTML(components) {
  9231. return this.RGB_HTML(this.CMYK_RGB(components));
  9232. }
  9233. static RGB_CMYK([r, g, b]) {
  9234. const c = 1 - r;
  9235. const m = 1 - g;
  9236. const y = 1 - b;
  9237. const k = Math.min(c, m, y);
  9238. return ["CMYK", c, m, y, k];
  9239. }
  9240. }
  9241. exports.ColorConverters = ColorConverters;
  9242. /***/ }),
  9243. /* 21 */
  9244. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  9245. Object.defineProperty(exports, "__esModule", ({
  9246. value: true
  9247. }));
  9248. exports.renderTextLayer = void 0;
  9249. var _util = __w_pdfjs_require__(2);
  9250. const renderTextLayer = function renderTextLayerClosure() {
  9251. const MAX_TEXT_DIVS_TO_RENDER = 100000;
  9252. const NonWhitespaceRegexp = /\S/;
  9253. function isAllWhitespace(str) {
  9254. return !NonWhitespaceRegexp.test(str);
  9255. }
  9256. function appendText(task, geom, styles) {
  9257. const textDiv = document.createElement("span");
  9258. const textDivProperties = {
  9259. angle: 0,
  9260. canvasWidth: 0,
  9261. isWhitespace: false,
  9262. originalTransform: null,
  9263. paddingBottom: 0,
  9264. paddingLeft: 0,
  9265. paddingRight: 0,
  9266. paddingTop: 0,
  9267. scale: 1
  9268. };
  9269. task._textDivs.push(textDiv);
  9270. if (isAllWhitespace(geom.str)) {
  9271. textDivProperties.isWhitespace = true;
  9272. task._textDivProperties.set(textDiv, textDivProperties);
  9273. return;
  9274. }
  9275. const tx = _util.Util.transform(task._viewport.transform, geom.transform);
  9276. let angle = Math.atan2(tx[1], tx[0]);
  9277. const style = styles[geom.fontName];
  9278. if (style.vertical) {
  9279. angle += Math.PI / 2;
  9280. }
  9281. const fontHeight = Math.sqrt(tx[2] * tx[2] + tx[3] * tx[3]);
  9282. let fontAscent = fontHeight;
  9283. if (style.ascent) {
  9284. fontAscent = style.ascent * fontAscent;
  9285. } else if (style.descent) {
  9286. fontAscent = (1 + style.descent) * fontAscent;
  9287. }
  9288. let left, top;
  9289. if (angle === 0) {
  9290. left = tx[4];
  9291. top = tx[5] - fontAscent;
  9292. } else {
  9293. left = tx[4] + fontAscent * Math.sin(angle);
  9294. top = tx[5] - fontAscent * Math.cos(angle);
  9295. }
  9296. textDiv.style.left = `${left}px`;
  9297. textDiv.style.top = `${top}px`;
  9298. textDiv.style.fontSize = `${fontHeight}px`;
  9299. textDiv.style.fontFamily = style.fontFamily;
  9300. textDiv.textContent = geom.str;
  9301. if (task._fontInspectorEnabled) {
  9302. textDiv.dataset.fontName = geom.fontName;
  9303. }
  9304. if (angle !== 0) {
  9305. textDivProperties.angle = angle * (180 / Math.PI);
  9306. }
  9307. let shouldScaleText = false;
  9308. if (geom.str.length > 1) {
  9309. shouldScaleText = true;
  9310. } else if (geom.transform[0] !== geom.transform[3]) {
  9311. const absScaleX = Math.abs(geom.transform[0]),
  9312. absScaleY = Math.abs(geom.transform[3]);
  9313. if (absScaleX !== absScaleY && Math.max(absScaleX, absScaleY) / Math.min(absScaleX, absScaleY) > 1.5) {
  9314. shouldScaleText = true;
  9315. }
  9316. }
  9317. if (shouldScaleText) {
  9318. if (style.vertical) {
  9319. textDivProperties.canvasWidth = geom.height * task._viewport.scale;
  9320. } else {
  9321. textDivProperties.canvasWidth = geom.width * task._viewport.scale;
  9322. }
  9323. }
  9324. task._textDivProperties.set(textDiv, textDivProperties);
  9325. if (task._textContentStream) {
  9326. task._layoutText(textDiv);
  9327. }
  9328. if (task._enhanceTextSelection) {
  9329. let angleCos = 1,
  9330. angleSin = 0;
  9331. if (angle !== 0) {
  9332. angleCos = Math.cos(angle);
  9333. angleSin = Math.sin(angle);
  9334. }
  9335. const divWidth = (style.vertical ? geom.height : geom.width) * task._viewport.scale;
  9336. const divHeight = fontHeight;
  9337. let m, b;
  9338. if (angle !== 0) {
  9339. m = [angleCos, angleSin, -angleSin, angleCos, left, top];
  9340. b = _util.Util.getAxialAlignedBoundingBox([0, 0, divWidth, divHeight], m);
  9341. } else {
  9342. b = [left, top, left + divWidth, top + divHeight];
  9343. }
  9344. task._bounds.push({
  9345. left: b[0],
  9346. top: b[1],
  9347. right: b[2],
  9348. bottom: b[3],
  9349. div: textDiv,
  9350. size: [divWidth, divHeight],
  9351. m
  9352. });
  9353. }
  9354. }
  9355. function render(task) {
  9356. if (task._canceled) {
  9357. return;
  9358. }
  9359. const textDivs = task._textDivs;
  9360. const capability = task._capability;
  9361. const textDivsLength = textDivs.length;
  9362. if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
  9363. task._renderingDone = true;
  9364. capability.resolve();
  9365. return;
  9366. }
  9367. if (!task._textContentStream) {
  9368. for (let i = 0; i < textDivsLength; i++) {
  9369. task._layoutText(textDivs[i]);
  9370. }
  9371. }
  9372. task._renderingDone = true;
  9373. capability.resolve();
  9374. }
  9375. function findPositiveMin(ts, offset, count) {
  9376. let result = 0;
  9377. for (let i = 0; i < count; i++) {
  9378. const t = ts[offset++];
  9379. if (t > 0) {
  9380. result = result ? Math.min(t, result) : t;
  9381. }
  9382. }
  9383. return result;
  9384. }
  9385. function expand(task) {
  9386. const bounds = task._bounds;
  9387. const viewport = task._viewport;
  9388. const expanded = expandBounds(viewport.width, viewport.height, bounds);
  9389. for (let i = 0; i < expanded.length; i++) {
  9390. const div = bounds[i].div;
  9391. const divProperties = task._textDivProperties.get(div);
  9392. if (divProperties.angle === 0) {
  9393. divProperties.paddingLeft = bounds[i].left - expanded[i].left;
  9394. divProperties.paddingTop = bounds[i].top - expanded[i].top;
  9395. divProperties.paddingRight = expanded[i].right - bounds[i].right;
  9396. divProperties.paddingBottom = expanded[i].bottom - bounds[i].bottom;
  9397. task._textDivProperties.set(div, divProperties);
  9398. continue;
  9399. }
  9400. const e = expanded[i],
  9401. b = bounds[i];
  9402. const m = b.m,
  9403. c = m[0],
  9404. s = m[1];
  9405. const points = [[0, 0], [0, b.size[1]], [b.size[0], 0], b.size];
  9406. const ts = new Float64Array(64);
  9407. points.forEach(function (p, j) {
  9408. const t = _util.Util.applyTransform(p, m);
  9409. ts[j + 0] = c && (e.left - t[0]) / c;
  9410. ts[j + 4] = s && (e.top - t[1]) / s;
  9411. ts[j + 8] = c && (e.right - t[0]) / c;
  9412. ts[j + 12] = s && (e.bottom - t[1]) / s;
  9413. ts[j + 16] = s && (e.left - t[0]) / -s;
  9414. ts[j + 20] = c && (e.top - t[1]) / c;
  9415. ts[j + 24] = s && (e.right - t[0]) / -s;
  9416. ts[j + 28] = c && (e.bottom - t[1]) / c;
  9417. ts[j + 32] = c && (e.left - t[0]) / -c;
  9418. ts[j + 36] = s && (e.top - t[1]) / -s;
  9419. ts[j + 40] = c && (e.right - t[0]) / -c;
  9420. ts[j + 44] = s && (e.bottom - t[1]) / -s;
  9421. ts[j + 48] = s && (e.left - t[0]) / s;
  9422. ts[j + 52] = c && (e.top - t[1]) / -c;
  9423. ts[j + 56] = s && (e.right - t[0]) / s;
  9424. ts[j + 60] = c && (e.bottom - t[1]) / -c;
  9425. });
  9426. const boxScale = 1 + Math.min(Math.abs(c), Math.abs(s));
  9427. divProperties.paddingLeft = findPositiveMin(ts, 32, 16) / boxScale;
  9428. divProperties.paddingTop = findPositiveMin(ts, 48, 16) / boxScale;
  9429. divProperties.paddingRight = findPositiveMin(ts, 0, 16) / boxScale;
  9430. divProperties.paddingBottom = findPositiveMin(ts, 16, 16) / boxScale;
  9431. task._textDivProperties.set(div, divProperties);
  9432. }
  9433. }
  9434. function expandBounds(width, height, boxes) {
  9435. const bounds = boxes.map(function (box, i) {
  9436. return {
  9437. x1: box.left,
  9438. y1: box.top,
  9439. x2: box.right,
  9440. y2: box.bottom,
  9441. index: i,
  9442. x1New: undefined,
  9443. x2New: undefined
  9444. };
  9445. });
  9446. expandBoundsLTR(width, bounds);
  9447. const expanded = new Array(boxes.length);
  9448. bounds.forEach(function (b) {
  9449. const i = b.index;
  9450. expanded[i] = {
  9451. left: b.x1New,
  9452. top: 0,
  9453. right: b.x2New,
  9454. bottom: 0
  9455. };
  9456. });
  9457. boxes.map(function (box, i) {
  9458. const e = expanded[i],
  9459. b = bounds[i];
  9460. b.x1 = box.top;
  9461. b.y1 = width - e.right;
  9462. b.x2 = box.bottom;
  9463. b.y2 = width - e.left;
  9464. b.index = i;
  9465. b.x1New = undefined;
  9466. b.x2New = undefined;
  9467. });
  9468. expandBoundsLTR(height, bounds);
  9469. bounds.forEach(function (b) {
  9470. const i = b.index;
  9471. expanded[i].top = b.x1New;
  9472. expanded[i].bottom = b.x2New;
  9473. });
  9474. return expanded;
  9475. }
  9476. function expandBoundsLTR(width, bounds) {
  9477. bounds.sort(function (a, b) {
  9478. return a.x1 - b.x1 || a.index - b.index;
  9479. });
  9480. const fakeBoundary = {
  9481. x1: -Infinity,
  9482. y1: -Infinity,
  9483. x2: 0,
  9484. y2: Infinity,
  9485. index: -1,
  9486. x1New: 0,
  9487. x2New: 0
  9488. };
  9489. const horizon = [{
  9490. start: -Infinity,
  9491. end: Infinity,
  9492. boundary: fakeBoundary
  9493. }];
  9494. bounds.forEach(function (boundary) {
  9495. let i = 0;
  9496. while (i < horizon.length && horizon[i].end <= boundary.y1) {
  9497. i++;
  9498. }
  9499. let j = horizon.length - 1;
  9500. while (j >= 0 && horizon[j].start >= boundary.y2) {
  9501. j--;
  9502. }
  9503. let horizonPart, affectedBoundary;
  9504. let q,
  9505. k,
  9506. maxXNew = -Infinity;
  9507. for (q = i; q <= j; q++) {
  9508. horizonPart = horizon[q];
  9509. affectedBoundary = horizonPart.boundary;
  9510. let xNew;
  9511. if (affectedBoundary.x2 > boundary.x1) {
  9512. xNew = affectedBoundary.index > boundary.index ? affectedBoundary.x1New : boundary.x1;
  9513. } else if (affectedBoundary.x2New === undefined) {
  9514. xNew = (affectedBoundary.x2 + boundary.x1) / 2;
  9515. } else {
  9516. xNew = affectedBoundary.x2New;
  9517. }
  9518. if (xNew > maxXNew) {
  9519. maxXNew = xNew;
  9520. }
  9521. }
  9522. boundary.x1New = maxXNew;
  9523. for (q = i; q <= j; q++) {
  9524. horizonPart = horizon[q];
  9525. affectedBoundary = horizonPart.boundary;
  9526. if (affectedBoundary.x2New === undefined) {
  9527. if (affectedBoundary.x2 > boundary.x1) {
  9528. if (affectedBoundary.index > boundary.index) {
  9529. affectedBoundary.x2New = affectedBoundary.x2;
  9530. }
  9531. } else {
  9532. affectedBoundary.x2New = maxXNew;
  9533. }
  9534. } else if (affectedBoundary.x2New > maxXNew) {
  9535. affectedBoundary.x2New = Math.max(maxXNew, affectedBoundary.x2);
  9536. }
  9537. }
  9538. const changedHorizon = [];
  9539. let lastBoundary = null;
  9540. for (q = i; q <= j; q++) {
  9541. horizonPart = horizon[q];
  9542. affectedBoundary = horizonPart.boundary;
  9543. const useBoundary = affectedBoundary.x2 > boundary.x2 ? affectedBoundary : boundary;
  9544. if (lastBoundary === useBoundary) {
  9545. changedHorizon[changedHorizon.length - 1].end = horizonPart.end;
  9546. } else {
  9547. changedHorizon.push({
  9548. start: horizonPart.start,
  9549. end: horizonPart.end,
  9550. boundary: useBoundary
  9551. });
  9552. lastBoundary = useBoundary;
  9553. }
  9554. }
  9555. if (horizon[i].start < boundary.y1) {
  9556. changedHorizon[0].start = boundary.y1;
  9557. changedHorizon.unshift({
  9558. start: horizon[i].start,
  9559. end: boundary.y1,
  9560. boundary: horizon[i].boundary
  9561. });
  9562. }
  9563. if (boundary.y2 < horizon[j].end) {
  9564. changedHorizon[changedHorizon.length - 1].end = boundary.y2;
  9565. changedHorizon.push({
  9566. start: boundary.y2,
  9567. end: horizon[j].end,
  9568. boundary: horizon[j].boundary
  9569. });
  9570. }
  9571. for (q = i; q <= j; q++) {
  9572. horizonPart = horizon[q];
  9573. affectedBoundary = horizonPart.boundary;
  9574. if (affectedBoundary.x2New !== undefined) {
  9575. continue;
  9576. }
  9577. let used = false;
  9578. for (k = i - 1; !used && k >= 0 && horizon[k].start >= affectedBoundary.y1; k--) {
  9579. used = horizon[k].boundary === affectedBoundary;
  9580. }
  9581. for (k = j + 1; !used && k < horizon.length && horizon[k].end <= affectedBoundary.y2; k++) {
  9582. used = horizon[k].boundary === affectedBoundary;
  9583. }
  9584. for (k = 0; !used && k < changedHorizon.length; k++) {
  9585. used = changedHorizon[k].boundary === affectedBoundary;
  9586. }
  9587. if (!used) {
  9588. affectedBoundary.x2New = maxXNew;
  9589. }
  9590. }
  9591. Array.prototype.splice.apply(horizon, [i, j - i + 1].concat(changedHorizon));
  9592. });
  9593. horizon.forEach(function (horizonPart) {
  9594. const affectedBoundary = horizonPart.boundary;
  9595. if (affectedBoundary.x2New === undefined) {
  9596. affectedBoundary.x2New = Math.max(width, affectedBoundary.x2);
  9597. }
  9598. });
  9599. }
  9600. function TextLayerRenderTask({
  9601. textContent,
  9602. textContentStream,
  9603. container,
  9604. viewport,
  9605. textDivs,
  9606. textContentItemsStr,
  9607. enhanceTextSelection
  9608. }) {
  9609. this._textContent = textContent;
  9610. this._textContentStream = textContentStream;
  9611. this._container = container;
  9612. this._document = container.ownerDocument;
  9613. this._viewport = viewport;
  9614. this._textDivs = textDivs || [];
  9615. this._textContentItemsStr = textContentItemsStr || [];
  9616. this._enhanceTextSelection = !!enhanceTextSelection;
  9617. this._fontInspectorEnabled = !!globalThis.FontInspector?.enabled;
  9618. this._reader = null;
  9619. this._layoutTextLastFontSize = null;
  9620. this._layoutTextLastFontFamily = null;
  9621. this._layoutTextCtx = null;
  9622. this._textDivProperties = new WeakMap();
  9623. this._renderingDone = false;
  9624. this._canceled = false;
  9625. this._capability = (0, _util.createPromiseCapability)();
  9626. this._renderTimer = null;
  9627. this._bounds = [];
  9628. this._capability.promise.finally(() => {
  9629. if (this._layoutTextCtx) {
  9630. this._layoutTextCtx.canvas.width = 0;
  9631. this._layoutTextCtx.canvas.height = 0;
  9632. this._layoutTextCtx = null;
  9633. }
  9634. }).catch(() => {});
  9635. }
  9636. TextLayerRenderTask.prototype = {
  9637. get promise() {
  9638. return this._capability.promise;
  9639. },
  9640. cancel: function TextLayer_cancel() {
  9641. this._canceled = true;
  9642. if (this._reader) {
  9643. this._reader.cancel(new _util.AbortException("TextLayer task cancelled."));
  9644. this._reader = null;
  9645. }
  9646. if (this._renderTimer !== null) {
  9647. clearTimeout(this._renderTimer);
  9648. this._renderTimer = null;
  9649. }
  9650. this._capability.reject(new Error("TextLayer task cancelled."));
  9651. },
  9652. _processItems(items, styleCache) {
  9653. for (let i = 0, len = items.length; i < len; i++) {
  9654. this._textContentItemsStr.push(items[i].str);
  9655. appendText(this, items[i], styleCache);
  9656. }
  9657. },
  9658. _layoutText(textDiv) {
  9659. const textDivProperties = this._textDivProperties.get(textDiv);
  9660. if (textDivProperties.isWhitespace) {
  9661. return;
  9662. }
  9663. let transform = "";
  9664. if (textDivProperties.canvasWidth !== 0) {
  9665. const {
  9666. fontSize,
  9667. fontFamily
  9668. } = textDiv.style;
  9669. if (fontSize !== this._layoutTextLastFontSize || fontFamily !== this._layoutTextLastFontFamily) {
  9670. this._layoutTextCtx.font = `${fontSize} ${fontFamily}`;
  9671. this._layoutTextLastFontSize = fontSize;
  9672. this._layoutTextLastFontFamily = fontFamily;
  9673. }
  9674. const {
  9675. width
  9676. } = this._layoutTextCtx.measureText(textDiv.textContent);
  9677. if (width > 0) {
  9678. textDivProperties.scale = textDivProperties.canvasWidth / width;
  9679. transform = `scaleX(${textDivProperties.scale})`;
  9680. }
  9681. }
  9682. if (textDivProperties.angle !== 0) {
  9683. transform = `rotate(${textDivProperties.angle}deg) ${transform}`;
  9684. }
  9685. if (transform.length > 0) {
  9686. if (this._enhanceTextSelection) {
  9687. textDivProperties.originalTransform = transform;
  9688. }
  9689. textDiv.style.transform = transform;
  9690. }
  9691. this._textDivProperties.set(textDiv, textDivProperties);
  9692. this._container.appendChild(textDiv);
  9693. },
  9694. _render: function TextLayer_render(timeout) {
  9695. const capability = (0, _util.createPromiseCapability)();
  9696. let styleCache = Object.create(null);
  9697. const canvas = this._document.createElement("canvas");
  9698. canvas.mozOpaque = true;
  9699. this._layoutTextCtx = canvas.getContext("2d", {
  9700. alpha: false
  9701. });
  9702. if (this._textContent) {
  9703. const textItems = this._textContent.items;
  9704. const textStyles = this._textContent.styles;
  9705. this._processItems(textItems, textStyles);
  9706. capability.resolve();
  9707. } else if (this._textContentStream) {
  9708. const pump = () => {
  9709. this._reader.read().then(({
  9710. value,
  9711. done
  9712. }) => {
  9713. if (done) {
  9714. capability.resolve();
  9715. return;
  9716. }
  9717. Object.assign(styleCache, value.styles);
  9718. this._processItems(value.items, styleCache);
  9719. pump();
  9720. }, capability.reject);
  9721. };
  9722. this._reader = this._textContentStream.getReader();
  9723. pump();
  9724. } else {
  9725. throw new Error('Neither "textContent" nor "textContentStream"' + " parameters specified.");
  9726. }
  9727. capability.promise.then(() => {
  9728. styleCache = null;
  9729. if (!timeout) {
  9730. render(this);
  9731. } else {
  9732. this._renderTimer = setTimeout(() => {
  9733. render(this);
  9734. this._renderTimer = null;
  9735. }, timeout);
  9736. }
  9737. }, this._capability.reject);
  9738. },
  9739. expandTextDivs: function TextLayer_expandTextDivs(expandDivs) {
  9740. if (!this._enhanceTextSelection || !this._renderingDone) {
  9741. return;
  9742. }
  9743. if (this._bounds !== null) {
  9744. expand(this);
  9745. this._bounds = null;
  9746. }
  9747. const transformBuf = [],
  9748. paddingBuf = [];
  9749. for (let i = 0, ii = this._textDivs.length; i < ii; i++) {
  9750. const div = this._textDivs[i];
  9751. const divProps = this._textDivProperties.get(div);
  9752. if (divProps.isWhitespace) {
  9753. continue;
  9754. }
  9755. if (expandDivs) {
  9756. transformBuf.length = 0;
  9757. paddingBuf.length = 0;
  9758. if (divProps.originalTransform) {
  9759. transformBuf.push(divProps.originalTransform);
  9760. }
  9761. if (divProps.paddingTop > 0) {
  9762. paddingBuf.push(`${divProps.paddingTop}px`);
  9763. transformBuf.push(`translateY(${-divProps.paddingTop}px)`);
  9764. } else {
  9765. paddingBuf.push(0);
  9766. }
  9767. if (divProps.paddingRight > 0) {
  9768. paddingBuf.push(`${divProps.paddingRight / divProps.scale}px`);
  9769. } else {
  9770. paddingBuf.push(0);
  9771. }
  9772. if (divProps.paddingBottom > 0) {
  9773. paddingBuf.push(`${divProps.paddingBottom}px`);
  9774. } else {
  9775. paddingBuf.push(0);
  9776. }
  9777. if (divProps.paddingLeft > 0) {
  9778. paddingBuf.push(`${divProps.paddingLeft / divProps.scale}px`);
  9779. transformBuf.push(`translateX(${-divProps.paddingLeft / divProps.scale}px)`);
  9780. } else {
  9781. paddingBuf.push(0);
  9782. }
  9783. div.style.padding = paddingBuf.join(" ");
  9784. if (transformBuf.length) {
  9785. div.style.transform = transformBuf.join(" ");
  9786. }
  9787. } else {
  9788. div.style.padding = null;
  9789. div.style.transform = divProps.originalTransform;
  9790. }
  9791. }
  9792. }
  9793. };
  9794. function renderTextLayer(renderParameters) {
  9795. const task = new TextLayerRenderTask({
  9796. textContent: renderParameters.textContent,
  9797. textContentStream: renderParameters.textContentStream,
  9798. container: renderParameters.container,
  9799. viewport: renderParameters.viewport,
  9800. textDivs: renderParameters.textDivs,
  9801. textContentItemsStr: renderParameters.textContentItemsStr,
  9802. enhanceTextSelection: renderParameters.enhanceTextSelection
  9803. });
  9804. task._render(renderParameters.timeout);
  9805. return task;
  9806. }
  9807. return renderTextLayer;
  9808. }();
  9809. exports.renderTextLayer = renderTextLayer;
  9810. /***/ }),
  9811. /* 22 */
  9812. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  9813. Object.defineProperty(exports, "__esModule", ({
  9814. value: true
  9815. }));
  9816. exports.SVGGraphics = void 0;
  9817. var _util = __w_pdfjs_require__(2);
  9818. var _display_utils = __w_pdfjs_require__(1);
  9819. var _is_node = __w_pdfjs_require__(4);
  9820. let SVGGraphics = function () {
  9821. throw new Error("Not implemented: SVGGraphics");
  9822. };
  9823. exports.SVGGraphics = SVGGraphics;
  9824. {
  9825. const SVG_DEFAULTS = {
  9826. fontStyle: "normal",
  9827. fontWeight: "normal",
  9828. fillColor: "#000000"
  9829. };
  9830. const XML_NS = "http://www.w3.org/XML/1998/namespace";
  9831. const XLINK_NS = "http://www.w3.org/1999/xlink";
  9832. const LINE_CAP_STYLES = ["butt", "round", "square"];
  9833. const LINE_JOIN_STYLES = ["miter", "round", "bevel"];
  9834. const convertImgDataToPng = function () {
  9835. const PNG_HEADER = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  9836. const CHUNK_WRAPPER_SIZE = 12;
  9837. const crcTable = new Int32Array(256);
  9838. for (let i = 0; i < 256; i++) {
  9839. let c = i;
  9840. for (let h = 0; h < 8; h++) {
  9841. if (c & 1) {
  9842. c = 0xedb88320 ^ c >> 1 & 0x7fffffff;
  9843. } else {
  9844. c = c >> 1 & 0x7fffffff;
  9845. }
  9846. }
  9847. crcTable[i] = c;
  9848. }
  9849. function crc32(data, start, end) {
  9850. let crc = -1;
  9851. for (let i = start; i < end; i++) {
  9852. const a = (crc ^ data[i]) & 0xff;
  9853. const b = crcTable[a];
  9854. crc = crc >>> 8 ^ b;
  9855. }
  9856. return crc ^ -1;
  9857. }
  9858. function writePngChunk(type, body, data, offset) {
  9859. let p = offset;
  9860. const len = body.length;
  9861. data[p] = len >> 24 & 0xff;
  9862. data[p + 1] = len >> 16 & 0xff;
  9863. data[p + 2] = len >> 8 & 0xff;
  9864. data[p + 3] = len & 0xff;
  9865. p += 4;
  9866. data[p] = type.charCodeAt(0) & 0xff;
  9867. data[p + 1] = type.charCodeAt(1) & 0xff;
  9868. data[p + 2] = type.charCodeAt(2) & 0xff;
  9869. data[p + 3] = type.charCodeAt(3) & 0xff;
  9870. p += 4;
  9871. data.set(body, p);
  9872. p += body.length;
  9873. const crc = crc32(data, offset + 4, p);
  9874. data[p] = crc >> 24 & 0xff;
  9875. data[p + 1] = crc >> 16 & 0xff;
  9876. data[p + 2] = crc >> 8 & 0xff;
  9877. data[p + 3] = crc & 0xff;
  9878. }
  9879. function adler32(data, start, end) {
  9880. let a = 1;
  9881. let b = 0;
  9882. for (let i = start; i < end; ++i) {
  9883. a = (a + (data[i] & 0xff)) % 65521;
  9884. b = (b + a) % 65521;
  9885. }
  9886. return b << 16 | a;
  9887. }
  9888. function deflateSync(literals) {
  9889. if (!_is_node.isNodeJS) {
  9890. return deflateSyncUncompressed(literals);
  9891. }
  9892. try {
  9893. let input;
  9894. if (parseInt(process.versions.node) >= 8) {
  9895. input = literals;
  9896. } else {
  9897. input = Buffer.from(literals);
  9898. }
  9899. const output = require("zlib").deflateSync(input, {
  9900. level: 9
  9901. });
  9902. return output instanceof Uint8Array ? output : new Uint8Array(output);
  9903. } catch (e) {
  9904. (0, _util.warn)("Not compressing PNG because zlib.deflateSync is unavailable: " + e);
  9905. }
  9906. return deflateSyncUncompressed(literals);
  9907. }
  9908. function deflateSyncUncompressed(literals) {
  9909. let len = literals.length;
  9910. const maxBlockLength = 0xffff;
  9911. const deflateBlocks = Math.ceil(len / maxBlockLength);
  9912. const idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  9913. let pi = 0;
  9914. idat[pi++] = 0x78;
  9915. idat[pi++] = 0x9c;
  9916. let pos = 0;
  9917. while (len > maxBlockLength) {
  9918. idat[pi++] = 0x00;
  9919. idat[pi++] = 0xff;
  9920. idat[pi++] = 0xff;
  9921. idat[pi++] = 0x00;
  9922. idat[pi++] = 0x00;
  9923. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  9924. pi += maxBlockLength;
  9925. pos += maxBlockLength;
  9926. len -= maxBlockLength;
  9927. }
  9928. idat[pi++] = 0x01;
  9929. idat[pi++] = len & 0xff;
  9930. idat[pi++] = len >> 8 & 0xff;
  9931. idat[pi++] = ~len & 0xffff & 0xff;
  9932. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  9933. idat.set(literals.subarray(pos), pi);
  9934. pi += literals.length - pos;
  9935. const adler = adler32(literals, 0, literals.length);
  9936. idat[pi++] = adler >> 24 & 0xff;
  9937. idat[pi++] = adler >> 16 & 0xff;
  9938. idat[pi++] = adler >> 8 & 0xff;
  9939. idat[pi++] = adler & 0xff;
  9940. return idat;
  9941. }
  9942. function encode(imgData, kind, forceDataSchema, isMask) {
  9943. const width = imgData.width;
  9944. const height = imgData.height;
  9945. let bitDepth, colorType, lineSize;
  9946. const bytes = imgData.data;
  9947. switch (kind) {
  9948. case _util.ImageKind.GRAYSCALE_1BPP:
  9949. colorType = 0;
  9950. bitDepth = 1;
  9951. lineSize = width + 7 >> 3;
  9952. break;
  9953. case _util.ImageKind.RGB_24BPP:
  9954. colorType = 2;
  9955. bitDepth = 8;
  9956. lineSize = width * 3;
  9957. break;
  9958. case _util.ImageKind.RGBA_32BPP:
  9959. colorType = 6;
  9960. bitDepth = 8;
  9961. lineSize = width * 4;
  9962. break;
  9963. default:
  9964. throw new Error("invalid format");
  9965. }
  9966. const literals = new Uint8Array((1 + lineSize) * height);
  9967. let offsetLiterals = 0,
  9968. offsetBytes = 0;
  9969. for (let y = 0; y < height; ++y) {
  9970. literals[offsetLiterals++] = 0;
  9971. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize), offsetLiterals);
  9972. offsetBytes += lineSize;
  9973. offsetLiterals += lineSize;
  9974. }
  9975. if (kind === _util.ImageKind.GRAYSCALE_1BPP && isMask) {
  9976. offsetLiterals = 0;
  9977. for (let y = 0; y < height; y++) {
  9978. offsetLiterals++;
  9979. for (let i = 0; i < lineSize; i++) {
  9980. literals[offsetLiterals++] ^= 0xff;
  9981. }
  9982. }
  9983. }
  9984. 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]);
  9985. const idat = deflateSync(literals);
  9986. const pngLength = PNG_HEADER.length + CHUNK_WRAPPER_SIZE * 3 + ihdr.length + idat.length;
  9987. const data = new Uint8Array(pngLength);
  9988. let offset = 0;
  9989. data.set(PNG_HEADER, offset);
  9990. offset += PNG_HEADER.length;
  9991. writePngChunk("IHDR", ihdr, data, offset);
  9992. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  9993. writePngChunk("IDATA", idat, data, offset);
  9994. offset += CHUNK_WRAPPER_SIZE + idat.length;
  9995. writePngChunk("IEND", new Uint8Array(0), data, offset);
  9996. return (0, _util.createObjectURL)(data, "image/png", forceDataSchema);
  9997. }
  9998. return function convertImgDataToPng(imgData, forceDataSchema, isMask) {
  9999. const kind = imgData.kind === undefined ? _util.ImageKind.GRAYSCALE_1BPP : imgData.kind;
  10000. return encode(imgData, kind, forceDataSchema, isMask);
  10001. };
  10002. }();
  10003. class SVGExtraState {
  10004. constructor() {
  10005. this.fontSizeScale = 1;
  10006. this.fontWeight = SVG_DEFAULTS.fontWeight;
  10007. this.fontSize = 0;
  10008. this.textMatrix = _util.IDENTITY_MATRIX;
  10009. this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
  10010. this.leading = 0;
  10011. this.textRenderingMode = _util.TextRenderingMode.FILL;
  10012. this.textMatrixScale = 1;
  10013. this.x = 0;
  10014. this.y = 0;
  10015. this.lineX = 0;
  10016. this.lineY = 0;
  10017. this.charSpacing = 0;
  10018. this.wordSpacing = 0;
  10019. this.textHScale = 1;
  10020. this.textRise = 0;
  10021. this.fillColor = SVG_DEFAULTS.fillColor;
  10022. this.strokeColor = "#000000";
  10023. this.fillAlpha = 1;
  10024. this.strokeAlpha = 1;
  10025. this.lineWidth = 1;
  10026. this.lineJoin = "";
  10027. this.lineCap = "";
  10028. this.miterLimit = 0;
  10029. this.dashArray = [];
  10030. this.dashPhase = 0;
  10031. this.dependencies = [];
  10032. this.activeClipUrl = null;
  10033. this.clipGroup = null;
  10034. this.maskId = "";
  10035. }
  10036. clone() {
  10037. return Object.create(this);
  10038. }
  10039. setCurrentPoint(x, y) {
  10040. this.x = x;
  10041. this.y = y;
  10042. }
  10043. }
  10044. function opListToTree(opList) {
  10045. let opTree = [];
  10046. const tmp = [];
  10047. for (const opListElement of opList) {
  10048. if (opListElement.fn === "save") {
  10049. opTree.push({
  10050. fnId: 92,
  10051. fn: "group",
  10052. items: []
  10053. });
  10054. tmp.push(opTree);
  10055. opTree = opTree[opTree.length - 1].items;
  10056. continue;
  10057. }
  10058. if (opListElement.fn === "restore") {
  10059. opTree = tmp.pop();
  10060. } else {
  10061. opTree.push(opListElement);
  10062. }
  10063. }
  10064. return opTree;
  10065. }
  10066. function pf(value) {
  10067. if (Number.isInteger(value)) {
  10068. return value.toString();
  10069. }
  10070. const s = value.toFixed(10);
  10071. let i = s.length - 1;
  10072. if (s[i] !== "0") {
  10073. return s;
  10074. }
  10075. do {
  10076. i--;
  10077. } while (s[i] === "0");
  10078. return s.substring(0, s[i] === "." ? i : i + 1);
  10079. }
  10080. function pm(m) {
  10081. if (m[4] === 0 && m[5] === 0) {
  10082. if (m[1] === 0 && m[2] === 0) {
  10083. if (m[0] === 1 && m[3] === 1) {
  10084. return "";
  10085. }
  10086. return `scale(${pf(m[0])} ${pf(m[3])})`;
  10087. }
  10088. if (m[0] === m[3] && m[1] === -m[2]) {
  10089. const a = Math.acos(m[0]) * 180 / Math.PI;
  10090. return `rotate(${pf(a)})`;
  10091. }
  10092. } else {
  10093. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  10094. return `translate(${pf(m[4])} ${pf(m[5])})`;
  10095. }
  10096. }
  10097. return `matrix(${pf(m[0])} ${pf(m[1])} ${pf(m[2])} ${pf(m[3])} ${pf(m[4])} ` + `${pf(m[5])})`;
  10098. }
  10099. let clipCount = 0;
  10100. let maskCount = 0;
  10101. let shadingCount = 0;
  10102. exports.SVGGraphics = SVGGraphics = class SVGGraphics {
  10103. constructor(commonObjs, objs, forceDataSchema = false) {
  10104. this.svgFactory = new _display_utils.DOMSVGFactory();
  10105. this.current = new SVGExtraState();
  10106. this.transformMatrix = _util.IDENTITY_MATRIX;
  10107. this.transformStack = [];
  10108. this.extraStack = [];
  10109. this.commonObjs = commonObjs;
  10110. this.objs = objs;
  10111. this.pendingClip = null;
  10112. this.pendingEOFill = false;
  10113. this.embedFonts = false;
  10114. this.embeddedFonts = Object.create(null);
  10115. this.cssStyle = null;
  10116. this.forceDataSchema = !!forceDataSchema;
  10117. this._operatorIdMapping = [];
  10118. for (const op in _util.OPS) {
  10119. this._operatorIdMapping[_util.OPS[op]] = op;
  10120. }
  10121. }
  10122. save() {
  10123. this.transformStack.push(this.transformMatrix);
  10124. const old = this.current;
  10125. this.extraStack.push(old);
  10126. this.current = old.clone();
  10127. }
  10128. restore() {
  10129. this.transformMatrix = this.transformStack.pop();
  10130. this.current = this.extraStack.pop();
  10131. this.pendingClip = null;
  10132. this.tgrp = null;
  10133. }
  10134. group(items) {
  10135. this.save();
  10136. this.executeOpTree(items);
  10137. this.restore();
  10138. }
  10139. loadDependencies(operatorList) {
  10140. const fnArray = operatorList.fnArray;
  10141. const argsArray = operatorList.argsArray;
  10142. for (let i = 0, ii = fnArray.length; i < ii; i++) {
  10143. if (fnArray[i] !== _util.OPS.dependency) {
  10144. continue;
  10145. }
  10146. for (const obj of argsArray[i]) {
  10147. const objsPool = obj.startsWith("g_") ? this.commonObjs : this.objs;
  10148. const promise = new Promise(resolve => {
  10149. objsPool.get(obj, resolve);
  10150. });
  10151. this.current.dependencies.push(promise);
  10152. }
  10153. }
  10154. return Promise.all(this.current.dependencies);
  10155. }
  10156. transform(a, b, c, d, e, f) {
  10157. const transformMatrix = [a, b, c, d, e, f];
  10158. this.transformMatrix = _util.Util.transform(this.transformMatrix, transformMatrix);
  10159. this.tgrp = null;
  10160. }
  10161. getSVG(operatorList, viewport) {
  10162. this.viewport = viewport;
  10163. const svgElement = this._initialize(viewport);
  10164. return this.loadDependencies(operatorList).then(() => {
  10165. this.transformMatrix = _util.IDENTITY_MATRIX;
  10166. this.executeOpTree(this.convertOpList(operatorList));
  10167. return svgElement;
  10168. });
  10169. }
  10170. convertOpList(operatorList) {
  10171. const operatorIdMapping = this._operatorIdMapping;
  10172. const argsArray = operatorList.argsArray;
  10173. const fnArray = operatorList.fnArray;
  10174. const opList = [];
  10175. for (let i = 0, ii = fnArray.length; i < ii; i++) {
  10176. const fnId = fnArray[i];
  10177. opList.push({
  10178. fnId,
  10179. fn: operatorIdMapping[fnId],
  10180. args: argsArray[i]
  10181. });
  10182. }
  10183. return opListToTree(opList);
  10184. }
  10185. executeOpTree(opTree) {
  10186. for (const opTreeElement of opTree) {
  10187. const fn = opTreeElement.fn;
  10188. const fnId = opTreeElement.fnId;
  10189. const args = opTreeElement.args;
  10190. switch (fnId | 0) {
  10191. case _util.OPS.beginText:
  10192. this.beginText();
  10193. break;
  10194. case _util.OPS.dependency:
  10195. break;
  10196. case _util.OPS.setLeading:
  10197. this.setLeading(args);
  10198. break;
  10199. case _util.OPS.setLeadingMoveText:
  10200. this.setLeadingMoveText(args[0], args[1]);
  10201. break;
  10202. case _util.OPS.setFont:
  10203. this.setFont(args);
  10204. break;
  10205. case _util.OPS.showText:
  10206. this.showText(args[0]);
  10207. break;
  10208. case _util.OPS.showSpacedText:
  10209. this.showText(args[0]);
  10210. break;
  10211. case _util.OPS.endText:
  10212. this.endText();
  10213. break;
  10214. case _util.OPS.moveText:
  10215. this.moveText(args[0], args[1]);
  10216. break;
  10217. case _util.OPS.setCharSpacing:
  10218. this.setCharSpacing(args[0]);
  10219. break;
  10220. case _util.OPS.setWordSpacing:
  10221. this.setWordSpacing(args[0]);
  10222. break;
  10223. case _util.OPS.setHScale:
  10224. this.setHScale(args[0]);
  10225. break;
  10226. case _util.OPS.setTextMatrix:
  10227. this.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
  10228. break;
  10229. case _util.OPS.setTextRise:
  10230. this.setTextRise(args[0]);
  10231. break;
  10232. case _util.OPS.setTextRenderingMode:
  10233. this.setTextRenderingMode(args[0]);
  10234. break;
  10235. case _util.OPS.setLineWidth:
  10236. this.setLineWidth(args[0]);
  10237. break;
  10238. case _util.OPS.setLineJoin:
  10239. this.setLineJoin(args[0]);
  10240. break;
  10241. case _util.OPS.setLineCap:
  10242. this.setLineCap(args[0]);
  10243. break;
  10244. case _util.OPS.setMiterLimit:
  10245. this.setMiterLimit(args[0]);
  10246. break;
  10247. case _util.OPS.setFillRGBColor:
  10248. this.setFillRGBColor(args[0], args[1], args[2]);
  10249. break;
  10250. case _util.OPS.setStrokeRGBColor:
  10251. this.setStrokeRGBColor(args[0], args[1], args[2]);
  10252. break;
  10253. case _util.OPS.setStrokeColorN:
  10254. this.setStrokeColorN(args);
  10255. break;
  10256. case _util.OPS.setFillColorN:
  10257. this.setFillColorN(args);
  10258. break;
  10259. case _util.OPS.shadingFill:
  10260. this.shadingFill(args[0]);
  10261. break;
  10262. case _util.OPS.setDash:
  10263. this.setDash(args[0], args[1]);
  10264. break;
  10265. case _util.OPS.setRenderingIntent:
  10266. this.setRenderingIntent(args[0]);
  10267. break;
  10268. case _util.OPS.setFlatness:
  10269. this.setFlatness(args[0]);
  10270. break;
  10271. case _util.OPS.setGState:
  10272. this.setGState(args[0]);
  10273. break;
  10274. case _util.OPS.fill:
  10275. this.fill();
  10276. break;
  10277. case _util.OPS.eoFill:
  10278. this.eoFill();
  10279. break;
  10280. case _util.OPS.stroke:
  10281. this.stroke();
  10282. break;
  10283. case _util.OPS.fillStroke:
  10284. this.fillStroke();
  10285. break;
  10286. case _util.OPS.eoFillStroke:
  10287. this.eoFillStroke();
  10288. break;
  10289. case _util.OPS.clip:
  10290. this.clip("nonzero");
  10291. break;
  10292. case _util.OPS.eoClip:
  10293. this.clip("evenodd");
  10294. break;
  10295. case _util.OPS.paintSolidColorImageMask:
  10296. this.paintSolidColorImageMask();
  10297. break;
  10298. case _util.OPS.paintImageXObject:
  10299. this.paintImageXObject(args[0]);
  10300. break;
  10301. case _util.OPS.paintInlineImageXObject:
  10302. this.paintInlineImageXObject(args[0]);
  10303. break;
  10304. case _util.OPS.paintImageMaskXObject:
  10305. this.paintImageMaskXObject(args[0]);
  10306. break;
  10307. case _util.OPS.paintFormXObjectBegin:
  10308. this.paintFormXObjectBegin(args[0], args[1]);
  10309. break;
  10310. case _util.OPS.paintFormXObjectEnd:
  10311. this.paintFormXObjectEnd();
  10312. break;
  10313. case _util.OPS.closePath:
  10314. this.closePath();
  10315. break;
  10316. case _util.OPS.closeStroke:
  10317. this.closeStroke();
  10318. break;
  10319. case _util.OPS.closeFillStroke:
  10320. this.closeFillStroke();
  10321. break;
  10322. case _util.OPS.closeEOFillStroke:
  10323. this.closeEOFillStroke();
  10324. break;
  10325. case _util.OPS.nextLine:
  10326. this.nextLine();
  10327. break;
  10328. case _util.OPS.transform:
  10329. this.transform(args[0], args[1], args[2], args[3], args[4], args[5]);
  10330. break;
  10331. case _util.OPS.constructPath:
  10332. this.constructPath(args[0], args[1]);
  10333. break;
  10334. case _util.OPS.endPath:
  10335. this.endPath();
  10336. break;
  10337. case 92:
  10338. this.group(opTreeElement.items);
  10339. break;
  10340. default:
  10341. (0, _util.warn)(`Unimplemented operator ${fn}`);
  10342. break;
  10343. }
  10344. }
  10345. }
  10346. setWordSpacing(wordSpacing) {
  10347. this.current.wordSpacing = wordSpacing;
  10348. }
  10349. setCharSpacing(charSpacing) {
  10350. this.current.charSpacing = charSpacing;
  10351. }
  10352. nextLine() {
  10353. this.moveText(0, this.current.leading);
  10354. }
  10355. setTextMatrix(a, b, c, d, e, f) {
  10356. const current = this.current;
  10357. current.textMatrix = current.lineMatrix = [a, b, c, d, e, f];
  10358. current.textMatrixScale = Math.sqrt(a * a + b * b);
  10359. current.x = current.lineX = 0;
  10360. current.y = current.lineY = 0;
  10361. current.xcoords = [];
  10362. current.ycoords = [];
  10363. current.tspan = this.svgFactory.createElement("svg:tspan");
  10364. current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
  10365. current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
  10366. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  10367. current.txtElement = this.svgFactory.createElement("svg:text");
  10368. current.txtElement.appendChild(current.tspan);
  10369. }
  10370. beginText() {
  10371. const current = this.current;
  10372. current.x = current.lineX = 0;
  10373. current.y = current.lineY = 0;
  10374. current.textMatrix = _util.IDENTITY_MATRIX;
  10375. current.lineMatrix = _util.IDENTITY_MATRIX;
  10376. current.textMatrixScale = 1;
  10377. current.tspan = this.svgFactory.createElement("svg:tspan");
  10378. current.txtElement = this.svgFactory.createElement("svg:text");
  10379. current.txtgrp = this.svgFactory.createElement("svg:g");
  10380. current.xcoords = [];
  10381. current.ycoords = [];
  10382. }
  10383. moveText(x, y) {
  10384. const current = this.current;
  10385. current.x = current.lineX += x;
  10386. current.y = current.lineY += y;
  10387. current.xcoords = [];
  10388. current.ycoords = [];
  10389. current.tspan = this.svgFactory.createElement("svg:tspan");
  10390. current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
  10391. current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
  10392. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  10393. }
  10394. showText(glyphs) {
  10395. const current = this.current;
  10396. const font = current.font;
  10397. const fontSize = current.fontSize;
  10398. if (fontSize === 0) {
  10399. return;
  10400. }
  10401. const fontSizeScale = current.fontSizeScale;
  10402. const charSpacing = current.charSpacing;
  10403. const wordSpacing = current.wordSpacing;
  10404. const fontDirection = current.fontDirection;
  10405. const textHScale = current.textHScale * fontDirection;
  10406. const vertical = font.vertical;
  10407. const spacingDir = vertical ? 1 : -1;
  10408. const defaultVMetrics = font.defaultVMetrics;
  10409. const widthAdvanceScale = fontSize * current.fontMatrix[0];
  10410. let x = 0;
  10411. for (const glyph of glyphs) {
  10412. if (glyph === null) {
  10413. x += fontDirection * wordSpacing;
  10414. continue;
  10415. } else if ((0, _util.isNum)(glyph)) {
  10416. x += spacingDir * glyph * fontSize / 1000;
  10417. continue;
  10418. }
  10419. const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  10420. const character = glyph.fontChar;
  10421. let scaledX, scaledY;
  10422. let width = glyph.width;
  10423. if (vertical) {
  10424. let vx;
  10425. const vmetric = glyph.vmetric || defaultVMetrics;
  10426. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  10427. vx = -vx * widthAdvanceScale;
  10428. const vy = vmetric[2] * widthAdvanceScale;
  10429. width = vmetric ? -vmetric[0] : width;
  10430. scaledX = vx / fontSizeScale;
  10431. scaledY = (x + vy) / fontSizeScale;
  10432. } else {
  10433. scaledX = x / fontSizeScale;
  10434. scaledY = 0;
  10435. }
  10436. if (glyph.isInFont || font.missingFile) {
  10437. current.xcoords.push(current.x + scaledX);
  10438. if (vertical) {
  10439. current.ycoords.push(-current.y + scaledY);
  10440. }
  10441. current.tspan.textContent += character;
  10442. } else {}
  10443. let charWidth;
  10444. if (vertical) {
  10445. charWidth = width * widthAdvanceScale - spacing * fontDirection;
  10446. } else {
  10447. charWidth = width * widthAdvanceScale + spacing * fontDirection;
  10448. }
  10449. x += charWidth;
  10450. }
  10451. current.tspan.setAttributeNS(null, "x", current.xcoords.map(pf).join(" "));
  10452. if (vertical) {
  10453. current.tspan.setAttributeNS(null, "y", current.ycoords.map(pf).join(" "));
  10454. } else {
  10455. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  10456. }
  10457. if (vertical) {
  10458. current.y -= x;
  10459. } else {
  10460. current.x += x * textHScale;
  10461. }
  10462. current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
  10463. current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
  10464. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  10465. current.tspan.setAttributeNS(null, "font-style", current.fontStyle);
  10466. }
  10467. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  10468. current.tspan.setAttributeNS(null, "font-weight", current.fontWeight);
  10469. }
  10470. const fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  10471. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  10472. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  10473. current.tspan.setAttributeNS(null, "fill", current.fillColor);
  10474. }
  10475. if (current.fillAlpha < 1) {
  10476. current.tspan.setAttributeNS(null, "fill-opacity", current.fillAlpha);
  10477. }
  10478. } else if (current.textRenderingMode === _util.TextRenderingMode.ADD_TO_PATH) {
  10479. current.tspan.setAttributeNS(null, "fill", "transparent");
  10480. } else {
  10481. current.tspan.setAttributeNS(null, "fill", "none");
  10482. }
  10483. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  10484. const lineWidthScale = 1 / (current.textMatrixScale || 1);
  10485. this._setStrokeAttributes(current.tspan, lineWidthScale);
  10486. }
  10487. let textMatrix = current.textMatrix;
  10488. if (current.textRise !== 0) {
  10489. textMatrix = textMatrix.slice();
  10490. textMatrix[5] += current.textRise;
  10491. }
  10492. current.txtElement.setAttributeNS(null, "transform", `${pm(textMatrix)} scale(${pf(textHScale)}, -1)`);
  10493. current.txtElement.setAttributeNS(XML_NS, "xml:space", "preserve");
  10494. current.txtElement.appendChild(current.tspan);
  10495. current.txtgrp.appendChild(current.txtElement);
  10496. this._ensureTransformGroup().appendChild(current.txtElement);
  10497. }
  10498. setLeadingMoveText(x, y) {
  10499. this.setLeading(-y);
  10500. this.moveText(x, y);
  10501. }
  10502. addFontStyle(fontObj) {
  10503. if (!fontObj.data) {
  10504. throw new Error("addFontStyle: No font data available, " + 'ensure that the "fontExtraProperties" API parameter is set.');
  10505. }
  10506. if (!this.cssStyle) {
  10507. this.cssStyle = this.svgFactory.createElement("svg:style");
  10508. this.cssStyle.setAttributeNS(null, "type", "text/css");
  10509. this.defs.appendChild(this.cssStyle);
  10510. }
  10511. const url = (0, _util.createObjectURL)(fontObj.data, fontObj.mimetype, this.forceDataSchema);
  10512. this.cssStyle.textContent += `@font-face { font-family: "${fontObj.loadedName}";` + ` src: url(${url}); }\n`;
  10513. }
  10514. setFont(details) {
  10515. const current = this.current;
  10516. const fontObj = this.commonObjs.get(details[0]);
  10517. let size = details[1];
  10518. current.font = fontObj;
  10519. if (this.embedFonts && !fontObj.missingFile && !this.embeddedFonts[fontObj.loadedName]) {
  10520. this.addFontStyle(fontObj);
  10521. this.embeddedFonts[fontObj.loadedName] = fontObj;
  10522. }
  10523. current.fontMatrix = fontObj.fontMatrix || _util.FONT_IDENTITY_MATRIX;
  10524. let bold = "normal";
  10525. if (fontObj.black) {
  10526. bold = "900";
  10527. } else if (fontObj.bold) {
  10528. bold = "bold";
  10529. }
  10530. const italic = fontObj.italic ? "italic" : "normal";
  10531. if (size < 0) {
  10532. size = -size;
  10533. current.fontDirection = -1;
  10534. } else {
  10535. current.fontDirection = 1;
  10536. }
  10537. current.fontSize = size;
  10538. current.fontFamily = fontObj.loadedName;
  10539. current.fontWeight = bold;
  10540. current.fontStyle = italic;
  10541. current.tspan = this.svgFactory.createElement("svg:tspan");
  10542. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  10543. current.xcoords = [];
  10544. current.ycoords = [];
  10545. }
  10546. endText() {
  10547. const current = this.current;
  10548. if (current.textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG && current.txtElement?.hasChildNodes()) {
  10549. current.element = current.txtElement;
  10550. this.clip("nonzero");
  10551. this.endPath();
  10552. }
  10553. }
  10554. setLineWidth(width) {
  10555. if (width > 0) {
  10556. this.current.lineWidth = width;
  10557. }
  10558. }
  10559. setLineCap(style) {
  10560. this.current.lineCap = LINE_CAP_STYLES[style];
  10561. }
  10562. setLineJoin(style) {
  10563. this.current.lineJoin = LINE_JOIN_STYLES[style];
  10564. }
  10565. setMiterLimit(limit) {
  10566. this.current.miterLimit = limit;
  10567. }
  10568. setStrokeAlpha(strokeAlpha) {
  10569. this.current.strokeAlpha = strokeAlpha;
  10570. }
  10571. setStrokeRGBColor(r, g, b) {
  10572. this.current.strokeColor = _util.Util.makeHexColor(r, g, b);
  10573. }
  10574. setFillAlpha(fillAlpha) {
  10575. this.current.fillAlpha = fillAlpha;
  10576. }
  10577. setFillRGBColor(r, g, b) {
  10578. this.current.fillColor = _util.Util.makeHexColor(r, g, b);
  10579. this.current.tspan = this.svgFactory.createElement("svg:tspan");
  10580. this.current.xcoords = [];
  10581. this.current.ycoords = [];
  10582. }
  10583. setStrokeColorN(args) {
  10584. this.current.strokeColor = this._makeColorN_Pattern(args);
  10585. }
  10586. setFillColorN(args) {
  10587. this.current.fillColor = this._makeColorN_Pattern(args);
  10588. }
  10589. shadingFill(args) {
  10590. const width = this.viewport.width;
  10591. const height = this.viewport.height;
  10592. const inv = _util.Util.inverseTransform(this.transformMatrix);
  10593. const bl = _util.Util.applyTransform([0, 0], inv);
  10594. const br = _util.Util.applyTransform([0, height], inv);
  10595. const ul = _util.Util.applyTransform([width, 0], inv);
  10596. const ur = _util.Util.applyTransform([width, height], inv);
  10597. const x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  10598. const y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  10599. const x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  10600. const y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  10601. const rect = this.svgFactory.createElement("svg:rect");
  10602. rect.setAttributeNS(null, "x", x0);
  10603. rect.setAttributeNS(null, "y", y0);
  10604. rect.setAttributeNS(null, "width", x1 - x0);
  10605. rect.setAttributeNS(null, "height", y1 - y0);
  10606. rect.setAttributeNS(null, "fill", this._makeShadingPattern(args));
  10607. if (this.current.fillAlpha < 1) {
  10608. rect.setAttributeNS(null, "fill-opacity", this.current.fillAlpha);
  10609. }
  10610. this._ensureTransformGroup().appendChild(rect);
  10611. }
  10612. _makeColorN_Pattern(args) {
  10613. if (args[0] === "TilingPattern") {
  10614. return this._makeTilingPattern(args);
  10615. }
  10616. return this._makeShadingPattern(args);
  10617. }
  10618. _makeTilingPattern(args) {
  10619. const color = args[1];
  10620. const operatorList = args[2];
  10621. const matrix = args[3] || _util.IDENTITY_MATRIX;
  10622. const [x0, y0, x1, y1] = args[4];
  10623. const xstep = args[5];
  10624. const ystep = args[6];
  10625. const paintType = args[7];
  10626. const tilingId = `shading${shadingCount++}`;
  10627. const [tx0, ty0] = _util.Util.applyTransform([x0, y0], matrix);
  10628. const [tx1, ty1] = _util.Util.applyTransform([x1, y1], matrix);
  10629. const [xscale, yscale] = _util.Util.singularValueDecompose2dScale(matrix);
  10630. const txstep = xstep * xscale;
  10631. const tystep = ystep * yscale;
  10632. const tiling = this.svgFactory.createElement("svg:pattern");
  10633. tiling.setAttributeNS(null, "id", tilingId);
  10634. tiling.setAttributeNS(null, "patternUnits", "userSpaceOnUse");
  10635. tiling.setAttributeNS(null, "width", txstep);
  10636. tiling.setAttributeNS(null, "height", tystep);
  10637. tiling.setAttributeNS(null, "x", `${tx0}`);
  10638. tiling.setAttributeNS(null, "y", `${ty0}`);
  10639. const svg = this.svg;
  10640. const transformMatrix = this.transformMatrix;
  10641. const fillColor = this.current.fillColor;
  10642. const strokeColor = this.current.strokeColor;
  10643. const bbox = this.svgFactory.create(tx1 - tx0, ty1 - ty0);
  10644. this.svg = bbox;
  10645. this.transformMatrix = matrix;
  10646. if (paintType === 2) {
  10647. const cssColor = _util.Util.makeHexColor(...color);
  10648. this.current.fillColor = cssColor;
  10649. this.current.strokeColor = cssColor;
  10650. }
  10651. this.executeOpTree(this.convertOpList(operatorList));
  10652. this.svg = svg;
  10653. this.transformMatrix = transformMatrix;
  10654. this.current.fillColor = fillColor;
  10655. this.current.strokeColor = strokeColor;
  10656. tiling.appendChild(bbox.childNodes[0]);
  10657. this.defs.appendChild(tiling);
  10658. return `url(#${tilingId})`;
  10659. }
  10660. _makeShadingPattern(args) {
  10661. switch (args[0]) {
  10662. case "RadialAxial":
  10663. const shadingId = `shading${shadingCount++}`;
  10664. const colorStops = args[3];
  10665. let gradient;
  10666. switch (args[1]) {
  10667. case "axial":
  10668. const point0 = args[4];
  10669. const point1 = args[5];
  10670. gradient = this.svgFactory.createElement("svg:linearGradient");
  10671. gradient.setAttributeNS(null, "id", shadingId);
  10672. gradient.setAttributeNS(null, "gradientUnits", "userSpaceOnUse");
  10673. gradient.setAttributeNS(null, "x1", point0[0]);
  10674. gradient.setAttributeNS(null, "y1", point0[1]);
  10675. gradient.setAttributeNS(null, "x2", point1[0]);
  10676. gradient.setAttributeNS(null, "y2", point1[1]);
  10677. break;
  10678. case "radial":
  10679. const focalPoint = args[4];
  10680. const circlePoint = args[5];
  10681. const focalRadius = args[6];
  10682. const circleRadius = args[7];
  10683. gradient = this.svgFactory.createElement("svg:radialGradient");
  10684. gradient.setAttributeNS(null, "id", shadingId);
  10685. gradient.setAttributeNS(null, "gradientUnits", "userSpaceOnUse");
  10686. gradient.setAttributeNS(null, "cx", circlePoint[0]);
  10687. gradient.setAttributeNS(null, "cy", circlePoint[1]);
  10688. gradient.setAttributeNS(null, "r", circleRadius);
  10689. gradient.setAttributeNS(null, "fx", focalPoint[0]);
  10690. gradient.setAttributeNS(null, "fy", focalPoint[1]);
  10691. gradient.setAttributeNS(null, "fr", focalRadius);
  10692. break;
  10693. default:
  10694. throw new Error(`Unknown RadialAxial type: ${args[1]}`);
  10695. }
  10696. for (const colorStop of colorStops) {
  10697. const stop = this.svgFactory.createElement("svg:stop");
  10698. stop.setAttributeNS(null, "offset", colorStop[0]);
  10699. stop.setAttributeNS(null, "stop-color", colorStop[1]);
  10700. gradient.appendChild(stop);
  10701. }
  10702. this.defs.appendChild(gradient);
  10703. return `url(#${shadingId})`;
  10704. case "Mesh":
  10705. (0, _util.warn)("Unimplemented pattern Mesh");
  10706. return null;
  10707. case "Dummy":
  10708. return "hotpink";
  10709. default:
  10710. throw new Error(`Unknown IR type: ${args[0]}`);
  10711. }
  10712. }
  10713. setDash(dashArray, dashPhase) {
  10714. this.current.dashArray = dashArray;
  10715. this.current.dashPhase = dashPhase;
  10716. }
  10717. constructPath(ops, args) {
  10718. const current = this.current;
  10719. let x = current.x,
  10720. y = current.y;
  10721. let d = [];
  10722. let j = 0;
  10723. for (const op of ops) {
  10724. switch (op | 0) {
  10725. case _util.OPS.rectangle:
  10726. x = args[j++];
  10727. y = args[j++];
  10728. const width = args[j++];
  10729. const height = args[j++];
  10730. const xw = x + width;
  10731. const yh = y + height;
  10732. d.push("M", pf(x), pf(y), "L", pf(xw), pf(y), "L", pf(xw), pf(yh), "L", pf(x), pf(yh), "Z");
  10733. break;
  10734. case _util.OPS.moveTo:
  10735. x = args[j++];
  10736. y = args[j++];
  10737. d.push("M", pf(x), pf(y));
  10738. break;
  10739. case _util.OPS.lineTo:
  10740. x = args[j++];
  10741. y = args[j++];
  10742. d.push("L", pf(x), pf(y));
  10743. break;
  10744. case _util.OPS.curveTo:
  10745. x = args[j + 4];
  10746. y = args[j + 5];
  10747. d.push("C", pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]), pf(x), pf(y));
  10748. j += 6;
  10749. break;
  10750. case _util.OPS.curveTo2:
  10751. d.push("C", pf(x), pf(y), pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]));
  10752. x = args[j + 2];
  10753. y = args[j + 3];
  10754. j += 4;
  10755. break;
  10756. case _util.OPS.curveTo3:
  10757. x = args[j + 2];
  10758. y = args[j + 3];
  10759. d.push("C", pf(args[j]), pf(args[j + 1]), pf(x), pf(y), pf(x), pf(y));
  10760. j += 4;
  10761. break;
  10762. case _util.OPS.closePath:
  10763. d.push("Z");
  10764. break;
  10765. }
  10766. }
  10767. d = d.join(" ");
  10768. if (current.path && ops.length > 0 && ops[0] !== _util.OPS.rectangle && ops[0] !== _util.OPS.moveTo) {
  10769. d = current.path.getAttributeNS(null, "d") + d;
  10770. } else {
  10771. current.path = this.svgFactory.createElement("svg:path");
  10772. this._ensureTransformGroup().appendChild(current.path);
  10773. }
  10774. current.path.setAttributeNS(null, "d", d);
  10775. current.path.setAttributeNS(null, "fill", "none");
  10776. current.element = current.path;
  10777. current.setCurrentPoint(x, y);
  10778. }
  10779. endPath() {
  10780. const current = this.current;
  10781. current.path = null;
  10782. if (!this.pendingClip) {
  10783. return;
  10784. }
  10785. if (!current.element) {
  10786. this.pendingClip = null;
  10787. return;
  10788. }
  10789. const clipId = `clippath${clipCount++}`;
  10790. const clipPath = this.svgFactory.createElement("svg:clipPath");
  10791. clipPath.setAttributeNS(null, "id", clipId);
  10792. clipPath.setAttributeNS(null, "transform", pm(this.transformMatrix));
  10793. const clipElement = current.element.cloneNode(true);
  10794. if (this.pendingClip === "evenodd") {
  10795. clipElement.setAttributeNS(null, "clip-rule", "evenodd");
  10796. } else {
  10797. clipElement.setAttributeNS(null, "clip-rule", "nonzero");
  10798. }
  10799. this.pendingClip = null;
  10800. clipPath.appendChild(clipElement);
  10801. this.defs.appendChild(clipPath);
  10802. if (current.activeClipUrl) {
  10803. current.clipGroup = null;
  10804. this.extraStack.forEach(function (prev) {
  10805. prev.clipGroup = null;
  10806. });
  10807. clipPath.setAttributeNS(null, "clip-path", current.activeClipUrl);
  10808. }
  10809. current.activeClipUrl = `url(#${clipId})`;
  10810. this.tgrp = null;
  10811. }
  10812. clip(type) {
  10813. this.pendingClip = type;
  10814. }
  10815. closePath() {
  10816. const current = this.current;
  10817. if (current.path) {
  10818. const d = `${current.path.getAttributeNS(null, "d")}Z`;
  10819. current.path.setAttributeNS(null, "d", d);
  10820. }
  10821. }
  10822. setLeading(leading) {
  10823. this.current.leading = -leading;
  10824. }
  10825. setTextRise(textRise) {
  10826. this.current.textRise = textRise;
  10827. }
  10828. setTextRenderingMode(textRenderingMode) {
  10829. this.current.textRenderingMode = textRenderingMode;
  10830. }
  10831. setHScale(scale) {
  10832. this.current.textHScale = scale / 100;
  10833. }
  10834. setRenderingIntent(intent) {}
  10835. setFlatness(flatness) {}
  10836. setGState(states) {
  10837. for (const [key, value] of states) {
  10838. switch (key) {
  10839. case "LW":
  10840. this.setLineWidth(value);
  10841. break;
  10842. case "LC":
  10843. this.setLineCap(value);
  10844. break;
  10845. case "LJ":
  10846. this.setLineJoin(value);
  10847. break;
  10848. case "ML":
  10849. this.setMiterLimit(value);
  10850. break;
  10851. case "D":
  10852. this.setDash(value[0], value[1]);
  10853. break;
  10854. case "RI":
  10855. this.setRenderingIntent(value);
  10856. break;
  10857. case "FL":
  10858. this.setFlatness(value);
  10859. break;
  10860. case "Font":
  10861. this.setFont(value);
  10862. break;
  10863. case "CA":
  10864. this.setStrokeAlpha(value);
  10865. break;
  10866. case "ca":
  10867. this.setFillAlpha(value);
  10868. break;
  10869. default:
  10870. (0, _util.warn)(`Unimplemented graphic state operator ${key}`);
  10871. break;
  10872. }
  10873. }
  10874. }
  10875. fill() {
  10876. const current = this.current;
  10877. if (current.element) {
  10878. current.element.setAttributeNS(null, "fill", current.fillColor);
  10879. current.element.setAttributeNS(null, "fill-opacity", current.fillAlpha);
  10880. this.endPath();
  10881. }
  10882. }
  10883. stroke() {
  10884. const current = this.current;
  10885. if (current.element) {
  10886. this._setStrokeAttributes(current.element);
  10887. current.element.setAttributeNS(null, "fill", "none");
  10888. this.endPath();
  10889. }
  10890. }
  10891. _setStrokeAttributes(element, lineWidthScale = 1) {
  10892. const current = this.current;
  10893. let dashArray = current.dashArray;
  10894. if (lineWidthScale !== 1 && dashArray.length > 0) {
  10895. dashArray = dashArray.map(function (value) {
  10896. return lineWidthScale * value;
  10897. });
  10898. }
  10899. element.setAttributeNS(null, "stroke", current.strokeColor);
  10900. element.setAttributeNS(null, "stroke-opacity", current.strokeAlpha);
  10901. element.setAttributeNS(null, "stroke-miterlimit", pf(current.miterLimit));
  10902. element.setAttributeNS(null, "stroke-linecap", current.lineCap);
  10903. element.setAttributeNS(null, "stroke-linejoin", current.lineJoin);
  10904. element.setAttributeNS(null, "stroke-width", pf(lineWidthScale * current.lineWidth) + "px");
  10905. element.setAttributeNS(null, "stroke-dasharray", dashArray.map(pf).join(" "));
  10906. element.setAttributeNS(null, "stroke-dashoffset", pf(lineWidthScale * current.dashPhase) + "px");
  10907. }
  10908. eoFill() {
  10909. if (this.current.element) {
  10910. this.current.element.setAttributeNS(null, "fill-rule", "evenodd");
  10911. }
  10912. this.fill();
  10913. }
  10914. fillStroke() {
  10915. this.stroke();
  10916. this.fill();
  10917. }
  10918. eoFillStroke() {
  10919. if (this.current.element) {
  10920. this.current.element.setAttributeNS(null, "fill-rule", "evenodd");
  10921. }
  10922. this.fillStroke();
  10923. }
  10924. closeStroke() {
  10925. this.closePath();
  10926. this.stroke();
  10927. }
  10928. closeFillStroke() {
  10929. this.closePath();
  10930. this.fillStroke();
  10931. }
  10932. closeEOFillStroke() {
  10933. this.closePath();
  10934. this.eoFillStroke();
  10935. }
  10936. paintSolidColorImageMask() {
  10937. const rect = this.svgFactory.createElement("svg:rect");
  10938. rect.setAttributeNS(null, "x", "0");
  10939. rect.setAttributeNS(null, "y", "0");
  10940. rect.setAttributeNS(null, "width", "1px");
  10941. rect.setAttributeNS(null, "height", "1px");
  10942. rect.setAttributeNS(null, "fill", this.current.fillColor);
  10943. this._ensureTransformGroup().appendChild(rect);
  10944. }
  10945. paintImageXObject(objId) {
  10946. const imgData = objId.startsWith("g_") ? this.commonObjs.get(objId) : this.objs.get(objId);
  10947. if (!imgData) {
  10948. (0, _util.warn)(`Dependent image with object ID ${objId} is not ready yet`);
  10949. return;
  10950. }
  10951. this.paintInlineImageXObject(imgData);
  10952. }
  10953. paintInlineImageXObject(imgData, mask) {
  10954. const width = imgData.width;
  10955. const height = imgData.height;
  10956. const imgSrc = convertImgDataToPng(imgData, this.forceDataSchema, !!mask);
  10957. const cliprect = this.svgFactory.createElement("svg:rect");
  10958. cliprect.setAttributeNS(null, "x", "0");
  10959. cliprect.setAttributeNS(null, "y", "0");
  10960. cliprect.setAttributeNS(null, "width", pf(width));
  10961. cliprect.setAttributeNS(null, "height", pf(height));
  10962. this.current.element = cliprect;
  10963. this.clip("nonzero");
  10964. const imgEl = this.svgFactory.createElement("svg:image");
  10965. imgEl.setAttributeNS(XLINK_NS, "xlink:href", imgSrc);
  10966. imgEl.setAttributeNS(null, "x", "0");
  10967. imgEl.setAttributeNS(null, "y", pf(-height));
  10968. imgEl.setAttributeNS(null, "width", pf(width) + "px");
  10969. imgEl.setAttributeNS(null, "height", pf(height) + "px");
  10970. imgEl.setAttributeNS(null, "transform", `scale(${pf(1 / width)} ${pf(-1 / height)})`);
  10971. if (mask) {
  10972. mask.appendChild(imgEl);
  10973. } else {
  10974. this._ensureTransformGroup().appendChild(imgEl);
  10975. }
  10976. }
  10977. paintImageMaskXObject(imgData) {
  10978. const current = this.current;
  10979. const width = imgData.width;
  10980. const height = imgData.height;
  10981. const fillColor = current.fillColor;
  10982. current.maskId = `mask${maskCount++}`;
  10983. const mask = this.svgFactory.createElement("svg:mask");
  10984. mask.setAttributeNS(null, "id", current.maskId);
  10985. const rect = this.svgFactory.createElement("svg:rect");
  10986. rect.setAttributeNS(null, "x", "0");
  10987. rect.setAttributeNS(null, "y", "0");
  10988. rect.setAttributeNS(null, "width", pf(width));
  10989. rect.setAttributeNS(null, "height", pf(height));
  10990. rect.setAttributeNS(null, "fill", fillColor);
  10991. rect.setAttributeNS(null, "mask", `url(#${current.maskId})`);
  10992. this.defs.appendChild(mask);
  10993. this._ensureTransformGroup().appendChild(rect);
  10994. this.paintInlineImageXObject(imgData, mask);
  10995. }
  10996. paintFormXObjectBegin(matrix, bbox) {
  10997. if (Array.isArray(matrix) && matrix.length === 6) {
  10998. this.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
  10999. }
  11000. if (bbox) {
  11001. const width = bbox[2] - bbox[0];
  11002. const height = bbox[3] - bbox[1];
  11003. const cliprect = this.svgFactory.createElement("svg:rect");
  11004. cliprect.setAttributeNS(null, "x", bbox[0]);
  11005. cliprect.setAttributeNS(null, "y", bbox[1]);
  11006. cliprect.setAttributeNS(null, "width", pf(width));
  11007. cliprect.setAttributeNS(null, "height", pf(height));
  11008. this.current.element = cliprect;
  11009. this.clip("nonzero");
  11010. this.endPath();
  11011. }
  11012. }
  11013. paintFormXObjectEnd() {}
  11014. _initialize(viewport) {
  11015. const svg = this.svgFactory.create(viewport.width, viewport.height);
  11016. const definitions = this.svgFactory.createElement("svg:defs");
  11017. svg.appendChild(definitions);
  11018. this.defs = definitions;
  11019. const rootGroup = this.svgFactory.createElement("svg:g");
  11020. rootGroup.setAttributeNS(null, "transform", pm(viewport.transform));
  11021. svg.appendChild(rootGroup);
  11022. this.svg = rootGroup;
  11023. return svg;
  11024. }
  11025. _ensureClipGroup() {
  11026. if (!this.current.clipGroup) {
  11027. const clipGroup = this.svgFactory.createElement("svg:g");
  11028. clipGroup.setAttributeNS(null, "clip-path", this.current.activeClipUrl);
  11029. this.svg.appendChild(clipGroup);
  11030. this.current.clipGroup = clipGroup;
  11031. }
  11032. return this.current.clipGroup;
  11033. }
  11034. _ensureTransformGroup() {
  11035. if (!this.tgrp) {
  11036. this.tgrp = this.svgFactory.createElement("svg:g");
  11037. this.tgrp.setAttributeNS(null, "transform", pm(this.transformMatrix));
  11038. if (this.current.activeClipUrl) {
  11039. this._ensureClipGroup().appendChild(this.tgrp);
  11040. } else {
  11041. this.svg.appendChild(this.tgrp);
  11042. }
  11043. }
  11044. return this.tgrp;
  11045. }
  11046. };
  11047. }
  11048. /***/ }),
  11049. /* 23 */
  11050. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  11051. Object.defineProperty(exports, "__esModule", ({
  11052. value: true
  11053. }));
  11054. exports.PDFNodeStream = void 0;
  11055. var _util = __w_pdfjs_require__(2);
  11056. var _network_utils = __w_pdfjs_require__(24);
  11057. ;
  11058. const fs = require("fs");
  11059. const http = require("http");
  11060. const https = require("https");
  11061. const url = require("url");
  11062. const fileUriRegex = /^file:\/\/\/[a-zA-Z]:\//;
  11063. function parseUrl(sourceUrl) {
  11064. const parsedUrl = url.parse(sourceUrl);
  11065. if (parsedUrl.protocol === "file:" || parsedUrl.host) {
  11066. return parsedUrl;
  11067. }
  11068. if (/^[a-z]:[/\\]/i.test(sourceUrl)) {
  11069. return url.parse(`file:///${sourceUrl}`);
  11070. }
  11071. if (!parsedUrl.host) {
  11072. parsedUrl.protocol = "file:";
  11073. }
  11074. return parsedUrl;
  11075. }
  11076. class PDFNodeStream {
  11077. constructor(source) {
  11078. this.source = source;
  11079. this.url = parseUrl(source.url);
  11080. this.isHttp = this.url.protocol === "http:" || this.url.protocol === "https:";
  11081. this.isFsUrl = this.url.protocol === "file:";
  11082. this.httpHeaders = this.isHttp && source.httpHeaders || {};
  11083. this._fullRequestReader = null;
  11084. this._rangeRequestReaders = [];
  11085. }
  11086. get _progressiveDataLength() {
  11087. return this._fullRequestReader?._loaded ?? 0;
  11088. }
  11089. getFullReader() {
  11090. (0, _util.assert)(!this._fullRequestReader, "PDFNodeStream.getFullReader can only be called once.");
  11091. this._fullRequestReader = this.isFsUrl ? new PDFNodeStreamFsFullReader(this) : new PDFNodeStreamFullReader(this);
  11092. return this._fullRequestReader;
  11093. }
  11094. getRangeReader(start, end) {
  11095. if (end <= this._progressiveDataLength) {
  11096. return null;
  11097. }
  11098. const rangeReader = this.isFsUrl ? new PDFNodeStreamFsRangeReader(this, start, end) : new PDFNodeStreamRangeReader(this, start, end);
  11099. this._rangeRequestReaders.push(rangeReader);
  11100. return rangeReader;
  11101. }
  11102. cancelAllRequests(reason) {
  11103. if (this._fullRequestReader) {
  11104. this._fullRequestReader.cancel(reason);
  11105. }
  11106. const readers = this._rangeRequestReaders.slice(0);
  11107. readers.forEach(function (reader) {
  11108. reader.cancel(reason);
  11109. });
  11110. }
  11111. }
  11112. exports.PDFNodeStream = PDFNodeStream;
  11113. class BaseFullReader {
  11114. constructor(stream) {
  11115. this._url = stream.url;
  11116. this._done = false;
  11117. this._storedError = null;
  11118. this.onProgress = null;
  11119. const source = stream.source;
  11120. this._contentLength = source.length;
  11121. this._loaded = 0;
  11122. this._filename = null;
  11123. this._disableRange = source.disableRange || false;
  11124. this._rangeChunkSize = source.rangeChunkSize;
  11125. if (!this._rangeChunkSize && !this._disableRange) {
  11126. this._disableRange = true;
  11127. }
  11128. this._isStreamingSupported = !source.disableStream;
  11129. this._isRangeSupported = !source.disableRange;
  11130. this._readableStream = null;
  11131. this._readCapability = (0, _util.createPromiseCapability)();
  11132. this._headersCapability = (0, _util.createPromiseCapability)();
  11133. }
  11134. get headersReady() {
  11135. return this._headersCapability.promise;
  11136. }
  11137. get filename() {
  11138. return this._filename;
  11139. }
  11140. get contentLength() {
  11141. return this._contentLength;
  11142. }
  11143. get isRangeSupported() {
  11144. return this._isRangeSupported;
  11145. }
  11146. get isStreamingSupported() {
  11147. return this._isStreamingSupported;
  11148. }
  11149. async read() {
  11150. await this._readCapability.promise;
  11151. if (this._done) {
  11152. return {
  11153. value: undefined,
  11154. done: true
  11155. };
  11156. }
  11157. if (this._storedError) {
  11158. throw this._storedError;
  11159. }
  11160. const chunk = this._readableStream.read();
  11161. if (chunk === null) {
  11162. this._readCapability = (0, _util.createPromiseCapability)();
  11163. return this.read();
  11164. }
  11165. this._loaded += chunk.length;
  11166. if (this.onProgress) {
  11167. this.onProgress({
  11168. loaded: this._loaded,
  11169. total: this._contentLength
  11170. });
  11171. }
  11172. const buffer = new Uint8Array(chunk).buffer;
  11173. return {
  11174. value: buffer,
  11175. done: false
  11176. };
  11177. }
  11178. cancel(reason) {
  11179. if (!this._readableStream) {
  11180. this._error(reason);
  11181. return;
  11182. }
  11183. this._readableStream.destroy(reason);
  11184. }
  11185. _error(reason) {
  11186. this._storedError = reason;
  11187. this._readCapability.resolve();
  11188. }
  11189. _setReadableStream(readableStream) {
  11190. this._readableStream = readableStream;
  11191. readableStream.on("readable", () => {
  11192. this._readCapability.resolve();
  11193. });
  11194. readableStream.on("end", () => {
  11195. readableStream.destroy();
  11196. this._done = true;
  11197. this._readCapability.resolve();
  11198. });
  11199. readableStream.on("error", reason => {
  11200. this._error(reason);
  11201. });
  11202. if (!this._isStreamingSupported && this._isRangeSupported) {
  11203. this._error(new _util.AbortException("streaming is disabled"));
  11204. }
  11205. if (this._storedError) {
  11206. this._readableStream.destroy(this._storedError);
  11207. }
  11208. }
  11209. }
  11210. class BaseRangeReader {
  11211. constructor(stream) {
  11212. this._url = stream.url;
  11213. this._done = false;
  11214. this._storedError = null;
  11215. this.onProgress = null;
  11216. this._loaded = 0;
  11217. this._readableStream = null;
  11218. this._readCapability = (0, _util.createPromiseCapability)();
  11219. const source = stream.source;
  11220. this._isStreamingSupported = !source.disableStream;
  11221. }
  11222. get isStreamingSupported() {
  11223. return this._isStreamingSupported;
  11224. }
  11225. async read() {
  11226. await this._readCapability.promise;
  11227. if (this._done) {
  11228. return {
  11229. value: undefined,
  11230. done: true
  11231. };
  11232. }
  11233. if (this._storedError) {
  11234. throw this._storedError;
  11235. }
  11236. const chunk = this._readableStream.read();
  11237. if (chunk === null) {
  11238. this._readCapability = (0, _util.createPromiseCapability)();
  11239. return this.read();
  11240. }
  11241. this._loaded += chunk.length;
  11242. if (this.onProgress) {
  11243. this.onProgress({
  11244. loaded: this._loaded
  11245. });
  11246. }
  11247. const buffer = new Uint8Array(chunk).buffer;
  11248. return {
  11249. value: buffer,
  11250. done: false
  11251. };
  11252. }
  11253. cancel(reason) {
  11254. if (!this._readableStream) {
  11255. this._error(reason);
  11256. return;
  11257. }
  11258. this._readableStream.destroy(reason);
  11259. }
  11260. _error(reason) {
  11261. this._storedError = reason;
  11262. this._readCapability.resolve();
  11263. }
  11264. _setReadableStream(readableStream) {
  11265. this._readableStream = readableStream;
  11266. readableStream.on("readable", () => {
  11267. this._readCapability.resolve();
  11268. });
  11269. readableStream.on("end", () => {
  11270. readableStream.destroy();
  11271. this._done = true;
  11272. this._readCapability.resolve();
  11273. });
  11274. readableStream.on("error", reason => {
  11275. this._error(reason);
  11276. });
  11277. if (this._storedError) {
  11278. this._readableStream.destroy(this._storedError);
  11279. }
  11280. }
  11281. }
  11282. function createRequestOptions(parsedUrl, headers) {
  11283. return {
  11284. protocol: parsedUrl.protocol,
  11285. auth: parsedUrl.auth,
  11286. host: parsedUrl.hostname,
  11287. port: parsedUrl.port,
  11288. path: parsedUrl.path,
  11289. method: "GET",
  11290. headers
  11291. };
  11292. }
  11293. class PDFNodeStreamFullReader extends BaseFullReader {
  11294. constructor(stream) {
  11295. super(stream);
  11296. const handleResponse = response => {
  11297. if (response.statusCode === 404) {
  11298. const error = new _util.MissingPDFException(`Missing PDF "${this._url}".`);
  11299. this._storedError = error;
  11300. this._headersCapability.reject(error);
  11301. return;
  11302. }
  11303. this._headersCapability.resolve();
  11304. this._setReadableStream(response);
  11305. const getResponseHeader = name => {
  11306. return this._readableStream.headers[name.toLowerCase()];
  11307. };
  11308. const {
  11309. allowRangeRequests,
  11310. suggestedLength
  11311. } = (0, _network_utils.validateRangeRequestCapabilities)({
  11312. getResponseHeader,
  11313. isHttp: stream.isHttp,
  11314. rangeChunkSize: this._rangeChunkSize,
  11315. disableRange: this._disableRange
  11316. });
  11317. this._isRangeSupported = allowRangeRequests;
  11318. this._contentLength = suggestedLength || this._contentLength;
  11319. this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
  11320. };
  11321. this._request = null;
  11322. if (this._url.protocol === "http:") {
  11323. this._request = http.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
  11324. } else {
  11325. this._request = https.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
  11326. }
  11327. this._request.on("error", reason => {
  11328. this._storedError = reason;
  11329. this._headersCapability.reject(reason);
  11330. });
  11331. this._request.end();
  11332. }
  11333. }
  11334. class PDFNodeStreamRangeReader extends BaseRangeReader {
  11335. constructor(stream, start, end) {
  11336. super(stream);
  11337. this._httpHeaders = {};
  11338. for (const property in stream.httpHeaders) {
  11339. const value = stream.httpHeaders[property];
  11340. if (typeof value === "undefined") {
  11341. continue;
  11342. }
  11343. this._httpHeaders[property] = value;
  11344. }
  11345. this._httpHeaders.Range = `bytes=${start}-${end - 1}`;
  11346. const handleResponse = response => {
  11347. if (response.statusCode === 404) {
  11348. const error = new _util.MissingPDFException(`Missing PDF "${this._url}".`);
  11349. this._storedError = error;
  11350. return;
  11351. }
  11352. this._setReadableStream(response);
  11353. };
  11354. this._request = null;
  11355. if (this._url.protocol === "http:") {
  11356. this._request = http.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
  11357. } else {
  11358. this._request = https.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
  11359. }
  11360. this._request.on("error", reason => {
  11361. this._storedError = reason;
  11362. });
  11363. this._request.end();
  11364. }
  11365. }
  11366. class PDFNodeStreamFsFullReader extends BaseFullReader {
  11367. constructor(stream) {
  11368. super(stream);
  11369. let path = decodeURIComponent(this._url.path);
  11370. if (fileUriRegex.test(this._url.href)) {
  11371. path = path.replace(/^\//, "");
  11372. }
  11373. fs.lstat(path, (error, stat) => {
  11374. if (error) {
  11375. if (error.code === "ENOENT") {
  11376. error = new _util.MissingPDFException(`Missing PDF "${path}".`);
  11377. }
  11378. this._storedError = error;
  11379. this._headersCapability.reject(error);
  11380. return;
  11381. }
  11382. this._contentLength = stat.size;
  11383. this._setReadableStream(fs.createReadStream(path));
  11384. this._headersCapability.resolve();
  11385. });
  11386. }
  11387. }
  11388. class PDFNodeStreamFsRangeReader extends BaseRangeReader {
  11389. constructor(stream, start, end) {
  11390. super(stream);
  11391. let path = decodeURIComponent(this._url.path);
  11392. if (fileUriRegex.test(this._url.href)) {
  11393. path = path.replace(/^\//, "");
  11394. }
  11395. this._setReadableStream(fs.createReadStream(path, {
  11396. start,
  11397. end: end - 1
  11398. }));
  11399. }
  11400. }
  11401. /***/ }),
  11402. /* 24 */
  11403. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  11404. Object.defineProperty(exports, "__esModule", ({
  11405. value: true
  11406. }));
  11407. exports.createResponseStatusError = createResponseStatusError;
  11408. exports.extractFilenameFromHeader = extractFilenameFromHeader;
  11409. exports.validateRangeRequestCapabilities = validateRangeRequestCapabilities;
  11410. exports.validateResponseStatus = validateResponseStatus;
  11411. var _util = __w_pdfjs_require__(2);
  11412. var _content_disposition = __w_pdfjs_require__(25);
  11413. function validateRangeRequestCapabilities({
  11414. getResponseHeader,
  11415. isHttp,
  11416. rangeChunkSize,
  11417. disableRange
  11418. }) {
  11419. (0, _util.assert)(rangeChunkSize > 0, "Range chunk size must be larger than zero");
  11420. const returnValues = {
  11421. allowRangeRequests: false,
  11422. suggestedLength: undefined
  11423. };
  11424. const length = parseInt(getResponseHeader("Content-Length"), 10);
  11425. if (!Number.isInteger(length)) {
  11426. return returnValues;
  11427. }
  11428. returnValues.suggestedLength = length;
  11429. if (length <= 2 * rangeChunkSize) {
  11430. return returnValues;
  11431. }
  11432. if (disableRange || !isHttp) {
  11433. return returnValues;
  11434. }
  11435. if (getResponseHeader("Accept-Ranges") !== "bytes") {
  11436. return returnValues;
  11437. }
  11438. const contentEncoding = getResponseHeader("Content-Encoding") || "identity";
  11439. if (contentEncoding !== "identity") {
  11440. return returnValues;
  11441. }
  11442. returnValues.allowRangeRequests = true;
  11443. return returnValues;
  11444. }
  11445. function extractFilenameFromHeader(getResponseHeader) {
  11446. const contentDisposition = getResponseHeader("Content-Disposition");
  11447. if (contentDisposition) {
  11448. let filename = (0, _content_disposition.getFilenameFromContentDispositionHeader)(contentDisposition);
  11449. if (filename.includes("%")) {
  11450. try {
  11451. filename = decodeURIComponent(filename);
  11452. } catch (ex) {}
  11453. }
  11454. if (/\.pdf$/i.test(filename)) {
  11455. return filename;
  11456. }
  11457. }
  11458. return null;
  11459. }
  11460. function createResponseStatusError(status, url) {
  11461. if (status === 404 || status === 0 && url.startsWith("file:")) {
  11462. return new _util.MissingPDFException('Missing PDF "' + url + '".');
  11463. }
  11464. return new _util.UnexpectedResponseException("Unexpected server response (" + status + ') while retrieving PDF "' + url + '".', status);
  11465. }
  11466. function validateResponseStatus(status) {
  11467. return status === 200 || status === 206;
  11468. }
  11469. /***/ }),
  11470. /* 25 */
  11471. /***/ ((__unused_webpack_module, exports) => {
  11472. Object.defineProperty(exports, "__esModule", ({
  11473. value: true
  11474. }));
  11475. exports.getFilenameFromContentDispositionHeader = getFilenameFromContentDispositionHeader;
  11476. function getFilenameFromContentDispositionHeader(contentDisposition) {
  11477. let needsEncodingFixup = true;
  11478. let tmp = toParamRegExp("filename\\*", "i").exec(contentDisposition);
  11479. if (tmp) {
  11480. tmp = tmp[1];
  11481. let filename = rfc2616unquote(tmp);
  11482. filename = unescape(filename);
  11483. filename = rfc5987decode(filename);
  11484. filename = rfc2047decode(filename);
  11485. return fixupEncoding(filename);
  11486. }
  11487. tmp = rfc2231getparam(contentDisposition);
  11488. if (tmp) {
  11489. const filename = rfc2047decode(tmp);
  11490. return fixupEncoding(filename);
  11491. }
  11492. tmp = toParamRegExp("filename", "i").exec(contentDisposition);
  11493. if (tmp) {
  11494. tmp = tmp[1];
  11495. let filename = rfc2616unquote(tmp);
  11496. filename = rfc2047decode(filename);
  11497. return fixupEncoding(filename);
  11498. }
  11499. function toParamRegExp(attributePattern, flags) {
  11500. return new RegExp("(?:^|;)\\s*" + attributePattern + "\\s*=\\s*" + "(" + '[^";\\s][^;\\s]*' + "|" + '"(?:[^"\\\\]|\\\\"?)+"?' + ")", flags);
  11501. }
  11502. function textdecode(encoding, value) {
  11503. if (encoding) {
  11504. if (!/^[\x00-\xFF]+$/.test(value)) {
  11505. return value;
  11506. }
  11507. try {
  11508. const decoder = new TextDecoder(encoding, {
  11509. fatal: true
  11510. });
  11511. const bytes = Array.from(value, function (ch) {
  11512. return ch.charCodeAt(0) & 0xff;
  11513. });
  11514. value = decoder.decode(new Uint8Array(bytes));
  11515. needsEncodingFixup = false;
  11516. } catch (e) {
  11517. if (/^utf-?8$/i.test(encoding)) {
  11518. try {
  11519. value = decodeURIComponent(escape(value));
  11520. needsEncodingFixup = false;
  11521. } catch (err) {}
  11522. }
  11523. }
  11524. }
  11525. return value;
  11526. }
  11527. function fixupEncoding(value) {
  11528. if (needsEncodingFixup && /[\x80-\xff]/.test(value)) {
  11529. value = textdecode("utf-8", value);
  11530. if (needsEncodingFixup) {
  11531. value = textdecode("iso-8859-1", value);
  11532. }
  11533. }
  11534. return value;
  11535. }
  11536. function rfc2231getparam(contentDispositionStr) {
  11537. const matches = [];
  11538. let match;
  11539. const iter = toParamRegExp("filename\\*((?!0\\d)\\d+)(\\*?)", "ig");
  11540. while ((match = iter.exec(contentDispositionStr)) !== null) {
  11541. let [, n, quot, part] = match;
  11542. n = parseInt(n, 10);
  11543. if (n in matches) {
  11544. if (n === 0) {
  11545. break;
  11546. }
  11547. continue;
  11548. }
  11549. matches[n] = [quot, part];
  11550. }
  11551. const parts = [];
  11552. for (let n = 0; n < matches.length; ++n) {
  11553. if (!(n in matches)) {
  11554. break;
  11555. }
  11556. let [quot, part] = matches[n];
  11557. part = rfc2616unquote(part);
  11558. if (quot) {
  11559. part = unescape(part);
  11560. if (n === 0) {
  11561. part = rfc5987decode(part);
  11562. }
  11563. }
  11564. parts.push(part);
  11565. }
  11566. return parts.join("");
  11567. }
  11568. function rfc2616unquote(value) {
  11569. if (value.startsWith('"')) {
  11570. const parts = value.slice(1).split('\\"');
  11571. for (let i = 0; i < parts.length; ++i) {
  11572. const quotindex = parts[i].indexOf('"');
  11573. if (quotindex !== -1) {
  11574. parts[i] = parts[i].slice(0, quotindex);
  11575. parts.length = i + 1;
  11576. }
  11577. parts[i] = parts[i].replace(/\\(.)/g, "$1");
  11578. }
  11579. value = parts.join('"');
  11580. }
  11581. return value;
  11582. }
  11583. function rfc5987decode(extvalue) {
  11584. const encodingend = extvalue.indexOf("'");
  11585. if (encodingend === -1) {
  11586. return extvalue;
  11587. }
  11588. const encoding = extvalue.slice(0, encodingend);
  11589. const langvalue = extvalue.slice(encodingend + 1);
  11590. const value = langvalue.replace(/^[^']*'/, "");
  11591. return textdecode(encoding, value);
  11592. }
  11593. function rfc2047decode(value) {
  11594. if (!value.startsWith("=?") || /[\x00-\x19\x80-\xff]/.test(value)) {
  11595. return value;
  11596. }
  11597. return value.replace(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g, function (matches, charset, encoding, text) {
  11598. if (encoding === "q" || encoding === "Q") {
  11599. text = text.replace(/_/g, " ");
  11600. text = text.replace(/=([0-9a-fA-F]{2})/g, function (match, hex) {
  11601. return String.fromCharCode(parseInt(hex, 16));
  11602. });
  11603. return textdecode(charset, text);
  11604. }
  11605. try {
  11606. text = atob(text);
  11607. } catch (e) {}
  11608. return textdecode(charset, text);
  11609. });
  11610. }
  11611. return "";
  11612. }
  11613. /***/ }),
  11614. /* 26 */
  11615. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  11616. Object.defineProperty(exports, "__esModule", ({
  11617. value: true
  11618. }));
  11619. exports.PDFNetworkStream = void 0;
  11620. var _util = __w_pdfjs_require__(2);
  11621. var _network_utils = __w_pdfjs_require__(24);
  11622. ;
  11623. const OK_RESPONSE = 200;
  11624. const PARTIAL_CONTENT_RESPONSE = 206;
  11625. function getArrayBuffer(xhr) {
  11626. const data = xhr.response;
  11627. if (typeof data !== "string") {
  11628. return data;
  11629. }
  11630. const array = (0, _util.stringToBytes)(data);
  11631. return array.buffer;
  11632. }
  11633. class NetworkManager {
  11634. constructor(url, args) {
  11635. this.url = url;
  11636. args = args || {};
  11637. this.isHttp = /^https?:/i.test(url);
  11638. this.httpHeaders = this.isHttp && args.httpHeaders || {};
  11639. this.withCredentials = args.withCredentials || false;
  11640. this.getXhr = args.getXhr || function NetworkManager_getXhr() {
  11641. return new XMLHttpRequest();
  11642. };
  11643. this.currXhrId = 0;
  11644. this.pendingRequests = Object.create(null);
  11645. }
  11646. requestRange(begin, end, listeners) {
  11647. const args = {
  11648. begin,
  11649. end
  11650. };
  11651. for (const prop in listeners) {
  11652. args[prop] = listeners[prop];
  11653. }
  11654. return this.request(args);
  11655. }
  11656. requestFull(listeners) {
  11657. return this.request(listeners);
  11658. }
  11659. request(args) {
  11660. const xhr = this.getXhr();
  11661. const xhrId = this.currXhrId++;
  11662. const pendingRequest = this.pendingRequests[xhrId] = {
  11663. xhr
  11664. };
  11665. xhr.open("GET", this.url);
  11666. xhr.withCredentials = this.withCredentials;
  11667. for (const property in this.httpHeaders) {
  11668. const value = this.httpHeaders[property];
  11669. if (typeof value === "undefined") {
  11670. continue;
  11671. }
  11672. xhr.setRequestHeader(property, value);
  11673. }
  11674. if (this.isHttp && "begin" in args && "end" in args) {
  11675. xhr.setRequestHeader("Range", `bytes=${args.begin}-${args.end - 1}`);
  11676. pendingRequest.expectedStatus = PARTIAL_CONTENT_RESPONSE;
  11677. } else {
  11678. pendingRequest.expectedStatus = OK_RESPONSE;
  11679. }
  11680. xhr.responseType = "arraybuffer";
  11681. if (args.onError) {
  11682. xhr.onerror = function (evt) {
  11683. args.onError(xhr.status);
  11684. };
  11685. }
  11686. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  11687. xhr.onprogress = this.onProgress.bind(this, xhrId);
  11688. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  11689. pendingRequest.onDone = args.onDone;
  11690. pendingRequest.onError = args.onError;
  11691. pendingRequest.onProgress = args.onProgress;
  11692. xhr.send(null);
  11693. return xhrId;
  11694. }
  11695. onProgress(xhrId, evt) {
  11696. const pendingRequest = this.pendingRequests[xhrId];
  11697. if (!pendingRequest) {
  11698. return;
  11699. }
  11700. if (pendingRequest.onProgress) {
  11701. pendingRequest.onProgress(evt);
  11702. }
  11703. }
  11704. onStateChange(xhrId, evt) {
  11705. const pendingRequest = this.pendingRequests[xhrId];
  11706. if (!pendingRequest) {
  11707. return;
  11708. }
  11709. const xhr = pendingRequest.xhr;
  11710. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  11711. pendingRequest.onHeadersReceived();
  11712. delete pendingRequest.onHeadersReceived;
  11713. }
  11714. if (xhr.readyState !== 4) {
  11715. return;
  11716. }
  11717. if (!(xhrId in this.pendingRequests)) {
  11718. return;
  11719. }
  11720. delete this.pendingRequests[xhrId];
  11721. if (xhr.status === 0 && this.isHttp) {
  11722. if (pendingRequest.onError) {
  11723. pendingRequest.onError(xhr.status);
  11724. }
  11725. return;
  11726. }
  11727. const xhrStatus = xhr.status || OK_RESPONSE;
  11728. const ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  11729. if (!ok_response_on_range_request && xhrStatus !== pendingRequest.expectedStatus) {
  11730. if (pendingRequest.onError) {
  11731. pendingRequest.onError(xhr.status);
  11732. }
  11733. return;
  11734. }
  11735. const chunk = getArrayBuffer(xhr);
  11736. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  11737. const rangeHeader = xhr.getResponseHeader("Content-Range");
  11738. const matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  11739. pendingRequest.onDone({
  11740. begin: parseInt(matches[1], 10),
  11741. chunk
  11742. });
  11743. } else if (chunk) {
  11744. pendingRequest.onDone({
  11745. begin: 0,
  11746. chunk
  11747. });
  11748. } else if (pendingRequest.onError) {
  11749. pendingRequest.onError(xhr.status);
  11750. }
  11751. }
  11752. getRequestXhr(xhrId) {
  11753. return this.pendingRequests[xhrId].xhr;
  11754. }
  11755. isPendingRequest(xhrId) {
  11756. return xhrId in this.pendingRequests;
  11757. }
  11758. abortRequest(xhrId) {
  11759. const xhr = this.pendingRequests[xhrId].xhr;
  11760. delete this.pendingRequests[xhrId];
  11761. xhr.abort();
  11762. }
  11763. }
  11764. class PDFNetworkStream {
  11765. constructor(source) {
  11766. this._source = source;
  11767. this._manager = new NetworkManager(source.url, {
  11768. httpHeaders: source.httpHeaders,
  11769. withCredentials: source.withCredentials
  11770. });
  11771. this._rangeChunkSize = source.rangeChunkSize;
  11772. this._fullRequestReader = null;
  11773. this._rangeRequestReaders = [];
  11774. }
  11775. _onRangeRequestReaderClosed(reader) {
  11776. const i = this._rangeRequestReaders.indexOf(reader);
  11777. if (i >= 0) {
  11778. this._rangeRequestReaders.splice(i, 1);
  11779. }
  11780. }
  11781. getFullReader() {
  11782. (0, _util.assert)(!this._fullRequestReader, "PDFNetworkStream.getFullReader can only be called once.");
  11783. this._fullRequestReader = new PDFNetworkStreamFullRequestReader(this._manager, this._source);
  11784. return this._fullRequestReader;
  11785. }
  11786. getRangeReader(begin, end) {
  11787. const reader = new PDFNetworkStreamRangeRequestReader(this._manager, begin, end);
  11788. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  11789. this._rangeRequestReaders.push(reader);
  11790. return reader;
  11791. }
  11792. cancelAllRequests(reason) {
  11793. if (this._fullRequestReader) {
  11794. this._fullRequestReader.cancel(reason);
  11795. }
  11796. const readers = this._rangeRequestReaders.slice(0);
  11797. readers.forEach(function (reader) {
  11798. reader.cancel(reason);
  11799. });
  11800. }
  11801. }
  11802. exports.PDFNetworkStream = PDFNetworkStream;
  11803. class PDFNetworkStreamFullRequestReader {
  11804. constructor(manager, source) {
  11805. this._manager = manager;
  11806. const args = {
  11807. onHeadersReceived: this._onHeadersReceived.bind(this),
  11808. onDone: this._onDone.bind(this),
  11809. onError: this._onError.bind(this),
  11810. onProgress: this._onProgress.bind(this)
  11811. };
  11812. this._url = source.url;
  11813. this._fullRequestId = manager.requestFull(args);
  11814. this._headersReceivedCapability = (0, _util.createPromiseCapability)();
  11815. this._disableRange = source.disableRange || false;
  11816. this._contentLength = source.length;
  11817. this._rangeChunkSize = source.rangeChunkSize;
  11818. if (!this._rangeChunkSize && !this._disableRange) {
  11819. this._disableRange = true;
  11820. }
  11821. this._isStreamingSupported = false;
  11822. this._isRangeSupported = false;
  11823. this._cachedChunks = [];
  11824. this._requests = [];
  11825. this._done = false;
  11826. this._storedError = undefined;
  11827. this._filename = null;
  11828. this.onProgress = null;
  11829. }
  11830. _onHeadersReceived() {
  11831. const fullRequestXhrId = this._fullRequestId;
  11832. const fullRequestXhr = this._manager.getRequestXhr(fullRequestXhrId);
  11833. const getResponseHeader = name => {
  11834. return fullRequestXhr.getResponseHeader(name);
  11835. };
  11836. const {
  11837. allowRangeRequests,
  11838. suggestedLength
  11839. } = (0, _network_utils.validateRangeRequestCapabilities)({
  11840. getResponseHeader,
  11841. isHttp: this._manager.isHttp,
  11842. rangeChunkSize: this._rangeChunkSize,
  11843. disableRange: this._disableRange
  11844. });
  11845. if (allowRangeRequests) {
  11846. this._isRangeSupported = true;
  11847. }
  11848. this._contentLength = suggestedLength || this._contentLength;
  11849. this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
  11850. if (this._isRangeSupported) {
  11851. this._manager.abortRequest(fullRequestXhrId);
  11852. }
  11853. this._headersReceivedCapability.resolve();
  11854. }
  11855. _onDone(args) {
  11856. if (args) {
  11857. if (this._requests.length > 0) {
  11858. const requestCapability = this._requests.shift();
  11859. requestCapability.resolve({
  11860. value: args.chunk,
  11861. done: false
  11862. });
  11863. } else {
  11864. this._cachedChunks.push(args.chunk);
  11865. }
  11866. }
  11867. this._done = true;
  11868. if (this._cachedChunks.length > 0) {
  11869. return;
  11870. }
  11871. this._requests.forEach(function (requestCapability) {
  11872. requestCapability.resolve({
  11873. value: undefined,
  11874. done: true
  11875. });
  11876. });
  11877. this._requests = [];
  11878. }
  11879. _onError(status) {
  11880. const url = this._url;
  11881. const exception = (0, _network_utils.createResponseStatusError)(status, url);
  11882. this._storedError = exception;
  11883. this._headersReceivedCapability.reject(exception);
  11884. this._requests.forEach(function (requestCapability) {
  11885. requestCapability.reject(exception);
  11886. });
  11887. this._requests = [];
  11888. this._cachedChunks = [];
  11889. }
  11890. _onProgress(data) {
  11891. if (this.onProgress) {
  11892. this.onProgress({
  11893. loaded: data.loaded,
  11894. total: data.lengthComputable ? data.total : this._contentLength
  11895. });
  11896. }
  11897. }
  11898. get filename() {
  11899. return this._filename;
  11900. }
  11901. get isRangeSupported() {
  11902. return this._isRangeSupported;
  11903. }
  11904. get isStreamingSupported() {
  11905. return this._isStreamingSupported;
  11906. }
  11907. get contentLength() {
  11908. return this._contentLength;
  11909. }
  11910. get headersReady() {
  11911. return this._headersReceivedCapability.promise;
  11912. }
  11913. async read() {
  11914. if (this._storedError) {
  11915. throw this._storedError;
  11916. }
  11917. if (this._cachedChunks.length > 0) {
  11918. const chunk = this._cachedChunks.shift();
  11919. return {
  11920. value: chunk,
  11921. done: false
  11922. };
  11923. }
  11924. if (this._done) {
  11925. return {
  11926. value: undefined,
  11927. done: true
  11928. };
  11929. }
  11930. const requestCapability = (0, _util.createPromiseCapability)();
  11931. this._requests.push(requestCapability);
  11932. return requestCapability.promise;
  11933. }
  11934. cancel(reason) {
  11935. this._done = true;
  11936. this._headersReceivedCapability.reject(reason);
  11937. this._requests.forEach(function (requestCapability) {
  11938. requestCapability.resolve({
  11939. value: undefined,
  11940. done: true
  11941. });
  11942. });
  11943. this._requests = [];
  11944. if (this._manager.isPendingRequest(this._fullRequestId)) {
  11945. this._manager.abortRequest(this._fullRequestId);
  11946. }
  11947. this._fullRequestReader = null;
  11948. }
  11949. }
  11950. class PDFNetworkStreamRangeRequestReader {
  11951. constructor(manager, begin, end) {
  11952. this._manager = manager;
  11953. const args = {
  11954. onDone: this._onDone.bind(this),
  11955. onProgress: this._onProgress.bind(this)
  11956. };
  11957. this._requestId = manager.requestRange(begin, end, args);
  11958. this._requests = [];
  11959. this._queuedChunk = null;
  11960. this._done = false;
  11961. this.onProgress = null;
  11962. this.onClosed = null;
  11963. }
  11964. _close() {
  11965. if (this.onClosed) {
  11966. this.onClosed(this);
  11967. }
  11968. }
  11969. _onDone(data) {
  11970. const chunk = data.chunk;
  11971. if (this._requests.length > 0) {
  11972. const requestCapability = this._requests.shift();
  11973. requestCapability.resolve({
  11974. value: chunk,
  11975. done: false
  11976. });
  11977. } else {
  11978. this._queuedChunk = chunk;
  11979. }
  11980. this._done = true;
  11981. this._requests.forEach(function (requestCapability) {
  11982. requestCapability.resolve({
  11983. value: undefined,
  11984. done: true
  11985. });
  11986. });
  11987. this._requests = [];
  11988. this._close();
  11989. }
  11990. _onProgress(evt) {
  11991. if (!this.isStreamingSupported && this.onProgress) {
  11992. this.onProgress({
  11993. loaded: evt.loaded
  11994. });
  11995. }
  11996. }
  11997. get isStreamingSupported() {
  11998. return false;
  11999. }
  12000. async read() {
  12001. if (this._queuedChunk !== null) {
  12002. const chunk = this._queuedChunk;
  12003. this._queuedChunk = null;
  12004. return {
  12005. value: chunk,
  12006. done: false
  12007. };
  12008. }
  12009. if (this._done) {
  12010. return {
  12011. value: undefined,
  12012. done: true
  12013. };
  12014. }
  12015. const requestCapability = (0, _util.createPromiseCapability)();
  12016. this._requests.push(requestCapability);
  12017. return requestCapability.promise;
  12018. }
  12019. cancel(reason) {
  12020. this._done = true;
  12021. this._requests.forEach(function (requestCapability) {
  12022. requestCapability.resolve({
  12023. value: undefined,
  12024. done: true
  12025. });
  12026. });
  12027. this._requests = [];
  12028. if (this._manager.isPendingRequest(this._requestId)) {
  12029. this._manager.abortRequest(this._requestId);
  12030. }
  12031. this._close();
  12032. }
  12033. }
  12034. /***/ }),
  12035. /* 27 */
  12036. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  12037. Object.defineProperty(exports, "__esModule", ({
  12038. value: true
  12039. }));
  12040. exports.PDFFetchStream = void 0;
  12041. var _util = __w_pdfjs_require__(2);
  12042. var _network_utils = __w_pdfjs_require__(24);
  12043. ;
  12044. function createFetchOptions(headers, withCredentials, abortController) {
  12045. return {
  12046. method: "GET",
  12047. headers,
  12048. signal: abortController?.signal,
  12049. mode: "cors",
  12050. credentials: withCredentials ? "include" : "same-origin",
  12051. redirect: "follow"
  12052. };
  12053. }
  12054. function createHeaders(httpHeaders) {
  12055. const headers = new Headers();
  12056. for (const property in httpHeaders) {
  12057. const value = httpHeaders[property];
  12058. if (typeof value === "undefined") {
  12059. continue;
  12060. }
  12061. headers.append(property, value);
  12062. }
  12063. return headers;
  12064. }
  12065. class PDFFetchStream {
  12066. constructor(source) {
  12067. this.source = source;
  12068. this.isHttp = /^https?:/i.test(source.url);
  12069. this.httpHeaders = this.isHttp && source.httpHeaders || {};
  12070. this._fullRequestReader = null;
  12071. this._rangeRequestReaders = [];
  12072. }
  12073. get _progressiveDataLength() {
  12074. return this._fullRequestReader?._loaded ?? 0;
  12075. }
  12076. getFullReader() {
  12077. (0, _util.assert)(!this._fullRequestReader, "PDFFetchStream.getFullReader can only be called once.");
  12078. this._fullRequestReader = new PDFFetchStreamReader(this);
  12079. return this._fullRequestReader;
  12080. }
  12081. getRangeReader(begin, end) {
  12082. if (end <= this._progressiveDataLength) {
  12083. return null;
  12084. }
  12085. const reader = new PDFFetchStreamRangeReader(this, begin, end);
  12086. this._rangeRequestReaders.push(reader);
  12087. return reader;
  12088. }
  12089. cancelAllRequests(reason) {
  12090. if (this._fullRequestReader) {
  12091. this._fullRequestReader.cancel(reason);
  12092. }
  12093. const readers = this._rangeRequestReaders.slice(0);
  12094. readers.forEach(function (reader) {
  12095. reader.cancel(reason);
  12096. });
  12097. }
  12098. }
  12099. exports.PDFFetchStream = PDFFetchStream;
  12100. class PDFFetchStreamReader {
  12101. constructor(stream) {
  12102. this._stream = stream;
  12103. this._reader = null;
  12104. this._loaded = 0;
  12105. this._filename = null;
  12106. const source = stream.source;
  12107. this._withCredentials = source.withCredentials || false;
  12108. this._contentLength = source.length;
  12109. this._headersCapability = (0, _util.createPromiseCapability)();
  12110. this._disableRange = source.disableRange || false;
  12111. this._rangeChunkSize = source.rangeChunkSize;
  12112. if (!this._rangeChunkSize && !this._disableRange) {
  12113. this._disableRange = true;
  12114. }
  12115. if (typeof AbortController !== "undefined") {
  12116. this._abortController = new AbortController();
  12117. }
  12118. this._isStreamingSupported = !source.disableStream;
  12119. this._isRangeSupported = !source.disableRange;
  12120. this._headers = createHeaders(this._stream.httpHeaders);
  12121. const url = source.url;
  12122. fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(response => {
  12123. if (!(0, _network_utils.validateResponseStatus)(response.status)) {
  12124. throw (0, _network_utils.createResponseStatusError)(response.status, url);
  12125. }
  12126. this._reader = response.body.getReader();
  12127. this._headersCapability.resolve();
  12128. const getResponseHeader = name => {
  12129. return response.headers.get(name);
  12130. };
  12131. const {
  12132. allowRangeRequests,
  12133. suggestedLength
  12134. } = (0, _network_utils.validateRangeRequestCapabilities)({
  12135. getResponseHeader,
  12136. isHttp: this._stream.isHttp,
  12137. rangeChunkSize: this._rangeChunkSize,
  12138. disableRange: this._disableRange
  12139. });
  12140. this._isRangeSupported = allowRangeRequests;
  12141. this._contentLength = suggestedLength || this._contentLength;
  12142. this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
  12143. if (!this._isStreamingSupported && this._isRangeSupported) {
  12144. this.cancel(new _util.AbortException("Streaming is disabled."));
  12145. }
  12146. }).catch(this._headersCapability.reject);
  12147. this.onProgress = null;
  12148. }
  12149. get headersReady() {
  12150. return this._headersCapability.promise;
  12151. }
  12152. get filename() {
  12153. return this._filename;
  12154. }
  12155. get contentLength() {
  12156. return this._contentLength;
  12157. }
  12158. get isRangeSupported() {
  12159. return this._isRangeSupported;
  12160. }
  12161. get isStreamingSupported() {
  12162. return this._isStreamingSupported;
  12163. }
  12164. async read() {
  12165. await this._headersCapability.promise;
  12166. const {
  12167. value,
  12168. done
  12169. } = await this._reader.read();
  12170. if (done) {
  12171. return {
  12172. value,
  12173. done
  12174. };
  12175. }
  12176. this._loaded += value.byteLength;
  12177. if (this.onProgress) {
  12178. this.onProgress({
  12179. loaded: this._loaded,
  12180. total: this._contentLength
  12181. });
  12182. }
  12183. const buffer = new Uint8Array(value).buffer;
  12184. return {
  12185. value: buffer,
  12186. done: false
  12187. };
  12188. }
  12189. cancel(reason) {
  12190. if (this._reader) {
  12191. this._reader.cancel(reason);
  12192. }
  12193. if (this._abortController) {
  12194. this._abortController.abort();
  12195. }
  12196. }
  12197. }
  12198. class PDFFetchStreamRangeReader {
  12199. constructor(stream, begin, end) {
  12200. this._stream = stream;
  12201. this._reader = null;
  12202. this._loaded = 0;
  12203. const source = stream.source;
  12204. this._withCredentials = source.withCredentials || false;
  12205. this._readCapability = (0, _util.createPromiseCapability)();
  12206. this._isStreamingSupported = !source.disableStream;
  12207. if (typeof AbortController !== "undefined") {
  12208. this._abortController = new AbortController();
  12209. }
  12210. this._headers = createHeaders(this._stream.httpHeaders);
  12211. this._headers.append("Range", `bytes=${begin}-${end - 1}`);
  12212. const url = source.url;
  12213. fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(response => {
  12214. if (!(0, _network_utils.validateResponseStatus)(response.status)) {
  12215. throw (0, _network_utils.createResponseStatusError)(response.status, url);
  12216. }
  12217. this._readCapability.resolve();
  12218. this._reader = response.body.getReader();
  12219. }).catch(reason => {
  12220. if (reason?.name === "AbortError") {
  12221. return;
  12222. }
  12223. throw reason;
  12224. });
  12225. this.onProgress = null;
  12226. }
  12227. get isStreamingSupported() {
  12228. return this._isStreamingSupported;
  12229. }
  12230. async read() {
  12231. await this._readCapability.promise;
  12232. const {
  12233. value,
  12234. done
  12235. } = await this._reader.read();
  12236. if (done) {
  12237. return {
  12238. value,
  12239. done
  12240. };
  12241. }
  12242. this._loaded += value.byteLength;
  12243. if (this.onProgress) {
  12244. this.onProgress({
  12245. loaded: this._loaded
  12246. });
  12247. }
  12248. const buffer = new Uint8Array(value).buffer;
  12249. return {
  12250. value: buffer,
  12251. done: false
  12252. };
  12253. }
  12254. cancel(reason) {
  12255. if (this._reader) {
  12256. this._reader.cancel(reason);
  12257. }
  12258. if (this._abortController) {
  12259. this._abortController.abort();
  12260. }
  12261. }
  12262. }
  12263. /***/ })
  12264. /******/ ]);
  12265. /************************************************************************/
  12266. /******/ // The module cache
  12267. /******/ var __webpack_module_cache__ = {};
  12268. /******/
  12269. /******/ // The require function
  12270. /******/ function __w_pdfjs_require__(moduleId) {
  12271. /******/ // Check if module is in cache
  12272. /******/ if(__webpack_module_cache__[moduleId]) {
  12273. /******/ return __webpack_module_cache__[moduleId].exports;
  12274. /******/ }
  12275. /******/ // Create a new module (and put it into the cache)
  12276. /******/ var module = __webpack_module_cache__[moduleId] = {
  12277. /******/ // no module.id needed
  12278. /******/ // no module.loaded needed
  12279. /******/ exports: {}
  12280. /******/ };
  12281. /******/
  12282. /******/ // Execute the module function
  12283. /******/ __webpack_modules__[moduleId](module, module.exports, __w_pdfjs_require__);
  12284. /******/
  12285. /******/ // Return the exports of the module
  12286. /******/ return module.exports;
  12287. /******/ }
  12288. /******/
  12289. /************************************************************************/
  12290. /******/ // module exports must be returned from runtime so entry inlining is disabled
  12291. /******/ // startup
  12292. /******/ // Load entry module and return exports
  12293. /******/ return __w_pdfjs_require__(0);
  12294. /******/ })()
  12295. ;
  12296. });
  12297. //# sourceMappingURL=pdf.js.map