pdf.js 504 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * JavaScript code in this page
  4. *
  5. * Copyright 2022 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * JavaScript code in this page
  21. */
  22. (function webpackUniversalModuleDefinition(root, factory) {
  23. if(typeof exports === 'object' && typeof module === 'object')
  24. module.exports = factory();
  25. else if(typeof define === 'function' && define.amd)
  26. define("pdfjs-dist/build/pdf", [], factory);
  27. else if(typeof exports === 'object')
  28. exports["pdfjs-dist/build/pdf"] = factory();
  29. else
  30. root["pdfjs-dist/build/pdf"] = root.pdfjsLib = factory();
  31. })(globalThis, () => {
  32. return /******/ (() => { // webpackBootstrap
  33. /******/ "use strict";
  34. /******/ var __webpack_modules__ = ([
  35. /* 0 */,
  36. /* 1 */
  37. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  38. Object.defineProperty(exports, "__esModule", ({
  39. value: true
  40. }));
  41. exports.VerbosityLevel = exports.Util = exports.UnknownErrorException = exports.UnexpectedResponseException = exports.UNSUPPORTED_FEATURES = exports.TextRenderingMode = exports.StreamType = exports.RenderingIntentFlag = exports.PermissionFlag = exports.PasswordResponses = exports.PasswordException = exports.PageActionEventType = exports.OPS = exports.MissingPDFException = exports.LINE_FACTOR = exports.LINE_DESCENT_FACTOR = exports.InvalidPDFException = exports.ImageKind = exports.IDENTITY_MATRIX = exports.FormatError = exports.FontType = exports.FeatureTest = exports.FONT_IDENTITY_MATRIX = exports.DocumentActionEventType = exports.CMapCompressionType = exports.BaseException = exports.AnnotationType = exports.AnnotationStateModelType = exports.AnnotationReviewState = exports.AnnotationReplyType = exports.AnnotationMode = exports.AnnotationMarkedState = exports.AnnotationFlag = exports.AnnotationFieldFlag = exports.AnnotationEditorType = exports.AnnotationEditorPrefix = exports.AnnotationEditorParamsType = exports.AnnotationBorderStyleType = exports.AnnotationActionEventType = exports.AbortException = void 0;
  42. exports.arrayByteLength = arrayByteLength;
  43. exports.arraysToBytes = arraysToBytes;
  44. exports.assert = assert;
  45. exports.bytesToString = bytesToString;
  46. exports.createPromiseCapability = createPromiseCapability;
  47. exports.createValidAbsoluteUrl = createValidAbsoluteUrl;
  48. exports.escapeString = escapeString;
  49. exports.getModificationDate = getModificationDate;
  50. exports.getVerbosityLevel = getVerbosityLevel;
  51. exports.info = info;
  52. exports.isArrayBuffer = isArrayBuffer;
  53. exports.isArrayEqual = isArrayEqual;
  54. exports.isAscii = isAscii;
  55. exports.objectFromMap = objectFromMap;
  56. exports.objectSize = objectSize;
  57. exports.setVerbosityLevel = setVerbosityLevel;
  58. exports.shadow = shadow;
  59. exports.string32 = string32;
  60. exports.stringToBytes = stringToBytes;
  61. exports.stringToPDFString = stringToPDFString;
  62. exports.stringToUTF16BEString = stringToUTF16BEString;
  63. exports.stringToUTF8String = stringToUTF8String;
  64. exports.unreachable = unreachable;
  65. exports.utf8StringToString = utf8StringToString;
  66. exports.warn = warn;
  67. __w_pdfjs_require__(2);
  68. const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  69. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  70. const FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  71. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  72. const LINE_FACTOR = 1.35;
  73. exports.LINE_FACTOR = LINE_FACTOR;
  74. const LINE_DESCENT_FACTOR = 0.35;
  75. exports.LINE_DESCENT_FACTOR = LINE_DESCENT_FACTOR;
  76. const RenderingIntentFlag = {
  77. ANY: 0x01,
  78. DISPLAY: 0x02,
  79. PRINT: 0x04,
  80. ANNOTATIONS_FORMS: 0x10,
  81. ANNOTATIONS_STORAGE: 0x20,
  82. ANNOTATIONS_DISABLE: 0x40,
  83. OPLIST: 0x100
  84. };
  85. exports.RenderingIntentFlag = RenderingIntentFlag;
  86. const AnnotationMode = {
  87. DISABLE: 0,
  88. ENABLE: 1,
  89. ENABLE_FORMS: 2,
  90. ENABLE_STORAGE: 3
  91. };
  92. exports.AnnotationMode = AnnotationMode;
  93. const AnnotationEditorPrefix = "pdfjs_internal_editor_";
  94. exports.AnnotationEditorPrefix = AnnotationEditorPrefix;
  95. const AnnotationEditorType = {
  96. DISABLE: -1,
  97. NONE: 0,
  98. FREETEXT: 3,
  99. INK: 15
  100. };
  101. exports.AnnotationEditorType = AnnotationEditorType;
  102. const AnnotationEditorParamsType = {
  103. FREETEXT_SIZE: 1,
  104. FREETEXT_COLOR: 2,
  105. FREETEXT_OPACITY: 3,
  106. INK_COLOR: 11,
  107. INK_THICKNESS: 12,
  108. INK_OPACITY: 13
  109. };
  110. exports.AnnotationEditorParamsType = AnnotationEditorParamsType;
  111. const PermissionFlag = {
  112. PRINT: 0x04,
  113. MODIFY_CONTENTS: 0x08,
  114. COPY: 0x10,
  115. MODIFY_ANNOTATIONS: 0x20,
  116. FILL_INTERACTIVE_FORMS: 0x100,
  117. COPY_FOR_ACCESSIBILITY: 0x200,
  118. ASSEMBLE: 0x400,
  119. PRINT_HIGH_QUALITY: 0x800
  120. };
  121. exports.PermissionFlag = PermissionFlag;
  122. const TextRenderingMode = {
  123. FILL: 0,
  124. STROKE: 1,
  125. FILL_STROKE: 2,
  126. INVISIBLE: 3,
  127. FILL_ADD_TO_PATH: 4,
  128. STROKE_ADD_TO_PATH: 5,
  129. FILL_STROKE_ADD_TO_PATH: 6,
  130. ADD_TO_PATH: 7,
  131. FILL_STROKE_MASK: 3,
  132. ADD_TO_PATH_FLAG: 4
  133. };
  134. exports.TextRenderingMode = TextRenderingMode;
  135. const ImageKind = {
  136. GRAYSCALE_1BPP: 1,
  137. RGB_24BPP: 2,
  138. RGBA_32BPP: 3
  139. };
  140. exports.ImageKind = ImageKind;
  141. const AnnotationType = {
  142. TEXT: 1,
  143. LINK: 2,
  144. FREETEXT: 3,
  145. LINE: 4,
  146. SQUARE: 5,
  147. CIRCLE: 6,
  148. POLYGON: 7,
  149. POLYLINE: 8,
  150. HIGHLIGHT: 9,
  151. UNDERLINE: 10,
  152. SQUIGGLY: 11,
  153. STRIKEOUT: 12,
  154. STAMP: 13,
  155. CARET: 14,
  156. INK: 15,
  157. POPUP: 16,
  158. FILEATTACHMENT: 17,
  159. SOUND: 18,
  160. MOVIE: 19,
  161. WIDGET: 20,
  162. SCREEN: 21,
  163. PRINTERMARK: 22,
  164. TRAPNET: 23,
  165. WATERMARK: 24,
  166. THREED: 25,
  167. REDACT: 26
  168. };
  169. exports.AnnotationType = AnnotationType;
  170. const AnnotationStateModelType = {
  171. MARKED: "Marked",
  172. REVIEW: "Review"
  173. };
  174. exports.AnnotationStateModelType = AnnotationStateModelType;
  175. const AnnotationMarkedState = {
  176. MARKED: "Marked",
  177. UNMARKED: "Unmarked"
  178. };
  179. exports.AnnotationMarkedState = AnnotationMarkedState;
  180. const AnnotationReviewState = {
  181. ACCEPTED: "Accepted",
  182. REJECTED: "Rejected",
  183. CANCELLED: "Cancelled",
  184. COMPLETED: "Completed",
  185. NONE: "None"
  186. };
  187. exports.AnnotationReviewState = AnnotationReviewState;
  188. const AnnotationReplyType = {
  189. GROUP: "Group",
  190. REPLY: "R"
  191. };
  192. exports.AnnotationReplyType = AnnotationReplyType;
  193. const AnnotationFlag = {
  194. INVISIBLE: 0x01,
  195. HIDDEN: 0x02,
  196. PRINT: 0x04,
  197. NOZOOM: 0x08,
  198. NOROTATE: 0x10,
  199. NOVIEW: 0x20,
  200. READONLY: 0x40,
  201. LOCKED: 0x80,
  202. TOGGLENOVIEW: 0x100,
  203. LOCKEDCONTENTS: 0x200
  204. };
  205. exports.AnnotationFlag = AnnotationFlag;
  206. const AnnotationFieldFlag = {
  207. READONLY: 0x0000001,
  208. REQUIRED: 0x0000002,
  209. NOEXPORT: 0x0000004,
  210. MULTILINE: 0x0001000,
  211. PASSWORD: 0x0002000,
  212. NOTOGGLETOOFF: 0x0004000,
  213. RADIO: 0x0008000,
  214. PUSHBUTTON: 0x0010000,
  215. COMBO: 0x0020000,
  216. EDIT: 0x0040000,
  217. SORT: 0x0080000,
  218. FILESELECT: 0x0100000,
  219. MULTISELECT: 0x0200000,
  220. DONOTSPELLCHECK: 0x0400000,
  221. DONOTSCROLL: 0x0800000,
  222. COMB: 0x1000000,
  223. RICHTEXT: 0x2000000,
  224. RADIOSINUNISON: 0x2000000,
  225. COMMITONSELCHANGE: 0x4000000
  226. };
  227. exports.AnnotationFieldFlag = AnnotationFieldFlag;
  228. const AnnotationBorderStyleType = {
  229. SOLID: 1,
  230. DASHED: 2,
  231. BEVELED: 3,
  232. INSET: 4,
  233. UNDERLINE: 5
  234. };
  235. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  236. const AnnotationActionEventType = {
  237. E: "Mouse Enter",
  238. X: "Mouse Exit",
  239. D: "Mouse Down",
  240. U: "Mouse Up",
  241. Fo: "Focus",
  242. Bl: "Blur",
  243. PO: "PageOpen",
  244. PC: "PageClose",
  245. PV: "PageVisible",
  246. PI: "PageInvisible",
  247. K: "Keystroke",
  248. F: "Format",
  249. V: "Validate",
  250. C: "Calculate"
  251. };
  252. exports.AnnotationActionEventType = AnnotationActionEventType;
  253. const DocumentActionEventType = {
  254. WC: "WillClose",
  255. WS: "WillSave",
  256. DS: "DidSave",
  257. WP: "WillPrint",
  258. DP: "DidPrint"
  259. };
  260. exports.DocumentActionEventType = DocumentActionEventType;
  261. const PageActionEventType = {
  262. O: "PageOpen",
  263. C: "PageClose"
  264. };
  265. exports.PageActionEventType = PageActionEventType;
  266. const StreamType = {
  267. UNKNOWN: "UNKNOWN",
  268. FLATE: "FLATE",
  269. LZW: "LZW",
  270. DCT: "DCT",
  271. JPX: "JPX",
  272. JBIG: "JBIG",
  273. A85: "A85",
  274. AHX: "AHX",
  275. CCF: "CCF",
  276. RLX: "RLX"
  277. };
  278. exports.StreamType = StreamType;
  279. const FontType = {
  280. UNKNOWN: "UNKNOWN",
  281. TYPE1: "TYPE1",
  282. TYPE1STANDARD: "TYPE1STANDARD",
  283. TYPE1C: "TYPE1C",
  284. CIDFONTTYPE0: "CIDFONTTYPE0",
  285. CIDFONTTYPE0C: "CIDFONTTYPE0C",
  286. TRUETYPE: "TRUETYPE",
  287. CIDFONTTYPE2: "CIDFONTTYPE2",
  288. TYPE3: "TYPE3",
  289. OPENTYPE: "OPENTYPE",
  290. TYPE0: "TYPE0",
  291. MMTYPE1: "MMTYPE1"
  292. };
  293. exports.FontType = FontType;
  294. const VerbosityLevel = {
  295. ERRORS: 0,
  296. WARNINGS: 1,
  297. INFOS: 5
  298. };
  299. exports.VerbosityLevel = VerbosityLevel;
  300. const CMapCompressionType = {
  301. NONE: 0,
  302. BINARY: 1,
  303. STREAM: 2
  304. };
  305. exports.CMapCompressionType = CMapCompressionType;
  306. const OPS = {
  307. dependency: 1,
  308. setLineWidth: 2,
  309. setLineCap: 3,
  310. setLineJoin: 4,
  311. setMiterLimit: 5,
  312. setDash: 6,
  313. setRenderingIntent: 7,
  314. setFlatness: 8,
  315. setGState: 9,
  316. save: 10,
  317. restore: 11,
  318. transform: 12,
  319. moveTo: 13,
  320. lineTo: 14,
  321. curveTo: 15,
  322. curveTo2: 16,
  323. curveTo3: 17,
  324. closePath: 18,
  325. rectangle: 19,
  326. stroke: 20,
  327. closeStroke: 21,
  328. fill: 22,
  329. eoFill: 23,
  330. fillStroke: 24,
  331. eoFillStroke: 25,
  332. closeFillStroke: 26,
  333. closeEOFillStroke: 27,
  334. endPath: 28,
  335. clip: 29,
  336. eoClip: 30,
  337. beginText: 31,
  338. endText: 32,
  339. setCharSpacing: 33,
  340. setWordSpacing: 34,
  341. setHScale: 35,
  342. setLeading: 36,
  343. setFont: 37,
  344. setTextRenderingMode: 38,
  345. setTextRise: 39,
  346. moveText: 40,
  347. setLeadingMoveText: 41,
  348. setTextMatrix: 42,
  349. nextLine: 43,
  350. showText: 44,
  351. showSpacedText: 45,
  352. nextLineShowText: 46,
  353. nextLineSetSpacingShowText: 47,
  354. setCharWidth: 48,
  355. setCharWidthAndBounds: 49,
  356. setStrokeColorSpace: 50,
  357. setFillColorSpace: 51,
  358. setStrokeColor: 52,
  359. setStrokeColorN: 53,
  360. setFillColor: 54,
  361. setFillColorN: 55,
  362. setStrokeGray: 56,
  363. setFillGray: 57,
  364. setStrokeRGBColor: 58,
  365. setFillRGBColor: 59,
  366. setStrokeCMYKColor: 60,
  367. setFillCMYKColor: 61,
  368. shadingFill: 62,
  369. beginInlineImage: 63,
  370. beginImageData: 64,
  371. endInlineImage: 65,
  372. paintXObject: 66,
  373. markPoint: 67,
  374. markPointProps: 68,
  375. beginMarkedContent: 69,
  376. beginMarkedContentProps: 70,
  377. endMarkedContent: 71,
  378. beginCompat: 72,
  379. endCompat: 73,
  380. paintFormXObjectBegin: 74,
  381. paintFormXObjectEnd: 75,
  382. beginGroup: 76,
  383. endGroup: 77,
  384. beginAnnotations: 78,
  385. endAnnotations: 79,
  386. beginAnnotation: 80,
  387. endAnnotation: 81,
  388. paintJpegXObject: 82,
  389. paintImageMaskXObject: 83,
  390. paintImageMaskXObjectGroup: 84,
  391. paintImageXObject: 85,
  392. paintInlineImageXObject: 86,
  393. paintInlineImageXObjectGroup: 87,
  394. paintImageXObjectRepeat: 88,
  395. paintImageMaskXObjectRepeat: 89,
  396. paintSolidColorImageMask: 90,
  397. constructPath: 91
  398. };
  399. exports.OPS = OPS;
  400. const UNSUPPORTED_FEATURES = {
  401. unknown: "unknown",
  402. forms: "forms",
  403. javaScript: "javaScript",
  404. signatures: "signatures",
  405. smask: "smask",
  406. shadingPattern: "shadingPattern",
  407. font: "font",
  408. errorTilingPattern: "errorTilingPattern",
  409. errorExtGState: "errorExtGState",
  410. errorXObject: "errorXObject",
  411. errorFontLoadType3: "errorFontLoadType3",
  412. errorFontState: "errorFontState",
  413. errorFontMissing: "errorFontMissing",
  414. errorFontTranslate: "errorFontTranslate",
  415. errorColorSpace: "errorColorSpace",
  416. errorOperatorList: "errorOperatorList",
  417. errorFontToUnicode: "errorFontToUnicode",
  418. errorFontLoadNative: "errorFontLoadNative",
  419. errorFontBuildPath: "errorFontBuildPath",
  420. errorFontGetPath: "errorFontGetPath",
  421. errorMarkedContent: "errorMarkedContent",
  422. errorContentSubStream: "errorContentSubStream"
  423. };
  424. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  425. const PasswordResponses = {
  426. NEED_PASSWORD: 1,
  427. INCORRECT_PASSWORD: 2
  428. };
  429. exports.PasswordResponses = PasswordResponses;
  430. let verbosity = VerbosityLevel.WARNINGS;
  431. function setVerbosityLevel(level) {
  432. if (Number.isInteger(level)) {
  433. verbosity = level;
  434. }
  435. }
  436. function getVerbosityLevel() {
  437. return verbosity;
  438. }
  439. function info(msg) {
  440. if (verbosity >= VerbosityLevel.INFOS) {
  441. console.log(`Info: ${msg}`);
  442. }
  443. }
  444. function warn(msg) {
  445. if (verbosity >= VerbosityLevel.WARNINGS) {
  446. console.log(`Warning: ${msg}`);
  447. }
  448. }
  449. function unreachable(msg) {
  450. throw new Error(msg);
  451. }
  452. function assert(cond, msg) {
  453. if (!cond) {
  454. unreachable(msg);
  455. }
  456. }
  457. function _isValidProtocol(url) {
  458. if (!url) {
  459. return false;
  460. }
  461. switch (url.protocol) {
  462. case "http:":
  463. case "https:":
  464. case "ftp:":
  465. case "mailto:":
  466. case "tel:":
  467. return true;
  468. default:
  469. return false;
  470. }
  471. }
  472. function createValidAbsoluteUrl(url, baseUrl = null, options = null) {
  473. if (!url) {
  474. return null;
  475. }
  476. try {
  477. if (options && typeof url === "string") {
  478. if (options.addDefaultProtocol && url.startsWith("www.")) {
  479. const dots = url.match(/\./g);
  480. if (dots && dots.length >= 2) {
  481. url = `http://${url}`;
  482. }
  483. }
  484. if (options.tryConvertEncoding) {
  485. try {
  486. url = stringToUTF8String(url);
  487. } catch (ex) {}
  488. }
  489. }
  490. const absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url);
  491. if (_isValidProtocol(absoluteUrl)) {
  492. return absoluteUrl;
  493. }
  494. } catch (ex) {}
  495. return null;
  496. }
  497. function shadow(obj, prop, value) {
  498. Object.defineProperty(obj, prop, {
  499. value,
  500. enumerable: true,
  501. configurable: true,
  502. writable: false
  503. });
  504. return value;
  505. }
  506. const BaseException = function BaseExceptionClosure() {
  507. function BaseException(message, name) {
  508. if (this.constructor === BaseException) {
  509. unreachable("Cannot initialize BaseException.");
  510. }
  511. this.message = message;
  512. this.name = name;
  513. }
  514. BaseException.prototype = new Error();
  515. BaseException.constructor = BaseException;
  516. return BaseException;
  517. }();
  518. exports.BaseException = BaseException;
  519. class PasswordException extends BaseException {
  520. constructor(msg, code) {
  521. super(msg, "PasswordException");
  522. this.code = code;
  523. }
  524. }
  525. exports.PasswordException = PasswordException;
  526. class UnknownErrorException extends BaseException {
  527. constructor(msg, details) {
  528. super(msg, "UnknownErrorException");
  529. this.details = details;
  530. }
  531. }
  532. exports.UnknownErrorException = UnknownErrorException;
  533. class InvalidPDFException extends BaseException {
  534. constructor(msg) {
  535. super(msg, "InvalidPDFException");
  536. }
  537. }
  538. exports.InvalidPDFException = InvalidPDFException;
  539. class MissingPDFException extends BaseException {
  540. constructor(msg) {
  541. super(msg, "MissingPDFException");
  542. }
  543. }
  544. exports.MissingPDFException = MissingPDFException;
  545. class UnexpectedResponseException extends BaseException {
  546. constructor(msg, status) {
  547. super(msg, "UnexpectedResponseException");
  548. this.status = status;
  549. }
  550. }
  551. exports.UnexpectedResponseException = UnexpectedResponseException;
  552. class FormatError extends BaseException {
  553. constructor(msg) {
  554. super(msg, "FormatError");
  555. }
  556. }
  557. exports.FormatError = FormatError;
  558. class AbortException extends BaseException {
  559. constructor(msg) {
  560. super(msg, "AbortException");
  561. }
  562. }
  563. exports.AbortException = AbortException;
  564. function bytesToString(bytes) {
  565. if (typeof bytes !== "object" || bytes === null || bytes.length === undefined) {
  566. unreachable("Invalid argument for bytesToString");
  567. }
  568. const length = bytes.length;
  569. const MAX_ARGUMENT_COUNT = 8192;
  570. if (length < MAX_ARGUMENT_COUNT) {
  571. return String.fromCharCode.apply(null, bytes);
  572. }
  573. const strBuf = [];
  574. for (let i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  575. const chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  576. const chunk = bytes.subarray(i, chunkEnd);
  577. strBuf.push(String.fromCharCode.apply(null, chunk));
  578. }
  579. return strBuf.join("");
  580. }
  581. function stringToBytes(str) {
  582. if (typeof str !== "string") {
  583. unreachable("Invalid argument for stringToBytes");
  584. }
  585. const length = str.length;
  586. const bytes = new Uint8Array(length);
  587. for (let i = 0; i < length; ++i) {
  588. bytes[i] = str.charCodeAt(i) & 0xff;
  589. }
  590. return bytes;
  591. }
  592. function arrayByteLength(arr) {
  593. if (arr.length !== undefined) {
  594. return arr.length;
  595. }
  596. if (arr.byteLength !== undefined) {
  597. return arr.byteLength;
  598. }
  599. unreachable("Invalid argument for arrayByteLength");
  600. }
  601. function arraysToBytes(arr) {
  602. const length = arr.length;
  603. if (length === 1 && arr[0] instanceof Uint8Array) {
  604. return arr[0];
  605. }
  606. let resultLength = 0;
  607. for (let i = 0; i < length; i++) {
  608. resultLength += arrayByteLength(arr[i]);
  609. }
  610. let pos = 0;
  611. const data = new Uint8Array(resultLength);
  612. for (let i = 0; i < length; i++) {
  613. let item = arr[i];
  614. if (!(item instanceof Uint8Array)) {
  615. if (typeof item === "string") {
  616. item = stringToBytes(item);
  617. } else {
  618. item = new Uint8Array(item);
  619. }
  620. }
  621. const itemLength = item.byteLength;
  622. data.set(item, pos);
  623. pos += itemLength;
  624. }
  625. return data;
  626. }
  627. function string32(value) {
  628. return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
  629. }
  630. function objectSize(obj) {
  631. return Object.keys(obj).length;
  632. }
  633. function objectFromMap(map) {
  634. const obj = Object.create(null);
  635. for (const [key, value] of map) {
  636. obj[key] = value;
  637. }
  638. return obj;
  639. }
  640. function isLittleEndian() {
  641. const buffer8 = new Uint8Array(4);
  642. buffer8[0] = 1;
  643. const view32 = new Uint32Array(buffer8.buffer, 0, 1);
  644. return view32[0] === 1;
  645. }
  646. function isEvalSupported() {
  647. try {
  648. new Function("");
  649. return true;
  650. } catch (e) {
  651. return false;
  652. }
  653. }
  654. class FeatureTest {
  655. static get isLittleEndian() {
  656. return shadow(this, "isLittleEndian", isLittleEndian());
  657. }
  658. static get isEvalSupported() {
  659. return shadow(this, "isEvalSupported", isEvalSupported());
  660. }
  661. static get isOffscreenCanvasSupported() {
  662. return shadow(this, "isOffscreenCanvasSupported", typeof OffscreenCanvas !== "undefined");
  663. }
  664. }
  665. exports.FeatureTest = FeatureTest;
  666. const hexNumbers = [...Array(256).keys()].map(n => n.toString(16).padStart(2, "0"));
  667. class Util {
  668. static makeHexColor(r, g, b) {
  669. return `#${hexNumbers[r]}${hexNumbers[g]}${hexNumbers[b]}`;
  670. }
  671. static scaleMinMax(transform, minMax) {
  672. let temp;
  673. if (transform[0]) {
  674. if (transform[0] < 0) {
  675. temp = minMax[0];
  676. minMax[0] = minMax[1];
  677. minMax[1] = temp;
  678. }
  679. minMax[0] *= transform[0];
  680. minMax[1] *= transform[0];
  681. if (transform[3] < 0) {
  682. temp = minMax[2];
  683. minMax[2] = minMax[3];
  684. minMax[3] = temp;
  685. }
  686. minMax[2] *= transform[3];
  687. minMax[3] *= transform[3];
  688. } else {
  689. temp = minMax[0];
  690. minMax[0] = minMax[2];
  691. minMax[2] = temp;
  692. temp = minMax[1];
  693. minMax[1] = minMax[3];
  694. minMax[3] = temp;
  695. if (transform[1] < 0) {
  696. temp = minMax[2];
  697. minMax[2] = minMax[3];
  698. minMax[3] = temp;
  699. }
  700. minMax[2] *= transform[1];
  701. minMax[3] *= transform[1];
  702. if (transform[2] < 0) {
  703. temp = minMax[0];
  704. minMax[0] = minMax[1];
  705. minMax[1] = temp;
  706. }
  707. minMax[0] *= transform[2];
  708. minMax[1] *= transform[2];
  709. }
  710. minMax[0] += transform[4];
  711. minMax[1] += transform[4];
  712. minMax[2] += transform[5];
  713. minMax[3] += transform[5];
  714. }
  715. static transform(m1, m2) {
  716. 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]];
  717. }
  718. static applyTransform(p, m) {
  719. const xt = p[0] * m[0] + p[1] * m[2] + m[4];
  720. const yt = p[0] * m[1] + p[1] * m[3] + m[5];
  721. return [xt, yt];
  722. }
  723. static applyInverseTransform(p, m) {
  724. const d = m[0] * m[3] - m[1] * m[2];
  725. const xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  726. const yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  727. return [xt, yt];
  728. }
  729. static getAxialAlignedBoundingBox(r, m) {
  730. const p1 = Util.applyTransform(r, m);
  731. const p2 = Util.applyTransform(r.slice(2, 4), m);
  732. const p3 = Util.applyTransform([r[0], r[3]], m);
  733. const p4 = Util.applyTransform([r[2], r[1]], m);
  734. 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])];
  735. }
  736. static inverseTransform(m) {
  737. const d = m[0] * m[3] - m[1] * m[2];
  738. 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];
  739. }
  740. static apply3dTransform(m, v) {
  741. 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]];
  742. }
  743. static singularValueDecompose2dScale(m) {
  744. const transpose = [m[0], m[2], m[1], m[3]];
  745. const a = m[0] * transpose[0] + m[1] * transpose[2];
  746. const b = m[0] * transpose[1] + m[1] * transpose[3];
  747. const c = m[2] * transpose[0] + m[3] * transpose[2];
  748. const d = m[2] * transpose[1] + m[3] * transpose[3];
  749. const first = (a + d) / 2;
  750. const second = Math.sqrt((a + d) ** 2 - 4 * (a * d - c * b)) / 2;
  751. const sx = first + second || 1;
  752. const sy = first - second || 1;
  753. return [Math.sqrt(sx), Math.sqrt(sy)];
  754. }
  755. static normalizeRect(rect) {
  756. const r = rect.slice(0);
  757. if (rect[0] > rect[2]) {
  758. r[0] = rect[2];
  759. r[2] = rect[0];
  760. }
  761. if (rect[1] > rect[3]) {
  762. r[1] = rect[3];
  763. r[3] = rect[1];
  764. }
  765. return r;
  766. }
  767. static intersect(rect1, rect2) {
  768. const xLow = Math.max(Math.min(rect1[0], rect1[2]), Math.min(rect2[0], rect2[2]));
  769. const xHigh = Math.min(Math.max(rect1[0], rect1[2]), Math.max(rect2[0], rect2[2]));
  770. if (xLow > xHigh) {
  771. return null;
  772. }
  773. const yLow = Math.max(Math.min(rect1[1], rect1[3]), Math.min(rect2[1], rect2[3]));
  774. const yHigh = Math.min(Math.max(rect1[1], rect1[3]), Math.max(rect2[1], rect2[3]));
  775. if (yLow > yHigh) {
  776. return null;
  777. }
  778. return [xLow, yLow, xHigh, yHigh];
  779. }
  780. static bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3) {
  781. const tvalues = [],
  782. bounds = [[], []];
  783. let a, b, c, t, t1, t2, b2ac, sqrtb2ac;
  784. for (let i = 0; i < 2; ++i) {
  785. if (i === 0) {
  786. b = 6 * x0 - 12 * x1 + 6 * x2;
  787. a = -3 * x0 + 9 * x1 - 9 * x2 + 3 * x3;
  788. c = 3 * x1 - 3 * x0;
  789. } else {
  790. b = 6 * y0 - 12 * y1 + 6 * y2;
  791. a = -3 * y0 + 9 * y1 - 9 * y2 + 3 * y3;
  792. c = 3 * y1 - 3 * y0;
  793. }
  794. if (Math.abs(a) < 1e-12) {
  795. if (Math.abs(b) < 1e-12) {
  796. continue;
  797. }
  798. t = -c / b;
  799. if (0 < t && t < 1) {
  800. tvalues.push(t);
  801. }
  802. continue;
  803. }
  804. b2ac = b * b - 4 * c * a;
  805. sqrtb2ac = Math.sqrt(b2ac);
  806. if (b2ac < 0) {
  807. continue;
  808. }
  809. t1 = (-b + sqrtb2ac) / (2 * a);
  810. if (0 < t1 && t1 < 1) {
  811. tvalues.push(t1);
  812. }
  813. t2 = (-b - sqrtb2ac) / (2 * a);
  814. if (0 < t2 && t2 < 1) {
  815. tvalues.push(t2);
  816. }
  817. }
  818. let j = tvalues.length,
  819. mt;
  820. const jlen = j;
  821. while (j--) {
  822. t = tvalues[j];
  823. mt = 1 - t;
  824. bounds[0][j] = mt * mt * mt * x0 + 3 * mt * mt * t * x1 + 3 * mt * t * t * x2 + t * t * t * x3;
  825. bounds[1][j] = mt * mt * mt * y0 + 3 * mt * mt * t * y1 + 3 * mt * t * t * y2 + t * t * t * y3;
  826. }
  827. bounds[0][jlen] = x0;
  828. bounds[1][jlen] = y0;
  829. bounds[0][jlen + 1] = x3;
  830. bounds[1][jlen + 1] = y3;
  831. bounds[0].length = bounds[1].length = jlen + 2;
  832. return [Math.min(...bounds[0]), Math.min(...bounds[1]), Math.max(...bounds[0]), Math.max(...bounds[1])];
  833. }
  834. }
  835. exports.Util = Util;
  836. 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];
  837. function stringToPDFString(str) {
  838. if (str[0] >= "\xEF") {
  839. let encoding;
  840. if (str[0] === "\xFE" && str[1] === "\xFF") {
  841. encoding = "utf-16be";
  842. } else if (str[0] === "\xFF" && str[1] === "\xFE") {
  843. encoding = "utf-16le";
  844. } else if (str[0] === "\xEF" && str[1] === "\xBB" && str[2] === "\xBF") {
  845. encoding = "utf-8";
  846. }
  847. if (encoding) {
  848. try {
  849. const decoder = new TextDecoder(encoding, {
  850. fatal: true
  851. });
  852. const buffer = stringToBytes(str);
  853. return decoder.decode(buffer);
  854. } catch (ex) {
  855. warn(`stringToPDFString: "${ex}".`);
  856. }
  857. }
  858. }
  859. const strBuf = [];
  860. for (let i = 0, ii = str.length; i < ii; i++) {
  861. const code = PDFStringTranslateTable[str.charCodeAt(i)];
  862. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  863. }
  864. return strBuf.join("");
  865. }
  866. function escapeString(str) {
  867. return str.replace(/([()\\\n\r])/g, match => {
  868. if (match === "\n") {
  869. return "\\n";
  870. } else if (match === "\r") {
  871. return "\\r";
  872. }
  873. return `\\${match}`;
  874. });
  875. }
  876. function isAscii(str) {
  877. return /^[\x00-\x7F]*$/.test(str);
  878. }
  879. function stringToUTF16BEString(str) {
  880. const buf = ["\xFE\xFF"];
  881. for (let i = 0, ii = str.length; i < ii; i++) {
  882. const char = str.charCodeAt(i);
  883. buf.push(String.fromCharCode(char >> 8 & 0xff), String.fromCharCode(char & 0xff));
  884. }
  885. return buf.join("");
  886. }
  887. function stringToUTF8String(str) {
  888. return decodeURIComponent(escape(str));
  889. }
  890. function utf8StringToString(str) {
  891. return unescape(encodeURIComponent(str));
  892. }
  893. function isArrayBuffer(v) {
  894. return typeof v === "object" && v !== null && v.byteLength !== undefined;
  895. }
  896. function isArrayEqual(arr1, arr2) {
  897. if (arr1.length !== arr2.length) {
  898. return false;
  899. }
  900. for (let i = 0, ii = arr1.length; i < ii; i++) {
  901. if (arr1[i] !== arr2[i]) {
  902. return false;
  903. }
  904. }
  905. return true;
  906. }
  907. function getModificationDate(date = new Date()) {
  908. 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")];
  909. return buffer.join("");
  910. }
  911. function createPromiseCapability() {
  912. const capability = Object.create(null);
  913. let isSettled = false;
  914. Object.defineProperty(capability, "settled", {
  915. get() {
  916. return isSettled;
  917. }
  918. });
  919. capability.promise = new Promise(function (resolve, reject) {
  920. capability.resolve = function (data) {
  921. isSettled = true;
  922. resolve(data);
  923. };
  924. capability.reject = function (reason) {
  925. isSettled = true;
  926. reject(reason);
  927. };
  928. });
  929. return capability;
  930. }
  931. /***/ }),
  932. /* 2 */
  933. /***/ ((__unused_webpack_module, __unused_webpack_exports, __w_pdfjs_require__) => {
  934. var _is_node = __w_pdfjs_require__(3);
  935. ;
  936. /***/ }),
  937. /* 3 */
  938. /***/ ((__unused_webpack_module, exports) => {
  939. Object.defineProperty(exports, "__esModule", ({
  940. value: true
  941. }));
  942. exports.isNodeJS = void 0;
  943. const isNodeJS = typeof process === "object" && process + "" === "[object process]" && !process.versions.nw && !(process.versions.electron && process.type && process.type !== "browser");
  944. exports.isNodeJS = isNodeJS;
  945. /***/ }),
  946. /* 4 */
  947. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  948. Object.defineProperty(exports, "__esModule", ({
  949. value: true
  950. }));
  951. exports.build = exports.RenderTask = exports.PDFWorkerUtil = exports.PDFWorker = exports.PDFPageProxy = exports.PDFDocumentProxy = exports.PDFDocumentLoadingTask = exports.PDFDataRangeTransport = exports.LoopbackPort = exports.DefaultStandardFontDataFactory = exports.DefaultCanvasFactory = exports.DefaultCMapReaderFactory = void 0;
  952. exports.getDocument = getDocument;
  953. exports.setPDFNetworkStreamFactory = setPDFNetworkStreamFactory;
  954. exports.version = void 0;
  955. var _util = __w_pdfjs_require__(1);
  956. var _annotation_storage = __w_pdfjs_require__(5);
  957. var _display_utils = __w_pdfjs_require__(8);
  958. var _font_loader = __w_pdfjs_require__(11);
  959. var _canvas = __w_pdfjs_require__(12);
  960. var _worker_options = __w_pdfjs_require__(15);
  961. var _is_node = __w_pdfjs_require__(3);
  962. var _message_handler = __w_pdfjs_require__(16);
  963. var _metadata = __w_pdfjs_require__(17);
  964. var _optional_content_config = __w_pdfjs_require__(18);
  965. var _transport_stream = __w_pdfjs_require__(19);
  966. var _xfa_text = __w_pdfjs_require__(20);
  967. const DEFAULT_RANGE_CHUNK_SIZE = 65536;
  968. const RENDERING_CANCELLED_TIMEOUT = 100;
  969. let DefaultCanvasFactory = _display_utils.DOMCanvasFactory;
  970. exports.DefaultCanvasFactory = DefaultCanvasFactory;
  971. let DefaultCMapReaderFactory = _display_utils.DOMCMapReaderFactory;
  972. exports.DefaultCMapReaderFactory = DefaultCMapReaderFactory;
  973. let DefaultStandardFontDataFactory = _display_utils.DOMStandardFontDataFactory;
  974. exports.DefaultStandardFontDataFactory = DefaultStandardFontDataFactory;
  975. if (_is_node.isNodeJS) {
  976. const {
  977. NodeCanvasFactory,
  978. NodeCMapReaderFactory,
  979. NodeStandardFontDataFactory
  980. } = __w_pdfjs_require__(21);
  981. exports.DefaultCanvasFactory = DefaultCanvasFactory = NodeCanvasFactory;
  982. exports.DefaultCMapReaderFactory = DefaultCMapReaderFactory = NodeCMapReaderFactory;
  983. exports.DefaultStandardFontDataFactory = DefaultStandardFontDataFactory = NodeStandardFontDataFactory;
  984. }
  985. let createPDFNetworkStream;
  986. function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) {
  987. createPDFNetworkStream = pdfNetworkStreamFactory;
  988. }
  989. function getDocument(src) {
  990. const task = new PDFDocumentLoadingTask();
  991. let source;
  992. if (typeof src === "string" || src instanceof URL) {
  993. source = {
  994. url: src
  995. };
  996. } else if ((0, _util.isArrayBuffer)(src)) {
  997. source = {
  998. data: src
  999. };
  1000. } else if (src instanceof PDFDataRangeTransport) {
  1001. source = {
  1002. range: src
  1003. };
  1004. } else {
  1005. if (typeof src !== "object") {
  1006. throw new Error("Invalid parameter in getDocument, " + "need either string, URL, TypedArray, or parameter object.");
  1007. }
  1008. if (!src.url && !src.data && !src.range) {
  1009. throw new Error("Invalid parameter object: need either .data, .range or .url");
  1010. }
  1011. source = src;
  1012. }
  1013. const params = Object.create(null);
  1014. let rangeTransport = null,
  1015. worker = null;
  1016. for (const key in source) {
  1017. const value = source[key];
  1018. switch (key) {
  1019. case "url":
  1020. if (typeof window !== "undefined") {
  1021. try {
  1022. params[key] = new URL(value, window.location).href;
  1023. continue;
  1024. } catch (ex) {
  1025. (0, _util.warn)(`Cannot create valid URL: "${ex}".`);
  1026. }
  1027. } else if (typeof value === "string" || value instanceof URL) {
  1028. params[key] = value.toString();
  1029. continue;
  1030. }
  1031. throw new Error("Invalid PDF url data: " + "either string or URL-object is expected in the url property.");
  1032. case "range":
  1033. rangeTransport = value;
  1034. continue;
  1035. case "worker":
  1036. worker = value;
  1037. continue;
  1038. case "data":
  1039. if (_is_node.isNodeJS && typeof Buffer !== "undefined" && value instanceof Buffer) {
  1040. params[key] = new Uint8Array(value);
  1041. } else if (value instanceof Uint8Array) {
  1042. break;
  1043. } else if (typeof value === "string") {
  1044. params[key] = (0, _util.stringToBytes)(value);
  1045. } else if (typeof value === "object" && value !== null && !isNaN(value.length)) {
  1046. params[key] = new Uint8Array(value);
  1047. } else if ((0, _util.isArrayBuffer)(value)) {
  1048. params[key] = new Uint8Array(value);
  1049. } else {
  1050. throw new Error("Invalid PDF binary data: either TypedArray, " + "string, or array-like object is expected in the data property.");
  1051. }
  1052. continue;
  1053. }
  1054. params[key] = value;
  1055. }
  1056. params.CMapReaderFactory = params.CMapReaderFactory || DefaultCMapReaderFactory;
  1057. params.StandardFontDataFactory = params.StandardFontDataFactory || DefaultStandardFontDataFactory;
  1058. params.ignoreErrors = params.stopAtErrors !== true;
  1059. params.fontExtraProperties = params.fontExtraProperties === true;
  1060. params.pdfBug = params.pdfBug === true;
  1061. params.enableXfa = params.enableXfa === true;
  1062. if (!Number.isInteger(params.rangeChunkSize) || params.rangeChunkSize < 1) {
  1063. params.rangeChunkSize = DEFAULT_RANGE_CHUNK_SIZE;
  1064. }
  1065. if (typeof params.docBaseUrl !== "string" || (0, _display_utils.isDataScheme)(params.docBaseUrl)) {
  1066. params.docBaseUrl = null;
  1067. }
  1068. if (!Number.isInteger(params.maxImageSize) || params.maxImageSize < -1) {
  1069. params.maxImageSize = -1;
  1070. }
  1071. if (typeof params.cMapUrl !== "string") {
  1072. params.cMapUrl = null;
  1073. }
  1074. if (typeof params.standardFontDataUrl !== "string") {
  1075. params.standardFontDataUrl = null;
  1076. }
  1077. if (typeof params.useWorkerFetch !== "boolean") {
  1078. params.useWorkerFetch = params.CMapReaderFactory === _display_utils.DOMCMapReaderFactory && params.StandardFontDataFactory === _display_utils.DOMStandardFontDataFactory;
  1079. }
  1080. if (typeof params.isEvalSupported !== "boolean") {
  1081. params.isEvalSupported = true;
  1082. }
  1083. if (typeof params.disableFontFace !== "boolean") {
  1084. params.disableFontFace = _is_node.isNodeJS;
  1085. }
  1086. if (typeof params.useSystemFonts !== "boolean") {
  1087. params.useSystemFonts = !_is_node.isNodeJS && !params.disableFontFace;
  1088. }
  1089. if (typeof params.ownerDocument !== "object" || params.ownerDocument === null) {
  1090. params.ownerDocument = globalThis.document;
  1091. }
  1092. if (typeof params.disableRange !== "boolean") {
  1093. params.disableRange = false;
  1094. }
  1095. if (typeof params.disableStream !== "boolean") {
  1096. params.disableStream = false;
  1097. }
  1098. if (typeof params.disableAutoFetch !== "boolean") {
  1099. params.disableAutoFetch = false;
  1100. }
  1101. (0, _util.setVerbosityLevel)(params.verbosity);
  1102. if (!worker) {
  1103. const workerParams = {
  1104. verbosity: params.verbosity,
  1105. port: _worker_options.GlobalWorkerOptions.workerPort
  1106. };
  1107. worker = workerParams.port ? PDFWorker.fromPort(workerParams) : new PDFWorker(workerParams);
  1108. task._worker = worker;
  1109. }
  1110. const docId = task.docId;
  1111. worker.promise.then(function () {
  1112. if (task.destroyed) {
  1113. throw new Error("Loading aborted");
  1114. }
  1115. const workerIdPromise = _fetchDocument(worker, params, rangeTransport, docId);
  1116. const networkStreamPromise = new Promise(function (resolve) {
  1117. let networkStream;
  1118. if (rangeTransport) {
  1119. networkStream = new _transport_stream.PDFDataTransportStream({
  1120. length: params.length,
  1121. initialData: params.initialData,
  1122. progressiveDone: params.progressiveDone,
  1123. contentDispositionFilename: params.contentDispositionFilename,
  1124. disableRange: params.disableRange,
  1125. disableStream: params.disableStream
  1126. }, rangeTransport);
  1127. } else if (!params.data) {
  1128. networkStream = createPDFNetworkStream({
  1129. url: params.url,
  1130. length: params.length,
  1131. httpHeaders: params.httpHeaders,
  1132. withCredentials: params.withCredentials,
  1133. rangeChunkSize: params.rangeChunkSize,
  1134. disableRange: params.disableRange,
  1135. disableStream: params.disableStream
  1136. });
  1137. }
  1138. resolve(networkStream);
  1139. });
  1140. return Promise.all([workerIdPromise, networkStreamPromise]).then(function ([workerId, networkStream]) {
  1141. if (task.destroyed) {
  1142. throw new Error("Loading aborted");
  1143. }
  1144. const messageHandler = new _message_handler.MessageHandler(docId, workerId, worker.port);
  1145. const transport = new WorkerTransport(messageHandler, task, networkStream, params);
  1146. task._transport = transport;
  1147. messageHandler.send("Ready", null);
  1148. });
  1149. }).catch(task._capability.reject);
  1150. return task;
  1151. }
  1152. async function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
  1153. if (worker.destroyed) {
  1154. throw new Error("Worker was destroyed");
  1155. }
  1156. if (pdfDataRangeTransport) {
  1157. source.length = pdfDataRangeTransport.length;
  1158. source.initialData = pdfDataRangeTransport.initialData;
  1159. source.progressiveDone = pdfDataRangeTransport.progressiveDone;
  1160. source.contentDispositionFilename = pdfDataRangeTransport.contentDispositionFilename;
  1161. }
  1162. const workerId = await worker.messageHandler.sendWithPromise("GetDocRequest", {
  1163. docId,
  1164. apiVersion: '2.16.105',
  1165. source: {
  1166. data: source.data,
  1167. url: source.url,
  1168. password: source.password,
  1169. disableAutoFetch: source.disableAutoFetch,
  1170. rangeChunkSize: source.rangeChunkSize,
  1171. length: source.length
  1172. },
  1173. maxImageSize: source.maxImageSize,
  1174. disableFontFace: source.disableFontFace,
  1175. docBaseUrl: source.docBaseUrl,
  1176. ignoreErrors: source.ignoreErrors,
  1177. isEvalSupported: source.isEvalSupported,
  1178. fontExtraProperties: source.fontExtraProperties,
  1179. enableXfa: source.enableXfa,
  1180. useSystemFonts: source.useSystemFonts,
  1181. cMapUrl: source.useWorkerFetch ? source.cMapUrl : null,
  1182. standardFontDataUrl: source.useWorkerFetch ? source.standardFontDataUrl : null
  1183. });
  1184. if (source.data) {
  1185. source.data = null;
  1186. }
  1187. if (worker.destroyed) {
  1188. throw new Error("Worker was destroyed");
  1189. }
  1190. return workerId;
  1191. }
  1192. class PDFDocumentLoadingTask {
  1193. static #docId = 0;
  1194. constructor() {
  1195. this._capability = (0, _util.createPromiseCapability)();
  1196. this._transport = null;
  1197. this._worker = null;
  1198. this.docId = `d${PDFDocumentLoadingTask.#docId++}`;
  1199. this.destroyed = false;
  1200. this.onPassword = null;
  1201. this.onProgress = null;
  1202. this.onUnsupportedFeature = null;
  1203. }
  1204. get promise() {
  1205. return this._capability.promise;
  1206. }
  1207. async destroy() {
  1208. this.destroyed = true;
  1209. await this._transport?.destroy();
  1210. this._transport = null;
  1211. if (this._worker) {
  1212. this._worker.destroy();
  1213. this._worker = null;
  1214. }
  1215. }
  1216. }
  1217. exports.PDFDocumentLoadingTask = PDFDocumentLoadingTask;
  1218. class PDFDataRangeTransport {
  1219. constructor(length, initialData, progressiveDone = false, contentDispositionFilename = null) {
  1220. this.length = length;
  1221. this.initialData = initialData;
  1222. this.progressiveDone = progressiveDone;
  1223. this.contentDispositionFilename = contentDispositionFilename;
  1224. this._rangeListeners = [];
  1225. this._progressListeners = [];
  1226. this._progressiveReadListeners = [];
  1227. this._progressiveDoneListeners = [];
  1228. this._readyCapability = (0, _util.createPromiseCapability)();
  1229. }
  1230. addRangeListener(listener) {
  1231. this._rangeListeners.push(listener);
  1232. }
  1233. addProgressListener(listener) {
  1234. this._progressListeners.push(listener);
  1235. }
  1236. addProgressiveReadListener(listener) {
  1237. this._progressiveReadListeners.push(listener);
  1238. }
  1239. addProgressiveDoneListener(listener) {
  1240. this._progressiveDoneListeners.push(listener);
  1241. }
  1242. onDataRange(begin, chunk) {
  1243. for (const listener of this._rangeListeners) {
  1244. listener(begin, chunk);
  1245. }
  1246. }
  1247. onDataProgress(loaded, total) {
  1248. this._readyCapability.promise.then(() => {
  1249. for (const listener of this._progressListeners) {
  1250. listener(loaded, total);
  1251. }
  1252. });
  1253. }
  1254. onDataProgressiveRead(chunk) {
  1255. this._readyCapability.promise.then(() => {
  1256. for (const listener of this._progressiveReadListeners) {
  1257. listener(chunk);
  1258. }
  1259. });
  1260. }
  1261. onDataProgressiveDone() {
  1262. this._readyCapability.promise.then(() => {
  1263. for (const listener of this._progressiveDoneListeners) {
  1264. listener();
  1265. }
  1266. });
  1267. }
  1268. transportReady() {
  1269. this._readyCapability.resolve();
  1270. }
  1271. requestDataRange(begin, end) {
  1272. (0, _util.unreachable)("Abstract method PDFDataRangeTransport.requestDataRange");
  1273. }
  1274. abort() {}
  1275. }
  1276. exports.PDFDataRangeTransport = PDFDataRangeTransport;
  1277. class PDFDocumentProxy {
  1278. constructor(pdfInfo, transport) {
  1279. this._pdfInfo = pdfInfo;
  1280. this._transport = transport;
  1281. Object.defineProperty(this, "fingerprint", {
  1282. get() {
  1283. (0, _display_utils.deprecated)("`PDFDocumentProxy.fingerprint`, " + "please use `PDFDocumentProxy.fingerprints` instead.");
  1284. return this.fingerprints[0];
  1285. }
  1286. });
  1287. Object.defineProperty(this, "getStats", {
  1288. value: async () => {
  1289. (0, _display_utils.deprecated)("`PDFDocumentProxy.getStats`, " + "please use the `PDFDocumentProxy.stats`-getter instead.");
  1290. return this.stats || {
  1291. streamTypes: {},
  1292. fontTypes: {}
  1293. };
  1294. }
  1295. });
  1296. }
  1297. get annotationStorage() {
  1298. return this._transport.annotationStorage;
  1299. }
  1300. get numPages() {
  1301. return this._pdfInfo.numPages;
  1302. }
  1303. get fingerprints() {
  1304. return this._pdfInfo.fingerprints;
  1305. }
  1306. get stats() {
  1307. return this._transport.stats;
  1308. }
  1309. get isPureXfa() {
  1310. return !!this._transport._htmlForXfa;
  1311. }
  1312. get allXfaHtml() {
  1313. return this._transport._htmlForXfa;
  1314. }
  1315. getPage(pageNumber) {
  1316. return this._transport.getPage(pageNumber);
  1317. }
  1318. getPageIndex(ref) {
  1319. return this._transport.getPageIndex(ref);
  1320. }
  1321. getDestinations() {
  1322. return this._transport.getDestinations();
  1323. }
  1324. getDestination(id) {
  1325. return this._transport.getDestination(id);
  1326. }
  1327. getPageLabels() {
  1328. return this._transport.getPageLabels();
  1329. }
  1330. getPageLayout() {
  1331. return this._transport.getPageLayout();
  1332. }
  1333. getPageMode() {
  1334. return this._transport.getPageMode();
  1335. }
  1336. getViewerPreferences() {
  1337. return this._transport.getViewerPreferences();
  1338. }
  1339. getOpenAction() {
  1340. return this._transport.getOpenAction();
  1341. }
  1342. getAttachments() {
  1343. return this._transport.getAttachments();
  1344. }
  1345. getJavaScript() {
  1346. return this._transport.getJavaScript();
  1347. }
  1348. getJSActions() {
  1349. return this._transport.getDocJSActions();
  1350. }
  1351. getOutline() {
  1352. return this._transport.getOutline();
  1353. }
  1354. getOptionalContentConfig() {
  1355. return this._transport.getOptionalContentConfig();
  1356. }
  1357. getPermissions() {
  1358. return this._transport.getPermissions();
  1359. }
  1360. getMetadata() {
  1361. return this._transport.getMetadata();
  1362. }
  1363. getMarkInfo() {
  1364. return this._transport.getMarkInfo();
  1365. }
  1366. getData() {
  1367. return this._transport.getData();
  1368. }
  1369. getDownloadInfo() {
  1370. return this._transport.downloadInfoCapability.promise;
  1371. }
  1372. cleanup(keepLoadedFonts = false) {
  1373. return this._transport.startCleanup(keepLoadedFonts || this.isPureXfa);
  1374. }
  1375. destroy() {
  1376. return this.loadingTask.destroy();
  1377. }
  1378. get loadingParams() {
  1379. return this._transport.loadingParams;
  1380. }
  1381. get loadingTask() {
  1382. return this._transport.loadingTask;
  1383. }
  1384. saveDocument() {
  1385. if (this._transport.annotationStorage.size <= 0) {
  1386. (0, _display_utils.deprecated)("saveDocument called while `annotationStorage` is empty, " + "please use the getData-method instead.");
  1387. }
  1388. return this._transport.saveDocument();
  1389. }
  1390. getFieldObjects() {
  1391. return this._transport.getFieldObjects();
  1392. }
  1393. hasJSActions() {
  1394. return this._transport.hasJSActions();
  1395. }
  1396. getCalculationOrderIds() {
  1397. return this._transport.getCalculationOrderIds();
  1398. }
  1399. }
  1400. exports.PDFDocumentProxy = PDFDocumentProxy;
  1401. class PDFPageProxy {
  1402. constructor(pageIndex, pageInfo, transport, ownerDocument, pdfBug = false) {
  1403. this._pageIndex = pageIndex;
  1404. this._pageInfo = pageInfo;
  1405. this._ownerDocument = ownerDocument;
  1406. this._transport = transport;
  1407. this._stats = pdfBug ? new _display_utils.StatTimer() : null;
  1408. this._pdfBug = pdfBug;
  1409. this.commonObjs = transport.commonObjs;
  1410. this.objs = new PDFObjects();
  1411. this._bitmaps = new Set();
  1412. this.cleanupAfterRender = false;
  1413. this.pendingCleanup = false;
  1414. this._intentStates = new Map();
  1415. this._annotationPromises = new Map();
  1416. this.destroyed = false;
  1417. }
  1418. get pageNumber() {
  1419. return this._pageIndex + 1;
  1420. }
  1421. get rotate() {
  1422. return this._pageInfo.rotate;
  1423. }
  1424. get ref() {
  1425. return this._pageInfo.ref;
  1426. }
  1427. get userUnit() {
  1428. return this._pageInfo.userUnit;
  1429. }
  1430. get view() {
  1431. return this._pageInfo.view;
  1432. }
  1433. getViewport({
  1434. scale,
  1435. rotation = this.rotate,
  1436. offsetX = 0,
  1437. offsetY = 0,
  1438. dontFlip = false
  1439. } = {}) {
  1440. return new _display_utils.PageViewport({
  1441. viewBox: this.view,
  1442. scale,
  1443. rotation,
  1444. offsetX,
  1445. offsetY,
  1446. dontFlip
  1447. });
  1448. }
  1449. getAnnotations({
  1450. intent = "display"
  1451. } = {}) {
  1452. const intentArgs = this._transport.getRenderingIntent(intent);
  1453. let promise = this._annotationPromises.get(intentArgs.cacheKey);
  1454. if (!promise) {
  1455. promise = this._transport.getAnnotations(this._pageIndex, intentArgs.renderingIntent);
  1456. this._annotationPromises.set(intentArgs.cacheKey, promise);
  1457. promise = promise.then(annotations => {
  1458. for (const annotation of annotations) {
  1459. if (annotation.titleObj !== undefined) {
  1460. Object.defineProperty(annotation, "title", {
  1461. get() {
  1462. (0, _display_utils.deprecated)("`title`-property on annotation, please use `titleObj` instead.");
  1463. return annotation.titleObj.str;
  1464. }
  1465. });
  1466. }
  1467. if (annotation.contentsObj !== undefined) {
  1468. Object.defineProperty(annotation, "contents", {
  1469. get() {
  1470. (0, _display_utils.deprecated)("`contents`-property on annotation, please use `contentsObj` instead.");
  1471. return annotation.contentsObj.str;
  1472. }
  1473. });
  1474. }
  1475. }
  1476. return annotations;
  1477. });
  1478. }
  1479. return promise;
  1480. }
  1481. getJSActions() {
  1482. return this._jsActionsPromise ||= this._transport.getPageJSActions(this._pageIndex);
  1483. }
  1484. async getXfa() {
  1485. return this._transport._htmlForXfa?.children[this._pageIndex] || null;
  1486. }
  1487. render({
  1488. canvasContext,
  1489. viewport,
  1490. intent = "display",
  1491. annotationMode = _util.AnnotationMode.ENABLE,
  1492. transform = null,
  1493. imageLayer = null,
  1494. canvasFactory = null,
  1495. background = null,
  1496. optionalContentConfigPromise = null,
  1497. annotationCanvasMap = null,
  1498. pageColors = null,
  1499. printAnnotationStorage = null
  1500. }) {
  1501. if (arguments[0]?.renderInteractiveForms !== undefined) {
  1502. (0, _display_utils.deprecated)("render no longer accepts the `renderInteractiveForms`-option, " + "please use the `annotationMode`-option instead.");
  1503. if (arguments[0].renderInteractiveForms === true && annotationMode === _util.AnnotationMode.ENABLE) {
  1504. annotationMode = _util.AnnotationMode.ENABLE_FORMS;
  1505. }
  1506. }
  1507. if (arguments[0]?.includeAnnotationStorage !== undefined) {
  1508. (0, _display_utils.deprecated)("render no longer accepts the `includeAnnotationStorage`-option, " + "please use the `annotationMode`-option instead.");
  1509. if (arguments[0].includeAnnotationStorage === true && annotationMode === _util.AnnotationMode.ENABLE) {
  1510. annotationMode = _util.AnnotationMode.ENABLE_STORAGE;
  1511. }
  1512. }
  1513. if (this._stats) {
  1514. this._stats.time("Overall");
  1515. }
  1516. const intentArgs = this._transport.getRenderingIntent(intent, annotationMode, printAnnotationStorage);
  1517. this.pendingCleanup = false;
  1518. if (!optionalContentConfigPromise) {
  1519. optionalContentConfigPromise = this._transport.getOptionalContentConfig();
  1520. }
  1521. let intentState = this._intentStates.get(intentArgs.cacheKey);
  1522. if (!intentState) {
  1523. intentState = Object.create(null);
  1524. this._intentStates.set(intentArgs.cacheKey, intentState);
  1525. }
  1526. if (intentState.streamReaderCancelTimeout) {
  1527. clearTimeout(intentState.streamReaderCancelTimeout);
  1528. intentState.streamReaderCancelTimeout = null;
  1529. }
  1530. const canvasFactoryInstance = canvasFactory || new DefaultCanvasFactory({
  1531. ownerDocument: this._ownerDocument
  1532. });
  1533. const intentPrint = !!(intentArgs.renderingIntent & _util.RenderingIntentFlag.PRINT);
  1534. if (!intentState.displayReadyCapability) {
  1535. intentState.displayReadyCapability = (0, _util.createPromiseCapability)();
  1536. intentState.operatorList = {
  1537. fnArray: [],
  1538. argsArray: [],
  1539. lastChunk: false,
  1540. separateAnnots: null
  1541. };
  1542. if (this._stats) {
  1543. this._stats.time("Page Request");
  1544. }
  1545. this._pumpOperatorList(intentArgs);
  1546. }
  1547. const complete = error => {
  1548. intentState.renderTasks.delete(internalRenderTask);
  1549. if (this.cleanupAfterRender || intentPrint) {
  1550. this.pendingCleanup = true;
  1551. }
  1552. this._tryCleanup();
  1553. if (error) {
  1554. internalRenderTask.capability.reject(error);
  1555. this._abortOperatorList({
  1556. intentState,
  1557. reason: error instanceof Error ? error : new Error(error)
  1558. });
  1559. } else {
  1560. internalRenderTask.capability.resolve();
  1561. }
  1562. if (this._stats) {
  1563. this._stats.timeEnd("Rendering");
  1564. this._stats.timeEnd("Overall");
  1565. }
  1566. };
  1567. const internalRenderTask = new InternalRenderTask({
  1568. callback: complete,
  1569. params: {
  1570. canvasContext,
  1571. viewport,
  1572. transform,
  1573. imageLayer,
  1574. background
  1575. },
  1576. objs: this.objs,
  1577. commonObjs: this.commonObjs,
  1578. annotationCanvasMap,
  1579. operatorList: intentState.operatorList,
  1580. pageIndex: this._pageIndex,
  1581. canvasFactory: canvasFactoryInstance,
  1582. useRequestAnimationFrame: !intentPrint,
  1583. pdfBug: this._pdfBug,
  1584. pageColors
  1585. });
  1586. (intentState.renderTasks ||= new Set()).add(internalRenderTask);
  1587. const renderTask = internalRenderTask.task;
  1588. Promise.all([intentState.displayReadyCapability.promise, optionalContentConfigPromise]).then(([transparency, optionalContentConfig]) => {
  1589. if (this.pendingCleanup) {
  1590. complete();
  1591. return;
  1592. }
  1593. if (this._stats) {
  1594. this._stats.time("Rendering");
  1595. }
  1596. internalRenderTask.initializeGraphics({
  1597. transparency,
  1598. optionalContentConfig
  1599. });
  1600. internalRenderTask.operatorListChanged();
  1601. }).catch(complete);
  1602. return renderTask;
  1603. }
  1604. getOperatorList({
  1605. intent = "display",
  1606. annotationMode = _util.AnnotationMode.ENABLE,
  1607. printAnnotationStorage = null
  1608. } = {}) {
  1609. function operatorListChanged() {
  1610. if (intentState.operatorList.lastChunk) {
  1611. intentState.opListReadCapability.resolve(intentState.operatorList);
  1612. intentState.renderTasks.delete(opListTask);
  1613. }
  1614. }
  1615. const intentArgs = this._transport.getRenderingIntent(intent, annotationMode, printAnnotationStorage, true);
  1616. let intentState = this._intentStates.get(intentArgs.cacheKey);
  1617. if (!intentState) {
  1618. intentState = Object.create(null);
  1619. this._intentStates.set(intentArgs.cacheKey, intentState);
  1620. }
  1621. let opListTask;
  1622. if (!intentState.opListReadCapability) {
  1623. opListTask = Object.create(null);
  1624. opListTask.operatorListChanged = operatorListChanged;
  1625. intentState.opListReadCapability = (0, _util.createPromiseCapability)();
  1626. (intentState.renderTasks ||= new Set()).add(opListTask);
  1627. intentState.operatorList = {
  1628. fnArray: [],
  1629. argsArray: [],
  1630. lastChunk: false,
  1631. separateAnnots: null
  1632. };
  1633. if (this._stats) {
  1634. this._stats.time("Page Request");
  1635. }
  1636. this._pumpOperatorList(intentArgs);
  1637. }
  1638. return intentState.opListReadCapability.promise;
  1639. }
  1640. streamTextContent({
  1641. disableCombineTextItems = false,
  1642. includeMarkedContent = false
  1643. } = {}) {
  1644. const TEXT_CONTENT_CHUNK_SIZE = 100;
  1645. return this._transport.messageHandler.sendWithStream("GetTextContent", {
  1646. pageIndex: this._pageIndex,
  1647. combineTextItems: disableCombineTextItems !== true,
  1648. includeMarkedContent: includeMarkedContent === true
  1649. }, {
  1650. highWaterMark: TEXT_CONTENT_CHUNK_SIZE,
  1651. size(textContent) {
  1652. return textContent.items.length;
  1653. }
  1654. });
  1655. }
  1656. getTextContent(params = {}) {
  1657. if (this._transport._htmlForXfa) {
  1658. return this.getXfa().then(xfa => {
  1659. return _xfa_text.XfaText.textContent(xfa);
  1660. });
  1661. }
  1662. const readableStream = this.streamTextContent(params);
  1663. return new Promise(function (resolve, reject) {
  1664. function pump() {
  1665. reader.read().then(function ({
  1666. value,
  1667. done
  1668. }) {
  1669. if (done) {
  1670. resolve(textContent);
  1671. return;
  1672. }
  1673. Object.assign(textContent.styles, value.styles);
  1674. textContent.items.push(...value.items);
  1675. pump();
  1676. }, reject);
  1677. }
  1678. const reader = readableStream.getReader();
  1679. const textContent = {
  1680. items: [],
  1681. styles: Object.create(null)
  1682. };
  1683. pump();
  1684. });
  1685. }
  1686. getStructTree() {
  1687. return this._structTreePromise ||= this._transport.getStructTree(this._pageIndex);
  1688. }
  1689. _destroy() {
  1690. this.destroyed = true;
  1691. const waitOn = [];
  1692. for (const intentState of this._intentStates.values()) {
  1693. this._abortOperatorList({
  1694. intentState,
  1695. reason: new Error("Page was destroyed."),
  1696. force: true
  1697. });
  1698. if (intentState.opListReadCapability) {
  1699. continue;
  1700. }
  1701. for (const internalRenderTask of intentState.renderTasks) {
  1702. waitOn.push(internalRenderTask.completed);
  1703. internalRenderTask.cancel();
  1704. }
  1705. }
  1706. this.objs.clear();
  1707. for (const bitmap of this._bitmaps) {
  1708. bitmap.close();
  1709. }
  1710. this._bitmaps.clear();
  1711. this._annotationPromises.clear();
  1712. this._jsActionsPromise = null;
  1713. this._structTreePromise = null;
  1714. this.pendingCleanup = false;
  1715. return Promise.all(waitOn);
  1716. }
  1717. cleanup(resetStats = false) {
  1718. this.pendingCleanup = true;
  1719. return this._tryCleanup(resetStats);
  1720. }
  1721. _tryCleanup(resetStats = false) {
  1722. if (!this.pendingCleanup) {
  1723. return false;
  1724. }
  1725. for (const {
  1726. renderTasks,
  1727. operatorList
  1728. } of this._intentStates.values()) {
  1729. if (renderTasks.size > 0 || !operatorList.lastChunk) {
  1730. return false;
  1731. }
  1732. }
  1733. this._intentStates.clear();
  1734. this.objs.clear();
  1735. this._annotationPromises.clear();
  1736. this._jsActionsPromise = null;
  1737. this._structTreePromise = null;
  1738. if (resetStats && this._stats) {
  1739. this._stats = new _display_utils.StatTimer();
  1740. }
  1741. for (const bitmap of this._bitmaps) {
  1742. bitmap.close();
  1743. }
  1744. this._bitmaps.clear();
  1745. this.pendingCleanup = false;
  1746. return true;
  1747. }
  1748. _startRenderPage(transparency, cacheKey) {
  1749. const intentState = this._intentStates.get(cacheKey);
  1750. if (!intentState) {
  1751. return;
  1752. }
  1753. if (this._stats) {
  1754. this._stats.timeEnd("Page Request");
  1755. }
  1756. if (intentState.displayReadyCapability) {
  1757. intentState.displayReadyCapability.resolve(transparency);
  1758. }
  1759. }
  1760. _renderPageChunk(operatorListChunk, intentState) {
  1761. for (let i = 0, ii = operatorListChunk.length; i < ii; i++) {
  1762. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  1763. intentState.operatorList.argsArray.push(operatorListChunk.argsArray[i]);
  1764. }
  1765. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  1766. intentState.operatorList.separateAnnots = operatorListChunk.separateAnnots;
  1767. for (const internalRenderTask of intentState.renderTasks) {
  1768. internalRenderTask.operatorListChanged();
  1769. }
  1770. if (operatorListChunk.lastChunk) {
  1771. this._tryCleanup();
  1772. }
  1773. }
  1774. _pumpOperatorList({
  1775. renderingIntent,
  1776. cacheKey,
  1777. annotationStorageMap
  1778. }) {
  1779. const readableStream = this._transport.messageHandler.sendWithStream("GetOperatorList", {
  1780. pageIndex: this._pageIndex,
  1781. intent: renderingIntent,
  1782. cacheKey,
  1783. annotationStorage: annotationStorageMap
  1784. });
  1785. const reader = readableStream.getReader();
  1786. const intentState = this._intentStates.get(cacheKey);
  1787. intentState.streamReader = reader;
  1788. const pump = () => {
  1789. reader.read().then(({
  1790. value,
  1791. done
  1792. }) => {
  1793. if (done) {
  1794. intentState.streamReader = null;
  1795. return;
  1796. }
  1797. if (this._transport.destroyed) {
  1798. return;
  1799. }
  1800. this._renderPageChunk(value, intentState);
  1801. pump();
  1802. }, reason => {
  1803. intentState.streamReader = null;
  1804. if (this._transport.destroyed) {
  1805. return;
  1806. }
  1807. if (intentState.operatorList) {
  1808. intentState.operatorList.lastChunk = true;
  1809. for (const internalRenderTask of intentState.renderTasks) {
  1810. internalRenderTask.operatorListChanged();
  1811. }
  1812. this._tryCleanup();
  1813. }
  1814. if (intentState.displayReadyCapability) {
  1815. intentState.displayReadyCapability.reject(reason);
  1816. } else if (intentState.opListReadCapability) {
  1817. intentState.opListReadCapability.reject(reason);
  1818. } else {
  1819. throw reason;
  1820. }
  1821. });
  1822. };
  1823. pump();
  1824. }
  1825. _abortOperatorList({
  1826. intentState,
  1827. reason,
  1828. force = false
  1829. }) {
  1830. if (!intentState.streamReader) {
  1831. return;
  1832. }
  1833. if (!force) {
  1834. if (intentState.renderTasks.size > 0) {
  1835. return;
  1836. }
  1837. if (reason instanceof _display_utils.RenderingCancelledException) {
  1838. intentState.streamReaderCancelTimeout = setTimeout(() => {
  1839. this._abortOperatorList({
  1840. intentState,
  1841. reason,
  1842. force: true
  1843. });
  1844. intentState.streamReaderCancelTimeout = null;
  1845. }, RENDERING_CANCELLED_TIMEOUT);
  1846. return;
  1847. }
  1848. }
  1849. intentState.streamReader.cancel(new _util.AbortException(reason.message)).catch(() => {});
  1850. intentState.streamReader = null;
  1851. if (this._transport.destroyed) {
  1852. return;
  1853. }
  1854. for (const [curCacheKey, curIntentState] of this._intentStates) {
  1855. if (curIntentState === intentState) {
  1856. this._intentStates.delete(curCacheKey);
  1857. break;
  1858. }
  1859. }
  1860. this.cleanup();
  1861. }
  1862. get stats() {
  1863. return this._stats;
  1864. }
  1865. }
  1866. exports.PDFPageProxy = PDFPageProxy;
  1867. class LoopbackPort {
  1868. constructor() {
  1869. this._listeners = [];
  1870. this._deferred = Promise.resolve();
  1871. }
  1872. postMessage(obj, transfers) {
  1873. const event = {
  1874. data: structuredClone(obj, transfers)
  1875. };
  1876. this._deferred.then(() => {
  1877. for (const listener of this._listeners) {
  1878. listener.call(this, event);
  1879. }
  1880. });
  1881. }
  1882. addEventListener(name, listener) {
  1883. this._listeners.push(listener);
  1884. }
  1885. removeEventListener(name, listener) {
  1886. const i = this._listeners.indexOf(listener);
  1887. this._listeners.splice(i, 1);
  1888. }
  1889. terminate() {
  1890. this._listeners.length = 0;
  1891. }
  1892. }
  1893. exports.LoopbackPort = LoopbackPort;
  1894. const PDFWorkerUtil = {
  1895. isWorkerDisabled: false,
  1896. fallbackWorkerSrc: null,
  1897. fakeWorkerId: 0
  1898. };
  1899. exports.PDFWorkerUtil = PDFWorkerUtil;
  1900. {
  1901. if (_is_node.isNodeJS && typeof require === "function") {
  1902. PDFWorkerUtil.isWorkerDisabled = true;
  1903. PDFWorkerUtil.fallbackWorkerSrc = "./pdf.worker.js";
  1904. } else if (typeof document === "object") {
  1905. const pdfjsFilePath = document?.currentScript?.src;
  1906. if (pdfjsFilePath) {
  1907. PDFWorkerUtil.fallbackWorkerSrc = pdfjsFilePath.replace(/(\.(?:min\.)?js)(\?.*)?$/i, ".worker$1$2");
  1908. }
  1909. }
  1910. PDFWorkerUtil.isSameOrigin = function (baseUrl, otherUrl) {
  1911. let base;
  1912. try {
  1913. base = new URL(baseUrl);
  1914. if (!base.origin || base.origin === "null") {
  1915. return false;
  1916. }
  1917. } catch (e) {
  1918. return false;
  1919. }
  1920. const other = new URL(otherUrl, base);
  1921. return base.origin === other.origin;
  1922. };
  1923. PDFWorkerUtil.createCDNWrapper = function (url) {
  1924. const wrapper = `importScripts("${url}");`;
  1925. return URL.createObjectURL(new Blob([wrapper]));
  1926. };
  1927. }
  1928. class PDFWorker {
  1929. static #workerPorts = new WeakMap();
  1930. constructor({
  1931. name = null,
  1932. port = null,
  1933. verbosity = (0, _util.getVerbosityLevel)()
  1934. } = {}) {
  1935. if (port && PDFWorker.#workerPorts.has(port)) {
  1936. throw new Error("Cannot use more than one PDFWorker per port.");
  1937. }
  1938. this.name = name;
  1939. this.destroyed = false;
  1940. this.verbosity = verbosity;
  1941. this._readyCapability = (0, _util.createPromiseCapability)();
  1942. this._port = null;
  1943. this._webWorker = null;
  1944. this._messageHandler = null;
  1945. if (port) {
  1946. PDFWorker.#workerPorts.set(port, this);
  1947. this._initializeFromPort(port);
  1948. return;
  1949. }
  1950. this._initialize();
  1951. }
  1952. get promise() {
  1953. return this._readyCapability.promise;
  1954. }
  1955. get port() {
  1956. return this._port;
  1957. }
  1958. get messageHandler() {
  1959. return this._messageHandler;
  1960. }
  1961. _initializeFromPort(port) {
  1962. this._port = port;
  1963. this._messageHandler = new _message_handler.MessageHandler("main", "worker", port);
  1964. this._messageHandler.on("ready", function () {});
  1965. this._readyCapability.resolve();
  1966. }
  1967. _initialize() {
  1968. if (!PDFWorkerUtil.isWorkerDisabled && !PDFWorker._mainThreadWorkerMessageHandler) {
  1969. let {
  1970. workerSrc
  1971. } = PDFWorker;
  1972. try {
  1973. if (!PDFWorkerUtil.isSameOrigin(window.location.href, workerSrc)) {
  1974. workerSrc = PDFWorkerUtil.createCDNWrapper(new URL(workerSrc, window.location).href);
  1975. }
  1976. const worker = new Worker(workerSrc);
  1977. const messageHandler = new _message_handler.MessageHandler("main", "worker", worker);
  1978. const terminateEarly = () => {
  1979. worker.removeEventListener("error", onWorkerError);
  1980. messageHandler.destroy();
  1981. worker.terminate();
  1982. if (this.destroyed) {
  1983. this._readyCapability.reject(new Error("Worker was destroyed"));
  1984. } else {
  1985. this._setupFakeWorker();
  1986. }
  1987. };
  1988. const onWorkerError = () => {
  1989. if (!this._webWorker) {
  1990. terminateEarly();
  1991. }
  1992. };
  1993. worker.addEventListener("error", onWorkerError);
  1994. messageHandler.on("test", data => {
  1995. worker.removeEventListener("error", onWorkerError);
  1996. if (this.destroyed) {
  1997. terminateEarly();
  1998. return;
  1999. }
  2000. if (data) {
  2001. this._messageHandler = messageHandler;
  2002. this._port = worker;
  2003. this._webWorker = worker;
  2004. this._readyCapability.resolve();
  2005. messageHandler.send("configure", {
  2006. verbosity: this.verbosity
  2007. });
  2008. } else {
  2009. this._setupFakeWorker();
  2010. messageHandler.destroy();
  2011. worker.terminate();
  2012. }
  2013. });
  2014. messageHandler.on("ready", data => {
  2015. worker.removeEventListener("error", onWorkerError);
  2016. if (this.destroyed) {
  2017. terminateEarly();
  2018. return;
  2019. }
  2020. try {
  2021. sendTest();
  2022. } catch (e) {
  2023. this._setupFakeWorker();
  2024. }
  2025. });
  2026. const sendTest = () => {
  2027. const testObj = new Uint8Array();
  2028. messageHandler.send("test", testObj, [testObj.buffer]);
  2029. };
  2030. sendTest();
  2031. return;
  2032. } catch (e) {
  2033. (0, _util.info)("The worker has been disabled.");
  2034. }
  2035. }
  2036. this._setupFakeWorker();
  2037. }
  2038. _setupFakeWorker() {
  2039. if (!PDFWorkerUtil.isWorkerDisabled) {
  2040. (0, _util.warn)("Setting up fake worker.");
  2041. PDFWorkerUtil.isWorkerDisabled = true;
  2042. }
  2043. PDFWorker._setupFakeWorkerGlobal.then(WorkerMessageHandler => {
  2044. if (this.destroyed) {
  2045. this._readyCapability.reject(new Error("Worker was destroyed"));
  2046. return;
  2047. }
  2048. const port = new LoopbackPort();
  2049. this._port = port;
  2050. const id = `fake${PDFWorkerUtil.fakeWorkerId++}`;
  2051. const workerHandler = new _message_handler.MessageHandler(id + "_worker", id, port);
  2052. WorkerMessageHandler.setup(workerHandler, port);
  2053. const messageHandler = new _message_handler.MessageHandler(id, id + "_worker", port);
  2054. this._messageHandler = messageHandler;
  2055. this._readyCapability.resolve();
  2056. messageHandler.send("configure", {
  2057. verbosity: this.verbosity
  2058. });
  2059. }).catch(reason => {
  2060. this._readyCapability.reject(new Error(`Setting up fake worker failed: "${reason.message}".`));
  2061. });
  2062. }
  2063. destroy() {
  2064. this.destroyed = true;
  2065. if (this._webWorker) {
  2066. this._webWorker.terminate();
  2067. this._webWorker = null;
  2068. }
  2069. PDFWorker.#workerPorts.delete(this._port);
  2070. this._port = null;
  2071. if (this._messageHandler) {
  2072. this._messageHandler.destroy();
  2073. this._messageHandler = null;
  2074. }
  2075. }
  2076. static fromPort(params) {
  2077. if (!params?.port) {
  2078. throw new Error("PDFWorker.fromPort - invalid method signature.");
  2079. }
  2080. if (this.#workerPorts.has(params.port)) {
  2081. return this.#workerPorts.get(params.port);
  2082. }
  2083. return new PDFWorker(params);
  2084. }
  2085. static get workerSrc() {
  2086. if (_worker_options.GlobalWorkerOptions.workerSrc) {
  2087. return _worker_options.GlobalWorkerOptions.workerSrc;
  2088. }
  2089. if (PDFWorkerUtil.fallbackWorkerSrc !== null) {
  2090. if (!_is_node.isNodeJS) {
  2091. (0, _display_utils.deprecated)('No "GlobalWorkerOptions.workerSrc" specified.');
  2092. }
  2093. return PDFWorkerUtil.fallbackWorkerSrc;
  2094. }
  2095. throw new Error('No "GlobalWorkerOptions.workerSrc" specified.');
  2096. }
  2097. static get _mainThreadWorkerMessageHandler() {
  2098. try {
  2099. return globalThis.pdfjsWorker?.WorkerMessageHandler || null;
  2100. } catch (ex) {
  2101. return null;
  2102. }
  2103. }
  2104. static get _setupFakeWorkerGlobal() {
  2105. const loader = async () => {
  2106. const mainWorkerMessageHandler = this._mainThreadWorkerMessageHandler;
  2107. if (mainWorkerMessageHandler) {
  2108. return mainWorkerMessageHandler;
  2109. }
  2110. if (_is_node.isNodeJS && typeof require === "function") {
  2111. const worker = eval("require")(this.workerSrc);
  2112. return worker.WorkerMessageHandler;
  2113. }
  2114. await (0, _display_utils.loadScript)(this.workerSrc);
  2115. return window.pdfjsWorker.WorkerMessageHandler;
  2116. };
  2117. return (0, _util.shadow)(this, "_setupFakeWorkerGlobal", loader());
  2118. }
  2119. }
  2120. exports.PDFWorker = PDFWorker;
  2121. {
  2122. PDFWorker.getWorkerSrc = function () {
  2123. (0, _display_utils.deprecated)("`PDFWorker.getWorkerSrc()`, please use `PDFWorker.workerSrc` instead.");
  2124. return this.workerSrc;
  2125. };
  2126. }
  2127. class WorkerTransport {
  2128. #docStats = null;
  2129. #pageCache = new Map();
  2130. #pagePromises = new Map();
  2131. #metadataPromise = null;
  2132. constructor(messageHandler, loadingTask, networkStream, params) {
  2133. this.messageHandler = messageHandler;
  2134. this.loadingTask = loadingTask;
  2135. this.commonObjs = new PDFObjects();
  2136. this.fontLoader = new _font_loader.FontLoader({
  2137. docId: loadingTask.docId,
  2138. onUnsupportedFeature: this._onUnsupportedFeature.bind(this),
  2139. ownerDocument: params.ownerDocument,
  2140. styleElement: params.styleElement
  2141. });
  2142. this._params = params;
  2143. if (!params.useWorkerFetch) {
  2144. this.CMapReaderFactory = new params.CMapReaderFactory({
  2145. baseUrl: params.cMapUrl,
  2146. isCompressed: params.cMapPacked
  2147. });
  2148. this.StandardFontDataFactory = new params.StandardFontDataFactory({
  2149. baseUrl: params.standardFontDataUrl
  2150. });
  2151. }
  2152. this.destroyed = false;
  2153. this.destroyCapability = null;
  2154. this._passwordCapability = null;
  2155. this._networkStream = networkStream;
  2156. this._fullReader = null;
  2157. this._lastProgress = null;
  2158. this.downloadInfoCapability = (0, _util.createPromiseCapability)();
  2159. this.setupMessageHandler();
  2160. }
  2161. get annotationStorage() {
  2162. return (0, _util.shadow)(this, "annotationStorage", new _annotation_storage.AnnotationStorage());
  2163. }
  2164. get stats() {
  2165. return this.#docStats;
  2166. }
  2167. getRenderingIntent(intent, annotationMode = _util.AnnotationMode.ENABLE, printAnnotationStorage = null, isOpList = false) {
  2168. let renderingIntent = _util.RenderingIntentFlag.DISPLAY;
  2169. let annotationMap = null;
  2170. switch (intent) {
  2171. case "any":
  2172. renderingIntent = _util.RenderingIntentFlag.ANY;
  2173. break;
  2174. case "display":
  2175. break;
  2176. case "print":
  2177. renderingIntent = _util.RenderingIntentFlag.PRINT;
  2178. break;
  2179. default:
  2180. (0, _util.warn)(`getRenderingIntent - invalid intent: ${intent}`);
  2181. }
  2182. switch (annotationMode) {
  2183. case _util.AnnotationMode.DISABLE:
  2184. renderingIntent += _util.RenderingIntentFlag.ANNOTATIONS_DISABLE;
  2185. break;
  2186. case _util.AnnotationMode.ENABLE:
  2187. break;
  2188. case _util.AnnotationMode.ENABLE_FORMS:
  2189. renderingIntent += _util.RenderingIntentFlag.ANNOTATIONS_FORMS;
  2190. break;
  2191. case _util.AnnotationMode.ENABLE_STORAGE:
  2192. renderingIntent += _util.RenderingIntentFlag.ANNOTATIONS_STORAGE;
  2193. const annotationStorage = renderingIntent & _util.RenderingIntentFlag.PRINT && printAnnotationStorage instanceof _annotation_storage.PrintAnnotationStorage ? printAnnotationStorage : this.annotationStorage;
  2194. annotationMap = annotationStorage.serializable;
  2195. break;
  2196. default:
  2197. (0, _util.warn)(`getRenderingIntent - invalid annotationMode: ${annotationMode}`);
  2198. }
  2199. if (isOpList) {
  2200. renderingIntent += _util.RenderingIntentFlag.OPLIST;
  2201. }
  2202. return {
  2203. renderingIntent,
  2204. cacheKey: `${renderingIntent}_${_annotation_storage.AnnotationStorage.getHash(annotationMap)}`,
  2205. annotationStorageMap: annotationMap
  2206. };
  2207. }
  2208. destroy() {
  2209. if (this.destroyCapability) {
  2210. return this.destroyCapability.promise;
  2211. }
  2212. this.destroyed = true;
  2213. this.destroyCapability = (0, _util.createPromiseCapability)();
  2214. if (this._passwordCapability) {
  2215. this._passwordCapability.reject(new Error("Worker was destroyed during onPassword callback"));
  2216. }
  2217. const waitOn = [];
  2218. for (const page of this.#pageCache.values()) {
  2219. waitOn.push(page._destroy());
  2220. }
  2221. this.#pageCache.clear();
  2222. this.#pagePromises.clear();
  2223. if (this.hasOwnProperty("annotationStorage")) {
  2224. this.annotationStorage.resetModified();
  2225. }
  2226. const terminated = this.messageHandler.sendWithPromise("Terminate", null);
  2227. waitOn.push(terminated);
  2228. Promise.all(waitOn).then(() => {
  2229. this.commonObjs.clear();
  2230. this.fontLoader.clear();
  2231. this.#metadataPromise = null;
  2232. this._getFieldObjectsPromise = null;
  2233. this._hasJSActionsPromise = null;
  2234. if (this._networkStream) {
  2235. this._networkStream.cancelAllRequests(new _util.AbortException("Worker was terminated."));
  2236. }
  2237. if (this.messageHandler) {
  2238. this.messageHandler.destroy();
  2239. this.messageHandler = null;
  2240. }
  2241. this.destroyCapability.resolve();
  2242. }, this.destroyCapability.reject);
  2243. return this.destroyCapability.promise;
  2244. }
  2245. setupMessageHandler() {
  2246. const {
  2247. messageHandler,
  2248. loadingTask
  2249. } = this;
  2250. messageHandler.on("GetReader", (data, sink) => {
  2251. (0, _util.assert)(this._networkStream, "GetReader - no `IPDFStream` instance available.");
  2252. this._fullReader = this._networkStream.getFullReader();
  2253. this._fullReader.onProgress = evt => {
  2254. this._lastProgress = {
  2255. loaded: evt.loaded,
  2256. total: evt.total
  2257. };
  2258. };
  2259. sink.onPull = () => {
  2260. this._fullReader.read().then(function ({
  2261. value,
  2262. done
  2263. }) {
  2264. if (done) {
  2265. sink.close();
  2266. return;
  2267. }
  2268. (0, _util.assert)((0, _util.isArrayBuffer)(value), "GetReader - expected an ArrayBuffer.");
  2269. sink.enqueue(new Uint8Array(value), 1, [value]);
  2270. }).catch(reason => {
  2271. sink.error(reason);
  2272. });
  2273. };
  2274. sink.onCancel = reason => {
  2275. this._fullReader.cancel(reason);
  2276. sink.ready.catch(readyReason => {
  2277. if (this.destroyed) {
  2278. return;
  2279. }
  2280. throw readyReason;
  2281. });
  2282. };
  2283. });
  2284. messageHandler.on("ReaderHeadersReady", data => {
  2285. const headersCapability = (0, _util.createPromiseCapability)();
  2286. const fullReader = this._fullReader;
  2287. fullReader.headersReady.then(() => {
  2288. if (!fullReader.isStreamingSupported || !fullReader.isRangeSupported) {
  2289. if (this._lastProgress) {
  2290. loadingTask.onProgress?.(this._lastProgress);
  2291. }
  2292. fullReader.onProgress = evt => {
  2293. loadingTask.onProgress?.({
  2294. loaded: evt.loaded,
  2295. total: evt.total
  2296. });
  2297. };
  2298. }
  2299. headersCapability.resolve({
  2300. isStreamingSupported: fullReader.isStreamingSupported,
  2301. isRangeSupported: fullReader.isRangeSupported,
  2302. contentLength: fullReader.contentLength
  2303. });
  2304. }, headersCapability.reject);
  2305. return headersCapability.promise;
  2306. });
  2307. messageHandler.on("GetRangeReader", (data, sink) => {
  2308. (0, _util.assert)(this._networkStream, "GetRangeReader - no `IPDFStream` instance available.");
  2309. const rangeReader = this._networkStream.getRangeReader(data.begin, data.end);
  2310. if (!rangeReader) {
  2311. sink.close();
  2312. return;
  2313. }
  2314. sink.onPull = () => {
  2315. rangeReader.read().then(function ({
  2316. value,
  2317. done
  2318. }) {
  2319. if (done) {
  2320. sink.close();
  2321. return;
  2322. }
  2323. (0, _util.assert)((0, _util.isArrayBuffer)(value), "GetRangeReader - expected an ArrayBuffer.");
  2324. sink.enqueue(new Uint8Array(value), 1, [value]);
  2325. }).catch(reason => {
  2326. sink.error(reason);
  2327. });
  2328. };
  2329. sink.onCancel = reason => {
  2330. rangeReader.cancel(reason);
  2331. sink.ready.catch(readyReason => {
  2332. if (this.destroyed) {
  2333. return;
  2334. }
  2335. throw readyReason;
  2336. });
  2337. };
  2338. });
  2339. messageHandler.on("GetDoc", ({
  2340. pdfInfo
  2341. }) => {
  2342. this._numPages = pdfInfo.numPages;
  2343. this._htmlForXfa = pdfInfo.htmlForXfa;
  2344. delete pdfInfo.htmlForXfa;
  2345. loadingTask._capability.resolve(new PDFDocumentProxy(pdfInfo, this));
  2346. });
  2347. messageHandler.on("DocException", function (ex) {
  2348. let reason;
  2349. switch (ex.name) {
  2350. case "PasswordException":
  2351. reason = new _util.PasswordException(ex.message, ex.code);
  2352. break;
  2353. case "InvalidPDFException":
  2354. reason = new _util.InvalidPDFException(ex.message);
  2355. break;
  2356. case "MissingPDFException":
  2357. reason = new _util.MissingPDFException(ex.message);
  2358. break;
  2359. case "UnexpectedResponseException":
  2360. reason = new _util.UnexpectedResponseException(ex.message, ex.status);
  2361. break;
  2362. case "UnknownErrorException":
  2363. reason = new _util.UnknownErrorException(ex.message, ex.details);
  2364. break;
  2365. default:
  2366. (0, _util.unreachable)("DocException - expected a valid Error.");
  2367. }
  2368. loadingTask._capability.reject(reason);
  2369. });
  2370. messageHandler.on("PasswordRequest", exception => {
  2371. this._passwordCapability = (0, _util.createPromiseCapability)();
  2372. if (loadingTask.onPassword) {
  2373. const updatePassword = password => {
  2374. if (password instanceof Error) {
  2375. this._passwordCapability.reject(password);
  2376. } else {
  2377. this._passwordCapability.resolve({
  2378. password
  2379. });
  2380. }
  2381. };
  2382. try {
  2383. loadingTask.onPassword(updatePassword, exception.code);
  2384. } catch (ex) {
  2385. this._passwordCapability.reject(ex);
  2386. }
  2387. } else {
  2388. this._passwordCapability.reject(new _util.PasswordException(exception.message, exception.code));
  2389. }
  2390. return this._passwordCapability.promise;
  2391. });
  2392. messageHandler.on("DataLoaded", data => {
  2393. loadingTask.onProgress?.({
  2394. loaded: data.length,
  2395. total: data.length
  2396. });
  2397. this.downloadInfoCapability.resolve(data);
  2398. });
  2399. messageHandler.on("StartRenderPage", data => {
  2400. if (this.destroyed) {
  2401. return;
  2402. }
  2403. const page = this.#pageCache.get(data.pageIndex);
  2404. page._startRenderPage(data.transparency, data.cacheKey);
  2405. });
  2406. messageHandler.on("commonobj", ([id, type, exportedData]) => {
  2407. if (this.destroyed) {
  2408. return;
  2409. }
  2410. if (this.commonObjs.has(id)) {
  2411. return;
  2412. }
  2413. switch (type) {
  2414. case "Font":
  2415. const params = this._params;
  2416. if ("error" in exportedData) {
  2417. const exportedError = exportedData.error;
  2418. (0, _util.warn)(`Error during font loading: ${exportedError}`);
  2419. this.commonObjs.resolve(id, exportedError);
  2420. break;
  2421. }
  2422. let fontRegistry = null;
  2423. if (params.pdfBug && globalThis.FontInspector?.enabled) {
  2424. fontRegistry = {
  2425. registerFont(font, url) {
  2426. globalThis.FontInspector.fontAdded(font, url);
  2427. }
  2428. };
  2429. }
  2430. const font = new _font_loader.FontFaceObject(exportedData, {
  2431. isEvalSupported: params.isEvalSupported,
  2432. disableFontFace: params.disableFontFace,
  2433. ignoreErrors: params.ignoreErrors,
  2434. onUnsupportedFeature: this._onUnsupportedFeature.bind(this),
  2435. fontRegistry
  2436. });
  2437. this.fontLoader.bind(font).catch(reason => {
  2438. return messageHandler.sendWithPromise("FontFallback", {
  2439. id
  2440. });
  2441. }).finally(() => {
  2442. if (!params.fontExtraProperties && font.data) {
  2443. font.data = null;
  2444. }
  2445. this.commonObjs.resolve(id, font);
  2446. });
  2447. break;
  2448. case "FontPath":
  2449. case "Image":
  2450. this.commonObjs.resolve(id, exportedData);
  2451. break;
  2452. default:
  2453. throw new Error(`Got unknown common object type ${type}`);
  2454. }
  2455. });
  2456. messageHandler.on("obj", ([id, pageIndex, type, imageData]) => {
  2457. if (this.destroyed) {
  2458. return;
  2459. }
  2460. const pageProxy = this.#pageCache.get(pageIndex);
  2461. if (pageProxy.objs.has(id)) {
  2462. return;
  2463. }
  2464. switch (type) {
  2465. case "Image":
  2466. pageProxy.objs.resolve(id, imageData);
  2467. const MAX_IMAGE_SIZE_TO_STORE = 8000000;
  2468. if (imageData) {
  2469. let length;
  2470. if (imageData.bitmap) {
  2471. const {
  2472. bitmap,
  2473. width,
  2474. height
  2475. } = imageData;
  2476. length = width * height * 4;
  2477. pageProxy._bitmaps.add(bitmap);
  2478. } else {
  2479. length = imageData.data?.length || 0;
  2480. }
  2481. if (length > MAX_IMAGE_SIZE_TO_STORE) {
  2482. pageProxy.cleanupAfterRender = true;
  2483. }
  2484. }
  2485. break;
  2486. case "Pattern":
  2487. pageProxy.objs.resolve(id, imageData);
  2488. break;
  2489. default:
  2490. throw new Error(`Got unknown object type ${type}`);
  2491. }
  2492. });
  2493. messageHandler.on("DocProgress", data => {
  2494. if (this.destroyed) {
  2495. return;
  2496. }
  2497. loadingTask.onProgress?.({
  2498. loaded: data.loaded,
  2499. total: data.total
  2500. });
  2501. });
  2502. messageHandler.on("DocStats", data => {
  2503. if (this.destroyed) {
  2504. return;
  2505. }
  2506. this.#docStats = Object.freeze({
  2507. streamTypes: Object.freeze(data.streamTypes),
  2508. fontTypes: Object.freeze(data.fontTypes)
  2509. });
  2510. });
  2511. messageHandler.on("UnsupportedFeature", this._onUnsupportedFeature.bind(this));
  2512. messageHandler.on("FetchBuiltInCMap", data => {
  2513. if (this.destroyed) {
  2514. return Promise.reject(new Error("Worker was destroyed."));
  2515. }
  2516. if (!this.CMapReaderFactory) {
  2517. return Promise.reject(new Error("CMapReaderFactory not initialized, see the `useWorkerFetch` parameter."));
  2518. }
  2519. return this.CMapReaderFactory.fetch(data);
  2520. });
  2521. messageHandler.on("FetchStandardFontData", data => {
  2522. if (this.destroyed) {
  2523. return Promise.reject(new Error("Worker was destroyed."));
  2524. }
  2525. if (!this.StandardFontDataFactory) {
  2526. return Promise.reject(new Error("StandardFontDataFactory not initialized, see the `useWorkerFetch` parameter."));
  2527. }
  2528. return this.StandardFontDataFactory.fetch(data);
  2529. });
  2530. }
  2531. _onUnsupportedFeature({
  2532. featureId
  2533. }) {
  2534. if (this.destroyed) {
  2535. return;
  2536. }
  2537. this.loadingTask.onUnsupportedFeature?.(featureId);
  2538. }
  2539. getData() {
  2540. return this.messageHandler.sendWithPromise("GetData", null);
  2541. }
  2542. getPage(pageNumber) {
  2543. if (!Number.isInteger(pageNumber) || pageNumber <= 0 || pageNumber > this._numPages) {
  2544. return Promise.reject(new Error("Invalid page request."));
  2545. }
  2546. const pageIndex = pageNumber - 1,
  2547. cachedPromise = this.#pagePromises.get(pageIndex);
  2548. if (cachedPromise) {
  2549. return cachedPromise;
  2550. }
  2551. const promise = this.messageHandler.sendWithPromise("GetPage", {
  2552. pageIndex
  2553. }).then(pageInfo => {
  2554. if (this.destroyed) {
  2555. throw new Error("Transport destroyed");
  2556. }
  2557. const page = new PDFPageProxy(pageIndex, pageInfo, this, this._params.ownerDocument, this._params.pdfBug);
  2558. this.#pageCache.set(pageIndex, page);
  2559. return page;
  2560. });
  2561. this.#pagePromises.set(pageIndex, promise);
  2562. return promise;
  2563. }
  2564. getPageIndex(ref) {
  2565. if (typeof ref !== "object" || ref === null || !Number.isInteger(ref.num) || ref.num < 0 || !Number.isInteger(ref.gen) || ref.gen < 0) {
  2566. return Promise.reject(new Error("Invalid pageIndex request."));
  2567. }
  2568. return this.messageHandler.sendWithPromise("GetPageIndex", {
  2569. num: ref.num,
  2570. gen: ref.gen
  2571. });
  2572. }
  2573. getAnnotations(pageIndex, intent) {
  2574. return this.messageHandler.sendWithPromise("GetAnnotations", {
  2575. pageIndex,
  2576. intent
  2577. });
  2578. }
  2579. saveDocument() {
  2580. return this.messageHandler.sendWithPromise("SaveDocument", {
  2581. isPureXfa: !!this._htmlForXfa,
  2582. numPages: this._numPages,
  2583. annotationStorage: this.annotationStorage.serializable,
  2584. filename: this._fullReader?.filename ?? null
  2585. }).finally(() => {
  2586. this.annotationStorage.resetModified();
  2587. });
  2588. }
  2589. getFieldObjects() {
  2590. return this._getFieldObjectsPromise ||= this.messageHandler.sendWithPromise("GetFieldObjects", null);
  2591. }
  2592. hasJSActions() {
  2593. return this._hasJSActionsPromise ||= this.messageHandler.sendWithPromise("HasJSActions", null);
  2594. }
  2595. getCalculationOrderIds() {
  2596. return this.messageHandler.sendWithPromise("GetCalculationOrderIds", null);
  2597. }
  2598. getDestinations() {
  2599. return this.messageHandler.sendWithPromise("GetDestinations", null);
  2600. }
  2601. getDestination(id) {
  2602. if (typeof id !== "string") {
  2603. return Promise.reject(new Error("Invalid destination request."));
  2604. }
  2605. return this.messageHandler.sendWithPromise("GetDestination", {
  2606. id
  2607. });
  2608. }
  2609. getPageLabels() {
  2610. return this.messageHandler.sendWithPromise("GetPageLabels", null);
  2611. }
  2612. getPageLayout() {
  2613. return this.messageHandler.sendWithPromise("GetPageLayout", null);
  2614. }
  2615. getPageMode() {
  2616. return this.messageHandler.sendWithPromise("GetPageMode", null);
  2617. }
  2618. getViewerPreferences() {
  2619. return this.messageHandler.sendWithPromise("GetViewerPreferences", null);
  2620. }
  2621. getOpenAction() {
  2622. return this.messageHandler.sendWithPromise("GetOpenAction", null);
  2623. }
  2624. getAttachments() {
  2625. return this.messageHandler.sendWithPromise("GetAttachments", null);
  2626. }
  2627. getJavaScript() {
  2628. return this.messageHandler.sendWithPromise("GetJavaScript", null);
  2629. }
  2630. getDocJSActions() {
  2631. return this.messageHandler.sendWithPromise("GetDocJSActions", null);
  2632. }
  2633. getPageJSActions(pageIndex) {
  2634. return this.messageHandler.sendWithPromise("GetPageJSActions", {
  2635. pageIndex
  2636. });
  2637. }
  2638. getStructTree(pageIndex) {
  2639. return this.messageHandler.sendWithPromise("GetStructTree", {
  2640. pageIndex
  2641. });
  2642. }
  2643. getOutline() {
  2644. return this.messageHandler.sendWithPromise("GetOutline", null);
  2645. }
  2646. getOptionalContentConfig() {
  2647. return this.messageHandler.sendWithPromise("GetOptionalContentConfig", null).then(results => {
  2648. return new _optional_content_config.OptionalContentConfig(results);
  2649. });
  2650. }
  2651. getPermissions() {
  2652. return this.messageHandler.sendWithPromise("GetPermissions", null);
  2653. }
  2654. getMetadata() {
  2655. return this.#metadataPromise ||= this.messageHandler.sendWithPromise("GetMetadata", null).then(results => {
  2656. return {
  2657. info: results[0],
  2658. metadata: results[1] ? new _metadata.Metadata(results[1]) : null,
  2659. contentDispositionFilename: this._fullReader?.filename ?? null,
  2660. contentLength: this._fullReader?.contentLength ?? null
  2661. };
  2662. });
  2663. }
  2664. getMarkInfo() {
  2665. return this.messageHandler.sendWithPromise("GetMarkInfo", null);
  2666. }
  2667. async startCleanup(keepLoadedFonts = false) {
  2668. await this.messageHandler.sendWithPromise("Cleanup", null);
  2669. if (this.destroyed) {
  2670. return;
  2671. }
  2672. for (const page of this.#pageCache.values()) {
  2673. const cleanupSuccessful = page.cleanup();
  2674. if (!cleanupSuccessful) {
  2675. throw new Error(`startCleanup: Page ${page.pageNumber} is currently rendering.`);
  2676. }
  2677. }
  2678. this.commonObjs.clear();
  2679. if (!keepLoadedFonts) {
  2680. this.fontLoader.clear();
  2681. }
  2682. this.#metadataPromise = null;
  2683. this._getFieldObjectsPromise = null;
  2684. this._hasJSActionsPromise = null;
  2685. }
  2686. get loadingParams() {
  2687. const params = this._params;
  2688. return (0, _util.shadow)(this, "loadingParams", {
  2689. disableAutoFetch: params.disableAutoFetch,
  2690. enableXfa: params.enableXfa
  2691. });
  2692. }
  2693. }
  2694. class PDFObjects {
  2695. #objs = Object.create(null);
  2696. #ensureObj(objId) {
  2697. const obj = this.#objs[objId];
  2698. if (obj) {
  2699. return obj;
  2700. }
  2701. return this.#objs[objId] = {
  2702. capability: (0, _util.createPromiseCapability)(),
  2703. data: null
  2704. };
  2705. }
  2706. get(objId, callback = null) {
  2707. if (callback) {
  2708. const obj = this.#ensureObj(objId);
  2709. obj.capability.promise.then(() => callback(obj.data));
  2710. return null;
  2711. }
  2712. const obj = this.#objs[objId];
  2713. if (!obj?.capability.settled) {
  2714. throw new Error(`Requesting object that isn't resolved yet ${objId}.`);
  2715. }
  2716. return obj.data;
  2717. }
  2718. has(objId) {
  2719. const obj = this.#objs[objId];
  2720. return obj?.capability.settled || false;
  2721. }
  2722. resolve(objId, data = null) {
  2723. const obj = this.#ensureObj(objId);
  2724. obj.data = data;
  2725. obj.capability.resolve();
  2726. }
  2727. clear() {
  2728. this.#objs = Object.create(null);
  2729. }
  2730. }
  2731. class RenderTask {
  2732. #internalRenderTask = null;
  2733. constructor(internalRenderTask) {
  2734. this.#internalRenderTask = internalRenderTask;
  2735. this.onContinue = null;
  2736. }
  2737. get promise() {
  2738. return this.#internalRenderTask.capability.promise;
  2739. }
  2740. cancel() {
  2741. this.#internalRenderTask.cancel();
  2742. }
  2743. get separateAnnots() {
  2744. const {
  2745. separateAnnots
  2746. } = this.#internalRenderTask.operatorList;
  2747. if (!separateAnnots) {
  2748. return false;
  2749. }
  2750. const {
  2751. annotationCanvasMap
  2752. } = this.#internalRenderTask;
  2753. return separateAnnots.form || separateAnnots.canvas && annotationCanvasMap?.size > 0;
  2754. }
  2755. }
  2756. exports.RenderTask = RenderTask;
  2757. class InternalRenderTask {
  2758. static #canvasInUse = new WeakSet();
  2759. constructor({
  2760. callback,
  2761. params,
  2762. objs,
  2763. commonObjs,
  2764. annotationCanvasMap,
  2765. operatorList,
  2766. pageIndex,
  2767. canvasFactory,
  2768. useRequestAnimationFrame = false,
  2769. pdfBug = false,
  2770. pageColors = null
  2771. }) {
  2772. this.callback = callback;
  2773. this.params = params;
  2774. this.objs = objs;
  2775. this.commonObjs = commonObjs;
  2776. this.annotationCanvasMap = annotationCanvasMap;
  2777. this.operatorListIdx = null;
  2778. this.operatorList = operatorList;
  2779. this._pageIndex = pageIndex;
  2780. this.canvasFactory = canvasFactory;
  2781. this._pdfBug = pdfBug;
  2782. this.pageColors = pageColors;
  2783. this.running = false;
  2784. this.graphicsReadyCallback = null;
  2785. this.graphicsReady = false;
  2786. this._useRequestAnimationFrame = useRequestAnimationFrame === true && typeof window !== "undefined";
  2787. this.cancelled = false;
  2788. this.capability = (0, _util.createPromiseCapability)();
  2789. this.task = new RenderTask(this);
  2790. this._cancelBound = this.cancel.bind(this);
  2791. this._continueBound = this._continue.bind(this);
  2792. this._scheduleNextBound = this._scheduleNext.bind(this);
  2793. this._nextBound = this._next.bind(this);
  2794. this._canvas = params.canvasContext.canvas;
  2795. }
  2796. get completed() {
  2797. return this.capability.promise.catch(function () {});
  2798. }
  2799. initializeGraphics({
  2800. transparency = false,
  2801. optionalContentConfig
  2802. }) {
  2803. if (this.cancelled) {
  2804. return;
  2805. }
  2806. if (this._canvas) {
  2807. if (InternalRenderTask.#canvasInUse.has(this._canvas)) {
  2808. throw new Error("Cannot use the same canvas during multiple render() operations. " + "Use different canvas or ensure previous operations were " + "cancelled or completed.");
  2809. }
  2810. InternalRenderTask.#canvasInUse.add(this._canvas);
  2811. }
  2812. if (this._pdfBug && globalThis.StepperManager?.enabled) {
  2813. this.stepper = globalThis.StepperManager.create(this._pageIndex);
  2814. this.stepper.init(this.operatorList);
  2815. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  2816. }
  2817. const {
  2818. canvasContext,
  2819. viewport,
  2820. transform,
  2821. imageLayer,
  2822. background
  2823. } = this.params;
  2824. this.gfx = new _canvas.CanvasGraphics(canvasContext, this.commonObjs, this.objs, this.canvasFactory, imageLayer, optionalContentConfig, this.annotationCanvasMap, this.pageColors);
  2825. this.gfx.beginDrawing({
  2826. transform,
  2827. viewport,
  2828. transparency,
  2829. background
  2830. });
  2831. this.operatorListIdx = 0;
  2832. this.graphicsReady = true;
  2833. if (this.graphicsReadyCallback) {
  2834. this.graphicsReadyCallback();
  2835. }
  2836. }
  2837. cancel(error = null) {
  2838. this.running = false;
  2839. this.cancelled = true;
  2840. if (this.gfx) {
  2841. this.gfx.endDrawing();
  2842. }
  2843. if (this._canvas) {
  2844. InternalRenderTask.#canvasInUse.delete(this._canvas);
  2845. }
  2846. this.callback(error || new _display_utils.RenderingCancelledException(`Rendering cancelled, page ${this._pageIndex + 1}`, "canvas"));
  2847. }
  2848. operatorListChanged() {
  2849. if (!this.graphicsReady) {
  2850. if (!this.graphicsReadyCallback) {
  2851. this.graphicsReadyCallback = this._continueBound;
  2852. }
  2853. return;
  2854. }
  2855. if (this.stepper) {
  2856. this.stepper.updateOperatorList(this.operatorList);
  2857. }
  2858. if (this.running) {
  2859. return;
  2860. }
  2861. this._continue();
  2862. }
  2863. _continue() {
  2864. this.running = true;
  2865. if (this.cancelled) {
  2866. return;
  2867. }
  2868. if (this.task.onContinue) {
  2869. this.task.onContinue(this._scheduleNextBound);
  2870. } else {
  2871. this._scheduleNext();
  2872. }
  2873. }
  2874. _scheduleNext() {
  2875. if (this._useRequestAnimationFrame) {
  2876. window.requestAnimationFrame(() => {
  2877. this._nextBound().catch(this._cancelBound);
  2878. });
  2879. } else {
  2880. Promise.resolve().then(this._nextBound).catch(this._cancelBound);
  2881. }
  2882. }
  2883. async _next() {
  2884. if (this.cancelled) {
  2885. return;
  2886. }
  2887. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList, this.operatorListIdx, this._continueBound, this.stepper);
  2888. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  2889. this.running = false;
  2890. if (this.operatorList.lastChunk) {
  2891. this.gfx.endDrawing();
  2892. if (this._canvas) {
  2893. InternalRenderTask.#canvasInUse.delete(this._canvas);
  2894. }
  2895. this.callback();
  2896. }
  2897. }
  2898. }
  2899. }
  2900. const version = '2.16.105';
  2901. exports.version = version;
  2902. const build = '172ccdbe5';
  2903. exports.build = build;
  2904. /***/ }),
  2905. /* 5 */
  2906. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  2907. Object.defineProperty(exports, "__esModule", ({
  2908. value: true
  2909. }));
  2910. exports.PrintAnnotationStorage = exports.AnnotationStorage = void 0;
  2911. var _util = __w_pdfjs_require__(1);
  2912. var _editor = __w_pdfjs_require__(6);
  2913. var _murmurhash = __w_pdfjs_require__(10);
  2914. class AnnotationStorage {
  2915. constructor() {
  2916. this._storage = new Map();
  2917. this._modified = false;
  2918. this.onSetModified = null;
  2919. this.onResetModified = null;
  2920. this.onAnnotationEditor = null;
  2921. }
  2922. getValue(key, defaultValue) {
  2923. const value = this._storage.get(key);
  2924. if (value === undefined) {
  2925. return defaultValue;
  2926. }
  2927. return Object.assign(defaultValue, value);
  2928. }
  2929. getRawValue(key) {
  2930. return this._storage.get(key);
  2931. }
  2932. remove(key) {
  2933. this._storage.delete(key);
  2934. if (this._storage.size === 0) {
  2935. this.resetModified();
  2936. }
  2937. if (typeof this.onAnnotationEditor === "function") {
  2938. for (const value of this._storage.values()) {
  2939. if (value instanceof _editor.AnnotationEditor) {
  2940. return;
  2941. }
  2942. }
  2943. this.onAnnotationEditor(null);
  2944. }
  2945. }
  2946. setValue(key, value) {
  2947. const obj = this._storage.get(key);
  2948. let modified = false;
  2949. if (obj !== undefined) {
  2950. for (const [entry, val] of Object.entries(value)) {
  2951. if (obj[entry] !== val) {
  2952. modified = true;
  2953. obj[entry] = val;
  2954. }
  2955. }
  2956. } else {
  2957. modified = true;
  2958. this._storage.set(key, value);
  2959. }
  2960. if (modified) {
  2961. this.#setModified();
  2962. }
  2963. if (value instanceof _editor.AnnotationEditor && typeof this.onAnnotationEditor === "function") {
  2964. this.onAnnotationEditor(value.constructor._type);
  2965. }
  2966. }
  2967. has(key) {
  2968. return this._storage.has(key);
  2969. }
  2970. getAll() {
  2971. return this._storage.size > 0 ? (0, _util.objectFromMap)(this._storage) : null;
  2972. }
  2973. get size() {
  2974. return this._storage.size;
  2975. }
  2976. #setModified() {
  2977. if (!this._modified) {
  2978. this._modified = true;
  2979. if (typeof this.onSetModified === "function") {
  2980. this.onSetModified();
  2981. }
  2982. }
  2983. }
  2984. resetModified() {
  2985. if (this._modified) {
  2986. this._modified = false;
  2987. if (typeof this.onResetModified === "function") {
  2988. this.onResetModified();
  2989. }
  2990. }
  2991. }
  2992. get print() {
  2993. return new PrintAnnotationStorage(this);
  2994. }
  2995. get serializable() {
  2996. if (this._storage.size === 0) {
  2997. return null;
  2998. }
  2999. const clone = new Map();
  3000. for (const [key, val] of this._storage) {
  3001. const serialized = val instanceof _editor.AnnotationEditor ? val.serialize() : val;
  3002. if (serialized) {
  3003. clone.set(key, serialized);
  3004. }
  3005. }
  3006. return clone;
  3007. }
  3008. static getHash(map) {
  3009. if (!map) {
  3010. return "";
  3011. }
  3012. const hash = new _murmurhash.MurmurHash3_64();
  3013. for (const [key, val] of map) {
  3014. hash.update(`${key}:${JSON.stringify(val)}`);
  3015. }
  3016. return hash.hexdigest();
  3017. }
  3018. }
  3019. exports.AnnotationStorage = AnnotationStorage;
  3020. class PrintAnnotationStorage extends AnnotationStorage {
  3021. #serializable = null;
  3022. constructor(parent) {
  3023. super();
  3024. this.#serializable = structuredClone(parent.serializable);
  3025. }
  3026. get print() {
  3027. (0, _util.unreachable)("Should not call PrintAnnotationStorage.print");
  3028. }
  3029. get serializable() {
  3030. return this.#serializable;
  3031. }
  3032. }
  3033. exports.PrintAnnotationStorage = PrintAnnotationStorage;
  3034. /***/ }),
  3035. /* 6 */
  3036. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3037. Object.defineProperty(exports, "__esModule", ({
  3038. value: true
  3039. }));
  3040. exports.AnnotationEditor = void 0;
  3041. var _tools = __w_pdfjs_require__(7);
  3042. var _util = __w_pdfjs_require__(1);
  3043. class AnnotationEditor {
  3044. #boundFocusin = this.focusin.bind(this);
  3045. #boundFocusout = this.focusout.bind(this);
  3046. #hasBeenSelected = false;
  3047. #isEditing = false;
  3048. #isInEditMode = false;
  3049. #zIndex = AnnotationEditor._zIndex++;
  3050. static _colorManager = new _tools.ColorManager();
  3051. static _zIndex = 1;
  3052. constructor(parameters) {
  3053. if (this.constructor === AnnotationEditor) {
  3054. (0, _util.unreachable)("Cannot initialize AnnotationEditor.");
  3055. }
  3056. this.parent = parameters.parent;
  3057. this.id = parameters.id;
  3058. this.width = this.height = null;
  3059. this.pageIndex = parameters.parent.pageIndex;
  3060. this.name = parameters.name;
  3061. this.div = null;
  3062. const [width, height] = this.parent.viewportBaseDimensions;
  3063. this.x = parameters.x / width;
  3064. this.y = parameters.y / height;
  3065. this.rotation = this.parent.viewport.rotation;
  3066. this.isAttachedToDOM = false;
  3067. }
  3068. static get _defaultLineColor() {
  3069. return (0, _util.shadow)(this, "_defaultLineColor", this._colorManager.getHexCode("CanvasText"));
  3070. }
  3071. setInBackground() {
  3072. this.div.style.zIndex = 0;
  3073. }
  3074. setInForeground() {
  3075. this.div.style.zIndex = this.#zIndex;
  3076. }
  3077. focusin(event) {
  3078. if (!this.#hasBeenSelected) {
  3079. this.parent.setSelected(this);
  3080. } else {
  3081. this.#hasBeenSelected = false;
  3082. }
  3083. }
  3084. focusout(event) {
  3085. if (!this.isAttachedToDOM) {
  3086. return;
  3087. }
  3088. const target = event.relatedTarget;
  3089. if (target?.closest(`#${this.id}`)) {
  3090. return;
  3091. }
  3092. event.preventDefault();
  3093. if (!this.parent.isMultipleSelection) {
  3094. this.commitOrRemove();
  3095. }
  3096. }
  3097. commitOrRemove() {
  3098. if (this.isEmpty()) {
  3099. this.remove();
  3100. } else {
  3101. this.commit();
  3102. }
  3103. }
  3104. commit() {
  3105. this.parent.addToAnnotationStorage(this);
  3106. }
  3107. dragstart(event) {
  3108. const rect = this.parent.div.getBoundingClientRect();
  3109. this.startX = event.clientX - rect.x;
  3110. this.startY = event.clientY - rect.y;
  3111. event.dataTransfer.setData("text/plain", this.id);
  3112. event.dataTransfer.effectAllowed = "move";
  3113. }
  3114. setAt(x, y, tx, ty) {
  3115. const [width, height] = this.parent.viewportBaseDimensions;
  3116. [tx, ty] = this.screenToPageTranslation(tx, ty);
  3117. this.x = (x + tx) / width;
  3118. this.y = (y + ty) / height;
  3119. this.div.style.left = `${100 * this.x}%`;
  3120. this.div.style.top = `${100 * this.y}%`;
  3121. }
  3122. translate(x, y) {
  3123. const [width, height] = this.parent.viewportBaseDimensions;
  3124. [x, y] = this.screenToPageTranslation(x, y);
  3125. this.x += x / width;
  3126. this.y += y / height;
  3127. this.div.style.left = `${100 * this.x}%`;
  3128. this.div.style.top = `${100 * this.y}%`;
  3129. }
  3130. screenToPageTranslation(x, y) {
  3131. const {
  3132. rotation
  3133. } = this.parent.viewport;
  3134. switch (rotation) {
  3135. case 90:
  3136. return [y, -x];
  3137. case 180:
  3138. return [-x, -y];
  3139. case 270:
  3140. return [-y, x];
  3141. default:
  3142. return [x, y];
  3143. }
  3144. }
  3145. setDims(width, height) {
  3146. const [parentWidth, parentHeight] = this.parent.viewportBaseDimensions;
  3147. this.div.style.width = `${100 * width / parentWidth}%`;
  3148. this.div.style.height = `${100 * height / parentHeight}%`;
  3149. }
  3150. getInitialTranslation() {
  3151. return [0, 0];
  3152. }
  3153. render() {
  3154. this.div = document.createElement("div");
  3155. this.div.setAttribute("data-editor-rotation", (360 - this.rotation) % 360);
  3156. this.div.className = this.name;
  3157. this.div.setAttribute("id", this.id);
  3158. this.div.setAttribute("tabIndex", 0);
  3159. this.setInForeground();
  3160. this.div.addEventListener("focusin", this.#boundFocusin);
  3161. this.div.addEventListener("focusout", this.#boundFocusout);
  3162. const [tx, ty] = this.getInitialTranslation();
  3163. this.translate(tx, ty);
  3164. (0, _tools.bindEvents)(this, this.div, ["dragstart", "pointerdown"]);
  3165. return this.div;
  3166. }
  3167. pointerdown(event) {
  3168. const isMac = _tools.KeyboardManager.platform.isMac;
  3169. if (event.button !== 0 || event.ctrlKey && isMac) {
  3170. event.preventDefault();
  3171. return;
  3172. }
  3173. if (event.ctrlKey && !isMac || event.shiftKey || event.metaKey && isMac) {
  3174. this.parent.toggleSelected(this);
  3175. } else {
  3176. this.parent.setSelected(this);
  3177. }
  3178. this.#hasBeenSelected = true;
  3179. }
  3180. getRect(tx, ty) {
  3181. const [parentWidth, parentHeight] = this.parent.viewportBaseDimensions;
  3182. const [pageWidth, pageHeight] = this.parent.pageDimensions;
  3183. const shiftX = pageWidth * tx / parentWidth;
  3184. const shiftY = pageHeight * ty / parentHeight;
  3185. const x = this.x * pageWidth;
  3186. const y = this.y * pageHeight;
  3187. const width = this.width * pageWidth;
  3188. const height = this.height * pageHeight;
  3189. switch (this.rotation) {
  3190. case 0:
  3191. return [x + shiftX, pageHeight - y - shiftY - height, x + shiftX + width, pageHeight - y - shiftY];
  3192. case 90:
  3193. return [x + shiftY, pageHeight - y + shiftX, x + shiftY + height, pageHeight - y + shiftX + width];
  3194. case 180:
  3195. return [x - shiftX - width, pageHeight - y + shiftY, x - shiftX, pageHeight - y + shiftY + height];
  3196. case 270:
  3197. return [x - shiftY - height, pageHeight - y - shiftX - width, x - shiftY, pageHeight - y - shiftX];
  3198. default:
  3199. throw new Error("Invalid rotation");
  3200. }
  3201. }
  3202. getRectInCurrentCoords(rect, pageHeight) {
  3203. const [x1, y1, x2, y2] = rect;
  3204. const width = x2 - x1;
  3205. const height = y2 - y1;
  3206. switch (this.rotation) {
  3207. case 0:
  3208. return [x1, pageHeight - y2, width, height];
  3209. case 90:
  3210. return [x1, pageHeight - y1, height, width];
  3211. case 180:
  3212. return [x2, pageHeight - y1, width, height];
  3213. case 270:
  3214. return [x2, pageHeight - y2, height, width];
  3215. default:
  3216. throw new Error("Invalid rotation");
  3217. }
  3218. }
  3219. onceAdded() {}
  3220. isEmpty() {
  3221. return false;
  3222. }
  3223. enableEditMode() {
  3224. this.#isInEditMode = true;
  3225. }
  3226. disableEditMode() {
  3227. this.#isInEditMode = false;
  3228. }
  3229. isInEditMode() {
  3230. return this.#isInEditMode;
  3231. }
  3232. shouldGetKeyboardEvents() {
  3233. return false;
  3234. }
  3235. needsToBeRebuilt() {
  3236. return this.div && !this.isAttachedToDOM;
  3237. }
  3238. rebuild() {
  3239. this.div?.addEventListener("focusin", this.#boundFocusin);
  3240. }
  3241. serialize() {
  3242. (0, _util.unreachable)("An editor must be serializable");
  3243. }
  3244. static deserialize(data, parent) {
  3245. const editor = new this.prototype.constructor({
  3246. parent,
  3247. id: parent.getNextId()
  3248. });
  3249. editor.rotation = data.rotation;
  3250. const [pageWidth, pageHeight] = parent.pageDimensions;
  3251. const [x, y, width, height] = editor.getRectInCurrentCoords(data.rect, pageHeight);
  3252. editor.x = x / pageWidth;
  3253. editor.y = y / pageHeight;
  3254. editor.width = width / pageWidth;
  3255. editor.height = height / pageHeight;
  3256. return editor;
  3257. }
  3258. remove() {
  3259. this.div.removeEventListener("focusin", this.#boundFocusin);
  3260. this.div.removeEventListener("focusout", this.#boundFocusout);
  3261. if (!this.isEmpty()) {
  3262. this.commit();
  3263. }
  3264. this.parent.remove(this);
  3265. }
  3266. select() {
  3267. this.div?.classList.add("selectedEditor");
  3268. }
  3269. unselect() {
  3270. this.div?.classList.remove("selectedEditor");
  3271. }
  3272. updateParams(type, value) {}
  3273. disableEditing() {}
  3274. enableEditing() {}
  3275. get propertiesToUpdate() {
  3276. return {};
  3277. }
  3278. get contentDiv() {
  3279. return this.div;
  3280. }
  3281. get isEditing() {
  3282. return this.#isEditing;
  3283. }
  3284. set isEditing(value) {
  3285. this.#isEditing = value;
  3286. if (value) {
  3287. this.parent.setSelected(this);
  3288. this.parent.setActiveEditor(this);
  3289. } else {
  3290. this.parent.setActiveEditor(null);
  3291. }
  3292. }
  3293. }
  3294. exports.AnnotationEditor = AnnotationEditor;
  3295. /***/ }),
  3296. /* 7 */
  3297. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3298. Object.defineProperty(exports, "__esModule", ({
  3299. value: true
  3300. }));
  3301. exports.KeyboardManager = exports.CommandManager = exports.ColorManager = exports.AnnotationEditorUIManager = void 0;
  3302. exports.bindEvents = bindEvents;
  3303. exports.opacityToHex = opacityToHex;
  3304. var _util = __w_pdfjs_require__(1);
  3305. var _display_utils = __w_pdfjs_require__(8);
  3306. function bindEvents(obj, element, names) {
  3307. for (const name of names) {
  3308. element.addEventListener(name, obj[name].bind(obj));
  3309. }
  3310. }
  3311. function opacityToHex(opacity) {
  3312. return Math.round(Math.min(255, Math.max(1, 255 * opacity))).toString(16).padStart(2, "0");
  3313. }
  3314. class IdManager {
  3315. #id = 0;
  3316. getId() {
  3317. return `${_util.AnnotationEditorPrefix}${this.#id++}`;
  3318. }
  3319. }
  3320. class CommandManager {
  3321. #commands = [];
  3322. #locked = false;
  3323. #maxSize;
  3324. #position = -1;
  3325. constructor(maxSize = 128) {
  3326. this.#maxSize = maxSize;
  3327. }
  3328. add({
  3329. cmd,
  3330. undo,
  3331. mustExec,
  3332. type = NaN,
  3333. overwriteIfSameType = false,
  3334. keepUndo = false
  3335. }) {
  3336. if (mustExec) {
  3337. cmd();
  3338. }
  3339. if (this.#locked) {
  3340. return;
  3341. }
  3342. const save = {
  3343. cmd,
  3344. undo,
  3345. type
  3346. };
  3347. if (this.#position === -1) {
  3348. if (this.#commands.length > 0) {
  3349. this.#commands.length = 0;
  3350. }
  3351. this.#position = 0;
  3352. this.#commands.push(save);
  3353. return;
  3354. }
  3355. if (overwriteIfSameType && this.#commands[this.#position].type === type) {
  3356. if (keepUndo) {
  3357. save.undo = this.#commands[this.#position].undo;
  3358. }
  3359. this.#commands[this.#position] = save;
  3360. return;
  3361. }
  3362. const next = this.#position + 1;
  3363. if (next === this.#maxSize) {
  3364. this.#commands.splice(0, 1);
  3365. } else {
  3366. this.#position = next;
  3367. if (next < this.#commands.length) {
  3368. this.#commands.splice(next);
  3369. }
  3370. }
  3371. this.#commands.push(save);
  3372. }
  3373. undo() {
  3374. if (this.#position === -1) {
  3375. return;
  3376. }
  3377. this.#locked = true;
  3378. this.#commands[this.#position].undo();
  3379. this.#locked = false;
  3380. this.#position -= 1;
  3381. }
  3382. redo() {
  3383. if (this.#position < this.#commands.length - 1) {
  3384. this.#position += 1;
  3385. this.#locked = true;
  3386. this.#commands[this.#position].cmd();
  3387. this.#locked = false;
  3388. }
  3389. }
  3390. hasSomethingToUndo() {
  3391. return this.#position !== -1;
  3392. }
  3393. hasSomethingToRedo() {
  3394. return this.#position < this.#commands.length - 1;
  3395. }
  3396. destroy() {
  3397. this.#commands = null;
  3398. }
  3399. }
  3400. exports.CommandManager = CommandManager;
  3401. class KeyboardManager {
  3402. constructor(callbacks) {
  3403. this.buffer = [];
  3404. this.callbacks = new Map();
  3405. this.allKeys = new Set();
  3406. const isMac = KeyboardManager.platform.isMac;
  3407. for (const [keys, callback] of callbacks) {
  3408. for (const key of keys) {
  3409. const isMacKey = key.startsWith("mac+");
  3410. if (isMac && isMacKey) {
  3411. this.callbacks.set(key.slice(4), callback);
  3412. this.allKeys.add(key.split("+").at(-1));
  3413. } else if (!isMac && !isMacKey) {
  3414. this.callbacks.set(key, callback);
  3415. this.allKeys.add(key.split("+").at(-1));
  3416. }
  3417. }
  3418. }
  3419. }
  3420. static get platform() {
  3421. const platform = typeof navigator !== "undefined" ? navigator.platform : "";
  3422. return (0, _util.shadow)(this, "platform", {
  3423. isWin: platform.includes("Win"),
  3424. isMac: platform.includes("Mac")
  3425. });
  3426. }
  3427. #serialize(event) {
  3428. if (event.altKey) {
  3429. this.buffer.push("alt");
  3430. }
  3431. if (event.ctrlKey) {
  3432. this.buffer.push("ctrl");
  3433. }
  3434. if (event.metaKey) {
  3435. this.buffer.push("meta");
  3436. }
  3437. if (event.shiftKey) {
  3438. this.buffer.push("shift");
  3439. }
  3440. this.buffer.push(event.key);
  3441. const str = this.buffer.join("+");
  3442. this.buffer.length = 0;
  3443. return str;
  3444. }
  3445. exec(self, event) {
  3446. if (!this.allKeys.has(event.key)) {
  3447. return;
  3448. }
  3449. const callback = this.callbacks.get(this.#serialize(event));
  3450. if (!callback) {
  3451. return;
  3452. }
  3453. callback.bind(self)();
  3454. event.stopPropagation();
  3455. event.preventDefault();
  3456. }
  3457. }
  3458. exports.KeyboardManager = KeyboardManager;
  3459. class ClipboardManager {
  3460. #elements = null;
  3461. copy(element) {
  3462. if (!element) {
  3463. return;
  3464. }
  3465. if (Array.isArray(element)) {
  3466. this.#elements = element.map(el => el.serialize());
  3467. } else {
  3468. this.#elements = [element.serialize()];
  3469. }
  3470. this.#elements = this.#elements.filter(el => !!el);
  3471. if (this.#elements.length === 0) {
  3472. this.#elements = null;
  3473. }
  3474. }
  3475. paste() {
  3476. return this.#elements;
  3477. }
  3478. isEmpty() {
  3479. return this.#elements === null;
  3480. }
  3481. destroy() {
  3482. this.#elements = null;
  3483. }
  3484. }
  3485. class ColorManager {
  3486. static _colorsMapping = new Map([["CanvasText", [0, 0, 0]], ["Canvas", [255, 255, 255]]]);
  3487. get _colors() {
  3488. const colors = new Map([["CanvasText", null], ["Canvas", null]]);
  3489. (0, _display_utils.getColorValues)(colors);
  3490. return (0, _util.shadow)(this, "_colors", colors);
  3491. }
  3492. convert(color) {
  3493. const rgb = (0, _display_utils.getRGB)(color);
  3494. if (!window.matchMedia("(forced-colors: active)").matches) {
  3495. return rgb;
  3496. }
  3497. for (const [name, RGB] of this._colors) {
  3498. if (RGB.every((x, i) => x === rgb[i])) {
  3499. return ColorManager._colorsMapping.get(name);
  3500. }
  3501. }
  3502. return rgb;
  3503. }
  3504. getHexCode(name) {
  3505. const rgb = this._colors.get(name);
  3506. if (!rgb) {
  3507. return name;
  3508. }
  3509. return _util.Util.makeHexColor(...rgb);
  3510. }
  3511. }
  3512. exports.ColorManager = ColorManager;
  3513. class AnnotationEditorUIManager {
  3514. #activeEditor = null;
  3515. #allEditors = new Map();
  3516. #allLayers = new Map();
  3517. #clipboardManager = new ClipboardManager();
  3518. #commandManager = new CommandManager();
  3519. #currentPageIndex = 0;
  3520. #editorTypes = null;
  3521. #eventBus = null;
  3522. #idManager = new IdManager();
  3523. #isEnabled = false;
  3524. #mode = _util.AnnotationEditorType.NONE;
  3525. #selectedEditors = new Set();
  3526. #boundKeydown = this.keydown.bind(this);
  3527. #boundOnEditingAction = this.onEditingAction.bind(this);
  3528. #boundOnPageChanging = this.onPageChanging.bind(this);
  3529. #previousStates = {
  3530. isEditing: false,
  3531. isEmpty: true,
  3532. hasEmptyClipboard: true,
  3533. hasSomethingToUndo: false,
  3534. hasSomethingToRedo: false,
  3535. hasSelectedEditor: false
  3536. };
  3537. #container = null;
  3538. static _keyboardManager = new KeyboardManager([[["ctrl+a", "mac+meta+a"], AnnotationEditorUIManager.prototype.selectAll], [["ctrl+c", "mac+meta+c"], AnnotationEditorUIManager.prototype.copy], [["ctrl+v", "mac+meta+v"], AnnotationEditorUIManager.prototype.paste], [["ctrl+x", "mac+meta+x"], AnnotationEditorUIManager.prototype.cut], [["ctrl+z", "mac+meta+z"], AnnotationEditorUIManager.prototype.undo], [["ctrl+y", "ctrl+shift+Z", "mac+meta+shift+Z"], AnnotationEditorUIManager.prototype.redo], [["Backspace", "alt+Backspace", "ctrl+Backspace", "shift+Backspace", "mac+Backspace", "mac+alt+Backspace", "mac+ctrl+Backspace", "Delete", "ctrl+Delete", "shift+Delete"], AnnotationEditorUIManager.prototype.delete], [["Escape", "mac+Escape"], AnnotationEditorUIManager.prototype.unselectAll]]);
  3539. constructor(container, eventBus) {
  3540. this.#container = container;
  3541. this.#eventBus = eventBus;
  3542. this.#eventBus._on("editingaction", this.#boundOnEditingAction);
  3543. this.#eventBus._on("pagechanging", this.#boundOnPageChanging);
  3544. }
  3545. destroy() {
  3546. this.#removeKeyboardManager();
  3547. this.#eventBus._off("editingaction", this.#boundOnEditingAction);
  3548. this.#eventBus._off("pagechanging", this.#boundOnPageChanging);
  3549. for (const layer of this.#allLayers.values()) {
  3550. layer.destroy();
  3551. }
  3552. this.#allLayers.clear();
  3553. this.#allEditors.clear();
  3554. this.#activeEditor = null;
  3555. this.#selectedEditors.clear();
  3556. this.#clipboardManager.destroy();
  3557. this.#commandManager.destroy();
  3558. }
  3559. onPageChanging({
  3560. pageNumber
  3561. }) {
  3562. this.#currentPageIndex = pageNumber - 1;
  3563. }
  3564. focusMainContainer() {
  3565. this.#container.focus();
  3566. }
  3567. #addKeyboardManager() {
  3568. this.#container.addEventListener("keydown", this.#boundKeydown);
  3569. }
  3570. #removeKeyboardManager() {
  3571. this.#container.removeEventListener("keydown", this.#boundKeydown);
  3572. }
  3573. keydown(event) {
  3574. if (!this.getActive()?.shouldGetKeyboardEvents()) {
  3575. AnnotationEditorUIManager._keyboardManager.exec(this, event);
  3576. }
  3577. }
  3578. onEditingAction(details) {
  3579. if (["undo", "redo", "cut", "copy", "paste", "delete", "selectAll"].includes(details.name)) {
  3580. this[details.name]();
  3581. }
  3582. }
  3583. #dispatchUpdateStates(details) {
  3584. const hasChanged = Object.entries(details).some(([key, value]) => this.#previousStates[key] !== value);
  3585. if (hasChanged) {
  3586. this.#eventBus.dispatch("annotationeditorstateschanged", {
  3587. source: this,
  3588. details: Object.assign(this.#previousStates, details)
  3589. });
  3590. }
  3591. }
  3592. #dispatchUpdateUI(details) {
  3593. this.#eventBus.dispatch("annotationeditorparamschanged", {
  3594. source: this,
  3595. details
  3596. });
  3597. }
  3598. setEditingState(isEditing) {
  3599. if (isEditing) {
  3600. this.#addKeyboardManager();
  3601. this.#dispatchUpdateStates({
  3602. isEditing: this.#mode !== _util.AnnotationEditorType.NONE,
  3603. isEmpty: this.#isEmpty(),
  3604. hasSomethingToUndo: this.#commandManager.hasSomethingToUndo(),
  3605. hasSomethingToRedo: this.#commandManager.hasSomethingToRedo(),
  3606. hasSelectedEditor: false,
  3607. hasEmptyClipboard: this.#clipboardManager.isEmpty()
  3608. });
  3609. } else {
  3610. this.#removeKeyboardManager();
  3611. this.#dispatchUpdateStates({
  3612. isEditing: false
  3613. });
  3614. }
  3615. }
  3616. registerEditorTypes(types) {
  3617. this.#editorTypes = types;
  3618. for (const editorType of this.#editorTypes) {
  3619. this.#dispatchUpdateUI(editorType.defaultPropertiesToUpdate);
  3620. }
  3621. }
  3622. getId() {
  3623. return this.#idManager.getId();
  3624. }
  3625. addLayer(layer) {
  3626. this.#allLayers.set(layer.pageIndex, layer);
  3627. if (this.#isEnabled) {
  3628. layer.enable();
  3629. } else {
  3630. layer.disable();
  3631. }
  3632. }
  3633. removeLayer(layer) {
  3634. this.#allLayers.delete(layer.pageIndex);
  3635. }
  3636. updateMode(mode) {
  3637. this.#mode = mode;
  3638. if (mode === _util.AnnotationEditorType.NONE) {
  3639. this.setEditingState(false);
  3640. this.#disableAll();
  3641. } else {
  3642. this.setEditingState(true);
  3643. this.#enableAll();
  3644. for (const layer of this.#allLayers.values()) {
  3645. layer.updateMode(mode);
  3646. }
  3647. }
  3648. }
  3649. updateToolbar(mode) {
  3650. if (mode === this.#mode) {
  3651. return;
  3652. }
  3653. this.#eventBus.dispatch("switchannotationeditormode", {
  3654. source: this,
  3655. mode
  3656. });
  3657. }
  3658. updateParams(type, value) {
  3659. for (const editor of this.#selectedEditors) {
  3660. editor.updateParams(type, value);
  3661. }
  3662. for (const editorType of this.#editorTypes) {
  3663. editorType.updateDefaultParams(type, value);
  3664. }
  3665. }
  3666. #enableAll() {
  3667. if (!this.#isEnabled) {
  3668. this.#isEnabled = true;
  3669. for (const layer of this.#allLayers.values()) {
  3670. layer.enable();
  3671. }
  3672. }
  3673. }
  3674. #disableAll() {
  3675. this.unselectAll();
  3676. if (this.#isEnabled) {
  3677. this.#isEnabled = false;
  3678. for (const layer of this.#allLayers.values()) {
  3679. layer.disable();
  3680. }
  3681. }
  3682. }
  3683. getEditors(pageIndex) {
  3684. const editors = [];
  3685. for (const editor of this.#allEditors.values()) {
  3686. if (editor.pageIndex === pageIndex) {
  3687. editors.push(editor);
  3688. }
  3689. }
  3690. return editors;
  3691. }
  3692. getEditor(id) {
  3693. return this.#allEditors.get(id);
  3694. }
  3695. addEditor(editor) {
  3696. this.#allEditors.set(editor.id, editor);
  3697. }
  3698. removeEditor(editor) {
  3699. this.#allEditors.delete(editor.id);
  3700. this.unselect(editor);
  3701. }
  3702. #addEditorToLayer(editor) {
  3703. const layer = this.#allLayers.get(editor.pageIndex);
  3704. if (layer) {
  3705. layer.addOrRebuild(editor);
  3706. } else {
  3707. this.addEditor(editor);
  3708. }
  3709. }
  3710. setActiveEditor(editor) {
  3711. if (this.#activeEditor === editor) {
  3712. return;
  3713. }
  3714. this.#activeEditor = editor;
  3715. if (editor) {
  3716. this.#dispatchUpdateUI(editor.propertiesToUpdate);
  3717. }
  3718. }
  3719. toggleSelected(editor) {
  3720. if (this.#selectedEditors.has(editor)) {
  3721. this.#selectedEditors.delete(editor);
  3722. editor.unselect();
  3723. this.#dispatchUpdateStates({
  3724. hasSelectedEditor: this.hasSelection
  3725. });
  3726. return;
  3727. }
  3728. this.#selectedEditors.add(editor);
  3729. editor.select();
  3730. this.#dispatchUpdateUI(editor.propertiesToUpdate);
  3731. this.#dispatchUpdateStates({
  3732. hasSelectedEditor: true
  3733. });
  3734. }
  3735. setSelected(editor) {
  3736. for (const ed of this.#selectedEditors) {
  3737. if (ed !== editor) {
  3738. ed.unselect();
  3739. }
  3740. }
  3741. this.#selectedEditors.clear();
  3742. this.#selectedEditors.add(editor);
  3743. editor.select();
  3744. this.#dispatchUpdateUI(editor.propertiesToUpdate);
  3745. this.#dispatchUpdateStates({
  3746. hasSelectedEditor: true
  3747. });
  3748. }
  3749. isSelected(editor) {
  3750. return this.#selectedEditors.has(editor);
  3751. }
  3752. unselect(editor) {
  3753. editor.unselect();
  3754. this.#selectedEditors.delete(editor);
  3755. this.#dispatchUpdateStates({
  3756. hasSelectedEditor: this.hasSelection
  3757. });
  3758. }
  3759. get hasSelection() {
  3760. return this.#selectedEditors.size !== 0;
  3761. }
  3762. undo() {
  3763. this.#commandManager.undo();
  3764. this.#dispatchUpdateStates({
  3765. hasSomethingToUndo: this.#commandManager.hasSomethingToUndo(),
  3766. hasSomethingToRedo: true,
  3767. isEmpty: this.#isEmpty()
  3768. });
  3769. }
  3770. redo() {
  3771. this.#commandManager.redo();
  3772. this.#dispatchUpdateStates({
  3773. hasSomethingToUndo: true,
  3774. hasSomethingToRedo: this.#commandManager.hasSomethingToRedo(),
  3775. isEmpty: this.#isEmpty()
  3776. });
  3777. }
  3778. addCommands(params) {
  3779. this.#commandManager.add(params);
  3780. this.#dispatchUpdateStates({
  3781. hasSomethingToUndo: true,
  3782. hasSomethingToRedo: false,
  3783. isEmpty: this.#isEmpty()
  3784. });
  3785. }
  3786. #isEmpty() {
  3787. if (this.#allEditors.size === 0) {
  3788. return true;
  3789. }
  3790. if (this.#allEditors.size === 1) {
  3791. for (const editor of this.#allEditors.values()) {
  3792. return editor.isEmpty();
  3793. }
  3794. }
  3795. return false;
  3796. }
  3797. delete() {
  3798. if (this.#activeEditor) {
  3799. this.#activeEditor.commitOrRemove();
  3800. }
  3801. if (!this.hasSelection) {
  3802. return;
  3803. }
  3804. const editors = [...this.#selectedEditors];
  3805. const cmd = () => {
  3806. for (const editor of editors) {
  3807. editor.remove();
  3808. }
  3809. };
  3810. const undo = () => {
  3811. for (const editor of editors) {
  3812. this.#addEditorToLayer(editor);
  3813. }
  3814. };
  3815. this.addCommands({
  3816. cmd,
  3817. undo,
  3818. mustExec: true
  3819. });
  3820. }
  3821. copy() {
  3822. if (this.#activeEditor) {
  3823. this.#activeEditor.commitOrRemove();
  3824. }
  3825. if (this.hasSelection) {
  3826. const editors = [];
  3827. for (const editor of this.#selectedEditors) {
  3828. if (!editor.isEmpty()) {
  3829. editors.push(editor);
  3830. }
  3831. }
  3832. if (editors.length === 0) {
  3833. return;
  3834. }
  3835. this.#clipboardManager.copy(editors);
  3836. this.#dispatchUpdateStates({
  3837. hasEmptyClipboard: false
  3838. });
  3839. }
  3840. }
  3841. cut() {
  3842. this.copy();
  3843. this.delete();
  3844. }
  3845. paste() {
  3846. if (this.#clipboardManager.isEmpty()) {
  3847. return;
  3848. }
  3849. this.unselectAll();
  3850. const layer = this.#allLayers.get(this.#currentPageIndex);
  3851. const newEditors = this.#clipboardManager.paste().map(data => layer.deserialize(data));
  3852. const cmd = () => {
  3853. for (const editor of newEditors) {
  3854. this.#addEditorToLayer(editor);
  3855. }
  3856. this.#selectEditors(newEditors);
  3857. };
  3858. const undo = () => {
  3859. for (const editor of newEditors) {
  3860. editor.remove();
  3861. }
  3862. };
  3863. this.addCommands({
  3864. cmd,
  3865. undo,
  3866. mustExec: true
  3867. });
  3868. }
  3869. #selectEditors(editors) {
  3870. this.#selectedEditors.clear();
  3871. for (const editor of editors) {
  3872. if (editor.isEmpty()) {
  3873. continue;
  3874. }
  3875. this.#selectedEditors.add(editor);
  3876. editor.select();
  3877. }
  3878. this.#dispatchUpdateStates({
  3879. hasSelectedEditor: true
  3880. });
  3881. }
  3882. selectAll() {
  3883. for (const editor of this.#selectedEditors) {
  3884. editor.commit();
  3885. }
  3886. this.#selectEditors(this.#allEditors.values());
  3887. }
  3888. unselectAll() {
  3889. if (this.#activeEditor) {
  3890. this.#activeEditor.commitOrRemove();
  3891. return;
  3892. }
  3893. if (this.#selectEditors.size === 0) {
  3894. return;
  3895. }
  3896. for (const editor of this.#selectedEditors) {
  3897. editor.unselect();
  3898. }
  3899. this.#selectedEditors.clear();
  3900. this.#dispatchUpdateStates({
  3901. hasSelectedEditor: false
  3902. });
  3903. }
  3904. isActive(editor) {
  3905. return this.#activeEditor === editor;
  3906. }
  3907. getActive() {
  3908. return this.#activeEditor;
  3909. }
  3910. getMode() {
  3911. return this.#mode;
  3912. }
  3913. }
  3914. exports.AnnotationEditorUIManager = AnnotationEditorUIManager;
  3915. /***/ }),
  3916. /* 8 */
  3917. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3918. Object.defineProperty(exports, "__esModule", ({
  3919. value: true
  3920. }));
  3921. exports.StatTimer = exports.RenderingCancelledException = exports.PixelsPerInch = exports.PageViewport = exports.PDFDateString = exports.DOMStandardFontDataFactory = exports.DOMSVGFactory = exports.DOMCanvasFactory = exports.DOMCMapReaderFactory = exports.AnnotationPrefix = void 0;
  3922. exports.deprecated = deprecated;
  3923. exports.getColorValues = getColorValues;
  3924. exports.getCurrentTransform = getCurrentTransform;
  3925. exports.getCurrentTransformInverse = getCurrentTransformInverse;
  3926. exports.getFilenameFromUrl = getFilenameFromUrl;
  3927. exports.getPdfFilenameFromUrl = getPdfFilenameFromUrl;
  3928. exports.getRGB = getRGB;
  3929. exports.getXfaPageViewport = getXfaPageViewport;
  3930. exports.isDataScheme = isDataScheme;
  3931. exports.isPdfFile = isPdfFile;
  3932. exports.isValidFetchUrl = isValidFetchUrl;
  3933. exports.loadScript = loadScript;
  3934. var _base_factory = __w_pdfjs_require__(9);
  3935. var _util = __w_pdfjs_require__(1);
  3936. const SVG_NS = "http://www.w3.org/2000/svg";
  3937. const AnnotationPrefix = "pdfjs_internal_id_";
  3938. exports.AnnotationPrefix = AnnotationPrefix;
  3939. class PixelsPerInch {
  3940. static CSS = 96.0;
  3941. static PDF = 72.0;
  3942. static PDF_TO_CSS_UNITS = this.CSS / this.PDF;
  3943. }
  3944. exports.PixelsPerInch = PixelsPerInch;
  3945. class DOMCanvasFactory extends _base_factory.BaseCanvasFactory {
  3946. constructor({
  3947. ownerDocument = globalThis.document
  3948. } = {}) {
  3949. super();
  3950. this._document = ownerDocument;
  3951. }
  3952. _createCanvas(width, height) {
  3953. const canvas = this._document.createElement("canvas");
  3954. canvas.width = width;
  3955. canvas.height = height;
  3956. return canvas;
  3957. }
  3958. }
  3959. exports.DOMCanvasFactory = DOMCanvasFactory;
  3960. async function fetchData(url, asTypedArray = false) {
  3961. if (isValidFetchUrl(url, document.baseURI)) {
  3962. const response = await fetch(url);
  3963. if (!response.ok) {
  3964. throw new Error(response.statusText);
  3965. }
  3966. return asTypedArray ? new Uint8Array(await response.arrayBuffer()) : (0, _util.stringToBytes)(await response.text());
  3967. }
  3968. return new Promise((resolve, reject) => {
  3969. const request = new XMLHttpRequest();
  3970. request.open("GET", url, true);
  3971. if (asTypedArray) {
  3972. request.responseType = "arraybuffer";
  3973. }
  3974. request.onreadystatechange = () => {
  3975. if (request.readyState !== XMLHttpRequest.DONE) {
  3976. return;
  3977. }
  3978. if (request.status === 200 || request.status === 0) {
  3979. let data;
  3980. if (asTypedArray && request.response) {
  3981. data = new Uint8Array(request.response);
  3982. } else if (!asTypedArray && request.responseText) {
  3983. data = (0, _util.stringToBytes)(request.responseText);
  3984. }
  3985. if (data) {
  3986. resolve(data);
  3987. return;
  3988. }
  3989. }
  3990. reject(new Error(request.statusText));
  3991. };
  3992. request.send(null);
  3993. });
  3994. }
  3995. class DOMCMapReaderFactory extends _base_factory.BaseCMapReaderFactory {
  3996. _fetchData(url, compressionType) {
  3997. return fetchData(url, this.isCompressed).then(data => {
  3998. return {
  3999. cMapData: data,
  4000. compressionType
  4001. };
  4002. });
  4003. }
  4004. }
  4005. exports.DOMCMapReaderFactory = DOMCMapReaderFactory;
  4006. class DOMStandardFontDataFactory extends _base_factory.BaseStandardFontDataFactory {
  4007. _fetchData(url) {
  4008. return fetchData(url, true);
  4009. }
  4010. }
  4011. exports.DOMStandardFontDataFactory = DOMStandardFontDataFactory;
  4012. class DOMSVGFactory extends _base_factory.BaseSVGFactory {
  4013. _createSVG(type) {
  4014. return document.createElementNS(SVG_NS, type);
  4015. }
  4016. }
  4017. exports.DOMSVGFactory = DOMSVGFactory;
  4018. class PageViewport {
  4019. constructor({
  4020. viewBox,
  4021. scale,
  4022. rotation,
  4023. offsetX = 0,
  4024. offsetY = 0,
  4025. dontFlip = false
  4026. }) {
  4027. this.viewBox = viewBox;
  4028. this.scale = scale;
  4029. this.rotation = rotation;
  4030. this.offsetX = offsetX;
  4031. this.offsetY = offsetY;
  4032. const centerX = (viewBox[2] + viewBox[0]) / 2;
  4033. const centerY = (viewBox[3] + viewBox[1]) / 2;
  4034. let rotateA, rotateB, rotateC, rotateD;
  4035. rotation %= 360;
  4036. if (rotation < 0) {
  4037. rotation += 360;
  4038. }
  4039. switch (rotation) {
  4040. case 180:
  4041. rotateA = -1;
  4042. rotateB = 0;
  4043. rotateC = 0;
  4044. rotateD = 1;
  4045. break;
  4046. case 90:
  4047. rotateA = 0;
  4048. rotateB = 1;
  4049. rotateC = 1;
  4050. rotateD = 0;
  4051. break;
  4052. case 270:
  4053. rotateA = 0;
  4054. rotateB = -1;
  4055. rotateC = -1;
  4056. rotateD = 0;
  4057. break;
  4058. case 0:
  4059. rotateA = 1;
  4060. rotateB = 0;
  4061. rotateC = 0;
  4062. rotateD = -1;
  4063. break;
  4064. default:
  4065. throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.");
  4066. }
  4067. if (dontFlip) {
  4068. rotateC = -rotateC;
  4069. rotateD = -rotateD;
  4070. }
  4071. let offsetCanvasX, offsetCanvasY;
  4072. let width, height;
  4073. if (rotateA === 0) {
  4074. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  4075. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  4076. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  4077. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  4078. } else {
  4079. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  4080. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  4081. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  4082. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  4083. }
  4084. this.transform = [rotateA * scale, rotateB * scale, rotateC * scale, rotateD * scale, offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY, offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY];
  4085. this.width = width;
  4086. this.height = height;
  4087. }
  4088. clone({
  4089. scale = this.scale,
  4090. rotation = this.rotation,
  4091. offsetX = this.offsetX,
  4092. offsetY = this.offsetY,
  4093. dontFlip = false
  4094. } = {}) {
  4095. return new PageViewport({
  4096. viewBox: this.viewBox.slice(),
  4097. scale,
  4098. rotation,
  4099. offsetX,
  4100. offsetY,
  4101. dontFlip
  4102. });
  4103. }
  4104. convertToViewportPoint(x, y) {
  4105. return _util.Util.applyTransform([x, y], this.transform);
  4106. }
  4107. convertToViewportRectangle(rect) {
  4108. const topLeft = _util.Util.applyTransform([rect[0], rect[1]], this.transform);
  4109. const bottomRight = _util.Util.applyTransform([rect[2], rect[3]], this.transform);
  4110. return [topLeft[0], topLeft[1], bottomRight[0], bottomRight[1]];
  4111. }
  4112. convertToPdfPoint(x, y) {
  4113. return _util.Util.applyInverseTransform([x, y], this.transform);
  4114. }
  4115. }
  4116. exports.PageViewport = PageViewport;
  4117. class RenderingCancelledException extends _util.BaseException {
  4118. constructor(msg, type) {
  4119. super(msg, "RenderingCancelledException");
  4120. this.type = type;
  4121. }
  4122. }
  4123. exports.RenderingCancelledException = RenderingCancelledException;
  4124. function isDataScheme(url) {
  4125. const ii = url.length;
  4126. let i = 0;
  4127. while (i < ii && url[i].trim() === "") {
  4128. i++;
  4129. }
  4130. return url.substring(i, i + 5).toLowerCase() === "data:";
  4131. }
  4132. function isPdfFile(filename) {
  4133. return typeof filename === "string" && /\.pdf$/i.test(filename);
  4134. }
  4135. function getFilenameFromUrl(url) {
  4136. const anchor = url.indexOf("#");
  4137. const query = url.indexOf("?");
  4138. const end = Math.min(anchor > 0 ? anchor : url.length, query > 0 ? query : url.length);
  4139. return url.substring(url.lastIndexOf("/", end) + 1, end);
  4140. }
  4141. function getPdfFilenameFromUrl(url, defaultFilename = "document.pdf") {
  4142. if (typeof url !== "string") {
  4143. return defaultFilename;
  4144. }
  4145. if (isDataScheme(url)) {
  4146. (0, _util.warn)('getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.');
  4147. return defaultFilename;
  4148. }
  4149. const reURI = /^(?:(?:[^:]+:)?\/\/[^/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
  4150. const reFilename = /[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
  4151. const splitURI = reURI.exec(url);
  4152. let suggestedFilename = reFilename.exec(splitURI[1]) || reFilename.exec(splitURI[2]) || reFilename.exec(splitURI[3]);
  4153. if (suggestedFilename) {
  4154. suggestedFilename = suggestedFilename[0];
  4155. if (suggestedFilename.includes("%")) {
  4156. try {
  4157. suggestedFilename = reFilename.exec(decodeURIComponent(suggestedFilename))[0];
  4158. } catch (ex) {}
  4159. }
  4160. }
  4161. return suggestedFilename || defaultFilename;
  4162. }
  4163. class StatTimer {
  4164. constructor() {
  4165. this.started = Object.create(null);
  4166. this.times = [];
  4167. }
  4168. time(name) {
  4169. if (name in this.started) {
  4170. (0, _util.warn)(`Timer is already running for ${name}`);
  4171. }
  4172. this.started[name] = Date.now();
  4173. }
  4174. timeEnd(name) {
  4175. if (!(name in this.started)) {
  4176. (0, _util.warn)(`Timer has not been started for ${name}`);
  4177. }
  4178. this.times.push({
  4179. name,
  4180. start: this.started[name],
  4181. end: Date.now()
  4182. });
  4183. delete this.started[name];
  4184. }
  4185. toString() {
  4186. const outBuf = [];
  4187. let longest = 0;
  4188. for (const time of this.times) {
  4189. const name = time.name;
  4190. if (name.length > longest) {
  4191. longest = name.length;
  4192. }
  4193. }
  4194. for (const time of this.times) {
  4195. const duration = time.end - time.start;
  4196. outBuf.push(`${time.name.padEnd(longest)} ${duration}ms\n`);
  4197. }
  4198. return outBuf.join("");
  4199. }
  4200. }
  4201. exports.StatTimer = StatTimer;
  4202. function isValidFetchUrl(url, baseUrl) {
  4203. try {
  4204. const {
  4205. protocol
  4206. } = baseUrl ? new URL(url, baseUrl) : new URL(url);
  4207. return protocol === "http:" || protocol === "https:";
  4208. } catch (ex) {
  4209. return false;
  4210. }
  4211. }
  4212. function loadScript(src, removeScriptElement = false) {
  4213. return new Promise((resolve, reject) => {
  4214. const script = document.createElement("script");
  4215. script.src = src;
  4216. script.onload = function (evt) {
  4217. if (removeScriptElement) {
  4218. script.remove();
  4219. }
  4220. resolve(evt);
  4221. };
  4222. script.onerror = function () {
  4223. reject(new Error(`Cannot load script at: ${script.src}`));
  4224. };
  4225. (document.head || document.documentElement).append(script);
  4226. });
  4227. }
  4228. function deprecated(details) {
  4229. console.log("Deprecated API usage: " + details);
  4230. }
  4231. let pdfDateStringRegex;
  4232. class PDFDateString {
  4233. static toDateObject(input) {
  4234. if (!input || typeof input !== "string") {
  4235. return null;
  4236. }
  4237. if (!pdfDateStringRegex) {
  4238. pdfDateStringRegex = new RegExp("^D:" + "(\\d{4})" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "([Z|+|-])?" + "(\\d{2})?" + "'?" + "(\\d{2})?" + "'?");
  4239. }
  4240. const matches = pdfDateStringRegex.exec(input);
  4241. if (!matches) {
  4242. return null;
  4243. }
  4244. const year = parseInt(matches[1], 10);
  4245. let month = parseInt(matches[2], 10);
  4246. month = month >= 1 && month <= 12 ? month - 1 : 0;
  4247. let day = parseInt(matches[3], 10);
  4248. day = day >= 1 && day <= 31 ? day : 1;
  4249. let hour = parseInt(matches[4], 10);
  4250. hour = hour >= 0 && hour <= 23 ? hour : 0;
  4251. let minute = parseInt(matches[5], 10);
  4252. minute = minute >= 0 && minute <= 59 ? minute : 0;
  4253. let second = parseInt(matches[6], 10);
  4254. second = second >= 0 && second <= 59 ? second : 0;
  4255. const universalTimeRelation = matches[7] || "Z";
  4256. let offsetHour = parseInt(matches[8], 10);
  4257. offsetHour = offsetHour >= 0 && offsetHour <= 23 ? offsetHour : 0;
  4258. let offsetMinute = parseInt(matches[9], 10) || 0;
  4259. offsetMinute = offsetMinute >= 0 && offsetMinute <= 59 ? offsetMinute : 0;
  4260. if (universalTimeRelation === "-") {
  4261. hour += offsetHour;
  4262. minute += offsetMinute;
  4263. } else if (universalTimeRelation === "+") {
  4264. hour -= offsetHour;
  4265. minute -= offsetMinute;
  4266. }
  4267. return new Date(Date.UTC(year, month, day, hour, minute, second));
  4268. }
  4269. }
  4270. exports.PDFDateString = PDFDateString;
  4271. function getXfaPageViewport(xfaPage, {
  4272. scale = 1,
  4273. rotation = 0
  4274. }) {
  4275. const {
  4276. width,
  4277. height
  4278. } = xfaPage.attributes.style;
  4279. const viewBox = [0, 0, parseInt(width), parseInt(height)];
  4280. return new PageViewport({
  4281. viewBox,
  4282. scale,
  4283. rotation
  4284. });
  4285. }
  4286. function getRGB(color) {
  4287. if (color.startsWith("#")) {
  4288. const colorRGB = parseInt(color.slice(1), 16);
  4289. return [(colorRGB & 0xff0000) >> 16, (colorRGB & 0x00ff00) >> 8, colorRGB & 0x0000ff];
  4290. }
  4291. if (color.startsWith("rgb(")) {
  4292. return color.slice(4, -1).split(",").map(x => parseInt(x));
  4293. }
  4294. if (color.startsWith("rgba(")) {
  4295. return color.slice(5, -1).split(",").map(x => parseInt(x)).slice(0, 3);
  4296. }
  4297. (0, _util.warn)(`Not a valid color format: "${color}"`);
  4298. return [0, 0, 0];
  4299. }
  4300. function getColorValues(colors) {
  4301. const span = document.createElement("span");
  4302. span.style.visibility = "hidden";
  4303. document.body.append(span);
  4304. for (const name of colors.keys()) {
  4305. span.style.color = name;
  4306. const computedColor = window.getComputedStyle(span).color;
  4307. colors.set(name, getRGB(computedColor));
  4308. }
  4309. span.remove();
  4310. }
  4311. function getCurrentTransform(ctx) {
  4312. const {
  4313. a,
  4314. b,
  4315. c,
  4316. d,
  4317. e,
  4318. f
  4319. } = ctx.getTransform();
  4320. return [a, b, c, d, e, f];
  4321. }
  4322. function getCurrentTransformInverse(ctx) {
  4323. const {
  4324. a,
  4325. b,
  4326. c,
  4327. d,
  4328. e,
  4329. f
  4330. } = ctx.getTransform().invertSelf();
  4331. return [a, b, c, d, e, f];
  4332. }
  4333. /***/ }),
  4334. /* 9 */
  4335. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  4336. Object.defineProperty(exports, "__esModule", ({
  4337. value: true
  4338. }));
  4339. exports.BaseStandardFontDataFactory = exports.BaseSVGFactory = exports.BaseCanvasFactory = exports.BaseCMapReaderFactory = void 0;
  4340. var _util = __w_pdfjs_require__(1);
  4341. class BaseCanvasFactory {
  4342. constructor() {
  4343. if (this.constructor === BaseCanvasFactory) {
  4344. (0, _util.unreachable)("Cannot initialize BaseCanvasFactory.");
  4345. }
  4346. }
  4347. create(width, height) {
  4348. if (width <= 0 || height <= 0) {
  4349. throw new Error("Invalid canvas size");
  4350. }
  4351. const canvas = this._createCanvas(width, height);
  4352. return {
  4353. canvas,
  4354. context: canvas.getContext("2d")
  4355. };
  4356. }
  4357. reset(canvasAndContext, width, height) {
  4358. if (!canvasAndContext.canvas) {
  4359. throw new Error("Canvas is not specified");
  4360. }
  4361. if (width <= 0 || height <= 0) {
  4362. throw new Error("Invalid canvas size");
  4363. }
  4364. canvasAndContext.canvas.width = width;
  4365. canvasAndContext.canvas.height = height;
  4366. }
  4367. destroy(canvasAndContext) {
  4368. if (!canvasAndContext.canvas) {
  4369. throw new Error("Canvas is not specified");
  4370. }
  4371. canvasAndContext.canvas.width = 0;
  4372. canvasAndContext.canvas.height = 0;
  4373. canvasAndContext.canvas = null;
  4374. canvasAndContext.context = null;
  4375. }
  4376. _createCanvas(width, height) {
  4377. (0, _util.unreachable)("Abstract method `_createCanvas` called.");
  4378. }
  4379. }
  4380. exports.BaseCanvasFactory = BaseCanvasFactory;
  4381. class BaseCMapReaderFactory {
  4382. constructor({
  4383. baseUrl = null,
  4384. isCompressed = false
  4385. }) {
  4386. if (this.constructor === BaseCMapReaderFactory) {
  4387. (0, _util.unreachable)("Cannot initialize BaseCMapReaderFactory.");
  4388. }
  4389. this.baseUrl = baseUrl;
  4390. this.isCompressed = isCompressed;
  4391. }
  4392. async fetch({
  4393. name
  4394. }) {
  4395. if (!this.baseUrl) {
  4396. throw new Error('The CMap "baseUrl" parameter must be specified, ensure that ' + 'the "cMapUrl" and "cMapPacked" API parameters are provided.');
  4397. }
  4398. if (!name) {
  4399. throw new Error("CMap name must be specified.");
  4400. }
  4401. const url = this.baseUrl + name + (this.isCompressed ? ".bcmap" : "");
  4402. const compressionType = this.isCompressed ? _util.CMapCompressionType.BINARY : _util.CMapCompressionType.NONE;
  4403. return this._fetchData(url, compressionType).catch(reason => {
  4404. throw new Error(`Unable to load ${this.isCompressed ? "binary " : ""}CMap at: ${url}`);
  4405. });
  4406. }
  4407. _fetchData(url, compressionType) {
  4408. (0, _util.unreachable)("Abstract method `_fetchData` called.");
  4409. }
  4410. }
  4411. exports.BaseCMapReaderFactory = BaseCMapReaderFactory;
  4412. class BaseStandardFontDataFactory {
  4413. constructor({
  4414. baseUrl = null
  4415. }) {
  4416. if (this.constructor === BaseStandardFontDataFactory) {
  4417. (0, _util.unreachable)("Cannot initialize BaseStandardFontDataFactory.");
  4418. }
  4419. this.baseUrl = baseUrl;
  4420. }
  4421. async fetch({
  4422. filename
  4423. }) {
  4424. if (!this.baseUrl) {
  4425. throw new Error('The standard font "baseUrl" parameter must be specified, ensure that ' + 'the "standardFontDataUrl" API parameter is provided.');
  4426. }
  4427. if (!filename) {
  4428. throw new Error("Font filename must be specified.");
  4429. }
  4430. const url = `${this.baseUrl}${filename}`;
  4431. return this._fetchData(url).catch(reason => {
  4432. throw new Error(`Unable to load font data at: ${url}`);
  4433. });
  4434. }
  4435. _fetchData(url) {
  4436. (0, _util.unreachable)("Abstract method `_fetchData` called.");
  4437. }
  4438. }
  4439. exports.BaseStandardFontDataFactory = BaseStandardFontDataFactory;
  4440. class BaseSVGFactory {
  4441. constructor() {
  4442. if (this.constructor === BaseSVGFactory) {
  4443. (0, _util.unreachable)("Cannot initialize BaseSVGFactory.");
  4444. }
  4445. }
  4446. create(width, height, skipDimensions = false) {
  4447. if (width <= 0 || height <= 0) {
  4448. throw new Error("Invalid SVG dimensions");
  4449. }
  4450. const svg = this._createSVG("svg:svg");
  4451. svg.setAttribute("version", "1.1");
  4452. if (!skipDimensions) {
  4453. svg.setAttribute("width", `${width}px`);
  4454. svg.setAttribute("height", `${height}px`);
  4455. }
  4456. svg.setAttribute("preserveAspectRatio", "none");
  4457. svg.setAttribute("viewBox", `0 0 ${width} ${height}`);
  4458. return svg;
  4459. }
  4460. createElement(type) {
  4461. if (typeof type !== "string") {
  4462. throw new Error("Invalid SVG element type");
  4463. }
  4464. return this._createSVG(type);
  4465. }
  4466. _createSVG(type) {
  4467. (0, _util.unreachable)("Abstract method `_createSVG` called.");
  4468. }
  4469. }
  4470. exports.BaseSVGFactory = BaseSVGFactory;
  4471. /***/ }),
  4472. /* 10 */
  4473. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  4474. Object.defineProperty(exports, "__esModule", ({
  4475. value: true
  4476. }));
  4477. exports.MurmurHash3_64 = void 0;
  4478. var _util = __w_pdfjs_require__(1);
  4479. const SEED = 0xc3d2e1f0;
  4480. const MASK_HIGH = 0xffff0000;
  4481. const MASK_LOW = 0xffff;
  4482. class MurmurHash3_64 {
  4483. constructor(seed) {
  4484. this.h1 = seed ? seed & 0xffffffff : SEED;
  4485. this.h2 = seed ? seed & 0xffffffff : SEED;
  4486. }
  4487. update(input) {
  4488. let data, length;
  4489. if (typeof input === "string") {
  4490. data = new Uint8Array(input.length * 2);
  4491. length = 0;
  4492. for (let i = 0, ii = input.length; i < ii; i++) {
  4493. const code = input.charCodeAt(i);
  4494. if (code <= 0xff) {
  4495. data[length++] = code;
  4496. } else {
  4497. data[length++] = code >>> 8;
  4498. data[length++] = code & 0xff;
  4499. }
  4500. }
  4501. } else if ((0, _util.isArrayBuffer)(input)) {
  4502. data = input.slice();
  4503. length = data.byteLength;
  4504. } else {
  4505. throw new Error("Wrong data format in MurmurHash3_64_update. " + "Input must be a string or array.");
  4506. }
  4507. const blockCounts = length >> 2;
  4508. const tailLength = length - blockCounts * 4;
  4509. const dataUint32 = new Uint32Array(data.buffer, 0, blockCounts);
  4510. let k1 = 0,
  4511. k2 = 0;
  4512. let h1 = this.h1,
  4513. h2 = this.h2;
  4514. const C1 = 0xcc9e2d51,
  4515. C2 = 0x1b873593;
  4516. const C1_LOW = C1 & MASK_LOW,
  4517. C2_LOW = C2 & MASK_LOW;
  4518. for (let i = 0; i < blockCounts; i++) {
  4519. if (i & 1) {
  4520. k1 = dataUint32[i];
  4521. k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
  4522. k1 = k1 << 15 | k1 >>> 17;
  4523. k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
  4524. h1 ^= k1;
  4525. h1 = h1 << 13 | h1 >>> 19;
  4526. h1 = h1 * 5 + 0xe6546b64;
  4527. } else {
  4528. k2 = dataUint32[i];
  4529. k2 = k2 * C1 & MASK_HIGH | k2 * C1_LOW & MASK_LOW;
  4530. k2 = k2 << 15 | k2 >>> 17;
  4531. k2 = k2 * C2 & MASK_HIGH | k2 * C2_LOW & MASK_LOW;
  4532. h2 ^= k2;
  4533. h2 = h2 << 13 | h2 >>> 19;
  4534. h2 = h2 * 5 + 0xe6546b64;
  4535. }
  4536. }
  4537. k1 = 0;
  4538. switch (tailLength) {
  4539. case 3:
  4540. k1 ^= data[blockCounts * 4 + 2] << 16;
  4541. case 2:
  4542. k1 ^= data[blockCounts * 4 + 1] << 8;
  4543. case 1:
  4544. k1 ^= data[blockCounts * 4];
  4545. k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
  4546. k1 = k1 << 15 | k1 >>> 17;
  4547. k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
  4548. if (blockCounts & 1) {
  4549. h1 ^= k1;
  4550. } else {
  4551. h2 ^= k1;
  4552. }
  4553. }
  4554. this.h1 = h1;
  4555. this.h2 = h2;
  4556. }
  4557. hexdigest() {
  4558. let h1 = this.h1,
  4559. h2 = this.h2;
  4560. h1 ^= h2 >>> 1;
  4561. h1 = h1 * 0xed558ccd & MASK_HIGH | h1 * 0x8ccd & MASK_LOW;
  4562. h2 = h2 * 0xff51afd7 & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16;
  4563. h1 ^= h2 >>> 1;
  4564. h1 = h1 * 0x1a85ec53 & MASK_HIGH | h1 * 0xec53 & MASK_LOW;
  4565. h2 = h2 * 0xc4ceb9fe & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16;
  4566. h1 ^= h2 >>> 1;
  4567. const hex1 = (h1 >>> 0).toString(16),
  4568. hex2 = (h2 >>> 0).toString(16);
  4569. return hex1.padStart(8, "0") + hex2.padStart(8, "0");
  4570. }
  4571. }
  4572. exports.MurmurHash3_64 = MurmurHash3_64;
  4573. /***/ }),
  4574. /* 11 */
  4575. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  4576. Object.defineProperty(exports, "__esModule", ({
  4577. value: true
  4578. }));
  4579. exports.FontLoader = exports.FontFaceObject = void 0;
  4580. var _util = __w_pdfjs_require__(1);
  4581. class BaseFontLoader {
  4582. constructor({
  4583. docId,
  4584. onUnsupportedFeature,
  4585. ownerDocument = globalThis.document,
  4586. styleElement = null
  4587. }) {
  4588. if (this.constructor === BaseFontLoader) {
  4589. (0, _util.unreachable)("Cannot initialize BaseFontLoader.");
  4590. }
  4591. this.docId = docId;
  4592. this._onUnsupportedFeature = onUnsupportedFeature;
  4593. this._document = ownerDocument;
  4594. this.nativeFontFaces = [];
  4595. this.styleElement = null;
  4596. }
  4597. addNativeFontFace(nativeFontFace) {
  4598. this.nativeFontFaces.push(nativeFontFace);
  4599. this._document.fonts.add(nativeFontFace);
  4600. }
  4601. insertRule(rule) {
  4602. let styleElement = this.styleElement;
  4603. if (!styleElement) {
  4604. styleElement = this.styleElement = this._document.createElement("style");
  4605. styleElement.id = `PDFJS_FONT_STYLE_TAG_${this.docId}`;
  4606. this._document.documentElement.getElementsByTagName("head")[0].append(styleElement);
  4607. }
  4608. const styleSheet = styleElement.sheet;
  4609. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  4610. }
  4611. clear() {
  4612. for (const nativeFontFace of this.nativeFontFaces) {
  4613. this._document.fonts.delete(nativeFontFace);
  4614. }
  4615. this.nativeFontFaces.length = 0;
  4616. if (this.styleElement) {
  4617. this.styleElement.remove();
  4618. this.styleElement = null;
  4619. }
  4620. }
  4621. async bind(font) {
  4622. if (font.attached || font.missingFile) {
  4623. return;
  4624. }
  4625. font.attached = true;
  4626. if (this.isFontLoadingAPISupported) {
  4627. const nativeFontFace = font.createNativeFontFace();
  4628. if (nativeFontFace) {
  4629. this.addNativeFontFace(nativeFontFace);
  4630. try {
  4631. await nativeFontFace.loaded;
  4632. } catch (ex) {
  4633. this._onUnsupportedFeature({
  4634. featureId: _util.UNSUPPORTED_FEATURES.errorFontLoadNative
  4635. });
  4636. (0, _util.warn)(`Failed to load font '${nativeFontFace.family}': '${ex}'.`);
  4637. font.disableFontFace = true;
  4638. throw ex;
  4639. }
  4640. }
  4641. return;
  4642. }
  4643. const rule = font.createFontFaceRule();
  4644. if (rule) {
  4645. this.insertRule(rule);
  4646. if (this.isSyncFontLoadingSupported) {
  4647. return;
  4648. }
  4649. await new Promise(resolve => {
  4650. const request = this._queueLoadingCallback(resolve);
  4651. this._prepareFontLoadEvent([rule], [font], request);
  4652. });
  4653. }
  4654. }
  4655. _queueLoadingCallback(callback) {
  4656. (0, _util.unreachable)("Abstract method `_queueLoadingCallback`.");
  4657. }
  4658. get isFontLoadingAPISupported() {
  4659. const hasFonts = !!this._document?.fonts;
  4660. return (0, _util.shadow)(this, "isFontLoadingAPISupported", hasFonts);
  4661. }
  4662. get isSyncFontLoadingSupported() {
  4663. (0, _util.unreachable)("Abstract method `isSyncFontLoadingSupported`.");
  4664. }
  4665. get _loadTestFont() {
  4666. (0, _util.unreachable)("Abstract method `_loadTestFont`.");
  4667. }
  4668. _prepareFontLoadEvent(rules, fontsToLoad, request) {
  4669. (0, _util.unreachable)("Abstract method `_prepareFontLoadEvent`.");
  4670. }
  4671. }
  4672. let FontLoader;
  4673. exports.FontLoader = FontLoader;
  4674. {
  4675. exports.FontLoader = FontLoader = class GenericFontLoader extends BaseFontLoader {
  4676. constructor(params) {
  4677. super(params);
  4678. this.loadingContext = {
  4679. requests: [],
  4680. nextRequestId: 0
  4681. };
  4682. this.loadTestFontId = 0;
  4683. }
  4684. get isSyncFontLoadingSupported() {
  4685. let supported = false;
  4686. if (typeof navigator === "undefined") {
  4687. supported = true;
  4688. } else {
  4689. const m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(navigator.userAgent);
  4690. if (m?.[1] >= 14) {
  4691. supported = true;
  4692. }
  4693. }
  4694. return (0, _util.shadow)(this, "isSyncFontLoadingSupported", supported);
  4695. }
  4696. _queueLoadingCallback(callback) {
  4697. function completeRequest() {
  4698. (0, _util.assert)(!request.done, "completeRequest() cannot be called twice.");
  4699. request.done = true;
  4700. while (context.requests.length > 0 && context.requests[0].done) {
  4701. const otherRequest = context.requests.shift();
  4702. setTimeout(otherRequest.callback, 0);
  4703. }
  4704. }
  4705. const context = this.loadingContext;
  4706. const request = {
  4707. id: `pdfjs-font-loading-${context.nextRequestId++}`,
  4708. done: false,
  4709. complete: completeRequest,
  4710. callback
  4711. };
  4712. context.requests.push(request);
  4713. return request;
  4714. }
  4715. get _loadTestFont() {
  4716. const getLoadTestFont = function () {
  4717. 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==");
  4718. };
  4719. return (0, _util.shadow)(this, "_loadTestFont", getLoadTestFont());
  4720. }
  4721. _prepareFontLoadEvent(rules, fonts, request) {
  4722. function int32(data, offset) {
  4723. return data.charCodeAt(offset) << 24 | data.charCodeAt(offset + 1) << 16 | data.charCodeAt(offset + 2) << 8 | data.charCodeAt(offset + 3) & 0xff;
  4724. }
  4725. function spliceString(s, offset, remove, insert) {
  4726. const chunk1 = s.substring(0, offset);
  4727. const chunk2 = s.substring(offset + remove);
  4728. return chunk1 + insert + chunk2;
  4729. }
  4730. let i, ii;
  4731. const canvas = this._document.createElement("canvas");
  4732. canvas.width = 1;
  4733. canvas.height = 1;
  4734. const ctx = canvas.getContext("2d");
  4735. let called = 0;
  4736. function isFontReady(name, callback) {
  4737. called++;
  4738. if (called > 30) {
  4739. (0, _util.warn)("Load test font never loaded.");
  4740. callback();
  4741. return;
  4742. }
  4743. ctx.font = "30px " + name;
  4744. ctx.fillText(".", 0, 20);
  4745. const imageData = ctx.getImageData(0, 0, 1, 1);
  4746. if (imageData.data[3] > 0) {
  4747. callback();
  4748. return;
  4749. }
  4750. setTimeout(isFontReady.bind(null, name, callback));
  4751. }
  4752. const loadTestFontId = `lt${Date.now()}${this.loadTestFontId++}`;
  4753. let data = this._loadTestFont;
  4754. const COMMENT_OFFSET = 976;
  4755. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length, loadTestFontId);
  4756. const CFF_CHECKSUM_OFFSET = 16;
  4757. const XXXX_VALUE = 0x58585858;
  4758. let checksum = int32(data, CFF_CHECKSUM_OFFSET);
  4759. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  4760. checksum = checksum - XXXX_VALUE + int32(loadTestFontId, i) | 0;
  4761. }
  4762. if (i < loadTestFontId.length) {
  4763. checksum = checksum - XXXX_VALUE + int32(loadTestFontId + "XXX", i) | 0;
  4764. }
  4765. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, (0, _util.string32)(checksum));
  4766. const url = `url(data:font/opentype;base64,${btoa(data)});`;
  4767. const rule = `@font-face {font-family:"${loadTestFontId}";src:${url}}`;
  4768. this.insertRule(rule);
  4769. const names = [];
  4770. for (const font of fonts) {
  4771. names.push(font.loadedName);
  4772. }
  4773. names.push(loadTestFontId);
  4774. const div = this._document.createElement("div");
  4775. div.style.visibility = "hidden";
  4776. div.style.width = div.style.height = "10px";
  4777. div.style.position = "absolute";
  4778. div.style.top = div.style.left = "0px";
  4779. for (const name of names) {
  4780. const span = this._document.createElement("span");
  4781. span.textContent = "Hi";
  4782. span.style.fontFamily = name;
  4783. div.append(span);
  4784. }
  4785. this._document.body.append(div);
  4786. isFontReady(loadTestFontId, () => {
  4787. div.remove();
  4788. request.complete();
  4789. });
  4790. }
  4791. };
  4792. }
  4793. class FontFaceObject {
  4794. constructor(translatedData, {
  4795. isEvalSupported = true,
  4796. disableFontFace = false,
  4797. ignoreErrors = false,
  4798. onUnsupportedFeature,
  4799. fontRegistry = null
  4800. }) {
  4801. this.compiledGlyphs = Object.create(null);
  4802. for (const i in translatedData) {
  4803. this[i] = translatedData[i];
  4804. }
  4805. this.isEvalSupported = isEvalSupported !== false;
  4806. this.disableFontFace = disableFontFace === true;
  4807. this.ignoreErrors = ignoreErrors === true;
  4808. this._onUnsupportedFeature = onUnsupportedFeature;
  4809. this.fontRegistry = fontRegistry;
  4810. }
  4811. createNativeFontFace() {
  4812. if (!this.data || this.disableFontFace) {
  4813. return null;
  4814. }
  4815. let nativeFontFace;
  4816. if (!this.cssFontInfo) {
  4817. nativeFontFace = new FontFace(this.loadedName, this.data, {});
  4818. } else {
  4819. const css = {
  4820. weight: this.cssFontInfo.fontWeight
  4821. };
  4822. if (this.cssFontInfo.italicAngle) {
  4823. css.style = `oblique ${this.cssFontInfo.italicAngle}deg`;
  4824. }
  4825. nativeFontFace = new FontFace(this.cssFontInfo.fontFamily, this.data, css);
  4826. }
  4827. if (this.fontRegistry) {
  4828. this.fontRegistry.registerFont(this);
  4829. }
  4830. return nativeFontFace;
  4831. }
  4832. createFontFaceRule() {
  4833. if (!this.data || this.disableFontFace) {
  4834. return null;
  4835. }
  4836. const data = (0, _util.bytesToString)(this.data);
  4837. const url = `url(data:${this.mimetype};base64,${btoa(data)});`;
  4838. let rule;
  4839. if (!this.cssFontInfo) {
  4840. rule = `@font-face {font-family:"${this.loadedName}";src:${url}}`;
  4841. } else {
  4842. let css = `font-weight: ${this.cssFontInfo.fontWeight};`;
  4843. if (this.cssFontInfo.italicAngle) {
  4844. css += `font-style: oblique ${this.cssFontInfo.italicAngle}deg;`;
  4845. }
  4846. rule = `@font-face {font-family:"${this.cssFontInfo.fontFamily}";${css}src:${url}}`;
  4847. }
  4848. if (this.fontRegistry) {
  4849. this.fontRegistry.registerFont(this, url);
  4850. }
  4851. return rule;
  4852. }
  4853. getPathGenerator(objs, character) {
  4854. if (this.compiledGlyphs[character] !== undefined) {
  4855. return this.compiledGlyphs[character];
  4856. }
  4857. let cmds;
  4858. try {
  4859. cmds = objs.get(this.loadedName + "_path_" + character);
  4860. } catch (ex) {
  4861. if (!this.ignoreErrors) {
  4862. throw ex;
  4863. }
  4864. this._onUnsupportedFeature({
  4865. featureId: _util.UNSUPPORTED_FEATURES.errorFontGetPath
  4866. });
  4867. (0, _util.warn)(`getPathGenerator - ignoring character: "${ex}".`);
  4868. return this.compiledGlyphs[character] = function (c, size) {};
  4869. }
  4870. if (this.isEvalSupported && _util.FeatureTest.isEvalSupported) {
  4871. const jsBuf = [];
  4872. for (const current of cmds) {
  4873. const args = current.args !== undefined ? current.args.join(",") : "";
  4874. jsBuf.push("c.", current.cmd, "(", args, ");\n");
  4875. }
  4876. return this.compiledGlyphs[character] = new Function("c", "size", jsBuf.join(""));
  4877. }
  4878. return this.compiledGlyphs[character] = function (c, size) {
  4879. for (const current of cmds) {
  4880. if (current.cmd === "scale") {
  4881. current.args = [size, -size];
  4882. }
  4883. c[current.cmd].apply(c, current.args);
  4884. }
  4885. };
  4886. }
  4887. }
  4888. exports.FontFaceObject = FontFaceObject;
  4889. /***/ }),
  4890. /* 12 */
  4891. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  4892. Object.defineProperty(exports, "__esModule", ({
  4893. value: true
  4894. }));
  4895. exports.CanvasGraphics = void 0;
  4896. var _display_utils = __w_pdfjs_require__(8);
  4897. var _util = __w_pdfjs_require__(1);
  4898. var _pattern_helper = __w_pdfjs_require__(13);
  4899. var _image_utils = __w_pdfjs_require__(14);
  4900. var _is_node = __w_pdfjs_require__(3);
  4901. const MIN_FONT_SIZE = 16;
  4902. const MAX_FONT_SIZE = 100;
  4903. const MAX_GROUP_SIZE = 4096;
  4904. const EXECUTION_TIME = 15;
  4905. const EXECUTION_STEPS = 10;
  4906. const MAX_SIZE_TO_COMPILE = _is_node.isNodeJS && typeof Path2D === "undefined" ? -1 : 1000;
  4907. const FULL_CHUNK_HEIGHT = 16;
  4908. function mirrorContextOperations(ctx, destCtx) {
  4909. if (ctx._removeMirroring) {
  4910. throw new Error("Context is already forwarding operations.");
  4911. }
  4912. ctx.__originalSave = ctx.save;
  4913. ctx.__originalRestore = ctx.restore;
  4914. ctx.__originalRotate = ctx.rotate;
  4915. ctx.__originalScale = ctx.scale;
  4916. ctx.__originalTranslate = ctx.translate;
  4917. ctx.__originalTransform = ctx.transform;
  4918. ctx.__originalSetTransform = ctx.setTransform;
  4919. ctx.__originalResetTransform = ctx.resetTransform;
  4920. ctx.__originalClip = ctx.clip;
  4921. ctx.__originalMoveTo = ctx.moveTo;
  4922. ctx.__originalLineTo = ctx.lineTo;
  4923. ctx.__originalBezierCurveTo = ctx.bezierCurveTo;
  4924. ctx.__originalRect = ctx.rect;
  4925. ctx.__originalClosePath = ctx.closePath;
  4926. ctx.__originalBeginPath = ctx.beginPath;
  4927. ctx._removeMirroring = () => {
  4928. ctx.save = ctx.__originalSave;
  4929. ctx.restore = ctx.__originalRestore;
  4930. ctx.rotate = ctx.__originalRotate;
  4931. ctx.scale = ctx.__originalScale;
  4932. ctx.translate = ctx.__originalTranslate;
  4933. ctx.transform = ctx.__originalTransform;
  4934. ctx.setTransform = ctx.__originalSetTransform;
  4935. ctx.resetTransform = ctx.__originalResetTransform;
  4936. ctx.clip = ctx.__originalClip;
  4937. ctx.moveTo = ctx.__originalMoveTo;
  4938. ctx.lineTo = ctx.__originalLineTo;
  4939. ctx.bezierCurveTo = ctx.__originalBezierCurveTo;
  4940. ctx.rect = ctx.__originalRect;
  4941. ctx.closePath = ctx.__originalClosePath;
  4942. ctx.beginPath = ctx.__originalBeginPath;
  4943. delete ctx._removeMirroring;
  4944. };
  4945. ctx.save = function ctxSave() {
  4946. destCtx.save();
  4947. this.__originalSave();
  4948. };
  4949. ctx.restore = function ctxRestore() {
  4950. destCtx.restore();
  4951. this.__originalRestore();
  4952. };
  4953. ctx.translate = function ctxTranslate(x, y) {
  4954. destCtx.translate(x, y);
  4955. this.__originalTranslate(x, y);
  4956. };
  4957. ctx.scale = function ctxScale(x, y) {
  4958. destCtx.scale(x, y);
  4959. this.__originalScale(x, y);
  4960. };
  4961. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  4962. destCtx.transform(a, b, c, d, e, f);
  4963. this.__originalTransform(a, b, c, d, e, f);
  4964. };
  4965. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  4966. destCtx.setTransform(a, b, c, d, e, f);
  4967. this.__originalSetTransform(a, b, c, d, e, f);
  4968. };
  4969. ctx.resetTransform = function ctxResetTransform() {
  4970. destCtx.resetTransform();
  4971. this.__originalResetTransform();
  4972. };
  4973. ctx.rotate = function ctxRotate(angle) {
  4974. destCtx.rotate(angle);
  4975. this.__originalRotate(angle);
  4976. };
  4977. ctx.clip = function ctxRotate(rule) {
  4978. destCtx.clip(rule);
  4979. this.__originalClip(rule);
  4980. };
  4981. ctx.moveTo = function (x, y) {
  4982. destCtx.moveTo(x, y);
  4983. this.__originalMoveTo(x, y);
  4984. };
  4985. ctx.lineTo = function (x, y) {
  4986. destCtx.lineTo(x, y);
  4987. this.__originalLineTo(x, y);
  4988. };
  4989. ctx.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
  4990. destCtx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
  4991. this.__originalBezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
  4992. };
  4993. ctx.rect = function (x, y, width, height) {
  4994. destCtx.rect(x, y, width, height);
  4995. this.__originalRect(x, y, width, height);
  4996. };
  4997. ctx.closePath = function () {
  4998. destCtx.closePath();
  4999. this.__originalClosePath();
  5000. };
  5001. ctx.beginPath = function () {
  5002. destCtx.beginPath();
  5003. this.__originalBeginPath();
  5004. };
  5005. }
  5006. class CachedCanvases {
  5007. constructor(canvasFactory) {
  5008. this.canvasFactory = canvasFactory;
  5009. this.cache = Object.create(null);
  5010. }
  5011. getCanvas(id, width, height) {
  5012. let canvasEntry;
  5013. if (this.cache[id] !== undefined) {
  5014. canvasEntry = this.cache[id];
  5015. this.canvasFactory.reset(canvasEntry, width, height);
  5016. } else {
  5017. canvasEntry = this.canvasFactory.create(width, height);
  5018. this.cache[id] = canvasEntry;
  5019. }
  5020. return canvasEntry;
  5021. }
  5022. delete(id) {
  5023. delete this.cache[id];
  5024. }
  5025. clear() {
  5026. for (const id in this.cache) {
  5027. const canvasEntry = this.cache[id];
  5028. this.canvasFactory.destroy(canvasEntry);
  5029. delete this.cache[id];
  5030. }
  5031. }
  5032. }
  5033. function drawImageAtIntegerCoords(ctx, srcImg, srcX, srcY, srcW, srcH, destX, destY, destW, destH) {
  5034. const [a, b, c, d, tx, ty] = (0, _display_utils.getCurrentTransform)(ctx);
  5035. if (b === 0 && c === 0) {
  5036. const tlX = destX * a + tx;
  5037. const rTlX = Math.round(tlX);
  5038. const tlY = destY * d + ty;
  5039. const rTlY = Math.round(tlY);
  5040. const brX = (destX + destW) * a + tx;
  5041. const rWidth = Math.abs(Math.round(brX) - rTlX) || 1;
  5042. const brY = (destY + destH) * d + ty;
  5043. const rHeight = Math.abs(Math.round(brY) - rTlY) || 1;
  5044. ctx.setTransform(Math.sign(a), 0, 0, Math.sign(d), rTlX, rTlY);
  5045. ctx.drawImage(srcImg, srcX, srcY, srcW, srcH, 0, 0, rWidth, rHeight);
  5046. ctx.setTransform(a, b, c, d, tx, ty);
  5047. return [rWidth, rHeight];
  5048. }
  5049. if (a === 0 && d === 0) {
  5050. const tlX = destY * c + tx;
  5051. const rTlX = Math.round(tlX);
  5052. const tlY = destX * b + ty;
  5053. const rTlY = Math.round(tlY);
  5054. const brX = (destY + destH) * c + tx;
  5055. const rWidth = Math.abs(Math.round(brX) - rTlX) || 1;
  5056. const brY = (destX + destW) * b + ty;
  5057. const rHeight = Math.abs(Math.round(brY) - rTlY) || 1;
  5058. ctx.setTransform(0, Math.sign(b), Math.sign(c), 0, rTlX, rTlY);
  5059. ctx.drawImage(srcImg, srcX, srcY, srcW, srcH, 0, 0, rHeight, rWidth);
  5060. ctx.setTransform(a, b, c, d, tx, ty);
  5061. return [rHeight, rWidth];
  5062. }
  5063. ctx.drawImage(srcImg, srcX, srcY, srcW, srcH, destX, destY, destW, destH);
  5064. const scaleX = Math.hypot(a, b);
  5065. const scaleY = Math.hypot(c, d);
  5066. return [scaleX * destW, scaleY * destH];
  5067. }
  5068. function compileType3Glyph(imgData) {
  5069. const {
  5070. width,
  5071. height
  5072. } = imgData;
  5073. if (width > MAX_SIZE_TO_COMPILE || height > MAX_SIZE_TO_COMPILE) {
  5074. return null;
  5075. }
  5076. const POINT_TO_PROCESS_LIMIT = 1000;
  5077. const POINT_TYPES = new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  5078. const width1 = width + 1;
  5079. let points = new Uint8Array(width1 * (height + 1));
  5080. let i, j, j0;
  5081. const lineSize = width + 7 & ~7;
  5082. let data = new Uint8Array(lineSize * height),
  5083. pos = 0;
  5084. for (const elem of imgData.data) {
  5085. let mask = 128;
  5086. while (mask > 0) {
  5087. data[pos++] = elem & mask ? 0 : 255;
  5088. mask >>= 1;
  5089. }
  5090. }
  5091. let count = 0;
  5092. pos = 0;
  5093. if (data[pos] !== 0) {
  5094. points[0] = 1;
  5095. ++count;
  5096. }
  5097. for (j = 1; j < width; j++) {
  5098. if (data[pos] !== data[pos + 1]) {
  5099. points[j] = data[pos] ? 2 : 1;
  5100. ++count;
  5101. }
  5102. pos++;
  5103. }
  5104. if (data[pos] !== 0) {
  5105. points[j] = 2;
  5106. ++count;
  5107. }
  5108. for (i = 1; i < height; i++) {
  5109. pos = i * lineSize;
  5110. j0 = i * width1;
  5111. if (data[pos - lineSize] !== data[pos]) {
  5112. points[j0] = data[pos] ? 1 : 8;
  5113. ++count;
  5114. }
  5115. let sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  5116. for (j = 1; j < width; j++) {
  5117. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) + (data[pos - lineSize + 1] ? 8 : 0);
  5118. if (POINT_TYPES[sum]) {
  5119. points[j0 + j] = POINT_TYPES[sum];
  5120. ++count;
  5121. }
  5122. pos++;
  5123. }
  5124. if (data[pos - lineSize] !== data[pos]) {
  5125. points[j0 + j] = data[pos] ? 2 : 4;
  5126. ++count;
  5127. }
  5128. if (count > POINT_TO_PROCESS_LIMIT) {
  5129. return null;
  5130. }
  5131. }
  5132. pos = lineSize * (height - 1);
  5133. j0 = i * width1;
  5134. if (data[pos] !== 0) {
  5135. points[j0] = 8;
  5136. ++count;
  5137. }
  5138. for (j = 1; j < width; j++) {
  5139. if (data[pos] !== data[pos + 1]) {
  5140. points[j0 + j] = data[pos] ? 4 : 8;
  5141. ++count;
  5142. }
  5143. pos++;
  5144. }
  5145. if (data[pos] !== 0) {
  5146. points[j0 + j] = 4;
  5147. ++count;
  5148. }
  5149. if (count > POINT_TO_PROCESS_LIMIT) {
  5150. return null;
  5151. }
  5152. const steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  5153. const path = new Path2D();
  5154. for (i = 0; count && i <= height; i++) {
  5155. let p = i * width1;
  5156. const end = p + width;
  5157. while (p < end && !points[p]) {
  5158. p++;
  5159. }
  5160. if (p === end) {
  5161. continue;
  5162. }
  5163. path.moveTo(p % width1, i);
  5164. const p0 = p;
  5165. let type = points[p];
  5166. do {
  5167. const step = steps[type];
  5168. do {
  5169. p += step;
  5170. } while (!points[p]);
  5171. const pp = points[p];
  5172. if (pp !== 5 && pp !== 10) {
  5173. type = pp;
  5174. points[p] = 0;
  5175. } else {
  5176. type = pp & 0x33 * type >> 4;
  5177. points[p] &= type >> 2 | type << 2;
  5178. }
  5179. path.lineTo(p % width1, p / width1 | 0);
  5180. if (!points[p]) {
  5181. --count;
  5182. }
  5183. } while (p0 !== p);
  5184. --i;
  5185. }
  5186. data = null;
  5187. points = null;
  5188. const drawOutline = function (c) {
  5189. c.save();
  5190. c.scale(1 / width, -1 / height);
  5191. c.translate(0, -height);
  5192. c.fill(path);
  5193. c.beginPath();
  5194. c.restore();
  5195. };
  5196. return drawOutline;
  5197. }
  5198. class CanvasExtraState {
  5199. constructor(width, height) {
  5200. this.alphaIsShape = false;
  5201. this.fontSize = 0;
  5202. this.fontSizeScale = 1;
  5203. this.textMatrix = _util.IDENTITY_MATRIX;
  5204. this.textMatrixScale = 1;
  5205. this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
  5206. this.leading = 0;
  5207. this.x = 0;
  5208. this.y = 0;
  5209. this.lineX = 0;
  5210. this.lineY = 0;
  5211. this.charSpacing = 0;
  5212. this.wordSpacing = 0;
  5213. this.textHScale = 1;
  5214. this.textRenderingMode = _util.TextRenderingMode.FILL;
  5215. this.textRise = 0;
  5216. this.fillColor = "#000000";
  5217. this.strokeColor = "#000000";
  5218. this.patternFill = false;
  5219. this.fillAlpha = 1;
  5220. this.strokeAlpha = 1;
  5221. this.lineWidth = 1;
  5222. this.activeSMask = null;
  5223. this.transferMaps = null;
  5224. this.startNewPathAndClipBox([0, 0, width, height]);
  5225. }
  5226. clone() {
  5227. const clone = Object.create(this);
  5228. clone.clipBox = this.clipBox.slice();
  5229. return clone;
  5230. }
  5231. setCurrentPoint(x, y) {
  5232. this.x = x;
  5233. this.y = y;
  5234. }
  5235. updatePathMinMax(transform, x, y) {
  5236. [x, y] = _util.Util.applyTransform([x, y], transform);
  5237. this.minX = Math.min(this.minX, x);
  5238. this.minY = Math.min(this.minY, y);
  5239. this.maxX = Math.max(this.maxX, x);
  5240. this.maxY = Math.max(this.maxY, y);
  5241. }
  5242. updateRectMinMax(transform, rect) {
  5243. const p1 = _util.Util.applyTransform(rect, transform);
  5244. const p2 = _util.Util.applyTransform(rect.slice(2), transform);
  5245. this.minX = Math.min(this.minX, p1[0], p2[0]);
  5246. this.minY = Math.min(this.minY, p1[1], p2[1]);
  5247. this.maxX = Math.max(this.maxX, p1[0], p2[0]);
  5248. this.maxY = Math.max(this.maxY, p1[1], p2[1]);
  5249. }
  5250. updateScalingPathMinMax(transform, minMax) {
  5251. _util.Util.scaleMinMax(transform, minMax);
  5252. this.minX = Math.min(this.minX, minMax[0]);
  5253. this.maxX = Math.max(this.maxX, minMax[1]);
  5254. this.minY = Math.min(this.minY, minMax[2]);
  5255. this.maxY = Math.max(this.maxY, minMax[3]);
  5256. }
  5257. updateCurvePathMinMax(transform, x0, y0, x1, y1, x2, y2, x3, y3, minMax) {
  5258. const box = _util.Util.bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3);
  5259. if (minMax) {
  5260. minMax[0] = Math.min(minMax[0], box[0], box[2]);
  5261. minMax[1] = Math.max(minMax[1], box[0], box[2]);
  5262. minMax[2] = Math.min(minMax[2], box[1], box[3]);
  5263. minMax[3] = Math.max(minMax[3], box[1], box[3]);
  5264. return;
  5265. }
  5266. this.updateRectMinMax(transform, box);
  5267. }
  5268. getPathBoundingBox(pathType = _pattern_helper.PathType.FILL, transform = null) {
  5269. const box = [this.minX, this.minY, this.maxX, this.maxY];
  5270. if (pathType === _pattern_helper.PathType.STROKE) {
  5271. if (!transform) {
  5272. (0, _util.unreachable)("Stroke bounding box must include transform.");
  5273. }
  5274. const scale = _util.Util.singularValueDecompose2dScale(transform);
  5275. const xStrokePad = scale[0] * this.lineWidth / 2;
  5276. const yStrokePad = scale[1] * this.lineWidth / 2;
  5277. box[0] -= xStrokePad;
  5278. box[1] -= yStrokePad;
  5279. box[2] += xStrokePad;
  5280. box[3] += yStrokePad;
  5281. }
  5282. return box;
  5283. }
  5284. updateClipFromPath() {
  5285. const intersect = _util.Util.intersect(this.clipBox, this.getPathBoundingBox());
  5286. this.startNewPathAndClipBox(intersect || [0, 0, 0, 0]);
  5287. }
  5288. isEmptyClip() {
  5289. return this.minX === Infinity;
  5290. }
  5291. startNewPathAndClipBox(box) {
  5292. this.clipBox = box;
  5293. this.minX = Infinity;
  5294. this.minY = Infinity;
  5295. this.maxX = 0;
  5296. this.maxY = 0;
  5297. }
  5298. getClippedPathBoundingBox(pathType = _pattern_helper.PathType.FILL, transform = null) {
  5299. return _util.Util.intersect(this.clipBox, this.getPathBoundingBox(pathType, transform));
  5300. }
  5301. }
  5302. function putBinaryImageData(ctx, imgData, transferMaps = null) {
  5303. if (typeof ImageData !== "undefined" && imgData instanceof ImageData) {
  5304. ctx.putImageData(imgData, 0, 0);
  5305. return;
  5306. }
  5307. const height = imgData.height,
  5308. width = imgData.width;
  5309. const partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  5310. const fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  5311. const totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  5312. const chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  5313. let srcPos = 0,
  5314. destPos;
  5315. const src = imgData.data;
  5316. const dest = chunkImgData.data;
  5317. let i, j, thisChunkHeight, elemsInThisChunk;
  5318. let transferMapRed, transferMapGreen, transferMapBlue, transferMapGray;
  5319. if (transferMaps) {
  5320. switch (transferMaps.length) {
  5321. case 1:
  5322. transferMapRed = transferMaps[0];
  5323. transferMapGreen = transferMaps[0];
  5324. transferMapBlue = transferMaps[0];
  5325. transferMapGray = transferMaps[0];
  5326. break;
  5327. case 4:
  5328. transferMapRed = transferMaps[0];
  5329. transferMapGreen = transferMaps[1];
  5330. transferMapBlue = transferMaps[2];
  5331. transferMapGray = transferMaps[3];
  5332. break;
  5333. }
  5334. }
  5335. if (imgData.kind === _util.ImageKind.GRAYSCALE_1BPP) {
  5336. const srcLength = src.byteLength;
  5337. const dest32 = new Uint32Array(dest.buffer, 0, dest.byteLength >> 2);
  5338. const dest32DataLength = dest32.length;
  5339. const fullSrcDiff = width + 7 >> 3;
  5340. let white = 0xffffffff;
  5341. let black = _util.FeatureTest.isLittleEndian ? 0xff000000 : 0x000000ff;
  5342. if (transferMapGray) {
  5343. if (transferMapGray[0] === 0xff && transferMapGray[0xff] === 0) {
  5344. [white, black] = [black, white];
  5345. }
  5346. }
  5347. for (i = 0; i < totalChunks; i++) {
  5348. thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  5349. destPos = 0;
  5350. for (j = 0; j < thisChunkHeight; j++) {
  5351. const srcDiff = srcLength - srcPos;
  5352. let k = 0;
  5353. const kEnd = srcDiff > fullSrcDiff ? width : srcDiff * 8 - 7;
  5354. const kEndUnrolled = kEnd & ~7;
  5355. let mask = 0;
  5356. let srcByte = 0;
  5357. for (; k < kEndUnrolled; k += 8) {
  5358. srcByte = src[srcPos++];
  5359. dest32[destPos++] = srcByte & 128 ? white : black;
  5360. dest32[destPos++] = srcByte & 64 ? white : black;
  5361. dest32[destPos++] = srcByte & 32 ? white : black;
  5362. dest32[destPos++] = srcByte & 16 ? white : black;
  5363. dest32[destPos++] = srcByte & 8 ? white : black;
  5364. dest32[destPos++] = srcByte & 4 ? white : black;
  5365. dest32[destPos++] = srcByte & 2 ? white : black;
  5366. dest32[destPos++] = srcByte & 1 ? white : black;
  5367. }
  5368. for (; k < kEnd; k++) {
  5369. if (mask === 0) {
  5370. srcByte = src[srcPos++];
  5371. mask = 128;
  5372. }
  5373. dest32[destPos++] = srcByte & mask ? white : black;
  5374. mask >>= 1;
  5375. }
  5376. }
  5377. while (destPos < dest32DataLength) {
  5378. dest32[destPos++] = 0;
  5379. }
  5380. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  5381. }
  5382. } else if (imgData.kind === _util.ImageKind.RGBA_32BPP) {
  5383. const hasTransferMaps = !!(transferMapRed || transferMapGreen || transferMapBlue);
  5384. j = 0;
  5385. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  5386. for (i = 0; i < fullChunks; i++) {
  5387. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  5388. srcPos += elemsInThisChunk;
  5389. if (hasTransferMaps) {
  5390. for (let k = 0; k < elemsInThisChunk; k += 4) {
  5391. if (transferMapRed) {
  5392. dest[k + 0] = transferMapRed[dest[k + 0]];
  5393. }
  5394. if (transferMapGreen) {
  5395. dest[k + 1] = transferMapGreen[dest[k + 1]];
  5396. }
  5397. if (transferMapBlue) {
  5398. dest[k + 2] = transferMapBlue[dest[k + 2]];
  5399. }
  5400. }
  5401. }
  5402. ctx.putImageData(chunkImgData, 0, j);
  5403. j += FULL_CHUNK_HEIGHT;
  5404. }
  5405. if (i < totalChunks) {
  5406. elemsInThisChunk = width * partialChunkHeight * 4;
  5407. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  5408. if (hasTransferMaps) {
  5409. for (let k = 0; k < elemsInThisChunk; k += 4) {
  5410. if (transferMapRed) {
  5411. dest[k + 0] = transferMapRed[dest[k + 0]];
  5412. }
  5413. if (transferMapGreen) {
  5414. dest[k + 1] = transferMapGreen[dest[k + 1]];
  5415. }
  5416. if (transferMapBlue) {
  5417. dest[k + 2] = transferMapBlue[dest[k + 2]];
  5418. }
  5419. }
  5420. }
  5421. ctx.putImageData(chunkImgData, 0, j);
  5422. }
  5423. } else if (imgData.kind === _util.ImageKind.RGB_24BPP) {
  5424. const hasTransferMaps = !!(transferMapRed || transferMapGreen || transferMapBlue);
  5425. thisChunkHeight = FULL_CHUNK_HEIGHT;
  5426. elemsInThisChunk = width * thisChunkHeight;
  5427. for (i = 0; i < totalChunks; i++) {
  5428. if (i >= fullChunks) {
  5429. thisChunkHeight = partialChunkHeight;
  5430. elemsInThisChunk = width * thisChunkHeight;
  5431. }
  5432. destPos = 0;
  5433. for (j = elemsInThisChunk; j--;) {
  5434. dest[destPos++] = src[srcPos++];
  5435. dest[destPos++] = src[srcPos++];
  5436. dest[destPos++] = src[srcPos++];
  5437. dest[destPos++] = 255;
  5438. }
  5439. if (hasTransferMaps) {
  5440. for (let k = 0; k < destPos; k += 4) {
  5441. if (transferMapRed) {
  5442. dest[k + 0] = transferMapRed[dest[k + 0]];
  5443. }
  5444. if (transferMapGreen) {
  5445. dest[k + 1] = transferMapGreen[dest[k + 1]];
  5446. }
  5447. if (transferMapBlue) {
  5448. dest[k + 2] = transferMapBlue[dest[k + 2]];
  5449. }
  5450. }
  5451. }
  5452. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  5453. }
  5454. } else {
  5455. throw new Error(`bad image kind: ${imgData.kind}`);
  5456. }
  5457. }
  5458. function putBinaryImageMask(ctx, imgData) {
  5459. if (imgData.bitmap) {
  5460. ctx.drawImage(imgData.bitmap, 0, 0);
  5461. return;
  5462. }
  5463. const height = imgData.height,
  5464. width = imgData.width;
  5465. const partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  5466. const fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  5467. const totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  5468. const chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  5469. let srcPos = 0;
  5470. const src = imgData.data;
  5471. const dest = chunkImgData.data;
  5472. for (let i = 0; i < totalChunks; i++) {
  5473. const thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  5474. ({
  5475. srcPos
  5476. } = (0, _image_utils.applyMaskImageData)({
  5477. src,
  5478. srcPos,
  5479. dest,
  5480. width,
  5481. height: thisChunkHeight
  5482. }));
  5483. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  5484. }
  5485. }
  5486. function copyCtxState(sourceCtx, destCtx) {
  5487. const properties = ["strokeStyle", "fillStyle", "fillRule", "globalAlpha", "lineWidth", "lineCap", "lineJoin", "miterLimit", "globalCompositeOperation", "font"];
  5488. for (let i = 0, ii = properties.length; i < ii; i++) {
  5489. const property = properties[i];
  5490. if (sourceCtx[property] !== undefined) {
  5491. destCtx[property] = sourceCtx[property];
  5492. }
  5493. }
  5494. if (sourceCtx.setLineDash !== undefined) {
  5495. destCtx.setLineDash(sourceCtx.getLineDash());
  5496. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  5497. }
  5498. }
  5499. function resetCtxToDefault(ctx, foregroundColor) {
  5500. ctx.strokeStyle = ctx.fillStyle = foregroundColor || "#000000";
  5501. ctx.fillRule = "nonzero";
  5502. ctx.globalAlpha = 1;
  5503. ctx.lineWidth = 1;
  5504. ctx.lineCap = "butt";
  5505. ctx.lineJoin = "miter";
  5506. ctx.miterLimit = 10;
  5507. ctx.globalCompositeOperation = "source-over";
  5508. ctx.font = "10px sans-serif";
  5509. if (ctx.setLineDash !== undefined) {
  5510. ctx.setLineDash([]);
  5511. ctx.lineDashOffset = 0;
  5512. }
  5513. }
  5514. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  5515. const length = bytes.length;
  5516. for (let i = 3; i < length; i += 4) {
  5517. const alpha = bytes[i];
  5518. if (alpha === 0) {
  5519. bytes[i - 3] = r0;
  5520. bytes[i - 2] = g0;
  5521. bytes[i - 1] = b0;
  5522. } else if (alpha < 255) {
  5523. const alpha_ = 255 - alpha;
  5524. bytes[i - 3] = bytes[i - 3] * alpha + r0 * alpha_ >> 8;
  5525. bytes[i - 2] = bytes[i - 2] * alpha + g0 * alpha_ >> 8;
  5526. bytes[i - 1] = bytes[i - 1] * alpha + b0 * alpha_ >> 8;
  5527. }
  5528. }
  5529. }
  5530. function composeSMaskAlpha(maskData, layerData, transferMap) {
  5531. const length = maskData.length;
  5532. const scale = 1 / 255;
  5533. for (let i = 3; i < length; i += 4) {
  5534. const alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
  5535. layerData[i] = layerData[i] * alpha * scale | 0;
  5536. }
  5537. }
  5538. function composeSMaskLuminosity(maskData, layerData, transferMap) {
  5539. const length = maskData.length;
  5540. for (let i = 3; i < length; i += 4) {
  5541. const y = maskData[i - 3] * 77 + maskData[i - 2] * 152 + maskData[i - 1] * 28;
  5542. layerData[i] = transferMap ? layerData[i] * transferMap[y >> 8] >> 8 : layerData[i] * y >> 16;
  5543. }
  5544. }
  5545. function genericComposeSMask(maskCtx, layerCtx, width, height, subtype, backdrop, transferMap, layerOffsetX, layerOffsetY, maskOffsetX, maskOffsetY) {
  5546. const hasBackdrop = !!backdrop;
  5547. const r0 = hasBackdrop ? backdrop[0] : 0;
  5548. const g0 = hasBackdrop ? backdrop[1] : 0;
  5549. const b0 = hasBackdrop ? backdrop[2] : 0;
  5550. let composeFn;
  5551. if (subtype === "Luminosity") {
  5552. composeFn = composeSMaskLuminosity;
  5553. } else {
  5554. composeFn = composeSMaskAlpha;
  5555. }
  5556. const PIXELS_TO_PROCESS = 1048576;
  5557. const chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  5558. for (let row = 0; row < height; row += chunkSize) {
  5559. const chunkHeight = Math.min(chunkSize, height - row);
  5560. const maskData = maskCtx.getImageData(layerOffsetX - maskOffsetX, row + (layerOffsetY - maskOffsetY), width, chunkHeight);
  5561. const layerData = layerCtx.getImageData(layerOffsetX, row + layerOffsetY, width, chunkHeight);
  5562. if (hasBackdrop) {
  5563. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  5564. }
  5565. composeFn(maskData.data, layerData.data, transferMap);
  5566. layerCtx.putImageData(layerData, layerOffsetX, row + layerOffsetY);
  5567. }
  5568. }
  5569. function composeSMask(ctx, smask, layerCtx, layerBox) {
  5570. const layerOffsetX = layerBox[0];
  5571. const layerOffsetY = layerBox[1];
  5572. const layerWidth = layerBox[2] - layerOffsetX;
  5573. const layerHeight = layerBox[3] - layerOffsetY;
  5574. if (layerWidth === 0 || layerHeight === 0) {
  5575. return;
  5576. }
  5577. genericComposeSMask(smask.context, layerCtx, layerWidth, layerHeight, smask.subtype, smask.backdrop, smask.transferMap, layerOffsetX, layerOffsetY, smask.offsetX, smask.offsetY);
  5578. ctx.save();
  5579. ctx.globalAlpha = 1;
  5580. ctx.globalCompositeOperation = "source-over";
  5581. ctx.setTransform(1, 0, 0, 1, 0, 0);
  5582. ctx.drawImage(layerCtx.canvas, 0, 0);
  5583. ctx.restore();
  5584. }
  5585. function getImageSmoothingEnabled(transform, interpolate) {
  5586. const scale = _util.Util.singularValueDecompose2dScale(transform);
  5587. scale[0] = Math.fround(scale[0]);
  5588. scale[1] = Math.fround(scale[1]);
  5589. const actualScale = Math.fround((globalThis.devicePixelRatio || 1) * _display_utils.PixelsPerInch.PDF_TO_CSS_UNITS);
  5590. if (interpolate !== undefined) {
  5591. return interpolate;
  5592. } else if (scale[0] <= actualScale || scale[1] <= actualScale) {
  5593. return true;
  5594. }
  5595. return false;
  5596. }
  5597. const LINE_CAP_STYLES = ["butt", "round", "square"];
  5598. const LINE_JOIN_STYLES = ["miter", "round", "bevel"];
  5599. const NORMAL_CLIP = {};
  5600. const EO_CLIP = {};
  5601. class CanvasGraphics {
  5602. constructor(canvasCtx, commonObjs, objs, canvasFactory, imageLayer, optionalContentConfig, annotationCanvasMap, pageColors) {
  5603. this.ctx = canvasCtx;
  5604. this.current = new CanvasExtraState(this.ctx.canvas.width, this.ctx.canvas.height);
  5605. this.stateStack = [];
  5606. this.pendingClip = null;
  5607. this.pendingEOFill = false;
  5608. this.res = null;
  5609. this.xobjs = null;
  5610. this.commonObjs = commonObjs;
  5611. this.objs = objs;
  5612. this.canvasFactory = canvasFactory;
  5613. this.imageLayer = imageLayer;
  5614. this.groupStack = [];
  5615. this.processingType3 = null;
  5616. this.baseTransform = null;
  5617. this.baseTransformStack = [];
  5618. this.groupLevel = 0;
  5619. this.smaskStack = [];
  5620. this.smaskCounter = 0;
  5621. this.tempSMask = null;
  5622. this.suspendedCtx = null;
  5623. this.contentVisible = true;
  5624. this.markedContentStack = [];
  5625. this.optionalContentConfig = optionalContentConfig;
  5626. this.cachedCanvases = new CachedCanvases(this.canvasFactory);
  5627. this.cachedPatterns = new Map();
  5628. this.annotationCanvasMap = annotationCanvasMap;
  5629. this.viewportScale = 1;
  5630. this.outputScaleX = 1;
  5631. this.outputScaleY = 1;
  5632. this.backgroundColor = pageColors?.background || null;
  5633. this.foregroundColor = pageColors?.foreground || null;
  5634. this._cachedScaleForStroking = null;
  5635. this._cachedGetSinglePixelWidth = null;
  5636. this._cachedBitmapsMap = new Map();
  5637. }
  5638. getObject(data, fallback = null) {
  5639. if (typeof data === "string") {
  5640. return data.startsWith("g_") ? this.commonObjs.get(data) : this.objs.get(data);
  5641. }
  5642. return fallback;
  5643. }
  5644. beginDrawing({
  5645. transform,
  5646. viewport,
  5647. transparency = false,
  5648. background = null
  5649. }) {
  5650. const width = this.ctx.canvas.width;
  5651. const height = this.ctx.canvas.height;
  5652. const defaultBackgroundColor = background || "#ffffff";
  5653. this.ctx.save();
  5654. if (this.foregroundColor && this.backgroundColor) {
  5655. this.ctx.fillStyle = this.foregroundColor;
  5656. const fg = this.foregroundColor = this.ctx.fillStyle;
  5657. this.ctx.fillStyle = this.backgroundColor;
  5658. const bg = this.backgroundColor = this.ctx.fillStyle;
  5659. let isValidDefaultBg = true;
  5660. let defaultBg = defaultBackgroundColor;
  5661. this.ctx.fillStyle = defaultBackgroundColor;
  5662. defaultBg = this.ctx.fillStyle;
  5663. isValidDefaultBg = typeof defaultBg === "string" && /^#[0-9A-Fa-f]{6}$/.test(defaultBg);
  5664. if (fg === "#000000" && bg === "#ffffff" || fg === bg || !isValidDefaultBg) {
  5665. this.foregroundColor = this.backgroundColor = null;
  5666. } else {
  5667. const [rB, gB, bB] = (0, _display_utils.getRGB)(defaultBg);
  5668. const newComp = x => {
  5669. x /= 255;
  5670. return x <= 0.03928 ? x / 12.92 : ((x + 0.055) / 1.055) ** 2.4;
  5671. };
  5672. const lumB = Math.round(0.2126 * newComp(rB) + 0.7152 * newComp(gB) + 0.0722 * newComp(bB));
  5673. this.selectColor = (r, g, b) => {
  5674. const lumC = 0.2126 * newComp(r) + 0.7152 * newComp(g) + 0.0722 * newComp(b);
  5675. return Math.round(lumC) === lumB ? bg : fg;
  5676. };
  5677. }
  5678. }
  5679. this.ctx.fillStyle = this.backgroundColor || defaultBackgroundColor;
  5680. this.ctx.fillRect(0, 0, width, height);
  5681. this.ctx.restore();
  5682. if (transparency) {
  5683. const transparentCanvas = this.cachedCanvases.getCanvas("transparent", width, height);
  5684. this.compositeCtx = this.ctx;
  5685. this.transparentCanvas = transparentCanvas.canvas;
  5686. this.ctx = transparentCanvas.context;
  5687. this.ctx.save();
  5688. this.ctx.transform(...(0, _display_utils.getCurrentTransform)(this.compositeCtx));
  5689. }
  5690. this.ctx.save();
  5691. resetCtxToDefault(this.ctx, this.foregroundColor);
  5692. if (transform) {
  5693. this.ctx.transform(...transform);
  5694. this.outputScaleX = transform[0];
  5695. this.outputScaleY = transform[0];
  5696. }
  5697. this.ctx.transform(...viewport.transform);
  5698. this.viewportScale = viewport.scale;
  5699. this.baseTransform = (0, _display_utils.getCurrentTransform)(this.ctx);
  5700. if (this.imageLayer) {
  5701. (0, _display_utils.deprecated)("The `imageLayer` functionality will be removed in the future.");
  5702. this.imageLayer.beginLayout();
  5703. }
  5704. }
  5705. executeOperatorList(operatorList, executionStartIdx, continueCallback, stepper) {
  5706. const argsArray = operatorList.argsArray;
  5707. const fnArray = operatorList.fnArray;
  5708. let i = executionStartIdx || 0;
  5709. const argsArrayLen = argsArray.length;
  5710. if (argsArrayLen === i) {
  5711. return i;
  5712. }
  5713. const chunkOperations = argsArrayLen - i > EXECUTION_STEPS && typeof continueCallback === "function";
  5714. const endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  5715. let steps = 0;
  5716. const commonObjs = this.commonObjs;
  5717. const objs = this.objs;
  5718. let fnId;
  5719. while (true) {
  5720. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  5721. stepper.breakIt(i, continueCallback);
  5722. return i;
  5723. }
  5724. fnId = fnArray[i];
  5725. if (fnId !== _util.OPS.dependency) {
  5726. this[fnId].apply(this, argsArray[i]);
  5727. } else {
  5728. for (const depObjId of argsArray[i]) {
  5729. const objsPool = depObjId.startsWith("g_") ? commonObjs : objs;
  5730. if (!objsPool.has(depObjId)) {
  5731. objsPool.get(depObjId, continueCallback);
  5732. return i;
  5733. }
  5734. }
  5735. }
  5736. i++;
  5737. if (i === argsArrayLen) {
  5738. return i;
  5739. }
  5740. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  5741. if (Date.now() > endTime) {
  5742. continueCallback();
  5743. return i;
  5744. }
  5745. steps = 0;
  5746. }
  5747. }
  5748. }
  5749. #restoreInitialState() {
  5750. while (this.stateStack.length || this.inSMaskMode) {
  5751. this.restore();
  5752. }
  5753. this.ctx.restore();
  5754. if (this.transparentCanvas) {
  5755. this.ctx = this.compositeCtx;
  5756. this.ctx.save();
  5757. this.ctx.setTransform(1, 0, 0, 1, 0, 0);
  5758. this.ctx.drawImage(this.transparentCanvas, 0, 0);
  5759. this.ctx.restore();
  5760. this.transparentCanvas = null;
  5761. }
  5762. }
  5763. endDrawing() {
  5764. this.#restoreInitialState();
  5765. this.cachedCanvases.clear();
  5766. this.cachedPatterns.clear();
  5767. for (const cache of this._cachedBitmapsMap.values()) {
  5768. for (const canvas of cache.values()) {
  5769. if (typeof HTMLCanvasElement !== "undefined" && canvas instanceof HTMLCanvasElement) {
  5770. canvas.width = canvas.height = 0;
  5771. }
  5772. }
  5773. cache.clear();
  5774. }
  5775. this._cachedBitmapsMap.clear();
  5776. if (this.imageLayer) {
  5777. this.imageLayer.endLayout();
  5778. }
  5779. }
  5780. _scaleImage(img, inverseTransform) {
  5781. const width = img.width;
  5782. const height = img.height;
  5783. let widthScale = Math.max(Math.hypot(inverseTransform[0], inverseTransform[1]), 1);
  5784. let heightScale = Math.max(Math.hypot(inverseTransform[2], inverseTransform[3]), 1);
  5785. let paintWidth = width,
  5786. paintHeight = height;
  5787. let tmpCanvasId = "prescale1";
  5788. let tmpCanvas, tmpCtx;
  5789. while (widthScale > 2 && paintWidth > 1 || heightScale > 2 && paintHeight > 1) {
  5790. let newWidth = paintWidth,
  5791. newHeight = paintHeight;
  5792. if (widthScale > 2 && paintWidth > 1) {
  5793. newWidth = Math.ceil(paintWidth / 2);
  5794. widthScale /= paintWidth / newWidth;
  5795. }
  5796. if (heightScale > 2 && paintHeight > 1) {
  5797. newHeight = Math.ceil(paintHeight / 2);
  5798. heightScale /= paintHeight / newHeight;
  5799. }
  5800. tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
  5801. tmpCtx = tmpCanvas.context;
  5802. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  5803. tmpCtx.drawImage(img, 0, 0, paintWidth, paintHeight, 0, 0, newWidth, newHeight);
  5804. img = tmpCanvas.canvas;
  5805. paintWidth = newWidth;
  5806. paintHeight = newHeight;
  5807. tmpCanvasId = tmpCanvasId === "prescale1" ? "prescale2" : "prescale1";
  5808. }
  5809. return {
  5810. img,
  5811. paintWidth,
  5812. paintHeight
  5813. };
  5814. }
  5815. _createMaskCanvas(img) {
  5816. const ctx = this.ctx;
  5817. const {
  5818. width,
  5819. height
  5820. } = img;
  5821. const fillColor = this.current.fillColor;
  5822. const isPatternFill = this.current.patternFill;
  5823. const currentTransform = (0, _display_utils.getCurrentTransform)(ctx);
  5824. let cache, cacheKey, scaled, maskCanvas;
  5825. if ((img.bitmap || img.data) && img.count > 1) {
  5826. const mainKey = img.bitmap || img.data.buffer;
  5827. const withoutTranslation = currentTransform.slice(0, 4);
  5828. cacheKey = JSON.stringify(isPatternFill ? withoutTranslation : [withoutTranslation, fillColor]);
  5829. cache = this._cachedBitmapsMap.get(mainKey);
  5830. if (!cache) {
  5831. cache = new Map();
  5832. this._cachedBitmapsMap.set(mainKey, cache);
  5833. }
  5834. const cachedImage = cache.get(cacheKey);
  5835. if (cachedImage && !isPatternFill) {
  5836. const offsetX = Math.round(Math.min(currentTransform[0], currentTransform[2]) + currentTransform[4]);
  5837. const offsetY = Math.round(Math.min(currentTransform[1], currentTransform[3]) + currentTransform[5]);
  5838. return {
  5839. canvas: cachedImage,
  5840. offsetX,
  5841. offsetY
  5842. };
  5843. }
  5844. scaled = cachedImage;
  5845. }
  5846. if (!scaled) {
  5847. maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
  5848. putBinaryImageMask(maskCanvas.context, img);
  5849. }
  5850. let maskToCanvas = _util.Util.transform(currentTransform, [1 / width, 0, 0, -1 / height, 0, 0]);
  5851. maskToCanvas = _util.Util.transform(maskToCanvas, [1, 0, 0, 1, 0, -height]);
  5852. const cord1 = _util.Util.applyTransform([0, 0], maskToCanvas);
  5853. const cord2 = _util.Util.applyTransform([width, height], maskToCanvas);
  5854. const rect = _util.Util.normalizeRect([cord1[0], cord1[1], cord2[0], cord2[1]]);
  5855. const drawnWidth = Math.round(rect[2] - rect[0]) || 1;
  5856. const drawnHeight = Math.round(rect[3] - rect[1]) || 1;
  5857. const fillCanvas = this.cachedCanvases.getCanvas("fillCanvas", drawnWidth, drawnHeight);
  5858. const fillCtx = fillCanvas.context;
  5859. const offsetX = Math.min(cord1[0], cord2[0]);
  5860. const offsetY = Math.min(cord1[1], cord2[1]);
  5861. fillCtx.translate(-offsetX, -offsetY);
  5862. fillCtx.transform(...maskToCanvas);
  5863. if (!scaled) {
  5864. scaled = this._scaleImage(maskCanvas.canvas, (0, _display_utils.getCurrentTransformInverse)(fillCtx));
  5865. scaled = scaled.img;
  5866. if (cache && isPatternFill) {
  5867. cache.set(cacheKey, scaled);
  5868. }
  5869. }
  5870. fillCtx.imageSmoothingEnabled = getImageSmoothingEnabled((0, _display_utils.getCurrentTransform)(fillCtx), img.interpolate);
  5871. drawImageAtIntegerCoords(fillCtx, scaled, 0, 0, scaled.width, scaled.height, 0, 0, width, height);
  5872. fillCtx.globalCompositeOperation = "source-in";
  5873. const inverse = _util.Util.transform((0, _display_utils.getCurrentTransformInverse)(fillCtx), [1, 0, 0, 1, -offsetX, -offsetY]);
  5874. fillCtx.fillStyle = isPatternFill ? fillColor.getPattern(ctx, this, inverse, _pattern_helper.PathType.FILL) : fillColor;
  5875. fillCtx.fillRect(0, 0, width, height);
  5876. if (cache && !isPatternFill) {
  5877. this.cachedCanvases.delete("fillCanvas");
  5878. cache.set(cacheKey, fillCanvas.canvas);
  5879. }
  5880. return {
  5881. canvas: fillCanvas.canvas,
  5882. offsetX: Math.round(offsetX),
  5883. offsetY: Math.round(offsetY)
  5884. };
  5885. }
  5886. setLineWidth(width) {
  5887. if (width !== this.current.lineWidth) {
  5888. this._cachedScaleForStroking = null;
  5889. }
  5890. this.current.lineWidth = width;
  5891. this.ctx.lineWidth = width;
  5892. }
  5893. setLineCap(style) {
  5894. this.ctx.lineCap = LINE_CAP_STYLES[style];
  5895. }
  5896. setLineJoin(style) {
  5897. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  5898. }
  5899. setMiterLimit(limit) {
  5900. this.ctx.miterLimit = limit;
  5901. }
  5902. setDash(dashArray, dashPhase) {
  5903. const ctx = this.ctx;
  5904. if (ctx.setLineDash !== undefined) {
  5905. ctx.setLineDash(dashArray);
  5906. ctx.lineDashOffset = dashPhase;
  5907. }
  5908. }
  5909. setRenderingIntent(intent) {}
  5910. setFlatness(flatness) {}
  5911. setGState(states) {
  5912. for (let i = 0, ii = states.length; i < ii; i++) {
  5913. const state = states[i];
  5914. const key = state[0];
  5915. const value = state[1];
  5916. switch (key) {
  5917. case "LW":
  5918. this.setLineWidth(value);
  5919. break;
  5920. case "LC":
  5921. this.setLineCap(value);
  5922. break;
  5923. case "LJ":
  5924. this.setLineJoin(value);
  5925. break;
  5926. case "ML":
  5927. this.setMiterLimit(value);
  5928. break;
  5929. case "D":
  5930. this.setDash(value[0], value[1]);
  5931. break;
  5932. case "RI":
  5933. this.setRenderingIntent(value);
  5934. break;
  5935. case "FL":
  5936. this.setFlatness(value);
  5937. break;
  5938. case "Font":
  5939. this.setFont(value[0], value[1]);
  5940. break;
  5941. case "CA":
  5942. this.current.strokeAlpha = state[1];
  5943. break;
  5944. case "ca":
  5945. this.current.fillAlpha = state[1];
  5946. this.ctx.globalAlpha = state[1];
  5947. break;
  5948. case "BM":
  5949. this.ctx.globalCompositeOperation = value;
  5950. break;
  5951. case "SMask":
  5952. this.current.activeSMask = value ? this.tempSMask : null;
  5953. this.tempSMask = null;
  5954. this.checkSMaskState();
  5955. break;
  5956. case "TR":
  5957. this.current.transferMaps = value;
  5958. }
  5959. }
  5960. }
  5961. get inSMaskMode() {
  5962. return !!this.suspendedCtx;
  5963. }
  5964. checkSMaskState() {
  5965. const inSMaskMode = this.inSMaskMode;
  5966. if (this.current.activeSMask && !inSMaskMode) {
  5967. this.beginSMaskMode();
  5968. } else if (!this.current.activeSMask && inSMaskMode) {
  5969. this.endSMaskMode();
  5970. }
  5971. }
  5972. beginSMaskMode() {
  5973. if (this.inSMaskMode) {
  5974. throw new Error("beginSMaskMode called while already in smask mode");
  5975. }
  5976. const drawnWidth = this.ctx.canvas.width;
  5977. const drawnHeight = this.ctx.canvas.height;
  5978. const cacheId = "smaskGroupAt" + this.groupLevel;
  5979. const scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight);
  5980. this.suspendedCtx = this.ctx;
  5981. this.ctx = scratchCanvas.context;
  5982. const ctx = this.ctx;
  5983. ctx.setTransform(...(0, _display_utils.getCurrentTransform)(this.suspendedCtx));
  5984. copyCtxState(this.suspendedCtx, ctx);
  5985. mirrorContextOperations(ctx, this.suspendedCtx);
  5986. this.setGState([["BM", "source-over"], ["ca", 1], ["CA", 1]]);
  5987. }
  5988. endSMaskMode() {
  5989. if (!this.inSMaskMode) {
  5990. throw new Error("endSMaskMode called while not in smask mode");
  5991. }
  5992. this.ctx._removeMirroring();
  5993. copyCtxState(this.ctx, this.suspendedCtx);
  5994. this.ctx = this.suspendedCtx;
  5995. this.suspendedCtx = null;
  5996. }
  5997. compose(dirtyBox) {
  5998. if (!this.current.activeSMask) {
  5999. return;
  6000. }
  6001. if (!dirtyBox) {
  6002. dirtyBox = [0, 0, this.ctx.canvas.width, this.ctx.canvas.height];
  6003. } else {
  6004. dirtyBox[0] = Math.floor(dirtyBox[0]);
  6005. dirtyBox[1] = Math.floor(dirtyBox[1]);
  6006. dirtyBox[2] = Math.ceil(dirtyBox[2]);
  6007. dirtyBox[3] = Math.ceil(dirtyBox[3]);
  6008. }
  6009. const smask = this.current.activeSMask;
  6010. const suspendedCtx = this.suspendedCtx;
  6011. composeSMask(suspendedCtx, smask, this.ctx, dirtyBox);
  6012. this.ctx.save();
  6013. this.ctx.setTransform(1, 0, 0, 1, 0, 0);
  6014. this.ctx.clearRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height);
  6015. this.ctx.restore();
  6016. }
  6017. save() {
  6018. if (this.inSMaskMode) {
  6019. copyCtxState(this.ctx, this.suspendedCtx);
  6020. this.suspendedCtx.save();
  6021. } else {
  6022. this.ctx.save();
  6023. }
  6024. const old = this.current;
  6025. this.stateStack.push(old);
  6026. this.current = old.clone();
  6027. }
  6028. restore() {
  6029. if (this.stateStack.length === 0 && this.inSMaskMode) {
  6030. this.endSMaskMode();
  6031. }
  6032. if (this.stateStack.length !== 0) {
  6033. this.current = this.stateStack.pop();
  6034. if (this.inSMaskMode) {
  6035. this.suspendedCtx.restore();
  6036. copyCtxState(this.suspendedCtx, this.ctx);
  6037. } else {
  6038. this.ctx.restore();
  6039. }
  6040. this.checkSMaskState();
  6041. this.pendingClip = null;
  6042. this._cachedScaleForStroking = null;
  6043. this._cachedGetSinglePixelWidth = null;
  6044. }
  6045. }
  6046. transform(a, b, c, d, e, f) {
  6047. this.ctx.transform(a, b, c, d, e, f);
  6048. this._cachedScaleForStroking = null;
  6049. this._cachedGetSinglePixelWidth = null;
  6050. }
  6051. constructPath(ops, args, minMax) {
  6052. const ctx = this.ctx;
  6053. const current = this.current;
  6054. let x = current.x,
  6055. y = current.y;
  6056. let startX, startY;
  6057. const currentTransform = (0, _display_utils.getCurrentTransform)(ctx);
  6058. const isScalingMatrix = currentTransform[0] === 0 && currentTransform[3] === 0 || currentTransform[1] === 0 && currentTransform[2] === 0;
  6059. const minMaxForBezier = isScalingMatrix ? minMax.slice(0) : null;
  6060. for (let i = 0, j = 0, ii = ops.length; i < ii; i++) {
  6061. switch (ops[i] | 0) {
  6062. case _util.OPS.rectangle:
  6063. x = args[j++];
  6064. y = args[j++];
  6065. const width = args[j++];
  6066. const height = args[j++];
  6067. const xw = x + width;
  6068. const yh = y + height;
  6069. ctx.moveTo(x, y);
  6070. if (width === 0 || height === 0) {
  6071. ctx.lineTo(xw, yh);
  6072. } else {
  6073. ctx.lineTo(xw, y);
  6074. ctx.lineTo(xw, yh);
  6075. ctx.lineTo(x, yh);
  6076. }
  6077. if (!isScalingMatrix) {
  6078. current.updateRectMinMax(currentTransform, [x, y, xw, yh]);
  6079. }
  6080. ctx.closePath();
  6081. break;
  6082. case _util.OPS.moveTo:
  6083. x = args[j++];
  6084. y = args[j++];
  6085. ctx.moveTo(x, y);
  6086. if (!isScalingMatrix) {
  6087. current.updatePathMinMax(currentTransform, x, y);
  6088. }
  6089. break;
  6090. case _util.OPS.lineTo:
  6091. x = args[j++];
  6092. y = args[j++];
  6093. ctx.lineTo(x, y);
  6094. if (!isScalingMatrix) {
  6095. current.updatePathMinMax(currentTransform, x, y);
  6096. }
  6097. break;
  6098. case _util.OPS.curveTo:
  6099. startX = x;
  6100. startY = y;
  6101. x = args[j + 4];
  6102. y = args[j + 5];
  6103. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3], x, y);
  6104. current.updateCurvePathMinMax(currentTransform, startX, startY, args[j], args[j + 1], args[j + 2], args[j + 3], x, y, minMaxForBezier);
  6105. j += 6;
  6106. break;
  6107. case _util.OPS.curveTo2:
  6108. startX = x;
  6109. startY = y;
  6110. ctx.bezierCurveTo(x, y, args[j], args[j + 1], args[j + 2], args[j + 3]);
  6111. current.updateCurvePathMinMax(currentTransform, startX, startY, x, y, args[j], args[j + 1], args[j + 2], args[j + 3], minMaxForBezier);
  6112. x = args[j + 2];
  6113. y = args[j + 3];
  6114. j += 4;
  6115. break;
  6116. case _util.OPS.curveTo3:
  6117. startX = x;
  6118. startY = y;
  6119. x = args[j + 2];
  6120. y = args[j + 3];
  6121. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  6122. current.updateCurvePathMinMax(currentTransform, startX, startY, args[j], args[j + 1], x, y, x, y, minMaxForBezier);
  6123. j += 4;
  6124. break;
  6125. case _util.OPS.closePath:
  6126. ctx.closePath();
  6127. break;
  6128. }
  6129. }
  6130. if (isScalingMatrix) {
  6131. current.updateScalingPathMinMax(currentTransform, minMaxForBezier);
  6132. }
  6133. current.setCurrentPoint(x, y);
  6134. }
  6135. closePath() {
  6136. this.ctx.closePath();
  6137. }
  6138. stroke(consumePath) {
  6139. consumePath = typeof consumePath !== "undefined" ? consumePath : true;
  6140. const ctx = this.ctx;
  6141. const strokeColor = this.current.strokeColor;
  6142. ctx.globalAlpha = this.current.strokeAlpha;
  6143. if (this.contentVisible) {
  6144. if (typeof strokeColor === "object" && strokeColor?.getPattern) {
  6145. ctx.save();
  6146. ctx.strokeStyle = strokeColor.getPattern(ctx, this, (0, _display_utils.getCurrentTransformInverse)(ctx), _pattern_helper.PathType.STROKE);
  6147. this.rescaleAndStroke(false);
  6148. ctx.restore();
  6149. } else {
  6150. this.rescaleAndStroke(true);
  6151. }
  6152. }
  6153. if (consumePath) {
  6154. this.consumePath(this.current.getClippedPathBoundingBox());
  6155. }
  6156. ctx.globalAlpha = this.current.fillAlpha;
  6157. }
  6158. closeStroke() {
  6159. this.closePath();
  6160. this.stroke();
  6161. }
  6162. fill(consumePath) {
  6163. consumePath = typeof consumePath !== "undefined" ? consumePath : true;
  6164. const ctx = this.ctx;
  6165. const fillColor = this.current.fillColor;
  6166. const isPatternFill = this.current.patternFill;
  6167. let needRestore = false;
  6168. if (isPatternFill) {
  6169. ctx.save();
  6170. ctx.fillStyle = fillColor.getPattern(ctx, this, (0, _display_utils.getCurrentTransformInverse)(ctx), _pattern_helper.PathType.FILL);
  6171. needRestore = true;
  6172. }
  6173. const intersect = this.current.getClippedPathBoundingBox();
  6174. if (this.contentVisible && intersect !== null) {
  6175. if (this.pendingEOFill) {
  6176. ctx.fill("evenodd");
  6177. this.pendingEOFill = false;
  6178. } else {
  6179. ctx.fill();
  6180. }
  6181. }
  6182. if (needRestore) {
  6183. ctx.restore();
  6184. }
  6185. if (consumePath) {
  6186. this.consumePath(intersect);
  6187. }
  6188. }
  6189. eoFill() {
  6190. this.pendingEOFill = true;
  6191. this.fill();
  6192. }
  6193. fillStroke() {
  6194. this.fill(false);
  6195. this.stroke(false);
  6196. this.consumePath();
  6197. }
  6198. eoFillStroke() {
  6199. this.pendingEOFill = true;
  6200. this.fillStroke();
  6201. }
  6202. closeFillStroke() {
  6203. this.closePath();
  6204. this.fillStroke();
  6205. }
  6206. closeEOFillStroke() {
  6207. this.pendingEOFill = true;
  6208. this.closePath();
  6209. this.fillStroke();
  6210. }
  6211. endPath() {
  6212. this.consumePath();
  6213. }
  6214. clip() {
  6215. this.pendingClip = NORMAL_CLIP;
  6216. }
  6217. eoClip() {
  6218. this.pendingClip = EO_CLIP;
  6219. }
  6220. beginText() {
  6221. this.current.textMatrix = _util.IDENTITY_MATRIX;
  6222. this.current.textMatrixScale = 1;
  6223. this.current.x = this.current.lineX = 0;
  6224. this.current.y = this.current.lineY = 0;
  6225. }
  6226. endText() {
  6227. const paths = this.pendingTextPaths;
  6228. const ctx = this.ctx;
  6229. if (paths === undefined) {
  6230. ctx.beginPath();
  6231. return;
  6232. }
  6233. ctx.save();
  6234. ctx.beginPath();
  6235. for (const path of paths) {
  6236. ctx.setTransform(...path.transform);
  6237. ctx.translate(path.x, path.y);
  6238. path.addToPath(ctx, path.fontSize);
  6239. }
  6240. ctx.restore();
  6241. ctx.clip();
  6242. ctx.beginPath();
  6243. delete this.pendingTextPaths;
  6244. }
  6245. setCharSpacing(spacing) {
  6246. this.current.charSpacing = spacing;
  6247. }
  6248. setWordSpacing(spacing) {
  6249. this.current.wordSpacing = spacing;
  6250. }
  6251. setHScale(scale) {
  6252. this.current.textHScale = scale / 100;
  6253. }
  6254. setLeading(leading) {
  6255. this.current.leading = -leading;
  6256. }
  6257. setFont(fontRefName, size) {
  6258. const fontObj = this.commonObjs.get(fontRefName);
  6259. const current = this.current;
  6260. if (!fontObj) {
  6261. throw new Error(`Can't find font for ${fontRefName}`);
  6262. }
  6263. current.fontMatrix = fontObj.fontMatrix || _util.FONT_IDENTITY_MATRIX;
  6264. if (current.fontMatrix[0] === 0 || current.fontMatrix[3] === 0) {
  6265. (0, _util.warn)("Invalid font matrix for font " + fontRefName);
  6266. }
  6267. if (size < 0) {
  6268. size = -size;
  6269. current.fontDirection = -1;
  6270. } else {
  6271. current.fontDirection = 1;
  6272. }
  6273. this.current.font = fontObj;
  6274. this.current.fontSize = size;
  6275. if (fontObj.isType3Font) {
  6276. return;
  6277. }
  6278. const name = fontObj.loadedName || "sans-serif";
  6279. let bold = "normal";
  6280. if (fontObj.black) {
  6281. bold = "900";
  6282. } else if (fontObj.bold) {
  6283. bold = "bold";
  6284. }
  6285. const italic = fontObj.italic ? "italic" : "normal";
  6286. const typeface = `"${name}", ${fontObj.fallbackName}`;
  6287. let browserFontSize = size;
  6288. if (size < MIN_FONT_SIZE) {
  6289. browserFontSize = MIN_FONT_SIZE;
  6290. } else if (size > MAX_FONT_SIZE) {
  6291. browserFontSize = MAX_FONT_SIZE;
  6292. }
  6293. this.current.fontSizeScale = size / browserFontSize;
  6294. this.ctx.font = `${italic} ${bold} ${browserFontSize}px ${typeface}`;
  6295. }
  6296. setTextRenderingMode(mode) {
  6297. this.current.textRenderingMode = mode;
  6298. }
  6299. setTextRise(rise) {
  6300. this.current.textRise = rise;
  6301. }
  6302. moveText(x, y) {
  6303. this.current.x = this.current.lineX += x;
  6304. this.current.y = this.current.lineY += y;
  6305. }
  6306. setLeadingMoveText(x, y) {
  6307. this.setLeading(-y);
  6308. this.moveText(x, y);
  6309. }
  6310. setTextMatrix(a, b, c, d, e, f) {
  6311. this.current.textMatrix = [a, b, c, d, e, f];
  6312. this.current.textMatrixScale = Math.hypot(a, b);
  6313. this.current.x = this.current.lineX = 0;
  6314. this.current.y = this.current.lineY = 0;
  6315. }
  6316. nextLine() {
  6317. this.moveText(0, this.current.leading);
  6318. }
  6319. paintChar(character, x, y, patternTransform) {
  6320. const ctx = this.ctx;
  6321. const current = this.current;
  6322. const font = current.font;
  6323. const textRenderingMode = current.textRenderingMode;
  6324. const fontSize = current.fontSize / current.fontSizeScale;
  6325. const fillStrokeMode = textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  6326. const isAddToPathSet = !!(textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG);
  6327. const patternFill = current.patternFill && !font.missingFile;
  6328. let addToPath;
  6329. if (font.disableFontFace || isAddToPathSet || patternFill) {
  6330. addToPath = font.getPathGenerator(this.commonObjs, character);
  6331. }
  6332. if (font.disableFontFace || patternFill) {
  6333. ctx.save();
  6334. ctx.translate(x, y);
  6335. ctx.beginPath();
  6336. addToPath(ctx, fontSize);
  6337. if (patternTransform) {
  6338. ctx.setTransform(...patternTransform);
  6339. }
  6340. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  6341. ctx.fill();
  6342. }
  6343. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  6344. ctx.stroke();
  6345. }
  6346. ctx.restore();
  6347. } else {
  6348. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  6349. ctx.fillText(character, x, y);
  6350. }
  6351. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  6352. ctx.strokeText(character, x, y);
  6353. }
  6354. }
  6355. if (isAddToPathSet) {
  6356. const paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  6357. paths.push({
  6358. transform: (0, _display_utils.getCurrentTransform)(ctx),
  6359. x,
  6360. y,
  6361. fontSize,
  6362. addToPath
  6363. });
  6364. }
  6365. }
  6366. get isFontSubpixelAAEnabled() {
  6367. const {
  6368. context: ctx
  6369. } = this.cachedCanvases.getCanvas("isFontSubpixelAAEnabled", 10, 10);
  6370. ctx.scale(1.5, 1);
  6371. ctx.fillText("I", 0, 10);
  6372. const data = ctx.getImageData(0, 0, 10, 10).data;
  6373. let enabled = false;
  6374. for (let i = 3; i < data.length; i += 4) {
  6375. if (data[i] > 0 && data[i] < 255) {
  6376. enabled = true;
  6377. break;
  6378. }
  6379. }
  6380. return (0, _util.shadow)(this, "isFontSubpixelAAEnabled", enabled);
  6381. }
  6382. showText(glyphs) {
  6383. const current = this.current;
  6384. const font = current.font;
  6385. if (font.isType3Font) {
  6386. return this.showType3Text(glyphs);
  6387. }
  6388. const fontSize = current.fontSize;
  6389. if (fontSize === 0) {
  6390. return undefined;
  6391. }
  6392. const ctx = this.ctx;
  6393. const fontSizeScale = current.fontSizeScale;
  6394. const charSpacing = current.charSpacing;
  6395. const wordSpacing = current.wordSpacing;
  6396. const fontDirection = current.fontDirection;
  6397. const textHScale = current.textHScale * fontDirection;
  6398. const glyphsLength = glyphs.length;
  6399. const vertical = font.vertical;
  6400. const spacingDir = vertical ? 1 : -1;
  6401. const defaultVMetrics = font.defaultVMetrics;
  6402. const widthAdvanceScale = fontSize * current.fontMatrix[0];
  6403. const simpleFillText = current.textRenderingMode === _util.TextRenderingMode.FILL && !font.disableFontFace && !current.patternFill;
  6404. ctx.save();
  6405. ctx.transform(...current.textMatrix);
  6406. ctx.translate(current.x, current.y + current.textRise);
  6407. if (fontDirection > 0) {
  6408. ctx.scale(textHScale, -1);
  6409. } else {
  6410. ctx.scale(textHScale, 1);
  6411. }
  6412. let patternTransform;
  6413. if (current.patternFill) {
  6414. ctx.save();
  6415. const pattern = current.fillColor.getPattern(ctx, this, (0, _display_utils.getCurrentTransformInverse)(ctx), _pattern_helper.PathType.FILL);
  6416. patternTransform = (0, _display_utils.getCurrentTransform)(ctx);
  6417. ctx.restore();
  6418. ctx.fillStyle = pattern;
  6419. }
  6420. let lineWidth = current.lineWidth;
  6421. const scale = current.textMatrixScale;
  6422. if (scale === 0 || lineWidth === 0) {
  6423. const fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  6424. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  6425. lineWidth = this.getSinglePixelWidth();
  6426. }
  6427. } else {
  6428. lineWidth /= scale;
  6429. }
  6430. if (fontSizeScale !== 1.0) {
  6431. ctx.scale(fontSizeScale, fontSizeScale);
  6432. lineWidth /= fontSizeScale;
  6433. }
  6434. ctx.lineWidth = lineWidth;
  6435. let x = 0,
  6436. i;
  6437. for (i = 0; i < glyphsLength; ++i) {
  6438. const glyph = glyphs[i];
  6439. if (typeof glyph === "number") {
  6440. x += spacingDir * glyph * fontSize / 1000;
  6441. continue;
  6442. }
  6443. let restoreNeeded = false;
  6444. const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  6445. const character = glyph.fontChar;
  6446. const accent = glyph.accent;
  6447. let scaledX, scaledY;
  6448. let width = glyph.width;
  6449. if (vertical) {
  6450. const vmetric = glyph.vmetric || defaultVMetrics;
  6451. const vx = -(glyph.vmetric ? vmetric[1] : width * 0.5) * widthAdvanceScale;
  6452. const vy = vmetric[2] * widthAdvanceScale;
  6453. width = vmetric ? -vmetric[0] : width;
  6454. scaledX = vx / fontSizeScale;
  6455. scaledY = (x + vy) / fontSizeScale;
  6456. } else {
  6457. scaledX = x / fontSizeScale;
  6458. scaledY = 0;
  6459. }
  6460. if (font.remeasure && width > 0) {
  6461. const measuredWidth = ctx.measureText(character).width * 1000 / fontSize * fontSizeScale;
  6462. if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
  6463. const characterScaleX = width / measuredWidth;
  6464. restoreNeeded = true;
  6465. ctx.save();
  6466. ctx.scale(characterScaleX, 1);
  6467. scaledX /= characterScaleX;
  6468. } else if (width !== measuredWidth) {
  6469. scaledX += (width - measuredWidth) / 2000 * fontSize / fontSizeScale;
  6470. }
  6471. }
  6472. if (this.contentVisible && (glyph.isInFont || font.missingFile)) {
  6473. if (simpleFillText && !accent) {
  6474. ctx.fillText(character, scaledX, scaledY);
  6475. } else {
  6476. this.paintChar(character, scaledX, scaledY, patternTransform);
  6477. if (accent) {
  6478. const scaledAccentX = scaledX + fontSize * accent.offset.x / fontSizeScale;
  6479. const scaledAccentY = scaledY - fontSize * accent.offset.y / fontSizeScale;
  6480. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY, patternTransform);
  6481. }
  6482. }
  6483. }
  6484. let charWidth;
  6485. if (vertical) {
  6486. charWidth = width * widthAdvanceScale - spacing * fontDirection;
  6487. } else {
  6488. charWidth = width * widthAdvanceScale + spacing * fontDirection;
  6489. }
  6490. x += charWidth;
  6491. if (restoreNeeded) {
  6492. ctx.restore();
  6493. }
  6494. }
  6495. if (vertical) {
  6496. current.y -= x;
  6497. } else {
  6498. current.x += x * textHScale;
  6499. }
  6500. ctx.restore();
  6501. this.compose();
  6502. return undefined;
  6503. }
  6504. showType3Text(glyphs) {
  6505. const ctx = this.ctx;
  6506. const current = this.current;
  6507. const font = current.font;
  6508. const fontSize = current.fontSize;
  6509. const fontDirection = current.fontDirection;
  6510. const spacingDir = font.vertical ? 1 : -1;
  6511. const charSpacing = current.charSpacing;
  6512. const wordSpacing = current.wordSpacing;
  6513. const textHScale = current.textHScale * fontDirection;
  6514. const fontMatrix = current.fontMatrix || _util.FONT_IDENTITY_MATRIX;
  6515. const glyphsLength = glyphs.length;
  6516. const isTextInvisible = current.textRenderingMode === _util.TextRenderingMode.INVISIBLE;
  6517. let i, glyph, width, spacingLength;
  6518. if (isTextInvisible || fontSize === 0) {
  6519. return;
  6520. }
  6521. this._cachedScaleForStroking = null;
  6522. this._cachedGetSinglePixelWidth = null;
  6523. ctx.save();
  6524. ctx.transform(...current.textMatrix);
  6525. ctx.translate(current.x, current.y);
  6526. ctx.scale(textHScale, fontDirection);
  6527. for (i = 0; i < glyphsLength; ++i) {
  6528. glyph = glyphs[i];
  6529. if (typeof glyph === "number") {
  6530. spacingLength = spacingDir * glyph * fontSize / 1000;
  6531. this.ctx.translate(spacingLength, 0);
  6532. current.x += spacingLength * textHScale;
  6533. continue;
  6534. }
  6535. const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  6536. const operatorList = font.charProcOperatorList[glyph.operatorListId];
  6537. if (!operatorList) {
  6538. (0, _util.warn)(`Type3 character "${glyph.operatorListId}" is not available.`);
  6539. continue;
  6540. }
  6541. if (this.contentVisible) {
  6542. this.processingType3 = glyph;
  6543. this.save();
  6544. ctx.scale(fontSize, fontSize);
  6545. ctx.transform(...fontMatrix);
  6546. this.executeOperatorList(operatorList);
  6547. this.restore();
  6548. }
  6549. const transformed = _util.Util.applyTransform([glyph.width, 0], fontMatrix);
  6550. width = transformed[0] * fontSize + spacing;
  6551. ctx.translate(width, 0);
  6552. current.x += width * textHScale;
  6553. }
  6554. ctx.restore();
  6555. this.processingType3 = null;
  6556. }
  6557. setCharWidth(xWidth, yWidth) {}
  6558. setCharWidthAndBounds(xWidth, yWidth, llx, lly, urx, ury) {
  6559. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  6560. this.ctx.clip();
  6561. this.endPath();
  6562. }
  6563. getColorN_Pattern(IR) {
  6564. let pattern;
  6565. if (IR[0] === "TilingPattern") {
  6566. const color = IR[1];
  6567. const baseTransform = this.baseTransform || (0, _display_utils.getCurrentTransform)(this.ctx);
  6568. const canvasGraphicsFactory = {
  6569. createCanvasGraphics: ctx => {
  6570. return new CanvasGraphics(ctx, this.commonObjs, this.objs, this.canvasFactory);
  6571. }
  6572. };
  6573. pattern = new _pattern_helper.TilingPattern(IR, color, this.ctx, canvasGraphicsFactory, baseTransform);
  6574. } else {
  6575. pattern = this._getPattern(IR[1], IR[2]);
  6576. }
  6577. return pattern;
  6578. }
  6579. setStrokeColorN() {
  6580. this.current.strokeColor = this.getColorN_Pattern(arguments);
  6581. }
  6582. setFillColorN() {
  6583. this.current.fillColor = this.getColorN_Pattern(arguments);
  6584. this.current.patternFill = true;
  6585. }
  6586. setStrokeRGBColor(r, g, b) {
  6587. const color = this.selectColor?.(r, g, b) || _util.Util.makeHexColor(r, g, b);
  6588. this.ctx.strokeStyle = color;
  6589. this.current.strokeColor = color;
  6590. }
  6591. setFillRGBColor(r, g, b) {
  6592. const color = this.selectColor?.(r, g, b) || _util.Util.makeHexColor(r, g, b);
  6593. this.ctx.fillStyle = color;
  6594. this.current.fillColor = color;
  6595. this.current.patternFill = false;
  6596. }
  6597. _getPattern(objId, matrix = null) {
  6598. let pattern;
  6599. if (this.cachedPatterns.has(objId)) {
  6600. pattern = this.cachedPatterns.get(objId);
  6601. } else {
  6602. pattern = (0, _pattern_helper.getShadingPattern)(this.objs.get(objId));
  6603. this.cachedPatterns.set(objId, pattern);
  6604. }
  6605. if (matrix) {
  6606. pattern.matrix = matrix;
  6607. }
  6608. return pattern;
  6609. }
  6610. shadingFill(objId) {
  6611. if (!this.contentVisible) {
  6612. return;
  6613. }
  6614. const ctx = this.ctx;
  6615. this.save();
  6616. const pattern = this._getPattern(objId);
  6617. ctx.fillStyle = pattern.getPattern(ctx, this, (0, _display_utils.getCurrentTransformInverse)(ctx), _pattern_helper.PathType.SHADING);
  6618. const inv = (0, _display_utils.getCurrentTransformInverse)(ctx);
  6619. if (inv) {
  6620. const canvas = ctx.canvas;
  6621. const width = canvas.width;
  6622. const height = canvas.height;
  6623. const bl = _util.Util.applyTransform([0, 0], inv);
  6624. const br = _util.Util.applyTransform([0, height], inv);
  6625. const ul = _util.Util.applyTransform([width, 0], inv);
  6626. const ur = _util.Util.applyTransform([width, height], inv);
  6627. const x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  6628. const y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  6629. const x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  6630. const y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  6631. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  6632. } else {
  6633. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  6634. }
  6635. this.compose(this.current.getClippedPathBoundingBox());
  6636. this.restore();
  6637. }
  6638. beginInlineImage() {
  6639. (0, _util.unreachable)("Should not call beginInlineImage");
  6640. }
  6641. beginImageData() {
  6642. (0, _util.unreachable)("Should not call beginImageData");
  6643. }
  6644. paintFormXObjectBegin(matrix, bbox) {
  6645. if (!this.contentVisible) {
  6646. return;
  6647. }
  6648. this.save();
  6649. this.baseTransformStack.push(this.baseTransform);
  6650. if (Array.isArray(matrix) && matrix.length === 6) {
  6651. this.transform(...matrix);
  6652. }
  6653. this.baseTransform = (0, _display_utils.getCurrentTransform)(this.ctx);
  6654. if (bbox) {
  6655. const width = bbox[2] - bbox[0];
  6656. const height = bbox[3] - bbox[1];
  6657. this.ctx.rect(bbox[0], bbox[1], width, height);
  6658. this.current.updateRectMinMax((0, _display_utils.getCurrentTransform)(this.ctx), bbox);
  6659. this.clip();
  6660. this.endPath();
  6661. }
  6662. }
  6663. paintFormXObjectEnd() {
  6664. if (!this.contentVisible) {
  6665. return;
  6666. }
  6667. this.restore();
  6668. this.baseTransform = this.baseTransformStack.pop();
  6669. }
  6670. beginGroup(group) {
  6671. if (!this.contentVisible) {
  6672. return;
  6673. }
  6674. this.save();
  6675. if (this.inSMaskMode) {
  6676. this.endSMaskMode();
  6677. this.current.activeSMask = null;
  6678. }
  6679. const currentCtx = this.ctx;
  6680. if (!group.isolated) {
  6681. (0, _util.info)("TODO: Support non-isolated groups.");
  6682. }
  6683. if (group.knockout) {
  6684. (0, _util.warn)("Knockout groups not supported.");
  6685. }
  6686. const currentTransform = (0, _display_utils.getCurrentTransform)(currentCtx);
  6687. if (group.matrix) {
  6688. currentCtx.transform(...group.matrix);
  6689. }
  6690. if (!group.bbox) {
  6691. throw new Error("Bounding box is required.");
  6692. }
  6693. let bounds = _util.Util.getAxialAlignedBoundingBox(group.bbox, (0, _display_utils.getCurrentTransform)(currentCtx));
  6694. const canvasBounds = [0, 0, currentCtx.canvas.width, currentCtx.canvas.height];
  6695. bounds = _util.Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  6696. const offsetX = Math.floor(bounds[0]);
  6697. const offsetY = Math.floor(bounds[1]);
  6698. let drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  6699. let drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  6700. let scaleX = 1,
  6701. scaleY = 1;
  6702. if (drawnWidth > MAX_GROUP_SIZE) {
  6703. scaleX = drawnWidth / MAX_GROUP_SIZE;
  6704. drawnWidth = MAX_GROUP_SIZE;
  6705. }
  6706. if (drawnHeight > MAX_GROUP_SIZE) {
  6707. scaleY = drawnHeight / MAX_GROUP_SIZE;
  6708. drawnHeight = MAX_GROUP_SIZE;
  6709. }
  6710. this.current.startNewPathAndClipBox([0, 0, drawnWidth, drawnHeight]);
  6711. let cacheId = "groupAt" + this.groupLevel;
  6712. if (group.smask) {
  6713. cacheId += "_smask_" + this.smaskCounter++ % 2;
  6714. }
  6715. const scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight);
  6716. const groupCtx = scratchCanvas.context;
  6717. groupCtx.scale(1 / scaleX, 1 / scaleY);
  6718. groupCtx.translate(-offsetX, -offsetY);
  6719. groupCtx.transform(...currentTransform);
  6720. if (group.smask) {
  6721. this.smaskStack.push({
  6722. canvas: scratchCanvas.canvas,
  6723. context: groupCtx,
  6724. offsetX,
  6725. offsetY,
  6726. scaleX,
  6727. scaleY,
  6728. subtype: group.smask.subtype,
  6729. backdrop: group.smask.backdrop,
  6730. transferMap: group.smask.transferMap || null,
  6731. startTransformInverse: null
  6732. });
  6733. } else {
  6734. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  6735. currentCtx.translate(offsetX, offsetY);
  6736. currentCtx.scale(scaleX, scaleY);
  6737. currentCtx.save();
  6738. }
  6739. copyCtxState(currentCtx, groupCtx);
  6740. this.ctx = groupCtx;
  6741. this.setGState([["BM", "source-over"], ["ca", 1], ["CA", 1]]);
  6742. this.groupStack.push(currentCtx);
  6743. this.groupLevel++;
  6744. }
  6745. endGroup(group) {
  6746. if (!this.contentVisible) {
  6747. return;
  6748. }
  6749. this.groupLevel--;
  6750. const groupCtx = this.ctx;
  6751. const ctx = this.groupStack.pop();
  6752. this.ctx = ctx;
  6753. this.ctx.imageSmoothingEnabled = false;
  6754. if (group.smask) {
  6755. this.tempSMask = this.smaskStack.pop();
  6756. this.restore();
  6757. } else {
  6758. this.ctx.restore();
  6759. const currentMtx = (0, _display_utils.getCurrentTransform)(this.ctx);
  6760. this.restore();
  6761. this.ctx.save();
  6762. this.ctx.setTransform(...currentMtx);
  6763. const dirtyBox = _util.Util.getAxialAlignedBoundingBox([0, 0, groupCtx.canvas.width, groupCtx.canvas.height], currentMtx);
  6764. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  6765. this.ctx.restore();
  6766. this.compose(dirtyBox);
  6767. }
  6768. }
  6769. beginAnnotation(id, rect, transform, matrix, hasOwnCanvas) {
  6770. this.#restoreInitialState();
  6771. resetCtxToDefault(this.ctx, this.foregroundColor);
  6772. this.ctx.save();
  6773. this.save();
  6774. if (this.baseTransform) {
  6775. this.ctx.setTransform(...this.baseTransform);
  6776. }
  6777. if (Array.isArray(rect) && rect.length === 4) {
  6778. const width = rect[2] - rect[0];
  6779. const height = rect[3] - rect[1];
  6780. if (hasOwnCanvas && this.annotationCanvasMap) {
  6781. transform = transform.slice();
  6782. transform[4] -= rect[0];
  6783. transform[5] -= rect[1];
  6784. rect = rect.slice();
  6785. rect[0] = rect[1] = 0;
  6786. rect[2] = width;
  6787. rect[3] = height;
  6788. const [scaleX, scaleY] = _util.Util.singularValueDecompose2dScale((0, _display_utils.getCurrentTransform)(this.ctx));
  6789. const {
  6790. viewportScale
  6791. } = this;
  6792. const canvasWidth = Math.ceil(width * this.outputScaleX * viewportScale);
  6793. const canvasHeight = Math.ceil(height * this.outputScaleY * viewportScale);
  6794. this.annotationCanvas = this.canvasFactory.create(canvasWidth, canvasHeight);
  6795. const {
  6796. canvas,
  6797. context
  6798. } = this.annotationCanvas;
  6799. this.annotationCanvasMap.set(id, canvas);
  6800. this.annotationCanvas.savedCtx = this.ctx;
  6801. this.ctx = context;
  6802. this.ctx.setTransform(scaleX, 0, 0, -scaleY, 0, height * scaleY);
  6803. resetCtxToDefault(this.ctx, this.foregroundColor);
  6804. } else {
  6805. resetCtxToDefault(this.ctx, this.foregroundColor);
  6806. this.ctx.rect(rect[0], rect[1], width, height);
  6807. this.ctx.clip();
  6808. this.endPath();
  6809. }
  6810. }
  6811. this.current = new CanvasExtraState(this.ctx.canvas.width, this.ctx.canvas.height);
  6812. this.transform(...transform);
  6813. this.transform(...matrix);
  6814. }
  6815. endAnnotation() {
  6816. if (this.annotationCanvas) {
  6817. this.ctx = this.annotationCanvas.savedCtx;
  6818. delete this.annotationCanvas.savedCtx;
  6819. delete this.annotationCanvas;
  6820. }
  6821. }
  6822. paintImageMaskXObject(img) {
  6823. if (!this.contentVisible) {
  6824. return;
  6825. }
  6826. const count = img.count;
  6827. img = this.getObject(img.data, img);
  6828. img.count = count;
  6829. const ctx = this.ctx;
  6830. const glyph = this.processingType3;
  6831. if (glyph) {
  6832. if (glyph.compiled === undefined) {
  6833. glyph.compiled = compileType3Glyph(img);
  6834. }
  6835. if (glyph.compiled) {
  6836. glyph.compiled(ctx);
  6837. return;
  6838. }
  6839. }
  6840. const mask = this._createMaskCanvas(img);
  6841. const maskCanvas = mask.canvas;
  6842. ctx.save();
  6843. ctx.setTransform(1, 0, 0, 1, 0, 0);
  6844. ctx.drawImage(maskCanvas, mask.offsetX, mask.offsetY);
  6845. ctx.restore();
  6846. this.compose();
  6847. }
  6848. paintImageMaskXObjectRepeat(img, scaleX, skewX = 0, skewY = 0, scaleY, positions) {
  6849. if (!this.contentVisible) {
  6850. return;
  6851. }
  6852. img = this.getObject(img.data, img);
  6853. const ctx = this.ctx;
  6854. ctx.save();
  6855. const currentTransform = (0, _display_utils.getCurrentTransform)(ctx);
  6856. ctx.transform(scaleX, skewX, skewY, scaleY, 0, 0);
  6857. const mask = this._createMaskCanvas(img);
  6858. ctx.setTransform(1, 0, 0, 1, 0, 0);
  6859. for (let i = 0, ii = positions.length; i < ii; i += 2) {
  6860. const trans = _util.Util.transform(currentTransform, [scaleX, skewX, skewY, scaleY, positions[i], positions[i + 1]]);
  6861. const [x, y] = _util.Util.applyTransform([0, 0], trans);
  6862. ctx.drawImage(mask.canvas, x, y);
  6863. }
  6864. ctx.restore();
  6865. this.compose();
  6866. }
  6867. paintImageMaskXObjectGroup(images) {
  6868. if (!this.contentVisible) {
  6869. return;
  6870. }
  6871. const ctx = this.ctx;
  6872. const fillColor = this.current.fillColor;
  6873. const isPatternFill = this.current.patternFill;
  6874. for (const image of images) {
  6875. const {
  6876. data,
  6877. width,
  6878. height,
  6879. transform
  6880. } = image;
  6881. const maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
  6882. const maskCtx = maskCanvas.context;
  6883. maskCtx.save();
  6884. const img = this.getObject(data, image);
  6885. putBinaryImageMask(maskCtx, img);
  6886. maskCtx.globalCompositeOperation = "source-in";
  6887. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this, (0, _display_utils.getCurrentTransformInverse)(ctx), _pattern_helper.PathType.FILL) : fillColor;
  6888. maskCtx.fillRect(0, 0, width, height);
  6889. maskCtx.restore();
  6890. ctx.save();
  6891. ctx.transform(...transform);
  6892. ctx.scale(1, -1);
  6893. drawImageAtIntegerCoords(ctx, maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1);
  6894. ctx.restore();
  6895. }
  6896. this.compose();
  6897. }
  6898. paintImageXObject(objId) {
  6899. if (!this.contentVisible) {
  6900. return;
  6901. }
  6902. const imgData = this.getObject(objId);
  6903. if (!imgData) {
  6904. (0, _util.warn)("Dependent image isn't ready yet");
  6905. return;
  6906. }
  6907. this.paintInlineImageXObject(imgData);
  6908. }
  6909. paintImageXObjectRepeat(objId, scaleX, scaleY, positions) {
  6910. if (!this.contentVisible) {
  6911. return;
  6912. }
  6913. const imgData = this.getObject(objId);
  6914. if (!imgData) {
  6915. (0, _util.warn)("Dependent image isn't ready yet");
  6916. return;
  6917. }
  6918. const width = imgData.width;
  6919. const height = imgData.height;
  6920. const map = [];
  6921. for (let i = 0, ii = positions.length; i < ii; i += 2) {
  6922. map.push({
  6923. transform: [scaleX, 0, 0, scaleY, positions[i], positions[i + 1]],
  6924. x: 0,
  6925. y: 0,
  6926. w: width,
  6927. h: height
  6928. });
  6929. }
  6930. this.paintInlineImageXObjectGroup(imgData, map);
  6931. }
  6932. paintInlineImageXObject(imgData) {
  6933. if (!this.contentVisible) {
  6934. return;
  6935. }
  6936. const width = imgData.width;
  6937. const height = imgData.height;
  6938. const ctx = this.ctx;
  6939. this.save();
  6940. ctx.scale(1 / width, -1 / height);
  6941. let imgToPaint;
  6942. if (typeof HTMLElement === "function" && imgData instanceof HTMLElement || !imgData.data) {
  6943. imgToPaint = imgData;
  6944. } else {
  6945. const tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", width, height);
  6946. const tmpCtx = tmpCanvas.context;
  6947. putBinaryImageData(tmpCtx, imgData, this.current.transferMaps);
  6948. imgToPaint = tmpCanvas.canvas;
  6949. }
  6950. const scaled = this._scaleImage(imgToPaint, (0, _display_utils.getCurrentTransformInverse)(ctx));
  6951. ctx.imageSmoothingEnabled = getImageSmoothingEnabled((0, _display_utils.getCurrentTransform)(ctx), imgData.interpolate);
  6952. const [rWidth, rHeight] = drawImageAtIntegerCoords(ctx, scaled.img, 0, 0, scaled.paintWidth, scaled.paintHeight, 0, -height, width, height);
  6953. if (this.imageLayer) {
  6954. const [left, top] = _util.Util.applyTransform([0, -height], (0, _display_utils.getCurrentTransform)(this.ctx));
  6955. this.imageLayer.appendImage({
  6956. imgData,
  6957. left,
  6958. top,
  6959. width: rWidth,
  6960. height: rHeight
  6961. });
  6962. }
  6963. this.compose();
  6964. this.restore();
  6965. }
  6966. paintInlineImageXObjectGroup(imgData, map) {
  6967. if (!this.contentVisible) {
  6968. return;
  6969. }
  6970. const ctx = this.ctx;
  6971. const w = imgData.width;
  6972. const h = imgData.height;
  6973. const tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", w, h);
  6974. const tmpCtx = tmpCanvas.context;
  6975. putBinaryImageData(tmpCtx, imgData, this.current.transferMaps);
  6976. for (const entry of map) {
  6977. ctx.save();
  6978. ctx.transform(...entry.transform);
  6979. ctx.scale(1, -1);
  6980. drawImageAtIntegerCoords(ctx, tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h, 0, -1, 1, 1);
  6981. if (this.imageLayer) {
  6982. const [left, top] = _util.Util.applyTransform([entry.x, entry.y], (0, _display_utils.getCurrentTransform)(this.ctx));
  6983. this.imageLayer.appendImage({
  6984. imgData,
  6985. left,
  6986. top,
  6987. width: w,
  6988. height: h
  6989. });
  6990. }
  6991. ctx.restore();
  6992. }
  6993. this.compose();
  6994. }
  6995. paintSolidColorImageMask() {
  6996. if (!this.contentVisible) {
  6997. return;
  6998. }
  6999. this.ctx.fillRect(0, 0, 1, 1);
  7000. this.compose();
  7001. }
  7002. markPoint(tag) {}
  7003. markPointProps(tag, properties) {}
  7004. beginMarkedContent(tag) {
  7005. this.markedContentStack.push({
  7006. visible: true
  7007. });
  7008. }
  7009. beginMarkedContentProps(tag, properties) {
  7010. if (tag === "OC") {
  7011. this.markedContentStack.push({
  7012. visible: this.optionalContentConfig.isVisible(properties)
  7013. });
  7014. } else {
  7015. this.markedContentStack.push({
  7016. visible: true
  7017. });
  7018. }
  7019. this.contentVisible = this.isContentVisible();
  7020. }
  7021. endMarkedContent() {
  7022. this.markedContentStack.pop();
  7023. this.contentVisible = this.isContentVisible();
  7024. }
  7025. beginCompat() {}
  7026. endCompat() {}
  7027. consumePath(clipBox) {
  7028. const isEmpty = this.current.isEmptyClip();
  7029. if (this.pendingClip) {
  7030. this.current.updateClipFromPath();
  7031. }
  7032. if (!this.pendingClip) {
  7033. this.compose(clipBox);
  7034. }
  7035. const ctx = this.ctx;
  7036. if (this.pendingClip) {
  7037. if (!isEmpty) {
  7038. if (this.pendingClip === EO_CLIP) {
  7039. ctx.clip("evenodd");
  7040. } else {
  7041. ctx.clip();
  7042. }
  7043. }
  7044. this.pendingClip = null;
  7045. }
  7046. this.current.startNewPathAndClipBox(this.current.clipBox);
  7047. ctx.beginPath();
  7048. }
  7049. getSinglePixelWidth() {
  7050. if (!this._cachedGetSinglePixelWidth) {
  7051. const m = (0, _display_utils.getCurrentTransform)(this.ctx);
  7052. if (m[1] === 0 && m[2] === 0) {
  7053. this._cachedGetSinglePixelWidth = 1 / Math.min(Math.abs(m[0]), Math.abs(m[3]));
  7054. } else {
  7055. const absDet = Math.abs(m[0] * m[3] - m[2] * m[1]);
  7056. const normX = Math.hypot(m[0], m[2]);
  7057. const normY = Math.hypot(m[1], m[3]);
  7058. this._cachedGetSinglePixelWidth = Math.max(normX, normY) / absDet;
  7059. }
  7060. }
  7061. return this._cachedGetSinglePixelWidth;
  7062. }
  7063. getScaleForStroking() {
  7064. if (!this._cachedScaleForStroking) {
  7065. const {
  7066. lineWidth
  7067. } = this.current;
  7068. const m = (0, _display_utils.getCurrentTransform)(this.ctx);
  7069. let scaleX, scaleY;
  7070. if (m[1] === 0 && m[2] === 0) {
  7071. const normX = Math.abs(m[0]);
  7072. const normY = Math.abs(m[3]);
  7073. if (lineWidth === 0) {
  7074. scaleX = 1 / normX;
  7075. scaleY = 1 / normY;
  7076. } else {
  7077. const scaledXLineWidth = normX * lineWidth;
  7078. const scaledYLineWidth = normY * lineWidth;
  7079. scaleX = scaledXLineWidth < 1 ? 1 / scaledXLineWidth : 1;
  7080. scaleY = scaledYLineWidth < 1 ? 1 / scaledYLineWidth : 1;
  7081. }
  7082. } else {
  7083. const absDet = Math.abs(m[0] * m[3] - m[2] * m[1]);
  7084. const normX = Math.hypot(m[0], m[1]);
  7085. const normY = Math.hypot(m[2], m[3]);
  7086. if (lineWidth === 0) {
  7087. scaleX = normY / absDet;
  7088. scaleY = normX / absDet;
  7089. } else {
  7090. const baseArea = lineWidth * absDet;
  7091. scaleX = normY > baseArea ? normY / baseArea : 1;
  7092. scaleY = normX > baseArea ? normX / baseArea : 1;
  7093. }
  7094. }
  7095. this._cachedScaleForStroking = [scaleX, scaleY];
  7096. }
  7097. return this._cachedScaleForStroking;
  7098. }
  7099. rescaleAndStroke(saveRestore) {
  7100. const {
  7101. ctx
  7102. } = this;
  7103. const {
  7104. lineWidth
  7105. } = this.current;
  7106. const [scaleX, scaleY] = this.getScaleForStroking();
  7107. ctx.lineWidth = lineWidth || 1;
  7108. if (scaleX === 1 && scaleY === 1) {
  7109. ctx.stroke();
  7110. return;
  7111. }
  7112. let savedMatrix, savedDashes, savedDashOffset;
  7113. if (saveRestore) {
  7114. savedMatrix = (0, _display_utils.getCurrentTransform)(ctx);
  7115. savedDashes = ctx.getLineDash().slice();
  7116. savedDashOffset = ctx.lineDashOffset;
  7117. }
  7118. ctx.scale(scaleX, scaleY);
  7119. const scale = Math.max(scaleX, scaleY);
  7120. ctx.setLineDash(ctx.getLineDash().map(x => x / scale));
  7121. ctx.lineDashOffset /= scale;
  7122. ctx.stroke();
  7123. if (saveRestore) {
  7124. ctx.setTransform(...savedMatrix);
  7125. ctx.setLineDash(savedDashes);
  7126. ctx.lineDashOffset = savedDashOffset;
  7127. }
  7128. }
  7129. isContentVisible() {
  7130. for (let i = this.markedContentStack.length - 1; i >= 0; i--) {
  7131. if (!this.markedContentStack[i].visible) {
  7132. return false;
  7133. }
  7134. }
  7135. return true;
  7136. }
  7137. }
  7138. exports.CanvasGraphics = CanvasGraphics;
  7139. for (const op in _util.OPS) {
  7140. if (CanvasGraphics.prototype[op] !== undefined) {
  7141. CanvasGraphics.prototype[_util.OPS[op]] = CanvasGraphics.prototype[op];
  7142. }
  7143. }
  7144. /***/ }),
  7145. /* 13 */
  7146. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  7147. Object.defineProperty(exports, "__esModule", ({
  7148. value: true
  7149. }));
  7150. exports.TilingPattern = exports.PathType = void 0;
  7151. exports.getShadingPattern = getShadingPattern;
  7152. var _util = __w_pdfjs_require__(1);
  7153. var _display_utils = __w_pdfjs_require__(8);
  7154. var _is_node = __w_pdfjs_require__(3);
  7155. const PathType = {
  7156. FILL: "Fill",
  7157. STROKE: "Stroke",
  7158. SHADING: "Shading"
  7159. };
  7160. exports.PathType = PathType;
  7161. function applyBoundingBox(ctx, bbox) {
  7162. if (!bbox || _is_node.isNodeJS) {
  7163. return;
  7164. }
  7165. const width = bbox[2] - bbox[0];
  7166. const height = bbox[3] - bbox[1];
  7167. const region = new Path2D();
  7168. region.rect(bbox[0], bbox[1], width, height);
  7169. ctx.clip(region);
  7170. }
  7171. class BaseShadingPattern {
  7172. constructor() {
  7173. if (this.constructor === BaseShadingPattern) {
  7174. (0, _util.unreachable)("Cannot initialize BaseShadingPattern.");
  7175. }
  7176. }
  7177. getPattern() {
  7178. (0, _util.unreachable)("Abstract method `getPattern` called.");
  7179. }
  7180. }
  7181. class RadialAxialShadingPattern extends BaseShadingPattern {
  7182. constructor(IR) {
  7183. super();
  7184. this._type = IR[1];
  7185. this._bbox = IR[2];
  7186. this._colorStops = IR[3];
  7187. this._p0 = IR[4];
  7188. this._p1 = IR[5];
  7189. this._r0 = IR[6];
  7190. this._r1 = IR[7];
  7191. this.matrix = null;
  7192. }
  7193. _createGradient(ctx) {
  7194. let grad;
  7195. if (this._type === "axial") {
  7196. grad = ctx.createLinearGradient(this._p0[0], this._p0[1], this._p1[0], this._p1[1]);
  7197. } else if (this._type === "radial") {
  7198. grad = ctx.createRadialGradient(this._p0[0], this._p0[1], this._r0, this._p1[0], this._p1[1], this._r1);
  7199. }
  7200. for (const colorStop of this._colorStops) {
  7201. grad.addColorStop(colorStop[0], colorStop[1]);
  7202. }
  7203. return grad;
  7204. }
  7205. getPattern(ctx, owner, inverse, pathType) {
  7206. let pattern;
  7207. if (pathType === PathType.STROKE || pathType === PathType.FILL) {
  7208. const ownerBBox = owner.current.getClippedPathBoundingBox(pathType, (0, _display_utils.getCurrentTransform)(ctx)) || [0, 0, 0, 0];
  7209. const width = Math.ceil(ownerBBox[2] - ownerBBox[0]) || 1;
  7210. const height = Math.ceil(ownerBBox[3] - ownerBBox[1]) || 1;
  7211. const tmpCanvas = owner.cachedCanvases.getCanvas("pattern", width, height, true);
  7212. const tmpCtx = tmpCanvas.context;
  7213. tmpCtx.clearRect(0, 0, tmpCtx.canvas.width, tmpCtx.canvas.height);
  7214. tmpCtx.beginPath();
  7215. tmpCtx.rect(0, 0, tmpCtx.canvas.width, tmpCtx.canvas.height);
  7216. tmpCtx.translate(-ownerBBox[0], -ownerBBox[1]);
  7217. inverse = _util.Util.transform(inverse, [1, 0, 0, 1, ownerBBox[0], ownerBBox[1]]);
  7218. tmpCtx.transform(...owner.baseTransform);
  7219. if (this.matrix) {
  7220. tmpCtx.transform(...this.matrix);
  7221. }
  7222. applyBoundingBox(tmpCtx, this._bbox);
  7223. tmpCtx.fillStyle = this._createGradient(tmpCtx);
  7224. tmpCtx.fill();
  7225. pattern = ctx.createPattern(tmpCanvas.canvas, "no-repeat");
  7226. const domMatrix = new DOMMatrix(inverse);
  7227. try {
  7228. pattern.setTransform(domMatrix);
  7229. } catch (ex) {
  7230. (0, _util.warn)(`RadialAxialShadingPattern.getPattern: "${ex?.message}".`);
  7231. }
  7232. } else {
  7233. applyBoundingBox(ctx, this._bbox);
  7234. pattern = this._createGradient(ctx);
  7235. }
  7236. return pattern;
  7237. }
  7238. }
  7239. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  7240. const coords = context.coords,
  7241. colors = context.colors;
  7242. const bytes = data.data,
  7243. rowSize = data.width * 4;
  7244. let tmp;
  7245. if (coords[p1 + 1] > coords[p2 + 1]) {
  7246. tmp = p1;
  7247. p1 = p2;
  7248. p2 = tmp;
  7249. tmp = c1;
  7250. c1 = c2;
  7251. c2 = tmp;
  7252. }
  7253. if (coords[p2 + 1] > coords[p3 + 1]) {
  7254. tmp = p2;
  7255. p2 = p3;
  7256. p3 = tmp;
  7257. tmp = c2;
  7258. c2 = c3;
  7259. c3 = tmp;
  7260. }
  7261. if (coords[p1 + 1] > coords[p2 + 1]) {
  7262. tmp = p1;
  7263. p1 = p2;
  7264. p2 = tmp;
  7265. tmp = c1;
  7266. c1 = c2;
  7267. c2 = tmp;
  7268. }
  7269. const x1 = (coords[p1] + context.offsetX) * context.scaleX;
  7270. const y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  7271. const x2 = (coords[p2] + context.offsetX) * context.scaleX;
  7272. const y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  7273. const x3 = (coords[p3] + context.offsetX) * context.scaleX;
  7274. const y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  7275. if (y1 >= y3) {
  7276. return;
  7277. }
  7278. const c1r = colors[c1],
  7279. c1g = colors[c1 + 1],
  7280. c1b = colors[c1 + 2];
  7281. const c2r = colors[c2],
  7282. c2g = colors[c2 + 1],
  7283. c2b = colors[c2 + 2];
  7284. const c3r = colors[c3],
  7285. c3g = colors[c3 + 1],
  7286. c3b = colors[c3 + 2];
  7287. const minY = Math.round(y1),
  7288. maxY = Math.round(y3);
  7289. let xa, car, cag, cab;
  7290. let xb, cbr, cbg, cbb;
  7291. for (let y = minY; y <= maxY; y++) {
  7292. if (y < y2) {
  7293. let k;
  7294. if (y < y1) {
  7295. k = 0;
  7296. } else {
  7297. k = (y1 - y) / (y1 - y2);
  7298. }
  7299. xa = x1 - (x1 - x2) * k;
  7300. car = c1r - (c1r - c2r) * k;
  7301. cag = c1g - (c1g - c2g) * k;
  7302. cab = c1b - (c1b - c2b) * k;
  7303. } else {
  7304. let k;
  7305. if (y > y3) {
  7306. k = 1;
  7307. } else if (y2 === y3) {
  7308. k = 0;
  7309. } else {
  7310. k = (y2 - y) / (y2 - y3);
  7311. }
  7312. xa = x2 - (x2 - x3) * k;
  7313. car = c2r - (c2r - c3r) * k;
  7314. cag = c2g - (c2g - c3g) * k;
  7315. cab = c2b - (c2b - c3b) * k;
  7316. }
  7317. let k;
  7318. if (y < y1) {
  7319. k = 0;
  7320. } else if (y > y3) {
  7321. k = 1;
  7322. } else {
  7323. k = (y1 - y) / (y1 - y3);
  7324. }
  7325. xb = x1 - (x1 - x3) * k;
  7326. cbr = c1r - (c1r - c3r) * k;
  7327. cbg = c1g - (c1g - c3g) * k;
  7328. cbb = c1b - (c1b - c3b) * k;
  7329. const x1_ = Math.round(Math.min(xa, xb));
  7330. const x2_ = Math.round(Math.max(xa, xb));
  7331. let j = rowSize * y + x1_ * 4;
  7332. for (let x = x1_; x <= x2_; x++) {
  7333. k = (xa - x) / (xa - xb);
  7334. if (k < 0) {
  7335. k = 0;
  7336. } else if (k > 1) {
  7337. k = 1;
  7338. }
  7339. bytes[j++] = car - (car - cbr) * k | 0;
  7340. bytes[j++] = cag - (cag - cbg) * k | 0;
  7341. bytes[j++] = cab - (cab - cbb) * k | 0;
  7342. bytes[j++] = 255;
  7343. }
  7344. }
  7345. }
  7346. function drawFigure(data, figure, context) {
  7347. const ps = figure.coords;
  7348. const cs = figure.colors;
  7349. let i, ii;
  7350. switch (figure.type) {
  7351. case "lattice":
  7352. const verticesPerRow = figure.verticesPerRow;
  7353. const rows = Math.floor(ps.length / verticesPerRow) - 1;
  7354. const cols = verticesPerRow - 1;
  7355. for (i = 0; i < rows; i++) {
  7356. let q = i * verticesPerRow;
  7357. for (let j = 0; j < cols; j++, q++) {
  7358. drawTriangle(data, context, ps[q], ps[q + 1], ps[q + verticesPerRow], cs[q], cs[q + 1], cs[q + verticesPerRow]);
  7359. drawTriangle(data, context, ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow], cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  7360. }
  7361. }
  7362. break;
  7363. case "triangles":
  7364. for (i = 0, ii = ps.length; i < ii; i += 3) {
  7365. drawTriangle(data, context, ps[i], ps[i + 1], ps[i + 2], cs[i], cs[i + 1], cs[i + 2]);
  7366. }
  7367. break;
  7368. default:
  7369. throw new Error("illegal figure");
  7370. }
  7371. }
  7372. class MeshShadingPattern extends BaseShadingPattern {
  7373. constructor(IR) {
  7374. super();
  7375. this._coords = IR[2];
  7376. this._colors = IR[3];
  7377. this._figures = IR[4];
  7378. this._bounds = IR[5];
  7379. this._bbox = IR[7];
  7380. this._background = IR[8];
  7381. this.matrix = null;
  7382. }
  7383. _createMeshCanvas(combinedScale, backgroundColor, cachedCanvases) {
  7384. const EXPECTED_SCALE = 1.1;
  7385. const MAX_PATTERN_SIZE = 3000;
  7386. const BORDER_SIZE = 2;
  7387. const offsetX = Math.floor(this._bounds[0]);
  7388. const offsetY = Math.floor(this._bounds[1]);
  7389. const boundsWidth = Math.ceil(this._bounds[2]) - offsetX;
  7390. const boundsHeight = Math.ceil(this._bounds[3]) - offsetY;
  7391. const width = Math.min(Math.ceil(Math.abs(boundsWidth * combinedScale[0] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  7392. const height = Math.min(Math.ceil(Math.abs(boundsHeight * combinedScale[1] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  7393. const scaleX = boundsWidth / width;
  7394. const scaleY = boundsHeight / height;
  7395. const context = {
  7396. coords: this._coords,
  7397. colors: this._colors,
  7398. offsetX: -offsetX,
  7399. offsetY: -offsetY,
  7400. scaleX: 1 / scaleX,
  7401. scaleY: 1 / scaleY
  7402. };
  7403. const paddedWidth = width + BORDER_SIZE * 2;
  7404. const paddedHeight = height + BORDER_SIZE * 2;
  7405. const tmpCanvas = cachedCanvases.getCanvas("mesh", paddedWidth, paddedHeight, false);
  7406. const tmpCtx = tmpCanvas.context;
  7407. const data = tmpCtx.createImageData(width, height);
  7408. if (backgroundColor) {
  7409. const bytes = data.data;
  7410. for (let i = 0, ii = bytes.length; i < ii; i += 4) {
  7411. bytes[i] = backgroundColor[0];
  7412. bytes[i + 1] = backgroundColor[1];
  7413. bytes[i + 2] = backgroundColor[2];
  7414. bytes[i + 3] = 255;
  7415. }
  7416. }
  7417. for (const figure of this._figures) {
  7418. drawFigure(data, figure, context);
  7419. }
  7420. tmpCtx.putImageData(data, BORDER_SIZE, BORDER_SIZE);
  7421. const canvas = tmpCanvas.canvas;
  7422. return {
  7423. canvas,
  7424. offsetX: offsetX - BORDER_SIZE * scaleX,
  7425. offsetY: offsetY - BORDER_SIZE * scaleY,
  7426. scaleX,
  7427. scaleY
  7428. };
  7429. }
  7430. getPattern(ctx, owner, inverse, pathType) {
  7431. applyBoundingBox(ctx, this._bbox);
  7432. let scale;
  7433. if (pathType === PathType.SHADING) {
  7434. scale = _util.Util.singularValueDecompose2dScale((0, _display_utils.getCurrentTransform)(ctx));
  7435. } else {
  7436. scale = _util.Util.singularValueDecompose2dScale(owner.baseTransform);
  7437. if (this.matrix) {
  7438. const matrixScale = _util.Util.singularValueDecompose2dScale(this.matrix);
  7439. scale = [scale[0] * matrixScale[0], scale[1] * matrixScale[1]];
  7440. }
  7441. }
  7442. const temporaryPatternCanvas = this._createMeshCanvas(scale, pathType === PathType.SHADING ? null : this._background, owner.cachedCanvases);
  7443. if (pathType !== PathType.SHADING) {
  7444. ctx.setTransform(...owner.baseTransform);
  7445. if (this.matrix) {
  7446. ctx.transform(...this.matrix);
  7447. }
  7448. }
  7449. ctx.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY);
  7450. ctx.scale(temporaryPatternCanvas.scaleX, temporaryPatternCanvas.scaleY);
  7451. return ctx.createPattern(temporaryPatternCanvas.canvas, "no-repeat");
  7452. }
  7453. }
  7454. class DummyShadingPattern extends BaseShadingPattern {
  7455. getPattern() {
  7456. return "hotpink";
  7457. }
  7458. }
  7459. function getShadingPattern(IR) {
  7460. switch (IR[0]) {
  7461. case "RadialAxial":
  7462. return new RadialAxialShadingPattern(IR);
  7463. case "Mesh":
  7464. return new MeshShadingPattern(IR);
  7465. case "Dummy":
  7466. return new DummyShadingPattern();
  7467. }
  7468. throw new Error(`Unknown IR type: ${IR[0]}`);
  7469. }
  7470. const PaintType = {
  7471. COLORED: 1,
  7472. UNCOLORED: 2
  7473. };
  7474. class TilingPattern {
  7475. static get MAX_PATTERN_SIZE() {
  7476. return (0, _util.shadow)(this, "MAX_PATTERN_SIZE", 3000);
  7477. }
  7478. constructor(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
  7479. this.operatorList = IR[2];
  7480. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  7481. this.bbox = IR[4];
  7482. this.xstep = IR[5];
  7483. this.ystep = IR[6];
  7484. this.paintType = IR[7];
  7485. this.tilingType = IR[8];
  7486. this.color = color;
  7487. this.ctx = ctx;
  7488. this.canvasGraphicsFactory = canvasGraphicsFactory;
  7489. this.baseTransform = baseTransform;
  7490. }
  7491. createPatternCanvas(owner) {
  7492. const operatorList = this.operatorList;
  7493. const bbox = this.bbox;
  7494. const xstep = this.xstep;
  7495. const ystep = this.ystep;
  7496. const paintType = this.paintType;
  7497. const tilingType = this.tilingType;
  7498. const color = this.color;
  7499. const canvasGraphicsFactory = this.canvasGraphicsFactory;
  7500. (0, _util.info)("TilingType: " + tilingType);
  7501. const x0 = bbox[0],
  7502. y0 = bbox[1],
  7503. x1 = bbox[2],
  7504. y1 = bbox[3];
  7505. const matrixScale = _util.Util.singularValueDecompose2dScale(this.matrix);
  7506. const curMatrixScale = _util.Util.singularValueDecompose2dScale(this.baseTransform);
  7507. const combinedScale = [matrixScale[0] * curMatrixScale[0], matrixScale[1] * curMatrixScale[1]];
  7508. const dimx = this.getSizeAndScale(xstep, this.ctx.canvas.width, combinedScale[0]);
  7509. const dimy = this.getSizeAndScale(ystep, this.ctx.canvas.height, combinedScale[1]);
  7510. const tmpCanvas = owner.cachedCanvases.getCanvas("pattern", dimx.size, dimy.size, true);
  7511. const tmpCtx = tmpCanvas.context;
  7512. const graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
  7513. graphics.groupLevel = owner.groupLevel;
  7514. this.setFillAndStrokeStyleToContext(graphics, paintType, color);
  7515. let adjustedX0 = x0;
  7516. let adjustedY0 = y0;
  7517. let adjustedX1 = x1;
  7518. let adjustedY1 = y1;
  7519. if (x0 < 0) {
  7520. adjustedX0 = 0;
  7521. adjustedX1 += Math.abs(x0);
  7522. }
  7523. if (y0 < 0) {
  7524. adjustedY0 = 0;
  7525. adjustedY1 += Math.abs(y0);
  7526. }
  7527. tmpCtx.translate(-(dimx.scale * adjustedX0), -(dimy.scale * adjustedY0));
  7528. graphics.transform(dimx.scale, 0, 0, dimy.scale, 0, 0);
  7529. tmpCtx.save();
  7530. this.clipBbox(graphics, adjustedX0, adjustedY0, adjustedX1, adjustedY1);
  7531. graphics.baseTransform = (0, _display_utils.getCurrentTransform)(graphics.ctx);
  7532. graphics.executeOperatorList(operatorList);
  7533. graphics.endDrawing();
  7534. return {
  7535. canvas: tmpCanvas.canvas,
  7536. scaleX: dimx.scale,
  7537. scaleY: dimy.scale,
  7538. offsetX: adjustedX0,
  7539. offsetY: adjustedY0
  7540. };
  7541. }
  7542. getSizeAndScale(step, realOutputSize, scale) {
  7543. step = Math.abs(step);
  7544. const maxSize = Math.max(TilingPattern.MAX_PATTERN_SIZE, realOutputSize);
  7545. let size = Math.ceil(step * scale);
  7546. if (size >= maxSize) {
  7547. size = maxSize;
  7548. } else {
  7549. scale = size / step;
  7550. }
  7551. return {
  7552. scale,
  7553. size
  7554. };
  7555. }
  7556. clipBbox(graphics, x0, y0, x1, y1) {
  7557. const bboxWidth = x1 - x0;
  7558. const bboxHeight = y1 - y0;
  7559. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  7560. graphics.current.updateRectMinMax((0, _display_utils.getCurrentTransform)(graphics.ctx), [x0, y0, x1, y1]);
  7561. graphics.clip();
  7562. graphics.endPath();
  7563. }
  7564. setFillAndStrokeStyleToContext(graphics, paintType, color) {
  7565. const context = graphics.ctx,
  7566. current = graphics.current;
  7567. switch (paintType) {
  7568. case PaintType.COLORED:
  7569. const ctx = this.ctx;
  7570. context.fillStyle = ctx.fillStyle;
  7571. context.strokeStyle = ctx.strokeStyle;
  7572. current.fillColor = ctx.fillStyle;
  7573. current.strokeColor = ctx.strokeStyle;
  7574. break;
  7575. case PaintType.UNCOLORED:
  7576. const cssColor = _util.Util.makeHexColor(color[0], color[1], color[2]);
  7577. context.fillStyle = cssColor;
  7578. context.strokeStyle = cssColor;
  7579. current.fillColor = cssColor;
  7580. current.strokeColor = cssColor;
  7581. break;
  7582. default:
  7583. throw new _util.FormatError(`Unsupported paint type: ${paintType}`);
  7584. }
  7585. }
  7586. getPattern(ctx, owner, inverse, pathType) {
  7587. let matrix = inverse;
  7588. if (pathType !== PathType.SHADING) {
  7589. matrix = _util.Util.transform(matrix, owner.baseTransform);
  7590. if (this.matrix) {
  7591. matrix = _util.Util.transform(matrix, this.matrix);
  7592. }
  7593. }
  7594. const temporaryPatternCanvas = this.createPatternCanvas(owner);
  7595. let domMatrix = new DOMMatrix(matrix);
  7596. domMatrix = domMatrix.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY);
  7597. domMatrix = domMatrix.scale(1 / temporaryPatternCanvas.scaleX, 1 / temporaryPatternCanvas.scaleY);
  7598. const pattern = ctx.createPattern(temporaryPatternCanvas.canvas, "repeat");
  7599. try {
  7600. pattern.setTransform(domMatrix);
  7601. } catch (ex) {
  7602. (0, _util.warn)(`TilingPattern.getPattern: "${ex?.message}".`);
  7603. }
  7604. return pattern;
  7605. }
  7606. }
  7607. exports.TilingPattern = TilingPattern;
  7608. /***/ }),
  7609. /* 14 */
  7610. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  7611. Object.defineProperty(exports, "__esModule", ({
  7612. value: true
  7613. }));
  7614. exports.applyMaskImageData = applyMaskImageData;
  7615. var _util = __w_pdfjs_require__(1);
  7616. function applyMaskImageData({
  7617. src,
  7618. srcPos = 0,
  7619. dest,
  7620. destPos = 0,
  7621. width,
  7622. height,
  7623. inverseDecode = false
  7624. }) {
  7625. const opaque = _util.FeatureTest.isLittleEndian ? 0xff000000 : 0x000000ff;
  7626. const [zeroMapping, oneMapping] = !inverseDecode ? [opaque, 0] : [0, opaque];
  7627. const widthInSource = width >> 3;
  7628. const widthRemainder = width & 7;
  7629. const srcLength = src.length;
  7630. dest = new Uint32Array(dest.buffer);
  7631. for (let i = 0; i < height; i++) {
  7632. for (const max = srcPos + widthInSource; srcPos < max; srcPos++) {
  7633. const elem = srcPos < srcLength ? src[srcPos] : 255;
  7634. dest[destPos++] = elem & 0b10000000 ? oneMapping : zeroMapping;
  7635. dest[destPos++] = elem & 0b1000000 ? oneMapping : zeroMapping;
  7636. dest[destPos++] = elem & 0b100000 ? oneMapping : zeroMapping;
  7637. dest[destPos++] = elem & 0b10000 ? oneMapping : zeroMapping;
  7638. dest[destPos++] = elem & 0b1000 ? oneMapping : zeroMapping;
  7639. dest[destPos++] = elem & 0b100 ? oneMapping : zeroMapping;
  7640. dest[destPos++] = elem & 0b10 ? oneMapping : zeroMapping;
  7641. dest[destPos++] = elem & 0b1 ? oneMapping : zeroMapping;
  7642. }
  7643. if (widthRemainder === 0) {
  7644. continue;
  7645. }
  7646. const elem = srcPos < srcLength ? src[srcPos++] : 255;
  7647. for (let j = 0; j < widthRemainder; j++) {
  7648. dest[destPos++] = elem & 1 << 7 - j ? oneMapping : zeroMapping;
  7649. }
  7650. }
  7651. return {
  7652. srcPos,
  7653. destPos
  7654. };
  7655. }
  7656. /***/ }),
  7657. /* 15 */
  7658. /***/ ((__unused_webpack_module, exports) => {
  7659. Object.defineProperty(exports, "__esModule", ({
  7660. value: true
  7661. }));
  7662. exports.GlobalWorkerOptions = void 0;
  7663. const GlobalWorkerOptions = Object.create(null);
  7664. exports.GlobalWorkerOptions = GlobalWorkerOptions;
  7665. GlobalWorkerOptions.workerPort = GlobalWorkerOptions.workerPort === undefined ? null : GlobalWorkerOptions.workerPort;
  7666. GlobalWorkerOptions.workerSrc = GlobalWorkerOptions.workerSrc === undefined ? "" : GlobalWorkerOptions.workerSrc;
  7667. /***/ }),
  7668. /* 16 */
  7669. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  7670. Object.defineProperty(exports, "__esModule", ({
  7671. value: true
  7672. }));
  7673. exports.MessageHandler = void 0;
  7674. var _util = __w_pdfjs_require__(1);
  7675. const CallbackKind = {
  7676. UNKNOWN: 0,
  7677. DATA: 1,
  7678. ERROR: 2
  7679. };
  7680. const StreamKind = {
  7681. UNKNOWN: 0,
  7682. CANCEL: 1,
  7683. CANCEL_COMPLETE: 2,
  7684. CLOSE: 3,
  7685. ENQUEUE: 4,
  7686. ERROR: 5,
  7687. PULL: 6,
  7688. PULL_COMPLETE: 7,
  7689. START_COMPLETE: 8
  7690. };
  7691. function wrapReason(reason) {
  7692. if (!(reason instanceof Error || typeof reason === "object" && reason !== null)) {
  7693. (0, _util.unreachable)('wrapReason: Expected "reason" to be a (possibly cloned) Error.');
  7694. }
  7695. switch (reason.name) {
  7696. case "AbortException":
  7697. return new _util.AbortException(reason.message);
  7698. case "MissingPDFException":
  7699. return new _util.MissingPDFException(reason.message);
  7700. case "PasswordException":
  7701. return new _util.PasswordException(reason.message, reason.code);
  7702. case "UnexpectedResponseException":
  7703. return new _util.UnexpectedResponseException(reason.message, reason.status);
  7704. case "UnknownErrorException":
  7705. return new _util.UnknownErrorException(reason.message, reason.details);
  7706. default:
  7707. return new _util.UnknownErrorException(reason.message, reason.toString());
  7708. }
  7709. }
  7710. class MessageHandler {
  7711. constructor(sourceName, targetName, comObj) {
  7712. this.sourceName = sourceName;
  7713. this.targetName = targetName;
  7714. this.comObj = comObj;
  7715. this.callbackId = 1;
  7716. this.streamId = 1;
  7717. this.streamSinks = Object.create(null);
  7718. this.streamControllers = Object.create(null);
  7719. this.callbackCapabilities = Object.create(null);
  7720. this.actionHandler = Object.create(null);
  7721. this._onComObjOnMessage = event => {
  7722. const data = event.data;
  7723. if (data.targetName !== this.sourceName) {
  7724. return;
  7725. }
  7726. if (data.stream) {
  7727. this._processStreamMessage(data);
  7728. return;
  7729. }
  7730. if (data.callback) {
  7731. const callbackId = data.callbackId;
  7732. const capability = this.callbackCapabilities[callbackId];
  7733. if (!capability) {
  7734. throw new Error(`Cannot resolve callback ${callbackId}`);
  7735. }
  7736. delete this.callbackCapabilities[callbackId];
  7737. if (data.callback === CallbackKind.DATA) {
  7738. capability.resolve(data.data);
  7739. } else if (data.callback === CallbackKind.ERROR) {
  7740. capability.reject(wrapReason(data.reason));
  7741. } else {
  7742. throw new Error("Unexpected callback case");
  7743. }
  7744. return;
  7745. }
  7746. const action = this.actionHandler[data.action];
  7747. if (!action) {
  7748. throw new Error(`Unknown action from worker: ${data.action}`);
  7749. }
  7750. if (data.callbackId) {
  7751. const cbSourceName = this.sourceName;
  7752. const cbTargetName = data.sourceName;
  7753. new Promise(function (resolve) {
  7754. resolve(action(data.data));
  7755. }).then(function (result) {
  7756. comObj.postMessage({
  7757. sourceName: cbSourceName,
  7758. targetName: cbTargetName,
  7759. callback: CallbackKind.DATA,
  7760. callbackId: data.callbackId,
  7761. data: result
  7762. });
  7763. }, function (reason) {
  7764. comObj.postMessage({
  7765. sourceName: cbSourceName,
  7766. targetName: cbTargetName,
  7767. callback: CallbackKind.ERROR,
  7768. callbackId: data.callbackId,
  7769. reason: wrapReason(reason)
  7770. });
  7771. });
  7772. return;
  7773. }
  7774. if (data.streamId) {
  7775. this._createStreamSink(data);
  7776. return;
  7777. }
  7778. action(data.data);
  7779. };
  7780. comObj.addEventListener("message", this._onComObjOnMessage);
  7781. }
  7782. on(actionName, handler) {
  7783. const ah = this.actionHandler;
  7784. if (ah[actionName]) {
  7785. throw new Error(`There is already an actionName called "${actionName}"`);
  7786. }
  7787. ah[actionName] = handler;
  7788. }
  7789. send(actionName, data, transfers) {
  7790. this.comObj.postMessage({
  7791. sourceName: this.sourceName,
  7792. targetName: this.targetName,
  7793. action: actionName,
  7794. data
  7795. }, transfers);
  7796. }
  7797. sendWithPromise(actionName, data, transfers) {
  7798. const callbackId = this.callbackId++;
  7799. const capability = (0, _util.createPromiseCapability)();
  7800. this.callbackCapabilities[callbackId] = capability;
  7801. try {
  7802. this.comObj.postMessage({
  7803. sourceName: this.sourceName,
  7804. targetName: this.targetName,
  7805. action: actionName,
  7806. callbackId,
  7807. data
  7808. }, transfers);
  7809. } catch (ex) {
  7810. capability.reject(ex);
  7811. }
  7812. return capability.promise;
  7813. }
  7814. sendWithStream(actionName, data, queueingStrategy, transfers) {
  7815. const streamId = this.streamId++,
  7816. sourceName = this.sourceName,
  7817. targetName = this.targetName,
  7818. comObj = this.comObj;
  7819. return new ReadableStream({
  7820. start: controller => {
  7821. const startCapability = (0, _util.createPromiseCapability)();
  7822. this.streamControllers[streamId] = {
  7823. controller,
  7824. startCall: startCapability,
  7825. pullCall: null,
  7826. cancelCall: null,
  7827. isClosed: false
  7828. };
  7829. comObj.postMessage({
  7830. sourceName,
  7831. targetName,
  7832. action: actionName,
  7833. streamId,
  7834. data,
  7835. desiredSize: controller.desiredSize
  7836. }, transfers);
  7837. return startCapability.promise;
  7838. },
  7839. pull: controller => {
  7840. const pullCapability = (0, _util.createPromiseCapability)();
  7841. this.streamControllers[streamId].pullCall = pullCapability;
  7842. comObj.postMessage({
  7843. sourceName,
  7844. targetName,
  7845. stream: StreamKind.PULL,
  7846. streamId,
  7847. desiredSize: controller.desiredSize
  7848. });
  7849. return pullCapability.promise;
  7850. },
  7851. cancel: reason => {
  7852. (0, _util.assert)(reason instanceof Error, "cancel must have a valid reason");
  7853. const cancelCapability = (0, _util.createPromiseCapability)();
  7854. this.streamControllers[streamId].cancelCall = cancelCapability;
  7855. this.streamControllers[streamId].isClosed = true;
  7856. comObj.postMessage({
  7857. sourceName,
  7858. targetName,
  7859. stream: StreamKind.CANCEL,
  7860. streamId,
  7861. reason: wrapReason(reason)
  7862. });
  7863. return cancelCapability.promise;
  7864. }
  7865. }, queueingStrategy);
  7866. }
  7867. _createStreamSink(data) {
  7868. const streamId = data.streamId,
  7869. sourceName = this.sourceName,
  7870. targetName = data.sourceName,
  7871. comObj = this.comObj;
  7872. const self = this,
  7873. action = this.actionHandler[data.action];
  7874. const streamSink = {
  7875. enqueue(chunk, size = 1, transfers) {
  7876. if (this.isCancelled) {
  7877. return;
  7878. }
  7879. const lastDesiredSize = this.desiredSize;
  7880. this.desiredSize -= size;
  7881. if (lastDesiredSize > 0 && this.desiredSize <= 0) {
  7882. this.sinkCapability = (0, _util.createPromiseCapability)();
  7883. this.ready = this.sinkCapability.promise;
  7884. }
  7885. comObj.postMessage({
  7886. sourceName,
  7887. targetName,
  7888. stream: StreamKind.ENQUEUE,
  7889. streamId,
  7890. chunk
  7891. }, transfers);
  7892. },
  7893. close() {
  7894. if (this.isCancelled) {
  7895. return;
  7896. }
  7897. this.isCancelled = true;
  7898. comObj.postMessage({
  7899. sourceName,
  7900. targetName,
  7901. stream: StreamKind.CLOSE,
  7902. streamId
  7903. });
  7904. delete self.streamSinks[streamId];
  7905. },
  7906. error(reason) {
  7907. (0, _util.assert)(reason instanceof Error, "error must have a valid reason");
  7908. if (this.isCancelled) {
  7909. return;
  7910. }
  7911. this.isCancelled = true;
  7912. comObj.postMessage({
  7913. sourceName,
  7914. targetName,
  7915. stream: StreamKind.ERROR,
  7916. streamId,
  7917. reason: wrapReason(reason)
  7918. });
  7919. },
  7920. sinkCapability: (0, _util.createPromiseCapability)(),
  7921. onPull: null,
  7922. onCancel: null,
  7923. isCancelled: false,
  7924. desiredSize: data.desiredSize,
  7925. ready: null
  7926. };
  7927. streamSink.sinkCapability.resolve();
  7928. streamSink.ready = streamSink.sinkCapability.promise;
  7929. this.streamSinks[streamId] = streamSink;
  7930. new Promise(function (resolve) {
  7931. resolve(action(data.data, streamSink));
  7932. }).then(function () {
  7933. comObj.postMessage({
  7934. sourceName,
  7935. targetName,
  7936. stream: StreamKind.START_COMPLETE,
  7937. streamId,
  7938. success: true
  7939. });
  7940. }, function (reason) {
  7941. comObj.postMessage({
  7942. sourceName,
  7943. targetName,
  7944. stream: StreamKind.START_COMPLETE,
  7945. streamId,
  7946. reason: wrapReason(reason)
  7947. });
  7948. });
  7949. }
  7950. _processStreamMessage(data) {
  7951. const streamId = data.streamId,
  7952. sourceName = this.sourceName,
  7953. targetName = data.sourceName,
  7954. comObj = this.comObj;
  7955. const streamController = this.streamControllers[streamId],
  7956. streamSink = this.streamSinks[streamId];
  7957. switch (data.stream) {
  7958. case StreamKind.START_COMPLETE:
  7959. if (data.success) {
  7960. streamController.startCall.resolve();
  7961. } else {
  7962. streamController.startCall.reject(wrapReason(data.reason));
  7963. }
  7964. break;
  7965. case StreamKind.PULL_COMPLETE:
  7966. if (data.success) {
  7967. streamController.pullCall.resolve();
  7968. } else {
  7969. streamController.pullCall.reject(wrapReason(data.reason));
  7970. }
  7971. break;
  7972. case StreamKind.PULL:
  7973. if (!streamSink) {
  7974. comObj.postMessage({
  7975. sourceName,
  7976. targetName,
  7977. stream: StreamKind.PULL_COMPLETE,
  7978. streamId,
  7979. success: true
  7980. });
  7981. break;
  7982. }
  7983. if (streamSink.desiredSize <= 0 && data.desiredSize > 0) {
  7984. streamSink.sinkCapability.resolve();
  7985. }
  7986. streamSink.desiredSize = data.desiredSize;
  7987. new Promise(function (resolve) {
  7988. resolve(streamSink.onPull && streamSink.onPull());
  7989. }).then(function () {
  7990. comObj.postMessage({
  7991. sourceName,
  7992. targetName,
  7993. stream: StreamKind.PULL_COMPLETE,
  7994. streamId,
  7995. success: true
  7996. });
  7997. }, function (reason) {
  7998. comObj.postMessage({
  7999. sourceName,
  8000. targetName,
  8001. stream: StreamKind.PULL_COMPLETE,
  8002. streamId,
  8003. reason: wrapReason(reason)
  8004. });
  8005. });
  8006. break;
  8007. case StreamKind.ENQUEUE:
  8008. (0, _util.assert)(streamController, "enqueue should have stream controller");
  8009. if (streamController.isClosed) {
  8010. break;
  8011. }
  8012. streamController.controller.enqueue(data.chunk);
  8013. break;
  8014. case StreamKind.CLOSE:
  8015. (0, _util.assert)(streamController, "close should have stream controller");
  8016. if (streamController.isClosed) {
  8017. break;
  8018. }
  8019. streamController.isClosed = true;
  8020. streamController.controller.close();
  8021. this._deleteStreamController(streamController, streamId);
  8022. break;
  8023. case StreamKind.ERROR:
  8024. (0, _util.assert)(streamController, "error should have stream controller");
  8025. streamController.controller.error(wrapReason(data.reason));
  8026. this._deleteStreamController(streamController, streamId);
  8027. break;
  8028. case StreamKind.CANCEL_COMPLETE:
  8029. if (data.success) {
  8030. streamController.cancelCall.resolve();
  8031. } else {
  8032. streamController.cancelCall.reject(wrapReason(data.reason));
  8033. }
  8034. this._deleteStreamController(streamController, streamId);
  8035. break;
  8036. case StreamKind.CANCEL:
  8037. if (!streamSink) {
  8038. break;
  8039. }
  8040. new Promise(function (resolve) {
  8041. resolve(streamSink.onCancel && streamSink.onCancel(wrapReason(data.reason)));
  8042. }).then(function () {
  8043. comObj.postMessage({
  8044. sourceName,
  8045. targetName,
  8046. stream: StreamKind.CANCEL_COMPLETE,
  8047. streamId,
  8048. success: true
  8049. });
  8050. }, function (reason) {
  8051. comObj.postMessage({
  8052. sourceName,
  8053. targetName,
  8054. stream: StreamKind.CANCEL_COMPLETE,
  8055. streamId,
  8056. reason: wrapReason(reason)
  8057. });
  8058. });
  8059. streamSink.sinkCapability.reject(wrapReason(data.reason));
  8060. streamSink.isCancelled = true;
  8061. delete this.streamSinks[streamId];
  8062. break;
  8063. default:
  8064. throw new Error("Unexpected stream case");
  8065. }
  8066. }
  8067. async _deleteStreamController(streamController, streamId) {
  8068. await Promise.allSettled([streamController.startCall && streamController.startCall.promise, streamController.pullCall && streamController.pullCall.promise, streamController.cancelCall && streamController.cancelCall.promise]);
  8069. delete this.streamControllers[streamId];
  8070. }
  8071. destroy() {
  8072. this.comObj.removeEventListener("message", this._onComObjOnMessage);
  8073. }
  8074. }
  8075. exports.MessageHandler = MessageHandler;
  8076. /***/ }),
  8077. /* 17 */
  8078. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  8079. Object.defineProperty(exports, "__esModule", ({
  8080. value: true
  8081. }));
  8082. exports.Metadata = void 0;
  8083. var _util = __w_pdfjs_require__(1);
  8084. class Metadata {
  8085. #metadataMap;
  8086. #data;
  8087. constructor({
  8088. parsedData,
  8089. rawData
  8090. }) {
  8091. this.#metadataMap = parsedData;
  8092. this.#data = rawData;
  8093. }
  8094. getRaw() {
  8095. return this.#data;
  8096. }
  8097. get(name) {
  8098. return this.#metadataMap.get(name) ?? null;
  8099. }
  8100. getAll() {
  8101. return (0, _util.objectFromMap)(this.#metadataMap);
  8102. }
  8103. has(name) {
  8104. return this.#metadataMap.has(name);
  8105. }
  8106. }
  8107. exports.Metadata = Metadata;
  8108. /***/ }),
  8109. /* 18 */
  8110. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  8111. Object.defineProperty(exports, "__esModule", ({
  8112. value: true
  8113. }));
  8114. exports.OptionalContentConfig = void 0;
  8115. var _util = __w_pdfjs_require__(1);
  8116. const INTERNAL = Symbol("INTERNAL");
  8117. class OptionalContentGroup {
  8118. #visible = true;
  8119. constructor(name, intent) {
  8120. this.name = name;
  8121. this.intent = intent;
  8122. }
  8123. get visible() {
  8124. return this.#visible;
  8125. }
  8126. _setVisible(internal, visible) {
  8127. if (internal !== INTERNAL) {
  8128. (0, _util.unreachable)("Internal method `_setVisible` called.");
  8129. }
  8130. this.#visible = visible;
  8131. }
  8132. }
  8133. class OptionalContentConfig {
  8134. #cachedHasInitialVisibility = true;
  8135. #groups = new Map();
  8136. #initialVisibility = null;
  8137. #order = null;
  8138. constructor(data) {
  8139. this.name = null;
  8140. this.creator = null;
  8141. if (data === null) {
  8142. return;
  8143. }
  8144. this.name = data.name;
  8145. this.creator = data.creator;
  8146. this.#order = data.order;
  8147. for (const group of data.groups) {
  8148. this.#groups.set(group.id, new OptionalContentGroup(group.name, group.intent));
  8149. }
  8150. if (data.baseState === "OFF") {
  8151. for (const group of this.#groups.values()) {
  8152. group._setVisible(INTERNAL, false);
  8153. }
  8154. }
  8155. for (const on of data.on) {
  8156. this.#groups.get(on)._setVisible(INTERNAL, true);
  8157. }
  8158. for (const off of data.off) {
  8159. this.#groups.get(off)._setVisible(INTERNAL, false);
  8160. }
  8161. this.#initialVisibility = new Map();
  8162. for (const [id, group] of this.#groups) {
  8163. this.#initialVisibility.set(id, group.visible);
  8164. }
  8165. }
  8166. #evaluateVisibilityExpression(array) {
  8167. const length = array.length;
  8168. if (length < 2) {
  8169. return true;
  8170. }
  8171. const operator = array[0];
  8172. for (let i = 1; i < length; i++) {
  8173. const element = array[i];
  8174. let state;
  8175. if (Array.isArray(element)) {
  8176. state = this.#evaluateVisibilityExpression(element);
  8177. } else if (this.#groups.has(element)) {
  8178. state = this.#groups.get(element).visible;
  8179. } else {
  8180. (0, _util.warn)(`Optional content group not found: ${element}`);
  8181. return true;
  8182. }
  8183. switch (operator) {
  8184. case "And":
  8185. if (!state) {
  8186. return false;
  8187. }
  8188. break;
  8189. case "Or":
  8190. if (state) {
  8191. return true;
  8192. }
  8193. break;
  8194. case "Not":
  8195. return !state;
  8196. default:
  8197. return true;
  8198. }
  8199. }
  8200. return operator === "And";
  8201. }
  8202. isVisible(group) {
  8203. if (this.#groups.size === 0) {
  8204. return true;
  8205. }
  8206. if (!group) {
  8207. (0, _util.warn)("Optional content group not defined.");
  8208. return true;
  8209. }
  8210. if (group.type === "OCG") {
  8211. if (!this.#groups.has(group.id)) {
  8212. (0, _util.warn)(`Optional content group not found: ${group.id}`);
  8213. return true;
  8214. }
  8215. return this.#groups.get(group.id).visible;
  8216. } else if (group.type === "OCMD") {
  8217. if (group.expression) {
  8218. return this.#evaluateVisibilityExpression(group.expression);
  8219. }
  8220. if (!group.policy || group.policy === "AnyOn") {
  8221. for (const id of group.ids) {
  8222. if (!this.#groups.has(id)) {
  8223. (0, _util.warn)(`Optional content group not found: ${id}`);
  8224. return true;
  8225. }
  8226. if (this.#groups.get(id).visible) {
  8227. return true;
  8228. }
  8229. }
  8230. return false;
  8231. } else if (group.policy === "AllOn") {
  8232. for (const id of group.ids) {
  8233. if (!this.#groups.has(id)) {
  8234. (0, _util.warn)(`Optional content group not found: ${id}`);
  8235. return true;
  8236. }
  8237. if (!this.#groups.get(id).visible) {
  8238. return false;
  8239. }
  8240. }
  8241. return true;
  8242. } else if (group.policy === "AnyOff") {
  8243. for (const id of group.ids) {
  8244. if (!this.#groups.has(id)) {
  8245. (0, _util.warn)(`Optional content group not found: ${id}`);
  8246. return true;
  8247. }
  8248. if (!this.#groups.get(id).visible) {
  8249. return true;
  8250. }
  8251. }
  8252. return false;
  8253. } else if (group.policy === "AllOff") {
  8254. for (const id of group.ids) {
  8255. if (!this.#groups.has(id)) {
  8256. (0, _util.warn)(`Optional content group not found: ${id}`);
  8257. return true;
  8258. }
  8259. if (this.#groups.get(id).visible) {
  8260. return false;
  8261. }
  8262. }
  8263. return true;
  8264. }
  8265. (0, _util.warn)(`Unknown optional content policy ${group.policy}.`);
  8266. return true;
  8267. }
  8268. (0, _util.warn)(`Unknown group type ${group.type}.`);
  8269. return true;
  8270. }
  8271. setVisibility(id, visible = true) {
  8272. if (!this.#groups.has(id)) {
  8273. (0, _util.warn)(`Optional content group not found: ${id}`);
  8274. return;
  8275. }
  8276. this.#groups.get(id)._setVisible(INTERNAL, !!visible);
  8277. this.#cachedHasInitialVisibility = null;
  8278. }
  8279. get hasInitialVisibility() {
  8280. if (this.#cachedHasInitialVisibility !== null) {
  8281. return this.#cachedHasInitialVisibility;
  8282. }
  8283. for (const [id, group] of this.#groups) {
  8284. const visible = this.#initialVisibility.get(id);
  8285. if (group.visible !== visible) {
  8286. return this.#cachedHasInitialVisibility = false;
  8287. }
  8288. }
  8289. return this.#cachedHasInitialVisibility = true;
  8290. }
  8291. getOrder() {
  8292. if (!this.#groups.size) {
  8293. return null;
  8294. }
  8295. if (this.#order) {
  8296. return this.#order.slice();
  8297. }
  8298. return [...this.#groups.keys()];
  8299. }
  8300. getGroups() {
  8301. return this.#groups.size > 0 ? (0, _util.objectFromMap)(this.#groups) : null;
  8302. }
  8303. getGroup(id) {
  8304. return this.#groups.get(id) || null;
  8305. }
  8306. }
  8307. exports.OptionalContentConfig = OptionalContentConfig;
  8308. /***/ }),
  8309. /* 19 */
  8310. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  8311. Object.defineProperty(exports, "__esModule", ({
  8312. value: true
  8313. }));
  8314. exports.PDFDataTransportStream = void 0;
  8315. var _util = __w_pdfjs_require__(1);
  8316. var _display_utils = __w_pdfjs_require__(8);
  8317. class PDFDataTransportStream {
  8318. constructor(params, pdfDataRangeTransport) {
  8319. (0, _util.assert)(pdfDataRangeTransport, 'PDFDataTransportStream - missing required "pdfDataRangeTransport" argument.');
  8320. this._queuedChunks = [];
  8321. this._progressiveDone = params.progressiveDone || false;
  8322. this._contentDispositionFilename = params.contentDispositionFilename || null;
  8323. const initialData = params.initialData;
  8324. if (initialData?.length > 0) {
  8325. const buffer = new Uint8Array(initialData).buffer;
  8326. this._queuedChunks.push(buffer);
  8327. }
  8328. this._pdfDataRangeTransport = pdfDataRangeTransport;
  8329. this._isStreamingSupported = !params.disableStream;
  8330. this._isRangeSupported = !params.disableRange;
  8331. this._contentLength = params.length;
  8332. this._fullRequestReader = null;
  8333. this._rangeReaders = [];
  8334. this._pdfDataRangeTransport.addRangeListener((begin, chunk) => {
  8335. this._onReceiveData({
  8336. begin,
  8337. chunk
  8338. });
  8339. });
  8340. this._pdfDataRangeTransport.addProgressListener((loaded, total) => {
  8341. this._onProgress({
  8342. loaded,
  8343. total
  8344. });
  8345. });
  8346. this._pdfDataRangeTransport.addProgressiveReadListener(chunk => {
  8347. this._onReceiveData({
  8348. chunk
  8349. });
  8350. });
  8351. this._pdfDataRangeTransport.addProgressiveDoneListener(() => {
  8352. this._onProgressiveDone();
  8353. });
  8354. this._pdfDataRangeTransport.transportReady();
  8355. }
  8356. _onReceiveData(args) {
  8357. const buffer = new Uint8Array(args.chunk).buffer;
  8358. if (args.begin === undefined) {
  8359. if (this._fullRequestReader) {
  8360. this._fullRequestReader._enqueue(buffer);
  8361. } else {
  8362. this._queuedChunks.push(buffer);
  8363. }
  8364. } else {
  8365. const found = this._rangeReaders.some(function (rangeReader) {
  8366. if (rangeReader._begin !== args.begin) {
  8367. return false;
  8368. }
  8369. rangeReader._enqueue(buffer);
  8370. return true;
  8371. });
  8372. (0, _util.assert)(found, "_onReceiveData - no `PDFDataTransportStreamRangeReader` instance found.");
  8373. }
  8374. }
  8375. get _progressiveDataLength() {
  8376. return this._fullRequestReader?._loaded ?? 0;
  8377. }
  8378. _onProgress(evt) {
  8379. if (evt.total === undefined) {
  8380. const firstReader = this._rangeReaders[0];
  8381. if (firstReader?.onProgress) {
  8382. firstReader.onProgress({
  8383. loaded: evt.loaded
  8384. });
  8385. }
  8386. } else {
  8387. const fullReader = this._fullRequestReader;
  8388. if (fullReader?.onProgress) {
  8389. fullReader.onProgress({
  8390. loaded: evt.loaded,
  8391. total: evt.total
  8392. });
  8393. }
  8394. }
  8395. }
  8396. _onProgressiveDone() {
  8397. if (this._fullRequestReader) {
  8398. this._fullRequestReader.progressiveDone();
  8399. }
  8400. this._progressiveDone = true;
  8401. }
  8402. _removeRangeReader(reader) {
  8403. const i = this._rangeReaders.indexOf(reader);
  8404. if (i >= 0) {
  8405. this._rangeReaders.splice(i, 1);
  8406. }
  8407. }
  8408. getFullReader() {
  8409. (0, _util.assert)(!this._fullRequestReader, "PDFDataTransportStream.getFullReader can only be called once.");
  8410. const queuedChunks = this._queuedChunks;
  8411. this._queuedChunks = null;
  8412. return new PDFDataTransportStreamReader(this, queuedChunks, this._progressiveDone, this._contentDispositionFilename);
  8413. }
  8414. getRangeReader(begin, end) {
  8415. if (end <= this._progressiveDataLength) {
  8416. return null;
  8417. }
  8418. const reader = new PDFDataTransportStreamRangeReader(this, begin, end);
  8419. this._pdfDataRangeTransport.requestDataRange(begin, end);
  8420. this._rangeReaders.push(reader);
  8421. return reader;
  8422. }
  8423. cancelAllRequests(reason) {
  8424. if (this._fullRequestReader) {
  8425. this._fullRequestReader.cancel(reason);
  8426. }
  8427. for (const reader of this._rangeReaders.slice(0)) {
  8428. reader.cancel(reason);
  8429. }
  8430. this._pdfDataRangeTransport.abort();
  8431. }
  8432. }
  8433. exports.PDFDataTransportStream = PDFDataTransportStream;
  8434. class PDFDataTransportStreamReader {
  8435. constructor(stream, queuedChunks, progressiveDone = false, contentDispositionFilename = null) {
  8436. this._stream = stream;
  8437. this._done = progressiveDone || false;
  8438. this._filename = (0, _display_utils.isPdfFile)(contentDispositionFilename) ? contentDispositionFilename : null;
  8439. this._queuedChunks = queuedChunks || [];
  8440. this._loaded = 0;
  8441. for (const chunk of this._queuedChunks) {
  8442. this._loaded += chunk.byteLength;
  8443. }
  8444. this._requests = [];
  8445. this._headersReady = Promise.resolve();
  8446. stream._fullRequestReader = this;
  8447. this.onProgress = null;
  8448. }
  8449. _enqueue(chunk) {
  8450. if (this._done) {
  8451. return;
  8452. }
  8453. if (this._requests.length > 0) {
  8454. const requestCapability = this._requests.shift();
  8455. requestCapability.resolve({
  8456. value: chunk,
  8457. done: false
  8458. });
  8459. } else {
  8460. this._queuedChunks.push(chunk);
  8461. }
  8462. this._loaded += chunk.byteLength;
  8463. }
  8464. get headersReady() {
  8465. return this._headersReady;
  8466. }
  8467. get filename() {
  8468. return this._filename;
  8469. }
  8470. get isRangeSupported() {
  8471. return this._stream._isRangeSupported;
  8472. }
  8473. get isStreamingSupported() {
  8474. return this._stream._isStreamingSupported;
  8475. }
  8476. get contentLength() {
  8477. return this._stream._contentLength;
  8478. }
  8479. async read() {
  8480. if (this._queuedChunks.length > 0) {
  8481. const chunk = this._queuedChunks.shift();
  8482. return {
  8483. value: chunk,
  8484. done: false
  8485. };
  8486. }
  8487. if (this._done) {
  8488. return {
  8489. value: undefined,
  8490. done: true
  8491. };
  8492. }
  8493. const requestCapability = (0, _util.createPromiseCapability)();
  8494. this._requests.push(requestCapability);
  8495. return requestCapability.promise;
  8496. }
  8497. cancel(reason) {
  8498. this._done = true;
  8499. for (const requestCapability of this._requests) {
  8500. requestCapability.resolve({
  8501. value: undefined,
  8502. done: true
  8503. });
  8504. }
  8505. this._requests.length = 0;
  8506. }
  8507. progressiveDone() {
  8508. if (this._done) {
  8509. return;
  8510. }
  8511. this._done = true;
  8512. }
  8513. }
  8514. class PDFDataTransportStreamRangeReader {
  8515. constructor(stream, begin, end) {
  8516. this._stream = stream;
  8517. this._begin = begin;
  8518. this._end = end;
  8519. this._queuedChunk = null;
  8520. this._requests = [];
  8521. this._done = false;
  8522. this.onProgress = null;
  8523. }
  8524. _enqueue(chunk) {
  8525. if (this._done) {
  8526. return;
  8527. }
  8528. if (this._requests.length === 0) {
  8529. this._queuedChunk = chunk;
  8530. } else {
  8531. const requestsCapability = this._requests.shift();
  8532. requestsCapability.resolve({
  8533. value: chunk,
  8534. done: false
  8535. });
  8536. for (const requestCapability of this._requests) {
  8537. requestCapability.resolve({
  8538. value: undefined,
  8539. done: true
  8540. });
  8541. }
  8542. this._requests.length = 0;
  8543. }
  8544. this._done = true;
  8545. this._stream._removeRangeReader(this);
  8546. }
  8547. get isStreamingSupported() {
  8548. return false;
  8549. }
  8550. async read() {
  8551. if (this._queuedChunk) {
  8552. const chunk = this._queuedChunk;
  8553. this._queuedChunk = null;
  8554. return {
  8555. value: chunk,
  8556. done: false
  8557. };
  8558. }
  8559. if (this._done) {
  8560. return {
  8561. value: undefined,
  8562. done: true
  8563. };
  8564. }
  8565. const requestCapability = (0, _util.createPromiseCapability)();
  8566. this._requests.push(requestCapability);
  8567. return requestCapability.promise;
  8568. }
  8569. cancel(reason) {
  8570. this._done = true;
  8571. for (const requestCapability of this._requests) {
  8572. requestCapability.resolve({
  8573. value: undefined,
  8574. done: true
  8575. });
  8576. }
  8577. this._requests.length = 0;
  8578. this._stream._removeRangeReader(this);
  8579. }
  8580. }
  8581. /***/ }),
  8582. /* 20 */
  8583. /***/ ((__unused_webpack_module, exports) => {
  8584. Object.defineProperty(exports, "__esModule", ({
  8585. value: true
  8586. }));
  8587. exports.XfaText = void 0;
  8588. class XfaText {
  8589. static textContent(xfa) {
  8590. const items = [];
  8591. const output = {
  8592. items,
  8593. styles: Object.create(null)
  8594. };
  8595. function walk(node) {
  8596. if (!node) {
  8597. return;
  8598. }
  8599. let str = null;
  8600. const name = node.name;
  8601. if (name === "#text") {
  8602. str = node.value;
  8603. } else if (!XfaText.shouldBuildText(name)) {
  8604. return;
  8605. } else if (node?.attributes?.textContent) {
  8606. str = node.attributes.textContent;
  8607. } else if (node.value) {
  8608. str = node.value;
  8609. }
  8610. if (str !== null) {
  8611. items.push({
  8612. str
  8613. });
  8614. }
  8615. if (!node.children) {
  8616. return;
  8617. }
  8618. for (const child of node.children) {
  8619. walk(child);
  8620. }
  8621. }
  8622. walk(xfa);
  8623. return output;
  8624. }
  8625. static shouldBuildText(name) {
  8626. return !(name === "textarea" || name === "input" || name === "option" || name === "select");
  8627. }
  8628. }
  8629. exports.XfaText = XfaText;
  8630. /***/ }),
  8631. /* 21 */
  8632. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  8633. Object.defineProperty(exports, "__esModule", ({
  8634. value: true
  8635. }));
  8636. exports.NodeStandardFontDataFactory = exports.NodeCanvasFactory = exports.NodeCMapReaderFactory = void 0;
  8637. var _base_factory = __w_pdfjs_require__(9);
  8638. ;
  8639. const fetchData = function (url) {
  8640. return new Promise((resolve, reject) => {
  8641. const fs = require("fs");
  8642. fs.readFile(url, (error, data) => {
  8643. if (error || !data) {
  8644. reject(new Error(error));
  8645. return;
  8646. }
  8647. resolve(new Uint8Array(data));
  8648. });
  8649. });
  8650. };
  8651. class NodeCanvasFactory extends _base_factory.BaseCanvasFactory {
  8652. _createCanvas(width, height) {
  8653. const Canvas = require("canvas");
  8654. return Canvas.createCanvas(width, height);
  8655. }
  8656. }
  8657. exports.NodeCanvasFactory = NodeCanvasFactory;
  8658. class NodeCMapReaderFactory extends _base_factory.BaseCMapReaderFactory {
  8659. _fetchData(url, compressionType) {
  8660. return fetchData(url).then(data => {
  8661. return {
  8662. cMapData: data,
  8663. compressionType
  8664. };
  8665. });
  8666. }
  8667. }
  8668. exports.NodeCMapReaderFactory = NodeCMapReaderFactory;
  8669. class NodeStandardFontDataFactory extends _base_factory.BaseStandardFontDataFactory {
  8670. _fetchData(url) {
  8671. return fetchData(url);
  8672. }
  8673. }
  8674. exports.NodeStandardFontDataFactory = NodeStandardFontDataFactory;
  8675. /***/ }),
  8676. /* 22 */
  8677. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  8678. Object.defineProperty(exports, "__esModule", ({
  8679. value: true
  8680. }));
  8681. exports.AnnotationEditorLayer = void 0;
  8682. var _tools = __w_pdfjs_require__(7);
  8683. var _util = __w_pdfjs_require__(1);
  8684. var _freetext = __w_pdfjs_require__(23);
  8685. var _ink = __w_pdfjs_require__(24);
  8686. class AnnotationEditorLayer {
  8687. #accessibilityManager;
  8688. #allowClick = false;
  8689. #boundPointerup = this.pointerup.bind(this);
  8690. #boundPointerdown = this.pointerdown.bind(this);
  8691. #editors = new Map();
  8692. #hadPointerDown = false;
  8693. #isCleaningUp = false;
  8694. #uiManager;
  8695. static _initialized = false;
  8696. constructor(options) {
  8697. if (!AnnotationEditorLayer._initialized) {
  8698. AnnotationEditorLayer._initialized = true;
  8699. _freetext.FreeTextEditor.initialize(options.l10n);
  8700. _ink.InkEditor.initialize(options.l10n);
  8701. options.uiManager.registerEditorTypes([_freetext.FreeTextEditor, _ink.InkEditor]);
  8702. }
  8703. this.#uiManager = options.uiManager;
  8704. this.annotationStorage = options.annotationStorage;
  8705. this.pageIndex = options.pageIndex;
  8706. this.div = options.div;
  8707. this.#accessibilityManager = options.accessibilityManager;
  8708. this.#uiManager.addLayer(this);
  8709. }
  8710. updateToolbar(mode) {
  8711. this.#uiManager.updateToolbar(mode);
  8712. }
  8713. updateMode(mode = this.#uiManager.getMode()) {
  8714. this.#cleanup();
  8715. if (mode === _util.AnnotationEditorType.INK) {
  8716. this.addInkEditorIfNeeded(false);
  8717. this.disableClick();
  8718. } else {
  8719. this.enableClick();
  8720. }
  8721. this.#uiManager.unselectAll();
  8722. }
  8723. addInkEditorIfNeeded(isCommitting) {
  8724. if (!isCommitting && this.#uiManager.getMode() !== _util.AnnotationEditorType.INK) {
  8725. return;
  8726. }
  8727. if (!isCommitting) {
  8728. for (const editor of this.#editors.values()) {
  8729. if (editor.isEmpty()) {
  8730. editor.setInBackground();
  8731. return;
  8732. }
  8733. }
  8734. }
  8735. const editor = this.#createAndAddNewEditor({
  8736. offsetX: 0,
  8737. offsetY: 0
  8738. });
  8739. editor.setInBackground();
  8740. }
  8741. setEditingState(isEditing) {
  8742. this.#uiManager.setEditingState(isEditing);
  8743. }
  8744. addCommands(params) {
  8745. this.#uiManager.addCommands(params);
  8746. }
  8747. enable() {
  8748. this.div.style.pointerEvents = "auto";
  8749. for (const editor of this.#editors.values()) {
  8750. editor.enableEditing();
  8751. }
  8752. }
  8753. disable() {
  8754. this.div.style.pointerEvents = "none";
  8755. for (const editor of this.#editors.values()) {
  8756. editor.disableEditing();
  8757. }
  8758. }
  8759. setActiveEditor(editor) {
  8760. const currentActive = this.#uiManager.getActive();
  8761. if (currentActive === editor) {
  8762. return;
  8763. }
  8764. this.#uiManager.setActiveEditor(editor);
  8765. }
  8766. enableClick() {
  8767. this.div.addEventListener("pointerdown", this.#boundPointerdown);
  8768. this.div.addEventListener("pointerup", this.#boundPointerup);
  8769. }
  8770. disableClick() {
  8771. this.div.removeEventListener("pointerdown", this.#boundPointerdown);
  8772. this.div.removeEventListener("pointerup", this.#boundPointerup);
  8773. }
  8774. attach(editor) {
  8775. this.#editors.set(editor.id, editor);
  8776. }
  8777. detach(editor) {
  8778. this.#editors.delete(editor.id);
  8779. this.#accessibilityManager?.removePointerInTextLayer(editor.contentDiv);
  8780. }
  8781. remove(editor) {
  8782. this.#uiManager.removeEditor(editor);
  8783. this.detach(editor);
  8784. this.annotationStorage.remove(editor.id);
  8785. editor.div.style.display = "none";
  8786. setTimeout(() => {
  8787. editor.div.style.display = "";
  8788. editor.div.remove();
  8789. editor.isAttachedToDOM = false;
  8790. if (document.activeElement === document.body) {
  8791. this.#uiManager.focusMainContainer();
  8792. }
  8793. }, 0);
  8794. if (!this.#isCleaningUp) {
  8795. this.addInkEditorIfNeeded(false);
  8796. }
  8797. }
  8798. #changeParent(editor) {
  8799. if (editor.parent === this) {
  8800. return;
  8801. }
  8802. this.attach(editor);
  8803. editor.pageIndex = this.pageIndex;
  8804. editor.parent?.detach(editor);
  8805. editor.parent = this;
  8806. if (editor.div && editor.isAttachedToDOM) {
  8807. editor.div.remove();
  8808. this.div.append(editor.div);
  8809. }
  8810. }
  8811. add(editor) {
  8812. this.#changeParent(editor);
  8813. this.#uiManager.addEditor(editor);
  8814. this.attach(editor);
  8815. if (!editor.isAttachedToDOM) {
  8816. const div = editor.render();
  8817. this.div.append(div);
  8818. editor.isAttachedToDOM = true;
  8819. }
  8820. this.moveEditorInDOM(editor);
  8821. editor.onceAdded();
  8822. this.addToAnnotationStorage(editor);
  8823. }
  8824. moveEditorInDOM(editor) {
  8825. this.#accessibilityManager?.moveElementInDOM(this.div, editor.div, editor.contentDiv, true);
  8826. }
  8827. addToAnnotationStorage(editor) {
  8828. if (!editor.isEmpty() && !this.annotationStorage.has(editor.id)) {
  8829. this.annotationStorage.setValue(editor.id, editor);
  8830. }
  8831. }
  8832. addOrRebuild(editor) {
  8833. if (editor.needsToBeRebuilt()) {
  8834. editor.rebuild();
  8835. } else {
  8836. this.add(editor);
  8837. }
  8838. }
  8839. addANewEditor(editor) {
  8840. const cmd = () => {
  8841. this.addOrRebuild(editor);
  8842. };
  8843. const undo = () => {
  8844. editor.remove();
  8845. };
  8846. this.addCommands({
  8847. cmd,
  8848. undo,
  8849. mustExec: true
  8850. });
  8851. }
  8852. addUndoableEditor(editor) {
  8853. const cmd = () => {
  8854. this.addOrRebuild(editor);
  8855. };
  8856. const undo = () => {
  8857. editor.remove();
  8858. };
  8859. this.addCommands({
  8860. cmd,
  8861. undo,
  8862. mustExec: false
  8863. });
  8864. }
  8865. getNextId() {
  8866. return this.#uiManager.getId();
  8867. }
  8868. #createNewEditor(params) {
  8869. switch (this.#uiManager.getMode()) {
  8870. case _util.AnnotationEditorType.FREETEXT:
  8871. return new _freetext.FreeTextEditor(params);
  8872. case _util.AnnotationEditorType.INK:
  8873. return new _ink.InkEditor(params);
  8874. }
  8875. return null;
  8876. }
  8877. deserialize(data) {
  8878. switch (data.annotationType) {
  8879. case _util.AnnotationEditorType.FREETEXT:
  8880. return _freetext.FreeTextEditor.deserialize(data, this);
  8881. case _util.AnnotationEditorType.INK:
  8882. return _ink.InkEditor.deserialize(data, this);
  8883. }
  8884. return null;
  8885. }
  8886. #createAndAddNewEditor(event) {
  8887. const id = this.getNextId();
  8888. const editor = this.#createNewEditor({
  8889. parent: this,
  8890. id,
  8891. x: event.offsetX,
  8892. y: event.offsetY
  8893. });
  8894. if (editor) {
  8895. this.add(editor);
  8896. }
  8897. return editor;
  8898. }
  8899. setSelected(editor) {
  8900. this.#uiManager.setSelected(editor);
  8901. }
  8902. toggleSelected(editor) {
  8903. this.#uiManager.toggleSelected(editor);
  8904. }
  8905. isSelected(editor) {
  8906. return this.#uiManager.isSelected(editor);
  8907. }
  8908. unselect(editor) {
  8909. this.#uiManager.unselect(editor);
  8910. }
  8911. pointerup(event) {
  8912. const isMac = _tools.KeyboardManager.platform.isMac;
  8913. if (event.button !== 0 || event.ctrlKey && isMac) {
  8914. return;
  8915. }
  8916. if (event.target !== this.div) {
  8917. return;
  8918. }
  8919. if (!this.#hadPointerDown) {
  8920. return;
  8921. }
  8922. this.#hadPointerDown = false;
  8923. if (!this.#allowClick) {
  8924. this.#allowClick = true;
  8925. return;
  8926. }
  8927. this.#createAndAddNewEditor(event);
  8928. }
  8929. pointerdown(event) {
  8930. const isMac = _tools.KeyboardManager.platform.isMac;
  8931. if (event.button !== 0 || event.ctrlKey && isMac) {
  8932. return;
  8933. }
  8934. if (event.target !== this.div) {
  8935. return;
  8936. }
  8937. this.#hadPointerDown = true;
  8938. const editor = this.#uiManager.getActive();
  8939. this.#allowClick = !editor || editor.isEmpty();
  8940. }
  8941. drop(event) {
  8942. const id = event.dataTransfer.getData("text/plain");
  8943. const editor = this.#uiManager.getEditor(id);
  8944. if (!editor) {
  8945. return;
  8946. }
  8947. event.preventDefault();
  8948. event.dataTransfer.dropEffect = "move";
  8949. this.#changeParent(editor);
  8950. const rect = this.div.getBoundingClientRect();
  8951. const endX = event.clientX - rect.x;
  8952. const endY = event.clientY - rect.y;
  8953. editor.translate(endX - editor.startX, endY - editor.startY);
  8954. this.moveEditorInDOM(editor);
  8955. editor.div.focus();
  8956. }
  8957. dragover(event) {
  8958. event.preventDefault();
  8959. }
  8960. destroy() {
  8961. if (this.#uiManager.getActive()?.parent === this) {
  8962. this.#uiManager.setActiveEditor(null);
  8963. }
  8964. for (const editor of this.#editors.values()) {
  8965. this.#accessibilityManager?.removePointerInTextLayer(editor.contentDiv);
  8966. editor.isAttachedToDOM = false;
  8967. editor.div.remove();
  8968. editor.parent = null;
  8969. }
  8970. this.div = null;
  8971. this.#editors.clear();
  8972. this.#uiManager.removeLayer(this);
  8973. }
  8974. #cleanup() {
  8975. this.#isCleaningUp = true;
  8976. for (const editor of this.#editors.values()) {
  8977. if (editor.isEmpty()) {
  8978. editor.remove();
  8979. }
  8980. }
  8981. this.#isCleaningUp = false;
  8982. }
  8983. render(parameters) {
  8984. this.viewport = parameters.viewport;
  8985. (0, _tools.bindEvents)(this, this.div, ["dragover", "drop"]);
  8986. this.setDimensions();
  8987. for (const editor of this.#uiManager.getEditors(this.pageIndex)) {
  8988. this.add(editor);
  8989. }
  8990. this.updateMode();
  8991. }
  8992. update(parameters) {
  8993. this.viewport = parameters.viewport;
  8994. this.setDimensions();
  8995. this.updateMode();
  8996. }
  8997. get scaleFactor() {
  8998. return this.viewport.scale;
  8999. }
  9000. get pageDimensions() {
  9001. const [pageLLx, pageLLy, pageURx, pageURy] = this.viewport.viewBox;
  9002. const width = pageURx - pageLLx;
  9003. const height = pageURy - pageLLy;
  9004. return [width, height];
  9005. }
  9006. get viewportBaseDimensions() {
  9007. const {
  9008. width,
  9009. height,
  9010. rotation
  9011. } = this.viewport;
  9012. return rotation % 180 === 0 ? [width, height] : [height, width];
  9013. }
  9014. setDimensions() {
  9015. const {
  9016. width,
  9017. height,
  9018. rotation
  9019. } = this.viewport;
  9020. const flipOrientation = rotation % 180 !== 0,
  9021. widthStr = Math.floor(width) + "px",
  9022. heightStr = Math.floor(height) + "px";
  9023. this.div.style.width = flipOrientation ? heightStr : widthStr;
  9024. this.div.style.height = flipOrientation ? widthStr : heightStr;
  9025. this.div.setAttribute("data-main-rotation", rotation);
  9026. }
  9027. }
  9028. exports.AnnotationEditorLayer = AnnotationEditorLayer;
  9029. /***/ }),
  9030. /* 23 */
  9031. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  9032. Object.defineProperty(exports, "__esModule", ({
  9033. value: true
  9034. }));
  9035. exports.FreeTextEditor = void 0;
  9036. var _util = __w_pdfjs_require__(1);
  9037. var _tools = __w_pdfjs_require__(7);
  9038. var _editor = __w_pdfjs_require__(6);
  9039. class FreeTextEditor extends _editor.AnnotationEditor {
  9040. #boundEditorDivBlur = this.editorDivBlur.bind(this);
  9041. #boundEditorDivFocus = this.editorDivFocus.bind(this);
  9042. #boundEditorDivKeydown = this.editorDivKeydown.bind(this);
  9043. #color;
  9044. #content = "";
  9045. #hasAlreadyBeenCommitted = false;
  9046. #fontSize;
  9047. static _freeTextDefaultContent = "";
  9048. static _l10nPromise;
  9049. static _internalPadding = 0;
  9050. static _defaultColor = null;
  9051. static _defaultFontSize = 10;
  9052. static _keyboardManager = new _tools.KeyboardManager([[["ctrl+Enter", "mac+meta+Enter", "Escape", "mac+Escape"], FreeTextEditor.prototype.commitOrRemove]]);
  9053. static _type = "freetext";
  9054. constructor(params) {
  9055. super({ ...params,
  9056. name: "freeTextEditor"
  9057. });
  9058. this.#color = params.color || FreeTextEditor._defaultColor || _editor.AnnotationEditor._defaultLineColor;
  9059. this.#fontSize = params.fontSize || FreeTextEditor._defaultFontSize;
  9060. }
  9061. static initialize(l10n) {
  9062. this._l10nPromise = new Map(["free_text_default_content", "editor_free_text_aria_label"].map(str => [str, l10n.get(str)]));
  9063. const style = getComputedStyle(document.documentElement);
  9064. this._internalPadding = parseFloat(style.getPropertyValue("--freetext-padding"));
  9065. }
  9066. static updateDefaultParams(type, value) {
  9067. switch (type) {
  9068. case _util.AnnotationEditorParamsType.FREETEXT_SIZE:
  9069. FreeTextEditor._defaultFontSize = value;
  9070. break;
  9071. case _util.AnnotationEditorParamsType.FREETEXT_COLOR:
  9072. FreeTextEditor._defaultColor = value;
  9073. break;
  9074. }
  9075. }
  9076. updateParams(type, value) {
  9077. switch (type) {
  9078. case _util.AnnotationEditorParamsType.FREETEXT_SIZE:
  9079. this.#updateFontSize(value);
  9080. break;
  9081. case _util.AnnotationEditorParamsType.FREETEXT_COLOR:
  9082. this.#updateColor(value);
  9083. break;
  9084. }
  9085. }
  9086. static get defaultPropertiesToUpdate() {
  9087. return [[_util.AnnotationEditorParamsType.FREETEXT_SIZE, FreeTextEditor._defaultFontSize], [_util.AnnotationEditorParamsType.FREETEXT_COLOR, FreeTextEditor._defaultColor || _editor.AnnotationEditor._defaultLineColor]];
  9088. }
  9089. get propertiesToUpdate() {
  9090. return [[_util.AnnotationEditorParamsType.FREETEXT_SIZE, this.#fontSize], [_util.AnnotationEditorParamsType.FREETEXT_COLOR, this.#color]];
  9091. }
  9092. #updateFontSize(fontSize) {
  9093. const setFontsize = size => {
  9094. this.editorDiv.style.fontSize = `calc(${size}px * var(--scale-factor))`;
  9095. this.translate(0, -(size - this.#fontSize) * this.parent.scaleFactor);
  9096. this.#fontSize = size;
  9097. this.#setEditorDimensions();
  9098. };
  9099. const savedFontsize = this.#fontSize;
  9100. this.parent.addCommands({
  9101. cmd: () => {
  9102. setFontsize(fontSize);
  9103. },
  9104. undo: () => {
  9105. setFontsize(savedFontsize);
  9106. },
  9107. mustExec: true,
  9108. type: _util.AnnotationEditorParamsType.FREETEXT_SIZE,
  9109. overwriteIfSameType: true,
  9110. keepUndo: true
  9111. });
  9112. }
  9113. #updateColor(color) {
  9114. const savedColor = this.#color;
  9115. this.parent.addCommands({
  9116. cmd: () => {
  9117. this.#color = color;
  9118. this.editorDiv.style.color = color;
  9119. },
  9120. undo: () => {
  9121. this.#color = savedColor;
  9122. this.editorDiv.style.color = savedColor;
  9123. },
  9124. mustExec: true,
  9125. type: _util.AnnotationEditorParamsType.FREETEXT_COLOR,
  9126. overwriteIfSameType: true,
  9127. keepUndo: true
  9128. });
  9129. }
  9130. getInitialTranslation() {
  9131. return [-FreeTextEditor._internalPadding * this.parent.scaleFactor, -(FreeTextEditor._internalPadding + this.#fontSize) * this.parent.scaleFactor];
  9132. }
  9133. rebuild() {
  9134. super.rebuild();
  9135. if (this.div === null) {
  9136. return;
  9137. }
  9138. if (!this.isAttachedToDOM) {
  9139. this.parent.add(this);
  9140. }
  9141. }
  9142. enableEditMode() {
  9143. if (this.isInEditMode()) {
  9144. return;
  9145. }
  9146. this.parent.setEditingState(false);
  9147. this.parent.updateToolbar(_util.AnnotationEditorType.FREETEXT);
  9148. super.enableEditMode();
  9149. this.enableEditing();
  9150. this.overlayDiv.classList.remove("enabled");
  9151. this.editorDiv.contentEditable = true;
  9152. this.div.draggable = false;
  9153. this.editorDiv.addEventListener("keydown", this.#boundEditorDivKeydown);
  9154. this.editorDiv.addEventListener("focus", this.#boundEditorDivFocus);
  9155. this.editorDiv.addEventListener("blur", this.#boundEditorDivBlur);
  9156. }
  9157. disableEditMode() {
  9158. if (!this.isInEditMode()) {
  9159. return;
  9160. }
  9161. this.parent.setEditingState(true);
  9162. super.disableEditMode();
  9163. this.disableEditing();
  9164. this.overlayDiv.classList.add("enabled");
  9165. this.editorDiv.contentEditable = false;
  9166. this.div.draggable = true;
  9167. this.editorDiv.removeEventListener("keydown", this.#boundEditorDivKeydown);
  9168. this.editorDiv.removeEventListener("focus", this.#boundEditorDivFocus);
  9169. this.editorDiv.removeEventListener("blur", this.#boundEditorDivBlur);
  9170. this.div.focus();
  9171. this.isEditing = false;
  9172. }
  9173. focusin(event) {
  9174. super.focusin(event);
  9175. if (event.target !== this.editorDiv) {
  9176. this.editorDiv.focus();
  9177. }
  9178. }
  9179. onceAdded() {
  9180. if (this.width) {
  9181. return;
  9182. }
  9183. this.enableEditMode();
  9184. this.editorDiv.focus();
  9185. }
  9186. isEmpty() {
  9187. return !this.editorDiv || this.editorDiv.innerText.trim() === "";
  9188. }
  9189. remove() {
  9190. this.isEditing = false;
  9191. this.parent.setEditingState(true);
  9192. super.remove();
  9193. }
  9194. #extractText() {
  9195. const divs = this.editorDiv.getElementsByTagName("div");
  9196. if (divs.length === 0) {
  9197. return this.editorDiv.innerText;
  9198. }
  9199. const buffer = [];
  9200. for (let i = 0, ii = divs.length; i < ii; i++) {
  9201. const div = divs[i];
  9202. const first = div.firstChild;
  9203. if (first?.nodeName === "#text") {
  9204. buffer.push(first.data);
  9205. } else {
  9206. buffer.push("");
  9207. }
  9208. }
  9209. return buffer.join("\n");
  9210. }
  9211. #setEditorDimensions() {
  9212. const [parentWidth, parentHeight] = this.parent.viewportBaseDimensions;
  9213. const rect = this.div.getBoundingClientRect();
  9214. this.width = rect.width / parentWidth;
  9215. this.height = rect.height / parentHeight;
  9216. }
  9217. commit() {
  9218. super.commit();
  9219. if (!this.#hasAlreadyBeenCommitted) {
  9220. this.#hasAlreadyBeenCommitted = true;
  9221. this.parent.addUndoableEditor(this);
  9222. }
  9223. this.disableEditMode();
  9224. this.#content = this.#extractText().trimEnd();
  9225. this.#setEditorDimensions();
  9226. }
  9227. shouldGetKeyboardEvents() {
  9228. return this.isInEditMode();
  9229. }
  9230. dblclick(event) {
  9231. this.enableEditMode();
  9232. this.editorDiv.focus();
  9233. }
  9234. keydown(event) {
  9235. if (event.target === this.div && event.key === "Enter") {
  9236. this.enableEditMode();
  9237. this.editorDiv.focus();
  9238. }
  9239. }
  9240. editorDivKeydown(event) {
  9241. FreeTextEditor._keyboardManager.exec(this, event);
  9242. }
  9243. editorDivFocus(event) {
  9244. this.isEditing = true;
  9245. }
  9246. editorDivBlur(event) {
  9247. this.isEditing = false;
  9248. }
  9249. disableEditing() {
  9250. this.editorDiv.setAttribute("role", "comment");
  9251. this.editorDiv.removeAttribute("aria-multiline");
  9252. }
  9253. enableEditing() {
  9254. this.editorDiv.setAttribute("role", "textbox");
  9255. this.editorDiv.setAttribute("aria-multiline", true);
  9256. }
  9257. render() {
  9258. if (this.div) {
  9259. return this.div;
  9260. }
  9261. let baseX, baseY;
  9262. if (this.width) {
  9263. baseX = this.x;
  9264. baseY = this.y;
  9265. }
  9266. super.render();
  9267. this.editorDiv = document.createElement("div");
  9268. this.editorDiv.className = "internal";
  9269. this.editorDiv.setAttribute("id", `${this.id}-editor`);
  9270. this.enableEditing();
  9271. FreeTextEditor._l10nPromise.get("editor_free_text_aria_label").then(msg => this.editorDiv?.setAttribute("aria-label", msg));
  9272. FreeTextEditor._l10nPromise.get("free_text_default_content").then(msg => this.editorDiv?.setAttribute("default-content", msg));
  9273. this.editorDiv.contentEditable = true;
  9274. const {
  9275. style
  9276. } = this.editorDiv;
  9277. style.fontSize = `calc(${this.#fontSize}px * var(--scale-factor))`;
  9278. style.color = this.#color;
  9279. this.div.append(this.editorDiv);
  9280. this.overlayDiv = document.createElement("div");
  9281. this.overlayDiv.classList.add("overlay", "enabled");
  9282. this.div.append(this.overlayDiv);
  9283. (0, _tools.bindEvents)(this, this.div, ["dblclick", "keydown"]);
  9284. if (this.width) {
  9285. const [parentWidth, parentHeight] = this.parent.viewportBaseDimensions;
  9286. this.setAt(baseX * parentWidth, baseY * parentHeight, this.width * parentWidth, this.height * parentHeight);
  9287. for (const line of this.#content.split("\n")) {
  9288. const div = document.createElement("div");
  9289. div.append(line ? document.createTextNode(line) : document.createElement("br"));
  9290. this.editorDiv.append(div);
  9291. }
  9292. this.div.draggable = true;
  9293. this.editorDiv.contentEditable = false;
  9294. } else {
  9295. this.div.draggable = false;
  9296. this.editorDiv.contentEditable = true;
  9297. }
  9298. return this.div;
  9299. }
  9300. get contentDiv() {
  9301. return this.editorDiv;
  9302. }
  9303. static deserialize(data, parent) {
  9304. const editor = super.deserialize(data, parent);
  9305. editor.#fontSize = data.fontSize;
  9306. editor.#color = _util.Util.makeHexColor(...data.color);
  9307. editor.#content = data.value;
  9308. return editor;
  9309. }
  9310. serialize() {
  9311. if (this.isEmpty()) {
  9312. return null;
  9313. }
  9314. const padding = FreeTextEditor._internalPadding * this.parent.scaleFactor;
  9315. const rect = this.getRect(padding, padding);
  9316. const color = _editor.AnnotationEditor._colorManager.convert(getComputedStyle(this.editorDiv).color);
  9317. return {
  9318. annotationType: _util.AnnotationEditorType.FREETEXT,
  9319. color,
  9320. fontSize: this.#fontSize,
  9321. value: this.#content,
  9322. pageIndex: this.parent.pageIndex,
  9323. rect,
  9324. rotation: this.rotation
  9325. };
  9326. }
  9327. }
  9328. exports.FreeTextEditor = FreeTextEditor;
  9329. /***/ }),
  9330. /* 24 */
  9331. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  9332. Object.defineProperty(exports, "__esModule", ({
  9333. value: true
  9334. }));
  9335. exports.InkEditor = void 0;
  9336. Object.defineProperty(exports, "fitCurve", ({
  9337. enumerable: true,
  9338. get: function () {
  9339. return _pdfjsFitCurve.fitCurve;
  9340. }
  9341. }));
  9342. var _util = __w_pdfjs_require__(1);
  9343. var _editor = __w_pdfjs_require__(6);
  9344. var _pdfjsFitCurve = __w_pdfjs_require__(25);
  9345. var _tools = __w_pdfjs_require__(7);
  9346. const RESIZER_SIZE = 16;
  9347. class InkEditor extends _editor.AnnotationEditor {
  9348. #aspectRatio = 0;
  9349. #baseHeight = 0;
  9350. #baseWidth = 0;
  9351. #boundCanvasPointermove = this.canvasPointermove.bind(this);
  9352. #boundCanvasPointerleave = this.canvasPointerleave.bind(this);
  9353. #boundCanvasPointerup = this.canvasPointerup.bind(this);
  9354. #boundCanvasPointerdown = this.canvasPointerdown.bind(this);
  9355. #disableEditing = false;
  9356. #isCanvasInitialized = false;
  9357. #lastPoint = null;
  9358. #observer = null;
  9359. #realWidth = 0;
  9360. #realHeight = 0;
  9361. #requestFrameCallback = null;
  9362. static _defaultColor = null;
  9363. static _defaultOpacity = 1;
  9364. static _defaultThickness = 1;
  9365. static _l10nPromise;
  9366. static _type = "ink";
  9367. constructor(params) {
  9368. super({ ...params,
  9369. name: "inkEditor"
  9370. });
  9371. this.color = params.color || null;
  9372. this.thickness = params.thickness || null;
  9373. this.opacity = params.opacity || null;
  9374. this.paths = [];
  9375. this.bezierPath2D = [];
  9376. this.currentPath = [];
  9377. this.scaleFactor = 1;
  9378. this.translationX = this.translationY = 0;
  9379. this.x = 0;
  9380. this.y = 0;
  9381. }
  9382. static initialize(l10n) {
  9383. this._l10nPromise = new Map(["editor_ink_canvas_aria_label", "editor_ink_aria_label"].map(str => [str, l10n.get(str)]));
  9384. }
  9385. static updateDefaultParams(type, value) {
  9386. switch (type) {
  9387. case _util.AnnotationEditorParamsType.INK_THICKNESS:
  9388. InkEditor._defaultThickness = value;
  9389. break;
  9390. case _util.AnnotationEditorParamsType.INK_COLOR:
  9391. InkEditor._defaultColor = value;
  9392. break;
  9393. case _util.AnnotationEditorParamsType.INK_OPACITY:
  9394. InkEditor._defaultOpacity = value / 100;
  9395. break;
  9396. }
  9397. }
  9398. updateParams(type, value) {
  9399. switch (type) {
  9400. case _util.AnnotationEditorParamsType.INK_THICKNESS:
  9401. this.#updateThickness(value);
  9402. break;
  9403. case _util.AnnotationEditorParamsType.INK_COLOR:
  9404. this.#updateColor(value);
  9405. break;
  9406. case _util.AnnotationEditorParamsType.INK_OPACITY:
  9407. this.#updateOpacity(value);
  9408. break;
  9409. }
  9410. }
  9411. static get defaultPropertiesToUpdate() {
  9412. return [[_util.AnnotationEditorParamsType.INK_THICKNESS, InkEditor._defaultThickness], [_util.AnnotationEditorParamsType.INK_COLOR, InkEditor._defaultColor || _editor.AnnotationEditor._defaultLineColor], [_util.AnnotationEditorParamsType.INK_OPACITY, Math.round(InkEditor._defaultOpacity * 100)]];
  9413. }
  9414. get propertiesToUpdate() {
  9415. return [[_util.AnnotationEditorParamsType.INK_THICKNESS, this.thickness || InkEditor._defaultThickness], [_util.AnnotationEditorParamsType.INK_COLOR, this.color || InkEditor._defaultColor || _editor.AnnotationEditor._defaultLineColor], [_util.AnnotationEditorParamsType.INK_OPACITY, Math.round(100 * (this.opacity ?? InkEditor._defaultOpacity))]];
  9416. }
  9417. #updateThickness(thickness) {
  9418. const savedThickness = this.thickness;
  9419. this.parent.addCommands({
  9420. cmd: () => {
  9421. this.thickness = thickness;
  9422. this.#fitToContent();
  9423. },
  9424. undo: () => {
  9425. this.thickness = savedThickness;
  9426. this.#fitToContent();
  9427. },
  9428. mustExec: true,
  9429. type: _util.AnnotationEditorParamsType.INK_THICKNESS,
  9430. overwriteIfSameType: true,
  9431. keepUndo: true
  9432. });
  9433. }
  9434. #updateColor(color) {
  9435. const savedColor = this.color;
  9436. this.parent.addCommands({
  9437. cmd: () => {
  9438. this.color = color;
  9439. this.#redraw();
  9440. },
  9441. undo: () => {
  9442. this.color = savedColor;
  9443. this.#redraw();
  9444. },
  9445. mustExec: true,
  9446. type: _util.AnnotationEditorParamsType.INK_COLOR,
  9447. overwriteIfSameType: true,
  9448. keepUndo: true
  9449. });
  9450. }
  9451. #updateOpacity(opacity) {
  9452. opacity /= 100;
  9453. const savedOpacity = this.opacity;
  9454. this.parent.addCommands({
  9455. cmd: () => {
  9456. this.opacity = opacity;
  9457. this.#redraw();
  9458. },
  9459. undo: () => {
  9460. this.opacity = savedOpacity;
  9461. this.#redraw();
  9462. },
  9463. mustExec: true,
  9464. type: _util.AnnotationEditorParamsType.INK_OPACITY,
  9465. overwriteIfSameType: true,
  9466. keepUndo: true
  9467. });
  9468. }
  9469. rebuild() {
  9470. super.rebuild();
  9471. if (this.div === null) {
  9472. return;
  9473. }
  9474. if (!this.canvas) {
  9475. this.#createCanvas();
  9476. this.#createObserver();
  9477. }
  9478. if (!this.isAttachedToDOM) {
  9479. this.parent.add(this);
  9480. this.#setCanvasDims();
  9481. }
  9482. this.#fitToContent();
  9483. }
  9484. remove() {
  9485. if (this.canvas === null) {
  9486. return;
  9487. }
  9488. if (!this.isEmpty()) {
  9489. this.commit();
  9490. }
  9491. this.canvas.width = this.canvas.height = 0;
  9492. this.canvas.remove();
  9493. this.canvas = null;
  9494. this.#observer.disconnect();
  9495. this.#observer = null;
  9496. super.remove();
  9497. }
  9498. enableEditMode() {
  9499. if (this.#disableEditing || this.canvas === null) {
  9500. return;
  9501. }
  9502. super.enableEditMode();
  9503. this.div.draggable = false;
  9504. this.canvas.addEventListener("pointerdown", this.#boundCanvasPointerdown);
  9505. this.canvas.addEventListener("pointerup", this.#boundCanvasPointerup);
  9506. }
  9507. disableEditMode() {
  9508. if (!this.isInEditMode() || this.canvas === null) {
  9509. return;
  9510. }
  9511. super.disableEditMode();
  9512. this.div.draggable = !this.isEmpty();
  9513. this.div.classList.remove("editing");
  9514. this.canvas.removeEventListener("pointerdown", this.#boundCanvasPointerdown);
  9515. this.canvas.removeEventListener("pointerup", this.#boundCanvasPointerup);
  9516. }
  9517. onceAdded() {
  9518. this.div.draggable = !this.isEmpty();
  9519. }
  9520. isEmpty() {
  9521. return this.paths.length === 0 || this.paths.length === 1 && this.paths[0].length === 0;
  9522. }
  9523. #getInitialBBox() {
  9524. const {
  9525. width,
  9526. height,
  9527. rotation
  9528. } = this.parent.viewport;
  9529. switch (rotation) {
  9530. case 90:
  9531. return [0, width, width, height];
  9532. case 180:
  9533. return [width, height, width, height];
  9534. case 270:
  9535. return [height, 0, width, height];
  9536. default:
  9537. return [0, 0, width, height];
  9538. }
  9539. }
  9540. #setStroke() {
  9541. this.ctx.lineWidth = this.thickness * this.parent.scaleFactor / this.scaleFactor;
  9542. this.ctx.lineCap = "round";
  9543. this.ctx.lineJoin = "round";
  9544. this.ctx.miterLimit = 10;
  9545. this.ctx.strokeStyle = `${this.color}${(0, _tools.opacityToHex)(this.opacity)}`;
  9546. }
  9547. #startDrawing(x, y) {
  9548. this.isEditing = true;
  9549. if (!this.#isCanvasInitialized) {
  9550. this.#isCanvasInitialized = true;
  9551. this.#setCanvasDims();
  9552. this.thickness ||= InkEditor._defaultThickness;
  9553. this.color ||= InkEditor._defaultColor || _editor.AnnotationEditor._defaultLineColor;
  9554. this.opacity ??= InkEditor._defaultOpacity;
  9555. }
  9556. this.currentPath.push([x, y]);
  9557. this.#lastPoint = null;
  9558. this.#setStroke();
  9559. this.ctx.beginPath();
  9560. this.ctx.moveTo(x, y);
  9561. this.#requestFrameCallback = () => {
  9562. if (!this.#requestFrameCallback) {
  9563. return;
  9564. }
  9565. if (this.#lastPoint) {
  9566. if (this.isEmpty()) {
  9567. this.ctx.setTransform(1, 0, 0, 1, 0, 0);
  9568. this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
  9569. } else {
  9570. this.#redraw();
  9571. }
  9572. this.ctx.lineTo(...this.#lastPoint);
  9573. this.#lastPoint = null;
  9574. this.ctx.stroke();
  9575. }
  9576. window.requestAnimationFrame(this.#requestFrameCallback);
  9577. };
  9578. window.requestAnimationFrame(this.#requestFrameCallback);
  9579. }
  9580. #draw(x, y) {
  9581. const [lastX, lastY] = this.currentPath.at(-1);
  9582. if (x === lastX && y === lastY) {
  9583. return;
  9584. }
  9585. this.currentPath.push([x, y]);
  9586. this.#lastPoint = [x, y];
  9587. }
  9588. #stopDrawing(x, y) {
  9589. this.ctx.closePath();
  9590. this.#requestFrameCallback = null;
  9591. x = Math.min(Math.max(x, 0), this.canvas.width);
  9592. y = Math.min(Math.max(y, 0), this.canvas.height);
  9593. const [lastX, lastY] = this.currentPath.at(-1);
  9594. if (x !== lastX || y !== lastY) {
  9595. this.currentPath.push([x, y]);
  9596. }
  9597. let bezier;
  9598. if (this.currentPath.length !== 1) {
  9599. bezier = (0, _pdfjsFitCurve.fitCurve)(this.currentPath, 30, null);
  9600. } else {
  9601. const xy = [x, y];
  9602. bezier = [[xy, xy.slice(), xy.slice(), xy]];
  9603. }
  9604. const path2D = InkEditor.#buildPath2D(bezier);
  9605. this.currentPath.length = 0;
  9606. const cmd = () => {
  9607. this.paths.push(bezier);
  9608. this.bezierPath2D.push(path2D);
  9609. this.rebuild();
  9610. };
  9611. const undo = () => {
  9612. this.paths.pop();
  9613. this.bezierPath2D.pop();
  9614. if (this.paths.length === 0) {
  9615. this.remove();
  9616. } else {
  9617. if (!this.canvas) {
  9618. this.#createCanvas();
  9619. this.#createObserver();
  9620. }
  9621. this.#fitToContent();
  9622. }
  9623. };
  9624. this.parent.addCommands({
  9625. cmd,
  9626. undo,
  9627. mustExec: true
  9628. });
  9629. }
  9630. #redraw() {
  9631. if (this.isEmpty()) {
  9632. this.#updateTransform();
  9633. return;
  9634. }
  9635. this.#setStroke();
  9636. const {
  9637. canvas,
  9638. ctx
  9639. } = this;
  9640. ctx.setTransform(1, 0, 0, 1, 0, 0);
  9641. ctx.clearRect(0, 0, canvas.width, canvas.height);
  9642. this.#updateTransform();
  9643. for (const path of this.bezierPath2D) {
  9644. ctx.stroke(path);
  9645. }
  9646. }
  9647. commit() {
  9648. if (this.#disableEditing) {
  9649. return;
  9650. }
  9651. super.commit();
  9652. this.isEditing = false;
  9653. this.disableEditMode();
  9654. this.setInForeground();
  9655. this.#disableEditing = true;
  9656. this.div.classList.add("disabled");
  9657. this.#fitToContent(true);
  9658. this.parent.addInkEditorIfNeeded(true);
  9659. this.parent.moveEditorInDOM(this);
  9660. this.div.focus();
  9661. }
  9662. focusin(event) {
  9663. super.focusin(event);
  9664. this.enableEditMode();
  9665. }
  9666. canvasPointerdown(event) {
  9667. if (event.button !== 0 || !this.isInEditMode() || this.#disableEditing) {
  9668. return;
  9669. }
  9670. this.setInForeground();
  9671. if (event.type !== "mouse") {
  9672. this.div.focus();
  9673. }
  9674. event.stopPropagation();
  9675. this.canvas.addEventListener("pointerleave", this.#boundCanvasPointerleave);
  9676. this.canvas.addEventListener("pointermove", this.#boundCanvasPointermove);
  9677. this.#startDrawing(event.offsetX, event.offsetY);
  9678. }
  9679. canvasPointermove(event) {
  9680. event.stopPropagation();
  9681. this.#draw(event.offsetX, event.offsetY);
  9682. }
  9683. canvasPointerup(event) {
  9684. if (event.button !== 0) {
  9685. return;
  9686. }
  9687. if (this.isInEditMode() && this.currentPath.length !== 0) {
  9688. event.stopPropagation();
  9689. this.#endDrawing(event);
  9690. this.setInBackground();
  9691. }
  9692. }
  9693. canvasPointerleave(event) {
  9694. this.#endDrawing(event);
  9695. this.setInBackground();
  9696. }
  9697. #endDrawing(event) {
  9698. this.#stopDrawing(event.offsetX, event.offsetY);
  9699. this.canvas.removeEventListener("pointerleave", this.#boundCanvasPointerleave);
  9700. this.canvas.removeEventListener("pointermove", this.#boundCanvasPointermove);
  9701. this.parent.addToAnnotationStorage(this);
  9702. }
  9703. #createCanvas() {
  9704. this.canvas = document.createElement("canvas");
  9705. this.canvas.width = this.canvas.height = 0;
  9706. this.canvas.className = "inkEditorCanvas";
  9707. InkEditor._l10nPromise.get("editor_ink_canvas_aria_label").then(msg => this.canvas?.setAttribute("aria-label", msg));
  9708. this.div.append(this.canvas);
  9709. this.ctx = this.canvas.getContext("2d");
  9710. }
  9711. #createObserver() {
  9712. this.#observer = new ResizeObserver(entries => {
  9713. const rect = entries[0].contentRect;
  9714. if (rect.width && rect.height) {
  9715. this.setDimensions(rect.width, rect.height);
  9716. }
  9717. });
  9718. this.#observer.observe(this.div);
  9719. }
  9720. render() {
  9721. if (this.div) {
  9722. return this.div;
  9723. }
  9724. let baseX, baseY;
  9725. if (this.width) {
  9726. baseX = this.x;
  9727. baseY = this.y;
  9728. }
  9729. super.render();
  9730. InkEditor._l10nPromise.get("editor_ink_aria_label").then(msg => this.div?.setAttribute("aria-label", msg));
  9731. const [x, y, w, h] = this.#getInitialBBox();
  9732. this.setAt(x, y, 0, 0);
  9733. this.setDims(w, h);
  9734. this.#createCanvas();
  9735. if (this.width) {
  9736. const [parentWidth, parentHeight] = this.parent.viewportBaseDimensions;
  9737. this.setAt(baseX * parentWidth, baseY * parentHeight, this.width * parentWidth, this.height * parentHeight);
  9738. this.#isCanvasInitialized = true;
  9739. this.#setCanvasDims();
  9740. this.setDims(this.width * parentWidth, this.height * parentHeight);
  9741. this.#redraw();
  9742. this.#setMinDims();
  9743. this.div.classList.add("disabled");
  9744. } else {
  9745. this.div.classList.add("editing");
  9746. this.enableEditMode();
  9747. }
  9748. this.#createObserver();
  9749. return this.div;
  9750. }
  9751. #setCanvasDims() {
  9752. if (!this.#isCanvasInitialized) {
  9753. return;
  9754. }
  9755. const [parentWidth, parentHeight] = this.parent.viewportBaseDimensions;
  9756. this.canvas.width = Math.ceil(this.width * parentWidth);
  9757. this.canvas.height = Math.ceil(this.height * parentHeight);
  9758. this.#updateTransform();
  9759. }
  9760. setDimensions(width, height) {
  9761. const roundedWidth = Math.round(width);
  9762. const roundedHeight = Math.round(height);
  9763. if (this.#realWidth === roundedWidth && this.#realHeight === roundedHeight) {
  9764. return;
  9765. }
  9766. this.#realWidth = roundedWidth;
  9767. this.#realHeight = roundedHeight;
  9768. this.canvas.style.visibility = "hidden";
  9769. if (this.#aspectRatio && Math.abs(this.#aspectRatio - width / height) > 1e-2) {
  9770. height = Math.ceil(width / this.#aspectRatio);
  9771. this.setDims(width, height);
  9772. }
  9773. const [parentWidth, parentHeight] = this.parent.viewportBaseDimensions;
  9774. this.width = width / parentWidth;
  9775. this.height = height / parentHeight;
  9776. if (this.#disableEditing) {
  9777. this.#setScaleFactor(width, height);
  9778. }
  9779. this.#setCanvasDims();
  9780. this.#redraw();
  9781. this.canvas.style.visibility = "visible";
  9782. }
  9783. #setScaleFactor(width, height) {
  9784. const padding = this.#getPadding();
  9785. const scaleFactorW = (width - padding) / this.#baseWidth;
  9786. const scaleFactorH = (height - padding) / this.#baseHeight;
  9787. this.scaleFactor = Math.min(scaleFactorW, scaleFactorH);
  9788. }
  9789. #updateTransform() {
  9790. const padding = this.#getPadding() / 2;
  9791. this.ctx.setTransform(this.scaleFactor, 0, 0, this.scaleFactor, this.translationX * this.scaleFactor + padding, this.translationY * this.scaleFactor + padding);
  9792. }
  9793. static #buildPath2D(bezier) {
  9794. const path2D = new Path2D();
  9795. for (let i = 0, ii = bezier.length; i < ii; i++) {
  9796. const [first, control1, control2, second] = bezier[i];
  9797. if (i === 0) {
  9798. path2D.moveTo(...first);
  9799. }
  9800. path2D.bezierCurveTo(control1[0], control1[1], control2[0], control2[1], second[0], second[1]);
  9801. }
  9802. return path2D;
  9803. }
  9804. #serializePaths(s, tx, ty, h) {
  9805. const NUMBER_OF_POINTS_ON_BEZIER_CURVE = 4;
  9806. const paths = [];
  9807. const padding = this.thickness / 2;
  9808. let buffer, points;
  9809. for (const bezier of this.paths) {
  9810. buffer = [];
  9811. points = [];
  9812. for (let i = 0, ii = bezier.length; i < ii; i++) {
  9813. const [first, control1, control2, second] = bezier[i];
  9814. const p10 = s * (first[0] + tx) + padding;
  9815. const p11 = h - s * (first[1] + ty) - padding;
  9816. const p20 = s * (control1[0] + tx) + padding;
  9817. const p21 = h - s * (control1[1] + ty) - padding;
  9818. const p30 = s * (control2[0] + tx) + padding;
  9819. const p31 = h - s * (control2[1] + ty) - padding;
  9820. const p40 = s * (second[0] + tx) + padding;
  9821. const p41 = h - s * (second[1] + ty) - padding;
  9822. if (i === 0) {
  9823. buffer.push(p10, p11);
  9824. points.push(p10, p11);
  9825. }
  9826. buffer.push(p20, p21, p30, p31, p40, p41);
  9827. this.#extractPointsOnBezier(p10, p11, p20, p21, p30, p31, p40, p41, NUMBER_OF_POINTS_ON_BEZIER_CURVE, points);
  9828. }
  9829. paths.push({
  9830. bezier: buffer,
  9831. points
  9832. });
  9833. }
  9834. return paths;
  9835. }
  9836. #extractPointsOnBezier(p10, p11, p20, p21, p30, p31, p40, p41, n, points) {
  9837. if (this.#isAlmostFlat(p10, p11, p20, p21, p30, p31, p40, p41)) {
  9838. points.push(p40, p41);
  9839. return;
  9840. }
  9841. for (let i = 1; i < n - 1; i++) {
  9842. const t = i / n;
  9843. const mt = 1 - t;
  9844. let q10 = t * p10 + mt * p20;
  9845. let q11 = t * p11 + mt * p21;
  9846. let q20 = t * p20 + mt * p30;
  9847. let q21 = t * p21 + mt * p31;
  9848. const q30 = t * p30 + mt * p40;
  9849. const q31 = t * p31 + mt * p41;
  9850. q10 = t * q10 + mt * q20;
  9851. q11 = t * q11 + mt * q21;
  9852. q20 = t * q20 + mt * q30;
  9853. q21 = t * q21 + mt * q31;
  9854. q10 = t * q10 + mt * q20;
  9855. q11 = t * q11 + mt * q21;
  9856. points.push(q10, q11);
  9857. }
  9858. points.push(p40, p41);
  9859. }
  9860. #isAlmostFlat(p10, p11, p20, p21, p30, p31, p40, p41) {
  9861. const tol = 10;
  9862. const ax = (3 * p20 - 2 * p10 - p40) ** 2;
  9863. const ay = (3 * p21 - 2 * p11 - p41) ** 2;
  9864. const bx = (3 * p30 - p10 - 2 * p40) ** 2;
  9865. const by = (3 * p31 - p11 - 2 * p41) ** 2;
  9866. return Math.max(ax, bx) + Math.max(ay, by) <= tol;
  9867. }
  9868. #getBbox() {
  9869. let xMin = Infinity;
  9870. let xMax = -Infinity;
  9871. let yMin = Infinity;
  9872. let yMax = -Infinity;
  9873. for (const path of this.paths) {
  9874. for (const [first, control1, control2, second] of path) {
  9875. const bbox = _util.Util.bezierBoundingBox(...first, ...control1, ...control2, ...second);
  9876. xMin = Math.min(xMin, bbox[0]);
  9877. yMin = Math.min(yMin, bbox[1]);
  9878. xMax = Math.max(xMax, bbox[2]);
  9879. yMax = Math.max(yMax, bbox[3]);
  9880. }
  9881. }
  9882. return [xMin, yMin, xMax, yMax];
  9883. }
  9884. #getPadding() {
  9885. return this.#disableEditing ? Math.ceil(this.thickness * this.parent.scaleFactor) : 0;
  9886. }
  9887. #fitToContent(firstTime = false) {
  9888. if (this.isEmpty()) {
  9889. return;
  9890. }
  9891. if (!this.#disableEditing) {
  9892. this.#redraw();
  9893. return;
  9894. }
  9895. const bbox = this.#getBbox();
  9896. const padding = this.#getPadding();
  9897. this.#baseWidth = Math.max(RESIZER_SIZE, bbox[2] - bbox[0]);
  9898. this.#baseHeight = Math.max(RESIZER_SIZE, bbox[3] - bbox[1]);
  9899. const width = Math.ceil(padding + this.#baseWidth * this.scaleFactor);
  9900. const height = Math.ceil(padding + this.#baseHeight * this.scaleFactor);
  9901. const [parentWidth, parentHeight] = this.parent.viewportBaseDimensions;
  9902. this.width = width / parentWidth;
  9903. this.height = height / parentHeight;
  9904. this.#aspectRatio = width / height;
  9905. this.#setMinDims();
  9906. const prevTranslationX = this.translationX;
  9907. const prevTranslationY = this.translationY;
  9908. this.translationX = -bbox[0];
  9909. this.translationY = -bbox[1];
  9910. this.#setCanvasDims();
  9911. this.#redraw();
  9912. this.#realWidth = width;
  9913. this.#realHeight = height;
  9914. this.setDims(width, height);
  9915. const unscaledPadding = firstTime ? padding / this.scaleFactor / 2 : 0;
  9916. this.translate(prevTranslationX - this.translationX - unscaledPadding, prevTranslationY - this.translationY - unscaledPadding);
  9917. }
  9918. #setMinDims() {
  9919. const {
  9920. style
  9921. } = this.div;
  9922. if (this.#aspectRatio >= 1) {
  9923. style.minHeight = `${RESIZER_SIZE}px`;
  9924. style.minWidth = `${Math.round(this.#aspectRatio * RESIZER_SIZE)}px`;
  9925. } else {
  9926. style.minWidth = `${RESIZER_SIZE}px`;
  9927. style.minHeight = `${Math.round(RESIZER_SIZE / this.#aspectRatio)}px`;
  9928. }
  9929. }
  9930. static deserialize(data, parent) {
  9931. const editor = super.deserialize(data, parent);
  9932. editor.thickness = data.thickness;
  9933. editor.color = _util.Util.makeHexColor(...data.color);
  9934. editor.opacity = data.opacity;
  9935. const [pageWidth, pageHeight] = parent.pageDimensions;
  9936. const width = editor.width * pageWidth;
  9937. const height = editor.height * pageHeight;
  9938. const scaleFactor = parent.scaleFactor;
  9939. const padding = data.thickness / 2;
  9940. editor.#aspectRatio = width / height;
  9941. editor.#disableEditing = true;
  9942. editor.#realWidth = Math.round(width);
  9943. editor.#realHeight = Math.round(height);
  9944. for (const {
  9945. bezier
  9946. } of data.paths) {
  9947. const path = [];
  9948. editor.paths.push(path);
  9949. let p0 = scaleFactor * (bezier[0] - padding);
  9950. let p1 = scaleFactor * (height - bezier[1] - padding);
  9951. for (let i = 2, ii = bezier.length; i < ii; i += 6) {
  9952. const p10 = scaleFactor * (bezier[i] - padding);
  9953. const p11 = scaleFactor * (height - bezier[i + 1] - padding);
  9954. const p20 = scaleFactor * (bezier[i + 2] - padding);
  9955. const p21 = scaleFactor * (height - bezier[i + 3] - padding);
  9956. const p30 = scaleFactor * (bezier[i + 4] - padding);
  9957. const p31 = scaleFactor * (height - bezier[i + 5] - padding);
  9958. path.push([[p0, p1], [p10, p11], [p20, p21], [p30, p31]]);
  9959. p0 = p30;
  9960. p1 = p31;
  9961. }
  9962. const path2D = this.#buildPath2D(path);
  9963. editor.bezierPath2D.push(path2D);
  9964. }
  9965. const bbox = editor.#getBbox();
  9966. editor.#baseWidth = Math.max(RESIZER_SIZE, bbox[2] - bbox[0]);
  9967. editor.#baseHeight = Math.max(RESIZER_SIZE, bbox[3] - bbox[1]);
  9968. editor.#setScaleFactor(width, height);
  9969. return editor;
  9970. }
  9971. serialize() {
  9972. if (this.isEmpty()) {
  9973. return null;
  9974. }
  9975. const rect = this.getRect(0, 0);
  9976. const height = this.rotation % 180 === 0 ? rect[3] - rect[1] : rect[2] - rect[0];
  9977. const color = _editor.AnnotationEditor._colorManager.convert(this.ctx.strokeStyle);
  9978. return {
  9979. annotationType: _util.AnnotationEditorType.INK,
  9980. color,
  9981. thickness: this.thickness,
  9982. opacity: this.opacity,
  9983. paths: this.#serializePaths(this.scaleFactor / this.parent.scaleFactor, this.translationX, this.translationY, height),
  9984. pageIndex: this.parent.pageIndex,
  9985. rect,
  9986. rotation: this.rotation
  9987. };
  9988. }
  9989. }
  9990. exports.InkEditor = InkEditor;
  9991. /***/ }),
  9992. /* 25 */
  9993. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  9994. Object.defineProperty(exports, "__esModule", ({
  9995. value: true
  9996. }));
  9997. exports.fitCurve = void 0;
  9998. const fitCurve = __w_pdfjs_require__(26);
  9999. exports.fitCurve = fitCurve;
  10000. /***/ }),
  10001. /* 26 */
  10002. /***/ ((module) => {
  10003. function fitCurve(points, maxError, progressCallback) {
  10004. if (!Array.isArray(points)) {
  10005. throw new TypeError("First argument should be an array");
  10006. }
  10007. points.forEach(point => {
  10008. if (!Array.isArray(point) || point.some(item => typeof item !== 'number') || point.length !== points[0].length) {
  10009. throw Error("Each point should be an array of numbers. Each point should have the same amount of numbers.");
  10010. }
  10011. });
  10012. points = points.filter((point, i) => i === 0 || !point.every((val, j) => val === points[i - 1][j]));
  10013. if (points.length < 2) {
  10014. return [];
  10015. }
  10016. const len = points.length;
  10017. const leftTangent = createTangent(points[1], points[0]);
  10018. const rightTangent = createTangent(points[len - 2], points[len - 1]);
  10019. return fitCubic(points, leftTangent, rightTangent, maxError, progressCallback);
  10020. }
  10021. function fitCubic(points, leftTangent, rightTangent, error, progressCallback) {
  10022. const MaxIterations = 20;
  10023. var bezCurve, u, uPrime, maxError, prevErr, splitPoint, prevSplit, centerVector, toCenterTangent, fromCenterTangent, beziers, dist, i;
  10024. if (points.length === 2) {
  10025. dist = maths.vectorLen(maths.subtract(points[0], points[1])) / 3.0;
  10026. bezCurve = [points[0], maths.addArrays(points[0], maths.mulItems(leftTangent, dist)), maths.addArrays(points[1], maths.mulItems(rightTangent, dist)), points[1]];
  10027. return [bezCurve];
  10028. }
  10029. u = chordLengthParameterize(points);
  10030. [bezCurve, maxError, splitPoint] = generateAndReport(points, u, u, leftTangent, rightTangent, progressCallback);
  10031. if (maxError === 0 || maxError < error) {
  10032. return [bezCurve];
  10033. }
  10034. if (maxError < error * error) {
  10035. uPrime = u;
  10036. prevErr = maxError;
  10037. prevSplit = splitPoint;
  10038. for (i = 0; i < MaxIterations; i++) {
  10039. uPrime = reparameterize(bezCurve, points, uPrime);
  10040. [bezCurve, maxError, splitPoint] = generateAndReport(points, u, uPrime, leftTangent, rightTangent, progressCallback);
  10041. if (maxError < error) {
  10042. return [bezCurve];
  10043. } else if (splitPoint === prevSplit) {
  10044. let errChange = maxError / prevErr;
  10045. if (errChange > .9999 && errChange < 1.0001) {
  10046. break;
  10047. }
  10048. }
  10049. prevErr = maxError;
  10050. prevSplit = splitPoint;
  10051. }
  10052. }
  10053. beziers = [];
  10054. centerVector = maths.subtract(points[splitPoint - 1], points[splitPoint + 1]);
  10055. if (centerVector.every(val => val === 0)) {
  10056. centerVector = maths.subtract(points[splitPoint - 1], points[splitPoint]);
  10057. [centerVector[0], centerVector[1]] = [-centerVector[1], centerVector[0]];
  10058. }
  10059. toCenterTangent = maths.normalize(centerVector);
  10060. fromCenterTangent = maths.mulItems(toCenterTangent, -1);
  10061. beziers = beziers.concat(fitCubic(points.slice(0, splitPoint + 1), leftTangent, toCenterTangent, error, progressCallback));
  10062. beziers = beziers.concat(fitCubic(points.slice(splitPoint), fromCenterTangent, rightTangent, error, progressCallback));
  10063. return beziers;
  10064. }
  10065. ;
  10066. function generateAndReport(points, paramsOrig, paramsPrime, leftTangent, rightTangent, progressCallback) {
  10067. var bezCurve, maxError, splitPoint;
  10068. bezCurve = generateBezier(points, paramsPrime, leftTangent, rightTangent, progressCallback);
  10069. [maxError, splitPoint] = computeMaxError(points, bezCurve, paramsOrig);
  10070. if (progressCallback) {
  10071. progressCallback({
  10072. bez: bezCurve,
  10073. points: points,
  10074. params: paramsOrig,
  10075. maxErr: maxError,
  10076. maxPoint: splitPoint
  10077. });
  10078. }
  10079. return [bezCurve, maxError, splitPoint];
  10080. }
  10081. function generateBezier(points, parameters, leftTangent, rightTangent) {
  10082. var bezCurve,
  10083. A,
  10084. a,
  10085. C,
  10086. X,
  10087. det_C0_C1,
  10088. det_C0_X,
  10089. det_X_C1,
  10090. alpha_l,
  10091. alpha_r,
  10092. epsilon,
  10093. segLength,
  10094. i,
  10095. len,
  10096. tmp,
  10097. u,
  10098. ux,
  10099. firstPoint = points[0],
  10100. lastPoint = points[points.length - 1];
  10101. bezCurve = [firstPoint, null, null, lastPoint];
  10102. A = maths.zeros_Xx2x2(parameters.length);
  10103. for (i = 0, len = parameters.length; i < len; i++) {
  10104. u = parameters[i];
  10105. ux = 1 - u;
  10106. a = A[i];
  10107. a[0] = maths.mulItems(leftTangent, 3 * u * (ux * ux));
  10108. a[1] = maths.mulItems(rightTangent, 3 * ux * (u * u));
  10109. }
  10110. C = [[0, 0], [0, 0]];
  10111. X = [0, 0];
  10112. for (i = 0, len = points.length; i < len; i++) {
  10113. u = parameters[i];
  10114. a = A[i];
  10115. C[0][0] += maths.dot(a[0], a[0]);
  10116. C[0][1] += maths.dot(a[0], a[1]);
  10117. C[1][0] += maths.dot(a[0], a[1]);
  10118. C[1][1] += maths.dot(a[1], a[1]);
  10119. tmp = maths.subtract(points[i], bezier.q([firstPoint, firstPoint, lastPoint, lastPoint], u));
  10120. X[0] += maths.dot(a[0], tmp);
  10121. X[1] += maths.dot(a[1], tmp);
  10122. }
  10123. det_C0_C1 = C[0][0] * C[1][1] - C[1][0] * C[0][1];
  10124. det_C0_X = C[0][0] * X[1] - C[1][0] * X[0];
  10125. det_X_C1 = X[0] * C[1][1] - X[1] * C[0][1];
  10126. alpha_l = det_C0_C1 === 0 ? 0 : det_X_C1 / det_C0_C1;
  10127. alpha_r = det_C0_C1 === 0 ? 0 : det_C0_X / det_C0_C1;
  10128. segLength = maths.vectorLen(maths.subtract(firstPoint, lastPoint));
  10129. epsilon = 1.0e-6 * segLength;
  10130. if (alpha_l < epsilon || alpha_r < epsilon) {
  10131. bezCurve[1] = maths.addArrays(firstPoint, maths.mulItems(leftTangent, segLength / 3.0));
  10132. bezCurve[2] = maths.addArrays(lastPoint, maths.mulItems(rightTangent, segLength / 3.0));
  10133. } else {
  10134. bezCurve[1] = maths.addArrays(firstPoint, maths.mulItems(leftTangent, alpha_l));
  10135. bezCurve[2] = maths.addArrays(lastPoint, maths.mulItems(rightTangent, alpha_r));
  10136. }
  10137. return bezCurve;
  10138. }
  10139. ;
  10140. function reparameterize(bezier, points, parameters) {
  10141. return parameters.map((p, i) => newtonRaphsonRootFind(bezier, points[i], p));
  10142. }
  10143. ;
  10144. function newtonRaphsonRootFind(bez, point, u) {
  10145. var d = maths.subtract(bezier.q(bez, u), point),
  10146. qprime = bezier.qprime(bez, u),
  10147. numerator = maths.mulMatrix(d, qprime),
  10148. denominator = maths.sum(maths.squareItems(qprime)) + 2 * maths.mulMatrix(d, bezier.qprimeprime(bez, u));
  10149. if (denominator === 0) {
  10150. return u;
  10151. } else {
  10152. return u - numerator / denominator;
  10153. }
  10154. }
  10155. ;
  10156. function chordLengthParameterize(points) {
  10157. var u = [],
  10158. currU,
  10159. prevU,
  10160. prevP;
  10161. points.forEach((p, i) => {
  10162. currU = i ? prevU + maths.vectorLen(maths.subtract(p, prevP)) : 0;
  10163. u.push(currU);
  10164. prevU = currU;
  10165. prevP = p;
  10166. });
  10167. u = u.map(x => x / prevU);
  10168. return u;
  10169. }
  10170. ;
  10171. function computeMaxError(points, bez, parameters) {
  10172. var dist, maxDist, splitPoint, v, i, count, point, t;
  10173. maxDist = 0;
  10174. splitPoint = Math.floor(points.length / 2);
  10175. const t_distMap = mapTtoRelativeDistances(bez, 10);
  10176. for (i = 0, count = points.length; i < count; i++) {
  10177. point = points[i];
  10178. t = find_t(bez, parameters[i], t_distMap, 10);
  10179. v = maths.subtract(bezier.q(bez, t), point);
  10180. dist = v[0] * v[0] + v[1] * v[1];
  10181. if (dist > maxDist) {
  10182. maxDist = dist;
  10183. splitPoint = i;
  10184. }
  10185. }
  10186. return [maxDist, splitPoint];
  10187. }
  10188. ;
  10189. var mapTtoRelativeDistances = function (bez, B_parts) {
  10190. var B_t_curr;
  10191. var B_t_dist = [0];
  10192. var B_t_prev = bez[0];
  10193. var sumLen = 0;
  10194. for (var i = 1; i <= B_parts; i++) {
  10195. B_t_curr = bezier.q(bez, i / B_parts);
  10196. sumLen += maths.vectorLen(maths.subtract(B_t_curr, B_t_prev));
  10197. B_t_dist.push(sumLen);
  10198. B_t_prev = B_t_curr;
  10199. }
  10200. B_t_dist = B_t_dist.map(x => x / sumLen);
  10201. return B_t_dist;
  10202. };
  10203. function find_t(bez, param, t_distMap, B_parts) {
  10204. if (param < 0) {
  10205. return 0;
  10206. }
  10207. if (param > 1) {
  10208. return 1;
  10209. }
  10210. var lenMax, lenMin, tMax, tMin, t;
  10211. for (var i = 1; i <= B_parts; i++) {
  10212. if (param <= t_distMap[i]) {
  10213. tMin = (i - 1) / B_parts;
  10214. tMax = i / B_parts;
  10215. lenMin = t_distMap[i - 1];
  10216. lenMax = t_distMap[i];
  10217. t = (param - lenMin) / (lenMax - lenMin) * (tMax - tMin) + tMin;
  10218. break;
  10219. }
  10220. }
  10221. return t;
  10222. }
  10223. function createTangent(pointA, pointB) {
  10224. return maths.normalize(maths.subtract(pointA, pointB));
  10225. }
  10226. class maths {
  10227. static zeros_Xx2x2(x) {
  10228. var zs = [];
  10229. while (x--) {
  10230. zs.push([0, 0]);
  10231. }
  10232. return zs;
  10233. }
  10234. static mulItems(items, multiplier) {
  10235. return items.map(x => x * multiplier);
  10236. }
  10237. static mulMatrix(m1, m2) {
  10238. return m1.reduce((sum, x1, i) => sum + x1 * m2[i], 0);
  10239. }
  10240. static subtract(arr1, arr2) {
  10241. return arr1.map((x1, i) => x1 - arr2[i]);
  10242. }
  10243. static addArrays(arr1, arr2) {
  10244. return arr1.map((x1, i) => x1 + arr2[i]);
  10245. }
  10246. static addItems(items, addition) {
  10247. return items.map(x => x + addition);
  10248. }
  10249. static sum(items) {
  10250. return items.reduce((sum, x) => sum + x);
  10251. }
  10252. static dot(m1, m2) {
  10253. return maths.mulMatrix(m1, m2);
  10254. }
  10255. static vectorLen(v) {
  10256. return Math.hypot(...v);
  10257. }
  10258. static divItems(items, divisor) {
  10259. return items.map(x => x / divisor);
  10260. }
  10261. static squareItems(items) {
  10262. return items.map(x => x * x);
  10263. }
  10264. static normalize(v) {
  10265. return this.divItems(v, this.vectorLen(v));
  10266. }
  10267. }
  10268. class bezier {
  10269. static q(ctrlPoly, t) {
  10270. var tx = 1.0 - t;
  10271. var pA = maths.mulItems(ctrlPoly[0], tx * tx * tx),
  10272. pB = maths.mulItems(ctrlPoly[1], 3 * tx * tx * t),
  10273. pC = maths.mulItems(ctrlPoly[2], 3 * tx * t * t),
  10274. pD = maths.mulItems(ctrlPoly[3], t * t * t);
  10275. return maths.addArrays(maths.addArrays(pA, pB), maths.addArrays(pC, pD));
  10276. }
  10277. static qprime(ctrlPoly, t) {
  10278. var tx = 1.0 - t;
  10279. var pA = maths.mulItems(maths.subtract(ctrlPoly[1], ctrlPoly[0]), 3 * tx * tx),
  10280. pB = maths.mulItems(maths.subtract(ctrlPoly[2], ctrlPoly[1]), 6 * tx * t),
  10281. pC = maths.mulItems(maths.subtract(ctrlPoly[3], ctrlPoly[2]), 3 * t * t);
  10282. return maths.addArrays(maths.addArrays(pA, pB), pC);
  10283. }
  10284. static qprimeprime(ctrlPoly, t) {
  10285. return maths.addArrays(maths.mulItems(maths.addArrays(maths.subtract(ctrlPoly[2], maths.mulItems(ctrlPoly[1], 2)), ctrlPoly[0]), 6 * (1.0 - t)), maths.mulItems(maths.addArrays(maths.subtract(ctrlPoly[3], maths.mulItems(ctrlPoly[2], 2)), ctrlPoly[1]), 6 * t));
  10286. }
  10287. }
  10288. module.exports = fitCurve;
  10289. module.exports.fitCubic = fitCubic;
  10290. module.exports.createTangent = createTangent;
  10291. /***/ }),
  10292. /* 27 */
  10293. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  10294. Object.defineProperty(exports, "__esModule", ({
  10295. value: true
  10296. }));
  10297. exports.AnnotationLayer = void 0;
  10298. var _util = __w_pdfjs_require__(1);
  10299. var _display_utils = __w_pdfjs_require__(8);
  10300. var _annotation_storage = __w_pdfjs_require__(5);
  10301. var _scripting_utils = __w_pdfjs_require__(28);
  10302. var _xfa_layer = __w_pdfjs_require__(29);
  10303. const DEFAULT_TAB_INDEX = 1000;
  10304. const DEFAULT_FONT_SIZE = 9;
  10305. const GetElementsByNameSet = new WeakSet();
  10306. function getRectDims(rect) {
  10307. return {
  10308. width: rect[2] - rect[0],
  10309. height: rect[3] - rect[1]
  10310. };
  10311. }
  10312. class AnnotationElementFactory {
  10313. static create(parameters) {
  10314. const subtype = parameters.data.annotationType;
  10315. switch (subtype) {
  10316. case _util.AnnotationType.LINK:
  10317. return new LinkAnnotationElement(parameters);
  10318. case _util.AnnotationType.TEXT:
  10319. return new TextAnnotationElement(parameters);
  10320. case _util.AnnotationType.WIDGET:
  10321. const fieldType = parameters.data.fieldType;
  10322. switch (fieldType) {
  10323. case "Tx":
  10324. return new TextWidgetAnnotationElement(parameters);
  10325. case "Btn":
  10326. if (parameters.data.radioButton) {
  10327. return new RadioButtonWidgetAnnotationElement(parameters);
  10328. } else if (parameters.data.checkBox) {
  10329. return new CheckboxWidgetAnnotationElement(parameters);
  10330. }
  10331. return new PushButtonWidgetAnnotationElement(parameters);
  10332. case "Ch":
  10333. return new ChoiceWidgetAnnotationElement(parameters);
  10334. }
  10335. return new WidgetAnnotationElement(parameters);
  10336. case _util.AnnotationType.POPUP:
  10337. return new PopupAnnotationElement(parameters);
  10338. case _util.AnnotationType.FREETEXT:
  10339. return new FreeTextAnnotationElement(parameters);
  10340. case _util.AnnotationType.LINE:
  10341. return new LineAnnotationElement(parameters);
  10342. case _util.AnnotationType.SQUARE:
  10343. return new SquareAnnotationElement(parameters);
  10344. case _util.AnnotationType.CIRCLE:
  10345. return new CircleAnnotationElement(parameters);
  10346. case _util.AnnotationType.POLYLINE:
  10347. return new PolylineAnnotationElement(parameters);
  10348. case _util.AnnotationType.CARET:
  10349. return new CaretAnnotationElement(parameters);
  10350. case _util.AnnotationType.INK:
  10351. return new InkAnnotationElement(parameters);
  10352. case _util.AnnotationType.POLYGON:
  10353. return new PolygonAnnotationElement(parameters);
  10354. case _util.AnnotationType.HIGHLIGHT:
  10355. return new HighlightAnnotationElement(parameters);
  10356. case _util.AnnotationType.UNDERLINE:
  10357. return new UnderlineAnnotationElement(parameters);
  10358. case _util.AnnotationType.SQUIGGLY:
  10359. return new SquigglyAnnotationElement(parameters);
  10360. case _util.AnnotationType.STRIKEOUT:
  10361. return new StrikeOutAnnotationElement(parameters);
  10362. case _util.AnnotationType.STAMP:
  10363. return new StampAnnotationElement(parameters);
  10364. case _util.AnnotationType.FILEATTACHMENT:
  10365. return new FileAttachmentAnnotationElement(parameters);
  10366. default:
  10367. return new AnnotationElement(parameters);
  10368. }
  10369. }
  10370. }
  10371. class AnnotationElement {
  10372. constructor(parameters, {
  10373. isRenderable = false,
  10374. ignoreBorder = false,
  10375. createQuadrilaterals = false
  10376. } = {}) {
  10377. this.isRenderable = isRenderable;
  10378. this.data = parameters.data;
  10379. this.layer = parameters.layer;
  10380. this.page = parameters.page;
  10381. this.viewport = parameters.viewport;
  10382. this.linkService = parameters.linkService;
  10383. this.downloadManager = parameters.downloadManager;
  10384. this.imageResourcesPath = parameters.imageResourcesPath;
  10385. this.renderForms = parameters.renderForms;
  10386. this.svgFactory = parameters.svgFactory;
  10387. this.annotationStorage = parameters.annotationStorage;
  10388. this.enableScripting = parameters.enableScripting;
  10389. this.hasJSActions = parameters.hasJSActions;
  10390. this._fieldObjects = parameters.fieldObjects;
  10391. this._mouseState = parameters.mouseState;
  10392. if (isRenderable) {
  10393. this.container = this._createContainer(ignoreBorder);
  10394. }
  10395. if (createQuadrilaterals) {
  10396. this.quadrilaterals = this._createQuadrilaterals(ignoreBorder);
  10397. }
  10398. }
  10399. _createContainer(ignoreBorder = false) {
  10400. const data = this.data,
  10401. page = this.page,
  10402. viewport = this.viewport;
  10403. const container = document.createElement("section");
  10404. const {
  10405. width,
  10406. height
  10407. } = getRectDims(data.rect);
  10408. const [pageLLx, pageLLy, pageURx, pageURy] = viewport.viewBox;
  10409. const pageWidth = pageURx - pageLLx;
  10410. const pageHeight = pageURy - pageLLy;
  10411. container.setAttribute("data-annotation-id", data.id);
  10412. 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]]);
  10413. if (!ignoreBorder && data.borderStyle.width > 0) {
  10414. container.style.borderWidth = `${data.borderStyle.width}px`;
  10415. const horizontalRadius = data.borderStyle.horizontalCornerRadius;
  10416. const verticalRadius = data.borderStyle.verticalCornerRadius;
  10417. if (horizontalRadius > 0 || verticalRadius > 0) {
  10418. const radius = `calc(${horizontalRadius}px * var(--scale-factor)) / calc(${verticalRadius}px * var(--scale-factor))`;
  10419. container.style.borderRadius = radius;
  10420. } else if (this instanceof RadioButtonWidgetAnnotationElement) {
  10421. const radius = `calc(${width}px * var(--scale-factor)) / calc(${height}px * var(--scale-factor))`;
  10422. container.style.borderRadius = radius;
  10423. }
  10424. switch (data.borderStyle.style) {
  10425. case _util.AnnotationBorderStyleType.SOLID:
  10426. container.style.borderStyle = "solid";
  10427. break;
  10428. case _util.AnnotationBorderStyleType.DASHED:
  10429. container.style.borderStyle = "dashed";
  10430. break;
  10431. case _util.AnnotationBorderStyleType.BEVELED:
  10432. (0, _util.warn)("Unimplemented border style: beveled");
  10433. break;
  10434. case _util.AnnotationBorderStyleType.INSET:
  10435. (0, _util.warn)("Unimplemented border style: inset");
  10436. break;
  10437. case _util.AnnotationBorderStyleType.UNDERLINE:
  10438. container.style.borderBottomStyle = "solid";
  10439. break;
  10440. default:
  10441. break;
  10442. }
  10443. const borderColor = data.borderColor || null;
  10444. if (borderColor) {
  10445. container.style.borderColor = _util.Util.makeHexColor(borderColor[0] | 0, borderColor[1] | 0, borderColor[2] | 0);
  10446. } else {
  10447. container.style.borderWidth = 0;
  10448. }
  10449. }
  10450. container.style.left = `${100 * (rect[0] - pageLLx) / pageWidth}%`;
  10451. container.style.top = `${100 * (rect[1] - pageLLy) / pageHeight}%`;
  10452. const {
  10453. rotation
  10454. } = data;
  10455. if (data.hasOwnCanvas || rotation === 0) {
  10456. container.style.width = `${100 * width / pageWidth}%`;
  10457. container.style.height = `${100 * height / pageHeight}%`;
  10458. } else {
  10459. this.setRotation(rotation, container);
  10460. }
  10461. return container;
  10462. }
  10463. setRotation(angle, container = this.container) {
  10464. const [pageLLx, pageLLy, pageURx, pageURy] = this.viewport.viewBox;
  10465. const pageWidth = pageURx - pageLLx;
  10466. const pageHeight = pageURy - pageLLy;
  10467. const {
  10468. width,
  10469. height
  10470. } = getRectDims(this.data.rect);
  10471. let elementWidth, elementHeight;
  10472. if (angle % 180 === 0) {
  10473. elementWidth = 100 * width / pageWidth;
  10474. elementHeight = 100 * height / pageHeight;
  10475. } else {
  10476. elementWidth = 100 * height / pageWidth;
  10477. elementHeight = 100 * width / pageHeight;
  10478. }
  10479. container.style.width = `${elementWidth}%`;
  10480. container.style.height = `${elementHeight}%`;
  10481. container.setAttribute("data-main-rotation", (360 - angle) % 360);
  10482. }
  10483. get _commonActions() {
  10484. const setColor = (jsName, styleName, event) => {
  10485. const color = event.detail[jsName];
  10486. event.target.style[styleName] = _scripting_utils.ColorConverters[`${color[0]}_HTML`](color.slice(1));
  10487. };
  10488. return (0, _util.shadow)(this, "_commonActions", {
  10489. display: event => {
  10490. const hidden = event.detail.display % 2 === 1;
  10491. this.container.style.visibility = hidden ? "hidden" : "visible";
  10492. this.annotationStorage.setValue(this.data.id, {
  10493. hidden,
  10494. print: event.detail.display === 0 || event.detail.display === 3
  10495. });
  10496. },
  10497. print: event => {
  10498. this.annotationStorage.setValue(this.data.id, {
  10499. print: event.detail.print
  10500. });
  10501. },
  10502. hidden: event => {
  10503. this.container.style.visibility = event.detail.hidden ? "hidden" : "visible";
  10504. this.annotationStorage.setValue(this.data.id, {
  10505. hidden: event.detail.hidden
  10506. });
  10507. },
  10508. focus: event => {
  10509. setTimeout(() => event.target.focus({
  10510. preventScroll: false
  10511. }), 0);
  10512. },
  10513. userName: event => {
  10514. event.target.title = event.detail.userName;
  10515. },
  10516. readonly: event => {
  10517. if (event.detail.readonly) {
  10518. event.target.setAttribute("readonly", "");
  10519. } else {
  10520. event.target.removeAttribute("readonly");
  10521. }
  10522. },
  10523. required: event => {
  10524. this._setRequired(event.target, event.detail.required);
  10525. },
  10526. bgColor: event => {
  10527. setColor("bgColor", "backgroundColor", event);
  10528. },
  10529. fillColor: event => {
  10530. setColor("fillColor", "backgroundColor", event);
  10531. },
  10532. fgColor: event => {
  10533. setColor("fgColor", "color", event);
  10534. },
  10535. textColor: event => {
  10536. setColor("textColor", "color", event);
  10537. },
  10538. borderColor: event => {
  10539. setColor("borderColor", "borderColor", event);
  10540. },
  10541. strokeColor: event => {
  10542. setColor("strokeColor", "borderColor", event);
  10543. },
  10544. rotation: event => {
  10545. const angle = event.detail.rotation;
  10546. this.setRotation(angle);
  10547. this.annotationStorage.setValue(this.data.id, {
  10548. rotation: angle
  10549. });
  10550. }
  10551. });
  10552. }
  10553. _dispatchEventFromSandbox(actions, jsEvent) {
  10554. const commonActions = this._commonActions;
  10555. for (const name of Object.keys(jsEvent.detail)) {
  10556. const action = actions[name] || commonActions[name];
  10557. if (action) {
  10558. action(jsEvent);
  10559. }
  10560. }
  10561. }
  10562. _setDefaultPropertiesFromJS(element) {
  10563. if (!this.enableScripting) {
  10564. return;
  10565. }
  10566. const storedData = this.annotationStorage.getRawValue(this.data.id);
  10567. if (!storedData) {
  10568. return;
  10569. }
  10570. const commonActions = this._commonActions;
  10571. for (const [actionName, detail] of Object.entries(storedData)) {
  10572. const action = commonActions[actionName];
  10573. if (action) {
  10574. const eventProxy = {
  10575. detail: {
  10576. [actionName]: detail
  10577. },
  10578. target: element
  10579. };
  10580. action(eventProxy);
  10581. delete storedData[actionName];
  10582. }
  10583. }
  10584. }
  10585. _createQuadrilaterals(ignoreBorder = false) {
  10586. if (!this.data.quadPoints) {
  10587. return null;
  10588. }
  10589. const quadrilaterals = [];
  10590. const savedRect = this.data.rect;
  10591. for (const quadPoint of this.data.quadPoints) {
  10592. this.data.rect = [quadPoint[2].x, quadPoint[2].y, quadPoint[1].x, quadPoint[1].y];
  10593. quadrilaterals.push(this._createContainer(ignoreBorder));
  10594. }
  10595. this.data.rect = savedRect;
  10596. return quadrilaterals;
  10597. }
  10598. _createPopup(trigger, data) {
  10599. let container = this.container;
  10600. if (this.quadrilaterals) {
  10601. trigger = trigger || this.quadrilaterals;
  10602. container = this.quadrilaterals[0];
  10603. }
  10604. if (!trigger) {
  10605. trigger = document.createElement("div");
  10606. trigger.className = "popupTriggerArea";
  10607. container.append(trigger);
  10608. }
  10609. const popupElement = new PopupElement({
  10610. container,
  10611. trigger,
  10612. color: data.color,
  10613. titleObj: data.titleObj,
  10614. modificationDate: data.modificationDate,
  10615. contentsObj: data.contentsObj,
  10616. richText: data.richText,
  10617. hideWrapper: true
  10618. });
  10619. const popup = popupElement.render();
  10620. popup.style.left = "100%";
  10621. container.append(popup);
  10622. }
  10623. _renderQuadrilaterals(className) {
  10624. for (const quadrilateral of this.quadrilaterals) {
  10625. quadrilateral.className = className;
  10626. }
  10627. return this.quadrilaterals;
  10628. }
  10629. render() {
  10630. (0, _util.unreachable)("Abstract method `AnnotationElement.render` called");
  10631. }
  10632. _getElementsByName(name, skipId = null) {
  10633. const fields = [];
  10634. if (this._fieldObjects) {
  10635. const fieldObj = this._fieldObjects[name];
  10636. if (fieldObj) {
  10637. for (const {
  10638. page,
  10639. id,
  10640. exportValues
  10641. } of fieldObj) {
  10642. if (page === -1) {
  10643. continue;
  10644. }
  10645. if (id === skipId) {
  10646. continue;
  10647. }
  10648. const exportValue = typeof exportValues === "string" ? exportValues : null;
  10649. const domElement = document.querySelector(`[data-element-id="${id}"]`);
  10650. if (domElement && !GetElementsByNameSet.has(domElement)) {
  10651. (0, _util.warn)(`_getElementsByName - element not allowed: ${id}`);
  10652. continue;
  10653. }
  10654. fields.push({
  10655. id,
  10656. exportValue,
  10657. domElement
  10658. });
  10659. }
  10660. }
  10661. return fields;
  10662. }
  10663. for (const domElement of document.getElementsByName(name)) {
  10664. const {
  10665. id,
  10666. exportValue
  10667. } = domElement;
  10668. if (id === skipId) {
  10669. continue;
  10670. }
  10671. if (!GetElementsByNameSet.has(domElement)) {
  10672. continue;
  10673. }
  10674. fields.push({
  10675. id,
  10676. exportValue,
  10677. domElement
  10678. });
  10679. }
  10680. return fields;
  10681. }
  10682. static get platform() {
  10683. const platform = typeof navigator !== "undefined" ? navigator.platform : "";
  10684. return (0, _util.shadow)(this, "platform", {
  10685. isWin: platform.includes("Win"),
  10686. isMac: platform.includes("Mac")
  10687. });
  10688. }
  10689. }
  10690. class LinkAnnotationElement extends AnnotationElement {
  10691. constructor(parameters, options = null) {
  10692. super(parameters, {
  10693. isRenderable: true,
  10694. ignoreBorder: !!options?.ignoreBorder,
  10695. createQuadrilaterals: true
  10696. });
  10697. this.isTooltipOnly = parameters.data.isTooltipOnly;
  10698. }
  10699. render() {
  10700. const {
  10701. data,
  10702. linkService
  10703. } = this;
  10704. const link = document.createElement("a");
  10705. link.setAttribute("data-element-id", data.id);
  10706. let isBound = false;
  10707. if (data.url) {
  10708. linkService.addLinkAttributes(link, data.url, data.newWindow);
  10709. isBound = true;
  10710. } else if (data.action) {
  10711. this._bindNamedAction(link, data.action);
  10712. isBound = true;
  10713. } else if (data.dest) {
  10714. this._bindLink(link, data.dest);
  10715. isBound = true;
  10716. } else {
  10717. if (data.actions && (data.actions.Action || data.actions["Mouse Up"] || data.actions["Mouse Down"]) && this.enableScripting && this.hasJSActions) {
  10718. this._bindJSAction(link, data);
  10719. isBound = true;
  10720. }
  10721. if (data.resetForm) {
  10722. this._bindResetFormAction(link, data.resetForm);
  10723. isBound = true;
  10724. } else if (this.isTooltipOnly && !isBound) {
  10725. this._bindLink(link, "");
  10726. isBound = true;
  10727. }
  10728. }
  10729. if (this.quadrilaterals) {
  10730. return this._renderQuadrilaterals("linkAnnotation").map((quadrilateral, index) => {
  10731. const linkElement = index === 0 ? link : link.cloneNode();
  10732. quadrilateral.append(linkElement);
  10733. return quadrilateral;
  10734. });
  10735. }
  10736. this.container.className = "linkAnnotation";
  10737. if (isBound) {
  10738. this.container.append(link);
  10739. }
  10740. return this.container;
  10741. }
  10742. _bindLink(link, destination) {
  10743. link.href = this.linkService.getDestinationHash(destination);
  10744. link.onclick = () => {
  10745. if (destination) {
  10746. this.linkService.goToDestination(destination);
  10747. }
  10748. return false;
  10749. };
  10750. if (destination || destination === "") {
  10751. link.className = "internalLink";
  10752. }
  10753. }
  10754. _bindNamedAction(link, action) {
  10755. link.href = this.linkService.getAnchorUrl("");
  10756. link.onclick = () => {
  10757. this.linkService.executeNamedAction(action);
  10758. return false;
  10759. };
  10760. link.className = "internalLink";
  10761. }
  10762. _bindJSAction(link, data) {
  10763. link.href = this.linkService.getAnchorUrl("");
  10764. const map = new Map([["Action", "onclick"], ["Mouse Up", "onmouseup"], ["Mouse Down", "onmousedown"]]);
  10765. for (const name of Object.keys(data.actions)) {
  10766. const jsName = map.get(name);
  10767. if (!jsName) {
  10768. continue;
  10769. }
  10770. link[jsName] = () => {
  10771. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  10772. source: this,
  10773. detail: {
  10774. id: data.id,
  10775. name
  10776. }
  10777. });
  10778. return false;
  10779. };
  10780. }
  10781. if (!link.onclick) {
  10782. link.onclick = () => false;
  10783. }
  10784. link.className = "internalLink";
  10785. }
  10786. _bindResetFormAction(link, resetForm) {
  10787. const otherClickAction = link.onclick;
  10788. if (!otherClickAction) {
  10789. link.href = this.linkService.getAnchorUrl("");
  10790. }
  10791. link.className = "internalLink";
  10792. if (!this._fieldObjects) {
  10793. (0, _util.warn)(`_bindResetFormAction - "resetForm" action not supported, ` + "ensure that the `fieldObjects` parameter is provided.");
  10794. if (!otherClickAction) {
  10795. link.onclick = () => false;
  10796. }
  10797. return;
  10798. }
  10799. link.onclick = () => {
  10800. if (otherClickAction) {
  10801. otherClickAction();
  10802. }
  10803. const {
  10804. fields: resetFormFields,
  10805. refs: resetFormRefs,
  10806. include
  10807. } = resetForm;
  10808. const allFields = [];
  10809. if (resetFormFields.length !== 0 || resetFormRefs.length !== 0) {
  10810. const fieldIds = new Set(resetFormRefs);
  10811. for (const fieldName of resetFormFields) {
  10812. const fields = this._fieldObjects[fieldName] || [];
  10813. for (const {
  10814. id
  10815. } of fields) {
  10816. fieldIds.add(id);
  10817. }
  10818. }
  10819. for (const fields of Object.values(this._fieldObjects)) {
  10820. for (const field of fields) {
  10821. if (fieldIds.has(field.id) === include) {
  10822. allFields.push(field);
  10823. }
  10824. }
  10825. }
  10826. } else {
  10827. for (const fields of Object.values(this._fieldObjects)) {
  10828. allFields.push(...fields);
  10829. }
  10830. }
  10831. const storage = this.annotationStorage;
  10832. const allIds = [];
  10833. for (const field of allFields) {
  10834. const {
  10835. id
  10836. } = field;
  10837. allIds.push(id);
  10838. switch (field.type) {
  10839. case "text":
  10840. {
  10841. const value = field.defaultValue || "";
  10842. storage.setValue(id, {
  10843. value
  10844. });
  10845. break;
  10846. }
  10847. case "checkbox":
  10848. case "radiobutton":
  10849. {
  10850. const value = field.defaultValue === field.exportValues;
  10851. storage.setValue(id, {
  10852. value
  10853. });
  10854. break;
  10855. }
  10856. case "combobox":
  10857. case "listbox":
  10858. {
  10859. const value = field.defaultValue || "";
  10860. storage.setValue(id, {
  10861. value
  10862. });
  10863. break;
  10864. }
  10865. default:
  10866. continue;
  10867. }
  10868. const domElement = document.querySelector(`[data-element-id="${id}"]`);
  10869. if (!domElement) {
  10870. continue;
  10871. } else if (!GetElementsByNameSet.has(domElement)) {
  10872. (0, _util.warn)(`_bindResetFormAction - element not allowed: ${id}`);
  10873. continue;
  10874. }
  10875. domElement.dispatchEvent(new Event("resetform"));
  10876. }
  10877. if (this.enableScripting) {
  10878. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  10879. source: this,
  10880. detail: {
  10881. id: "app",
  10882. ids: allIds,
  10883. name: "ResetForm"
  10884. }
  10885. });
  10886. }
  10887. return false;
  10888. };
  10889. }
  10890. }
  10891. class TextAnnotationElement extends AnnotationElement {
  10892. constructor(parameters) {
  10893. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  10894. super(parameters, {
  10895. isRenderable
  10896. });
  10897. }
  10898. render() {
  10899. this.container.className = "textAnnotation";
  10900. const image = document.createElement("img");
  10901. image.src = this.imageResourcesPath + "annotation-" + this.data.name.toLowerCase() + ".svg";
  10902. image.alt = "[{{type}} Annotation]";
  10903. image.dataset.l10nId = "text_annotation_type";
  10904. image.dataset.l10nArgs = JSON.stringify({
  10905. type: this.data.name
  10906. });
  10907. if (!this.data.hasPopup) {
  10908. this._createPopup(image, this.data);
  10909. }
  10910. this.container.append(image);
  10911. return this.container;
  10912. }
  10913. }
  10914. class WidgetAnnotationElement extends AnnotationElement {
  10915. render() {
  10916. if (this.data.alternativeText) {
  10917. this.container.title = this.data.alternativeText;
  10918. }
  10919. return this.container;
  10920. }
  10921. _getKeyModifier(event) {
  10922. const {
  10923. isWin,
  10924. isMac
  10925. } = AnnotationElement.platform;
  10926. return isWin && event.ctrlKey || isMac && event.metaKey;
  10927. }
  10928. _setEventListener(element, baseName, eventName, valueGetter) {
  10929. if (baseName.includes("mouse")) {
  10930. element.addEventListener(baseName, event => {
  10931. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  10932. source: this,
  10933. detail: {
  10934. id: this.data.id,
  10935. name: eventName,
  10936. value: valueGetter(event),
  10937. shift: event.shiftKey,
  10938. modifier: this._getKeyModifier(event)
  10939. }
  10940. });
  10941. });
  10942. } else {
  10943. element.addEventListener(baseName, event => {
  10944. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  10945. source: this,
  10946. detail: {
  10947. id: this.data.id,
  10948. name: eventName,
  10949. value: valueGetter(event)
  10950. }
  10951. });
  10952. });
  10953. }
  10954. }
  10955. _setEventListeners(element, names, getter) {
  10956. for (const [baseName, eventName] of names) {
  10957. if (eventName === "Action" || this.data.actions?.[eventName]) {
  10958. this._setEventListener(element, baseName, eventName, getter);
  10959. }
  10960. }
  10961. }
  10962. _setBackgroundColor(element) {
  10963. const color = this.data.backgroundColor || null;
  10964. element.style.backgroundColor = color === null ? "transparent" : _util.Util.makeHexColor(color[0], color[1], color[2]);
  10965. }
  10966. _setTextStyle(element) {
  10967. const TEXT_ALIGNMENT = ["left", "center", "right"];
  10968. const {
  10969. fontColor
  10970. } = this.data.defaultAppearanceData;
  10971. const fontSize = this.data.defaultAppearanceData.fontSize || DEFAULT_FONT_SIZE;
  10972. const style = element.style;
  10973. let computedFontSize;
  10974. if (this.data.multiLine) {
  10975. const height = Math.abs(this.data.rect[3] - this.data.rect[1]);
  10976. const numberOfLines = Math.round(height / (_util.LINE_FACTOR * fontSize)) || 1;
  10977. const lineHeight = height / numberOfLines;
  10978. computedFontSize = Math.min(fontSize, Math.round(lineHeight / _util.LINE_FACTOR));
  10979. } else {
  10980. const height = Math.abs(this.data.rect[3] - this.data.rect[1]);
  10981. computedFontSize = Math.min(fontSize, Math.round(height / _util.LINE_FACTOR));
  10982. }
  10983. style.fontSize = `calc(${computedFontSize}px * var(--scale-factor))`;
  10984. style.color = _util.Util.makeHexColor(fontColor[0], fontColor[1], fontColor[2]);
  10985. if (this.data.textAlignment !== null) {
  10986. style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
  10987. }
  10988. }
  10989. _setRequired(element, isRequired) {
  10990. if (isRequired) {
  10991. element.setAttribute("required", true);
  10992. } else {
  10993. element.removeAttribute("required");
  10994. }
  10995. element.setAttribute("aria-required", isRequired);
  10996. }
  10997. }
  10998. class TextWidgetAnnotationElement extends WidgetAnnotationElement {
  10999. constructor(parameters) {
  11000. const isRenderable = parameters.renderForms || !parameters.data.hasAppearance && !!parameters.data.fieldValue;
  11001. super(parameters, {
  11002. isRenderable
  11003. });
  11004. }
  11005. setPropertyOnSiblings(base, key, value, keyInStorage) {
  11006. const storage = this.annotationStorage;
  11007. for (const element of this._getElementsByName(base.name, base.id)) {
  11008. if (element.domElement) {
  11009. element.domElement[key] = value;
  11010. }
  11011. storage.setValue(element.id, {
  11012. [keyInStorage]: value
  11013. });
  11014. }
  11015. }
  11016. render() {
  11017. const storage = this.annotationStorage;
  11018. const id = this.data.id;
  11019. this.container.className = "textWidgetAnnotation";
  11020. let element = null;
  11021. if (this.renderForms) {
  11022. const storedData = storage.getValue(id, {
  11023. value: this.data.fieldValue
  11024. });
  11025. let textContent = storedData.formattedValue || storedData.value || "";
  11026. const maxLen = storage.getValue(id, {
  11027. charLimit: this.data.maxLen
  11028. }).charLimit;
  11029. if (maxLen && textContent.length > maxLen) {
  11030. textContent = textContent.slice(0, maxLen);
  11031. }
  11032. const elementData = {
  11033. userValue: textContent,
  11034. formattedValue: null,
  11035. valueOnFocus: ""
  11036. };
  11037. if (this.data.multiLine) {
  11038. element = document.createElement("textarea");
  11039. element.textContent = textContent;
  11040. if (this.data.doNotScroll) {
  11041. element.style.overflowY = "hidden";
  11042. }
  11043. } else {
  11044. element = document.createElement("input");
  11045. element.type = "text";
  11046. element.setAttribute("value", textContent);
  11047. if (this.data.doNotScroll) {
  11048. element.style.overflowX = "hidden";
  11049. }
  11050. }
  11051. GetElementsByNameSet.add(element);
  11052. element.setAttribute("data-element-id", id);
  11053. element.disabled = this.data.readOnly;
  11054. element.name = this.data.fieldName;
  11055. element.tabIndex = DEFAULT_TAB_INDEX;
  11056. this._setRequired(element, this.data.required);
  11057. if (maxLen) {
  11058. element.maxLength = maxLen;
  11059. }
  11060. element.addEventListener("input", event => {
  11061. storage.setValue(id, {
  11062. value: event.target.value
  11063. });
  11064. this.setPropertyOnSiblings(element, "value", event.target.value, "value");
  11065. });
  11066. element.addEventListener("resetform", event => {
  11067. const defaultValue = this.data.defaultFieldValue ?? "";
  11068. element.value = elementData.userValue = defaultValue;
  11069. elementData.formattedValue = null;
  11070. });
  11071. let blurListener = event => {
  11072. const {
  11073. formattedValue
  11074. } = elementData;
  11075. if (formattedValue !== null && formattedValue !== undefined) {
  11076. event.target.value = formattedValue;
  11077. }
  11078. event.target.scrollLeft = 0;
  11079. };
  11080. if (this.enableScripting && this.hasJSActions) {
  11081. element.addEventListener("focus", event => {
  11082. if (elementData.userValue) {
  11083. event.target.value = elementData.userValue;
  11084. }
  11085. elementData.valueOnFocus = event.target.value;
  11086. });
  11087. element.addEventListener("updatefromsandbox", jsEvent => {
  11088. const actions = {
  11089. value(event) {
  11090. elementData.userValue = event.detail.value ?? "";
  11091. storage.setValue(id, {
  11092. value: elementData.userValue.toString()
  11093. });
  11094. event.target.value = elementData.userValue;
  11095. },
  11096. formattedValue(event) {
  11097. const {
  11098. formattedValue
  11099. } = event.detail;
  11100. elementData.formattedValue = formattedValue;
  11101. if (formattedValue !== null && formattedValue !== undefined && event.target !== document.activeElement) {
  11102. event.target.value = formattedValue;
  11103. }
  11104. storage.setValue(id, {
  11105. formattedValue
  11106. });
  11107. },
  11108. selRange(event) {
  11109. event.target.setSelectionRange(...event.detail.selRange);
  11110. },
  11111. charLimit: event => {
  11112. const {
  11113. charLimit
  11114. } = event.detail;
  11115. const {
  11116. target
  11117. } = event;
  11118. if (charLimit === 0) {
  11119. target.removeAttribute("maxLength");
  11120. return;
  11121. }
  11122. target.setAttribute("maxLength", charLimit);
  11123. let value = elementData.userValue;
  11124. if (!value || value.length <= charLimit) {
  11125. return;
  11126. }
  11127. value = value.slice(0, charLimit);
  11128. target.value = elementData.userValue = value;
  11129. storage.setValue(id, {
  11130. value
  11131. });
  11132. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  11133. source: this,
  11134. detail: {
  11135. id,
  11136. name: "Keystroke",
  11137. value,
  11138. willCommit: true,
  11139. commitKey: 1,
  11140. selStart: target.selectionStart,
  11141. selEnd: target.selectionEnd
  11142. }
  11143. });
  11144. }
  11145. };
  11146. this._dispatchEventFromSandbox(actions, jsEvent);
  11147. });
  11148. element.addEventListener("keydown", event => {
  11149. let commitKey = -1;
  11150. if (event.key === "Escape") {
  11151. commitKey = 0;
  11152. } else if (event.key === "Enter") {
  11153. commitKey = 2;
  11154. } else if (event.key === "Tab") {
  11155. commitKey = 3;
  11156. }
  11157. if (commitKey === -1) {
  11158. return;
  11159. }
  11160. const {
  11161. value
  11162. } = event.target;
  11163. if (elementData.valueOnFocus === value) {
  11164. return;
  11165. }
  11166. elementData.userValue = value;
  11167. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  11168. source: this,
  11169. detail: {
  11170. id,
  11171. name: "Keystroke",
  11172. value,
  11173. willCommit: true,
  11174. commitKey,
  11175. selStart: event.target.selectionStart,
  11176. selEnd: event.target.selectionEnd
  11177. }
  11178. });
  11179. });
  11180. const _blurListener = blurListener;
  11181. blurListener = null;
  11182. element.addEventListener("blur", event => {
  11183. const {
  11184. value
  11185. } = event.target;
  11186. elementData.userValue = value;
  11187. if (this._mouseState.isDown && elementData.valueOnFocus !== value) {
  11188. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  11189. source: this,
  11190. detail: {
  11191. id,
  11192. name: "Keystroke",
  11193. value,
  11194. willCommit: true,
  11195. commitKey: 1,
  11196. selStart: event.target.selectionStart,
  11197. selEnd: event.target.selectionEnd
  11198. }
  11199. });
  11200. }
  11201. _blurListener(event);
  11202. });
  11203. if (this.data.actions?.Keystroke) {
  11204. element.addEventListener("beforeinput", event => {
  11205. const {
  11206. data,
  11207. target
  11208. } = event;
  11209. const {
  11210. value,
  11211. selectionStart,
  11212. selectionEnd
  11213. } = target;
  11214. let selStart = selectionStart,
  11215. selEnd = selectionEnd;
  11216. switch (event.inputType) {
  11217. case "deleteWordBackward":
  11218. {
  11219. const match = value.substring(0, selectionStart).match(/\w*[^\w]*$/);
  11220. if (match) {
  11221. selStart -= match[0].length;
  11222. }
  11223. break;
  11224. }
  11225. case "deleteWordForward":
  11226. {
  11227. const match = value.substring(selectionStart).match(/^[^\w]*\w*/);
  11228. if (match) {
  11229. selEnd += match[0].length;
  11230. }
  11231. break;
  11232. }
  11233. case "deleteContentBackward":
  11234. if (selectionStart === selectionEnd) {
  11235. selStart -= 1;
  11236. }
  11237. break;
  11238. case "deleteContentForward":
  11239. if (selectionStart === selectionEnd) {
  11240. selEnd += 1;
  11241. }
  11242. break;
  11243. }
  11244. event.preventDefault();
  11245. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  11246. source: this,
  11247. detail: {
  11248. id,
  11249. name: "Keystroke",
  11250. value,
  11251. change: data || "",
  11252. willCommit: false,
  11253. selStart,
  11254. selEnd
  11255. }
  11256. });
  11257. });
  11258. }
  11259. this._setEventListeners(element, [["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"]], event => event.target.value);
  11260. }
  11261. if (blurListener) {
  11262. element.addEventListener("blur", blurListener);
  11263. }
  11264. if (this.data.comb) {
  11265. const fieldWidth = this.data.rect[2] - this.data.rect[0];
  11266. const combWidth = fieldWidth / maxLen;
  11267. element.classList.add("comb");
  11268. element.style.letterSpacing = `calc(${combWidth}px * var(--scale-factor) - 1ch)`;
  11269. }
  11270. } else {
  11271. element = document.createElement("div");
  11272. element.textContent = this.data.fieldValue;
  11273. element.style.verticalAlign = "middle";
  11274. element.style.display = "table-cell";
  11275. }
  11276. this._setTextStyle(element);
  11277. this._setBackgroundColor(element);
  11278. this._setDefaultPropertiesFromJS(element);
  11279. this.container.append(element);
  11280. return this.container;
  11281. }
  11282. }
  11283. class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement {
  11284. constructor(parameters) {
  11285. super(parameters, {
  11286. isRenderable: parameters.renderForms
  11287. });
  11288. }
  11289. render() {
  11290. const storage = this.annotationStorage;
  11291. const data = this.data;
  11292. const id = data.id;
  11293. let value = storage.getValue(id, {
  11294. value: data.exportValue === data.fieldValue
  11295. }).value;
  11296. if (typeof value === "string") {
  11297. value = value !== "Off";
  11298. storage.setValue(id, {
  11299. value
  11300. });
  11301. }
  11302. this.container.className = "buttonWidgetAnnotation checkBox";
  11303. const element = document.createElement("input");
  11304. GetElementsByNameSet.add(element);
  11305. element.setAttribute("data-element-id", id);
  11306. element.disabled = data.readOnly;
  11307. this._setRequired(element, this.data.required);
  11308. element.type = "checkbox";
  11309. element.name = data.fieldName;
  11310. if (value) {
  11311. element.setAttribute("checked", true);
  11312. }
  11313. element.setAttribute("exportValue", data.exportValue);
  11314. element.tabIndex = DEFAULT_TAB_INDEX;
  11315. element.addEventListener("change", event => {
  11316. const {
  11317. name,
  11318. checked
  11319. } = event.target;
  11320. for (const checkbox of this._getElementsByName(name, id)) {
  11321. const curChecked = checked && checkbox.exportValue === data.exportValue;
  11322. if (checkbox.domElement) {
  11323. checkbox.domElement.checked = curChecked;
  11324. }
  11325. storage.setValue(checkbox.id, {
  11326. value: curChecked
  11327. });
  11328. }
  11329. storage.setValue(id, {
  11330. value: checked
  11331. });
  11332. });
  11333. element.addEventListener("resetform", event => {
  11334. const defaultValue = data.defaultFieldValue || "Off";
  11335. event.target.checked = defaultValue === data.exportValue;
  11336. });
  11337. if (this.enableScripting && this.hasJSActions) {
  11338. element.addEventListener("updatefromsandbox", jsEvent => {
  11339. const actions = {
  11340. value(event) {
  11341. event.target.checked = event.detail.value !== "Off";
  11342. storage.setValue(id, {
  11343. value: event.target.checked
  11344. });
  11345. }
  11346. };
  11347. this._dispatchEventFromSandbox(actions, jsEvent);
  11348. });
  11349. 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);
  11350. }
  11351. this._setBackgroundColor(element);
  11352. this._setDefaultPropertiesFromJS(element);
  11353. this.container.append(element);
  11354. return this.container;
  11355. }
  11356. }
  11357. class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
  11358. constructor(parameters) {
  11359. super(parameters, {
  11360. isRenderable: parameters.renderForms
  11361. });
  11362. }
  11363. render() {
  11364. this.container.className = "buttonWidgetAnnotation radioButton";
  11365. const storage = this.annotationStorage;
  11366. const data = this.data;
  11367. const id = data.id;
  11368. let value = storage.getValue(id, {
  11369. value: data.fieldValue === data.buttonValue
  11370. }).value;
  11371. if (typeof value === "string") {
  11372. value = value !== data.buttonValue;
  11373. storage.setValue(id, {
  11374. value
  11375. });
  11376. }
  11377. const element = document.createElement("input");
  11378. GetElementsByNameSet.add(element);
  11379. element.setAttribute("data-element-id", id);
  11380. element.disabled = data.readOnly;
  11381. this._setRequired(element, this.data.required);
  11382. element.type = "radio";
  11383. element.name = data.fieldName;
  11384. if (value) {
  11385. element.setAttribute("checked", true);
  11386. }
  11387. element.tabIndex = DEFAULT_TAB_INDEX;
  11388. element.addEventListener("change", event => {
  11389. const {
  11390. name,
  11391. checked
  11392. } = event.target;
  11393. for (const radio of this._getElementsByName(name, id)) {
  11394. storage.setValue(radio.id, {
  11395. value: false
  11396. });
  11397. }
  11398. storage.setValue(id, {
  11399. value: checked
  11400. });
  11401. });
  11402. element.addEventListener("resetform", event => {
  11403. const defaultValue = data.defaultFieldValue;
  11404. event.target.checked = defaultValue !== null && defaultValue !== undefined && defaultValue === data.buttonValue;
  11405. });
  11406. if (this.enableScripting && this.hasJSActions) {
  11407. const pdfButtonValue = data.buttonValue;
  11408. element.addEventListener("updatefromsandbox", jsEvent => {
  11409. const actions = {
  11410. value: event => {
  11411. const checked = pdfButtonValue === event.detail.value;
  11412. for (const radio of this._getElementsByName(event.target.name)) {
  11413. const curChecked = checked && radio.id === id;
  11414. if (radio.domElement) {
  11415. radio.domElement.checked = curChecked;
  11416. }
  11417. storage.setValue(radio.id, {
  11418. value: curChecked
  11419. });
  11420. }
  11421. }
  11422. };
  11423. this._dispatchEventFromSandbox(actions, jsEvent);
  11424. });
  11425. 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);
  11426. }
  11427. this._setBackgroundColor(element);
  11428. this._setDefaultPropertiesFromJS(element);
  11429. this.container.append(element);
  11430. return this.container;
  11431. }
  11432. }
  11433. class PushButtonWidgetAnnotationElement extends LinkAnnotationElement {
  11434. constructor(parameters) {
  11435. super(parameters, {
  11436. ignoreBorder: parameters.data.hasAppearance
  11437. });
  11438. }
  11439. render() {
  11440. const container = super.render();
  11441. container.className = "buttonWidgetAnnotation pushButton";
  11442. if (this.data.alternativeText) {
  11443. container.title = this.data.alternativeText;
  11444. }
  11445. const linkElement = container.lastChild;
  11446. if (this.enableScripting && this.hasJSActions && linkElement) {
  11447. this._setDefaultPropertiesFromJS(linkElement);
  11448. linkElement.addEventListener("updatefromsandbox", jsEvent => {
  11449. this._dispatchEventFromSandbox({}, jsEvent);
  11450. });
  11451. }
  11452. return container;
  11453. }
  11454. }
  11455. class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
  11456. constructor(parameters) {
  11457. super(parameters, {
  11458. isRenderable: parameters.renderForms
  11459. });
  11460. }
  11461. render() {
  11462. this.container.className = "choiceWidgetAnnotation";
  11463. const storage = this.annotationStorage;
  11464. const id = this.data.id;
  11465. const storedData = storage.getValue(id, {
  11466. value: this.data.fieldValue
  11467. });
  11468. const selectElement = document.createElement("select");
  11469. GetElementsByNameSet.add(selectElement);
  11470. selectElement.setAttribute("data-element-id", id);
  11471. selectElement.disabled = this.data.readOnly;
  11472. this._setRequired(selectElement, this.data.required);
  11473. selectElement.name = this.data.fieldName;
  11474. selectElement.tabIndex = DEFAULT_TAB_INDEX;
  11475. let addAnEmptyEntry = this.data.combo && this.data.options.length > 0;
  11476. if (!this.data.combo) {
  11477. selectElement.size = this.data.options.length;
  11478. if (this.data.multiSelect) {
  11479. selectElement.multiple = true;
  11480. }
  11481. }
  11482. selectElement.addEventListener("resetform", event => {
  11483. const defaultValue = this.data.defaultFieldValue;
  11484. for (const option of selectElement.options) {
  11485. option.selected = option.value === defaultValue;
  11486. }
  11487. });
  11488. for (const option of this.data.options) {
  11489. const optionElement = document.createElement("option");
  11490. optionElement.textContent = option.displayValue;
  11491. optionElement.value = option.exportValue;
  11492. if (storedData.value.includes(option.exportValue)) {
  11493. optionElement.setAttribute("selected", true);
  11494. addAnEmptyEntry = false;
  11495. }
  11496. selectElement.append(optionElement);
  11497. }
  11498. let removeEmptyEntry = null;
  11499. if (addAnEmptyEntry) {
  11500. const noneOptionElement = document.createElement("option");
  11501. noneOptionElement.value = " ";
  11502. noneOptionElement.setAttribute("hidden", true);
  11503. noneOptionElement.setAttribute("selected", true);
  11504. selectElement.prepend(noneOptionElement);
  11505. removeEmptyEntry = () => {
  11506. noneOptionElement.remove();
  11507. selectElement.removeEventListener("input", removeEmptyEntry);
  11508. removeEmptyEntry = null;
  11509. };
  11510. selectElement.addEventListener("input", removeEmptyEntry);
  11511. }
  11512. const getValue = (event, isExport) => {
  11513. const name = isExport ? "value" : "textContent";
  11514. const options = event.target.options;
  11515. if (!event.target.multiple) {
  11516. return options.selectedIndex === -1 ? null : options[options.selectedIndex][name];
  11517. }
  11518. return Array.prototype.filter.call(options, option => option.selected).map(option => option[name]);
  11519. };
  11520. const getItems = event => {
  11521. const options = event.target.options;
  11522. return Array.prototype.map.call(options, option => {
  11523. return {
  11524. displayValue: option.textContent,
  11525. exportValue: option.value
  11526. };
  11527. });
  11528. };
  11529. if (this.enableScripting && this.hasJSActions) {
  11530. selectElement.addEventListener("updatefromsandbox", jsEvent => {
  11531. const actions = {
  11532. value(event) {
  11533. removeEmptyEntry?.();
  11534. const value = event.detail.value;
  11535. const values = new Set(Array.isArray(value) ? value : [value]);
  11536. for (const option of selectElement.options) {
  11537. option.selected = values.has(option.value);
  11538. }
  11539. storage.setValue(id, {
  11540. value: getValue(event, true)
  11541. });
  11542. },
  11543. multipleSelection(event) {
  11544. selectElement.multiple = true;
  11545. },
  11546. remove(event) {
  11547. const options = selectElement.options;
  11548. const index = event.detail.remove;
  11549. options[index].selected = false;
  11550. selectElement.remove(index);
  11551. if (options.length > 0) {
  11552. const i = Array.prototype.findIndex.call(options, option => option.selected);
  11553. if (i === -1) {
  11554. options[0].selected = true;
  11555. }
  11556. }
  11557. storage.setValue(id, {
  11558. value: getValue(event, true),
  11559. items: getItems(event)
  11560. });
  11561. },
  11562. clear(event) {
  11563. while (selectElement.length !== 0) {
  11564. selectElement.remove(0);
  11565. }
  11566. storage.setValue(id, {
  11567. value: null,
  11568. items: []
  11569. });
  11570. },
  11571. insert(event) {
  11572. const {
  11573. index,
  11574. displayValue,
  11575. exportValue
  11576. } = event.detail.insert;
  11577. const selectChild = selectElement.children[index];
  11578. const optionElement = document.createElement("option");
  11579. optionElement.textContent = displayValue;
  11580. optionElement.value = exportValue;
  11581. if (selectChild) {
  11582. selectChild.before(optionElement);
  11583. } else {
  11584. selectElement.append(optionElement);
  11585. }
  11586. storage.setValue(id, {
  11587. value: getValue(event, true),
  11588. items: getItems(event)
  11589. });
  11590. },
  11591. items(event) {
  11592. const {
  11593. items
  11594. } = event.detail;
  11595. while (selectElement.length !== 0) {
  11596. selectElement.remove(0);
  11597. }
  11598. for (const item of items) {
  11599. const {
  11600. displayValue,
  11601. exportValue
  11602. } = item;
  11603. const optionElement = document.createElement("option");
  11604. optionElement.textContent = displayValue;
  11605. optionElement.value = exportValue;
  11606. selectElement.append(optionElement);
  11607. }
  11608. if (selectElement.options.length > 0) {
  11609. selectElement.options[0].selected = true;
  11610. }
  11611. storage.setValue(id, {
  11612. value: getValue(event, true),
  11613. items: getItems(event)
  11614. });
  11615. },
  11616. indices(event) {
  11617. const indices = new Set(event.detail.indices);
  11618. for (const option of event.target.options) {
  11619. option.selected = indices.has(option.index);
  11620. }
  11621. storage.setValue(id, {
  11622. value: getValue(event, true)
  11623. });
  11624. },
  11625. editable(event) {
  11626. event.target.disabled = !event.detail.editable;
  11627. }
  11628. };
  11629. this._dispatchEventFromSandbox(actions, jsEvent);
  11630. });
  11631. selectElement.addEventListener("input", event => {
  11632. const exportValue = getValue(event, true);
  11633. const value = getValue(event, false);
  11634. storage.setValue(id, {
  11635. value: exportValue
  11636. });
  11637. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  11638. source: this,
  11639. detail: {
  11640. id,
  11641. name: "Keystroke",
  11642. value,
  11643. changeEx: exportValue,
  11644. willCommit: true,
  11645. commitKey: 1,
  11646. keyDown: false
  11647. }
  11648. });
  11649. });
  11650. 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);
  11651. } else {
  11652. selectElement.addEventListener("input", function (event) {
  11653. storage.setValue(id, {
  11654. value: getValue(event, true)
  11655. });
  11656. });
  11657. }
  11658. if (this.data.combo) {
  11659. this._setTextStyle(selectElement);
  11660. } else {}
  11661. this._setBackgroundColor(selectElement);
  11662. this._setDefaultPropertiesFromJS(selectElement);
  11663. this.container.append(selectElement);
  11664. return this.container;
  11665. }
  11666. }
  11667. class PopupAnnotationElement extends AnnotationElement {
  11668. constructor(parameters) {
  11669. const isRenderable = !!(parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  11670. super(parameters, {
  11671. isRenderable
  11672. });
  11673. }
  11674. render() {
  11675. const IGNORE_TYPES = ["Line", "Square", "Circle", "PolyLine", "Polygon", "Ink"];
  11676. this.container.className = "popupAnnotation";
  11677. if (IGNORE_TYPES.includes(this.data.parentType)) {
  11678. return this.container;
  11679. }
  11680. const selector = `[data-annotation-id="${this.data.parentId}"]`;
  11681. const parentElements = this.layer.querySelectorAll(selector);
  11682. if (parentElements.length === 0) {
  11683. return this.container;
  11684. }
  11685. const popup = new PopupElement({
  11686. container: this.container,
  11687. trigger: Array.from(parentElements),
  11688. color: this.data.color,
  11689. titleObj: this.data.titleObj,
  11690. modificationDate: this.data.modificationDate,
  11691. contentsObj: this.data.contentsObj,
  11692. richText: this.data.richText
  11693. });
  11694. const page = this.page;
  11695. 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]]);
  11696. const popupLeft = rect[0] + this.data.parentRect[2] - this.data.parentRect[0];
  11697. const popupTop = rect[1];
  11698. const [pageLLx, pageLLy, pageURx, pageURy] = this.viewport.viewBox;
  11699. const pageWidth = pageURx - pageLLx;
  11700. const pageHeight = pageURy - pageLLy;
  11701. this.container.style.left = `${100 * (popupLeft - pageLLx) / pageWidth}%`;
  11702. this.container.style.top = `${100 * (popupTop - pageLLy) / pageHeight}%`;
  11703. this.container.append(popup.render());
  11704. return this.container;
  11705. }
  11706. }
  11707. class PopupElement {
  11708. constructor(parameters) {
  11709. this.container = parameters.container;
  11710. this.trigger = parameters.trigger;
  11711. this.color = parameters.color;
  11712. this.titleObj = parameters.titleObj;
  11713. this.modificationDate = parameters.modificationDate;
  11714. this.contentsObj = parameters.contentsObj;
  11715. this.richText = parameters.richText;
  11716. this.hideWrapper = parameters.hideWrapper || false;
  11717. this.pinned = false;
  11718. }
  11719. render() {
  11720. const BACKGROUND_ENLIGHT = 0.7;
  11721. const wrapper = document.createElement("div");
  11722. wrapper.className = "popupWrapper";
  11723. this.hideElement = this.hideWrapper ? wrapper : this.container;
  11724. this.hideElement.hidden = true;
  11725. const popup = document.createElement("div");
  11726. popup.className = "popup";
  11727. const color = this.color;
  11728. if (color) {
  11729. const r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  11730. const g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  11731. const b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  11732. popup.style.backgroundColor = _util.Util.makeHexColor(r | 0, g | 0, b | 0);
  11733. }
  11734. const title = document.createElement("h1");
  11735. title.dir = this.titleObj.dir;
  11736. title.textContent = this.titleObj.str;
  11737. popup.append(title);
  11738. const dateObject = _display_utils.PDFDateString.toDateObject(this.modificationDate);
  11739. if (dateObject) {
  11740. const modificationDate = document.createElement("span");
  11741. modificationDate.className = "popupDate";
  11742. modificationDate.textContent = "{{date}}, {{time}}";
  11743. modificationDate.dataset.l10nId = "annotation_date_string";
  11744. modificationDate.dataset.l10nArgs = JSON.stringify({
  11745. date: dateObject.toLocaleDateString(),
  11746. time: dateObject.toLocaleTimeString()
  11747. });
  11748. popup.append(modificationDate);
  11749. }
  11750. if (this.richText?.str && (!this.contentsObj?.str || this.contentsObj.str === this.richText.str)) {
  11751. _xfa_layer.XfaLayer.render({
  11752. xfaHtml: this.richText.html,
  11753. intent: "richText",
  11754. div: popup
  11755. });
  11756. popup.lastChild.className = "richText popupContent";
  11757. } else {
  11758. const contents = this._formatContents(this.contentsObj);
  11759. popup.append(contents);
  11760. }
  11761. if (!Array.isArray(this.trigger)) {
  11762. this.trigger = [this.trigger];
  11763. }
  11764. for (const element of this.trigger) {
  11765. element.addEventListener("click", this._toggle.bind(this));
  11766. element.addEventListener("mouseover", this._show.bind(this, false));
  11767. element.addEventListener("mouseout", this._hide.bind(this, false));
  11768. }
  11769. popup.addEventListener("click", this._hide.bind(this, true));
  11770. wrapper.append(popup);
  11771. return wrapper;
  11772. }
  11773. _formatContents({
  11774. str,
  11775. dir
  11776. }) {
  11777. const p = document.createElement("p");
  11778. p.className = "popupContent";
  11779. p.dir = dir;
  11780. const lines = str.split(/(?:\r\n?|\n)/);
  11781. for (let i = 0, ii = lines.length; i < ii; ++i) {
  11782. const line = lines[i];
  11783. p.append(document.createTextNode(line));
  11784. if (i < ii - 1) {
  11785. p.append(document.createElement("br"));
  11786. }
  11787. }
  11788. return p;
  11789. }
  11790. _toggle() {
  11791. if (this.pinned) {
  11792. this._hide(true);
  11793. } else {
  11794. this._show(true);
  11795. }
  11796. }
  11797. _show(pin = false) {
  11798. if (pin) {
  11799. this.pinned = true;
  11800. }
  11801. if (this.hideElement.hidden) {
  11802. this.hideElement.hidden = false;
  11803. this.container.style.zIndex = parseInt(this.container.style.zIndex) + 1000;
  11804. }
  11805. }
  11806. _hide(unpin = true) {
  11807. if (unpin) {
  11808. this.pinned = false;
  11809. }
  11810. if (!this.hideElement.hidden && !this.pinned) {
  11811. this.hideElement.hidden = true;
  11812. this.container.style.zIndex = parseInt(this.container.style.zIndex) - 1000;
  11813. }
  11814. }
  11815. }
  11816. class FreeTextAnnotationElement extends AnnotationElement {
  11817. constructor(parameters) {
  11818. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  11819. super(parameters, {
  11820. isRenderable,
  11821. ignoreBorder: true
  11822. });
  11823. this.textContent = parameters.data.textContent;
  11824. }
  11825. render() {
  11826. this.container.className = "freeTextAnnotation";
  11827. if (this.textContent) {
  11828. const content = document.createElement("div");
  11829. content.className = "annotationTextContent";
  11830. content.setAttribute("role", "comment");
  11831. for (const line of this.textContent) {
  11832. const lineSpan = document.createElement("span");
  11833. lineSpan.textContent = line;
  11834. content.append(lineSpan);
  11835. }
  11836. this.container.append(content);
  11837. }
  11838. if (!this.data.hasPopup) {
  11839. this._createPopup(null, this.data);
  11840. }
  11841. return this.container;
  11842. }
  11843. }
  11844. class LineAnnotationElement extends AnnotationElement {
  11845. constructor(parameters) {
  11846. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  11847. super(parameters, {
  11848. isRenderable,
  11849. ignoreBorder: true
  11850. });
  11851. }
  11852. render() {
  11853. this.container.className = "lineAnnotation";
  11854. const data = this.data;
  11855. const {
  11856. width,
  11857. height
  11858. } = getRectDims(data.rect);
  11859. const svg = this.svgFactory.create(width, height, true);
  11860. const line = this.svgFactory.createElement("svg:line");
  11861. line.setAttribute("x1", data.rect[2] - data.lineCoordinates[0]);
  11862. line.setAttribute("y1", data.rect[3] - data.lineCoordinates[1]);
  11863. line.setAttribute("x2", data.rect[2] - data.lineCoordinates[2]);
  11864. line.setAttribute("y2", data.rect[3] - data.lineCoordinates[3]);
  11865. line.setAttribute("stroke-width", data.borderStyle.width || 1);
  11866. line.setAttribute("stroke", "transparent");
  11867. line.setAttribute("fill", "transparent");
  11868. svg.append(line);
  11869. this.container.append(svg);
  11870. this._createPopup(line, data);
  11871. return this.container;
  11872. }
  11873. }
  11874. class SquareAnnotationElement extends AnnotationElement {
  11875. constructor(parameters) {
  11876. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  11877. super(parameters, {
  11878. isRenderable,
  11879. ignoreBorder: true
  11880. });
  11881. }
  11882. render() {
  11883. this.container.className = "squareAnnotation";
  11884. const data = this.data;
  11885. const {
  11886. width,
  11887. height
  11888. } = getRectDims(data.rect);
  11889. const svg = this.svgFactory.create(width, height, true);
  11890. const borderWidth = data.borderStyle.width;
  11891. const square = this.svgFactory.createElement("svg:rect");
  11892. square.setAttribute("x", borderWidth / 2);
  11893. square.setAttribute("y", borderWidth / 2);
  11894. square.setAttribute("width", width - borderWidth);
  11895. square.setAttribute("height", height - borderWidth);
  11896. square.setAttribute("stroke-width", borderWidth || 1);
  11897. square.setAttribute("stroke", "transparent");
  11898. square.setAttribute("fill", "transparent");
  11899. svg.append(square);
  11900. this.container.append(svg);
  11901. this._createPopup(square, data);
  11902. return this.container;
  11903. }
  11904. }
  11905. class CircleAnnotationElement extends AnnotationElement {
  11906. constructor(parameters) {
  11907. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  11908. super(parameters, {
  11909. isRenderable,
  11910. ignoreBorder: true
  11911. });
  11912. }
  11913. render() {
  11914. this.container.className = "circleAnnotation";
  11915. const data = this.data;
  11916. const {
  11917. width,
  11918. height
  11919. } = getRectDims(data.rect);
  11920. const svg = this.svgFactory.create(width, height, true);
  11921. const borderWidth = data.borderStyle.width;
  11922. const circle = this.svgFactory.createElement("svg:ellipse");
  11923. circle.setAttribute("cx", width / 2);
  11924. circle.setAttribute("cy", height / 2);
  11925. circle.setAttribute("rx", width / 2 - borderWidth / 2);
  11926. circle.setAttribute("ry", height / 2 - borderWidth / 2);
  11927. circle.setAttribute("stroke-width", borderWidth || 1);
  11928. circle.setAttribute("stroke", "transparent");
  11929. circle.setAttribute("fill", "transparent");
  11930. svg.append(circle);
  11931. this.container.append(svg);
  11932. this._createPopup(circle, data);
  11933. return this.container;
  11934. }
  11935. }
  11936. class PolylineAnnotationElement extends AnnotationElement {
  11937. constructor(parameters) {
  11938. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  11939. super(parameters, {
  11940. isRenderable,
  11941. ignoreBorder: true
  11942. });
  11943. this.containerClassName = "polylineAnnotation";
  11944. this.svgElementName = "svg:polyline";
  11945. }
  11946. render() {
  11947. this.container.className = this.containerClassName;
  11948. const data = this.data;
  11949. const {
  11950. width,
  11951. height
  11952. } = getRectDims(data.rect);
  11953. const svg = this.svgFactory.create(width, height, true);
  11954. let points = [];
  11955. for (const coordinate of data.vertices) {
  11956. const x = coordinate.x - data.rect[0];
  11957. const y = data.rect[3] - coordinate.y;
  11958. points.push(x + "," + y);
  11959. }
  11960. points = points.join(" ");
  11961. const polyline = this.svgFactory.createElement(this.svgElementName);
  11962. polyline.setAttribute("points", points);
  11963. polyline.setAttribute("stroke-width", data.borderStyle.width || 1);
  11964. polyline.setAttribute("stroke", "transparent");
  11965. polyline.setAttribute("fill", "transparent");
  11966. svg.append(polyline);
  11967. this.container.append(svg);
  11968. this._createPopup(polyline, data);
  11969. return this.container;
  11970. }
  11971. }
  11972. class PolygonAnnotationElement extends PolylineAnnotationElement {
  11973. constructor(parameters) {
  11974. super(parameters);
  11975. this.containerClassName = "polygonAnnotation";
  11976. this.svgElementName = "svg:polygon";
  11977. }
  11978. }
  11979. class CaretAnnotationElement extends AnnotationElement {
  11980. constructor(parameters) {
  11981. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  11982. super(parameters, {
  11983. isRenderable,
  11984. ignoreBorder: true
  11985. });
  11986. }
  11987. render() {
  11988. this.container.className = "caretAnnotation";
  11989. if (!this.data.hasPopup) {
  11990. this._createPopup(null, this.data);
  11991. }
  11992. return this.container;
  11993. }
  11994. }
  11995. class InkAnnotationElement extends AnnotationElement {
  11996. constructor(parameters) {
  11997. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  11998. super(parameters, {
  11999. isRenderable,
  12000. ignoreBorder: true
  12001. });
  12002. this.containerClassName = "inkAnnotation";
  12003. this.svgElementName = "svg:polyline";
  12004. }
  12005. render() {
  12006. this.container.className = this.containerClassName;
  12007. const data = this.data;
  12008. const {
  12009. width,
  12010. height
  12011. } = getRectDims(data.rect);
  12012. const svg = this.svgFactory.create(width, height, true);
  12013. for (const inkList of data.inkLists) {
  12014. let points = [];
  12015. for (const coordinate of inkList) {
  12016. const x = coordinate.x - data.rect[0];
  12017. const y = data.rect[3] - coordinate.y;
  12018. points.push(`${x},${y}`);
  12019. }
  12020. points = points.join(" ");
  12021. const polyline = this.svgFactory.createElement(this.svgElementName);
  12022. polyline.setAttribute("points", points);
  12023. polyline.setAttribute("stroke-width", data.borderStyle.width || 1);
  12024. polyline.setAttribute("stroke", "transparent");
  12025. polyline.setAttribute("fill", "transparent");
  12026. this._createPopup(polyline, data);
  12027. svg.append(polyline);
  12028. }
  12029. this.container.append(svg);
  12030. return this.container;
  12031. }
  12032. }
  12033. class HighlightAnnotationElement extends AnnotationElement {
  12034. constructor(parameters) {
  12035. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  12036. super(parameters, {
  12037. isRenderable,
  12038. ignoreBorder: true,
  12039. createQuadrilaterals: true
  12040. });
  12041. }
  12042. render() {
  12043. if (!this.data.hasPopup) {
  12044. this._createPopup(null, this.data);
  12045. }
  12046. if (this.quadrilaterals) {
  12047. return this._renderQuadrilaterals("highlightAnnotation");
  12048. }
  12049. this.container.className = "highlightAnnotation";
  12050. return this.container;
  12051. }
  12052. }
  12053. class UnderlineAnnotationElement extends AnnotationElement {
  12054. constructor(parameters) {
  12055. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  12056. super(parameters, {
  12057. isRenderable,
  12058. ignoreBorder: true,
  12059. createQuadrilaterals: true
  12060. });
  12061. }
  12062. render() {
  12063. if (!this.data.hasPopup) {
  12064. this._createPopup(null, this.data);
  12065. }
  12066. if (this.quadrilaterals) {
  12067. return this._renderQuadrilaterals("underlineAnnotation");
  12068. }
  12069. this.container.className = "underlineAnnotation";
  12070. return this.container;
  12071. }
  12072. }
  12073. class SquigglyAnnotationElement extends AnnotationElement {
  12074. constructor(parameters) {
  12075. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  12076. super(parameters, {
  12077. isRenderable,
  12078. ignoreBorder: true,
  12079. createQuadrilaterals: true
  12080. });
  12081. }
  12082. render() {
  12083. if (!this.data.hasPopup) {
  12084. this._createPopup(null, this.data);
  12085. }
  12086. if (this.quadrilaterals) {
  12087. return this._renderQuadrilaterals("squigglyAnnotation");
  12088. }
  12089. this.container.className = "squigglyAnnotation";
  12090. return this.container;
  12091. }
  12092. }
  12093. class StrikeOutAnnotationElement extends AnnotationElement {
  12094. constructor(parameters) {
  12095. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  12096. super(parameters, {
  12097. isRenderable,
  12098. ignoreBorder: true,
  12099. createQuadrilaterals: true
  12100. });
  12101. }
  12102. render() {
  12103. if (!this.data.hasPopup) {
  12104. this._createPopup(null, this.data);
  12105. }
  12106. if (this.quadrilaterals) {
  12107. return this._renderQuadrilaterals("strikeoutAnnotation");
  12108. }
  12109. this.container.className = "strikeoutAnnotation";
  12110. return this.container;
  12111. }
  12112. }
  12113. class StampAnnotationElement extends AnnotationElement {
  12114. constructor(parameters) {
  12115. const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
  12116. super(parameters, {
  12117. isRenderable,
  12118. ignoreBorder: true
  12119. });
  12120. }
  12121. render() {
  12122. this.container.className = "stampAnnotation";
  12123. if (!this.data.hasPopup) {
  12124. this._createPopup(null, this.data);
  12125. }
  12126. return this.container;
  12127. }
  12128. }
  12129. class FileAttachmentAnnotationElement extends AnnotationElement {
  12130. constructor(parameters) {
  12131. super(parameters, {
  12132. isRenderable: true
  12133. });
  12134. const {
  12135. filename,
  12136. content
  12137. } = this.data.file;
  12138. this.filename = (0, _display_utils.getFilenameFromUrl)(filename);
  12139. this.content = content;
  12140. this.linkService.eventBus?.dispatch("fileattachmentannotation", {
  12141. source: this,
  12142. filename,
  12143. content
  12144. });
  12145. }
  12146. render() {
  12147. this.container.className = "fileAttachmentAnnotation";
  12148. const trigger = document.createElement("div");
  12149. trigger.className = "popupTriggerArea";
  12150. trigger.addEventListener("dblclick", this._download.bind(this));
  12151. if (!this.data.hasPopup && (this.data.titleObj?.str || this.data.contentsObj?.str || this.data.richText)) {
  12152. this._createPopup(trigger, this.data);
  12153. }
  12154. this.container.append(trigger);
  12155. return this.container;
  12156. }
  12157. _download() {
  12158. this.downloadManager?.openOrDownloadData(this.container, this.content, this.filename);
  12159. }
  12160. }
  12161. class AnnotationLayer {
  12162. static #appendElement(element, id, div, accessibilityManager) {
  12163. const contentElement = element.firstChild || element;
  12164. contentElement.id = `${_display_utils.AnnotationPrefix}${id}`;
  12165. div.append(element);
  12166. accessibilityManager?.moveElementInDOM(div, element, contentElement, false);
  12167. }
  12168. static render(parameters) {
  12169. const {
  12170. annotations,
  12171. div,
  12172. viewport,
  12173. accessibilityManager
  12174. } = parameters;
  12175. this.#setDimensions(div, viewport);
  12176. let zIndex = 0;
  12177. for (const data of annotations) {
  12178. if (data.annotationType !== _util.AnnotationType.POPUP) {
  12179. const {
  12180. width,
  12181. height
  12182. } = getRectDims(data.rect);
  12183. if (width <= 0 || height <= 0) {
  12184. continue;
  12185. }
  12186. }
  12187. const element = AnnotationElementFactory.create({
  12188. data,
  12189. layer: div,
  12190. page: parameters.page,
  12191. viewport,
  12192. linkService: parameters.linkService,
  12193. downloadManager: parameters.downloadManager,
  12194. imageResourcesPath: parameters.imageResourcesPath || "",
  12195. renderForms: parameters.renderForms !== false,
  12196. svgFactory: new _display_utils.DOMSVGFactory(),
  12197. annotationStorage: parameters.annotationStorage || new _annotation_storage.AnnotationStorage(),
  12198. enableScripting: parameters.enableScripting,
  12199. hasJSActions: parameters.hasJSActions,
  12200. fieldObjects: parameters.fieldObjects,
  12201. mouseState: parameters.mouseState || {
  12202. isDown: false
  12203. }
  12204. });
  12205. if (element.isRenderable) {
  12206. const rendered = element.render();
  12207. if (data.hidden) {
  12208. rendered.style.visibility = "hidden";
  12209. }
  12210. if (Array.isArray(rendered)) {
  12211. for (const renderedElement of rendered) {
  12212. renderedElement.style.zIndex = zIndex++;
  12213. AnnotationLayer.#appendElement(renderedElement, data.id, div, accessibilityManager);
  12214. }
  12215. } else {
  12216. rendered.style.zIndex = zIndex++;
  12217. if (element instanceof PopupAnnotationElement) {
  12218. div.prepend(rendered);
  12219. } else {
  12220. AnnotationLayer.#appendElement(rendered, data.id, div, accessibilityManager);
  12221. }
  12222. }
  12223. }
  12224. }
  12225. this.#setAnnotationCanvasMap(div, parameters.annotationCanvasMap);
  12226. }
  12227. static update(parameters) {
  12228. const {
  12229. annotationCanvasMap,
  12230. div,
  12231. viewport
  12232. } = parameters;
  12233. this.#setDimensions(div, viewport);
  12234. this.#setAnnotationCanvasMap(div, annotationCanvasMap);
  12235. div.hidden = false;
  12236. }
  12237. static #setDimensions(div, {
  12238. width,
  12239. height,
  12240. rotation
  12241. }) {
  12242. const {
  12243. style
  12244. } = div;
  12245. const flipOrientation = rotation % 180 !== 0,
  12246. widthStr = Math.floor(width) + "px",
  12247. heightStr = Math.floor(height) + "px";
  12248. style.width = flipOrientation ? heightStr : widthStr;
  12249. style.height = flipOrientation ? widthStr : heightStr;
  12250. div.setAttribute("data-main-rotation", rotation);
  12251. }
  12252. static #setAnnotationCanvasMap(div, annotationCanvasMap) {
  12253. if (!annotationCanvasMap) {
  12254. return;
  12255. }
  12256. for (const [id, canvas] of annotationCanvasMap) {
  12257. const element = div.querySelector(`[data-annotation-id="${id}"]`);
  12258. if (!element) {
  12259. continue;
  12260. }
  12261. const {
  12262. firstChild
  12263. } = element;
  12264. if (!firstChild) {
  12265. element.append(canvas);
  12266. } else if (firstChild.nodeName === "CANVAS") {
  12267. firstChild.replaceWith(canvas);
  12268. } else {
  12269. firstChild.before(canvas);
  12270. }
  12271. }
  12272. annotationCanvasMap.clear();
  12273. }
  12274. }
  12275. exports.AnnotationLayer = AnnotationLayer;
  12276. /***/ }),
  12277. /* 28 */
  12278. /***/ ((__unused_webpack_module, exports) => {
  12279. Object.defineProperty(exports, "__esModule", ({
  12280. value: true
  12281. }));
  12282. exports.ColorConverters = void 0;
  12283. function makeColorComp(n) {
  12284. return Math.floor(Math.max(0, Math.min(1, n)) * 255).toString(16).padStart(2, "0");
  12285. }
  12286. class ColorConverters {
  12287. static CMYK_G([c, y, m, k]) {
  12288. return ["G", 1 - Math.min(1, 0.3 * c + 0.59 * m + 0.11 * y + k)];
  12289. }
  12290. static G_CMYK([g]) {
  12291. return ["CMYK", 0, 0, 0, 1 - g];
  12292. }
  12293. static G_RGB([g]) {
  12294. return ["RGB", g, g, g];
  12295. }
  12296. static G_HTML([g]) {
  12297. const G = makeColorComp(g);
  12298. return `#${G}${G}${G}`;
  12299. }
  12300. static RGB_G([r, g, b]) {
  12301. return ["G", 0.3 * r + 0.59 * g + 0.11 * b];
  12302. }
  12303. static RGB_HTML([r, g, b]) {
  12304. const R = makeColorComp(r);
  12305. const G = makeColorComp(g);
  12306. const B = makeColorComp(b);
  12307. return `#${R}${G}${B}`;
  12308. }
  12309. static T_HTML() {
  12310. return "#00000000";
  12311. }
  12312. static CMYK_RGB([c, y, m, k]) {
  12313. return ["RGB", 1 - Math.min(1, c + k), 1 - Math.min(1, m + k), 1 - Math.min(1, y + k)];
  12314. }
  12315. static CMYK_HTML(components) {
  12316. const rgb = this.CMYK_RGB(components).slice(1);
  12317. return this.RGB_HTML(rgb);
  12318. }
  12319. static RGB_CMYK([r, g, b]) {
  12320. const c = 1 - r;
  12321. const m = 1 - g;
  12322. const y = 1 - b;
  12323. const k = Math.min(c, m, y);
  12324. return ["CMYK", c, m, y, k];
  12325. }
  12326. }
  12327. exports.ColorConverters = ColorConverters;
  12328. /***/ }),
  12329. /* 29 */
  12330. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  12331. Object.defineProperty(exports, "__esModule", ({
  12332. value: true
  12333. }));
  12334. exports.XfaLayer = void 0;
  12335. var _xfa_text = __w_pdfjs_require__(20);
  12336. class XfaLayer {
  12337. static setupStorage(html, id, element, storage, intent) {
  12338. const storedData = storage.getValue(id, {
  12339. value: null
  12340. });
  12341. switch (element.name) {
  12342. case "textarea":
  12343. if (storedData.value !== null) {
  12344. html.textContent = storedData.value;
  12345. }
  12346. if (intent === "print") {
  12347. break;
  12348. }
  12349. html.addEventListener("input", event => {
  12350. storage.setValue(id, {
  12351. value: event.target.value
  12352. });
  12353. });
  12354. break;
  12355. case "input":
  12356. if (element.attributes.type === "radio" || element.attributes.type === "checkbox") {
  12357. if (storedData.value === element.attributes.xfaOn) {
  12358. html.setAttribute("checked", true);
  12359. } else if (storedData.value === element.attributes.xfaOff) {
  12360. html.removeAttribute("checked");
  12361. }
  12362. if (intent === "print") {
  12363. break;
  12364. }
  12365. html.addEventListener("change", event => {
  12366. storage.setValue(id, {
  12367. value: event.target.checked ? event.target.getAttribute("xfaOn") : event.target.getAttribute("xfaOff")
  12368. });
  12369. });
  12370. } else {
  12371. if (storedData.value !== null) {
  12372. html.setAttribute("value", storedData.value);
  12373. }
  12374. if (intent === "print") {
  12375. break;
  12376. }
  12377. html.addEventListener("input", event => {
  12378. storage.setValue(id, {
  12379. value: event.target.value
  12380. });
  12381. });
  12382. }
  12383. break;
  12384. case "select":
  12385. if (storedData.value !== null) {
  12386. for (const option of element.children) {
  12387. if (option.attributes.value === storedData.value) {
  12388. option.attributes.selected = true;
  12389. }
  12390. }
  12391. }
  12392. html.addEventListener("input", event => {
  12393. const options = event.target.options;
  12394. const value = options.selectedIndex === -1 ? "" : options[options.selectedIndex].value;
  12395. storage.setValue(id, {
  12396. value
  12397. });
  12398. });
  12399. break;
  12400. }
  12401. }
  12402. static setAttributes({
  12403. html,
  12404. element,
  12405. storage = null,
  12406. intent,
  12407. linkService
  12408. }) {
  12409. const {
  12410. attributes
  12411. } = element;
  12412. const isHTMLAnchorElement = html instanceof HTMLAnchorElement;
  12413. if (attributes.type === "radio") {
  12414. attributes.name = `${attributes.name}-${intent}`;
  12415. }
  12416. for (const [key, value] of Object.entries(attributes)) {
  12417. if (value === null || value === undefined) {
  12418. continue;
  12419. }
  12420. switch (key) {
  12421. case "class":
  12422. if (value.length) {
  12423. html.setAttribute(key, value.join(" "));
  12424. }
  12425. break;
  12426. case "dataId":
  12427. break;
  12428. case "id":
  12429. html.setAttribute("data-element-id", value);
  12430. break;
  12431. case "style":
  12432. Object.assign(html.style, value);
  12433. break;
  12434. case "textContent":
  12435. html.textContent = value;
  12436. break;
  12437. default:
  12438. if (!isHTMLAnchorElement || key !== "href" && key !== "newWindow") {
  12439. html.setAttribute(key, value);
  12440. }
  12441. }
  12442. }
  12443. if (isHTMLAnchorElement) {
  12444. linkService.addLinkAttributes(html, attributes.href, attributes.newWindow);
  12445. }
  12446. if (storage && attributes.dataId) {
  12447. this.setupStorage(html, attributes.dataId, element, storage);
  12448. }
  12449. }
  12450. static render(parameters) {
  12451. const storage = parameters.annotationStorage;
  12452. const linkService = parameters.linkService;
  12453. const root = parameters.xfaHtml;
  12454. const intent = parameters.intent || "display";
  12455. const rootHtml = document.createElement(root.name);
  12456. if (root.attributes) {
  12457. this.setAttributes({
  12458. html: rootHtml,
  12459. element: root,
  12460. intent,
  12461. linkService
  12462. });
  12463. }
  12464. const stack = [[root, -1, rootHtml]];
  12465. const rootDiv = parameters.div;
  12466. rootDiv.append(rootHtml);
  12467. if (parameters.viewport) {
  12468. const transform = `matrix(${parameters.viewport.transform.join(",")})`;
  12469. rootDiv.style.transform = transform;
  12470. }
  12471. if (intent !== "richText") {
  12472. rootDiv.setAttribute("class", "xfaLayer xfaFont");
  12473. }
  12474. const textDivs = [];
  12475. while (stack.length > 0) {
  12476. const [parent, i, html] = stack.at(-1);
  12477. if (i + 1 === parent.children.length) {
  12478. stack.pop();
  12479. continue;
  12480. }
  12481. const child = parent.children[++stack.at(-1)[1]];
  12482. if (child === null) {
  12483. continue;
  12484. }
  12485. const {
  12486. name
  12487. } = child;
  12488. if (name === "#text") {
  12489. const node = document.createTextNode(child.value);
  12490. textDivs.push(node);
  12491. html.append(node);
  12492. continue;
  12493. }
  12494. let childHtml;
  12495. if (child?.attributes?.xmlns) {
  12496. childHtml = document.createElementNS(child.attributes.xmlns, name);
  12497. } else {
  12498. childHtml = document.createElement(name);
  12499. }
  12500. html.append(childHtml);
  12501. if (child.attributes) {
  12502. this.setAttributes({
  12503. html: childHtml,
  12504. element: child,
  12505. storage,
  12506. intent,
  12507. linkService
  12508. });
  12509. }
  12510. if (child.children && child.children.length > 0) {
  12511. stack.push([child, -1, childHtml]);
  12512. } else if (child.value) {
  12513. const node = document.createTextNode(child.value);
  12514. if (_xfa_text.XfaText.shouldBuildText(name)) {
  12515. textDivs.push(node);
  12516. }
  12517. childHtml.append(node);
  12518. }
  12519. }
  12520. for (const el of rootDiv.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea")) {
  12521. el.setAttribute("readOnly", true);
  12522. }
  12523. return {
  12524. textDivs
  12525. };
  12526. }
  12527. static update(parameters) {
  12528. const transform = `matrix(${parameters.viewport.transform.join(",")})`;
  12529. parameters.div.style.transform = transform;
  12530. parameters.div.hidden = false;
  12531. }
  12532. }
  12533. exports.XfaLayer = XfaLayer;
  12534. /***/ }),
  12535. /* 30 */
  12536. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  12537. Object.defineProperty(exports, "__esModule", ({
  12538. value: true
  12539. }));
  12540. exports.TextLayerRenderTask = void 0;
  12541. exports.renderTextLayer = renderTextLayer;
  12542. var _util = __w_pdfjs_require__(1);
  12543. var _display_utils = __w_pdfjs_require__(8);
  12544. const MAX_TEXT_DIVS_TO_RENDER = 100000;
  12545. const DEFAULT_FONT_SIZE = 30;
  12546. const DEFAULT_FONT_ASCENT = 0.8;
  12547. const ascentCache = new Map();
  12548. const AllWhitespaceRegexp = /^\s+$/g;
  12549. function getAscent(fontFamily, ctx) {
  12550. const cachedAscent = ascentCache.get(fontFamily);
  12551. if (cachedAscent) {
  12552. return cachedAscent;
  12553. }
  12554. ctx.save();
  12555. ctx.font = `${DEFAULT_FONT_SIZE}px ${fontFamily}`;
  12556. const metrics = ctx.measureText("");
  12557. let ascent = metrics.fontBoundingBoxAscent;
  12558. let descent = Math.abs(metrics.fontBoundingBoxDescent);
  12559. if (ascent) {
  12560. ctx.restore();
  12561. const ratio = ascent / (ascent + descent);
  12562. ascentCache.set(fontFamily, ratio);
  12563. return ratio;
  12564. }
  12565. ctx.strokeStyle = "red";
  12566. ctx.clearRect(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE);
  12567. ctx.strokeText("g", 0, 0);
  12568. let pixels = ctx.getImageData(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE).data;
  12569. descent = 0;
  12570. for (let i = pixels.length - 1 - 3; i >= 0; i -= 4) {
  12571. if (pixels[i] > 0) {
  12572. descent = Math.ceil(i / 4 / DEFAULT_FONT_SIZE);
  12573. break;
  12574. }
  12575. }
  12576. ctx.clearRect(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE);
  12577. ctx.strokeText("A", 0, DEFAULT_FONT_SIZE);
  12578. pixels = ctx.getImageData(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE).data;
  12579. ascent = 0;
  12580. for (let i = 0, ii = pixels.length; i < ii; i += 4) {
  12581. if (pixels[i] > 0) {
  12582. ascent = DEFAULT_FONT_SIZE - Math.floor(i / 4 / DEFAULT_FONT_SIZE);
  12583. break;
  12584. }
  12585. }
  12586. ctx.restore();
  12587. if (ascent) {
  12588. const ratio = ascent / (ascent + descent);
  12589. ascentCache.set(fontFamily, ratio);
  12590. return ratio;
  12591. }
  12592. ascentCache.set(fontFamily, DEFAULT_FONT_ASCENT);
  12593. return DEFAULT_FONT_ASCENT;
  12594. }
  12595. function appendText(task, geom, styles, ctx) {
  12596. const textDiv = document.createElement("span");
  12597. const textDivProperties = task._enhanceTextSelection ? {
  12598. angle: 0,
  12599. canvasWidth: 0,
  12600. hasText: geom.str !== "",
  12601. hasEOL: geom.hasEOL,
  12602. originalTransform: null,
  12603. paddingBottom: 0,
  12604. paddingLeft: 0,
  12605. paddingRight: 0,
  12606. paddingTop: 0,
  12607. scale: 1,
  12608. fontSize: 0
  12609. } : {
  12610. angle: 0,
  12611. canvasWidth: 0,
  12612. hasText: geom.str !== "",
  12613. hasEOL: geom.hasEOL,
  12614. fontSize: 0
  12615. };
  12616. task._textDivs.push(textDiv);
  12617. const tx = _util.Util.transform(task._viewport.transform, geom.transform);
  12618. let angle = Math.atan2(tx[1], tx[0]);
  12619. const style = styles[geom.fontName];
  12620. if (style.vertical) {
  12621. angle += Math.PI / 2;
  12622. }
  12623. const fontHeight = Math.hypot(tx[2], tx[3]);
  12624. const fontAscent = fontHeight * getAscent(style.fontFamily, ctx);
  12625. let left, top;
  12626. if (angle === 0) {
  12627. left = tx[4];
  12628. top = tx[5] - fontAscent;
  12629. } else {
  12630. left = tx[4] + fontAscent * Math.sin(angle);
  12631. top = tx[5] - fontAscent * Math.cos(angle);
  12632. }
  12633. textDiv.style.left = `${left}px`;
  12634. textDiv.style.top = `${top}px`;
  12635. textDiv.style.fontSize = `${fontHeight}px`;
  12636. textDiv.style.fontFamily = style.fontFamily;
  12637. textDivProperties.fontSize = fontHeight;
  12638. textDiv.setAttribute("role", "presentation");
  12639. textDiv.textContent = geom.str;
  12640. textDiv.dir = geom.dir;
  12641. if (task._fontInspectorEnabled) {
  12642. textDiv.dataset.fontName = geom.fontName;
  12643. }
  12644. if (angle !== 0) {
  12645. textDivProperties.angle = angle * (180 / Math.PI);
  12646. }
  12647. let shouldScaleText = false;
  12648. if (geom.str.length > 1 || task._enhanceTextSelection && AllWhitespaceRegexp.test(geom.str)) {
  12649. shouldScaleText = true;
  12650. } else if (geom.str !== " " && geom.transform[0] !== geom.transform[3]) {
  12651. const absScaleX = Math.abs(geom.transform[0]),
  12652. absScaleY = Math.abs(geom.transform[3]);
  12653. if (absScaleX !== absScaleY && Math.max(absScaleX, absScaleY) / Math.min(absScaleX, absScaleY) > 1.5) {
  12654. shouldScaleText = true;
  12655. }
  12656. }
  12657. if (shouldScaleText) {
  12658. if (style.vertical) {
  12659. textDivProperties.canvasWidth = geom.height * task._viewport.scale;
  12660. } else {
  12661. textDivProperties.canvasWidth = geom.width * task._viewport.scale;
  12662. }
  12663. }
  12664. task._textDivProperties.set(textDiv, textDivProperties);
  12665. if (task._textContentStream) {
  12666. task._layoutText(textDiv);
  12667. }
  12668. if (task._enhanceTextSelection && textDivProperties.hasText) {
  12669. let angleCos = 1,
  12670. angleSin = 0;
  12671. if (angle !== 0) {
  12672. angleCos = Math.cos(angle);
  12673. angleSin = Math.sin(angle);
  12674. }
  12675. const divWidth = (style.vertical ? geom.height : geom.width) * task._viewport.scale;
  12676. const divHeight = fontHeight;
  12677. let m, b;
  12678. if (angle !== 0) {
  12679. m = [angleCos, angleSin, -angleSin, angleCos, left, top];
  12680. b = _util.Util.getAxialAlignedBoundingBox([0, 0, divWidth, divHeight], m);
  12681. } else {
  12682. b = [left, top, left + divWidth, top + divHeight];
  12683. }
  12684. task._bounds.push({
  12685. left: b[0],
  12686. top: b[1],
  12687. right: b[2],
  12688. bottom: b[3],
  12689. div: textDiv,
  12690. size: [divWidth, divHeight],
  12691. m
  12692. });
  12693. }
  12694. }
  12695. function render(task) {
  12696. if (task._canceled) {
  12697. return;
  12698. }
  12699. const textDivs = task._textDivs;
  12700. const capability = task._capability;
  12701. const textDivsLength = textDivs.length;
  12702. if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
  12703. task._renderingDone = true;
  12704. capability.resolve();
  12705. return;
  12706. }
  12707. if (!task._textContentStream) {
  12708. for (let i = 0; i < textDivsLength; i++) {
  12709. task._layoutText(textDivs[i]);
  12710. }
  12711. }
  12712. task._renderingDone = true;
  12713. capability.resolve();
  12714. }
  12715. function findPositiveMin(ts, offset, count) {
  12716. let result = 0;
  12717. for (let i = 0; i < count; i++) {
  12718. const t = ts[offset++];
  12719. if (t > 0) {
  12720. result = result ? Math.min(t, result) : t;
  12721. }
  12722. }
  12723. return result;
  12724. }
  12725. function expand(task) {
  12726. const bounds = task._bounds;
  12727. const viewport = task._viewport;
  12728. const expanded = expandBounds(viewport.width, viewport.height, bounds);
  12729. for (let i = 0; i < expanded.length; i++) {
  12730. const div = bounds[i].div;
  12731. const divProperties = task._textDivProperties.get(div);
  12732. if (divProperties.angle === 0) {
  12733. divProperties.paddingLeft = bounds[i].left - expanded[i].left;
  12734. divProperties.paddingTop = bounds[i].top - expanded[i].top;
  12735. divProperties.paddingRight = expanded[i].right - bounds[i].right;
  12736. divProperties.paddingBottom = expanded[i].bottom - bounds[i].bottom;
  12737. task._textDivProperties.set(div, divProperties);
  12738. continue;
  12739. }
  12740. const e = expanded[i],
  12741. b = bounds[i];
  12742. const m = b.m,
  12743. c = m[0],
  12744. s = m[1];
  12745. const points = [[0, 0], [0, b.size[1]], [b.size[0], 0], b.size];
  12746. const ts = new Float64Array(64);
  12747. for (let j = 0, jj = points.length; j < jj; j++) {
  12748. const t = _util.Util.applyTransform(points[j], m);
  12749. ts[j + 0] = c && (e.left - t[0]) / c;
  12750. ts[j + 4] = s && (e.top - t[1]) / s;
  12751. ts[j + 8] = c && (e.right - t[0]) / c;
  12752. ts[j + 12] = s && (e.bottom - t[1]) / s;
  12753. ts[j + 16] = s && (e.left - t[0]) / -s;
  12754. ts[j + 20] = c && (e.top - t[1]) / c;
  12755. ts[j + 24] = s && (e.right - t[0]) / -s;
  12756. ts[j + 28] = c && (e.bottom - t[1]) / c;
  12757. ts[j + 32] = c && (e.left - t[0]) / -c;
  12758. ts[j + 36] = s && (e.top - t[1]) / -s;
  12759. ts[j + 40] = c && (e.right - t[0]) / -c;
  12760. ts[j + 44] = s && (e.bottom - t[1]) / -s;
  12761. ts[j + 48] = s && (e.left - t[0]) / s;
  12762. ts[j + 52] = c && (e.top - t[1]) / -c;
  12763. ts[j + 56] = s && (e.right - t[0]) / s;
  12764. ts[j + 60] = c && (e.bottom - t[1]) / -c;
  12765. }
  12766. const boxScale = 1 + Math.min(Math.abs(c), Math.abs(s));
  12767. divProperties.paddingLeft = findPositiveMin(ts, 32, 16) / boxScale;
  12768. divProperties.paddingTop = findPositiveMin(ts, 48, 16) / boxScale;
  12769. divProperties.paddingRight = findPositiveMin(ts, 0, 16) / boxScale;
  12770. divProperties.paddingBottom = findPositiveMin(ts, 16, 16) / boxScale;
  12771. task._textDivProperties.set(div, divProperties);
  12772. }
  12773. }
  12774. function expandBounds(width, height, boxes) {
  12775. const bounds = boxes.map(function (box, i) {
  12776. return {
  12777. x1: box.left,
  12778. y1: box.top,
  12779. x2: box.right,
  12780. y2: box.bottom,
  12781. index: i,
  12782. x1New: undefined,
  12783. x2New: undefined
  12784. };
  12785. });
  12786. expandBoundsLTR(width, bounds);
  12787. const expanded = new Array(boxes.length);
  12788. for (const b of bounds) {
  12789. const i = b.index;
  12790. expanded[i] = {
  12791. left: b.x1New,
  12792. top: 0,
  12793. right: b.x2New,
  12794. bottom: 0
  12795. };
  12796. }
  12797. boxes.map(function (box, i) {
  12798. const e = expanded[i],
  12799. b = bounds[i];
  12800. b.x1 = box.top;
  12801. b.y1 = width - e.right;
  12802. b.x2 = box.bottom;
  12803. b.y2 = width - e.left;
  12804. b.index = i;
  12805. b.x1New = undefined;
  12806. b.x2New = undefined;
  12807. });
  12808. expandBoundsLTR(height, bounds);
  12809. for (const b of bounds) {
  12810. const i = b.index;
  12811. expanded[i].top = b.x1New;
  12812. expanded[i].bottom = b.x2New;
  12813. }
  12814. return expanded;
  12815. }
  12816. function expandBoundsLTR(width, bounds) {
  12817. bounds.sort(function (a, b) {
  12818. return a.x1 - b.x1 || a.index - b.index;
  12819. });
  12820. const fakeBoundary = {
  12821. x1: -Infinity,
  12822. y1: -Infinity,
  12823. x2: 0,
  12824. y2: Infinity,
  12825. index: -1,
  12826. x1New: 0,
  12827. x2New: 0
  12828. };
  12829. const horizon = [{
  12830. start: -Infinity,
  12831. end: Infinity,
  12832. boundary: fakeBoundary
  12833. }];
  12834. for (const boundary of bounds) {
  12835. let i = 0;
  12836. while (i < horizon.length && horizon[i].end <= boundary.y1) {
  12837. i++;
  12838. }
  12839. let j = horizon.length - 1;
  12840. while (j >= 0 && horizon[j].start >= boundary.y2) {
  12841. j--;
  12842. }
  12843. let horizonPart, affectedBoundary;
  12844. let q,
  12845. k,
  12846. maxXNew = -Infinity;
  12847. for (q = i; q <= j; q++) {
  12848. horizonPart = horizon[q];
  12849. affectedBoundary = horizonPart.boundary;
  12850. let xNew;
  12851. if (affectedBoundary.x2 > boundary.x1) {
  12852. xNew = affectedBoundary.index > boundary.index ? affectedBoundary.x1New : boundary.x1;
  12853. } else if (affectedBoundary.x2New === undefined) {
  12854. xNew = (affectedBoundary.x2 + boundary.x1) / 2;
  12855. } else {
  12856. xNew = affectedBoundary.x2New;
  12857. }
  12858. if (xNew > maxXNew) {
  12859. maxXNew = xNew;
  12860. }
  12861. }
  12862. boundary.x1New = maxXNew;
  12863. for (q = i; q <= j; q++) {
  12864. horizonPart = horizon[q];
  12865. affectedBoundary = horizonPart.boundary;
  12866. if (affectedBoundary.x2New === undefined) {
  12867. if (affectedBoundary.x2 > boundary.x1) {
  12868. if (affectedBoundary.index > boundary.index) {
  12869. affectedBoundary.x2New = affectedBoundary.x2;
  12870. }
  12871. } else {
  12872. affectedBoundary.x2New = maxXNew;
  12873. }
  12874. } else if (affectedBoundary.x2New > maxXNew) {
  12875. affectedBoundary.x2New = Math.max(maxXNew, affectedBoundary.x2);
  12876. }
  12877. }
  12878. const changedHorizon = [];
  12879. let lastBoundary = null;
  12880. for (q = i; q <= j; q++) {
  12881. horizonPart = horizon[q];
  12882. affectedBoundary = horizonPart.boundary;
  12883. const useBoundary = affectedBoundary.x2 > boundary.x2 ? affectedBoundary : boundary;
  12884. if (lastBoundary === useBoundary) {
  12885. changedHorizon.at(-1).end = horizonPart.end;
  12886. } else {
  12887. changedHorizon.push({
  12888. start: horizonPart.start,
  12889. end: horizonPart.end,
  12890. boundary: useBoundary
  12891. });
  12892. lastBoundary = useBoundary;
  12893. }
  12894. }
  12895. if (horizon[i].start < boundary.y1) {
  12896. changedHorizon[0].start = boundary.y1;
  12897. changedHorizon.unshift({
  12898. start: horizon[i].start,
  12899. end: boundary.y1,
  12900. boundary: horizon[i].boundary
  12901. });
  12902. }
  12903. if (boundary.y2 < horizon[j].end) {
  12904. changedHorizon.at(-1).end = boundary.y2;
  12905. changedHorizon.push({
  12906. start: boundary.y2,
  12907. end: horizon[j].end,
  12908. boundary: horizon[j].boundary
  12909. });
  12910. }
  12911. for (q = i; q <= j; q++) {
  12912. horizonPart = horizon[q];
  12913. affectedBoundary = horizonPart.boundary;
  12914. if (affectedBoundary.x2New !== undefined) {
  12915. continue;
  12916. }
  12917. let used = false;
  12918. for (k = i - 1; !used && k >= 0 && horizon[k].start >= affectedBoundary.y1; k--) {
  12919. used = horizon[k].boundary === affectedBoundary;
  12920. }
  12921. for (k = j + 1; !used && k < horizon.length && horizon[k].end <= affectedBoundary.y2; k++) {
  12922. used = horizon[k].boundary === affectedBoundary;
  12923. }
  12924. for (k = 0; !used && k < changedHorizon.length; k++) {
  12925. used = changedHorizon[k].boundary === affectedBoundary;
  12926. }
  12927. if (!used) {
  12928. affectedBoundary.x2New = maxXNew;
  12929. }
  12930. }
  12931. Array.prototype.splice.apply(horizon, [i, j - i + 1, ...changedHorizon]);
  12932. }
  12933. for (const horizonPart of horizon) {
  12934. const affectedBoundary = horizonPart.boundary;
  12935. if (affectedBoundary.x2New === undefined) {
  12936. affectedBoundary.x2New = Math.max(width, affectedBoundary.x2);
  12937. }
  12938. }
  12939. }
  12940. class TextLayerRenderTask {
  12941. constructor({
  12942. textContent,
  12943. textContentStream,
  12944. container,
  12945. viewport,
  12946. textDivs,
  12947. textContentItemsStr,
  12948. enhanceTextSelection
  12949. }) {
  12950. if (enhanceTextSelection) {
  12951. (0, _display_utils.deprecated)("The `enhanceTextSelection` functionality will be removed in the future.");
  12952. }
  12953. this._textContent = textContent;
  12954. this._textContentStream = textContentStream;
  12955. this._container = container;
  12956. this._document = container.ownerDocument;
  12957. this._viewport = viewport;
  12958. this._textDivs = textDivs || [];
  12959. this._textContentItemsStr = textContentItemsStr || [];
  12960. this._enhanceTextSelection = !!enhanceTextSelection;
  12961. this._fontInspectorEnabled = !!globalThis.FontInspector?.enabled;
  12962. this._reader = null;
  12963. this._layoutTextLastFontSize = null;
  12964. this._layoutTextLastFontFamily = null;
  12965. this._layoutTextCtx = null;
  12966. this._textDivProperties = new WeakMap();
  12967. this._renderingDone = false;
  12968. this._canceled = false;
  12969. this._capability = (0, _util.createPromiseCapability)();
  12970. this._renderTimer = null;
  12971. this._bounds = [];
  12972. this._devicePixelRatio = globalThis.devicePixelRatio || 1;
  12973. this._capability.promise.finally(() => {
  12974. if (!this._enhanceTextSelection) {
  12975. this._textDivProperties = null;
  12976. }
  12977. if (this._layoutTextCtx) {
  12978. this._layoutTextCtx.canvas.width = 0;
  12979. this._layoutTextCtx.canvas.height = 0;
  12980. this._layoutTextCtx = null;
  12981. }
  12982. }).catch(() => {});
  12983. }
  12984. get promise() {
  12985. return this._capability.promise;
  12986. }
  12987. cancel() {
  12988. this._canceled = true;
  12989. if (this._reader) {
  12990. this._reader.cancel(new _util.AbortException("TextLayer task cancelled.")).catch(() => {});
  12991. this._reader = null;
  12992. }
  12993. if (this._renderTimer !== null) {
  12994. clearTimeout(this._renderTimer);
  12995. this._renderTimer = null;
  12996. }
  12997. this._capability.reject(new Error("TextLayer task cancelled."));
  12998. }
  12999. _processItems(items, styleCache) {
  13000. for (let i = 0, len = items.length; i < len; i++) {
  13001. if (items[i].str === undefined) {
  13002. if (items[i].type === "beginMarkedContentProps" || items[i].type === "beginMarkedContent") {
  13003. const parent = this._container;
  13004. this._container = document.createElement("span");
  13005. this._container.classList.add("markedContent");
  13006. if (items[i].id !== null) {
  13007. this._container.setAttribute("id", `${items[i].id}`);
  13008. }
  13009. parent.append(this._container);
  13010. } else if (items[i].type === "endMarkedContent") {
  13011. this._container = this._container.parentNode;
  13012. }
  13013. continue;
  13014. }
  13015. this._textContentItemsStr.push(items[i].str);
  13016. appendText(this, items[i], styleCache, this._layoutTextCtx);
  13017. }
  13018. }
  13019. _layoutText(textDiv) {
  13020. const textDivProperties = this._textDivProperties.get(textDiv);
  13021. let transform = "";
  13022. if (textDivProperties.canvasWidth !== 0 && textDivProperties.hasText) {
  13023. const {
  13024. fontFamily
  13025. } = textDiv.style;
  13026. const {
  13027. fontSize
  13028. } = textDivProperties;
  13029. if (fontSize !== this._layoutTextLastFontSize || fontFamily !== this._layoutTextLastFontFamily) {
  13030. this._layoutTextCtx.font = `${fontSize * this._devicePixelRatio}px ${fontFamily}`;
  13031. this._layoutTextLastFontSize = fontSize;
  13032. this._layoutTextLastFontFamily = fontFamily;
  13033. }
  13034. const {
  13035. width
  13036. } = this._layoutTextCtx.measureText(textDiv.textContent);
  13037. if (width > 0) {
  13038. const scale = this._devicePixelRatio * textDivProperties.canvasWidth / width;
  13039. if (this._enhanceTextSelection) {
  13040. textDivProperties.scale = scale;
  13041. }
  13042. transform = `scaleX(${scale})`;
  13043. }
  13044. }
  13045. if (textDivProperties.angle !== 0) {
  13046. transform = `rotate(${textDivProperties.angle}deg) ${transform}`;
  13047. }
  13048. if (transform.length > 0) {
  13049. if (this._enhanceTextSelection) {
  13050. textDivProperties.originalTransform = transform;
  13051. }
  13052. textDiv.style.transform = transform;
  13053. }
  13054. if (textDivProperties.hasText) {
  13055. this._container.append(textDiv);
  13056. }
  13057. if (textDivProperties.hasEOL) {
  13058. const br = document.createElement("br");
  13059. br.setAttribute("role", "presentation");
  13060. this._container.append(br);
  13061. }
  13062. }
  13063. _render(timeout = 0) {
  13064. const capability = (0, _util.createPromiseCapability)();
  13065. let styleCache = Object.create(null);
  13066. const canvas = this._document.createElement("canvas");
  13067. canvas.height = canvas.width = DEFAULT_FONT_SIZE;
  13068. this._layoutTextCtx = canvas.getContext("2d", {
  13069. alpha: false
  13070. });
  13071. if (this._textContent) {
  13072. const textItems = this._textContent.items;
  13073. const textStyles = this._textContent.styles;
  13074. this._processItems(textItems, textStyles);
  13075. capability.resolve();
  13076. } else if (this._textContentStream) {
  13077. const pump = () => {
  13078. this._reader.read().then(({
  13079. value,
  13080. done
  13081. }) => {
  13082. if (done) {
  13083. capability.resolve();
  13084. return;
  13085. }
  13086. Object.assign(styleCache, value.styles);
  13087. this._processItems(value.items, styleCache);
  13088. pump();
  13089. }, capability.reject);
  13090. };
  13091. this._reader = this._textContentStream.getReader();
  13092. pump();
  13093. } else {
  13094. throw new Error('Neither "textContent" nor "textContentStream" parameters specified.');
  13095. }
  13096. capability.promise.then(() => {
  13097. styleCache = null;
  13098. if (!timeout) {
  13099. render(this);
  13100. } else {
  13101. this._renderTimer = setTimeout(() => {
  13102. render(this);
  13103. this._renderTimer = null;
  13104. }, timeout);
  13105. }
  13106. }, this._capability.reject);
  13107. }
  13108. expandTextDivs(expandDivs = false) {
  13109. if (!this._enhanceTextSelection || !this._renderingDone) {
  13110. return;
  13111. }
  13112. if (this._bounds !== null) {
  13113. expand(this);
  13114. this._bounds = null;
  13115. }
  13116. const transformBuf = [],
  13117. paddingBuf = [];
  13118. for (let i = 0, ii = this._textDivs.length; i < ii; i++) {
  13119. const div = this._textDivs[i];
  13120. const divProps = this._textDivProperties.get(div);
  13121. if (!divProps.hasText) {
  13122. continue;
  13123. }
  13124. if (expandDivs) {
  13125. transformBuf.length = 0;
  13126. paddingBuf.length = 0;
  13127. if (divProps.originalTransform) {
  13128. transformBuf.push(divProps.originalTransform);
  13129. }
  13130. if (divProps.paddingTop > 0) {
  13131. paddingBuf.push(`${divProps.paddingTop}px`);
  13132. transformBuf.push(`translateY(${-divProps.paddingTop}px)`);
  13133. } else {
  13134. paddingBuf.push(0);
  13135. }
  13136. if (divProps.paddingRight > 0) {
  13137. paddingBuf.push(`${divProps.paddingRight / divProps.scale}px`);
  13138. } else {
  13139. paddingBuf.push(0);
  13140. }
  13141. if (divProps.paddingBottom > 0) {
  13142. paddingBuf.push(`${divProps.paddingBottom}px`);
  13143. } else {
  13144. paddingBuf.push(0);
  13145. }
  13146. if (divProps.paddingLeft > 0) {
  13147. paddingBuf.push(`${divProps.paddingLeft / divProps.scale}px`);
  13148. transformBuf.push(`translateX(${-divProps.paddingLeft / divProps.scale}px)`);
  13149. } else {
  13150. paddingBuf.push(0);
  13151. }
  13152. div.style.padding = paddingBuf.join(" ");
  13153. if (transformBuf.length) {
  13154. div.style.transform = transformBuf.join(" ");
  13155. }
  13156. } else {
  13157. div.style.padding = null;
  13158. div.style.transform = divProps.originalTransform;
  13159. }
  13160. }
  13161. }
  13162. }
  13163. exports.TextLayerRenderTask = TextLayerRenderTask;
  13164. function renderTextLayer(renderParameters) {
  13165. const task = new TextLayerRenderTask({
  13166. textContent: renderParameters.textContent,
  13167. textContentStream: renderParameters.textContentStream,
  13168. container: renderParameters.container,
  13169. viewport: renderParameters.viewport,
  13170. textDivs: renderParameters.textDivs,
  13171. textContentItemsStr: renderParameters.textContentItemsStr,
  13172. enhanceTextSelection: renderParameters.enhanceTextSelection
  13173. });
  13174. task._render(renderParameters.timeout);
  13175. return task;
  13176. }
  13177. /***/ }),
  13178. /* 31 */
  13179. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  13180. Object.defineProperty(exports, "__esModule", ({
  13181. value: true
  13182. }));
  13183. exports.SVGGraphics = void 0;
  13184. var _display_utils = __w_pdfjs_require__(8);
  13185. var _util = __w_pdfjs_require__(1);
  13186. var _is_node = __w_pdfjs_require__(3);
  13187. let SVGGraphics = class {
  13188. constructor() {
  13189. (0, _util.unreachable)("Not implemented: SVGGraphics");
  13190. }
  13191. };
  13192. exports.SVGGraphics = SVGGraphics;
  13193. {
  13194. const SVG_DEFAULTS = {
  13195. fontStyle: "normal",
  13196. fontWeight: "normal",
  13197. fillColor: "#000000"
  13198. };
  13199. const XML_NS = "http://www.w3.org/XML/1998/namespace";
  13200. const XLINK_NS = "http://www.w3.org/1999/xlink";
  13201. const LINE_CAP_STYLES = ["butt", "round", "square"];
  13202. const LINE_JOIN_STYLES = ["miter", "round", "bevel"];
  13203. const createObjectURL = function (data, contentType = "", forceDataSchema = false) {
  13204. if (URL.createObjectURL && typeof Blob !== "undefined" && !forceDataSchema) {
  13205. return URL.createObjectURL(new Blob([data], {
  13206. type: contentType
  13207. }));
  13208. }
  13209. const digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  13210. let buffer = `data:${contentType};base64,`;
  13211. for (let i = 0, ii = data.length; i < ii; i += 3) {
  13212. const b1 = data[i] & 0xff;
  13213. const b2 = data[i + 1] & 0xff;
  13214. const b3 = data[i + 2] & 0xff;
  13215. const d1 = b1 >> 2,
  13216. d2 = (b1 & 3) << 4 | b2 >> 4;
  13217. const d3 = i + 1 < ii ? (b2 & 0xf) << 2 | b3 >> 6 : 64;
  13218. const d4 = i + 2 < ii ? b3 & 0x3f : 64;
  13219. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  13220. }
  13221. return buffer;
  13222. };
  13223. const convertImgDataToPng = function () {
  13224. const PNG_HEADER = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  13225. const CHUNK_WRAPPER_SIZE = 12;
  13226. const crcTable = new Int32Array(256);
  13227. for (let i = 0; i < 256; i++) {
  13228. let c = i;
  13229. for (let h = 0; h < 8; h++) {
  13230. if (c & 1) {
  13231. c = 0xedb88320 ^ c >> 1 & 0x7fffffff;
  13232. } else {
  13233. c = c >> 1 & 0x7fffffff;
  13234. }
  13235. }
  13236. crcTable[i] = c;
  13237. }
  13238. function crc32(data, start, end) {
  13239. let crc = -1;
  13240. for (let i = start; i < end; i++) {
  13241. const a = (crc ^ data[i]) & 0xff;
  13242. const b = crcTable[a];
  13243. crc = crc >>> 8 ^ b;
  13244. }
  13245. return crc ^ -1;
  13246. }
  13247. function writePngChunk(type, body, data, offset) {
  13248. let p = offset;
  13249. const len = body.length;
  13250. data[p] = len >> 24 & 0xff;
  13251. data[p + 1] = len >> 16 & 0xff;
  13252. data[p + 2] = len >> 8 & 0xff;
  13253. data[p + 3] = len & 0xff;
  13254. p += 4;
  13255. data[p] = type.charCodeAt(0) & 0xff;
  13256. data[p + 1] = type.charCodeAt(1) & 0xff;
  13257. data[p + 2] = type.charCodeAt(2) & 0xff;
  13258. data[p + 3] = type.charCodeAt(3) & 0xff;
  13259. p += 4;
  13260. data.set(body, p);
  13261. p += body.length;
  13262. const crc = crc32(data, offset + 4, p);
  13263. data[p] = crc >> 24 & 0xff;
  13264. data[p + 1] = crc >> 16 & 0xff;
  13265. data[p + 2] = crc >> 8 & 0xff;
  13266. data[p + 3] = crc & 0xff;
  13267. }
  13268. function adler32(data, start, end) {
  13269. let a = 1;
  13270. let b = 0;
  13271. for (let i = start; i < end; ++i) {
  13272. a = (a + (data[i] & 0xff)) % 65521;
  13273. b = (b + a) % 65521;
  13274. }
  13275. return b << 16 | a;
  13276. }
  13277. function deflateSync(literals) {
  13278. if (!_is_node.isNodeJS) {
  13279. return deflateSyncUncompressed(literals);
  13280. }
  13281. try {
  13282. let input;
  13283. if (parseInt(process.versions.node) >= 8) {
  13284. input = literals;
  13285. } else {
  13286. input = Buffer.from(literals);
  13287. }
  13288. const output = require("zlib").deflateSync(input, {
  13289. level: 9
  13290. });
  13291. return output instanceof Uint8Array ? output : new Uint8Array(output);
  13292. } catch (e) {
  13293. (0, _util.warn)("Not compressing PNG because zlib.deflateSync is unavailable: " + e);
  13294. }
  13295. return deflateSyncUncompressed(literals);
  13296. }
  13297. function deflateSyncUncompressed(literals) {
  13298. let len = literals.length;
  13299. const maxBlockLength = 0xffff;
  13300. const deflateBlocks = Math.ceil(len / maxBlockLength);
  13301. const idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  13302. let pi = 0;
  13303. idat[pi++] = 0x78;
  13304. idat[pi++] = 0x9c;
  13305. let pos = 0;
  13306. while (len > maxBlockLength) {
  13307. idat[pi++] = 0x00;
  13308. idat[pi++] = 0xff;
  13309. idat[pi++] = 0xff;
  13310. idat[pi++] = 0x00;
  13311. idat[pi++] = 0x00;
  13312. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  13313. pi += maxBlockLength;
  13314. pos += maxBlockLength;
  13315. len -= maxBlockLength;
  13316. }
  13317. idat[pi++] = 0x01;
  13318. idat[pi++] = len & 0xff;
  13319. idat[pi++] = len >> 8 & 0xff;
  13320. idat[pi++] = ~len & 0xffff & 0xff;
  13321. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  13322. idat.set(literals.subarray(pos), pi);
  13323. pi += literals.length - pos;
  13324. const adler = adler32(literals, 0, literals.length);
  13325. idat[pi++] = adler >> 24 & 0xff;
  13326. idat[pi++] = adler >> 16 & 0xff;
  13327. idat[pi++] = adler >> 8 & 0xff;
  13328. idat[pi++] = adler & 0xff;
  13329. return idat;
  13330. }
  13331. function encode(imgData, kind, forceDataSchema, isMask) {
  13332. const width = imgData.width;
  13333. const height = imgData.height;
  13334. let bitDepth, colorType, lineSize;
  13335. const bytes = imgData.data;
  13336. switch (kind) {
  13337. case _util.ImageKind.GRAYSCALE_1BPP:
  13338. colorType = 0;
  13339. bitDepth = 1;
  13340. lineSize = width + 7 >> 3;
  13341. break;
  13342. case _util.ImageKind.RGB_24BPP:
  13343. colorType = 2;
  13344. bitDepth = 8;
  13345. lineSize = width * 3;
  13346. break;
  13347. case _util.ImageKind.RGBA_32BPP:
  13348. colorType = 6;
  13349. bitDepth = 8;
  13350. lineSize = width * 4;
  13351. break;
  13352. default:
  13353. throw new Error("invalid format");
  13354. }
  13355. const literals = new Uint8Array((1 + lineSize) * height);
  13356. let offsetLiterals = 0,
  13357. offsetBytes = 0;
  13358. for (let y = 0; y < height; ++y) {
  13359. literals[offsetLiterals++] = 0;
  13360. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize), offsetLiterals);
  13361. offsetBytes += lineSize;
  13362. offsetLiterals += lineSize;
  13363. }
  13364. if (kind === _util.ImageKind.GRAYSCALE_1BPP && isMask) {
  13365. offsetLiterals = 0;
  13366. for (let y = 0; y < height; y++) {
  13367. offsetLiterals++;
  13368. for (let i = 0; i < lineSize; i++) {
  13369. literals[offsetLiterals++] ^= 0xff;
  13370. }
  13371. }
  13372. }
  13373. 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]);
  13374. const idat = deflateSync(literals);
  13375. const pngLength = PNG_HEADER.length + CHUNK_WRAPPER_SIZE * 3 + ihdr.length + idat.length;
  13376. const data = new Uint8Array(pngLength);
  13377. let offset = 0;
  13378. data.set(PNG_HEADER, offset);
  13379. offset += PNG_HEADER.length;
  13380. writePngChunk("IHDR", ihdr, data, offset);
  13381. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  13382. writePngChunk("IDATA", idat, data, offset);
  13383. offset += CHUNK_WRAPPER_SIZE + idat.length;
  13384. writePngChunk("IEND", new Uint8Array(0), data, offset);
  13385. return createObjectURL(data, "image/png", forceDataSchema);
  13386. }
  13387. return function convertImgDataToPng(imgData, forceDataSchema, isMask) {
  13388. const kind = imgData.kind === undefined ? _util.ImageKind.GRAYSCALE_1BPP : imgData.kind;
  13389. return encode(imgData, kind, forceDataSchema, isMask);
  13390. };
  13391. }();
  13392. class SVGExtraState {
  13393. constructor() {
  13394. this.fontSizeScale = 1;
  13395. this.fontWeight = SVG_DEFAULTS.fontWeight;
  13396. this.fontSize = 0;
  13397. this.textMatrix = _util.IDENTITY_MATRIX;
  13398. this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
  13399. this.leading = 0;
  13400. this.textRenderingMode = _util.TextRenderingMode.FILL;
  13401. this.textMatrixScale = 1;
  13402. this.x = 0;
  13403. this.y = 0;
  13404. this.lineX = 0;
  13405. this.lineY = 0;
  13406. this.charSpacing = 0;
  13407. this.wordSpacing = 0;
  13408. this.textHScale = 1;
  13409. this.textRise = 0;
  13410. this.fillColor = SVG_DEFAULTS.fillColor;
  13411. this.strokeColor = "#000000";
  13412. this.fillAlpha = 1;
  13413. this.strokeAlpha = 1;
  13414. this.lineWidth = 1;
  13415. this.lineJoin = "";
  13416. this.lineCap = "";
  13417. this.miterLimit = 0;
  13418. this.dashArray = [];
  13419. this.dashPhase = 0;
  13420. this.dependencies = [];
  13421. this.activeClipUrl = null;
  13422. this.clipGroup = null;
  13423. this.maskId = "";
  13424. }
  13425. clone() {
  13426. return Object.create(this);
  13427. }
  13428. setCurrentPoint(x, y) {
  13429. this.x = x;
  13430. this.y = y;
  13431. }
  13432. }
  13433. function opListToTree(opList) {
  13434. let opTree = [];
  13435. const tmp = [];
  13436. for (const opListElement of opList) {
  13437. if (opListElement.fn === "save") {
  13438. opTree.push({
  13439. fnId: 92,
  13440. fn: "group",
  13441. items: []
  13442. });
  13443. tmp.push(opTree);
  13444. opTree = opTree.at(-1).items;
  13445. continue;
  13446. }
  13447. if (opListElement.fn === "restore") {
  13448. opTree = tmp.pop();
  13449. } else {
  13450. opTree.push(opListElement);
  13451. }
  13452. }
  13453. return opTree;
  13454. }
  13455. function pf(value) {
  13456. if (Number.isInteger(value)) {
  13457. return value.toString();
  13458. }
  13459. const s = value.toFixed(10);
  13460. let i = s.length - 1;
  13461. if (s[i] !== "0") {
  13462. return s;
  13463. }
  13464. do {
  13465. i--;
  13466. } while (s[i] === "0");
  13467. return s.substring(0, s[i] === "." ? i : i + 1);
  13468. }
  13469. function pm(m) {
  13470. if (m[4] === 0 && m[5] === 0) {
  13471. if (m[1] === 0 && m[2] === 0) {
  13472. if (m[0] === 1 && m[3] === 1) {
  13473. return "";
  13474. }
  13475. return `scale(${pf(m[0])} ${pf(m[3])})`;
  13476. }
  13477. if (m[0] === m[3] && m[1] === -m[2]) {
  13478. const a = Math.acos(m[0]) * 180 / Math.PI;
  13479. return `rotate(${pf(a)})`;
  13480. }
  13481. } else {
  13482. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  13483. return `translate(${pf(m[4])} ${pf(m[5])})`;
  13484. }
  13485. }
  13486. return `matrix(${pf(m[0])} ${pf(m[1])} ${pf(m[2])} ${pf(m[3])} ${pf(m[4])} ` + `${pf(m[5])})`;
  13487. }
  13488. let clipCount = 0;
  13489. let maskCount = 0;
  13490. let shadingCount = 0;
  13491. exports.SVGGraphics = SVGGraphics = class {
  13492. constructor(commonObjs, objs, forceDataSchema = false) {
  13493. (0, _display_utils.deprecated)("The SVG back-end is no longer maintained and *may* be removed in the future.");
  13494. this.svgFactory = new _display_utils.DOMSVGFactory();
  13495. this.current = new SVGExtraState();
  13496. this.transformMatrix = _util.IDENTITY_MATRIX;
  13497. this.transformStack = [];
  13498. this.extraStack = [];
  13499. this.commonObjs = commonObjs;
  13500. this.objs = objs;
  13501. this.pendingClip = null;
  13502. this.pendingEOFill = false;
  13503. this.embedFonts = false;
  13504. this.embeddedFonts = Object.create(null);
  13505. this.cssStyle = null;
  13506. this.forceDataSchema = !!forceDataSchema;
  13507. this._operatorIdMapping = [];
  13508. for (const op in _util.OPS) {
  13509. this._operatorIdMapping[_util.OPS[op]] = op;
  13510. }
  13511. }
  13512. save() {
  13513. this.transformStack.push(this.transformMatrix);
  13514. const old = this.current;
  13515. this.extraStack.push(old);
  13516. this.current = old.clone();
  13517. }
  13518. restore() {
  13519. this.transformMatrix = this.transformStack.pop();
  13520. this.current = this.extraStack.pop();
  13521. this.pendingClip = null;
  13522. this.tgrp = null;
  13523. }
  13524. group(items) {
  13525. this.save();
  13526. this.executeOpTree(items);
  13527. this.restore();
  13528. }
  13529. loadDependencies(operatorList) {
  13530. const fnArray = operatorList.fnArray;
  13531. const argsArray = operatorList.argsArray;
  13532. for (let i = 0, ii = fnArray.length; i < ii; i++) {
  13533. if (fnArray[i] !== _util.OPS.dependency) {
  13534. continue;
  13535. }
  13536. for (const obj of argsArray[i]) {
  13537. const objsPool = obj.startsWith("g_") ? this.commonObjs : this.objs;
  13538. const promise = new Promise(resolve => {
  13539. objsPool.get(obj, resolve);
  13540. });
  13541. this.current.dependencies.push(promise);
  13542. }
  13543. }
  13544. return Promise.all(this.current.dependencies);
  13545. }
  13546. transform(a, b, c, d, e, f) {
  13547. const transformMatrix = [a, b, c, d, e, f];
  13548. this.transformMatrix = _util.Util.transform(this.transformMatrix, transformMatrix);
  13549. this.tgrp = null;
  13550. }
  13551. getSVG(operatorList, viewport) {
  13552. this.viewport = viewport;
  13553. const svgElement = this._initialize(viewport);
  13554. return this.loadDependencies(operatorList).then(() => {
  13555. this.transformMatrix = _util.IDENTITY_MATRIX;
  13556. this.executeOpTree(this.convertOpList(operatorList));
  13557. return svgElement;
  13558. });
  13559. }
  13560. convertOpList(operatorList) {
  13561. const operatorIdMapping = this._operatorIdMapping;
  13562. const argsArray = operatorList.argsArray;
  13563. const fnArray = operatorList.fnArray;
  13564. const opList = [];
  13565. for (let i = 0, ii = fnArray.length; i < ii; i++) {
  13566. const fnId = fnArray[i];
  13567. opList.push({
  13568. fnId,
  13569. fn: operatorIdMapping[fnId],
  13570. args: argsArray[i]
  13571. });
  13572. }
  13573. return opListToTree(opList);
  13574. }
  13575. executeOpTree(opTree) {
  13576. for (const opTreeElement of opTree) {
  13577. const fn = opTreeElement.fn;
  13578. const fnId = opTreeElement.fnId;
  13579. const args = opTreeElement.args;
  13580. switch (fnId | 0) {
  13581. case _util.OPS.beginText:
  13582. this.beginText();
  13583. break;
  13584. case _util.OPS.dependency:
  13585. break;
  13586. case _util.OPS.setLeading:
  13587. this.setLeading(args);
  13588. break;
  13589. case _util.OPS.setLeadingMoveText:
  13590. this.setLeadingMoveText(args[0], args[1]);
  13591. break;
  13592. case _util.OPS.setFont:
  13593. this.setFont(args);
  13594. break;
  13595. case _util.OPS.showText:
  13596. this.showText(args[0]);
  13597. break;
  13598. case _util.OPS.showSpacedText:
  13599. this.showText(args[0]);
  13600. break;
  13601. case _util.OPS.endText:
  13602. this.endText();
  13603. break;
  13604. case _util.OPS.moveText:
  13605. this.moveText(args[0], args[1]);
  13606. break;
  13607. case _util.OPS.setCharSpacing:
  13608. this.setCharSpacing(args[0]);
  13609. break;
  13610. case _util.OPS.setWordSpacing:
  13611. this.setWordSpacing(args[0]);
  13612. break;
  13613. case _util.OPS.setHScale:
  13614. this.setHScale(args[0]);
  13615. break;
  13616. case _util.OPS.setTextMatrix:
  13617. this.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
  13618. break;
  13619. case _util.OPS.setTextRise:
  13620. this.setTextRise(args[0]);
  13621. break;
  13622. case _util.OPS.setTextRenderingMode:
  13623. this.setTextRenderingMode(args[0]);
  13624. break;
  13625. case _util.OPS.setLineWidth:
  13626. this.setLineWidth(args[0]);
  13627. break;
  13628. case _util.OPS.setLineJoin:
  13629. this.setLineJoin(args[0]);
  13630. break;
  13631. case _util.OPS.setLineCap:
  13632. this.setLineCap(args[0]);
  13633. break;
  13634. case _util.OPS.setMiterLimit:
  13635. this.setMiterLimit(args[0]);
  13636. break;
  13637. case _util.OPS.setFillRGBColor:
  13638. this.setFillRGBColor(args[0], args[1], args[2]);
  13639. break;
  13640. case _util.OPS.setStrokeRGBColor:
  13641. this.setStrokeRGBColor(args[0], args[1], args[2]);
  13642. break;
  13643. case _util.OPS.setStrokeColorN:
  13644. this.setStrokeColorN(args);
  13645. break;
  13646. case _util.OPS.setFillColorN:
  13647. this.setFillColorN(args);
  13648. break;
  13649. case _util.OPS.shadingFill:
  13650. this.shadingFill(args[0]);
  13651. break;
  13652. case _util.OPS.setDash:
  13653. this.setDash(args[0], args[1]);
  13654. break;
  13655. case _util.OPS.setRenderingIntent:
  13656. this.setRenderingIntent(args[0]);
  13657. break;
  13658. case _util.OPS.setFlatness:
  13659. this.setFlatness(args[0]);
  13660. break;
  13661. case _util.OPS.setGState:
  13662. this.setGState(args[0]);
  13663. break;
  13664. case _util.OPS.fill:
  13665. this.fill();
  13666. break;
  13667. case _util.OPS.eoFill:
  13668. this.eoFill();
  13669. break;
  13670. case _util.OPS.stroke:
  13671. this.stroke();
  13672. break;
  13673. case _util.OPS.fillStroke:
  13674. this.fillStroke();
  13675. break;
  13676. case _util.OPS.eoFillStroke:
  13677. this.eoFillStroke();
  13678. break;
  13679. case _util.OPS.clip:
  13680. this.clip("nonzero");
  13681. break;
  13682. case _util.OPS.eoClip:
  13683. this.clip("evenodd");
  13684. break;
  13685. case _util.OPS.paintSolidColorImageMask:
  13686. this.paintSolidColorImageMask();
  13687. break;
  13688. case _util.OPS.paintImageXObject:
  13689. this.paintImageXObject(args[0]);
  13690. break;
  13691. case _util.OPS.paintInlineImageXObject:
  13692. this.paintInlineImageXObject(args[0]);
  13693. break;
  13694. case _util.OPS.paintImageMaskXObject:
  13695. this.paintImageMaskXObject(args[0]);
  13696. break;
  13697. case _util.OPS.paintFormXObjectBegin:
  13698. this.paintFormXObjectBegin(args[0], args[1]);
  13699. break;
  13700. case _util.OPS.paintFormXObjectEnd:
  13701. this.paintFormXObjectEnd();
  13702. break;
  13703. case _util.OPS.closePath:
  13704. this.closePath();
  13705. break;
  13706. case _util.OPS.closeStroke:
  13707. this.closeStroke();
  13708. break;
  13709. case _util.OPS.closeFillStroke:
  13710. this.closeFillStroke();
  13711. break;
  13712. case _util.OPS.closeEOFillStroke:
  13713. this.closeEOFillStroke();
  13714. break;
  13715. case _util.OPS.nextLine:
  13716. this.nextLine();
  13717. break;
  13718. case _util.OPS.transform:
  13719. this.transform(args[0], args[1], args[2], args[3], args[4], args[5]);
  13720. break;
  13721. case _util.OPS.constructPath:
  13722. this.constructPath(args[0], args[1]);
  13723. break;
  13724. case _util.OPS.endPath:
  13725. this.endPath();
  13726. break;
  13727. case 92:
  13728. this.group(opTreeElement.items);
  13729. break;
  13730. default:
  13731. (0, _util.warn)(`Unimplemented operator ${fn}`);
  13732. break;
  13733. }
  13734. }
  13735. }
  13736. setWordSpacing(wordSpacing) {
  13737. this.current.wordSpacing = wordSpacing;
  13738. }
  13739. setCharSpacing(charSpacing) {
  13740. this.current.charSpacing = charSpacing;
  13741. }
  13742. nextLine() {
  13743. this.moveText(0, this.current.leading);
  13744. }
  13745. setTextMatrix(a, b, c, d, e, f) {
  13746. const current = this.current;
  13747. current.textMatrix = current.lineMatrix = [a, b, c, d, e, f];
  13748. current.textMatrixScale = Math.hypot(a, b);
  13749. current.x = current.lineX = 0;
  13750. current.y = current.lineY = 0;
  13751. current.xcoords = [];
  13752. current.ycoords = [];
  13753. current.tspan = this.svgFactory.createElement("svg:tspan");
  13754. current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
  13755. current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
  13756. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  13757. current.txtElement = this.svgFactory.createElement("svg:text");
  13758. current.txtElement.append(current.tspan);
  13759. }
  13760. beginText() {
  13761. const current = this.current;
  13762. current.x = current.lineX = 0;
  13763. current.y = current.lineY = 0;
  13764. current.textMatrix = _util.IDENTITY_MATRIX;
  13765. current.lineMatrix = _util.IDENTITY_MATRIX;
  13766. current.textMatrixScale = 1;
  13767. current.tspan = this.svgFactory.createElement("svg:tspan");
  13768. current.txtElement = this.svgFactory.createElement("svg:text");
  13769. current.txtgrp = this.svgFactory.createElement("svg:g");
  13770. current.xcoords = [];
  13771. current.ycoords = [];
  13772. }
  13773. moveText(x, y) {
  13774. const current = this.current;
  13775. current.x = current.lineX += x;
  13776. current.y = current.lineY += y;
  13777. current.xcoords = [];
  13778. current.ycoords = [];
  13779. current.tspan = this.svgFactory.createElement("svg:tspan");
  13780. current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
  13781. current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
  13782. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  13783. }
  13784. showText(glyphs) {
  13785. const current = this.current;
  13786. const font = current.font;
  13787. const fontSize = current.fontSize;
  13788. if (fontSize === 0) {
  13789. return;
  13790. }
  13791. const fontSizeScale = current.fontSizeScale;
  13792. const charSpacing = current.charSpacing;
  13793. const wordSpacing = current.wordSpacing;
  13794. const fontDirection = current.fontDirection;
  13795. const textHScale = current.textHScale * fontDirection;
  13796. const vertical = font.vertical;
  13797. const spacingDir = vertical ? 1 : -1;
  13798. const defaultVMetrics = font.defaultVMetrics;
  13799. const widthAdvanceScale = fontSize * current.fontMatrix[0];
  13800. let x = 0;
  13801. for (const glyph of glyphs) {
  13802. if (glyph === null) {
  13803. x += fontDirection * wordSpacing;
  13804. continue;
  13805. } else if (typeof glyph === "number") {
  13806. x += spacingDir * glyph * fontSize / 1000;
  13807. continue;
  13808. }
  13809. const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  13810. const character = glyph.fontChar;
  13811. let scaledX, scaledY;
  13812. let width = glyph.width;
  13813. if (vertical) {
  13814. let vx;
  13815. const vmetric = glyph.vmetric || defaultVMetrics;
  13816. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  13817. vx = -vx * widthAdvanceScale;
  13818. const vy = vmetric[2] * widthAdvanceScale;
  13819. width = vmetric ? -vmetric[0] : width;
  13820. scaledX = vx / fontSizeScale;
  13821. scaledY = (x + vy) / fontSizeScale;
  13822. } else {
  13823. scaledX = x / fontSizeScale;
  13824. scaledY = 0;
  13825. }
  13826. if (glyph.isInFont || font.missingFile) {
  13827. current.xcoords.push(current.x + scaledX);
  13828. if (vertical) {
  13829. current.ycoords.push(-current.y + scaledY);
  13830. }
  13831. current.tspan.textContent += character;
  13832. } else {}
  13833. let charWidth;
  13834. if (vertical) {
  13835. charWidth = width * widthAdvanceScale - spacing * fontDirection;
  13836. } else {
  13837. charWidth = width * widthAdvanceScale + spacing * fontDirection;
  13838. }
  13839. x += charWidth;
  13840. }
  13841. current.tspan.setAttributeNS(null, "x", current.xcoords.map(pf).join(" "));
  13842. if (vertical) {
  13843. current.tspan.setAttributeNS(null, "y", current.ycoords.map(pf).join(" "));
  13844. } else {
  13845. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  13846. }
  13847. if (vertical) {
  13848. current.y -= x;
  13849. } else {
  13850. current.x += x * textHScale;
  13851. }
  13852. current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
  13853. current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
  13854. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  13855. current.tspan.setAttributeNS(null, "font-style", current.fontStyle);
  13856. }
  13857. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  13858. current.tspan.setAttributeNS(null, "font-weight", current.fontWeight);
  13859. }
  13860. const fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  13861. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  13862. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  13863. current.tspan.setAttributeNS(null, "fill", current.fillColor);
  13864. }
  13865. if (current.fillAlpha < 1) {
  13866. current.tspan.setAttributeNS(null, "fill-opacity", current.fillAlpha);
  13867. }
  13868. } else if (current.textRenderingMode === _util.TextRenderingMode.ADD_TO_PATH) {
  13869. current.tspan.setAttributeNS(null, "fill", "transparent");
  13870. } else {
  13871. current.tspan.setAttributeNS(null, "fill", "none");
  13872. }
  13873. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  13874. const lineWidthScale = 1 / (current.textMatrixScale || 1);
  13875. this._setStrokeAttributes(current.tspan, lineWidthScale);
  13876. }
  13877. let textMatrix = current.textMatrix;
  13878. if (current.textRise !== 0) {
  13879. textMatrix = textMatrix.slice();
  13880. textMatrix[5] += current.textRise;
  13881. }
  13882. current.txtElement.setAttributeNS(null, "transform", `${pm(textMatrix)} scale(${pf(textHScale)}, -1)`);
  13883. current.txtElement.setAttributeNS(XML_NS, "xml:space", "preserve");
  13884. current.txtElement.append(current.tspan);
  13885. current.txtgrp.append(current.txtElement);
  13886. this._ensureTransformGroup().append(current.txtElement);
  13887. }
  13888. setLeadingMoveText(x, y) {
  13889. this.setLeading(-y);
  13890. this.moveText(x, y);
  13891. }
  13892. addFontStyle(fontObj) {
  13893. if (!fontObj.data) {
  13894. throw new Error("addFontStyle: No font data available, " + 'ensure that the "fontExtraProperties" API parameter is set.');
  13895. }
  13896. if (!this.cssStyle) {
  13897. this.cssStyle = this.svgFactory.createElement("svg:style");
  13898. this.cssStyle.setAttributeNS(null, "type", "text/css");
  13899. this.defs.append(this.cssStyle);
  13900. }
  13901. const url = createObjectURL(fontObj.data, fontObj.mimetype, this.forceDataSchema);
  13902. this.cssStyle.textContent += `@font-face { font-family: "${fontObj.loadedName}";` + ` src: url(${url}); }\n`;
  13903. }
  13904. setFont(details) {
  13905. const current = this.current;
  13906. const fontObj = this.commonObjs.get(details[0]);
  13907. let size = details[1];
  13908. current.font = fontObj;
  13909. if (this.embedFonts && !fontObj.missingFile && !this.embeddedFonts[fontObj.loadedName]) {
  13910. this.addFontStyle(fontObj);
  13911. this.embeddedFonts[fontObj.loadedName] = fontObj;
  13912. }
  13913. current.fontMatrix = fontObj.fontMatrix || _util.FONT_IDENTITY_MATRIX;
  13914. let bold = "normal";
  13915. if (fontObj.black) {
  13916. bold = "900";
  13917. } else if (fontObj.bold) {
  13918. bold = "bold";
  13919. }
  13920. const italic = fontObj.italic ? "italic" : "normal";
  13921. if (size < 0) {
  13922. size = -size;
  13923. current.fontDirection = -1;
  13924. } else {
  13925. current.fontDirection = 1;
  13926. }
  13927. current.fontSize = size;
  13928. current.fontFamily = fontObj.loadedName;
  13929. current.fontWeight = bold;
  13930. current.fontStyle = italic;
  13931. current.tspan = this.svgFactory.createElement("svg:tspan");
  13932. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  13933. current.xcoords = [];
  13934. current.ycoords = [];
  13935. }
  13936. endText() {
  13937. const current = this.current;
  13938. if (current.textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG && current.txtElement?.hasChildNodes()) {
  13939. current.element = current.txtElement;
  13940. this.clip("nonzero");
  13941. this.endPath();
  13942. }
  13943. }
  13944. setLineWidth(width) {
  13945. if (width > 0) {
  13946. this.current.lineWidth = width;
  13947. }
  13948. }
  13949. setLineCap(style) {
  13950. this.current.lineCap = LINE_CAP_STYLES[style];
  13951. }
  13952. setLineJoin(style) {
  13953. this.current.lineJoin = LINE_JOIN_STYLES[style];
  13954. }
  13955. setMiterLimit(limit) {
  13956. this.current.miterLimit = limit;
  13957. }
  13958. setStrokeAlpha(strokeAlpha) {
  13959. this.current.strokeAlpha = strokeAlpha;
  13960. }
  13961. setStrokeRGBColor(r, g, b) {
  13962. this.current.strokeColor = _util.Util.makeHexColor(r, g, b);
  13963. }
  13964. setFillAlpha(fillAlpha) {
  13965. this.current.fillAlpha = fillAlpha;
  13966. }
  13967. setFillRGBColor(r, g, b) {
  13968. this.current.fillColor = _util.Util.makeHexColor(r, g, b);
  13969. this.current.tspan = this.svgFactory.createElement("svg:tspan");
  13970. this.current.xcoords = [];
  13971. this.current.ycoords = [];
  13972. }
  13973. setStrokeColorN(args) {
  13974. this.current.strokeColor = this._makeColorN_Pattern(args);
  13975. }
  13976. setFillColorN(args) {
  13977. this.current.fillColor = this._makeColorN_Pattern(args);
  13978. }
  13979. shadingFill(args) {
  13980. const width = this.viewport.width;
  13981. const height = this.viewport.height;
  13982. const inv = _util.Util.inverseTransform(this.transformMatrix);
  13983. const bl = _util.Util.applyTransform([0, 0], inv);
  13984. const br = _util.Util.applyTransform([0, height], inv);
  13985. const ul = _util.Util.applyTransform([width, 0], inv);
  13986. const ur = _util.Util.applyTransform([width, height], inv);
  13987. const x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  13988. const y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  13989. const x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  13990. const y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  13991. const rect = this.svgFactory.createElement("svg:rect");
  13992. rect.setAttributeNS(null, "x", x0);
  13993. rect.setAttributeNS(null, "y", y0);
  13994. rect.setAttributeNS(null, "width", x1 - x0);
  13995. rect.setAttributeNS(null, "height", y1 - y0);
  13996. rect.setAttributeNS(null, "fill", this._makeShadingPattern(args));
  13997. if (this.current.fillAlpha < 1) {
  13998. rect.setAttributeNS(null, "fill-opacity", this.current.fillAlpha);
  13999. }
  14000. this._ensureTransformGroup().append(rect);
  14001. }
  14002. _makeColorN_Pattern(args) {
  14003. if (args[0] === "TilingPattern") {
  14004. return this._makeTilingPattern(args);
  14005. }
  14006. return this._makeShadingPattern(args);
  14007. }
  14008. _makeTilingPattern(args) {
  14009. const color = args[1];
  14010. const operatorList = args[2];
  14011. const matrix = args[3] || _util.IDENTITY_MATRIX;
  14012. const [x0, y0, x1, y1] = args[4];
  14013. const xstep = args[5];
  14014. const ystep = args[6];
  14015. const paintType = args[7];
  14016. const tilingId = `shading${shadingCount++}`;
  14017. const [tx0, ty0, tx1, ty1] = _util.Util.normalizeRect([..._util.Util.applyTransform([x0, y0], matrix), ..._util.Util.applyTransform([x1, y1], matrix)]);
  14018. const [xscale, yscale] = _util.Util.singularValueDecompose2dScale(matrix);
  14019. const txstep = xstep * xscale;
  14020. const tystep = ystep * yscale;
  14021. const tiling = this.svgFactory.createElement("svg:pattern");
  14022. tiling.setAttributeNS(null, "id", tilingId);
  14023. tiling.setAttributeNS(null, "patternUnits", "userSpaceOnUse");
  14024. tiling.setAttributeNS(null, "width", txstep);
  14025. tiling.setAttributeNS(null, "height", tystep);
  14026. tiling.setAttributeNS(null, "x", `${tx0}`);
  14027. tiling.setAttributeNS(null, "y", `${ty0}`);
  14028. const svg = this.svg;
  14029. const transformMatrix = this.transformMatrix;
  14030. const fillColor = this.current.fillColor;
  14031. const strokeColor = this.current.strokeColor;
  14032. const bbox = this.svgFactory.create(tx1 - tx0, ty1 - ty0);
  14033. this.svg = bbox;
  14034. this.transformMatrix = matrix;
  14035. if (paintType === 2) {
  14036. const cssColor = _util.Util.makeHexColor(...color);
  14037. this.current.fillColor = cssColor;
  14038. this.current.strokeColor = cssColor;
  14039. }
  14040. this.executeOpTree(this.convertOpList(operatorList));
  14041. this.svg = svg;
  14042. this.transformMatrix = transformMatrix;
  14043. this.current.fillColor = fillColor;
  14044. this.current.strokeColor = strokeColor;
  14045. tiling.append(bbox.childNodes[0]);
  14046. this.defs.append(tiling);
  14047. return `url(#${tilingId})`;
  14048. }
  14049. _makeShadingPattern(args) {
  14050. if (typeof args === "string") {
  14051. args = this.objs.get(args);
  14052. }
  14053. switch (args[0]) {
  14054. case "RadialAxial":
  14055. const shadingId = `shading${shadingCount++}`;
  14056. const colorStops = args[3];
  14057. let gradient;
  14058. switch (args[1]) {
  14059. case "axial":
  14060. const point0 = args[4];
  14061. const point1 = args[5];
  14062. gradient = this.svgFactory.createElement("svg:linearGradient");
  14063. gradient.setAttributeNS(null, "id", shadingId);
  14064. gradient.setAttributeNS(null, "gradientUnits", "userSpaceOnUse");
  14065. gradient.setAttributeNS(null, "x1", point0[0]);
  14066. gradient.setAttributeNS(null, "y1", point0[1]);
  14067. gradient.setAttributeNS(null, "x2", point1[0]);
  14068. gradient.setAttributeNS(null, "y2", point1[1]);
  14069. break;
  14070. case "radial":
  14071. const focalPoint = args[4];
  14072. const circlePoint = args[5];
  14073. const focalRadius = args[6];
  14074. const circleRadius = args[7];
  14075. gradient = this.svgFactory.createElement("svg:radialGradient");
  14076. gradient.setAttributeNS(null, "id", shadingId);
  14077. gradient.setAttributeNS(null, "gradientUnits", "userSpaceOnUse");
  14078. gradient.setAttributeNS(null, "cx", circlePoint[0]);
  14079. gradient.setAttributeNS(null, "cy", circlePoint[1]);
  14080. gradient.setAttributeNS(null, "r", circleRadius);
  14081. gradient.setAttributeNS(null, "fx", focalPoint[0]);
  14082. gradient.setAttributeNS(null, "fy", focalPoint[1]);
  14083. gradient.setAttributeNS(null, "fr", focalRadius);
  14084. break;
  14085. default:
  14086. throw new Error(`Unknown RadialAxial type: ${args[1]}`);
  14087. }
  14088. for (const colorStop of colorStops) {
  14089. const stop = this.svgFactory.createElement("svg:stop");
  14090. stop.setAttributeNS(null, "offset", colorStop[0]);
  14091. stop.setAttributeNS(null, "stop-color", colorStop[1]);
  14092. gradient.append(stop);
  14093. }
  14094. this.defs.append(gradient);
  14095. return `url(#${shadingId})`;
  14096. case "Mesh":
  14097. (0, _util.warn)("Unimplemented pattern Mesh");
  14098. return null;
  14099. case "Dummy":
  14100. return "hotpink";
  14101. default:
  14102. throw new Error(`Unknown IR type: ${args[0]}`);
  14103. }
  14104. }
  14105. setDash(dashArray, dashPhase) {
  14106. this.current.dashArray = dashArray;
  14107. this.current.dashPhase = dashPhase;
  14108. }
  14109. constructPath(ops, args) {
  14110. const current = this.current;
  14111. let x = current.x,
  14112. y = current.y;
  14113. let d = [];
  14114. let j = 0;
  14115. for (const op of ops) {
  14116. switch (op | 0) {
  14117. case _util.OPS.rectangle:
  14118. x = args[j++];
  14119. y = args[j++];
  14120. const width = args[j++];
  14121. const height = args[j++];
  14122. const xw = x + width;
  14123. const yh = y + height;
  14124. d.push("M", pf(x), pf(y), "L", pf(xw), pf(y), "L", pf(xw), pf(yh), "L", pf(x), pf(yh), "Z");
  14125. break;
  14126. case _util.OPS.moveTo:
  14127. x = args[j++];
  14128. y = args[j++];
  14129. d.push("M", pf(x), pf(y));
  14130. break;
  14131. case _util.OPS.lineTo:
  14132. x = args[j++];
  14133. y = args[j++];
  14134. d.push("L", pf(x), pf(y));
  14135. break;
  14136. case _util.OPS.curveTo:
  14137. x = args[j + 4];
  14138. y = args[j + 5];
  14139. d.push("C", pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]), pf(x), pf(y));
  14140. j += 6;
  14141. break;
  14142. case _util.OPS.curveTo2:
  14143. d.push("C", pf(x), pf(y), pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]));
  14144. x = args[j + 2];
  14145. y = args[j + 3];
  14146. j += 4;
  14147. break;
  14148. case _util.OPS.curveTo3:
  14149. x = args[j + 2];
  14150. y = args[j + 3];
  14151. d.push("C", pf(args[j]), pf(args[j + 1]), pf(x), pf(y), pf(x), pf(y));
  14152. j += 4;
  14153. break;
  14154. case _util.OPS.closePath:
  14155. d.push("Z");
  14156. break;
  14157. }
  14158. }
  14159. d = d.join(" ");
  14160. if (current.path && ops.length > 0 && ops[0] !== _util.OPS.rectangle && ops[0] !== _util.OPS.moveTo) {
  14161. d = current.path.getAttributeNS(null, "d") + d;
  14162. } else {
  14163. current.path = this.svgFactory.createElement("svg:path");
  14164. this._ensureTransformGroup().append(current.path);
  14165. }
  14166. current.path.setAttributeNS(null, "d", d);
  14167. current.path.setAttributeNS(null, "fill", "none");
  14168. current.element = current.path;
  14169. current.setCurrentPoint(x, y);
  14170. }
  14171. endPath() {
  14172. const current = this.current;
  14173. current.path = null;
  14174. if (!this.pendingClip) {
  14175. return;
  14176. }
  14177. if (!current.element) {
  14178. this.pendingClip = null;
  14179. return;
  14180. }
  14181. const clipId = `clippath${clipCount++}`;
  14182. const clipPath = this.svgFactory.createElement("svg:clipPath");
  14183. clipPath.setAttributeNS(null, "id", clipId);
  14184. clipPath.setAttributeNS(null, "transform", pm(this.transformMatrix));
  14185. const clipElement = current.element.cloneNode(true);
  14186. if (this.pendingClip === "evenodd") {
  14187. clipElement.setAttributeNS(null, "clip-rule", "evenodd");
  14188. } else {
  14189. clipElement.setAttributeNS(null, "clip-rule", "nonzero");
  14190. }
  14191. this.pendingClip = null;
  14192. clipPath.append(clipElement);
  14193. this.defs.append(clipPath);
  14194. if (current.activeClipUrl) {
  14195. current.clipGroup = null;
  14196. for (const prev of this.extraStack) {
  14197. prev.clipGroup = null;
  14198. }
  14199. clipPath.setAttributeNS(null, "clip-path", current.activeClipUrl);
  14200. }
  14201. current.activeClipUrl = `url(#${clipId})`;
  14202. this.tgrp = null;
  14203. }
  14204. clip(type) {
  14205. this.pendingClip = type;
  14206. }
  14207. closePath() {
  14208. const current = this.current;
  14209. if (current.path) {
  14210. const d = `${current.path.getAttributeNS(null, "d")}Z`;
  14211. current.path.setAttributeNS(null, "d", d);
  14212. }
  14213. }
  14214. setLeading(leading) {
  14215. this.current.leading = -leading;
  14216. }
  14217. setTextRise(textRise) {
  14218. this.current.textRise = textRise;
  14219. }
  14220. setTextRenderingMode(textRenderingMode) {
  14221. this.current.textRenderingMode = textRenderingMode;
  14222. }
  14223. setHScale(scale) {
  14224. this.current.textHScale = scale / 100;
  14225. }
  14226. setRenderingIntent(intent) {}
  14227. setFlatness(flatness) {}
  14228. setGState(states) {
  14229. for (const [key, value] of states) {
  14230. switch (key) {
  14231. case "LW":
  14232. this.setLineWidth(value);
  14233. break;
  14234. case "LC":
  14235. this.setLineCap(value);
  14236. break;
  14237. case "LJ":
  14238. this.setLineJoin(value);
  14239. break;
  14240. case "ML":
  14241. this.setMiterLimit(value);
  14242. break;
  14243. case "D":
  14244. this.setDash(value[0], value[1]);
  14245. break;
  14246. case "RI":
  14247. this.setRenderingIntent(value);
  14248. break;
  14249. case "FL":
  14250. this.setFlatness(value);
  14251. break;
  14252. case "Font":
  14253. this.setFont(value);
  14254. break;
  14255. case "CA":
  14256. this.setStrokeAlpha(value);
  14257. break;
  14258. case "ca":
  14259. this.setFillAlpha(value);
  14260. break;
  14261. default:
  14262. (0, _util.warn)(`Unimplemented graphic state operator ${key}`);
  14263. break;
  14264. }
  14265. }
  14266. }
  14267. fill() {
  14268. const current = this.current;
  14269. if (current.element) {
  14270. current.element.setAttributeNS(null, "fill", current.fillColor);
  14271. current.element.setAttributeNS(null, "fill-opacity", current.fillAlpha);
  14272. this.endPath();
  14273. }
  14274. }
  14275. stroke() {
  14276. const current = this.current;
  14277. if (current.element) {
  14278. this._setStrokeAttributes(current.element);
  14279. current.element.setAttributeNS(null, "fill", "none");
  14280. this.endPath();
  14281. }
  14282. }
  14283. _setStrokeAttributes(element, lineWidthScale = 1) {
  14284. const current = this.current;
  14285. let dashArray = current.dashArray;
  14286. if (lineWidthScale !== 1 && dashArray.length > 0) {
  14287. dashArray = dashArray.map(function (value) {
  14288. return lineWidthScale * value;
  14289. });
  14290. }
  14291. element.setAttributeNS(null, "stroke", current.strokeColor);
  14292. element.setAttributeNS(null, "stroke-opacity", current.strokeAlpha);
  14293. element.setAttributeNS(null, "stroke-miterlimit", pf(current.miterLimit));
  14294. element.setAttributeNS(null, "stroke-linecap", current.lineCap);
  14295. element.setAttributeNS(null, "stroke-linejoin", current.lineJoin);
  14296. element.setAttributeNS(null, "stroke-width", pf(lineWidthScale * current.lineWidth) + "px");
  14297. element.setAttributeNS(null, "stroke-dasharray", dashArray.map(pf).join(" "));
  14298. element.setAttributeNS(null, "stroke-dashoffset", pf(lineWidthScale * current.dashPhase) + "px");
  14299. }
  14300. eoFill() {
  14301. if (this.current.element) {
  14302. this.current.element.setAttributeNS(null, "fill-rule", "evenodd");
  14303. }
  14304. this.fill();
  14305. }
  14306. fillStroke() {
  14307. this.stroke();
  14308. this.fill();
  14309. }
  14310. eoFillStroke() {
  14311. if (this.current.element) {
  14312. this.current.element.setAttributeNS(null, "fill-rule", "evenodd");
  14313. }
  14314. this.fillStroke();
  14315. }
  14316. closeStroke() {
  14317. this.closePath();
  14318. this.stroke();
  14319. }
  14320. closeFillStroke() {
  14321. this.closePath();
  14322. this.fillStroke();
  14323. }
  14324. closeEOFillStroke() {
  14325. this.closePath();
  14326. this.eoFillStroke();
  14327. }
  14328. paintSolidColorImageMask() {
  14329. const rect = this.svgFactory.createElement("svg:rect");
  14330. rect.setAttributeNS(null, "x", "0");
  14331. rect.setAttributeNS(null, "y", "0");
  14332. rect.setAttributeNS(null, "width", "1px");
  14333. rect.setAttributeNS(null, "height", "1px");
  14334. rect.setAttributeNS(null, "fill", this.current.fillColor);
  14335. this._ensureTransformGroup().append(rect);
  14336. }
  14337. paintImageXObject(objId) {
  14338. const imgData = objId.startsWith("g_") ? this.commonObjs.get(objId) : this.objs.get(objId);
  14339. if (!imgData) {
  14340. (0, _util.warn)(`Dependent image with object ID ${objId} is not ready yet`);
  14341. return;
  14342. }
  14343. this.paintInlineImageXObject(imgData);
  14344. }
  14345. paintInlineImageXObject(imgData, mask) {
  14346. const width = imgData.width;
  14347. const height = imgData.height;
  14348. const imgSrc = convertImgDataToPng(imgData, this.forceDataSchema, !!mask);
  14349. const cliprect = this.svgFactory.createElement("svg:rect");
  14350. cliprect.setAttributeNS(null, "x", "0");
  14351. cliprect.setAttributeNS(null, "y", "0");
  14352. cliprect.setAttributeNS(null, "width", pf(width));
  14353. cliprect.setAttributeNS(null, "height", pf(height));
  14354. this.current.element = cliprect;
  14355. this.clip("nonzero");
  14356. const imgEl = this.svgFactory.createElement("svg:image");
  14357. imgEl.setAttributeNS(XLINK_NS, "xlink:href", imgSrc);
  14358. imgEl.setAttributeNS(null, "x", "0");
  14359. imgEl.setAttributeNS(null, "y", pf(-height));
  14360. imgEl.setAttributeNS(null, "width", pf(width) + "px");
  14361. imgEl.setAttributeNS(null, "height", pf(height) + "px");
  14362. imgEl.setAttributeNS(null, "transform", `scale(${pf(1 / width)} ${pf(-1 / height)})`);
  14363. if (mask) {
  14364. mask.append(imgEl);
  14365. } else {
  14366. this._ensureTransformGroup().append(imgEl);
  14367. }
  14368. }
  14369. paintImageMaskXObject(imgData) {
  14370. const current = this.current;
  14371. const width = imgData.width;
  14372. const height = imgData.height;
  14373. const fillColor = current.fillColor;
  14374. current.maskId = `mask${maskCount++}`;
  14375. const mask = this.svgFactory.createElement("svg:mask");
  14376. mask.setAttributeNS(null, "id", current.maskId);
  14377. const rect = this.svgFactory.createElement("svg:rect");
  14378. rect.setAttributeNS(null, "x", "0");
  14379. rect.setAttributeNS(null, "y", "0");
  14380. rect.setAttributeNS(null, "width", pf(width));
  14381. rect.setAttributeNS(null, "height", pf(height));
  14382. rect.setAttributeNS(null, "fill", fillColor);
  14383. rect.setAttributeNS(null, "mask", `url(#${current.maskId})`);
  14384. this.defs.append(mask);
  14385. this._ensureTransformGroup().append(rect);
  14386. this.paintInlineImageXObject(imgData, mask);
  14387. }
  14388. paintFormXObjectBegin(matrix, bbox) {
  14389. if (Array.isArray(matrix) && matrix.length === 6) {
  14390. this.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
  14391. }
  14392. if (bbox) {
  14393. const width = bbox[2] - bbox[0];
  14394. const height = bbox[3] - bbox[1];
  14395. const cliprect = this.svgFactory.createElement("svg:rect");
  14396. cliprect.setAttributeNS(null, "x", bbox[0]);
  14397. cliprect.setAttributeNS(null, "y", bbox[1]);
  14398. cliprect.setAttributeNS(null, "width", pf(width));
  14399. cliprect.setAttributeNS(null, "height", pf(height));
  14400. this.current.element = cliprect;
  14401. this.clip("nonzero");
  14402. this.endPath();
  14403. }
  14404. }
  14405. paintFormXObjectEnd() {}
  14406. _initialize(viewport) {
  14407. const svg = this.svgFactory.create(viewport.width, viewport.height);
  14408. const definitions = this.svgFactory.createElement("svg:defs");
  14409. svg.append(definitions);
  14410. this.defs = definitions;
  14411. const rootGroup = this.svgFactory.createElement("svg:g");
  14412. rootGroup.setAttributeNS(null, "transform", pm(viewport.transform));
  14413. svg.append(rootGroup);
  14414. this.svg = rootGroup;
  14415. return svg;
  14416. }
  14417. _ensureClipGroup() {
  14418. if (!this.current.clipGroup) {
  14419. const clipGroup = this.svgFactory.createElement("svg:g");
  14420. clipGroup.setAttributeNS(null, "clip-path", this.current.activeClipUrl);
  14421. this.svg.append(clipGroup);
  14422. this.current.clipGroup = clipGroup;
  14423. }
  14424. return this.current.clipGroup;
  14425. }
  14426. _ensureTransformGroup() {
  14427. if (!this.tgrp) {
  14428. this.tgrp = this.svgFactory.createElement("svg:g");
  14429. this.tgrp.setAttributeNS(null, "transform", pm(this.transformMatrix));
  14430. if (this.current.activeClipUrl) {
  14431. this._ensureClipGroup().append(this.tgrp);
  14432. } else {
  14433. this.svg.append(this.tgrp);
  14434. }
  14435. }
  14436. return this.tgrp;
  14437. }
  14438. };
  14439. }
  14440. /***/ }),
  14441. /* 32 */
  14442. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  14443. Object.defineProperty(exports, "__esModule", ({
  14444. value: true
  14445. }));
  14446. exports.PDFNodeStream = void 0;
  14447. var _util = __w_pdfjs_require__(1);
  14448. var _network_utils = __w_pdfjs_require__(33);
  14449. ;
  14450. const fs = require("fs");
  14451. const http = require("http");
  14452. const https = require("https");
  14453. const url = require("url");
  14454. const fileUriRegex = /^file:\/\/\/[a-zA-Z]:\//;
  14455. function parseUrl(sourceUrl) {
  14456. const parsedUrl = url.parse(sourceUrl);
  14457. if (parsedUrl.protocol === "file:" || parsedUrl.host) {
  14458. return parsedUrl;
  14459. }
  14460. if (/^[a-z]:[/\\]/i.test(sourceUrl)) {
  14461. return url.parse(`file:///${sourceUrl}`);
  14462. }
  14463. if (!parsedUrl.host) {
  14464. parsedUrl.protocol = "file:";
  14465. }
  14466. return parsedUrl;
  14467. }
  14468. class PDFNodeStream {
  14469. constructor(source) {
  14470. this.source = source;
  14471. this.url = parseUrl(source.url);
  14472. this.isHttp = this.url.protocol === "http:" || this.url.protocol === "https:";
  14473. this.isFsUrl = this.url.protocol === "file:";
  14474. this.httpHeaders = this.isHttp && source.httpHeaders || {};
  14475. this._fullRequestReader = null;
  14476. this._rangeRequestReaders = [];
  14477. }
  14478. get _progressiveDataLength() {
  14479. return this._fullRequestReader?._loaded ?? 0;
  14480. }
  14481. getFullReader() {
  14482. (0, _util.assert)(!this._fullRequestReader, "PDFNodeStream.getFullReader can only be called once.");
  14483. this._fullRequestReader = this.isFsUrl ? new PDFNodeStreamFsFullReader(this) : new PDFNodeStreamFullReader(this);
  14484. return this._fullRequestReader;
  14485. }
  14486. getRangeReader(start, end) {
  14487. if (end <= this._progressiveDataLength) {
  14488. return null;
  14489. }
  14490. const rangeReader = this.isFsUrl ? new PDFNodeStreamFsRangeReader(this, start, end) : new PDFNodeStreamRangeReader(this, start, end);
  14491. this._rangeRequestReaders.push(rangeReader);
  14492. return rangeReader;
  14493. }
  14494. cancelAllRequests(reason) {
  14495. if (this._fullRequestReader) {
  14496. this._fullRequestReader.cancel(reason);
  14497. }
  14498. for (const reader of this._rangeRequestReaders.slice(0)) {
  14499. reader.cancel(reason);
  14500. }
  14501. }
  14502. }
  14503. exports.PDFNodeStream = PDFNodeStream;
  14504. class BaseFullReader {
  14505. constructor(stream) {
  14506. this._url = stream.url;
  14507. this._done = false;
  14508. this._storedError = null;
  14509. this.onProgress = null;
  14510. const source = stream.source;
  14511. this._contentLength = source.length;
  14512. this._loaded = 0;
  14513. this._filename = null;
  14514. this._disableRange = source.disableRange || false;
  14515. this._rangeChunkSize = source.rangeChunkSize;
  14516. if (!this._rangeChunkSize && !this._disableRange) {
  14517. this._disableRange = true;
  14518. }
  14519. this._isStreamingSupported = !source.disableStream;
  14520. this._isRangeSupported = !source.disableRange;
  14521. this._readableStream = null;
  14522. this._readCapability = (0, _util.createPromiseCapability)();
  14523. this._headersCapability = (0, _util.createPromiseCapability)();
  14524. }
  14525. get headersReady() {
  14526. return this._headersCapability.promise;
  14527. }
  14528. get filename() {
  14529. return this._filename;
  14530. }
  14531. get contentLength() {
  14532. return this._contentLength;
  14533. }
  14534. get isRangeSupported() {
  14535. return this._isRangeSupported;
  14536. }
  14537. get isStreamingSupported() {
  14538. return this._isStreamingSupported;
  14539. }
  14540. async read() {
  14541. await this._readCapability.promise;
  14542. if (this._done) {
  14543. return {
  14544. value: undefined,
  14545. done: true
  14546. };
  14547. }
  14548. if (this._storedError) {
  14549. throw this._storedError;
  14550. }
  14551. const chunk = this._readableStream.read();
  14552. if (chunk === null) {
  14553. this._readCapability = (0, _util.createPromiseCapability)();
  14554. return this.read();
  14555. }
  14556. this._loaded += chunk.length;
  14557. if (this.onProgress) {
  14558. this.onProgress({
  14559. loaded: this._loaded,
  14560. total: this._contentLength
  14561. });
  14562. }
  14563. const buffer = new Uint8Array(chunk).buffer;
  14564. return {
  14565. value: buffer,
  14566. done: false
  14567. };
  14568. }
  14569. cancel(reason) {
  14570. if (!this._readableStream) {
  14571. this._error(reason);
  14572. return;
  14573. }
  14574. this._readableStream.destroy(reason);
  14575. }
  14576. _error(reason) {
  14577. this._storedError = reason;
  14578. this._readCapability.resolve();
  14579. }
  14580. _setReadableStream(readableStream) {
  14581. this._readableStream = readableStream;
  14582. readableStream.on("readable", () => {
  14583. this._readCapability.resolve();
  14584. });
  14585. readableStream.on("end", () => {
  14586. readableStream.destroy();
  14587. this._done = true;
  14588. this._readCapability.resolve();
  14589. });
  14590. readableStream.on("error", reason => {
  14591. this._error(reason);
  14592. });
  14593. if (!this._isStreamingSupported && this._isRangeSupported) {
  14594. this._error(new _util.AbortException("streaming is disabled"));
  14595. }
  14596. if (this._storedError) {
  14597. this._readableStream.destroy(this._storedError);
  14598. }
  14599. }
  14600. }
  14601. class BaseRangeReader {
  14602. constructor(stream) {
  14603. this._url = stream.url;
  14604. this._done = false;
  14605. this._storedError = null;
  14606. this.onProgress = null;
  14607. this._loaded = 0;
  14608. this._readableStream = null;
  14609. this._readCapability = (0, _util.createPromiseCapability)();
  14610. const source = stream.source;
  14611. this._isStreamingSupported = !source.disableStream;
  14612. }
  14613. get isStreamingSupported() {
  14614. return this._isStreamingSupported;
  14615. }
  14616. async read() {
  14617. await this._readCapability.promise;
  14618. if (this._done) {
  14619. return {
  14620. value: undefined,
  14621. done: true
  14622. };
  14623. }
  14624. if (this._storedError) {
  14625. throw this._storedError;
  14626. }
  14627. const chunk = this._readableStream.read();
  14628. if (chunk === null) {
  14629. this._readCapability = (0, _util.createPromiseCapability)();
  14630. return this.read();
  14631. }
  14632. this._loaded += chunk.length;
  14633. if (this.onProgress) {
  14634. this.onProgress({
  14635. loaded: this._loaded
  14636. });
  14637. }
  14638. const buffer = new Uint8Array(chunk).buffer;
  14639. return {
  14640. value: buffer,
  14641. done: false
  14642. };
  14643. }
  14644. cancel(reason) {
  14645. if (!this._readableStream) {
  14646. this._error(reason);
  14647. return;
  14648. }
  14649. this._readableStream.destroy(reason);
  14650. }
  14651. _error(reason) {
  14652. this._storedError = reason;
  14653. this._readCapability.resolve();
  14654. }
  14655. _setReadableStream(readableStream) {
  14656. this._readableStream = readableStream;
  14657. readableStream.on("readable", () => {
  14658. this._readCapability.resolve();
  14659. });
  14660. readableStream.on("end", () => {
  14661. readableStream.destroy();
  14662. this._done = true;
  14663. this._readCapability.resolve();
  14664. });
  14665. readableStream.on("error", reason => {
  14666. this._error(reason);
  14667. });
  14668. if (this._storedError) {
  14669. this._readableStream.destroy(this._storedError);
  14670. }
  14671. }
  14672. }
  14673. function createRequestOptions(parsedUrl, headers) {
  14674. return {
  14675. protocol: parsedUrl.protocol,
  14676. auth: parsedUrl.auth,
  14677. host: parsedUrl.hostname,
  14678. port: parsedUrl.port,
  14679. path: parsedUrl.path,
  14680. method: "GET",
  14681. headers
  14682. };
  14683. }
  14684. class PDFNodeStreamFullReader extends BaseFullReader {
  14685. constructor(stream) {
  14686. super(stream);
  14687. const handleResponse = response => {
  14688. if (response.statusCode === 404) {
  14689. const error = new _util.MissingPDFException(`Missing PDF "${this._url}".`);
  14690. this._storedError = error;
  14691. this._headersCapability.reject(error);
  14692. return;
  14693. }
  14694. this._headersCapability.resolve();
  14695. this._setReadableStream(response);
  14696. const getResponseHeader = name => {
  14697. return this._readableStream.headers[name.toLowerCase()];
  14698. };
  14699. const {
  14700. allowRangeRequests,
  14701. suggestedLength
  14702. } = (0, _network_utils.validateRangeRequestCapabilities)({
  14703. getResponseHeader,
  14704. isHttp: stream.isHttp,
  14705. rangeChunkSize: this._rangeChunkSize,
  14706. disableRange: this._disableRange
  14707. });
  14708. this._isRangeSupported = allowRangeRequests;
  14709. this._contentLength = suggestedLength || this._contentLength;
  14710. this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
  14711. };
  14712. this._request = null;
  14713. if (this._url.protocol === "http:") {
  14714. this._request = http.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
  14715. } else {
  14716. this._request = https.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
  14717. }
  14718. this._request.on("error", reason => {
  14719. this._storedError = reason;
  14720. this._headersCapability.reject(reason);
  14721. });
  14722. this._request.end();
  14723. }
  14724. }
  14725. class PDFNodeStreamRangeReader extends BaseRangeReader {
  14726. constructor(stream, start, end) {
  14727. super(stream);
  14728. this._httpHeaders = {};
  14729. for (const property in stream.httpHeaders) {
  14730. const value = stream.httpHeaders[property];
  14731. if (typeof value === "undefined") {
  14732. continue;
  14733. }
  14734. this._httpHeaders[property] = value;
  14735. }
  14736. this._httpHeaders.Range = `bytes=${start}-${end - 1}`;
  14737. const handleResponse = response => {
  14738. if (response.statusCode === 404) {
  14739. const error = new _util.MissingPDFException(`Missing PDF "${this._url}".`);
  14740. this._storedError = error;
  14741. return;
  14742. }
  14743. this._setReadableStream(response);
  14744. };
  14745. this._request = null;
  14746. if (this._url.protocol === "http:") {
  14747. this._request = http.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
  14748. } else {
  14749. this._request = https.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
  14750. }
  14751. this._request.on("error", reason => {
  14752. this._storedError = reason;
  14753. });
  14754. this._request.end();
  14755. }
  14756. }
  14757. class PDFNodeStreamFsFullReader extends BaseFullReader {
  14758. constructor(stream) {
  14759. super(stream);
  14760. let path = decodeURIComponent(this._url.path);
  14761. if (fileUriRegex.test(this._url.href)) {
  14762. path = path.replace(/^\//, "");
  14763. }
  14764. fs.lstat(path, (error, stat) => {
  14765. if (error) {
  14766. if (error.code === "ENOENT") {
  14767. error = new _util.MissingPDFException(`Missing PDF "${path}".`);
  14768. }
  14769. this._storedError = error;
  14770. this._headersCapability.reject(error);
  14771. return;
  14772. }
  14773. this._contentLength = stat.size;
  14774. this._setReadableStream(fs.createReadStream(path));
  14775. this._headersCapability.resolve();
  14776. });
  14777. }
  14778. }
  14779. class PDFNodeStreamFsRangeReader extends BaseRangeReader {
  14780. constructor(stream, start, end) {
  14781. super(stream);
  14782. let path = decodeURIComponent(this._url.path);
  14783. if (fileUriRegex.test(this._url.href)) {
  14784. path = path.replace(/^\//, "");
  14785. }
  14786. this._setReadableStream(fs.createReadStream(path, {
  14787. start,
  14788. end: end - 1
  14789. }));
  14790. }
  14791. }
  14792. /***/ }),
  14793. /* 33 */
  14794. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  14795. Object.defineProperty(exports, "__esModule", ({
  14796. value: true
  14797. }));
  14798. exports.createResponseStatusError = createResponseStatusError;
  14799. exports.extractFilenameFromHeader = extractFilenameFromHeader;
  14800. exports.validateRangeRequestCapabilities = validateRangeRequestCapabilities;
  14801. exports.validateResponseStatus = validateResponseStatus;
  14802. var _util = __w_pdfjs_require__(1);
  14803. var _content_disposition = __w_pdfjs_require__(34);
  14804. var _display_utils = __w_pdfjs_require__(8);
  14805. function validateRangeRequestCapabilities({
  14806. getResponseHeader,
  14807. isHttp,
  14808. rangeChunkSize,
  14809. disableRange
  14810. }) {
  14811. const returnValues = {
  14812. allowRangeRequests: false,
  14813. suggestedLength: undefined
  14814. };
  14815. const length = parseInt(getResponseHeader("Content-Length"), 10);
  14816. if (!Number.isInteger(length)) {
  14817. return returnValues;
  14818. }
  14819. returnValues.suggestedLength = length;
  14820. if (length <= 2 * rangeChunkSize) {
  14821. return returnValues;
  14822. }
  14823. if (disableRange || !isHttp) {
  14824. return returnValues;
  14825. }
  14826. if (getResponseHeader("Accept-Ranges") !== "bytes") {
  14827. return returnValues;
  14828. }
  14829. const contentEncoding = getResponseHeader("Content-Encoding") || "identity";
  14830. if (contentEncoding !== "identity") {
  14831. return returnValues;
  14832. }
  14833. returnValues.allowRangeRequests = true;
  14834. return returnValues;
  14835. }
  14836. function extractFilenameFromHeader(getResponseHeader) {
  14837. const contentDisposition = getResponseHeader("Content-Disposition");
  14838. if (contentDisposition) {
  14839. let filename = (0, _content_disposition.getFilenameFromContentDispositionHeader)(contentDisposition);
  14840. if (filename.includes("%")) {
  14841. try {
  14842. filename = decodeURIComponent(filename);
  14843. } catch (ex) {}
  14844. }
  14845. if ((0, _display_utils.isPdfFile)(filename)) {
  14846. return filename;
  14847. }
  14848. }
  14849. return null;
  14850. }
  14851. function createResponseStatusError(status, url) {
  14852. if (status === 404 || status === 0 && url.startsWith("file:")) {
  14853. return new _util.MissingPDFException('Missing PDF "' + url + '".');
  14854. }
  14855. return new _util.UnexpectedResponseException(`Unexpected server response (${status}) while retrieving PDF "${url}".`, status);
  14856. }
  14857. function validateResponseStatus(status) {
  14858. return status === 200 || status === 206;
  14859. }
  14860. /***/ }),
  14861. /* 34 */
  14862. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  14863. Object.defineProperty(exports, "__esModule", ({
  14864. value: true
  14865. }));
  14866. exports.getFilenameFromContentDispositionHeader = getFilenameFromContentDispositionHeader;
  14867. var _util = __w_pdfjs_require__(1);
  14868. function getFilenameFromContentDispositionHeader(contentDisposition) {
  14869. let needsEncodingFixup = true;
  14870. let tmp = toParamRegExp("filename\\*", "i").exec(contentDisposition);
  14871. if (tmp) {
  14872. tmp = tmp[1];
  14873. let filename = rfc2616unquote(tmp);
  14874. filename = unescape(filename);
  14875. filename = rfc5987decode(filename);
  14876. filename = rfc2047decode(filename);
  14877. return fixupEncoding(filename);
  14878. }
  14879. tmp = rfc2231getparam(contentDisposition);
  14880. if (tmp) {
  14881. const filename = rfc2047decode(tmp);
  14882. return fixupEncoding(filename);
  14883. }
  14884. tmp = toParamRegExp("filename", "i").exec(contentDisposition);
  14885. if (tmp) {
  14886. tmp = tmp[1];
  14887. let filename = rfc2616unquote(tmp);
  14888. filename = rfc2047decode(filename);
  14889. return fixupEncoding(filename);
  14890. }
  14891. function toParamRegExp(attributePattern, flags) {
  14892. return new RegExp("(?:^|;)\\s*" + attributePattern + "\\s*=\\s*" + "(" + '[^";\\s][^;\\s]*' + "|" + '"(?:[^"\\\\]|\\\\"?)+"?' + ")", flags);
  14893. }
  14894. function textdecode(encoding, value) {
  14895. if (encoding) {
  14896. if (!/^[\x00-\xFF]+$/.test(value)) {
  14897. return value;
  14898. }
  14899. try {
  14900. const decoder = new TextDecoder(encoding, {
  14901. fatal: true
  14902. });
  14903. const buffer = (0, _util.stringToBytes)(value);
  14904. value = decoder.decode(buffer);
  14905. needsEncodingFixup = false;
  14906. } catch (e) {}
  14907. }
  14908. return value;
  14909. }
  14910. function fixupEncoding(value) {
  14911. if (needsEncodingFixup && /[\x80-\xff]/.test(value)) {
  14912. value = textdecode("utf-8", value);
  14913. if (needsEncodingFixup) {
  14914. value = textdecode("iso-8859-1", value);
  14915. }
  14916. }
  14917. return value;
  14918. }
  14919. function rfc2231getparam(contentDispositionStr) {
  14920. const matches = [];
  14921. let match;
  14922. const iter = toParamRegExp("filename\\*((?!0\\d)\\d+)(\\*?)", "ig");
  14923. while ((match = iter.exec(contentDispositionStr)) !== null) {
  14924. let [, n, quot, part] = match;
  14925. n = parseInt(n, 10);
  14926. if (n in matches) {
  14927. if (n === 0) {
  14928. break;
  14929. }
  14930. continue;
  14931. }
  14932. matches[n] = [quot, part];
  14933. }
  14934. const parts = [];
  14935. for (let n = 0; n < matches.length; ++n) {
  14936. if (!(n in matches)) {
  14937. break;
  14938. }
  14939. let [quot, part] = matches[n];
  14940. part = rfc2616unquote(part);
  14941. if (quot) {
  14942. part = unescape(part);
  14943. if (n === 0) {
  14944. part = rfc5987decode(part);
  14945. }
  14946. }
  14947. parts.push(part);
  14948. }
  14949. return parts.join("");
  14950. }
  14951. function rfc2616unquote(value) {
  14952. if (value.startsWith('"')) {
  14953. const parts = value.slice(1).split('\\"');
  14954. for (let i = 0; i < parts.length; ++i) {
  14955. const quotindex = parts[i].indexOf('"');
  14956. if (quotindex !== -1) {
  14957. parts[i] = parts[i].slice(0, quotindex);
  14958. parts.length = i + 1;
  14959. }
  14960. parts[i] = parts[i].replace(/\\(.)/g, "$1");
  14961. }
  14962. value = parts.join('"');
  14963. }
  14964. return value;
  14965. }
  14966. function rfc5987decode(extvalue) {
  14967. const encodingend = extvalue.indexOf("'");
  14968. if (encodingend === -1) {
  14969. return extvalue;
  14970. }
  14971. const encoding = extvalue.slice(0, encodingend);
  14972. const langvalue = extvalue.slice(encodingend + 1);
  14973. const value = langvalue.replace(/^[^']*'/, "");
  14974. return textdecode(encoding, value);
  14975. }
  14976. function rfc2047decode(value) {
  14977. if (!value.startsWith("=?") || /[\x00-\x19\x80-\xff]/.test(value)) {
  14978. return value;
  14979. }
  14980. return value.replace(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g, function (matches, charset, encoding, text) {
  14981. if (encoding === "q" || encoding === "Q") {
  14982. text = text.replace(/_/g, " ");
  14983. text = text.replace(/=([0-9a-fA-F]{2})/g, function (match, hex) {
  14984. return String.fromCharCode(parseInt(hex, 16));
  14985. });
  14986. return textdecode(charset, text);
  14987. }
  14988. try {
  14989. text = atob(text);
  14990. } catch (e) {}
  14991. return textdecode(charset, text);
  14992. });
  14993. }
  14994. return "";
  14995. }
  14996. /***/ }),
  14997. /* 35 */
  14998. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  14999. Object.defineProperty(exports, "__esModule", ({
  15000. value: true
  15001. }));
  15002. exports.PDFNetworkStream = void 0;
  15003. var _util = __w_pdfjs_require__(1);
  15004. var _network_utils = __w_pdfjs_require__(33);
  15005. ;
  15006. const OK_RESPONSE = 200;
  15007. const PARTIAL_CONTENT_RESPONSE = 206;
  15008. function getArrayBuffer(xhr) {
  15009. const data = xhr.response;
  15010. if (typeof data !== "string") {
  15011. return data;
  15012. }
  15013. const array = (0, _util.stringToBytes)(data);
  15014. return array.buffer;
  15015. }
  15016. class NetworkManager {
  15017. constructor(url, args = {}) {
  15018. this.url = url;
  15019. this.isHttp = /^https?:/i.test(url);
  15020. this.httpHeaders = this.isHttp && args.httpHeaders || Object.create(null);
  15021. this.withCredentials = args.withCredentials || false;
  15022. this.getXhr = args.getXhr || function NetworkManager_getXhr() {
  15023. return new XMLHttpRequest();
  15024. };
  15025. this.currXhrId = 0;
  15026. this.pendingRequests = Object.create(null);
  15027. }
  15028. requestRange(begin, end, listeners) {
  15029. const args = {
  15030. begin,
  15031. end
  15032. };
  15033. for (const prop in listeners) {
  15034. args[prop] = listeners[prop];
  15035. }
  15036. return this.request(args);
  15037. }
  15038. requestFull(listeners) {
  15039. return this.request(listeners);
  15040. }
  15041. request(args) {
  15042. const xhr = this.getXhr();
  15043. const xhrId = this.currXhrId++;
  15044. const pendingRequest = this.pendingRequests[xhrId] = {
  15045. xhr
  15046. };
  15047. xhr.open("GET", this.url);
  15048. xhr.withCredentials = this.withCredentials;
  15049. for (const property in this.httpHeaders) {
  15050. const value = this.httpHeaders[property];
  15051. if (typeof value === "undefined") {
  15052. continue;
  15053. }
  15054. xhr.setRequestHeader(property, value);
  15055. }
  15056. if (this.isHttp && "begin" in args && "end" in args) {
  15057. xhr.setRequestHeader("Range", `bytes=${args.begin}-${args.end - 1}`);
  15058. pendingRequest.expectedStatus = PARTIAL_CONTENT_RESPONSE;
  15059. } else {
  15060. pendingRequest.expectedStatus = OK_RESPONSE;
  15061. }
  15062. xhr.responseType = "arraybuffer";
  15063. if (args.onError) {
  15064. xhr.onerror = function (evt) {
  15065. args.onError(xhr.status);
  15066. };
  15067. }
  15068. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  15069. xhr.onprogress = this.onProgress.bind(this, xhrId);
  15070. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  15071. pendingRequest.onDone = args.onDone;
  15072. pendingRequest.onError = args.onError;
  15073. pendingRequest.onProgress = args.onProgress;
  15074. xhr.send(null);
  15075. return xhrId;
  15076. }
  15077. onProgress(xhrId, evt) {
  15078. const pendingRequest = this.pendingRequests[xhrId];
  15079. if (!pendingRequest) {
  15080. return;
  15081. }
  15082. pendingRequest.onProgress?.(evt);
  15083. }
  15084. onStateChange(xhrId, evt) {
  15085. const pendingRequest = this.pendingRequests[xhrId];
  15086. if (!pendingRequest) {
  15087. return;
  15088. }
  15089. const xhr = pendingRequest.xhr;
  15090. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  15091. pendingRequest.onHeadersReceived();
  15092. delete pendingRequest.onHeadersReceived;
  15093. }
  15094. if (xhr.readyState !== 4) {
  15095. return;
  15096. }
  15097. if (!(xhrId in this.pendingRequests)) {
  15098. return;
  15099. }
  15100. delete this.pendingRequests[xhrId];
  15101. if (xhr.status === 0 && this.isHttp) {
  15102. pendingRequest.onError?.(xhr.status);
  15103. return;
  15104. }
  15105. const xhrStatus = xhr.status || OK_RESPONSE;
  15106. const ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  15107. if (!ok_response_on_range_request && xhrStatus !== pendingRequest.expectedStatus) {
  15108. pendingRequest.onError?.(xhr.status);
  15109. return;
  15110. }
  15111. const chunk = getArrayBuffer(xhr);
  15112. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  15113. const rangeHeader = xhr.getResponseHeader("Content-Range");
  15114. const matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  15115. pendingRequest.onDone({
  15116. begin: parseInt(matches[1], 10),
  15117. chunk
  15118. });
  15119. } else if (chunk) {
  15120. pendingRequest.onDone({
  15121. begin: 0,
  15122. chunk
  15123. });
  15124. } else {
  15125. pendingRequest.onError?.(xhr.status);
  15126. }
  15127. }
  15128. getRequestXhr(xhrId) {
  15129. return this.pendingRequests[xhrId].xhr;
  15130. }
  15131. isPendingRequest(xhrId) {
  15132. return xhrId in this.pendingRequests;
  15133. }
  15134. abortRequest(xhrId) {
  15135. const xhr = this.pendingRequests[xhrId].xhr;
  15136. delete this.pendingRequests[xhrId];
  15137. xhr.abort();
  15138. }
  15139. }
  15140. class PDFNetworkStream {
  15141. constructor(source) {
  15142. this._source = source;
  15143. this._manager = new NetworkManager(source.url, {
  15144. httpHeaders: source.httpHeaders,
  15145. withCredentials: source.withCredentials
  15146. });
  15147. this._rangeChunkSize = source.rangeChunkSize;
  15148. this._fullRequestReader = null;
  15149. this._rangeRequestReaders = [];
  15150. }
  15151. _onRangeRequestReaderClosed(reader) {
  15152. const i = this._rangeRequestReaders.indexOf(reader);
  15153. if (i >= 0) {
  15154. this._rangeRequestReaders.splice(i, 1);
  15155. }
  15156. }
  15157. getFullReader() {
  15158. (0, _util.assert)(!this._fullRequestReader, "PDFNetworkStream.getFullReader can only be called once.");
  15159. this._fullRequestReader = new PDFNetworkStreamFullRequestReader(this._manager, this._source);
  15160. return this._fullRequestReader;
  15161. }
  15162. getRangeReader(begin, end) {
  15163. const reader = new PDFNetworkStreamRangeRequestReader(this._manager, begin, end);
  15164. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  15165. this._rangeRequestReaders.push(reader);
  15166. return reader;
  15167. }
  15168. cancelAllRequests(reason) {
  15169. this._fullRequestReader?.cancel(reason);
  15170. for (const reader of this._rangeRequestReaders.slice(0)) {
  15171. reader.cancel(reason);
  15172. }
  15173. }
  15174. }
  15175. exports.PDFNetworkStream = PDFNetworkStream;
  15176. class PDFNetworkStreamFullRequestReader {
  15177. constructor(manager, source) {
  15178. this._manager = manager;
  15179. const args = {
  15180. onHeadersReceived: this._onHeadersReceived.bind(this),
  15181. onDone: this._onDone.bind(this),
  15182. onError: this._onError.bind(this),
  15183. onProgress: this._onProgress.bind(this)
  15184. };
  15185. this._url = source.url;
  15186. this._fullRequestId = manager.requestFull(args);
  15187. this._headersReceivedCapability = (0, _util.createPromiseCapability)();
  15188. this._disableRange = source.disableRange || false;
  15189. this._contentLength = source.length;
  15190. this._rangeChunkSize = source.rangeChunkSize;
  15191. if (!this._rangeChunkSize && !this._disableRange) {
  15192. this._disableRange = true;
  15193. }
  15194. this._isStreamingSupported = false;
  15195. this._isRangeSupported = false;
  15196. this._cachedChunks = [];
  15197. this._requests = [];
  15198. this._done = false;
  15199. this._storedError = undefined;
  15200. this._filename = null;
  15201. this.onProgress = null;
  15202. }
  15203. _onHeadersReceived() {
  15204. const fullRequestXhrId = this._fullRequestId;
  15205. const fullRequestXhr = this._manager.getRequestXhr(fullRequestXhrId);
  15206. const getResponseHeader = name => {
  15207. return fullRequestXhr.getResponseHeader(name);
  15208. };
  15209. const {
  15210. allowRangeRequests,
  15211. suggestedLength
  15212. } = (0, _network_utils.validateRangeRequestCapabilities)({
  15213. getResponseHeader,
  15214. isHttp: this._manager.isHttp,
  15215. rangeChunkSize: this._rangeChunkSize,
  15216. disableRange: this._disableRange
  15217. });
  15218. if (allowRangeRequests) {
  15219. this._isRangeSupported = true;
  15220. }
  15221. this._contentLength = suggestedLength || this._contentLength;
  15222. this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
  15223. if (this._isRangeSupported) {
  15224. this._manager.abortRequest(fullRequestXhrId);
  15225. }
  15226. this._headersReceivedCapability.resolve();
  15227. }
  15228. _onDone(data) {
  15229. if (data) {
  15230. if (this._requests.length > 0) {
  15231. const requestCapability = this._requests.shift();
  15232. requestCapability.resolve({
  15233. value: data.chunk,
  15234. done: false
  15235. });
  15236. } else {
  15237. this._cachedChunks.push(data.chunk);
  15238. }
  15239. }
  15240. this._done = true;
  15241. if (this._cachedChunks.length > 0) {
  15242. return;
  15243. }
  15244. for (const requestCapability of this._requests) {
  15245. requestCapability.resolve({
  15246. value: undefined,
  15247. done: true
  15248. });
  15249. }
  15250. this._requests.length = 0;
  15251. }
  15252. _onError(status) {
  15253. this._storedError = (0, _network_utils.createResponseStatusError)(status, this._url);
  15254. this._headersReceivedCapability.reject(this._storedError);
  15255. for (const requestCapability of this._requests) {
  15256. requestCapability.reject(this._storedError);
  15257. }
  15258. this._requests.length = 0;
  15259. this._cachedChunks.length = 0;
  15260. }
  15261. _onProgress(evt) {
  15262. this.onProgress?.({
  15263. loaded: evt.loaded,
  15264. total: evt.lengthComputable ? evt.total : this._contentLength
  15265. });
  15266. }
  15267. get filename() {
  15268. return this._filename;
  15269. }
  15270. get isRangeSupported() {
  15271. return this._isRangeSupported;
  15272. }
  15273. get isStreamingSupported() {
  15274. return this._isStreamingSupported;
  15275. }
  15276. get contentLength() {
  15277. return this._contentLength;
  15278. }
  15279. get headersReady() {
  15280. return this._headersReceivedCapability.promise;
  15281. }
  15282. async read() {
  15283. if (this._storedError) {
  15284. throw this._storedError;
  15285. }
  15286. if (this._cachedChunks.length > 0) {
  15287. const chunk = this._cachedChunks.shift();
  15288. return {
  15289. value: chunk,
  15290. done: false
  15291. };
  15292. }
  15293. if (this._done) {
  15294. return {
  15295. value: undefined,
  15296. done: true
  15297. };
  15298. }
  15299. const requestCapability = (0, _util.createPromiseCapability)();
  15300. this._requests.push(requestCapability);
  15301. return requestCapability.promise;
  15302. }
  15303. cancel(reason) {
  15304. this._done = true;
  15305. this._headersReceivedCapability.reject(reason);
  15306. for (const requestCapability of this._requests) {
  15307. requestCapability.resolve({
  15308. value: undefined,
  15309. done: true
  15310. });
  15311. }
  15312. this._requests.length = 0;
  15313. if (this._manager.isPendingRequest(this._fullRequestId)) {
  15314. this._manager.abortRequest(this._fullRequestId);
  15315. }
  15316. this._fullRequestReader = null;
  15317. }
  15318. }
  15319. class PDFNetworkStreamRangeRequestReader {
  15320. constructor(manager, begin, end) {
  15321. this._manager = manager;
  15322. const args = {
  15323. onDone: this._onDone.bind(this),
  15324. onError: this._onError.bind(this),
  15325. onProgress: this._onProgress.bind(this)
  15326. };
  15327. this._url = manager.url;
  15328. this._requestId = manager.requestRange(begin, end, args);
  15329. this._requests = [];
  15330. this._queuedChunk = null;
  15331. this._done = false;
  15332. this._storedError = undefined;
  15333. this.onProgress = null;
  15334. this.onClosed = null;
  15335. }
  15336. _close() {
  15337. this.onClosed?.(this);
  15338. }
  15339. _onDone(data) {
  15340. const chunk = data.chunk;
  15341. if (this._requests.length > 0) {
  15342. const requestCapability = this._requests.shift();
  15343. requestCapability.resolve({
  15344. value: chunk,
  15345. done: false
  15346. });
  15347. } else {
  15348. this._queuedChunk = chunk;
  15349. }
  15350. this._done = true;
  15351. for (const requestCapability of this._requests) {
  15352. requestCapability.resolve({
  15353. value: undefined,
  15354. done: true
  15355. });
  15356. }
  15357. this._requests.length = 0;
  15358. this._close();
  15359. }
  15360. _onError(status) {
  15361. this._storedError = (0, _network_utils.createResponseStatusError)(status, this._url);
  15362. for (const requestCapability of this._requests) {
  15363. requestCapability.reject(this._storedError);
  15364. }
  15365. this._requests.length = 0;
  15366. this._queuedChunk = null;
  15367. }
  15368. _onProgress(evt) {
  15369. if (!this.isStreamingSupported) {
  15370. this.onProgress?.({
  15371. loaded: evt.loaded
  15372. });
  15373. }
  15374. }
  15375. get isStreamingSupported() {
  15376. return false;
  15377. }
  15378. async read() {
  15379. if (this._storedError) {
  15380. throw this._storedError;
  15381. }
  15382. if (this._queuedChunk !== null) {
  15383. const chunk = this._queuedChunk;
  15384. this._queuedChunk = null;
  15385. return {
  15386. value: chunk,
  15387. done: false
  15388. };
  15389. }
  15390. if (this._done) {
  15391. return {
  15392. value: undefined,
  15393. done: true
  15394. };
  15395. }
  15396. const requestCapability = (0, _util.createPromiseCapability)();
  15397. this._requests.push(requestCapability);
  15398. return requestCapability.promise;
  15399. }
  15400. cancel(reason) {
  15401. this._done = true;
  15402. for (const requestCapability of this._requests) {
  15403. requestCapability.resolve({
  15404. value: undefined,
  15405. done: true
  15406. });
  15407. }
  15408. this._requests.length = 0;
  15409. if (this._manager.isPendingRequest(this._requestId)) {
  15410. this._manager.abortRequest(this._requestId);
  15411. }
  15412. this._close();
  15413. }
  15414. }
  15415. /***/ }),
  15416. /* 36 */
  15417. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  15418. Object.defineProperty(exports, "__esModule", ({
  15419. value: true
  15420. }));
  15421. exports.PDFFetchStream = void 0;
  15422. var _util = __w_pdfjs_require__(1);
  15423. var _network_utils = __w_pdfjs_require__(33);
  15424. ;
  15425. function createFetchOptions(headers, withCredentials, abortController) {
  15426. return {
  15427. method: "GET",
  15428. headers,
  15429. signal: abortController.signal,
  15430. mode: "cors",
  15431. credentials: withCredentials ? "include" : "same-origin",
  15432. redirect: "follow"
  15433. };
  15434. }
  15435. function createHeaders(httpHeaders) {
  15436. const headers = new Headers();
  15437. for (const property in httpHeaders) {
  15438. const value = httpHeaders[property];
  15439. if (typeof value === "undefined") {
  15440. continue;
  15441. }
  15442. headers.append(property, value);
  15443. }
  15444. return headers;
  15445. }
  15446. class PDFFetchStream {
  15447. constructor(source) {
  15448. this.source = source;
  15449. this.isHttp = /^https?:/i.test(source.url);
  15450. this.httpHeaders = this.isHttp && source.httpHeaders || {};
  15451. this._fullRequestReader = null;
  15452. this._rangeRequestReaders = [];
  15453. }
  15454. get _progressiveDataLength() {
  15455. return this._fullRequestReader?._loaded ?? 0;
  15456. }
  15457. getFullReader() {
  15458. (0, _util.assert)(!this._fullRequestReader, "PDFFetchStream.getFullReader can only be called once.");
  15459. this._fullRequestReader = new PDFFetchStreamReader(this);
  15460. return this._fullRequestReader;
  15461. }
  15462. getRangeReader(begin, end) {
  15463. if (end <= this._progressiveDataLength) {
  15464. return null;
  15465. }
  15466. const reader = new PDFFetchStreamRangeReader(this, begin, end);
  15467. this._rangeRequestReaders.push(reader);
  15468. return reader;
  15469. }
  15470. cancelAllRequests(reason) {
  15471. if (this._fullRequestReader) {
  15472. this._fullRequestReader.cancel(reason);
  15473. }
  15474. for (const reader of this._rangeRequestReaders.slice(0)) {
  15475. reader.cancel(reason);
  15476. }
  15477. }
  15478. }
  15479. exports.PDFFetchStream = PDFFetchStream;
  15480. class PDFFetchStreamReader {
  15481. constructor(stream) {
  15482. this._stream = stream;
  15483. this._reader = null;
  15484. this._loaded = 0;
  15485. this._filename = null;
  15486. const source = stream.source;
  15487. this._withCredentials = source.withCredentials || false;
  15488. this._contentLength = source.length;
  15489. this._headersCapability = (0, _util.createPromiseCapability)();
  15490. this._disableRange = source.disableRange || false;
  15491. this._rangeChunkSize = source.rangeChunkSize;
  15492. if (!this._rangeChunkSize && !this._disableRange) {
  15493. this._disableRange = true;
  15494. }
  15495. this._abortController = new AbortController();
  15496. this._isStreamingSupported = !source.disableStream;
  15497. this._isRangeSupported = !source.disableRange;
  15498. this._headers = createHeaders(this._stream.httpHeaders);
  15499. const url = source.url;
  15500. fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(response => {
  15501. if (!(0, _network_utils.validateResponseStatus)(response.status)) {
  15502. throw (0, _network_utils.createResponseStatusError)(response.status, url);
  15503. }
  15504. this._reader = response.body.getReader();
  15505. this._headersCapability.resolve();
  15506. const getResponseHeader = name => {
  15507. return response.headers.get(name);
  15508. };
  15509. const {
  15510. allowRangeRequests,
  15511. suggestedLength
  15512. } = (0, _network_utils.validateRangeRequestCapabilities)({
  15513. getResponseHeader,
  15514. isHttp: this._stream.isHttp,
  15515. rangeChunkSize: this._rangeChunkSize,
  15516. disableRange: this._disableRange
  15517. });
  15518. this._isRangeSupported = allowRangeRequests;
  15519. this._contentLength = suggestedLength || this._contentLength;
  15520. this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
  15521. if (!this._isStreamingSupported && this._isRangeSupported) {
  15522. this.cancel(new _util.AbortException("Streaming is disabled."));
  15523. }
  15524. }).catch(this._headersCapability.reject);
  15525. this.onProgress = null;
  15526. }
  15527. get headersReady() {
  15528. return this._headersCapability.promise;
  15529. }
  15530. get filename() {
  15531. return this._filename;
  15532. }
  15533. get contentLength() {
  15534. return this._contentLength;
  15535. }
  15536. get isRangeSupported() {
  15537. return this._isRangeSupported;
  15538. }
  15539. get isStreamingSupported() {
  15540. return this._isStreamingSupported;
  15541. }
  15542. async read() {
  15543. await this._headersCapability.promise;
  15544. const {
  15545. value,
  15546. done
  15547. } = await this._reader.read();
  15548. if (done) {
  15549. return {
  15550. value,
  15551. done
  15552. };
  15553. }
  15554. this._loaded += value.byteLength;
  15555. if (this.onProgress) {
  15556. this.onProgress({
  15557. loaded: this._loaded,
  15558. total: this._contentLength
  15559. });
  15560. }
  15561. const buffer = new Uint8Array(value).buffer;
  15562. return {
  15563. value: buffer,
  15564. done: false
  15565. };
  15566. }
  15567. cancel(reason) {
  15568. if (this._reader) {
  15569. this._reader.cancel(reason);
  15570. }
  15571. this._abortController.abort();
  15572. }
  15573. }
  15574. class PDFFetchStreamRangeReader {
  15575. constructor(stream, begin, end) {
  15576. this._stream = stream;
  15577. this._reader = null;
  15578. this._loaded = 0;
  15579. const source = stream.source;
  15580. this._withCredentials = source.withCredentials || false;
  15581. this._readCapability = (0, _util.createPromiseCapability)();
  15582. this._isStreamingSupported = !source.disableStream;
  15583. this._abortController = new AbortController();
  15584. this._headers = createHeaders(this._stream.httpHeaders);
  15585. this._headers.append("Range", `bytes=${begin}-${end - 1}`);
  15586. const url = source.url;
  15587. fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(response => {
  15588. if (!(0, _network_utils.validateResponseStatus)(response.status)) {
  15589. throw (0, _network_utils.createResponseStatusError)(response.status, url);
  15590. }
  15591. this._readCapability.resolve();
  15592. this._reader = response.body.getReader();
  15593. }).catch(this._readCapability.reject);
  15594. this.onProgress = null;
  15595. }
  15596. get isStreamingSupported() {
  15597. return this._isStreamingSupported;
  15598. }
  15599. async read() {
  15600. await this._readCapability.promise;
  15601. const {
  15602. value,
  15603. done
  15604. } = await this._reader.read();
  15605. if (done) {
  15606. return {
  15607. value,
  15608. done
  15609. };
  15610. }
  15611. this._loaded += value.byteLength;
  15612. if (this.onProgress) {
  15613. this.onProgress({
  15614. loaded: this._loaded
  15615. });
  15616. }
  15617. const buffer = new Uint8Array(value).buffer;
  15618. return {
  15619. value: buffer,
  15620. done: false
  15621. };
  15622. }
  15623. cancel(reason) {
  15624. if (this._reader) {
  15625. this._reader.cancel(reason);
  15626. }
  15627. this._abortController.abort();
  15628. }
  15629. }
  15630. /***/ })
  15631. /******/ ]);
  15632. /************************************************************************/
  15633. /******/ // The module cache
  15634. /******/ var __webpack_module_cache__ = {};
  15635. /******/
  15636. /******/ // The require function
  15637. /******/ function __w_pdfjs_require__(moduleId) {
  15638. /******/ // Check if module is in cache
  15639. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  15640. /******/ if (cachedModule !== undefined) {
  15641. /******/ return cachedModule.exports;
  15642. /******/ }
  15643. /******/ // Create a new module (and put it into the cache)
  15644. /******/ var module = __webpack_module_cache__[moduleId] = {
  15645. /******/ // no module.id needed
  15646. /******/ // no module.loaded needed
  15647. /******/ exports: {}
  15648. /******/ };
  15649. /******/
  15650. /******/ // Execute the module function
  15651. /******/ __webpack_modules__[moduleId](module, module.exports, __w_pdfjs_require__);
  15652. /******/
  15653. /******/ // Return the exports of the module
  15654. /******/ return module.exports;
  15655. /******/ }
  15656. /******/
  15657. /************************************************************************/
  15658. var __webpack_exports__ = {};
  15659. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  15660. (() => {
  15661. var exports = __webpack_exports__;
  15662. Object.defineProperty(exports, "__esModule", ({
  15663. value: true
  15664. }));
  15665. Object.defineProperty(exports, "AnnotationEditorLayer", ({
  15666. enumerable: true,
  15667. get: function () {
  15668. return _annotation_editor_layer.AnnotationEditorLayer;
  15669. }
  15670. }));
  15671. Object.defineProperty(exports, "AnnotationEditorParamsType", ({
  15672. enumerable: true,
  15673. get: function () {
  15674. return _util.AnnotationEditorParamsType;
  15675. }
  15676. }));
  15677. Object.defineProperty(exports, "AnnotationEditorType", ({
  15678. enumerable: true,
  15679. get: function () {
  15680. return _util.AnnotationEditorType;
  15681. }
  15682. }));
  15683. Object.defineProperty(exports, "AnnotationEditorUIManager", ({
  15684. enumerable: true,
  15685. get: function () {
  15686. return _tools.AnnotationEditorUIManager;
  15687. }
  15688. }));
  15689. Object.defineProperty(exports, "AnnotationLayer", ({
  15690. enumerable: true,
  15691. get: function () {
  15692. return _annotation_layer.AnnotationLayer;
  15693. }
  15694. }));
  15695. Object.defineProperty(exports, "AnnotationMode", ({
  15696. enumerable: true,
  15697. get: function () {
  15698. return _util.AnnotationMode;
  15699. }
  15700. }));
  15701. Object.defineProperty(exports, "CMapCompressionType", ({
  15702. enumerable: true,
  15703. get: function () {
  15704. return _util.CMapCompressionType;
  15705. }
  15706. }));
  15707. Object.defineProperty(exports, "GlobalWorkerOptions", ({
  15708. enumerable: true,
  15709. get: function () {
  15710. return _worker_options.GlobalWorkerOptions;
  15711. }
  15712. }));
  15713. Object.defineProperty(exports, "InvalidPDFException", ({
  15714. enumerable: true,
  15715. get: function () {
  15716. return _util.InvalidPDFException;
  15717. }
  15718. }));
  15719. Object.defineProperty(exports, "LoopbackPort", ({
  15720. enumerable: true,
  15721. get: function () {
  15722. return _api.LoopbackPort;
  15723. }
  15724. }));
  15725. Object.defineProperty(exports, "MissingPDFException", ({
  15726. enumerable: true,
  15727. get: function () {
  15728. return _util.MissingPDFException;
  15729. }
  15730. }));
  15731. Object.defineProperty(exports, "OPS", ({
  15732. enumerable: true,
  15733. get: function () {
  15734. return _util.OPS;
  15735. }
  15736. }));
  15737. Object.defineProperty(exports, "PDFDataRangeTransport", ({
  15738. enumerable: true,
  15739. get: function () {
  15740. return _api.PDFDataRangeTransport;
  15741. }
  15742. }));
  15743. Object.defineProperty(exports, "PDFDateString", ({
  15744. enumerable: true,
  15745. get: function () {
  15746. return _display_utils.PDFDateString;
  15747. }
  15748. }));
  15749. Object.defineProperty(exports, "PDFWorker", ({
  15750. enumerable: true,
  15751. get: function () {
  15752. return _api.PDFWorker;
  15753. }
  15754. }));
  15755. Object.defineProperty(exports, "PasswordResponses", ({
  15756. enumerable: true,
  15757. get: function () {
  15758. return _util.PasswordResponses;
  15759. }
  15760. }));
  15761. Object.defineProperty(exports, "PermissionFlag", ({
  15762. enumerable: true,
  15763. get: function () {
  15764. return _util.PermissionFlag;
  15765. }
  15766. }));
  15767. Object.defineProperty(exports, "PixelsPerInch", ({
  15768. enumerable: true,
  15769. get: function () {
  15770. return _display_utils.PixelsPerInch;
  15771. }
  15772. }));
  15773. Object.defineProperty(exports, "RenderingCancelledException", ({
  15774. enumerable: true,
  15775. get: function () {
  15776. return _display_utils.RenderingCancelledException;
  15777. }
  15778. }));
  15779. Object.defineProperty(exports, "SVGGraphics", ({
  15780. enumerable: true,
  15781. get: function () {
  15782. return _svg.SVGGraphics;
  15783. }
  15784. }));
  15785. Object.defineProperty(exports, "UNSUPPORTED_FEATURES", ({
  15786. enumerable: true,
  15787. get: function () {
  15788. return _util.UNSUPPORTED_FEATURES;
  15789. }
  15790. }));
  15791. Object.defineProperty(exports, "UnexpectedResponseException", ({
  15792. enumerable: true,
  15793. get: function () {
  15794. return _util.UnexpectedResponseException;
  15795. }
  15796. }));
  15797. Object.defineProperty(exports, "Util", ({
  15798. enumerable: true,
  15799. get: function () {
  15800. return _util.Util;
  15801. }
  15802. }));
  15803. Object.defineProperty(exports, "VerbosityLevel", ({
  15804. enumerable: true,
  15805. get: function () {
  15806. return _util.VerbosityLevel;
  15807. }
  15808. }));
  15809. Object.defineProperty(exports, "XfaLayer", ({
  15810. enumerable: true,
  15811. get: function () {
  15812. return _xfa_layer.XfaLayer;
  15813. }
  15814. }));
  15815. Object.defineProperty(exports, "build", ({
  15816. enumerable: true,
  15817. get: function () {
  15818. return _api.build;
  15819. }
  15820. }));
  15821. Object.defineProperty(exports, "createPromiseCapability", ({
  15822. enumerable: true,
  15823. get: function () {
  15824. return _util.createPromiseCapability;
  15825. }
  15826. }));
  15827. Object.defineProperty(exports, "createValidAbsoluteUrl", ({
  15828. enumerable: true,
  15829. get: function () {
  15830. return _util.createValidAbsoluteUrl;
  15831. }
  15832. }));
  15833. Object.defineProperty(exports, "getDocument", ({
  15834. enumerable: true,
  15835. get: function () {
  15836. return _api.getDocument;
  15837. }
  15838. }));
  15839. Object.defineProperty(exports, "getFilenameFromUrl", ({
  15840. enumerable: true,
  15841. get: function () {
  15842. return _display_utils.getFilenameFromUrl;
  15843. }
  15844. }));
  15845. Object.defineProperty(exports, "getPdfFilenameFromUrl", ({
  15846. enumerable: true,
  15847. get: function () {
  15848. return _display_utils.getPdfFilenameFromUrl;
  15849. }
  15850. }));
  15851. Object.defineProperty(exports, "getXfaPageViewport", ({
  15852. enumerable: true,
  15853. get: function () {
  15854. return _display_utils.getXfaPageViewport;
  15855. }
  15856. }));
  15857. Object.defineProperty(exports, "isPdfFile", ({
  15858. enumerable: true,
  15859. get: function () {
  15860. return _display_utils.isPdfFile;
  15861. }
  15862. }));
  15863. Object.defineProperty(exports, "loadScript", ({
  15864. enumerable: true,
  15865. get: function () {
  15866. return _display_utils.loadScript;
  15867. }
  15868. }));
  15869. Object.defineProperty(exports, "renderTextLayer", ({
  15870. enumerable: true,
  15871. get: function () {
  15872. return _text_layer.renderTextLayer;
  15873. }
  15874. }));
  15875. Object.defineProperty(exports, "shadow", ({
  15876. enumerable: true,
  15877. get: function () {
  15878. return _util.shadow;
  15879. }
  15880. }));
  15881. Object.defineProperty(exports, "version", ({
  15882. enumerable: true,
  15883. get: function () {
  15884. return _api.version;
  15885. }
  15886. }));
  15887. var _util = __w_pdfjs_require__(1);
  15888. var _api = __w_pdfjs_require__(4);
  15889. var _display_utils = __w_pdfjs_require__(8);
  15890. var _annotation_editor_layer = __w_pdfjs_require__(22);
  15891. var _tools = __w_pdfjs_require__(7);
  15892. var _annotation_layer = __w_pdfjs_require__(27);
  15893. var _worker_options = __w_pdfjs_require__(15);
  15894. var _is_node = __w_pdfjs_require__(3);
  15895. var _text_layer = __w_pdfjs_require__(30);
  15896. var _svg = __w_pdfjs_require__(31);
  15897. var _xfa_layer = __w_pdfjs_require__(29);
  15898. const pdfjsVersion = '2.16.105';
  15899. const pdfjsBuild = '172ccdbe5';
  15900. {
  15901. if (_is_node.isNodeJS) {
  15902. const {
  15903. PDFNodeStream
  15904. } = __w_pdfjs_require__(32);
  15905. (0, _api.setPDFNetworkStreamFactory)(params => {
  15906. return new PDFNodeStream(params);
  15907. });
  15908. } else {
  15909. const {
  15910. PDFNetworkStream
  15911. } = __w_pdfjs_require__(35);
  15912. const {
  15913. PDFFetchStream
  15914. } = __w_pdfjs_require__(36);
  15915. (0, _api.setPDFNetworkStreamFactory)(params => {
  15916. if ((0, _display_utils.isValidFetchUrl)(params.url)) {
  15917. return new PDFFetchStream(params);
  15918. }
  15919. return new PDFNetworkStream(params);
  15920. });
  15921. }
  15922. }
  15923. })();
  15924. /******/ return __webpack_exports__;
  15925. /******/ })()
  15926. ;
  15927. });
  15928. //# sourceMappingURL=pdf.js.map