pdf.js 412 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2021 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. (function webpackUniversalModuleDefinition(root, factory) {
  23. if(typeof exports === 'object' && typeof module === 'object')
  24. module.exports = factory();
  25. else if(typeof define === 'function' && define.amd)
  26. define("pdfjs-dist/build/pdf", [], factory);
  27. else if(typeof exports === 'object')
  28. exports["pdfjs-dist/build/pdf"] = factory();
  29. else
  30. root["pdfjs-dist/build/pdf"] = root.pdfjsLib = factory();
  31. })(this, function() {
  32. return /******/ (() => { // webpackBootstrap
  33. /******/ "use strict";
  34. /******/ var __webpack_modules__ = ([
  35. /* 0 */,
  36. /* 1 */
  37. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  38. Object.defineProperty(exports, "__esModule", ({
  39. value: true
  40. }));
  41. exports.StatTimer = exports.RenderingCancelledException = exports.PixelsPerInch = exports.PageViewport = exports.PDFDateString = exports.LinkTarget = exports.DOMStandardFontDataFactory = exports.DOMSVGFactory = exports.DOMCanvasFactory = exports.DOMCMapReaderFactory = void 0;
  42. exports.addLinkAttributes = addLinkAttributes;
  43. exports.deprecated = deprecated;
  44. exports.getFilenameFromUrl = getFilenameFromUrl;
  45. exports.getPdfFilenameFromUrl = getPdfFilenameFromUrl;
  46. exports.getXfaPageViewport = getXfaPageViewport;
  47. exports.isDataScheme = isDataScheme;
  48. exports.isPdfFile = isPdfFile;
  49. exports.isValidFetchUrl = isValidFetchUrl;
  50. exports.loadScript = loadScript;
  51. var _util = __w_pdfjs_require__(2);
  52. var _base_factory = __w_pdfjs_require__(5);
  53. const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
  54. const SVG_NS = "http://www.w3.org/2000/svg";
  55. const PixelsPerInch = {
  56. CSS: 96.0,
  57. PDF: 72.0,
  58. get PDF_TO_CSS_UNITS() {
  59. return (0, _util.shadow)(this, "PDF_TO_CSS_UNITS", this.CSS / this.PDF);
  60. }
  61. };
  62. exports.PixelsPerInch = PixelsPerInch;
  63. class DOMCanvasFactory extends _base_factory.BaseCanvasFactory {
  64. constructor({
  65. ownerDocument = globalThis.document
  66. } = {}) {
  67. super();
  68. this._document = ownerDocument;
  69. }
  70. _createCanvas(width, height) {
  71. const canvas = this._document.createElement("canvas");
  72. canvas.width = width;
  73. canvas.height = height;
  74. return canvas;
  75. }
  76. }
  77. exports.DOMCanvasFactory = DOMCanvasFactory;
  78. async function fetchData(url, asTypedArray = false) {
  79. if (isValidFetchUrl(url, document.baseURI)) {
  80. const response = await fetch(url);
  81. if (!response.ok) {
  82. throw new Error(response.statusText);
  83. }
  84. return asTypedArray ? new Uint8Array(await response.arrayBuffer()) : (0, _util.stringToBytes)(await response.text());
  85. }
  86. return new Promise((resolve, reject) => {
  87. const request = new XMLHttpRequest();
  88. request.open("GET", url, true);
  89. if (asTypedArray) {
  90. request.responseType = "arraybuffer";
  91. }
  92. request.onreadystatechange = () => {
  93. if (request.readyState !== XMLHttpRequest.DONE) {
  94. return;
  95. }
  96. if (request.status === 200 || request.status === 0) {
  97. let data;
  98. if (asTypedArray && request.response) {
  99. data = new Uint8Array(request.response);
  100. } else if (!asTypedArray && request.responseText) {
  101. data = (0, _util.stringToBytes)(request.responseText);
  102. }
  103. if (data) {
  104. resolve(data);
  105. return;
  106. }
  107. }
  108. reject(new Error(request.statusText));
  109. };
  110. request.send(null);
  111. });
  112. }
  113. class DOMCMapReaderFactory extends _base_factory.BaseCMapReaderFactory {
  114. _fetchData(url, compressionType) {
  115. return fetchData(url, this.isCompressed).then(data => {
  116. return {
  117. cMapData: data,
  118. compressionType
  119. };
  120. });
  121. }
  122. }
  123. exports.DOMCMapReaderFactory = DOMCMapReaderFactory;
  124. class DOMStandardFontDataFactory extends _base_factory.BaseStandardFontDataFactory {
  125. _fetchData(url) {
  126. return fetchData(url, true);
  127. }
  128. }
  129. exports.DOMStandardFontDataFactory = DOMStandardFontDataFactory;
  130. class DOMSVGFactory extends _base_factory.BaseSVGFactory {
  131. _createSVG(type) {
  132. return document.createElementNS(SVG_NS, type);
  133. }
  134. }
  135. exports.DOMSVGFactory = DOMSVGFactory;
  136. class PageViewport {
  137. constructor({
  138. viewBox,
  139. scale,
  140. rotation,
  141. offsetX = 0,
  142. offsetY = 0,
  143. dontFlip = false
  144. }) {
  145. this.viewBox = viewBox;
  146. this.scale = scale;
  147. this.rotation = rotation;
  148. this.offsetX = offsetX;
  149. this.offsetY = offsetY;
  150. const centerX = (viewBox[2] + viewBox[0]) / 2;
  151. const centerY = (viewBox[3] + viewBox[1]) / 2;
  152. let rotateA, rotateB, rotateC, rotateD;
  153. rotation %= 360;
  154. if (rotation < 0) {
  155. rotation += 360;
  156. }
  157. switch (rotation) {
  158. case 180:
  159. rotateA = -1;
  160. rotateB = 0;
  161. rotateC = 0;
  162. rotateD = 1;
  163. break;
  164. case 90:
  165. rotateA = 0;
  166. rotateB = 1;
  167. rotateC = 1;
  168. rotateD = 0;
  169. break;
  170. case 270:
  171. rotateA = 0;
  172. rotateB = -1;
  173. rotateC = -1;
  174. rotateD = 0;
  175. break;
  176. case 0:
  177. rotateA = 1;
  178. rotateB = 0;
  179. rotateC = 0;
  180. rotateD = -1;
  181. break;
  182. default:
  183. throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.");
  184. }
  185. if (dontFlip) {
  186. rotateC = -rotateC;
  187. rotateD = -rotateD;
  188. }
  189. let offsetCanvasX, offsetCanvasY;
  190. let width, height;
  191. if (rotateA === 0) {
  192. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  193. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  194. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  195. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  196. } else {
  197. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  198. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  199. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  200. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  201. }
  202. this.transform = [rotateA * scale, rotateB * scale, rotateC * scale, rotateD * scale, offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY, offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY];
  203. this.width = width;
  204. this.height = height;
  205. }
  206. clone({
  207. scale = this.scale,
  208. rotation = this.rotation,
  209. offsetX = this.offsetX,
  210. offsetY = this.offsetY,
  211. dontFlip = false
  212. } = {}) {
  213. return new PageViewport({
  214. viewBox: this.viewBox.slice(),
  215. scale,
  216. rotation,
  217. offsetX,
  218. offsetY,
  219. dontFlip
  220. });
  221. }
  222. convertToViewportPoint(x, y) {
  223. return _util.Util.applyTransform([x, y], this.transform);
  224. }
  225. convertToViewportRectangle(rect) {
  226. const topLeft = _util.Util.applyTransform([rect[0], rect[1]], this.transform);
  227. const bottomRight = _util.Util.applyTransform([rect[2], rect[3]], this.transform);
  228. return [topLeft[0], topLeft[1], bottomRight[0], bottomRight[1]];
  229. }
  230. convertToPdfPoint(x, y) {
  231. return _util.Util.applyInverseTransform([x, y], this.transform);
  232. }
  233. }
  234. exports.PageViewport = PageViewport;
  235. class RenderingCancelledException extends _util.BaseException {
  236. constructor(msg, type) {
  237. super(msg, "RenderingCancelledException");
  238. this.type = type;
  239. }
  240. }
  241. exports.RenderingCancelledException = RenderingCancelledException;
  242. const LinkTarget = {
  243. NONE: 0,
  244. SELF: 1,
  245. BLANK: 2,
  246. PARENT: 3,
  247. TOP: 4
  248. };
  249. exports.LinkTarget = LinkTarget;
  250. function addLinkAttributes(link, {
  251. url,
  252. target,
  253. rel,
  254. enabled = true
  255. } = {}) {
  256. (0, _util.assert)(url && typeof url === "string", 'addLinkAttributes: A valid "url" parameter must provided.');
  257. const urlNullRemoved = (0, _util.removeNullCharacters)(url);
  258. if (enabled) {
  259. link.href = link.title = urlNullRemoved;
  260. } else {
  261. link.href = "";
  262. link.title = `Disabled: ${urlNullRemoved}`;
  263. link.onclick = () => {
  264. return false;
  265. };
  266. }
  267. let targetStr = "";
  268. switch (target) {
  269. case LinkTarget.NONE:
  270. break;
  271. case LinkTarget.SELF:
  272. targetStr = "_self";
  273. break;
  274. case LinkTarget.BLANK:
  275. targetStr = "_blank";
  276. break;
  277. case LinkTarget.PARENT:
  278. targetStr = "_parent";
  279. break;
  280. case LinkTarget.TOP:
  281. targetStr = "_top";
  282. break;
  283. }
  284. link.target = targetStr;
  285. link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL;
  286. }
  287. function isDataScheme(url) {
  288. const ii = url.length;
  289. let i = 0;
  290. while (i < ii && url[i].trim() === "") {
  291. i++;
  292. }
  293. return url.substring(i, i + 5).toLowerCase() === "data:";
  294. }
  295. function isPdfFile(filename) {
  296. return typeof filename === "string" && /\.pdf$/i.test(filename);
  297. }
  298. function getFilenameFromUrl(url) {
  299. const anchor = url.indexOf("#");
  300. const query = url.indexOf("?");
  301. const end = Math.min(anchor > 0 ? anchor : url.length, query > 0 ? query : url.length);
  302. return url.substring(url.lastIndexOf("/", end) + 1, end);
  303. }
  304. function getPdfFilenameFromUrl(url, defaultFilename = "document.pdf") {
  305. if (typeof url !== "string") {
  306. return defaultFilename;
  307. }
  308. if (isDataScheme(url)) {
  309. (0, _util.warn)('getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.');
  310. return defaultFilename;
  311. }
  312. const reURI = /^(?:(?:[^:]+:)?\/\/[^/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
  313. const reFilename = /[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
  314. const splitURI = reURI.exec(url);
  315. let suggestedFilename = reFilename.exec(splitURI[1]) || reFilename.exec(splitURI[2]) || reFilename.exec(splitURI[3]);
  316. if (suggestedFilename) {
  317. suggestedFilename = suggestedFilename[0];
  318. if (suggestedFilename.includes("%")) {
  319. try {
  320. suggestedFilename = reFilename.exec(decodeURIComponent(suggestedFilename))[0];
  321. } catch (ex) {}
  322. }
  323. }
  324. return suggestedFilename || defaultFilename;
  325. }
  326. class StatTimer {
  327. constructor() {
  328. this.started = Object.create(null);
  329. this.times = [];
  330. }
  331. time(name) {
  332. if (name in this.started) {
  333. (0, _util.warn)(`Timer is already running for ${name}`);
  334. }
  335. this.started[name] = Date.now();
  336. }
  337. timeEnd(name) {
  338. if (!(name in this.started)) {
  339. (0, _util.warn)(`Timer has not been started for ${name}`);
  340. }
  341. this.times.push({
  342. name,
  343. start: this.started[name],
  344. end: Date.now()
  345. });
  346. delete this.started[name];
  347. }
  348. toString() {
  349. const outBuf = [];
  350. let longest = 0;
  351. for (const time of this.times) {
  352. const name = time.name;
  353. if (name.length > longest) {
  354. longest = name.length;
  355. }
  356. }
  357. for (const time of this.times) {
  358. const duration = time.end - time.start;
  359. outBuf.push(`${time.name.padEnd(longest)} ${duration}ms\n`);
  360. }
  361. return outBuf.join("");
  362. }
  363. }
  364. exports.StatTimer = StatTimer;
  365. function isValidFetchUrl(url, baseUrl) {
  366. try {
  367. const {
  368. protocol
  369. } = baseUrl ? new URL(url, baseUrl) : new URL(url);
  370. return protocol === "http:" || protocol === "https:";
  371. } catch (ex) {
  372. return false;
  373. }
  374. }
  375. function loadScript(src, removeScriptElement = false) {
  376. return new Promise((resolve, reject) => {
  377. const script = document.createElement("script");
  378. script.src = src;
  379. script.onload = function (evt) {
  380. if (removeScriptElement) {
  381. script.remove();
  382. }
  383. resolve(evt);
  384. };
  385. script.onerror = function () {
  386. reject(new Error(`Cannot load script at: ${script.src}`));
  387. };
  388. (document.head || document.documentElement).appendChild(script);
  389. });
  390. }
  391. function deprecated(details) {
  392. console.log("Deprecated API usage: " + details);
  393. }
  394. let pdfDateStringRegex;
  395. class PDFDateString {
  396. static toDateObject(input) {
  397. if (!input || !(0, _util.isString)(input)) {
  398. return null;
  399. }
  400. if (!pdfDateStringRegex) {
  401. pdfDateStringRegex = new RegExp("^D:" + "(\\d{4})" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "([Z|+|-])?" + "(\\d{2})?" + "'?" + "(\\d{2})?" + "'?");
  402. }
  403. const matches = pdfDateStringRegex.exec(input);
  404. if (!matches) {
  405. return null;
  406. }
  407. const year = parseInt(matches[1], 10);
  408. let month = parseInt(matches[2], 10);
  409. month = month >= 1 && month <= 12 ? month - 1 : 0;
  410. let day = parseInt(matches[3], 10);
  411. day = day >= 1 && day <= 31 ? day : 1;
  412. let hour = parseInt(matches[4], 10);
  413. hour = hour >= 0 && hour <= 23 ? hour : 0;
  414. let minute = parseInt(matches[5], 10);
  415. minute = minute >= 0 && minute <= 59 ? minute : 0;
  416. let second = parseInt(matches[6], 10);
  417. second = second >= 0 && second <= 59 ? second : 0;
  418. const universalTimeRelation = matches[7] || "Z";
  419. let offsetHour = parseInt(matches[8], 10);
  420. offsetHour = offsetHour >= 0 && offsetHour <= 23 ? offsetHour : 0;
  421. let offsetMinute = parseInt(matches[9], 10) || 0;
  422. offsetMinute = offsetMinute >= 0 && offsetMinute <= 59 ? offsetMinute : 0;
  423. if (universalTimeRelation === "-") {
  424. hour += offsetHour;
  425. minute += offsetMinute;
  426. } else if (universalTimeRelation === "+") {
  427. hour -= offsetHour;
  428. minute -= offsetMinute;
  429. }
  430. return new Date(Date.UTC(year, month, day, hour, minute, second));
  431. }
  432. }
  433. exports.PDFDateString = PDFDateString;
  434. function getXfaPageViewport(xfaPage, {
  435. scale = 1,
  436. rotation = 0
  437. }) {
  438. const {
  439. width,
  440. height
  441. } = xfaPage.attributes.style;
  442. const viewBox = [0, 0, parseInt(width), parseInt(height)];
  443. return new PageViewport({
  444. viewBox,
  445. scale,
  446. rotation
  447. });
  448. }
  449. /***/ }),
  450. /* 2 */
  451. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  452. Object.defineProperty(exports, "__esModule", ({
  453. value: true
  454. }));
  455. exports.VerbosityLevel = exports.Util = exports.UnknownErrorException = exports.UnexpectedResponseException = exports.UNSUPPORTED_FEATURES = exports.TextRenderingMode = exports.StreamType = exports.RenderingIntentFlag = exports.PermissionFlag = exports.PasswordResponses = exports.PasswordException = exports.PageActionEventType = exports.OPS = exports.MissingPDFException = exports.IsLittleEndianCached = exports.IsEvalSupportedCached = exports.InvalidPDFException = exports.ImageKind = exports.IDENTITY_MATRIX = exports.FormatError = exports.FontType = exports.FONT_IDENTITY_MATRIX = exports.DocumentActionEventType = exports.CMapCompressionType = exports.BaseException = exports.AnnotationType = exports.AnnotationStateModelType = exports.AnnotationReviewState = exports.AnnotationReplyType = exports.AnnotationMode = exports.AnnotationMarkedState = exports.AnnotationFlag = exports.AnnotationFieldFlag = exports.AnnotationBorderStyleType = exports.AnnotationActionEventType = exports.AbortException = void 0;
  456. exports.arrayByteLength = arrayByteLength;
  457. exports.arraysToBytes = arraysToBytes;
  458. exports.assert = assert;
  459. exports.bytesToString = bytesToString;
  460. exports.createObjectURL = createObjectURL;
  461. exports.createPromiseCapability = createPromiseCapability;
  462. exports.createValidAbsoluteUrl = createValidAbsoluteUrl;
  463. exports.escapeString = escapeString;
  464. exports.getModificationDate = getModificationDate;
  465. exports.getVerbosityLevel = getVerbosityLevel;
  466. exports.info = info;
  467. exports.isArrayBuffer = isArrayBuffer;
  468. exports.isArrayEqual = isArrayEqual;
  469. exports.isAscii = isAscii;
  470. exports.isBool = isBool;
  471. exports.isNum = isNum;
  472. exports.isSameOrigin = isSameOrigin;
  473. exports.isString = isString;
  474. exports.objectFromMap = objectFromMap;
  475. exports.objectSize = objectSize;
  476. exports.removeNullCharacters = removeNullCharacters;
  477. exports.setVerbosityLevel = setVerbosityLevel;
  478. exports.shadow = shadow;
  479. exports.string32 = string32;
  480. exports.stringToBytes = stringToBytes;
  481. exports.stringToPDFString = stringToPDFString;
  482. exports.stringToUTF16BEString = stringToUTF16BEString;
  483. exports.stringToUTF8String = stringToUTF8String;
  484. exports.unreachable = unreachable;
  485. exports.utf8StringToString = utf8StringToString;
  486. exports.warn = warn;
  487. __w_pdfjs_require__(3);
  488. const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  489. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  490. const FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  491. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  492. const RenderingIntentFlag = {
  493. ANY: 0x01,
  494. DISPLAY: 0x02,
  495. PRINT: 0x04,
  496. ANNOTATIONS_FORMS: 0x10,
  497. ANNOTATIONS_STORAGE: 0x20,
  498. ANNOTATIONS_DISABLE: 0x40,
  499. OPLIST: 0x100
  500. };
  501. exports.RenderingIntentFlag = RenderingIntentFlag;
  502. const AnnotationMode = {
  503. DISABLE: 0,
  504. ENABLE: 1,
  505. ENABLE_FORMS: 2,
  506. ENABLE_STORAGE: 3
  507. };
  508. exports.AnnotationMode = AnnotationMode;
  509. const PermissionFlag = {
  510. PRINT: 0x04,
  511. MODIFY_CONTENTS: 0x08,
  512. COPY: 0x10,
  513. MODIFY_ANNOTATIONS: 0x20,
  514. FILL_INTERACTIVE_FORMS: 0x100,
  515. COPY_FOR_ACCESSIBILITY: 0x200,
  516. ASSEMBLE: 0x400,
  517. PRINT_HIGH_QUALITY: 0x800
  518. };
  519. exports.PermissionFlag = PermissionFlag;
  520. const TextRenderingMode = {
  521. FILL: 0,
  522. STROKE: 1,
  523. FILL_STROKE: 2,
  524. INVISIBLE: 3,
  525. FILL_ADD_TO_PATH: 4,
  526. STROKE_ADD_TO_PATH: 5,
  527. FILL_STROKE_ADD_TO_PATH: 6,
  528. ADD_TO_PATH: 7,
  529. FILL_STROKE_MASK: 3,
  530. ADD_TO_PATH_FLAG: 4
  531. };
  532. exports.TextRenderingMode = TextRenderingMode;
  533. const ImageKind = {
  534. GRAYSCALE_1BPP: 1,
  535. RGB_24BPP: 2,
  536. RGBA_32BPP: 3
  537. };
  538. exports.ImageKind = ImageKind;
  539. const AnnotationType = {
  540. TEXT: 1,
  541. LINK: 2,
  542. FREETEXT: 3,
  543. LINE: 4,
  544. SQUARE: 5,
  545. CIRCLE: 6,
  546. POLYGON: 7,
  547. POLYLINE: 8,
  548. HIGHLIGHT: 9,
  549. UNDERLINE: 10,
  550. SQUIGGLY: 11,
  551. STRIKEOUT: 12,
  552. STAMP: 13,
  553. CARET: 14,
  554. INK: 15,
  555. POPUP: 16,
  556. FILEATTACHMENT: 17,
  557. SOUND: 18,
  558. MOVIE: 19,
  559. WIDGET: 20,
  560. SCREEN: 21,
  561. PRINTERMARK: 22,
  562. TRAPNET: 23,
  563. WATERMARK: 24,
  564. THREED: 25,
  565. REDACT: 26
  566. };
  567. exports.AnnotationType = AnnotationType;
  568. const AnnotationStateModelType = {
  569. MARKED: "Marked",
  570. REVIEW: "Review"
  571. };
  572. exports.AnnotationStateModelType = AnnotationStateModelType;
  573. const AnnotationMarkedState = {
  574. MARKED: "Marked",
  575. UNMARKED: "Unmarked"
  576. };
  577. exports.AnnotationMarkedState = AnnotationMarkedState;
  578. const AnnotationReviewState = {
  579. ACCEPTED: "Accepted",
  580. REJECTED: "Rejected",
  581. CANCELLED: "Cancelled",
  582. COMPLETED: "Completed",
  583. NONE: "None"
  584. };
  585. exports.AnnotationReviewState = AnnotationReviewState;
  586. const AnnotationReplyType = {
  587. GROUP: "Group",
  588. REPLY: "R"
  589. };
  590. exports.AnnotationReplyType = AnnotationReplyType;
  591. const AnnotationFlag = {
  592. INVISIBLE: 0x01,
  593. HIDDEN: 0x02,
  594. PRINT: 0x04,
  595. NOZOOM: 0x08,
  596. NOROTATE: 0x10,
  597. NOVIEW: 0x20,
  598. READONLY: 0x40,
  599. LOCKED: 0x80,
  600. TOGGLENOVIEW: 0x100,
  601. LOCKEDCONTENTS: 0x200
  602. };
  603. exports.AnnotationFlag = AnnotationFlag;
  604. const AnnotationFieldFlag = {
  605. READONLY: 0x0000001,
  606. REQUIRED: 0x0000002,
  607. NOEXPORT: 0x0000004,
  608. MULTILINE: 0x0001000,
  609. PASSWORD: 0x0002000,
  610. NOTOGGLETOOFF: 0x0004000,
  611. RADIO: 0x0008000,
  612. PUSHBUTTON: 0x0010000,
  613. COMBO: 0x0020000,
  614. EDIT: 0x0040000,
  615. SORT: 0x0080000,
  616. FILESELECT: 0x0100000,
  617. MULTISELECT: 0x0200000,
  618. DONOTSPELLCHECK: 0x0400000,
  619. DONOTSCROLL: 0x0800000,
  620. COMB: 0x1000000,
  621. RICHTEXT: 0x2000000,
  622. RADIOSINUNISON: 0x2000000,
  623. COMMITONSELCHANGE: 0x4000000
  624. };
  625. exports.AnnotationFieldFlag = AnnotationFieldFlag;
  626. const AnnotationBorderStyleType = {
  627. SOLID: 1,
  628. DASHED: 2,
  629. BEVELED: 3,
  630. INSET: 4,
  631. UNDERLINE: 5
  632. };
  633. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  634. const AnnotationActionEventType = {
  635. E: "Mouse Enter",
  636. X: "Mouse Exit",
  637. D: "Mouse Down",
  638. U: "Mouse Up",
  639. Fo: "Focus",
  640. Bl: "Blur",
  641. PO: "PageOpen",
  642. PC: "PageClose",
  643. PV: "PageVisible",
  644. PI: "PageInvisible",
  645. K: "Keystroke",
  646. F: "Format",
  647. V: "Validate",
  648. C: "Calculate"
  649. };
  650. exports.AnnotationActionEventType = AnnotationActionEventType;
  651. const DocumentActionEventType = {
  652. WC: "WillClose",
  653. WS: "WillSave",
  654. DS: "DidSave",
  655. WP: "WillPrint",
  656. DP: "DidPrint"
  657. };
  658. exports.DocumentActionEventType = DocumentActionEventType;
  659. const PageActionEventType = {
  660. O: "PageOpen",
  661. C: "PageClose"
  662. };
  663. exports.PageActionEventType = PageActionEventType;
  664. const StreamType = {
  665. UNKNOWN: "UNKNOWN",
  666. FLATE: "FLATE",
  667. LZW: "LZW",
  668. DCT: "DCT",
  669. JPX: "JPX",
  670. JBIG: "JBIG",
  671. A85: "A85",
  672. AHX: "AHX",
  673. CCF: "CCF",
  674. RLX: "RLX"
  675. };
  676. exports.StreamType = StreamType;
  677. const FontType = {
  678. UNKNOWN: "UNKNOWN",
  679. TYPE1: "TYPE1",
  680. TYPE1STANDARD: "TYPE1STANDARD",
  681. TYPE1C: "TYPE1C",
  682. CIDFONTTYPE0: "CIDFONTTYPE0",
  683. CIDFONTTYPE0C: "CIDFONTTYPE0C",
  684. TRUETYPE: "TRUETYPE",
  685. CIDFONTTYPE2: "CIDFONTTYPE2",
  686. TYPE3: "TYPE3",
  687. OPENTYPE: "OPENTYPE",
  688. TYPE0: "TYPE0",
  689. MMTYPE1: "MMTYPE1"
  690. };
  691. exports.FontType = FontType;
  692. const VerbosityLevel = {
  693. ERRORS: 0,
  694. WARNINGS: 1,
  695. INFOS: 5
  696. };
  697. exports.VerbosityLevel = VerbosityLevel;
  698. const CMapCompressionType = {
  699. NONE: 0,
  700. BINARY: 1,
  701. STREAM: 2
  702. };
  703. exports.CMapCompressionType = CMapCompressionType;
  704. const OPS = {
  705. dependency: 1,
  706. setLineWidth: 2,
  707. setLineCap: 3,
  708. setLineJoin: 4,
  709. setMiterLimit: 5,
  710. setDash: 6,
  711. setRenderingIntent: 7,
  712. setFlatness: 8,
  713. setGState: 9,
  714. save: 10,
  715. restore: 11,
  716. transform: 12,
  717. moveTo: 13,
  718. lineTo: 14,
  719. curveTo: 15,
  720. curveTo2: 16,
  721. curveTo3: 17,
  722. closePath: 18,
  723. rectangle: 19,
  724. stroke: 20,
  725. closeStroke: 21,
  726. fill: 22,
  727. eoFill: 23,
  728. fillStroke: 24,
  729. eoFillStroke: 25,
  730. closeFillStroke: 26,
  731. closeEOFillStroke: 27,
  732. endPath: 28,
  733. clip: 29,
  734. eoClip: 30,
  735. beginText: 31,
  736. endText: 32,
  737. setCharSpacing: 33,
  738. setWordSpacing: 34,
  739. setHScale: 35,
  740. setLeading: 36,
  741. setFont: 37,
  742. setTextRenderingMode: 38,
  743. setTextRise: 39,
  744. moveText: 40,
  745. setLeadingMoveText: 41,
  746. setTextMatrix: 42,
  747. nextLine: 43,
  748. showText: 44,
  749. showSpacedText: 45,
  750. nextLineShowText: 46,
  751. nextLineSetSpacingShowText: 47,
  752. setCharWidth: 48,
  753. setCharWidthAndBounds: 49,
  754. setStrokeColorSpace: 50,
  755. setFillColorSpace: 51,
  756. setStrokeColor: 52,
  757. setStrokeColorN: 53,
  758. setFillColor: 54,
  759. setFillColorN: 55,
  760. setStrokeGray: 56,
  761. setFillGray: 57,
  762. setStrokeRGBColor: 58,
  763. setFillRGBColor: 59,
  764. setStrokeCMYKColor: 60,
  765. setFillCMYKColor: 61,
  766. shadingFill: 62,
  767. beginInlineImage: 63,
  768. beginImageData: 64,
  769. endInlineImage: 65,
  770. paintXObject: 66,
  771. markPoint: 67,
  772. markPointProps: 68,
  773. beginMarkedContent: 69,
  774. beginMarkedContentProps: 70,
  775. endMarkedContent: 71,
  776. beginCompat: 72,
  777. endCompat: 73,
  778. paintFormXObjectBegin: 74,
  779. paintFormXObjectEnd: 75,
  780. beginGroup: 76,
  781. endGroup: 77,
  782. beginAnnotations: 78,
  783. endAnnotations: 79,
  784. beginAnnotation: 80,
  785. endAnnotation: 81,
  786. paintJpegXObject: 82,
  787. paintImageMaskXObject: 83,
  788. paintImageMaskXObjectGroup: 84,
  789. paintImageXObject: 85,
  790. paintInlineImageXObject: 86,
  791. paintInlineImageXObjectGroup: 87,
  792. paintImageXObjectRepeat: 88,
  793. paintImageMaskXObjectRepeat: 89,
  794. paintSolidColorImageMask: 90,
  795. constructPath: 91
  796. };
  797. exports.OPS = OPS;
  798. const UNSUPPORTED_FEATURES = {
  799. unknown: "unknown",
  800. forms: "forms",
  801. javaScript: "javaScript",
  802. signatures: "signatures",
  803. smask: "smask",
  804. shadingPattern: "shadingPattern",
  805. font: "font",
  806. errorTilingPattern: "errorTilingPattern",
  807. errorExtGState: "errorExtGState",
  808. errorXObject: "errorXObject",
  809. errorFontLoadType3: "errorFontLoadType3",
  810. errorFontState: "errorFontState",
  811. errorFontMissing: "errorFontMissing",
  812. errorFontTranslate: "errorFontTranslate",
  813. errorColorSpace: "errorColorSpace",
  814. errorOperatorList: "errorOperatorList",
  815. errorFontToUnicode: "errorFontToUnicode",
  816. errorFontLoadNative: "errorFontLoadNative",
  817. errorFontBuildPath: "errorFontBuildPath",
  818. errorFontGetPath: "errorFontGetPath",
  819. errorMarkedContent: "errorMarkedContent",
  820. errorContentSubStream: "errorContentSubStream"
  821. };
  822. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  823. const PasswordResponses = {
  824. NEED_PASSWORD: 1,
  825. INCORRECT_PASSWORD: 2
  826. };
  827. exports.PasswordResponses = PasswordResponses;
  828. let verbosity = VerbosityLevel.WARNINGS;
  829. function setVerbosityLevel(level) {
  830. if (Number.isInteger(level)) {
  831. verbosity = level;
  832. }
  833. }
  834. function getVerbosityLevel() {
  835. return verbosity;
  836. }
  837. function info(msg) {
  838. if (verbosity >= VerbosityLevel.INFOS) {
  839. console.log(`Info: ${msg}`);
  840. }
  841. }
  842. function warn(msg) {
  843. if (verbosity >= VerbosityLevel.WARNINGS) {
  844. console.log(`Warning: ${msg}`);
  845. }
  846. }
  847. function unreachable(msg) {
  848. throw new Error(msg);
  849. }
  850. function assert(cond, msg) {
  851. if (!cond) {
  852. unreachable(msg);
  853. }
  854. }
  855. function isSameOrigin(baseUrl, otherUrl) {
  856. let base;
  857. try {
  858. base = new URL(baseUrl);
  859. if (!base.origin || base.origin === "null") {
  860. return false;
  861. }
  862. } catch (e) {
  863. return false;
  864. }
  865. const other = new URL(otherUrl, base);
  866. return base.origin === other.origin;
  867. }
  868. function _isValidProtocol(url) {
  869. if (!url) {
  870. return false;
  871. }
  872. switch (url.protocol) {
  873. case "http:":
  874. case "https:":
  875. case "ftp:":
  876. case "mailto:":
  877. case "tel:":
  878. return true;
  879. default:
  880. return false;
  881. }
  882. }
  883. function createValidAbsoluteUrl(url, baseUrl = null, options = null) {
  884. if (!url) {
  885. return null;
  886. }
  887. try {
  888. if (options && typeof url === "string") {
  889. if (options.addDefaultProtocol && url.startsWith("www.")) {
  890. const dots = url.match(/\./g);
  891. if (dots && dots.length >= 2) {
  892. url = `http://${url}`;
  893. }
  894. }
  895. if (options.tryConvertEncoding) {
  896. try {
  897. url = stringToUTF8String(url);
  898. } catch (ex) {}
  899. }
  900. }
  901. const absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url);
  902. if (_isValidProtocol(absoluteUrl)) {
  903. return absoluteUrl;
  904. }
  905. } catch (ex) {}
  906. return null;
  907. }
  908. function shadow(obj, prop, value) {
  909. Object.defineProperty(obj, prop, {
  910. value,
  911. enumerable: true,
  912. configurable: true,
  913. writable: false
  914. });
  915. return value;
  916. }
  917. const BaseException = function BaseExceptionClosure() {
  918. function BaseException(message, name) {
  919. if (this.constructor === BaseException) {
  920. unreachable("Cannot initialize BaseException.");
  921. }
  922. this.message = message;
  923. this.name = name;
  924. }
  925. BaseException.prototype = new Error();
  926. BaseException.constructor = BaseException;
  927. return BaseException;
  928. }();
  929. exports.BaseException = BaseException;
  930. class PasswordException extends BaseException {
  931. constructor(msg, code) {
  932. super(msg, "PasswordException");
  933. this.code = code;
  934. }
  935. }
  936. exports.PasswordException = PasswordException;
  937. class UnknownErrorException extends BaseException {
  938. constructor(msg, details) {
  939. super(msg, "UnknownErrorException");
  940. this.details = details;
  941. }
  942. }
  943. exports.UnknownErrorException = UnknownErrorException;
  944. class InvalidPDFException extends BaseException {
  945. constructor(msg) {
  946. super(msg, "InvalidPDFException");
  947. }
  948. }
  949. exports.InvalidPDFException = InvalidPDFException;
  950. class MissingPDFException extends BaseException {
  951. constructor(msg) {
  952. super(msg, "MissingPDFException");
  953. }
  954. }
  955. exports.MissingPDFException = MissingPDFException;
  956. class UnexpectedResponseException extends BaseException {
  957. constructor(msg, status) {
  958. super(msg, "UnexpectedResponseException");
  959. this.status = status;
  960. }
  961. }
  962. exports.UnexpectedResponseException = UnexpectedResponseException;
  963. class FormatError extends BaseException {
  964. constructor(msg) {
  965. super(msg, "FormatError");
  966. }
  967. }
  968. exports.FormatError = FormatError;
  969. class AbortException extends BaseException {
  970. constructor(msg) {
  971. super(msg, "AbortException");
  972. }
  973. }
  974. exports.AbortException = AbortException;
  975. const NullCharactersRegExp = /\x00+/g;
  976. const InvisibleCharactersRegExp = /[\x01-\x1F]/g;
  977. function removeNullCharacters(str, replaceInvisible = false) {
  978. if (typeof str !== "string") {
  979. warn("The argument for removeNullCharacters must be a string.");
  980. return str;
  981. }
  982. if (replaceInvisible) {
  983. str = str.replace(InvisibleCharactersRegExp, " ");
  984. }
  985. return str.replace(NullCharactersRegExp, "");
  986. }
  987. function bytesToString(bytes) {
  988. assert(bytes !== null && typeof bytes === "object" && bytes.length !== undefined, "Invalid argument for bytesToString");
  989. const length = bytes.length;
  990. const MAX_ARGUMENT_COUNT = 8192;
  991. if (length < MAX_ARGUMENT_COUNT) {
  992. return String.fromCharCode.apply(null, bytes);
  993. }
  994. const strBuf = [];
  995. for (let i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  996. const chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  997. const chunk = bytes.subarray(i, chunkEnd);
  998. strBuf.push(String.fromCharCode.apply(null, chunk));
  999. }
  1000. return strBuf.join("");
  1001. }
  1002. function stringToBytes(str) {
  1003. assert(typeof str === "string", "Invalid argument for stringToBytes");
  1004. const length = str.length;
  1005. const bytes = new Uint8Array(length);
  1006. for (let i = 0; i < length; ++i) {
  1007. bytes[i] = str.charCodeAt(i) & 0xff;
  1008. }
  1009. return bytes;
  1010. }
  1011. function arrayByteLength(arr) {
  1012. if (arr.length !== undefined) {
  1013. return arr.length;
  1014. }
  1015. assert(arr.byteLength !== undefined, "arrayByteLength - invalid argument.");
  1016. return arr.byteLength;
  1017. }
  1018. function arraysToBytes(arr) {
  1019. const length = arr.length;
  1020. if (length === 1 && arr[0] instanceof Uint8Array) {
  1021. return arr[0];
  1022. }
  1023. let resultLength = 0;
  1024. for (let i = 0; i < length; i++) {
  1025. resultLength += arrayByteLength(arr[i]);
  1026. }
  1027. let pos = 0;
  1028. const data = new Uint8Array(resultLength);
  1029. for (let i = 0; i < length; i++) {
  1030. let item = arr[i];
  1031. if (!(item instanceof Uint8Array)) {
  1032. if (typeof item === "string") {
  1033. item = stringToBytes(item);
  1034. } else {
  1035. item = new Uint8Array(item);
  1036. }
  1037. }
  1038. const itemLength = item.byteLength;
  1039. data.set(item, pos);
  1040. pos += itemLength;
  1041. }
  1042. return data;
  1043. }
  1044. function string32(value) {
  1045. return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
  1046. }
  1047. function objectSize(obj) {
  1048. return Object.keys(obj).length;
  1049. }
  1050. function objectFromMap(map) {
  1051. const obj = Object.create(null);
  1052. for (const [key, value] of map) {
  1053. obj[key] = value;
  1054. }
  1055. return obj;
  1056. }
  1057. function isLittleEndian() {
  1058. const buffer8 = new Uint8Array(4);
  1059. buffer8[0] = 1;
  1060. const view32 = new Uint32Array(buffer8.buffer, 0, 1);
  1061. return view32[0] === 1;
  1062. }
  1063. const IsLittleEndianCached = {
  1064. get value() {
  1065. return shadow(this, "value", isLittleEndian());
  1066. }
  1067. };
  1068. exports.IsLittleEndianCached = IsLittleEndianCached;
  1069. function isEvalSupported() {
  1070. try {
  1071. new Function("");
  1072. return true;
  1073. } catch (e) {
  1074. return false;
  1075. }
  1076. }
  1077. const IsEvalSupportedCached = {
  1078. get value() {
  1079. return shadow(this, "value", isEvalSupported());
  1080. }
  1081. };
  1082. exports.IsEvalSupportedCached = IsEvalSupportedCached;
  1083. const hexNumbers = [...Array(256).keys()].map(n => n.toString(16).padStart(2, "0"));
  1084. class Util {
  1085. static makeHexColor(r, g, b) {
  1086. return `#${hexNumbers[r]}${hexNumbers[g]}${hexNumbers[b]}`;
  1087. }
  1088. static transform(m1, m2) {
  1089. 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]];
  1090. }
  1091. static applyTransform(p, m) {
  1092. const xt = p[0] * m[0] + p[1] * m[2] + m[4];
  1093. const yt = p[0] * m[1] + p[1] * m[3] + m[5];
  1094. return [xt, yt];
  1095. }
  1096. static applyInverseTransform(p, m) {
  1097. const d = m[0] * m[3] - m[1] * m[2];
  1098. const xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  1099. const yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  1100. return [xt, yt];
  1101. }
  1102. static getAxialAlignedBoundingBox(r, m) {
  1103. const p1 = Util.applyTransform(r, m);
  1104. const p2 = Util.applyTransform(r.slice(2, 4), m);
  1105. const p3 = Util.applyTransform([r[0], r[3]], m);
  1106. const p4 = Util.applyTransform([r[2], r[1]], m);
  1107. 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])];
  1108. }
  1109. static inverseTransform(m) {
  1110. const d = m[0] * m[3] - m[1] * m[2];
  1111. 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];
  1112. }
  1113. static apply3dTransform(m, v) {
  1114. 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]];
  1115. }
  1116. static singularValueDecompose2dScale(m) {
  1117. const transpose = [m[0], m[2], m[1], m[3]];
  1118. const a = m[0] * transpose[0] + m[1] * transpose[2];
  1119. const b = m[0] * transpose[1] + m[1] * transpose[3];
  1120. const c = m[2] * transpose[0] + m[3] * transpose[2];
  1121. const d = m[2] * transpose[1] + m[3] * transpose[3];
  1122. const first = (a + d) / 2;
  1123. const second = Math.sqrt((a + d) ** 2 - 4 * (a * d - c * b)) / 2;
  1124. const sx = first + second || 1;
  1125. const sy = first - second || 1;
  1126. return [Math.sqrt(sx), Math.sqrt(sy)];
  1127. }
  1128. static normalizeRect(rect) {
  1129. const r = rect.slice(0);
  1130. if (rect[0] > rect[2]) {
  1131. r[0] = rect[2];
  1132. r[2] = rect[0];
  1133. }
  1134. if (rect[1] > rect[3]) {
  1135. r[1] = rect[3];
  1136. r[3] = rect[1];
  1137. }
  1138. return r;
  1139. }
  1140. static intersect(rect1, rect2) {
  1141. function compare(a, b) {
  1142. return a - b;
  1143. }
  1144. const orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare);
  1145. const orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare);
  1146. const result = [];
  1147. rect1 = Util.normalizeRect(rect1);
  1148. rect2 = Util.normalizeRect(rect2);
  1149. if (orderedX[0] === rect1[0] && orderedX[1] === rect2[0] || orderedX[0] === rect2[0] && orderedX[1] === rect1[0]) {
  1150. result[0] = orderedX[1];
  1151. result[2] = orderedX[2];
  1152. } else {
  1153. return null;
  1154. }
  1155. if (orderedY[0] === rect1[1] && orderedY[1] === rect2[1] || orderedY[0] === rect2[1] && orderedY[1] === rect1[1]) {
  1156. result[1] = orderedY[1];
  1157. result[3] = orderedY[2];
  1158. } else {
  1159. return null;
  1160. }
  1161. return result;
  1162. }
  1163. static bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3) {
  1164. const tvalues = [],
  1165. bounds = [[], []];
  1166. let a, b, c, t, t1, t2, b2ac, sqrtb2ac;
  1167. for (let i = 0; i < 2; ++i) {
  1168. if (i === 0) {
  1169. b = 6 * x0 - 12 * x1 + 6 * x2;
  1170. a = -3 * x0 + 9 * x1 - 9 * x2 + 3 * x3;
  1171. c = 3 * x1 - 3 * x0;
  1172. } else {
  1173. b = 6 * y0 - 12 * y1 + 6 * y2;
  1174. a = -3 * y0 + 9 * y1 - 9 * y2 + 3 * y3;
  1175. c = 3 * y1 - 3 * y0;
  1176. }
  1177. if (Math.abs(a) < 1e-12) {
  1178. if (Math.abs(b) < 1e-12) {
  1179. continue;
  1180. }
  1181. t = -c / b;
  1182. if (0 < t && t < 1) {
  1183. tvalues.push(t);
  1184. }
  1185. continue;
  1186. }
  1187. b2ac = b * b - 4 * c * a;
  1188. sqrtb2ac = Math.sqrt(b2ac);
  1189. if (b2ac < 0) {
  1190. continue;
  1191. }
  1192. t1 = (-b + sqrtb2ac) / (2 * a);
  1193. if (0 < t1 && t1 < 1) {
  1194. tvalues.push(t1);
  1195. }
  1196. t2 = (-b - sqrtb2ac) / (2 * a);
  1197. if (0 < t2 && t2 < 1) {
  1198. tvalues.push(t2);
  1199. }
  1200. }
  1201. let j = tvalues.length,
  1202. mt;
  1203. const jlen = j;
  1204. while (j--) {
  1205. t = tvalues[j];
  1206. mt = 1 - t;
  1207. bounds[0][j] = mt * mt * mt * x0 + 3 * mt * mt * t * x1 + 3 * mt * t * t * x2 + t * t * t * x3;
  1208. bounds[1][j] = mt * mt * mt * y0 + 3 * mt * mt * t * y1 + 3 * mt * t * t * y2 + t * t * t * y3;
  1209. }
  1210. bounds[0][jlen] = x0;
  1211. bounds[1][jlen] = y0;
  1212. bounds[0][jlen + 1] = x3;
  1213. bounds[1][jlen + 1] = y3;
  1214. bounds[0].length = bounds[1].length = jlen + 2;
  1215. return [Math.min(...bounds[0]), Math.min(...bounds[1]), Math.max(...bounds[0]), Math.max(...bounds[1])];
  1216. }
  1217. }
  1218. exports.Util = Util;
  1219. 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];
  1220. function stringToPDFString(str) {
  1221. const length = str.length,
  1222. strBuf = [];
  1223. if (str[0] === "\xFE" && str[1] === "\xFF") {
  1224. for (let i = 2; i < length; i += 2) {
  1225. strBuf.push(String.fromCharCode(str.charCodeAt(i) << 8 | str.charCodeAt(i + 1)));
  1226. }
  1227. } else if (str[0] === "\xFF" && str[1] === "\xFE") {
  1228. for (let i = 2; i < length; i += 2) {
  1229. strBuf.push(String.fromCharCode(str.charCodeAt(i + 1) << 8 | str.charCodeAt(i)));
  1230. }
  1231. } else {
  1232. for (let i = 0; i < length; ++i) {
  1233. const code = PDFStringTranslateTable[str.charCodeAt(i)];
  1234. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  1235. }
  1236. }
  1237. return strBuf.join("");
  1238. }
  1239. function escapeString(str) {
  1240. return str.replace(/([()\\\n\r])/g, match => {
  1241. if (match === "\n") {
  1242. return "\\n";
  1243. } else if (match === "\r") {
  1244. return "\\r";
  1245. }
  1246. return `\\${match}`;
  1247. });
  1248. }
  1249. function isAscii(str) {
  1250. return /^[\x00-\x7F]*$/.test(str);
  1251. }
  1252. function stringToUTF16BEString(str) {
  1253. const buf = ["\xFE\xFF"];
  1254. for (let i = 0, ii = str.length; i < ii; i++) {
  1255. const char = str.charCodeAt(i);
  1256. buf.push(String.fromCharCode(char >> 8 & 0xff), String.fromCharCode(char & 0xff));
  1257. }
  1258. return buf.join("");
  1259. }
  1260. function stringToUTF8String(str) {
  1261. return decodeURIComponent(escape(str));
  1262. }
  1263. function utf8StringToString(str) {
  1264. return unescape(encodeURIComponent(str));
  1265. }
  1266. function isBool(v) {
  1267. return typeof v === "boolean";
  1268. }
  1269. function isNum(v) {
  1270. return typeof v === "number";
  1271. }
  1272. function isString(v) {
  1273. return typeof v === "string";
  1274. }
  1275. function isArrayBuffer(v) {
  1276. return typeof v === "object" && v !== null && v.byteLength !== undefined;
  1277. }
  1278. function isArrayEqual(arr1, arr2) {
  1279. if (arr1.length !== arr2.length) {
  1280. return false;
  1281. }
  1282. for (let i = 0, ii = arr1.length; i < ii; i++) {
  1283. if (arr1[i] !== arr2[i]) {
  1284. return false;
  1285. }
  1286. }
  1287. return true;
  1288. }
  1289. function getModificationDate(date = new Date()) {
  1290. 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")];
  1291. return buffer.join("");
  1292. }
  1293. function createPromiseCapability() {
  1294. const capability = Object.create(null);
  1295. let isSettled = false;
  1296. Object.defineProperty(capability, "settled", {
  1297. get() {
  1298. return isSettled;
  1299. }
  1300. });
  1301. capability.promise = new Promise(function (resolve, reject) {
  1302. capability.resolve = function (data) {
  1303. isSettled = true;
  1304. resolve(data);
  1305. };
  1306. capability.reject = function (reason) {
  1307. isSettled = true;
  1308. reject(reason);
  1309. };
  1310. });
  1311. return capability;
  1312. }
  1313. function createObjectURL(data, contentType = "", forceDataSchema = false) {
  1314. if (URL.createObjectURL && typeof Blob !== "undefined" && !forceDataSchema) {
  1315. return URL.createObjectURL(new Blob([data], {
  1316. type: contentType
  1317. }));
  1318. }
  1319. const digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  1320. let buffer = `data:${contentType};base64,`;
  1321. for (let i = 0, ii = data.length; i < ii; i += 3) {
  1322. const b1 = data[i] & 0xff;
  1323. const b2 = data[i + 1] & 0xff;
  1324. const b3 = data[i + 2] & 0xff;
  1325. const d1 = b1 >> 2,
  1326. d2 = (b1 & 3) << 4 | b2 >> 4;
  1327. const d3 = i + 1 < ii ? (b2 & 0xf) << 2 | b3 >> 6 : 64;
  1328. const d4 = i + 2 < ii ? b3 & 0x3f : 64;
  1329. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1330. }
  1331. return buffer;
  1332. }
  1333. /***/ }),
  1334. /* 3 */
  1335. /***/ ((__unused_webpack_module, __unused_webpack_exports, __w_pdfjs_require__) => {
  1336. var _is_node = __w_pdfjs_require__(4);
  1337. ;
  1338. /***/ }),
  1339. /* 4 */
  1340. /***/ ((__unused_webpack_module, exports) => {
  1341. Object.defineProperty(exports, "__esModule", ({
  1342. value: true
  1343. }));
  1344. exports.isNodeJS = void 0;
  1345. const isNodeJS = typeof process === "object" && process + "" === "[object process]" && !process.versions.nw && !(process.versions.electron && process.type && process.type !== "browser");
  1346. exports.isNodeJS = isNodeJS;
  1347. /***/ }),
  1348. /* 5 */
  1349. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  1350. Object.defineProperty(exports, "__esModule", ({
  1351. value: true
  1352. }));
  1353. exports.BaseStandardFontDataFactory = exports.BaseSVGFactory = exports.BaseCanvasFactory = exports.BaseCMapReaderFactory = void 0;
  1354. var _util = __w_pdfjs_require__(2);
  1355. class BaseCanvasFactory {
  1356. constructor() {
  1357. if (this.constructor === BaseCanvasFactory) {
  1358. (0, _util.unreachable)("Cannot initialize BaseCanvasFactory.");
  1359. }
  1360. }
  1361. create(width, height) {
  1362. if (width <= 0 || height <= 0) {
  1363. throw new Error("Invalid canvas size");
  1364. }
  1365. const canvas = this._createCanvas(width, height);
  1366. return {
  1367. canvas,
  1368. context: canvas.getContext("2d")
  1369. };
  1370. }
  1371. reset(canvasAndContext, width, height) {
  1372. if (!canvasAndContext.canvas) {
  1373. throw new Error("Canvas is not specified");
  1374. }
  1375. if (width <= 0 || height <= 0) {
  1376. throw new Error("Invalid canvas size");
  1377. }
  1378. canvasAndContext.canvas.width = width;
  1379. canvasAndContext.canvas.height = height;
  1380. }
  1381. destroy(canvasAndContext) {
  1382. if (!canvasAndContext.canvas) {
  1383. throw new Error("Canvas is not specified");
  1384. }
  1385. canvasAndContext.canvas.width = 0;
  1386. canvasAndContext.canvas.height = 0;
  1387. canvasAndContext.canvas = null;
  1388. canvasAndContext.context = null;
  1389. }
  1390. _createCanvas(width, height) {
  1391. (0, _util.unreachable)("Abstract method `_createCanvas` called.");
  1392. }
  1393. }
  1394. exports.BaseCanvasFactory = BaseCanvasFactory;
  1395. class BaseCMapReaderFactory {
  1396. constructor({
  1397. baseUrl = null,
  1398. isCompressed = false
  1399. }) {
  1400. if (this.constructor === BaseCMapReaderFactory) {
  1401. (0, _util.unreachable)("Cannot initialize BaseCMapReaderFactory.");
  1402. }
  1403. this.baseUrl = baseUrl;
  1404. this.isCompressed = isCompressed;
  1405. }
  1406. async fetch({
  1407. name
  1408. }) {
  1409. if (!this.baseUrl) {
  1410. throw new Error('The CMap "baseUrl" parameter must be specified, ensure that ' + 'the "cMapUrl" and "cMapPacked" API parameters are provided.');
  1411. }
  1412. if (!name) {
  1413. throw new Error("CMap name must be specified.");
  1414. }
  1415. const url = this.baseUrl + name + (this.isCompressed ? ".bcmap" : "");
  1416. const compressionType = this.isCompressed ? _util.CMapCompressionType.BINARY : _util.CMapCompressionType.NONE;
  1417. return this._fetchData(url, compressionType).catch(reason => {
  1418. throw new Error(`Unable to load ${this.isCompressed ? "binary " : ""}CMap at: ${url}`);
  1419. });
  1420. }
  1421. _fetchData(url, compressionType) {
  1422. (0, _util.unreachable)("Abstract method `_fetchData` called.");
  1423. }
  1424. }
  1425. exports.BaseCMapReaderFactory = BaseCMapReaderFactory;
  1426. class BaseStandardFontDataFactory {
  1427. constructor({
  1428. baseUrl = null
  1429. }) {
  1430. if (this.constructor === BaseStandardFontDataFactory) {
  1431. (0, _util.unreachable)("Cannot initialize BaseStandardFontDataFactory.");
  1432. }
  1433. this.baseUrl = baseUrl;
  1434. }
  1435. async fetch({
  1436. filename
  1437. }) {
  1438. if (!this.baseUrl) {
  1439. throw new Error('The standard font "baseUrl" parameter must be specified, ensure that ' + 'the "standardFontDataUrl" API parameter is provided.');
  1440. }
  1441. if (!filename) {
  1442. throw new Error("Font filename must be specified.");
  1443. }
  1444. const url = `${this.baseUrl}${filename}`;
  1445. return this._fetchData(url).catch(reason => {
  1446. throw new Error(`Unable to load font data at: ${url}`);
  1447. });
  1448. }
  1449. _fetchData(url) {
  1450. (0, _util.unreachable)("Abstract method `_fetchData` called.");
  1451. }
  1452. }
  1453. exports.BaseStandardFontDataFactory = BaseStandardFontDataFactory;
  1454. class BaseSVGFactory {
  1455. constructor() {
  1456. if (this.constructor === BaseSVGFactory) {
  1457. (0, _util.unreachable)("Cannot initialize BaseSVGFactory.");
  1458. }
  1459. }
  1460. create(width, height) {
  1461. if (width <= 0 || height <= 0) {
  1462. throw new Error("Invalid SVG dimensions");
  1463. }
  1464. const svg = this._createSVG("svg:svg");
  1465. svg.setAttribute("version", "1.1");
  1466. svg.setAttribute("width", `${width}px`);
  1467. svg.setAttribute("height", `${height}px`);
  1468. svg.setAttribute("preserveAspectRatio", "none");
  1469. svg.setAttribute("viewBox", `0 0 ${width} ${height}`);
  1470. return svg;
  1471. }
  1472. createElement(type) {
  1473. if (typeof type !== "string") {
  1474. throw new Error("Invalid SVG element type");
  1475. }
  1476. return this._createSVG(type);
  1477. }
  1478. _createSVG(type) {
  1479. (0, _util.unreachable)("Abstract method `_createSVG` called.");
  1480. }
  1481. }
  1482. exports.BaseSVGFactory = BaseSVGFactory;
  1483. /***/ }),
  1484. /* 6 */
  1485. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  1486. Object.defineProperty(exports, "__esModule", ({
  1487. value: true
  1488. }));
  1489. exports.build = exports.RenderTask = exports.PDFWorker = exports.PDFPageProxy = exports.PDFDocumentProxy = exports.PDFDocumentLoadingTask = exports.PDFDataRangeTransport = exports.LoopbackPort = exports.DefaultStandardFontDataFactory = exports.DefaultCanvasFactory = exports.DefaultCMapReaderFactory = void 0;
  1490. exports.getDocument = getDocument;
  1491. exports.setPDFNetworkStreamFactory = setPDFNetworkStreamFactory;
  1492. exports.version = void 0;
  1493. var _util = __w_pdfjs_require__(2);
  1494. var _display_utils = __w_pdfjs_require__(1);
  1495. var _font_loader = __w_pdfjs_require__(7);
  1496. var _node_utils = __w_pdfjs_require__(8);
  1497. var _annotation_storage = __w_pdfjs_require__(9);
  1498. var _canvas = __w_pdfjs_require__(10);
  1499. var _worker_options = __w_pdfjs_require__(12);
  1500. var _is_node = __w_pdfjs_require__(4);
  1501. var _message_handler = __w_pdfjs_require__(13);
  1502. var _metadata = __w_pdfjs_require__(14);
  1503. var _optional_content_config = __w_pdfjs_require__(15);
  1504. var _transport_stream = __w_pdfjs_require__(16);
  1505. var _xfa_text = __w_pdfjs_require__(17);
  1506. const DEFAULT_RANGE_CHUNK_SIZE = 65536;
  1507. const RENDERING_CANCELLED_TIMEOUT = 100;
  1508. const DefaultCanvasFactory = _is_node.isNodeJS ? _node_utils.NodeCanvasFactory : _display_utils.DOMCanvasFactory;
  1509. exports.DefaultCanvasFactory = DefaultCanvasFactory;
  1510. const DefaultCMapReaderFactory = _is_node.isNodeJS ? _node_utils.NodeCMapReaderFactory : _display_utils.DOMCMapReaderFactory;
  1511. exports.DefaultCMapReaderFactory = DefaultCMapReaderFactory;
  1512. const DefaultStandardFontDataFactory = _is_node.isNodeJS ? _node_utils.NodeStandardFontDataFactory : _display_utils.DOMStandardFontDataFactory;
  1513. exports.DefaultStandardFontDataFactory = DefaultStandardFontDataFactory;
  1514. let createPDFNetworkStream;
  1515. function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) {
  1516. createPDFNetworkStream = pdfNetworkStreamFactory;
  1517. }
  1518. function getDocument(src) {
  1519. const task = new PDFDocumentLoadingTask();
  1520. let source;
  1521. if (typeof src === "string" || src instanceof URL) {
  1522. source = {
  1523. url: src
  1524. };
  1525. } else if ((0, _util.isArrayBuffer)(src)) {
  1526. source = {
  1527. data: src
  1528. };
  1529. } else if (src instanceof PDFDataRangeTransport) {
  1530. source = {
  1531. range: src
  1532. };
  1533. } else {
  1534. if (typeof src !== "object") {
  1535. throw new Error("Invalid parameter in getDocument, " + "need either string, URL, Uint8Array, or parameter object.");
  1536. }
  1537. if (!src.url && !src.data && !src.range) {
  1538. throw new Error("Invalid parameter object: need either .data, .range or .url");
  1539. }
  1540. source = src;
  1541. }
  1542. const params = Object.create(null);
  1543. let rangeTransport = null,
  1544. worker = null;
  1545. for (const key in source) {
  1546. const value = source[key];
  1547. switch (key) {
  1548. case "url":
  1549. if (typeof window !== "undefined") {
  1550. try {
  1551. params[key] = new URL(value, window.location).href;
  1552. continue;
  1553. } catch (ex) {
  1554. (0, _util.warn)(`Cannot create valid URL: "${ex}".`);
  1555. }
  1556. } else if (typeof value === "string" || value instanceof URL) {
  1557. params[key] = value.toString();
  1558. continue;
  1559. }
  1560. throw new Error("Invalid PDF url data: " + "either string or URL-object is expected in the url property.");
  1561. case "range":
  1562. rangeTransport = value;
  1563. continue;
  1564. case "worker":
  1565. worker = value;
  1566. continue;
  1567. case "data":
  1568. if (_is_node.isNodeJS && typeof Buffer !== "undefined" && value instanceof Buffer) {
  1569. params[key] = new Uint8Array(value);
  1570. } else if (value instanceof Uint8Array) {
  1571. break;
  1572. } else if (typeof value === "string") {
  1573. params[key] = (0, _util.stringToBytes)(value);
  1574. } else if (typeof value === "object" && value !== null && !isNaN(value.length)) {
  1575. params[key] = new Uint8Array(value);
  1576. } else if ((0, _util.isArrayBuffer)(value)) {
  1577. params[key] = new Uint8Array(value);
  1578. } else {
  1579. throw new Error("Invalid PDF binary data: either typed array, " + "string, or array-like object is expected in the data property.");
  1580. }
  1581. continue;
  1582. }
  1583. params[key] = value;
  1584. }
  1585. params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
  1586. params.CMapReaderFactory = params.CMapReaderFactory || DefaultCMapReaderFactory;
  1587. params.StandardFontDataFactory = params.StandardFontDataFactory || DefaultStandardFontDataFactory;
  1588. params.ignoreErrors = params.stopAtErrors !== true;
  1589. params.fontExtraProperties = params.fontExtraProperties === true;
  1590. params.pdfBug = params.pdfBug === true;
  1591. params.enableXfa = params.enableXfa === true;
  1592. if (typeof params.docBaseUrl !== "string" || (0, _display_utils.isDataScheme)(params.docBaseUrl)) {
  1593. params.docBaseUrl = null;
  1594. }
  1595. if (!Number.isInteger(params.maxImageSize)) {
  1596. params.maxImageSize = -1;
  1597. }
  1598. if (typeof params.useWorkerFetch !== "boolean") {
  1599. params.useWorkerFetch = params.CMapReaderFactory === _display_utils.DOMCMapReaderFactory && params.StandardFontDataFactory === _display_utils.DOMStandardFontDataFactory;
  1600. }
  1601. if (typeof params.isEvalSupported !== "boolean") {
  1602. params.isEvalSupported = true;
  1603. }
  1604. if (typeof params.disableFontFace !== "boolean") {
  1605. params.disableFontFace = _is_node.isNodeJS;
  1606. }
  1607. if (typeof params.useSystemFonts !== "boolean") {
  1608. params.useSystemFonts = !_is_node.isNodeJS && !params.disableFontFace;
  1609. }
  1610. if (typeof params.ownerDocument === "undefined") {
  1611. params.ownerDocument = globalThis.document;
  1612. }
  1613. if (typeof params.disableRange !== "boolean") {
  1614. params.disableRange = false;
  1615. }
  1616. if (typeof params.disableStream !== "boolean") {
  1617. params.disableStream = false;
  1618. }
  1619. if (typeof params.disableAutoFetch !== "boolean") {
  1620. params.disableAutoFetch = false;
  1621. }
  1622. (0, _util.setVerbosityLevel)(params.verbosity);
  1623. if (!worker) {
  1624. const workerParams = {
  1625. verbosity: params.verbosity,
  1626. port: _worker_options.GlobalWorkerOptions.workerPort
  1627. };
  1628. worker = workerParams.port ? PDFWorker.fromPort(workerParams) : new PDFWorker(workerParams);
  1629. task._worker = worker;
  1630. }
  1631. const docId = task.docId;
  1632. worker.promise.then(function () {
  1633. if (task.destroyed) {
  1634. throw new Error("Loading aborted");
  1635. }
  1636. const workerIdPromise = _fetchDocument(worker, params, rangeTransport, docId);
  1637. const networkStreamPromise = new Promise(function (resolve) {
  1638. let networkStream;
  1639. if (rangeTransport) {
  1640. networkStream = new _transport_stream.PDFDataTransportStream({
  1641. length: params.length,
  1642. initialData: params.initialData,
  1643. progressiveDone: params.progressiveDone,
  1644. contentDispositionFilename: params.contentDispositionFilename,
  1645. disableRange: params.disableRange,
  1646. disableStream: params.disableStream
  1647. }, rangeTransport);
  1648. } else if (!params.data) {
  1649. networkStream = createPDFNetworkStream({
  1650. url: params.url,
  1651. length: params.length,
  1652. httpHeaders: params.httpHeaders,
  1653. withCredentials: params.withCredentials,
  1654. rangeChunkSize: params.rangeChunkSize,
  1655. disableRange: params.disableRange,
  1656. disableStream: params.disableStream
  1657. });
  1658. }
  1659. resolve(networkStream);
  1660. });
  1661. return Promise.all([workerIdPromise, networkStreamPromise]).then(function ([workerId, networkStream]) {
  1662. if (task.destroyed) {
  1663. throw new Error("Loading aborted");
  1664. }
  1665. const messageHandler = new _message_handler.MessageHandler(docId, workerId, worker.port);
  1666. const transport = new WorkerTransport(messageHandler, task, networkStream, params);
  1667. task._transport = transport;
  1668. messageHandler.send("Ready", null);
  1669. });
  1670. }).catch(task._capability.reject);
  1671. return task;
  1672. }
  1673. async function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
  1674. if (worker.destroyed) {
  1675. throw new Error("Worker was destroyed");
  1676. }
  1677. if (pdfDataRangeTransport) {
  1678. source.length = pdfDataRangeTransport.length;
  1679. source.initialData = pdfDataRangeTransport.initialData;
  1680. source.progressiveDone = pdfDataRangeTransport.progressiveDone;
  1681. source.contentDispositionFilename = pdfDataRangeTransport.contentDispositionFilename;
  1682. }
  1683. const workerId = await worker.messageHandler.sendWithPromise("GetDocRequest", {
  1684. docId,
  1685. apiVersion: '2.12.313',
  1686. source: {
  1687. data: source.data,
  1688. url: source.url,
  1689. password: source.password,
  1690. disableAutoFetch: source.disableAutoFetch,
  1691. rangeChunkSize: source.rangeChunkSize,
  1692. length: source.length
  1693. },
  1694. maxImageSize: source.maxImageSize,
  1695. disableFontFace: source.disableFontFace,
  1696. docBaseUrl: source.docBaseUrl,
  1697. ignoreErrors: source.ignoreErrors,
  1698. isEvalSupported: source.isEvalSupported,
  1699. fontExtraProperties: source.fontExtraProperties,
  1700. enableXfa: source.enableXfa,
  1701. useSystemFonts: source.useSystemFonts,
  1702. cMapUrl: source.useWorkerFetch ? source.cMapUrl : null,
  1703. standardFontDataUrl: source.useWorkerFetch ? source.standardFontDataUrl : null
  1704. });
  1705. if (worker.destroyed) {
  1706. throw new Error("Worker was destroyed");
  1707. }
  1708. return workerId;
  1709. }
  1710. class PDFDocumentLoadingTask {
  1711. static get idCounters() {
  1712. return (0, _util.shadow)(this, "idCounters", {
  1713. doc: 0
  1714. });
  1715. }
  1716. constructor() {
  1717. this._capability = (0, _util.createPromiseCapability)();
  1718. this._transport = null;
  1719. this._worker = null;
  1720. this.docId = `d${PDFDocumentLoadingTask.idCounters.doc++}`;
  1721. this.destroyed = false;
  1722. this.onPassword = null;
  1723. this.onProgress = null;
  1724. this.onUnsupportedFeature = null;
  1725. }
  1726. get promise() {
  1727. return this._capability.promise;
  1728. }
  1729. async destroy() {
  1730. this.destroyed = true;
  1731. await this._transport?.destroy();
  1732. this._transport = null;
  1733. if (this._worker) {
  1734. this._worker.destroy();
  1735. this._worker = null;
  1736. }
  1737. }
  1738. }
  1739. exports.PDFDocumentLoadingTask = PDFDocumentLoadingTask;
  1740. class PDFDataRangeTransport {
  1741. constructor(length, initialData, progressiveDone = false, contentDispositionFilename = null) {
  1742. this.length = length;
  1743. this.initialData = initialData;
  1744. this.progressiveDone = progressiveDone;
  1745. this.contentDispositionFilename = contentDispositionFilename;
  1746. this._rangeListeners = [];
  1747. this._progressListeners = [];
  1748. this._progressiveReadListeners = [];
  1749. this._progressiveDoneListeners = [];
  1750. this._readyCapability = (0, _util.createPromiseCapability)();
  1751. }
  1752. addRangeListener(listener) {
  1753. this._rangeListeners.push(listener);
  1754. }
  1755. addProgressListener(listener) {
  1756. this._progressListeners.push(listener);
  1757. }
  1758. addProgressiveReadListener(listener) {
  1759. this._progressiveReadListeners.push(listener);
  1760. }
  1761. addProgressiveDoneListener(listener) {
  1762. this._progressiveDoneListeners.push(listener);
  1763. }
  1764. onDataRange(begin, chunk) {
  1765. for (const listener of this._rangeListeners) {
  1766. listener(begin, chunk);
  1767. }
  1768. }
  1769. onDataProgress(loaded, total) {
  1770. this._readyCapability.promise.then(() => {
  1771. for (const listener of this._progressListeners) {
  1772. listener(loaded, total);
  1773. }
  1774. });
  1775. }
  1776. onDataProgressiveRead(chunk) {
  1777. this._readyCapability.promise.then(() => {
  1778. for (const listener of this._progressiveReadListeners) {
  1779. listener(chunk);
  1780. }
  1781. });
  1782. }
  1783. onDataProgressiveDone() {
  1784. this._readyCapability.promise.then(() => {
  1785. for (const listener of this._progressiveDoneListeners) {
  1786. listener();
  1787. }
  1788. });
  1789. }
  1790. transportReady() {
  1791. this._readyCapability.resolve();
  1792. }
  1793. requestDataRange(begin, end) {
  1794. (0, _util.unreachable)("Abstract method PDFDataRangeTransport.requestDataRange");
  1795. }
  1796. abort() {}
  1797. }
  1798. exports.PDFDataRangeTransport = PDFDataRangeTransport;
  1799. class PDFDocumentProxy {
  1800. constructor(pdfInfo, transport) {
  1801. this._pdfInfo = pdfInfo;
  1802. this._transport = transport;
  1803. Object.defineProperty(this, "fingerprint", {
  1804. get() {
  1805. (0, _display_utils.deprecated)("`PDFDocumentProxy.fingerprint`, " + "please use `PDFDocumentProxy.fingerprints` instead.");
  1806. return this.fingerprints[0];
  1807. }
  1808. });
  1809. Object.defineProperty(this, "getStats", {
  1810. value: async () => {
  1811. (0, _display_utils.deprecated)("`PDFDocumentProxy.getStats`, " + "please use the `PDFDocumentProxy.stats`-getter instead.");
  1812. return this.stats || {
  1813. streamTypes: {},
  1814. fontTypes: {}
  1815. };
  1816. }
  1817. });
  1818. }
  1819. get annotationStorage() {
  1820. return this._transport.annotationStorage;
  1821. }
  1822. get numPages() {
  1823. return this._pdfInfo.numPages;
  1824. }
  1825. get fingerprints() {
  1826. return this._pdfInfo.fingerprints;
  1827. }
  1828. get stats() {
  1829. return this._transport.stats;
  1830. }
  1831. get isPureXfa() {
  1832. return !!this._transport._htmlForXfa;
  1833. }
  1834. get allXfaHtml() {
  1835. return this._transport._htmlForXfa;
  1836. }
  1837. getPage(pageNumber) {
  1838. return this._transport.getPage(pageNumber);
  1839. }
  1840. getPageIndex(ref) {
  1841. return this._transport.getPageIndex(ref);
  1842. }
  1843. getDestinations() {
  1844. return this._transport.getDestinations();
  1845. }
  1846. getDestination(id) {
  1847. return this._transport.getDestination(id);
  1848. }
  1849. getPageLabels() {
  1850. return this._transport.getPageLabels();
  1851. }
  1852. getPageLayout() {
  1853. return this._transport.getPageLayout();
  1854. }
  1855. getPageMode() {
  1856. return this._transport.getPageMode();
  1857. }
  1858. getViewerPreferences() {
  1859. return this._transport.getViewerPreferences();
  1860. }
  1861. getOpenAction() {
  1862. return this._transport.getOpenAction();
  1863. }
  1864. getAttachments() {
  1865. return this._transport.getAttachments();
  1866. }
  1867. getJavaScript() {
  1868. return this._transport.getJavaScript();
  1869. }
  1870. getJSActions() {
  1871. return this._transport.getDocJSActions();
  1872. }
  1873. getOutline() {
  1874. return this._transport.getOutline();
  1875. }
  1876. getOptionalContentConfig() {
  1877. return this._transport.getOptionalContentConfig();
  1878. }
  1879. getPermissions() {
  1880. return this._transport.getPermissions();
  1881. }
  1882. getMetadata() {
  1883. return this._transport.getMetadata();
  1884. }
  1885. getMarkInfo() {
  1886. return this._transport.getMarkInfo();
  1887. }
  1888. getData() {
  1889. return this._transport.getData();
  1890. }
  1891. getDownloadInfo() {
  1892. return this._transport.downloadInfoCapability.promise;
  1893. }
  1894. cleanup(keepLoadedFonts = false) {
  1895. return this._transport.startCleanup(keepLoadedFonts || this.isPureXfa);
  1896. }
  1897. destroy() {
  1898. return this.loadingTask.destroy();
  1899. }
  1900. get loadingParams() {
  1901. return this._transport.loadingParams;
  1902. }
  1903. get loadingTask() {
  1904. return this._transport.loadingTask;
  1905. }
  1906. saveDocument() {
  1907. if (this._transport.annotationStorage.size <= 0) {
  1908. (0, _display_utils.deprecated)("saveDocument called while `annotationStorage` is empty, " + "please use the getData-method instead.");
  1909. }
  1910. return this._transport.saveDocument();
  1911. }
  1912. getFieldObjects() {
  1913. return this._transport.getFieldObjects();
  1914. }
  1915. hasJSActions() {
  1916. return this._transport.hasJSActions();
  1917. }
  1918. getCalculationOrderIds() {
  1919. return this._transport.getCalculationOrderIds();
  1920. }
  1921. }
  1922. exports.PDFDocumentProxy = PDFDocumentProxy;
  1923. class PDFPageProxy {
  1924. constructor(pageIndex, pageInfo, transport, ownerDocument, pdfBug = false) {
  1925. this._pageIndex = pageIndex;
  1926. this._pageInfo = pageInfo;
  1927. this._ownerDocument = ownerDocument;
  1928. this._transport = transport;
  1929. this._stats = pdfBug ? new _display_utils.StatTimer() : null;
  1930. this._pdfBug = pdfBug;
  1931. this.commonObjs = transport.commonObjs;
  1932. this.objs = new PDFObjects();
  1933. this.cleanupAfterRender = false;
  1934. this.pendingCleanup = false;
  1935. this._intentStates = new Map();
  1936. this._annotationPromises = new Map();
  1937. this.destroyed = false;
  1938. }
  1939. get pageNumber() {
  1940. return this._pageIndex + 1;
  1941. }
  1942. get rotate() {
  1943. return this._pageInfo.rotate;
  1944. }
  1945. get ref() {
  1946. return this._pageInfo.ref;
  1947. }
  1948. get userUnit() {
  1949. return this._pageInfo.userUnit;
  1950. }
  1951. get view() {
  1952. return this._pageInfo.view;
  1953. }
  1954. getViewport({
  1955. scale,
  1956. rotation = this.rotate,
  1957. offsetX = 0,
  1958. offsetY = 0,
  1959. dontFlip = false
  1960. } = {}) {
  1961. return new _display_utils.PageViewport({
  1962. viewBox: this.view,
  1963. scale,
  1964. rotation,
  1965. offsetX,
  1966. offsetY,
  1967. dontFlip
  1968. });
  1969. }
  1970. getAnnotations({
  1971. intent = "display"
  1972. } = {}) {
  1973. const intentArgs = this._transport.getRenderingIntent(intent);
  1974. let promise = this._annotationPromises.get(intentArgs.cacheKey);
  1975. if (!promise) {
  1976. promise = this._transport.getAnnotations(this._pageIndex, intentArgs.renderingIntent);
  1977. this._annotationPromises.set(intentArgs.cacheKey, promise);
  1978. promise = promise.then(annotations => {
  1979. for (const annotation of annotations) {
  1980. if (annotation.titleObj !== undefined) {
  1981. Object.defineProperty(annotation, "title", {
  1982. get() {
  1983. (0, _display_utils.deprecated)("`title`-property on annotation, please use `titleObj` instead.");
  1984. return annotation.titleObj.str;
  1985. }
  1986. });
  1987. }
  1988. if (annotation.contentsObj !== undefined) {
  1989. Object.defineProperty(annotation, "contents", {
  1990. get() {
  1991. (0, _display_utils.deprecated)("`contents`-property on annotation, please use `contentsObj` instead.");
  1992. return annotation.contentsObj.str;
  1993. }
  1994. });
  1995. }
  1996. }
  1997. return annotations;
  1998. });
  1999. }
  2000. return promise;
  2001. }
  2002. getJSActions() {
  2003. return this._jsActionsPromise ||= this._transport.getPageJSActions(this._pageIndex);
  2004. }
  2005. async getXfa() {
  2006. return this._transport._htmlForXfa?.children[this._pageIndex] || null;
  2007. }
  2008. render({
  2009. canvasContext,
  2010. viewport,
  2011. intent = "display",
  2012. annotationMode = _util.AnnotationMode.ENABLE,
  2013. transform = null,
  2014. imageLayer = null,
  2015. canvasFactory = null,
  2016. background = null,
  2017. optionalContentConfigPromise = null,
  2018. annotationCanvasMap = null
  2019. }) {
  2020. if (arguments[0]?.renderInteractiveForms !== undefined) {
  2021. (0, _display_utils.deprecated)("render no longer accepts the `renderInteractiveForms`-option, " + "please use the `annotationMode`-option instead.");
  2022. if (arguments[0].renderInteractiveForms === true && annotationMode === _util.AnnotationMode.ENABLE) {
  2023. annotationMode = _util.AnnotationMode.ENABLE_FORMS;
  2024. }
  2025. }
  2026. if (arguments[0]?.includeAnnotationStorage !== undefined) {
  2027. (0, _display_utils.deprecated)("render no longer accepts the `includeAnnotationStorage`-option, " + "please use the `annotationMode`-option instead.");
  2028. if (arguments[0].includeAnnotationStorage === true && annotationMode === _util.AnnotationMode.ENABLE) {
  2029. annotationMode = _util.AnnotationMode.ENABLE_STORAGE;
  2030. }
  2031. }
  2032. if (this._stats) {
  2033. this._stats.time("Overall");
  2034. }
  2035. const intentArgs = this._transport.getRenderingIntent(intent, annotationMode);
  2036. this.pendingCleanup = false;
  2037. if (!optionalContentConfigPromise) {
  2038. optionalContentConfigPromise = this._transport.getOptionalContentConfig();
  2039. }
  2040. let intentState = this._intentStates.get(intentArgs.cacheKey);
  2041. if (!intentState) {
  2042. intentState = Object.create(null);
  2043. this._intentStates.set(intentArgs.cacheKey, intentState);
  2044. }
  2045. if (intentState.streamReaderCancelTimeout) {
  2046. clearTimeout(intentState.streamReaderCancelTimeout);
  2047. intentState.streamReaderCancelTimeout = null;
  2048. }
  2049. const canvasFactoryInstance = canvasFactory || new DefaultCanvasFactory({
  2050. ownerDocument: this._ownerDocument
  2051. });
  2052. const intentPrint = !!(intentArgs.renderingIntent & _util.RenderingIntentFlag.PRINT);
  2053. if (!intentState.displayReadyCapability) {
  2054. intentState.displayReadyCapability = (0, _util.createPromiseCapability)();
  2055. intentState.operatorList = {
  2056. fnArray: [],
  2057. argsArray: [],
  2058. lastChunk: false
  2059. };
  2060. if (this._stats) {
  2061. this._stats.time("Page Request");
  2062. }
  2063. this._pumpOperatorList(intentArgs);
  2064. }
  2065. const complete = error => {
  2066. intentState.renderTasks.delete(internalRenderTask);
  2067. if (this.cleanupAfterRender || intentPrint) {
  2068. this.pendingCleanup = true;
  2069. }
  2070. this._tryCleanup();
  2071. if (error) {
  2072. internalRenderTask.capability.reject(error);
  2073. this._abortOperatorList({
  2074. intentState,
  2075. reason: error instanceof Error ? error : new Error(error)
  2076. });
  2077. } else {
  2078. internalRenderTask.capability.resolve();
  2079. }
  2080. if (this._stats) {
  2081. this._stats.timeEnd("Rendering");
  2082. this._stats.timeEnd("Overall");
  2083. }
  2084. };
  2085. const internalRenderTask = new InternalRenderTask({
  2086. callback: complete,
  2087. params: {
  2088. canvasContext,
  2089. viewport,
  2090. transform,
  2091. imageLayer,
  2092. background
  2093. },
  2094. objs: this.objs,
  2095. commonObjs: this.commonObjs,
  2096. annotationCanvasMap,
  2097. operatorList: intentState.operatorList,
  2098. pageIndex: this._pageIndex,
  2099. canvasFactory: canvasFactoryInstance,
  2100. useRequestAnimationFrame: !intentPrint,
  2101. pdfBug: this._pdfBug
  2102. });
  2103. (intentState.renderTasks ||= new Set()).add(internalRenderTask);
  2104. const renderTask = internalRenderTask.task;
  2105. Promise.all([intentState.displayReadyCapability.promise, optionalContentConfigPromise]).then(([transparency, optionalContentConfig]) => {
  2106. if (this.pendingCleanup) {
  2107. complete();
  2108. return;
  2109. }
  2110. if (this._stats) {
  2111. this._stats.time("Rendering");
  2112. }
  2113. internalRenderTask.initializeGraphics({
  2114. transparency,
  2115. optionalContentConfig
  2116. });
  2117. internalRenderTask.operatorListChanged();
  2118. }).catch(complete);
  2119. return renderTask;
  2120. }
  2121. getOperatorList({
  2122. intent = "display",
  2123. annotationMode = _util.AnnotationMode.ENABLE
  2124. } = {}) {
  2125. function operatorListChanged() {
  2126. if (intentState.operatorList.lastChunk) {
  2127. intentState.opListReadCapability.resolve(intentState.operatorList);
  2128. intentState.renderTasks.delete(opListTask);
  2129. }
  2130. }
  2131. const intentArgs = this._transport.getRenderingIntent(intent, annotationMode, true);
  2132. let intentState = this._intentStates.get(intentArgs.cacheKey);
  2133. if (!intentState) {
  2134. intentState = Object.create(null);
  2135. this._intentStates.set(intentArgs.cacheKey, intentState);
  2136. }
  2137. let opListTask;
  2138. if (!intentState.opListReadCapability) {
  2139. opListTask = Object.create(null);
  2140. opListTask.operatorListChanged = operatorListChanged;
  2141. intentState.opListReadCapability = (0, _util.createPromiseCapability)();
  2142. (intentState.renderTasks ||= new Set()).add(opListTask);
  2143. intentState.operatorList = {
  2144. fnArray: [],
  2145. argsArray: [],
  2146. lastChunk: false
  2147. };
  2148. if (this._stats) {
  2149. this._stats.time("Page Request");
  2150. }
  2151. this._pumpOperatorList(intentArgs);
  2152. }
  2153. return intentState.opListReadCapability.promise;
  2154. }
  2155. streamTextContent({
  2156. normalizeWhitespace = false,
  2157. disableCombineTextItems = false,
  2158. includeMarkedContent = false
  2159. } = {}) {
  2160. const TEXT_CONTENT_CHUNK_SIZE = 100;
  2161. return this._transport.messageHandler.sendWithStream("GetTextContent", {
  2162. pageIndex: this._pageIndex,
  2163. normalizeWhitespace: normalizeWhitespace === true,
  2164. combineTextItems: disableCombineTextItems !== true,
  2165. includeMarkedContent: includeMarkedContent === true
  2166. }, {
  2167. highWaterMark: TEXT_CONTENT_CHUNK_SIZE,
  2168. size(textContent) {
  2169. return textContent.items.length;
  2170. }
  2171. });
  2172. }
  2173. getTextContent(params = {}) {
  2174. if (this._transport._htmlForXfa) {
  2175. return this.getXfa().then(xfa => {
  2176. return _xfa_text.XfaText.textContent(xfa);
  2177. });
  2178. }
  2179. const readableStream = this.streamTextContent(params);
  2180. return new Promise(function (resolve, reject) {
  2181. function pump() {
  2182. reader.read().then(function ({
  2183. value,
  2184. done
  2185. }) {
  2186. if (done) {
  2187. resolve(textContent);
  2188. return;
  2189. }
  2190. Object.assign(textContent.styles, value.styles);
  2191. textContent.items.push(...value.items);
  2192. pump();
  2193. }, reject);
  2194. }
  2195. const reader = readableStream.getReader();
  2196. const textContent = {
  2197. items: [],
  2198. styles: Object.create(null)
  2199. };
  2200. pump();
  2201. });
  2202. }
  2203. getStructTree() {
  2204. return this._structTreePromise ||= this._transport.getStructTree(this._pageIndex);
  2205. }
  2206. _destroy() {
  2207. this.destroyed = true;
  2208. const waitOn = [];
  2209. for (const intentState of this._intentStates.values()) {
  2210. this._abortOperatorList({
  2211. intentState,
  2212. reason: new Error("Page was destroyed."),
  2213. force: true
  2214. });
  2215. if (intentState.opListReadCapability) {
  2216. continue;
  2217. }
  2218. for (const internalRenderTask of intentState.renderTasks) {
  2219. waitOn.push(internalRenderTask.completed);
  2220. internalRenderTask.cancel();
  2221. }
  2222. }
  2223. this.objs.clear();
  2224. this._annotationPromises.clear();
  2225. this._jsActionsPromise = null;
  2226. this._structTreePromise = null;
  2227. this.pendingCleanup = false;
  2228. return Promise.all(waitOn);
  2229. }
  2230. cleanup(resetStats = false) {
  2231. this.pendingCleanup = true;
  2232. return this._tryCleanup(resetStats);
  2233. }
  2234. _tryCleanup(resetStats = false) {
  2235. if (!this.pendingCleanup) {
  2236. return false;
  2237. }
  2238. for (const {
  2239. renderTasks,
  2240. operatorList
  2241. } of this._intentStates.values()) {
  2242. if (renderTasks.size > 0 || !operatorList.lastChunk) {
  2243. return false;
  2244. }
  2245. }
  2246. this._intentStates.clear();
  2247. this.objs.clear();
  2248. this._annotationPromises.clear();
  2249. this._jsActionsPromise = null;
  2250. this._structTreePromise = null;
  2251. if (resetStats && this._stats) {
  2252. this._stats = new _display_utils.StatTimer();
  2253. }
  2254. this.pendingCleanup = false;
  2255. return true;
  2256. }
  2257. _startRenderPage(transparency, cacheKey) {
  2258. const intentState = this._intentStates.get(cacheKey);
  2259. if (!intentState) {
  2260. return;
  2261. }
  2262. if (this._stats) {
  2263. this._stats.timeEnd("Page Request");
  2264. }
  2265. if (intentState.displayReadyCapability) {
  2266. intentState.displayReadyCapability.resolve(transparency);
  2267. }
  2268. }
  2269. _renderPageChunk(operatorListChunk, intentState) {
  2270. for (let i = 0, ii = operatorListChunk.length; i < ii; i++) {
  2271. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  2272. intentState.operatorList.argsArray.push(operatorListChunk.argsArray[i]);
  2273. }
  2274. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  2275. for (const internalRenderTask of intentState.renderTasks) {
  2276. internalRenderTask.operatorListChanged();
  2277. }
  2278. if (operatorListChunk.lastChunk) {
  2279. this._tryCleanup();
  2280. }
  2281. }
  2282. _pumpOperatorList({
  2283. renderingIntent,
  2284. cacheKey
  2285. }) {
  2286. const readableStream = this._transport.messageHandler.sendWithStream("GetOperatorList", {
  2287. pageIndex: this._pageIndex,
  2288. intent: renderingIntent,
  2289. cacheKey,
  2290. annotationStorage: renderingIntent & _util.RenderingIntentFlag.ANNOTATIONS_STORAGE ? this._transport.annotationStorage.serializable : null
  2291. });
  2292. const reader = readableStream.getReader();
  2293. const intentState = this._intentStates.get(cacheKey);
  2294. intentState.streamReader = reader;
  2295. const pump = () => {
  2296. reader.read().then(({
  2297. value,
  2298. done
  2299. }) => {
  2300. if (done) {
  2301. intentState.streamReader = null;
  2302. return;
  2303. }
  2304. if (this._transport.destroyed) {
  2305. return;
  2306. }
  2307. this._renderPageChunk(value, intentState);
  2308. pump();
  2309. }, reason => {
  2310. intentState.streamReader = null;
  2311. if (this._transport.destroyed) {
  2312. return;
  2313. }
  2314. if (intentState.operatorList) {
  2315. intentState.operatorList.lastChunk = true;
  2316. for (const internalRenderTask of intentState.renderTasks) {
  2317. internalRenderTask.operatorListChanged();
  2318. }
  2319. this._tryCleanup();
  2320. }
  2321. if (intentState.displayReadyCapability) {
  2322. intentState.displayReadyCapability.reject(reason);
  2323. } else if (intentState.opListReadCapability) {
  2324. intentState.opListReadCapability.reject(reason);
  2325. } else {
  2326. throw reason;
  2327. }
  2328. });
  2329. };
  2330. pump();
  2331. }
  2332. _abortOperatorList({
  2333. intentState,
  2334. reason,
  2335. force = false
  2336. }) {
  2337. if (!intentState.streamReader) {
  2338. return;
  2339. }
  2340. if (!force) {
  2341. if (intentState.renderTasks.size > 0) {
  2342. return;
  2343. }
  2344. if (reason instanceof _display_utils.RenderingCancelledException) {
  2345. intentState.streamReaderCancelTimeout = setTimeout(() => {
  2346. this._abortOperatorList({
  2347. intentState,
  2348. reason,
  2349. force: true
  2350. });
  2351. intentState.streamReaderCancelTimeout = null;
  2352. }, RENDERING_CANCELLED_TIMEOUT);
  2353. return;
  2354. }
  2355. }
  2356. intentState.streamReader.cancel(new _util.AbortException(reason.message)).catch(() => {});
  2357. intentState.streamReader = null;
  2358. if (this._transport.destroyed) {
  2359. return;
  2360. }
  2361. for (const [curCacheKey, curIntentState] of this._intentStates) {
  2362. if (curIntentState === intentState) {
  2363. this._intentStates.delete(curCacheKey);
  2364. break;
  2365. }
  2366. }
  2367. this.cleanup();
  2368. }
  2369. get stats() {
  2370. return this._stats;
  2371. }
  2372. }
  2373. exports.PDFPageProxy = PDFPageProxy;
  2374. class LoopbackPort {
  2375. constructor() {
  2376. this._listeners = [];
  2377. this._deferred = Promise.resolve();
  2378. }
  2379. postMessage(obj, transfers) {
  2380. function cloneValue(object) {
  2381. if (globalThis.structuredClone) {
  2382. return globalThis.structuredClone(object, transfers);
  2383. }
  2384. function fallbackCloneValue(value) {
  2385. if (typeof value === "function" || typeof value === "symbol" || value instanceof URL) {
  2386. throw new Error(`LoopbackPort.postMessage - cannot clone: ${value?.toString()}`);
  2387. }
  2388. if (typeof value !== "object" || value === null) {
  2389. return value;
  2390. }
  2391. if (cloned.has(value)) {
  2392. return cloned.get(value);
  2393. }
  2394. let buffer, result;
  2395. if ((buffer = value.buffer) && (0, _util.isArrayBuffer)(buffer)) {
  2396. if (transfers?.includes(buffer)) {
  2397. result = new value.constructor(buffer, value.byteOffset, value.byteLength);
  2398. } else {
  2399. result = new value.constructor(value);
  2400. }
  2401. cloned.set(value, result);
  2402. return result;
  2403. }
  2404. if (value instanceof Map) {
  2405. result = new Map();
  2406. cloned.set(value, result);
  2407. for (const [key, val] of value) {
  2408. result.set(key, fallbackCloneValue(val));
  2409. }
  2410. return result;
  2411. }
  2412. if (value instanceof Set) {
  2413. result = new Set();
  2414. cloned.set(value, result);
  2415. for (const val of value) {
  2416. result.add(fallbackCloneValue(val));
  2417. }
  2418. return result;
  2419. }
  2420. result = Array.isArray(value) ? [] : Object.create(null);
  2421. cloned.set(value, result);
  2422. for (const i in value) {
  2423. let desc,
  2424. p = value;
  2425. while (!(desc = Object.getOwnPropertyDescriptor(p, i))) {
  2426. p = Object.getPrototypeOf(p);
  2427. }
  2428. if (typeof desc.value === "undefined") {
  2429. continue;
  2430. }
  2431. if (typeof desc.value === "function" && !value.hasOwnProperty?.(i)) {
  2432. continue;
  2433. }
  2434. result[i] = fallbackCloneValue(desc.value);
  2435. }
  2436. return result;
  2437. }
  2438. const cloned = new WeakMap();
  2439. return fallbackCloneValue(object);
  2440. }
  2441. const event = {
  2442. data: cloneValue(obj)
  2443. };
  2444. this._deferred.then(() => {
  2445. for (const listener of this._listeners) {
  2446. listener.call(this, event);
  2447. }
  2448. });
  2449. }
  2450. addEventListener(name, listener) {
  2451. this._listeners.push(listener);
  2452. }
  2453. removeEventListener(name, listener) {
  2454. const i = this._listeners.indexOf(listener);
  2455. this._listeners.splice(i, 1);
  2456. }
  2457. terminate() {
  2458. this._listeners.length = 0;
  2459. }
  2460. }
  2461. exports.LoopbackPort = LoopbackPort;
  2462. const PDFWorkerUtil = {
  2463. isWorkerDisabled: false,
  2464. fallbackWorkerSrc: null,
  2465. fakeWorkerId: 0
  2466. };
  2467. {
  2468. if (_is_node.isNodeJS && typeof require === "function") {
  2469. PDFWorkerUtil.isWorkerDisabled = true;
  2470. PDFWorkerUtil.fallbackWorkerSrc = "./pdf.worker.js";
  2471. } else if (typeof document === "object") {
  2472. const pdfjsFilePath = document?.currentScript?.src;
  2473. if (pdfjsFilePath) {
  2474. PDFWorkerUtil.fallbackWorkerSrc = pdfjsFilePath.replace(/(\.(?:min\.)?js)(\?.*)?$/i, ".worker$1$2");
  2475. }
  2476. }
  2477. PDFWorkerUtil.createCDNWrapper = function (url) {
  2478. const wrapper = `importScripts("${url}");`;
  2479. return URL.createObjectURL(new Blob([wrapper]));
  2480. };
  2481. }
  2482. class PDFWorker {
  2483. static get _workerPorts() {
  2484. return (0, _util.shadow)(this, "_workerPorts", new WeakMap());
  2485. }
  2486. constructor({
  2487. name = null,
  2488. port = null,
  2489. verbosity = (0, _util.getVerbosityLevel)()
  2490. } = {}) {
  2491. if (port && PDFWorker._workerPorts.has(port)) {
  2492. throw new Error("Cannot use more than one PDFWorker per port.");
  2493. }
  2494. this.name = name;
  2495. this.destroyed = false;
  2496. this.verbosity = verbosity;
  2497. this._readyCapability = (0, _util.createPromiseCapability)();
  2498. this._port = null;
  2499. this._webWorker = null;
  2500. this._messageHandler = null;
  2501. if (port) {
  2502. PDFWorker._workerPorts.set(port, this);
  2503. this._initializeFromPort(port);
  2504. return;
  2505. }
  2506. this._initialize();
  2507. }
  2508. get promise() {
  2509. return this._readyCapability.promise;
  2510. }
  2511. get port() {
  2512. return this._port;
  2513. }
  2514. get messageHandler() {
  2515. return this._messageHandler;
  2516. }
  2517. _initializeFromPort(port) {
  2518. this._port = port;
  2519. this._messageHandler = new _message_handler.MessageHandler("main", "worker", port);
  2520. this._messageHandler.on("ready", function () {});
  2521. this._readyCapability.resolve();
  2522. }
  2523. _initialize() {
  2524. if (typeof Worker !== "undefined" && !PDFWorkerUtil.isWorkerDisabled && !PDFWorker._mainThreadWorkerMessageHandler) {
  2525. let workerSrc = PDFWorker.workerSrc;
  2526. try {
  2527. if (!(0, _util.isSameOrigin)(window.location.href, workerSrc)) {
  2528. workerSrc = PDFWorkerUtil.createCDNWrapper(new URL(workerSrc, window.location).href);
  2529. }
  2530. const worker = new Worker(workerSrc);
  2531. const messageHandler = new _message_handler.MessageHandler("main", "worker", worker);
  2532. const terminateEarly = () => {
  2533. worker.removeEventListener("error", onWorkerError);
  2534. messageHandler.destroy();
  2535. worker.terminate();
  2536. if (this.destroyed) {
  2537. this._readyCapability.reject(new Error("Worker was destroyed"));
  2538. } else {
  2539. this._setupFakeWorker();
  2540. }
  2541. };
  2542. const onWorkerError = () => {
  2543. if (!this._webWorker) {
  2544. terminateEarly();
  2545. }
  2546. };
  2547. worker.addEventListener("error", onWorkerError);
  2548. messageHandler.on("test", data => {
  2549. worker.removeEventListener("error", onWorkerError);
  2550. if (this.destroyed) {
  2551. terminateEarly();
  2552. return;
  2553. }
  2554. if (data) {
  2555. this._messageHandler = messageHandler;
  2556. this._port = worker;
  2557. this._webWorker = worker;
  2558. this._readyCapability.resolve();
  2559. messageHandler.send("configure", {
  2560. verbosity: this.verbosity
  2561. });
  2562. } else {
  2563. this._setupFakeWorker();
  2564. messageHandler.destroy();
  2565. worker.terminate();
  2566. }
  2567. });
  2568. messageHandler.on("ready", data => {
  2569. worker.removeEventListener("error", onWorkerError);
  2570. if (this.destroyed) {
  2571. terminateEarly();
  2572. return;
  2573. }
  2574. try {
  2575. sendTest();
  2576. } catch (e) {
  2577. this._setupFakeWorker();
  2578. }
  2579. });
  2580. const sendTest = () => {
  2581. const testObj = new Uint8Array([255]);
  2582. try {
  2583. messageHandler.send("test", testObj, [testObj.buffer]);
  2584. } catch (ex) {
  2585. (0, _util.warn)("Cannot use postMessage transfers.");
  2586. testObj[0] = 0;
  2587. messageHandler.send("test", testObj);
  2588. }
  2589. };
  2590. sendTest();
  2591. return;
  2592. } catch (e) {
  2593. (0, _util.info)("The worker has been disabled.");
  2594. }
  2595. }
  2596. this._setupFakeWorker();
  2597. }
  2598. _setupFakeWorker() {
  2599. if (!PDFWorkerUtil.isWorkerDisabled) {
  2600. (0, _util.warn)("Setting up fake worker.");
  2601. PDFWorkerUtil.isWorkerDisabled = true;
  2602. }
  2603. PDFWorker._setupFakeWorkerGlobal.then(WorkerMessageHandler => {
  2604. if (this.destroyed) {
  2605. this._readyCapability.reject(new Error("Worker was destroyed"));
  2606. return;
  2607. }
  2608. const port = new LoopbackPort();
  2609. this._port = port;
  2610. const id = `fake${PDFWorkerUtil.fakeWorkerId++}`;
  2611. const workerHandler = new _message_handler.MessageHandler(id + "_worker", id, port);
  2612. WorkerMessageHandler.setup(workerHandler, port);
  2613. const messageHandler = new _message_handler.MessageHandler(id, id + "_worker", port);
  2614. this._messageHandler = messageHandler;
  2615. this._readyCapability.resolve();
  2616. messageHandler.send("configure", {
  2617. verbosity: this.verbosity
  2618. });
  2619. }).catch(reason => {
  2620. this._readyCapability.reject(new Error(`Setting up fake worker failed: "${reason.message}".`));
  2621. });
  2622. }
  2623. destroy() {
  2624. this.destroyed = true;
  2625. if (this._webWorker) {
  2626. this._webWorker.terminate();
  2627. this._webWorker = null;
  2628. }
  2629. PDFWorker._workerPorts.delete(this._port);
  2630. this._port = null;
  2631. if (this._messageHandler) {
  2632. this._messageHandler.destroy();
  2633. this._messageHandler = null;
  2634. }
  2635. }
  2636. static fromPort(params) {
  2637. if (!params?.port) {
  2638. throw new Error("PDFWorker.fromPort - invalid method signature.");
  2639. }
  2640. if (this._workerPorts.has(params.port)) {
  2641. return this._workerPorts.get(params.port);
  2642. }
  2643. return new PDFWorker(params);
  2644. }
  2645. static get workerSrc() {
  2646. if (_worker_options.GlobalWorkerOptions.workerSrc) {
  2647. return _worker_options.GlobalWorkerOptions.workerSrc;
  2648. }
  2649. if (PDFWorkerUtil.fallbackWorkerSrc !== null) {
  2650. if (!_is_node.isNodeJS) {
  2651. (0, _display_utils.deprecated)('No "GlobalWorkerOptions.workerSrc" specified.');
  2652. }
  2653. return PDFWorkerUtil.fallbackWorkerSrc;
  2654. }
  2655. throw new Error('No "GlobalWorkerOptions.workerSrc" specified.');
  2656. }
  2657. static get _mainThreadWorkerMessageHandler() {
  2658. try {
  2659. return globalThis.pdfjsWorker?.WorkerMessageHandler || null;
  2660. } catch (ex) {
  2661. return null;
  2662. }
  2663. }
  2664. static get _setupFakeWorkerGlobal() {
  2665. const loader = async () => {
  2666. const mainWorkerMessageHandler = this._mainThreadWorkerMessageHandler;
  2667. if (mainWorkerMessageHandler) {
  2668. return mainWorkerMessageHandler;
  2669. }
  2670. if (_is_node.isNodeJS && typeof require === "function") {
  2671. const worker = eval("require")(this.workerSrc);
  2672. return worker.WorkerMessageHandler;
  2673. }
  2674. await (0, _display_utils.loadScript)(this.workerSrc);
  2675. return window.pdfjsWorker.WorkerMessageHandler;
  2676. };
  2677. return (0, _util.shadow)(this, "_setupFakeWorkerGlobal", loader());
  2678. }
  2679. }
  2680. exports.PDFWorker = PDFWorker;
  2681. {
  2682. PDFWorker.getWorkerSrc = function () {
  2683. (0, _display_utils.deprecated)("`PDFWorker.getWorkerSrc()`, please use `PDFWorker.workerSrc` instead.");
  2684. return this.workerSrc;
  2685. };
  2686. }
  2687. class WorkerTransport {
  2688. #docStats = null;
  2689. #pageCache = new Map();
  2690. #pagePromises = new Map();
  2691. #metadataPromise = null;
  2692. constructor(messageHandler, loadingTask, networkStream, params) {
  2693. this.messageHandler = messageHandler;
  2694. this.loadingTask = loadingTask;
  2695. this.commonObjs = new PDFObjects();
  2696. this.fontLoader = new _font_loader.FontLoader({
  2697. docId: loadingTask.docId,
  2698. onUnsupportedFeature: this._onUnsupportedFeature.bind(this),
  2699. ownerDocument: params.ownerDocument,
  2700. styleElement: params.styleElement
  2701. });
  2702. this._params = params;
  2703. if (!params.useWorkerFetch) {
  2704. this.CMapReaderFactory = new params.CMapReaderFactory({
  2705. baseUrl: params.cMapUrl,
  2706. isCompressed: params.cMapPacked
  2707. });
  2708. this.StandardFontDataFactory = new params.StandardFontDataFactory({
  2709. baseUrl: params.standardFontDataUrl
  2710. });
  2711. }
  2712. this.destroyed = false;
  2713. this.destroyCapability = null;
  2714. this._passwordCapability = null;
  2715. this._networkStream = networkStream;
  2716. this._fullReader = null;
  2717. this._lastProgress = null;
  2718. this.downloadInfoCapability = (0, _util.createPromiseCapability)();
  2719. this.setupMessageHandler();
  2720. }
  2721. get annotationStorage() {
  2722. return (0, _util.shadow)(this, "annotationStorage", new _annotation_storage.AnnotationStorage());
  2723. }
  2724. get stats() {
  2725. return this.#docStats;
  2726. }
  2727. getRenderingIntent(intent, annotationMode = _util.AnnotationMode.ENABLE, isOpList = false) {
  2728. let renderingIntent = _util.RenderingIntentFlag.DISPLAY;
  2729. let lastModified = "";
  2730. switch (intent) {
  2731. case "any":
  2732. renderingIntent = _util.RenderingIntentFlag.ANY;
  2733. break;
  2734. case "display":
  2735. break;
  2736. case "print":
  2737. renderingIntent = _util.RenderingIntentFlag.PRINT;
  2738. break;
  2739. default:
  2740. (0, _util.warn)(`getRenderingIntent - invalid intent: ${intent}`);
  2741. }
  2742. switch (annotationMode) {
  2743. case _util.AnnotationMode.DISABLE:
  2744. renderingIntent += _util.RenderingIntentFlag.ANNOTATIONS_DISABLE;
  2745. break;
  2746. case _util.AnnotationMode.ENABLE:
  2747. break;
  2748. case _util.AnnotationMode.ENABLE_FORMS:
  2749. renderingIntent += _util.RenderingIntentFlag.ANNOTATIONS_FORMS;
  2750. break;
  2751. case _util.AnnotationMode.ENABLE_STORAGE:
  2752. renderingIntent += _util.RenderingIntentFlag.ANNOTATIONS_STORAGE;
  2753. lastModified = this.annotationStorage.lastModified;
  2754. break;
  2755. default:
  2756. (0, _util.warn)(`getRenderingIntent - invalid annotationMode: ${annotationMode}`);
  2757. }
  2758. if (isOpList) {
  2759. renderingIntent += _util.RenderingIntentFlag.OPLIST;
  2760. }
  2761. return {
  2762. renderingIntent,
  2763. cacheKey: `${renderingIntent}_${lastModified}`
  2764. };
  2765. }
  2766. destroy() {
  2767. if (this.destroyCapability) {
  2768. return this.destroyCapability.promise;
  2769. }
  2770. this.destroyed = true;
  2771. this.destroyCapability = (0, _util.createPromiseCapability)();
  2772. if (this._passwordCapability) {
  2773. this._passwordCapability.reject(new Error("Worker was destroyed during onPassword callback"));
  2774. }
  2775. const waitOn = [];
  2776. for (const page of this.#pageCache.values()) {
  2777. waitOn.push(page._destroy());
  2778. }
  2779. this.#pageCache.clear();
  2780. this.#pagePromises.clear();
  2781. if (this.hasOwnProperty("annotationStorage")) {
  2782. this.annotationStorage.resetModified();
  2783. }
  2784. const terminated = this.messageHandler.sendWithPromise("Terminate", null);
  2785. waitOn.push(terminated);
  2786. Promise.all(waitOn).then(() => {
  2787. this.commonObjs.clear();
  2788. this.fontLoader.clear();
  2789. this.#metadataPromise = null;
  2790. this._getFieldObjectsPromise = null;
  2791. this._hasJSActionsPromise = null;
  2792. if (this._networkStream) {
  2793. this._networkStream.cancelAllRequests(new _util.AbortException("Worker was terminated."));
  2794. }
  2795. if (this.messageHandler) {
  2796. this.messageHandler.destroy();
  2797. this.messageHandler = null;
  2798. }
  2799. this.destroyCapability.resolve();
  2800. }, this.destroyCapability.reject);
  2801. return this.destroyCapability.promise;
  2802. }
  2803. setupMessageHandler() {
  2804. const {
  2805. messageHandler,
  2806. loadingTask
  2807. } = this;
  2808. messageHandler.on("GetReader", (data, sink) => {
  2809. (0, _util.assert)(this._networkStream, "GetReader - no `IPDFStream` instance available.");
  2810. this._fullReader = this._networkStream.getFullReader();
  2811. this._fullReader.onProgress = evt => {
  2812. this._lastProgress = {
  2813. loaded: evt.loaded,
  2814. total: evt.total
  2815. };
  2816. };
  2817. sink.onPull = () => {
  2818. this._fullReader.read().then(function ({
  2819. value,
  2820. done
  2821. }) {
  2822. if (done) {
  2823. sink.close();
  2824. return;
  2825. }
  2826. (0, _util.assert)((0, _util.isArrayBuffer)(value), "GetReader - expected an ArrayBuffer.");
  2827. sink.enqueue(new Uint8Array(value), 1, [value]);
  2828. }).catch(reason => {
  2829. sink.error(reason);
  2830. });
  2831. };
  2832. sink.onCancel = reason => {
  2833. this._fullReader.cancel(reason);
  2834. sink.ready.catch(readyReason => {
  2835. if (this.destroyed) {
  2836. return;
  2837. }
  2838. throw readyReason;
  2839. });
  2840. };
  2841. });
  2842. messageHandler.on("ReaderHeadersReady", data => {
  2843. const headersCapability = (0, _util.createPromiseCapability)();
  2844. const fullReader = this._fullReader;
  2845. fullReader.headersReady.then(() => {
  2846. if (!fullReader.isStreamingSupported || !fullReader.isRangeSupported) {
  2847. if (this._lastProgress) {
  2848. loadingTask.onProgress?.(this._lastProgress);
  2849. }
  2850. fullReader.onProgress = evt => {
  2851. loadingTask.onProgress?.({
  2852. loaded: evt.loaded,
  2853. total: evt.total
  2854. });
  2855. };
  2856. }
  2857. headersCapability.resolve({
  2858. isStreamingSupported: fullReader.isStreamingSupported,
  2859. isRangeSupported: fullReader.isRangeSupported,
  2860. contentLength: fullReader.contentLength
  2861. });
  2862. }, headersCapability.reject);
  2863. return headersCapability.promise;
  2864. });
  2865. messageHandler.on("GetRangeReader", (data, sink) => {
  2866. (0, _util.assert)(this._networkStream, "GetRangeReader - no `IPDFStream` instance available.");
  2867. const rangeReader = this._networkStream.getRangeReader(data.begin, data.end);
  2868. if (!rangeReader) {
  2869. sink.close();
  2870. return;
  2871. }
  2872. sink.onPull = () => {
  2873. rangeReader.read().then(function ({
  2874. value,
  2875. done
  2876. }) {
  2877. if (done) {
  2878. sink.close();
  2879. return;
  2880. }
  2881. (0, _util.assert)((0, _util.isArrayBuffer)(value), "GetRangeReader - expected an ArrayBuffer.");
  2882. sink.enqueue(new Uint8Array(value), 1, [value]);
  2883. }).catch(reason => {
  2884. sink.error(reason);
  2885. });
  2886. };
  2887. sink.onCancel = reason => {
  2888. rangeReader.cancel(reason);
  2889. sink.ready.catch(readyReason => {
  2890. if (this.destroyed) {
  2891. return;
  2892. }
  2893. throw readyReason;
  2894. });
  2895. };
  2896. });
  2897. messageHandler.on("GetDoc", ({
  2898. pdfInfo
  2899. }) => {
  2900. this._numPages = pdfInfo.numPages;
  2901. this._htmlForXfa = pdfInfo.htmlForXfa;
  2902. delete pdfInfo.htmlForXfa;
  2903. loadingTask._capability.resolve(new PDFDocumentProxy(pdfInfo, this));
  2904. });
  2905. messageHandler.on("DocException", function (ex) {
  2906. let reason;
  2907. switch (ex.name) {
  2908. case "PasswordException":
  2909. reason = new _util.PasswordException(ex.message, ex.code);
  2910. break;
  2911. case "InvalidPDFException":
  2912. reason = new _util.InvalidPDFException(ex.message);
  2913. break;
  2914. case "MissingPDFException":
  2915. reason = new _util.MissingPDFException(ex.message);
  2916. break;
  2917. case "UnexpectedResponseException":
  2918. reason = new _util.UnexpectedResponseException(ex.message, ex.status);
  2919. break;
  2920. case "UnknownErrorException":
  2921. reason = new _util.UnknownErrorException(ex.message, ex.details);
  2922. break;
  2923. default:
  2924. (0, _util.unreachable)("DocException - expected a valid Error.");
  2925. }
  2926. loadingTask._capability.reject(reason);
  2927. });
  2928. messageHandler.on("PasswordRequest", exception => {
  2929. this._passwordCapability = (0, _util.createPromiseCapability)();
  2930. if (loadingTask.onPassword) {
  2931. const updatePassword = password => {
  2932. this._passwordCapability.resolve({
  2933. password
  2934. });
  2935. };
  2936. try {
  2937. loadingTask.onPassword(updatePassword, exception.code);
  2938. } catch (ex) {
  2939. this._passwordCapability.reject(ex);
  2940. }
  2941. } else {
  2942. this._passwordCapability.reject(new _util.PasswordException(exception.message, exception.code));
  2943. }
  2944. return this._passwordCapability.promise;
  2945. });
  2946. messageHandler.on("DataLoaded", data => {
  2947. loadingTask.onProgress?.({
  2948. loaded: data.length,
  2949. total: data.length
  2950. });
  2951. this.downloadInfoCapability.resolve(data);
  2952. });
  2953. messageHandler.on("StartRenderPage", data => {
  2954. if (this.destroyed) {
  2955. return;
  2956. }
  2957. const page = this.#pageCache.get(data.pageIndex);
  2958. page._startRenderPage(data.transparency, data.cacheKey);
  2959. });
  2960. messageHandler.on("commonobj", ([id, type, exportedData]) => {
  2961. if (this.destroyed) {
  2962. return;
  2963. }
  2964. if (this.commonObjs.has(id)) {
  2965. return;
  2966. }
  2967. switch (type) {
  2968. case "Font":
  2969. const params = this._params;
  2970. if ("error" in exportedData) {
  2971. const exportedError = exportedData.error;
  2972. (0, _util.warn)(`Error during font loading: ${exportedError}`);
  2973. this.commonObjs.resolve(id, exportedError);
  2974. break;
  2975. }
  2976. let fontRegistry = null;
  2977. if (params.pdfBug && globalThis.FontInspector?.enabled) {
  2978. fontRegistry = {
  2979. registerFont(font, url) {
  2980. globalThis.FontInspector.fontAdded(font, url);
  2981. }
  2982. };
  2983. }
  2984. const font = new _font_loader.FontFaceObject(exportedData, {
  2985. isEvalSupported: params.isEvalSupported,
  2986. disableFontFace: params.disableFontFace,
  2987. ignoreErrors: params.ignoreErrors,
  2988. onUnsupportedFeature: this._onUnsupportedFeature.bind(this),
  2989. fontRegistry
  2990. });
  2991. this.fontLoader.bind(font).catch(reason => {
  2992. return messageHandler.sendWithPromise("FontFallback", {
  2993. id
  2994. });
  2995. }).finally(() => {
  2996. if (!params.fontExtraProperties && font.data) {
  2997. font.data = null;
  2998. }
  2999. this.commonObjs.resolve(id, font);
  3000. });
  3001. break;
  3002. case "FontPath":
  3003. case "Image":
  3004. this.commonObjs.resolve(id, exportedData);
  3005. break;
  3006. default:
  3007. throw new Error(`Got unknown common object type ${type}`);
  3008. }
  3009. });
  3010. messageHandler.on("obj", ([id, pageIndex, type, imageData]) => {
  3011. if (this.destroyed) {
  3012. return;
  3013. }
  3014. const pageProxy = this.#pageCache.get(pageIndex);
  3015. if (pageProxy.objs.has(id)) {
  3016. return;
  3017. }
  3018. switch (type) {
  3019. case "Image":
  3020. pageProxy.objs.resolve(id, imageData);
  3021. const MAX_IMAGE_SIZE_TO_STORE = 8000000;
  3022. if (imageData?.data?.length > MAX_IMAGE_SIZE_TO_STORE) {
  3023. pageProxy.cleanupAfterRender = true;
  3024. }
  3025. break;
  3026. case "Pattern":
  3027. pageProxy.objs.resolve(id, imageData);
  3028. break;
  3029. default:
  3030. throw new Error(`Got unknown object type ${type}`);
  3031. }
  3032. });
  3033. messageHandler.on("DocProgress", data => {
  3034. if (this.destroyed) {
  3035. return;
  3036. }
  3037. loadingTask.onProgress?.({
  3038. loaded: data.loaded,
  3039. total: data.total
  3040. });
  3041. });
  3042. messageHandler.on("DocStats", data => {
  3043. if (this.destroyed) {
  3044. return;
  3045. }
  3046. this.#docStats = Object.freeze({
  3047. streamTypes: Object.freeze(data.streamTypes),
  3048. fontTypes: Object.freeze(data.fontTypes)
  3049. });
  3050. });
  3051. messageHandler.on("UnsupportedFeature", this._onUnsupportedFeature.bind(this));
  3052. messageHandler.on("FetchBuiltInCMap", data => {
  3053. if (this.destroyed) {
  3054. return Promise.reject(new Error("Worker was destroyed."));
  3055. }
  3056. if (!this.CMapReaderFactory) {
  3057. return Promise.reject(new Error("CMapReaderFactory not initialized, see the `useWorkerFetch` parameter."));
  3058. }
  3059. return this.CMapReaderFactory.fetch(data);
  3060. });
  3061. messageHandler.on("FetchStandardFontData", data => {
  3062. if (this.destroyed) {
  3063. return Promise.reject(new Error("Worker was destroyed."));
  3064. }
  3065. if (!this.StandardFontDataFactory) {
  3066. return Promise.reject(new Error("StandardFontDataFactory not initialized, see the `useWorkerFetch` parameter."));
  3067. }
  3068. return this.StandardFontDataFactory.fetch(data);
  3069. });
  3070. }
  3071. _onUnsupportedFeature({
  3072. featureId
  3073. }) {
  3074. if (this.destroyed) {
  3075. return;
  3076. }
  3077. this.loadingTask.onUnsupportedFeature?.(featureId);
  3078. }
  3079. getData() {
  3080. return this.messageHandler.sendWithPromise("GetData", null);
  3081. }
  3082. getPage(pageNumber) {
  3083. if (!Number.isInteger(pageNumber) || pageNumber <= 0 || pageNumber > this._numPages) {
  3084. return Promise.reject(new Error("Invalid page request"));
  3085. }
  3086. const pageIndex = pageNumber - 1,
  3087. cachedPromise = this.#pagePromises.get(pageIndex);
  3088. if (cachedPromise) {
  3089. return cachedPromise;
  3090. }
  3091. const promise = this.messageHandler.sendWithPromise("GetPage", {
  3092. pageIndex
  3093. }).then(pageInfo => {
  3094. if (this.destroyed) {
  3095. throw new Error("Transport destroyed");
  3096. }
  3097. const page = new PDFPageProxy(pageIndex, pageInfo, this, this._params.ownerDocument, this._params.pdfBug);
  3098. this.#pageCache.set(pageIndex, page);
  3099. return page;
  3100. });
  3101. this.#pagePromises.set(pageIndex, promise);
  3102. return promise;
  3103. }
  3104. getPageIndex(ref) {
  3105. return this.messageHandler.sendWithPromise("GetPageIndex", {
  3106. ref
  3107. });
  3108. }
  3109. getAnnotations(pageIndex, intent) {
  3110. return this.messageHandler.sendWithPromise("GetAnnotations", {
  3111. pageIndex,
  3112. intent
  3113. });
  3114. }
  3115. saveDocument() {
  3116. return this.messageHandler.sendWithPromise("SaveDocument", {
  3117. isPureXfa: !!this._htmlForXfa,
  3118. numPages: this._numPages,
  3119. annotationStorage: this.annotationStorage.serializable,
  3120. filename: this._fullReader?.filename ?? null
  3121. }).finally(() => {
  3122. this.annotationStorage.resetModified();
  3123. });
  3124. }
  3125. getFieldObjects() {
  3126. return this._getFieldObjectsPromise ||= this.messageHandler.sendWithPromise("GetFieldObjects", null);
  3127. }
  3128. hasJSActions() {
  3129. return this._hasJSActionsPromise ||= this.messageHandler.sendWithPromise("HasJSActions", null);
  3130. }
  3131. getCalculationOrderIds() {
  3132. return this.messageHandler.sendWithPromise("GetCalculationOrderIds", null);
  3133. }
  3134. getDestinations() {
  3135. return this.messageHandler.sendWithPromise("GetDestinations", null);
  3136. }
  3137. getDestination(id) {
  3138. if (typeof id !== "string") {
  3139. return Promise.reject(new Error("Invalid destination request."));
  3140. }
  3141. return this.messageHandler.sendWithPromise("GetDestination", {
  3142. id
  3143. });
  3144. }
  3145. getPageLabels() {
  3146. return this.messageHandler.sendWithPromise("GetPageLabels", null);
  3147. }
  3148. getPageLayout() {
  3149. return this.messageHandler.sendWithPromise("GetPageLayout", null);
  3150. }
  3151. getPageMode() {
  3152. return this.messageHandler.sendWithPromise("GetPageMode", null);
  3153. }
  3154. getViewerPreferences() {
  3155. return this.messageHandler.sendWithPromise("GetViewerPreferences", null);
  3156. }
  3157. getOpenAction() {
  3158. return this.messageHandler.sendWithPromise("GetOpenAction", null);
  3159. }
  3160. getAttachments() {
  3161. return this.messageHandler.sendWithPromise("GetAttachments", null);
  3162. }
  3163. getJavaScript() {
  3164. return this.messageHandler.sendWithPromise("GetJavaScript", null);
  3165. }
  3166. getDocJSActions() {
  3167. return this.messageHandler.sendWithPromise("GetDocJSActions", null);
  3168. }
  3169. getPageJSActions(pageIndex) {
  3170. return this.messageHandler.sendWithPromise("GetPageJSActions", {
  3171. pageIndex
  3172. });
  3173. }
  3174. getStructTree(pageIndex) {
  3175. return this.messageHandler.sendWithPromise("GetStructTree", {
  3176. pageIndex
  3177. });
  3178. }
  3179. getOutline() {
  3180. return this.messageHandler.sendWithPromise("GetOutline", null);
  3181. }
  3182. getOptionalContentConfig() {
  3183. return this.messageHandler.sendWithPromise("GetOptionalContentConfig", null).then(results => {
  3184. return new _optional_content_config.OptionalContentConfig(results);
  3185. });
  3186. }
  3187. getPermissions() {
  3188. return this.messageHandler.sendWithPromise("GetPermissions", null);
  3189. }
  3190. getMetadata() {
  3191. return this.#metadataPromise ||= this.messageHandler.sendWithPromise("GetMetadata", null).then(results => {
  3192. return {
  3193. info: results[0],
  3194. metadata: results[1] ? new _metadata.Metadata(results[1]) : null,
  3195. contentDispositionFilename: this._fullReader?.filename ?? null,
  3196. contentLength: this._fullReader?.contentLength ?? null
  3197. };
  3198. });
  3199. }
  3200. getMarkInfo() {
  3201. return this.messageHandler.sendWithPromise("GetMarkInfo", null);
  3202. }
  3203. async startCleanup(keepLoadedFonts = false) {
  3204. await this.messageHandler.sendWithPromise("Cleanup", null);
  3205. if (this.destroyed) {
  3206. return;
  3207. }
  3208. for (const page of this.#pageCache.values()) {
  3209. const cleanupSuccessful = page.cleanup();
  3210. if (!cleanupSuccessful) {
  3211. throw new Error(`startCleanup: Page ${page.pageNumber} is currently rendering.`);
  3212. }
  3213. }
  3214. this.commonObjs.clear();
  3215. if (!keepLoadedFonts) {
  3216. this.fontLoader.clear();
  3217. }
  3218. this.#metadataPromise = null;
  3219. this._getFieldObjectsPromise = null;
  3220. this._hasJSActionsPromise = null;
  3221. }
  3222. get loadingParams() {
  3223. const params = this._params;
  3224. return (0, _util.shadow)(this, "loadingParams", {
  3225. disableAutoFetch: params.disableAutoFetch,
  3226. enableXfa: params.enableXfa
  3227. });
  3228. }
  3229. }
  3230. class PDFObjects {
  3231. constructor() {
  3232. this._objs = Object.create(null);
  3233. }
  3234. _ensureObj(objId) {
  3235. if (this._objs[objId]) {
  3236. return this._objs[objId];
  3237. }
  3238. return this._objs[objId] = {
  3239. capability: (0, _util.createPromiseCapability)(),
  3240. data: null,
  3241. resolved: false
  3242. };
  3243. }
  3244. get(objId, callback = null) {
  3245. if (callback) {
  3246. this._ensureObj(objId).capability.promise.then(callback);
  3247. return null;
  3248. }
  3249. const obj = this._objs[objId];
  3250. if (!obj || !obj.resolved) {
  3251. throw new Error(`Requesting object that isn't resolved yet ${objId}.`);
  3252. }
  3253. return obj.data;
  3254. }
  3255. has(objId) {
  3256. const obj = this._objs[objId];
  3257. return obj?.resolved || false;
  3258. }
  3259. resolve(objId, data) {
  3260. const obj = this._ensureObj(objId);
  3261. obj.resolved = true;
  3262. obj.data = data;
  3263. obj.capability.resolve(data);
  3264. }
  3265. clear() {
  3266. this._objs = Object.create(null);
  3267. }
  3268. }
  3269. class RenderTask {
  3270. constructor(internalRenderTask) {
  3271. this._internalRenderTask = internalRenderTask;
  3272. this.onContinue = null;
  3273. }
  3274. get promise() {
  3275. return this._internalRenderTask.capability.promise;
  3276. }
  3277. cancel() {
  3278. this._internalRenderTask.cancel();
  3279. }
  3280. }
  3281. exports.RenderTask = RenderTask;
  3282. class InternalRenderTask {
  3283. static get canvasInUse() {
  3284. return (0, _util.shadow)(this, "canvasInUse", new WeakSet());
  3285. }
  3286. constructor({
  3287. callback,
  3288. params,
  3289. objs,
  3290. commonObjs,
  3291. annotationCanvasMap,
  3292. operatorList,
  3293. pageIndex,
  3294. canvasFactory,
  3295. useRequestAnimationFrame = false,
  3296. pdfBug = false
  3297. }) {
  3298. this.callback = callback;
  3299. this.params = params;
  3300. this.objs = objs;
  3301. this.commonObjs = commonObjs;
  3302. this.annotationCanvasMap = annotationCanvasMap;
  3303. this.operatorListIdx = null;
  3304. this.operatorList = operatorList;
  3305. this._pageIndex = pageIndex;
  3306. this.canvasFactory = canvasFactory;
  3307. this._pdfBug = pdfBug;
  3308. this.running = false;
  3309. this.graphicsReadyCallback = null;
  3310. this.graphicsReady = false;
  3311. this._useRequestAnimationFrame = useRequestAnimationFrame === true && typeof window !== "undefined";
  3312. this.cancelled = false;
  3313. this.capability = (0, _util.createPromiseCapability)();
  3314. this.task = new RenderTask(this);
  3315. this._cancelBound = this.cancel.bind(this);
  3316. this._continueBound = this._continue.bind(this);
  3317. this._scheduleNextBound = this._scheduleNext.bind(this);
  3318. this._nextBound = this._next.bind(this);
  3319. this._canvas = params.canvasContext.canvas;
  3320. }
  3321. get completed() {
  3322. return this.capability.promise.catch(function () {});
  3323. }
  3324. initializeGraphics({
  3325. transparency = false,
  3326. optionalContentConfig
  3327. }) {
  3328. if (this.cancelled) {
  3329. return;
  3330. }
  3331. if (this._canvas) {
  3332. if (InternalRenderTask.canvasInUse.has(this._canvas)) {
  3333. throw new Error("Cannot use the same canvas during multiple render() operations. " + "Use different canvas or ensure previous operations were " + "cancelled or completed.");
  3334. }
  3335. InternalRenderTask.canvasInUse.add(this._canvas);
  3336. }
  3337. if (this._pdfBug && globalThis.StepperManager?.enabled) {
  3338. this.stepper = globalThis.StepperManager.create(this._pageIndex);
  3339. this.stepper.init(this.operatorList);
  3340. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  3341. }
  3342. const {
  3343. canvasContext,
  3344. viewport,
  3345. transform,
  3346. imageLayer,
  3347. background
  3348. } = this.params;
  3349. this.gfx = new _canvas.CanvasGraphics(canvasContext, this.commonObjs, this.objs, this.canvasFactory, imageLayer, optionalContentConfig, this.annotationCanvasMap);
  3350. this.gfx.beginDrawing({
  3351. transform,
  3352. viewport,
  3353. transparency,
  3354. background
  3355. });
  3356. this.operatorListIdx = 0;
  3357. this.graphicsReady = true;
  3358. if (this.graphicsReadyCallback) {
  3359. this.graphicsReadyCallback();
  3360. }
  3361. }
  3362. cancel(error = null) {
  3363. this.running = false;
  3364. this.cancelled = true;
  3365. if (this.gfx) {
  3366. this.gfx.endDrawing();
  3367. }
  3368. if (this._canvas) {
  3369. InternalRenderTask.canvasInUse.delete(this._canvas);
  3370. }
  3371. this.callback(error || new _display_utils.RenderingCancelledException(`Rendering cancelled, page ${this._pageIndex + 1}`, "canvas"));
  3372. }
  3373. operatorListChanged() {
  3374. if (!this.graphicsReady) {
  3375. if (!this.graphicsReadyCallback) {
  3376. this.graphicsReadyCallback = this._continueBound;
  3377. }
  3378. return;
  3379. }
  3380. if (this.stepper) {
  3381. this.stepper.updateOperatorList(this.operatorList);
  3382. }
  3383. if (this.running) {
  3384. return;
  3385. }
  3386. this._continue();
  3387. }
  3388. _continue() {
  3389. this.running = true;
  3390. if (this.cancelled) {
  3391. return;
  3392. }
  3393. if (this.task.onContinue) {
  3394. this.task.onContinue(this._scheduleNextBound);
  3395. } else {
  3396. this._scheduleNext();
  3397. }
  3398. }
  3399. _scheduleNext() {
  3400. if (this._useRequestAnimationFrame) {
  3401. window.requestAnimationFrame(() => {
  3402. this._nextBound().catch(this._cancelBound);
  3403. });
  3404. } else {
  3405. Promise.resolve().then(this._nextBound).catch(this._cancelBound);
  3406. }
  3407. }
  3408. async _next() {
  3409. if (this.cancelled) {
  3410. return;
  3411. }
  3412. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList, this.operatorListIdx, this._continueBound, this.stepper);
  3413. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  3414. this.running = false;
  3415. if (this.operatorList.lastChunk) {
  3416. this.gfx.endDrawing();
  3417. if (this._canvas) {
  3418. InternalRenderTask.canvasInUse.delete(this._canvas);
  3419. }
  3420. this.callback();
  3421. }
  3422. }
  3423. }
  3424. }
  3425. const version = '2.12.313';
  3426. exports.version = version;
  3427. const build = 'a2ae56f39';
  3428. exports.build = build;
  3429. /***/ }),
  3430. /* 7 */
  3431. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3432. Object.defineProperty(exports, "__esModule", ({
  3433. value: true
  3434. }));
  3435. exports.FontLoader = exports.FontFaceObject = void 0;
  3436. var _util = __w_pdfjs_require__(2);
  3437. class BaseFontLoader {
  3438. constructor({
  3439. docId,
  3440. onUnsupportedFeature,
  3441. ownerDocument = globalThis.document,
  3442. styleElement = null
  3443. }) {
  3444. if (this.constructor === BaseFontLoader) {
  3445. (0, _util.unreachable)("Cannot initialize BaseFontLoader.");
  3446. }
  3447. this.docId = docId;
  3448. this._onUnsupportedFeature = onUnsupportedFeature;
  3449. this._document = ownerDocument;
  3450. this.nativeFontFaces = [];
  3451. this.styleElement = null;
  3452. }
  3453. addNativeFontFace(nativeFontFace) {
  3454. this.nativeFontFaces.push(nativeFontFace);
  3455. this._document.fonts.add(nativeFontFace);
  3456. }
  3457. insertRule(rule) {
  3458. let styleElement = this.styleElement;
  3459. if (!styleElement) {
  3460. styleElement = this.styleElement = this._document.createElement("style");
  3461. styleElement.id = `PDFJS_FONT_STYLE_TAG_${this.docId}`;
  3462. this._document.documentElement.getElementsByTagName("head")[0].appendChild(styleElement);
  3463. }
  3464. const styleSheet = styleElement.sheet;
  3465. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  3466. }
  3467. clear() {
  3468. for (const nativeFontFace of this.nativeFontFaces) {
  3469. this._document.fonts.delete(nativeFontFace);
  3470. }
  3471. this.nativeFontFaces.length = 0;
  3472. if (this.styleElement) {
  3473. this.styleElement.remove();
  3474. this.styleElement = null;
  3475. }
  3476. }
  3477. async bind(font) {
  3478. if (font.attached || font.missingFile) {
  3479. return;
  3480. }
  3481. font.attached = true;
  3482. if (this.isFontLoadingAPISupported) {
  3483. const nativeFontFace = font.createNativeFontFace();
  3484. if (nativeFontFace) {
  3485. this.addNativeFontFace(nativeFontFace);
  3486. try {
  3487. await nativeFontFace.loaded;
  3488. } catch (ex) {
  3489. this._onUnsupportedFeature({
  3490. featureId: _util.UNSUPPORTED_FEATURES.errorFontLoadNative
  3491. });
  3492. (0, _util.warn)(`Failed to load font '${nativeFontFace.family}': '${ex}'.`);
  3493. font.disableFontFace = true;
  3494. throw ex;
  3495. }
  3496. }
  3497. return;
  3498. }
  3499. const rule = font.createFontFaceRule();
  3500. if (rule) {
  3501. this.insertRule(rule);
  3502. if (this.isSyncFontLoadingSupported) {
  3503. return;
  3504. }
  3505. await new Promise(resolve => {
  3506. const request = this._queueLoadingCallback(resolve);
  3507. this._prepareFontLoadEvent([rule], [font], request);
  3508. });
  3509. }
  3510. }
  3511. _queueLoadingCallback(callback) {
  3512. (0, _util.unreachable)("Abstract method `_queueLoadingCallback`.");
  3513. }
  3514. get isFontLoadingAPISupported() {
  3515. const hasFonts = !!this._document?.fonts;
  3516. return (0, _util.shadow)(this, "isFontLoadingAPISupported", hasFonts);
  3517. }
  3518. get isSyncFontLoadingSupported() {
  3519. (0, _util.unreachable)("Abstract method `isSyncFontLoadingSupported`.");
  3520. }
  3521. get _loadTestFont() {
  3522. (0, _util.unreachable)("Abstract method `_loadTestFont`.");
  3523. }
  3524. _prepareFontLoadEvent(rules, fontsToLoad, request) {
  3525. (0, _util.unreachable)("Abstract method `_prepareFontLoadEvent`.");
  3526. }
  3527. }
  3528. let FontLoader;
  3529. exports.FontLoader = FontLoader;
  3530. {
  3531. exports.FontLoader = FontLoader = class GenericFontLoader extends BaseFontLoader {
  3532. constructor(params) {
  3533. super(params);
  3534. this.loadingContext = {
  3535. requests: [],
  3536. nextRequestId: 0
  3537. };
  3538. this.loadTestFontId = 0;
  3539. }
  3540. get isSyncFontLoadingSupported() {
  3541. let supported = false;
  3542. if (typeof navigator === "undefined") {
  3543. supported = true;
  3544. } else {
  3545. const m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(navigator.userAgent);
  3546. if (m?.[1] >= 14) {
  3547. supported = true;
  3548. }
  3549. }
  3550. return (0, _util.shadow)(this, "isSyncFontLoadingSupported", supported);
  3551. }
  3552. _queueLoadingCallback(callback) {
  3553. function completeRequest() {
  3554. (0, _util.assert)(!request.done, "completeRequest() cannot be called twice.");
  3555. request.done = true;
  3556. while (context.requests.length > 0 && context.requests[0].done) {
  3557. const otherRequest = context.requests.shift();
  3558. setTimeout(otherRequest.callback, 0);
  3559. }
  3560. }
  3561. const context = this.loadingContext;
  3562. const request = {
  3563. id: `pdfjs-font-loading-${context.nextRequestId++}`,
  3564. done: false,
  3565. complete: completeRequest,
  3566. callback
  3567. };
  3568. context.requests.push(request);
  3569. return request;
  3570. }
  3571. get _loadTestFont() {
  3572. const getLoadTestFont = function () {
  3573. 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==");
  3574. };
  3575. return (0, _util.shadow)(this, "_loadTestFont", getLoadTestFont());
  3576. }
  3577. _prepareFontLoadEvent(rules, fonts, request) {
  3578. function int32(data, offset) {
  3579. return data.charCodeAt(offset) << 24 | data.charCodeAt(offset + 1) << 16 | data.charCodeAt(offset + 2) << 8 | data.charCodeAt(offset + 3) & 0xff;
  3580. }
  3581. function spliceString(s, offset, remove, insert) {
  3582. const chunk1 = s.substring(0, offset);
  3583. const chunk2 = s.substring(offset + remove);
  3584. return chunk1 + insert + chunk2;
  3585. }
  3586. let i, ii;
  3587. const canvas = this._document.createElement("canvas");
  3588. canvas.width = 1;
  3589. canvas.height = 1;
  3590. const ctx = canvas.getContext("2d");
  3591. let called = 0;
  3592. function isFontReady(name, callback) {
  3593. called++;
  3594. if (called > 30) {
  3595. (0, _util.warn)("Load test font never loaded.");
  3596. callback();
  3597. return;
  3598. }
  3599. ctx.font = "30px " + name;
  3600. ctx.fillText(".", 0, 20);
  3601. const imageData = ctx.getImageData(0, 0, 1, 1);
  3602. if (imageData.data[3] > 0) {
  3603. callback();
  3604. return;
  3605. }
  3606. setTimeout(isFontReady.bind(null, name, callback));
  3607. }
  3608. const loadTestFontId = `lt${Date.now()}${this.loadTestFontId++}`;
  3609. let data = this._loadTestFont;
  3610. const COMMENT_OFFSET = 976;
  3611. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length, loadTestFontId);
  3612. const CFF_CHECKSUM_OFFSET = 16;
  3613. const XXXX_VALUE = 0x58585858;
  3614. let checksum = int32(data, CFF_CHECKSUM_OFFSET);
  3615. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  3616. checksum = checksum - XXXX_VALUE + int32(loadTestFontId, i) | 0;
  3617. }
  3618. if (i < loadTestFontId.length) {
  3619. checksum = checksum - XXXX_VALUE + int32(loadTestFontId + "XXX", i) | 0;
  3620. }
  3621. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, (0, _util.string32)(checksum));
  3622. const url = `url(data:font/opentype;base64,${btoa(data)});`;
  3623. const rule = `@font-face {font-family:"${loadTestFontId}";src:${url}}`;
  3624. this.insertRule(rule);
  3625. const names = [];
  3626. for (const font of fonts) {
  3627. names.push(font.loadedName);
  3628. }
  3629. names.push(loadTestFontId);
  3630. const div = this._document.createElement("div");
  3631. div.style.visibility = "hidden";
  3632. div.style.width = div.style.height = "10px";
  3633. div.style.position = "absolute";
  3634. div.style.top = div.style.left = "0px";
  3635. for (const name of names) {
  3636. const span = this._document.createElement("span");
  3637. span.textContent = "Hi";
  3638. span.style.fontFamily = name;
  3639. div.appendChild(span);
  3640. }
  3641. this._document.body.appendChild(div);
  3642. isFontReady(loadTestFontId, () => {
  3643. div.remove();
  3644. request.complete();
  3645. });
  3646. }
  3647. };
  3648. }
  3649. class FontFaceObject {
  3650. constructor(translatedData, {
  3651. isEvalSupported = true,
  3652. disableFontFace = false,
  3653. ignoreErrors = false,
  3654. onUnsupportedFeature,
  3655. fontRegistry = null
  3656. }) {
  3657. this.compiledGlyphs = Object.create(null);
  3658. for (const i in translatedData) {
  3659. this[i] = translatedData[i];
  3660. }
  3661. this.isEvalSupported = isEvalSupported !== false;
  3662. this.disableFontFace = disableFontFace === true;
  3663. this.ignoreErrors = ignoreErrors === true;
  3664. this._onUnsupportedFeature = onUnsupportedFeature;
  3665. this.fontRegistry = fontRegistry;
  3666. }
  3667. createNativeFontFace() {
  3668. if (!this.data || this.disableFontFace) {
  3669. return null;
  3670. }
  3671. let nativeFontFace;
  3672. if (!this.cssFontInfo) {
  3673. nativeFontFace = new FontFace(this.loadedName, this.data, {});
  3674. } else {
  3675. const css = {
  3676. weight: this.cssFontInfo.fontWeight
  3677. };
  3678. if (this.cssFontInfo.italicAngle) {
  3679. css.style = `oblique ${this.cssFontInfo.italicAngle}deg`;
  3680. }
  3681. nativeFontFace = new FontFace(this.cssFontInfo.fontFamily, this.data, css);
  3682. }
  3683. if (this.fontRegistry) {
  3684. this.fontRegistry.registerFont(this);
  3685. }
  3686. return nativeFontFace;
  3687. }
  3688. createFontFaceRule() {
  3689. if (!this.data || this.disableFontFace) {
  3690. return null;
  3691. }
  3692. const data = (0, _util.bytesToString)(this.data);
  3693. const url = `url(data:${this.mimetype};base64,${btoa(data)});`;
  3694. let rule;
  3695. if (!this.cssFontInfo) {
  3696. rule = `@font-face {font-family:"${this.loadedName}";src:${url}}`;
  3697. } else {
  3698. let css = `font-weight: ${this.cssFontInfo.fontWeight};`;
  3699. if (this.cssFontInfo.italicAngle) {
  3700. css += `font-style: oblique ${this.cssFontInfo.italicAngle}deg;`;
  3701. }
  3702. rule = `@font-face {font-family:"${this.cssFontInfo.fontFamily}";${css}src:${url}}`;
  3703. }
  3704. if (this.fontRegistry) {
  3705. this.fontRegistry.registerFont(this, url);
  3706. }
  3707. return rule;
  3708. }
  3709. getPathGenerator(objs, character) {
  3710. if (this.compiledGlyphs[character] !== undefined) {
  3711. return this.compiledGlyphs[character];
  3712. }
  3713. let cmds;
  3714. try {
  3715. cmds = objs.get(this.loadedName + "_path_" + character);
  3716. } catch (ex) {
  3717. if (!this.ignoreErrors) {
  3718. throw ex;
  3719. }
  3720. this._onUnsupportedFeature({
  3721. featureId: _util.UNSUPPORTED_FEATURES.errorFontGetPath
  3722. });
  3723. (0, _util.warn)(`getPathGenerator - ignoring character: "${ex}".`);
  3724. return this.compiledGlyphs[character] = function (c, size) {};
  3725. }
  3726. if (this.isEvalSupported && _util.IsEvalSupportedCached.value) {
  3727. const jsBuf = [];
  3728. for (const current of cmds) {
  3729. const args = current.args !== undefined ? current.args.join(",") : "";
  3730. jsBuf.push("c.", current.cmd, "(", args, ");\n");
  3731. }
  3732. return this.compiledGlyphs[character] = new Function("c", "size", jsBuf.join(""));
  3733. }
  3734. return this.compiledGlyphs[character] = function (c, size) {
  3735. for (const current of cmds) {
  3736. if (current.cmd === "scale") {
  3737. current.args = [size, -size];
  3738. }
  3739. c[current.cmd].apply(c, current.args);
  3740. }
  3741. };
  3742. }
  3743. }
  3744. exports.FontFaceObject = FontFaceObject;
  3745. /***/ }),
  3746. /* 8 */
  3747. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3748. Object.defineProperty(exports, "__esModule", ({
  3749. value: true
  3750. }));
  3751. exports.NodeStandardFontDataFactory = exports.NodeCanvasFactory = exports.NodeCMapReaderFactory = void 0;
  3752. var _base_factory = __w_pdfjs_require__(5);
  3753. var _is_node = __w_pdfjs_require__(4);
  3754. var _util = __w_pdfjs_require__(2);
  3755. let NodeCanvasFactory = class {
  3756. constructor() {
  3757. (0, _util.unreachable)("Not implemented: NodeCanvasFactory");
  3758. }
  3759. };
  3760. exports.NodeCanvasFactory = NodeCanvasFactory;
  3761. let NodeCMapReaderFactory = class {
  3762. constructor() {
  3763. (0, _util.unreachable)("Not implemented: NodeCMapReaderFactory");
  3764. }
  3765. };
  3766. exports.NodeCMapReaderFactory = NodeCMapReaderFactory;
  3767. let NodeStandardFontDataFactory = class {
  3768. constructor() {
  3769. (0, _util.unreachable)("Not implemented: NodeStandardFontDataFactory");
  3770. }
  3771. };
  3772. exports.NodeStandardFontDataFactory = NodeStandardFontDataFactory;
  3773. if (_is_node.isNodeJS) {
  3774. const fetchData = function (url) {
  3775. return new Promise((resolve, reject) => {
  3776. const fs = require("fs");
  3777. fs.readFile(url, (error, data) => {
  3778. if (error || !data) {
  3779. reject(new Error(error));
  3780. return;
  3781. }
  3782. resolve(new Uint8Array(data));
  3783. });
  3784. });
  3785. };
  3786. exports.NodeCanvasFactory = NodeCanvasFactory = class extends _base_factory.BaseCanvasFactory {
  3787. _createCanvas(width, height) {
  3788. const Canvas = require("canvas");
  3789. return Canvas.createCanvas(width, height);
  3790. }
  3791. };
  3792. exports.NodeCMapReaderFactory = NodeCMapReaderFactory = class extends _base_factory.BaseCMapReaderFactory {
  3793. _fetchData(url, compressionType) {
  3794. return fetchData(url).then(data => {
  3795. return {
  3796. cMapData: data,
  3797. compressionType
  3798. };
  3799. });
  3800. }
  3801. };
  3802. exports.NodeStandardFontDataFactory = NodeStandardFontDataFactory = class extends _base_factory.BaseStandardFontDataFactory {
  3803. _fetchData(url) {
  3804. return fetchData(url);
  3805. }
  3806. };
  3807. }
  3808. /***/ }),
  3809. /* 9 */
  3810. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3811. Object.defineProperty(exports, "__esModule", ({
  3812. value: true
  3813. }));
  3814. exports.AnnotationStorage = void 0;
  3815. var _util = __w_pdfjs_require__(2);
  3816. class AnnotationStorage {
  3817. constructor() {
  3818. this._storage = new Map();
  3819. this._timeStamp = Date.now();
  3820. this._modified = false;
  3821. this.onSetModified = null;
  3822. this.onResetModified = null;
  3823. }
  3824. getValue(key, defaultValue) {
  3825. const value = this._storage.get(key);
  3826. if (value === undefined) {
  3827. return defaultValue;
  3828. }
  3829. return Object.assign(defaultValue, value);
  3830. }
  3831. setValue(key, value) {
  3832. const obj = this._storage.get(key);
  3833. let modified = false;
  3834. if (obj !== undefined) {
  3835. for (const [entry, val] of Object.entries(value)) {
  3836. if (obj[entry] !== val) {
  3837. modified = true;
  3838. obj[entry] = val;
  3839. }
  3840. }
  3841. } else {
  3842. modified = true;
  3843. this._storage.set(key, value);
  3844. }
  3845. if (modified) {
  3846. this._timeStamp = Date.now();
  3847. this._setModified();
  3848. }
  3849. }
  3850. getAll() {
  3851. return this._storage.size > 0 ? (0, _util.objectFromMap)(this._storage) : null;
  3852. }
  3853. get size() {
  3854. return this._storage.size;
  3855. }
  3856. _setModified() {
  3857. if (!this._modified) {
  3858. this._modified = true;
  3859. if (typeof this.onSetModified === "function") {
  3860. this.onSetModified();
  3861. }
  3862. }
  3863. }
  3864. resetModified() {
  3865. if (this._modified) {
  3866. this._modified = false;
  3867. if (typeof this.onResetModified === "function") {
  3868. this.onResetModified();
  3869. }
  3870. }
  3871. }
  3872. get serializable() {
  3873. return this._storage.size > 0 ? this._storage : null;
  3874. }
  3875. get lastModified() {
  3876. return this._timeStamp.toString();
  3877. }
  3878. }
  3879. exports.AnnotationStorage = AnnotationStorage;
  3880. /***/ }),
  3881. /* 10 */
  3882. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3883. Object.defineProperty(exports, "__esModule", ({
  3884. value: true
  3885. }));
  3886. exports.CanvasGraphics = void 0;
  3887. var _util = __w_pdfjs_require__(2);
  3888. var _pattern_helper = __w_pdfjs_require__(11);
  3889. var _display_utils = __w_pdfjs_require__(1);
  3890. const MIN_FONT_SIZE = 16;
  3891. const MAX_FONT_SIZE = 100;
  3892. const MAX_GROUP_SIZE = 4096;
  3893. const EXECUTION_TIME = 15;
  3894. const EXECUTION_STEPS = 10;
  3895. const COMPILE_TYPE3_GLYPHS = true;
  3896. const MAX_SIZE_TO_COMPILE = 1000;
  3897. const FULL_CHUNK_HEIGHT = 16;
  3898. const LINEWIDTH_SCALE_FACTOR = 1.000001;
  3899. function mirrorContextOperations(ctx, destCtx) {
  3900. if (ctx._removeMirroring) {
  3901. throw new Error("Context is already forwarding operations.");
  3902. }
  3903. ctx.__originalSave = ctx.save;
  3904. ctx.__originalRestore = ctx.restore;
  3905. ctx.__originalRotate = ctx.rotate;
  3906. ctx.__originalScale = ctx.scale;
  3907. ctx.__originalTranslate = ctx.translate;
  3908. ctx.__originalTransform = ctx.transform;
  3909. ctx.__originalSetTransform = ctx.setTransform;
  3910. ctx.__originalResetTransform = ctx.resetTransform;
  3911. ctx.__originalClip = ctx.clip;
  3912. ctx.__originalMoveTo = ctx.moveTo;
  3913. ctx.__originalLineTo = ctx.lineTo;
  3914. ctx.__originalBezierCurveTo = ctx.bezierCurveTo;
  3915. ctx.__originalRect = ctx.rect;
  3916. ctx.__originalClosePath = ctx.closePath;
  3917. ctx.__originalBeginPath = ctx.beginPath;
  3918. ctx._removeMirroring = () => {
  3919. ctx.save = ctx.__originalSave;
  3920. ctx.restore = ctx.__originalRestore;
  3921. ctx.rotate = ctx.__originalRotate;
  3922. ctx.scale = ctx.__originalScale;
  3923. ctx.translate = ctx.__originalTranslate;
  3924. ctx.transform = ctx.__originalTransform;
  3925. ctx.setTransform = ctx.__originalSetTransform;
  3926. ctx.resetTransform = ctx.__originalResetTransform;
  3927. ctx.clip = ctx.__originalClip;
  3928. ctx.moveTo = ctx.__originalMoveTo;
  3929. ctx.lineTo = ctx.__originalLineTo;
  3930. ctx.bezierCurveTo = ctx.__originalBezierCurveTo;
  3931. ctx.rect = ctx.__originalRect;
  3932. ctx.closePath = ctx.__originalClosePath;
  3933. ctx.beginPath = ctx.__originalBeginPath;
  3934. delete ctx._removeMirroring;
  3935. };
  3936. ctx.save = function ctxSave() {
  3937. destCtx.save();
  3938. this.__originalSave();
  3939. };
  3940. ctx.restore = function ctxRestore() {
  3941. destCtx.restore();
  3942. this.__originalRestore();
  3943. };
  3944. ctx.translate = function ctxTranslate(x, y) {
  3945. destCtx.translate(x, y);
  3946. this.__originalTranslate(x, y);
  3947. };
  3948. ctx.scale = function ctxScale(x, y) {
  3949. destCtx.scale(x, y);
  3950. this.__originalScale(x, y);
  3951. };
  3952. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  3953. destCtx.transform(a, b, c, d, e, f);
  3954. this.__originalTransform(a, b, c, d, e, f);
  3955. };
  3956. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  3957. destCtx.setTransform(a, b, c, d, e, f);
  3958. this.__originalSetTransform(a, b, c, d, e, f);
  3959. };
  3960. ctx.resetTransform = function ctxResetTransform() {
  3961. destCtx.resetTransform();
  3962. this.__originalResetTransform();
  3963. };
  3964. ctx.rotate = function ctxRotate(angle) {
  3965. destCtx.rotate(angle);
  3966. this.__originalRotate(angle);
  3967. };
  3968. ctx.clip = function ctxRotate(rule) {
  3969. destCtx.clip(rule);
  3970. this.__originalClip(rule);
  3971. };
  3972. ctx.moveTo = function (x, y) {
  3973. destCtx.moveTo(x, y);
  3974. this.__originalMoveTo(x, y);
  3975. };
  3976. ctx.lineTo = function (x, y) {
  3977. destCtx.lineTo(x, y);
  3978. this.__originalLineTo(x, y);
  3979. };
  3980. ctx.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
  3981. destCtx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
  3982. this.__originalBezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
  3983. };
  3984. ctx.rect = function (x, y, width, height) {
  3985. destCtx.rect(x, y, width, height);
  3986. this.__originalRect(x, y, width, height);
  3987. };
  3988. ctx.closePath = function () {
  3989. destCtx.closePath();
  3990. this.__originalClosePath();
  3991. };
  3992. ctx.beginPath = function () {
  3993. destCtx.beginPath();
  3994. this.__originalBeginPath();
  3995. };
  3996. }
  3997. function addContextCurrentTransform(ctx) {
  3998. if (ctx.mozCurrentTransform) {
  3999. return;
  4000. }
  4001. ctx._originalSave = ctx.save;
  4002. ctx._originalRestore = ctx.restore;
  4003. ctx._originalRotate = ctx.rotate;
  4004. ctx._originalScale = ctx.scale;
  4005. ctx._originalTranslate = ctx.translate;
  4006. ctx._originalTransform = ctx.transform;
  4007. ctx._originalSetTransform = ctx.setTransform;
  4008. ctx._originalResetTransform = ctx.resetTransform;
  4009. ctx._transformMatrix = ctx._transformMatrix || [1, 0, 0, 1, 0, 0];
  4010. ctx._transformStack = [];
  4011. try {
  4012. const desc = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(ctx), "lineWidth");
  4013. ctx._setLineWidth = desc.set;
  4014. ctx._getLineWidth = desc.get;
  4015. Object.defineProperty(ctx, "lineWidth", {
  4016. set: function setLineWidth(width) {
  4017. this._setLineWidth(width * LINEWIDTH_SCALE_FACTOR);
  4018. },
  4019. get: function getLineWidth() {
  4020. return this._getLineWidth();
  4021. }
  4022. });
  4023. } catch (_) {}
  4024. Object.defineProperty(ctx, "mozCurrentTransform", {
  4025. get: function getCurrentTransform() {
  4026. return this._transformMatrix;
  4027. }
  4028. });
  4029. Object.defineProperty(ctx, "mozCurrentTransformInverse", {
  4030. get: function getCurrentTransformInverse() {
  4031. const [a, b, c, d, e, f] = this._transformMatrix;
  4032. const ad_bc = a * d - b * c;
  4033. const bc_ad = b * c - a * d;
  4034. 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];
  4035. }
  4036. });
  4037. ctx.save = function ctxSave() {
  4038. const old = this._transformMatrix;
  4039. this._transformStack.push(old);
  4040. this._transformMatrix = old.slice(0, 6);
  4041. this._originalSave();
  4042. };
  4043. ctx.restore = function ctxRestore() {
  4044. const prev = this._transformStack.pop();
  4045. if (prev) {
  4046. this._transformMatrix = prev;
  4047. this._originalRestore();
  4048. }
  4049. };
  4050. ctx.translate = function ctxTranslate(x, y) {
  4051. const m = this._transformMatrix;
  4052. m[4] = m[0] * x + m[2] * y + m[4];
  4053. m[5] = m[1] * x + m[3] * y + m[5];
  4054. this._originalTranslate(x, y);
  4055. };
  4056. ctx.scale = function ctxScale(x, y) {
  4057. const m = this._transformMatrix;
  4058. m[0] *= x;
  4059. m[1] *= x;
  4060. m[2] *= y;
  4061. m[3] *= y;
  4062. this._originalScale(x, y);
  4063. };
  4064. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  4065. const m = this._transformMatrix;
  4066. 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]];
  4067. ctx._originalTransform(a, b, c, d, e, f);
  4068. };
  4069. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  4070. this._transformMatrix = [a, b, c, d, e, f];
  4071. ctx._originalSetTransform(a, b, c, d, e, f);
  4072. };
  4073. ctx.resetTransform = function ctxResetTransform() {
  4074. this._transformMatrix = [1, 0, 0, 1, 0, 0];
  4075. ctx._originalResetTransform();
  4076. };
  4077. ctx.rotate = function ctxRotate(angle) {
  4078. const cosValue = Math.cos(angle);
  4079. const sinValue = Math.sin(angle);
  4080. const m = this._transformMatrix;
  4081. 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]];
  4082. this._originalRotate(angle);
  4083. };
  4084. }
  4085. class CachedCanvases {
  4086. constructor(canvasFactory) {
  4087. this.canvasFactory = canvasFactory;
  4088. this.cache = Object.create(null);
  4089. }
  4090. getCanvas(id, width, height, trackTransform) {
  4091. let canvasEntry;
  4092. if (this.cache[id] !== undefined) {
  4093. canvasEntry = this.cache[id];
  4094. this.canvasFactory.reset(canvasEntry, width, height);
  4095. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  4096. } else {
  4097. canvasEntry = this.canvasFactory.create(width, height);
  4098. this.cache[id] = canvasEntry;
  4099. }
  4100. if (trackTransform) {
  4101. addContextCurrentTransform(canvasEntry.context);
  4102. }
  4103. return canvasEntry;
  4104. }
  4105. clear() {
  4106. for (const id in this.cache) {
  4107. const canvasEntry = this.cache[id];
  4108. this.canvasFactory.destroy(canvasEntry);
  4109. delete this.cache[id];
  4110. }
  4111. }
  4112. }
  4113. function compileType3Glyph(imgData) {
  4114. const POINT_TO_PROCESS_LIMIT = 1000;
  4115. const POINT_TYPES = new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  4116. const width = imgData.width,
  4117. height = imgData.height,
  4118. width1 = width + 1;
  4119. let i, ii, j, j0;
  4120. const points = new Uint8Array(width1 * (height + 1));
  4121. const lineSize = width + 7 & ~7,
  4122. data0 = imgData.data;
  4123. const data = new Uint8Array(lineSize * height);
  4124. let pos = 0;
  4125. for (i = 0, ii = data0.length; i < ii; i++) {
  4126. const elem = data0[i];
  4127. let mask = 128;
  4128. while (mask > 0) {
  4129. data[pos++] = elem & mask ? 0 : 255;
  4130. mask >>= 1;
  4131. }
  4132. }
  4133. let count = 0;
  4134. pos = 0;
  4135. if (data[pos] !== 0) {
  4136. points[0] = 1;
  4137. ++count;
  4138. }
  4139. for (j = 1; j < width; j++) {
  4140. if (data[pos] !== data[pos + 1]) {
  4141. points[j] = data[pos] ? 2 : 1;
  4142. ++count;
  4143. }
  4144. pos++;
  4145. }
  4146. if (data[pos] !== 0) {
  4147. points[j] = 2;
  4148. ++count;
  4149. }
  4150. for (i = 1; i < height; i++) {
  4151. pos = i * lineSize;
  4152. j0 = i * width1;
  4153. if (data[pos - lineSize] !== data[pos]) {
  4154. points[j0] = data[pos] ? 1 : 8;
  4155. ++count;
  4156. }
  4157. let sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  4158. for (j = 1; j < width; j++) {
  4159. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) + (data[pos - lineSize + 1] ? 8 : 0);
  4160. if (POINT_TYPES[sum]) {
  4161. points[j0 + j] = POINT_TYPES[sum];
  4162. ++count;
  4163. }
  4164. pos++;
  4165. }
  4166. if (data[pos - lineSize] !== data[pos]) {
  4167. points[j0 + j] = data[pos] ? 2 : 4;
  4168. ++count;
  4169. }
  4170. if (count > POINT_TO_PROCESS_LIMIT) {
  4171. return null;
  4172. }
  4173. }
  4174. pos = lineSize * (height - 1);
  4175. j0 = i * width1;
  4176. if (data[pos] !== 0) {
  4177. points[j0] = 8;
  4178. ++count;
  4179. }
  4180. for (j = 1; j < width; j++) {
  4181. if (data[pos] !== data[pos + 1]) {
  4182. points[j0 + j] = data[pos] ? 4 : 8;
  4183. ++count;
  4184. }
  4185. pos++;
  4186. }
  4187. if (data[pos] !== 0) {
  4188. points[j0 + j] = 4;
  4189. ++count;
  4190. }
  4191. if (count > POINT_TO_PROCESS_LIMIT) {
  4192. return null;
  4193. }
  4194. const steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  4195. const outlines = [];
  4196. for (i = 0; count && i <= height; i++) {
  4197. let p = i * width1;
  4198. const end = p + width;
  4199. while (p < end && !points[p]) {
  4200. p++;
  4201. }
  4202. if (p === end) {
  4203. continue;
  4204. }
  4205. const coords = [p % width1, i];
  4206. const p0 = p;
  4207. let type = points[p];
  4208. do {
  4209. const step = steps[type];
  4210. do {
  4211. p += step;
  4212. } while (!points[p]);
  4213. const pp = points[p];
  4214. if (pp !== 5 && pp !== 10) {
  4215. type = pp;
  4216. points[p] = 0;
  4217. } else {
  4218. type = pp & 0x33 * type >> 4;
  4219. points[p] &= type >> 2 | type << 2;
  4220. }
  4221. coords.push(p % width1, p / width1 | 0);
  4222. if (!points[p]) {
  4223. --count;
  4224. }
  4225. } while (p0 !== p);
  4226. outlines.push(coords);
  4227. --i;
  4228. }
  4229. const drawOutline = function (c) {
  4230. c.save();
  4231. c.scale(1 / width, -1 / height);
  4232. c.translate(0, -height);
  4233. c.beginPath();
  4234. for (let k = 0, kk = outlines.length; k < kk; k++) {
  4235. const o = outlines[k];
  4236. c.moveTo(o[0], o[1]);
  4237. for (let l = 2, ll = o.length; l < ll; l += 2) {
  4238. c.lineTo(o[l], o[l + 1]);
  4239. }
  4240. }
  4241. c.fill();
  4242. c.beginPath();
  4243. c.restore();
  4244. };
  4245. return drawOutline;
  4246. }
  4247. class CanvasExtraState {
  4248. constructor(width, height) {
  4249. this.alphaIsShape = false;
  4250. this.fontSize = 0;
  4251. this.fontSizeScale = 1;
  4252. this.textMatrix = _util.IDENTITY_MATRIX;
  4253. this.textMatrixScale = 1;
  4254. this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
  4255. this.leading = 0;
  4256. this.x = 0;
  4257. this.y = 0;
  4258. this.lineX = 0;
  4259. this.lineY = 0;
  4260. this.charSpacing = 0;
  4261. this.wordSpacing = 0;
  4262. this.textHScale = 1;
  4263. this.textRenderingMode = _util.TextRenderingMode.FILL;
  4264. this.textRise = 0;
  4265. this.fillColor = "#000000";
  4266. this.strokeColor = "#000000";
  4267. this.patternFill = false;
  4268. this.fillAlpha = 1;
  4269. this.strokeAlpha = 1;
  4270. this.lineWidth = 1;
  4271. this.activeSMask = null;
  4272. this.transferMaps = null;
  4273. this.startNewPathAndClipBox([0, 0, width, height]);
  4274. }
  4275. clone() {
  4276. const clone = Object.create(this);
  4277. clone.clipBox = this.clipBox.slice();
  4278. return clone;
  4279. }
  4280. setCurrentPoint(x, y) {
  4281. this.x = x;
  4282. this.y = y;
  4283. }
  4284. updatePathMinMax(transform, x, y) {
  4285. [x, y] = _util.Util.applyTransform([x, y], transform);
  4286. this.minX = Math.min(this.minX, x);
  4287. this.minY = Math.min(this.minY, y);
  4288. this.maxX = Math.max(this.maxX, x);
  4289. this.maxY = Math.max(this.maxY, y);
  4290. }
  4291. updateCurvePathMinMax(transform, x0, y0, x1, y1, x2, y2, x3, y3) {
  4292. const box = _util.Util.bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3);
  4293. this.updatePathMinMax(transform, box[0], box[1]);
  4294. this.updatePathMinMax(transform, box[2], box[3]);
  4295. }
  4296. getPathBoundingBox(pathType = _pattern_helper.PathType.FILL, transform = null) {
  4297. const box = [this.minX, this.minY, this.maxX, this.maxY];
  4298. if (pathType === _pattern_helper.PathType.STROKE) {
  4299. if (!transform) {
  4300. (0, _util.unreachable)("Stroke bounding box must include transform.");
  4301. }
  4302. const scale = _util.Util.singularValueDecompose2dScale(transform);
  4303. const xStrokePad = scale[0] * this.lineWidth / 2;
  4304. const yStrokePad = scale[1] * this.lineWidth / 2;
  4305. box[0] -= xStrokePad;
  4306. box[1] -= yStrokePad;
  4307. box[2] += xStrokePad;
  4308. box[3] += yStrokePad;
  4309. }
  4310. return box;
  4311. }
  4312. updateClipFromPath() {
  4313. const intersect = _util.Util.intersect(this.clipBox, this.getPathBoundingBox());
  4314. this.startNewPathAndClipBox(intersect || [0, 0, 0, 0]);
  4315. }
  4316. startNewPathAndClipBox(box) {
  4317. this.clipBox = box;
  4318. this.minX = Infinity;
  4319. this.minY = Infinity;
  4320. this.maxX = 0;
  4321. this.maxY = 0;
  4322. }
  4323. getClippedPathBoundingBox(pathType = _pattern_helper.PathType.FILL, transform = null) {
  4324. return _util.Util.intersect(this.clipBox, this.getPathBoundingBox(pathType, transform));
  4325. }
  4326. }
  4327. function putBinaryImageData(ctx, imgData, transferMaps = null) {
  4328. if (typeof ImageData !== "undefined" && imgData instanceof ImageData) {
  4329. ctx.putImageData(imgData, 0, 0);
  4330. return;
  4331. }
  4332. const height = imgData.height,
  4333. width = imgData.width;
  4334. const partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  4335. const fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  4336. const totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  4337. const chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  4338. let srcPos = 0,
  4339. destPos;
  4340. const src = imgData.data;
  4341. const dest = chunkImgData.data;
  4342. let i, j, thisChunkHeight, elemsInThisChunk;
  4343. let transferMapRed, transferMapGreen, transferMapBlue, transferMapGray;
  4344. if (transferMaps) {
  4345. switch (transferMaps.length) {
  4346. case 1:
  4347. transferMapRed = transferMaps[0];
  4348. transferMapGreen = transferMaps[0];
  4349. transferMapBlue = transferMaps[0];
  4350. transferMapGray = transferMaps[0];
  4351. break;
  4352. case 4:
  4353. transferMapRed = transferMaps[0];
  4354. transferMapGreen = transferMaps[1];
  4355. transferMapBlue = transferMaps[2];
  4356. transferMapGray = transferMaps[3];
  4357. break;
  4358. }
  4359. }
  4360. if (imgData.kind === _util.ImageKind.GRAYSCALE_1BPP) {
  4361. const srcLength = src.byteLength;
  4362. const dest32 = new Uint32Array(dest.buffer, 0, dest.byteLength >> 2);
  4363. const dest32DataLength = dest32.length;
  4364. const fullSrcDiff = width + 7 >> 3;
  4365. let white = 0xffffffff;
  4366. let black = _util.IsLittleEndianCached.value ? 0xff000000 : 0x000000ff;
  4367. if (transferMapGray) {
  4368. if (transferMapGray[0] === 0xff && transferMapGray[0xff] === 0) {
  4369. [white, black] = [black, white];
  4370. }
  4371. }
  4372. for (i = 0; i < totalChunks; i++) {
  4373. thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  4374. destPos = 0;
  4375. for (j = 0; j < thisChunkHeight; j++) {
  4376. const srcDiff = srcLength - srcPos;
  4377. let k = 0;
  4378. const kEnd = srcDiff > fullSrcDiff ? width : srcDiff * 8 - 7;
  4379. const kEndUnrolled = kEnd & ~7;
  4380. let mask = 0;
  4381. let srcByte = 0;
  4382. for (; k < kEndUnrolled; k += 8) {
  4383. srcByte = src[srcPos++];
  4384. dest32[destPos++] = srcByte & 128 ? white : black;
  4385. dest32[destPos++] = srcByte & 64 ? white : black;
  4386. dest32[destPos++] = srcByte & 32 ? white : black;
  4387. dest32[destPos++] = srcByte & 16 ? white : black;
  4388. dest32[destPos++] = srcByte & 8 ? white : black;
  4389. dest32[destPos++] = srcByte & 4 ? white : black;
  4390. dest32[destPos++] = srcByte & 2 ? white : black;
  4391. dest32[destPos++] = srcByte & 1 ? white : black;
  4392. }
  4393. for (; k < kEnd; k++) {
  4394. if (mask === 0) {
  4395. srcByte = src[srcPos++];
  4396. mask = 128;
  4397. }
  4398. dest32[destPos++] = srcByte & mask ? white : black;
  4399. mask >>= 1;
  4400. }
  4401. }
  4402. while (destPos < dest32DataLength) {
  4403. dest32[destPos++] = 0;
  4404. }
  4405. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  4406. }
  4407. } else if (imgData.kind === _util.ImageKind.RGBA_32BPP) {
  4408. const hasTransferMaps = !!(transferMapRed || transferMapGreen || transferMapBlue);
  4409. j = 0;
  4410. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  4411. for (i = 0; i < fullChunks; i++) {
  4412. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  4413. srcPos += elemsInThisChunk;
  4414. if (hasTransferMaps) {
  4415. for (let k = 0; k < elemsInThisChunk; k += 4) {
  4416. if (transferMapRed) {
  4417. dest[k + 0] = transferMapRed[dest[k + 0]];
  4418. }
  4419. if (transferMapGreen) {
  4420. dest[k + 1] = transferMapGreen[dest[k + 1]];
  4421. }
  4422. if (transferMapBlue) {
  4423. dest[k + 2] = transferMapBlue[dest[k + 2]];
  4424. }
  4425. }
  4426. }
  4427. ctx.putImageData(chunkImgData, 0, j);
  4428. j += FULL_CHUNK_HEIGHT;
  4429. }
  4430. if (i < totalChunks) {
  4431. elemsInThisChunk = width * partialChunkHeight * 4;
  4432. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  4433. if (hasTransferMaps) {
  4434. for (let k = 0; k < elemsInThisChunk; k += 4) {
  4435. if (transferMapRed) {
  4436. dest[k + 0] = transferMapRed[dest[k + 0]];
  4437. }
  4438. if (transferMapGreen) {
  4439. dest[k + 1] = transferMapGreen[dest[k + 1]];
  4440. }
  4441. if (transferMapBlue) {
  4442. dest[k + 2] = transferMapBlue[dest[k + 2]];
  4443. }
  4444. }
  4445. }
  4446. ctx.putImageData(chunkImgData, 0, j);
  4447. }
  4448. } else if (imgData.kind === _util.ImageKind.RGB_24BPP) {
  4449. const hasTransferMaps = !!(transferMapRed || transferMapGreen || transferMapBlue);
  4450. thisChunkHeight = FULL_CHUNK_HEIGHT;
  4451. elemsInThisChunk = width * thisChunkHeight;
  4452. for (i = 0; i < totalChunks; i++) {
  4453. if (i >= fullChunks) {
  4454. thisChunkHeight = partialChunkHeight;
  4455. elemsInThisChunk = width * thisChunkHeight;
  4456. }
  4457. destPos = 0;
  4458. for (j = elemsInThisChunk; j--;) {
  4459. dest[destPos++] = src[srcPos++];
  4460. dest[destPos++] = src[srcPos++];
  4461. dest[destPos++] = src[srcPos++];
  4462. dest[destPos++] = 255;
  4463. }
  4464. if (hasTransferMaps) {
  4465. for (let k = 0; k < destPos; k += 4) {
  4466. if (transferMapRed) {
  4467. dest[k + 0] = transferMapRed[dest[k + 0]];
  4468. }
  4469. if (transferMapGreen) {
  4470. dest[k + 1] = transferMapGreen[dest[k + 1]];
  4471. }
  4472. if (transferMapBlue) {
  4473. dest[k + 2] = transferMapBlue[dest[k + 2]];
  4474. }
  4475. }
  4476. }
  4477. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  4478. }
  4479. } else {
  4480. throw new Error(`bad image kind: ${imgData.kind}`);
  4481. }
  4482. }
  4483. function putBinaryImageMask(ctx, imgData) {
  4484. const height = imgData.height,
  4485. width = imgData.width;
  4486. const partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  4487. const fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  4488. const totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  4489. const chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  4490. let srcPos = 0;
  4491. const src = imgData.data;
  4492. const dest = chunkImgData.data;
  4493. for (let i = 0; i < totalChunks; i++) {
  4494. const thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  4495. let destPos = 3;
  4496. for (let j = 0; j < thisChunkHeight; j++) {
  4497. let elem,
  4498. mask = 0;
  4499. for (let k = 0; k < width; k++) {
  4500. if (!mask) {
  4501. elem = src[srcPos++];
  4502. mask = 128;
  4503. }
  4504. dest[destPos] = elem & mask ? 0 : 255;
  4505. destPos += 4;
  4506. mask >>= 1;
  4507. }
  4508. }
  4509. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  4510. }
  4511. }
  4512. function copyCtxState(sourceCtx, destCtx) {
  4513. const properties = ["strokeStyle", "fillStyle", "fillRule", "globalAlpha", "lineWidth", "lineCap", "lineJoin", "miterLimit", "globalCompositeOperation", "font"];
  4514. for (let i = 0, ii = properties.length; i < ii; i++) {
  4515. const property = properties[i];
  4516. if (sourceCtx[property] !== undefined) {
  4517. destCtx[property] = sourceCtx[property];
  4518. }
  4519. }
  4520. if (sourceCtx.setLineDash !== undefined) {
  4521. destCtx.setLineDash(sourceCtx.getLineDash());
  4522. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  4523. }
  4524. }
  4525. function resetCtxToDefault(ctx) {
  4526. ctx.strokeStyle = "#000000";
  4527. ctx.fillStyle = "#000000";
  4528. ctx.fillRule = "nonzero";
  4529. ctx.globalAlpha = 1;
  4530. ctx.lineWidth = 1;
  4531. ctx.lineCap = "butt";
  4532. ctx.lineJoin = "miter";
  4533. ctx.miterLimit = 10;
  4534. ctx.globalCompositeOperation = "source-over";
  4535. ctx.font = "10px sans-serif";
  4536. if (ctx.setLineDash !== undefined) {
  4537. ctx.setLineDash([]);
  4538. ctx.lineDashOffset = 0;
  4539. }
  4540. }
  4541. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  4542. const length = bytes.length;
  4543. for (let i = 3; i < length; i += 4) {
  4544. const alpha = bytes[i];
  4545. if (alpha === 0) {
  4546. bytes[i - 3] = r0;
  4547. bytes[i - 2] = g0;
  4548. bytes[i - 1] = b0;
  4549. } else if (alpha < 255) {
  4550. const alpha_ = 255 - alpha;
  4551. bytes[i - 3] = bytes[i - 3] * alpha + r0 * alpha_ >> 8;
  4552. bytes[i - 2] = bytes[i - 2] * alpha + g0 * alpha_ >> 8;
  4553. bytes[i - 1] = bytes[i - 1] * alpha + b0 * alpha_ >> 8;
  4554. }
  4555. }
  4556. }
  4557. function composeSMaskAlpha(maskData, layerData, transferMap) {
  4558. const length = maskData.length;
  4559. const scale = 1 / 255;
  4560. for (let i = 3; i < length; i += 4) {
  4561. const alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
  4562. layerData[i] = layerData[i] * alpha * scale | 0;
  4563. }
  4564. }
  4565. function composeSMaskLuminosity(maskData, layerData, transferMap) {
  4566. const length = maskData.length;
  4567. for (let i = 3; i < length; i += 4) {
  4568. const y = maskData[i - 3] * 77 + maskData[i - 2] * 152 + maskData[i - 1] * 28;
  4569. layerData[i] = transferMap ? layerData[i] * transferMap[y >> 8] >> 8 : layerData[i] * y >> 16;
  4570. }
  4571. }
  4572. function genericComposeSMask(maskCtx, layerCtx, width, height, subtype, backdrop, transferMap, layerOffsetX, layerOffsetY, maskOffsetX, maskOffsetY) {
  4573. const hasBackdrop = !!backdrop;
  4574. const r0 = hasBackdrop ? backdrop[0] : 0;
  4575. const g0 = hasBackdrop ? backdrop[1] : 0;
  4576. const b0 = hasBackdrop ? backdrop[2] : 0;
  4577. let composeFn;
  4578. if (subtype === "Luminosity") {
  4579. composeFn = composeSMaskLuminosity;
  4580. } else {
  4581. composeFn = composeSMaskAlpha;
  4582. }
  4583. const PIXELS_TO_PROCESS = 1048576;
  4584. const chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  4585. for (let row = 0; row < height; row += chunkSize) {
  4586. const chunkHeight = Math.min(chunkSize, height - row);
  4587. const maskData = maskCtx.getImageData(layerOffsetX - maskOffsetX, row + (layerOffsetY - maskOffsetY), width, chunkHeight);
  4588. const layerData = layerCtx.getImageData(layerOffsetX, row + layerOffsetY, width, chunkHeight);
  4589. if (hasBackdrop) {
  4590. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  4591. }
  4592. composeFn(maskData.data, layerData.data, transferMap);
  4593. layerCtx.putImageData(layerData, layerOffsetX, row + layerOffsetY);
  4594. }
  4595. }
  4596. function composeSMask(ctx, smask, layerCtx, layerBox) {
  4597. const layerOffsetX = layerBox[0];
  4598. const layerOffsetY = layerBox[1];
  4599. const layerWidth = layerBox[2] - layerOffsetX;
  4600. const layerHeight = layerBox[3] - layerOffsetY;
  4601. if (layerWidth === 0 || layerHeight === 0) {
  4602. return;
  4603. }
  4604. genericComposeSMask(smask.context, layerCtx, layerWidth, layerHeight, smask.subtype, smask.backdrop, smask.transferMap, layerOffsetX, layerOffsetY, smask.offsetX, smask.offsetY);
  4605. ctx.save();
  4606. ctx.globalAlpha = 1;
  4607. ctx.globalCompositeOperation = "source-over";
  4608. ctx.setTransform(1, 0, 0, 1, 0, 0);
  4609. ctx.drawImage(layerCtx.canvas, 0, 0);
  4610. ctx.restore();
  4611. }
  4612. function getImageSmoothingEnabled(transform, interpolate) {
  4613. const scale = _util.Util.singularValueDecompose2dScale(transform);
  4614. scale[0] = Math.fround(scale[0]);
  4615. scale[1] = Math.fround(scale[1]);
  4616. const actualScale = Math.fround((globalThis.devicePixelRatio || 1) * _display_utils.PixelsPerInch.PDF_TO_CSS_UNITS);
  4617. if (interpolate !== undefined) {
  4618. return interpolate;
  4619. } else if (scale[0] <= actualScale || scale[1] <= actualScale) {
  4620. return true;
  4621. }
  4622. return false;
  4623. }
  4624. const LINE_CAP_STYLES = ["butt", "round", "square"];
  4625. const LINE_JOIN_STYLES = ["miter", "round", "bevel"];
  4626. const NORMAL_CLIP = {};
  4627. const EO_CLIP = {};
  4628. class CanvasGraphics {
  4629. constructor(canvasCtx, commonObjs, objs, canvasFactory, imageLayer, optionalContentConfig, annotationCanvasMap) {
  4630. this.ctx = canvasCtx;
  4631. this.current = new CanvasExtraState(this.ctx.canvas.width, this.ctx.canvas.height);
  4632. this.stateStack = [];
  4633. this.pendingClip = null;
  4634. this.pendingEOFill = false;
  4635. this.res = null;
  4636. this.xobjs = null;
  4637. this.commonObjs = commonObjs;
  4638. this.objs = objs;
  4639. this.canvasFactory = canvasFactory;
  4640. this.imageLayer = imageLayer;
  4641. this.groupStack = [];
  4642. this.processingType3 = null;
  4643. this.baseTransform = null;
  4644. this.baseTransformStack = [];
  4645. this.groupLevel = 0;
  4646. this.smaskStack = [];
  4647. this.smaskCounter = 0;
  4648. this.tempSMask = null;
  4649. this.suspendedCtx = null;
  4650. this.contentVisible = true;
  4651. this.markedContentStack = [];
  4652. this.optionalContentConfig = optionalContentConfig;
  4653. this.cachedCanvases = new CachedCanvases(this.canvasFactory);
  4654. this.cachedPatterns = new Map();
  4655. this.annotationCanvasMap = annotationCanvasMap;
  4656. this.viewportScale = 1;
  4657. this.outputScaleX = 1;
  4658. this.outputScaleY = 1;
  4659. if (canvasCtx) {
  4660. addContextCurrentTransform(canvasCtx);
  4661. }
  4662. this._cachedGetSinglePixelWidth = null;
  4663. }
  4664. beginDrawing({
  4665. transform,
  4666. viewport,
  4667. transparency = false,
  4668. background = null
  4669. }) {
  4670. const width = this.ctx.canvas.width;
  4671. const height = this.ctx.canvas.height;
  4672. this.ctx.save();
  4673. this.ctx.fillStyle = background || "rgb(255, 255, 255)";
  4674. this.ctx.fillRect(0, 0, width, height);
  4675. this.ctx.restore();
  4676. if (transparency) {
  4677. const transparentCanvas = this.cachedCanvases.getCanvas("transparent", width, height, true);
  4678. this.compositeCtx = this.ctx;
  4679. this.transparentCanvas = transparentCanvas.canvas;
  4680. this.ctx = transparentCanvas.context;
  4681. this.ctx.save();
  4682. this.ctx.transform.apply(this.ctx, this.compositeCtx.mozCurrentTransform);
  4683. }
  4684. this.ctx.save();
  4685. resetCtxToDefault(this.ctx);
  4686. if (transform) {
  4687. this.ctx.transform.apply(this.ctx, transform);
  4688. this.outputScaleX = transform[0];
  4689. this.outputScaleY = transform[0];
  4690. }
  4691. this.ctx.transform.apply(this.ctx, viewport.transform);
  4692. this.viewportScale = viewport.scale;
  4693. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  4694. this._combinedScaleFactor = Math.hypot(this.baseTransform[0], this.baseTransform[2]);
  4695. if (this.imageLayer) {
  4696. this.imageLayer.beginLayout();
  4697. }
  4698. }
  4699. executeOperatorList(operatorList, executionStartIdx, continueCallback, stepper) {
  4700. const argsArray = operatorList.argsArray;
  4701. const fnArray = operatorList.fnArray;
  4702. let i = executionStartIdx || 0;
  4703. const argsArrayLen = argsArray.length;
  4704. if (argsArrayLen === i) {
  4705. return i;
  4706. }
  4707. const chunkOperations = argsArrayLen - i > EXECUTION_STEPS && typeof continueCallback === "function";
  4708. const endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  4709. let steps = 0;
  4710. const commonObjs = this.commonObjs;
  4711. const objs = this.objs;
  4712. let fnId;
  4713. while (true) {
  4714. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  4715. stepper.breakIt(i, continueCallback);
  4716. return i;
  4717. }
  4718. fnId = fnArray[i];
  4719. if (fnId !== _util.OPS.dependency) {
  4720. this[fnId].apply(this, argsArray[i]);
  4721. } else {
  4722. for (const depObjId of argsArray[i]) {
  4723. const objsPool = depObjId.startsWith("g_") ? commonObjs : objs;
  4724. if (!objsPool.has(depObjId)) {
  4725. objsPool.get(depObjId, continueCallback);
  4726. return i;
  4727. }
  4728. }
  4729. }
  4730. i++;
  4731. if (i === argsArrayLen) {
  4732. return i;
  4733. }
  4734. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  4735. if (Date.now() > endTime) {
  4736. continueCallback();
  4737. return i;
  4738. }
  4739. steps = 0;
  4740. }
  4741. }
  4742. }
  4743. endDrawing() {
  4744. while (this.stateStack.length || this.current.activeSMask !== null) {
  4745. this.restore();
  4746. }
  4747. this.ctx.restore();
  4748. if (this.transparentCanvas) {
  4749. this.ctx = this.compositeCtx;
  4750. this.ctx.save();
  4751. this.ctx.setTransform(1, 0, 0, 1, 0, 0);
  4752. this.ctx.drawImage(this.transparentCanvas, 0, 0);
  4753. this.ctx.restore();
  4754. this.transparentCanvas = null;
  4755. }
  4756. this.cachedCanvases.clear();
  4757. this.cachedPatterns.clear();
  4758. if (this.imageLayer) {
  4759. this.imageLayer.endLayout();
  4760. }
  4761. }
  4762. _scaleImage(img, inverseTransform) {
  4763. const width = img.width;
  4764. const height = img.height;
  4765. let widthScale = Math.max(Math.hypot(inverseTransform[0], inverseTransform[1]), 1);
  4766. let heightScale = Math.max(Math.hypot(inverseTransform[2], inverseTransform[3]), 1);
  4767. let paintWidth = width,
  4768. paintHeight = height;
  4769. let tmpCanvasId = "prescale1";
  4770. let tmpCanvas, tmpCtx;
  4771. while (widthScale > 2 && paintWidth > 1 || heightScale > 2 && paintHeight > 1) {
  4772. let newWidth = paintWidth,
  4773. newHeight = paintHeight;
  4774. if (widthScale > 2 && paintWidth > 1) {
  4775. newWidth = Math.ceil(paintWidth / 2);
  4776. widthScale /= paintWidth / newWidth;
  4777. }
  4778. if (heightScale > 2 && paintHeight > 1) {
  4779. newHeight = Math.ceil(paintHeight / 2);
  4780. heightScale /= paintHeight / newHeight;
  4781. }
  4782. tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
  4783. tmpCtx = tmpCanvas.context;
  4784. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  4785. tmpCtx.drawImage(img, 0, 0, paintWidth, paintHeight, 0, 0, newWidth, newHeight);
  4786. img = tmpCanvas.canvas;
  4787. paintWidth = newWidth;
  4788. paintHeight = newHeight;
  4789. tmpCanvasId = tmpCanvasId === "prescale1" ? "prescale2" : "prescale1";
  4790. }
  4791. return {
  4792. img,
  4793. paintWidth,
  4794. paintHeight
  4795. };
  4796. }
  4797. _createMaskCanvas(img) {
  4798. const ctx = this.ctx;
  4799. const width = img.width,
  4800. height = img.height;
  4801. const fillColor = this.current.fillColor;
  4802. const isPatternFill = this.current.patternFill;
  4803. const maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
  4804. const maskCtx = maskCanvas.context;
  4805. putBinaryImageMask(maskCtx, img);
  4806. const objToCanvas = ctx.mozCurrentTransform;
  4807. let maskToCanvas = _util.Util.transform(objToCanvas, [1 / width, 0, 0, -1 / height, 0, 0]);
  4808. maskToCanvas = _util.Util.transform(maskToCanvas, [1, 0, 0, 1, 0, -height]);
  4809. const cord1 = _util.Util.applyTransform([0, 0], maskToCanvas);
  4810. const cord2 = _util.Util.applyTransform([width, height], maskToCanvas);
  4811. const rect = _util.Util.normalizeRect([cord1[0], cord1[1], cord2[0], cord2[1]]);
  4812. const drawnWidth = Math.ceil(rect[2] - rect[0]);
  4813. const drawnHeight = Math.ceil(rect[3] - rect[1]);
  4814. const fillCanvas = this.cachedCanvases.getCanvas("fillCanvas", drawnWidth, drawnHeight, true);
  4815. const fillCtx = fillCanvas.context;
  4816. const offsetX = Math.min(cord1[0], cord2[0]);
  4817. const offsetY = Math.min(cord1[1], cord2[1]);
  4818. fillCtx.translate(-offsetX, -offsetY);
  4819. fillCtx.transform.apply(fillCtx, maskToCanvas);
  4820. const scaled = this._scaleImage(maskCanvas.canvas, fillCtx.mozCurrentTransformInverse);
  4821. fillCtx.imageSmoothingEnabled = getImageSmoothingEnabled(fillCtx.mozCurrentTransform, img.interpolate);
  4822. fillCtx.drawImage(scaled.img, 0, 0, scaled.img.width, scaled.img.height, 0, 0, width, height);
  4823. fillCtx.globalCompositeOperation = "source-in";
  4824. const inverse = _util.Util.transform(fillCtx.mozCurrentTransformInverse, [1, 0, 0, 1, -offsetX, -offsetY]);
  4825. fillCtx.fillStyle = isPatternFill ? fillColor.getPattern(ctx, this, inverse, _pattern_helper.PathType.FILL) : fillColor;
  4826. fillCtx.fillRect(0, 0, width, height);
  4827. return {
  4828. canvas: fillCanvas.canvas,
  4829. offsetX: Math.round(offsetX),
  4830. offsetY: Math.round(offsetY)
  4831. };
  4832. }
  4833. setLineWidth(width) {
  4834. this.current.lineWidth = width;
  4835. this.ctx.lineWidth = width;
  4836. }
  4837. setLineCap(style) {
  4838. this.ctx.lineCap = LINE_CAP_STYLES[style];
  4839. }
  4840. setLineJoin(style) {
  4841. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  4842. }
  4843. setMiterLimit(limit) {
  4844. this.ctx.miterLimit = limit;
  4845. }
  4846. setDash(dashArray, dashPhase) {
  4847. const ctx = this.ctx;
  4848. if (ctx.setLineDash !== undefined) {
  4849. ctx.setLineDash(dashArray);
  4850. ctx.lineDashOffset = dashPhase;
  4851. }
  4852. }
  4853. setRenderingIntent(intent) {}
  4854. setFlatness(flatness) {}
  4855. setGState(states) {
  4856. for (let i = 0, ii = states.length; i < ii; i++) {
  4857. const state = states[i];
  4858. const key = state[0];
  4859. const value = state[1];
  4860. switch (key) {
  4861. case "LW":
  4862. this.setLineWidth(value);
  4863. break;
  4864. case "LC":
  4865. this.setLineCap(value);
  4866. break;
  4867. case "LJ":
  4868. this.setLineJoin(value);
  4869. break;
  4870. case "ML":
  4871. this.setMiterLimit(value);
  4872. break;
  4873. case "D":
  4874. this.setDash(value[0], value[1]);
  4875. break;
  4876. case "RI":
  4877. this.setRenderingIntent(value);
  4878. break;
  4879. case "FL":
  4880. this.setFlatness(value);
  4881. break;
  4882. case "Font":
  4883. this.setFont(value[0], value[1]);
  4884. break;
  4885. case "CA":
  4886. this.current.strokeAlpha = state[1];
  4887. break;
  4888. case "ca":
  4889. this.current.fillAlpha = state[1];
  4890. this.ctx.globalAlpha = state[1];
  4891. break;
  4892. case "BM":
  4893. this.ctx.globalCompositeOperation = value;
  4894. break;
  4895. case "SMask":
  4896. this.current.activeSMask = value ? this.tempSMask : null;
  4897. this.tempSMask = null;
  4898. this.checkSMaskState();
  4899. break;
  4900. case "TR":
  4901. this.current.transferMaps = value;
  4902. }
  4903. }
  4904. }
  4905. checkSMaskState() {
  4906. const inSMaskMode = !!this.suspendedCtx;
  4907. if (this.current.activeSMask && !inSMaskMode) {
  4908. this.beginSMaskMode();
  4909. } else if (!this.current.activeSMask && inSMaskMode) {
  4910. this.endSMaskMode();
  4911. }
  4912. }
  4913. beginSMaskMode() {
  4914. if (this.suspendedCtx) {
  4915. throw new Error("beginSMaskMode called while already in smask mode");
  4916. }
  4917. const drawnWidth = this.ctx.canvas.width;
  4918. const drawnHeight = this.ctx.canvas.height;
  4919. const cacheId = "smaskGroupAt" + this.groupLevel;
  4920. const scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true);
  4921. this.suspendedCtx = this.ctx;
  4922. this.ctx = scratchCanvas.context;
  4923. const ctx = this.ctx;
  4924. ctx.setTransform.apply(ctx, this.suspendedCtx.mozCurrentTransform);
  4925. copyCtxState(this.suspendedCtx, ctx);
  4926. mirrorContextOperations(ctx, this.suspendedCtx);
  4927. this.setGState([["BM", "source-over"], ["ca", 1], ["CA", 1]]);
  4928. }
  4929. endSMaskMode() {
  4930. if (!this.suspendedCtx) {
  4931. throw new Error("endSMaskMode called while not in smask mode");
  4932. }
  4933. this.ctx._removeMirroring();
  4934. copyCtxState(this.ctx, this.suspendedCtx);
  4935. this.ctx = this.suspendedCtx;
  4936. this.current.activeSMask = null;
  4937. this.suspendedCtx = null;
  4938. }
  4939. compose(dirtyBox) {
  4940. if (!this.current.activeSMask) {
  4941. return;
  4942. }
  4943. if (!dirtyBox) {
  4944. dirtyBox = [0, 0, this.ctx.canvas.width, this.ctx.canvas.height];
  4945. } else {
  4946. dirtyBox[0] = Math.floor(dirtyBox[0]);
  4947. dirtyBox[1] = Math.floor(dirtyBox[1]);
  4948. dirtyBox[2] = Math.ceil(dirtyBox[2]);
  4949. dirtyBox[3] = Math.ceil(dirtyBox[3]);
  4950. }
  4951. const smask = this.current.activeSMask;
  4952. const suspendedCtx = this.suspendedCtx;
  4953. composeSMask(suspendedCtx, smask, this.ctx, dirtyBox);
  4954. this.ctx.save();
  4955. this.ctx.setTransform(1, 0, 0, 1, 0, 0);
  4956. this.ctx.clearRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height);
  4957. this.ctx.restore();
  4958. }
  4959. save() {
  4960. this.ctx.save();
  4961. const old = this.current;
  4962. this.stateStack.push(old);
  4963. this.current = old.clone();
  4964. }
  4965. restore() {
  4966. if (this.stateStack.length === 0 && this.current.activeSMask) {
  4967. this.endSMaskMode();
  4968. }
  4969. if (this.stateStack.length !== 0) {
  4970. this.current = this.stateStack.pop();
  4971. this.ctx.restore();
  4972. this.checkSMaskState();
  4973. this.pendingClip = null;
  4974. this._cachedGetSinglePixelWidth = null;
  4975. }
  4976. }
  4977. transform(a, b, c, d, e, f) {
  4978. this.ctx.transform(a, b, c, d, e, f);
  4979. this._cachedGetSinglePixelWidth = null;
  4980. }
  4981. constructPath(ops, args) {
  4982. const ctx = this.ctx;
  4983. const current = this.current;
  4984. let x = current.x,
  4985. y = current.y;
  4986. let startX, startY;
  4987. for (let i = 0, j = 0, ii = ops.length; i < ii; i++) {
  4988. switch (ops[i] | 0) {
  4989. case _util.OPS.rectangle:
  4990. x = args[j++];
  4991. y = args[j++];
  4992. const width = args[j++];
  4993. const height = args[j++];
  4994. const xw = x + width;
  4995. const yh = y + height;
  4996. ctx.moveTo(x, y);
  4997. if (width === 0 || height === 0) {
  4998. ctx.lineTo(xw, yh);
  4999. } else {
  5000. ctx.lineTo(xw, y);
  5001. ctx.lineTo(xw, yh);
  5002. ctx.lineTo(x, yh);
  5003. }
  5004. current.updatePathMinMax(ctx.mozCurrentTransform, x, y);
  5005. current.updatePathMinMax(ctx.mozCurrentTransform, xw, yh);
  5006. ctx.closePath();
  5007. break;
  5008. case _util.OPS.moveTo:
  5009. x = args[j++];
  5010. y = args[j++];
  5011. ctx.moveTo(x, y);
  5012. current.updatePathMinMax(ctx.mozCurrentTransform, x, y);
  5013. break;
  5014. case _util.OPS.lineTo:
  5015. x = args[j++];
  5016. y = args[j++];
  5017. ctx.lineTo(x, y);
  5018. current.updatePathMinMax(ctx.mozCurrentTransform, x, y);
  5019. break;
  5020. case _util.OPS.curveTo:
  5021. startX = x;
  5022. startY = y;
  5023. x = args[j + 4];
  5024. y = args[j + 5];
  5025. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3], x, y);
  5026. current.updateCurvePathMinMax(ctx.mozCurrentTransform, startX, startY, args[j], args[j + 1], args[j + 2], args[j + 3], x, y);
  5027. j += 6;
  5028. break;
  5029. case _util.OPS.curveTo2:
  5030. startX = x;
  5031. startY = y;
  5032. ctx.bezierCurveTo(x, y, args[j], args[j + 1], args[j + 2], args[j + 3]);
  5033. current.updateCurvePathMinMax(ctx.mozCurrentTransform, startX, startY, x, y, args[j], args[j + 1], args[j + 2], args[j + 3]);
  5034. x = args[j + 2];
  5035. y = args[j + 3];
  5036. j += 4;
  5037. break;
  5038. case _util.OPS.curveTo3:
  5039. startX = x;
  5040. startY = y;
  5041. x = args[j + 2];
  5042. y = args[j + 3];
  5043. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  5044. current.updateCurvePathMinMax(ctx.mozCurrentTransform, startX, startY, args[j], args[j + 1], x, y, x, y);
  5045. j += 4;
  5046. break;
  5047. case _util.OPS.closePath:
  5048. ctx.closePath();
  5049. break;
  5050. }
  5051. }
  5052. current.setCurrentPoint(x, y);
  5053. }
  5054. closePath() {
  5055. this.ctx.closePath();
  5056. }
  5057. stroke(consumePath) {
  5058. consumePath = typeof consumePath !== "undefined" ? consumePath : true;
  5059. const ctx = this.ctx;
  5060. const strokeColor = this.current.strokeColor;
  5061. ctx.globalAlpha = this.current.strokeAlpha;
  5062. if (this.contentVisible) {
  5063. if (typeof strokeColor === "object" && strokeColor?.getPattern) {
  5064. const lineWidth = this.getSinglePixelWidth();
  5065. ctx.save();
  5066. ctx.strokeStyle = strokeColor.getPattern(ctx, this, ctx.mozCurrentTransformInverse, _pattern_helper.PathType.STROKE);
  5067. ctx.lineWidth = Math.max(lineWidth, this.current.lineWidth);
  5068. ctx.stroke();
  5069. ctx.restore();
  5070. } else {
  5071. const lineWidth = this.getSinglePixelWidth();
  5072. if (lineWidth < 0 && -lineWidth >= this.current.lineWidth) {
  5073. ctx.save();
  5074. ctx.resetTransform();
  5075. ctx.lineWidth = Math.round(this._combinedScaleFactor);
  5076. ctx.stroke();
  5077. ctx.restore();
  5078. } else {
  5079. ctx.lineWidth = Math.max(lineWidth, this.current.lineWidth);
  5080. ctx.stroke();
  5081. }
  5082. }
  5083. }
  5084. if (consumePath) {
  5085. this.consumePath(this.current.getClippedPathBoundingBox());
  5086. }
  5087. ctx.globalAlpha = this.current.fillAlpha;
  5088. }
  5089. closeStroke() {
  5090. this.closePath();
  5091. this.stroke();
  5092. }
  5093. fill(consumePath) {
  5094. consumePath = typeof consumePath !== "undefined" ? consumePath : true;
  5095. const ctx = this.ctx;
  5096. const fillColor = this.current.fillColor;
  5097. const isPatternFill = this.current.patternFill;
  5098. let needRestore = false;
  5099. if (isPatternFill) {
  5100. ctx.save();
  5101. ctx.fillStyle = fillColor.getPattern(ctx, this, ctx.mozCurrentTransformInverse, _pattern_helper.PathType.FILL);
  5102. needRestore = true;
  5103. }
  5104. const intersect = this.current.getClippedPathBoundingBox();
  5105. if (this.contentVisible && intersect !== null) {
  5106. if (this.pendingEOFill) {
  5107. ctx.fill("evenodd");
  5108. this.pendingEOFill = false;
  5109. } else {
  5110. ctx.fill();
  5111. }
  5112. }
  5113. if (needRestore) {
  5114. ctx.restore();
  5115. }
  5116. if (consumePath) {
  5117. this.consumePath(intersect);
  5118. }
  5119. }
  5120. eoFill() {
  5121. this.pendingEOFill = true;
  5122. this.fill();
  5123. }
  5124. fillStroke() {
  5125. this.fill(false);
  5126. this.stroke(false);
  5127. this.consumePath();
  5128. }
  5129. eoFillStroke() {
  5130. this.pendingEOFill = true;
  5131. this.fillStroke();
  5132. }
  5133. closeFillStroke() {
  5134. this.closePath();
  5135. this.fillStroke();
  5136. }
  5137. closeEOFillStroke() {
  5138. this.pendingEOFill = true;
  5139. this.closePath();
  5140. this.fillStroke();
  5141. }
  5142. endPath() {
  5143. this.consumePath();
  5144. }
  5145. clip() {
  5146. this.pendingClip = NORMAL_CLIP;
  5147. }
  5148. eoClip() {
  5149. this.pendingClip = EO_CLIP;
  5150. }
  5151. beginText() {
  5152. this.current.textMatrix = _util.IDENTITY_MATRIX;
  5153. this.current.textMatrixScale = 1;
  5154. this.current.x = this.current.lineX = 0;
  5155. this.current.y = this.current.lineY = 0;
  5156. }
  5157. endText() {
  5158. const paths = this.pendingTextPaths;
  5159. const ctx = this.ctx;
  5160. if (paths === undefined) {
  5161. ctx.beginPath();
  5162. return;
  5163. }
  5164. ctx.save();
  5165. ctx.beginPath();
  5166. for (let i = 0; i < paths.length; i++) {
  5167. const path = paths[i];
  5168. ctx.setTransform.apply(ctx, path.transform);
  5169. ctx.translate(path.x, path.y);
  5170. path.addToPath(ctx, path.fontSize);
  5171. }
  5172. ctx.restore();
  5173. ctx.clip();
  5174. ctx.beginPath();
  5175. delete this.pendingTextPaths;
  5176. }
  5177. setCharSpacing(spacing) {
  5178. this.current.charSpacing = spacing;
  5179. }
  5180. setWordSpacing(spacing) {
  5181. this.current.wordSpacing = spacing;
  5182. }
  5183. setHScale(scale) {
  5184. this.current.textHScale = scale / 100;
  5185. }
  5186. setLeading(leading) {
  5187. this.current.leading = -leading;
  5188. }
  5189. setFont(fontRefName, size) {
  5190. const fontObj = this.commonObjs.get(fontRefName);
  5191. const current = this.current;
  5192. if (!fontObj) {
  5193. throw new Error(`Can't find font for ${fontRefName}`);
  5194. }
  5195. current.fontMatrix = fontObj.fontMatrix || _util.FONT_IDENTITY_MATRIX;
  5196. if (current.fontMatrix[0] === 0 || current.fontMatrix[3] === 0) {
  5197. (0, _util.warn)("Invalid font matrix for font " + fontRefName);
  5198. }
  5199. if (size < 0) {
  5200. size = -size;
  5201. current.fontDirection = -1;
  5202. } else {
  5203. current.fontDirection = 1;
  5204. }
  5205. this.current.font = fontObj;
  5206. this.current.fontSize = size;
  5207. if (fontObj.isType3Font) {
  5208. return;
  5209. }
  5210. const name = fontObj.loadedName || "sans-serif";
  5211. let bold = "normal";
  5212. if (fontObj.black) {
  5213. bold = "900";
  5214. } else if (fontObj.bold) {
  5215. bold = "bold";
  5216. }
  5217. const italic = fontObj.italic ? "italic" : "normal";
  5218. const typeface = `"${name}", ${fontObj.fallbackName}`;
  5219. let browserFontSize = size;
  5220. if (size < MIN_FONT_SIZE) {
  5221. browserFontSize = MIN_FONT_SIZE;
  5222. } else if (size > MAX_FONT_SIZE) {
  5223. browserFontSize = MAX_FONT_SIZE;
  5224. }
  5225. this.current.fontSizeScale = size / browserFontSize;
  5226. this.ctx.font = `${italic} ${bold} ${browserFontSize}px ${typeface}`;
  5227. }
  5228. setTextRenderingMode(mode) {
  5229. this.current.textRenderingMode = mode;
  5230. }
  5231. setTextRise(rise) {
  5232. this.current.textRise = rise;
  5233. }
  5234. moveText(x, y) {
  5235. this.current.x = this.current.lineX += x;
  5236. this.current.y = this.current.lineY += y;
  5237. }
  5238. setLeadingMoveText(x, y) {
  5239. this.setLeading(-y);
  5240. this.moveText(x, y);
  5241. }
  5242. setTextMatrix(a, b, c, d, e, f) {
  5243. this.current.textMatrix = [a, b, c, d, e, f];
  5244. this.current.textMatrixScale = Math.hypot(a, b);
  5245. this.current.x = this.current.lineX = 0;
  5246. this.current.y = this.current.lineY = 0;
  5247. }
  5248. nextLine() {
  5249. this.moveText(0, this.current.leading);
  5250. }
  5251. paintChar(character, x, y, patternTransform, resetLineWidthToOne) {
  5252. const ctx = this.ctx;
  5253. const current = this.current;
  5254. const font = current.font;
  5255. const textRenderingMode = current.textRenderingMode;
  5256. const fontSize = current.fontSize / current.fontSizeScale;
  5257. const fillStrokeMode = textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  5258. const isAddToPathSet = !!(textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG);
  5259. const patternFill = current.patternFill && !font.missingFile;
  5260. let addToPath;
  5261. if (font.disableFontFace || isAddToPathSet || patternFill) {
  5262. addToPath = font.getPathGenerator(this.commonObjs, character);
  5263. }
  5264. if (font.disableFontFace || patternFill) {
  5265. ctx.save();
  5266. ctx.translate(x, y);
  5267. ctx.beginPath();
  5268. addToPath(ctx, fontSize);
  5269. if (patternTransform) {
  5270. ctx.setTransform.apply(ctx, patternTransform);
  5271. }
  5272. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  5273. ctx.fill();
  5274. }
  5275. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  5276. if (resetLineWidthToOne) {
  5277. ctx.resetTransform();
  5278. ctx.lineWidth = Math.round(this._combinedScaleFactor);
  5279. }
  5280. ctx.stroke();
  5281. }
  5282. ctx.restore();
  5283. } else {
  5284. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  5285. ctx.fillText(character, x, y);
  5286. }
  5287. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  5288. if (resetLineWidthToOne) {
  5289. ctx.save();
  5290. ctx.moveTo(x, y);
  5291. ctx.resetTransform();
  5292. ctx.lineWidth = Math.round(this._combinedScaleFactor);
  5293. ctx.strokeText(character, 0, 0);
  5294. ctx.restore();
  5295. } else {
  5296. ctx.strokeText(character, x, y);
  5297. }
  5298. }
  5299. }
  5300. if (isAddToPathSet) {
  5301. const paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  5302. paths.push({
  5303. transform: ctx.mozCurrentTransform,
  5304. x,
  5305. y,
  5306. fontSize,
  5307. addToPath
  5308. });
  5309. }
  5310. }
  5311. get isFontSubpixelAAEnabled() {
  5312. const {
  5313. context: ctx
  5314. } = this.cachedCanvases.getCanvas("isFontSubpixelAAEnabled", 10, 10);
  5315. ctx.scale(1.5, 1);
  5316. ctx.fillText("I", 0, 10);
  5317. const data = ctx.getImageData(0, 0, 10, 10).data;
  5318. let enabled = false;
  5319. for (let i = 3; i < data.length; i += 4) {
  5320. if (data[i] > 0 && data[i] < 255) {
  5321. enabled = true;
  5322. break;
  5323. }
  5324. }
  5325. return (0, _util.shadow)(this, "isFontSubpixelAAEnabled", enabled);
  5326. }
  5327. showText(glyphs) {
  5328. const current = this.current;
  5329. const font = current.font;
  5330. if (font.isType3Font) {
  5331. return this.showType3Text(glyphs);
  5332. }
  5333. const fontSize = current.fontSize;
  5334. if (fontSize === 0) {
  5335. return undefined;
  5336. }
  5337. const ctx = this.ctx;
  5338. const fontSizeScale = current.fontSizeScale;
  5339. const charSpacing = current.charSpacing;
  5340. const wordSpacing = current.wordSpacing;
  5341. const fontDirection = current.fontDirection;
  5342. const textHScale = current.textHScale * fontDirection;
  5343. const glyphsLength = glyphs.length;
  5344. const vertical = font.vertical;
  5345. const spacingDir = vertical ? 1 : -1;
  5346. const defaultVMetrics = font.defaultVMetrics;
  5347. const widthAdvanceScale = fontSize * current.fontMatrix[0];
  5348. const simpleFillText = current.textRenderingMode === _util.TextRenderingMode.FILL && !font.disableFontFace && !current.patternFill;
  5349. ctx.save();
  5350. ctx.transform.apply(ctx, current.textMatrix);
  5351. ctx.translate(current.x, current.y + current.textRise);
  5352. if (fontDirection > 0) {
  5353. ctx.scale(textHScale, -1);
  5354. } else {
  5355. ctx.scale(textHScale, 1);
  5356. }
  5357. let patternTransform;
  5358. if (current.patternFill) {
  5359. ctx.save();
  5360. const pattern = current.fillColor.getPattern(ctx, this, ctx.mozCurrentTransformInverse, _pattern_helper.PathType.FILL);
  5361. patternTransform = ctx.mozCurrentTransform;
  5362. ctx.restore();
  5363. ctx.fillStyle = pattern;
  5364. }
  5365. let lineWidth = current.lineWidth;
  5366. let resetLineWidthToOne = false;
  5367. const scale = current.textMatrixScale;
  5368. if (scale === 0 || lineWidth === 0) {
  5369. const fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  5370. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  5371. this._cachedGetSinglePixelWidth = null;
  5372. lineWidth = this.getSinglePixelWidth();
  5373. resetLineWidthToOne = lineWidth < 0;
  5374. }
  5375. } else {
  5376. lineWidth /= scale;
  5377. }
  5378. if (fontSizeScale !== 1.0) {
  5379. ctx.scale(fontSizeScale, fontSizeScale);
  5380. lineWidth /= fontSizeScale;
  5381. }
  5382. ctx.lineWidth = lineWidth;
  5383. let x = 0,
  5384. i;
  5385. for (i = 0; i < glyphsLength; ++i) {
  5386. const glyph = glyphs[i];
  5387. if ((0, _util.isNum)(glyph)) {
  5388. x += spacingDir * glyph * fontSize / 1000;
  5389. continue;
  5390. }
  5391. let restoreNeeded = false;
  5392. const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  5393. const character = glyph.fontChar;
  5394. const accent = glyph.accent;
  5395. let scaledX, scaledY;
  5396. let width = glyph.width;
  5397. if (vertical) {
  5398. const vmetric = glyph.vmetric || defaultVMetrics;
  5399. const vx = -(glyph.vmetric ? vmetric[1] : width * 0.5) * widthAdvanceScale;
  5400. const vy = vmetric[2] * widthAdvanceScale;
  5401. width = vmetric ? -vmetric[0] : width;
  5402. scaledX = vx / fontSizeScale;
  5403. scaledY = (x + vy) / fontSizeScale;
  5404. } else {
  5405. scaledX = x / fontSizeScale;
  5406. scaledY = 0;
  5407. }
  5408. if (font.remeasure && width > 0) {
  5409. const measuredWidth = ctx.measureText(character).width * 1000 / fontSize * fontSizeScale;
  5410. if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
  5411. const characterScaleX = width / measuredWidth;
  5412. restoreNeeded = true;
  5413. ctx.save();
  5414. ctx.scale(characterScaleX, 1);
  5415. scaledX /= characterScaleX;
  5416. } else if (width !== measuredWidth) {
  5417. scaledX += (width - measuredWidth) / 2000 * fontSize / fontSizeScale;
  5418. }
  5419. }
  5420. if (this.contentVisible && (glyph.isInFont || font.missingFile)) {
  5421. if (simpleFillText && !accent) {
  5422. ctx.fillText(character, scaledX, scaledY);
  5423. } else {
  5424. this.paintChar(character, scaledX, scaledY, patternTransform, resetLineWidthToOne);
  5425. if (accent) {
  5426. const scaledAccentX = scaledX + fontSize * accent.offset.x / fontSizeScale;
  5427. const scaledAccentY = scaledY - fontSize * accent.offset.y / fontSizeScale;
  5428. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY, patternTransform, resetLineWidthToOne);
  5429. }
  5430. }
  5431. }
  5432. let charWidth;
  5433. if (vertical) {
  5434. charWidth = width * widthAdvanceScale - spacing * fontDirection;
  5435. } else {
  5436. charWidth = width * widthAdvanceScale + spacing * fontDirection;
  5437. }
  5438. x += charWidth;
  5439. if (restoreNeeded) {
  5440. ctx.restore();
  5441. }
  5442. }
  5443. if (vertical) {
  5444. current.y -= x;
  5445. } else {
  5446. current.x += x * textHScale;
  5447. }
  5448. ctx.restore();
  5449. this.compose();
  5450. return undefined;
  5451. }
  5452. showType3Text(glyphs) {
  5453. const ctx = this.ctx;
  5454. const current = this.current;
  5455. const font = current.font;
  5456. const fontSize = current.fontSize;
  5457. const fontDirection = current.fontDirection;
  5458. const spacingDir = font.vertical ? 1 : -1;
  5459. const charSpacing = current.charSpacing;
  5460. const wordSpacing = current.wordSpacing;
  5461. const textHScale = current.textHScale * fontDirection;
  5462. const fontMatrix = current.fontMatrix || _util.FONT_IDENTITY_MATRIX;
  5463. const glyphsLength = glyphs.length;
  5464. const isTextInvisible = current.textRenderingMode === _util.TextRenderingMode.INVISIBLE;
  5465. let i, glyph, width, spacingLength;
  5466. if (isTextInvisible || fontSize === 0) {
  5467. return;
  5468. }
  5469. this._cachedGetSinglePixelWidth = null;
  5470. ctx.save();
  5471. ctx.transform.apply(ctx, current.textMatrix);
  5472. ctx.translate(current.x, current.y);
  5473. ctx.scale(textHScale, fontDirection);
  5474. for (i = 0; i < glyphsLength; ++i) {
  5475. glyph = glyphs[i];
  5476. if ((0, _util.isNum)(glyph)) {
  5477. spacingLength = spacingDir * glyph * fontSize / 1000;
  5478. this.ctx.translate(spacingLength, 0);
  5479. current.x += spacingLength * textHScale;
  5480. continue;
  5481. }
  5482. const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  5483. const operatorList = font.charProcOperatorList[glyph.operatorListId];
  5484. if (!operatorList) {
  5485. (0, _util.warn)(`Type3 character "${glyph.operatorListId}" is not available.`);
  5486. continue;
  5487. }
  5488. if (this.contentVisible) {
  5489. this.processingType3 = glyph;
  5490. this.save();
  5491. ctx.scale(fontSize, fontSize);
  5492. ctx.transform.apply(ctx, fontMatrix);
  5493. this.executeOperatorList(operatorList);
  5494. this.restore();
  5495. }
  5496. const transformed = _util.Util.applyTransform([glyph.width, 0], fontMatrix);
  5497. width = transformed[0] * fontSize + spacing;
  5498. ctx.translate(width, 0);
  5499. current.x += width * textHScale;
  5500. }
  5501. ctx.restore();
  5502. this.processingType3 = null;
  5503. }
  5504. setCharWidth(xWidth, yWidth) {}
  5505. setCharWidthAndBounds(xWidth, yWidth, llx, lly, urx, ury) {
  5506. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  5507. this.clip();
  5508. this.endPath();
  5509. }
  5510. getColorN_Pattern(IR) {
  5511. let pattern;
  5512. if (IR[0] === "TilingPattern") {
  5513. const color = IR[1];
  5514. const baseTransform = this.baseTransform || this.ctx.mozCurrentTransform.slice();
  5515. const canvasGraphicsFactory = {
  5516. createCanvasGraphics: ctx => {
  5517. return new CanvasGraphics(ctx, this.commonObjs, this.objs, this.canvasFactory);
  5518. }
  5519. };
  5520. pattern = new _pattern_helper.TilingPattern(IR, color, this.ctx, canvasGraphicsFactory, baseTransform);
  5521. } else {
  5522. pattern = this._getPattern(IR[1], IR[2]);
  5523. }
  5524. return pattern;
  5525. }
  5526. setStrokeColorN() {
  5527. this.current.strokeColor = this.getColorN_Pattern(arguments);
  5528. }
  5529. setFillColorN() {
  5530. this.current.fillColor = this.getColorN_Pattern(arguments);
  5531. this.current.patternFill = true;
  5532. }
  5533. setStrokeRGBColor(r, g, b) {
  5534. const color = _util.Util.makeHexColor(r, g, b);
  5535. this.ctx.strokeStyle = color;
  5536. this.current.strokeColor = color;
  5537. }
  5538. setFillRGBColor(r, g, b) {
  5539. const color = _util.Util.makeHexColor(r, g, b);
  5540. this.ctx.fillStyle = color;
  5541. this.current.fillColor = color;
  5542. this.current.patternFill = false;
  5543. }
  5544. _getPattern(objId, matrix = null) {
  5545. let pattern;
  5546. if (this.cachedPatterns.has(objId)) {
  5547. pattern = this.cachedPatterns.get(objId);
  5548. } else {
  5549. pattern = (0, _pattern_helper.getShadingPattern)(this.objs.get(objId));
  5550. this.cachedPatterns.set(objId, pattern);
  5551. }
  5552. if (matrix) {
  5553. pattern.matrix = matrix;
  5554. }
  5555. return pattern;
  5556. }
  5557. shadingFill(objId) {
  5558. if (!this.contentVisible) {
  5559. return;
  5560. }
  5561. const ctx = this.ctx;
  5562. this.save();
  5563. const pattern = this._getPattern(objId);
  5564. ctx.fillStyle = pattern.getPattern(ctx, this, ctx.mozCurrentTransformInverse, _pattern_helper.PathType.SHADING);
  5565. const inv = ctx.mozCurrentTransformInverse;
  5566. if (inv) {
  5567. const canvas = ctx.canvas;
  5568. const width = canvas.width;
  5569. const height = canvas.height;
  5570. const bl = _util.Util.applyTransform([0, 0], inv);
  5571. const br = _util.Util.applyTransform([0, height], inv);
  5572. const ul = _util.Util.applyTransform([width, 0], inv);
  5573. const ur = _util.Util.applyTransform([width, height], inv);
  5574. const x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  5575. const y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  5576. const x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  5577. const y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  5578. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  5579. } else {
  5580. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  5581. }
  5582. this.compose(this.current.getClippedPathBoundingBox());
  5583. this.restore();
  5584. }
  5585. beginInlineImage() {
  5586. (0, _util.unreachable)("Should not call beginInlineImage");
  5587. }
  5588. beginImageData() {
  5589. (0, _util.unreachable)("Should not call beginImageData");
  5590. }
  5591. paintFormXObjectBegin(matrix, bbox) {
  5592. if (!this.contentVisible) {
  5593. return;
  5594. }
  5595. this.save();
  5596. this.baseTransformStack.push(this.baseTransform);
  5597. if (Array.isArray(matrix) && matrix.length === 6) {
  5598. this.transform.apply(this, matrix);
  5599. }
  5600. this.baseTransform = this.ctx.mozCurrentTransform;
  5601. if (bbox) {
  5602. const width = bbox[2] - bbox[0];
  5603. const height = bbox[3] - bbox[1];
  5604. this.ctx.rect(bbox[0], bbox[1], width, height);
  5605. this.current.updatePathMinMax(this.ctx.mozCurrentTransform, bbox[0], bbox[1]);
  5606. this.current.updatePathMinMax(this.ctx.mozCurrentTransform, bbox[2], bbox[3]);
  5607. this.clip();
  5608. this.endPath();
  5609. }
  5610. }
  5611. paintFormXObjectEnd() {
  5612. if (!this.contentVisible) {
  5613. return;
  5614. }
  5615. this.restore();
  5616. this.baseTransform = this.baseTransformStack.pop();
  5617. }
  5618. beginGroup(group) {
  5619. if (!this.contentVisible) {
  5620. return;
  5621. }
  5622. this.save();
  5623. const suspendedCtx = this.suspendedCtx;
  5624. if (this.current.activeSMask) {
  5625. this.suspendedCtx = null;
  5626. this.current.activeSMask = null;
  5627. }
  5628. const currentCtx = this.ctx;
  5629. if (!group.isolated) {
  5630. (0, _util.info)("TODO: Support non-isolated groups.");
  5631. }
  5632. if (group.knockout) {
  5633. (0, _util.warn)("Knockout groups not supported.");
  5634. }
  5635. const currentTransform = currentCtx.mozCurrentTransform;
  5636. if (group.matrix) {
  5637. currentCtx.transform.apply(currentCtx, group.matrix);
  5638. }
  5639. if (!group.bbox) {
  5640. throw new Error("Bounding box is required.");
  5641. }
  5642. let bounds = _util.Util.getAxialAlignedBoundingBox(group.bbox, currentCtx.mozCurrentTransform);
  5643. const canvasBounds = [0, 0, currentCtx.canvas.width, currentCtx.canvas.height];
  5644. bounds = _util.Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  5645. const offsetX = Math.floor(bounds[0]);
  5646. const offsetY = Math.floor(bounds[1]);
  5647. let drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  5648. let drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  5649. let scaleX = 1,
  5650. scaleY = 1;
  5651. if (drawnWidth > MAX_GROUP_SIZE) {
  5652. scaleX = drawnWidth / MAX_GROUP_SIZE;
  5653. drawnWidth = MAX_GROUP_SIZE;
  5654. }
  5655. if (drawnHeight > MAX_GROUP_SIZE) {
  5656. scaleY = drawnHeight / MAX_GROUP_SIZE;
  5657. drawnHeight = MAX_GROUP_SIZE;
  5658. }
  5659. this.current.startNewPathAndClipBox([0, 0, drawnWidth, drawnHeight]);
  5660. let cacheId = "groupAt" + this.groupLevel;
  5661. if (group.smask) {
  5662. cacheId += "_smask_" + this.smaskCounter++ % 2;
  5663. }
  5664. const scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true);
  5665. const groupCtx = scratchCanvas.context;
  5666. groupCtx.scale(1 / scaleX, 1 / scaleY);
  5667. groupCtx.translate(-offsetX, -offsetY);
  5668. groupCtx.transform.apply(groupCtx, currentTransform);
  5669. if (group.smask) {
  5670. this.smaskStack.push({
  5671. canvas: scratchCanvas.canvas,
  5672. context: groupCtx,
  5673. offsetX,
  5674. offsetY,
  5675. scaleX,
  5676. scaleY,
  5677. subtype: group.smask.subtype,
  5678. backdrop: group.smask.backdrop,
  5679. transferMap: group.smask.transferMap || null,
  5680. startTransformInverse: null
  5681. });
  5682. } else {
  5683. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  5684. currentCtx.translate(offsetX, offsetY);
  5685. currentCtx.scale(scaleX, scaleY);
  5686. currentCtx.save();
  5687. }
  5688. copyCtxState(currentCtx, groupCtx);
  5689. this.ctx = groupCtx;
  5690. this.setGState([["BM", "source-over"], ["ca", 1], ["CA", 1]]);
  5691. this.groupStack.push({
  5692. ctx: currentCtx,
  5693. suspendedCtx
  5694. });
  5695. this.groupLevel++;
  5696. }
  5697. endGroup(group) {
  5698. if (!this.contentVisible) {
  5699. return;
  5700. }
  5701. this.groupLevel--;
  5702. const groupCtx = this.ctx;
  5703. const {
  5704. ctx,
  5705. suspendedCtx
  5706. } = this.groupStack.pop();
  5707. this.ctx = ctx;
  5708. this.ctx.imageSmoothingEnabled = false;
  5709. if (suspendedCtx) {
  5710. this.suspendedCtx = suspendedCtx;
  5711. }
  5712. if (group.smask) {
  5713. this.tempSMask = this.smaskStack.pop();
  5714. this.restore();
  5715. } else {
  5716. this.ctx.restore();
  5717. const currentMtx = this.ctx.mozCurrentTransform;
  5718. this.restore();
  5719. this.ctx.save();
  5720. this.ctx.setTransform.apply(this.ctx, currentMtx);
  5721. const dirtyBox = _util.Util.getAxialAlignedBoundingBox([0, 0, groupCtx.canvas.width, groupCtx.canvas.height], currentMtx);
  5722. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  5723. this.ctx.restore();
  5724. this.compose(dirtyBox);
  5725. }
  5726. }
  5727. beginAnnotations() {
  5728. this.save();
  5729. if (this.baseTransform) {
  5730. this.ctx.setTransform.apply(this.ctx, this.baseTransform);
  5731. }
  5732. }
  5733. endAnnotations() {
  5734. this.restore();
  5735. }
  5736. beginAnnotation(id, rect, transform, matrix, hasOwnCanvas) {
  5737. this.save();
  5738. if (Array.isArray(rect) && rect.length === 4) {
  5739. const width = rect[2] - rect[0];
  5740. const height = rect[3] - rect[1];
  5741. if (hasOwnCanvas && this.annotationCanvasMap) {
  5742. transform = transform.slice();
  5743. transform[4] -= rect[0];
  5744. transform[5] -= rect[1];
  5745. rect = rect.slice();
  5746. rect[0] = rect[1] = 0;
  5747. rect[2] = width;
  5748. rect[3] = height;
  5749. const [scaleX, scaleY] = _util.Util.singularValueDecompose2dScale(this.ctx.mozCurrentTransform);
  5750. const {
  5751. viewportScale
  5752. } = this;
  5753. const canvasWidth = Math.ceil(width * this.outputScaleX * viewportScale);
  5754. const canvasHeight = Math.ceil(height * this.outputScaleY * viewportScale);
  5755. this.annotationCanvas = this.canvasFactory.create(canvasWidth, canvasHeight);
  5756. const {
  5757. canvas,
  5758. context
  5759. } = this.annotationCanvas;
  5760. canvas.style.width = `calc(${width}px * var(--viewport-scale-factor))`;
  5761. canvas.style.height = `calc(${height}px * var(--viewport-scale-factor))`;
  5762. this.annotationCanvasMap.set(id, canvas);
  5763. this.annotationCanvas.savedCtx = this.ctx;
  5764. this.ctx = context;
  5765. this.ctx.setTransform(scaleX, 0, 0, -scaleY, 0, height * scaleY);
  5766. addContextCurrentTransform(this.ctx);
  5767. resetCtxToDefault(this.ctx);
  5768. } else {
  5769. resetCtxToDefault(this.ctx);
  5770. this.ctx.rect(rect[0], rect[1], width, height);
  5771. this.clip();
  5772. this.endPath();
  5773. }
  5774. }
  5775. this.current = new CanvasExtraState(this.ctx.canvas.width, this.ctx.canvas.height);
  5776. this.transform.apply(this, transform);
  5777. this.transform.apply(this, matrix);
  5778. }
  5779. endAnnotation() {
  5780. if (this.annotationCanvas) {
  5781. this.ctx = this.annotationCanvas.savedCtx;
  5782. delete this.annotationCanvas.savedCtx;
  5783. delete this.annotationCanvas;
  5784. }
  5785. this.restore();
  5786. }
  5787. paintImageMaskXObject(img) {
  5788. if (!this.contentVisible) {
  5789. return;
  5790. }
  5791. const ctx = this.ctx;
  5792. const width = img.width,
  5793. height = img.height;
  5794. const glyph = this.processingType3;
  5795. if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
  5796. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  5797. glyph.compiled = compileType3Glyph({
  5798. data: img.data,
  5799. width,
  5800. height
  5801. });
  5802. } else {
  5803. glyph.compiled = null;
  5804. }
  5805. }
  5806. if (glyph?.compiled) {
  5807. glyph.compiled(ctx);
  5808. return;
  5809. }
  5810. const mask = this._createMaskCanvas(img);
  5811. const maskCanvas = mask.canvas;
  5812. ctx.save();
  5813. ctx.setTransform(1, 0, 0, 1, 0, 0);
  5814. ctx.drawImage(maskCanvas, mask.offsetX, mask.offsetY);
  5815. ctx.restore();
  5816. this.compose();
  5817. }
  5818. paintImageMaskXObjectRepeat(imgData, scaleX, skewX = 0, skewY = 0, scaleY, positions) {
  5819. if (!this.contentVisible) {
  5820. return;
  5821. }
  5822. const ctx = this.ctx;
  5823. ctx.save();
  5824. const currentTransform = ctx.mozCurrentTransform;
  5825. ctx.transform(scaleX, skewX, skewY, scaleY, 0, 0);
  5826. const mask = this._createMaskCanvas(imgData);
  5827. ctx.setTransform(1, 0, 0, 1, 0, 0);
  5828. for (let i = 0, ii = positions.length; i < ii; i += 2) {
  5829. const trans = _util.Util.transform(currentTransform, [scaleX, skewX, skewY, scaleY, positions[i], positions[i + 1]]);
  5830. const [x, y] = _util.Util.applyTransform([0, 0], trans);
  5831. ctx.drawImage(mask.canvas, x, y);
  5832. }
  5833. ctx.restore();
  5834. this.compose();
  5835. }
  5836. paintImageMaskXObjectGroup(images) {
  5837. if (!this.contentVisible) {
  5838. return;
  5839. }
  5840. const ctx = this.ctx;
  5841. const fillColor = this.current.fillColor;
  5842. const isPatternFill = this.current.patternFill;
  5843. for (let i = 0, ii = images.length; i < ii; i++) {
  5844. const image = images[i];
  5845. const width = image.width,
  5846. height = image.height;
  5847. const maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
  5848. const maskCtx = maskCanvas.context;
  5849. maskCtx.save();
  5850. putBinaryImageMask(maskCtx, image);
  5851. maskCtx.globalCompositeOperation = "source-in";
  5852. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this, ctx.mozCurrentTransformInverse, _pattern_helper.PathType.FILL) : fillColor;
  5853. maskCtx.fillRect(0, 0, width, height);
  5854. maskCtx.restore();
  5855. ctx.save();
  5856. ctx.transform.apply(ctx, image.transform);
  5857. ctx.scale(1, -1);
  5858. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1);
  5859. ctx.restore();
  5860. }
  5861. this.compose();
  5862. }
  5863. paintImageXObject(objId) {
  5864. if (!this.contentVisible) {
  5865. return;
  5866. }
  5867. const imgData = objId.startsWith("g_") ? this.commonObjs.get(objId) : this.objs.get(objId);
  5868. if (!imgData) {
  5869. (0, _util.warn)("Dependent image isn't ready yet");
  5870. return;
  5871. }
  5872. this.paintInlineImageXObject(imgData);
  5873. }
  5874. paintImageXObjectRepeat(objId, scaleX, scaleY, positions) {
  5875. if (!this.contentVisible) {
  5876. return;
  5877. }
  5878. const imgData = objId.startsWith("g_") ? this.commonObjs.get(objId) : this.objs.get(objId);
  5879. if (!imgData) {
  5880. (0, _util.warn)("Dependent image isn't ready yet");
  5881. return;
  5882. }
  5883. const width = imgData.width;
  5884. const height = imgData.height;
  5885. const map = [];
  5886. for (let i = 0, ii = positions.length; i < ii; i += 2) {
  5887. map.push({
  5888. transform: [scaleX, 0, 0, scaleY, positions[i], positions[i + 1]],
  5889. x: 0,
  5890. y: 0,
  5891. w: width,
  5892. h: height
  5893. });
  5894. }
  5895. this.paintInlineImageXObjectGroup(imgData, map);
  5896. }
  5897. paintInlineImageXObject(imgData) {
  5898. if (!this.contentVisible) {
  5899. return;
  5900. }
  5901. const width = imgData.width;
  5902. const height = imgData.height;
  5903. const ctx = this.ctx;
  5904. this.save();
  5905. ctx.scale(1 / width, -1 / height);
  5906. let imgToPaint;
  5907. if (typeof HTMLElement === "function" && imgData instanceof HTMLElement || !imgData.data) {
  5908. imgToPaint = imgData;
  5909. } else {
  5910. const tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", width, height);
  5911. const tmpCtx = tmpCanvas.context;
  5912. putBinaryImageData(tmpCtx, imgData, this.current.transferMaps);
  5913. imgToPaint = tmpCanvas.canvas;
  5914. }
  5915. const scaled = this._scaleImage(imgToPaint, ctx.mozCurrentTransformInverse);
  5916. ctx.imageSmoothingEnabled = getImageSmoothingEnabled(ctx.mozCurrentTransform, imgData.interpolate);
  5917. ctx.drawImage(scaled.img, 0, 0, scaled.paintWidth, scaled.paintHeight, 0, -height, width, height);
  5918. if (this.imageLayer) {
  5919. const position = this.getCanvasPosition(0, -height);
  5920. this.imageLayer.appendImage({
  5921. imgData,
  5922. left: position[0],
  5923. top: position[1],
  5924. width: width / ctx.mozCurrentTransformInverse[0],
  5925. height: height / ctx.mozCurrentTransformInverse[3]
  5926. });
  5927. }
  5928. this.compose();
  5929. this.restore();
  5930. }
  5931. paintInlineImageXObjectGroup(imgData, map) {
  5932. if (!this.contentVisible) {
  5933. return;
  5934. }
  5935. const ctx = this.ctx;
  5936. const w = imgData.width;
  5937. const h = imgData.height;
  5938. const tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", w, h);
  5939. const tmpCtx = tmpCanvas.context;
  5940. putBinaryImageData(tmpCtx, imgData, this.current.transferMaps);
  5941. for (let i = 0, ii = map.length; i < ii; i++) {
  5942. const entry = map[i];
  5943. ctx.save();
  5944. ctx.transform.apply(ctx, entry.transform);
  5945. ctx.scale(1, -1);
  5946. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h, 0, -1, 1, 1);
  5947. if (this.imageLayer) {
  5948. const position = this.getCanvasPosition(entry.x, entry.y);
  5949. this.imageLayer.appendImage({
  5950. imgData,
  5951. left: position[0],
  5952. top: position[1],
  5953. width: w,
  5954. height: h
  5955. });
  5956. }
  5957. ctx.restore();
  5958. }
  5959. this.compose();
  5960. }
  5961. paintSolidColorImageMask() {
  5962. if (!this.contentVisible) {
  5963. return;
  5964. }
  5965. this.ctx.fillRect(0, 0, 1, 1);
  5966. this.compose();
  5967. }
  5968. markPoint(tag) {}
  5969. markPointProps(tag, properties) {}
  5970. beginMarkedContent(tag) {
  5971. this.markedContentStack.push({
  5972. visible: true
  5973. });
  5974. }
  5975. beginMarkedContentProps(tag, properties) {
  5976. if (tag === "OC") {
  5977. this.markedContentStack.push({
  5978. visible: this.optionalContentConfig.isVisible(properties)
  5979. });
  5980. } else {
  5981. this.markedContentStack.push({
  5982. visible: true
  5983. });
  5984. }
  5985. this.contentVisible = this.isContentVisible();
  5986. }
  5987. endMarkedContent() {
  5988. this.markedContentStack.pop();
  5989. this.contentVisible = this.isContentVisible();
  5990. }
  5991. beginCompat() {}
  5992. endCompat() {}
  5993. consumePath(clipBox) {
  5994. if (this.pendingClip) {
  5995. this.current.updateClipFromPath();
  5996. }
  5997. if (!this.pendingClip) {
  5998. this.compose(clipBox);
  5999. }
  6000. const ctx = this.ctx;
  6001. if (this.pendingClip) {
  6002. if (this.pendingClip === EO_CLIP) {
  6003. ctx.clip("evenodd");
  6004. } else {
  6005. ctx.clip();
  6006. }
  6007. this.pendingClip = null;
  6008. }
  6009. this.current.startNewPathAndClipBox(this.current.clipBox);
  6010. ctx.beginPath();
  6011. }
  6012. getSinglePixelWidth() {
  6013. if (this._cachedGetSinglePixelWidth === null) {
  6014. const m = this.ctx.mozCurrentTransform;
  6015. const absDet = Math.abs(m[0] * m[3] - m[2] * m[1]);
  6016. const sqNorm1 = m[0] ** 2 + m[2] ** 2;
  6017. const sqNorm2 = m[1] ** 2 + m[3] ** 2;
  6018. const pixelHeight = Math.sqrt(Math.max(sqNorm1, sqNorm2)) / absDet;
  6019. if (sqNorm1 !== sqNorm2 && this._combinedScaleFactor * pixelHeight > 1) {
  6020. this._cachedGetSinglePixelWidth = -(this._combinedScaleFactor * pixelHeight);
  6021. } else if (absDet > Number.EPSILON) {
  6022. this._cachedGetSinglePixelWidth = pixelHeight;
  6023. } else {
  6024. this._cachedGetSinglePixelWidth = 1;
  6025. }
  6026. }
  6027. return this._cachedGetSinglePixelWidth;
  6028. }
  6029. getCanvasPosition(x, y) {
  6030. const transform = this.ctx.mozCurrentTransform;
  6031. return [transform[0] * x + transform[2] * y + transform[4], transform[1] * x + transform[3] * y + transform[5]];
  6032. }
  6033. isContentVisible() {
  6034. for (let i = this.markedContentStack.length - 1; i >= 0; i--) {
  6035. if (!this.markedContentStack[i].visible) {
  6036. return false;
  6037. }
  6038. }
  6039. return true;
  6040. }
  6041. }
  6042. exports.CanvasGraphics = CanvasGraphics;
  6043. for (const op in _util.OPS) {
  6044. if (CanvasGraphics.prototype[op] !== undefined) {
  6045. CanvasGraphics.prototype[_util.OPS[op]] = CanvasGraphics.prototype[op];
  6046. }
  6047. }
  6048. /***/ }),
  6049. /* 11 */
  6050. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  6051. Object.defineProperty(exports, "__esModule", ({
  6052. value: true
  6053. }));
  6054. exports.TilingPattern = exports.PathType = void 0;
  6055. exports.getShadingPattern = getShadingPattern;
  6056. var _util = __w_pdfjs_require__(2);
  6057. const PathType = {
  6058. FILL: "Fill",
  6059. STROKE: "Stroke",
  6060. SHADING: "Shading"
  6061. };
  6062. exports.PathType = PathType;
  6063. function applyBoundingBox(ctx, bbox) {
  6064. if (!bbox || typeof Path2D === "undefined") {
  6065. return;
  6066. }
  6067. const width = bbox[2] - bbox[0];
  6068. const height = bbox[3] - bbox[1];
  6069. const region = new Path2D();
  6070. region.rect(bbox[0], bbox[1], width, height);
  6071. ctx.clip(region);
  6072. }
  6073. class BaseShadingPattern {
  6074. constructor() {
  6075. if (this.constructor === BaseShadingPattern) {
  6076. (0, _util.unreachable)("Cannot initialize BaseShadingPattern.");
  6077. }
  6078. }
  6079. getPattern() {
  6080. (0, _util.unreachable)("Abstract method `getPattern` called.");
  6081. }
  6082. }
  6083. class RadialAxialShadingPattern extends BaseShadingPattern {
  6084. constructor(IR) {
  6085. super();
  6086. this._type = IR[1];
  6087. this._bbox = IR[2];
  6088. this._colorStops = IR[3];
  6089. this._p0 = IR[4];
  6090. this._p1 = IR[5];
  6091. this._r0 = IR[6];
  6092. this._r1 = IR[7];
  6093. this.matrix = null;
  6094. }
  6095. _createGradient(ctx) {
  6096. let grad;
  6097. if (this._type === "axial") {
  6098. grad = ctx.createLinearGradient(this._p0[0], this._p0[1], this._p1[0], this._p1[1]);
  6099. } else if (this._type === "radial") {
  6100. grad = ctx.createRadialGradient(this._p0[0], this._p0[1], this._r0, this._p1[0], this._p1[1], this._r1);
  6101. }
  6102. for (const colorStop of this._colorStops) {
  6103. grad.addColorStop(colorStop[0], colorStop[1]);
  6104. }
  6105. return grad;
  6106. }
  6107. getPattern(ctx, owner, inverse, pathType) {
  6108. let pattern;
  6109. if (pathType === PathType.STROKE || pathType === PathType.FILL) {
  6110. const ownerBBox = owner.current.getClippedPathBoundingBox(pathType, ctx.mozCurrentTransform) || [0, 0, 0, 0];
  6111. const width = Math.ceil(ownerBBox[2] - ownerBBox[0]) || 1;
  6112. const height = Math.ceil(ownerBBox[3] - ownerBBox[1]) || 1;
  6113. const tmpCanvas = owner.cachedCanvases.getCanvas("pattern", width, height, true);
  6114. const tmpCtx = tmpCanvas.context;
  6115. tmpCtx.clearRect(0, 0, tmpCtx.canvas.width, tmpCtx.canvas.height);
  6116. tmpCtx.beginPath();
  6117. tmpCtx.rect(0, 0, tmpCtx.canvas.width, tmpCtx.canvas.height);
  6118. tmpCtx.translate(-ownerBBox[0], -ownerBBox[1]);
  6119. inverse = _util.Util.transform(inverse, [1, 0, 0, 1, ownerBBox[0], ownerBBox[1]]);
  6120. tmpCtx.transform.apply(tmpCtx, owner.baseTransform);
  6121. if (this.matrix) {
  6122. tmpCtx.transform.apply(tmpCtx, this.matrix);
  6123. }
  6124. applyBoundingBox(tmpCtx, this._bbox);
  6125. tmpCtx.fillStyle = this._createGradient(tmpCtx);
  6126. tmpCtx.fill();
  6127. pattern = ctx.createPattern(tmpCanvas.canvas, "no-repeat");
  6128. const domMatrix = new DOMMatrix(inverse);
  6129. try {
  6130. pattern.setTransform(domMatrix);
  6131. } catch (ex) {
  6132. (0, _util.warn)(`RadialAxialShadingPattern.getPattern: "${ex?.message}".`);
  6133. }
  6134. } else {
  6135. applyBoundingBox(ctx, this._bbox);
  6136. pattern = this._createGradient(ctx);
  6137. }
  6138. return pattern;
  6139. }
  6140. }
  6141. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  6142. const coords = context.coords,
  6143. colors = context.colors;
  6144. const bytes = data.data,
  6145. rowSize = data.width * 4;
  6146. let tmp;
  6147. if (coords[p1 + 1] > coords[p2 + 1]) {
  6148. tmp = p1;
  6149. p1 = p2;
  6150. p2 = tmp;
  6151. tmp = c1;
  6152. c1 = c2;
  6153. c2 = tmp;
  6154. }
  6155. if (coords[p2 + 1] > coords[p3 + 1]) {
  6156. tmp = p2;
  6157. p2 = p3;
  6158. p3 = tmp;
  6159. tmp = c2;
  6160. c2 = c3;
  6161. c3 = tmp;
  6162. }
  6163. if (coords[p1 + 1] > coords[p2 + 1]) {
  6164. tmp = p1;
  6165. p1 = p2;
  6166. p2 = tmp;
  6167. tmp = c1;
  6168. c1 = c2;
  6169. c2 = tmp;
  6170. }
  6171. const x1 = (coords[p1] + context.offsetX) * context.scaleX;
  6172. const y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  6173. const x2 = (coords[p2] + context.offsetX) * context.scaleX;
  6174. const y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  6175. const x3 = (coords[p3] + context.offsetX) * context.scaleX;
  6176. const y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  6177. if (y1 >= y3) {
  6178. return;
  6179. }
  6180. const c1r = colors[c1],
  6181. c1g = colors[c1 + 1],
  6182. c1b = colors[c1 + 2];
  6183. const c2r = colors[c2],
  6184. c2g = colors[c2 + 1],
  6185. c2b = colors[c2 + 2];
  6186. const c3r = colors[c3],
  6187. c3g = colors[c3 + 1],
  6188. c3b = colors[c3 + 2];
  6189. const minY = Math.round(y1),
  6190. maxY = Math.round(y3);
  6191. let xa, car, cag, cab;
  6192. let xb, cbr, cbg, cbb;
  6193. for (let y = minY; y <= maxY; y++) {
  6194. if (y < y2) {
  6195. let k;
  6196. if (y < y1) {
  6197. k = 0;
  6198. } else {
  6199. k = (y1 - y) / (y1 - y2);
  6200. }
  6201. xa = x1 - (x1 - x2) * k;
  6202. car = c1r - (c1r - c2r) * k;
  6203. cag = c1g - (c1g - c2g) * k;
  6204. cab = c1b - (c1b - c2b) * k;
  6205. } else {
  6206. let k;
  6207. if (y > y3) {
  6208. k = 1;
  6209. } else if (y2 === y3) {
  6210. k = 0;
  6211. } else {
  6212. k = (y2 - y) / (y2 - y3);
  6213. }
  6214. xa = x2 - (x2 - x3) * k;
  6215. car = c2r - (c2r - c3r) * k;
  6216. cag = c2g - (c2g - c3g) * k;
  6217. cab = c2b - (c2b - c3b) * k;
  6218. }
  6219. let k;
  6220. if (y < y1) {
  6221. k = 0;
  6222. } else if (y > y3) {
  6223. k = 1;
  6224. } else {
  6225. k = (y1 - y) / (y1 - y3);
  6226. }
  6227. xb = x1 - (x1 - x3) * k;
  6228. cbr = c1r - (c1r - c3r) * k;
  6229. cbg = c1g - (c1g - c3g) * k;
  6230. cbb = c1b - (c1b - c3b) * k;
  6231. const x1_ = Math.round(Math.min(xa, xb));
  6232. const x2_ = Math.round(Math.max(xa, xb));
  6233. let j = rowSize * y + x1_ * 4;
  6234. for (let x = x1_; x <= x2_; x++) {
  6235. k = (xa - x) / (xa - xb);
  6236. if (k < 0) {
  6237. k = 0;
  6238. } else if (k > 1) {
  6239. k = 1;
  6240. }
  6241. bytes[j++] = car - (car - cbr) * k | 0;
  6242. bytes[j++] = cag - (cag - cbg) * k | 0;
  6243. bytes[j++] = cab - (cab - cbb) * k | 0;
  6244. bytes[j++] = 255;
  6245. }
  6246. }
  6247. }
  6248. function drawFigure(data, figure, context) {
  6249. const ps = figure.coords;
  6250. const cs = figure.colors;
  6251. let i, ii;
  6252. switch (figure.type) {
  6253. case "lattice":
  6254. const verticesPerRow = figure.verticesPerRow;
  6255. const rows = Math.floor(ps.length / verticesPerRow) - 1;
  6256. const cols = verticesPerRow - 1;
  6257. for (i = 0; i < rows; i++) {
  6258. let q = i * verticesPerRow;
  6259. for (let j = 0; j < cols; j++, q++) {
  6260. drawTriangle(data, context, ps[q], ps[q + 1], ps[q + verticesPerRow], cs[q], cs[q + 1], cs[q + verticesPerRow]);
  6261. drawTriangle(data, context, ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow], cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  6262. }
  6263. }
  6264. break;
  6265. case "triangles":
  6266. for (i = 0, ii = ps.length; i < ii; i += 3) {
  6267. drawTriangle(data, context, ps[i], ps[i + 1], ps[i + 2], cs[i], cs[i + 1], cs[i + 2]);
  6268. }
  6269. break;
  6270. default:
  6271. throw new Error("illegal figure");
  6272. }
  6273. }
  6274. class MeshShadingPattern extends BaseShadingPattern {
  6275. constructor(IR) {
  6276. super();
  6277. this._coords = IR[2];
  6278. this._colors = IR[3];
  6279. this._figures = IR[4];
  6280. this._bounds = IR[5];
  6281. this._bbox = IR[7];
  6282. this._background = IR[8];
  6283. this.matrix = null;
  6284. }
  6285. _createMeshCanvas(combinedScale, backgroundColor, cachedCanvases) {
  6286. const EXPECTED_SCALE = 1.1;
  6287. const MAX_PATTERN_SIZE = 3000;
  6288. const BORDER_SIZE = 2;
  6289. const offsetX = Math.floor(this._bounds[0]);
  6290. const offsetY = Math.floor(this._bounds[1]);
  6291. const boundsWidth = Math.ceil(this._bounds[2]) - offsetX;
  6292. const boundsHeight = Math.ceil(this._bounds[3]) - offsetY;
  6293. const width = Math.min(Math.ceil(Math.abs(boundsWidth * combinedScale[0] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  6294. const height = Math.min(Math.ceil(Math.abs(boundsHeight * combinedScale[1] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  6295. const scaleX = boundsWidth / width;
  6296. const scaleY = boundsHeight / height;
  6297. const context = {
  6298. coords: this._coords,
  6299. colors: this._colors,
  6300. offsetX: -offsetX,
  6301. offsetY: -offsetY,
  6302. scaleX: 1 / scaleX,
  6303. scaleY: 1 / scaleY
  6304. };
  6305. const paddedWidth = width + BORDER_SIZE * 2;
  6306. const paddedHeight = height + BORDER_SIZE * 2;
  6307. const tmpCanvas = cachedCanvases.getCanvas("mesh", paddedWidth, paddedHeight, false);
  6308. const tmpCtx = tmpCanvas.context;
  6309. const data = tmpCtx.createImageData(width, height);
  6310. if (backgroundColor) {
  6311. const bytes = data.data;
  6312. for (let i = 0, ii = bytes.length; i < ii; i += 4) {
  6313. bytes[i] = backgroundColor[0];
  6314. bytes[i + 1] = backgroundColor[1];
  6315. bytes[i + 2] = backgroundColor[2];
  6316. bytes[i + 3] = 255;
  6317. }
  6318. }
  6319. for (const figure of this._figures) {
  6320. drawFigure(data, figure, context);
  6321. }
  6322. tmpCtx.putImageData(data, BORDER_SIZE, BORDER_SIZE);
  6323. const canvas = tmpCanvas.canvas;
  6324. return {
  6325. canvas,
  6326. offsetX: offsetX - BORDER_SIZE * scaleX,
  6327. offsetY: offsetY - BORDER_SIZE * scaleY,
  6328. scaleX,
  6329. scaleY
  6330. };
  6331. }
  6332. getPattern(ctx, owner, inverse, pathType) {
  6333. applyBoundingBox(ctx, this._bbox);
  6334. let scale;
  6335. if (pathType === PathType.SHADING) {
  6336. scale = _util.Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  6337. } else {
  6338. scale = _util.Util.singularValueDecompose2dScale(owner.baseTransform);
  6339. if (this.matrix) {
  6340. const matrixScale = _util.Util.singularValueDecompose2dScale(this.matrix);
  6341. scale = [scale[0] * matrixScale[0], scale[1] * matrixScale[1]];
  6342. }
  6343. }
  6344. const temporaryPatternCanvas = this._createMeshCanvas(scale, pathType === PathType.SHADING ? null : this._background, owner.cachedCanvases);
  6345. if (pathType !== PathType.SHADING) {
  6346. ctx.setTransform.apply(ctx, owner.baseTransform);
  6347. if (this.matrix) {
  6348. ctx.transform.apply(ctx, this.matrix);
  6349. }
  6350. }
  6351. ctx.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY);
  6352. ctx.scale(temporaryPatternCanvas.scaleX, temporaryPatternCanvas.scaleY);
  6353. return ctx.createPattern(temporaryPatternCanvas.canvas, "no-repeat");
  6354. }
  6355. }
  6356. class DummyShadingPattern extends BaseShadingPattern {
  6357. getPattern() {
  6358. return "hotpink";
  6359. }
  6360. }
  6361. function getShadingPattern(IR) {
  6362. switch (IR[0]) {
  6363. case "RadialAxial":
  6364. return new RadialAxialShadingPattern(IR);
  6365. case "Mesh":
  6366. return new MeshShadingPattern(IR);
  6367. case "Dummy":
  6368. return new DummyShadingPattern();
  6369. }
  6370. throw new Error(`Unknown IR type: ${IR[0]}`);
  6371. }
  6372. const PaintType = {
  6373. COLORED: 1,
  6374. UNCOLORED: 2
  6375. };
  6376. class TilingPattern {
  6377. static get MAX_PATTERN_SIZE() {
  6378. return (0, _util.shadow)(this, "MAX_PATTERN_SIZE", 3000);
  6379. }
  6380. constructor(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
  6381. this.operatorList = IR[2];
  6382. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  6383. this.bbox = IR[4];
  6384. this.xstep = IR[5];
  6385. this.ystep = IR[6];
  6386. this.paintType = IR[7];
  6387. this.tilingType = IR[8];
  6388. this.color = color;
  6389. this.ctx = ctx;
  6390. this.canvasGraphicsFactory = canvasGraphicsFactory;
  6391. this.baseTransform = baseTransform;
  6392. }
  6393. createPatternCanvas(owner) {
  6394. const operatorList = this.operatorList;
  6395. const bbox = this.bbox;
  6396. const xstep = this.xstep;
  6397. const ystep = this.ystep;
  6398. const paintType = this.paintType;
  6399. const tilingType = this.tilingType;
  6400. const color = this.color;
  6401. const canvasGraphicsFactory = this.canvasGraphicsFactory;
  6402. (0, _util.info)("TilingType: " + tilingType);
  6403. const x0 = bbox[0],
  6404. y0 = bbox[1],
  6405. x1 = bbox[2],
  6406. y1 = bbox[3];
  6407. const matrixScale = _util.Util.singularValueDecompose2dScale(this.matrix);
  6408. const curMatrixScale = _util.Util.singularValueDecompose2dScale(this.baseTransform);
  6409. const combinedScale = [matrixScale[0] * curMatrixScale[0], matrixScale[1] * curMatrixScale[1]];
  6410. const dimx = this.getSizeAndScale(xstep, this.ctx.canvas.width, combinedScale[0]);
  6411. const dimy = this.getSizeAndScale(ystep, this.ctx.canvas.height, combinedScale[1]);
  6412. const tmpCanvas = owner.cachedCanvases.getCanvas("pattern", dimx.size, dimy.size, true);
  6413. const tmpCtx = tmpCanvas.context;
  6414. const graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
  6415. graphics.groupLevel = owner.groupLevel;
  6416. this.setFillAndStrokeStyleToContext(graphics, paintType, color);
  6417. let adjustedX0 = x0;
  6418. let adjustedY0 = y0;
  6419. let adjustedX1 = x1;
  6420. let adjustedY1 = y1;
  6421. if (x0 < 0) {
  6422. adjustedX0 = 0;
  6423. adjustedX1 += Math.abs(x0);
  6424. }
  6425. if (y0 < 0) {
  6426. adjustedY0 = 0;
  6427. adjustedY1 += Math.abs(y0);
  6428. }
  6429. tmpCtx.translate(-(dimx.scale * adjustedX0), -(dimy.scale * adjustedY0));
  6430. graphics.transform(dimx.scale, 0, 0, dimy.scale, 0, 0);
  6431. this.clipBbox(graphics, adjustedX0, adjustedY0, adjustedX1, adjustedY1);
  6432. graphics.baseTransform = graphics.ctx.mozCurrentTransform.slice();
  6433. graphics.executeOperatorList(operatorList);
  6434. graphics.endDrawing();
  6435. return {
  6436. canvas: tmpCanvas.canvas,
  6437. scaleX: dimx.scale,
  6438. scaleY: dimy.scale,
  6439. offsetX: adjustedX0,
  6440. offsetY: adjustedY0
  6441. };
  6442. }
  6443. getSizeAndScale(step, realOutputSize, scale) {
  6444. step = Math.abs(step);
  6445. const maxSize = Math.max(TilingPattern.MAX_PATTERN_SIZE, realOutputSize);
  6446. let size = Math.ceil(step * scale);
  6447. if (size >= maxSize) {
  6448. size = maxSize;
  6449. } else {
  6450. scale = size / step;
  6451. }
  6452. return {
  6453. scale,
  6454. size
  6455. };
  6456. }
  6457. clipBbox(graphics, x0, y0, x1, y1) {
  6458. const bboxWidth = x1 - x0;
  6459. const bboxHeight = y1 - y0;
  6460. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  6461. graphics.clip();
  6462. graphics.endPath();
  6463. }
  6464. setFillAndStrokeStyleToContext(graphics, paintType, color) {
  6465. const context = graphics.ctx,
  6466. current = graphics.current;
  6467. switch (paintType) {
  6468. case PaintType.COLORED:
  6469. const ctx = this.ctx;
  6470. context.fillStyle = ctx.fillStyle;
  6471. context.strokeStyle = ctx.strokeStyle;
  6472. current.fillColor = ctx.fillStyle;
  6473. current.strokeColor = ctx.strokeStyle;
  6474. break;
  6475. case PaintType.UNCOLORED:
  6476. const cssColor = _util.Util.makeHexColor(color[0], color[1], color[2]);
  6477. context.fillStyle = cssColor;
  6478. context.strokeStyle = cssColor;
  6479. current.fillColor = cssColor;
  6480. current.strokeColor = cssColor;
  6481. break;
  6482. default:
  6483. throw new _util.FormatError(`Unsupported paint type: ${paintType}`);
  6484. }
  6485. }
  6486. getPattern(ctx, owner, inverse, pathType) {
  6487. let matrix = inverse;
  6488. if (pathType !== PathType.SHADING) {
  6489. matrix = _util.Util.transform(matrix, owner.baseTransform);
  6490. if (this.matrix) {
  6491. matrix = _util.Util.transform(matrix, this.matrix);
  6492. }
  6493. }
  6494. const temporaryPatternCanvas = this.createPatternCanvas(owner);
  6495. let domMatrix = new DOMMatrix(matrix);
  6496. domMatrix = domMatrix.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY);
  6497. domMatrix = domMatrix.scale(1 / temporaryPatternCanvas.scaleX, 1 / temporaryPatternCanvas.scaleY);
  6498. const pattern = ctx.createPattern(temporaryPatternCanvas.canvas, "repeat");
  6499. try {
  6500. pattern.setTransform(domMatrix);
  6501. } catch (ex) {
  6502. (0, _util.warn)(`TilingPattern.getPattern: "${ex?.message}".`);
  6503. }
  6504. return pattern;
  6505. }
  6506. }
  6507. exports.TilingPattern = TilingPattern;
  6508. /***/ }),
  6509. /* 12 */
  6510. /***/ ((__unused_webpack_module, exports) => {
  6511. Object.defineProperty(exports, "__esModule", ({
  6512. value: true
  6513. }));
  6514. exports.GlobalWorkerOptions = void 0;
  6515. const GlobalWorkerOptions = Object.create(null);
  6516. exports.GlobalWorkerOptions = GlobalWorkerOptions;
  6517. GlobalWorkerOptions.workerPort = GlobalWorkerOptions.workerPort === undefined ? null : GlobalWorkerOptions.workerPort;
  6518. GlobalWorkerOptions.workerSrc = GlobalWorkerOptions.workerSrc === undefined ? "" : GlobalWorkerOptions.workerSrc;
  6519. /***/ }),
  6520. /* 13 */
  6521. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  6522. Object.defineProperty(exports, "__esModule", ({
  6523. value: true
  6524. }));
  6525. exports.MessageHandler = void 0;
  6526. var _util = __w_pdfjs_require__(2);
  6527. const CallbackKind = {
  6528. UNKNOWN: 0,
  6529. DATA: 1,
  6530. ERROR: 2
  6531. };
  6532. const StreamKind = {
  6533. UNKNOWN: 0,
  6534. CANCEL: 1,
  6535. CANCEL_COMPLETE: 2,
  6536. CLOSE: 3,
  6537. ENQUEUE: 4,
  6538. ERROR: 5,
  6539. PULL: 6,
  6540. PULL_COMPLETE: 7,
  6541. START_COMPLETE: 8
  6542. };
  6543. function wrapReason(reason) {
  6544. if (!(reason instanceof Error || typeof reason === "object" && reason !== null)) {
  6545. (0, _util.warn)('wrapReason: Expected "reason" to be a (possibly cloned) Error.');
  6546. return reason;
  6547. }
  6548. switch (reason.name) {
  6549. case "AbortException":
  6550. return new _util.AbortException(reason.message);
  6551. case "MissingPDFException":
  6552. return new _util.MissingPDFException(reason.message);
  6553. case "PasswordException":
  6554. return new _util.PasswordException(reason.message, reason.code);
  6555. case "UnexpectedResponseException":
  6556. return new _util.UnexpectedResponseException(reason.message, reason.status);
  6557. case "UnknownErrorException":
  6558. return new _util.UnknownErrorException(reason.message, reason.details);
  6559. default:
  6560. return new _util.UnknownErrorException(reason.message, reason.toString());
  6561. }
  6562. }
  6563. class MessageHandler {
  6564. constructor(sourceName, targetName, comObj) {
  6565. this.sourceName = sourceName;
  6566. this.targetName = targetName;
  6567. this.comObj = comObj;
  6568. this.callbackId = 1;
  6569. this.streamId = 1;
  6570. this.streamSinks = Object.create(null);
  6571. this.streamControllers = Object.create(null);
  6572. this.callbackCapabilities = Object.create(null);
  6573. this.actionHandler = Object.create(null);
  6574. this._onComObjOnMessage = event => {
  6575. const data = event.data;
  6576. if (data.targetName !== this.sourceName) {
  6577. return;
  6578. }
  6579. if (data.stream) {
  6580. this._processStreamMessage(data);
  6581. return;
  6582. }
  6583. if (data.callback) {
  6584. const callbackId = data.callbackId;
  6585. const capability = this.callbackCapabilities[callbackId];
  6586. if (!capability) {
  6587. throw new Error(`Cannot resolve callback ${callbackId}`);
  6588. }
  6589. delete this.callbackCapabilities[callbackId];
  6590. if (data.callback === CallbackKind.DATA) {
  6591. capability.resolve(data.data);
  6592. } else if (data.callback === CallbackKind.ERROR) {
  6593. capability.reject(wrapReason(data.reason));
  6594. } else {
  6595. throw new Error("Unexpected callback case");
  6596. }
  6597. return;
  6598. }
  6599. const action = this.actionHandler[data.action];
  6600. if (!action) {
  6601. throw new Error(`Unknown action from worker: ${data.action}`);
  6602. }
  6603. if (data.callbackId) {
  6604. const cbSourceName = this.sourceName;
  6605. const cbTargetName = data.sourceName;
  6606. new Promise(function (resolve) {
  6607. resolve(action(data.data));
  6608. }).then(function (result) {
  6609. comObj.postMessage({
  6610. sourceName: cbSourceName,
  6611. targetName: cbTargetName,
  6612. callback: CallbackKind.DATA,
  6613. callbackId: data.callbackId,
  6614. data: result
  6615. });
  6616. }, function (reason) {
  6617. comObj.postMessage({
  6618. sourceName: cbSourceName,
  6619. targetName: cbTargetName,
  6620. callback: CallbackKind.ERROR,
  6621. callbackId: data.callbackId,
  6622. reason: wrapReason(reason)
  6623. });
  6624. });
  6625. return;
  6626. }
  6627. if (data.streamId) {
  6628. this._createStreamSink(data);
  6629. return;
  6630. }
  6631. action(data.data);
  6632. };
  6633. comObj.addEventListener("message", this._onComObjOnMessage);
  6634. }
  6635. on(actionName, handler) {
  6636. const ah = this.actionHandler;
  6637. if (ah[actionName]) {
  6638. throw new Error(`There is already an actionName called "${actionName}"`);
  6639. }
  6640. ah[actionName] = handler;
  6641. }
  6642. send(actionName, data, transfers) {
  6643. this.comObj.postMessage({
  6644. sourceName: this.sourceName,
  6645. targetName: this.targetName,
  6646. action: actionName,
  6647. data
  6648. }, transfers);
  6649. }
  6650. sendWithPromise(actionName, data, transfers) {
  6651. const callbackId = this.callbackId++;
  6652. const capability = (0, _util.createPromiseCapability)();
  6653. this.callbackCapabilities[callbackId] = capability;
  6654. try {
  6655. this.comObj.postMessage({
  6656. sourceName: this.sourceName,
  6657. targetName: this.targetName,
  6658. action: actionName,
  6659. callbackId,
  6660. data
  6661. }, transfers);
  6662. } catch (ex) {
  6663. capability.reject(ex);
  6664. }
  6665. return capability.promise;
  6666. }
  6667. sendWithStream(actionName, data, queueingStrategy, transfers) {
  6668. const streamId = this.streamId++,
  6669. sourceName = this.sourceName,
  6670. targetName = this.targetName,
  6671. comObj = this.comObj;
  6672. return new ReadableStream({
  6673. start: controller => {
  6674. const startCapability = (0, _util.createPromiseCapability)();
  6675. this.streamControllers[streamId] = {
  6676. controller,
  6677. startCall: startCapability,
  6678. pullCall: null,
  6679. cancelCall: null,
  6680. isClosed: false
  6681. };
  6682. comObj.postMessage({
  6683. sourceName,
  6684. targetName,
  6685. action: actionName,
  6686. streamId,
  6687. data,
  6688. desiredSize: controller.desiredSize
  6689. }, transfers);
  6690. return startCapability.promise;
  6691. },
  6692. pull: controller => {
  6693. const pullCapability = (0, _util.createPromiseCapability)();
  6694. this.streamControllers[streamId].pullCall = pullCapability;
  6695. comObj.postMessage({
  6696. sourceName,
  6697. targetName,
  6698. stream: StreamKind.PULL,
  6699. streamId,
  6700. desiredSize: controller.desiredSize
  6701. });
  6702. return pullCapability.promise;
  6703. },
  6704. cancel: reason => {
  6705. (0, _util.assert)(reason instanceof Error, "cancel must have a valid reason");
  6706. const cancelCapability = (0, _util.createPromiseCapability)();
  6707. this.streamControllers[streamId].cancelCall = cancelCapability;
  6708. this.streamControllers[streamId].isClosed = true;
  6709. comObj.postMessage({
  6710. sourceName,
  6711. targetName,
  6712. stream: StreamKind.CANCEL,
  6713. streamId,
  6714. reason: wrapReason(reason)
  6715. });
  6716. return cancelCapability.promise;
  6717. }
  6718. }, queueingStrategy);
  6719. }
  6720. _createStreamSink(data) {
  6721. const streamId = data.streamId,
  6722. sourceName = this.sourceName,
  6723. targetName = data.sourceName,
  6724. comObj = this.comObj;
  6725. const self = this,
  6726. action = this.actionHandler[data.action];
  6727. const streamSink = {
  6728. enqueue(chunk, size = 1, transfers) {
  6729. if (this.isCancelled) {
  6730. return;
  6731. }
  6732. const lastDesiredSize = this.desiredSize;
  6733. this.desiredSize -= size;
  6734. if (lastDesiredSize > 0 && this.desiredSize <= 0) {
  6735. this.sinkCapability = (0, _util.createPromiseCapability)();
  6736. this.ready = this.sinkCapability.promise;
  6737. }
  6738. comObj.postMessage({
  6739. sourceName,
  6740. targetName,
  6741. stream: StreamKind.ENQUEUE,
  6742. streamId,
  6743. chunk
  6744. }, transfers);
  6745. },
  6746. close() {
  6747. if (this.isCancelled) {
  6748. return;
  6749. }
  6750. this.isCancelled = true;
  6751. comObj.postMessage({
  6752. sourceName,
  6753. targetName,
  6754. stream: StreamKind.CLOSE,
  6755. streamId
  6756. });
  6757. delete self.streamSinks[streamId];
  6758. },
  6759. error(reason) {
  6760. (0, _util.assert)(reason instanceof Error, "error must have a valid reason");
  6761. if (this.isCancelled) {
  6762. return;
  6763. }
  6764. this.isCancelled = true;
  6765. comObj.postMessage({
  6766. sourceName,
  6767. targetName,
  6768. stream: StreamKind.ERROR,
  6769. streamId,
  6770. reason: wrapReason(reason)
  6771. });
  6772. },
  6773. sinkCapability: (0, _util.createPromiseCapability)(),
  6774. onPull: null,
  6775. onCancel: null,
  6776. isCancelled: false,
  6777. desiredSize: data.desiredSize,
  6778. ready: null
  6779. };
  6780. streamSink.sinkCapability.resolve();
  6781. streamSink.ready = streamSink.sinkCapability.promise;
  6782. this.streamSinks[streamId] = streamSink;
  6783. new Promise(function (resolve) {
  6784. resolve(action(data.data, streamSink));
  6785. }).then(function () {
  6786. comObj.postMessage({
  6787. sourceName,
  6788. targetName,
  6789. stream: StreamKind.START_COMPLETE,
  6790. streamId,
  6791. success: true
  6792. });
  6793. }, function (reason) {
  6794. comObj.postMessage({
  6795. sourceName,
  6796. targetName,
  6797. stream: StreamKind.START_COMPLETE,
  6798. streamId,
  6799. reason: wrapReason(reason)
  6800. });
  6801. });
  6802. }
  6803. _processStreamMessage(data) {
  6804. const streamId = data.streamId,
  6805. sourceName = this.sourceName,
  6806. targetName = data.sourceName,
  6807. comObj = this.comObj;
  6808. const streamController = this.streamControllers[streamId],
  6809. streamSink = this.streamSinks[streamId];
  6810. switch (data.stream) {
  6811. case StreamKind.START_COMPLETE:
  6812. if (data.success) {
  6813. streamController.startCall.resolve();
  6814. } else {
  6815. streamController.startCall.reject(wrapReason(data.reason));
  6816. }
  6817. break;
  6818. case StreamKind.PULL_COMPLETE:
  6819. if (data.success) {
  6820. streamController.pullCall.resolve();
  6821. } else {
  6822. streamController.pullCall.reject(wrapReason(data.reason));
  6823. }
  6824. break;
  6825. case StreamKind.PULL:
  6826. if (!streamSink) {
  6827. comObj.postMessage({
  6828. sourceName,
  6829. targetName,
  6830. stream: StreamKind.PULL_COMPLETE,
  6831. streamId,
  6832. success: true
  6833. });
  6834. break;
  6835. }
  6836. if (streamSink.desiredSize <= 0 && data.desiredSize > 0) {
  6837. streamSink.sinkCapability.resolve();
  6838. }
  6839. streamSink.desiredSize = data.desiredSize;
  6840. new Promise(function (resolve) {
  6841. resolve(streamSink.onPull && streamSink.onPull());
  6842. }).then(function () {
  6843. comObj.postMessage({
  6844. sourceName,
  6845. targetName,
  6846. stream: StreamKind.PULL_COMPLETE,
  6847. streamId,
  6848. success: true
  6849. });
  6850. }, function (reason) {
  6851. comObj.postMessage({
  6852. sourceName,
  6853. targetName,
  6854. stream: StreamKind.PULL_COMPLETE,
  6855. streamId,
  6856. reason: wrapReason(reason)
  6857. });
  6858. });
  6859. break;
  6860. case StreamKind.ENQUEUE:
  6861. (0, _util.assert)(streamController, "enqueue should have stream controller");
  6862. if (streamController.isClosed) {
  6863. break;
  6864. }
  6865. streamController.controller.enqueue(data.chunk);
  6866. break;
  6867. case StreamKind.CLOSE:
  6868. (0, _util.assert)(streamController, "close should have stream controller");
  6869. if (streamController.isClosed) {
  6870. break;
  6871. }
  6872. streamController.isClosed = true;
  6873. streamController.controller.close();
  6874. this._deleteStreamController(streamController, streamId);
  6875. break;
  6876. case StreamKind.ERROR:
  6877. (0, _util.assert)(streamController, "error should have stream controller");
  6878. streamController.controller.error(wrapReason(data.reason));
  6879. this._deleteStreamController(streamController, streamId);
  6880. break;
  6881. case StreamKind.CANCEL_COMPLETE:
  6882. if (data.success) {
  6883. streamController.cancelCall.resolve();
  6884. } else {
  6885. streamController.cancelCall.reject(wrapReason(data.reason));
  6886. }
  6887. this._deleteStreamController(streamController, streamId);
  6888. break;
  6889. case StreamKind.CANCEL:
  6890. if (!streamSink) {
  6891. break;
  6892. }
  6893. new Promise(function (resolve) {
  6894. resolve(streamSink.onCancel && streamSink.onCancel(wrapReason(data.reason)));
  6895. }).then(function () {
  6896. comObj.postMessage({
  6897. sourceName,
  6898. targetName,
  6899. stream: StreamKind.CANCEL_COMPLETE,
  6900. streamId,
  6901. success: true
  6902. });
  6903. }, function (reason) {
  6904. comObj.postMessage({
  6905. sourceName,
  6906. targetName,
  6907. stream: StreamKind.CANCEL_COMPLETE,
  6908. streamId,
  6909. reason: wrapReason(reason)
  6910. });
  6911. });
  6912. streamSink.sinkCapability.reject(wrapReason(data.reason));
  6913. streamSink.isCancelled = true;
  6914. delete this.streamSinks[streamId];
  6915. break;
  6916. default:
  6917. throw new Error("Unexpected stream case");
  6918. }
  6919. }
  6920. async _deleteStreamController(streamController, streamId) {
  6921. await Promise.allSettled([streamController.startCall && streamController.startCall.promise, streamController.pullCall && streamController.pullCall.promise, streamController.cancelCall && streamController.cancelCall.promise]);
  6922. delete this.streamControllers[streamId];
  6923. }
  6924. destroy() {
  6925. this.comObj.removeEventListener("message", this._onComObjOnMessage);
  6926. }
  6927. }
  6928. exports.MessageHandler = MessageHandler;
  6929. /***/ }),
  6930. /* 14 */
  6931. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  6932. Object.defineProperty(exports, "__esModule", ({
  6933. value: true
  6934. }));
  6935. exports.Metadata = void 0;
  6936. var _util = __w_pdfjs_require__(2);
  6937. class Metadata {
  6938. #metadataMap;
  6939. #data;
  6940. constructor({
  6941. parsedData,
  6942. rawData
  6943. }) {
  6944. this.#metadataMap = parsedData;
  6945. this.#data = rawData;
  6946. }
  6947. getRaw() {
  6948. return this.#data;
  6949. }
  6950. get(name) {
  6951. return this.#metadataMap.get(name) ?? null;
  6952. }
  6953. getAll() {
  6954. return (0, _util.objectFromMap)(this.#metadataMap);
  6955. }
  6956. has(name) {
  6957. return this.#metadataMap.has(name);
  6958. }
  6959. }
  6960. exports.Metadata = Metadata;
  6961. /***/ }),
  6962. /* 15 */
  6963. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  6964. Object.defineProperty(exports, "__esModule", ({
  6965. value: true
  6966. }));
  6967. exports.OptionalContentConfig = void 0;
  6968. var _util = __w_pdfjs_require__(2);
  6969. class OptionalContentGroup {
  6970. constructor(name, intent) {
  6971. this.visible = true;
  6972. this.name = name;
  6973. this.intent = intent;
  6974. }
  6975. }
  6976. class OptionalContentConfig {
  6977. constructor(data) {
  6978. this.name = null;
  6979. this.creator = null;
  6980. this._order = null;
  6981. this._groups = new Map();
  6982. if (data === null) {
  6983. return;
  6984. }
  6985. this.name = data.name;
  6986. this.creator = data.creator;
  6987. this._order = data.order;
  6988. for (const group of data.groups) {
  6989. this._groups.set(group.id, new OptionalContentGroup(group.name, group.intent));
  6990. }
  6991. if (data.baseState === "OFF") {
  6992. for (const group of this._groups) {
  6993. group.visible = false;
  6994. }
  6995. }
  6996. for (const on of data.on) {
  6997. this._groups.get(on).visible = true;
  6998. }
  6999. for (const off of data.off) {
  7000. this._groups.get(off).visible = false;
  7001. }
  7002. }
  7003. _evaluateVisibilityExpression(array) {
  7004. const length = array.length;
  7005. if (length < 2) {
  7006. return true;
  7007. }
  7008. const operator = array[0];
  7009. for (let i = 1; i < length; i++) {
  7010. const element = array[i];
  7011. let state;
  7012. if (Array.isArray(element)) {
  7013. state = this._evaluateVisibilityExpression(element);
  7014. } else if (this._groups.has(element)) {
  7015. state = this._groups.get(element).visible;
  7016. } else {
  7017. (0, _util.warn)(`Optional content group not found: ${element}`);
  7018. return true;
  7019. }
  7020. switch (operator) {
  7021. case "And":
  7022. if (!state) {
  7023. return false;
  7024. }
  7025. break;
  7026. case "Or":
  7027. if (state) {
  7028. return true;
  7029. }
  7030. break;
  7031. case "Not":
  7032. return !state;
  7033. default:
  7034. return true;
  7035. }
  7036. }
  7037. return operator === "And";
  7038. }
  7039. isVisible(group) {
  7040. if (this._groups.size === 0) {
  7041. return true;
  7042. }
  7043. if (!group) {
  7044. (0, _util.warn)("Optional content group not defined.");
  7045. return true;
  7046. }
  7047. if (group.type === "OCG") {
  7048. if (!this._groups.has(group.id)) {
  7049. (0, _util.warn)(`Optional content group not found: ${group.id}`);
  7050. return true;
  7051. }
  7052. return this._groups.get(group.id).visible;
  7053. } else if (group.type === "OCMD") {
  7054. if (group.expression) {
  7055. return this._evaluateVisibilityExpression(group.expression);
  7056. }
  7057. if (!group.policy || group.policy === "AnyOn") {
  7058. for (const id of group.ids) {
  7059. if (!this._groups.has(id)) {
  7060. (0, _util.warn)(`Optional content group not found: ${id}`);
  7061. return true;
  7062. }
  7063. if (this._groups.get(id).visible) {
  7064. return true;
  7065. }
  7066. }
  7067. return false;
  7068. } else if (group.policy === "AllOn") {
  7069. for (const id of group.ids) {
  7070. if (!this._groups.has(id)) {
  7071. (0, _util.warn)(`Optional content group not found: ${id}`);
  7072. return true;
  7073. }
  7074. if (!this._groups.get(id).visible) {
  7075. return false;
  7076. }
  7077. }
  7078. return true;
  7079. } else if (group.policy === "AnyOff") {
  7080. for (const id of group.ids) {
  7081. if (!this._groups.has(id)) {
  7082. (0, _util.warn)(`Optional content group not found: ${id}`);
  7083. return true;
  7084. }
  7085. if (!this._groups.get(id).visible) {
  7086. return true;
  7087. }
  7088. }
  7089. return false;
  7090. } else if (group.policy === "AllOff") {
  7091. for (const id of group.ids) {
  7092. if (!this._groups.has(id)) {
  7093. (0, _util.warn)(`Optional content group not found: ${id}`);
  7094. return true;
  7095. }
  7096. if (this._groups.get(id).visible) {
  7097. return false;
  7098. }
  7099. }
  7100. return true;
  7101. }
  7102. (0, _util.warn)(`Unknown optional content policy ${group.policy}.`);
  7103. return true;
  7104. }
  7105. (0, _util.warn)(`Unknown group type ${group.type}.`);
  7106. return true;
  7107. }
  7108. setVisibility(id, visible = true) {
  7109. if (!this._groups.has(id)) {
  7110. (0, _util.warn)(`Optional content group not found: ${id}`);
  7111. return;
  7112. }
  7113. this._groups.get(id).visible = !!visible;
  7114. }
  7115. getOrder() {
  7116. if (!this._groups.size) {
  7117. return null;
  7118. }
  7119. if (this._order) {
  7120. return this._order.slice();
  7121. }
  7122. return Array.from(this._groups.keys());
  7123. }
  7124. getGroups() {
  7125. return this._groups.size > 0 ? (0, _util.objectFromMap)(this._groups) : null;
  7126. }
  7127. getGroup(id) {
  7128. return this._groups.get(id) || null;
  7129. }
  7130. }
  7131. exports.OptionalContentConfig = OptionalContentConfig;
  7132. /***/ }),
  7133. /* 16 */
  7134. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  7135. Object.defineProperty(exports, "__esModule", ({
  7136. value: true
  7137. }));
  7138. exports.PDFDataTransportStream = void 0;
  7139. var _util = __w_pdfjs_require__(2);
  7140. var _display_utils = __w_pdfjs_require__(1);
  7141. class PDFDataTransportStream {
  7142. constructor(params, pdfDataRangeTransport) {
  7143. (0, _util.assert)(pdfDataRangeTransport, 'PDFDataTransportStream - missing required "pdfDataRangeTransport" argument.');
  7144. this._queuedChunks = [];
  7145. this._progressiveDone = params.progressiveDone || false;
  7146. this._contentDispositionFilename = params.contentDispositionFilename || null;
  7147. const initialData = params.initialData;
  7148. if (initialData?.length > 0) {
  7149. const buffer = new Uint8Array(initialData).buffer;
  7150. this._queuedChunks.push(buffer);
  7151. }
  7152. this._pdfDataRangeTransport = pdfDataRangeTransport;
  7153. this._isStreamingSupported = !params.disableStream;
  7154. this._isRangeSupported = !params.disableRange;
  7155. this._contentLength = params.length;
  7156. this._fullRequestReader = null;
  7157. this._rangeReaders = [];
  7158. this._pdfDataRangeTransport.addRangeListener((begin, chunk) => {
  7159. this._onReceiveData({
  7160. begin,
  7161. chunk
  7162. });
  7163. });
  7164. this._pdfDataRangeTransport.addProgressListener((loaded, total) => {
  7165. this._onProgress({
  7166. loaded,
  7167. total
  7168. });
  7169. });
  7170. this._pdfDataRangeTransport.addProgressiveReadListener(chunk => {
  7171. this._onReceiveData({
  7172. chunk
  7173. });
  7174. });
  7175. this._pdfDataRangeTransport.addProgressiveDoneListener(() => {
  7176. this._onProgressiveDone();
  7177. });
  7178. this._pdfDataRangeTransport.transportReady();
  7179. }
  7180. _onReceiveData(args) {
  7181. const buffer = new Uint8Array(args.chunk).buffer;
  7182. if (args.begin === undefined) {
  7183. if (this._fullRequestReader) {
  7184. this._fullRequestReader._enqueue(buffer);
  7185. } else {
  7186. this._queuedChunks.push(buffer);
  7187. }
  7188. } else {
  7189. const found = this._rangeReaders.some(function (rangeReader) {
  7190. if (rangeReader._begin !== args.begin) {
  7191. return false;
  7192. }
  7193. rangeReader._enqueue(buffer);
  7194. return true;
  7195. });
  7196. (0, _util.assert)(found, "_onReceiveData - no `PDFDataTransportStreamRangeReader` instance found.");
  7197. }
  7198. }
  7199. get _progressiveDataLength() {
  7200. return this._fullRequestReader?._loaded ?? 0;
  7201. }
  7202. _onProgress(evt) {
  7203. if (evt.total === undefined) {
  7204. const firstReader = this._rangeReaders[0];
  7205. if (firstReader?.onProgress) {
  7206. firstReader.onProgress({
  7207. loaded: evt.loaded
  7208. });
  7209. }
  7210. } else {
  7211. const fullReader = this._fullRequestReader;
  7212. if (fullReader?.onProgress) {
  7213. fullReader.onProgress({
  7214. loaded: evt.loaded,
  7215. total: evt.total
  7216. });
  7217. }
  7218. }
  7219. }
  7220. _onProgressiveDone() {
  7221. if (this._fullRequestReader) {
  7222. this._fullRequestReader.progressiveDone();
  7223. }
  7224. this._progressiveDone = true;
  7225. }
  7226. _removeRangeReader(reader) {
  7227. const i = this._rangeReaders.indexOf(reader);
  7228. if (i >= 0) {
  7229. this._rangeReaders.splice(i, 1);
  7230. }
  7231. }
  7232. getFullReader() {
  7233. (0, _util.assert)(!this._fullRequestReader, "PDFDataTransportStream.getFullReader can only be called once.");
  7234. const queuedChunks = this._queuedChunks;
  7235. this._queuedChunks = null;
  7236. return new PDFDataTransportStreamReader(this, queuedChunks, this._progressiveDone, this._contentDispositionFilename);
  7237. }
  7238. getRangeReader(begin, end) {
  7239. if (end <= this._progressiveDataLength) {
  7240. return null;
  7241. }
  7242. const reader = new PDFDataTransportStreamRangeReader(this, begin, end);
  7243. this._pdfDataRangeTransport.requestDataRange(begin, end);
  7244. this._rangeReaders.push(reader);
  7245. return reader;
  7246. }
  7247. cancelAllRequests(reason) {
  7248. if (this._fullRequestReader) {
  7249. this._fullRequestReader.cancel(reason);
  7250. }
  7251. for (const reader of this._rangeReaders.slice(0)) {
  7252. reader.cancel(reason);
  7253. }
  7254. this._pdfDataRangeTransport.abort();
  7255. }
  7256. }
  7257. exports.PDFDataTransportStream = PDFDataTransportStream;
  7258. class PDFDataTransportStreamReader {
  7259. constructor(stream, queuedChunks, progressiveDone = false, contentDispositionFilename = null) {
  7260. this._stream = stream;
  7261. this._done = progressiveDone || false;
  7262. this._filename = (0, _display_utils.isPdfFile)(contentDispositionFilename) ? contentDispositionFilename : null;
  7263. this._queuedChunks = queuedChunks || [];
  7264. this._loaded = 0;
  7265. for (const chunk of this._queuedChunks) {
  7266. this._loaded += chunk.byteLength;
  7267. }
  7268. this._requests = [];
  7269. this._headersReady = Promise.resolve();
  7270. stream._fullRequestReader = this;
  7271. this.onProgress = null;
  7272. }
  7273. _enqueue(chunk) {
  7274. if (this._done) {
  7275. return;
  7276. }
  7277. if (this._requests.length > 0) {
  7278. const requestCapability = this._requests.shift();
  7279. requestCapability.resolve({
  7280. value: chunk,
  7281. done: false
  7282. });
  7283. } else {
  7284. this._queuedChunks.push(chunk);
  7285. }
  7286. this._loaded += chunk.byteLength;
  7287. }
  7288. get headersReady() {
  7289. return this._headersReady;
  7290. }
  7291. get filename() {
  7292. return this._filename;
  7293. }
  7294. get isRangeSupported() {
  7295. return this._stream._isRangeSupported;
  7296. }
  7297. get isStreamingSupported() {
  7298. return this._stream._isStreamingSupported;
  7299. }
  7300. get contentLength() {
  7301. return this._stream._contentLength;
  7302. }
  7303. async read() {
  7304. if (this._queuedChunks.length > 0) {
  7305. const chunk = this._queuedChunks.shift();
  7306. return {
  7307. value: chunk,
  7308. done: false
  7309. };
  7310. }
  7311. if (this._done) {
  7312. return {
  7313. value: undefined,
  7314. done: true
  7315. };
  7316. }
  7317. const requestCapability = (0, _util.createPromiseCapability)();
  7318. this._requests.push(requestCapability);
  7319. return requestCapability.promise;
  7320. }
  7321. cancel(reason) {
  7322. this._done = true;
  7323. for (const requestCapability of this._requests) {
  7324. requestCapability.resolve({
  7325. value: undefined,
  7326. done: true
  7327. });
  7328. }
  7329. this._requests.length = 0;
  7330. }
  7331. progressiveDone() {
  7332. if (this._done) {
  7333. return;
  7334. }
  7335. this._done = true;
  7336. }
  7337. }
  7338. class PDFDataTransportStreamRangeReader {
  7339. constructor(stream, begin, end) {
  7340. this._stream = stream;
  7341. this._begin = begin;
  7342. this._end = end;
  7343. this._queuedChunk = null;
  7344. this._requests = [];
  7345. this._done = false;
  7346. this.onProgress = null;
  7347. }
  7348. _enqueue(chunk) {
  7349. if (this._done) {
  7350. return;
  7351. }
  7352. if (this._requests.length === 0) {
  7353. this._queuedChunk = chunk;
  7354. } else {
  7355. const requestsCapability = this._requests.shift();
  7356. requestsCapability.resolve({
  7357. value: chunk,
  7358. done: false
  7359. });
  7360. for (const requestCapability of this._requests) {
  7361. requestCapability.resolve({
  7362. value: undefined,
  7363. done: true
  7364. });
  7365. }
  7366. this._requests.length = 0;
  7367. }
  7368. this._done = true;
  7369. this._stream._removeRangeReader(this);
  7370. }
  7371. get isStreamingSupported() {
  7372. return false;
  7373. }
  7374. async read() {
  7375. if (this._queuedChunk) {
  7376. const chunk = this._queuedChunk;
  7377. this._queuedChunk = null;
  7378. return {
  7379. value: chunk,
  7380. done: false
  7381. };
  7382. }
  7383. if (this._done) {
  7384. return {
  7385. value: undefined,
  7386. done: true
  7387. };
  7388. }
  7389. const requestCapability = (0, _util.createPromiseCapability)();
  7390. this._requests.push(requestCapability);
  7391. return requestCapability.promise;
  7392. }
  7393. cancel(reason) {
  7394. this._done = true;
  7395. for (const requestCapability of this._requests) {
  7396. requestCapability.resolve({
  7397. value: undefined,
  7398. done: true
  7399. });
  7400. }
  7401. this._requests.length = 0;
  7402. this._stream._removeRangeReader(this);
  7403. }
  7404. }
  7405. /***/ }),
  7406. /* 17 */
  7407. /***/ ((__unused_webpack_module, exports) => {
  7408. Object.defineProperty(exports, "__esModule", ({
  7409. value: true
  7410. }));
  7411. exports.XfaText = void 0;
  7412. class XfaText {
  7413. static textContent(xfa) {
  7414. const items = [];
  7415. const output = {
  7416. items,
  7417. styles: Object.create(null)
  7418. };
  7419. function walk(node) {
  7420. if (!node) {
  7421. return;
  7422. }
  7423. let str = null;
  7424. const name = node.name;
  7425. if (name === "#text") {
  7426. str = node.value;
  7427. } else if (!XfaText.shouldBuildText(name)) {
  7428. return;
  7429. } else if (node?.attributes?.textContent) {
  7430. str = node.attributes.textContent;
  7431. } else if (node.value) {
  7432. str = node.value;
  7433. }
  7434. if (str !== null) {
  7435. items.push({
  7436. str
  7437. });
  7438. }
  7439. if (!node.children) {
  7440. return;
  7441. }
  7442. for (const child of node.children) {
  7443. walk(child);
  7444. }
  7445. }
  7446. walk(xfa);
  7447. return output;
  7448. }
  7449. static shouldBuildText(name) {
  7450. return !(name === "textarea" || name === "input" || name === "option" || name === "select");
  7451. }
  7452. }
  7453. exports.XfaText = XfaText;
  7454. /***/ }),
  7455. /* 18 */
  7456. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  7457. Object.defineProperty(exports, "__esModule", ({
  7458. value: true
  7459. }));
  7460. exports.AnnotationLayer = void 0;
  7461. var _util = __w_pdfjs_require__(2);
  7462. var _display_utils = __w_pdfjs_require__(1);
  7463. var _annotation_storage = __w_pdfjs_require__(9);
  7464. var _scripting_utils = __w_pdfjs_require__(19);
  7465. var _xfa_layer = __w_pdfjs_require__(20);
  7466. const DEFAULT_TAB_INDEX = 1000;
  7467. const GetElementsByNameSet = new WeakSet();
  7468. class AnnotationElementFactory {
  7469. static create(parameters) {
  7470. const subtype = parameters.data.annotationType;
  7471. switch (subtype) {
  7472. case _util.AnnotationType.LINK:
  7473. return new LinkAnnotationElement(parameters);
  7474. case _util.AnnotationType.TEXT:
  7475. return new TextAnnotationElement(parameters);
  7476. case _util.AnnotationType.WIDGET:
  7477. const fieldType = parameters.data.fieldType;
  7478. switch (fieldType) {
  7479. case "Tx":
  7480. return new TextWidgetAnnotationElement(parameters);
  7481. case "Btn":
  7482. if (parameters.data.radioButton) {
  7483. return new RadioButtonWidgetAnnotationElement(parameters);
  7484. } else if (parameters.data.checkBox) {
  7485. return new CheckboxWidgetAnnotationElement(parameters);
  7486. }
  7487. return new PushButtonWidgetAnnotationElement(parameters);
  7488. case "Ch":
  7489. return new ChoiceWidgetAnnotationElement(parameters);
  7490. }
  7491. return new WidgetAnnotationElement(parameters);
  7492. case _util.AnnotationType.POPUP:
  7493. return new PopupAnnotationElement(parameters);
  7494. case _util.AnnotationType.FREETEXT:
  7495. return new FreeTextAnnotationElement(parameters);
  7496. case _util.AnnotationType.LINE:
  7497. return new LineAnnotationElement(parameters);
  7498. case _util.AnnotationType.SQUARE:
  7499. return new SquareAnnotationElement(parameters);
  7500. case _util.AnnotationType.CIRCLE:
  7501. return new CircleAnnotationElement(parameters);
  7502. case _util.AnnotationType.POLYLINE:
  7503. return new PolylineAnnotationElement(parameters);
  7504. case _util.AnnotationType.CARET:
  7505. return new CaretAnnotationElement(parameters);
  7506. case _util.AnnotationType.INK:
  7507. return new InkAnnotationElement(parameters);
  7508. case _util.AnnotationType.POLYGON:
  7509. return new PolygonAnnotationElement(parameters);
  7510. case _util.AnnotationType.HIGHLIGHT:
  7511. return new HighlightAnnotationElement(parameters);
  7512. case _util.AnnotationType.UNDERLINE:
  7513. return new UnderlineAnnotationElement(parameters);
  7514. case _util.AnnotationType.SQUIGGLY:
  7515. return new SquigglyAnnotationElement(parameters);
  7516. case _util.AnnotationType.STRIKEOUT:
  7517. return new StrikeOutAnnotationElement(parameters);
  7518. case _util.AnnotationType.STAMP:
  7519. return new StampAnnotationElement(parameters);
  7520. case _util.AnnotationType.FILEATTACHMENT:
  7521. return new FileAttachmentAnnotationElement(parameters);
  7522. default:
  7523. return new AnnotationElement(parameters);
  7524. }
  7525. }
  7526. }
  7527. class AnnotationElement {
  7528. constructor(parameters, {
  7529. isRenderable = false,
  7530. ignoreBorder = false,
  7531. createQuadrilaterals = false
  7532. } = {}) {
  7533. this.isRenderable = isRenderable;
  7534. this.data = parameters.data;
  7535. this.layer = parameters.layer;
  7536. this.page = parameters.page;
  7537. this.viewport = parameters.viewport;
  7538. this.linkService = parameters.linkService;
  7539. this.downloadManager = parameters.downloadManager;
  7540. this.imageResourcesPath = parameters.imageResourcesPath;
  7541. this.renderForms = parameters.renderForms;
  7542. this.svgFactory = parameters.svgFactory;
  7543. this.annotationStorage = parameters.annotationStorage;
  7544. this.enableScripting = parameters.enableScripting;
  7545. this.hasJSActions = parameters.hasJSActions;
  7546. this._fieldObjects = parameters.fieldObjects;
  7547. this._mouseState = parameters.mouseState;
  7548. if (isRenderable) {
  7549. this.container = this._createContainer(ignoreBorder);
  7550. }
  7551. if (createQuadrilaterals) {
  7552. this.quadrilaterals = this._createQuadrilaterals(ignoreBorder);
  7553. }
  7554. }
  7555. _createContainer(ignoreBorder = false) {
  7556. const data = this.data,
  7557. page = this.page,
  7558. viewport = this.viewport;
  7559. const container = document.createElement("section");
  7560. let width = data.rect[2] - data.rect[0];
  7561. let height = data.rect[3] - data.rect[1];
  7562. container.setAttribute("data-annotation-id", data.id);
  7563. 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]]);
  7564. if (data.hasOwnCanvas) {
  7565. const transform = viewport.transform.slice();
  7566. const [scaleX, scaleY] = _util.Util.singularValueDecompose2dScale(transform);
  7567. width = Math.ceil(width * scaleX);
  7568. height = Math.ceil(height * scaleY);
  7569. rect[0] *= scaleX;
  7570. rect[1] *= scaleY;
  7571. for (let i = 0; i < 4; i++) {
  7572. transform[i] = Math.sign(transform[i]);
  7573. }
  7574. container.style.transform = `matrix(${transform.join(",")})`;
  7575. } else {
  7576. container.style.transform = `matrix(${viewport.transform.join(",")})`;
  7577. }
  7578. container.style.transformOrigin = `${-rect[0]}px ${-rect[1]}px`;
  7579. if (!ignoreBorder && data.borderStyle.width > 0) {
  7580. container.style.borderWidth = `${data.borderStyle.width}px`;
  7581. if (data.borderStyle.style !== _util.AnnotationBorderStyleType.UNDERLINE) {
  7582. width -= 2 * data.borderStyle.width;
  7583. height -= 2 * data.borderStyle.width;
  7584. }
  7585. const horizontalRadius = data.borderStyle.horizontalCornerRadius;
  7586. const verticalRadius = data.borderStyle.verticalCornerRadius;
  7587. if (horizontalRadius > 0 || verticalRadius > 0) {
  7588. const radius = `${horizontalRadius}px / ${verticalRadius}px`;
  7589. container.style.borderRadius = radius;
  7590. }
  7591. switch (data.borderStyle.style) {
  7592. case _util.AnnotationBorderStyleType.SOLID:
  7593. container.style.borderStyle = "solid";
  7594. break;
  7595. case _util.AnnotationBorderStyleType.DASHED:
  7596. container.style.borderStyle = "dashed";
  7597. break;
  7598. case _util.AnnotationBorderStyleType.BEVELED:
  7599. (0, _util.warn)("Unimplemented border style: beveled");
  7600. break;
  7601. case _util.AnnotationBorderStyleType.INSET:
  7602. (0, _util.warn)("Unimplemented border style: inset");
  7603. break;
  7604. case _util.AnnotationBorderStyleType.UNDERLINE:
  7605. container.style.borderBottomStyle = "solid";
  7606. break;
  7607. default:
  7608. break;
  7609. }
  7610. const borderColor = data.borderColor || data.color || null;
  7611. if (borderColor) {
  7612. container.style.borderColor = _util.Util.makeHexColor(data.color[0] | 0, data.color[1] | 0, data.color[2] | 0);
  7613. } else {
  7614. container.style.borderWidth = 0;
  7615. }
  7616. }
  7617. container.style.left = `${rect[0]}px`;
  7618. container.style.top = `${rect[1]}px`;
  7619. if (data.hasOwnCanvas) {
  7620. container.style.width = container.style.height = "auto";
  7621. } else {
  7622. container.style.width = `${width}px`;
  7623. container.style.height = `${height}px`;
  7624. }
  7625. return container;
  7626. }
  7627. _createQuadrilaterals(ignoreBorder = false) {
  7628. if (!this.data.quadPoints) {
  7629. return null;
  7630. }
  7631. const quadrilaterals = [];
  7632. const savedRect = this.data.rect;
  7633. for (const quadPoint of this.data.quadPoints) {
  7634. this.data.rect = [quadPoint[2].x, quadPoint[2].y, quadPoint[1].x, quadPoint[1].y];
  7635. quadrilaterals.push(this._createContainer(ignoreBorder));
  7636. }
  7637. this.data.rect = savedRect;
  7638. return quadrilaterals;
  7639. }
  7640. _createPopup(trigger, data) {
  7641. let container = this.container;
  7642. if (this.quadrilaterals) {
  7643. trigger = trigger || this.quadrilaterals;
  7644. container = this.quadrilaterals[0];
  7645. }
  7646. if (!trigger) {
  7647. trigger = document.createElement("div");
  7648. trigger.style.height = container.style.height;
  7649. trigger.style.width = container.style.width;
  7650. container.appendChild(trigger);
  7651. }
  7652. const popupElement = new PopupElement({
  7653. container,
  7654. trigger,
  7655. color: data.color,
  7656. titleObj: data.titleObj,
  7657. modificationDate: data.modificationDate,
  7658. contentsObj: data.contentsObj,
  7659. richText: data.richText,
  7660. hideWrapper: true
  7661. });
  7662. const popup = popupElement.render();
  7663. popup.style.left = container.style.width;
  7664. container.appendChild(popup);
  7665. }
  7666. _renderQuadrilaterals(className) {
  7667. for (const quadrilateral of this.quadrilaterals) {
  7668. quadrilateral.className = className;
  7669. }
  7670. return this.quadrilaterals;
  7671. }
  7672. render() {
  7673. (0, _util.unreachable)("Abstract method `AnnotationElement.render` called");
  7674. }
  7675. _getElementsByName(name, skipId = null) {
  7676. const fields = [];
  7677. if (this._fieldObjects) {
  7678. const fieldObj = this._fieldObjects[name];
  7679. if (fieldObj) {
  7680. for (const {
  7681. page,
  7682. id,
  7683. exportValues
  7684. } of fieldObj) {
  7685. if (page === -1) {
  7686. continue;
  7687. }
  7688. if (id === skipId) {
  7689. continue;
  7690. }
  7691. const exportValue = typeof exportValues === "string" ? exportValues : null;
  7692. const domElement = document.getElementById(id);
  7693. if (domElement && !GetElementsByNameSet.has(domElement)) {
  7694. (0, _util.warn)(`_getElementsByName - element not allowed: ${id}`);
  7695. continue;
  7696. }
  7697. fields.push({
  7698. id,
  7699. exportValue,
  7700. domElement
  7701. });
  7702. }
  7703. }
  7704. return fields;
  7705. }
  7706. for (const domElement of document.getElementsByName(name)) {
  7707. const {
  7708. id,
  7709. exportValue
  7710. } = domElement;
  7711. if (id === skipId) {
  7712. continue;
  7713. }
  7714. if (!GetElementsByNameSet.has(domElement)) {
  7715. continue;
  7716. }
  7717. fields.push({
  7718. id,
  7719. exportValue,
  7720. domElement
  7721. });
  7722. }
  7723. return fields;
  7724. }
  7725. static get platform() {
  7726. const platform = typeof navigator !== "undefined" ? navigator.platform : "";
  7727. return (0, _util.shadow)(this, "platform", {
  7728. isWin: platform.includes("Win"),
  7729. isMac: platform.includes("Mac")
  7730. });
  7731. }
  7732. }
  7733. class LinkAnnotationElement extends AnnotationElement {
  7734. constructor(parameters, options = null) {
  7735. const isRenderable = !!(parameters.data.url || parameters.data.dest || parameters.data.action || parameters.data.isTooltipOnly || parameters.data.resetForm || parameters.data.actions && (parameters.data.actions.Action || parameters.data.actions["Mouse Up"] || parameters.data.actions["Mouse Down"]));
  7736. super(parameters, {
  7737. isRenderable,
  7738. ignoreBorder: !!options?.ignoreBorder,
  7739. createQuadrilaterals: true
  7740. });
  7741. }
  7742. render() {
  7743. const {
  7744. data,
  7745. linkService
  7746. } = this;
  7747. const link = document.createElement("a");
  7748. if (data.url) {
  7749. if (!linkService.addLinkAttributes) {
  7750. (0, _util.warn)("LinkAnnotationElement.render - missing `addLinkAttributes`-method on the `linkService`-instance.");
  7751. }
  7752. linkService.addLinkAttributes?.(link, data.url, data.newWindow);
  7753. } else if (data.action) {
  7754. this._bindNamedAction(link, data.action);
  7755. } else if (data.dest) {
  7756. this._bindLink(link, data.dest);
  7757. } else {
  7758. let hasClickAction = false;
  7759. if (data.actions && (data.actions.Action || data.actions["Mouse Up"] || data.actions["Mouse Down"]) && this.enableScripting && this.hasJSActions) {
  7760. hasClickAction = true;
  7761. this._bindJSAction(link, data);
  7762. }
  7763. if (data.resetForm) {
  7764. this._bindResetFormAction(link, data.resetForm);
  7765. } else if (!hasClickAction) {
  7766. this._bindLink(link, "");
  7767. }
  7768. }
  7769. if (this.quadrilaterals) {
  7770. return this._renderQuadrilaterals("linkAnnotation").map((quadrilateral, index) => {
  7771. const linkElement = index === 0 ? link : link.cloneNode();
  7772. quadrilateral.appendChild(linkElement);
  7773. return quadrilateral;
  7774. });
  7775. }
  7776. this.container.className = "linkAnnotation";
  7777. this.container.appendChild(link);
  7778. return this.container;
  7779. }
  7780. _bindLink(link, destination) {
  7781. link.href = this.linkService.getDestinationHash(destination);
  7782. link.onclick = () => {
  7783. if (destination) {
  7784. this.linkService.goToDestination(destination);
  7785. }
  7786. return false;
  7787. };
  7788. if (destination || destination === "") {
  7789. link.className = "internalLink";
  7790. }
  7791. }
  7792. _bindNamedAction(link, action) {
  7793. link.href = this.linkService.getAnchorUrl("");
  7794. link.onclick = () => {
  7795. this.linkService.executeNamedAction(action);
  7796. return false;
  7797. };
  7798. link.className = "internalLink";
  7799. }
  7800. _bindJSAction(link, data) {
  7801. link.href = this.linkService.getAnchorUrl("");
  7802. const map = new Map([["Action", "onclick"], ["Mouse Up", "onmouseup"], ["Mouse Down", "onmousedown"]]);
  7803. for (const name of Object.keys(data.actions)) {
  7804. const jsName = map.get(name);
  7805. if (!jsName) {
  7806. continue;
  7807. }
  7808. link[jsName] = () => {
  7809. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  7810. source: this,
  7811. detail: {
  7812. id: data.id,
  7813. name
  7814. }
  7815. });
  7816. return false;
  7817. };
  7818. }
  7819. if (!link.onclick) {
  7820. link.onclick = () => false;
  7821. }
  7822. link.className = "internalLink";
  7823. }
  7824. _bindResetFormAction(link, resetForm) {
  7825. const otherClickAction = link.onclick;
  7826. if (!otherClickAction) {
  7827. link.href = this.linkService.getAnchorUrl("");
  7828. }
  7829. link.className = "internalLink";
  7830. if (!this._fieldObjects) {
  7831. (0, _util.warn)(`_bindResetFormAction - "resetForm" action not supported, ` + "ensure that the `fieldObjects` parameter is provided.");
  7832. if (!otherClickAction) {
  7833. link.onclick = () => false;
  7834. }
  7835. return;
  7836. }
  7837. link.onclick = () => {
  7838. if (otherClickAction) {
  7839. otherClickAction();
  7840. }
  7841. const {
  7842. fields: resetFormFields,
  7843. refs: resetFormRefs,
  7844. include
  7845. } = resetForm;
  7846. const allFields = [];
  7847. if (resetFormFields.length !== 0 || resetFormRefs.length !== 0) {
  7848. const fieldIds = new Set(resetFormRefs);
  7849. for (const fieldName of resetFormFields) {
  7850. const fields = this._fieldObjects[fieldName] || [];
  7851. for (const {
  7852. id
  7853. } of fields) {
  7854. fieldIds.add(id);
  7855. }
  7856. }
  7857. for (const fields of Object.values(this._fieldObjects)) {
  7858. for (const field of fields) {
  7859. if (fieldIds.has(field.id) === include) {
  7860. allFields.push(field);
  7861. }
  7862. }
  7863. }
  7864. } else {
  7865. for (const fields of Object.values(this._fieldObjects)) {
  7866. allFields.push(...fields);
  7867. }
  7868. }
  7869. const storage = this.annotationStorage;
  7870. const allIds = [];
  7871. for (const field of allFields) {
  7872. const {
  7873. id
  7874. } = field;
  7875. allIds.push(id);
  7876. switch (field.type) {
  7877. case "text":
  7878. {
  7879. const value = field.defaultValue || "";
  7880. storage.setValue(id, {
  7881. value,
  7882. valueAsString: value
  7883. });
  7884. break;
  7885. }
  7886. case "checkbox":
  7887. case "radiobutton":
  7888. {
  7889. const value = field.defaultValue === field.exportValues;
  7890. storage.setValue(id, {
  7891. value
  7892. });
  7893. break;
  7894. }
  7895. case "combobox":
  7896. case "listbox":
  7897. {
  7898. const value = field.defaultValue || "";
  7899. storage.setValue(id, {
  7900. value
  7901. });
  7902. break;
  7903. }
  7904. default:
  7905. continue;
  7906. }
  7907. const domElement = document.getElementById(id);
  7908. if (!domElement || !GetElementsByNameSet.has(domElement)) {
  7909. continue;
  7910. }
  7911. domElement.dispatchEvent(new Event("resetform"));
  7912. }
  7913. if (this.enableScripting) {
  7914. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  7915. source: this,
  7916. detail: {
  7917. id: "app",
  7918. ids: allIds,
  7919. name: "ResetForm"
  7920. }
  7921. });
  7922. }
  7923. return false;
  7924. };
  7925. }
  7926. }
  7927. class TextAnnotationElement extends AnnotationElement {
  7928. constructor(parameters) {
  7929. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  7930. super(parameters, {
  7931. isRenderable
  7932. });
  7933. }
  7934. render() {
  7935. this.container.className = "textAnnotation";
  7936. const image = document.createElement("img");
  7937. image.style.height = this.container.style.height;
  7938. image.style.width = this.container.style.width;
  7939. image.src = this.imageResourcesPath + "annotation-" + this.data.name.toLowerCase() + ".svg";
  7940. image.alt = "[{{type}} Annotation]";
  7941. image.dataset.l10nId = "text_annotation_type";
  7942. image.dataset.l10nArgs = JSON.stringify({
  7943. type: this.data.name
  7944. });
  7945. if (!this.data.hasPopup) {
  7946. this._createPopup(image, this.data);
  7947. }
  7948. this.container.appendChild(image);
  7949. return this.container;
  7950. }
  7951. }
  7952. class WidgetAnnotationElement extends AnnotationElement {
  7953. render() {
  7954. if (this.data.alternativeText) {
  7955. this.container.title = this.data.alternativeText;
  7956. }
  7957. return this.container;
  7958. }
  7959. _getKeyModifier(event) {
  7960. const {
  7961. isWin,
  7962. isMac
  7963. } = AnnotationElement.platform;
  7964. return isWin && event.ctrlKey || isMac && event.metaKey;
  7965. }
  7966. _setEventListener(element, baseName, eventName, valueGetter) {
  7967. if (baseName.includes("mouse")) {
  7968. element.addEventListener(baseName, event => {
  7969. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  7970. source: this,
  7971. detail: {
  7972. id: this.data.id,
  7973. name: eventName,
  7974. value: valueGetter(event),
  7975. shift: event.shiftKey,
  7976. modifier: this._getKeyModifier(event)
  7977. }
  7978. });
  7979. });
  7980. } else {
  7981. element.addEventListener(baseName, event => {
  7982. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  7983. source: this,
  7984. detail: {
  7985. id: this.data.id,
  7986. name: eventName,
  7987. value: event.target.checked
  7988. }
  7989. });
  7990. });
  7991. }
  7992. }
  7993. _setEventListeners(element, names, getter) {
  7994. for (const [baseName, eventName] of names) {
  7995. if (eventName === "Action" || this.data.actions?.[eventName]) {
  7996. this._setEventListener(element, baseName, eventName, getter);
  7997. }
  7998. }
  7999. }
  8000. _setBackgroundColor(element) {
  8001. const color = this.data.backgroundColor || null;
  8002. element.style.backgroundColor = color === null ? "transparent" : _util.Util.makeHexColor(color[0], color[1], color[2]);
  8003. }
  8004. _dispatchEventFromSandbox(actions, jsEvent) {
  8005. const setColor = (jsName, styleName, event) => {
  8006. const color = event.detail[jsName];
  8007. event.target.style[styleName] = _scripting_utils.ColorConverters[`${color[0]}_HTML`](color.slice(1));
  8008. };
  8009. const commonActions = {
  8010. display: event => {
  8011. const hidden = event.detail.display % 2 === 1;
  8012. event.target.style.visibility = hidden ? "hidden" : "visible";
  8013. this.annotationStorage.setValue(this.data.id, {
  8014. hidden,
  8015. print: event.detail.display === 0 || event.detail.display === 3
  8016. });
  8017. },
  8018. print: event => {
  8019. this.annotationStorage.setValue(this.data.id, {
  8020. print: event.detail.print
  8021. });
  8022. },
  8023. hidden: event => {
  8024. event.target.style.visibility = event.detail.hidden ? "hidden" : "visible";
  8025. this.annotationStorage.setValue(this.data.id, {
  8026. hidden: event.detail.hidden
  8027. });
  8028. },
  8029. focus: event => {
  8030. setTimeout(() => event.target.focus({
  8031. preventScroll: false
  8032. }), 0);
  8033. },
  8034. userName: event => {
  8035. event.target.title = event.detail.userName;
  8036. },
  8037. readonly: event => {
  8038. if (event.detail.readonly) {
  8039. event.target.setAttribute("readonly", "");
  8040. } else {
  8041. event.target.removeAttribute("readonly");
  8042. }
  8043. },
  8044. required: event => {
  8045. if (event.detail.required) {
  8046. event.target.setAttribute("required", "");
  8047. } else {
  8048. event.target.removeAttribute("required");
  8049. }
  8050. },
  8051. bgColor: event => {
  8052. setColor("bgColor", "backgroundColor", event);
  8053. },
  8054. fillColor: event => {
  8055. setColor("fillColor", "backgroundColor", event);
  8056. },
  8057. fgColor: event => {
  8058. setColor("fgColor", "color", event);
  8059. },
  8060. textColor: event => {
  8061. setColor("textColor", "color", event);
  8062. },
  8063. borderColor: event => {
  8064. setColor("borderColor", "borderColor", event);
  8065. },
  8066. strokeColor: event => {
  8067. setColor("strokeColor", "borderColor", event);
  8068. }
  8069. };
  8070. for (const name of Object.keys(jsEvent.detail)) {
  8071. const action = actions[name] || commonActions[name];
  8072. if (action) {
  8073. action(jsEvent);
  8074. }
  8075. }
  8076. }
  8077. }
  8078. class TextWidgetAnnotationElement extends WidgetAnnotationElement {
  8079. constructor(parameters) {
  8080. const isRenderable = parameters.renderForms || !parameters.data.hasAppearance && !!parameters.data.fieldValue;
  8081. super(parameters, {
  8082. isRenderable
  8083. });
  8084. }
  8085. setPropertyOnSiblings(base, key, value, keyInStorage) {
  8086. const storage = this.annotationStorage;
  8087. for (const element of this._getElementsByName(base.name, base.id)) {
  8088. if (element.domElement) {
  8089. element.domElement[key] = value;
  8090. }
  8091. storage.setValue(element.id, {
  8092. [keyInStorage]: value
  8093. });
  8094. }
  8095. }
  8096. render() {
  8097. const storage = this.annotationStorage;
  8098. const id = this.data.id;
  8099. this.container.className = "textWidgetAnnotation";
  8100. let element = null;
  8101. if (this.renderForms) {
  8102. const storedData = storage.getValue(id, {
  8103. value: this.data.fieldValue,
  8104. valueAsString: this.data.fieldValue
  8105. });
  8106. const textContent = storedData.valueAsString || storedData.value || "";
  8107. const elementData = {
  8108. userValue: null,
  8109. formattedValue: null,
  8110. beforeInputSelectionRange: null,
  8111. beforeInputValue: null
  8112. };
  8113. if (this.data.multiLine) {
  8114. element = document.createElement("textarea");
  8115. element.textContent = textContent;
  8116. } else {
  8117. element = document.createElement("input");
  8118. element.type = "text";
  8119. element.setAttribute("value", textContent);
  8120. }
  8121. GetElementsByNameSet.add(element);
  8122. element.disabled = this.data.readOnly;
  8123. element.name = this.data.fieldName;
  8124. element.tabIndex = DEFAULT_TAB_INDEX;
  8125. elementData.userValue = textContent;
  8126. element.setAttribute("id", id);
  8127. element.addEventListener("input", event => {
  8128. storage.setValue(id, {
  8129. value: event.target.value
  8130. });
  8131. this.setPropertyOnSiblings(element, "value", event.target.value, "value");
  8132. });
  8133. element.addEventListener("resetform", event => {
  8134. const defaultValue = this.data.defaultFieldValue || "";
  8135. element.value = elementData.userValue = defaultValue;
  8136. delete elementData.formattedValue;
  8137. });
  8138. let blurListener = event => {
  8139. if (elementData.formattedValue) {
  8140. event.target.value = elementData.formattedValue;
  8141. }
  8142. event.target.scrollLeft = 0;
  8143. elementData.beforeInputSelectionRange = null;
  8144. };
  8145. if (this.enableScripting && this.hasJSActions) {
  8146. element.addEventListener("focus", event => {
  8147. if (elementData.userValue) {
  8148. event.target.value = elementData.userValue;
  8149. }
  8150. });
  8151. element.addEventListener("updatefromsandbox", jsEvent => {
  8152. const actions = {
  8153. value(event) {
  8154. elementData.userValue = event.detail.value || "";
  8155. storage.setValue(id, {
  8156. value: elementData.userValue.toString()
  8157. });
  8158. if (!elementData.formattedValue) {
  8159. event.target.value = elementData.userValue;
  8160. }
  8161. },
  8162. valueAsString(event) {
  8163. elementData.formattedValue = event.detail.valueAsString || "";
  8164. if (event.target !== document.activeElement) {
  8165. event.target.value = elementData.formattedValue;
  8166. }
  8167. storage.setValue(id, {
  8168. formattedValue: elementData.formattedValue
  8169. });
  8170. },
  8171. selRange(event) {
  8172. const [selStart, selEnd] = event.detail.selRange;
  8173. if (selStart >= 0 && selEnd < event.target.value.length) {
  8174. event.target.setSelectionRange(selStart, selEnd);
  8175. }
  8176. }
  8177. };
  8178. this._dispatchEventFromSandbox(actions, jsEvent);
  8179. });
  8180. element.addEventListener("keydown", event => {
  8181. elementData.beforeInputValue = event.target.value;
  8182. let commitKey = -1;
  8183. if (event.key === "Escape") {
  8184. commitKey = 0;
  8185. } else if (event.key === "Enter") {
  8186. commitKey = 2;
  8187. } else if (event.key === "Tab") {
  8188. commitKey = 3;
  8189. }
  8190. if (commitKey === -1) {
  8191. return;
  8192. }
  8193. elementData.userValue = event.target.value;
  8194. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  8195. source: this,
  8196. detail: {
  8197. id,
  8198. name: "Keystroke",
  8199. value: event.target.value,
  8200. willCommit: true,
  8201. commitKey,
  8202. selStart: event.target.selectionStart,
  8203. selEnd: event.target.selectionEnd
  8204. }
  8205. });
  8206. });
  8207. const _blurListener = blurListener;
  8208. blurListener = null;
  8209. element.addEventListener("blur", event => {
  8210. if (this._mouseState.isDown) {
  8211. elementData.userValue = event.target.value;
  8212. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  8213. source: this,
  8214. detail: {
  8215. id,
  8216. name: "Keystroke",
  8217. value: event.target.value,
  8218. willCommit: true,
  8219. commitKey: 1,
  8220. selStart: event.target.selectionStart,
  8221. selEnd: event.target.selectionEnd
  8222. }
  8223. });
  8224. }
  8225. _blurListener(event);
  8226. });
  8227. element.addEventListener("mousedown", event => {
  8228. elementData.beforeInputValue = event.target.value;
  8229. elementData.beforeInputSelectionRange = null;
  8230. });
  8231. element.addEventListener("keyup", event => {
  8232. if (event.target.selectionStart === event.target.selectionEnd) {
  8233. elementData.beforeInputSelectionRange = null;
  8234. }
  8235. });
  8236. element.addEventListener("select", event => {
  8237. elementData.beforeInputSelectionRange = [event.target.selectionStart, event.target.selectionEnd];
  8238. });
  8239. if (this.data.actions?.Keystroke) {
  8240. element.addEventListener("input", event => {
  8241. let selStart = -1;
  8242. let selEnd = -1;
  8243. if (elementData.beforeInputSelectionRange) {
  8244. [selStart, selEnd] = elementData.beforeInputSelectionRange;
  8245. }
  8246. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  8247. source: this,
  8248. detail: {
  8249. id,
  8250. name: "Keystroke",
  8251. value: elementData.beforeInputValue,
  8252. change: event.data,
  8253. willCommit: false,
  8254. selStart,
  8255. selEnd
  8256. }
  8257. });
  8258. });
  8259. }
  8260. this._setEventListeners(element, [["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"]], event => event.target.value);
  8261. }
  8262. if (blurListener) {
  8263. element.addEventListener("blur", blurListener);
  8264. }
  8265. if (this.data.maxLen !== null) {
  8266. element.maxLength = this.data.maxLen;
  8267. }
  8268. if (this.data.comb) {
  8269. const fieldWidth = this.data.rect[2] - this.data.rect[0];
  8270. const combWidth = fieldWidth / this.data.maxLen;
  8271. element.classList.add("comb");
  8272. element.style.letterSpacing = `calc(${combWidth}px - 1ch)`;
  8273. }
  8274. } else {
  8275. element = document.createElement("div");
  8276. element.textContent = this.data.fieldValue;
  8277. element.style.verticalAlign = "middle";
  8278. element.style.display = "table-cell";
  8279. }
  8280. this._setTextStyle(element);
  8281. this._setBackgroundColor(element);
  8282. this.container.appendChild(element);
  8283. return this.container;
  8284. }
  8285. _setTextStyle(element) {
  8286. const TEXT_ALIGNMENT = ["left", "center", "right"];
  8287. const {
  8288. fontSize,
  8289. fontColor
  8290. } = this.data.defaultAppearanceData;
  8291. const style = element.style;
  8292. if (fontSize) {
  8293. style.fontSize = `${fontSize}px`;
  8294. }
  8295. style.color = _util.Util.makeHexColor(fontColor[0], fontColor[1], fontColor[2]);
  8296. if (this.data.textAlignment !== null) {
  8297. style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
  8298. }
  8299. }
  8300. }
  8301. class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement {
  8302. constructor(parameters) {
  8303. super(parameters, {
  8304. isRenderable: parameters.renderForms
  8305. });
  8306. }
  8307. render() {
  8308. const storage = this.annotationStorage;
  8309. const data = this.data;
  8310. const id = data.id;
  8311. let value = storage.getValue(id, {
  8312. value: data.exportValue === data.fieldValue
  8313. }).value;
  8314. if (typeof value === "string") {
  8315. value = value !== "Off";
  8316. storage.setValue(id, {
  8317. value
  8318. });
  8319. }
  8320. this.container.className = "buttonWidgetAnnotation checkBox";
  8321. const element = document.createElement("input");
  8322. GetElementsByNameSet.add(element);
  8323. element.disabled = data.readOnly;
  8324. element.type = "checkbox";
  8325. element.name = data.fieldName;
  8326. if (value) {
  8327. element.setAttribute("checked", true);
  8328. }
  8329. element.setAttribute("id", id);
  8330. element.setAttribute("exportValue", data.exportValue);
  8331. element.tabIndex = DEFAULT_TAB_INDEX;
  8332. element.addEventListener("change", event => {
  8333. const {
  8334. name,
  8335. checked
  8336. } = event.target;
  8337. for (const checkbox of this._getElementsByName(name, id)) {
  8338. const curChecked = checked && checkbox.exportValue === data.exportValue;
  8339. if (checkbox.domElement) {
  8340. checkbox.domElement.checked = curChecked;
  8341. }
  8342. storage.setValue(checkbox.id, {
  8343. value: curChecked
  8344. });
  8345. }
  8346. storage.setValue(id, {
  8347. value: checked
  8348. });
  8349. });
  8350. element.addEventListener("resetform", event => {
  8351. const defaultValue = data.defaultFieldValue || "Off";
  8352. event.target.checked = defaultValue === data.exportValue;
  8353. });
  8354. if (this.enableScripting && this.hasJSActions) {
  8355. element.addEventListener("updatefromsandbox", jsEvent => {
  8356. const actions = {
  8357. value(event) {
  8358. event.target.checked = event.detail.value !== "Off";
  8359. storage.setValue(id, {
  8360. value: event.target.checked
  8361. });
  8362. }
  8363. };
  8364. this._dispatchEventFromSandbox(actions, jsEvent);
  8365. });
  8366. 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);
  8367. }
  8368. this._setBackgroundColor(element);
  8369. this.container.appendChild(element);
  8370. return this.container;
  8371. }
  8372. }
  8373. class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
  8374. constructor(parameters) {
  8375. super(parameters, {
  8376. isRenderable: parameters.renderForms
  8377. });
  8378. }
  8379. render() {
  8380. this.container.className = "buttonWidgetAnnotation radioButton";
  8381. const storage = this.annotationStorage;
  8382. const data = this.data;
  8383. const id = data.id;
  8384. let value = storage.getValue(id, {
  8385. value: data.fieldValue === data.buttonValue
  8386. }).value;
  8387. if (typeof value === "string") {
  8388. value = value !== data.buttonValue;
  8389. storage.setValue(id, {
  8390. value
  8391. });
  8392. }
  8393. const element = document.createElement("input");
  8394. GetElementsByNameSet.add(element);
  8395. element.disabled = data.readOnly;
  8396. element.type = "radio";
  8397. element.name = data.fieldName;
  8398. if (value) {
  8399. element.setAttribute("checked", true);
  8400. }
  8401. element.setAttribute("id", id);
  8402. element.tabIndex = DEFAULT_TAB_INDEX;
  8403. element.addEventListener("change", event => {
  8404. const {
  8405. name,
  8406. checked
  8407. } = event.target;
  8408. for (const radio of this._getElementsByName(name, id)) {
  8409. storage.setValue(radio.id, {
  8410. value: false
  8411. });
  8412. }
  8413. storage.setValue(id, {
  8414. value: checked
  8415. });
  8416. });
  8417. element.addEventListener("resetform", event => {
  8418. const defaultValue = data.defaultFieldValue;
  8419. event.target.checked = defaultValue !== null && defaultValue !== undefined && defaultValue === data.buttonValue;
  8420. });
  8421. if (this.enableScripting && this.hasJSActions) {
  8422. const pdfButtonValue = data.buttonValue;
  8423. element.addEventListener("updatefromsandbox", jsEvent => {
  8424. const actions = {
  8425. value: event => {
  8426. const checked = pdfButtonValue === event.detail.value;
  8427. for (const radio of this._getElementsByName(event.target.name)) {
  8428. const curChecked = checked && radio.id === id;
  8429. if (radio.domElement) {
  8430. radio.domElement.checked = curChecked;
  8431. }
  8432. storage.setValue(radio.id, {
  8433. value: curChecked
  8434. });
  8435. }
  8436. }
  8437. };
  8438. this._dispatchEventFromSandbox(actions, jsEvent);
  8439. });
  8440. 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);
  8441. }
  8442. this._setBackgroundColor(element);
  8443. this.container.appendChild(element);
  8444. return this.container;
  8445. }
  8446. }
  8447. class PushButtonWidgetAnnotationElement extends LinkAnnotationElement {
  8448. constructor(parameters) {
  8449. super(parameters, {
  8450. ignoreBorder: parameters.data.hasAppearance
  8451. });
  8452. }
  8453. render() {
  8454. const container = super.render();
  8455. container.className = "buttonWidgetAnnotation pushButton";
  8456. if (this.data.alternativeText) {
  8457. container.title = this.data.alternativeText;
  8458. }
  8459. return container;
  8460. }
  8461. }
  8462. class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
  8463. constructor(parameters) {
  8464. super(parameters, {
  8465. isRenderable: parameters.renderForms
  8466. });
  8467. }
  8468. render() {
  8469. this.container.className = "choiceWidgetAnnotation";
  8470. const storage = this.annotationStorage;
  8471. const id = this.data.id;
  8472. storage.getValue(id, {
  8473. value: this.data.fieldValue.length > 0 ? this.data.fieldValue[0] : undefined
  8474. });
  8475. let {
  8476. fontSize
  8477. } = this.data.defaultAppearanceData;
  8478. if (!fontSize) {
  8479. fontSize = 9;
  8480. }
  8481. const fontSizeStyle = `calc(${fontSize}px * var(--zoom-factor))`;
  8482. const selectElement = document.createElement("select");
  8483. GetElementsByNameSet.add(selectElement);
  8484. selectElement.disabled = this.data.readOnly;
  8485. selectElement.name = this.data.fieldName;
  8486. selectElement.setAttribute("id", id);
  8487. selectElement.tabIndex = DEFAULT_TAB_INDEX;
  8488. selectElement.style.fontSize = `${fontSize}px`;
  8489. if (!this.data.combo) {
  8490. selectElement.size = this.data.options.length;
  8491. if (this.data.multiSelect) {
  8492. selectElement.multiple = true;
  8493. }
  8494. }
  8495. selectElement.addEventListener("resetform", event => {
  8496. const defaultValue = this.data.defaultFieldValue;
  8497. for (const option of selectElement.options) {
  8498. option.selected = option.value === defaultValue;
  8499. }
  8500. });
  8501. for (const option of this.data.options) {
  8502. const optionElement = document.createElement("option");
  8503. optionElement.textContent = option.displayValue;
  8504. optionElement.value = option.exportValue;
  8505. if (this.data.combo) {
  8506. optionElement.style.fontSize = fontSizeStyle;
  8507. }
  8508. if (this.data.fieldValue.includes(option.exportValue)) {
  8509. optionElement.setAttribute("selected", true);
  8510. }
  8511. selectElement.appendChild(optionElement);
  8512. }
  8513. const getValue = (event, isExport) => {
  8514. const name = isExport ? "value" : "textContent";
  8515. const options = event.target.options;
  8516. if (!event.target.multiple) {
  8517. return options.selectedIndex === -1 ? null : options[options.selectedIndex][name];
  8518. }
  8519. return Array.prototype.filter.call(options, option => option.selected).map(option => option[name]);
  8520. };
  8521. const getItems = event => {
  8522. const options = event.target.options;
  8523. return Array.prototype.map.call(options, option => {
  8524. return {
  8525. displayValue: option.textContent,
  8526. exportValue: option.value
  8527. };
  8528. });
  8529. };
  8530. if (this.enableScripting && this.hasJSActions) {
  8531. selectElement.addEventListener("updatefromsandbox", jsEvent => {
  8532. const actions = {
  8533. value(event) {
  8534. const value = event.detail.value;
  8535. const values = new Set(Array.isArray(value) ? value : [value]);
  8536. for (const option of selectElement.options) {
  8537. option.selected = values.has(option.value);
  8538. }
  8539. storage.setValue(id, {
  8540. value: getValue(event, true)
  8541. });
  8542. },
  8543. multipleSelection(event) {
  8544. selectElement.multiple = true;
  8545. },
  8546. remove(event) {
  8547. const options = selectElement.options;
  8548. const index = event.detail.remove;
  8549. options[index].selected = false;
  8550. selectElement.remove(index);
  8551. if (options.length > 0) {
  8552. const i = Array.prototype.findIndex.call(options, option => option.selected);
  8553. if (i === -1) {
  8554. options[0].selected = true;
  8555. }
  8556. }
  8557. storage.setValue(id, {
  8558. value: getValue(event, true),
  8559. items: getItems(event)
  8560. });
  8561. },
  8562. clear(event) {
  8563. while (selectElement.length !== 0) {
  8564. selectElement.remove(0);
  8565. }
  8566. storage.setValue(id, {
  8567. value: null,
  8568. items: []
  8569. });
  8570. },
  8571. insert(event) {
  8572. const {
  8573. index,
  8574. displayValue,
  8575. exportValue
  8576. } = event.detail.insert;
  8577. const optionElement = document.createElement("option");
  8578. optionElement.textContent = displayValue;
  8579. optionElement.value = exportValue;
  8580. selectElement.insertBefore(optionElement, selectElement.children[index]);
  8581. storage.setValue(id, {
  8582. value: getValue(event, true),
  8583. items: getItems(event)
  8584. });
  8585. },
  8586. items(event) {
  8587. const {
  8588. items
  8589. } = event.detail;
  8590. while (selectElement.length !== 0) {
  8591. selectElement.remove(0);
  8592. }
  8593. for (const item of items) {
  8594. const {
  8595. displayValue,
  8596. exportValue
  8597. } = item;
  8598. const optionElement = document.createElement("option");
  8599. optionElement.textContent = displayValue;
  8600. optionElement.value = exportValue;
  8601. selectElement.appendChild(optionElement);
  8602. }
  8603. if (selectElement.options.length > 0) {
  8604. selectElement.options[0].selected = true;
  8605. }
  8606. storage.setValue(id, {
  8607. value: getValue(event, true),
  8608. items: getItems(event)
  8609. });
  8610. },
  8611. indices(event) {
  8612. const indices = new Set(event.detail.indices);
  8613. for (const option of event.target.options) {
  8614. option.selected = indices.has(option.index);
  8615. }
  8616. storage.setValue(id, {
  8617. value: getValue(event, true)
  8618. });
  8619. },
  8620. editable(event) {
  8621. event.target.disabled = !event.detail.editable;
  8622. }
  8623. };
  8624. this._dispatchEventFromSandbox(actions, jsEvent);
  8625. });
  8626. selectElement.addEventListener("input", event => {
  8627. const exportValue = getValue(event, true);
  8628. const value = getValue(event, false);
  8629. storage.setValue(id, {
  8630. value: exportValue
  8631. });
  8632. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  8633. source: this,
  8634. detail: {
  8635. id,
  8636. name: "Keystroke",
  8637. value,
  8638. changeEx: exportValue,
  8639. willCommit: true,
  8640. commitKey: 1,
  8641. keyDown: false
  8642. }
  8643. });
  8644. });
  8645. this._setEventListeners(selectElement, [["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"], ["input", "Action"]], event => event.target.checked);
  8646. } else {
  8647. selectElement.addEventListener("input", function (event) {
  8648. storage.setValue(id, {
  8649. value: getValue(event)
  8650. });
  8651. });
  8652. }
  8653. this._setBackgroundColor(selectElement);
  8654. this.container.appendChild(selectElement);
  8655. return this.container;
  8656. }
  8657. }
  8658. class PopupAnnotationElement extends AnnotationElement {
  8659. constructor(parameters) {
  8660. const isRenderable = !!(parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  8661. super(parameters, {
  8662. isRenderable
  8663. });
  8664. }
  8665. render() {
  8666. const IGNORE_TYPES = ["Line", "Square", "Circle", "PolyLine", "Polygon", "Ink"];
  8667. this.container.className = "popupAnnotation";
  8668. if (IGNORE_TYPES.includes(this.data.parentType)) {
  8669. return this.container;
  8670. }
  8671. const selector = `[data-annotation-id="${this.data.parentId}"]`;
  8672. const parentElements = this.layer.querySelectorAll(selector);
  8673. if (parentElements.length === 0) {
  8674. return this.container;
  8675. }
  8676. const popup = new PopupElement({
  8677. container: this.container,
  8678. trigger: Array.from(parentElements),
  8679. color: this.data.color,
  8680. titleObj: this.data.titleObj,
  8681. modificationDate: this.data.modificationDate,
  8682. contentsObj: this.data.contentsObj,
  8683. richText: this.data.richText
  8684. });
  8685. const page = this.page;
  8686. 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]]);
  8687. const popupLeft = rect[0] + this.data.parentRect[2] - this.data.parentRect[0];
  8688. const popupTop = rect[1];
  8689. this.container.style.transformOrigin = `${-popupLeft}px ${-popupTop}px`;
  8690. this.container.style.left = `${popupLeft}px`;
  8691. this.container.style.top = `${popupTop}px`;
  8692. this.container.appendChild(popup.render());
  8693. return this.container;
  8694. }
  8695. }
  8696. class PopupElement {
  8697. constructor(parameters) {
  8698. this.container = parameters.container;
  8699. this.trigger = parameters.trigger;
  8700. this.color = parameters.color;
  8701. this.titleObj = parameters.titleObj;
  8702. this.modificationDate = parameters.modificationDate;
  8703. this.contentsObj = parameters.contentsObj;
  8704. this.richText = parameters.richText;
  8705. this.hideWrapper = parameters.hideWrapper || false;
  8706. this.pinned = false;
  8707. }
  8708. render() {
  8709. const BACKGROUND_ENLIGHT = 0.7;
  8710. const wrapper = document.createElement("div");
  8711. wrapper.className = "popupWrapper";
  8712. this.hideElement = this.hideWrapper ? wrapper : this.container;
  8713. this.hideElement.hidden = true;
  8714. const popup = document.createElement("div");
  8715. popup.className = "popup";
  8716. const color = this.color;
  8717. if (color) {
  8718. const r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  8719. const g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  8720. const b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  8721. popup.style.backgroundColor = _util.Util.makeHexColor(r | 0, g | 0, b | 0);
  8722. }
  8723. const title = document.createElement("h1");
  8724. title.dir = this.titleObj.dir;
  8725. title.textContent = this.titleObj.str;
  8726. popup.appendChild(title);
  8727. const dateObject = _display_utils.PDFDateString.toDateObject(this.modificationDate);
  8728. if (dateObject) {
  8729. const modificationDate = document.createElement("span");
  8730. modificationDate.className = "popupDate";
  8731. modificationDate.textContent = "{{date}}, {{time}}";
  8732. modificationDate.dataset.l10nId = "annotation_date_string";
  8733. modificationDate.dataset.l10nArgs = JSON.stringify({
  8734. date: dateObject.toLocaleDateString(),
  8735. time: dateObject.toLocaleTimeString()
  8736. });
  8737. popup.appendChild(modificationDate);
  8738. }
  8739. if (this.richText?.str && (!this.contentsObj?.str || this.contentsObj.str === this.richText.str)) {
  8740. _xfa_layer.XfaLayer.render({
  8741. xfaHtml: this.richText.html,
  8742. intent: "richText",
  8743. div: popup
  8744. });
  8745. popup.lastChild.className = "richText popupContent";
  8746. } else {
  8747. const contents = this._formatContents(this.contentsObj);
  8748. popup.appendChild(contents);
  8749. }
  8750. if (!Array.isArray(this.trigger)) {
  8751. this.trigger = [this.trigger];
  8752. }
  8753. for (const element of this.trigger) {
  8754. element.addEventListener("click", this._toggle.bind(this));
  8755. element.addEventListener("mouseover", this._show.bind(this, false));
  8756. element.addEventListener("mouseout", this._hide.bind(this, false));
  8757. }
  8758. popup.addEventListener("click", this._hide.bind(this, true));
  8759. wrapper.appendChild(popup);
  8760. return wrapper;
  8761. }
  8762. _formatContents({
  8763. str,
  8764. dir
  8765. }) {
  8766. const p = document.createElement("p");
  8767. p.className = "popupContent";
  8768. p.dir = dir;
  8769. const lines = str.split(/(?:\r\n?|\n)/);
  8770. for (let i = 0, ii = lines.length; i < ii; ++i) {
  8771. const line = lines[i];
  8772. p.appendChild(document.createTextNode(line));
  8773. if (i < ii - 1) {
  8774. p.appendChild(document.createElement("br"));
  8775. }
  8776. }
  8777. return p;
  8778. }
  8779. _toggle() {
  8780. if (this.pinned) {
  8781. this._hide(true);
  8782. } else {
  8783. this._show(true);
  8784. }
  8785. }
  8786. _show(pin = false) {
  8787. if (pin) {
  8788. this.pinned = true;
  8789. }
  8790. if (this.hideElement.hidden) {
  8791. this.hideElement.hidden = false;
  8792. this.container.style.zIndex += 1;
  8793. }
  8794. }
  8795. _hide(unpin = true) {
  8796. if (unpin) {
  8797. this.pinned = false;
  8798. }
  8799. if (!this.hideElement.hidden && !this.pinned) {
  8800. this.hideElement.hidden = true;
  8801. this.container.style.zIndex -= 1;
  8802. }
  8803. }
  8804. }
  8805. class FreeTextAnnotationElement extends AnnotationElement {
  8806. constructor(parameters) {
  8807. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  8808. super(parameters, {
  8809. isRenderable,
  8810. ignoreBorder: true
  8811. });
  8812. }
  8813. render() {
  8814. this.container.className = "freeTextAnnotation";
  8815. if (!this.data.hasPopup) {
  8816. this._createPopup(null, this.data);
  8817. }
  8818. return this.container;
  8819. }
  8820. }
  8821. class LineAnnotationElement extends AnnotationElement {
  8822. constructor(parameters) {
  8823. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  8824. super(parameters, {
  8825. isRenderable,
  8826. ignoreBorder: true
  8827. });
  8828. }
  8829. render() {
  8830. this.container.className = "lineAnnotation";
  8831. const data = this.data;
  8832. const width = data.rect[2] - data.rect[0];
  8833. const height = data.rect[3] - data.rect[1];
  8834. const svg = this.svgFactory.create(width, height);
  8835. const line = this.svgFactory.createElement("svg:line");
  8836. line.setAttribute("x1", data.rect[2] - data.lineCoordinates[0]);
  8837. line.setAttribute("y1", data.rect[3] - data.lineCoordinates[1]);
  8838. line.setAttribute("x2", data.rect[2] - data.lineCoordinates[2]);
  8839. line.setAttribute("y2", data.rect[3] - data.lineCoordinates[3]);
  8840. line.setAttribute("stroke-width", data.borderStyle.width || 1);
  8841. line.setAttribute("stroke", "transparent");
  8842. line.setAttribute("fill", "transparent");
  8843. svg.appendChild(line);
  8844. this.container.append(svg);
  8845. this._createPopup(line, data);
  8846. return this.container;
  8847. }
  8848. }
  8849. class SquareAnnotationElement extends AnnotationElement {
  8850. constructor(parameters) {
  8851. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  8852. super(parameters, {
  8853. isRenderable,
  8854. ignoreBorder: true
  8855. });
  8856. }
  8857. render() {
  8858. this.container.className = "squareAnnotation";
  8859. const data = this.data;
  8860. const width = data.rect[2] - data.rect[0];
  8861. const height = data.rect[3] - data.rect[1];
  8862. const svg = this.svgFactory.create(width, height);
  8863. const borderWidth = data.borderStyle.width;
  8864. const square = this.svgFactory.createElement("svg:rect");
  8865. square.setAttribute("x", borderWidth / 2);
  8866. square.setAttribute("y", borderWidth / 2);
  8867. square.setAttribute("width", width - borderWidth);
  8868. square.setAttribute("height", height - borderWidth);
  8869. square.setAttribute("stroke-width", borderWidth || 1);
  8870. square.setAttribute("stroke", "transparent");
  8871. square.setAttribute("fill", "transparent");
  8872. svg.appendChild(square);
  8873. this.container.append(svg);
  8874. this._createPopup(square, data);
  8875. return this.container;
  8876. }
  8877. }
  8878. class CircleAnnotationElement extends AnnotationElement {
  8879. constructor(parameters) {
  8880. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  8881. super(parameters, {
  8882. isRenderable,
  8883. ignoreBorder: true
  8884. });
  8885. }
  8886. render() {
  8887. this.container.className = "circleAnnotation";
  8888. const data = this.data;
  8889. const width = data.rect[2] - data.rect[0];
  8890. const height = data.rect[3] - data.rect[1];
  8891. const svg = this.svgFactory.create(width, height);
  8892. const borderWidth = data.borderStyle.width;
  8893. const circle = this.svgFactory.createElement("svg:ellipse");
  8894. circle.setAttribute("cx", width / 2);
  8895. circle.setAttribute("cy", height / 2);
  8896. circle.setAttribute("rx", width / 2 - borderWidth / 2);
  8897. circle.setAttribute("ry", height / 2 - borderWidth / 2);
  8898. circle.setAttribute("stroke-width", borderWidth || 1);
  8899. circle.setAttribute("stroke", "transparent");
  8900. circle.setAttribute("fill", "transparent");
  8901. svg.appendChild(circle);
  8902. this.container.append(svg);
  8903. this._createPopup(circle, data);
  8904. return this.container;
  8905. }
  8906. }
  8907. class PolylineAnnotationElement extends AnnotationElement {
  8908. constructor(parameters) {
  8909. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  8910. super(parameters, {
  8911. isRenderable,
  8912. ignoreBorder: true
  8913. });
  8914. this.containerClassName = "polylineAnnotation";
  8915. this.svgElementName = "svg:polyline";
  8916. }
  8917. render() {
  8918. this.container.className = this.containerClassName;
  8919. const data = this.data;
  8920. const width = data.rect[2] - data.rect[0];
  8921. const height = data.rect[3] - data.rect[1];
  8922. const svg = this.svgFactory.create(width, height);
  8923. let points = [];
  8924. for (const coordinate of data.vertices) {
  8925. const x = coordinate.x - data.rect[0];
  8926. const y = data.rect[3] - coordinate.y;
  8927. points.push(x + "," + y);
  8928. }
  8929. points = points.join(" ");
  8930. const polyline = this.svgFactory.createElement(this.svgElementName);
  8931. polyline.setAttribute("points", points);
  8932. polyline.setAttribute("stroke-width", data.borderStyle.width || 1);
  8933. polyline.setAttribute("stroke", "transparent");
  8934. polyline.setAttribute("fill", "transparent");
  8935. svg.appendChild(polyline);
  8936. this.container.append(svg);
  8937. this._createPopup(polyline, data);
  8938. return this.container;
  8939. }
  8940. }
  8941. class PolygonAnnotationElement extends PolylineAnnotationElement {
  8942. constructor(parameters) {
  8943. super(parameters);
  8944. this.containerClassName = "polygonAnnotation";
  8945. this.svgElementName = "svg:polygon";
  8946. }
  8947. }
  8948. class CaretAnnotationElement extends AnnotationElement {
  8949. constructor(parameters) {
  8950. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  8951. super(parameters, {
  8952. isRenderable,
  8953. ignoreBorder: true
  8954. });
  8955. }
  8956. render() {
  8957. this.container.className = "caretAnnotation";
  8958. if (!this.data.hasPopup) {
  8959. this._createPopup(null, this.data);
  8960. }
  8961. return this.container;
  8962. }
  8963. }
  8964. class InkAnnotationElement extends AnnotationElement {
  8965. constructor(parameters) {
  8966. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  8967. super(parameters, {
  8968. isRenderable,
  8969. ignoreBorder: true
  8970. });
  8971. this.containerClassName = "inkAnnotation";
  8972. this.svgElementName = "svg:polyline";
  8973. }
  8974. render() {
  8975. this.container.className = this.containerClassName;
  8976. const data = this.data;
  8977. const width = data.rect[2] - data.rect[0];
  8978. const height = data.rect[3] - data.rect[1];
  8979. const svg = this.svgFactory.create(width, height);
  8980. for (const inkList of data.inkLists) {
  8981. let points = [];
  8982. for (const coordinate of inkList) {
  8983. const x = coordinate.x - data.rect[0];
  8984. const y = data.rect[3] - coordinate.y;
  8985. points.push(`${x},${y}`);
  8986. }
  8987. points = points.join(" ");
  8988. const polyline = this.svgFactory.createElement(this.svgElementName);
  8989. polyline.setAttribute("points", points);
  8990. polyline.setAttribute("stroke-width", data.borderStyle.width || 1);
  8991. polyline.setAttribute("stroke", "transparent");
  8992. polyline.setAttribute("fill", "transparent");
  8993. this._createPopup(polyline, data);
  8994. svg.appendChild(polyline);
  8995. }
  8996. this.container.append(svg);
  8997. return this.container;
  8998. }
  8999. }
  9000. class HighlightAnnotationElement extends AnnotationElement {
  9001. constructor(parameters) {
  9002. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  9003. super(parameters, {
  9004. isRenderable,
  9005. ignoreBorder: true,
  9006. createQuadrilaterals: true
  9007. });
  9008. }
  9009. render() {
  9010. if (!this.data.hasPopup) {
  9011. this._createPopup(null, this.data);
  9012. }
  9013. if (this.quadrilaterals) {
  9014. return this._renderQuadrilaterals("highlightAnnotation");
  9015. }
  9016. this.container.className = "highlightAnnotation";
  9017. return this.container;
  9018. }
  9019. }
  9020. class UnderlineAnnotationElement extends AnnotationElement {
  9021. constructor(parameters) {
  9022. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  9023. super(parameters, {
  9024. isRenderable,
  9025. ignoreBorder: true,
  9026. createQuadrilaterals: true
  9027. });
  9028. }
  9029. render() {
  9030. if (!this.data.hasPopup) {
  9031. this._createPopup(null, this.data);
  9032. }
  9033. if (this.quadrilaterals) {
  9034. return this._renderQuadrilaterals("underlineAnnotation");
  9035. }
  9036. this.container.className = "underlineAnnotation";
  9037. return this.container;
  9038. }
  9039. }
  9040. class SquigglyAnnotationElement extends AnnotationElement {
  9041. constructor(parameters) {
  9042. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  9043. super(parameters, {
  9044. isRenderable,
  9045. ignoreBorder: true,
  9046. createQuadrilaterals: true
  9047. });
  9048. }
  9049. render() {
  9050. if (!this.data.hasPopup) {
  9051. this._createPopup(null, this.data);
  9052. }
  9053. if (this.quadrilaterals) {
  9054. return this._renderQuadrilaterals("squigglyAnnotation");
  9055. }
  9056. this.container.className = "squigglyAnnotation";
  9057. return this.container;
  9058. }
  9059. }
  9060. class StrikeOutAnnotationElement extends AnnotationElement {
  9061. constructor(parameters) {
  9062. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  9063. super(parameters, {
  9064. isRenderable,
  9065. ignoreBorder: true,
  9066. createQuadrilaterals: true
  9067. });
  9068. }
  9069. render() {
  9070. if (!this.data.hasPopup) {
  9071. this._createPopup(null, this.data);
  9072. }
  9073. if (this.quadrilaterals) {
  9074. return this._renderQuadrilaterals("strikeoutAnnotation");
  9075. }
  9076. this.container.className = "strikeoutAnnotation";
  9077. return this.container;
  9078. }
  9079. }
  9080. class StampAnnotationElement extends AnnotationElement {
  9081. constructor(parameters) {
  9082. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  9083. super(parameters, {
  9084. isRenderable,
  9085. ignoreBorder: true
  9086. });
  9087. }
  9088. render() {
  9089. this.container.className = "stampAnnotation";
  9090. if (!this.data.hasPopup) {
  9091. this._createPopup(null, this.data);
  9092. }
  9093. return this.container;
  9094. }
  9095. }
  9096. class FileAttachmentAnnotationElement extends AnnotationElement {
  9097. constructor(parameters) {
  9098. super(parameters, {
  9099. isRenderable: true
  9100. });
  9101. const {
  9102. filename,
  9103. content
  9104. } = this.data.file;
  9105. this.filename = (0, _display_utils.getFilenameFromUrl)(filename);
  9106. this.content = content;
  9107. this.linkService.eventBus?.dispatch("fileattachmentannotation", {
  9108. source: this,
  9109. id: (0, _util.stringToPDFString)(filename),
  9110. filename,
  9111. content
  9112. });
  9113. }
  9114. render() {
  9115. this.container.className = "fileAttachmentAnnotation";
  9116. const trigger = document.createElement("div");
  9117. trigger.style.height = this.container.style.height;
  9118. trigger.style.width = this.container.style.width;
  9119. trigger.addEventListener("dblclick", this._download.bind(this));
  9120. if (!this.data.hasPopup && (this.data.titleObj?.str || this.data.contentsObj?.str || this.data.richText)) {
  9121. this._createPopup(trigger, this.data);
  9122. }
  9123. this.container.appendChild(trigger);
  9124. return this.container;
  9125. }
  9126. _download() {
  9127. this.downloadManager?.openOrDownloadData(this.container, this.content, this.filename);
  9128. }
  9129. }
  9130. class AnnotationLayer {
  9131. static render(parameters) {
  9132. const sortedAnnotations = [],
  9133. popupAnnotations = [];
  9134. for (const data of parameters.annotations) {
  9135. if (!data) {
  9136. continue;
  9137. }
  9138. if (data.annotationType === _util.AnnotationType.POPUP) {
  9139. popupAnnotations.push(data);
  9140. continue;
  9141. }
  9142. sortedAnnotations.push(data);
  9143. }
  9144. if (popupAnnotations.length) {
  9145. sortedAnnotations.push(...popupAnnotations);
  9146. }
  9147. const div = parameters.div;
  9148. for (const data of sortedAnnotations) {
  9149. const element = AnnotationElementFactory.create({
  9150. data,
  9151. layer: div,
  9152. page: parameters.page,
  9153. viewport: parameters.viewport,
  9154. linkService: parameters.linkService,
  9155. downloadManager: parameters.downloadManager,
  9156. imageResourcesPath: parameters.imageResourcesPath || "",
  9157. renderForms: parameters.renderForms !== false,
  9158. svgFactory: new _display_utils.DOMSVGFactory(),
  9159. annotationStorage: parameters.annotationStorage || new _annotation_storage.AnnotationStorage(),
  9160. enableScripting: parameters.enableScripting,
  9161. hasJSActions: parameters.hasJSActions,
  9162. fieldObjects: parameters.fieldObjects,
  9163. mouseState: parameters.mouseState || {
  9164. isDown: false
  9165. }
  9166. });
  9167. if (element.isRenderable) {
  9168. const rendered = element.render();
  9169. if (data.hidden) {
  9170. rendered.style.visibility = "hidden";
  9171. }
  9172. if (Array.isArray(rendered)) {
  9173. for (const renderedElement of rendered) {
  9174. div.appendChild(renderedElement);
  9175. }
  9176. } else {
  9177. if (element instanceof PopupAnnotationElement) {
  9178. div.prepend(rendered);
  9179. } else {
  9180. div.appendChild(rendered);
  9181. }
  9182. }
  9183. }
  9184. }
  9185. this.#setAnnotationCanvasMap(div, parameters.annotationCanvasMap);
  9186. }
  9187. static update(parameters) {
  9188. const {
  9189. page,
  9190. viewport,
  9191. annotations,
  9192. annotationCanvasMap,
  9193. div
  9194. } = parameters;
  9195. const transform = viewport.transform;
  9196. const matrix = `matrix(${transform.join(",")})`;
  9197. let scale, ownMatrix;
  9198. for (const data of annotations) {
  9199. const elements = div.querySelectorAll(`[data-annotation-id="${data.id}"]`);
  9200. if (elements) {
  9201. for (const element of elements) {
  9202. if (data.hasOwnCanvas) {
  9203. 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]]);
  9204. if (!ownMatrix) {
  9205. scale = Math.abs(transform[0] || transform[1]);
  9206. const ownTransform = transform.slice();
  9207. for (let i = 0; i < 4; i++) {
  9208. ownTransform[i] = Math.sign(ownTransform[i]);
  9209. }
  9210. ownMatrix = `matrix(${ownTransform.join(",")})`;
  9211. }
  9212. const left = rect[0] * scale;
  9213. const top = rect[1] * scale;
  9214. element.style.left = `${left}px`;
  9215. element.style.top = `${top}px`;
  9216. element.style.transformOrigin = `${-left}px ${-top}px`;
  9217. element.style.transform = ownMatrix;
  9218. } else {
  9219. element.style.transform = matrix;
  9220. }
  9221. }
  9222. }
  9223. }
  9224. this.#setAnnotationCanvasMap(div, annotationCanvasMap);
  9225. div.hidden = false;
  9226. }
  9227. static #setAnnotationCanvasMap(div, annotationCanvasMap) {
  9228. if (!annotationCanvasMap) {
  9229. return;
  9230. }
  9231. for (const [id, canvas] of annotationCanvasMap) {
  9232. const element = div.querySelector(`[data-annotation-id="${id}"]`);
  9233. if (!element) {
  9234. continue;
  9235. }
  9236. const {
  9237. firstChild
  9238. } = element;
  9239. if (firstChild.nodeName === "CANVAS") {
  9240. element.replaceChild(canvas, firstChild);
  9241. } else {
  9242. element.insertBefore(canvas, firstChild);
  9243. }
  9244. }
  9245. annotationCanvasMap.clear();
  9246. }
  9247. }
  9248. exports.AnnotationLayer = AnnotationLayer;
  9249. /***/ }),
  9250. /* 19 */
  9251. /***/ ((__unused_webpack_module, exports) => {
  9252. Object.defineProperty(exports, "__esModule", ({
  9253. value: true
  9254. }));
  9255. exports.ColorConverters = void 0;
  9256. function makeColorComp(n) {
  9257. return Math.floor(Math.max(0, Math.min(1, n)) * 255).toString(16).padStart(2, "0");
  9258. }
  9259. class ColorConverters {
  9260. static CMYK_G([c, y, m, k]) {
  9261. return ["G", 1 - Math.min(1, 0.3 * c + 0.59 * m + 0.11 * y + k)];
  9262. }
  9263. static G_CMYK([g]) {
  9264. return ["CMYK", 0, 0, 0, 1 - g];
  9265. }
  9266. static G_RGB([g]) {
  9267. return ["RGB", g, g, g];
  9268. }
  9269. static G_HTML([g]) {
  9270. const G = makeColorComp(g);
  9271. return `#${G}${G}${G}`;
  9272. }
  9273. static RGB_G([r, g, b]) {
  9274. return ["G", 0.3 * r + 0.59 * g + 0.11 * b];
  9275. }
  9276. static RGB_HTML([r, g, b]) {
  9277. const R = makeColorComp(r);
  9278. const G = makeColorComp(g);
  9279. const B = makeColorComp(b);
  9280. return `#${R}${G}${B}`;
  9281. }
  9282. static T_HTML() {
  9283. return "#00000000";
  9284. }
  9285. static CMYK_RGB([c, y, m, k]) {
  9286. return ["RGB", 1 - Math.min(1, c + k), 1 - Math.min(1, m + k), 1 - Math.min(1, y + k)];
  9287. }
  9288. static CMYK_HTML(components) {
  9289. return this.RGB_HTML(this.CMYK_RGB(components));
  9290. }
  9291. static RGB_CMYK([r, g, b]) {
  9292. const c = 1 - r;
  9293. const m = 1 - g;
  9294. const y = 1 - b;
  9295. const k = Math.min(c, m, y);
  9296. return ["CMYK", c, m, y, k];
  9297. }
  9298. }
  9299. exports.ColorConverters = ColorConverters;
  9300. /***/ }),
  9301. /* 20 */
  9302. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  9303. Object.defineProperty(exports, "__esModule", ({
  9304. value: true
  9305. }));
  9306. exports.XfaLayer = void 0;
  9307. var _util = __w_pdfjs_require__(2);
  9308. var _xfa_text = __w_pdfjs_require__(17);
  9309. class XfaLayer {
  9310. static setupStorage(html, id, element, storage, intent) {
  9311. const storedData = storage.getValue(id, {
  9312. value: null
  9313. });
  9314. switch (element.name) {
  9315. case "textarea":
  9316. if (storedData.value !== null) {
  9317. html.textContent = storedData.value;
  9318. }
  9319. if (intent === "print") {
  9320. break;
  9321. }
  9322. html.addEventListener("input", event => {
  9323. storage.setValue(id, {
  9324. value: event.target.value
  9325. });
  9326. });
  9327. break;
  9328. case "input":
  9329. if (element.attributes.type === "radio" || element.attributes.type === "checkbox") {
  9330. if (storedData.value === element.attributes.xfaOn) {
  9331. html.setAttribute("checked", true);
  9332. } else if (storedData.value === element.attributes.xfaOff) {
  9333. html.removeAttribute("checked");
  9334. }
  9335. if (intent === "print") {
  9336. break;
  9337. }
  9338. html.addEventListener("change", event => {
  9339. storage.setValue(id, {
  9340. value: event.target.checked ? event.target.getAttribute("xfaOn") : event.target.getAttribute("xfaOff")
  9341. });
  9342. });
  9343. } else {
  9344. if (storedData.value !== null) {
  9345. html.setAttribute("value", storedData.value);
  9346. }
  9347. if (intent === "print") {
  9348. break;
  9349. }
  9350. html.addEventListener("input", event => {
  9351. storage.setValue(id, {
  9352. value: event.target.value
  9353. });
  9354. });
  9355. }
  9356. break;
  9357. case "select":
  9358. if (storedData.value !== null) {
  9359. for (const option of element.children) {
  9360. if (option.attributes.value === storedData.value) {
  9361. option.attributes.selected = true;
  9362. }
  9363. }
  9364. }
  9365. html.addEventListener("input", event => {
  9366. const options = event.target.options;
  9367. const value = options.selectedIndex === -1 ? "" : options[options.selectedIndex].value;
  9368. storage.setValue(id, {
  9369. value
  9370. });
  9371. });
  9372. break;
  9373. }
  9374. }
  9375. static setAttributes({
  9376. html,
  9377. element,
  9378. storage = null,
  9379. intent,
  9380. linkService
  9381. }) {
  9382. const {
  9383. attributes
  9384. } = element;
  9385. const isHTMLAnchorElement = html instanceof HTMLAnchorElement;
  9386. if (attributes.type === "radio") {
  9387. attributes.name = `${attributes.name}-${intent}`;
  9388. }
  9389. for (const [key, value] of Object.entries(attributes)) {
  9390. if (value === null || value === undefined || key === "dataId") {
  9391. continue;
  9392. }
  9393. if (key !== "style") {
  9394. if (key === "textContent") {
  9395. html.textContent = value;
  9396. } else if (key === "class") {
  9397. if (value.length) {
  9398. html.setAttribute(key, value.join(" "));
  9399. }
  9400. } else {
  9401. if (isHTMLAnchorElement && (key === "href" || key === "newWindow")) {
  9402. continue;
  9403. }
  9404. html.setAttribute(key, value);
  9405. }
  9406. } else {
  9407. Object.assign(html.style, value);
  9408. }
  9409. }
  9410. if (isHTMLAnchorElement) {
  9411. if (!linkService.addLinkAttributes) {
  9412. (0, _util.warn)("XfaLayer.setAttribute - missing `addLinkAttributes`-method on the `linkService`-instance.");
  9413. }
  9414. linkService.addLinkAttributes?.(html, attributes.href, attributes.newWindow);
  9415. }
  9416. if (storage && attributes.dataId) {
  9417. this.setupStorage(html, attributes.dataId, element, storage);
  9418. }
  9419. }
  9420. static render(parameters) {
  9421. const storage = parameters.annotationStorage;
  9422. const linkService = parameters.linkService;
  9423. const root = parameters.xfaHtml;
  9424. const intent = parameters.intent || "display";
  9425. const rootHtml = document.createElement(root.name);
  9426. if (root.attributes) {
  9427. this.setAttributes({
  9428. html: rootHtml,
  9429. element: root,
  9430. intent,
  9431. linkService
  9432. });
  9433. }
  9434. const stack = [[root, -1, rootHtml]];
  9435. const rootDiv = parameters.div;
  9436. rootDiv.appendChild(rootHtml);
  9437. if (parameters.viewport) {
  9438. const transform = `matrix(${parameters.viewport.transform.join(",")})`;
  9439. rootDiv.style.transform = transform;
  9440. }
  9441. if (intent !== "richText") {
  9442. rootDiv.setAttribute("class", "xfaLayer xfaFont");
  9443. }
  9444. const textDivs = [];
  9445. while (stack.length > 0) {
  9446. const [parent, i, html] = stack[stack.length - 1];
  9447. if (i + 1 === parent.children.length) {
  9448. stack.pop();
  9449. continue;
  9450. }
  9451. const child = parent.children[++stack[stack.length - 1][1]];
  9452. if (child === null) {
  9453. continue;
  9454. }
  9455. const {
  9456. name
  9457. } = child;
  9458. if (name === "#text") {
  9459. const node = document.createTextNode(child.value);
  9460. textDivs.push(node);
  9461. html.appendChild(node);
  9462. continue;
  9463. }
  9464. let childHtml;
  9465. if (child?.attributes?.xmlns) {
  9466. childHtml = document.createElementNS(child.attributes.xmlns, name);
  9467. } else {
  9468. childHtml = document.createElement(name);
  9469. }
  9470. html.appendChild(childHtml);
  9471. if (child.attributes) {
  9472. this.setAttributes({
  9473. html: childHtml,
  9474. element: child,
  9475. storage,
  9476. intent,
  9477. linkService
  9478. });
  9479. }
  9480. if (child.children && child.children.length > 0) {
  9481. stack.push([child, -1, childHtml]);
  9482. } else if (child.value) {
  9483. const node = document.createTextNode(child.value);
  9484. if (_xfa_text.XfaText.shouldBuildText(name)) {
  9485. textDivs.push(node);
  9486. }
  9487. childHtml.appendChild(node);
  9488. }
  9489. }
  9490. for (const el of rootDiv.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea")) {
  9491. el.setAttribute("readOnly", true);
  9492. }
  9493. return {
  9494. textDivs
  9495. };
  9496. }
  9497. static update(parameters) {
  9498. const transform = `matrix(${parameters.viewport.transform.join(",")})`;
  9499. parameters.div.style.transform = transform;
  9500. parameters.div.hidden = false;
  9501. }
  9502. }
  9503. exports.XfaLayer = XfaLayer;
  9504. /***/ }),
  9505. /* 21 */
  9506. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  9507. Object.defineProperty(exports, "__esModule", ({
  9508. value: true
  9509. }));
  9510. exports.renderTextLayer = renderTextLayer;
  9511. var _util = __w_pdfjs_require__(2);
  9512. const MAX_TEXT_DIVS_TO_RENDER = 100000;
  9513. const DEFAULT_FONT_SIZE = 30;
  9514. const DEFAULT_FONT_ASCENT = 0.8;
  9515. const ascentCache = new Map();
  9516. const AllWhitespaceRegexp = /^\s+$/g;
  9517. function getAscent(fontFamily, ctx) {
  9518. const cachedAscent = ascentCache.get(fontFamily);
  9519. if (cachedAscent) {
  9520. return cachedAscent;
  9521. }
  9522. ctx.save();
  9523. ctx.font = `${DEFAULT_FONT_SIZE}px ${fontFamily}`;
  9524. const metrics = ctx.measureText("");
  9525. let ascent = metrics.fontBoundingBoxAscent;
  9526. let descent = Math.abs(metrics.fontBoundingBoxDescent);
  9527. if (ascent) {
  9528. ctx.restore();
  9529. const ratio = ascent / (ascent + descent);
  9530. ascentCache.set(fontFamily, ratio);
  9531. return ratio;
  9532. }
  9533. ctx.strokeStyle = "red";
  9534. ctx.clearRect(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE);
  9535. ctx.strokeText("g", 0, 0);
  9536. let pixels = ctx.getImageData(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE).data;
  9537. descent = 0;
  9538. for (let i = pixels.length - 1 - 3; i >= 0; i -= 4) {
  9539. if (pixels[i] > 0) {
  9540. descent = Math.ceil(i / 4 / DEFAULT_FONT_SIZE);
  9541. break;
  9542. }
  9543. }
  9544. ctx.clearRect(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE);
  9545. ctx.strokeText("A", 0, DEFAULT_FONT_SIZE);
  9546. pixels = ctx.getImageData(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE).data;
  9547. ascent = 0;
  9548. for (let i = 0, ii = pixels.length; i < ii; i += 4) {
  9549. if (pixels[i] > 0) {
  9550. ascent = DEFAULT_FONT_SIZE - Math.floor(i / 4 / DEFAULT_FONT_SIZE);
  9551. break;
  9552. }
  9553. }
  9554. ctx.restore();
  9555. if (ascent) {
  9556. const ratio = ascent / (ascent + descent);
  9557. ascentCache.set(fontFamily, ratio);
  9558. return ratio;
  9559. }
  9560. ascentCache.set(fontFamily, DEFAULT_FONT_ASCENT);
  9561. return DEFAULT_FONT_ASCENT;
  9562. }
  9563. function appendText(task, geom, styles, ctx) {
  9564. const textDiv = document.createElement("span");
  9565. const textDivProperties = task._enhanceTextSelection ? {
  9566. angle: 0,
  9567. canvasWidth: 0,
  9568. hasText: geom.str !== "",
  9569. hasEOL: geom.hasEOL,
  9570. originalTransform: null,
  9571. paddingBottom: 0,
  9572. paddingLeft: 0,
  9573. paddingRight: 0,
  9574. paddingTop: 0,
  9575. scale: 1
  9576. } : {
  9577. angle: 0,
  9578. canvasWidth: 0,
  9579. hasText: geom.str !== "",
  9580. hasEOL: geom.hasEOL
  9581. };
  9582. task._textDivs.push(textDiv);
  9583. const tx = _util.Util.transform(task._viewport.transform, geom.transform);
  9584. let angle = Math.atan2(tx[1], tx[0]);
  9585. const style = styles[geom.fontName];
  9586. if (style.vertical) {
  9587. angle += Math.PI / 2;
  9588. }
  9589. const fontHeight = Math.hypot(tx[2], tx[3]);
  9590. const fontAscent = fontHeight * getAscent(style.fontFamily, ctx);
  9591. let left, top;
  9592. if (angle === 0) {
  9593. left = tx[4];
  9594. top = tx[5] - fontAscent;
  9595. } else {
  9596. left = tx[4] + fontAscent * Math.sin(angle);
  9597. top = tx[5] - fontAscent * Math.cos(angle);
  9598. }
  9599. textDiv.style.left = `${left}px`;
  9600. textDiv.style.top = `${top}px`;
  9601. textDiv.style.fontSize = `${fontHeight}px`;
  9602. textDiv.style.fontFamily = style.fontFamily;
  9603. textDiv.setAttribute("role", "presentation");
  9604. textDiv.textContent = geom.str;
  9605. textDiv.dir = geom.dir;
  9606. if (task._fontInspectorEnabled) {
  9607. textDiv.dataset.fontName = geom.fontName;
  9608. }
  9609. if (angle !== 0) {
  9610. textDivProperties.angle = angle * (180 / Math.PI);
  9611. }
  9612. let shouldScaleText = false;
  9613. if (geom.str.length > 1 || task._enhanceTextSelection && AllWhitespaceRegexp.test(geom.str)) {
  9614. shouldScaleText = true;
  9615. } else if (geom.str !== " " && geom.transform[0] !== geom.transform[3]) {
  9616. const absScaleX = Math.abs(geom.transform[0]),
  9617. absScaleY = Math.abs(geom.transform[3]);
  9618. if (absScaleX !== absScaleY && Math.max(absScaleX, absScaleY) / Math.min(absScaleX, absScaleY) > 1.5) {
  9619. shouldScaleText = true;
  9620. }
  9621. }
  9622. if (shouldScaleText) {
  9623. if (style.vertical) {
  9624. textDivProperties.canvasWidth = geom.height * task._viewport.scale;
  9625. } else {
  9626. textDivProperties.canvasWidth = geom.width * task._viewport.scale;
  9627. }
  9628. }
  9629. task._textDivProperties.set(textDiv, textDivProperties);
  9630. if (task._textContentStream) {
  9631. task._layoutText(textDiv);
  9632. }
  9633. if (task._enhanceTextSelection && textDivProperties.hasText) {
  9634. let angleCos = 1,
  9635. angleSin = 0;
  9636. if (angle !== 0) {
  9637. angleCos = Math.cos(angle);
  9638. angleSin = Math.sin(angle);
  9639. }
  9640. const divWidth = (style.vertical ? geom.height : geom.width) * task._viewport.scale;
  9641. const divHeight = fontHeight;
  9642. let m, b;
  9643. if (angle !== 0) {
  9644. m = [angleCos, angleSin, -angleSin, angleCos, left, top];
  9645. b = _util.Util.getAxialAlignedBoundingBox([0, 0, divWidth, divHeight], m);
  9646. } else {
  9647. b = [left, top, left + divWidth, top + divHeight];
  9648. }
  9649. task._bounds.push({
  9650. left: b[0],
  9651. top: b[1],
  9652. right: b[2],
  9653. bottom: b[3],
  9654. div: textDiv,
  9655. size: [divWidth, divHeight],
  9656. m
  9657. });
  9658. }
  9659. }
  9660. function render(task) {
  9661. if (task._canceled) {
  9662. return;
  9663. }
  9664. const textDivs = task._textDivs;
  9665. const capability = task._capability;
  9666. const textDivsLength = textDivs.length;
  9667. if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
  9668. task._renderingDone = true;
  9669. capability.resolve();
  9670. return;
  9671. }
  9672. if (!task._textContentStream) {
  9673. for (let i = 0; i < textDivsLength; i++) {
  9674. task._layoutText(textDivs[i]);
  9675. }
  9676. }
  9677. task._renderingDone = true;
  9678. capability.resolve();
  9679. }
  9680. function findPositiveMin(ts, offset, count) {
  9681. let result = 0;
  9682. for (let i = 0; i < count; i++) {
  9683. const t = ts[offset++];
  9684. if (t > 0) {
  9685. result = result ? Math.min(t, result) : t;
  9686. }
  9687. }
  9688. return result;
  9689. }
  9690. function expand(task) {
  9691. const bounds = task._bounds;
  9692. const viewport = task._viewport;
  9693. const expanded = expandBounds(viewport.width, viewport.height, bounds);
  9694. for (let i = 0; i < expanded.length; i++) {
  9695. const div = bounds[i].div;
  9696. const divProperties = task._textDivProperties.get(div);
  9697. if (divProperties.angle === 0) {
  9698. divProperties.paddingLeft = bounds[i].left - expanded[i].left;
  9699. divProperties.paddingTop = bounds[i].top - expanded[i].top;
  9700. divProperties.paddingRight = expanded[i].right - bounds[i].right;
  9701. divProperties.paddingBottom = expanded[i].bottom - bounds[i].bottom;
  9702. task._textDivProperties.set(div, divProperties);
  9703. continue;
  9704. }
  9705. const e = expanded[i],
  9706. b = bounds[i];
  9707. const m = b.m,
  9708. c = m[0],
  9709. s = m[1];
  9710. const points = [[0, 0], [0, b.size[1]], [b.size[0], 0], b.size];
  9711. const ts = new Float64Array(64);
  9712. for (let j = 0, jj = points.length; j < jj; j++) {
  9713. const t = _util.Util.applyTransform(points[j], m);
  9714. ts[j + 0] = c && (e.left - t[0]) / c;
  9715. ts[j + 4] = s && (e.top - t[1]) / s;
  9716. ts[j + 8] = c && (e.right - t[0]) / c;
  9717. ts[j + 12] = s && (e.bottom - t[1]) / s;
  9718. ts[j + 16] = s && (e.left - t[0]) / -s;
  9719. ts[j + 20] = c && (e.top - t[1]) / c;
  9720. ts[j + 24] = s && (e.right - t[0]) / -s;
  9721. ts[j + 28] = c && (e.bottom - t[1]) / c;
  9722. ts[j + 32] = c && (e.left - t[0]) / -c;
  9723. ts[j + 36] = s && (e.top - t[1]) / -s;
  9724. ts[j + 40] = c && (e.right - t[0]) / -c;
  9725. ts[j + 44] = s && (e.bottom - t[1]) / -s;
  9726. ts[j + 48] = s && (e.left - t[0]) / s;
  9727. ts[j + 52] = c && (e.top - t[1]) / -c;
  9728. ts[j + 56] = s && (e.right - t[0]) / s;
  9729. ts[j + 60] = c && (e.bottom - t[1]) / -c;
  9730. }
  9731. const boxScale = 1 + Math.min(Math.abs(c), Math.abs(s));
  9732. divProperties.paddingLeft = findPositiveMin(ts, 32, 16) / boxScale;
  9733. divProperties.paddingTop = findPositiveMin(ts, 48, 16) / boxScale;
  9734. divProperties.paddingRight = findPositiveMin(ts, 0, 16) / boxScale;
  9735. divProperties.paddingBottom = findPositiveMin(ts, 16, 16) / boxScale;
  9736. task._textDivProperties.set(div, divProperties);
  9737. }
  9738. }
  9739. function expandBounds(width, height, boxes) {
  9740. const bounds = boxes.map(function (box, i) {
  9741. return {
  9742. x1: box.left,
  9743. y1: box.top,
  9744. x2: box.right,
  9745. y2: box.bottom,
  9746. index: i,
  9747. x1New: undefined,
  9748. x2New: undefined
  9749. };
  9750. });
  9751. expandBoundsLTR(width, bounds);
  9752. const expanded = new Array(boxes.length);
  9753. for (const b of bounds) {
  9754. const i = b.index;
  9755. expanded[i] = {
  9756. left: b.x1New,
  9757. top: 0,
  9758. right: b.x2New,
  9759. bottom: 0
  9760. };
  9761. }
  9762. boxes.map(function (box, i) {
  9763. const e = expanded[i],
  9764. b = bounds[i];
  9765. b.x1 = box.top;
  9766. b.y1 = width - e.right;
  9767. b.x2 = box.bottom;
  9768. b.y2 = width - e.left;
  9769. b.index = i;
  9770. b.x1New = undefined;
  9771. b.x2New = undefined;
  9772. });
  9773. expandBoundsLTR(height, bounds);
  9774. for (const b of bounds) {
  9775. const i = b.index;
  9776. expanded[i].top = b.x1New;
  9777. expanded[i].bottom = b.x2New;
  9778. }
  9779. return expanded;
  9780. }
  9781. function expandBoundsLTR(width, bounds) {
  9782. bounds.sort(function (a, b) {
  9783. return a.x1 - b.x1 || a.index - b.index;
  9784. });
  9785. const fakeBoundary = {
  9786. x1: -Infinity,
  9787. y1: -Infinity,
  9788. x2: 0,
  9789. y2: Infinity,
  9790. index: -1,
  9791. x1New: 0,
  9792. x2New: 0
  9793. };
  9794. const horizon = [{
  9795. start: -Infinity,
  9796. end: Infinity,
  9797. boundary: fakeBoundary
  9798. }];
  9799. for (const boundary of bounds) {
  9800. let i = 0;
  9801. while (i < horizon.length && horizon[i].end <= boundary.y1) {
  9802. i++;
  9803. }
  9804. let j = horizon.length - 1;
  9805. while (j >= 0 && horizon[j].start >= boundary.y2) {
  9806. j--;
  9807. }
  9808. let horizonPart, affectedBoundary;
  9809. let q,
  9810. k,
  9811. maxXNew = -Infinity;
  9812. for (q = i; q <= j; q++) {
  9813. horizonPart = horizon[q];
  9814. affectedBoundary = horizonPart.boundary;
  9815. let xNew;
  9816. if (affectedBoundary.x2 > boundary.x1) {
  9817. xNew = affectedBoundary.index > boundary.index ? affectedBoundary.x1New : boundary.x1;
  9818. } else if (affectedBoundary.x2New === undefined) {
  9819. xNew = (affectedBoundary.x2 + boundary.x1) / 2;
  9820. } else {
  9821. xNew = affectedBoundary.x2New;
  9822. }
  9823. if (xNew > maxXNew) {
  9824. maxXNew = xNew;
  9825. }
  9826. }
  9827. boundary.x1New = maxXNew;
  9828. for (q = i; q <= j; q++) {
  9829. horizonPart = horizon[q];
  9830. affectedBoundary = horizonPart.boundary;
  9831. if (affectedBoundary.x2New === undefined) {
  9832. if (affectedBoundary.x2 > boundary.x1) {
  9833. if (affectedBoundary.index > boundary.index) {
  9834. affectedBoundary.x2New = affectedBoundary.x2;
  9835. }
  9836. } else {
  9837. affectedBoundary.x2New = maxXNew;
  9838. }
  9839. } else if (affectedBoundary.x2New > maxXNew) {
  9840. affectedBoundary.x2New = Math.max(maxXNew, affectedBoundary.x2);
  9841. }
  9842. }
  9843. const changedHorizon = [];
  9844. let lastBoundary = null;
  9845. for (q = i; q <= j; q++) {
  9846. horizonPart = horizon[q];
  9847. affectedBoundary = horizonPart.boundary;
  9848. const useBoundary = affectedBoundary.x2 > boundary.x2 ? affectedBoundary : boundary;
  9849. if (lastBoundary === useBoundary) {
  9850. changedHorizon[changedHorizon.length - 1].end = horizonPart.end;
  9851. } else {
  9852. changedHorizon.push({
  9853. start: horizonPart.start,
  9854. end: horizonPart.end,
  9855. boundary: useBoundary
  9856. });
  9857. lastBoundary = useBoundary;
  9858. }
  9859. }
  9860. if (horizon[i].start < boundary.y1) {
  9861. changedHorizon[0].start = boundary.y1;
  9862. changedHorizon.unshift({
  9863. start: horizon[i].start,
  9864. end: boundary.y1,
  9865. boundary: horizon[i].boundary
  9866. });
  9867. }
  9868. if (boundary.y2 < horizon[j].end) {
  9869. changedHorizon[changedHorizon.length - 1].end = boundary.y2;
  9870. changedHorizon.push({
  9871. start: boundary.y2,
  9872. end: horizon[j].end,
  9873. boundary: horizon[j].boundary
  9874. });
  9875. }
  9876. for (q = i; q <= j; q++) {
  9877. horizonPart = horizon[q];
  9878. affectedBoundary = horizonPart.boundary;
  9879. if (affectedBoundary.x2New !== undefined) {
  9880. continue;
  9881. }
  9882. let used = false;
  9883. for (k = i - 1; !used && k >= 0 && horizon[k].start >= affectedBoundary.y1; k--) {
  9884. used = horizon[k].boundary === affectedBoundary;
  9885. }
  9886. for (k = j + 1; !used && k < horizon.length && horizon[k].end <= affectedBoundary.y2; k++) {
  9887. used = horizon[k].boundary === affectedBoundary;
  9888. }
  9889. for (k = 0; !used && k < changedHorizon.length; k++) {
  9890. used = changedHorizon[k].boundary === affectedBoundary;
  9891. }
  9892. if (!used) {
  9893. affectedBoundary.x2New = maxXNew;
  9894. }
  9895. }
  9896. Array.prototype.splice.apply(horizon, [i, j - i + 1].concat(changedHorizon));
  9897. }
  9898. for (const horizonPart of horizon) {
  9899. const affectedBoundary = horizonPart.boundary;
  9900. if (affectedBoundary.x2New === undefined) {
  9901. affectedBoundary.x2New = Math.max(width, affectedBoundary.x2);
  9902. }
  9903. }
  9904. }
  9905. class TextLayerRenderTask {
  9906. constructor({
  9907. textContent,
  9908. textContentStream,
  9909. container,
  9910. viewport,
  9911. textDivs,
  9912. textContentItemsStr,
  9913. enhanceTextSelection
  9914. }) {
  9915. this._textContent = textContent;
  9916. this._textContentStream = textContentStream;
  9917. this._container = container;
  9918. this._document = container.ownerDocument;
  9919. this._viewport = viewport;
  9920. this._textDivs = textDivs || [];
  9921. this._textContentItemsStr = textContentItemsStr || [];
  9922. this._enhanceTextSelection = !!enhanceTextSelection;
  9923. this._fontInspectorEnabled = !!globalThis.FontInspector?.enabled;
  9924. this._reader = null;
  9925. this._layoutTextLastFontSize = null;
  9926. this._layoutTextLastFontFamily = null;
  9927. this._layoutTextCtx = null;
  9928. this._textDivProperties = new WeakMap();
  9929. this._renderingDone = false;
  9930. this._canceled = false;
  9931. this._capability = (0, _util.createPromiseCapability)();
  9932. this._renderTimer = null;
  9933. this._bounds = [];
  9934. this._capability.promise.finally(() => {
  9935. if (!this._enhanceTextSelection) {
  9936. this._textDivProperties = null;
  9937. }
  9938. if (this._layoutTextCtx) {
  9939. this._layoutTextCtx.canvas.width = 0;
  9940. this._layoutTextCtx.canvas.height = 0;
  9941. this._layoutTextCtx = null;
  9942. }
  9943. }).catch(() => {});
  9944. }
  9945. get promise() {
  9946. return this._capability.promise;
  9947. }
  9948. cancel() {
  9949. this._canceled = true;
  9950. if (this._reader) {
  9951. this._reader.cancel(new _util.AbortException("TextLayer task cancelled.")).catch(() => {});
  9952. this._reader = null;
  9953. }
  9954. if (this._renderTimer !== null) {
  9955. clearTimeout(this._renderTimer);
  9956. this._renderTimer = null;
  9957. }
  9958. this._capability.reject(new Error("TextLayer task cancelled."));
  9959. }
  9960. _processItems(items, styleCache) {
  9961. for (let i = 0, len = items.length; i < len; i++) {
  9962. if (items[i].str === undefined) {
  9963. if (items[i].type === "beginMarkedContentProps" || items[i].type === "beginMarkedContent") {
  9964. const parent = this._container;
  9965. this._container = document.createElement("span");
  9966. this._container.classList.add("markedContent");
  9967. if (items[i].id !== null) {
  9968. this._container.setAttribute("id", `${items[i].id}`);
  9969. }
  9970. parent.appendChild(this._container);
  9971. } else if (items[i].type === "endMarkedContent") {
  9972. this._container = this._container.parentNode;
  9973. }
  9974. continue;
  9975. }
  9976. this._textContentItemsStr.push(items[i].str);
  9977. appendText(this, items[i], styleCache, this._layoutTextCtx);
  9978. }
  9979. }
  9980. _layoutText(textDiv) {
  9981. const textDivProperties = this._textDivProperties.get(textDiv);
  9982. let transform = "";
  9983. if (textDivProperties.canvasWidth !== 0 && textDivProperties.hasText) {
  9984. const {
  9985. fontSize,
  9986. fontFamily
  9987. } = textDiv.style;
  9988. if (fontSize !== this._layoutTextLastFontSize || fontFamily !== this._layoutTextLastFontFamily) {
  9989. this._layoutTextCtx.font = `${fontSize} ${fontFamily}`;
  9990. this._layoutTextLastFontSize = fontSize;
  9991. this._layoutTextLastFontFamily = fontFamily;
  9992. }
  9993. const {
  9994. width
  9995. } = this._layoutTextCtx.measureText(textDiv.textContent);
  9996. if (width > 0) {
  9997. const scale = textDivProperties.canvasWidth / width;
  9998. if (this._enhanceTextSelection) {
  9999. textDivProperties.scale = scale;
  10000. }
  10001. transform = `scaleX(${scale})`;
  10002. }
  10003. }
  10004. if (textDivProperties.angle !== 0) {
  10005. transform = `rotate(${textDivProperties.angle}deg) ${transform}`;
  10006. }
  10007. if (transform.length > 0) {
  10008. if (this._enhanceTextSelection) {
  10009. textDivProperties.originalTransform = transform;
  10010. }
  10011. textDiv.style.transform = transform;
  10012. }
  10013. if (textDivProperties.hasText) {
  10014. this._container.appendChild(textDiv);
  10015. }
  10016. if (textDivProperties.hasEOL) {
  10017. const br = document.createElement("br");
  10018. br.setAttribute("role", "presentation");
  10019. this._container.appendChild(br);
  10020. }
  10021. }
  10022. _render(timeout = 0) {
  10023. const capability = (0, _util.createPromiseCapability)();
  10024. let styleCache = Object.create(null);
  10025. const canvas = this._document.createElement("canvas");
  10026. canvas.height = canvas.width = DEFAULT_FONT_SIZE;
  10027. canvas.mozOpaque = true;
  10028. this._layoutTextCtx = canvas.getContext("2d", {
  10029. alpha: false
  10030. });
  10031. if (this._textContent) {
  10032. const textItems = this._textContent.items;
  10033. const textStyles = this._textContent.styles;
  10034. this._processItems(textItems, textStyles);
  10035. capability.resolve();
  10036. } else if (this._textContentStream) {
  10037. const pump = () => {
  10038. this._reader.read().then(({
  10039. value,
  10040. done
  10041. }) => {
  10042. if (done) {
  10043. capability.resolve();
  10044. return;
  10045. }
  10046. Object.assign(styleCache, value.styles);
  10047. this._processItems(value.items, styleCache);
  10048. pump();
  10049. }, capability.reject);
  10050. };
  10051. this._reader = this._textContentStream.getReader();
  10052. pump();
  10053. } else {
  10054. throw new Error('Neither "textContent" nor "textContentStream" parameters specified.');
  10055. }
  10056. capability.promise.then(() => {
  10057. styleCache = null;
  10058. if (!timeout) {
  10059. render(this);
  10060. } else {
  10061. this._renderTimer = setTimeout(() => {
  10062. render(this);
  10063. this._renderTimer = null;
  10064. }, timeout);
  10065. }
  10066. }, this._capability.reject);
  10067. }
  10068. expandTextDivs(expandDivs = false) {
  10069. if (!this._enhanceTextSelection || !this._renderingDone) {
  10070. return;
  10071. }
  10072. if (this._bounds !== null) {
  10073. expand(this);
  10074. this._bounds = null;
  10075. }
  10076. const transformBuf = [],
  10077. paddingBuf = [];
  10078. for (let i = 0, ii = this._textDivs.length; i < ii; i++) {
  10079. const div = this._textDivs[i];
  10080. const divProps = this._textDivProperties.get(div);
  10081. if (!divProps.hasText) {
  10082. continue;
  10083. }
  10084. if (expandDivs) {
  10085. transformBuf.length = 0;
  10086. paddingBuf.length = 0;
  10087. if (divProps.originalTransform) {
  10088. transformBuf.push(divProps.originalTransform);
  10089. }
  10090. if (divProps.paddingTop > 0) {
  10091. paddingBuf.push(`${divProps.paddingTop}px`);
  10092. transformBuf.push(`translateY(${-divProps.paddingTop}px)`);
  10093. } else {
  10094. paddingBuf.push(0);
  10095. }
  10096. if (divProps.paddingRight > 0) {
  10097. paddingBuf.push(`${divProps.paddingRight / divProps.scale}px`);
  10098. } else {
  10099. paddingBuf.push(0);
  10100. }
  10101. if (divProps.paddingBottom > 0) {
  10102. paddingBuf.push(`${divProps.paddingBottom}px`);
  10103. } else {
  10104. paddingBuf.push(0);
  10105. }
  10106. if (divProps.paddingLeft > 0) {
  10107. paddingBuf.push(`${divProps.paddingLeft / divProps.scale}px`);
  10108. transformBuf.push(`translateX(${-divProps.paddingLeft / divProps.scale}px)`);
  10109. } else {
  10110. paddingBuf.push(0);
  10111. }
  10112. div.style.padding = paddingBuf.join(" ");
  10113. if (transformBuf.length) {
  10114. div.style.transform = transformBuf.join(" ");
  10115. }
  10116. } else {
  10117. div.style.padding = null;
  10118. div.style.transform = divProps.originalTransform;
  10119. }
  10120. }
  10121. }
  10122. }
  10123. function renderTextLayer(renderParameters) {
  10124. const task = new TextLayerRenderTask({
  10125. textContent: renderParameters.textContent,
  10126. textContentStream: renderParameters.textContentStream,
  10127. container: renderParameters.container,
  10128. viewport: renderParameters.viewport,
  10129. textDivs: renderParameters.textDivs,
  10130. textContentItemsStr: renderParameters.textContentItemsStr,
  10131. enhanceTextSelection: renderParameters.enhanceTextSelection
  10132. });
  10133. task._render(renderParameters.timeout);
  10134. return task;
  10135. }
  10136. /***/ }),
  10137. /* 22 */
  10138. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  10139. Object.defineProperty(exports, "__esModule", ({
  10140. value: true
  10141. }));
  10142. exports.SVGGraphics = void 0;
  10143. var _util = __w_pdfjs_require__(2);
  10144. var _display_utils = __w_pdfjs_require__(1);
  10145. var _is_node = __w_pdfjs_require__(4);
  10146. let SVGGraphics = class {
  10147. constructor() {
  10148. (0, _util.unreachable)("Not implemented: SVGGraphics");
  10149. }
  10150. };
  10151. exports.SVGGraphics = SVGGraphics;
  10152. {
  10153. const SVG_DEFAULTS = {
  10154. fontStyle: "normal",
  10155. fontWeight: "normal",
  10156. fillColor: "#000000"
  10157. };
  10158. const XML_NS = "http://www.w3.org/XML/1998/namespace";
  10159. const XLINK_NS = "http://www.w3.org/1999/xlink";
  10160. const LINE_CAP_STYLES = ["butt", "round", "square"];
  10161. const LINE_JOIN_STYLES = ["miter", "round", "bevel"];
  10162. const convertImgDataToPng = function () {
  10163. const PNG_HEADER = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  10164. const CHUNK_WRAPPER_SIZE = 12;
  10165. const crcTable = new Int32Array(256);
  10166. for (let i = 0; i < 256; i++) {
  10167. let c = i;
  10168. for (let h = 0; h < 8; h++) {
  10169. if (c & 1) {
  10170. c = 0xedb88320 ^ c >> 1 & 0x7fffffff;
  10171. } else {
  10172. c = c >> 1 & 0x7fffffff;
  10173. }
  10174. }
  10175. crcTable[i] = c;
  10176. }
  10177. function crc32(data, start, end) {
  10178. let crc = -1;
  10179. for (let i = start; i < end; i++) {
  10180. const a = (crc ^ data[i]) & 0xff;
  10181. const b = crcTable[a];
  10182. crc = crc >>> 8 ^ b;
  10183. }
  10184. return crc ^ -1;
  10185. }
  10186. function writePngChunk(type, body, data, offset) {
  10187. let p = offset;
  10188. const len = body.length;
  10189. data[p] = len >> 24 & 0xff;
  10190. data[p + 1] = len >> 16 & 0xff;
  10191. data[p + 2] = len >> 8 & 0xff;
  10192. data[p + 3] = len & 0xff;
  10193. p += 4;
  10194. data[p] = type.charCodeAt(0) & 0xff;
  10195. data[p + 1] = type.charCodeAt(1) & 0xff;
  10196. data[p + 2] = type.charCodeAt(2) & 0xff;
  10197. data[p + 3] = type.charCodeAt(3) & 0xff;
  10198. p += 4;
  10199. data.set(body, p);
  10200. p += body.length;
  10201. const crc = crc32(data, offset + 4, p);
  10202. data[p] = crc >> 24 & 0xff;
  10203. data[p + 1] = crc >> 16 & 0xff;
  10204. data[p + 2] = crc >> 8 & 0xff;
  10205. data[p + 3] = crc & 0xff;
  10206. }
  10207. function adler32(data, start, end) {
  10208. let a = 1;
  10209. let b = 0;
  10210. for (let i = start; i < end; ++i) {
  10211. a = (a + (data[i] & 0xff)) % 65521;
  10212. b = (b + a) % 65521;
  10213. }
  10214. return b << 16 | a;
  10215. }
  10216. function deflateSync(literals) {
  10217. if (!_is_node.isNodeJS) {
  10218. return deflateSyncUncompressed(literals);
  10219. }
  10220. try {
  10221. let input;
  10222. if (parseInt(process.versions.node) >= 8) {
  10223. input = literals;
  10224. } else {
  10225. input = Buffer.from(literals);
  10226. }
  10227. const output = require("zlib").deflateSync(input, {
  10228. level: 9
  10229. });
  10230. return output instanceof Uint8Array ? output : new Uint8Array(output);
  10231. } catch (e) {
  10232. (0, _util.warn)("Not compressing PNG because zlib.deflateSync is unavailable: " + e);
  10233. }
  10234. return deflateSyncUncompressed(literals);
  10235. }
  10236. function deflateSyncUncompressed(literals) {
  10237. let len = literals.length;
  10238. const maxBlockLength = 0xffff;
  10239. const deflateBlocks = Math.ceil(len / maxBlockLength);
  10240. const idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  10241. let pi = 0;
  10242. idat[pi++] = 0x78;
  10243. idat[pi++] = 0x9c;
  10244. let pos = 0;
  10245. while (len > maxBlockLength) {
  10246. idat[pi++] = 0x00;
  10247. idat[pi++] = 0xff;
  10248. idat[pi++] = 0xff;
  10249. idat[pi++] = 0x00;
  10250. idat[pi++] = 0x00;
  10251. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  10252. pi += maxBlockLength;
  10253. pos += maxBlockLength;
  10254. len -= maxBlockLength;
  10255. }
  10256. idat[pi++] = 0x01;
  10257. idat[pi++] = len & 0xff;
  10258. idat[pi++] = len >> 8 & 0xff;
  10259. idat[pi++] = ~len & 0xffff & 0xff;
  10260. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  10261. idat.set(literals.subarray(pos), pi);
  10262. pi += literals.length - pos;
  10263. const adler = adler32(literals, 0, literals.length);
  10264. idat[pi++] = adler >> 24 & 0xff;
  10265. idat[pi++] = adler >> 16 & 0xff;
  10266. idat[pi++] = adler >> 8 & 0xff;
  10267. idat[pi++] = adler & 0xff;
  10268. return idat;
  10269. }
  10270. function encode(imgData, kind, forceDataSchema, isMask) {
  10271. const width = imgData.width;
  10272. const height = imgData.height;
  10273. let bitDepth, colorType, lineSize;
  10274. const bytes = imgData.data;
  10275. switch (kind) {
  10276. case _util.ImageKind.GRAYSCALE_1BPP:
  10277. colorType = 0;
  10278. bitDepth = 1;
  10279. lineSize = width + 7 >> 3;
  10280. break;
  10281. case _util.ImageKind.RGB_24BPP:
  10282. colorType = 2;
  10283. bitDepth = 8;
  10284. lineSize = width * 3;
  10285. break;
  10286. case _util.ImageKind.RGBA_32BPP:
  10287. colorType = 6;
  10288. bitDepth = 8;
  10289. lineSize = width * 4;
  10290. break;
  10291. default:
  10292. throw new Error("invalid format");
  10293. }
  10294. const literals = new Uint8Array((1 + lineSize) * height);
  10295. let offsetLiterals = 0,
  10296. offsetBytes = 0;
  10297. for (let y = 0; y < height; ++y) {
  10298. literals[offsetLiterals++] = 0;
  10299. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize), offsetLiterals);
  10300. offsetBytes += lineSize;
  10301. offsetLiterals += lineSize;
  10302. }
  10303. if (kind === _util.ImageKind.GRAYSCALE_1BPP && isMask) {
  10304. offsetLiterals = 0;
  10305. for (let y = 0; y < height; y++) {
  10306. offsetLiterals++;
  10307. for (let i = 0; i < lineSize; i++) {
  10308. literals[offsetLiterals++] ^= 0xff;
  10309. }
  10310. }
  10311. }
  10312. 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]);
  10313. const idat = deflateSync(literals);
  10314. const pngLength = PNG_HEADER.length + CHUNK_WRAPPER_SIZE * 3 + ihdr.length + idat.length;
  10315. const data = new Uint8Array(pngLength);
  10316. let offset = 0;
  10317. data.set(PNG_HEADER, offset);
  10318. offset += PNG_HEADER.length;
  10319. writePngChunk("IHDR", ihdr, data, offset);
  10320. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  10321. writePngChunk("IDATA", idat, data, offset);
  10322. offset += CHUNK_WRAPPER_SIZE + idat.length;
  10323. writePngChunk("IEND", new Uint8Array(0), data, offset);
  10324. return (0, _util.createObjectURL)(data, "image/png", forceDataSchema);
  10325. }
  10326. return function convertImgDataToPng(imgData, forceDataSchema, isMask) {
  10327. const kind = imgData.kind === undefined ? _util.ImageKind.GRAYSCALE_1BPP : imgData.kind;
  10328. return encode(imgData, kind, forceDataSchema, isMask);
  10329. };
  10330. }();
  10331. class SVGExtraState {
  10332. constructor() {
  10333. this.fontSizeScale = 1;
  10334. this.fontWeight = SVG_DEFAULTS.fontWeight;
  10335. this.fontSize = 0;
  10336. this.textMatrix = _util.IDENTITY_MATRIX;
  10337. this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
  10338. this.leading = 0;
  10339. this.textRenderingMode = _util.TextRenderingMode.FILL;
  10340. this.textMatrixScale = 1;
  10341. this.x = 0;
  10342. this.y = 0;
  10343. this.lineX = 0;
  10344. this.lineY = 0;
  10345. this.charSpacing = 0;
  10346. this.wordSpacing = 0;
  10347. this.textHScale = 1;
  10348. this.textRise = 0;
  10349. this.fillColor = SVG_DEFAULTS.fillColor;
  10350. this.strokeColor = "#000000";
  10351. this.fillAlpha = 1;
  10352. this.strokeAlpha = 1;
  10353. this.lineWidth = 1;
  10354. this.lineJoin = "";
  10355. this.lineCap = "";
  10356. this.miterLimit = 0;
  10357. this.dashArray = [];
  10358. this.dashPhase = 0;
  10359. this.dependencies = [];
  10360. this.activeClipUrl = null;
  10361. this.clipGroup = null;
  10362. this.maskId = "";
  10363. }
  10364. clone() {
  10365. return Object.create(this);
  10366. }
  10367. setCurrentPoint(x, y) {
  10368. this.x = x;
  10369. this.y = y;
  10370. }
  10371. }
  10372. function opListToTree(opList) {
  10373. let opTree = [];
  10374. const tmp = [];
  10375. for (const opListElement of opList) {
  10376. if (opListElement.fn === "save") {
  10377. opTree.push({
  10378. fnId: 92,
  10379. fn: "group",
  10380. items: []
  10381. });
  10382. tmp.push(opTree);
  10383. opTree = opTree[opTree.length - 1].items;
  10384. continue;
  10385. }
  10386. if (opListElement.fn === "restore") {
  10387. opTree = tmp.pop();
  10388. } else {
  10389. opTree.push(opListElement);
  10390. }
  10391. }
  10392. return opTree;
  10393. }
  10394. function pf(value) {
  10395. if (Number.isInteger(value)) {
  10396. return value.toString();
  10397. }
  10398. const s = value.toFixed(10);
  10399. let i = s.length - 1;
  10400. if (s[i] !== "0") {
  10401. return s;
  10402. }
  10403. do {
  10404. i--;
  10405. } while (s[i] === "0");
  10406. return s.substring(0, s[i] === "." ? i : i + 1);
  10407. }
  10408. function pm(m) {
  10409. if (m[4] === 0 && m[5] === 0) {
  10410. if (m[1] === 0 && m[2] === 0) {
  10411. if (m[0] === 1 && m[3] === 1) {
  10412. return "";
  10413. }
  10414. return `scale(${pf(m[0])} ${pf(m[3])})`;
  10415. }
  10416. if (m[0] === m[3] && m[1] === -m[2]) {
  10417. const a = Math.acos(m[0]) * 180 / Math.PI;
  10418. return `rotate(${pf(a)})`;
  10419. }
  10420. } else {
  10421. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  10422. return `translate(${pf(m[4])} ${pf(m[5])})`;
  10423. }
  10424. }
  10425. return `matrix(${pf(m[0])} ${pf(m[1])} ${pf(m[2])} ${pf(m[3])} ${pf(m[4])} ` + `${pf(m[5])})`;
  10426. }
  10427. let clipCount = 0;
  10428. let maskCount = 0;
  10429. let shadingCount = 0;
  10430. exports.SVGGraphics = SVGGraphics = class {
  10431. constructor(commonObjs, objs, forceDataSchema = false) {
  10432. this.svgFactory = new _display_utils.DOMSVGFactory();
  10433. this.current = new SVGExtraState();
  10434. this.transformMatrix = _util.IDENTITY_MATRIX;
  10435. this.transformStack = [];
  10436. this.extraStack = [];
  10437. this.commonObjs = commonObjs;
  10438. this.objs = objs;
  10439. this.pendingClip = null;
  10440. this.pendingEOFill = false;
  10441. this.embedFonts = false;
  10442. this.embeddedFonts = Object.create(null);
  10443. this.cssStyle = null;
  10444. this.forceDataSchema = !!forceDataSchema;
  10445. this._operatorIdMapping = [];
  10446. for (const op in _util.OPS) {
  10447. this._operatorIdMapping[_util.OPS[op]] = op;
  10448. }
  10449. }
  10450. save() {
  10451. this.transformStack.push(this.transformMatrix);
  10452. const old = this.current;
  10453. this.extraStack.push(old);
  10454. this.current = old.clone();
  10455. }
  10456. restore() {
  10457. this.transformMatrix = this.transformStack.pop();
  10458. this.current = this.extraStack.pop();
  10459. this.pendingClip = null;
  10460. this.tgrp = null;
  10461. }
  10462. group(items) {
  10463. this.save();
  10464. this.executeOpTree(items);
  10465. this.restore();
  10466. }
  10467. loadDependencies(operatorList) {
  10468. const fnArray = operatorList.fnArray;
  10469. const argsArray = operatorList.argsArray;
  10470. for (let i = 0, ii = fnArray.length; i < ii; i++) {
  10471. if (fnArray[i] !== _util.OPS.dependency) {
  10472. continue;
  10473. }
  10474. for (const obj of argsArray[i]) {
  10475. const objsPool = obj.startsWith("g_") ? this.commonObjs : this.objs;
  10476. const promise = new Promise(resolve => {
  10477. objsPool.get(obj, resolve);
  10478. });
  10479. this.current.dependencies.push(promise);
  10480. }
  10481. }
  10482. return Promise.all(this.current.dependencies);
  10483. }
  10484. transform(a, b, c, d, e, f) {
  10485. const transformMatrix = [a, b, c, d, e, f];
  10486. this.transformMatrix = _util.Util.transform(this.transformMatrix, transformMatrix);
  10487. this.tgrp = null;
  10488. }
  10489. getSVG(operatorList, viewport) {
  10490. this.viewport = viewport;
  10491. const svgElement = this._initialize(viewport);
  10492. return this.loadDependencies(operatorList).then(() => {
  10493. this.transformMatrix = _util.IDENTITY_MATRIX;
  10494. this.executeOpTree(this.convertOpList(operatorList));
  10495. return svgElement;
  10496. });
  10497. }
  10498. convertOpList(operatorList) {
  10499. const operatorIdMapping = this._operatorIdMapping;
  10500. const argsArray = operatorList.argsArray;
  10501. const fnArray = operatorList.fnArray;
  10502. const opList = [];
  10503. for (let i = 0, ii = fnArray.length; i < ii; i++) {
  10504. const fnId = fnArray[i];
  10505. opList.push({
  10506. fnId,
  10507. fn: operatorIdMapping[fnId],
  10508. args: argsArray[i]
  10509. });
  10510. }
  10511. return opListToTree(opList);
  10512. }
  10513. executeOpTree(opTree) {
  10514. for (const opTreeElement of opTree) {
  10515. const fn = opTreeElement.fn;
  10516. const fnId = opTreeElement.fnId;
  10517. const args = opTreeElement.args;
  10518. switch (fnId | 0) {
  10519. case _util.OPS.beginText:
  10520. this.beginText();
  10521. break;
  10522. case _util.OPS.dependency:
  10523. break;
  10524. case _util.OPS.setLeading:
  10525. this.setLeading(args);
  10526. break;
  10527. case _util.OPS.setLeadingMoveText:
  10528. this.setLeadingMoveText(args[0], args[1]);
  10529. break;
  10530. case _util.OPS.setFont:
  10531. this.setFont(args);
  10532. break;
  10533. case _util.OPS.showText:
  10534. this.showText(args[0]);
  10535. break;
  10536. case _util.OPS.showSpacedText:
  10537. this.showText(args[0]);
  10538. break;
  10539. case _util.OPS.endText:
  10540. this.endText();
  10541. break;
  10542. case _util.OPS.moveText:
  10543. this.moveText(args[0], args[1]);
  10544. break;
  10545. case _util.OPS.setCharSpacing:
  10546. this.setCharSpacing(args[0]);
  10547. break;
  10548. case _util.OPS.setWordSpacing:
  10549. this.setWordSpacing(args[0]);
  10550. break;
  10551. case _util.OPS.setHScale:
  10552. this.setHScale(args[0]);
  10553. break;
  10554. case _util.OPS.setTextMatrix:
  10555. this.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
  10556. break;
  10557. case _util.OPS.setTextRise:
  10558. this.setTextRise(args[0]);
  10559. break;
  10560. case _util.OPS.setTextRenderingMode:
  10561. this.setTextRenderingMode(args[0]);
  10562. break;
  10563. case _util.OPS.setLineWidth:
  10564. this.setLineWidth(args[0]);
  10565. break;
  10566. case _util.OPS.setLineJoin:
  10567. this.setLineJoin(args[0]);
  10568. break;
  10569. case _util.OPS.setLineCap:
  10570. this.setLineCap(args[0]);
  10571. break;
  10572. case _util.OPS.setMiterLimit:
  10573. this.setMiterLimit(args[0]);
  10574. break;
  10575. case _util.OPS.setFillRGBColor:
  10576. this.setFillRGBColor(args[0], args[1], args[2]);
  10577. break;
  10578. case _util.OPS.setStrokeRGBColor:
  10579. this.setStrokeRGBColor(args[0], args[1], args[2]);
  10580. break;
  10581. case _util.OPS.setStrokeColorN:
  10582. this.setStrokeColorN(args);
  10583. break;
  10584. case _util.OPS.setFillColorN:
  10585. this.setFillColorN(args);
  10586. break;
  10587. case _util.OPS.shadingFill:
  10588. this.shadingFill(args[0]);
  10589. break;
  10590. case _util.OPS.setDash:
  10591. this.setDash(args[0], args[1]);
  10592. break;
  10593. case _util.OPS.setRenderingIntent:
  10594. this.setRenderingIntent(args[0]);
  10595. break;
  10596. case _util.OPS.setFlatness:
  10597. this.setFlatness(args[0]);
  10598. break;
  10599. case _util.OPS.setGState:
  10600. this.setGState(args[0]);
  10601. break;
  10602. case _util.OPS.fill:
  10603. this.fill();
  10604. break;
  10605. case _util.OPS.eoFill:
  10606. this.eoFill();
  10607. break;
  10608. case _util.OPS.stroke:
  10609. this.stroke();
  10610. break;
  10611. case _util.OPS.fillStroke:
  10612. this.fillStroke();
  10613. break;
  10614. case _util.OPS.eoFillStroke:
  10615. this.eoFillStroke();
  10616. break;
  10617. case _util.OPS.clip:
  10618. this.clip("nonzero");
  10619. break;
  10620. case _util.OPS.eoClip:
  10621. this.clip("evenodd");
  10622. break;
  10623. case _util.OPS.paintSolidColorImageMask:
  10624. this.paintSolidColorImageMask();
  10625. break;
  10626. case _util.OPS.paintImageXObject:
  10627. this.paintImageXObject(args[0]);
  10628. break;
  10629. case _util.OPS.paintInlineImageXObject:
  10630. this.paintInlineImageXObject(args[0]);
  10631. break;
  10632. case _util.OPS.paintImageMaskXObject:
  10633. this.paintImageMaskXObject(args[0]);
  10634. break;
  10635. case _util.OPS.paintFormXObjectBegin:
  10636. this.paintFormXObjectBegin(args[0], args[1]);
  10637. break;
  10638. case _util.OPS.paintFormXObjectEnd:
  10639. this.paintFormXObjectEnd();
  10640. break;
  10641. case _util.OPS.closePath:
  10642. this.closePath();
  10643. break;
  10644. case _util.OPS.closeStroke:
  10645. this.closeStroke();
  10646. break;
  10647. case _util.OPS.closeFillStroke:
  10648. this.closeFillStroke();
  10649. break;
  10650. case _util.OPS.closeEOFillStroke:
  10651. this.closeEOFillStroke();
  10652. break;
  10653. case _util.OPS.nextLine:
  10654. this.nextLine();
  10655. break;
  10656. case _util.OPS.transform:
  10657. this.transform(args[0], args[1], args[2], args[3], args[4], args[5]);
  10658. break;
  10659. case _util.OPS.constructPath:
  10660. this.constructPath(args[0], args[1]);
  10661. break;
  10662. case _util.OPS.endPath:
  10663. this.endPath();
  10664. break;
  10665. case 92:
  10666. this.group(opTreeElement.items);
  10667. break;
  10668. default:
  10669. (0, _util.warn)(`Unimplemented operator ${fn}`);
  10670. break;
  10671. }
  10672. }
  10673. }
  10674. setWordSpacing(wordSpacing) {
  10675. this.current.wordSpacing = wordSpacing;
  10676. }
  10677. setCharSpacing(charSpacing) {
  10678. this.current.charSpacing = charSpacing;
  10679. }
  10680. nextLine() {
  10681. this.moveText(0, this.current.leading);
  10682. }
  10683. setTextMatrix(a, b, c, d, e, f) {
  10684. const current = this.current;
  10685. current.textMatrix = current.lineMatrix = [a, b, c, d, e, f];
  10686. current.textMatrixScale = Math.hypot(a, b);
  10687. current.x = current.lineX = 0;
  10688. current.y = current.lineY = 0;
  10689. current.xcoords = [];
  10690. current.ycoords = [];
  10691. current.tspan = this.svgFactory.createElement("svg:tspan");
  10692. current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
  10693. current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
  10694. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  10695. current.txtElement = this.svgFactory.createElement("svg:text");
  10696. current.txtElement.appendChild(current.tspan);
  10697. }
  10698. beginText() {
  10699. const current = this.current;
  10700. current.x = current.lineX = 0;
  10701. current.y = current.lineY = 0;
  10702. current.textMatrix = _util.IDENTITY_MATRIX;
  10703. current.lineMatrix = _util.IDENTITY_MATRIX;
  10704. current.textMatrixScale = 1;
  10705. current.tspan = this.svgFactory.createElement("svg:tspan");
  10706. current.txtElement = this.svgFactory.createElement("svg:text");
  10707. current.txtgrp = this.svgFactory.createElement("svg:g");
  10708. current.xcoords = [];
  10709. current.ycoords = [];
  10710. }
  10711. moveText(x, y) {
  10712. const current = this.current;
  10713. current.x = current.lineX += x;
  10714. current.y = current.lineY += y;
  10715. current.xcoords = [];
  10716. current.ycoords = [];
  10717. current.tspan = this.svgFactory.createElement("svg:tspan");
  10718. current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
  10719. current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
  10720. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  10721. }
  10722. showText(glyphs) {
  10723. const current = this.current;
  10724. const font = current.font;
  10725. const fontSize = current.fontSize;
  10726. if (fontSize === 0) {
  10727. return;
  10728. }
  10729. const fontSizeScale = current.fontSizeScale;
  10730. const charSpacing = current.charSpacing;
  10731. const wordSpacing = current.wordSpacing;
  10732. const fontDirection = current.fontDirection;
  10733. const textHScale = current.textHScale * fontDirection;
  10734. const vertical = font.vertical;
  10735. const spacingDir = vertical ? 1 : -1;
  10736. const defaultVMetrics = font.defaultVMetrics;
  10737. const widthAdvanceScale = fontSize * current.fontMatrix[0];
  10738. let x = 0;
  10739. for (const glyph of glyphs) {
  10740. if (glyph === null) {
  10741. x += fontDirection * wordSpacing;
  10742. continue;
  10743. } else if ((0, _util.isNum)(glyph)) {
  10744. x += spacingDir * glyph * fontSize / 1000;
  10745. continue;
  10746. }
  10747. const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  10748. const character = glyph.fontChar;
  10749. let scaledX, scaledY;
  10750. let width = glyph.width;
  10751. if (vertical) {
  10752. let vx;
  10753. const vmetric = glyph.vmetric || defaultVMetrics;
  10754. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  10755. vx = -vx * widthAdvanceScale;
  10756. const vy = vmetric[2] * widthAdvanceScale;
  10757. width = vmetric ? -vmetric[0] : width;
  10758. scaledX = vx / fontSizeScale;
  10759. scaledY = (x + vy) / fontSizeScale;
  10760. } else {
  10761. scaledX = x / fontSizeScale;
  10762. scaledY = 0;
  10763. }
  10764. if (glyph.isInFont || font.missingFile) {
  10765. current.xcoords.push(current.x + scaledX);
  10766. if (vertical) {
  10767. current.ycoords.push(-current.y + scaledY);
  10768. }
  10769. current.tspan.textContent += character;
  10770. } else {}
  10771. let charWidth;
  10772. if (vertical) {
  10773. charWidth = width * widthAdvanceScale - spacing * fontDirection;
  10774. } else {
  10775. charWidth = width * widthAdvanceScale + spacing * fontDirection;
  10776. }
  10777. x += charWidth;
  10778. }
  10779. current.tspan.setAttributeNS(null, "x", current.xcoords.map(pf).join(" "));
  10780. if (vertical) {
  10781. current.tspan.setAttributeNS(null, "y", current.ycoords.map(pf).join(" "));
  10782. } else {
  10783. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  10784. }
  10785. if (vertical) {
  10786. current.y -= x;
  10787. } else {
  10788. current.x += x * textHScale;
  10789. }
  10790. current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
  10791. current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
  10792. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  10793. current.tspan.setAttributeNS(null, "font-style", current.fontStyle);
  10794. }
  10795. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  10796. current.tspan.setAttributeNS(null, "font-weight", current.fontWeight);
  10797. }
  10798. const fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  10799. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  10800. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  10801. current.tspan.setAttributeNS(null, "fill", current.fillColor);
  10802. }
  10803. if (current.fillAlpha < 1) {
  10804. current.tspan.setAttributeNS(null, "fill-opacity", current.fillAlpha);
  10805. }
  10806. } else if (current.textRenderingMode === _util.TextRenderingMode.ADD_TO_PATH) {
  10807. current.tspan.setAttributeNS(null, "fill", "transparent");
  10808. } else {
  10809. current.tspan.setAttributeNS(null, "fill", "none");
  10810. }
  10811. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  10812. const lineWidthScale = 1 / (current.textMatrixScale || 1);
  10813. this._setStrokeAttributes(current.tspan, lineWidthScale);
  10814. }
  10815. let textMatrix = current.textMatrix;
  10816. if (current.textRise !== 0) {
  10817. textMatrix = textMatrix.slice();
  10818. textMatrix[5] += current.textRise;
  10819. }
  10820. current.txtElement.setAttributeNS(null, "transform", `${pm(textMatrix)} scale(${pf(textHScale)}, -1)`);
  10821. current.txtElement.setAttributeNS(XML_NS, "xml:space", "preserve");
  10822. current.txtElement.appendChild(current.tspan);
  10823. current.txtgrp.appendChild(current.txtElement);
  10824. this._ensureTransformGroup().appendChild(current.txtElement);
  10825. }
  10826. setLeadingMoveText(x, y) {
  10827. this.setLeading(-y);
  10828. this.moveText(x, y);
  10829. }
  10830. addFontStyle(fontObj) {
  10831. if (!fontObj.data) {
  10832. throw new Error("addFontStyle: No font data available, " + 'ensure that the "fontExtraProperties" API parameter is set.');
  10833. }
  10834. if (!this.cssStyle) {
  10835. this.cssStyle = this.svgFactory.createElement("svg:style");
  10836. this.cssStyle.setAttributeNS(null, "type", "text/css");
  10837. this.defs.appendChild(this.cssStyle);
  10838. }
  10839. const url = (0, _util.createObjectURL)(fontObj.data, fontObj.mimetype, this.forceDataSchema);
  10840. this.cssStyle.textContent += `@font-face { font-family: "${fontObj.loadedName}";` + ` src: url(${url}); }\n`;
  10841. }
  10842. setFont(details) {
  10843. const current = this.current;
  10844. const fontObj = this.commonObjs.get(details[0]);
  10845. let size = details[1];
  10846. current.font = fontObj;
  10847. if (this.embedFonts && !fontObj.missingFile && !this.embeddedFonts[fontObj.loadedName]) {
  10848. this.addFontStyle(fontObj);
  10849. this.embeddedFonts[fontObj.loadedName] = fontObj;
  10850. }
  10851. current.fontMatrix = fontObj.fontMatrix || _util.FONT_IDENTITY_MATRIX;
  10852. let bold = "normal";
  10853. if (fontObj.black) {
  10854. bold = "900";
  10855. } else if (fontObj.bold) {
  10856. bold = "bold";
  10857. }
  10858. const italic = fontObj.italic ? "italic" : "normal";
  10859. if (size < 0) {
  10860. size = -size;
  10861. current.fontDirection = -1;
  10862. } else {
  10863. current.fontDirection = 1;
  10864. }
  10865. current.fontSize = size;
  10866. current.fontFamily = fontObj.loadedName;
  10867. current.fontWeight = bold;
  10868. current.fontStyle = italic;
  10869. current.tspan = this.svgFactory.createElement("svg:tspan");
  10870. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  10871. current.xcoords = [];
  10872. current.ycoords = [];
  10873. }
  10874. endText() {
  10875. const current = this.current;
  10876. if (current.textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG && current.txtElement?.hasChildNodes()) {
  10877. current.element = current.txtElement;
  10878. this.clip("nonzero");
  10879. this.endPath();
  10880. }
  10881. }
  10882. setLineWidth(width) {
  10883. if (width > 0) {
  10884. this.current.lineWidth = width;
  10885. }
  10886. }
  10887. setLineCap(style) {
  10888. this.current.lineCap = LINE_CAP_STYLES[style];
  10889. }
  10890. setLineJoin(style) {
  10891. this.current.lineJoin = LINE_JOIN_STYLES[style];
  10892. }
  10893. setMiterLimit(limit) {
  10894. this.current.miterLimit = limit;
  10895. }
  10896. setStrokeAlpha(strokeAlpha) {
  10897. this.current.strokeAlpha = strokeAlpha;
  10898. }
  10899. setStrokeRGBColor(r, g, b) {
  10900. this.current.strokeColor = _util.Util.makeHexColor(r, g, b);
  10901. }
  10902. setFillAlpha(fillAlpha) {
  10903. this.current.fillAlpha = fillAlpha;
  10904. }
  10905. setFillRGBColor(r, g, b) {
  10906. this.current.fillColor = _util.Util.makeHexColor(r, g, b);
  10907. this.current.tspan = this.svgFactory.createElement("svg:tspan");
  10908. this.current.xcoords = [];
  10909. this.current.ycoords = [];
  10910. }
  10911. setStrokeColorN(args) {
  10912. this.current.strokeColor = this._makeColorN_Pattern(args);
  10913. }
  10914. setFillColorN(args) {
  10915. this.current.fillColor = this._makeColorN_Pattern(args);
  10916. }
  10917. shadingFill(args) {
  10918. const width = this.viewport.width;
  10919. const height = this.viewport.height;
  10920. const inv = _util.Util.inverseTransform(this.transformMatrix);
  10921. const bl = _util.Util.applyTransform([0, 0], inv);
  10922. const br = _util.Util.applyTransform([0, height], inv);
  10923. const ul = _util.Util.applyTransform([width, 0], inv);
  10924. const ur = _util.Util.applyTransform([width, height], inv);
  10925. const x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  10926. const y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  10927. const x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  10928. const y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  10929. const rect = this.svgFactory.createElement("svg:rect");
  10930. rect.setAttributeNS(null, "x", x0);
  10931. rect.setAttributeNS(null, "y", y0);
  10932. rect.setAttributeNS(null, "width", x1 - x0);
  10933. rect.setAttributeNS(null, "height", y1 - y0);
  10934. rect.setAttributeNS(null, "fill", this._makeShadingPattern(args));
  10935. if (this.current.fillAlpha < 1) {
  10936. rect.setAttributeNS(null, "fill-opacity", this.current.fillAlpha);
  10937. }
  10938. this._ensureTransformGroup().appendChild(rect);
  10939. }
  10940. _makeColorN_Pattern(args) {
  10941. if (args[0] === "TilingPattern") {
  10942. return this._makeTilingPattern(args);
  10943. }
  10944. return this._makeShadingPattern(args);
  10945. }
  10946. _makeTilingPattern(args) {
  10947. const color = args[1];
  10948. const operatorList = args[2];
  10949. const matrix = args[3] || _util.IDENTITY_MATRIX;
  10950. const [x0, y0, x1, y1] = args[4];
  10951. const xstep = args[5];
  10952. const ystep = args[6];
  10953. const paintType = args[7];
  10954. const tilingId = `shading${shadingCount++}`;
  10955. const [tx0, ty0, tx1, ty1] = _util.Util.normalizeRect([..._util.Util.applyTransform([x0, y0], matrix), ..._util.Util.applyTransform([x1, y1], matrix)]);
  10956. const [xscale, yscale] = _util.Util.singularValueDecompose2dScale(matrix);
  10957. const txstep = xstep * xscale;
  10958. const tystep = ystep * yscale;
  10959. const tiling = this.svgFactory.createElement("svg:pattern");
  10960. tiling.setAttributeNS(null, "id", tilingId);
  10961. tiling.setAttributeNS(null, "patternUnits", "userSpaceOnUse");
  10962. tiling.setAttributeNS(null, "width", txstep);
  10963. tiling.setAttributeNS(null, "height", tystep);
  10964. tiling.setAttributeNS(null, "x", `${tx0}`);
  10965. tiling.setAttributeNS(null, "y", `${ty0}`);
  10966. const svg = this.svg;
  10967. const transformMatrix = this.transformMatrix;
  10968. const fillColor = this.current.fillColor;
  10969. const strokeColor = this.current.strokeColor;
  10970. const bbox = this.svgFactory.create(tx1 - tx0, ty1 - ty0);
  10971. this.svg = bbox;
  10972. this.transformMatrix = matrix;
  10973. if (paintType === 2) {
  10974. const cssColor = _util.Util.makeHexColor(...color);
  10975. this.current.fillColor = cssColor;
  10976. this.current.strokeColor = cssColor;
  10977. }
  10978. this.executeOpTree(this.convertOpList(operatorList));
  10979. this.svg = svg;
  10980. this.transformMatrix = transformMatrix;
  10981. this.current.fillColor = fillColor;
  10982. this.current.strokeColor = strokeColor;
  10983. tiling.appendChild(bbox.childNodes[0]);
  10984. this.defs.appendChild(tiling);
  10985. return `url(#${tilingId})`;
  10986. }
  10987. _makeShadingPattern(args) {
  10988. if (typeof args === "string") {
  10989. args = this.objs.get(args);
  10990. }
  10991. switch (args[0]) {
  10992. case "RadialAxial":
  10993. const shadingId = `shading${shadingCount++}`;
  10994. const colorStops = args[3];
  10995. let gradient;
  10996. switch (args[1]) {
  10997. case "axial":
  10998. const point0 = args[4];
  10999. const point1 = args[5];
  11000. gradient = this.svgFactory.createElement("svg:linearGradient");
  11001. gradient.setAttributeNS(null, "id", shadingId);
  11002. gradient.setAttributeNS(null, "gradientUnits", "userSpaceOnUse");
  11003. gradient.setAttributeNS(null, "x1", point0[0]);
  11004. gradient.setAttributeNS(null, "y1", point0[1]);
  11005. gradient.setAttributeNS(null, "x2", point1[0]);
  11006. gradient.setAttributeNS(null, "y2", point1[1]);
  11007. break;
  11008. case "radial":
  11009. const focalPoint = args[4];
  11010. const circlePoint = args[5];
  11011. const focalRadius = args[6];
  11012. const circleRadius = args[7];
  11013. gradient = this.svgFactory.createElement("svg:radialGradient");
  11014. gradient.setAttributeNS(null, "id", shadingId);
  11015. gradient.setAttributeNS(null, "gradientUnits", "userSpaceOnUse");
  11016. gradient.setAttributeNS(null, "cx", circlePoint[0]);
  11017. gradient.setAttributeNS(null, "cy", circlePoint[1]);
  11018. gradient.setAttributeNS(null, "r", circleRadius);
  11019. gradient.setAttributeNS(null, "fx", focalPoint[0]);
  11020. gradient.setAttributeNS(null, "fy", focalPoint[1]);
  11021. gradient.setAttributeNS(null, "fr", focalRadius);
  11022. break;
  11023. default:
  11024. throw new Error(`Unknown RadialAxial type: ${args[1]}`);
  11025. }
  11026. for (const colorStop of colorStops) {
  11027. const stop = this.svgFactory.createElement("svg:stop");
  11028. stop.setAttributeNS(null, "offset", colorStop[0]);
  11029. stop.setAttributeNS(null, "stop-color", colorStop[1]);
  11030. gradient.appendChild(stop);
  11031. }
  11032. this.defs.appendChild(gradient);
  11033. return `url(#${shadingId})`;
  11034. case "Mesh":
  11035. (0, _util.warn)("Unimplemented pattern Mesh");
  11036. return null;
  11037. case "Dummy":
  11038. return "hotpink";
  11039. default:
  11040. throw new Error(`Unknown IR type: ${args[0]}`);
  11041. }
  11042. }
  11043. setDash(dashArray, dashPhase) {
  11044. this.current.dashArray = dashArray;
  11045. this.current.dashPhase = dashPhase;
  11046. }
  11047. constructPath(ops, args) {
  11048. const current = this.current;
  11049. let x = current.x,
  11050. y = current.y;
  11051. let d = [];
  11052. let j = 0;
  11053. for (const op of ops) {
  11054. switch (op | 0) {
  11055. case _util.OPS.rectangle:
  11056. x = args[j++];
  11057. y = args[j++];
  11058. const width = args[j++];
  11059. const height = args[j++];
  11060. const xw = x + width;
  11061. const yh = y + height;
  11062. d.push("M", pf(x), pf(y), "L", pf(xw), pf(y), "L", pf(xw), pf(yh), "L", pf(x), pf(yh), "Z");
  11063. break;
  11064. case _util.OPS.moveTo:
  11065. x = args[j++];
  11066. y = args[j++];
  11067. d.push("M", pf(x), pf(y));
  11068. break;
  11069. case _util.OPS.lineTo:
  11070. x = args[j++];
  11071. y = args[j++];
  11072. d.push("L", pf(x), pf(y));
  11073. break;
  11074. case _util.OPS.curveTo:
  11075. x = args[j + 4];
  11076. y = args[j + 5];
  11077. d.push("C", pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]), pf(x), pf(y));
  11078. j += 6;
  11079. break;
  11080. case _util.OPS.curveTo2:
  11081. d.push("C", pf(x), pf(y), pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]));
  11082. x = args[j + 2];
  11083. y = args[j + 3];
  11084. j += 4;
  11085. break;
  11086. case _util.OPS.curveTo3:
  11087. x = args[j + 2];
  11088. y = args[j + 3];
  11089. d.push("C", pf(args[j]), pf(args[j + 1]), pf(x), pf(y), pf(x), pf(y));
  11090. j += 4;
  11091. break;
  11092. case _util.OPS.closePath:
  11093. d.push("Z");
  11094. break;
  11095. }
  11096. }
  11097. d = d.join(" ");
  11098. if (current.path && ops.length > 0 && ops[0] !== _util.OPS.rectangle && ops[0] !== _util.OPS.moveTo) {
  11099. d = current.path.getAttributeNS(null, "d") + d;
  11100. } else {
  11101. current.path = this.svgFactory.createElement("svg:path");
  11102. this._ensureTransformGroup().appendChild(current.path);
  11103. }
  11104. current.path.setAttributeNS(null, "d", d);
  11105. current.path.setAttributeNS(null, "fill", "none");
  11106. current.element = current.path;
  11107. current.setCurrentPoint(x, y);
  11108. }
  11109. endPath() {
  11110. const current = this.current;
  11111. current.path = null;
  11112. if (!this.pendingClip) {
  11113. return;
  11114. }
  11115. if (!current.element) {
  11116. this.pendingClip = null;
  11117. return;
  11118. }
  11119. const clipId = `clippath${clipCount++}`;
  11120. const clipPath = this.svgFactory.createElement("svg:clipPath");
  11121. clipPath.setAttributeNS(null, "id", clipId);
  11122. clipPath.setAttributeNS(null, "transform", pm(this.transformMatrix));
  11123. const clipElement = current.element.cloneNode(true);
  11124. if (this.pendingClip === "evenodd") {
  11125. clipElement.setAttributeNS(null, "clip-rule", "evenodd");
  11126. } else {
  11127. clipElement.setAttributeNS(null, "clip-rule", "nonzero");
  11128. }
  11129. this.pendingClip = null;
  11130. clipPath.appendChild(clipElement);
  11131. this.defs.appendChild(clipPath);
  11132. if (current.activeClipUrl) {
  11133. current.clipGroup = null;
  11134. for (const prev of this.extraStack) {
  11135. prev.clipGroup = null;
  11136. }
  11137. clipPath.setAttributeNS(null, "clip-path", current.activeClipUrl);
  11138. }
  11139. current.activeClipUrl = `url(#${clipId})`;
  11140. this.tgrp = null;
  11141. }
  11142. clip(type) {
  11143. this.pendingClip = type;
  11144. }
  11145. closePath() {
  11146. const current = this.current;
  11147. if (current.path) {
  11148. const d = `${current.path.getAttributeNS(null, "d")}Z`;
  11149. current.path.setAttributeNS(null, "d", d);
  11150. }
  11151. }
  11152. setLeading(leading) {
  11153. this.current.leading = -leading;
  11154. }
  11155. setTextRise(textRise) {
  11156. this.current.textRise = textRise;
  11157. }
  11158. setTextRenderingMode(textRenderingMode) {
  11159. this.current.textRenderingMode = textRenderingMode;
  11160. }
  11161. setHScale(scale) {
  11162. this.current.textHScale = scale / 100;
  11163. }
  11164. setRenderingIntent(intent) {}
  11165. setFlatness(flatness) {}
  11166. setGState(states) {
  11167. for (const [key, value] of states) {
  11168. switch (key) {
  11169. case "LW":
  11170. this.setLineWidth(value);
  11171. break;
  11172. case "LC":
  11173. this.setLineCap(value);
  11174. break;
  11175. case "LJ":
  11176. this.setLineJoin(value);
  11177. break;
  11178. case "ML":
  11179. this.setMiterLimit(value);
  11180. break;
  11181. case "D":
  11182. this.setDash(value[0], value[1]);
  11183. break;
  11184. case "RI":
  11185. this.setRenderingIntent(value);
  11186. break;
  11187. case "FL":
  11188. this.setFlatness(value);
  11189. break;
  11190. case "Font":
  11191. this.setFont(value);
  11192. break;
  11193. case "CA":
  11194. this.setStrokeAlpha(value);
  11195. break;
  11196. case "ca":
  11197. this.setFillAlpha(value);
  11198. break;
  11199. default:
  11200. (0, _util.warn)(`Unimplemented graphic state operator ${key}`);
  11201. break;
  11202. }
  11203. }
  11204. }
  11205. fill() {
  11206. const current = this.current;
  11207. if (current.element) {
  11208. current.element.setAttributeNS(null, "fill", current.fillColor);
  11209. current.element.setAttributeNS(null, "fill-opacity", current.fillAlpha);
  11210. this.endPath();
  11211. }
  11212. }
  11213. stroke() {
  11214. const current = this.current;
  11215. if (current.element) {
  11216. this._setStrokeAttributes(current.element);
  11217. current.element.setAttributeNS(null, "fill", "none");
  11218. this.endPath();
  11219. }
  11220. }
  11221. _setStrokeAttributes(element, lineWidthScale = 1) {
  11222. const current = this.current;
  11223. let dashArray = current.dashArray;
  11224. if (lineWidthScale !== 1 && dashArray.length > 0) {
  11225. dashArray = dashArray.map(function (value) {
  11226. return lineWidthScale * value;
  11227. });
  11228. }
  11229. element.setAttributeNS(null, "stroke", current.strokeColor);
  11230. element.setAttributeNS(null, "stroke-opacity", current.strokeAlpha);
  11231. element.setAttributeNS(null, "stroke-miterlimit", pf(current.miterLimit));
  11232. element.setAttributeNS(null, "stroke-linecap", current.lineCap);
  11233. element.setAttributeNS(null, "stroke-linejoin", current.lineJoin);
  11234. element.setAttributeNS(null, "stroke-width", pf(lineWidthScale * current.lineWidth) + "px");
  11235. element.setAttributeNS(null, "stroke-dasharray", dashArray.map(pf).join(" "));
  11236. element.setAttributeNS(null, "stroke-dashoffset", pf(lineWidthScale * current.dashPhase) + "px");
  11237. }
  11238. eoFill() {
  11239. if (this.current.element) {
  11240. this.current.element.setAttributeNS(null, "fill-rule", "evenodd");
  11241. }
  11242. this.fill();
  11243. }
  11244. fillStroke() {
  11245. this.stroke();
  11246. this.fill();
  11247. }
  11248. eoFillStroke() {
  11249. if (this.current.element) {
  11250. this.current.element.setAttributeNS(null, "fill-rule", "evenodd");
  11251. }
  11252. this.fillStroke();
  11253. }
  11254. closeStroke() {
  11255. this.closePath();
  11256. this.stroke();
  11257. }
  11258. closeFillStroke() {
  11259. this.closePath();
  11260. this.fillStroke();
  11261. }
  11262. closeEOFillStroke() {
  11263. this.closePath();
  11264. this.eoFillStroke();
  11265. }
  11266. paintSolidColorImageMask() {
  11267. const rect = this.svgFactory.createElement("svg:rect");
  11268. rect.setAttributeNS(null, "x", "0");
  11269. rect.setAttributeNS(null, "y", "0");
  11270. rect.setAttributeNS(null, "width", "1px");
  11271. rect.setAttributeNS(null, "height", "1px");
  11272. rect.setAttributeNS(null, "fill", this.current.fillColor);
  11273. this._ensureTransformGroup().appendChild(rect);
  11274. }
  11275. paintImageXObject(objId) {
  11276. const imgData = objId.startsWith("g_") ? this.commonObjs.get(objId) : this.objs.get(objId);
  11277. if (!imgData) {
  11278. (0, _util.warn)(`Dependent image with object ID ${objId} is not ready yet`);
  11279. return;
  11280. }
  11281. this.paintInlineImageXObject(imgData);
  11282. }
  11283. paintInlineImageXObject(imgData, mask) {
  11284. const width = imgData.width;
  11285. const height = imgData.height;
  11286. const imgSrc = convertImgDataToPng(imgData, this.forceDataSchema, !!mask);
  11287. const cliprect = this.svgFactory.createElement("svg:rect");
  11288. cliprect.setAttributeNS(null, "x", "0");
  11289. cliprect.setAttributeNS(null, "y", "0");
  11290. cliprect.setAttributeNS(null, "width", pf(width));
  11291. cliprect.setAttributeNS(null, "height", pf(height));
  11292. this.current.element = cliprect;
  11293. this.clip("nonzero");
  11294. const imgEl = this.svgFactory.createElement("svg:image");
  11295. imgEl.setAttributeNS(XLINK_NS, "xlink:href", imgSrc);
  11296. imgEl.setAttributeNS(null, "x", "0");
  11297. imgEl.setAttributeNS(null, "y", pf(-height));
  11298. imgEl.setAttributeNS(null, "width", pf(width) + "px");
  11299. imgEl.setAttributeNS(null, "height", pf(height) + "px");
  11300. imgEl.setAttributeNS(null, "transform", `scale(${pf(1 / width)} ${pf(-1 / height)})`);
  11301. if (mask) {
  11302. mask.appendChild(imgEl);
  11303. } else {
  11304. this._ensureTransformGroup().appendChild(imgEl);
  11305. }
  11306. }
  11307. paintImageMaskXObject(imgData) {
  11308. const current = this.current;
  11309. const width = imgData.width;
  11310. const height = imgData.height;
  11311. const fillColor = current.fillColor;
  11312. current.maskId = `mask${maskCount++}`;
  11313. const mask = this.svgFactory.createElement("svg:mask");
  11314. mask.setAttributeNS(null, "id", current.maskId);
  11315. const rect = this.svgFactory.createElement("svg:rect");
  11316. rect.setAttributeNS(null, "x", "0");
  11317. rect.setAttributeNS(null, "y", "0");
  11318. rect.setAttributeNS(null, "width", pf(width));
  11319. rect.setAttributeNS(null, "height", pf(height));
  11320. rect.setAttributeNS(null, "fill", fillColor);
  11321. rect.setAttributeNS(null, "mask", `url(#${current.maskId})`);
  11322. this.defs.appendChild(mask);
  11323. this._ensureTransformGroup().appendChild(rect);
  11324. this.paintInlineImageXObject(imgData, mask);
  11325. }
  11326. paintFormXObjectBegin(matrix, bbox) {
  11327. if (Array.isArray(matrix) && matrix.length === 6) {
  11328. this.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
  11329. }
  11330. if (bbox) {
  11331. const width = bbox[2] - bbox[0];
  11332. const height = bbox[3] - bbox[1];
  11333. const cliprect = this.svgFactory.createElement("svg:rect");
  11334. cliprect.setAttributeNS(null, "x", bbox[0]);
  11335. cliprect.setAttributeNS(null, "y", bbox[1]);
  11336. cliprect.setAttributeNS(null, "width", pf(width));
  11337. cliprect.setAttributeNS(null, "height", pf(height));
  11338. this.current.element = cliprect;
  11339. this.clip("nonzero");
  11340. this.endPath();
  11341. }
  11342. }
  11343. paintFormXObjectEnd() {}
  11344. _initialize(viewport) {
  11345. const svg = this.svgFactory.create(viewport.width, viewport.height);
  11346. const definitions = this.svgFactory.createElement("svg:defs");
  11347. svg.appendChild(definitions);
  11348. this.defs = definitions;
  11349. const rootGroup = this.svgFactory.createElement("svg:g");
  11350. rootGroup.setAttributeNS(null, "transform", pm(viewport.transform));
  11351. svg.appendChild(rootGroup);
  11352. this.svg = rootGroup;
  11353. return svg;
  11354. }
  11355. _ensureClipGroup() {
  11356. if (!this.current.clipGroup) {
  11357. const clipGroup = this.svgFactory.createElement("svg:g");
  11358. clipGroup.setAttributeNS(null, "clip-path", this.current.activeClipUrl);
  11359. this.svg.appendChild(clipGroup);
  11360. this.current.clipGroup = clipGroup;
  11361. }
  11362. return this.current.clipGroup;
  11363. }
  11364. _ensureTransformGroup() {
  11365. if (!this.tgrp) {
  11366. this.tgrp = this.svgFactory.createElement("svg:g");
  11367. this.tgrp.setAttributeNS(null, "transform", pm(this.transformMatrix));
  11368. if (this.current.activeClipUrl) {
  11369. this._ensureClipGroup().appendChild(this.tgrp);
  11370. } else {
  11371. this.svg.appendChild(this.tgrp);
  11372. }
  11373. }
  11374. return this.tgrp;
  11375. }
  11376. };
  11377. }
  11378. /***/ }),
  11379. /* 23 */
  11380. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  11381. Object.defineProperty(exports, "__esModule", ({
  11382. value: true
  11383. }));
  11384. exports.PDFNodeStream = void 0;
  11385. var _util = __w_pdfjs_require__(2);
  11386. var _network_utils = __w_pdfjs_require__(24);
  11387. ;
  11388. const fs = require("fs");
  11389. const http = require("http");
  11390. const https = require("https");
  11391. const url = require("url");
  11392. const fileUriRegex = /^file:\/\/\/[a-zA-Z]:\//;
  11393. function parseUrl(sourceUrl) {
  11394. const parsedUrl = url.parse(sourceUrl);
  11395. if (parsedUrl.protocol === "file:" || parsedUrl.host) {
  11396. return parsedUrl;
  11397. }
  11398. if (/^[a-z]:[/\\]/i.test(sourceUrl)) {
  11399. return url.parse(`file:///${sourceUrl}`);
  11400. }
  11401. if (!parsedUrl.host) {
  11402. parsedUrl.protocol = "file:";
  11403. }
  11404. return parsedUrl;
  11405. }
  11406. class PDFNodeStream {
  11407. constructor(source) {
  11408. this.source = source;
  11409. this.url = parseUrl(source.url);
  11410. this.isHttp = this.url.protocol === "http:" || this.url.protocol === "https:";
  11411. this.isFsUrl = this.url.protocol === "file:";
  11412. this.httpHeaders = this.isHttp && source.httpHeaders || {};
  11413. this._fullRequestReader = null;
  11414. this._rangeRequestReaders = [];
  11415. }
  11416. get _progressiveDataLength() {
  11417. return this._fullRequestReader?._loaded ?? 0;
  11418. }
  11419. getFullReader() {
  11420. (0, _util.assert)(!this._fullRequestReader, "PDFNodeStream.getFullReader can only be called once.");
  11421. this._fullRequestReader = this.isFsUrl ? new PDFNodeStreamFsFullReader(this) : new PDFNodeStreamFullReader(this);
  11422. return this._fullRequestReader;
  11423. }
  11424. getRangeReader(start, end) {
  11425. if (end <= this._progressiveDataLength) {
  11426. return null;
  11427. }
  11428. const rangeReader = this.isFsUrl ? new PDFNodeStreamFsRangeReader(this, start, end) : new PDFNodeStreamRangeReader(this, start, end);
  11429. this._rangeRequestReaders.push(rangeReader);
  11430. return rangeReader;
  11431. }
  11432. cancelAllRequests(reason) {
  11433. if (this._fullRequestReader) {
  11434. this._fullRequestReader.cancel(reason);
  11435. }
  11436. for (const reader of this._rangeRequestReaders.slice(0)) {
  11437. reader.cancel(reason);
  11438. }
  11439. }
  11440. }
  11441. exports.PDFNodeStream = PDFNodeStream;
  11442. class BaseFullReader {
  11443. constructor(stream) {
  11444. this._url = stream.url;
  11445. this._done = false;
  11446. this._storedError = null;
  11447. this.onProgress = null;
  11448. const source = stream.source;
  11449. this._contentLength = source.length;
  11450. this._loaded = 0;
  11451. this._filename = null;
  11452. this._disableRange = source.disableRange || false;
  11453. this._rangeChunkSize = source.rangeChunkSize;
  11454. if (!this._rangeChunkSize && !this._disableRange) {
  11455. this._disableRange = true;
  11456. }
  11457. this._isStreamingSupported = !source.disableStream;
  11458. this._isRangeSupported = !source.disableRange;
  11459. this._readableStream = null;
  11460. this._readCapability = (0, _util.createPromiseCapability)();
  11461. this._headersCapability = (0, _util.createPromiseCapability)();
  11462. }
  11463. get headersReady() {
  11464. return this._headersCapability.promise;
  11465. }
  11466. get filename() {
  11467. return this._filename;
  11468. }
  11469. get contentLength() {
  11470. return this._contentLength;
  11471. }
  11472. get isRangeSupported() {
  11473. return this._isRangeSupported;
  11474. }
  11475. get isStreamingSupported() {
  11476. return this._isStreamingSupported;
  11477. }
  11478. async read() {
  11479. await this._readCapability.promise;
  11480. if (this._done) {
  11481. return {
  11482. value: undefined,
  11483. done: true
  11484. };
  11485. }
  11486. if (this._storedError) {
  11487. throw this._storedError;
  11488. }
  11489. const chunk = this._readableStream.read();
  11490. if (chunk === null) {
  11491. this._readCapability = (0, _util.createPromiseCapability)();
  11492. return this.read();
  11493. }
  11494. this._loaded += chunk.length;
  11495. if (this.onProgress) {
  11496. this.onProgress({
  11497. loaded: this._loaded,
  11498. total: this._contentLength
  11499. });
  11500. }
  11501. const buffer = new Uint8Array(chunk).buffer;
  11502. return {
  11503. value: buffer,
  11504. done: false
  11505. };
  11506. }
  11507. cancel(reason) {
  11508. if (!this._readableStream) {
  11509. this._error(reason);
  11510. return;
  11511. }
  11512. this._readableStream.destroy(reason);
  11513. }
  11514. _error(reason) {
  11515. this._storedError = reason;
  11516. this._readCapability.resolve();
  11517. }
  11518. _setReadableStream(readableStream) {
  11519. this._readableStream = readableStream;
  11520. readableStream.on("readable", () => {
  11521. this._readCapability.resolve();
  11522. });
  11523. readableStream.on("end", () => {
  11524. readableStream.destroy();
  11525. this._done = true;
  11526. this._readCapability.resolve();
  11527. });
  11528. readableStream.on("error", reason => {
  11529. this._error(reason);
  11530. });
  11531. if (!this._isStreamingSupported && this._isRangeSupported) {
  11532. this._error(new _util.AbortException("streaming is disabled"));
  11533. }
  11534. if (this._storedError) {
  11535. this._readableStream.destroy(this._storedError);
  11536. }
  11537. }
  11538. }
  11539. class BaseRangeReader {
  11540. constructor(stream) {
  11541. this._url = stream.url;
  11542. this._done = false;
  11543. this._storedError = null;
  11544. this.onProgress = null;
  11545. this._loaded = 0;
  11546. this._readableStream = null;
  11547. this._readCapability = (0, _util.createPromiseCapability)();
  11548. const source = stream.source;
  11549. this._isStreamingSupported = !source.disableStream;
  11550. }
  11551. get isStreamingSupported() {
  11552. return this._isStreamingSupported;
  11553. }
  11554. async read() {
  11555. await this._readCapability.promise;
  11556. if (this._done) {
  11557. return {
  11558. value: undefined,
  11559. done: true
  11560. };
  11561. }
  11562. if (this._storedError) {
  11563. throw this._storedError;
  11564. }
  11565. const chunk = this._readableStream.read();
  11566. if (chunk === null) {
  11567. this._readCapability = (0, _util.createPromiseCapability)();
  11568. return this.read();
  11569. }
  11570. this._loaded += chunk.length;
  11571. if (this.onProgress) {
  11572. this.onProgress({
  11573. loaded: this._loaded
  11574. });
  11575. }
  11576. const buffer = new Uint8Array(chunk).buffer;
  11577. return {
  11578. value: buffer,
  11579. done: false
  11580. };
  11581. }
  11582. cancel(reason) {
  11583. if (!this._readableStream) {
  11584. this._error(reason);
  11585. return;
  11586. }
  11587. this._readableStream.destroy(reason);
  11588. }
  11589. _error(reason) {
  11590. this._storedError = reason;
  11591. this._readCapability.resolve();
  11592. }
  11593. _setReadableStream(readableStream) {
  11594. this._readableStream = readableStream;
  11595. readableStream.on("readable", () => {
  11596. this._readCapability.resolve();
  11597. });
  11598. readableStream.on("end", () => {
  11599. readableStream.destroy();
  11600. this._done = true;
  11601. this._readCapability.resolve();
  11602. });
  11603. readableStream.on("error", reason => {
  11604. this._error(reason);
  11605. });
  11606. if (this._storedError) {
  11607. this._readableStream.destroy(this._storedError);
  11608. }
  11609. }
  11610. }
  11611. function createRequestOptions(parsedUrl, headers) {
  11612. return {
  11613. protocol: parsedUrl.protocol,
  11614. auth: parsedUrl.auth,
  11615. host: parsedUrl.hostname,
  11616. port: parsedUrl.port,
  11617. path: parsedUrl.path,
  11618. method: "GET",
  11619. headers
  11620. };
  11621. }
  11622. class PDFNodeStreamFullReader extends BaseFullReader {
  11623. constructor(stream) {
  11624. super(stream);
  11625. const handleResponse = response => {
  11626. if (response.statusCode === 404) {
  11627. const error = new _util.MissingPDFException(`Missing PDF "${this._url}".`);
  11628. this._storedError = error;
  11629. this._headersCapability.reject(error);
  11630. return;
  11631. }
  11632. this._headersCapability.resolve();
  11633. this._setReadableStream(response);
  11634. const getResponseHeader = name => {
  11635. return this._readableStream.headers[name.toLowerCase()];
  11636. };
  11637. const {
  11638. allowRangeRequests,
  11639. suggestedLength
  11640. } = (0, _network_utils.validateRangeRequestCapabilities)({
  11641. getResponseHeader,
  11642. isHttp: stream.isHttp,
  11643. rangeChunkSize: this._rangeChunkSize,
  11644. disableRange: this._disableRange
  11645. });
  11646. this._isRangeSupported = allowRangeRequests;
  11647. this._contentLength = suggestedLength || this._contentLength;
  11648. this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
  11649. };
  11650. this._request = null;
  11651. if (this._url.protocol === "http:") {
  11652. this._request = http.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
  11653. } else {
  11654. this._request = https.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
  11655. }
  11656. this._request.on("error", reason => {
  11657. this._storedError = reason;
  11658. this._headersCapability.reject(reason);
  11659. });
  11660. this._request.end();
  11661. }
  11662. }
  11663. class PDFNodeStreamRangeReader extends BaseRangeReader {
  11664. constructor(stream, start, end) {
  11665. super(stream);
  11666. this._httpHeaders = {};
  11667. for (const property in stream.httpHeaders) {
  11668. const value = stream.httpHeaders[property];
  11669. if (typeof value === "undefined") {
  11670. continue;
  11671. }
  11672. this._httpHeaders[property] = value;
  11673. }
  11674. this._httpHeaders.Range = `bytes=${start}-${end - 1}`;
  11675. const handleResponse = response => {
  11676. if (response.statusCode === 404) {
  11677. const error = new _util.MissingPDFException(`Missing PDF "${this._url}".`);
  11678. this._storedError = error;
  11679. return;
  11680. }
  11681. this._setReadableStream(response);
  11682. };
  11683. this._request = null;
  11684. if (this._url.protocol === "http:") {
  11685. this._request = http.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
  11686. } else {
  11687. this._request = https.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
  11688. }
  11689. this._request.on("error", reason => {
  11690. this._storedError = reason;
  11691. });
  11692. this._request.end();
  11693. }
  11694. }
  11695. class PDFNodeStreamFsFullReader extends BaseFullReader {
  11696. constructor(stream) {
  11697. super(stream);
  11698. let path = decodeURIComponent(this._url.path);
  11699. if (fileUriRegex.test(this._url.href)) {
  11700. path = path.replace(/^\//, "");
  11701. }
  11702. fs.lstat(path, (error, stat) => {
  11703. if (error) {
  11704. if (error.code === "ENOENT") {
  11705. error = new _util.MissingPDFException(`Missing PDF "${path}".`);
  11706. }
  11707. this._storedError = error;
  11708. this._headersCapability.reject(error);
  11709. return;
  11710. }
  11711. this._contentLength = stat.size;
  11712. this._setReadableStream(fs.createReadStream(path));
  11713. this._headersCapability.resolve();
  11714. });
  11715. }
  11716. }
  11717. class PDFNodeStreamFsRangeReader extends BaseRangeReader {
  11718. constructor(stream, start, end) {
  11719. super(stream);
  11720. let path = decodeURIComponent(this._url.path);
  11721. if (fileUriRegex.test(this._url.href)) {
  11722. path = path.replace(/^\//, "");
  11723. }
  11724. this._setReadableStream(fs.createReadStream(path, {
  11725. start,
  11726. end: end - 1
  11727. }));
  11728. }
  11729. }
  11730. /***/ }),
  11731. /* 24 */
  11732. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  11733. Object.defineProperty(exports, "__esModule", ({
  11734. value: true
  11735. }));
  11736. exports.createResponseStatusError = createResponseStatusError;
  11737. exports.extractFilenameFromHeader = extractFilenameFromHeader;
  11738. exports.validateRangeRequestCapabilities = validateRangeRequestCapabilities;
  11739. exports.validateResponseStatus = validateResponseStatus;
  11740. var _util = __w_pdfjs_require__(2);
  11741. var _content_disposition = __w_pdfjs_require__(25);
  11742. var _display_utils = __w_pdfjs_require__(1);
  11743. function validateRangeRequestCapabilities({
  11744. getResponseHeader,
  11745. isHttp,
  11746. rangeChunkSize,
  11747. disableRange
  11748. }) {
  11749. (0, _util.assert)(rangeChunkSize > 0, "Range chunk size must be larger than zero");
  11750. const returnValues = {
  11751. allowRangeRequests: false,
  11752. suggestedLength: undefined
  11753. };
  11754. const length = parseInt(getResponseHeader("Content-Length"), 10);
  11755. if (!Number.isInteger(length)) {
  11756. return returnValues;
  11757. }
  11758. returnValues.suggestedLength = length;
  11759. if (length <= 2 * rangeChunkSize) {
  11760. return returnValues;
  11761. }
  11762. if (disableRange || !isHttp) {
  11763. return returnValues;
  11764. }
  11765. if (getResponseHeader("Accept-Ranges") !== "bytes") {
  11766. return returnValues;
  11767. }
  11768. const contentEncoding = getResponseHeader("Content-Encoding") || "identity";
  11769. if (contentEncoding !== "identity") {
  11770. return returnValues;
  11771. }
  11772. returnValues.allowRangeRequests = true;
  11773. return returnValues;
  11774. }
  11775. function extractFilenameFromHeader(getResponseHeader) {
  11776. const contentDisposition = getResponseHeader("Content-Disposition");
  11777. if (contentDisposition) {
  11778. let filename = (0, _content_disposition.getFilenameFromContentDispositionHeader)(contentDisposition);
  11779. if (filename.includes("%")) {
  11780. try {
  11781. filename = decodeURIComponent(filename);
  11782. } catch (ex) {}
  11783. }
  11784. if ((0, _display_utils.isPdfFile)(filename)) {
  11785. return filename;
  11786. }
  11787. }
  11788. return null;
  11789. }
  11790. function createResponseStatusError(status, url) {
  11791. if (status === 404 || status === 0 && url.startsWith("file:")) {
  11792. return new _util.MissingPDFException('Missing PDF "' + url + '".');
  11793. }
  11794. return new _util.UnexpectedResponseException(`Unexpected server response (${status}) while retrieving PDF "${url}".`, status);
  11795. }
  11796. function validateResponseStatus(status) {
  11797. return status === 200 || status === 206;
  11798. }
  11799. /***/ }),
  11800. /* 25 */
  11801. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  11802. Object.defineProperty(exports, "__esModule", ({
  11803. value: true
  11804. }));
  11805. exports.getFilenameFromContentDispositionHeader = getFilenameFromContentDispositionHeader;
  11806. var _util = __w_pdfjs_require__(2);
  11807. function getFilenameFromContentDispositionHeader(contentDisposition) {
  11808. let needsEncodingFixup = true;
  11809. let tmp = toParamRegExp("filename\\*", "i").exec(contentDisposition);
  11810. if (tmp) {
  11811. tmp = tmp[1];
  11812. let filename = rfc2616unquote(tmp);
  11813. filename = unescape(filename);
  11814. filename = rfc5987decode(filename);
  11815. filename = rfc2047decode(filename);
  11816. return fixupEncoding(filename);
  11817. }
  11818. tmp = rfc2231getparam(contentDisposition);
  11819. if (tmp) {
  11820. const filename = rfc2047decode(tmp);
  11821. return fixupEncoding(filename);
  11822. }
  11823. tmp = toParamRegExp("filename", "i").exec(contentDisposition);
  11824. if (tmp) {
  11825. tmp = tmp[1];
  11826. let filename = rfc2616unquote(tmp);
  11827. filename = rfc2047decode(filename);
  11828. return fixupEncoding(filename);
  11829. }
  11830. function toParamRegExp(attributePattern, flags) {
  11831. return new RegExp("(?:^|;)\\s*" + attributePattern + "\\s*=\\s*" + "(" + '[^";\\s][^;\\s]*' + "|" + '"(?:[^"\\\\]|\\\\"?)+"?' + ")", flags);
  11832. }
  11833. function textdecode(encoding, value) {
  11834. if (encoding) {
  11835. if (!/^[\x00-\xFF]+$/.test(value)) {
  11836. return value;
  11837. }
  11838. try {
  11839. const decoder = new TextDecoder(encoding, {
  11840. fatal: true
  11841. });
  11842. const buffer = (0, _util.stringToBytes)(value);
  11843. value = decoder.decode(buffer);
  11844. needsEncodingFixup = false;
  11845. } catch (e) {
  11846. if (/^utf-?8$/i.test(encoding)) {
  11847. try {
  11848. value = decodeURIComponent(escape(value));
  11849. needsEncodingFixup = false;
  11850. } catch (err) {}
  11851. }
  11852. }
  11853. }
  11854. return value;
  11855. }
  11856. function fixupEncoding(value) {
  11857. if (needsEncodingFixup && /[\x80-\xff]/.test(value)) {
  11858. value = textdecode("utf-8", value);
  11859. if (needsEncodingFixup) {
  11860. value = textdecode("iso-8859-1", value);
  11861. }
  11862. }
  11863. return value;
  11864. }
  11865. function rfc2231getparam(contentDispositionStr) {
  11866. const matches = [];
  11867. let match;
  11868. const iter = toParamRegExp("filename\\*((?!0\\d)\\d+)(\\*?)", "ig");
  11869. while ((match = iter.exec(contentDispositionStr)) !== null) {
  11870. let [, n, quot, part] = match;
  11871. n = parseInt(n, 10);
  11872. if (n in matches) {
  11873. if (n === 0) {
  11874. break;
  11875. }
  11876. continue;
  11877. }
  11878. matches[n] = [quot, part];
  11879. }
  11880. const parts = [];
  11881. for (let n = 0; n < matches.length; ++n) {
  11882. if (!(n in matches)) {
  11883. break;
  11884. }
  11885. let [quot, part] = matches[n];
  11886. part = rfc2616unquote(part);
  11887. if (quot) {
  11888. part = unescape(part);
  11889. if (n === 0) {
  11890. part = rfc5987decode(part);
  11891. }
  11892. }
  11893. parts.push(part);
  11894. }
  11895. return parts.join("");
  11896. }
  11897. function rfc2616unquote(value) {
  11898. if (value.startsWith('"')) {
  11899. const parts = value.slice(1).split('\\"');
  11900. for (let i = 0; i < parts.length; ++i) {
  11901. const quotindex = parts[i].indexOf('"');
  11902. if (quotindex !== -1) {
  11903. parts[i] = parts[i].slice(0, quotindex);
  11904. parts.length = i + 1;
  11905. }
  11906. parts[i] = parts[i].replace(/\\(.)/g, "$1");
  11907. }
  11908. value = parts.join('"');
  11909. }
  11910. return value;
  11911. }
  11912. function rfc5987decode(extvalue) {
  11913. const encodingend = extvalue.indexOf("'");
  11914. if (encodingend === -1) {
  11915. return extvalue;
  11916. }
  11917. const encoding = extvalue.slice(0, encodingend);
  11918. const langvalue = extvalue.slice(encodingend + 1);
  11919. const value = langvalue.replace(/^[^']*'/, "");
  11920. return textdecode(encoding, value);
  11921. }
  11922. function rfc2047decode(value) {
  11923. if (!value.startsWith("=?") || /[\x00-\x19\x80-\xff]/.test(value)) {
  11924. return value;
  11925. }
  11926. return value.replace(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g, function (matches, charset, encoding, text) {
  11927. if (encoding === "q" || encoding === "Q") {
  11928. text = text.replace(/_/g, " ");
  11929. text = text.replace(/=([0-9a-fA-F]{2})/g, function (match, hex) {
  11930. return String.fromCharCode(parseInt(hex, 16));
  11931. });
  11932. return textdecode(charset, text);
  11933. }
  11934. try {
  11935. text = atob(text);
  11936. } catch (e) {}
  11937. return textdecode(charset, text);
  11938. });
  11939. }
  11940. return "";
  11941. }
  11942. /***/ }),
  11943. /* 26 */
  11944. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  11945. Object.defineProperty(exports, "__esModule", ({
  11946. value: true
  11947. }));
  11948. exports.PDFNetworkStream = void 0;
  11949. var _util = __w_pdfjs_require__(2);
  11950. var _network_utils = __w_pdfjs_require__(24);
  11951. ;
  11952. const OK_RESPONSE = 200;
  11953. const PARTIAL_CONTENT_RESPONSE = 206;
  11954. function getArrayBuffer(xhr) {
  11955. const data = xhr.response;
  11956. if (typeof data !== "string") {
  11957. return data;
  11958. }
  11959. const array = (0, _util.stringToBytes)(data);
  11960. return array.buffer;
  11961. }
  11962. class NetworkManager {
  11963. constructor(url, args = {}) {
  11964. this.url = url;
  11965. this.isHttp = /^https?:/i.test(url);
  11966. this.httpHeaders = this.isHttp && args.httpHeaders || Object.create(null);
  11967. this.withCredentials = args.withCredentials || false;
  11968. this.getXhr = args.getXhr || function NetworkManager_getXhr() {
  11969. return new XMLHttpRequest();
  11970. };
  11971. this.currXhrId = 0;
  11972. this.pendingRequests = Object.create(null);
  11973. }
  11974. requestRange(begin, end, listeners) {
  11975. const args = {
  11976. begin,
  11977. end
  11978. };
  11979. for (const prop in listeners) {
  11980. args[prop] = listeners[prop];
  11981. }
  11982. return this.request(args);
  11983. }
  11984. requestFull(listeners) {
  11985. return this.request(listeners);
  11986. }
  11987. request(args) {
  11988. const xhr = this.getXhr();
  11989. const xhrId = this.currXhrId++;
  11990. const pendingRequest = this.pendingRequests[xhrId] = {
  11991. xhr
  11992. };
  11993. xhr.open("GET", this.url);
  11994. xhr.withCredentials = this.withCredentials;
  11995. for (const property in this.httpHeaders) {
  11996. const value = this.httpHeaders[property];
  11997. if (typeof value === "undefined") {
  11998. continue;
  11999. }
  12000. xhr.setRequestHeader(property, value);
  12001. }
  12002. if (this.isHttp && "begin" in args && "end" in args) {
  12003. xhr.setRequestHeader("Range", `bytes=${args.begin}-${args.end - 1}`);
  12004. pendingRequest.expectedStatus = PARTIAL_CONTENT_RESPONSE;
  12005. } else {
  12006. pendingRequest.expectedStatus = OK_RESPONSE;
  12007. }
  12008. xhr.responseType = "arraybuffer";
  12009. if (args.onError) {
  12010. xhr.onerror = function (evt) {
  12011. args.onError(xhr.status);
  12012. };
  12013. }
  12014. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  12015. xhr.onprogress = this.onProgress.bind(this, xhrId);
  12016. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  12017. pendingRequest.onDone = args.onDone;
  12018. pendingRequest.onError = args.onError;
  12019. pendingRequest.onProgress = args.onProgress;
  12020. xhr.send(null);
  12021. return xhrId;
  12022. }
  12023. onProgress(xhrId, evt) {
  12024. const pendingRequest = this.pendingRequests[xhrId];
  12025. if (!pendingRequest) {
  12026. return;
  12027. }
  12028. pendingRequest.onProgress?.(evt);
  12029. }
  12030. onStateChange(xhrId, evt) {
  12031. const pendingRequest = this.pendingRequests[xhrId];
  12032. if (!pendingRequest) {
  12033. return;
  12034. }
  12035. const xhr = pendingRequest.xhr;
  12036. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  12037. pendingRequest.onHeadersReceived();
  12038. delete pendingRequest.onHeadersReceived;
  12039. }
  12040. if (xhr.readyState !== 4) {
  12041. return;
  12042. }
  12043. if (!(xhrId in this.pendingRequests)) {
  12044. return;
  12045. }
  12046. delete this.pendingRequests[xhrId];
  12047. if (xhr.status === 0 && this.isHttp) {
  12048. pendingRequest.onError?.(xhr.status);
  12049. return;
  12050. }
  12051. const xhrStatus = xhr.status || OK_RESPONSE;
  12052. const ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  12053. if (!ok_response_on_range_request && xhrStatus !== pendingRequest.expectedStatus) {
  12054. pendingRequest.onError?.(xhr.status);
  12055. return;
  12056. }
  12057. const chunk = getArrayBuffer(xhr);
  12058. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  12059. const rangeHeader = xhr.getResponseHeader("Content-Range");
  12060. const matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  12061. pendingRequest.onDone({
  12062. begin: parseInt(matches[1], 10),
  12063. chunk
  12064. });
  12065. } else if (chunk) {
  12066. pendingRequest.onDone({
  12067. begin: 0,
  12068. chunk
  12069. });
  12070. } else {
  12071. pendingRequest.onError?.(xhr.status);
  12072. }
  12073. }
  12074. getRequestXhr(xhrId) {
  12075. return this.pendingRequests[xhrId].xhr;
  12076. }
  12077. isPendingRequest(xhrId) {
  12078. return xhrId in this.pendingRequests;
  12079. }
  12080. abortRequest(xhrId) {
  12081. const xhr = this.pendingRequests[xhrId].xhr;
  12082. delete this.pendingRequests[xhrId];
  12083. xhr.abort();
  12084. }
  12085. }
  12086. class PDFNetworkStream {
  12087. constructor(source) {
  12088. this._source = source;
  12089. this._manager = new NetworkManager(source.url, {
  12090. httpHeaders: source.httpHeaders,
  12091. withCredentials: source.withCredentials
  12092. });
  12093. this._rangeChunkSize = source.rangeChunkSize;
  12094. this._fullRequestReader = null;
  12095. this._rangeRequestReaders = [];
  12096. }
  12097. _onRangeRequestReaderClosed(reader) {
  12098. const i = this._rangeRequestReaders.indexOf(reader);
  12099. if (i >= 0) {
  12100. this._rangeRequestReaders.splice(i, 1);
  12101. }
  12102. }
  12103. getFullReader() {
  12104. (0, _util.assert)(!this._fullRequestReader, "PDFNetworkStream.getFullReader can only be called once.");
  12105. this._fullRequestReader = new PDFNetworkStreamFullRequestReader(this._manager, this._source);
  12106. return this._fullRequestReader;
  12107. }
  12108. getRangeReader(begin, end) {
  12109. const reader = new PDFNetworkStreamRangeRequestReader(this._manager, begin, end);
  12110. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  12111. this._rangeRequestReaders.push(reader);
  12112. return reader;
  12113. }
  12114. cancelAllRequests(reason) {
  12115. this._fullRequestReader?.cancel(reason);
  12116. for (const reader of this._rangeRequestReaders.slice(0)) {
  12117. reader.cancel(reason);
  12118. }
  12119. }
  12120. }
  12121. exports.PDFNetworkStream = PDFNetworkStream;
  12122. class PDFNetworkStreamFullRequestReader {
  12123. constructor(manager, source) {
  12124. this._manager = manager;
  12125. const args = {
  12126. onHeadersReceived: this._onHeadersReceived.bind(this),
  12127. onDone: this._onDone.bind(this),
  12128. onError: this._onError.bind(this),
  12129. onProgress: this._onProgress.bind(this)
  12130. };
  12131. this._url = source.url;
  12132. this._fullRequestId = manager.requestFull(args);
  12133. this._headersReceivedCapability = (0, _util.createPromiseCapability)();
  12134. this._disableRange = source.disableRange || false;
  12135. this._contentLength = source.length;
  12136. this._rangeChunkSize = source.rangeChunkSize;
  12137. if (!this._rangeChunkSize && !this._disableRange) {
  12138. this._disableRange = true;
  12139. }
  12140. this._isStreamingSupported = false;
  12141. this._isRangeSupported = false;
  12142. this._cachedChunks = [];
  12143. this._requests = [];
  12144. this._done = false;
  12145. this._storedError = undefined;
  12146. this._filename = null;
  12147. this.onProgress = null;
  12148. }
  12149. _onHeadersReceived() {
  12150. const fullRequestXhrId = this._fullRequestId;
  12151. const fullRequestXhr = this._manager.getRequestXhr(fullRequestXhrId);
  12152. const getResponseHeader = name => {
  12153. return fullRequestXhr.getResponseHeader(name);
  12154. };
  12155. const {
  12156. allowRangeRequests,
  12157. suggestedLength
  12158. } = (0, _network_utils.validateRangeRequestCapabilities)({
  12159. getResponseHeader,
  12160. isHttp: this._manager.isHttp,
  12161. rangeChunkSize: this._rangeChunkSize,
  12162. disableRange: this._disableRange
  12163. });
  12164. if (allowRangeRequests) {
  12165. this._isRangeSupported = true;
  12166. }
  12167. this._contentLength = suggestedLength || this._contentLength;
  12168. this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
  12169. if (this._isRangeSupported) {
  12170. this._manager.abortRequest(fullRequestXhrId);
  12171. }
  12172. this._headersReceivedCapability.resolve();
  12173. }
  12174. _onDone(data) {
  12175. if (data) {
  12176. if (this._requests.length > 0) {
  12177. const requestCapability = this._requests.shift();
  12178. requestCapability.resolve({
  12179. value: data.chunk,
  12180. done: false
  12181. });
  12182. } else {
  12183. this._cachedChunks.push(data.chunk);
  12184. }
  12185. }
  12186. this._done = true;
  12187. if (this._cachedChunks.length > 0) {
  12188. return;
  12189. }
  12190. for (const requestCapability of this._requests) {
  12191. requestCapability.resolve({
  12192. value: undefined,
  12193. done: true
  12194. });
  12195. }
  12196. this._requests.length = 0;
  12197. }
  12198. _onError(status) {
  12199. this._storedError = (0, _network_utils.createResponseStatusError)(status, this._url);
  12200. this._headersReceivedCapability.reject(this._storedError);
  12201. for (const requestCapability of this._requests) {
  12202. requestCapability.reject(this._storedError);
  12203. }
  12204. this._requests.length = 0;
  12205. this._cachedChunks.length = 0;
  12206. }
  12207. _onProgress(evt) {
  12208. this.onProgress?.({
  12209. loaded: evt.loaded,
  12210. total: evt.lengthComputable ? evt.total : this._contentLength
  12211. });
  12212. }
  12213. get filename() {
  12214. return this._filename;
  12215. }
  12216. get isRangeSupported() {
  12217. return this._isRangeSupported;
  12218. }
  12219. get isStreamingSupported() {
  12220. return this._isStreamingSupported;
  12221. }
  12222. get contentLength() {
  12223. return this._contentLength;
  12224. }
  12225. get headersReady() {
  12226. return this._headersReceivedCapability.promise;
  12227. }
  12228. async read() {
  12229. if (this._storedError) {
  12230. throw this._storedError;
  12231. }
  12232. if (this._cachedChunks.length > 0) {
  12233. const chunk = this._cachedChunks.shift();
  12234. return {
  12235. value: chunk,
  12236. done: false
  12237. };
  12238. }
  12239. if (this._done) {
  12240. return {
  12241. value: undefined,
  12242. done: true
  12243. };
  12244. }
  12245. const requestCapability = (0, _util.createPromiseCapability)();
  12246. this._requests.push(requestCapability);
  12247. return requestCapability.promise;
  12248. }
  12249. cancel(reason) {
  12250. this._done = true;
  12251. this._headersReceivedCapability.reject(reason);
  12252. for (const requestCapability of this._requests) {
  12253. requestCapability.resolve({
  12254. value: undefined,
  12255. done: true
  12256. });
  12257. }
  12258. this._requests.length = 0;
  12259. if (this._manager.isPendingRequest(this._fullRequestId)) {
  12260. this._manager.abortRequest(this._fullRequestId);
  12261. }
  12262. this._fullRequestReader = null;
  12263. }
  12264. }
  12265. class PDFNetworkStreamRangeRequestReader {
  12266. constructor(manager, begin, end) {
  12267. this._manager = manager;
  12268. const args = {
  12269. onDone: this._onDone.bind(this),
  12270. onError: this._onError.bind(this),
  12271. onProgress: this._onProgress.bind(this)
  12272. };
  12273. this._url = manager.url;
  12274. this._requestId = manager.requestRange(begin, end, args);
  12275. this._requests = [];
  12276. this._queuedChunk = null;
  12277. this._done = false;
  12278. this._storedError = undefined;
  12279. this.onProgress = null;
  12280. this.onClosed = null;
  12281. }
  12282. _close() {
  12283. this.onClosed?.(this);
  12284. }
  12285. _onDone(data) {
  12286. const chunk = data.chunk;
  12287. if (this._requests.length > 0) {
  12288. const requestCapability = this._requests.shift();
  12289. requestCapability.resolve({
  12290. value: chunk,
  12291. done: false
  12292. });
  12293. } else {
  12294. this._queuedChunk = chunk;
  12295. }
  12296. this._done = true;
  12297. for (const requestCapability of this._requests) {
  12298. requestCapability.resolve({
  12299. value: undefined,
  12300. done: true
  12301. });
  12302. }
  12303. this._requests.length = 0;
  12304. this._close();
  12305. }
  12306. _onError(status) {
  12307. this._storedError = (0, _network_utils.createResponseStatusError)(status, this._url);
  12308. for (const requestCapability of this._requests) {
  12309. requestCapability.reject(this._storedError);
  12310. }
  12311. this._requests.length = 0;
  12312. this._queuedChunk = null;
  12313. }
  12314. _onProgress(evt) {
  12315. if (!this.isStreamingSupported) {
  12316. this.onProgress?.({
  12317. loaded: evt.loaded
  12318. });
  12319. }
  12320. }
  12321. get isStreamingSupported() {
  12322. return false;
  12323. }
  12324. async read() {
  12325. if (this._storedError) {
  12326. throw this._storedError;
  12327. }
  12328. if (this._queuedChunk !== null) {
  12329. const chunk = this._queuedChunk;
  12330. this._queuedChunk = null;
  12331. return {
  12332. value: chunk,
  12333. done: false
  12334. };
  12335. }
  12336. if (this._done) {
  12337. return {
  12338. value: undefined,
  12339. done: true
  12340. };
  12341. }
  12342. const requestCapability = (0, _util.createPromiseCapability)();
  12343. this._requests.push(requestCapability);
  12344. return requestCapability.promise;
  12345. }
  12346. cancel(reason) {
  12347. this._done = true;
  12348. for (const requestCapability of this._requests) {
  12349. requestCapability.resolve({
  12350. value: undefined,
  12351. done: true
  12352. });
  12353. }
  12354. this._requests.length = 0;
  12355. if (this._manager.isPendingRequest(this._requestId)) {
  12356. this._manager.abortRequest(this._requestId);
  12357. }
  12358. this._close();
  12359. }
  12360. }
  12361. /***/ }),
  12362. /* 27 */
  12363. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  12364. Object.defineProperty(exports, "__esModule", ({
  12365. value: true
  12366. }));
  12367. exports.PDFFetchStream = void 0;
  12368. var _util = __w_pdfjs_require__(2);
  12369. var _network_utils = __w_pdfjs_require__(24);
  12370. ;
  12371. function createFetchOptions(headers, withCredentials, abortController) {
  12372. return {
  12373. method: "GET",
  12374. headers,
  12375. signal: abortController?.signal,
  12376. mode: "cors",
  12377. credentials: withCredentials ? "include" : "same-origin",
  12378. redirect: "follow"
  12379. };
  12380. }
  12381. function createHeaders(httpHeaders) {
  12382. const headers = new Headers();
  12383. for (const property in httpHeaders) {
  12384. const value = httpHeaders[property];
  12385. if (typeof value === "undefined") {
  12386. continue;
  12387. }
  12388. headers.append(property, value);
  12389. }
  12390. return headers;
  12391. }
  12392. class PDFFetchStream {
  12393. constructor(source) {
  12394. this.source = source;
  12395. this.isHttp = /^https?:/i.test(source.url);
  12396. this.httpHeaders = this.isHttp && source.httpHeaders || {};
  12397. this._fullRequestReader = null;
  12398. this._rangeRequestReaders = [];
  12399. }
  12400. get _progressiveDataLength() {
  12401. return this._fullRequestReader?._loaded ?? 0;
  12402. }
  12403. getFullReader() {
  12404. (0, _util.assert)(!this._fullRequestReader, "PDFFetchStream.getFullReader can only be called once.");
  12405. this._fullRequestReader = new PDFFetchStreamReader(this);
  12406. return this._fullRequestReader;
  12407. }
  12408. getRangeReader(begin, end) {
  12409. if (end <= this._progressiveDataLength) {
  12410. return null;
  12411. }
  12412. const reader = new PDFFetchStreamRangeReader(this, begin, end);
  12413. this._rangeRequestReaders.push(reader);
  12414. return reader;
  12415. }
  12416. cancelAllRequests(reason) {
  12417. if (this._fullRequestReader) {
  12418. this._fullRequestReader.cancel(reason);
  12419. }
  12420. for (const reader of this._rangeRequestReaders.slice(0)) {
  12421. reader.cancel(reason);
  12422. }
  12423. }
  12424. }
  12425. exports.PDFFetchStream = PDFFetchStream;
  12426. class PDFFetchStreamReader {
  12427. constructor(stream) {
  12428. this._stream = stream;
  12429. this._reader = null;
  12430. this._loaded = 0;
  12431. this._filename = null;
  12432. const source = stream.source;
  12433. this._withCredentials = source.withCredentials || false;
  12434. this._contentLength = source.length;
  12435. this._headersCapability = (0, _util.createPromiseCapability)();
  12436. this._disableRange = source.disableRange || false;
  12437. this._rangeChunkSize = source.rangeChunkSize;
  12438. if (!this._rangeChunkSize && !this._disableRange) {
  12439. this._disableRange = true;
  12440. }
  12441. if (typeof AbortController !== "undefined") {
  12442. this._abortController = new AbortController();
  12443. }
  12444. this._isStreamingSupported = !source.disableStream;
  12445. this._isRangeSupported = !source.disableRange;
  12446. this._headers = createHeaders(this._stream.httpHeaders);
  12447. const url = source.url;
  12448. fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(response => {
  12449. if (!(0, _network_utils.validateResponseStatus)(response.status)) {
  12450. throw (0, _network_utils.createResponseStatusError)(response.status, url);
  12451. }
  12452. this._reader = response.body.getReader();
  12453. this._headersCapability.resolve();
  12454. const getResponseHeader = name => {
  12455. return response.headers.get(name);
  12456. };
  12457. const {
  12458. allowRangeRequests,
  12459. suggestedLength
  12460. } = (0, _network_utils.validateRangeRequestCapabilities)({
  12461. getResponseHeader,
  12462. isHttp: this._stream.isHttp,
  12463. rangeChunkSize: this._rangeChunkSize,
  12464. disableRange: this._disableRange
  12465. });
  12466. this._isRangeSupported = allowRangeRequests;
  12467. this._contentLength = suggestedLength || this._contentLength;
  12468. this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
  12469. if (!this._isStreamingSupported && this._isRangeSupported) {
  12470. this.cancel(new _util.AbortException("Streaming is disabled."));
  12471. }
  12472. }).catch(this._headersCapability.reject);
  12473. this.onProgress = null;
  12474. }
  12475. get headersReady() {
  12476. return this._headersCapability.promise;
  12477. }
  12478. get filename() {
  12479. return this._filename;
  12480. }
  12481. get contentLength() {
  12482. return this._contentLength;
  12483. }
  12484. get isRangeSupported() {
  12485. return this._isRangeSupported;
  12486. }
  12487. get isStreamingSupported() {
  12488. return this._isStreamingSupported;
  12489. }
  12490. async read() {
  12491. await this._headersCapability.promise;
  12492. const {
  12493. value,
  12494. done
  12495. } = await this._reader.read();
  12496. if (done) {
  12497. return {
  12498. value,
  12499. done
  12500. };
  12501. }
  12502. this._loaded += value.byteLength;
  12503. if (this.onProgress) {
  12504. this.onProgress({
  12505. loaded: this._loaded,
  12506. total: this._contentLength
  12507. });
  12508. }
  12509. const buffer = new Uint8Array(value).buffer;
  12510. return {
  12511. value: buffer,
  12512. done: false
  12513. };
  12514. }
  12515. cancel(reason) {
  12516. if (this._reader) {
  12517. this._reader.cancel(reason);
  12518. }
  12519. if (this._abortController) {
  12520. this._abortController.abort();
  12521. }
  12522. }
  12523. }
  12524. class PDFFetchStreamRangeReader {
  12525. constructor(stream, begin, end) {
  12526. this._stream = stream;
  12527. this._reader = null;
  12528. this._loaded = 0;
  12529. const source = stream.source;
  12530. this._withCredentials = source.withCredentials || false;
  12531. this._readCapability = (0, _util.createPromiseCapability)();
  12532. this._isStreamingSupported = !source.disableStream;
  12533. if (typeof AbortController !== "undefined") {
  12534. this._abortController = new AbortController();
  12535. }
  12536. this._headers = createHeaders(this._stream.httpHeaders);
  12537. this._headers.append("Range", `bytes=${begin}-${end - 1}`);
  12538. const url = source.url;
  12539. fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(response => {
  12540. if (!(0, _network_utils.validateResponseStatus)(response.status)) {
  12541. throw (0, _network_utils.createResponseStatusError)(response.status, url);
  12542. }
  12543. this._readCapability.resolve();
  12544. this._reader = response.body.getReader();
  12545. }).catch(this._readCapability.reject);
  12546. this.onProgress = null;
  12547. }
  12548. get isStreamingSupported() {
  12549. return this._isStreamingSupported;
  12550. }
  12551. async read() {
  12552. await this._readCapability.promise;
  12553. const {
  12554. value,
  12555. done
  12556. } = await this._reader.read();
  12557. if (done) {
  12558. return {
  12559. value,
  12560. done
  12561. };
  12562. }
  12563. this._loaded += value.byteLength;
  12564. if (this.onProgress) {
  12565. this.onProgress({
  12566. loaded: this._loaded
  12567. });
  12568. }
  12569. const buffer = new Uint8Array(value).buffer;
  12570. return {
  12571. value: buffer,
  12572. done: false
  12573. };
  12574. }
  12575. cancel(reason) {
  12576. if (this._reader) {
  12577. this._reader.cancel(reason);
  12578. }
  12579. if (this._abortController) {
  12580. this._abortController.abort();
  12581. }
  12582. }
  12583. }
  12584. /***/ })
  12585. /******/ ]);
  12586. /************************************************************************/
  12587. /******/ // The module cache
  12588. /******/ var __webpack_module_cache__ = {};
  12589. /******/
  12590. /******/ // The require function
  12591. /******/ function __w_pdfjs_require__(moduleId) {
  12592. /******/ // Check if module is in cache
  12593. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  12594. /******/ if (cachedModule !== undefined) {
  12595. /******/ return cachedModule.exports;
  12596. /******/ }
  12597. /******/ // Create a new module (and put it into the cache)
  12598. /******/ var module = __webpack_module_cache__[moduleId] = {
  12599. /******/ // no module.id needed
  12600. /******/ // no module.loaded needed
  12601. /******/ exports: {}
  12602. /******/ };
  12603. /******/
  12604. /******/ // Execute the module function
  12605. /******/ __webpack_modules__[moduleId](module, module.exports, __w_pdfjs_require__);
  12606. /******/
  12607. /******/ // Return the exports of the module
  12608. /******/ return module.exports;
  12609. /******/ }
  12610. /******/
  12611. /************************************************************************/
  12612. var __webpack_exports__ = {};
  12613. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  12614. (() => {
  12615. var exports = __webpack_exports__;
  12616. Object.defineProperty(exports, "__esModule", ({
  12617. value: true
  12618. }));
  12619. Object.defineProperty(exports, "AnnotationLayer", ({
  12620. enumerable: true,
  12621. get: function () {
  12622. return _annotation_layer.AnnotationLayer;
  12623. }
  12624. }));
  12625. Object.defineProperty(exports, "AnnotationMode", ({
  12626. enumerable: true,
  12627. get: function () {
  12628. return _util.AnnotationMode;
  12629. }
  12630. }));
  12631. Object.defineProperty(exports, "CMapCompressionType", ({
  12632. enumerable: true,
  12633. get: function () {
  12634. return _util.CMapCompressionType;
  12635. }
  12636. }));
  12637. Object.defineProperty(exports, "GlobalWorkerOptions", ({
  12638. enumerable: true,
  12639. get: function () {
  12640. return _worker_options.GlobalWorkerOptions;
  12641. }
  12642. }));
  12643. Object.defineProperty(exports, "InvalidPDFException", ({
  12644. enumerable: true,
  12645. get: function () {
  12646. return _util.InvalidPDFException;
  12647. }
  12648. }));
  12649. Object.defineProperty(exports, "LinkTarget", ({
  12650. enumerable: true,
  12651. get: function () {
  12652. return _display_utils.LinkTarget;
  12653. }
  12654. }));
  12655. Object.defineProperty(exports, "LoopbackPort", ({
  12656. enumerable: true,
  12657. get: function () {
  12658. return _api.LoopbackPort;
  12659. }
  12660. }));
  12661. Object.defineProperty(exports, "MissingPDFException", ({
  12662. enumerable: true,
  12663. get: function () {
  12664. return _util.MissingPDFException;
  12665. }
  12666. }));
  12667. Object.defineProperty(exports, "OPS", ({
  12668. enumerable: true,
  12669. get: function () {
  12670. return _util.OPS;
  12671. }
  12672. }));
  12673. Object.defineProperty(exports, "PDFDataRangeTransport", ({
  12674. enumerable: true,
  12675. get: function () {
  12676. return _api.PDFDataRangeTransport;
  12677. }
  12678. }));
  12679. Object.defineProperty(exports, "PDFDateString", ({
  12680. enumerable: true,
  12681. get: function () {
  12682. return _display_utils.PDFDateString;
  12683. }
  12684. }));
  12685. Object.defineProperty(exports, "PDFWorker", ({
  12686. enumerable: true,
  12687. get: function () {
  12688. return _api.PDFWorker;
  12689. }
  12690. }));
  12691. Object.defineProperty(exports, "PasswordResponses", ({
  12692. enumerable: true,
  12693. get: function () {
  12694. return _util.PasswordResponses;
  12695. }
  12696. }));
  12697. Object.defineProperty(exports, "PermissionFlag", ({
  12698. enumerable: true,
  12699. get: function () {
  12700. return _util.PermissionFlag;
  12701. }
  12702. }));
  12703. Object.defineProperty(exports, "PixelsPerInch", ({
  12704. enumerable: true,
  12705. get: function () {
  12706. return _display_utils.PixelsPerInch;
  12707. }
  12708. }));
  12709. Object.defineProperty(exports, "RenderingCancelledException", ({
  12710. enumerable: true,
  12711. get: function () {
  12712. return _display_utils.RenderingCancelledException;
  12713. }
  12714. }));
  12715. Object.defineProperty(exports, "SVGGraphics", ({
  12716. enumerable: true,
  12717. get: function () {
  12718. return _svg.SVGGraphics;
  12719. }
  12720. }));
  12721. Object.defineProperty(exports, "UNSUPPORTED_FEATURES", ({
  12722. enumerable: true,
  12723. get: function () {
  12724. return _util.UNSUPPORTED_FEATURES;
  12725. }
  12726. }));
  12727. Object.defineProperty(exports, "UnexpectedResponseException", ({
  12728. enumerable: true,
  12729. get: function () {
  12730. return _util.UnexpectedResponseException;
  12731. }
  12732. }));
  12733. Object.defineProperty(exports, "Util", ({
  12734. enumerable: true,
  12735. get: function () {
  12736. return _util.Util;
  12737. }
  12738. }));
  12739. Object.defineProperty(exports, "VerbosityLevel", ({
  12740. enumerable: true,
  12741. get: function () {
  12742. return _util.VerbosityLevel;
  12743. }
  12744. }));
  12745. Object.defineProperty(exports, "XfaLayer", ({
  12746. enumerable: true,
  12747. get: function () {
  12748. return _xfa_layer.XfaLayer;
  12749. }
  12750. }));
  12751. Object.defineProperty(exports, "addLinkAttributes", ({
  12752. enumerable: true,
  12753. get: function () {
  12754. return _display_utils.addLinkAttributes;
  12755. }
  12756. }));
  12757. Object.defineProperty(exports, "build", ({
  12758. enumerable: true,
  12759. get: function () {
  12760. return _api.build;
  12761. }
  12762. }));
  12763. Object.defineProperty(exports, "createObjectURL", ({
  12764. enumerable: true,
  12765. get: function () {
  12766. return _util.createObjectURL;
  12767. }
  12768. }));
  12769. Object.defineProperty(exports, "createPromiseCapability", ({
  12770. enumerable: true,
  12771. get: function () {
  12772. return _util.createPromiseCapability;
  12773. }
  12774. }));
  12775. Object.defineProperty(exports, "createValidAbsoluteUrl", ({
  12776. enumerable: true,
  12777. get: function () {
  12778. return _util.createValidAbsoluteUrl;
  12779. }
  12780. }));
  12781. Object.defineProperty(exports, "getDocument", ({
  12782. enumerable: true,
  12783. get: function () {
  12784. return _api.getDocument;
  12785. }
  12786. }));
  12787. Object.defineProperty(exports, "getFilenameFromUrl", ({
  12788. enumerable: true,
  12789. get: function () {
  12790. return _display_utils.getFilenameFromUrl;
  12791. }
  12792. }));
  12793. Object.defineProperty(exports, "getPdfFilenameFromUrl", ({
  12794. enumerable: true,
  12795. get: function () {
  12796. return _display_utils.getPdfFilenameFromUrl;
  12797. }
  12798. }));
  12799. Object.defineProperty(exports, "getXfaPageViewport", ({
  12800. enumerable: true,
  12801. get: function () {
  12802. return _display_utils.getXfaPageViewport;
  12803. }
  12804. }));
  12805. Object.defineProperty(exports, "isPdfFile", ({
  12806. enumerable: true,
  12807. get: function () {
  12808. return _display_utils.isPdfFile;
  12809. }
  12810. }));
  12811. Object.defineProperty(exports, "loadScript", ({
  12812. enumerable: true,
  12813. get: function () {
  12814. return _display_utils.loadScript;
  12815. }
  12816. }));
  12817. Object.defineProperty(exports, "removeNullCharacters", ({
  12818. enumerable: true,
  12819. get: function () {
  12820. return _util.removeNullCharacters;
  12821. }
  12822. }));
  12823. Object.defineProperty(exports, "renderTextLayer", ({
  12824. enumerable: true,
  12825. get: function () {
  12826. return _text_layer.renderTextLayer;
  12827. }
  12828. }));
  12829. Object.defineProperty(exports, "shadow", ({
  12830. enumerable: true,
  12831. get: function () {
  12832. return _util.shadow;
  12833. }
  12834. }));
  12835. Object.defineProperty(exports, "version", ({
  12836. enumerable: true,
  12837. get: function () {
  12838. return _api.version;
  12839. }
  12840. }));
  12841. var _display_utils = __w_pdfjs_require__(1);
  12842. var _util = __w_pdfjs_require__(2);
  12843. var _api = __w_pdfjs_require__(6);
  12844. var _annotation_layer = __w_pdfjs_require__(18);
  12845. var _worker_options = __w_pdfjs_require__(12);
  12846. var _is_node = __w_pdfjs_require__(4);
  12847. var _text_layer = __w_pdfjs_require__(21);
  12848. var _svg = __w_pdfjs_require__(22);
  12849. var _xfa_layer = __w_pdfjs_require__(20);
  12850. const pdfjsVersion = '2.12.313';
  12851. const pdfjsBuild = 'a2ae56f39';
  12852. {
  12853. if (_is_node.isNodeJS) {
  12854. const {
  12855. PDFNodeStream
  12856. } = __w_pdfjs_require__(23);
  12857. (0, _api.setPDFNetworkStreamFactory)(params => {
  12858. return new PDFNodeStream(params);
  12859. });
  12860. } else {
  12861. const {
  12862. PDFNetworkStream
  12863. } = __w_pdfjs_require__(26);
  12864. const {
  12865. PDFFetchStream
  12866. } = __w_pdfjs_require__(27);
  12867. (0, _api.setPDFNetworkStreamFactory)(params => {
  12868. if ((0, _display_utils.isValidFetchUrl)(params.url)) {
  12869. return new PDFFetchStream(params);
  12870. }
  12871. return new PDFNetworkStream(params);
  12872. });
  12873. }
  12874. }
  12875. })();
  12876. /******/ return __webpack_exports__;
  12877. /******/ })()
  12878. ;
  12879. });
  12880. //# sourceMappingURL=pdf.js.map